* i386-tdep.c (i386_mxcsr_type): New variable.
[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
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@*
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 Free Software Foundation's Back-Cover Text is: ``You have
66 freedom to copy and modify this GNU Manual, like GNU software. Copies
67 published by the Free Software Foundation raise funds for GNU
68 development.''
69 @end ifinfo
70
71 @titlepage
72 @title Debugging with @value{GDBN}
73 @subtitle The @sc{gnu} Source-Level Debugger
74 @sp 1
75 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
76 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
77 @page
78 @tex
79 {\parskip=0pt
80 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
81 \hfill {\it Debugging with @value{GDBN}}\par
82 \hfill \TeX{}info \texinfoversion\par
83 }
84 @end tex
85
86 @vskip 0pt plus 1filll
87 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
88 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89 Free Software Foundation, Inc.
90 @sp 2
91 Published by the Free Software Foundation @*
92 51 Franklin Street, Fifth Floor,
93 Boston, MA 02110-1301, USA@*
94 ISBN 1-882114-77-9 @*
95
96 Permission is granted to copy, distribute and/or modify this document
97 under the terms of the GNU Free Documentation License, Version 1.1 or
98 any later version published by the Free Software Foundation; with the
99 Invariant Sections being ``Free Software'' and ``Free Software Needs
100 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101 and with the Back-Cover Texts as in (a) below.
102
103 (a) The Free Software Foundation's Back-Cover Text is: ``You have
104 freedom to copy and modify this GNU Manual, like GNU software. Copies
105 published by the Free Software Foundation raise funds for GNU
106 development.''
107 @end titlepage
108 @page
109
110 @ifnottex
111 @node Top, Summary, (dir), (dir)
112
113 @top Debugging with @value{GDBN}
114
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117 This is the @value{EDITION} Edition, for @value{GDBN} Version
118 @value{GDBVN}.
119
120 Copyright (C) 1988-2005 Free Software Foundation, Inc.
121
122 @menu
123 * Summary:: Summary of @value{GDBN}
124 * Sample Session:: A sample @value{GDBN} session
125
126 * Invocation:: Getting in and out of @value{GDBN}
127 * Commands:: @value{GDBN} commands
128 * Running:: Running programs under @value{GDBN}
129 * Stopping:: Stopping and continuing
130 * Stack:: Examining the stack
131 * Source:: Examining source files
132 * Data:: Examining data
133 * Macros:: Preprocessor Macros
134 * Tracepoints:: Debugging remote targets non-intrusively
135 * Overlays:: Debugging programs that use overlays
136
137 * Languages:: Using @value{GDBN} with different languages
138
139 * Symbols:: Examining the symbol table
140 * Altering:: Altering execution
141 * GDB Files:: @value{GDBN} files
142 * Targets:: Specifying a debugging target
143 * Remote Debugging:: Debugging remote programs
144 * Configurations:: Configuration-specific information
145 * Controlling GDB:: Controlling @value{GDBN}
146 * Sequences:: Canned sequences of commands
147 * TUI:: @value{GDBN} Text User Interface
148 * Interpreters:: Command Interpreters
149 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150 * Annotations:: @value{GDBN}'s annotation interface.
151 * GDB/MI:: @value{GDBN}'s Machine Interface.
152
153 * GDB Bugs:: Reporting bugs in @value{GDBN}
154 * Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156 * Command Line Editing:: Command Line Editing
157 * Using History Interactively:: Using History Interactively
158 * Installing GDB:: Installing GDB
159 * Maintenance Commands:: Maintenance Commands
160 * Remote Protocol:: GDB Remote Serial Protocol
161 * Agent Expressions:: The GDB Agent Expression Mechanism
162 * Copying:: GNU General Public License says
163 how you can copy and share GDB
164 * GNU Free Documentation License:: The license for this documentation
165 * Index:: Index
166 @end menu
167
168 @end ifnottex
169
170 @contents
171
172 @node Summary
173 @unnumbered Summary of @value{GDBN}
174
175 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176 going on ``inside'' another program while it executes---or what another
177 program was doing at the moment it crashed.
178
179 @value{GDBN} can do four main kinds of things (plus other things in support of
180 these) to help you catch bugs in the act:
181
182 @itemize @bullet
183 @item
184 Start your program, specifying anything that might affect its behavior.
185
186 @item
187 Make your program stop on specified conditions.
188
189 @item
190 Examine what has happened, when your program has stopped.
191
192 @item
193 Change things in your program, so you can experiment with correcting the
194 effects of one bug and go on to learn about another.
195 @end itemize
196
197 You can use @value{GDBN} to debug programs written in C and C@t{++}.
198 For more information, see @ref{Supported languages,,Supported languages}.
199 For more information, see @ref{C,,C and C++}.
200
201 @cindex Modula-2
202 Support for Modula-2 is partial. For information on Modula-2, see
203 @ref{Modula-2,,Modula-2}.
204
205 @cindex Pascal
206 Debugging Pascal programs which use sets, subranges, file variables, or
207 nested functions does not currently work. @value{GDBN} does not support
208 entering expressions, printing values, or similar features using Pascal
209 syntax.
210
211 @cindex Fortran
212 @value{GDBN} can be used to debug programs written in Fortran, although
213 it may be necessary to refer to some variables with a trailing
214 underscore.
215
216 @value{GDBN} can be used to debug programs written in Objective-C,
217 using either the Apple/NeXT or the GNU Objective-C runtime.
218
219 @menu
220 * Free Software:: Freely redistributable software
221 * Contributors:: Contributors to GDB
222 @end menu
223
224 @node Free Software
225 @unnumberedsec Free software
226
227 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
228 General Public License
229 (GPL). The GPL gives you the freedom to copy or adapt a licensed
230 program---but every person getting a copy also gets with it the
231 freedom to modify that copy (which means that they must get access to
232 the source code), and the freedom to distribute further copies.
233 Typical software companies use copyrights to limit your freedoms; the
234 Free Software Foundation uses the GPL to preserve these freedoms.
235
236 Fundamentally, the General Public License is a license which says that
237 you have these freedoms and that you cannot take these freedoms away
238 from anyone else.
239
240 @unnumberedsec Free Software Needs Free Documentation
241
242 The biggest deficiency in the free software community today is not in
243 the software---it is the lack of good free documentation that we can
244 include with the free software. Many of our most important
245 programs do not come with free reference manuals and free introductory
246 texts. Documentation is an essential part of any software package;
247 when an important free software package does not come with a free
248 manual and a free tutorial, that is a major gap. We have many such
249 gaps today.
250
251 Consider Perl, for instance. The tutorial manuals that people
252 normally use are non-free. How did this come about? Because the
253 authors of those manuals published them with restrictive terms---no
254 copying, no modification, source files not available---which exclude
255 them from the free software world.
256
257 That wasn't the first time this sort of thing happened, and it was far
258 from the last. Many times we have heard a GNU user eagerly describe a
259 manual that he is writing, his intended contribution to the community,
260 only to learn that he had ruined everything by signing a publication
261 contract to make it non-free.
262
263 Free documentation, like free software, is a matter of freedom, not
264 price. The problem with the non-free manual is not that publishers
265 charge a price for printed copies---that in itself is fine. (The Free
266 Software Foundation sells printed copies of manuals, too.) The
267 problem is the restrictions on the use of the manual. Free manuals
268 are available in source code form, and give you permission to copy and
269 modify. Non-free manuals do not allow this.
270
271 The criteria of freedom for a free manual are roughly the same as for
272 free software. Redistribution (including the normal kinds of
273 commercial redistribution) must be permitted, so that the manual can
274 accompany every copy of the program, both on-line and on paper.
275
276 Permission for modification of the technical content is crucial too.
277 When people modify the software, adding or changing features, if they
278 are conscientious they will change the manual too---so they can
279 provide accurate and clear documentation for the modified program. A
280 manual that leaves you no choice but to write a new manual to document
281 a changed version of the program is not really available to our
282 community.
283
284 Some kinds of limits on the way modification is handled are
285 acceptable. For example, requirements to preserve the original
286 author's copyright notice, the distribution terms, or the list of
287 authors, are ok. It is also no problem to require modified versions
288 to include notice that they were modified. Even entire sections that
289 may not be deleted or changed are acceptable, as long as they deal
290 with nontechnical topics (like this one). These kinds of restrictions
291 are acceptable because they don't obstruct the community's normal use
292 of the manual.
293
294 However, it must be possible to modify all the @emph{technical}
295 content of the manual, and then distribute the result in all the usual
296 media, through all the usual channels. Otherwise, the restrictions
297 obstruct the use of the manual, it is not free, and we need another
298 manual to replace it.
299
300 Please spread the word about this issue. Our community continues to
301 lose manuals to proprietary publishing. If we spread the word that
302 free software needs free reference manuals and free tutorials, perhaps
303 the next person who wants to contribute by writing documentation will
304 realize, before it is too late, that only free manuals contribute to
305 the free software community.
306
307 If you are writing documentation, please insist on publishing it under
308 the GNU Free Documentation License or another free documentation
309 license. Remember that this decision requires your approval---you
310 don't have to let the publisher decide. Some commercial publishers
311 will use a free license if you insist, but they will not propose the
312 option; it is up to you to raise the issue and say firmly that this is
313 what you want. If the publisher you are dealing with refuses, please
314 try other publishers. If you're not sure whether a proposed license
315 is free, write to @email{licensing@@gnu.org}.
316
317 You can encourage commercial publishers to sell more free, copylefted
318 manuals and tutorials by buying them, and particularly by buying
319 copies from the publishers that paid for their writing or for major
320 improvements. Meanwhile, try to avoid buying non-free documentation
321 at all. Check the distribution terms of a manual before you buy it,
322 and insist that whoever seeks your business must respect your freedom.
323 Check the history of the book, and try to reward the publishers that
324 have paid or pay the authors to work on it.
325
326 The Free Software Foundation maintains a list of free documentation
327 published by other publishers, at
328 @url{http://www.fsf.org/doc/other-free-books.html}.
329
330 @node Contributors
331 @unnumberedsec Contributors to @value{GDBN}
332
333 Richard Stallman was the original author of @value{GDBN}, and of many
334 other @sc{gnu} programs. Many others have contributed to its
335 development. This section attempts to credit major contributors. One
336 of the virtues of free software is that everyone is free to contribute
337 to it; with regret, we cannot actually acknowledge everyone here. The
338 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
339 blow-by-blow account.
340
341 Changes much prior to version 2.0 are lost in the mists of time.
342
343 @quotation
344 @emph{Plea:} Additions to this section are particularly welcome. If you
345 or your friends (or enemies, to be evenhanded) have been unfairly
346 omitted from this list, we would like to add your names!
347 @end quotation
348
349 So that they may not regard their many labors as thankless, we
350 particularly thank those who shepherded @value{GDBN} through major
351 releases:
352 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
353 Jim Blandy (release 4.18);
354 Jason Molenda (release 4.17);
355 Stan Shebs (release 4.14);
356 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359 Jim Kingdon (releases 3.5, 3.4, and 3.3);
360 and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362 Richard Stallman, assisted at various times by Peter TerMaat, Chris
363 Hanson, and Richard Mlynarik, handled releases through 2.8.
364
365 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366 in @value{GDBN}, with significant additional contributions from Per
367 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369 much general update work leading to release 3.0).
370
371 @value{GDBN} uses the BFD subroutine library to examine multiple
372 object-file formats; BFD was a joint project of David V.
373 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375 David Johnson wrote the original COFF support; Pace Willison did
376 the original support for encapsulated COFF.
377
378 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
379
380 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382 support.
383 Jean-Daniel Fekete contributed Sun 386i support.
384 Chris Hanson improved the HP9000 support.
385 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386 David Johnson contributed Encore Umax support.
387 Jyrki Kuoppala contributed Altos 3068 support.
388 Jeff Law contributed HP PA and SOM support.
389 Keith Packard contributed NS32K support.
390 Doug Rabson contributed Acorn Risc Machine support.
391 Bob Rusk contributed Harris Nighthawk CX-UX support.
392 Chris Smith contributed Convex support (and Fortran debugging).
393 Jonathan Stone contributed Pyramid support.
394 Michael Tiemann contributed SPARC support.
395 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396 Pace Willison contributed Intel 386 support.
397 Jay Vosburgh contributed Symmetry support.
398 Marko Mlinar contributed OpenRISC 1000 support.
399
400 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
401
402 Rich Schaefer and Peter Schauer helped with support of SunOS shared
403 libraries.
404
405 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406 about several machine instruction sets.
407
408 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411 and RDI targets, respectively.
412
413 Brian Fox is the author of the readline libraries providing
414 command-line editing and command history.
415
416 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417 Modula-2 support, and contributed the Languages chapter of this manual.
418
419 Fred Fish wrote most of the support for Unix System Vr4.
420 He also enhanced the command-completion support to cover C@t{++} overloaded
421 symbols.
422
423 Hitachi America (now Renesas America), Ltd. sponsored the support for
424 H8/300, H8/500, and Super-H processors.
425
426 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
428 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429 processors.
430
431 Toshiba sponsored the support for the TX39 Mips processor.
432
433 Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
435 Fujitsu sponsored the support for SPARClite and FR30 processors.
436
437 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438 watchpoints.
439
440 Michael Snyder added support for tracepoints.
441
442 Stu Grossman wrote gdbserver.
443
444 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
445 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
446
447 The following people at the Hewlett-Packard Company contributed
448 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
449 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
450 compiler, and the Text User Interface (nee Terminal User Interface):
451 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453 provided HP-specific information in this manual.
454
455 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456 Robert Hoehne made significant contributions to the DJGPP port.
457
458 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459 development since 1991. Cygnus engineers who have worked on @value{GDBN}
460 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472 Zuhn have made contributions both large and small.
473
474 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
477 Jim Blandy added support for preprocessor macros, while working for Red
478 Hat.
479
480 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485 with the migration of old architectures to this new framework.
486
487 @node Sample Session
488 @chapter A Sample @value{GDBN} Session
489
490 You can use this manual at your leisure to read all about @value{GDBN}.
491 However, a handful of commands are enough to get started using the
492 debugger. This chapter illustrates those commands.
493
494 @iftex
495 In this sample session, we emphasize user input like this: @b{input},
496 to make it easier to pick out from the surrounding output.
497 @end iftex
498
499 @c FIXME: this example may not be appropriate for some configs, where
500 @c FIXME...primary interest is in remote use.
501
502 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
503 processor) exhibits the following bug: sometimes, when we change its
504 quote strings from the default, the commands used to capture one macro
505 definition within another stop working. In the following short @code{m4}
506 session, we define a macro @code{foo} which expands to @code{0000}; we
507 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
508 same thing. However, when we change the open quote string to
509 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
510 procedure fails to define a new synonym @code{baz}:
511
512 @smallexample
513 $ @b{cd gnu/m4}
514 $ @b{./m4}
515 @b{define(foo,0000)}
516
517 @b{foo}
518 0000
519 @b{define(bar,defn(`foo'))}
520
521 @b{bar}
522 0000
523 @b{changequote(<QUOTE>,<UNQUOTE>)}
524
525 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
526 @b{baz}
527 @b{C-d}
528 m4: End of input: 0: fatal error: EOF in string
529 @end smallexample
530
531 @noindent
532 Let us use @value{GDBN} to try to see what is going on.
533
534 @smallexample
535 $ @b{@value{GDBP} m4}
536 @c FIXME: this falsifies the exact text played out, to permit smallbook
537 @c FIXME... format to come out better.
538 @value{GDBN} is free software and you are welcome to distribute copies
539 of it under certain conditions; type "show copying" to see
540 the conditions.
541 There is absolutely no warranty for @value{GDBN}; type "show warranty"
542 for details.
543
544 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
545 (@value{GDBP})
546 @end smallexample
547
548 @noindent
549 @value{GDBN} reads only enough symbol data to know where to find the
550 rest when needed; as a result, the first prompt comes up very quickly.
551 We now tell @value{GDBN} to use a narrower display width than usual, so
552 that examples fit in this manual.
553
554 @smallexample
555 (@value{GDBP}) @b{set width 70}
556 @end smallexample
557
558 @noindent
559 We need to see how the @code{m4} built-in @code{changequote} works.
560 Having looked at the source, we know the relevant subroutine is
561 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
562 @code{break} command.
563
564 @smallexample
565 (@value{GDBP}) @b{break m4_changequote}
566 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
567 @end smallexample
568
569 @noindent
570 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
571 control; as long as control does not reach the @code{m4_changequote}
572 subroutine, the program runs as usual:
573
574 @smallexample
575 (@value{GDBP}) @b{run}
576 Starting program: /work/Editorial/gdb/gnu/m4/m4
577 @b{define(foo,0000)}
578
579 @b{foo}
580 0000
581 @end smallexample
582
583 @noindent
584 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
585 suspends execution of @code{m4}, displaying information about the
586 context where it stops.
587
588 @smallexample
589 @b{changequote(<QUOTE>,<UNQUOTE>)}
590
591 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
592 at builtin.c:879
593 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
594 @end smallexample
595
596 @noindent
597 Now we use the command @code{n} (@code{next}) to advance execution to
598 the next line of the current function.
599
600 @smallexample
601 (@value{GDBP}) @b{n}
602 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
603 : nil,
604 @end smallexample
605
606 @noindent
607 @code{set_quotes} looks like a promising subroutine. We can go into it
608 by using the command @code{s} (@code{step}) instead of @code{next}.
609 @code{step} goes to the next line to be executed in @emph{any}
610 subroutine, so it steps into @code{set_quotes}.
611
612 @smallexample
613 (@value{GDBP}) @b{s}
614 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
615 at input.c:530
616 530 if (lquote != def_lquote)
617 @end smallexample
618
619 @noindent
620 The display that shows the subroutine where @code{m4} is now
621 suspended (and its arguments) is called a stack frame display. It
622 shows a summary of the stack. We can use the @code{backtrace}
623 command (which can also be spelled @code{bt}), to see where we are
624 in the stack as a whole: the @code{backtrace} command displays a
625 stack frame for each active subroutine.
626
627 @smallexample
628 (@value{GDBP}) @b{bt}
629 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
630 at input.c:530
631 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
632 at builtin.c:882
633 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
634 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
635 at macro.c:71
636 #4 0x79dc in expand_input () at macro.c:40
637 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
638 @end smallexample
639
640 @noindent
641 We step through a few more lines to see what happens. The first two
642 times, we can use @samp{s}; the next two times we use @code{n} to avoid
643 falling into the @code{xstrdup} subroutine.
644
645 @smallexample
646 (@value{GDBP}) @b{s}
647 0x3b5c 532 if (rquote != def_rquote)
648 (@value{GDBP}) @b{s}
649 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
650 def_lquote : xstrdup(lq);
651 (@value{GDBP}) @b{n}
652 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
653 : xstrdup(rq);
654 (@value{GDBP}) @b{n}
655 538 len_lquote = strlen(rquote);
656 @end smallexample
657
658 @noindent
659 The last line displayed looks a little odd; we can examine the variables
660 @code{lquote} and @code{rquote} to see if they are in fact the new left
661 and right quotes we specified. We use the command @code{p}
662 (@code{print}) to see their values.
663
664 @smallexample
665 (@value{GDBP}) @b{p lquote}
666 $1 = 0x35d40 "<QUOTE>"
667 (@value{GDBP}) @b{p rquote}
668 $2 = 0x35d50 "<UNQUOTE>"
669 @end smallexample
670
671 @noindent
672 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
673 To look at some context, we can display ten lines of source
674 surrounding the current line with the @code{l} (@code{list}) command.
675
676 @smallexample
677 (@value{GDBP}) @b{l}
678 533 xfree(rquote);
679 534
680 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
681 : xstrdup (lq);
682 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
683 : xstrdup (rq);
684 537
685 538 len_lquote = strlen(rquote);
686 539 len_rquote = strlen(lquote);
687 540 @}
688 541
689 542 void
690 @end smallexample
691
692 @noindent
693 Let us step past the two lines that set @code{len_lquote} and
694 @code{len_rquote}, and then examine the values of those variables.
695
696 @smallexample
697 (@value{GDBP}) @b{n}
698 539 len_rquote = strlen(lquote);
699 (@value{GDBP}) @b{n}
700 540 @}
701 (@value{GDBP}) @b{p len_lquote}
702 $3 = 9
703 (@value{GDBP}) @b{p len_rquote}
704 $4 = 7
705 @end smallexample
706
707 @noindent
708 That certainly looks wrong, assuming @code{len_lquote} and
709 @code{len_rquote} are meant to be the lengths of @code{lquote} and
710 @code{rquote} respectively. We can set them to better values using
711 the @code{p} command, since it can print the value of
712 any expression---and that expression can include subroutine calls and
713 assignments.
714
715 @smallexample
716 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
717 $5 = 7
718 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
719 $6 = 9
720 @end smallexample
721
722 @noindent
723 Is that enough to fix the problem of using the new quotes with the
724 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
725 executing with the @code{c} (@code{continue}) command, and then try the
726 example that caused trouble initially:
727
728 @smallexample
729 (@value{GDBP}) @b{c}
730 Continuing.
731
732 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
733
734 baz
735 0000
736 @end smallexample
737
738 @noindent
739 Success! The new quotes now work just as well as the default ones. The
740 problem seems to have been just the two typos defining the wrong
741 lengths. We allow @code{m4} exit by giving it an EOF as input:
742
743 @smallexample
744 @b{C-d}
745 Program exited normally.
746 @end smallexample
747
748 @noindent
749 The message @samp{Program exited normally.} is from @value{GDBN}; it
750 indicates @code{m4} has finished executing. We can end our @value{GDBN}
751 session with the @value{GDBN} @code{quit} command.
752
753 @smallexample
754 (@value{GDBP}) @b{quit}
755 @end smallexample
756
757 @node Invocation
758 @chapter Getting In and Out of @value{GDBN}
759
760 This chapter discusses how to start @value{GDBN}, and how to get out of it.
761 The essentials are:
762 @itemize @bullet
763 @item
764 type @samp{@value{GDBP}} to start @value{GDBN}.
765 @item
766 type @kbd{quit} or @kbd{C-d} to exit.
767 @end itemize
768
769 @menu
770 * Invoking GDB:: How to start @value{GDBN}
771 * Quitting GDB:: How to quit @value{GDBN}
772 * Shell Commands:: How to use shell commands inside @value{GDBN}
773 * Logging output:: How to log @value{GDBN}'s output to a file
774 @end menu
775
776 @node Invoking GDB
777 @section Invoking @value{GDBN}
778
779 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
780 @value{GDBN} reads commands from the terminal until you tell it to exit.
781
782 You can also run @code{@value{GDBP}} with a variety of arguments and options,
783 to specify more of your debugging environment at the outset.
784
785 The command-line options described here are designed
786 to cover a variety of situations; in some environments, some of these
787 options may effectively be unavailable.
788
789 The most usual way to start @value{GDBN} is with one argument,
790 specifying an executable program:
791
792 @smallexample
793 @value{GDBP} @var{program}
794 @end smallexample
795
796 @noindent
797 You can also start with both an executable program and a core file
798 specified:
799
800 @smallexample
801 @value{GDBP} @var{program} @var{core}
802 @end smallexample
803
804 You can, instead, specify a process ID as a second argument, if you want
805 to debug a running process:
806
807 @smallexample
808 @value{GDBP} @var{program} 1234
809 @end smallexample
810
811 @noindent
812 would attach @value{GDBN} to process @code{1234} (unless you also have a file
813 named @file{1234}; @value{GDBN} does check for a core file first).
814
815 Taking advantage of the second command-line argument requires a fairly
816 complete operating system; when you use @value{GDBN} as a remote
817 debugger attached to a bare board, there may not be any notion of
818 ``process'', and there is often no way to get a core dump. @value{GDBN}
819 will warn you if it is unable to attach or to read core dumps.
820
821 You can optionally have @code{@value{GDBP}} pass any arguments after the
822 executable file to the inferior using @code{--args}. This option stops
823 option processing.
824 @smallexample
825 gdb --args gcc -O2 -c foo.c
826 @end smallexample
827 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
828 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
829
830 You can run @code{@value{GDBP}} without printing the front material, which describes
831 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
832
833 @smallexample
834 @value{GDBP} -silent
835 @end smallexample
836
837 @noindent
838 You can further control how @value{GDBN} starts up by using command-line
839 options. @value{GDBN} itself can remind you of the options available.
840
841 @noindent
842 Type
843
844 @smallexample
845 @value{GDBP} -help
846 @end smallexample
847
848 @noindent
849 to display all available options and briefly describe their use
850 (@samp{@value{GDBP} -h} is a shorter equivalent).
851
852 All options and command line arguments you give are processed
853 in sequential order. The order makes a difference when the
854 @samp{-x} option is used.
855
856
857 @menu
858 * File Options:: Choosing files
859 * Mode Options:: Choosing modes
860 * Startup:: What @value{GDBN} does during startup
861 @end menu
862
863 @node File Options
864 @subsection Choosing files
865
866 When @value{GDBN} starts, it reads any arguments other than options as
867 specifying an executable file and core file (or process ID). This is
868 the same as if the arguments were specified by the @samp{-se} and
869 @samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
870 first argument that does not have an associated option flag as
871 equivalent to the @samp{-se} option followed by that argument; and the
872 second argument that does not have an associated option flag, if any, as
873 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
874 If the second argument begins with a decimal digit, @value{GDBN} will
875 first attempt to attach to it as a process, and if that fails, attempt
876 to open it as a corefile. If you have a corefile whose name begins with
877 a digit, you can prevent @value{GDBN} from treating it as a pid by
878 prefixing it with @file{./}, e.g.@: @file{./12345}.
879
880 If @value{GDBN} has not been configured to included core file support,
881 such as for most embedded targets, then it will complain about a second
882 argument and ignore it.
883
884 Many options have both long and short forms; both are shown in the
885 following list. @value{GDBN} also recognizes the long forms if you truncate
886 them, so long as enough of the option is present to be unambiguous.
887 (If you prefer, you can flag option arguments with @samp{--} rather
888 than @samp{-}, though we illustrate the more usual convention.)
889
890 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
891 @c way, both those who look for -foo and --foo in the index, will find
892 @c it.
893
894 @table @code
895 @item -symbols @var{file}
896 @itemx -s @var{file}
897 @cindex @code{--symbols}
898 @cindex @code{-s}
899 Read symbol table from file @var{file}.
900
901 @item -exec @var{file}
902 @itemx -e @var{file}
903 @cindex @code{--exec}
904 @cindex @code{-e}
905 Use file @var{file} as the executable file to execute when appropriate,
906 and for examining pure data in conjunction with a core dump.
907
908 @item -se @var{file}
909 @cindex @code{--se}
910 Read symbol table from file @var{file} and use it as the executable
911 file.
912
913 @item -core @var{file}
914 @itemx -c @var{file}
915 @cindex @code{--core}
916 @cindex @code{-c}
917 Use file @var{file} as a core dump to examine.
918
919 @item -c @var{number}
920 @item -pid @var{number}
921 @itemx -p @var{number}
922 @cindex @code{--pid}
923 @cindex @code{-p}
924 Connect to process ID @var{number}, as with the @code{attach} command.
925 If there is no such process, @value{GDBN} will attempt to open a core
926 file named @var{number}.
927
928 @item -command @var{file}
929 @itemx -x @var{file}
930 @cindex @code{--command}
931 @cindex @code{-x}
932 Execute @value{GDBN} commands from file @var{file}. @xref{Command
933 Files,, Command files}.
934
935 @item -eval-command @var{command}
936 @itemx -ex @var{command}
937 @cindex @code{--eval-command}
938 @cindex @code{-ex}
939 Execute a single @value{GDBN} command.
940
941 This option may be used multiple times to call multiple commands. It may
942 also be interleaved with @samp{-command} as required.
943
944 @smallexample
945 @value{GDBP} -ex 'target sim' -ex 'load' \
946 -x setbreakpoints -ex 'run' a.out
947 @end smallexample
948
949 @item -directory @var{directory}
950 @itemx -d @var{directory}
951 @cindex @code{--directory}
952 @cindex @code{-d}
953 Add @var{directory} to the path to search for source files.
954
955 @item -r
956 @itemx -readnow
957 @cindex @code{--readnow}
958 @cindex @code{-r}
959 Read each symbol file's entire symbol table immediately, rather than
960 the default, which is to read it incrementally as it is needed.
961 This makes startup slower, but makes future operations faster.
962
963 @end table
964
965 @node Mode Options
966 @subsection Choosing modes
967
968 You can run @value{GDBN} in various alternative modes---for example, in
969 batch mode or quiet mode.
970
971 @table @code
972 @item -nx
973 @itemx -n
974 @cindex @code{--nx}
975 @cindex @code{-n}
976 Do not execute commands found in any initialization files. Normally,
977 @value{GDBN} executes the commands in these files after all the command
978 options and arguments have been processed. @xref{Command Files,,Command
979 files}.
980
981 @item -quiet
982 @itemx -silent
983 @itemx -q
984 @cindex @code{--quiet}
985 @cindex @code{--silent}
986 @cindex @code{-q}
987 ``Quiet''. Do not print the introductory and copyright messages. These
988 messages are also suppressed in batch mode.
989
990 @item -batch
991 @cindex @code{--batch}
992 Run in batch mode. Exit with status @code{0} after processing all the
993 command files specified with @samp{-x} (and all commands from
994 initialization files, if not inhibited with @samp{-n}). Exit with
995 nonzero status if an error occurs in executing the @value{GDBN} commands
996 in the command files.
997
998 Batch mode may be useful for running @value{GDBN} as a filter, for
999 example to download and run a program on another computer; in order to
1000 make this more useful, the message
1001
1002 @smallexample
1003 Program exited normally.
1004 @end smallexample
1005
1006 @noindent
1007 (which is ordinarily issued whenever a program running under
1008 @value{GDBN} control terminates) is not issued when running in batch
1009 mode.
1010
1011 @item -batch-silent
1012 @cindex @code{--batch-silent}
1013 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1014 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1015 unaffected). This is much quieter than @samp{-silent} and would be useless
1016 for an interactive session.
1017
1018 This is particularly useful when using targets that give @samp{Loading section}
1019 messages, for example.
1020
1021 Note that targets that give their output via @value{GDBN}, as opposed to
1022 writing directly to @code{stdout}, will also be made silent.
1023
1024 @item -return-child-result
1025 @cindex @code{--return-child-result}
1026 The return code from @value{GDBN} will be the return code from the child
1027 process (the process being debugged), with the following exceptions:
1028
1029 @itemize @bullet
1030 @item
1031 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1032 internal error. In this case the exit code is the same as it would have been
1033 without @samp{-return-child-result}.
1034 @item
1035 The user quits with an explicit value. E.g., @samp{quit 1}.
1036 @item
1037 The child process never runs, or is not allowed to terminate, in which case
1038 the exit code will be -1.
1039 @end itemize
1040
1041 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1042 when @value{GDBN} is being used as a remote program loader or simulator
1043 interface.
1044
1045 @item -nowindows
1046 @itemx -nw
1047 @cindex @code{--nowindows}
1048 @cindex @code{-nw}
1049 ``No windows''. If @value{GDBN} comes with a graphical user interface
1050 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1051 interface. If no GUI is available, this option has no effect.
1052
1053 @item -windows
1054 @itemx -w
1055 @cindex @code{--windows}
1056 @cindex @code{-w}
1057 If @value{GDBN} includes a GUI, then this option requires it to be
1058 used if possible.
1059
1060 @item -cd @var{directory}
1061 @cindex @code{--cd}
1062 Run @value{GDBN} using @var{directory} as its working directory,
1063 instead of the current directory.
1064
1065 @item -fullname
1066 @itemx -f
1067 @cindex @code{--fullname}
1068 @cindex @code{-f}
1069 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1070 subprocess. It tells @value{GDBN} to output the full file name and line
1071 number in a standard, recognizable fashion each time a stack frame is
1072 displayed (which includes each time your program stops). This
1073 recognizable format looks like two @samp{\032} characters, followed by
1074 the file name, line number and character position separated by colons,
1075 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1076 @samp{\032} characters as a signal to display the source code for the
1077 frame.
1078
1079 @item -epoch
1080 @cindex @code{--epoch}
1081 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1082 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1083 routines so as to allow Epoch to display values of expressions in a
1084 separate window.
1085
1086 @item -annotate @var{level}
1087 @cindex @code{--annotate}
1088 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1089 effect is identical to using @samp{set annotate @var{level}}
1090 (@pxref{Annotations}). The annotation @var{level} controls how much
1091 information @value{GDBN} prints together with its prompt, values of
1092 expressions, source lines, and other types of output. Level 0 is the
1093 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1094 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1095 that control @value{GDBN}, and level 2 has been deprecated.
1096
1097 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1098 (@pxref{GDB/MI}).
1099
1100 @item --args
1101 @cindex @code{--args}
1102 Change interpretation of command line so that arguments following the
1103 executable file are passed as command line arguments to the inferior.
1104 This option stops option processing.
1105
1106 @item -baud @var{bps}
1107 @itemx -b @var{bps}
1108 @cindex @code{--baud}
1109 @cindex @code{-b}
1110 Set the line speed (baud rate or bits per second) of any serial
1111 interface used by @value{GDBN} for remote debugging.
1112
1113 @item -l @var{timeout}
1114 @cindex @code{-l}
1115 Set the timeout (in seconds) of any communication used by @value{GDBN}
1116 for remote debugging.
1117
1118 @item -tty @var{device}
1119 @itemx -t @var{device}
1120 @cindex @code{--tty}
1121 @cindex @code{-t}
1122 Run using @var{device} for your program's standard input and output.
1123 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1124
1125 @c resolve the situation of these eventually
1126 @item -tui
1127 @cindex @code{--tui}
1128 Activate the @dfn{Text User Interface} when starting. The Text User
1129 Interface manages several text windows on the terminal, showing
1130 source, assembly, registers and @value{GDBN} command outputs
1131 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1132 Text User Interface can be enabled by invoking the program
1133 @samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1134 Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1135
1136 @c @item -xdb
1137 @c @cindex @code{--xdb}
1138 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1139 @c For information, see the file @file{xdb_trans.html}, which is usually
1140 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1141 @c systems.
1142
1143 @item -interpreter @var{interp}
1144 @cindex @code{--interpreter}
1145 Use the interpreter @var{interp} for interface with the controlling
1146 program or device. This option is meant to be set by programs which
1147 communicate with @value{GDBN} using it as a back end.
1148 @xref{Interpreters, , Command Interpreters}.
1149
1150 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1151 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1152 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
1153 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1154 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1155 @sc{gdb/mi} interfaces are no longer supported.
1156
1157 @item -write
1158 @cindex @code{--write}
1159 Open the executable and core files for both reading and writing. This
1160 is equivalent to the @samp{set write on} command inside @value{GDBN}
1161 (@pxref{Patching}).
1162
1163 @item -statistics
1164 @cindex @code{--statistics}
1165 This option causes @value{GDBN} to print statistics about time and
1166 memory usage after it completes each command and returns to the prompt.
1167
1168 @item -version
1169 @cindex @code{--version}
1170 This option causes @value{GDBN} to print its version number and
1171 no-warranty blurb, and exit.
1172
1173 @end table
1174
1175 @node Startup
1176 @subsection What @value{GDBN} does during startup
1177 @cindex @value{GDBN} startup
1178
1179 Here's the description of what @value{GDBN} does during session startup:
1180
1181 @enumerate
1182 @item
1183 Sets up the command interpreter as specified by the command line
1184 (@pxref{Mode Options, interpreter}).
1185
1186 @item
1187 @cindex init file
1188 Reads the @dfn{init file} (if any) in your home directory@footnote{On
1189 DOS/Windows systems, the home directory is the one pointed to by the
1190 @code{HOME} environment variable.} and executes all the commands in
1191 that file.
1192
1193 @item
1194 Processes command line options and operands.
1195
1196 @item
1197 Reads and executes the commands from init file (if any) in the current
1198 working directory. This is only done if the current directory is
1199 different from your home directory. Thus, you can have more than one
1200 init file, one generic in your home directory, and another, specific
1201 to the program you are debugging, in the directory where you invoke
1202 @value{GDBN}.
1203
1204 @item
1205 Reads command files specified by the @samp{-x} option. @xref{Command
1206 Files}, for more details about @value{GDBN} command files.
1207
1208 @item
1209 Reads the command history recorded in the @dfn{history file}.
1210 @xref{Command History}, for more details about the command history and the
1211 files where @value{GDBN} records it.
1212 @end enumerate
1213
1214 Init files use the same syntax as @dfn{command files} (@pxref{Command
1215 Files}) and are processed by @value{GDBN} in the same way. The init
1216 file in your home directory can set options (such as @samp{set
1217 complaints}) that affect subsequent processing of command line options
1218 and operands. Init files are not executed if you use the @samp{-nx}
1219 option (@pxref{Mode Options, ,Choosing modes}).
1220
1221 @cindex init file name
1222 @cindex @file{.gdbinit}
1223 The @value{GDBN} init files are normally called @file{.gdbinit}.
1224 On some configurations of @value{GDBN}, the init file is known by a
1225 different name (these are typically environments where a specialized
1226 form of @value{GDBN} may need to coexist with other forms, hence a
1227 different name for the specialized version's init file). These are the
1228 environments with special init file names:
1229
1230 @itemize @bullet
1231 @cindex @file{gdb.ini}
1232 @item
1233 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1234 the limitations of file names imposed by DOS filesystems. The Windows
1235 ports of @value{GDBN} use the standard name, but if they find a
1236 @file{gdb.ini} file, they warn you about that and suggest to rename
1237 the file to the standard name.
1238
1239 @cindex @file{.vxgdbinit}
1240 @item
1241 VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1242
1243 @cindex @file{.os68gdbinit}
1244 @item
1245 OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1246
1247 @cindex @file{.esgdbinit}
1248 @item
1249 ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1250
1251 @item
1252 CISCO 68k: @file{.cisco-gdbinit}
1253 @end itemize
1254
1255
1256 @node Quitting GDB
1257 @section Quitting @value{GDBN}
1258 @cindex exiting @value{GDBN}
1259 @cindex leaving @value{GDBN}
1260
1261 @table @code
1262 @kindex quit @r{[}@var{expression}@r{]}
1263 @kindex q @r{(@code{quit})}
1264 @item quit @r{[}@var{expression}@r{]}
1265 @itemx q
1266 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1267 @code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1268 do not supply @var{expression}, @value{GDBN} will terminate normally;
1269 otherwise it will terminate using the result of @var{expression} as the
1270 error code.
1271 @end table
1272
1273 @cindex interrupt
1274 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1275 terminates the action of any @value{GDBN} command that is in progress and
1276 returns to @value{GDBN} command level. It is safe to type the interrupt
1277 character at any time because @value{GDBN} does not allow it to take effect
1278 until a time when it is safe.
1279
1280 If you have been using @value{GDBN} to control an attached process or
1281 device, you can release it with the @code{detach} command
1282 (@pxref{Attach, ,Debugging an already-running process}).
1283
1284 @node Shell Commands
1285 @section Shell commands
1286
1287 If you need to execute occasional shell commands during your
1288 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1289 just use the @code{shell} command.
1290
1291 @table @code
1292 @kindex shell
1293 @cindex shell escape
1294 @item shell @var{command string}
1295 Invoke a standard shell to execute @var{command string}.
1296 If it exists, the environment variable @code{SHELL} determines which
1297 shell to run. Otherwise @value{GDBN} uses the default shell
1298 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1299 @end table
1300
1301 The utility @code{make} is often needed in development environments.
1302 You do not have to use the @code{shell} command for this purpose in
1303 @value{GDBN}:
1304
1305 @table @code
1306 @kindex make
1307 @cindex calling make
1308 @item make @var{make-args}
1309 Execute the @code{make} program with the specified
1310 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1311 @end table
1312
1313 @node Logging output
1314 @section Logging output
1315 @cindex logging @value{GDBN} output
1316 @cindex save @value{GDBN} output to a file
1317
1318 You may want to save the output of @value{GDBN} commands to a file.
1319 There are several commands to control @value{GDBN}'s logging.
1320
1321 @table @code
1322 @kindex set logging
1323 @item set logging on
1324 Enable logging.
1325 @item set logging off
1326 Disable logging.
1327 @cindex logging file name
1328 @item set logging file @var{file}
1329 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1330 @item set logging overwrite [on|off]
1331 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1332 you want @code{set logging on} to overwrite the logfile instead.
1333 @item set logging redirect [on|off]
1334 By default, @value{GDBN} output will go to both the terminal and the logfile.
1335 Set @code{redirect} if you want output to go only to the log file.
1336 @kindex show logging
1337 @item show logging
1338 Show the current values of the logging settings.
1339 @end table
1340
1341 @node Commands
1342 @chapter @value{GDBN} Commands
1343
1344 You can abbreviate a @value{GDBN} command to the first few letters of the command
1345 name, if that abbreviation is unambiguous; and you can repeat certain
1346 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1347 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1348 show you the alternatives available, if there is more than one possibility).
1349
1350 @menu
1351 * Command Syntax:: How to give commands to @value{GDBN}
1352 * Completion:: Command completion
1353 * Help:: How to ask @value{GDBN} for help
1354 @end menu
1355
1356 @node Command Syntax
1357 @section Command syntax
1358
1359 A @value{GDBN} command is a single line of input. There is no limit on
1360 how long it can be. It starts with a command name, which is followed by
1361 arguments whose meaning depends on the command name. For example, the
1362 command @code{step} accepts an argument which is the number of times to
1363 step, as in @samp{step 5}. You can also use the @code{step} command
1364 with no arguments. Some commands do not allow any arguments.
1365
1366 @cindex abbreviation
1367 @value{GDBN} command names may always be truncated if that abbreviation is
1368 unambiguous. Other possible command abbreviations are listed in the
1369 documentation for individual commands. In some cases, even ambiguous
1370 abbreviations are allowed; for example, @code{s} is specially defined as
1371 equivalent to @code{step} even though there are other commands whose
1372 names start with @code{s}. You can test abbreviations by using them as
1373 arguments to the @code{help} command.
1374
1375 @cindex repeating commands
1376 @kindex RET @r{(repeat last command)}
1377 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1378 repeat the previous command. Certain commands (for example, @code{run})
1379 will not repeat this way; these are commands whose unintentional
1380 repetition might cause trouble and which you are unlikely to want to
1381 repeat. User-defined commands can disable this feature; see
1382 @ref{Define, dont-repeat}.
1383
1384 The @code{list} and @code{x} commands, when you repeat them with
1385 @key{RET}, construct new arguments rather than repeating
1386 exactly as typed. This permits easy scanning of source or memory.
1387
1388 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1389 output, in a way similar to the common utility @code{more}
1390 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1391 @key{RET} too many in this situation, @value{GDBN} disables command
1392 repetition after any command that generates this sort of display.
1393
1394 @kindex # @r{(a comment)}
1395 @cindex comment
1396 Any text from a @kbd{#} to the end of the line is a comment; it does
1397 nothing. This is useful mainly in command files (@pxref{Command
1398 Files,,Command files}).
1399
1400 @cindex repeating command sequences
1401 @kindex C-o @r{(operate-and-get-next)}
1402 The @kbd{C-o} binding is useful for repeating a complex sequence of
1403 commands. This command accepts the current line, like @kbd{RET}, and
1404 then fetches the next line relative to the current line from the history
1405 for editing.
1406
1407 @node Completion
1408 @section Command completion
1409
1410 @cindex completion
1411 @cindex word completion
1412 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1413 only one possibility; it can also show you what the valid possibilities
1414 are for the next word in a command, at any time. This works for @value{GDBN}
1415 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1416
1417 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1418 of a word. If there is only one possibility, @value{GDBN} fills in the
1419 word, and waits for you to finish the command (or press @key{RET} to
1420 enter it). For example, if you type
1421
1422 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1423 @c complete accuracy in these examples; space introduced for clarity.
1424 @c If texinfo enhancements make it unnecessary, it would be nice to
1425 @c replace " @key" by "@key" in the following...
1426 @smallexample
1427 (@value{GDBP}) info bre @key{TAB}
1428 @end smallexample
1429
1430 @noindent
1431 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1432 the only @code{info} subcommand beginning with @samp{bre}:
1433
1434 @smallexample
1435 (@value{GDBP}) info breakpoints
1436 @end smallexample
1437
1438 @noindent
1439 You can either press @key{RET} at this point, to run the @code{info
1440 breakpoints} command, or backspace and enter something else, if
1441 @samp{breakpoints} does not look like the command you expected. (If you
1442 were sure you wanted @code{info breakpoints} in the first place, you
1443 might as well just type @key{RET} immediately after @samp{info bre},
1444 to exploit command abbreviations rather than command completion).
1445
1446 If there is more than one possibility for the next word when you press
1447 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1448 characters and try again, or just press @key{TAB} a second time;
1449 @value{GDBN} displays all the possible completions for that word. For
1450 example, you might want to set a breakpoint on a subroutine whose name
1451 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1452 just sounds the bell. Typing @key{TAB} again displays all the
1453 function names in your program that begin with those characters, for
1454 example:
1455
1456 @smallexample
1457 (@value{GDBP}) b make_ @key{TAB}
1458 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1459 make_a_section_from_file make_environ
1460 make_abs_section make_function_type
1461 make_blockvector make_pointer_type
1462 make_cleanup make_reference_type
1463 make_command make_symbol_completion_list
1464 (@value{GDBP}) b make_
1465 @end smallexample
1466
1467 @noindent
1468 After displaying the available possibilities, @value{GDBN} copies your
1469 partial input (@samp{b make_} in the example) so you can finish the
1470 command.
1471
1472 If you just want to see the list of alternatives in the first place, you
1473 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1474 means @kbd{@key{META} ?}. You can type this either by holding down a
1475 key designated as the @key{META} shift on your keyboard (if there is
1476 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1477
1478 @cindex quotes in commands
1479 @cindex completion of quoted strings
1480 Sometimes the string you need, while logically a ``word'', may contain
1481 parentheses or other characters that @value{GDBN} normally excludes from
1482 its notion of a word. To permit word completion to work in this
1483 situation, you may enclose words in @code{'} (single quote marks) in
1484 @value{GDBN} commands.
1485
1486 The most likely situation where you might need this is in typing the
1487 name of a C@t{++} function. This is because C@t{++} allows function
1488 overloading (multiple definitions of the same function, distinguished
1489 by argument type). For example, when you want to set a breakpoint you
1490 may need to distinguish whether you mean the version of @code{name}
1491 that takes an @code{int} parameter, @code{name(int)}, or the version
1492 that takes a @code{float} parameter, @code{name(float)}. To use the
1493 word-completion facilities in this situation, type a single quote
1494 @code{'} at the beginning of the function name. This alerts
1495 @value{GDBN} that it may need to consider more information than usual
1496 when you press @key{TAB} or @kbd{M-?} to request word completion:
1497
1498 @smallexample
1499 (@value{GDBP}) b 'bubble( @kbd{M-?}
1500 bubble(double,double) bubble(int,int)
1501 (@value{GDBP}) b 'bubble(
1502 @end smallexample
1503
1504 In some cases, @value{GDBN} can tell that completing a name requires using
1505 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1506 completing as much as it can) if you do not type the quote in the first
1507 place:
1508
1509 @smallexample
1510 (@value{GDBP}) b bub @key{TAB}
1511 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1512 (@value{GDBP}) b 'bubble(
1513 @end smallexample
1514
1515 @noindent
1516 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1517 you have not yet started typing the argument list when you ask for
1518 completion on an overloaded symbol.
1519
1520 For more information about overloaded functions, see @ref{C plus plus
1521 expressions, ,C@t{++} expressions}. You can use the command @code{set
1522 overload-resolution off} to disable overload resolution;
1523 see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
1524
1525
1526 @node Help
1527 @section Getting help
1528 @cindex online documentation
1529 @kindex help
1530
1531 You can always ask @value{GDBN} itself for information on its commands,
1532 using the command @code{help}.
1533
1534 @table @code
1535 @kindex h @r{(@code{help})}
1536 @item help
1537 @itemx h
1538 You can use @code{help} (abbreviated @code{h}) with no arguments to
1539 display a short list of named classes of commands:
1540
1541 @smallexample
1542 (@value{GDBP}) help
1543 List of classes of commands:
1544
1545 aliases -- Aliases of other commands
1546 breakpoints -- Making program stop at certain points
1547 data -- Examining data
1548 files -- Specifying and examining files
1549 internals -- Maintenance commands
1550 obscure -- Obscure features
1551 running -- Running the program
1552 stack -- Examining the stack
1553 status -- Status inquiries
1554 support -- Support facilities
1555 tracepoints -- Tracing of program execution without@*
1556 stopping the program
1557 user-defined -- User-defined commands
1558
1559 Type "help" followed by a class name for a list of
1560 commands in that class.
1561 Type "help" followed by command name for full
1562 documentation.
1563 Command name abbreviations are allowed if unambiguous.
1564 (@value{GDBP})
1565 @end smallexample
1566 @c the above line break eliminates huge line overfull...
1567
1568 @item help @var{class}
1569 Using one of the general help classes as an argument, you can get a
1570 list of the individual commands in that class. For example, here is the
1571 help display for the class @code{status}:
1572
1573 @smallexample
1574 (@value{GDBP}) help status
1575 Status inquiries.
1576
1577 List of commands:
1578
1579 @c Line break in "show" line falsifies real output, but needed
1580 @c to fit in smallbook page size.
1581 info -- Generic command for showing things
1582 about the program being debugged
1583 show -- Generic command for showing things
1584 about the debugger
1585
1586 Type "help" followed by command name for full
1587 documentation.
1588 Command name abbreviations are allowed if unambiguous.
1589 (@value{GDBP})
1590 @end smallexample
1591
1592 @item help @var{command}
1593 With a command name as @code{help} argument, @value{GDBN} displays a
1594 short paragraph on how to use that command.
1595
1596 @kindex apropos
1597 @item apropos @var{args}
1598 The @code{apropos} command searches through all of the @value{GDBN}
1599 commands, and their documentation, for the regular expression specified in
1600 @var{args}. It prints out all matches found. For example:
1601
1602 @smallexample
1603 apropos reload
1604 @end smallexample
1605
1606 @noindent
1607 results in:
1608
1609 @smallexample
1610 @c @group
1611 set symbol-reloading -- Set dynamic symbol table reloading
1612 multiple times in one run
1613 show symbol-reloading -- Show dynamic symbol table reloading
1614 multiple times in one run
1615 @c @end group
1616 @end smallexample
1617
1618 @kindex complete
1619 @item complete @var{args}
1620 The @code{complete @var{args}} command lists all the possible completions
1621 for the beginning of a command. Use @var{args} to specify the beginning of the
1622 command you want completed. For example:
1623
1624 @smallexample
1625 complete i
1626 @end smallexample
1627
1628 @noindent results in:
1629
1630 @smallexample
1631 @group
1632 if
1633 ignore
1634 info
1635 inspect
1636 @end group
1637 @end smallexample
1638
1639 @noindent This is intended for use by @sc{gnu} Emacs.
1640 @end table
1641
1642 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1643 and @code{show} to inquire about the state of your program, or the state
1644 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1645 manual introduces each of them in the appropriate context. The listings
1646 under @code{info} and under @code{show} in the Index point to
1647 all the sub-commands. @xref{Index}.
1648
1649 @c @group
1650 @table @code
1651 @kindex info
1652 @kindex i @r{(@code{info})}
1653 @item info
1654 This command (abbreviated @code{i}) is for describing the state of your
1655 program. For example, you can list the arguments given to your program
1656 with @code{info args}, list the registers currently in use with @code{info
1657 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1658 You can get a complete list of the @code{info} sub-commands with
1659 @w{@code{help info}}.
1660
1661 @kindex set
1662 @item set
1663 You can assign the result of an expression to an environment variable with
1664 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1665 @code{set prompt $}.
1666
1667 @kindex show
1668 @item show
1669 In contrast to @code{info}, @code{show} is for describing the state of
1670 @value{GDBN} itself.
1671 You can change most of the things you can @code{show}, by using the
1672 related command @code{set}; for example, you can control what number
1673 system is used for displays with @code{set radix}, or simply inquire
1674 which is currently in use with @code{show radix}.
1675
1676 @kindex info set
1677 To display all the settable parameters and their current
1678 values, you can use @code{show} with no arguments; you may also use
1679 @code{info set}. Both commands produce the same display.
1680 @c FIXME: "info set" violates the rule that "info" is for state of
1681 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1682 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1683 @end table
1684 @c @end group
1685
1686 Here are three miscellaneous @code{show} subcommands, all of which are
1687 exceptional in lacking corresponding @code{set} commands:
1688
1689 @table @code
1690 @kindex show version
1691 @cindex @value{GDBN} version number
1692 @item show version
1693 Show what version of @value{GDBN} is running. You should include this
1694 information in @value{GDBN} bug-reports. If multiple versions of
1695 @value{GDBN} are in use at your site, you may need to determine which
1696 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1697 commands are introduced, and old ones may wither away. Also, many
1698 system vendors ship variant versions of @value{GDBN}, and there are
1699 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1700 The version number is the same as the one announced when you start
1701 @value{GDBN}.
1702
1703 @kindex show copying
1704 @kindex info copying
1705 @cindex display @value{GDBN} copyright
1706 @item show copying
1707 @itemx info copying
1708 Display information about permission for copying @value{GDBN}.
1709
1710 @kindex show warranty
1711 @kindex info warranty
1712 @item show warranty
1713 @itemx info warranty
1714 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1715 if your version of @value{GDBN} comes with one.
1716
1717 @end table
1718
1719 @node Running
1720 @chapter Running Programs Under @value{GDBN}
1721
1722 When you run a program under @value{GDBN}, you must first generate
1723 debugging information when you compile it.
1724
1725 You may start @value{GDBN} with its arguments, if any, in an environment
1726 of your choice. If you are doing native debugging, you may redirect
1727 your program's input and output, debug an already running process, or
1728 kill a child process.
1729
1730 @menu
1731 * Compilation:: Compiling for debugging
1732 * Starting:: Starting your program
1733 * Arguments:: Your program's arguments
1734 * Environment:: Your program's environment
1735
1736 * Working Directory:: Your program's working directory
1737 * Input/Output:: Your program's input and output
1738 * Attach:: Debugging an already-running process
1739 * Kill Process:: Killing the child process
1740
1741 * Threads:: Debugging programs with multiple threads
1742 * Processes:: Debugging programs with multiple processes
1743 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
1744 @end menu
1745
1746 @node Compilation
1747 @section Compiling for debugging
1748
1749 In order to debug a program effectively, you need to generate
1750 debugging information when you compile it. This debugging information
1751 is stored in the object file; it describes the data type of each
1752 variable or function and the correspondence between source line numbers
1753 and addresses in the executable code.
1754
1755 To request debugging information, specify the @samp{-g} option when you run
1756 the compiler.
1757
1758 Programs that are to be shipped to your customers are compiled with
1759 optimizations, using the @samp{-O} compiler option. However, many
1760 compilers are unable to handle the @samp{-g} and @samp{-O} options
1761 together. Using those compilers, you cannot generate optimized
1762 executables containing debugging information.
1763
1764 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1765 without @samp{-O}, making it possible to debug optimized code. We
1766 recommend that you @emph{always} use @samp{-g} whenever you compile a
1767 program. You may think your program is correct, but there is no sense
1768 in pushing your luck.
1769
1770 @cindex optimized code, debugging
1771 @cindex debugging optimized code
1772 When you debug a program compiled with @samp{-g -O}, remember that the
1773 optimizer is rearranging your code; the debugger shows you what is
1774 really there. Do not be too surprised when the execution path does not
1775 exactly match your source file! An extreme example: if you define a
1776 variable, but never use it, @value{GDBN} never sees that
1777 variable---because the compiler optimizes it out of existence.
1778
1779 Some things do not work as well with @samp{-g -O} as with just
1780 @samp{-g}, particularly on machines with instruction scheduling. If in
1781 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1782 please report it to us as a bug (including a test case!).
1783 @xref{Variables}, for more information about debugging optimized code.
1784
1785 Older versions of the @sc{gnu} C compiler permitted a variant option
1786 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1787 format; if your @sc{gnu} C compiler has this option, do not use it.
1788
1789 @value{GDBN} knows about preprocessor macros and can show you their
1790 expansion (@pxref{Macros}). Most compilers do not include information
1791 about preprocessor macros in the debugging information if you specify
1792 the @option{-g} flag alone, because this information is rather large.
1793 Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1794 provides macro information if you specify the options
1795 @option{-gdwarf-2} and @option{-g3}; the former option requests
1796 debugging information in the Dwarf 2 format, and the latter requests
1797 ``extra information''. In the future, we hope to find more compact
1798 ways to represent macro information, so that it can be included with
1799 @option{-g} alone.
1800
1801 @need 2000
1802 @node Starting
1803 @section Starting your program
1804 @cindex starting
1805 @cindex running
1806
1807 @table @code
1808 @kindex run
1809 @kindex r @r{(@code{run})}
1810 @item run
1811 @itemx r
1812 Use the @code{run} command to start your program under @value{GDBN}.
1813 You must first specify the program name (except on VxWorks) with an
1814 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1815 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1816 (@pxref{Files, ,Commands to specify files}).
1817
1818 @end table
1819
1820 If you are running your program in an execution environment that
1821 supports processes, @code{run} creates an inferior process and makes
1822 that process run your program. (In environments without processes,
1823 @code{run} jumps to the start of your program.)
1824
1825 The execution of a program is affected by certain information it
1826 receives from its superior. @value{GDBN} provides ways to specify this
1827 information, which you must do @emph{before} starting your program. (You
1828 can change it after starting your program, but such changes only affect
1829 your program the next time you start it.) This information may be
1830 divided into four categories:
1831
1832 @table @asis
1833 @item The @emph{arguments.}
1834 Specify the arguments to give your program as the arguments of the
1835 @code{run} command. If a shell is available on your target, the shell
1836 is used to pass the arguments, so that you may use normal conventions
1837 (such as wildcard expansion or variable substitution) in describing
1838 the arguments.
1839 In Unix systems, you can control which shell is used with the
1840 @code{SHELL} environment variable.
1841 @xref{Arguments, ,Your program's arguments}.
1842
1843 @item The @emph{environment.}
1844 Your program normally inherits its environment from @value{GDBN}, but you can
1845 use the @value{GDBN} commands @code{set environment} and @code{unset
1846 environment} to change parts of the environment that affect
1847 your program. @xref{Environment, ,Your program's environment}.
1848
1849 @item The @emph{working directory.}
1850 Your program inherits its working directory from @value{GDBN}. You can set
1851 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1852 @xref{Working Directory, ,Your program's working directory}.
1853
1854 @item The @emph{standard input and output.}
1855 Your program normally uses the same device for standard input and
1856 standard output as @value{GDBN} is using. You can redirect input and output
1857 in the @code{run} command line, or you can use the @code{tty} command to
1858 set a different device for your program.
1859 @xref{Input/Output, ,Your program's input and output}.
1860
1861 @cindex pipes
1862 @emph{Warning:} While input and output redirection work, you cannot use
1863 pipes to pass the output of the program you are debugging to another
1864 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1865 wrong program.
1866 @end table
1867
1868 When you issue the @code{run} command, your program begins to execute
1869 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1870 of how to arrange for your program to stop. Once your program has
1871 stopped, you may call functions in your program, using the @code{print}
1872 or @code{call} commands. @xref{Data, ,Examining Data}.
1873
1874 If the modification time of your symbol file has changed since the last
1875 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1876 table, and reads it again. When it does this, @value{GDBN} tries to retain
1877 your current breakpoints.
1878
1879 @table @code
1880 @kindex start
1881 @item start
1882 @cindex run to main procedure
1883 The name of the main procedure can vary from language to language.
1884 With C or C@t{++}, the main procedure name is always @code{main}, but
1885 other languages such as Ada do not require a specific name for their
1886 main procedure. The debugger provides a convenient way to start the
1887 execution of the program and to stop at the beginning of the main
1888 procedure, depending on the language used.
1889
1890 The @samp{start} command does the equivalent of setting a temporary
1891 breakpoint at the beginning of the main procedure and then invoking
1892 the @samp{run} command.
1893
1894 @cindex elaboration phase
1895 Some programs contain an @dfn{elaboration} phase where some startup code is
1896 executed before the main procedure is called. This depends on the
1897 languages used to write your program. In C@t{++}, for instance,
1898 constructors for static and global objects are executed before
1899 @code{main} is called. It is therefore possible that the debugger stops
1900 before reaching the main procedure. However, the temporary breakpoint
1901 will remain to halt execution.
1902
1903 Specify the arguments to give to your program as arguments to the
1904 @samp{start} command. These arguments will be given verbatim to the
1905 underlying @samp{run} command. Note that the same arguments will be
1906 reused if no argument is provided during subsequent calls to
1907 @samp{start} or @samp{run}.
1908
1909 It is sometimes necessary to debug the program during elaboration. In
1910 these cases, using the @code{start} command would stop the execution of
1911 your program too late, as the program would have already completed the
1912 elaboration phase. Under these circumstances, insert breakpoints in your
1913 elaboration code before running your program.
1914 @end table
1915
1916 @node Arguments
1917 @section Your program's arguments
1918
1919 @cindex arguments (to your program)
1920 The arguments to your program can be specified by the arguments of the
1921 @code{run} command.
1922 They are passed to a shell, which expands wildcard characters and
1923 performs redirection of I/O, and thence to your program. Your
1924 @code{SHELL} environment variable (if it exists) specifies what shell
1925 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1926 the default shell (@file{/bin/sh} on Unix).
1927
1928 On non-Unix systems, the program is usually invoked directly by
1929 @value{GDBN}, which emulates I/O redirection via the appropriate system
1930 calls, and the wildcard characters are expanded by the startup code of
1931 the program, not by the shell.
1932
1933 @code{run} with no arguments uses the same arguments used by the previous
1934 @code{run}, or those set by the @code{set args} command.
1935
1936 @table @code
1937 @kindex set args
1938 @item set args
1939 Specify the arguments to be used the next time your program is run. If
1940 @code{set args} has no arguments, @code{run} executes your program
1941 with no arguments. Once you have run your program with arguments,
1942 using @code{set args} before the next @code{run} is the only way to run
1943 it again without arguments.
1944
1945 @kindex show args
1946 @item show args
1947 Show the arguments to give your program when it is started.
1948 @end table
1949
1950 @node Environment
1951 @section Your program's environment
1952
1953 @cindex environment (of your program)
1954 The @dfn{environment} consists of a set of environment variables and
1955 their values. Environment variables conventionally record such things as
1956 your user name, your home directory, your terminal type, and your search
1957 path for programs to run. Usually you set up environment variables with
1958 the shell and they are inherited by all the other programs you run. When
1959 debugging, it can be useful to try running your program with a modified
1960 environment without having to start @value{GDBN} over again.
1961
1962 @table @code
1963 @kindex path
1964 @item path @var{directory}
1965 Add @var{directory} to the front of the @code{PATH} environment variable
1966 (the search path for executables) that will be passed to your program.
1967 The value of @code{PATH} used by @value{GDBN} does not change.
1968 You may specify several directory names, separated by whitespace or by a
1969 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1970 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1971 is moved to the front, so it is searched sooner.
1972
1973 You can use the string @samp{$cwd} to refer to whatever is the current
1974 working directory at the time @value{GDBN} searches the path. If you
1975 use @samp{.} instead, it refers to the directory where you executed the
1976 @code{path} command. @value{GDBN} replaces @samp{.} in the
1977 @var{directory} argument (with the current path) before adding
1978 @var{directory} to the search path.
1979 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1980 @c document that, since repeating it would be a no-op.
1981
1982 @kindex show paths
1983 @item show paths
1984 Display the list of search paths for executables (the @code{PATH}
1985 environment variable).
1986
1987 @kindex show environment
1988 @item show environment @r{[}@var{varname}@r{]}
1989 Print the value of environment variable @var{varname} to be given to
1990 your program when it starts. If you do not supply @var{varname},
1991 print the names and values of all environment variables to be given to
1992 your program. You can abbreviate @code{environment} as @code{env}.
1993
1994 @kindex set environment
1995 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1996 Set environment variable @var{varname} to @var{value}. The value
1997 changes for your program only, not for @value{GDBN} itself. @var{value} may
1998 be any string; the values of environment variables are just strings, and
1999 any interpretation is supplied by your program itself. The @var{value}
2000 parameter is optional; if it is eliminated, the variable is set to a
2001 null value.
2002 @c "any string" here does not include leading, trailing
2003 @c blanks. Gnu asks: does anyone care?
2004
2005 For example, this command:
2006
2007 @smallexample
2008 set env USER = foo
2009 @end smallexample
2010
2011 @noindent
2012 tells the debugged program, when subsequently run, that its user is named
2013 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2014 are not actually required.)
2015
2016 @kindex unset environment
2017 @item unset environment @var{varname}
2018 Remove variable @var{varname} from the environment to be passed to your
2019 program. This is different from @samp{set env @var{varname} =};
2020 @code{unset environment} removes the variable from the environment,
2021 rather than assigning it an empty value.
2022 @end table
2023
2024 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2025 the shell indicated
2026 by your @code{SHELL} environment variable if it exists (or
2027 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2028 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2029 @file{.bashrc} for BASH---any variables you set in that file affect
2030 your program. You may wish to move setting of environment variables to
2031 files that are only run when you sign on, such as @file{.login} or
2032 @file{.profile}.
2033
2034 @node Working Directory
2035 @section Your program's working directory
2036
2037 @cindex working directory (of your program)
2038 Each time you start your program with @code{run}, it inherits its
2039 working directory from the current working directory of @value{GDBN}.
2040 The @value{GDBN} working directory is initially whatever it inherited
2041 from its parent process (typically the shell), but you can specify a new
2042 working directory in @value{GDBN} with the @code{cd} command.
2043
2044 The @value{GDBN} working directory also serves as a default for the commands
2045 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2046 specify files}.
2047
2048 @table @code
2049 @kindex cd
2050 @cindex change working directory
2051 @item cd @var{directory}
2052 Set the @value{GDBN} working directory to @var{directory}.
2053
2054 @kindex pwd
2055 @item pwd
2056 Print the @value{GDBN} working directory.
2057 @end table
2058
2059 It is generally impossible to find the current working directory of
2060 the process being debugged (since a program can change its directory
2061 during its run). If you work on a system where @value{GDBN} is
2062 configured with the @file{/proc} support, you can use the @code{info
2063 proc} command (@pxref{SVR4 Process Information}) to find out the
2064 current working directory of the debuggee.
2065
2066 @node Input/Output
2067 @section Your program's input and output
2068
2069 @cindex redirection
2070 @cindex i/o
2071 @cindex terminal
2072 By default, the program you run under @value{GDBN} does input and output to
2073 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2074 to its own terminal modes to interact with you, but it records the terminal
2075 modes your program was using and switches back to them when you continue
2076 running your program.
2077
2078 @table @code
2079 @kindex info terminal
2080 @item info terminal
2081 Displays information recorded by @value{GDBN} about the terminal modes your
2082 program is using.
2083 @end table
2084
2085 You can redirect your program's input and/or output using shell
2086 redirection with the @code{run} command. For example,
2087
2088 @smallexample
2089 run > outfile
2090 @end smallexample
2091
2092 @noindent
2093 starts your program, diverting its output to the file @file{outfile}.
2094
2095 @kindex tty
2096 @cindex controlling terminal
2097 Another way to specify where your program should do input and output is
2098 with the @code{tty} command. This command accepts a file name as
2099 argument, and causes this file to be the default for future @code{run}
2100 commands. It also resets the controlling terminal for the child
2101 process, for future @code{run} commands. For example,
2102
2103 @smallexample
2104 tty /dev/ttyb
2105 @end smallexample
2106
2107 @noindent
2108 directs that processes started with subsequent @code{run} commands
2109 default to do input and output on the terminal @file{/dev/ttyb} and have
2110 that as their controlling terminal.
2111
2112 An explicit redirection in @code{run} overrides the @code{tty} command's
2113 effect on the input/output device, but not its effect on the controlling
2114 terminal.
2115
2116 When you use the @code{tty} command or redirect input in the @code{run}
2117 command, only the input @emph{for your program} is affected. The input
2118 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2119 for @code{set inferior-tty}.
2120
2121 @cindex inferior tty
2122 @cindex set inferior controlling terminal
2123 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2124 display the name of the terminal that will be used for future runs of your
2125 program.
2126
2127 @table @code
2128 @item set inferior-tty /dev/ttyb
2129 @kindex set inferior-tty
2130 Set the tty for the program being debugged to /dev/ttyb.
2131
2132 @item show inferior-tty
2133 @kindex show inferior-tty
2134 Show the current tty for the program being debugged.
2135 @end table
2136
2137 @node Attach
2138 @section Debugging an already-running process
2139 @kindex attach
2140 @cindex attach
2141
2142 @table @code
2143 @item attach @var{process-id}
2144 This command attaches to a running process---one that was started
2145 outside @value{GDBN}. (@code{info files} shows your active
2146 targets.) The command takes as argument a process ID. The usual way to
2147 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2148 or with the @samp{jobs -l} shell command.
2149
2150 @code{attach} does not repeat if you press @key{RET} a second time after
2151 executing the command.
2152 @end table
2153
2154 To use @code{attach}, your program must be running in an environment
2155 which supports processes; for example, @code{attach} does not work for
2156 programs on bare-board targets that lack an operating system. You must
2157 also have permission to send the process a signal.
2158
2159 When you use @code{attach}, the debugger finds the program running in
2160 the process first by looking in the current working directory, then (if
2161 the program is not found) by using the source file search path
2162 (@pxref{Source Path, ,Specifying source directories}). You can also use
2163 the @code{file} command to load the program. @xref{Files, ,Commands to
2164 Specify Files}.
2165
2166 The first thing @value{GDBN} does after arranging to debug the specified
2167 process is to stop it. You can examine and modify an attached process
2168 with all the @value{GDBN} commands that are ordinarily available when
2169 you start processes with @code{run}. You can insert breakpoints; you
2170 can step and continue; you can modify storage. If you would rather the
2171 process continue running, you may use the @code{continue} command after
2172 attaching @value{GDBN} to the process.
2173
2174 @table @code
2175 @kindex detach
2176 @item detach
2177 When you have finished debugging the attached process, you can use the
2178 @code{detach} command to release it from @value{GDBN} control. Detaching
2179 the process continues its execution. After the @code{detach} command,
2180 that process and @value{GDBN} become completely independent once more, and you
2181 are ready to @code{attach} another process or start one with @code{run}.
2182 @code{detach} does not repeat if you press @key{RET} again after
2183 executing the command.
2184 @end table
2185
2186 If you exit @value{GDBN} or use the @code{run} command while you have an
2187 attached process, you kill that process. By default, @value{GDBN} asks
2188 for confirmation if you try to do either of these things; you can
2189 control whether or not you need to confirm by using the @code{set
2190 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2191 messages}).
2192
2193 @node Kill Process
2194 @section Killing the child process
2195
2196 @table @code
2197 @kindex kill
2198 @item kill
2199 Kill the child process in which your program is running under @value{GDBN}.
2200 @end table
2201
2202 This command is useful if you wish to debug a core dump instead of a
2203 running process. @value{GDBN} ignores any core dump file while your program
2204 is running.
2205
2206 On some operating systems, a program cannot be executed outside @value{GDBN}
2207 while you have breakpoints set on it inside @value{GDBN}. You can use the
2208 @code{kill} command in this situation to permit running your program
2209 outside the debugger.
2210
2211 The @code{kill} command is also useful if you wish to recompile and
2212 relink your program, since on many systems it is impossible to modify an
2213 executable file while it is running in a process. In this case, when you
2214 next type @code{run}, @value{GDBN} notices that the file has changed, and
2215 reads the symbol table again (while trying to preserve your current
2216 breakpoint settings).
2217
2218 @node Threads
2219 @section Debugging programs with multiple threads
2220
2221 @cindex threads of execution
2222 @cindex multiple threads
2223 @cindex switching threads
2224 In some operating systems, such as HP-UX and Solaris, a single program
2225 may have more than one @dfn{thread} of execution. The precise semantics
2226 of threads differ from one operating system to another, but in general
2227 the threads of a single program are akin to multiple processes---except
2228 that they share one address space (that is, they can all examine and
2229 modify the same variables). On the other hand, each thread has its own
2230 registers and execution stack, and perhaps private memory.
2231
2232 @value{GDBN} provides these facilities for debugging multi-thread
2233 programs:
2234
2235 @itemize @bullet
2236 @item automatic notification of new threads
2237 @item @samp{thread @var{threadno}}, a command to switch among threads
2238 @item @samp{info threads}, a command to inquire about existing threads
2239 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2240 a command to apply a command to a list of threads
2241 @item thread-specific breakpoints
2242 @end itemize
2243
2244 @quotation
2245 @emph{Warning:} These facilities are not yet available on every
2246 @value{GDBN} configuration where the operating system supports threads.
2247 If your @value{GDBN} does not support threads, these commands have no
2248 effect. For example, a system without thread support shows no output
2249 from @samp{info threads}, and always rejects the @code{thread} command,
2250 like this:
2251
2252 @smallexample
2253 (@value{GDBP}) info threads
2254 (@value{GDBP}) thread 1
2255 Thread ID 1 not known. Use the "info threads" command to
2256 see the IDs of currently known threads.
2257 @end smallexample
2258 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2259 @c doesn't support threads"?
2260 @end quotation
2261
2262 @cindex focus of debugging
2263 @cindex current thread
2264 The @value{GDBN} thread debugging facility allows you to observe all
2265 threads while your program runs---but whenever @value{GDBN} takes
2266 control, one thread in particular is always the focus of debugging.
2267 This thread is called the @dfn{current thread}. Debugging commands show
2268 program information from the perspective of the current thread.
2269
2270 @cindex @code{New} @var{systag} message
2271 @cindex thread identifier (system)
2272 @c FIXME-implementors!! It would be more helpful if the [New...] message
2273 @c included GDB's numeric thread handle, so you could just go to that
2274 @c thread without first checking `info threads'.
2275 Whenever @value{GDBN} detects a new thread in your program, it displays
2276 the target system's identification for the thread with a message in the
2277 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2278 whose form varies depending on the particular system. For example, on
2279 LynxOS, you might see
2280
2281 @smallexample
2282 [New process 35 thread 27]
2283 @end smallexample
2284
2285 @noindent
2286 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2287 the @var{systag} is simply something like @samp{process 368}, with no
2288 further qualifier.
2289
2290 @c FIXME!! (1) Does the [New...] message appear even for the very first
2291 @c thread of a program, or does it only appear for the
2292 @c second---i.e.@: when it becomes obvious we have a multithread
2293 @c program?
2294 @c (2) *Is* there necessarily a first thread always? Or do some
2295 @c multithread systems permit starting a program with multiple
2296 @c threads ab initio?
2297
2298 @cindex thread number
2299 @cindex thread identifier (GDB)
2300 For debugging purposes, @value{GDBN} associates its own thread
2301 number---always a single integer---with each thread in your program.
2302
2303 @table @code
2304 @kindex info threads
2305 @item info threads
2306 Display a summary of all threads currently in your
2307 program. @value{GDBN} displays for each thread (in this order):
2308
2309 @enumerate
2310 @item
2311 the thread number assigned by @value{GDBN}
2312
2313 @item
2314 the target system's thread identifier (@var{systag})
2315
2316 @item
2317 the current stack frame summary for that thread
2318 @end enumerate
2319
2320 @noindent
2321 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2322 indicates the current thread.
2323
2324 For example,
2325 @end table
2326 @c end table here to get a little more width for example
2327
2328 @smallexample
2329 (@value{GDBP}) info threads
2330 3 process 35 thread 27 0x34e5 in sigpause ()
2331 2 process 35 thread 23 0x34e5 in sigpause ()
2332 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2333 at threadtest.c:68
2334 @end smallexample
2335
2336 On HP-UX systems:
2337
2338 @cindex debugging multithreaded programs (on HP-UX)
2339 @cindex thread identifier (GDB), on HP-UX
2340 For debugging purposes, @value{GDBN} associates its own thread
2341 number---a small integer assigned in thread-creation order---with each
2342 thread in your program.
2343
2344 @cindex @code{New} @var{systag} message, on HP-UX
2345 @cindex thread identifier (system), on HP-UX
2346 @c FIXME-implementors!! It would be more helpful if the [New...] message
2347 @c included GDB's numeric thread handle, so you could just go to that
2348 @c thread without first checking `info threads'.
2349 Whenever @value{GDBN} detects a new thread in your program, it displays
2350 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2351 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2352 whose form varies depending on the particular system. For example, on
2353 HP-UX, you see
2354
2355 @smallexample
2356 [New thread 2 (system thread 26594)]
2357 @end smallexample
2358
2359 @noindent
2360 when @value{GDBN} notices a new thread.
2361
2362 @table @code
2363 @kindex info threads (HP-UX)
2364 @item info threads
2365 Display a summary of all threads currently in your
2366 program. @value{GDBN} displays for each thread (in this order):
2367
2368 @enumerate
2369 @item the thread number assigned by @value{GDBN}
2370
2371 @item the target system's thread identifier (@var{systag})
2372
2373 @item the current stack frame summary for that thread
2374 @end enumerate
2375
2376 @noindent
2377 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2378 indicates the current thread.
2379
2380 For example,
2381 @end table
2382 @c end table here to get a little more width for example
2383
2384 @smallexample
2385 (@value{GDBP}) info threads
2386 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2387 at quicksort.c:137
2388 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2389 from /usr/lib/libc.2
2390 1 system thread 27905 0x7b003498 in _brk () \@*
2391 from /usr/lib/libc.2
2392 @end smallexample
2393
2394 On Solaris, you can display more information about user threads with a
2395 Solaris-specific command:
2396
2397 @table @code
2398 @item maint info sol-threads
2399 @kindex maint info sol-threads
2400 @cindex thread info (Solaris)
2401 Display info on Solaris user threads.
2402 @end table
2403
2404 @table @code
2405 @kindex thread @var{threadno}
2406 @item thread @var{threadno}
2407 Make thread number @var{threadno} the current thread. The command
2408 argument @var{threadno} is the internal @value{GDBN} thread number, as
2409 shown in the first field of the @samp{info threads} display.
2410 @value{GDBN} responds by displaying the system identifier of the thread
2411 you selected, and its current stack frame summary:
2412
2413 @smallexample
2414 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2415 (@value{GDBP}) thread 2
2416 [Switching to process 35 thread 23]
2417 0x34e5 in sigpause ()
2418 @end smallexample
2419
2420 @noindent
2421 As with the @samp{[New @dots{}]} message, the form of the text after
2422 @samp{Switching to} depends on your system's conventions for identifying
2423 threads.
2424
2425 @kindex thread apply
2426 @cindex apply command to several threads
2427 @item thread apply [@var{threadno}] [@var{all}] @var{args}
2428 The @code{thread apply} command allows you to apply a command to one or
2429 more threads. Specify the numbers of the threads that you want affected
2430 with the command argument @var{threadno}. @var{threadno} is the internal
2431 @value{GDBN} thread number, as shown in the first field of the @samp{info
2432 threads} display. To apply a command to all threads, use
2433 @code{thread apply all} @var{args}.
2434 @end table
2435
2436 @cindex automatic thread selection
2437 @cindex switching threads automatically
2438 @cindex threads, automatic switching
2439 Whenever @value{GDBN} stops your program, due to a breakpoint or a
2440 signal, it automatically selects the thread where that breakpoint or
2441 signal happened. @value{GDBN} alerts you to the context switch with a
2442 message of the form @samp{[Switching to @var{systag}]} to identify the
2443 thread.
2444
2445 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2446 more information about how @value{GDBN} behaves when you stop and start
2447 programs with multiple threads.
2448
2449 @xref{Set Watchpoints,,Setting watchpoints}, for information about
2450 watchpoints in programs with multiple threads.
2451
2452 @node Processes
2453 @section Debugging programs with multiple processes
2454
2455 @cindex fork, debugging programs which call
2456 @cindex multiple processes
2457 @cindex processes, multiple
2458 On most systems, @value{GDBN} has no special support for debugging
2459 programs which create additional processes using the @code{fork}
2460 function. When a program forks, @value{GDBN} will continue to debug the
2461 parent process and the child process will run unimpeded. If you have
2462 set a breakpoint in any code which the child then executes, the child
2463 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2464 will cause it to terminate.
2465
2466 However, if you want to debug the child process there is a workaround
2467 which isn't too painful. Put a call to @code{sleep} in the code which
2468 the child process executes after the fork. It may be useful to sleep
2469 only if a certain environment variable is set, or a certain file exists,
2470 so that the delay need not occur when you don't want to run @value{GDBN}
2471 on the child. While the child is sleeping, use the @code{ps} program to
2472 get its process ID. Then tell @value{GDBN} (a new invocation of
2473 @value{GDBN} if you are also debugging the parent process) to attach to
2474 the child process (@pxref{Attach}). From that point on you can debug
2475 the child process just like any other process which you attached to.
2476
2477 On some systems, @value{GDBN} provides support for debugging programs that
2478 create additional processes using the @code{fork} or @code{vfork} functions.
2479 Currently, the only platforms with this feature are HP-UX (11.x and later
2480 only?) and GNU/Linux (kernel version 2.5.60 and later).
2481
2482 By default, when a program forks, @value{GDBN} will continue to debug
2483 the parent process and the child process will run unimpeded.
2484
2485 If you want to follow the child process instead of the parent process,
2486 use the command @w{@code{set follow-fork-mode}}.
2487
2488 @table @code
2489 @kindex set follow-fork-mode
2490 @item set follow-fork-mode @var{mode}
2491 Set the debugger response to a program call of @code{fork} or
2492 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2493 process. The @var{mode} argument can be:
2494
2495 @table @code
2496 @item parent
2497 The original process is debugged after a fork. The child process runs
2498 unimpeded. This is the default.
2499
2500 @item child
2501 The new process is debugged after a fork. The parent process runs
2502 unimpeded.
2503
2504 @end table
2505
2506 @kindex show follow-fork-mode
2507 @item show follow-fork-mode
2508 Display the current debugger response to a @code{fork} or @code{vfork} call.
2509 @end table
2510
2511 @cindex debugging multiple processes
2512 On Linux, if you want to debug both the parent and child processes, use the
2513 command @w{@code{set detach-on-fork}}.
2514
2515 @table @code
2516 @kindex set detach-on-fork
2517 @item set detach-on-fork @var{mode}
2518 Tells gdb whether to detach one of the processes after a fork, or
2519 retain debugger control over them both.
2520
2521 @table @code
2522 @item on
2523 The child process (or parent process, depending on the value of
2524 @code{follow-fork-mode}) will be detached and allowed to run
2525 independently. This is the default.
2526
2527 @item off
2528 Both processes will be held under the control of @value{GDBN}.
2529 One process (child or parent, depending on the value of
2530 @code{follow-fork-mode}) is debugged as usual, while the other
2531 is held suspended.
2532
2533 @end table
2534
2535 @kindex show detach-on-follow
2536 @item show detach-on-follow
2537 Show whether detach-on-follow mode is on/off.
2538 @end table
2539
2540 If you choose to set @var{detach-on-follow} mode off, then
2541 @value{GDBN} will retain control of all forked processes (including
2542 nested forks). You can list the forked processes under the control of
2543 @value{GDBN} by using the @w{@code{info forks}} command, and switch
2544 from one fork to another by using the @w{@code{fork}} command.
2545
2546 @table @code
2547 @kindex info forks
2548 @item info forks
2549 Print a list of all forked processes under the control of @value{GDBN}.
2550 The listing will include a fork id, a process id, and the current
2551 position (program counter) of the process.
2552
2553
2554 @kindex fork @var{fork-id}
2555 @item fork @var{fork-id}
2556 Make fork number @var{fork-id} the current process. The argument
2557 @var{fork-id} is the internal fork number assigned by @value{GDBN},
2558 as shown in the first field of the @samp{info forks} display.
2559
2560 @end table
2561
2562 To quit debugging one of the forked processes, you can either detach
2563 from it by using the @w{@code{detach-fork}} command (allowing it to
2564 run independently), or delete (and kill) it using the
2565 @w{@code{delete-fork}} command.
2566
2567 @table @code
2568 @kindex detach-fork @var{fork-id}
2569 @item detach-fork @var{fork-id}
2570 Detach from the process identified by @value{GDBN} fork number
2571 @var{fork-id}, and remove it from the fork list. The process will be
2572 allowed to run independently.
2573
2574 @kindex delete-fork @var{fork-id}
2575 @item delete-fork @var{fork-id}
2576 Kill the process identified by @value{GDBN} fork number @var{fork-id},
2577 and remove it from the fork list.
2578
2579 @end table
2580
2581 If you ask to debug a child process and a @code{vfork} is followed by an
2582 @code{exec}, @value{GDBN} executes the new target up to the first
2583 breakpoint in the new target. If you have a breakpoint set on
2584 @code{main} in your original program, the breakpoint will also be set on
2585 the child process's @code{main}.
2586
2587 When a child process is spawned by @code{vfork}, you cannot debug the
2588 child or parent until an @code{exec} call completes.
2589
2590 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2591 call executes, the new target restarts. To restart the parent process,
2592 use the @code{file} command with the parent executable name as its
2593 argument.
2594
2595 You can use the @code{catch} command to make @value{GDBN} stop whenever
2596 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2597 Catchpoints, ,Setting catchpoints}.
2598
2599 @node Checkpoint/Restart
2600 @section Setting a @emph{bookmark} to return to later
2601
2602 @cindex checkpoint
2603 @cindex restart
2604 @cindex bookmark
2605 @cindex snapshot of a process
2606 @cindex rewind program state
2607
2608 On certain operating systems@footnote{Currently, only
2609 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2610 program's state, called a @dfn{checkpoint}, and come back to it
2611 later.
2612
2613 Returning to a checkpoint effectively undoes everything that has
2614 happened in the program since the @code{checkpoint} was saved. This
2615 includes changes in memory, registers, and even (within some limits)
2616 system state. Effectively, it is like going back in time to the
2617 moment when the checkpoint was saved.
2618
2619 Thus, if you're stepping thru a program and you think you're
2620 getting close to the point where things go wrong, you can save
2621 a checkpoint. Then, if you accidentally go too far and miss
2622 the critical statement, instead of having to restart your program
2623 from the beginning, you can just go back to the checkpoint and
2624 start again from there.
2625
2626 This can be especially useful if it takes a lot of time or
2627 steps to reach the point where you think the bug occurs.
2628
2629 To use the @code{checkpoint}/@code{restart} method of debugging:
2630
2631 @table @code
2632 @kindex checkpoint
2633 @item checkpoint
2634 Save a snapshot of the debugged program's current execution state.
2635 The @code{checkpoint} command takes no arguments, but each checkpoint
2636 is assigned a small integer id, similar to a breakpoint id.
2637
2638 @kindex info checkpoints
2639 @item info checkpoints
2640 List the checkpoints that have been saved in the current debugging
2641 session. For each checkpoint, the following information will be
2642 listed:
2643
2644 @table @code
2645 @item Checkpoint ID
2646 @item Process ID
2647 @item Code Address
2648 @item Source line, or label
2649 @end table
2650
2651 @kindex restart @var{checkpoint-id}
2652 @item restart @var{checkpoint-id}
2653 Restore the program state that was saved as checkpoint number
2654 @var{checkpoint-id}. All program variables, registers, stack frames
2655 etc.@: will be returned to the values that they had when the checkpoint
2656 was saved. In essence, gdb will ``wind back the clock'' to the point
2657 in time when the checkpoint was saved.
2658
2659 Note that breakpoints, @value{GDBN} variables, command history etc.
2660 are not affected by restoring a checkpoint. In general, a checkpoint
2661 only restores things that reside in the program being debugged, not in
2662 the debugger.
2663
2664 @kindex delete-checkpoint @var{checkpoint-id}
2665 @item delete-checkpoint @var{checkpoint-id}
2666 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2667
2668 @end table
2669
2670 Returning to a previously saved checkpoint will restore the user state
2671 of the program being debugged, plus a significant subset of the system
2672 (OS) state, including file pointers. It won't ``un-write'' data from
2673 a file, but it will rewind the file pointer to the previous location,
2674 so that the previously written data can be overwritten. For files
2675 opened in read mode, the pointer will also be restored so that the
2676 previously read data can be read again.
2677
2678 Of course, characters that have been sent to a printer (or other
2679 external device) cannot be ``snatched back'', and characters received
2680 from eg.@: a serial device can be removed from internal program buffers,
2681 but they cannot be ``pushed back'' into the serial pipeline, ready to
2682 be received again. Similarly, the actual contents of files that have
2683 been changed cannot be restored (at this time).
2684
2685 However, within those constraints, you actually can ``rewind'' your
2686 program to a previously saved point in time, and begin debugging it
2687 again --- and you can change the course of events so as to debug a
2688 different execution path this time.
2689
2690 @cindex checkpoints and process id
2691 Finally, there is one bit of internal program state that will be
2692 different when you return to a checkpoint --- the program's process
2693 id. Each checkpoint will have a unique process id (or @var{pid}),
2694 and each will be different from the program's original @var{pid}.
2695 If your program has saved a local copy of its process id, this could
2696 potentially pose a problem.
2697
2698 @subsection A non-obvious benefit of using checkpoints
2699
2700 On some systems such as @sc{gnu}/Linux, address space randomization
2701 is performed on new processes for security reasons. This makes it
2702 difficult or impossible to set a breakpoint, or watchpoint, on an
2703 absolute address if you have to restart the program, since the
2704 absolute location of a symbol will change from one execution to the
2705 next.
2706
2707 A checkpoint, however, is an @emph{identical} copy of a process.
2708 Therefore if you create a checkpoint at (eg.@:) the start of main,
2709 and simply return to that checkpoint instead of restarting the
2710 process, you can avoid the effects of address randomization and
2711 your symbols will all stay in the same place.
2712
2713 @node Stopping
2714 @chapter Stopping and Continuing
2715
2716 The principal purposes of using a debugger are so that you can stop your
2717 program before it terminates; or so that, if your program runs into
2718 trouble, you can investigate and find out why.
2719
2720 Inside @value{GDBN}, your program may stop for any of several reasons,
2721 such as a signal, a breakpoint, or reaching a new line after a
2722 @value{GDBN} command such as @code{step}. You may then examine and
2723 change variables, set new breakpoints or remove old ones, and then
2724 continue execution. Usually, the messages shown by @value{GDBN} provide
2725 ample explanation of the status of your program---but you can also
2726 explicitly request this information at any time.
2727
2728 @table @code
2729 @kindex info program
2730 @item info program
2731 Display information about the status of your program: whether it is
2732 running or not, what process it is, and why it stopped.
2733 @end table
2734
2735 @menu
2736 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2737 * Continuing and Stepping:: Resuming execution
2738 * Signals:: Signals
2739 * Thread Stops:: Stopping and starting multi-thread programs
2740 @end menu
2741
2742 @node Breakpoints
2743 @section Breakpoints, watchpoints, and catchpoints
2744
2745 @cindex breakpoints
2746 A @dfn{breakpoint} makes your program stop whenever a certain point in
2747 the program is reached. For each breakpoint, you can add conditions to
2748 control in finer detail whether your program stops. You can set
2749 breakpoints with the @code{break} command and its variants (@pxref{Set
2750 Breaks, ,Setting breakpoints}), to specify the place where your program
2751 should stop by line number, function name or exact address in the
2752 program.
2753
2754 On some systems, you can set breakpoints in shared libraries before
2755 the executable is run. There is a minor limitation on HP-UX systems:
2756 you must wait until the executable is run in order to set breakpoints
2757 in shared library routines that are not called directly by the program
2758 (for example, routines that are arguments in a @code{pthread_create}
2759 call).
2760
2761 @cindex watchpoints
2762 @cindex memory tracing
2763 @cindex breakpoint on memory address
2764 @cindex breakpoint on variable modification
2765 A @dfn{watchpoint} is a special breakpoint that stops your program
2766 when the value of an expression changes. You must use a different
2767 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2768 watchpoints}), but aside from that, you can manage a watchpoint like
2769 any other breakpoint: you enable, disable, and delete both breakpoints
2770 and watchpoints using the same commands.
2771
2772 You can arrange to have values from your program displayed automatically
2773 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2774 Automatic display}.
2775
2776 @cindex catchpoints
2777 @cindex breakpoint on events
2778 A @dfn{catchpoint} is another special breakpoint that stops your program
2779 when a certain kind of event occurs, such as the throwing of a C@t{++}
2780 exception or the loading of a library. As with watchpoints, you use a
2781 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2782 catchpoints}), but aside from that, you can manage a catchpoint like any
2783 other breakpoint. (To stop when your program receives a signal, use the
2784 @code{handle} command; see @ref{Signals, ,Signals}.)
2785
2786 @cindex breakpoint numbers
2787 @cindex numbers for breakpoints
2788 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2789 catchpoint when you create it; these numbers are successive integers
2790 starting with one. In many of the commands for controlling various
2791 features of breakpoints you use the breakpoint number to say which
2792 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2793 @dfn{disabled}; if disabled, it has no effect on your program until you
2794 enable it again.
2795
2796 @cindex breakpoint ranges
2797 @cindex ranges of breakpoints
2798 Some @value{GDBN} commands accept a range of breakpoints on which to
2799 operate. A breakpoint range is either a single breakpoint number, like
2800 @samp{5}, or two such numbers, in increasing order, separated by a
2801 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2802 all breakpoint in that range are operated on.
2803
2804 @menu
2805 * Set Breaks:: Setting breakpoints
2806 * Set Watchpoints:: Setting watchpoints
2807 * Set Catchpoints:: Setting catchpoints
2808 * Delete Breaks:: Deleting breakpoints
2809 * Disabling:: Disabling breakpoints
2810 * Conditions:: Break conditions
2811 * Break Commands:: Breakpoint command lists
2812 * Breakpoint Menus:: Breakpoint menus
2813 * Error in Breakpoints:: ``Cannot insert breakpoints''
2814 * Breakpoint related warnings:: ``Breakpoint address adjusted...''
2815 @end menu
2816
2817 @node Set Breaks
2818 @subsection Setting breakpoints
2819
2820 @c FIXME LMB what does GDB do if no code on line of breakpt?
2821 @c consider in particular declaration with/without initialization.
2822 @c
2823 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2824
2825 @kindex break
2826 @kindex b @r{(@code{break})}
2827 @vindex $bpnum@r{, convenience variable}
2828 @cindex latest breakpoint
2829 Breakpoints are set with the @code{break} command (abbreviated
2830 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2831 number of the breakpoint you've set most recently; see @ref{Convenience
2832 Vars,, Convenience variables}, for a discussion of what you can do with
2833 convenience variables.
2834
2835 You have several ways to say where the breakpoint should go.
2836
2837 @table @code
2838 @item break @var{function}
2839 Set a breakpoint at entry to function @var{function}.
2840 When using source languages that permit overloading of symbols, such as
2841 C@t{++}, @var{function} may refer to more than one possible place to break.
2842 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2843
2844 @item break +@var{offset}
2845 @itemx break -@var{offset}
2846 Set a breakpoint some number of lines forward or back from the position
2847 at which execution stopped in the currently selected @dfn{stack frame}.
2848 (@xref{Frames, ,Frames}, for a description of stack frames.)
2849
2850 @item break @var{linenum}
2851 Set a breakpoint at line @var{linenum} in the current source file.
2852 The current source file is the last file whose source text was printed.
2853 The breakpoint will stop your program just before it executes any of the
2854 code on that line.
2855
2856 @item break @var{filename}:@var{linenum}
2857 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2858
2859 @item break @var{filename}:@var{function}
2860 Set a breakpoint at entry to function @var{function} found in file
2861 @var{filename}. Specifying a file name as well as a function name is
2862 superfluous except when multiple files contain similarly named
2863 functions.
2864
2865 @item break *@var{address}
2866 Set a breakpoint at address @var{address}. You can use this to set
2867 breakpoints in parts of your program which do not have debugging
2868 information or source files.
2869
2870 @item break
2871 When called without any arguments, @code{break} sets a breakpoint at
2872 the next instruction to be executed in the selected stack frame
2873 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2874 innermost, this makes your program stop as soon as control
2875 returns to that frame. This is similar to the effect of a
2876 @code{finish} command in the frame inside the selected frame---except
2877 that @code{finish} does not leave an active breakpoint. If you use
2878 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2879 the next time it reaches the current location; this may be useful
2880 inside loops.
2881
2882 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2883 least one instruction has been executed. If it did not do this, you
2884 would be unable to proceed past a breakpoint without first disabling the
2885 breakpoint. This rule applies whether or not the breakpoint already
2886 existed when your program stopped.
2887
2888 @item break @dots{} if @var{cond}
2889 Set a breakpoint with condition @var{cond}; evaluate the expression
2890 @var{cond} each time the breakpoint is reached, and stop only if the
2891 value is nonzero---that is, if @var{cond} evaluates as true.
2892 @samp{@dots{}} stands for one of the possible arguments described
2893 above (or no argument) specifying where to break. @xref{Conditions,
2894 ,Break conditions}, for more information on breakpoint conditions.
2895
2896 @kindex tbreak
2897 @item tbreak @var{args}
2898 Set a breakpoint enabled only for one stop. @var{args} are the
2899 same as for the @code{break} command, and the breakpoint is set in the same
2900 way, but the breakpoint is automatically deleted after the first time your
2901 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2902
2903 @kindex hbreak
2904 @cindex hardware breakpoints
2905 @item hbreak @var{args}
2906 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2907 @code{break} command and the breakpoint is set in the same way, but the
2908 breakpoint requires hardware support and some target hardware may not
2909 have this support. The main purpose of this is EPROM/ROM code
2910 debugging, so you can set a breakpoint at an instruction without
2911 changing the instruction. This can be used with the new trap-generation
2912 provided by SPARClite DSU and most x86-based targets. These targets
2913 will generate traps when a program accesses some data or instruction
2914 address that is assigned to the debug registers. However the hardware
2915 breakpoint registers can take a limited number of breakpoints. For
2916 example, on the DSU, only two data breakpoints can be set at a time, and
2917 @value{GDBN} will reject this command if more than two are used. Delete
2918 or disable unused hardware breakpoints before setting new ones
2919 (@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
2920 For remote targets, you can restrict the number of hardware
2921 breakpoints @value{GDBN} will use, see @ref{set remote
2922 hardware-breakpoint-limit}.
2923
2924
2925 @kindex thbreak
2926 @item thbreak @var{args}
2927 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2928 are the same as for the @code{hbreak} command and the breakpoint is set in
2929 the same way. However, like the @code{tbreak} command,
2930 the breakpoint is automatically deleted after the
2931 first time your program stops there. Also, like the @code{hbreak}
2932 command, the breakpoint requires hardware support and some target hardware
2933 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2934 See also @ref{Conditions, ,Break conditions}.
2935
2936 @kindex rbreak
2937 @cindex regular expression
2938 @cindex breakpoints in functions matching a regexp
2939 @cindex set breakpoints in many functions
2940 @item rbreak @var{regex}
2941 Set breakpoints on all functions matching the regular expression
2942 @var{regex}. This command sets an unconditional breakpoint on all
2943 matches, printing a list of all breakpoints it set. Once these
2944 breakpoints are set, they are treated just like the breakpoints set with
2945 the @code{break} command. You can delete them, disable them, or make
2946 them conditional the same way as any other breakpoint.
2947
2948 The syntax of the regular expression is the standard one used with tools
2949 like @file{grep}. Note that this is different from the syntax used by
2950 shells, so for instance @code{foo*} matches all functions that include
2951 an @code{fo} followed by zero or more @code{o}s. There is an implicit
2952 @code{.*} leading and trailing the regular expression you supply, so to
2953 match only functions that begin with @code{foo}, use @code{^foo}.
2954
2955 @cindex non-member C@t{++} functions, set breakpoint in
2956 When debugging C@t{++} programs, @code{rbreak} is useful for setting
2957 breakpoints on overloaded functions that are not members of any special
2958 classes.
2959
2960 @cindex set breakpoints on all functions
2961 The @code{rbreak} command can be used to set breakpoints in
2962 @strong{all} the functions in a program, like this:
2963
2964 @smallexample
2965 (@value{GDBP}) rbreak .
2966 @end smallexample
2967
2968 @kindex info breakpoints
2969 @cindex @code{$_} and @code{info breakpoints}
2970 @item info breakpoints @r{[}@var{n}@r{]}
2971 @itemx info break @r{[}@var{n}@r{]}
2972 @itemx info watchpoints @r{[}@var{n}@r{]}
2973 Print a table of all breakpoints, watchpoints, and catchpoints set and
2974 not deleted, with the following columns for each breakpoint:
2975
2976 @table @emph
2977 @item Breakpoint Numbers
2978 @item Type
2979 Breakpoint, watchpoint, or catchpoint.
2980 @item Disposition
2981 Whether the breakpoint is marked to be disabled or deleted when hit.
2982 @item Enabled or Disabled
2983 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2984 that are not enabled.
2985 @item Address
2986 Where the breakpoint is in your program, as a memory address. If the
2987 breakpoint is pending (see below for details) on a future load of a shared library, the address
2988 will be listed as @samp{<PENDING>}.
2989 @item What
2990 Where the breakpoint is in the source for your program, as a file and
2991 line number. For a pending breakpoint, the original string passed to
2992 the breakpoint command will be listed as it cannot be resolved until
2993 the appropriate shared library is loaded in the future.
2994 @end table
2995
2996 @noindent
2997 If a breakpoint is conditional, @code{info break} shows the condition on
2998 the line following the affected breakpoint; breakpoint commands, if any,
2999 are listed after that. A pending breakpoint is allowed to have a condition
3000 specified for it. The condition is not parsed for validity until a shared
3001 library is loaded that allows the pending breakpoint to resolve to a
3002 valid location.
3003
3004 @noindent
3005 @code{info break} with a breakpoint
3006 number @var{n} as argument lists only that breakpoint. The
3007 convenience variable @code{$_} and the default examining-address for
3008 the @code{x} command are set to the address of the last breakpoint
3009 listed (@pxref{Memory, ,Examining memory}).
3010
3011 @noindent
3012 @code{info break} displays a count of the number of times the breakpoint
3013 has been hit. This is especially useful in conjunction with the
3014 @code{ignore} command. You can ignore a large number of breakpoint
3015 hits, look at the breakpoint info to see how many times the breakpoint
3016 was hit, and then run again, ignoring one less than that number. This
3017 will get you quickly to the last hit of that breakpoint.
3018 @end table
3019
3020 @value{GDBN} allows you to set any number of breakpoints at the same place in
3021 your program. There is nothing silly or meaningless about this. When
3022 the breakpoints are conditional, this is even useful
3023 (@pxref{Conditions, ,Break conditions}).
3024
3025 @cindex pending breakpoints
3026 If a specified breakpoint location cannot be found, it may be due to the fact
3027 that the location is in a shared library that is yet to be loaded. In such
3028 a case, you may want @value{GDBN} to create a special breakpoint (known as
3029 a @dfn{pending breakpoint}) that
3030 attempts to resolve itself in the future when an appropriate shared library
3031 gets loaded.
3032
3033 Pending breakpoints are useful to set at the start of your
3034 @value{GDBN} session for locations that you know will be dynamically loaded
3035 later by the program being debugged. When shared libraries are loaded,
3036 a check is made to see if the load resolves any pending breakpoint locations.
3037 If a pending breakpoint location gets resolved,
3038 a regular breakpoint is created and the original pending breakpoint is removed.
3039
3040 @value{GDBN} provides some additional commands for controlling pending
3041 breakpoint support:
3042
3043 @kindex set breakpoint pending
3044 @kindex show breakpoint pending
3045 @table @code
3046 @item set breakpoint pending auto
3047 This is the default behavior. When @value{GDBN} cannot find the breakpoint
3048 location, it queries you whether a pending breakpoint should be created.
3049
3050 @item set breakpoint pending on
3051 This indicates that an unrecognized breakpoint location should automatically
3052 result in a pending breakpoint being created.
3053
3054 @item set breakpoint pending off
3055 This indicates that pending breakpoints are not to be created. Any
3056 unrecognized breakpoint location results in an error. This setting does
3057 not affect any pending breakpoints previously created.
3058
3059 @item show breakpoint pending
3060 Show the current behavior setting for creating pending breakpoints.
3061 @end table
3062
3063 @cindex operations allowed on pending breakpoints
3064 Normal breakpoint operations apply to pending breakpoints as well. You may
3065 specify a condition for a pending breakpoint and/or commands to run when the
3066 breakpoint is reached. You can also enable or disable
3067 the pending breakpoint. When you specify a condition for a pending breakpoint,
3068 the parsing of the condition will be deferred until the point where the
3069 pending breakpoint location is resolved. Disabling a pending breakpoint
3070 tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
3071 shared library load. When a pending breakpoint is re-enabled,
3072 @value{GDBN} checks to see if the location is already resolved.
3073 This is done because any number of shared library loads could have
3074 occurred since the time the breakpoint was disabled and one or more
3075 of these loads could resolve the location.
3076
3077 @cindex negative breakpoint numbers
3078 @cindex internal @value{GDBN} breakpoints
3079 @value{GDBN} itself sometimes sets breakpoints in your program for
3080 special purposes, such as proper handling of @code{longjmp} (in C
3081 programs). These internal breakpoints are assigned negative numbers,
3082 starting with @code{-1}; @samp{info breakpoints} does not display them.
3083 You can see these breakpoints with the @value{GDBN} maintenance command
3084 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3085
3086
3087 @node Set Watchpoints
3088 @subsection Setting watchpoints
3089
3090 @cindex setting watchpoints
3091 You can use a watchpoint to stop execution whenever the value of an
3092 expression changes, without having to predict a particular place where
3093 this may happen.
3094
3095 @cindex software watchpoints
3096 @cindex hardware watchpoints
3097 Depending on your system, watchpoints may be implemented in software or
3098 hardware. @value{GDBN} does software watchpointing by single-stepping your
3099 program and testing the variable's value each time, which is hundreds of
3100 times slower than normal execution. (But this may still be worth it, to
3101 catch errors where you have no clue what part of your program is the
3102 culprit.)
3103
3104 On some systems, such as HP-UX, @sc{gnu}/Linux and most other
3105 x86-based targets, @value{GDBN} includes support for hardware
3106 watchpoints, which do not slow down the running of your program.
3107
3108 @table @code
3109 @kindex watch
3110 @item watch @var{expr}
3111 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
3112 is written into by the program and its value changes.
3113
3114 @kindex rwatch
3115 @item rwatch @var{expr}
3116 Set a watchpoint that will break when the value of @var{expr} is read
3117 by the program.
3118
3119 @kindex awatch
3120 @item awatch @var{expr}
3121 Set a watchpoint that will break when @var{expr} is either read from
3122 or written into by the program.
3123
3124 @kindex info watchpoints
3125 @item info watchpoints
3126 This command prints a list of watchpoints, breakpoints, and catchpoints;
3127 it is the same as @code{info break} (@pxref{Set Breaks}).
3128 @end table
3129
3130 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3131 watchpoints execute very quickly, and the debugger reports a change in
3132 value at the exact instruction where the change occurs. If @value{GDBN}
3133 cannot set a hardware watchpoint, it sets a software watchpoint, which
3134 executes more slowly and reports the change in value at the next
3135 @emph{statement}, not the instruction, after the change occurs.
3136
3137 @cindex use only software watchpoints
3138 You can force @value{GDBN} to use only software watchpoints with the
3139 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3140 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3141 the underlying system supports them. (Note that hardware-assisted
3142 watchpoints that were set @emph{before} setting
3143 @code{can-use-hw-watchpoints} to zero will still use the hardware
3144 mechanism of watching expressiion values.)
3145
3146 @table @code
3147 @item set can-use-hw-watchpoints
3148 @kindex set can-use-hw-watchpoints
3149 Set whether or not to use hardware watchpoints.
3150
3151 @item show can-use-hw-watchpoints
3152 @kindex show can-use-hw-watchpoints
3153 Show the current mode of using hardware watchpoints.
3154 @end table
3155
3156 For remote targets, you can restrict the number of hardware
3157 watchpoints @value{GDBN} will use, see @ref{set remote
3158 hardware-breakpoint-limit}.
3159
3160 When you issue the @code{watch} command, @value{GDBN} reports
3161
3162 @smallexample
3163 Hardware watchpoint @var{num}: @var{expr}
3164 @end smallexample
3165
3166 @noindent
3167 if it was able to set a hardware watchpoint.
3168
3169 Currently, the @code{awatch} and @code{rwatch} commands can only set
3170 hardware watchpoints, because accesses to data that don't change the
3171 value of the watched expression cannot be detected without examining
3172 every instruction as it is being executed, and @value{GDBN} does not do
3173 that currently. If @value{GDBN} finds that it is unable to set a
3174 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3175 will print a message like this:
3176
3177 @smallexample
3178 Expression cannot be implemented with read/access watchpoint.
3179 @end smallexample
3180
3181 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3182 data type of the watched expression is wider than what a hardware
3183 watchpoint on the target machine can handle. For example, some systems
3184 can only watch regions that are up to 4 bytes wide; on such systems you
3185 cannot set hardware watchpoints for an expression that yields a
3186 double-precision floating-point number (which is typically 8 bytes
3187 wide). As a work-around, it might be possible to break the large region
3188 into a series of smaller ones and watch them with separate watchpoints.
3189
3190 If you set too many hardware watchpoints, @value{GDBN} might be unable
3191 to insert all of them when you resume the execution of your program.
3192 Since the precise number of active watchpoints is unknown until such
3193 time as the program is about to be resumed, @value{GDBN} might not be
3194 able to warn you about this when you set the watchpoints, and the
3195 warning will be printed only when the program is resumed:
3196
3197 @smallexample
3198 Hardware watchpoint @var{num}: Could not insert watchpoint
3199 @end smallexample
3200
3201 @noindent
3202 If this happens, delete or disable some of the watchpoints.
3203
3204 The SPARClite DSU will generate traps when a program accesses some data
3205 or instruction address that is assigned to the debug registers. For the
3206 data addresses, DSU facilitates the @code{watch} command. However the
3207 hardware breakpoint registers can only take two data watchpoints, and
3208 both watchpoints must be the same kind. For example, you can set two
3209 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3210 @strong{or} two with @code{awatch} commands, but you cannot set one
3211 watchpoint with one command and the other with a different command.
3212 @value{GDBN} will reject the command if you try to mix watchpoints.
3213 Delete or disable unused watchpoint commands before setting new ones.
3214
3215 If you call a function interactively using @code{print} or @code{call},
3216 any watchpoints you have set will be inactive until @value{GDBN} reaches another
3217 kind of breakpoint or the call completes.
3218
3219 @value{GDBN} automatically deletes watchpoints that watch local
3220 (automatic) variables, or expressions that involve such variables, when
3221 they go out of scope, that is, when the execution leaves the block in
3222 which these variables were defined. In particular, when the program
3223 being debugged terminates, @emph{all} local variables go out of scope,
3224 and so only watchpoints that watch global variables remain set. If you
3225 rerun the program, you will need to set all such watchpoints again. One
3226 way of doing that would be to set a code breakpoint at the entry to the
3227 @code{main} function and when it breaks, set all the watchpoints.
3228
3229 @quotation
3230 @cindex watchpoints and threads
3231 @cindex threads and watchpoints
3232 @emph{Warning:} In multi-thread programs, watchpoints have only limited
3233 usefulness. With the current watchpoint implementation, @value{GDBN}
3234 can only watch the value of an expression @emph{in a single thread}. If
3235 you are confident that the expression can only change due to the current
3236 thread's activity (and if you are also confident that no other thread
3237 can become current), then you can use watchpoints as usual. However,
3238 @value{GDBN} may not notice when a non-current thread's activity changes
3239 the expression.
3240
3241 @c FIXME: this is almost identical to the previous paragraph.
3242 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3243 have only limited usefulness. If @value{GDBN} creates a software
3244 watchpoint, it can only watch the value of an expression @emph{in a
3245 single thread}. If you are confident that the expression can only
3246 change due to the current thread's activity (and if you are also
3247 confident that no other thread can become current), then you can use
3248 software watchpoints as usual. However, @value{GDBN} may not notice
3249 when a non-current thread's activity changes the expression. (Hardware
3250 watchpoints, in contrast, watch an expression in all threads.)
3251 @end quotation
3252
3253 @xref{set remote hardware-watchpoint-limit}.
3254
3255 @node Set Catchpoints
3256 @subsection Setting catchpoints
3257 @cindex catchpoints, setting
3258 @cindex exception handlers
3259 @cindex event handling
3260
3261 You can use @dfn{catchpoints} to cause the debugger to stop for certain
3262 kinds of program events, such as C@t{++} exceptions or the loading of a
3263 shared library. Use the @code{catch} command to set a catchpoint.
3264
3265 @table @code
3266 @kindex catch
3267 @item catch @var{event}
3268 Stop when @var{event} occurs. @var{event} can be any of the following:
3269 @table @code
3270 @item throw
3271 @cindex stop on C@t{++} exceptions
3272 The throwing of a C@t{++} exception.
3273
3274 @item catch
3275 The catching of a C@t{++} exception.
3276
3277 @item exec
3278 @cindex break on fork/exec
3279 A call to @code{exec}. This is currently only available for HP-UX.
3280
3281 @item fork
3282 A call to @code{fork}. This is currently only available for HP-UX.
3283
3284 @item vfork
3285 A call to @code{vfork}. This is currently only available for HP-UX.
3286
3287 @item load
3288 @itemx load @var{libname}
3289 @cindex break on load/unload of shared library
3290 The dynamic loading of any shared library, or the loading of the library
3291 @var{libname}. This is currently only available for HP-UX.
3292
3293 @item unload
3294 @itemx unload @var{libname}
3295 The unloading of any dynamically loaded shared library, or the unloading
3296 of the library @var{libname}. This is currently only available for HP-UX.
3297 @end table
3298
3299 @item tcatch @var{event}
3300 Set a catchpoint that is enabled only for one stop. The catchpoint is
3301 automatically deleted after the first time the event is caught.
3302
3303 @end table
3304
3305 Use the @code{info break} command to list the current catchpoints.
3306
3307 There are currently some limitations to C@t{++} exception handling
3308 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3309
3310 @itemize @bullet
3311 @item
3312 If you call a function interactively, @value{GDBN} normally returns
3313 control to you when the function has finished executing. If the call
3314 raises an exception, however, the call may bypass the mechanism that
3315 returns control to you and cause your program either to abort or to
3316 simply continue running until it hits a breakpoint, catches a signal
3317 that @value{GDBN} is listening for, or exits. This is the case even if
3318 you set a catchpoint for the exception; catchpoints on exceptions are
3319 disabled within interactive calls.
3320
3321 @item
3322 You cannot raise an exception interactively.
3323
3324 @item
3325 You cannot install an exception handler interactively.
3326 @end itemize
3327
3328 @cindex raise exceptions
3329 Sometimes @code{catch} is not the best way to debug exception handling:
3330 if you need to know exactly where an exception is raised, it is better to
3331 stop @emph{before} the exception handler is called, since that way you
3332 can see the stack before any unwinding takes place. If you set a
3333 breakpoint in an exception handler instead, it may not be easy to find
3334 out where the exception was raised.
3335
3336 To stop just before an exception handler is called, you need some
3337 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
3338 raised by calling a library function named @code{__raise_exception}
3339 which has the following ANSI C interface:
3340
3341 @smallexample
3342 /* @var{addr} is where the exception identifier is stored.
3343 @var{id} is the exception identifier. */
3344 void __raise_exception (void **addr, void *id);
3345 @end smallexample
3346
3347 @noindent
3348 To make the debugger catch all exceptions before any stack
3349 unwinding takes place, set a breakpoint on @code{__raise_exception}
3350 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3351
3352 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3353 that depends on the value of @var{id}, you can stop your program when
3354 a specific exception is raised. You can use multiple conditional
3355 breakpoints to stop your program when any of a number of exceptions are
3356 raised.
3357
3358
3359 @node Delete Breaks
3360 @subsection Deleting breakpoints
3361
3362 @cindex clearing breakpoints, watchpoints, catchpoints
3363 @cindex deleting breakpoints, watchpoints, catchpoints
3364 It is often necessary to eliminate a breakpoint, watchpoint, or
3365 catchpoint once it has done its job and you no longer want your program
3366 to stop there. This is called @dfn{deleting} the breakpoint. A
3367 breakpoint that has been deleted no longer exists; it is forgotten.
3368
3369 With the @code{clear} command you can delete breakpoints according to
3370 where they are in your program. With the @code{delete} command you can
3371 delete individual breakpoints, watchpoints, or catchpoints by specifying
3372 their breakpoint numbers.
3373
3374 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3375 automatically ignores breakpoints on the first instruction to be executed
3376 when you continue execution without changing the execution address.
3377
3378 @table @code
3379 @kindex clear
3380 @item clear
3381 Delete any breakpoints at the next instruction to be executed in the
3382 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3383 the innermost frame is selected, this is a good way to delete a
3384 breakpoint where your program just stopped.
3385
3386 @item clear @var{function}
3387 @itemx clear @var{filename}:@var{function}
3388 Delete any breakpoints set at entry to the named @var{function}.
3389
3390 @item clear @var{linenum}
3391 @itemx clear @var{filename}:@var{linenum}
3392 Delete any breakpoints set at or within the code of the specified
3393 @var{linenum} of the specified @var{filename}.
3394
3395 @cindex delete breakpoints
3396 @kindex delete
3397 @kindex d @r{(@code{delete})}
3398 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3399 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3400 ranges specified as arguments. If no argument is specified, delete all
3401 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3402 confirm off}). You can abbreviate this command as @code{d}.
3403 @end table
3404
3405 @node Disabling
3406 @subsection Disabling breakpoints
3407
3408 @cindex enable/disable a breakpoint
3409 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3410 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3411 it had been deleted, but remembers the information on the breakpoint so
3412 that you can @dfn{enable} it again later.
3413
3414 You disable and enable breakpoints, watchpoints, and catchpoints with
3415 the @code{enable} and @code{disable} commands, optionally specifying one
3416 or more breakpoint numbers as arguments. Use @code{info break} or
3417 @code{info watch} to print a list of breakpoints, watchpoints, and
3418 catchpoints if you do not know which numbers to use.
3419
3420 A breakpoint, watchpoint, or catchpoint can have any of four different
3421 states of enablement:
3422
3423 @itemize @bullet
3424 @item
3425 Enabled. The breakpoint stops your program. A breakpoint set
3426 with the @code{break} command starts out in this state.
3427 @item
3428 Disabled. The breakpoint has no effect on your program.
3429 @item
3430 Enabled once. The breakpoint stops your program, but then becomes
3431 disabled.
3432 @item
3433 Enabled for deletion. The breakpoint stops your program, but
3434 immediately after it does so it is deleted permanently. A breakpoint
3435 set with the @code{tbreak} command starts out in this state.
3436 @end itemize
3437
3438 You can use the following commands to enable or disable breakpoints,
3439 watchpoints, and catchpoints:
3440
3441 @table @code
3442 @kindex disable
3443 @kindex dis @r{(@code{disable})}
3444 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3445 Disable the specified breakpoints---or all breakpoints, if none are
3446 listed. A disabled breakpoint has no effect but is not forgotten. All
3447 options such as ignore-counts, conditions and commands are remembered in
3448 case the breakpoint is enabled again later. You may abbreviate
3449 @code{disable} as @code{dis}.
3450
3451 @kindex enable
3452 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3453 Enable the specified breakpoints (or all defined breakpoints). They
3454 become effective once again in stopping your program.
3455
3456 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
3457 Enable the specified breakpoints temporarily. @value{GDBN} disables any
3458 of these breakpoints immediately after stopping your program.
3459
3460 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
3461 Enable the specified breakpoints to work once, then die. @value{GDBN}
3462 deletes any of these breakpoints as soon as your program stops there.
3463 Breakpoints set by the @code{tbreak} command start out in this state.
3464 @end table
3465
3466 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3467 @c confusing: tbreak is also initially enabled.
3468 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3469 ,Setting breakpoints}), breakpoints that you set are initially enabled;
3470 subsequently, they become disabled or enabled only when you use one of
3471 the commands above. (The command @code{until} can set and delete a
3472 breakpoint of its own, but it does not change the state of your other
3473 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3474 stepping}.)
3475
3476 @node Conditions
3477 @subsection Break conditions
3478 @cindex conditional breakpoints
3479 @cindex breakpoint conditions
3480
3481 @c FIXME what is scope of break condition expr? Context where wanted?
3482 @c in particular for a watchpoint?
3483 The simplest sort of breakpoint breaks every time your program reaches a
3484 specified place. You can also specify a @dfn{condition} for a
3485 breakpoint. A condition is just a Boolean expression in your
3486 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3487 a condition evaluates the expression each time your program reaches it,
3488 and your program stops only if the condition is @emph{true}.
3489
3490 This is the converse of using assertions for program validation; in that
3491 situation, you want to stop when the assertion is violated---that is,
3492 when the condition is false. In C, if you want to test an assertion expressed
3493 by the condition @var{assert}, you should set the condition
3494 @samp{! @var{assert}} on the appropriate breakpoint.
3495
3496 Conditions are also accepted for watchpoints; you may not need them,
3497 since a watchpoint is inspecting the value of an expression anyhow---but
3498 it might be simpler, say, to just set a watchpoint on a variable name,
3499 and specify a condition that tests whether the new value is an interesting
3500 one.
3501
3502 Break conditions can have side effects, and may even call functions in
3503 your program. This can be useful, for example, to activate functions
3504 that log program progress, or to use your own print functions to
3505 format special data structures. The effects are completely predictable
3506 unless there is another enabled breakpoint at the same address. (In
3507 that case, @value{GDBN} might see the other breakpoint first and stop your
3508 program without checking the condition of this one.) Note that
3509 breakpoint commands are usually more convenient and flexible than break
3510 conditions for the
3511 purpose of performing side effects when a breakpoint is reached
3512 (@pxref{Break Commands, ,Breakpoint command lists}).
3513
3514 Break conditions can be specified when a breakpoint is set, by using
3515 @samp{if} in the arguments to the @code{break} command. @xref{Set
3516 Breaks, ,Setting breakpoints}. They can also be changed at any time
3517 with the @code{condition} command.
3518
3519 You can also use the @code{if} keyword with the @code{watch} command.
3520 The @code{catch} command does not recognize the @code{if} keyword;
3521 @code{condition} is the only way to impose a further condition on a
3522 catchpoint.
3523
3524 @table @code
3525 @kindex condition
3526 @item condition @var{bnum} @var{expression}
3527 Specify @var{expression} as the break condition for breakpoint,
3528 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3529 breakpoint @var{bnum} stops your program only if the value of
3530 @var{expression} is true (nonzero, in C). When you use
3531 @code{condition}, @value{GDBN} checks @var{expression} immediately for
3532 syntactic correctness, and to determine whether symbols in it have
3533 referents in the context of your breakpoint. If @var{expression} uses
3534 symbols not referenced in the context of the breakpoint, @value{GDBN}
3535 prints an error message:
3536
3537 @smallexample
3538 No symbol "foo" in current context.
3539 @end smallexample
3540
3541 @noindent
3542 @value{GDBN} does
3543 not actually evaluate @var{expression} at the time the @code{condition}
3544 command (or a command that sets a breakpoint with a condition, like
3545 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
3546
3547 @item condition @var{bnum}
3548 Remove the condition from breakpoint number @var{bnum}. It becomes
3549 an ordinary unconditional breakpoint.
3550 @end table
3551
3552 @cindex ignore count (of breakpoint)
3553 A special case of a breakpoint condition is to stop only when the
3554 breakpoint has been reached a certain number of times. This is so
3555 useful that there is a special way to do it, using the @dfn{ignore
3556 count} of the breakpoint. Every breakpoint has an ignore count, which
3557 is an integer. Most of the time, the ignore count is zero, and
3558 therefore has no effect. But if your program reaches a breakpoint whose
3559 ignore count is positive, then instead of stopping, it just decrements
3560 the ignore count by one and continues. As a result, if the ignore count
3561 value is @var{n}, the breakpoint does not stop the next @var{n} times
3562 your program reaches it.
3563
3564 @table @code
3565 @kindex ignore
3566 @item ignore @var{bnum} @var{count}
3567 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3568 The next @var{count} times the breakpoint is reached, your program's
3569 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3570 takes no action.
3571
3572 To make the breakpoint stop the next time it is reached, specify
3573 a count of zero.
3574
3575 When you use @code{continue} to resume execution of your program from a
3576 breakpoint, you can specify an ignore count directly as an argument to
3577 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3578 Stepping,,Continuing and stepping}.
3579
3580 If a breakpoint has a positive ignore count and a condition, the
3581 condition is not checked. Once the ignore count reaches zero,
3582 @value{GDBN} resumes checking the condition.
3583
3584 You could achieve the effect of the ignore count with a condition such
3585 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3586 is decremented each time. @xref{Convenience Vars, ,Convenience
3587 variables}.
3588 @end table
3589
3590 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3591
3592
3593 @node Break Commands
3594 @subsection Breakpoint command lists
3595
3596 @cindex breakpoint commands
3597 You can give any breakpoint (or watchpoint or catchpoint) a series of
3598 commands to execute when your program stops due to that breakpoint. For
3599 example, you might want to print the values of certain expressions, or
3600 enable other breakpoints.
3601
3602 @table @code
3603 @kindex commands
3604 @kindex end@r{ (breakpoint commands)}
3605 @item commands @r{[}@var{bnum}@r{]}
3606 @itemx @dots{} @var{command-list} @dots{}
3607 @itemx end
3608 Specify a list of commands for breakpoint number @var{bnum}. The commands
3609 themselves appear on the following lines. Type a line containing just
3610 @code{end} to terminate the commands.
3611
3612 To remove all commands from a breakpoint, type @code{commands} and
3613 follow it immediately with @code{end}; that is, give no commands.
3614
3615 With no @var{bnum} argument, @code{commands} refers to the last
3616 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3617 recently encountered).
3618 @end table
3619
3620 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3621 disabled within a @var{command-list}.
3622
3623 You can use breakpoint commands to start your program up again. Simply
3624 use the @code{continue} command, or @code{step}, or any other command
3625 that resumes execution.
3626
3627 Any other commands in the command list, after a command that resumes
3628 execution, are ignored. This is because any time you resume execution
3629 (even with a simple @code{next} or @code{step}), you may encounter
3630 another breakpoint---which could have its own command list, leading to
3631 ambiguities about which list to execute.
3632
3633 @kindex silent
3634 If the first command you specify in a command list is @code{silent}, the
3635 usual message about stopping at a breakpoint is not printed. This may
3636 be desirable for breakpoints that are to print a specific message and
3637 then continue. If none of the remaining commands print anything, you
3638 see no sign that the breakpoint was reached. @code{silent} is
3639 meaningful only at the beginning of a breakpoint command list.
3640
3641 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3642 print precisely controlled output, and are often useful in silent
3643 breakpoints. @xref{Output, ,Commands for controlled output}.
3644
3645 For example, here is how you could use breakpoint commands to print the
3646 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3647
3648 @smallexample
3649 break foo if x>0
3650 commands
3651 silent
3652 printf "x is %d\n",x
3653 cont
3654 end
3655 @end smallexample
3656
3657 One application for breakpoint commands is to compensate for one bug so
3658 you can test for another. Put a breakpoint just after the erroneous line
3659 of code, give it a condition to detect the case in which something
3660 erroneous has been done, and give it commands to assign correct values
3661 to any variables that need them. End with the @code{continue} command
3662 so that your program does not stop, and start with the @code{silent}
3663 command so that no output is produced. Here is an example:
3664
3665 @smallexample
3666 break 403
3667 commands
3668 silent
3669 set x = y + 4
3670 cont
3671 end
3672 @end smallexample
3673
3674 @node Breakpoint Menus
3675 @subsection Breakpoint menus
3676 @cindex overloading
3677 @cindex symbol overloading
3678
3679 Some programming languages (notably C@t{++} and Objective-C) permit a
3680 single function name
3681 to be defined several times, for application in different contexts.
3682 This is called @dfn{overloading}. When a function name is overloaded,
3683 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3684 a breakpoint. If you realize this is a problem, you can use
3685 something like @samp{break @var{function}(@var{types})} to specify which
3686 particular version of the function you want. Otherwise, @value{GDBN} offers
3687 you a menu of numbered choices for different possible breakpoints, and
3688 waits for your selection with the prompt @samp{>}. The first two
3689 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3690 sets a breakpoint at each definition of @var{function}, and typing
3691 @kbd{0} aborts the @code{break} command without setting any new
3692 breakpoints.
3693
3694 For example, the following session excerpt shows an attempt to set a
3695 breakpoint at the overloaded symbol @code{String::after}.
3696 We choose three particular definitions of that function name:
3697
3698 @c FIXME! This is likely to change to show arg type lists, at least
3699 @smallexample
3700 @group
3701 (@value{GDBP}) b String::after
3702 [0] cancel
3703 [1] all
3704 [2] file:String.cc; line number:867
3705 [3] file:String.cc; line number:860
3706 [4] file:String.cc; line number:875
3707 [5] file:String.cc; line number:853
3708 [6] file:String.cc; line number:846
3709 [7] file:String.cc; line number:735
3710 > 2 4 6
3711 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3712 Breakpoint 2 at 0xb344: file String.cc, line 875.
3713 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3714 Multiple breakpoints were set.
3715 Use the "delete" command to delete unwanted
3716 breakpoints.
3717 (@value{GDBP})
3718 @end group
3719 @end smallexample
3720
3721 @c @ifclear BARETARGET
3722 @node Error in Breakpoints
3723 @subsection ``Cannot insert breakpoints''
3724 @c
3725 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3726 @c
3727 Under some operating systems, breakpoints cannot be used in a program if
3728 any other process is running that program. In this situation,
3729 attempting to run or continue a program with a breakpoint causes
3730 @value{GDBN} to print an error message:
3731
3732 @smallexample
3733 Cannot insert breakpoints.
3734 The same program may be running in another process.
3735 @end smallexample
3736
3737 When this happens, you have three ways to proceed:
3738
3739 @enumerate
3740 @item
3741 Remove or disable the breakpoints, then continue.
3742
3743 @item
3744 Suspend @value{GDBN}, and copy the file containing your program to a new
3745 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3746 that @value{GDBN} should run your program under that name.
3747 Then start your program again.
3748
3749 @item
3750 Relink your program so that the text segment is nonsharable, using the
3751 linker option @samp{-N}. The operating system limitation may not apply
3752 to nonsharable executables.
3753 @end enumerate
3754 @c @end ifclear
3755
3756 A similar message can be printed if you request too many active
3757 hardware-assisted breakpoints and watchpoints:
3758
3759 @c FIXME: the precise wording of this message may change; the relevant
3760 @c source change is not committed yet (Sep 3, 1999).
3761 @smallexample
3762 Stopped; cannot insert breakpoints.
3763 You may have requested too many hardware breakpoints and watchpoints.
3764 @end smallexample
3765
3766 @noindent
3767 This message is printed when you attempt to resume the program, since
3768 only then @value{GDBN} knows exactly how many hardware breakpoints and
3769 watchpoints it needs to insert.
3770
3771 When this message is printed, you need to disable or remove some of the
3772 hardware-assisted breakpoints and watchpoints, and then continue.
3773
3774 @node Breakpoint related warnings
3775 @subsection ``Breakpoint address adjusted...''
3776 @cindex breakpoint address adjusted
3777
3778 Some processor architectures place constraints on the addresses at
3779 which breakpoints may be placed. For architectures thus constrained,
3780 @value{GDBN} will attempt to adjust the breakpoint's address to comply
3781 with the constraints dictated by the architecture.
3782
3783 One example of such an architecture is the Fujitsu FR-V. The FR-V is
3784 a VLIW architecture in which a number of RISC-like instructions may be
3785 bundled together for parallel execution. The FR-V architecture
3786 constrains the location of a breakpoint instruction within such a
3787 bundle to the instruction with the lowest address. @value{GDBN}
3788 honors this constraint by adjusting a breakpoint's address to the
3789 first in the bundle.
3790
3791 It is not uncommon for optimized code to have bundles which contain
3792 instructions from different source statements, thus it may happen that
3793 a breakpoint's address will be adjusted from one source statement to
3794 another. Since this adjustment may significantly alter @value{GDBN}'s
3795 breakpoint related behavior from what the user expects, a warning is
3796 printed when the breakpoint is first set and also when the breakpoint
3797 is hit.
3798
3799 A warning like the one below is printed when setting a breakpoint
3800 that's been subject to address adjustment:
3801
3802 @smallexample
3803 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3804 @end smallexample
3805
3806 Such warnings are printed both for user settable and @value{GDBN}'s
3807 internal breakpoints. If you see one of these warnings, you should
3808 verify that a breakpoint set at the adjusted address will have the
3809 desired affect. If not, the breakpoint in question may be removed and
3810 other breakpoints may be set which will have the desired behavior.
3811 E.g., it may be sufficient to place the breakpoint at a later
3812 instruction. A conditional breakpoint may also be useful in some
3813 cases to prevent the breakpoint from triggering too often.
3814
3815 @value{GDBN} will also issue a warning when stopping at one of these
3816 adjusted breakpoints:
3817
3818 @smallexample
3819 warning: Breakpoint 1 address previously adjusted from 0x00010414
3820 to 0x00010410.
3821 @end smallexample
3822
3823 When this warning is encountered, it may be too late to take remedial
3824 action except in cases where the breakpoint is hit earlier or more
3825 frequently than expected.
3826
3827 @node Continuing and Stepping
3828 @section Continuing and stepping
3829
3830 @cindex stepping
3831 @cindex continuing
3832 @cindex resuming execution
3833 @dfn{Continuing} means resuming program execution until your program
3834 completes normally. In contrast, @dfn{stepping} means executing just
3835 one more ``step'' of your program, where ``step'' may mean either one
3836 line of source code, or one machine instruction (depending on what
3837 particular command you use). Either when continuing or when stepping,
3838 your program may stop even sooner, due to a breakpoint or a signal. (If
3839 it stops due to a signal, you may want to use @code{handle}, or use
3840 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
3841
3842 @table @code
3843 @kindex continue
3844 @kindex c @r{(@code{continue})}
3845 @kindex fg @r{(resume foreground execution)}
3846 @item continue @r{[}@var{ignore-count}@r{]}
3847 @itemx c @r{[}@var{ignore-count}@r{]}
3848 @itemx fg @r{[}@var{ignore-count}@r{]}
3849 Resume program execution, at the address where your program last stopped;
3850 any breakpoints set at that address are bypassed. The optional argument
3851 @var{ignore-count} allows you to specify a further number of times to
3852 ignore a breakpoint at this location; its effect is like that of
3853 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3854
3855 The argument @var{ignore-count} is meaningful only when your program
3856 stopped due to a breakpoint. At other times, the argument to
3857 @code{continue} is ignored.
3858
3859 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3860 debugged program is deemed to be the foreground program) are provided
3861 purely for convenience, and have exactly the same behavior as
3862 @code{continue}.
3863 @end table
3864
3865 To resume execution at a different place, you can use @code{return}
3866 (@pxref{Returning, ,Returning from a function}) to go back to the
3867 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3868 different address}) to go to an arbitrary location in your program.
3869
3870 A typical technique for using stepping is to set a breakpoint
3871 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3872 beginning of the function or the section of your program where a problem
3873 is believed to lie, run your program until it stops at that breakpoint,
3874 and then step through the suspect area, examining the variables that are
3875 interesting, until you see the problem happen.
3876
3877 @table @code
3878 @kindex step
3879 @kindex s @r{(@code{step})}
3880 @item step
3881 Continue running your program until control reaches a different source
3882 line, then stop it and return control to @value{GDBN}. This command is
3883 abbreviated @code{s}.
3884
3885 @quotation
3886 @c "without debugging information" is imprecise; actually "without line
3887 @c numbers in the debugging information". (gcc -g1 has debugging info but
3888 @c not line numbers). But it seems complex to try to make that
3889 @c distinction here.
3890 @emph{Warning:} If you use the @code{step} command while control is
3891 within a function that was compiled without debugging information,
3892 execution proceeds until control reaches a function that does have
3893 debugging information. Likewise, it will not step into a function which
3894 is compiled without debugging information. To step through functions
3895 without debugging information, use the @code{stepi} command, described
3896 below.
3897 @end quotation
3898
3899 The @code{step} command only stops at the first instruction of a source
3900 line. This prevents the multiple stops that could otherwise occur in
3901 @code{switch} statements, @code{for} loops, etc. @code{step} continues
3902 to stop if a function that has debugging information is called within
3903 the line. In other words, @code{step} @emph{steps inside} any functions
3904 called within the line.
3905
3906 Also, the @code{step} command only enters a function if there is line
3907 number information for the function. Otherwise it acts like the
3908 @code{next} command. This avoids problems when using @code{cc -gl}
3909 on MIPS machines. Previously, @code{step} entered subroutines if there
3910 was any debugging information about the routine.
3911
3912 @item step @var{count}
3913 Continue running as in @code{step}, but do so @var{count} times. If a
3914 breakpoint is reached, or a signal not related to stepping occurs before
3915 @var{count} steps, stepping stops right away.
3916
3917 @kindex next
3918 @kindex n @r{(@code{next})}
3919 @item next @r{[}@var{count}@r{]}
3920 Continue to the next source line in the current (innermost) stack frame.
3921 This is similar to @code{step}, but function calls that appear within
3922 the line of code are executed without stopping. Execution stops when
3923 control reaches a different line of code at the original stack level
3924 that was executing when you gave the @code{next} command. This command
3925 is abbreviated @code{n}.
3926
3927 An argument @var{count} is a repeat count, as for @code{step}.
3928
3929
3930 @c FIX ME!! Do we delete this, or is there a way it fits in with
3931 @c the following paragraph? --- Vctoria
3932 @c
3933 @c @code{next} within a function that lacks debugging information acts like
3934 @c @code{step}, but any function calls appearing within the code of the
3935 @c function are executed without stopping.
3936
3937 The @code{next} command only stops at the first instruction of a
3938 source line. This prevents multiple stops that could otherwise occur in
3939 @code{switch} statements, @code{for} loops, etc.
3940
3941 @kindex set step-mode
3942 @item set step-mode
3943 @cindex functions without line info, and stepping
3944 @cindex stepping into functions with no line info
3945 @itemx set step-mode on
3946 The @code{set step-mode on} command causes the @code{step} command to
3947 stop at the first instruction of a function which contains no debug line
3948 information rather than stepping over it.
3949
3950 This is useful in cases where you may be interested in inspecting the
3951 machine instructions of a function which has no symbolic info and do not
3952 want @value{GDBN} to automatically skip over this function.
3953
3954 @item set step-mode off
3955 Causes the @code{step} command to step over any functions which contains no
3956 debug information. This is the default.
3957
3958 @item show step-mode
3959 Show whether @value{GDBN} will stop in or step over functions without
3960 source line debug information.
3961
3962 @kindex finish
3963 @item finish
3964 Continue running until just after function in the selected stack frame
3965 returns. Print the returned value (if any).
3966
3967 Contrast this with the @code{return} command (@pxref{Returning,
3968 ,Returning from a function}).
3969
3970 @kindex until
3971 @kindex u @r{(@code{until})}
3972 @cindex run until specified location
3973 @item until
3974 @itemx u
3975 Continue running until a source line past the current line, in the
3976 current stack frame, is reached. This command is used to avoid single
3977 stepping through a loop more than once. It is like the @code{next}
3978 command, except that when @code{until} encounters a jump, it
3979 automatically continues execution until the program counter is greater
3980 than the address of the jump.
3981
3982 This means that when you reach the end of a loop after single stepping
3983 though it, @code{until} makes your program continue execution until it
3984 exits the loop. In contrast, a @code{next} command at the end of a loop
3985 simply steps back to the beginning of the loop, which forces you to step
3986 through the next iteration.
3987
3988 @code{until} always stops your program if it attempts to exit the current
3989 stack frame.
3990
3991 @code{until} may produce somewhat counterintuitive results if the order
3992 of machine code does not match the order of the source lines. For
3993 example, in the following excerpt from a debugging session, the @code{f}
3994 (@code{frame}) command shows that execution is stopped at line
3995 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3996
3997 @smallexample
3998 (@value{GDBP}) f
3999 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4000 206 expand_input();
4001 (@value{GDBP}) until
4002 195 for ( ; argc > 0; NEXTARG) @{
4003 @end smallexample
4004
4005 This happened because, for execution efficiency, the compiler had
4006 generated code for the loop closure test at the end, rather than the
4007 start, of the loop---even though the test in a C @code{for}-loop is
4008 written before the body of the loop. The @code{until} command appeared
4009 to step back to the beginning of the loop when it advanced to this
4010 expression; however, it has not really gone to an earlier
4011 statement---not in terms of the actual machine code.
4012
4013 @code{until} with no argument works by means of single
4014 instruction stepping, and hence is slower than @code{until} with an
4015 argument.
4016
4017 @item until @var{location}
4018 @itemx u @var{location}
4019 Continue running your program until either the specified location is
4020 reached, or the current stack frame returns. @var{location} is any of
4021 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
4022 ,Setting breakpoints}). This form of the command uses breakpoints, and
4023 hence is quicker than @code{until} without an argument. The specified
4024 location is actually reached only if it is in the current frame. This
4025 implies that @code{until} can be used to skip over recursive function
4026 invocations. For instance in the code below, if the current location is
4027 line @code{96}, issuing @code{until 99} will execute the program up to
4028 line @code{99} in the same invocation of factorial, i.e. after the inner
4029 invocations have returned.
4030
4031 @smallexample
4032 94 int factorial (int value)
4033 95 @{
4034 96 if (value > 1) @{
4035 97 value *= factorial (value - 1);
4036 98 @}
4037 99 return (value);
4038 100 @}
4039 @end smallexample
4040
4041
4042 @kindex advance @var{location}
4043 @itemx advance @var{location}
4044 Continue running the program up to the given @var{location}. An argument is
4045 required, which should be of the same form as arguments for the @code{break}
4046 command. Execution will also stop upon exit from the current stack
4047 frame. This command is similar to @code{until}, but @code{advance} will
4048 not skip over recursive function calls, and the target location doesn't
4049 have to be in the same frame as the current one.
4050
4051
4052 @kindex stepi
4053 @kindex si @r{(@code{stepi})}
4054 @item stepi
4055 @itemx stepi @var{arg}
4056 @itemx si
4057 Execute one machine instruction, then stop and return to the debugger.
4058
4059 It is often useful to do @samp{display/i $pc} when stepping by machine
4060 instructions. This makes @value{GDBN} automatically display the next
4061 instruction to be executed, each time your program stops. @xref{Auto
4062 Display,, Automatic display}.
4063
4064 An argument is a repeat count, as in @code{step}.
4065
4066 @need 750
4067 @kindex nexti
4068 @kindex ni @r{(@code{nexti})}
4069 @item nexti
4070 @itemx nexti @var{arg}
4071 @itemx ni
4072 Execute one machine instruction, but if it is a function call,
4073 proceed until the function returns.
4074
4075 An argument is a repeat count, as in @code{next}.
4076 @end table
4077
4078 @node Signals
4079 @section Signals
4080 @cindex signals
4081
4082 A signal is an asynchronous event that can happen in a program. The
4083 operating system defines the possible kinds of signals, and gives each
4084 kind a name and a number. For example, in Unix @code{SIGINT} is the
4085 signal a program gets when you type an interrupt character (often @kbd{C-c});
4086 @code{SIGSEGV} is the signal a program gets from referencing a place in
4087 memory far away from all the areas in use; @code{SIGALRM} occurs when
4088 the alarm clock timer goes off (which happens only if your program has
4089 requested an alarm).
4090
4091 @cindex fatal signals
4092 Some signals, including @code{SIGALRM}, are a normal part of the
4093 functioning of your program. Others, such as @code{SIGSEGV}, indicate
4094 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
4095 program has not specified in advance some other way to handle the signal.
4096 @code{SIGINT} does not indicate an error in your program, but it is normally
4097 fatal so it can carry out the purpose of the interrupt: to kill the program.
4098
4099 @value{GDBN} has the ability to detect any occurrence of a signal in your
4100 program. You can tell @value{GDBN} in advance what to do for each kind of
4101 signal.
4102
4103 @cindex handling signals
4104 Normally, @value{GDBN} is set up to let the non-erroneous signals like
4105 @code{SIGALRM} be silently passed to your program
4106 (so as not to interfere with their role in the program's functioning)
4107 but to stop your program immediately whenever an error signal happens.
4108 You can change these settings with the @code{handle} command.
4109
4110 @table @code
4111 @kindex info signals
4112 @kindex info handle
4113 @item info signals
4114 @itemx info handle
4115 Print a table of all the kinds of signals and how @value{GDBN} has been told to
4116 handle each one. You can use this to see the signal numbers of all
4117 the defined types of signals.
4118
4119 @code{info handle} is an alias for @code{info signals}.
4120
4121 @kindex handle
4122 @item handle @var{signal} @var{keywords}@dots{}
4123 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4124 can be the number of a signal or its name (with or without the
4125 @samp{SIG} at the beginning); a list of signal numbers of the form
4126 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4127 known signals. The @var{keywords} say what change to make.
4128 @end table
4129
4130 @c @group
4131 The keywords allowed by the @code{handle} command can be abbreviated.
4132 Their full names are:
4133
4134 @table @code
4135 @item nostop
4136 @value{GDBN} should not stop your program when this signal happens. It may
4137 still print a message telling you that the signal has come in.
4138
4139 @item stop
4140 @value{GDBN} should stop your program when this signal happens. This implies
4141 the @code{print} keyword as well.
4142
4143 @item print
4144 @value{GDBN} should print a message when this signal happens.
4145
4146 @item noprint
4147 @value{GDBN} should not mention the occurrence of the signal at all. This
4148 implies the @code{nostop} keyword as well.
4149
4150 @item pass
4151 @itemx noignore
4152 @value{GDBN} should allow your program to see this signal; your program
4153 can handle the signal, or else it may terminate if the signal is fatal
4154 and not handled. @code{pass} and @code{noignore} are synonyms.
4155
4156 @item nopass
4157 @itemx ignore
4158 @value{GDBN} should not allow your program to see this signal.
4159 @code{nopass} and @code{ignore} are synonyms.
4160 @end table
4161 @c @end group
4162
4163 When a signal stops your program, the signal is not visible to the
4164 program until you
4165 continue. Your program sees the signal then, if @code{pass} is in
4166 effect for the signal in question @emph{at that time}. In other words,
4167 after @value{GDBN} reports a signal, you can use the @code{handle}
4168 command with @code{pass} or @code{nopass} to control whether your
4169 program sees that signal when you continue.
4170
4171 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4172 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4173 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4174 erroneous signals.
4175
4176 You can also use the @code{signal} command to prevent your program from
4177 seeing a signal, or cause it to see a signal it normally would not see,
4178 or to give it any signal at any time. For example, if your program stopped
4179 due to some sort of memory reference error, you might store correct
4180 values into the erroneous variables and continue, hoping to see more
4181 execution; but your program would probably terminate immediately as
4182 a result of the fatal signal once it saw the signal. To prevent this,
4183 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
4184 program a signal}.
4185
4186 @node Thread Stops
4187 @section Stopping and starting multi-thread programs
4188
4189 When your program has multiple threads (@pxref{Threads,, Debugging
4190 programs with multiple threads}), you can choose whether to set
4191 breakpoints on all threads, or on a particular thread.
4192
4193 @table @code
4194 @cindex breakpoints and threads
4195 @cindex thread breakpoints
4196 @kindex break @dots{} thread @var{threadno}
4197 @item break @var{linespec} thread @var{threadno}
4198 @itemx break @var{linespec} thread @var{threadno} if @dots{}
4199 @var{linespec} specifies source lines; there are several ways of
4200 writing them, but the effect is always to specify some source line.
4201
4202 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4203 to specify that you only want @value{GDBN} to stop the program when a
4204 particular thread reaches this breakpoint. @var{threadno} is one of the
4205 numeric thread identifiers assigned by @value{GDBN}, shown in the first
4206 column of the @samp{info threads} display.
4207
4208 If you do not specify @samp{thread @var{threadno}} when you set a
4209 breakpoint, the breakpoint applies to @emph{all} threads of your
4210 program.
4211
4212 You can use the @code{thread} qualifier on conditional breakpoints as
4213 well; in this case, place @samp{thread @var{threadno}} before the
4214 breakpoint condition, like this:
4215
4216 @smallexample
4217 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
4218 @end smallexample
4219
4220 @end table
4221
4222 @cindex stopped threads
4223 @cindex threads, stopped
4224 Whenever your program stops under @value{GDBN} for any reason,
4225 @emph{all} threads of execution stop, not just the current thread. This
4226 allows you to examine the overall state of the program, including
4227 switching between threads, without worrying that things may change
4228 underfoot.
4229
4230 @cindex thread breakpoints and system calls
4231 @cindex system calls and thread breakpoints
4232 @cindex premature return from system calls
4233 There is an unfortunate side effect. If one thread stops for a
4234 breakpoint, or for some other reason, and another thread is blocked in a
4235 system call, then the system call may return prematurely. This is a
4236 consequence of the interaction between multiple threads and the signals
4237 that @value{GDBN} uses to implement breakpoints and other events that
4238 stop execution.
4239
4240 To handle this problem, your program should check the return value of
4241 each system call and react appropriately. This is good programming
4242 style anyways.
4243
4244 For example, do not write code like this:
4245
4246 @smallexample
4247 sleep (10);
4248 @end smallexample
4249
4250 The call to @code{sleep} will return early if a different thread stops
4251 at a breakpoint or for some other reason.
4252
4253 Instead, write this:
4254
4255 @smallexample
4256 int unslept = 10;
4257 while (unslept > 0)
4258 unslept = sleep (unslept);
4259 @end smallexample
4260
4261 A system call is allowed to return early, so the system is still
4262 conforming to its specification. But @value{GDBN} does cause your
4263 multi-threaded program to behave differently than it would without
4264 @value{GDBN}.
4265
4266 Also, @value{GDBN} uses internal breakpoints in the thread library to
4267 monitor certain events such as thread creation and thread destruction.
4268 When such an event happens, a system call in another thread may return
4269 prematurely, even though your program does not appear to stop.
4270
4271 @cindex continuing threads
4272 @cindex threads, continuing
4273 Conversely, whenever you restart the program, @emph{all} threads start
4274 executing. @emph{This is true even when single-stepping} with commands
4275 like @code{step} or @code{next}.
4276
4277 In particular, @value{GDBN} cannot single-step all threads in lockstep.
4278 Since thread scheduling is up to your debugging target's operating
4279 system (not controlled by @value{GDBN}), other threads may
4280 execute more than one statement while the current thread completes a
4281 single step. Moreover, in general other threads stop in the middle of a
4282 statement, rather than at a clean statement boundary, when the program
4283 stops.
4284
4285 You might even find your program stopped in another thread after
4286 continuing or even single-stepping. This happens whenever some other
4287 thread runs into a breakpoint, a signal, or an exception before the
4288 first thread completes whatever you requested.
4289
4290 On some OSes, you can lock the OS scheduler and thus allow only a single
4291 thread to run.
4292
4293 @table @code
4294 @item set scheduler-locking @var{mode}
4295 @cindex scheduler locking mode
4296 @cindex lock scheduler
4297 Set the scheduler locking mode. If it is @code{off}, then there is no
4298 locking and any thread may run at any time. If @code{on}, then only the
4299 current thread may run when the inferior is resumed. The @code{step}
4300 mode optimizes for single-stepping. It stops other threads from
4301 ``seizing the prompt'' by preempting the current thread while you are
4302 stepping. Other threads will only rarely (or never) get a chance to run
4303 when you step. They are more likely to run when you @samp{next} over a
4304 function call, and they are completely free to run when you use commands
4305 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
4306 thread hits a breakpoint during its timeslice, they will never steal the
4307 @value{GDBN} prompt away from the thread that you are debugging.
4308
4309 @item show scheduler-locking
4310 Display the current scheduler locking mode.
4311 @end table
4312
4313
4314 @node Stack
4315 @chapter Examining the Stack
4316
4317 When your program has stopped, the first thing you need to know is where it
4318 stopped and how it got there.
4319
4320 @cindex call stack
4321 Each time your program performs a function call, information about the call
4322 is generated.
4323 That information includes the location of the call in your program,
4324 the arguments of the call,
4325 and the local variables of the function being called.
4326 The information is saved in a block of data called a @dfn{stack frame}.
4327 The stack frames are allocated in a region of memory called the @dfn{call
4328 stack}.
4329
4330 When your program stops, the @value{GDBN} commands for examining the
4331 stack allow you to see all of this information.
4332
4333 @cindex selected frame
4334 One of the stack frames is @dfn{selected} by @value{GDBN} and many
4335 @value{GDBN} commands refer implicitly to the selected frame. In
4336 particular, whenever you ask @value{GDBN} for the value of a variable in
4337 your program, the value is found in the selected frame. There are
4338 special @value{GDBN} commands to select whichever frame you are
4339 interested in. @xref{Selection, ,Selecting a frame}.
4340
4341 When your program stops, @value{GDBN} automatically selects the
4342 currently executing frame and describes it briefly, similar to the
4343 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4344
4345 @menu
4346 * Frames:: Stack frames
4347 * Backtrace:: Backtraces
4348 * Selection:: Selecting a frame
4349 * Frame Info:: Information on a frame
4350
4351 @end menu
4352
4353 @node Frames
4354 @section Stack frames
4355
4356 @cindex frame, definition
4357 @cindex stack frame
4358 The call stack is divided up into contiguous pieces called @dfn{stack
4359 frames}, or @dfn{frames} for short; each frame is the data associated
4360 with one call to one function. The frame contains the arguments given
4361 to the function, the function's local variables, and the address at
4362 which the function is executing.
4363
4364 @cindex initial frame
4365 @cindex outermost frame
4366 @cindex innermost frame
4367 When your program is started, the stack has only one frame, that of the
4368 function @code{main}. This is called the @dfn{initial} frame or the
4369 @dfn{outermost} frame. Each time a function is called, a new frame is
4370 made. Each time a function returns, the frame for that function invocation
4371 is eliminated. If a function is recursive, there can be many frames for
4372 the same function. The frame for the function in which execution is
4373 actually occurring is called the @dfn{innermost} frame. This is the most
4374 recently created of all the stack frames that still exist.
4375
4376 @cindex frame pointer
4377 Inside your program, stack frames are identified by their addresses. A
4378 stack frame consists of many bytes, each of which has its own address; each
4379 kind of computer has a convention for choosing one byte whose
4380 address serves as the address of the frame. Usually this address is kept
4381 in a register called the @dfn{frame pointer register}
4382 (@pxref{Registers, $fp}) while execution is going on in that frame.
4383
4384 @cindex frame number
4385 @value{GDBN} assigns numbers to all existing stack frames, starting with
4386 zero for the innermost frame, one for the frame that called it,
4387 and so on upward. These numbers do not really exist in your program;
4388 they are assigned by @value{GDBN} to give you a way of designating stack
4389 frames in @value{GDBN} commands.
4390
4391 @c The -fomit-frame-pointer below perennially causes hbox overflow
4392 @c underflow problems.
4393 @cindex frameless execution
4394 Some compilers provide a way to compile functions so that they operate
4395 without stack frames. (For example, the @value{GCC} option
4396 @smallexample
4397 @samp{-fomit-frame-pointer}
4398 @end smallexample
4399 generates functions without a frame.)
4400 This is occasionally done with heavily used library functions to save
4401 the frame setup time. @value{GDBN} has limited facilities for dealing
4402 with these function invocations. If the innermost function invocation
4403 has no stack frame, @value{GDBN} nevertheless regards it as though
4404 it had a separate frame, which is numbered zero as usual, allowing
4405 correct tracing of the function call chain. However, @value{GDBN} has
4406 no provision for frameless functions elsewhere in the stack.
4407
4408 @table @code
4409 @kindex frame@r{, command}
4410 @cindex current stack frame
4411 @item frame @var{args}
4412 The @code{frame} command allows you to move from one stack frame to another,
4413 and to print the stack frame you select. @var{args} may be either the
4414 address of the frame or the stack frame number. Without an argument,
4415 @code{frame} prints the current stack frame.
4416
4417 @kindex select-frame
4418 @cindex selecting frame silently
4419 @item select-frame
4420 The @code{select-frame} command allows you to move from one stack frame
4421 to another without printing the frame. This is the silent version of
4422 @code{frame}.
4423 @end table
4424
4425 @node Backtrace
4426 @section Backtraces
4427
4428 @cindex traceback
4429 @cindex call stack traces
4430 A backtrace is a summary of how your program got where it is. It shows one
4431 line per frame, for many frames, starting with the currently executing
4432 frame (frame zero), followed by its caller (frame one), and on up the
4433 stack.
4434
4435 @table @code
4436 @kindex backtrace
4437 @kindex bt @r{(@code{backtrace})}
4438 @item backtrace
4439 @itemx bt
4440 Print a backtrace of the entire stack: one line per frame for all
4441 frames in the stack.
4442
4443 You can stop the backtrace at any time by typing the system interrupt
4444 character, normally @kbd{C-c}.
4445
4446 @item backtrace @var{n}
4447 @itemx bt @var{n}
4448 Similar, but print only the innermost @var{n} frames.
4449
4450 @item backtrace -@var{n}
4451 @itemx bt -@var{n}
4452 Similar, but print only the outermost @var{n} frames.
4453
4454 @item backtrace full
4455 Print the values of the local variables also.
4456 @itemx bt full
4457 @end table
4458
4459 @kindex where
4460 @kindex info stack
4461 The names @code{where} and @code{info stack} (abbreviated @code{info s})
4462 are additional aliases for @code{backtrace}.
4463
4464 Each line in the backtrace shows the frame number and the function name.
4465 The program counter value is also shown---unless you use @code{set
4466 print address off}. The backtrace also shows the source file name and
4467 line number, as well as the arguments to the function. The program
4468 counter value is omitted if it is at the beginning of the code for that
4469 line number.
4470
4471 Here is an example of a backtrace. It was made with the command
4472 @samp{bt 3}, so it shows the innermost three frames.
4473
4474 @smallexample
4475 @group
4476 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4477 at builtin.c:993
4478 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4479 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4480 at macro.c:71
4481 (More stack frames follow...)
4482 @end group
4483 @end smallexample
4484
4485 @noindent
4486 The display for frame zero does not begin with a program counter
4487 value, indicating that your program has stopped at the beginning of the
4488 code for line @code{993} of @code{builtin.c}.
4489
4490 @cindex value optimized out, in backtrace
4491 @cindex function call arguments, optimized out
4492 If your program was compiled with optimizations, some compilers will
4493 optimize away arguments passed to functions if those arguments are
4494 never used after the call. Such optimizations generate code that
4495 passes arguments through registers, but doesn't store those arguments
4496 in the stack frame. @value{GDBN} has no way of displaying such
4497 arguments in stack frames other than the innermost one. Here's what
4498 such a backtrace might look like:
4499
4500 @smallexample
4501 @group
4502 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4503 at builtin.c:993
4504 #1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4505 #2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4506 at macro.c:71
4507 (More stack frames follow...)
4508 @end group
4509 @end smallexample
4510
4511 @noindent
4512 The values of arguments that were not saved in their stack frames are
4513 shown as @samp{<value optimized out>}.
4514
4515 If you need to display the values of such optimized-out arguments,
4516 either deduce that from other variables whose values depend on the one
4517 you are interested in, or recompile without optimizations.
4518
4519 @cindex backtrace beyond @code{main} function
4520 @cindex program entry point
4521 @cindex startup code, and backtrace
4522 Most programs have a standard user entry point---a place where system
4523 libraries and startup code transition into user code. For C this is
4524 @code{main}@footnote{
4525 Note that embedded programs (the so-called ``free-standing''
4526 environment) are not required to have a @code{main} function as the
4527 entry point. They could even have multiple entry points.}.
4528 When @value{GDBN} finds the entry function in a backtrace
4529 it will terminate the backtrace, to avoid tracing into highly
4530 system-specific (and generally uninteresting) code.
4531
4532 If you need to examine the startup code, or limit the number of levels
4533 in a backtrace, you can change this behavior:
4534
4535 @table @code
4536 @item set backtrace past-main
4537 @itemx set backtrace past-main on
4538 @kindex set backtrace
4539 Backtraces will continue past the user entry point.
4540
4541 @item set backtrace past-main off
4542 Backtraces will stop when they encounter the user entry point. This is the
4543 default.
4544
4545 @item show backtrace past-main
4546 @kindex show backtrace
4547 Display the current user entry point backtrace policy.
4548
4549 @item set backtrace past-entry
4550 @itemx set backtrace past-entry on
4551 Backtraces will continue past the internal entry point of an application.
4552 This entry point is encoded by the linker when the application is built,
4553 and is likely before the user entry point @code{main} (or equivalent) is called.
4554
4555 @item set backtrace past-entry off
4556 Backtraces will stop when they encouter the internal entry point of an
4557 application. This is the default.
4558
4559 @item show backtrace past-entry
4560 Display the current internal entry point backtrace policy.
4561
4562 @item set backtrace limit @var{n}
4563 @itemx set backtrace limit 0
4564 @cindex backtrace limit
4565 Limit the backtrace to @var{n} levels. A value of zero means
4566 unlimited.
4567
4568 @item show backtrace limit
4569 Display the current limit on backtrace levels.
4570 @end table
4571
4572 @node Selection
4573 @section Selecting a frame
4574
4575 Most commands for examining the stack and other data in your program work on
4576 whichever stack frame is selected at the moment. Here are the commands for
4577 selecting a stack frame; all of them finish by printing a brief description
4578 of the stack frame just selected.
4579
4580 @table @code
4581 @kindex frame@r{, selecting}
4582 @kindex f @r{(@code{frame})}
4583 @item frame @var{n}
4584 @itemx f @var{n}
4585 Select frame number @var{n}. Recall that frame zero is the innermost
4586 (currently executing) frame, frame one is the frame that called the
4587 innermost one, and so on. The highest-numbered frame is the one for
4588 @code{main}.
4589
4590 @item frame @var{addr}
4591 @itemx f @var{addr}
4592 Select the frame at address @var{addr}. This is useful mainly if the
4593 chaining of stack frames has been damaged by a bug, making it
4594 impossible for @value{GDBN} to assign numbers properly to all frames. In
4595 addition, this can be useful when your program has multiple stacks and
4596 switches between them.
4597
4598 On the SPARC architecture, @code{frame} needs two addresses to
4599 select an arbitrary frame: a frame pointer and a stack pointer.
4600
4601 On the MIPS and Alpha architecture, it needs two addresses: a stack
4602 pointer and a program counter.
4603
4604 On the 29k architecture, it needs three addresses: a register stack
4605 pointer, a program counter, and a memory stack pointer.
4606
4607 @kindex up
4608 @item up @var{n}
4609 Move @var{n} frames up the stack. For positive numbers @var{n}, this
4610 advances toward the outermost frame, to higher frame numbers, to frames
4611 that have existed longer. @var{n} defaults to one.
4612
4613 @kindex down
4614 @kindex do @r{(@code{down})}
4615 @item down @var{n}
4616 Move @var{n} frames down the stack. For positive numbers @var{n}, this
4617 advances toward the innermost frame, to lower frame numbers, to frames
4618 that were created more recently. @var{n} defaults to one. You may
4619 abbreviate @code{down} as @code{do}.
4620 @end table
4621
4622 All of these commands end by printing two lines of output describing the
4623 frame. The first line shows the frame number, the function name, the
4624 arguments, and the source file and line number of execution in that
4625 frame. The second line shows the text of that source line.
4626
4627 @need 1000
4628 For example:
4629
4630 @smallexample
4631 @group
4632 (@value{GDBP}) up
4633 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4634 at env.c:10
4635 10 read_input_file (argv[i]);
4636 @end group
4637 @end smallexample
4638
4639 After such a printout, the @code{list} command with no arguments
4640 prints ten lines centered on the point of execution in the frame.
4641 You can also edit the program at the point of execution with your favorite
4642 editing program by typing @code{edit}.
4643 @xref{List, ,Printing source lines},
4644 for details.
4645
4646 @table @code
4647 @kindex down-silently
4648 @kindex up-silently
4649 @item up-silently @var{n}
4650 @itemx down-silently @var{n}
4651 These two commands are variants of @code{up} and @code{down},
4652 respectively; they differ in that they do their work silently, without
4653 causing display of the new frame. They are intended primarily for use
4654 in @value{GDBN} command scripts, where the output might be unnecessary and
4655 distracting.
4656 @end table
4657
4658 @node Frame Info
4659 @section Information about a frame
4660
4661 There are several other commands to print information about the selected
4662 stack frame.
4663
4664 @table @code
4665 @item frame
4666 @itemx f
4667 When used without any argument, this command does not change which
4668 frame is selected, but prints a brief description of the currently
4669 selected stack frame. It can be abbreviated @code{f}. With an
4670 argument, this command is used to select a stack frame.
4671 @xref{Selection, ,Selecting a frame}.
4672
4673 @kindex info frame
4674 @kindex info f @r{(@code{info frame})}
4675 @item info frame
4676 @itemx info f
4677 This command prints a verbose description of the selected stack frame,
4678 including:
4679
4680 @itemize @bullet
4681 @item
4682 the address of the frame
4683 @item
4684 the address of the next frame down (called by this frame)
4685 @item
4686 the address of the next frame up (caller of this frame)
4687 @item
4688 the language in which the source code corresponding to this frame is written
4689 @item
4690 the address of the frame's arguments
4691 @item
4692 the address of the frame's local variables
4693 @item
4694 the program counter saved in it (the address of execution in the caller frame)
4695 @item
4696 which registers were saved in the frame
4697 @end itemize
4698
4699 @noindent The verbose description is useful when
4700 something has gone wrong that has made the stack format fail to fit
4701 the usual conventions.
4702
4703 @item info frame @var{addr}
4704 @itemx info f @var{addr}
4705 Print a verbose description of the frame at address @var{addr}, without
4706 selecting that frame. The selected frame remains unchanged by this
4707 command. This requires the same kind of address (more than one for some
4708 architectures) that you specify in the @code{frame} command.
4709 @xref{Selection, ,Selecting a frame}.
4710
4711 @kindex info args
4712 @item info args
4713 Print the arguments of the selected frame, each on a separate line.
4714
4715 @item info locals
4716 @kindex info locals
4717 Print the local variables of the selected frame, each on a separate
4718 line. These are all variables (declared either static or automatic)
4719 accessible at the point of execution of the selected frame.
4720
4721 @kindex info catch
4722 @cindex catch exceptions, list active handlers
4723 @cindex exception handlers, how to list
4724 @item info catch
4725 Print a list of all the exception handlers that are active in the
4726 current stack frame at the current point of execution. To see other
4727 exception handlers, visit the associated frame (using the @code{up},
4728 @code{down}, or @code{frame} commands); then type @code{info catch}.
4729 @xref{Set Catchpoints, , Setting catchpoints}.
4730
4731 @end table
4732
4733
4734 @node Source
4735 @chapter Examining Source Files
4736
4737 @value{GDBN} can print parts of your program's source, since the debugging
4738 information recorded in the program tells @value{GDBN} what source files were
4739 used to build it. When your program stops, @value{GDBN} spontaneously prints
4740 the line where it stopped. Likewise, when you select a stack frame
4741 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4742 execution in that frame has stopped. You can print other portions of
4743 source files by explicit command.
4744
4745 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
4746 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
4747 @value{GDBN} under @sc{gnu} Emacs}.
4748
4749 @menu
4750 * List:: Printing source lines
4751 * Edit:: Editing source files
4752 * Search:: Searching source files
4753 * Source Path:: Specifying source directories
4754 * Machine Code:: Source and machine code
4755 @end menu
4756
4757 @node List
4758 @section Printing source lines
4759
4760 @kindex list
4761 @kindex l @r{(@code{list})}
4762 To print lines from a source file, use the @code{list} command
4763 (abbreviated @code{l}). By default, ten lines are printed.
4764 There are several ways to specify what part of the file you want to print.
4765
4766 Here are the forms of the @code{list} command most commonly used:
4767
4768 @table @code
4769 @item list @var{linenum}
4770 Print lines centered around line number @var{linenum} in the
4771 current source file.
4772
4773 @item list @var{function}
4774 Print lines centered around the beginning of function
4775 @var{function}.
4776
4777 @item list
4778 Print more lines. If the last lines printed were printed with a
4779 @code{list} command, this prints lines following the last lines
4780 printed; however, if the last line printed was a solitary line printed
4781 as part of displaying a stack frame (@pxref{Stack, ,Examining the
4782 Stack}), this prints lines centered around that line.
4783
4784 @item list -
4785 Print lines just before the lines last printed.
4786 @end table
4787
4788 @cindex @code{list}, how many lines to display
4789 By default, @value{GDBN} prints ten source lines with any of these forms of
4790 the @code{list} command. You can change this using @code{set listsize}:
4791
4792 @table @code
4793 @kindex set listsize
4794 @item set listsize @var{count}
4795 Make the @code{list} command display @var{count} source lines (unless
4796 the @code{list} argument explicitly specifies some other number).
4797
4798 @kindex show listsize
4799 @item show listsize
4800 Display the number of lines that @code{list} prints.
4801 @end table
4802
4803 Repeating a @code{list} command with @key{RET} discards the argument,
4804 so it is equivalent to typing just @code{list}. This is more useful
4805 than listing the same lines again. An exception is made for an
4806 argument of @samp{-}; that argument is preserved in repetition so that
4807 each repetition moves up in the source file.
4808
4809 @cindex linespec
4810 In general, the @code{list} command expects you to supply zero, one or two
4811 @dfn{linespecs}. Linespecs specify source lines; there are several ways
4812 of writing them, but the effect is always to specify some source line.
4813 Here is a complete description of the possible arguments for @code{list}:
4814
4815 @table @code
4816 @item list @var{linespec}
4817 Print lines centered around the line specified by @var{linespec}.
4818
4819 @item list @var{first},@var{last}
4820 Print lines from @var{first} to @var{last}. Both arguments are
4821 linespecs.
4822
4823 @item list ,@var{last}
4824 Print lines ending with @var{last}.
4825
4826 @item list @var{first},
4827 Print lines starting with @var{first}.
4828
4829 @item list +
4830 Print lines just after the lines last printed.
4831
4832 @item list -
4833 Print lines just before the lines last printed.
4834
4835 @item list
4836 As described in the preceding table.
4837 @end table
4838
4839 Here are the ways of specifying a single source line---all the
4840 kinds of linespec.
4841
4842 @table @code
4843 @item @var{number}
4844 Specifies line @var{number} of the current source file.
4845 When a @code{list} command has two linespecs, this refers to
4846 the same source file as the first linespec.
4847
4848 @item +@var{offset}
4849 Specifies the line @var{offset} lines after the last line printed.
4850 When used as the second linespec in a @code{list} command that has
4851 two, this specifies the line @var{offset} lines down from the
4852 first linespec.
4853
4854 @item -@var{offset}
4855 Specifies the line @var{offset} lines before the last line printed.
4856
4857 @item @var{filename}:@var{number}
4858 Specifies line @var{number} in the source file @var{filename}.
4859
4860 @item @var{function}
4861 Specifies the line that begins the body of the function @var{function}.
4862 For example: in C, this is the line with the open brace.
4863
4864 @item @var{filename}:@var{function}
4865 Specifies the line of the open-brace that begins the body of the
4866 function @var{function} in the file @var{filename}. You only need the
4867 file name with a function name to avoid ambiguity when there are
4868 identically named functions in different source files.
4869
4870 @item *@var{address}
4871 Specifies the line containing the program address @var{address}.
4872 @var{address} may be any expression.
4873 @end table
4874
4875 @node Edit
4876 @section Editing source files
4877 @cindex editing source files
4878
4879 @kindex edit
4880 @kindex e @r{(@code{edit})}
4881 To edit the lines in a source file, use the @code{edit} command.
4882 The editing program of your choice
4883 is invoked with the current line set to
4884 the active line in the program.
4885 Alternatively, there are several ways to specify what part of the file you
4886 want to print if you want to see other parts of the program.
4887
4888 Here are the forms of the @code{edit} command most commonly used:
4889
4890 @table @code
4891 @item edit
4892 Edit the current source file at the active line number in the program.
4893
4894 @item edit @var{number}
4895 Edit the current source file with @var{number} as the active line number.
4896
4897 @item edit @var{function}
4898 Edit the file containing @var{function} at the beginning of its definition.
4899
4900 @item edit @var{filename}:@var{number}
4901 Specifies line @var{number} in the source file @var{filename}.
4902
4903 @item edit @var{filename}:@var{function}
4904 Specifies the line that begins the body of the
4905 function @var{function} in the file @var{filename}. You only need the
4906 file name with a function name to avoid ambiguity when there are
4907 identically named functions in different source files.
4908
4909 @item edit *@var{address}
4910 Specifies the line containing the program address @var{address}.
4911 @var{address} may be any expression.
4912 @end table
4913
4914 @subsection Choosing your editor
4915 You can customize @value{GDBN} to use any editor you want
4916 @footnote{
4917 The only restriction is that your editor (say @code{ex}), recognizes the
4918 following command-line syntax:
4919 @smallexample
4920 ex +@var{number} file
4921 @end smallexample
4922 The optional numeric value +@var{number} specifies the number of the line in
4923 the file where to start editing.}.
4924 By default, it is @file{@value{EDITOR}}, but you can change this
4925 by setting the environment variable @code{EDITOR} before using
4926 @value{GDBN}. For example, to configure @value{GDBN} to use the
4927 @code{vi} editor, you could use these commands with the @code{sh} shell:
4928 @smallexample
4929 EDITOR=/usr/bin/vi
4930 export EDITOR
4931 gdb @dots{}
4932 @end smallexample
4933 or in the @code{csh} shell,
4934 @smallexample
4935 setenv EDITOR /usr/bin/vi
4936 gdb @dots{}
4937 @end smallexample
4938
4939 @node Search
4940 @section Searching source files
4941 @cindex searching source files
4942
4943 There are two commands for searching through the current source file for a
4944 regular expression.
4945
4946 @table @code
4947 @kindex search
4948 @kindex forward-search
4949 @item forward-search @var{regexp}
4950 @itemx search @var{regexp}
4951 The command @samp{forward-search @var{regexp}} checks each line,
4952 starting with the one following the last line listed, for a match for
4953 @var{regexp}. It lists the line that is found. You can use the
4954 synonym @samp{search @var{regexp}} or abbreviate the command name as
4955 @code{fo}.
4956
4957 @kindex reverse-search
4958 @item reverse-search @var{regexp}
4959 The command @samp{reverse-search @var{regexp}} checks each line, starting
4960 with the one before the last line listed and going backward, for a match
4961 for @var{regexp}. It lists the line that is found. You can abbreviate
4962 this command as @code{rev}.
4963 @end table
4964
4965 @node Source Path
4966 @section Specifying source directories
4967
4968 @cindex source path
4969 @cindex directories for source files
4970 Executable programs sometimes do not record the directories of the source
4971 files from which they were compiled, just the names. Even when they do,
4972 the directories could be moved between the compilation and your debugging
4973 session. @value{GDBN} has a list of directories to search for source files;
4974 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4975 it tries all the directories in the list, in the order they are present
4976 in the list, until it finds a file with the desired name.
4977
4978 For example, suppose an executable references the file
4979 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4980 @file{/mnt/cross}. The file is first looked up literally; if this
4981 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4982 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4983 message is printed. @value{GDBN} does not look up the parts of the
4984 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4985 Likewise, the subdirectories of the source path are not searched: if
4986 the source path is @file{/mnt/cross}, and the binary refers to
4987 @file{foo.c}, @value{GDBN} would not find it under
4988 @file{/mnt/cross/usr/src/foo-1.0/lib}.
4989
4990 Plain file names, relative file names with leading directories, file
4991 names containing dots, etc.@: are all treated as described above; for
4992 instance, if the source path is @file{/mnt/cross}, and the source file
4993 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4994 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4995 that---@file{/mnt/cross/foo.c}.
4996
4997 Note that the executable search path is @emph{not} used to locate the
4998 source files. Neither is the current working directory, unless it
4999 happens to be in the source path.
5000
5001 Whenever you reset or rearrange the source path, @value{GDBN} clears out
5002 any information it has cached about where source files are found and where
5003 each line is in the file.
5004
5005 @kindex directory
5006 @kindex dir
5007 When you start @value{GDBN}, its source path includes only @samp{cdir}
5008 and @samp{cwd}, in that order.
5009 To add other directories, use the @code{directory} command.
5010
5011 @table @code
5012 @item directory @var{dirname} @dots{}
5013 @item dir @var{dirname} @dots{}
5014 Add directory @var{dirname} to the front of the source path. Several
5015 directory names may be given to this command, separated by @samp{:}
5016 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5017 part of absolute file names) or
5018 whitespace. You may specify a directory that is already in the source
5019 path; this moves it forward, so @value{GDBN} searches it sooner.
5020
5021 @kindex cdir
5022 @kindex cwd
5023 @vindex $cdir@r{, convenience variable}
5024 @vindex $cwdr@r{, convenience variable}
5025 @cindex compilation directory
5026 @cindex current directory
5027 @cindex working directory
5028 @cindex directory, current
5029 @cindex directory, compilation
5030 You can use the string @samp{$cdir} to refer to the compilation
5031 directory (if one is recorded), and @samp{$cwd} to refer to the current
5032 working directory. @samp{$cwd} is not the same as @samp{.}---the former
5033 tracks the current working directory as it changes during your @value{GDBN}
5034 session, while the latter is immediately expanded to the current
5035 directory at the time you add an entry to the source path.
5036
5037 @item directory
5038 Reset the source path to empty again. This requires confirmation.
5039
5040 @c RET-repeat for @code{directory} is explicitly disabled, but since
5041 @c repeating it would be a no-op we do not say that. (thanks to RMS)
5042
5043 @item show directories
5044 @kindex show directories
5045 Print the source path: show which directories it contains.
5046 @end table
5047
5048 If your source path is cluttered with directories that are no longer of
5049 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5050 versions of source. You can correct the situation as follows:
5051
5052 @enumerate
5053 @item
5054 Use @code{directory} with no argument to reset the source path to empty.
5055
5056 @item
5057 Use @code{directory} with suitable arguments to reinstall the
5058 directories you want in the source path. You can add all the
5059 directories in one command.
5060 @end enumerate
5061
5062 @node Machine Code
5063 @section Source and machine code
5064 @cindex source line and its code address
5065
5066 You can use the command @code{info line} to map source lines to program
5067 addresses (and vice versa), and the command @code{disassemble} to display
5068 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
5069 mode, the @code{info line} command causes the arrow to point to the
5070 line specified. Also, @code{info line} prints addresses in symbolic form as
5071 well as hex.
5072
5073 @table @code
5074 @kindex info line
5075 @item info line @var{linespec}
5076 Print the starting and ending addresses of the compiled code for
5077 source line @var{linespec}. You can specify source lines in any of
5078 the ways understood by the @code{list} command (@pxref{List, ,Printing
5079 source lines}).
5080 @end table
5081
5082 For example, we can use @code{info line} to discover the location of
5083 the object code for the first line of function
5084 @code{m4_changequote}:
5085
5086 @c FIXME: I think this example should also show the addresses in
5087 @c symbolic form, as they usually would be displayed.
5088 @smallexample
5089 (@value{GDBP}) info line m4_changequote
5090 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5091 @end smallexample
5092
5093 @noindent
5094 @cindex code address and its source line
5095 We can also inquire (using @code{*@var{addr}} as the form for
5096 @var{linespec}) what source line covers a particular address:
5097 @smallexample
5098 (@value{GDBP}) info line *0x63ff
5099 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5100 @end smallexample
5101
5102 @cindex @code{$_} and @code{info line}
5103 @cindex @code{x} command, default address
5104 @kindex x@r{(examine), and} info line
5105 After @code{info line}, the default address for the @code{x} command
5106 is changed to the starting address of the line, so that @samp{x/i} is
5107 sufficient to begin examining the machine code (@pxref{Memory,
5108 ,Examining memory}). Also, this address is saved as the value of the
5109 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
5110 variables}).
5111
5112 @table @code
5113 @kindex disassemble
5114 @cindex assembly instructions
5115 @cindex instructions, assembly
5116 @cindex machine instructions
5117 @cindex listing machine instructions
5118 @item disassemble
5119 This specialized command dumps a range of memory as machine
5120 instructions. The default memory range is the function surrounding the
5121 program counter of the selected frame. A single argument to this
5122 command is a program counter value; @value{GDBN} dumps the function
5123 surrounding this value. Two arguments specify a range of addresses
5124 (first inclusive, second exclusive) to dump.
5125 @end table
5126
5127 The following example shows the disassembly of a range of addresses of
5128 HP PA-RISC 2.0 code:
5129
5130 @smallexample
5131 (@value{GDBP}) disas 0x32c4 0x32e4
5132 Dump of assembler code from 0x32c4 to 0x32e4:
5133 0x32c4 <main+204>: addil 0,dp
5134 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
5135 0x32cc <main+212>: ldil 0x3000,r31
5136 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
5137 0x32d4 <main+220>: ldo 0(r31),rp
5138 0x32d8 <main+224>: addil -0x800,dp
5139 0x32dc <main+228>: ldo 0x588(r1),r26
5140 0x32e0 <main+232>: ldil 0x3000,r31
5141 End of assembler dump.
5142 @end smallexample
5143
5144 Some architectures have more than one commonly-used set of instruction
5145 mnemonics or other syntax.
5146
5147 For programs that were dynamically linked and use shared libraries,
5148 instructions that call functions or branch to locations in the shared
5149 libraries might show a seemingly bogus location---it's actually a
5150 location of the relocation table. On some architectures, @value{GDBN}
5151 might be able to resolve these to actual function names.
5152
5153 @table @code
5154 @kindex set disassembly-flavor
5155 @cindex Intel disassembly flavor
5156 @cindex AT&T disassembly flavor
5157 @item set disassembly-flavor @var{instruction-set}
5158 Select the instruction set to use when disassembling the
5159 program via the @code{disassemble} or @code{x/i} commands.
5160
5161 Currently this command is only defined for the Intel x86 family. You
5162 can set @var{instruction-set} to either @code{intel} or @code{att}.
5163 The default is @code{att}, the AT&T flavor used by default by Unix
5164 assemblers for x86-based targets.
5165
5166 @kindex show disassembly-flavor
5167 @item show disassembly-flavor
5168 Show the current setting of the disassembly flavor.
5169 @end table
5170
5171
5172 @node Data
5173 @chapter Examining Data
5174
5175 @cindex printing data
5176 @cindex examining data
5177 @kindex print
5178 @kindex inspect
5179 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
5180 @c document because it is nonstandard... Under Epoch it displays in a
5181 @c different window or something like that.
5182 The usual way to examine data in your program is with the @code{print}
5183 command (abbreviated @code{p}), or its synonym @code{inspect}. It
5184 evaluates and prints the value of an expression of the language your
5185 program is written in (@pxref{Languages, ,Using @value{GDBN} with
5186 Different Languages}).
5187
5188 @table @code
5189 @item print @var{expr}
5190 @itemx print /@var{f} @var{expr}
5191 @var{expr} is an expression (in the source language). By default the
5192 value of @var{expr} is printed in a format appropriate to its data type;
5193 you can choose a different format by specifying @samp{/@var{f}}, where
5194 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
5195 formats}.
5196
5197 @item print
5198 @itemx print /@var{f}
5199 @cindex reprint the last value
5200 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
5201 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
5202 conveniently inspect the same value in an alternative format.
5203 @end table
5204
5205 A more low-level way of examining data is with the @code{x} command.
5206 It examines data in memory at a specified address and prints it in a
5207 specified format. @xref{Memory, ,Examining memory}.
5208
5209 If you are interested in information about types, or about how the
5210 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5211 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
5212 Table}.
5213
5214 @menu
5215 * Expressions:: Expressions
5216 * Variables:: Program variables
5217 * Arrays:: Artificial arrays
5218 * Output Formats:: Output formats
5219 * Memory:: Examining memory
5220 * Auto Display:: Automatic display
5221 * Print Settings:: Print settings
5222 * Value History:: Value history
5223 * Convenience Vars:: Convenience variables
5224 * Registers:: Registers
5225 * Floating Point Hardware:: Floating point hardware
5226 * Vector Unit:: Vector Unit
5227 * OS Information:: Auxiliary data provided by operating system
5228 * Memory Region Attributes:: Memory region attributes
5229 * Dump/Restore Files:: Copy between memory and a file
5230 * Core File Generation:: Cause a program dump its core
5231 * Character Sets:: Debugging programs that use a different
5232 character set than GDB does
5233 * Caching Remote Data:: Data caching for remote targets
5234 @end menu
5235
5236 @node Expressions
5237 @section Expressions
5238
5239 @cindex expressions
5240 @code{print} and many other @value{GDBN} commands accept an expression and
5241 compute its value. Any kind of constant, variable or operator defined
5242 by the programming language you are using is valid in an expression in
5243 @value{GDBN}. This includes conditional expressions, function calls,
5244 casts, and string constants. It also includes preprocessor macros, if
5245 you compiled your program to include this information; see
5246 @ref{Compilation}.
5247
5248 @cindex arrays in expressions
5249 @value{GDBN} supports array constants in expressions input by
5250 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5251 you can use the command @code{print @{1, 2, 3@}} to build up an array in
5252 memory that is @code{malloc}ed in the target program.
5253
5254 Because C is so widespread, most of the expressions shown in examples in
5255 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5256 Languages}, for information on how to use expressions in other
5257 languages.
5258
5259 In this section, we discuss operators that you can use in @value{GDBN}
5260 expressions regardless of your programming language.
5261
5262 @cindex casts, in expressions
5263 Casts are supported in all languages, not just in C, because it is so
5264 useful to cast a number into a pointer in order to examine a structure
5265 at that address in memory.
5266 @c FIXME: casts supported---Mod2 true?
5267
5268 @value{GDBN} supports these operators, in addition to those common
5269 to programming languages:
5270
5271 @table @code
5272 @item @@
5273 @samp{@@} is a binary operator for treating parts of memory as arrays.
5274 @xref{Arrays, ,Artificial arrays}, for more information.
5275
5276 @item ::
5277 @samp{::} allows you to specify a variable in terms of the file or
5278 function where it is defined. @xref{Variables, ,Program variables}.
5279
5280 @cindex @{@var{type}@}
5281 @cindex type casting memory
5282 @cindex memory, viewing as typed object
5283 @cindex casts, to view memory
5284 @item @{@var{type}@} @var{addr}
5285 Refers to an object of type @var{type} stored at address @var{addr} in
5286 memory. @var{addr} may be any expression whose value is an integer or
5287 pointer (but parentheses are required around binary operators, just as in
5288 a cast). This construct is allowed regardless of what kind of data is
5289 normally supposed to reside at @var{addr}.
5290 @end table
5291
5292 @node Variables
5293 @section Program variables
5294
5295 The most common kind of expression to use is the name of a variable
5296 in your program.
5297
5298 Variables in expressions are understood in the selected stack frame
5299 (@pxref{Selection, ,Selecting a frame}); they must be either:
5300
5301 @itemize @bullet
5302 @item
5303 global (or file-static)
5304 @end itemize
5305
5306 @noindent or
5307
5308 @itemize @bullet
5309 @item
5310 visible according to the scope rules of the
5311 programming language from the point of execution in that frame
5312 @end itemize
5313
5314 @noindent This means that in the function
5315
5316 @smallexample
5317 foo (a)
5318 int a;
5319 @{
5320 bar (a);
5321 @{
5322 int b = test ();
5323 bar (b);
5324 @}
5325 @}
5326 @end smallexample
5327
5328 @noindent
5329 you can examine and use the variable @code{a} whenever your program is
5330 executing within the function @code{foo}, but you can only use or
5331 examine the variable @code{b} while your program is executing inside
5332 the block where @code{b} is declared.
5333
5334 @cindex variable name conflict
5335 There is an exception: you can refer to a variable or function whose
5336 scope is a single source file even if the current execution point is not
5337 in this file. But it is possible to have more than one such variable or
5338 function with the same name (in different source files). If that
5339 happens, referring to that name has unpredictable effects. If you wish,
5340 you can specify a static variable in a particular function or file,
5341 using the colon-colon (@code{::}) notation:
5342
5343 @cindex colon-colon, context for variables/functions
5344 @iftex
5345 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
5346 @cindex @code{::}, context for variables/functions
5347 @end iftex
5348 @smallexample
5349 @var{file}::@var{variable}
5350 @var{function}::@var{variable}
5351 @end smallexample
5352
5353 @noindent
5354 Here @var{file} or @var{function} is the name of the context for the
5355 static @var{variable}. In the case of file names, you can use quotes to
5356 make sure @value{GDBN} parses the file name as a single word---for example,
5357 to print a global value of @code{x} defined in @file{f2.c}:
5358
5359 @smallexample
5360 (@value{GDBP}) p 'f2.c'::x
5361 @end smallexample
5362
5363 @cindex C@t{++} scope resolution
5364 This use of @samp{::} is very rarely in conflict with the very similar
5365 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
5366 scope resolution operator in @value{GDBN} expressions.
5367 @c FIXME: Um, so what happens in one of those rare cases where it's in
5368 @c conflict?? --mew
5369
5370 @cindex wrong values
5371 @cindex variable values, wrong
5372 @cindex function entry/exit, wrong values of variables
5373 @cindex optimized code, wrong values of variables
5374 @quotation
5375 @emph{Warning:} Occasionally, a local variable may appear to have the
5376 wrong value at certain points in a function---just after entry to a new
5377 scope, and just before exit.
5378 @end quotation
5379 You may see this problem when you are stepping by machine instructions.
5380 This is because, on most machines, it takes more than one instruction to
5381 set up a stack frame (including local variable definitions); if you are
5382 stepping by machine instructions, variables may appear to have the wrong
5383 values until the stack frame is completely built. On exit, it usually
5384 also takes more than one machine instruction to destroy a stack frame;
5385 after you begin stepping through that group of instructions, local
5386 variable definitions may be gone.
5387
5388 This may also happen when the compiler does significant optimizations.
5389 To be sure of always seeing accurate values, turn off all optimization
5390 when compiling.
5391
5392 @cindex ``No symbol "foo" in current context''
5393 Another possible effect of compiler optimizations is to optimize
5394 unused variables out of existence, or assign variables to registers (as
5395 opposed to memory addresses). Depending on the support for such cases
5396 offered by the debug info format used by the compiler, @value{GDBN}
5397 might not be able to display values for such local variables. If that
5398 happens, @value{GDBN} will print a message like this:
5399
5400 @smallexample
5401 No symbol "foo" in current context.
5402 @end smallexample
5403
5404 To solve such problems, either recompile without optimizations, or use a
5405 different debug info format, if the compiler supports several such
5406 formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
5407 usually supports the @option{-gstabs+} option. @option{-gstabs+}
5408 produces debug info in a format that is superior to formats such as
5409 COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5410 an effective form for debug info. @xref{Debugging Options,,Options
5411 for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
5412 @xref{C, , Debugging C++}, for more info about debug info formats
5413 that are best suited to C@t{++} programs.
5414
5415 If you ask to print an object whose contents are unknown to
5416 @value{GDBN}, e.g., because its data type is not completely specified
5417 by the debug information, @value{GDBN} will say @samp{<incomplete
5418 type>}. @xref{Symbols, incomplete type}, for more about this.
5419
5420 @node Arrays
5421 @section Artificial arrays
5422
5423 @cindex artificial array
5424 @cindex arrays
5425 @kindex @@@r{, referencing memory as an array}
5426 It is often useful to print out several successive objects of the
5427 same type in memory; a section of an array, or an array of
5428 dynamically determined size for which only a pointer exists in the
5429 program.
5430
5431 You can do this by referring to a contiguous span of memory as an
5432 @dfn{artificial array}, using the binary operator @samp{@@}. The left
5433 operand of @samp{@@} should be the first element of the desired array
5434 and be an individual object. The right operand should be the desired length
5435 of the array. The result is an array value whose elements are all of
5436 the type of the left argument. The first element is actually the left
5437 argument; the second element comes from bytes of memory immediately
5438 following those that hold the first element, and so on. Here is an
5439 example. If a program says
5440
5441 @smallexample
5442 int *array = (int *) malloc (len * sizeof (int));
5443 @end smallexample
5444
5445 @noindent
5446 you can print the contents of @code{array} with
5447
5448 @smallexample
5449 p *array@@len
5450 @end smallexample
5451
5452 The left operand of @samp{@@} must reside in memory. Array values made
5453 with @samp{@@} in this way behave just like other arrays in terms of
5454 subscripting, and are coerced to pointers when used in expressions.
5455 Artificial arrays most often appear in expressions via the value history
5456 (@pxref{Value History, ,Value history}), after printing one out.
5457
5458 Another way to create an artificial array is to use a cast.
5459 This re-interprets a value as if it were an array.
5460 The value need not be in memory:
5461 @smallexample
5462 (@value{GDBP}) p/x (short[2])0x12345678
5463 $1 = @{0x1234, 0x5678@}
5464 @end smallexample
5465
5466 As a convenience, if you leave the array length out (as in
5467 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
5468 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
5469 @smallexample
5470 (@value{GDBP}) p/x (short[])0x12345678
5471 $2 = @{0x1234, 0x5678@}
5472 @end smallexample
5473
5474 Sometimes the artificial array mechanism is not quite enough; in
5475 moderately complex data structures, the elements of interest may not
5476 actually be adjacent---for example, if you are interested in the values
5477 of pointers in an array. One useful work-around in this situation is
5478 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5479 variables}) as a counter in an expression that prints the first
5480 interesting value, and then repeat that expression via @key{RET}. For
5481 instance, suppose you have an array @code{dtab} of pointers to
5482 structures, and you are interested in the values of a field @code{fv}
5483 in each structure. Here is an example of what you might type:
5484
5485 @smallexample
5486 set $i = 0
5487 p dtab[$i++]->fv
5488 @key{RET}
5489 @key{RET}
5490 @dots{}
5491 @end smallexample
5492
5493 @node Output Formats
5494 @section Output formats
5495
5496 @cindex formatted output
5497 @cindex output formats
5498 By default, @value{GDBN} prints a value according to its data type. Sometimes
5499 this is not what you want. For example, you might want to print a number
5500 in hex, or a pointer in decimal. Or you might want to view data in memory
5501 at a certain address as a character string or as an instruction. To do
5502 these things, specify an @dfn{output format} when you print a value.
5503
5504 The simplest use of output formats is to say how to print a value
5505 already computed. This is done by starting the arguments of the
5506 @code{print} command with a slash and a format letter. The format
5507 letters supported are:
5508
5509 @table @code
5510 @item x
5511 Regard the bits of the value as an integer, and print the integer in
5512 hexadecimal.
5513
5514 @item d
5515 Print as integer in signed decimal.
5516
5517 @item u
5518 Print as integer in unsigned decimal.
5519
5520 @item o
5521 Print as integer in octal.
5522
5523 @item t
5524 Print as integer in binary. The letter @samp{t} stands for ``two''.
5525 @footnote{@samp{b} cannot be used because these format letters are also
5526 used with the @code{x} command, where @samp{b} stands for ``byte'';
5527 see @ref{Memory,,Examining memory}.}
5528
5529 @item a
5530 @cindex unknown address, locating
5531 @cindex locate address
5532 Print as an address, both absolute in hexadecimal and as an offset from
5533 the nearest preceding symbol. You can use this format used to discover
5534 where (in what function) an unknown address is located:
5535
5536 @smallexample
5537 (@value{GDBP}) p/a 0x54320
5538 $3 = 0x54320 <_initialize_vx+396>
5539 @end smallexample
5540
5541 @noindent
5542 The command @code{info symbol 0x54320} yields similar results.
5543 @xref{Symbols, info symbol}.
5544
5545 @item c
5546 Regard as an integer and print it as a character constant. This
5547 prints both the numerical value and its character representation. The
5548 character representation is replaced with the octal escape @samp{\nnn}
5549 for characters outside the 7-bit @sc{ascii} range.
5550
5551 @item f
5552 Regard the bits of the value as a floating point number and print
5553 using typical floating point syntax.
5554 @end table
5555
5556 For example, to print the program counter in hex (@pxref{Registers}), type
5557
5558 @smallexample
5559 p/x $pc
5560 @end smallexample
5561
5562 @noindent
5563 Note that no space is required before the slash; this is because command
5564 names in @value{GDBN} cannot contain a slash.
5565
5566 To reprint the last value in the value history with a different format,
5567 you can use the @code{print} command with just a format and no
5568 expression. For example, @samp{p/x} reprints the last value in hex.
5569
5570 @node Memory
5571 @section Examining memory
5572
5573 You can use the command @code{x} (for ``examine'') to examine memory in
5574 any of several formats, independently of your program's data types.
5575
5576 @cindex examining memory
5577 @table @code
5578 @kindex x @r{(examine memory)}
5579 @item x/@var{nfu} @var{addr}
5580 @itemx x @var{addr}
5581 @itemx x
5582 Use the @code{x} command to examine memory.
5583 @end table
5584
5585 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5586 much memory to display and how to format it; @var{addr} is an
5587 expression giving the address where you want to start displaying memory.
5588 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5589 Several commands set convenient defaults for @var{addr}.
5590
5591 @table @r
5592 @item @var{n}, the repeat count
5593 The repeat count is a decimal integer; the default is 1. It specifies
5594 how much memory (counting by units @var{u}) to display.
5595 @c This really is **decimal**; unaffected by 'set radix' as of GDB
5596 @c 4.1.2.
5597
5598 @item @var{f}, the display format
5599 The display format is one of the formats used by @code{print}
5600 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5601 @samp{f}), and in addition @samp{s} (for null-terminated strings) and
5602 @samp{i} (for machine instructions). The default is @samp{x}
5603 (hexadecimal) initially. The default changes each time you use either
5604 @code{x} or @code{print}.
5605
5606 @item @var{u}, the unit size
5607 The unit size is any of
5608
5609 @table @code
5610 @item b
5611 Bytes.
5612 @item h
5613 Halfwords (two bytes).
5614 @item w
5615 Words (four bytes). This is the initial default.
5616 @item g
5617 Giant words (eight bytes).
5618 @end table
5619
5620 Each time you specify a unit size with @code{x}, that size becomes the
5621 default unit the next time you use @code{x}. (For the @samp{s} and
5622 @samp{i} formats, the unit size is ignored and is normally not written.)
5623
5624 @item @var{addr}, starting display address
5625 @var{addr} is the address where you want @value{GDBN} to begin displaying
5626 memory. The expression need not have a pointer value (though it may);
5627 it is always interpreted as an integer address of a byte of memory.
5628 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
5629 @var{addr} is usually just after the last address examined---but several
5630 other commands also set the default address: @code{info breakpoints} (to
5631 the address of the last breakpoint listed), @code{info line} (to the
5632 starting address of a line), and @code{print} (if you use it to display
5633 a value from memory).
5634 @end table
5635
5636 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5637 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5638 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5639 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
5640 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
5641
5642 Since the letters indicating unit sizes are all distinct from the
5643 letters specifying output formats, you do not have to remember whether
5644 unit size or format comes first; either order works. The output
5645 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5646 (However, the count @var{n} must come first; @samp{wx4} does not work.)
5647
5648 Even though the unit size @var{u} is ignored for the formats @samp{s}
5649 and @samp{i}, you might still want to use a count @var{n}; for example,
5650 @samp{3i} specifies that you want to see three machine instructions,
5651 including any operands. The command @code{disassemble} gives an
5652 alternative way of inspecting machine instructions; see @ref{Machine
5653 Code,,Source and machine code}.
5654
5655 All the defaults for the arguments to @code{x} are designed to make it
5656 easy to continue scanning memory with minimal specifications each time
5657 you use @code{x}. For example, after you have inspected three machine
5658 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5659 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5660 the repeat count @var{n} is used again; the other arguments default as
5661 for successive uses of @code{x}.
5662
5663 @cindex @code{$_}, @code{$__}, and value history
5664 The addresses and contents printed by the @code{x} command are not saved
5665 in the value history because there is often too much of them and they
5666 would get in the way. Instead, @value{GDBN} makes these values available for
5667 subsequent use in expressions as values of the convenience variables
5668 @code{$_} and @code{$__}. After an @code{x} command, the last address
5669 examined is available for use in expressions in the convenience variable
5670 @code{$_}. The contents of that address, as examined, are available in
5671 the convenience variable @code{$__}.
5672
5673 If the @code{x} command has a repeat count, the address and contents saved
5674 are from the last memory unit printed; this is not the same as the last
5675 address printed if several units were printed on the last line of output.
5676
5677 @cindex remote memory comparison
5678 @cindex verify remote memory image
5679 When you are debugging a program running on a remote target machine
5680 (@pxref{Remote}), you may wish to verify the program's image in the
5681 remote machine's memory against the executable file you downloaded to
5682 the target. The @code{compare-sections} command is provided for such
5683 situations.
5684
5685 @table @code
5686 @kindex compare-sections
5687 @item compare-sections @r{[}@var{section-name}@r{]}
5688 Compare the data of a loadable section @var{section-name} in the
5689 executable file of the program being debugged with the same section in
5690 the remote machine's memory, and report any mismatches. With no
5691 arguments, compares all loadable sections. This command's
5692 availability depends on the target's support for the @code{"qCRC"}
5693 remote request.
5694 @end table
5695
5696 @node Auto Display
5697 @section Automatic display
5698 @cindex automatic display
5699 @cindex display of expressions
5700
5701 If you find that you want to print the value of an expression frequently
5702 (to see how it changes), you might want to add it to the @dfn{automatic
5703 display list} so that @value{GDBN} prints its value each time your program stops.
5704 Each expression added to the list is given a number to identify it;
5705 to remove an expression from the list, you specify that number.
5706 The automatic display looks like this:
5707
5708 @smallexample
5709 2: foo = 38
5710 3: bar[5] = (struct hack *) 0x3804
5711 @end smallexample
5712
5713 @noindent
5714 This display shows item numbers, expressions and their current values. As with
5715 displays you request manually using @code{x} or @code{print}, you can
5716 specify the output format you prefer; in fact, @code{display} decides
5717 whether to use @code{print} or @code{x} depending on how elaborate your
5718 format specification is---it uses @code{x} if you specify a unit size,
5719 or one of the two formats (@samp{i} and @samp{s}) that are only
5720 supported by @code{x}; otherwise it uses @code{print}.
5721
5722 @table @code
5723 @kindex display
5724 @item display @var{expr}
5725 Add the expression @var{expr} to the list of expressions to display
5726 each time your program stops. @xref{Expressions, ,Expressions}.
5727
5728 @code{display} does not repeat if you press @key{RET} again after using it.
5729
5730 @item display/@var{fmt} @var{expr}
5731 For @var{fmt} specifying only a display format and not a size or
5732 count, add the expression @var{expr} to the auto-display list but
5733 arrange to display it each time in the specified format @var{fmt}.
5734 @xref{Output Formats,,Output formats}.
5735
5736 @item display/@var{fmt} @var{addr}
5737 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5738 number of units, add the expression @var{addr} as a memory address to
5739 be examined each time your program stops. Examining means in effect
5740 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5741 @end table
5742
5743 For example, @samp{display/i $pc} can be helpful, to see the machine
5744 instruction about to be executed each time execution stops (@samp{$pc}
5745 is a common name for the program counter; @pxref{Registers, ,Registers}).
5746
5747 @table @code
5748 @kindex delete display
5749 @kindex undisplay
5750 @item undisplay @var{dnums}@dots{}
5751 @itemx delete display @var{dnums}@dots{}
5752 Remove item numbers @var{dnums} from the list of expressions to display.
5753
5754 @code{undisplay} does not repeat if you press @key{RET} after using it.
5755 (Otherwise you would just get the error @samp{No display number @dots{}}.)
5756
5757 @kindex disable display
5758 @item disable display @var{dnums}@dots{}
5759 Disable the display of item numbers @var{dnums}. A disabled display
5760 item is not printed automatically, but is not forgotten. It may be
5761 enabled again later.
5762
5763 @kindex enable display
5764 @item enable display @var{dnums}@dots{}
5765 Enable display of item numbers @var{dnums}. It becomes effective once
5766 again in auto display of its expression, until you specify otherwise.
5767
5768 @item display
5769 Display the current values of the expressions on the list, just as is
5770 done when your program stops.
5771
5772 @kindex info display
5773 @item info display
5774 Print the list of expressions previously set up to display
5775 automatically, each one with its item number, but without showing the
5776 values. This includes disabled expressions, which are marked as such.
5777 It also includes expressions which would not be displayed right now
5778 because they refer to automatic variables not currently available.
5779 @end table
5780
5781 @cindex display disabled out of scope
5782 If a display expression refers to local variables, then it does not make
5783 sense outside the lexical context for which it was set up. Such an
5784 expression is disabled when execution enters a context where one of its
5785 variables is not defined. For example, if you give the command
5786 @code{display last_char} while inside a function with an argument
5787 @code{last_char}, @value{GDBN} displays this argument while your program
5788 continues to stop inside that function. When it stops elsewhere---where
5789 there is no variable @code{last_char}---the display is disabled
5790 automatically. The next time your program stops where @code{last_char}
5791 is meaningful, you can enable the display expression once again.
5792
5793 @node Print Settings
5794 @section Print settings
5795
5796 @cindex format options
5797 @cindex print settings
5798 @value{GDBN} provides the following ways to control how arrays, structures,
5799 and symbols are printed.
5800
5801 @noindent
5802 These settings are useful for debugging programs in any language:
5803
5804 @table @code
5805 @kindex set print
5806 @item set print address
5807 @itemx set print address on
5808 @cindex print/don't print memory addresses
5809 @value{GDBN} prints memory addresses showing the location of stack
5810 traces, structure values, pointer values, breakpoints, and so forth,
5811 even when it also displays the contents of those addresses. The default
5812 is @code{on}. For example, this is what a stack frame display looks like with
5813 @code{set print address on}:
5814
5815 @smallexample
5816 @group
5817 (@value{GDBP}) f
5818 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5819 at input.c:530
5820 530 if (lquote != def_lquote)
5821 @end group
5822 @end smallexample
5823
5824 @item set print address off
5825 Do not print addresses when displaying their contents. For example,
5826 this is the same stack frame displayed with @code{set print address off}:
5827
5828 @smallexample
5829 @group
5830 (@value{GDBP}) set print addr off
5831 (@value{GDBP}) f
5832 #0 set_quotes (lq="<<", rq=">>") at input.c:530
5833 530 if (lquote != def_lquote)
5834 @end group
5835 @end smallexample
5836
5837 You can use @samp{set print address off} to eliminate all machine
5838 dependent displays from the @value{GDBN} interface. For example, with
5839 @code{print address off}, you should get the same text for backtraces on
5840 all machines---whether or not they involve pointer arguments.
5841
5842 @kindex show print
5843 @item show print address
5844 Show whether or not addresses are to be printed.
5845 @end table
5846
5847 When @value{GDBN} prints a symbolic address, it normally prints the
5848 closest earlier symbol plus an offset. If that symbol does not uniquely
5849 identify the address (for example, it is a name whose scope is a single
5850 source file), you may need to clarify. One way to do this is with
5851 @code{info line}, for example @samp{info line *0x4537}. Alternately,
5852 you can set @value{GDBN} to print the source file and line number when
5853 it prints a symbolic address:
5854
5855 @table @code
5856 @item set print symbol-filename on
5857 @cindex source file and line of a symbol
5858 @cindex symbol, source file and line
5859 Tell @value{GDBN} to print the source file name and line number of a
5860 symbol in the symbolic form of an address.
5861
5862 @item set print symbol-filename off
5863 Do not print source file name and line number of a symbol. This is the
5864 default.
5865
5866 @item show print symbol-filename
5867 Show whether or not @value{GDBN} will print the source file name and
5868 line number of a symbol in the symbolic form of an address.
5869 @end table
5870
5871 Another situation where it is helpful to show symbol filenames and line
5872 numbers is when disassembling code; @value{GDBN} shows you the line
5873 number and source file that corresponds to each instruction.
5874
5875 Also, you may wish to see the symbolic form only if the address being
5876 printed is reasonably close to the closest earlier symbol:
5877
5878 @table @code
5879 @item set print max-symbolic-offset @var{max-offset}
5880 @cindex maximum value for offset of closest symbol
5881 Tell @value{GDBN} to only display the symbolic form of an address if the
5882 offset between the closest earlier symbol and the address is less than
5883 @var{max-offset}. The default is 0, which tells @value{GDBN}
5884 to always print the symbolic form of an address if any symbol precedes it.
5885
5886 @item show print max-symbolic-offset
5887 Ask how large the maximum offset is that @value{GDBN} prints in a
5888 symbolic address.
5889 @end table
5890
5891 @cindex wild pointer, interpreting
5892 @cindex pointer, finding referent
5893 If you have a pointer and you are not sure where it points, try
5894 @samp{set print symbol-filename on}. Then you can determine the name
5895 and source file location of the variable where it points, using
5896 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5897 For example, here @value{GDBN} shows that a variable @code{ptt} points
5898 at another variable @code{t}, defined in @file{hi2.c}:
5899
5900 @smallexample
5901 (@value{GDBP}) set print symbol-filename on
5902 (@value{GDBP}) p/a ptt
5903 $4 = 0xe008 <t in hi2.c>
5904 @end smallexample
5905
5906 @quotation
5907 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5908 does not show the symbol name and filename of the referent, even with
5909 the appropriate @code{set print} options turned on.
5910 @end quotation
5911
5912 Other settings control how different kinds of objects are printed:
5913
5914 @table @code
5915 @item set print array
5916 @itemx set print array on
5917 @cindex pretty print arrays
5918 Pretty print arrays. This format is more convenient to read,
5919 but uses more space. The default is off.
5920
5921 @item set print array off
5922 Return to compressed format for arrays.
5923
5924 @item show print array
5925 Show whether compressed or pretty format is selected for displaying
5926 arrays.
5927
5928 @cindex print array indexes
5929 @item set print array-indexes
5930 @itemx set print array-indexes on
5931 Print the index of each element when displaying arrays. May be more
5932 convenient to locate a given element in the array or quickly find the
5933 index of a given element in that printed array. The default is off.
5934
5935 @item set print array-indexes off
5936 Stop printing element indexes when displaying arrays.
5937
5938 @item show print array-indexes
5939 Show whether the index of each element is printed when displaying
5940 arrays.
5941
5942 @item set print elements @var{number-of-elements}
5943 @cindex number of array elements to print
5944 @cindex limit on number of printed array elements
5945 Set a limit on how many elements of an array @value{GDBN} will print.
5946 If @value{GDBN} is printing a large array, it stops printing after it has
5947 printed the number of elements set by the @code{set print elements} command.
5948 This limit also applies to the display of strings.
5949 When @value{GDBN} starts, this limit is set to 200.
5950 Setting @var{number-of-elements} to zero means that the printing is unlimited.
5951
5952 @item show print elements
5953 Display the number of elements of a large array that @value{GDBN} will print.
5954 If the number is 0, then the printing is unlimited.
5955
5956 @item set print repeats
5957 @cindex repeated array elements
5958 Set the threshold for suppressing display of repeated array
5959 elelments. When the number of consecutive identical elements of an
5960 array exceeds the threshold, @value{GDBN} prints the string
5961 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
5962 identical repetitions, instead of displaying the identical elements
5963 themselves. Setting the threshold to zero will cause all elements to
5964 be individually printed. The default threshold is 10.
5965
5966 @item show print repeats
5967 Display the current threshold for printing repeated identical
5968 elements.
5969
5970 @item set print null-stop
5971 @cindex @sc{null} elements in arrays
5972 Cause @value{GDBN} to stop printing the characters of an array when the first
5973 @sc{null} is encountered. This is useful when large arrays actually
5974 contain only short strings.
5975 The default is off.
5976
5977 @item show print null-stop
5978 Show whether @value{GDBN} stops printing an array on the first
5979 @sc{null} character.
5980
5981 @item set print pretty on
5982 @cindex print structures in indented form
5983 @cindex indentation in structure display
5984 Cause @value{GDBN} to print structures in an indented format with one member
5985 per line, like this:
5986
5987 @smallexample
5988 @group
5989 $1 = @{
5990 next = 0x0,
5991 flags = @{
5992 sweet = 1,
5993 sour = 1
5994 @},
5995 meat = 0x54 "Pork"
5996 @}
5997 @end group
5998 @end smallexample
5999
6000 @item set print pretty off
6001 Cause @value{GDBN} to print structures in a compact format, like this:
6002
6003 @smallexample
6004 @group
6005 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6006 meat = 0x54 "Pork"@}
6007 @end group
6008 @end smallexample
6009
6010 @noindent
6011 This is the default format.
6012
6013 @item show print pretty
6014 Show which format @value{GDBN} is using to print structures.
6015
6016 @item set print sevenbit-strings on
6017 @cindex eight-bit characters in strings
6018 @cindex octal escapes in strings
6019 Print using only seven-bit characters; if this option is set,
6020 @value{GDBN} displays any eight-bit characters (in strings or
6021 character values) using the notation @code{\}@var{nnn}. This setting is
6022 best if you are working in English (@sc{ascii}) and you use the
6023 high-order bit of characters as a marker or ``meta'' bit.
6024
6025 @item set print sevenbit-strings off
6026 Print full eight-bit characters. This allows the use of more
6027 international character sets, and is the default.
6028
6029 @item show print sevenbit-strings
6030 Show whether or not @value{GDBN} is printing only seven-bit characters.
6031
6032 @item set print union on
6033 @cindex unions in structures, printing
6034 Tell @value{GDBN} to print unions which are contained in structures
6035 and other unions. This is the default setting.
6036
6037 @item set print union off
6038 Tell @value{GDBN} not to print unions which are contained in
6039 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
6040 instead.
6041
6042 @item show print union
6043 Ask @value{GDBN} whether or not it will print unions which are contained in
6044 structures and other unions.
6045
6046 For example, given the declarations
6047
6048 @smallexample
6049 typedef enum @{Tree, Bug@} Species;
6050 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
6051 typedef enum @{Caterpillar, Cocoon, Butterfly@}
6052 Bug_forms;
6053
6054 struct thing @{
6055 Species it;
6056 union @{
6057 Tree_forms tree;
6058 Bug_forms bug;
6059 @} form;
6060 @};
6061
6062 struct thing foo = @{Tree, @{Acorn@}@};
6063 @end smallexample
6064
6065 @noindent
6066 with @code{set print union on} in effect @samp{p foo} would print
6067
6068 @smallexample
6069 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6070 @end smallexample
6071
6072 @noindent
6073 and with @code{set print union off} in effect it would print
6074
6075 @smallexample
6076 $1 = @{it = Tree, form = @{...@}@}
6077 @end smallexample
6078
6079 @noindent
6080 @code{set print union} affects programs written in C-like languages
6081 and in Pascal.
6082 @end table
6083
6084 @need 1000
6085 @noindent
6086 These settings are of interest when debugging C@t{++} programs:
6087
6088 @table @code
6089 @cindex demangling C@t{++} names
6090 @item set print demangle
6091 @itemx set print demangle on
6092 Print C@t{++} names in their source form rather than in the encoded
6093 (``mangled'') form passed to the assembler and linker for type-safe
6094 linkage. The default is on.
6095
6096 @item show print demangle
6097 Show whether C@t{++} names are printed in mangled or demangled form.
6098
6099 @item set print asm-demangle
6100 @itemx set print asm-demangle on
6101 Print C@t{++} names in their source form rather than their mangled form, even
6102 in assembler code printouts such as instruction disassemblies.
6103 The default is off.
6104
6105 @item show print asm-demangle
6106 Show whether C@t{++} names in assembly listings are printed in mangled
6107 or demangled form.
6108
6109 @cindex C@t{++} symbol decoding style
6110 @cindex symbol decoding style, C@t{++}
6111 @kindex set demangle-style
6112 @item set demangle-style @var{style}
6113 Choose among several encoding schemes used by different compilers to
6114 represent C@t{++} names. The choices for @var{style} are currently:
6115
6116 @table @code
6117 @item auto
6118 Allow @value{GDBN} to choose a decoding style by inspecting your program.
6119
6120 @item gnu
6121 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
6122 This is the default.
6123
6124 @item hp
6125 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
6126
6127 @item lucid
6128 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
6129
6130 @item arm
6131 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
6132 @strong{Warning:} this setting alone is not sufficient to allow
6133 debugging @code{cfront}-generated executables. @value{GDBN} would
6134 require further enhancement to permit that.
6135
6136 @end table
6137 If you omit @var{style}, you will see a list of possible formats.
6138
6139 @item show demangle-style
6140 Display the encoding style currently in use for decoding C@t{++} symbols.
6141
6142 @item set print object
6143 @itemx set print object on
6144 @cindex derived type of an object, printing
6145 @cindex display derived types
6146 When displaying a pointer to an object, identify the @emph{actual}
6147 (derived) type of the object rather than the @emph{declared} type, using
6148 the virtual function table.
6149
6150 @item set print object off
6151 Display only the declared type of objects, without reference to the
6152 virtual function table. This is the default setting.
6153
6154 @item show print object
6155 Show whether actual, or declared, object types are displayed.
6156
6157 @item set print static-members
6158 @itemx set print static-members on
6159 @cindex static members of C@t{++} objects
6160 Print static members when displaying a C@t{++} object. The default is on.
6161
6162 @item set print static-members off
6163 Do not print static members when displaying a C@t{++} object.
6164
6165 @item show print static-members
6166 Show whether C@t{++} static members are printed or not.
6167
6168 @item set print pascal_static-members
6169 @itemx set print pascal_static-members on
6170 @cindex static members of Pacal objects
6171 @cindex Pacal objects, static members display
6172 Print static members when displaying a Pascal object. The default is on.
6173
6174 @item set print pascal_static-members off
6175 Do not print static members when displaying a Pascal object.
6176
6177 @item show print pascal_static-members
6178 Show whether Pascal static members are printed or not.
6179
6180 @c These don't work with HP ANSI C++ yet.
6181 @item set print vtbl
6182 @itemx set print vtbl on
6183 @cindex pretty print C@t{++} virtual function tables
6184 @cindex virtual functions (C@t{++}) display
6185 @cindex VTBL display
6186 Pretty print C@t{++} virtual function tables. The default is off.
6187 (The @code{vtbl} commands do not work on programs compiled with the HP
6188 ANSI C@t{++} compiler (@code{aCC}).)
6189
6190 @item set print vtbl off
6191 Do not pretty print C@t{++} virtual function tables.
6192
6193 @item show print vtbl
6194 Show whether C@t{++} virtual function tables are pretty printed, or not.
6195 @end table
6196
6197 @node Value History
6198 @section Value history
6199
6200 @cindex value history
6201 @cindex history of values printed by @value{GDBN}
6202 Values printed by the @code{print} command are saved in the @value{GDBN}
6203 @dfn{value history}. This allows you to refer to them in other expressions.
6204 Values are kept until the symbol table is re-read or discarded
6205 (for example with the @code{file} or @code{symbol-file} commands).
6206 When the symbol table changes, the value history is discarded,
6207 since the values may contain pointers back to the types defined in the
6208 symbol table.
6209
6210 @cindex @code{$}
6211 @cindex @code{$$}
6212 @cindex history number
6213 The values printed are given @dfn{history numbers} by which you can
6214 refer to them. These are successive integers starting with one.
6215 @code{print} shows you the history number assigned to a value by
6216 printing @samp{$@var{num} = } before the value; here @var{num} is the
6217 history number.
6218
6219 To refer to any previous value, use @samp{$} followed by the value's
6220 history number. The way @code{print} labels its output is designed to
6221 remind you of this. Just @code{$} refers to the most recent value in
6222 the history, and @code{$$} refers to the value before that.
6223 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6224 is the value just prior to @code{$$}, @code{$$1} is equivalent to
6225 @code{$$}, and @code{$$0} is equivalent to @code{$}.
6226
6227 For example, suppose you have just printed a pointer to a structure and
6228 want to see the contents of the structure. It suffices to type
6229
6230 @smallexample
6231 p *$
6232 @end smallexample
6233
6234 If you have a chain of structures where the component @code{next} points
6235 to the next one, you can print the contents of the next one with this:
6236
6237 @smallexample
6238 p *$.next
6239 @end smallexample
6240
6241 @noindent
6242 You can print successive links in the chain by repeating this
6243 command---which you can do by just typing @key{RET}.
6244
6245 Note that the history records values, not expressions. If the value of
6246 @code{x} is 4 and you type these commands:
6247
6248 @smallexample
6249 print x
6250 set x=5
6251 @end smallexample
6252
6253 @noindent
6254 then the value recorded in the value history by the @code{print} command
6255 remains 4 even though the value of @code{x} has changed.
6256
6257 @table @code
6258 @kindex show values
6259 @item show values
6260 Print the last ten values in the value history, with their item numbers.
6261 This is like @samp{p@ $$9} repeated ten times, except that @code{show
6262 values} does not change the history.
6263
6264 @item show values @var{n}
6265 Print ten history values centered on history item number @var{n}.
6266
6267 @item show values +
6268 Print ten history values just after the values last printed. If no more
6269 values are available, @code{show values +} produces no display.
6270 @end table
6271
6272 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6273 same effect as @samp{show values +}.
6274
6275 @node Convenience Vars
6276 @section Convenience variables
6277
6278 @cindex convenience variables
6279 @cindex user-defined variables
6280 @value{GDBN} provides @dfn{convenience variables} that you can use within
6281 @value{GDBN} to hold on to a value and refer to it later. These variables
6282 exist entirely within @value{GDBN}; they are not part of your program, and
6283 setting a convenience variable has no direct effect on further execution
6284 of your program. That is why you can use them freely.
6285
6286 Convenience variables are prefixed with @samp{$}. Any name preceded by
6287 @samp{$} can be used for a convenience variable, unless it is one of
6288 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
6289 (Value history references, in contrast, are @emph{numbers} preceded
6290 by @samp{$}. @xref{Value History, ,Value history}.)
6291
6292 You can save a value in a convenience variable with an assignment
6293 expression, just as you would set a variable in your program.
6294 For example:
6295
6296 @smallexample
6297 set $foo = *object_ptr
6298 @end smallexample
6299
6300 @noindent
6301 would save in @code{$foo} the value contained in the object pointed to by
6302 @code{object_ptr}.
6303
6304 Using a convenience variable for the first time creates it, but its
6305 value is @code{void} until you assign a new value. You can alter the
6306 value with another assignment at any time.
6307
6308 Convenience variables have no fixed types. You can assign a convenience
6309 variable any type of value, including structures and arrays, even if
6310 that variable already has a value of a different type. The convenience
6311 variable, when used as an expression, has the type of its current value.
6312
6313 @table @code
6314 @kindex show convenience
6315 @cindex show all user variables
6316 @item show convenience
6317 Print a list of convenience variables used so far, and their values.
6318 Abbreviated @code{show conv}.
6319
6320 @kindex init-if-undefined
6321 @cindex convenience variables, initializing
6322 @item init-if-undefined $@var{variable} = @var{expression}
6323 Set a convenience variable if it has not already been set. This is useful
6324 for user-defined commands that keep some state. It is similar, in concept,
6325 to using local static variables with initializers in C (except that
6326 convenience variables are global). It can also be used to allow users to
6327 override default values used in a command script.
6328
6329 If the variable is already defined then the expression is not evaluated so
6330 any side-effects do not occur.
6331 @end table
6332
6333 One of the ways to use a convenience variable is as a counter to be
6334 incremented or a pointer to be advanced. For example, to print
6335 a field from successive elements of an array of structures:
6336
6337 @smallexample
6338 set $i = 0
6339 print bar[$i++]->contents
6340 @end smallexample
6341
6342 @noindent
6343 Repeat that command by typing @key{RET}.
6344
6345 Some convenience variables are created automatically by @value{GDBN} and given
6346 values likely to be useful.
6347
6348 @table @code
6349 @vindex $_@r{, convenience variable}
6350 @item $_
6351 The variable @code{$_} is automatically set by the @code{x} command to
6352 the last address examined (@pxref{Memory, ,Examining memory}). Other
6353 commands which provide a default address for @code{x} to examine also
6354 set @code{$_} to that address; these commands include @code{info line}
6355 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6356 except when set by the @code{x} command, in which case it is a pointer
6357 to the type of @code{$__}.
6358
6359 @vindex $__@r{, convenience variable}
6360 @item $__
6361 The variable @code{$__} is automatically set by the @code{x} command
6362 to the value found in the last address examined. Its type is chosen
6363 to match the format in which the data was printed.
6364
6365 @item $_exitcode
6366 @vindex $_exitcode@r{, convenience variable}
6367 The variable @code{$_exitcode} is automatically set to the exit code when
6368 the program being debugged terminates.
6369 @end table
6370
6371 On HP-UX systems, if you refer to a function or variable name that
6372 begins with a dollar sign, @value{GDBN} searches for a user or system
6373 name first, before it searches for a convenience variable.
6374
6375 @node Registers
6376 @section Registers
6377
6378 @cindex registers
6379 You can refer to machine register contents, in expressions, as variables
6380 with names starting with @samp{$}. The names of registers are different
6381 for each machine; use @code{info registers} to see the names used on
6382 your machine.
6383
6384 @table @code
6385 @kindex info registers
6386 @item info registers
6387 Print the names and values of all registers except floating-point
6388 and vector registers (in the selected stack frame).
6389
6390 @kindex info all-registers
6391 @cindex floating point registers
6392 @item info all-registers
6393 Print the names and values of all registers, including floating-point
6394 and vector registers (in the selected stack frame).
6395
6396 @item info registers @var{regname} @dots{}
6397 Print the @dfn{relativized} value of each specified register @var{regname}.
6398 As discussed in detail below, register values are normally relative to
6399 the selected stack frame. @var{regname} may be any register name valid on
6400 the machine you are using, with or without the initial @samp{$}.
6401 @end table
6402
6403 @cindex stack pointer register
6404 @cindex program counter register
6405 @cindex process status register
6406 @cindex frame pointer register
6407 @cindex standard registers
6408 @value{GDBN} has four ``standard'' register names that are available (in
6409 expressions) on most machines---whenever they do not conflict with an
6410 architecture's canonical mnemonics for registers. The register names
6411 @code{$pc} and @code{$sp} are used for the program counter register and
6412 the stack pointer. @code{$fp} is used for a register that contains a
6413 pointer to the current stack frame, and @code{$ps} is used for a
6414 register that contains the processor status. For example,
6415 you could print the program counter in hex with
6416
6417 @smallexample
6418 p/x $pc
6419 @end smallexample
6420
6421 @noindent
6422 or print the instruction to be executed next with
6423
6424 @smallexample
6425 x/i $pc
6426 @end smallexample
6427
6428 @noindent
6429 or add four to the stack pointer@footnote{This is a way of removing
6430 one word from the stack, on machines where stacks grow downward in
6431 memory (most machines, nowadays). This assumes that the innermost
6432 stack frame is selected; setting @code{$sp} is not allowed when other
6433 stack frames are selected. To pop entire frames off the stack,
6434 regardless of machine architecture, use @code{return};
6435 see @ref{Returning, ,Returning from a function}.} with
6436
6437 @smallexample
6438 set $sp += 4
6439 @end smallexample
6440
6441 Whenever possible, these four standard register names are available on
6442 your machine even though the machine has different canonical mnemonics,
6443 so long as there is no conflict. The @code{info registers} command
6444 shows the canonical names. For example, on the SPARC, @code{info
6445 registers} displays the processor status register as @code{$psr} but you
6446 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6447 is an alias for the @sc{eflags} register.
6448
6449 @value{GDBN} always considers the contents of an ordinary register as an
6450 integer when the register is examined in this way. Some machines have
6451 special registers which can hold nothing but floating point; these
6452 registers are considered to have floating point values. There is no way
6453 to refer to the contents of an ordinary register as floating point value
6454 (although you can @emph{print} it as a floating point value with
6455 @samp{print/f $@var{regname}}).
6456
6457 Some registers have distinct ``raw'' and ``virtual'' data formats. This
6458 means that the data format in which the register contents are saved by
6459 the operating system is not the same one that your program normally
6460 sees. For example, the registers of the 68881 floating point
6461 coprocessor are always saved in ``extended'' (raw) format, but all C
6462 programs expect to work with ``double'' (virtual) format. In such
6463 cases, @value{GDBN} normally works with the virtual format only (the format
6464 that makes sense for your program), but the @code{info registers} command
6465 prints the data in both formats.
6466
6467 @cindex SSE registers (x86)
6468 @cindex MMX registers (x86)
6469 Some machines have special registers whose contents can be interpreted
6470 in several different ways. For example, modern x86-based machines
6471 have SSE and MMX registers that can hold several values packed
6472 together in several different formats. @value{GDBN} refers to such
6473 registers in @code{struct} notation:
6474
6475 @smallexample
6476 (@value{GDBP}) print $xmm1
6477 $1 = @{
6478 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6479 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6480 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6481 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6482 v4_int32 = @{0, 20657912, 11, 13@},
6483 v2_int64 = @{88725056443645952, 55834574859@},
6484 uint128 = 0x0000000d0000000b013b36f800000000
6485 @}
6486 @end smallexample
6487
6488 @noindent
6489 To set values of such registers, you need to tell @value{GDBN} which
6490 view of the register you wish to change, as if you were assigning
6491 value to a @code{struct} member:
6492
6493 @smallexample
6494 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6495 @end smallexample
6496
6497 Normally, register values are relative to the selected stack frame
6498 (@pxref{Selection, ,Selecting a frame}). This means that you get the
6499 value that the register would contain if all stack frames farther in
6500 were exited and their saved registers restored. In order to see the
6501 true contents of hardware registers, you must select the innermost
6502 frame (with @samp{frame 0}).
6503
6504 However, @value{GDBN} must deduce where registers are saved, from the machine
6505 code generated by your compiler. If some registers are not saved, or if
6506 @value{GDBN} is unable to locate the saved registers, the selected stack
6507 frame makes no difference.
6508
6509 @node Floating Point Hardware
6510 @section Floating point hardware
6511 @cindex floating point
6512
6513 Depending on the configuration, @value{GDBN} may be able to give
6514 you more information about the status of the floating point hardware.
6515
6516 @table @code
6517 @kindex info float
6518 @item info float
6519 Display hardware-dependent information about the floating
6520 point unit. The exact contents and layout vary depending on the
6521 floating point chip. Currently, @samp{info float} is supported on
6522 the ARM and x86 machines.
6523 @end table
6524
6525 @node Vector Unit
6526 @section Vector Unit
6527 @cindex vector unit
6528
6529 Depending on the configuration, @value{GDBN} may be able to give you
6530 more information about the status of the vector unit.
6531
6532 @table @code
6533 @kindex info vector
6534 @item info vector
6535 Display information about the vector unit. The exact contents and
6536 layout vary depending on the hardware.
6537 @end table
6538
6539 @node OS Information
6540 @section Operating system auxiliary information
6541 @cindex OS information
6542
6543 @value{GDBN} provides interfaces to useful OS facilities that can help
6544 you debug your program.
6545
6546 @cindex @code{ptrace} system call
6547 @cindex @code{struct user} contents
6548 When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6549 machines), it interfaces with the inferior via the @code{ptrace}
6550 system call. The operating system creates a special sata structure,
6551 called @code{struct user}, for this interface. You can use the
6552 command @code{info udot} to display the contents of this data
6553 structure.
6554
6555 @table @code
6556 @item info udot
6557 @kindex info udot
6558 Display the contents of the @code{struct user} maintained by the OS
6559 kernel for the program being debugged. @value{GDBN} displays the
6560 contents of @code{struct user} as a list of hex numbers, similar to
6561 the @code{examine} command.
6562 @end table
6563
6564 @cindex auxiliary vector
6565 @cindex vector, auxiliary
6566 Some operating systems supply an @dfn{auxiliary vector} to programs at
6567 startup. This is akin to the arguments and environment that you
6568 specify for a program, but contains a system-dependent variety of
6569 binary values that tell system libraries important details about the
6570 hardware, operating system, and process. Each value's purpose is
6571 identified by an integer tag; the meanings are well-known but system-specific.
6572 Depending on the configuration and operating system facilities,
6573 @value{GDBN} may be able to show you this information. For remote
6574 targets, this functionality may further depend on the remote stub's
6575 support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6576 configuration, auxiliary vector}.
6577
6578 @table @code
6579 @kindex info auxv
6580 @item info auxv
6581 Display the auxiliary vector of the inferior, which can be either a
6582 live process or a core dump file. @value{GDBN} prints each tag value
6583 numerically, and also shows names and text descriptions for recognized
6584 tags. Some values in the vector are numbers, some bit masks, and some
6585 pointers to strings or other data. @value{GDBN} displays each value in the
6586 most appropriate form for a recognized tag, and in hexadecimal for
6587 an unrecognized tag.
6588 @end table
6589
6590
6591 @node Memory Region Attributes
6592 @section Memory region attributes
6593 @cindex memory region attributes
6594
6595 @dfn{Memory region attributes} allow you to describe special handling
6596 required by regions of your target's memory. @value{GDBN} uses attributes
6597 to determine whether to allow certain types of memory accesses; whether to
6598 use specific width accesses; and whether to cache target memory.
6599
6600 Defined memory regions can be individually enabled and disabled. When a
6601 memory region is disabled, @value{GDBN} uses the default attributes when
6602 accessing memory in that region. Similarly, if no memory regions have
6603 been defined, @value{GDBN} uses the default attributes when accessing
6604 all memory.
6605
6606 When a memory region is defined, it is given a number to identify it;
6607 to enable, disable, or remove a memory region, you specify that number.
6608
6609 @table @code
6610 @kindex mem
6611 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
6612 Define a memory region bounded by @var{lower} and @var{upper} with
6613 attributes @var{attributes}@dots{}, and add it to the list of regions
6614 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6615 case: it is treated as the the target's maximum memory address.
6616 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
6617
6618 @kindex delete mem
6619 @item delete mem @var{nums}@dots{}
6620 Remove memory regions @var{nums}@dots{} from the list of regions
6621 monitored by @value{GDBN}.
6622
6623 @kindex disable mem
6624 @item disable mem @var{nums}@dots{}
6625 Disable monitoring of memory regions @var{nums}@dots{}.
6626 A disabled memory region is not forgotten.
6627 It may be enabled again later.
6628
6629 @kindex enable mem
6630 @item enable mem @var{nums}@dots{}
6631 Enable monitoring of memory regions @var{nums}@dots{}.
6632
6633 @kindex info mem
6634 @item info mem
6635 Print a table of all defined memory regions, with the following columns
6636 for each region:
6637
6638 @table @emph
6639 @item Memory Region Number
6640 @item Enabled or Disabled.
6641 Enabled memory regions are marked with @samp{y}.
6642 Disabled memory regions are marked with @samp{n}.
6643
6644 @item Lo Address
6645 The address defining the inclusive lower bound of the memory region.
6646
6647 @item Hi Address
6648 The address defining the exclusive upper bound of the memory region.
6649
6650 @item Attributes
6651 The list of attributes set for this memory region.
6652 @end table
6653 @end table
6654
6655
6656 @subsection Attributes
6657
6658 @subsubsection Memory Access Mode
6659 The access mode attributes set whether @value{GDBN} may make read or
6660 write accesses to a memory region.
6661
6662 While these attributes prevent @value{GDBN} from performing invalid
6663 memory accesses, they do nothing to prevent the target system, I/O DMA,
6664 etc.@: from accessing memory.
6665
6666 @table @code
6667 @item ro
6668 Memory is read only.
6669 @item wo
6670 Memory is write only.
6671 @item rw
6672 Memory is read/write. This is the default.
6673 @end table
6674
6675 @subsubsection Memory Access Size
6676 The acccess size attributes tells @value{GDBN} to use specific sized
6677 accesses in the memory region. Often memory mapped device registers
6678 require specific sized accesses. If no access size attribute is
6679 specified, @value{GDBN} may use accesses of any size.
6680
6681 @table @code
6682 @item 8
6683 Use 8 bit memory accesses.
6684 @item 16
6685 Use 16 bit memory accesses.
6686 @item 32
6687 Use 32 bit memory accesses.
6688 @item 64
6689 Use 64 bit memory accesses.
6690 @end table
6691
6692 @c @subsubsection Hardware/Software Breakpoints
6693 @c The hardware/software breakpoint attributes set whether @value{GDBN}
6694 @c will use hardware or software breakpoints for the internal breakpoints
6695 @c used by the step, next, finish, until, etc. commands.
6696 @c
6697 @c @table @code
6698 @c @item hwbreak
6699 @c Always use hardware breakpoints
6700 @c @item swbreak (default)
6701 @c @end table
6702
6703 @subsubsection Data Cache
6704 The data cache attributes set whether @value{GDBN} will cache target
6705 memory. While this generally improves performance by reducing debug
6706 protocol overhead, it can lead to incorrect results because @value{GDBN}
6707 does not know about volatile variables or memory mapped device
6708 registers.
6709
6710 @table @code
6711 @item cache
6712 Enable @value{GDBN} to cache target memory.
6713 @item nocache
6714 Disable @value{GDBN} from caching target memory. This is the default.
6715 @end table
6716
6717 @c @subsubsection Memory Write Verification
6718 @c The memory write verification attributes set whether @value{GDBN}
6719 @c will re-reads data after each write to verify the write was successful.
6720 @c
6721 @c @table @code
6722 @c @item verify
6723 @c @item noverify (default)
6724 @c @end table
6725
6726 @node Dump/Restore Files
6727 @section Copy between memory and a file
6728 @cindex dump/restore files
6729 @cindex append data to a file
6730 @cindex dump data to a file
6731 @cindex restore data from a file
6732
6733 You can use the commands @code{dump}, @code{append}, and
6734 @code{restore} to copy data between target memory and a file. The
6735 @code{dump} and @code{append} commands write data to a file, and the
6736 @code{restore} command reads data from a file back into the inferior's
6737 memory. Files may be in binary, Motorola S-record, Intel hex, or
6738 Tektronix Hex format; however, @value{GDBN} can only append to binary
6739 files.
6740
6741 @table @code
6742
6743 @kindex dump
6744 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6745 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6746 Dump the contents of memory from @var{start_addr} to @var{end_addr},
6747 or the value of @var{expr}, to @var{filename} in the given format.
6748
6749 The @var{format} parameter may be any one of:
6750 @table @code
6751 @item binary
6752 Raw binary form.
6753 @item ihex
6754 Intel hex format.
6755 @item srec
6756 Motorola S-record format.
6757 @item tekhex
6758 Tektronix Hex format.
6759 @end table
6760
6761 @value{GDBN} uses the same definitions of these formats as the
6762 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6763 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
6764 form.
6765
6766 @kindex append
6767 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6768 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6769 Append the contents of memory from @var{start_addr} to @var{end_addr},
6770 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
6771 (@value{GDBN} can only append data to files in raw binary form.)
6772
6773 @kindex restore
6774 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6775 Restore the contents of file @var{filename} into memory. The
6776 @code{restore} command can automatically recognize any known @sc{bfd}
6777 file format, except for raw binary. To restore a raw binary file you
6778 must specify the optional keyword @code{binary} after the filename.
6779
6780 If @var{bias} is non-zero, its value will be added to the addresses
6781 contained in the file. Binary files always start at address zero, so
6782 they will be restored at address @var{bias}. Other bfd files have
6783 a built-in location; they will be restored at offset @var{bias}
6784 from that location.
6785
6786 If @var{start} and/or @var{end} are non-zero, then only data between
6787 file offset @var{start} and file offset @var{end} will be restored.
6788 These offsets are relative to the addresses in the file, before
6789 the @var{bias} argument is applied.
6790
6791 @end table
6792
6793 @node Core File Generation
6794 @section How to Produce a Core File from Your Program
6795 @cindex dump core from inferior
6796
6797 A @dfn{core file} or @dfn{core dump} is a file that records the memory
6798 image of a running process and its process status (register values
6799 etc.). Its primary use is post-mortem debugging of a program that
6800 crashed while it ran outside a debugger. A program that crashes
6801 automatically produces a core file, unless this feature is disabled by
6802 the user. @xref{Files}, for information on invoking @value{GDBN} in
6803 the post-mortem debugging mode.
6804
6805 Occasionally, you may wish to produce a core file of the program you
6806 are debugging in order to preserve a snapshot of its state.
6807 @value{GDBN} has a special command for that.
6808
6809 @table @code
6810 @kindex gcore
6811 @kindex generate-core-file
6812 @item generate-core-file [@var{file}]
6813 @itemx gcore [@var{file}]
6814 Produce a core dump of the inferior process. The optional argument
6815 @var{file} specifies the file name where to put the core dump. If not
6816 specified, the file name defaults to @file{core.@var{pid}}, where
6817 @var{pid} is the inferior process ID.
6818
6819 Note that this command is implemented only for some systems (as of
6820 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6821 @end table
6822
6823 @node Character Sets
6824 @section Character Sets
6825 @cindex character sets
6826 @cindex charset
6827 @cindex translating between character sets
6828 @cindex host character set
6829 @cindex target character set
6830
6831 If the program you are debugging uses a different character set to
6832 represent characters and strings than the one @value{GDBN} uses itself,
6833 @value{GDBN} can automatically translate between the character sets for
6834 you. The character set @value{GDBN} uses we call the @dfn{host
6835 character set}; the one the inferior program uses we call the
6836 @dfn{target character set}.
6837
6838 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6839 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6840 remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6841 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6842 then the host character set is Latin-1, and the target character set is
6843 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
6844 target-charset EBCDIC-US}, then @value{GDBN} translates between
6845 @sc{ebcdic} and Latin 1 as you print character or string values, or use
6846 character and string literals in expressions.
6847
6848 @value{GDBN} has no way to automatically recognize which character set
6849 the inferior program uses; you must tell it, using the @code{set
6850 target-charset} command, described below.
6851
6852 Here are the commands for controlling @value{GDBN}'s character set
6853 support:
6854
6855 @table @code
6856 @item set target-charset @var{charset}
6857 @kindex set target-charset
6858 Set the current target character set to @var{charset}. We list the
6859 character set names @value{GDBN} recognizes below, but if you type
6860 @code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6861 list the target character sets it supports.
6862 @end table
6863
6864 @table @code
6865 @item set host-charset @var{charset}
6866 @kindex set host-charset
6867 Set the current host character set to @var{charset}.
6868
6869 By default, @value{GDBN} uses a host character set appropriate to the
6870 system it is running on; you can override that default using the
6871 @code{set host-charset} command.
6872
6873 @value{GDBN} can only use certain character sets as its host character
6874 set. We list the character set names @value{GDBN} recognizes below, and
6875 indicate which can be host character sets, but if you type
6876 @code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6877 list the host character sets it supports.
6878
6879 @item set charset @var{charset}
6880 @kindex set charset
6881 Set the current host and target character sets to @var{charset}. As
6882 above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6883 @value{GDBN} will list the name of the character sets that can be used
6884 for both host and target.
6885
6886
6887 @item show charset
6888 @kindex show charset
6889 Show the names of the current host and target charsets.
6890
6891 @itemx show host-charset
6892 @kindex show host-charset
6893 Show the name of the current host charset.
6894
6895 @itemx show target-charset
6896 @kindex show target-charset
6897 Show the name of the current target charset.
6898
6899 @end table
6900
6901 @value{GDBN} currently includes support for the following character
6902 sets:
6903
6904 @table @code
6905
6906 @item ASCII
6907 @cindex ASCII character set
6908 Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6909 character set.
6910
6911 @item ISO-8859-1
6912 @cindex ISO 8859-1 character set
6913 @cindex ISO Latin 1 character set
6914 The ISO Latin 1 character set. This extends @sc{ascii} with accented
6915 characters needed for French, German, and Spanish. @value{GDBN} can use
6916 this as its host character set.
6917
6918 @item EBCDIC-US
6919 @itemx IBM1047
6920 @cindex EBCDIC character set
6921 @cindex IBM1047 character set
6922 Variants of the @sc{ebcdic} character set, used on some of IBM's
6923 mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6924 @value{GDBN} cannot use these as its host character set.
6925
6926 @end table
6927
6928 Note that these are all single-byte character sets. More work inside
6929 GDB is needed to support multi-byte or variable-width character
6930 encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6931
6932 Here is an example of @value{GDBN}'s character set support in action.
6933 Assume that the following source code has been placed in the file
6934 @file{charset-test.c}:
6935
6936 @smallexample
6937 #include <stdio.h>
6938
6939 char ascii_hello[]
6940 = @{72, 101, 108, 108, 111, 44, 32, 119,
6941 111, 114, 108, 100, 33, 10, 0@};
6942 char ibm1047_hello[]
6943 = @{200, 133, 147, 147, 150, 107, 64, 166,
6944 150, 153, 147, 132, 90, 37, 0@};
6945
6946 main ()
6947 @{
6948 printf ("Hello, world!\n");
6949 @}
6950 @end smallexample
6951
6952 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6953 containing the string @samp{Hello, world!} followed by a newline,
6954 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6955
6956 We compile the program, and invoke the debugger on it:
6957
6958 @smallexample
6959 $ gcc -g charset-test.c -o charset-test
6960 $ gdb -nw charset-test
6961 GNU gdb 2001-12-19-cvs
6962 Copyright 2001 Free Software Foundation, Inc.
6963 @dots{}
6964 (@value{GDBP})
6965 @end smallexample
6966
6967 We can use the @code{show charset} command to see what character sets
6968 @value{GDBN} is currently using to interpret and display characters and
6969 strings:
6970
6971 @smallexample
6972 (@value{GDBP}) show charset
6973 The current host and target character set is `ISO-8859-1'.
6974 (@value{GDBP})
6975 @end smallexample
6976
6977 For the sake of printing this manual, let's use @sc{ascii} as our
6978 initial character set:
6979 @smallexample
6980 (@value{GDBP}) set charset ASCII
6981 (@value{GDBP}) show charset
6982 The current host and target character set is `ASCII'.
6983 (@value{GDBP})
6984 @end smallexample
6985
6986 Let's assume that @sc{ascii} is indeed the correct character set for our
6987 host system --- in other words, let's assume that if @value{GDBN} prints
6988 characters using the @sc{ascii} character set, our terminal will display
6989 them properly. Since our current target character set is also
6990 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
6991
6992 @smallexample
6993 (@value{GDBP}) print ascii_hello
6994 $1 = 0x401698 "Hello, world!\n"
6995 (@value{GDBP}) print ascii_hello[0]
6996 $2 = 72 'H'
6997 (@value{GDBP})
6998 @end smallexample
6999
7000 @value{GDBN} uses the target character set for character and string
7001 literals you use in expressions:
7002
7003 @smallexample
7004 (@value{GDBP}) print '+'
7005 $3 = 43 '+'
7006 (@value{GDBP})
7007 @end smallexample
7008
7009 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7010 character.
7011
7012 @value{GDBN} relies on the user to tell it which character set the
7013 target program uses. If we print @code{ibm1047_hello} while our target
7014 character set is still @sc{ascii}, we get jibberish:
7015
7016 @smallexample
7017 (@value{GDBP}) print ibm1047_hello
7018 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
7019 (@value{GDBP}) print ibm1047_hello[0]
7020 $5 = 200 '\310'
7021 (@value{GDBP})
7022 @end smallexample
7023
7024 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
7025 @value{GDBN} tells us the character sets it supports:
7026
7027 @smallexample
7028 (@value{GDBP}) set target-charset
7029 ASCII EBCDIC-US IBM1047 ISO-8859-1
7030 (@value{GDBP}) set target-charset
7031 @end smallexample
7032
7033 We can select @sc{ibm1047} as our target character set, and examine the
7034 program's strings again. Now the @sc{ascii} string is wrong, but
7035 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
7036 target character set, @sc{ibm1047}, to the host character set,
7037 @sc{ascii}, and they display correctly:
7038
7039 @smallexample
7040 (@value{GDBP}) set target-charset IBM1047
7041 (@value{GDBP}) show charset
7042 The current host character set is `ASCII'.
7043 The current target character set is `IBM1047'.
7044 (@value{GDBP}) print ascii_hello
7045 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
7046 (@value{GDBP}) print ascii_hello[0]
7047 $7 = 72 '\110'
7048 (@value{GDBP}) print ibm1047_hello
7049 $8 = 0x4016a8 "Hello, world!\n"
7050 (@value{GDBP}) print ibm1047_hello[0]
7051 $9 = 200 'H'
7052 (@value{GDBP})
7053 @end smallexample
7054
7055 As above, @value{GDBN} uses the target character set for character and
7056 string literals you use in expressions:
7057
7058 @smallexample
7059 (@value{GDBP}) print '+'
7060 $10 = 78 '+'
7061 (@value{GDBP})
7062 @end smallexample
7063
7064 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
7065 character.
7066
7067 @node Caching Remote Data
7068 @section Caching Data of Remote Targets
7069 @cindex caching data of remote targets
7070
7071 @value{GDBN} can cache data exchanged between the debugger and a
7072 remote target (@pxref{Remote}). Such caching generally improves
7073 performance, because it reduces the overhead of the remote protocol by
7074 bundling memory reads and writes into large chunks. Unfortunately,
7075 @value{GDBN} does not currently know anything about volatile
7076 registers, and thus data caching will produce incorrect results when
7077 volatile registers are in use.
7078
7079 @table @code
7080 @kindex set remotecache
7081 @item set remotecache on
7082 @itemx set remotecache off
7083 Set caching state for remote targets. When @code{ON}, use data
7084 caching. By default, this option is @code{OFF}.
7085
7086 @kindex show remotecache
7087 @item show remotecache
7088 Show the current state of data caching for remote targets.
7089
7090 @kindex info dcache
7091 @item info dcache
7092 Print the information about the data cache performance. The
7093 information displayed includes: the dcache width and depth; and for
7094 each cache line, how many times it was referenced, and its data and
7095 state (dirty, bad, ok, etc.). This command is useful for debugging
7096 the data cache operation.
7097 @end table
7098
7099
7100 @node Macros
7101 @chapter C Preprocessor Macros
7102
7103 Some languages, such as C and C@t{++}, provide a way to define and invoke
7104 ``preprocessor macros'' which expand into strings of tokens.
7105 @value{GDBN} can evaluate expressions containing macro invocations, show
7106 the result of macro expansion, and show a macro's definition, including
7107 where it was defined.
7108
7109 You may need to compile your program specially to provide @value{GDBN}
7110 with information about preprocessor macros. Most compilers do not
7111 include macros in their debugging information, even when you compile
7112 with the @option{-g} flag. @xref{Compilation}.
7113
7114 A program may define a macro at one point, remove that definition later,
7115 and then provide a different definition after that. Thus, at different
7116 points in the program, a macro may have different definitions, or have
7117 no definition at all. If there is a current stack frame, @value{GDBN}
7118 uses the macros in scope at that frame's source code line. Otherwise,
7119 @value{GDBN} uses the macros in scope at the current listing location;
7120 see @ref{List}.
7121
7122 At the moment, @value{GDBN} does not support the @code{##}
7123 token-splicing operator, the @code{#} stringification operator, or
7124 variable-arity macros.
7125
7126 Whenever @value{GDBN} evaluates an expression, it always expands any
7127 macro invocations present in the expression. @value{GDBN} also provides
7128 the following commands for working with macros explicitly.
7129
7130 @table @code
7131
7132 @kindex macro expand
7133 @cindex macro expansion, showing the results of preprocessor
7134 @cindex preprocessor macro expansion, showing the results of
7135 @cindex expanding preprocessor macros
7136 @item macro expand @var{expression}
7137 @itemx macro exp @var{expression}
7138 Show the results of expanding all preprocessor macro invocations in
7139 @var{expression}. Since @value{GDBN} simply expands macros, but does
7140 not parse the result, @var{expression} need not be a valid expression;
7141 it can be any string of tokens.
7142
7143 @kindex macro exp1
7144 @item macro expand-once @var{expression}
7145 @itemx macro exp1 @var{expression}
7146 @cindex expand macro once
7147 @i{(This command is not yet implemented.)} Show the results of
7148 expanding those preprocessor macro invocations that appear explicitly in
7149 @var{expression}. Macro invocations appearing in that expansion are
7150 left unchanged. This command allows you to see the effect of a
7151 particular macro more clearly, without being confused by further
7152 expansions. Since @value{GDBN} simply expands macros, but does not
7153 parse the result, @var{expression} need not be a valid expression; it
7154 can be any string of tokens.
7155
7156 @kindex info macro
7157 @cindex macro definition, showing
7158 @cindex definition, showing a macro's
7159 @item info macro @var{macro}
7160 Show the definition of the macro named @var{macro}, and describe the
7161 source location where that definition was established.
7162
7163 @kindex macro define
7164 @cindex user-defined macros
7165 @cindex defining macros interactively
7166 @cindex macros, user-defined
7167 @item macro define @var{macro} @var{replacement-list}
7168 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7169 @i{(This command is not yet implemented.)} Introduce a definition for a
7170 preprocessor macro named @var{macro}, invocations of which are replaced
7171 by the tokens given in @var{replacement-list}. The first form of this
7172 command defines an ``object-like'' macro, which takes no arguments; the
7173 second form defines a ``function-like'' macro, which takes the arguments
7174 given in @var{arglist}.
7175
7176 A definition introduced by this command is in scope in every expression
7177 evaluated in @value{GDBN}, until it is removed with the @command{macro
7178 undef} command, described below. The definition overrides all
7179 definitions for @var{macro} present in the program being debugged, as
7180 well as any previous user-supplied definition.
7181
7182 @kindex macro undef
7183 @item macro undef @var{macro}
7184 @i{(This command is not yet implemented.)} Remove any user-supplied
7185 definition for the macro named @var{macro}. This command only affects
7186 definitions provided with the @command{macro define} command, described
7187 above; it cannot remove definitions present in the program being
7188 debugged.
7189
7190 @kindex macro list
7191 @item macro list
7192 @i{(This command is not yet implemented.)} List all the macros
7193 defined using the @code{macro define} command.
7194 @end table
7195
7196 @cindex macros, example of debugging with
7197 Here is a transcript showing the above commands in action. First, we
7198 show our source files:
7199
7200 @smallexample
7201 $ cat sample.c
7202 #include <stdio.h>
7203 #include "sample.h"
7204
7205 #define M 42
7206 #define ADD(x) (M + x)
7207
7208 main ()
7209 @{
7210 #define N 28
7211 printf ("Hello, world!\n");
7212 #undef N
7213 printf ("We're so creative.\n");
7214 #define N 1729
7215 printf ("Goodbye, world!\n");
7216 @}
7217 $ cat sample.h
7218 #define Q <
7219 $
7220 @end smallexample
7221
7222 Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7223 We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7224 compiler includes information about preprocessor macros in the debugging
7225 information.
7226
7227 @smallexample
7228 $ gcc -gdwarf-2 -g3 sample.c -o sample
7229 $
7230 @end smallexample
7231
7232 Now, we start @value{GDBN} on our sample program:
7233
7234 @smallexample
7235 $ gdb -nw sample
7236 GNU gdb 2002-05-06-cvs
7237 Copyright 2002 Free Software Foundation, Inc.
7238 GDB is free software, @dots{}
7239 (@value{GDBP})
7240 @end smallexample
7241
7242 We can expand macros and examine their definitions, even when the
7243 program is not running. @value{GDBN} uses the current listing position
7244 to decide which macro definitions are in scope:
7245
7246 @smallexample
7247 (@value{GDBP}) list main
7248 3
7249 4 #define M 42
7250 5 #define ADD(x) (M + x)
7251 6
7252 7 main ()
7253 8 @{
7254 9 #define N 28
7255 10 printf ("Hello, world!\n");
7256 11 #undef N
7257 12 printf ("We're so creative.\n");
7258 (@value{GDBP}) info macro ADD
7259 Defined at /home/jimb/gdb/macros/play/sample.c:5
7260 #define ADD(x) (M + x)
7261 (@value{GDBP}) info macro Q
7262 Defined at /home/jimb/gdb/macros/play/sample.h:1
7263 included at /home/jimb/gdb/macros/play/sample.c:2
7264 #define Q <
7265 (@value{GDBP}) macro expand ADD(1)
7266 expands to: (42 + 1)
7267 (@value{GDBP}) macro expand-once ADD(1)
7268 expands to: once (M + 1)
7269 (@value{GDBP})
7270 @end smallexample
7271
7272 In the example above, note that @command{macro expand-once} expands only
7273 the macro invocation explicit in the original text --- the invocation of
7274 @code{ADD} --- but does not expand the invocation of the macro @code{M},
7275 which was introduced by @code{ADD}.
7276
7277 Once the program is running, GDB uses the macro definitions in force at
7278 the source line of the current stack frame:
7279
7280 @smallexample
7281 (@value{GDBP}) break main
7282 Breakpoint 1 at 0x8048370: file sample.c, line 10.
7283 (@value{GDBP}) run
7284 Starting program: /home/jimb/gdb/macros/play/sample
7285
7286 Breakpoint 1, main () at sample.c:10
7287 10 printf ("Hello, world!\n");
7288 (@value{GDBP})
7289 @end smallexample
7290
7291 At line 10, the definition of the macro @code{N} at line 9 is in force:
7292
7293 @smallexample
7294 (@value{GDBP}) info macro N
7295 Defined at /home/jimb/gdb/macros/play/sample.c:9
7296 #define N 28
7297 (@value{GDBP}) macro expand N Q M
7298 expands to: 28 < 42
7299 (@value{GDBP}) print N Q M
7300 $1 = 1
7301 (@value{GDBP})
7302 @end smallexample
7303
7304 As we step over directives that remove @code{N}'s definition, and then
7305 give it a new definition, @value{GDBN} finds the definition (or lack
7306 thereof) in force at each point:
7307
7308 @smallexample
7309 (@value{GDBP}) next
7310 Hello, world!
7311 12 printf ("We're so creative.\n");
7312 (@value{GDBP}) info macro N
7313 The symbol `N' has no definition as a C/C++ preprocessor macro
7314 at /home/jimb/gdb/macros/play/sample.c:12
7315 (@value{GDBP}) next
7316 We're so creative.
7317 14 printf ("Goodbye, world!\n");
7318 (@value{GDBP}) info macro N
7319 Defined at /home/jimb/gdb/macros/play/sample.c:13
7320 #define N 1729
7321 (@value{GDBP}) macro expand N Q M
7322 expands to: 1729 < 42
7323 (@value{GDBP}) print N Q M
7324 $2 = 0
7325 (@value{GDBP})
7326 @end smallexample
7327
7328
7329 @node Tracepoints
7330 @chapter Tracepoints
7331 @c This chapter is based on the documentation written by Michael
7332 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7333
7334 @cindex tracepoints
7335 In some applications, it is not feasible for the debugger to interrupt
7336 the program's execution long enough for the developer to learn
7337 anything helpful about its behavior. If the program's correctness
7338 depends on its real-time behavior, delays introduced by a debugger
7339 might cause the program to change its behavior drastically, or perhaps
7340 fail, even when the code itself is correct. It is useful to be able
7341 to observe the program's behavior without interrupting it.
7342
7343 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7344 specify locations in the program, called @dfn{tracepoints}, and
7345 arbitrary expressions to evaluate when those tracepoints are reached.
7346 Later, using the @code{tfind} command, you can examine the values
7347 those expressions had when the program hit the tracepoints. The
7348 expressions may also denote objects in memory---structures or arrays,
7349 for example---whose values @value{GDBN} should record; while visiting
7350 a particular tracepoint, you may inspect those objects as if they were
7351 in memory at that moment. However, because @value{GDBN} records these
7352 values without interacting with you, it can do so quickly and
7353 unobtrusively, hopefully not disturbing the program's behavior.
7354
7355 The tracepoint facility is currently available only for remote
7356 targets. @xref{Targets}. In addition, your remote target must know
7357 how to collect trace data. This functionality is implemented in the
7358 remote stub; however, none of the stubs distributed with @value{GDBN}
7359 support tracepoints as of this writing. The format of the remote
7360 packets used to implement tracepoints are described in @ref{Tracepoint
7361 Packets}.
7362
7363 This chapter describes the tracepoint commands and features.
7364
7365 @menu
7366 * Set Tracepoints::
7367 * Analyze Collected Data::
7368 * Tracepoint Variables::
7369 @end menu
7370
7371 @node Set Tracepoints
7372 @section Commands to Set Tracepoints
7373
7374 Before running such a @dfn{trace experiment}, an arbitrary number of
7375 tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7376 tracepoint has a number assigned to it by @value{GDBN}. Like with
7377 breakpoints, tracepoint numbers are successive integers starting from
7378 one. Many of the commands associated with tracepoints take the
7379 tracepoint number as their argument, to identify which tracepoint to
7380 work on.
7381
7382 For each tracepoint, you can specify, in advance, some arbitrary set
7383 of data that you want the target to collect in the trace buffer when
7384 it hits that tracepoint. The collected data can include registers,
7385 local variables, or global data. Later, you can use @value{GDBN}
7386 commands to examine the values these data had at the time the
7387 tracepoint was hit.
7388
7389 This section describes commands to set tracepoints and associated
7390 conditions and actions.
7391
7392 @menu
7393 * Create and Delete Tracepoints::
7394 * Enable and Disable Tracepoints::
7395 * Tracepoint Passcounts::
7396 * Tracepoint Actions::
7397 * Listing Tracepoints::
7398 * Starting and Stopping Trace Experiment::
7399 @end menu
7400
7401 @node Create and Delete Tracepoints
7402 @subsection Create and Delete Tracepoints
7403
7404 @table @code
7405 @cindex set tracepoint
7406 @kindex trace
7407 @item trace
7408 The @code{trace} command is very similar to the @code{break} command.
7409 Its argument can be a source line, a function name, or an address in
7410 the target program. @xref{Set Breaks}. The @code{trace} command
7411 defines a tracepoint, which is a point in the target program where the
7412 debugger will briefly stop, collect some data, and then allow the
7413 program to continue. Setting a tracepoint or changing its commands
7414 doesn't take effect until the next @code{tstart} command; thus, you
7415 cannot change the tracepoint attributes once a trace experiment is
7416 running.
7417
7418 Here are some examples of using the @code{trace} command:
7419
7420 @smallexample
7421 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7422
7423 (@value{GDBP}) @b{trace +2} // 2 lines forward
7424
7425 (@value{GDBP}) @b{trace my_function} // first source line of function
7426
7427 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7428
7429 (@value{GDBP}) @b{trace *0x2117c4} // an address
7430 @end smallexample
7431
7432 @noindent
7433 You can abbreviate @code{trace} as @code{tr}.
7434
7435 @vindex $tpnum
7436 @cindex last tracepoint number
7437 @cindex recent tracepoint number
7438 @cindex tracepoint number
7439 The convenience variable @code{$tpnum} records the tracepoint number
7440 of the most recently set tracepoint.
7441
7442 @kindex delete tracepoint
7443 @cindex tracepoint deletion
7444 @item delete tracepoint @r{[}@var{num}@r{]}
7445 Permanently delete one or more tracepoints. With no argument, the
7446 default is to delete all tracepoints.
7447
7448 Examples:
7449
7450 @smallexample
7451 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7452
7453 (@value{GDBP}) @b{delete trace} // remove all tracepoints
7454 @end smallexample
7455
7456 @noindent
7457 You can abbreviate this command as @code{del tr}.
7458 @end table
7459
7460 @node Enable and Disable Tracepoints
7461 @subsection Enable and Disable Tracepoints
7462
7463 @table @code
7464 @kindex disable tracepoint
7465 @item disable tracepoint @r{[}@var{num}@r{]}
7466 Disable tracepoint @var{num}, or all tracepoints if no argument
7467 @var{num} is given. A disabled tracepoint will have no effect during
7468 the next trace experiment, but it is not forgotten. You can re-enable
7469 a disabled tracepoint using the @code{enable tracepoint} command.
7470
7471 @kindex enable tracepoint
7472 @item enable tracepoint @r{[}@var{num}@r{]}
7473 Enable tracepoint @var{num}, or all tracepoints. The enabled
7474 tracepoints will become effective the next time a trace experiment is
7475 run.
7476 @end table
7477
7478 @node Tracepoint Passcounts
7479 @subsection Tracepoint Passcounts
7480
7481 @table @code
7482 @kindex passcount
7483 @cindex tracepoint pass count
7484 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7485 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7486 automatically stop a trace experiment. If a tracepoint's passcount is
7487 @var{n}, then the trace experiment will be automatically stopped on
7488 the @var{n}'th time that tracepoint is hit. If the tracepoint number
7489 @var{num} is not specified, the @code{passcount} command sets the
7490 passcount of the most recently defined tracepoint. If no passcount is
7491 given, the trace experiment will run until stopped explicitly by the
7492 user.
7493
7494 Examples:
7495
7496 @smallexample
7497 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
7498 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
7499
7500 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
7501 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
7502 (@value{GDBP}) @b{trace foo}
7503 (@value{GDBP}) @b{pass 3}
7504 (@value{GDBP}) @b{trace bar}
7505 (@value{GDBP}) @b{pass 2}
7506 (@value{GDBP}) @b{trace baz}
7507 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
7508 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7509 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7510 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
7511 @end smallexample
7512 @end table
7513
7514 @node Tracepoint Actions
7515 @subsection Tracepoint Action Lists
7516
7517 @table @code
7518 @kindex actions
7519 @cindex tracepoint actions
7520 @item actions @r{[}@var{num}@r{]}
7521 This command will prompt for a list of actions to be taken when the
7522 tracepoint is hit. If the tracepoint number @var{num} is not
7523 specified, this command sets the actions for the one that was most
7524 recently defined (so that you can define a tracepoint and then say
7525 @code{actions} without bothering about its number). You specify the
7526 actions themselves on the following lines, one action at a time, and
7527 terminate the actions list with a line containing just @code{end}. So
7528 far, the only defined actions are @code{collect} and
7529 @code{while-stepping}.
7530
7531 @cindex remove actions from a tracepoint
7532 To remove all actions from a tracepoint, type @samp{actions @var{num}}
7533 and follow it immediately with @samp{end}.
7534
7535 @smallexample
7536 (@value{GDBP}) @b{collect @var{data}} // collect some data
7537
7538 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
7539
7540 (@value{GDBP}) @b{end} // signals the end of actions.
7541 @end smallexample
7542
7543 In the following example, the action list begins with @code{collect}
7544 commands indicating the things to be collected when the tracepoint is
7545 hit. Then, in order to single-step and collect additional data
7546 following the tracepoint, a @code{while-stepping} command is used,
7547 followed by the list of things to be collected while stepping. The
7548 @code{while-stepping} command is terminated by its own separate
7549 @code{end} command. Lastly, the action list is terminated by an
7550 @code{end} command.
7551
7552 @smallexample
7553 (@value{GDBP}) @b{trace foo}
7554 (@value{GDBP}) @b{actions}
7555 Enter actions for tracepoint 1, one per line:
7556 > collect bar,baz
7557 > collect $regs
7558 > while-stepping 12
7559 > collect $fp, $sp
7560 > end
7561 end
7562 @end smallexample
7563
7564 @kindex collect @r{(tracepoints)}
7565 @item collect @var{expr1}, @var{expr2}, @dots{}
7566 Collect values of the given expressions when the tracepoint is hit.
7567 This command accepts a comma-separated list of any valid expressions.
7568 In addition to global, static, or local variables, the following
7569 special arguments are supported:
7570
7571 @table @code
7572 @item $regs
7573 collect all registers
7574
7575 @item $args
7576 collect all function arguments
7577
7578 @item $locals
7579 collect all local variables.
7580 @end table
7581
7582 You can give several consecutive @code{collect} commands, each one
7583 with a single argument, or one @code{collect} command with several
7584 arguments separated by commas: the effect is the same.
7585
7586 The command @code{info scope} (@pxref{Symbols, info scope}) is
7587 particularly useful for figuring out what data to collect.
7588
7589 @kindex while-stepping @r{(tracepoints)}
7590 @item while-stepping @var{n}
7591 Perform @var{n} single-step traces after the tracepoint, collecting
7592 new data at each step. The @code{while-stepping} command is
7593 followed by the list of what to collect while stepping (followed by
7594 its own @code{end} command):
7595
7596 @smallexample
7597 > while-stepping 12
7598 > collect $regs, myglobal
7599 > end
7600 >
7601 @end smallexample
7602
7603 @noindent
7604 You may abbreviate @code{while-stepping} as @code{ws} or
7605 @code{stepping}.
7606 @end table
7607
7608 @node Listing Tracepoints
7609 @subsection Listing Tracepoints
7610
7611 @table @code
7612 @kindex info tracepoints
7613 @kindex info tp
7614 @cindex information about tracepoints
7615 @item info tracepoints @r{[}@var{num}@r{]}
7616 Display information about the tracepoint @var{num}. If you don't specify
7617 a tracepoint number, displays information about all the tracepoints
7618 defined so far. For each tracepoint, the following information is
7619 shown:
7620
7621 @itemize @bullet
7622 @item
7623 its number
7624 @item
7625 whether it is enabled or disabled
7626 @item
7627 its address
7628 @item
7629 its passcount as given by the @code{passcount @var{n}} command
7630 @item
7631 its step count as given by the @code{while-stepping @var{n}} command
7632 @item
7633 where in the source files is the tracepoint set
7634 @item
7635 its action list as given by the @code{actions} command
7636 @end itemize
7637
7638 @smallexample
7639 (@value{GDBP}) @b{info trace}
7640 Num Enb Address PassC StepC What
7641 1 y 0x002117c4 0 0 <gdb_asm>
7642 2 y 0x0020dc64 0 0 in g_test at g_test.c:1375
7643 3 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
7644 (@value{GDBP})
7645 @end smallexample
7646
7647 @noindent
7648 This command can be abbreviated @code{info tp}.
7649 @end table
7650
7651 @node Starting and Stopping Trace Experiment
7652 @subsection Starting and Stopping Trace Experiment
7653
7654 @table @code
7655 @kindex tstart
7656 @cindex start a new trace experiment
7657 @cindex collected data discarded
7658 @item tstart
7659 This command takes no arguments. It starts the trace experiment, and
7660 begins collecting data. This has the side effect of discarding all
7661 the data collected in the trace buffer during the previous trace
7662 experiment.
7663
7664 @kindex tstop
7665 @cindex stop a running trace experiment
7666 @item tstop
7667 This command takes no arguments. It ends the trace experiment, and
7668 stops collecting data.
7669
7670 @strong{Note}: a trace experiment and data collection may stop
7671 automatically if any tracepoint's passcount is reached
7672 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7673
7674 @kindex tstatus
7675 @cindex status of trace data collection
7676 @cindex trace experiment, status of
7677 @item tstatus
7678 This command displays the status of the current trace data
7679 collection.
7680 @end table
7681
7682 Here is an example of the commands we described so far:
7683
7684 @smallexample
7685 (@value{GDBP}) @b{trace gdb_c_test}
7686 (@value{GDBP}) @b{actions}
7687 Enter actions for tracepoint #1, one per line.
7688 > collect $regs,$locals,$args
7689 > while-stepping 11
7690 > collect $regs
7691 > end
7692 > end
7693 (@value{GDBP}) @b{tstart}
7694 [time passes @dots{}]
7695 (@value{GDBP}) @b{tstop}
7696 @end smallexample
7697
7698
7699 @node Analyze Collected Data
7700 @section Using the collected data
7701
7702 After the tracepoint experiment ends, you use @value{GDBN} commands
7703 for examining the trace data. The basic idea is that each tracepoint
7704 collects a trace @dfn{snapshot} every time it is hit and another
7705 snapshot every time it single-steps. All these snapshots are
7706 consecutively numbered from zero and go into a buffer, and you can
7707 examine them later. The way you examine them is to @dfn{focus} on a
7708 specific trace snapshot. When the remote stub is focused on a trace
7709 snapshot, it will respond to all @value{GDBN} requests for memory and
7710 registers by reading from the buffer which belongs to that snapshot,
7711 rather than from @emph{real} memory or registers of the program being
7712 debugged. This means that @strong{all} @value{GDBN} commands
7713 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7714 behave as if we were currently debugging the program state as it was
7715 when the tracepoint occurred. Any requests for data that are not in
7716 the buffer will fail.
7717
7718 @menu
7719 * tfind:: How to select a trace snapshot
7720 * tdump:: How to display all data for a snapshot
7721 * save-tracepoints:: How to save tracepoints for a future run
7722 @end menu
7723
7724 @node tfind
7725 @subsection @code{tfind @var{n}}
7726
7727 @kindex tfind
7728 @cindex select trace snapshot
7729 @cindex find trace snapshot
7730 The basic command for selecting a trace snapshot from the buffer is
7731 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
7732 counting from zero. If no argument @var{n} is given, the next
7733 snapshot is selected.
7734
7735 Here are the various forms of using the @code{tfind} command.
7736
7737 @table @code
7738 @item tfind start
7739 Find the first snapshot in the buffer. This is a synonym for
7740 @code{tfind 0} (since 0 is the number of the first snapshot).
7741
7742 @item tfind none
7743 Stop debugging trace snapshots, resume @emph{live} debugging.
7744
7745 @item tfind end
7746 Same as @samp{tfind none}.
7747
7748 @item tfind
7749 No argument means find the next trace snapshot.
7750
7751 @item tfind -
7752 Find the previous trace snapshot before the current one. This permits
7753 retracing earlier steps.
7754
7755 @item tfind tracepoint @var{num}
7756 Find the next snapshot associated with tracepoint @var{num}. Search
7757 proceeds forward from the last examined trace snapshot. If no
7758 argument @var{num} is given, it means find the next snapshot collected
7759 for the same tracepoint as the current snapshot.
7760
7761 @item tfind pc @var{addr}
7762 Find the next snapshot associated with the value @var{addr} of the
7763 program counter. Search proceeds forward from the last examined trace
7764 snapshot. If no argument @var{addr} is given, it means find the next
7765 snapshot with the same value of PC as the current snapshot.
7766
7767 @item tfind outside @var{addr1}, @var{addr2}
7768 Find the next snapshot whose PC is outside the given range of
7769 addresses.
7770
7771 @item tfind range @var{addr1}, @var{addr2}
7772 Find the next snapshot whose PC is between @var{addr1} and
7773 @var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7774
7775 @item tfind line @r{[}@var{file}:@r{]}@var{n}
7776 Find the next snapshot associated with the source line @var{n}. If
7777 the optional argument @var{file} is given, refer to line @var{n} in
7778 that source file. Search proceeds forward from the last examined
7779 trace snapshot. If no argument @var{n} is given, it means find the
7780 next line other than the one currently being examined; thus saying
7781 @code{tfind line} repeatedly can appear to have the same effect as
7782 stepping from line to line in a @emph{live} debugging session.
7783 @end table
7784
7785 The default arguments for the @code{tfind} commands are specifically
7786 designed to make it easy to scan through the trace buffer. For
7787 instance, @code{tfind} with no argument selects the next trace
7788 snapshot, and @code{tfind -} with no argument selects the previous
7789 trace snapshot. So, by giving one @code{tfind} command, and then
7790 simply hitting @key{RET} repeatedly you can examine all the trace
7791 snapshots in order. Or, by saying @code{tfind -} and then hitting
7792 @key{RET} repeatedly you can examine the snapshots in reverse order.
7793 The @code{tfind line} command with no argument selects the snapshot
7794 for the next source line executed. The @code{tfind pc} command with
7795 no argument selects the next snapshot with the same program counter
7796 (PC) as the current frame. The @code{tfind tracepoint} command with
7797 no argument selects the next trace snapshot collected by the same
7798 tracepoint as the current one.
7799
7800 In addition to letting you scan through the trace buffer manually,
7801 these commands make it easy to construct @value{GDBN} scripts that
7802 scan through the trace buffer and print out whatever collected data
7803 you are interested in. Thus, if we want to examine the PC, FP, and SP
7804 registers from each trace frame in the buffer, we can say this:
7805
7806 @smallexample
7807 (@value{GDBP}) @b{tfind start}
7808 (@value{GDBP}) @b{while ($trace_frame != -1)}
7809 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7810 $trace_frame, $pc, $sp, $fp
7811 > tfind
7812 > end
7813
7814 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7815 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7816 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7817 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7818 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7819 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7820 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7821 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7822 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7823 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7824 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7825 @end smallexample
7826
7827 Or, if we want to examine the variable @code{X} at each source line in
7828 the buffer:
7829
7830 @smallexample
7831 (@value{GDBP}) @b{tfind start}
7832 (@value{GDBP}) @b{while ($trace_frame != -1)}
7833 > printf "Frame %d, X == %d\n", $trace_frame, X
7834 > tfind line
7835 > end
7836
7837 Frame 0, X = 1
7838 Frame 7, X = 2
7839 Frame 13, X = 255
7840 @end smallexample
7841
7842 @node tdump
7843 @subsection @code{tdump}
7844 @kindex tdump
7845 @cindex dump all data collected at tracepoint
7846 @cindex tracepoint data, display
7847
7848 This command takes no arguments. It prints all the data collected at
7849 the current trace snapshot.
7850
7851 @smallexample
7852 (@value{GDBP}) @b{trace 444}
7853 (@value{GDBP}) @b{actions}
7854 Enter actions for tracepoint #2, one per line:
7855 > collect $regs, $locals, $args, gdb_long_test
7856 > end
7857
7858 (@value{GDBP}) @b{tstart}
7859
7860 (@value{GDBP}) @b{tfind line 444}
7861 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7862 at gdb_test.c:444
7863 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7864
7865 (@value{GDBP}) @b{tdump}
7866 Data collected at tracepoint 2, trace frame 1:
7867 d0 0xc4aa0085 -995491707
7868 d1 0x18 24
7869 d2 0x80 128
7870 d3 0x33 51
7871 d4 0x71aea3d 119204413
7872 d5 0x22 34
7873 d6 0xe0 224
7874 d7 0x380035 3670069
7875 a0 0x19e24a 1696330
7876 a1 0x3000668 50333288
7877 a2 0x100 256
7878 a3 0x322000 3284992
7879 a4 0x3000698 50333336
7880 a5 0x1ad3cc 1758156
7881 fp 0x30bf3c 0x30bf3c
7882 sp 0x30bf34 0x30bf34
7883 ps 0x0 0
7884 pc 0x20b2c8 0x20b2c8
7885 fpcontrol 0x0 0
7886 fpstatus 0x0 0
7887 fpiaddr 0x0 0
7888 p = 0x20e5b4 "gdb-test"
7889 p1 = (void *) 0x11
7890 p2 = (void *) 0x22
7891 p3 = (void *) 0x33
7892 p4 = (void *) 0x44
7893 p5 = (void *) 0x55
7894 p6 = (void *) 0x66
7895 gdb_long_test = 17 '\021'
7896
7897 (@value{GDBP})
7898 @end smallexample
7899
7900 @node save-tracepoints
7901 @subsection @code{save-tracepoints @var{filename}}
7902 @kindex save-tracepoints
7903 @cindex save tracepoints for future sessions
7904
7905 This command saves all current tracepoint definitions together with
7906 their actions and passcounts, into a file @file{@var{filename}}
7907 suitable for use in a later debugging session. To read the saved
7908 tracepoint definitions, use the @code{source} command (@pxref{Command
7909 Files}).
7910
7911 @node Tracepoint Variables
7912 @section Convenience Variables for Tracepoints
7913 @cindex tracepoint variables
7914 @cindex convenience variables for tracepoints
7915
7916 @table @code
7917 @vindex $trace_frame
7918 @item (int) $trace_frame
7919 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7920 snapshot is selected.
7921
7922 @vindex $tracepoint
7923 @item (int) $tracepoint
7924 The tracepoint for the current trace snapshot.
7925
7926 @vindex $trace_line
7927 @item (int) $trace_line
7928 The line number for the current trace snapshot.
7929
7930 @vindex $trace_file
7931 @item (char []) $trace_file
7932 The source file for the current trace snapshot.
7933
7934 @vindex $trace_func
7935 @item (char []) $trace_func
7936 The name of the function containing @code{$tracepoint}.
7937 @end table
7938
7939 Note: @code{$trace_file} is not suitable for use in @code{printf},
7940 use @code{output} instead.
7941
7942 Here's a simple example of using these convenience variables for
7943 stepping through all the trace snapshots and printing some of their
7944 data.
7945
7946 @smallexample
7947 (@value{GDBP}) @b{tfind start}
7948
7949 (@value{GDBP}) @b{while $trace_frame != -1}
7950 > output $trace_file
7951 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7952 > tfind
7953 > end
7954 @end smallexample
7955
7956 @node Overlays
7957 @chapter Debugging Programs That Use Overlays
7958 @cindex overlays
7959
7960 If your program is too large to fit completely in your target system's
7961 memory, you can sometimes use @dfn{overlays} to work around this
7962 problem. @value{GDBN} provides some support for debugging programs that
7963 use overlays.
7964
7965 @menu
7966 * How Overlays Work:: A general explanation of overlays.
7967 * Overlay Commands:: Managing overlays in @value{GDBN}.
7968 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7969 mapped by asking the inferior.
7970 * Overlay Sample Program:: A sample program using overlays.
7971 @end menu
7972
7973 @node How Overlays Work
7974 @section How Overlays Work
7975 @cindex mapped overlays
7976 @cindex unmapped overlays
7977 @cindex load address, overlay's
7978 @cindex mapped address
7979 @cindex overlay area
7980
7981 Suppose you have a computer whose instruction address space is only 64
7982 kilobytes long, but which has much more memory which can be accessed by
7983 other means: special instructions, segment registers, or memory
7984 management hardware, for example. Suppose further that you want to
7985 adapt a program which is larger than 64 kilobytes to run on this system.
7986
7987 One solution is to identify modules of your program which are relatively
7988 independent, and need not call each other directly; call these modules
7989 @dfn{overlays}. Separate the overlays from the main program, and place
7990 their machine code in the larger memory. Place your main program in
7991 instruction memory, but leave at least enough space there to hold the
7992 largest overlay as well.
7993
7994 Now, to call a function located in an overlay, you must first copy that
7995 overlay's machine code from the large memory into the space set aside
7996 for it in the instruction memory, and then jump to its entry point
7997 there.
7998
7999 @c NB: In the below the mapped area's size is greater or equal to the
8000 @c size of all overlays. This is intentional to remind the developer
8001 @c that overlays don't necessarily need to be the same size.
8002
8003 @smallexample
8004 @group
8005 Data Instruction Larger
8006 Address Space Address Space Address Space
8007 +-----------+ +-----------+ +-----------+
8008 | | | | | |
8009 +-----------+ +-----------+ +-----------+<-- overlay 1
8010 | program | | main | .----| overlay 1 | load address
8011 | variables | | program | | +-----------+
8012 | and heap | | | | | |
8013 +-----------+ | | | +-----------+<-- overlay 2
8014 | | +-----------+ | | | load address
8015 +-----------+ | | | .-| overlay 2 |
8016 | | | | | |
8017 mapped --->+-----------+ | | +-----------+
8018 address | | | | | |
8019 | overlay | <-' | | |
8020 | area | <---' +-----------+<-- overlay 3
8021 | | <---. | | load address
8022 +-----------+ `--| overlay 3 |
8023 | | | |
8024 +-----------+ | |
8025 +-----------+
8026 | |
8027 +-----------+
8028
8029 @anchor{A code overlay}A code overlay
8030 @end group
8031 @end smallexample
8032
8033 The diagram (@pxref{A code overlay}) shows a system with separate data
8034 and instruction address spaces. To map an overlay, the program copies
8035 its code from the larger address space to the instruction address space.
8036 Since the overlays shown here all use the same mapped address, only one
8037 may be mapped at a time. For a system with a single address space for
8038 data and instructions, the diagram would be similar, except that the
8039 program variables and heap would share an address space with the main
8040 program and the overlay area.
8041
8042 An overlay loaded into instruction memory and ready for use is called a
8043 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8044 instruction memory. An overlay not present (or only partially present)
8045 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8046 is its address in the larger memory. The mapped address is also called
8047 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8048 called the @dfn{load memory address}, or @dfn{LMA}.
8049
8050 Unfortunately, overlays are not a completely transparent way to adapt a
8051 program to limited instruction memory. They introduce a new set of
8052 global constraints you must keep in mind as you design your program:
8053
8054 @itemize @bullet
8055
8056 @item
8057 Before calling or returning to a function in an overlay, your program
8058 must make sure that overlay is actually mapped. Otherwise, the call or
8059 return will transfer control to the right address, but in the wrong
8060 overlay, and your program will probably crash.
8061
8062 @item
8063 If the process of mapping an overlay is expensive on your system, you
8064 will need to choose your overlays carefully to minimize their effect on
8065 your program's performance.
8066
8067 @item
8068 The executable file you load onto your system must contain each
8069 overlay's instructions, appearing at the overlay's load address, not its
8070 mapped address. However, each overlay's instructions must be relocated
8071 and its symbols defined as if the overlay were at its mapped address.
8072 You can use GNU linker scripts to specify different load and relocation
8073 addresses for pieces of your program; see @ref{Overlay Description,,,
8074 ld.info, Using ld: the GNU linker}.
8075
8076 @item
8077 The procedure for loading executable files onto your system must be able
8078 to load their contents into the larger address space as well as the
8079 instruction and data spaces.
8080
8081 @end itemize
8082
8083 The overlay system described above is rather simple, and could be
8084 improved in many ways:
8085
8086 @itemize @bullet
8087
8088 @item
8089 If your system has suitable bank switch registers or memory management
8090 hardware, you could use those facilities to make an overlay's load area
8091 contents simply appear at their mapped address in instruction space.
8092 This would probably be faster than copying the overlay to its mapped
8093 area in the usual way.
8094
8095 @item
8096 If your overlays are small enough, you could set aside more than one
8097 overlay area, and have more than one overlay mapped at a time.
8098
8099 @item
8100 You can use overlays to manage data, as well as instructions. In
8101 general, data overlays are even less transparent to your design than
8102 code overlays: whereas code overlays only require care when you call or
8103 return to functions, data overlays require care every time you access
8104 the data. Also, if you change the contents of a data overlay, you
8105 must copy its contents back out to its load address before you can copy a
8106 different data overlay into the same mapped area.
8107
8108 @end itemize
8109
8110
8111 @node Overlay Commands
8112 @section Overlay Commands
8113
8114 To use @value{GDBN}'s overlay support, each overlay in your program must
8115 correspond to a separate section of the executable file. The section's
8116 virtual memory address and load memory address must be the overlay's
8117 mapped and load addresses. Identifying overlays with sections allows
8118 @value{GDBN} to determine the appropriate address of a function or
8119 variable, depending on whether the overlay is mapped or not.
8120
8121 @value{GDBN}'s overlay commands all start with the word @code{overlay};
8122 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
8123
8124 @table @code
8125 @item overlay off
8126 @kindex overlay
8127 Disable @value{GDBN}'s overlay support. When overlay support is
8128 disabled, @value{GDBN} assumes that all functions and variables are
8129 always present at their mapped addresses. By default, @value{GDBN}'s
8130 overlay support is disabled.
8131
8132 @item overlay manual
8133 @cindex manual overlay debugging
8134 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
8135 relies on you to tell it which overlays are mapped, and which are not,
8136 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8137 commands described below.
8138
8139 @item overlay map-overlay @var{overlay}
8140 @itemx overlay map @var{overlay}
8141 @cindex map an overlay
8142 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8143 be the name of the object file section containing the overlay. When an
8144 overlay is mapped, @value{GDBN} assumes it can find the overlay's
8145 functions and variables at their mapped addresses. @value{GDBN} assumes
8146 that any other overlays whose mapped ranges overlap that of
8147 @var{overlay} are now unmapped.
8148
8149 @item overlay unmap-overlay @var{overlay}
8150 @itemx overlay unmap @var{overlay}
8151 @cindex unmap an overlay
8152 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8153 must be the name of the object file section containing the overlay.
8154 When an overlay is unmapped, @value{GDBN} assumes it can find the
8155 overlay's functions and variables at their load addresses.
8156
8157 @item overlay auto
8158 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
8159 consults a data structure the overlay manager maintains in the inferior
8160 to see which overlays are mapped. For details, see @ref{Automatic
8161 Overlay Debugging}.
8162
8163 @item overlay load-target
8164 @itemx overlay load
8165 @cindex reloading the overlay table
8166 Re-read the overlay table from the inferior. Normally, @value{GDBN}
8167 re-reads the table @value{GDBN} automatically each time the inferior
8168 stops, so this command should only be necessary if you have changed the
8169 overlay mapping yourself using @value{GDBN}. This command is only
8170 useful when using automatic overlay debugging.
8171
8172 @item overlay list-overlays
8173 @itemx overlay list
8174 @cindex listing mapped overlays
8175 Display a list of the overlays currently mapped, along with their mapped
8176 addresses, load addresses, and sizes.
8177
8178 @end table
8179
8180 Normally, when @value{GDBN} prints a code address, it includes the name
8181 of the function the address falls in:
8182
8183 @smallexample
8184 (@value{GDBP}) print main
8185 $3 = @{int ()@} 0x11a0 <main>
8186 @end smallexample
8187 @noindent
8188 When overlay debugging is enabled, @value{GDBN} recognizes code in
8189 unmapped overlays, and prints the names of unmapped functions with
8190 asterisks around them. For example, if @code{foo} is a function in an
8191 unmapped overlay, @value{GDBN} prints it this way:
8192
8193 @smallexample
8194 (@value{GDBP}) overlay list
8195 No sections are mapped.
8196 (@value{GDBP}) print foo
8197 $5 = @{int (int)@} 0x100000 <*foo*>
8198 @end smallexample
8199 @noindent
8200 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8201 name normally:
8202
8203 @smallexample
8204 (@value{GDBP}) overlay list
8205 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
8206 mapped at 0x1016 - 0x104a
8207 (@value{GDBP}) print foo
8208 $6 = @{int (int)@} 0x1016 <foo>
8209 @end smallexample
8210
8211 When overlay debugging is enabled, @value{GDBN} can find the correct
8212 address for functions and variables in an overlay, whether or not the
8213 overlay is mapped. This allows most @value{GDBN} commands, like
8214 @code{break} and @code{disassemble}, to work normally, even on unmapped
8215 code. However, @value{GDBN}'s breakpoint support has some limitations:
8216
8217 @itemize @bullet
8218 @item
8219 @cindex breakpoints in overlays
8220 @cindex overlays, setting breakpoints in
8221 You can set breakpoints in functions in unmapped overlays, as long as
8222 @value{GDBN} can write to the overlay at its load address.
8223 @item
8224 @value{GDBN} can not set hardware or simulator-based breakpoints in
8225 unmapped overlays. However, if you set a breakpoint at the end of your
8226 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8227 you are using manual overlay management), @value{GDBN} will re-set its
8228 breakpoints properly.
8229 @end itemize
8230
8231
8232 @node Automatic Overlay Debugging
8233 @section Automatic Overlay Debugging
8234 @cindex automatic overlay debugging
8235
8236 @value{GDBN} can automatically track which overlays are mapped and which
8237 are not, given some simple co-operation from the overlay manager in the
8238 inferior. If you enable automatic overlay debugging with the
8239 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8240 looks in the inferior's memory for certain variables describing the
8241 current state of the overlays.
8242
8243 Here are the variables your overlay manager must define to support
8244 @value{GDBN}'s automatic overlay debugging:
8245
8246 @table @asis
8247
8248 @item @code{_ovly_table}:
8249 This variable must be an array of the following structures:
8250
8251 @smallexample
8252 struct
8253 @{
8254 /* The overlay's mapped address. */
8255 unsigned long vma;
8256
8257 /* The size of the overlay, in bytes. */
8258 unsigned long size;
8259
8260 /* The overlay's load address. */
8261 unsigned long lma;
8262
8263 /* Non-zero if the overlay is currently mapped;
8264 zero otherwise. */
8265 unsigned long mapped;
8266 @}
8267 @end smallexample
8268
8269 @item @code{_novlys}:
8270 This variable must be a four-byte signed integer, holding the total
8271 number of elements in @code{_ovly_table}.
8272
8273 @end table
8274
8275 To decide whether a particular overlay is mapped or not, @value{GDBN}
8276 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8277 @code{lma} members equal the VMA and LMA of the overlay's section in the
8278 executable file. When @value{GDBN} finds a matching entry, it consults
8279 the entry's @code{mapped} member to determine whether the overlay is
8280 currently mapped.
8281
8282 In addition, your overlay manager may define a function called
8283 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
8284 will silently set a breakpoint there. If the overlay manager then
8285 calls this function whenever it has changed the overlay table, this
8286 will enable @value{GDBN} to accurately keep track of which overlays
8287 are in program memory, and update any breakpoints that may be set
8288 in overlays. This will allow breakpoints to work even if the
8289 overlays are kept in ROM or other non-writable memory while they
8290 are not being executed.
8291
8292 @node Overlay Sample Program
8293 @section Overlay Sample Program
8294 @cindex overlay example program
8295
8296 When linking a program which uses overlays, you must place the overlays
8297 at their load addresses, while relocating them to run at their mapped
8298 addresses. To do this, you must write a linker script (@pxref{Overlay
8299 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8300 since linker scripts are specific to a particular host system, target
8301 architecture, and target memory layout, this manual cannot provide
8302 portable sample code demonstrating @value{GDBN}'s overlay support.
8303
8304 However, the @value{GDBN} source distribution does contain an overlaid
8305 program, with linker scripts for a few systems, as part of its test
8306 suite. The program consists of the following files from
8307 @file{gdb/testsuite/gdb.base}:
8308
8309 @table @file
8310 @item overlays.c
8311 The main program file.
8312 @item ovlymgr.c
8313 A simple overlay manager, used by @file{overlays.c}.
8314 @item foo.c
8315 @itemx bar.c
8316 @itemx baz.c
8317 @itemx grbx.c
8318 Overlay modules, loaded and used by @file{overlays.c}.
8319 @item d10v.ld
8320 @itemx m32r.ld
8321 Linker scripts for linking the test program on the @code{d10v-elf}
8322 and @code{m32r-elf} targets.
8323 @end table
8324
8325 You can build the test program using the @code{d10v-elf} GCC
8326 cross-compiler like this:
8327
8328 @smallexample
8329 $ d10v-elf-gcc -g -c overlays.c
8330 $ d10v-elf-gcc -g -c ovlymgr.c
8331 $ d10v-elf-gcc -g -c foo.c
8332 $ d10v-elf-gcc -g -c bar.c
8333 $ d10v-elf-gcc -g -c baz.c
8334 $ d10v-elf-gcc -g -c grbx.c
8335 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8336 baz.o grbx.o -Wl,-Td10v.ld -o overlays
8337 @end smallexample
8338
8339 The build process is identical for any other architecture, except that
8340 you must substitute the appropriate compiler and linker script for the
8341 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8342
8343
8344 @node Languages
8345 @chapter Using @value{GDBN} with Different Languages
8346 @cindex languages
8347
8348 Although programming languages generally have common aspects, they are
8349 rarely expressed in the same manner. For instance, in ANSI C,
8350 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8351 Modula-2, it is accomplished by @code{p^}. Values can also be
8352 represented (and displayed) differently. Hex numbers in C appear as
8353 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
8354
8355 @cindex working language
8356 Language-specific information is built into @value{GDBN} for some languages,
8357 allowing you to express operations like the above in your program's
8358 native language, and allowing @value{GDBN} to output values in a manner
8359 consistent with the syntax of your program's native language. The
8360 language you use to build expressions is called the @dfn{working
8361 language}.
8362
8363 @menu
8364 * Setting:: Switching between source languages
8365 * Show:: Displaying the language
8366 * Checks:: Type and range checks
8367 * Supported languages:: Supported languages
8368 * Unsupported languages:: Unsupported languages
8369 @end menu
8370
8371 @node Setting
8372 @section Switching between source languages
8373
8374 There are two ways to control the working language---either have @value{GDBN}
8375 set it automatically, or select it manually yourself. You can use the
8376 @code{set language} command for either purpose. On startup, @value{GDBN}
8377 defaults to setting the language automatically. The working language is
8378 used to determine how expressions you type are interpreted, how values
8379 are printed, etc.
8380
8381 In addition to the working language, every source file that
8382 @value{GDBN} knows about has its own working language. For some object
8383 file formats, the compiler might indicate which language a particular
8384 source file is in. However, most of the time @value{GDBN} infers the
8385 language from the name of the file. The language of a source file
8386 controls whether C@t{++} names are demangled---this way @code{backtrace} can
8387 show each frame appropriately for its own language. There is no way to
8388 set the language of a source file from within @value{GDBN}, but you can
8389 set the language associated with a filename extension. @xref{Show, ,
8390 Displaying the language}.
8391
8392 This is most commonly a problem when you use a program, such
8393 as @code{cfront} or @code{f2c}, that generates C but is written in
8394 another language. In that case, make the
8395 program use @code{#line} directives in its C output; that way
8396 @value{GDBN} will know the correct language of the source code of the original
8397 program, and will display that source code, not the generated C code.
8398
8399 @menu
8400 * Filenames:: Filename extensions and languages.
8401 * Manually:: Setting the working language manually
8402 * Automatically:: Having @value{GDBN} infer the source language
8403 @end menu
8404
8405 @node Filenames
8406 @subsection List of filename extensions and languages
8407
8408 If a source file name ends in one of the following extensions, then
8409 @value{GDBN} infers that its language is the one indicated.
8410
8411 @table @file
8412 @item .ada
8413 @itemx .ads
8414 @itemx .adb
8415 @itemx .a
8416 Ada source file.
8417
8418 @item .c
8419 C source file
8420
8421 @item .C
8422 @itemx .cc
8423 @itemx .cp
8424 @itemx .cpp
8425 @itemx .cxx
8426 @itemx .c++
8427 C@t{++} source file
8428
8429 @item .m
8430 Objective-C source file
8431
8432 @item .f
8433 @itemx .F
8434 Fortran source file
8435
8436 @item .mod
8437 Modula-2 source file
8438
8439 @item .s
8440 @itemx .S
8441 Assembler source file. This actually behaves almost like C, but
8442 @value{GDBN} does not skip over function prologues when stepping.
8443 @end table
8444
8445 In addition, you may set the language associated with a filename
8446 extension. @xref{Show, , Displaying the language}.
8447
8448 @node Manually
8449 @subsection Setting the working language
8450
8451 If you allow @value{GDBN} to set the language automatically,
8452 expressions are interpreted the same way in your debugging session and
8453 your program.
8454
8455 @kindex set language
8456 If you wish, you may set the language manually. To do this, issue the
8457 command @samp{set language @var{lang}}, where @var{lang} is the name of
8458 a language, such as
8459 @code{c} or @code{modula-2}.
8460 For a list of the supported languages, type @samp{set language}.
8461
8462 Setting the language manually prevents @value{GDBN} from updating the working
8463 language automatically. This can lead to confusion if you try
8464 to debug a program when the working language is not the same as the
8465 source language, when an expression is acceptable to both
8466 languages---but means different things. For instance, if the current
8467 source file were written in C, and @value{GDBN} was parsing Modula-2, a
8468 command such as:
8469
8470 @smallexample
8471 print a = b + c
8472 @end smallexample
8473
8474 @noindent
8475 might not have the effect you intended. In C, this means to add
8476 @code{b} and @code{c} and place the result in @code{a}. The result
8477 printed would be the value of @code{a}. In Modula-2, this means to compare
8478 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
8479
8480 @node Automatically
8481 @subsection Having @value{GDBN} infer the source language
8482
8483 To have @value{GDBN} set the working language automatically, use
8484 @samp{set language local} or @samp{set language auto}. @value{GDBN}
8485 then infers the working language. That is, when your program stops in a
8486 frame (usually by encountering a breakpoint), @value{GDBN} sets the
8487 working language to the language recorded for the function in that
8488 frame. If the language for a frame is unknown (that is, if the function
8489 or block corresponding to the frame was defined in a source file that
8490 does not have a recognized extension), the current working language is
8491 not changed, and @value{GDBN} issues a warning.
8492
8493 This may not seem necessary for most programs, which are written
8494 entirely in one source language. However, program modules and libraries
8495 written in one source language can be used by a main program written in
8496 a different source language. Using @samp{set language auto} in this
8497 case frees you from having to set the working language manually.
8498
8499 @node Show
8500 @section Displaying the language
8501
8502 The following commands help you find out which language is the
8503 working language, and also what language source files were written in.
8504
8505 @table @code
8506 @item show language
8507 @kindex show language
8508 Display the current working language. This is the
8509 language you can use with commands such as @code{print} to
8510 build and compute expressions that may involve variables in your program.
8511
8512 @item info frame
8513 @kindex info frame@r{, show the source language}
8514 Display the source language for this frame. This language becomes the
8515 working language if you use an identifier from this frame.
8516 @xref{Frame Info, ,Information about a frame}, to identify the other
8517 information listed here.
8518
8519 @item info source
8520 @kindex info source@r{, show the source language}
8521 Display the source language of this source file.
8522 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
8523 information listed here.
8524 @end table
8525
8526 In unusual circumstances, you may have source files with extensions
8527 not in the standard list. You can then set the extension associated
8528 with a language explicitly:
8529
8530 @table @code
8531 @item set extension-language @var{ext} @var{language}
8532 @kindex set extension-language
8533 Tell @value{GDBN} that source files with extension @var{ext} are to be
8534 assumed as written in the source language @var{language}.
8535
8536 @item info extensions
8537 @kindex info extensions
8538 List all the filename extensions and the associated languages.
8539 @end table
8540
8541 @node Checks
8542 @section Type and range checking
8543
8544 @quotation
8545 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
8546 checking are included, but they do not yet have any effect. This
8547 section documents the intended facilities.
8548 @end quotation
8549 @c FIXME remove warning when type/range code added
8550
8551 Some languages are designed to guard you against making seemingly common
8552 errors through a series of compile- and run-time checks. These include
8553 checking the type of arguments to functions and operators, and making
8554 sure mathematical overflows are caught at run time. Checks such as
8555 these help to ensure a program's correctness once it has been compiled
8556 by eliminating type mismatches, and providing active checks for range
8557 errors when your program is running.
8558
8559 @value{GDBN} can check for conditions like the above if you wish.
8560 Although @value{GDBN} does not check the statements in your program,
8561 it can check expressions entered directly into @value{GDBN} for
8562 evaluation via the @code{print} command, for example. As with the
8563 working language, @value{GDBN} can also decide whether or not to check
8564 automatically based on your program's source language.
8565 @xref{Supported languages, ,Supported languages}, for the default
8566 settings of supported languages.
8567
8568 @menu
8569 * Type Checking:: An overview of type checking
8570 * Range Checking:: An overview of range checking
8571 @end menu
8572
8573 @cindex type checking
8574 @cindex checks, type
8575 @node Type Checking
8576 @subsection An overview of type checking
8577
8578 Some languages, such as Modula-2, are strongly typed, meaning that the
8579 arguments to operators and functions have to be of the correct type,
8580 otherwise an error occurs. These checks prevent type mismatch
8581 errors from ever causing any run-time problems. For example,
8582
8583 @smallexample
8584 1 + 2 @result{} 3
8585 @exdent but
8586 @error{} 1 + 2.3
8587 @end smallexample
8588
8589 The second example fails because the @code{CARDINAL} 1 is not
8590 type-compatible with the @code{REAL} 2.3.
8591
8592 For the expressions you use in @value{GDBN} commands, you can tell the
8593 @value{GDBN} type checker to skip checking;
8594 to treat any mismatches as errors and abandon the expression;
8595 or to only issue warnings when type mismatches occur,
8596 but evaluate the expression anyway. When you choose the last of
8597 these, @value{GDBN} evaluates expressions like the second example above, but
8598 also issues a warning.
8599
8600 Even if you turn type checking off, there may be other reasons
8601 related to type that prevent @value{GDBN} from evaluating an expression.
8602 For instance, @value{GDBN} does not know how to add an @code{int} and
8603 a @code{struct foo}. These particular type errors have nothing to do
8604 with the language in use, and usually arise from expressions, such as
8605 the one described above, which make little sense to evaluate anyway.
8606
8607 Each language defines to what degree it is strict about type. For
8608 instance, both Modula-2 and C require the arguments to arithmetical
8609 operators to be numbers. In C, enumerated types and pointers can be
8610 represented as numbers, so that they are valid arguments to mathematical
8611 operators. @xref{Supported languages, ,Supported languages}, for further
8612 details on specific languages.
8613
8614 @value{GDBN} provides some additional commands for controlling the type checker:
8615
8616 @kindex set check type
8617 @kindex show check type
8618 @table @code
8619 @item set check type auto
8620 Set type checking on or off based on the current working language.
8621 @xref{Supported languages, ,Supported languages}, for the default settings for
8622 each language.
8623
8624 @item set check type on
8625 @itemx set check type off
8626 Set type checking on or off, overriding the default setting for the
8627 current working language. Issue a warning if the setting does not
8628 match the language default. If any type mismatches occur in
8629 evaluating an expression while type checking is on, @value{GDBN} prints a
8630 message and aborts evaluation of the expression.
8631
8632 @item set check type warn
8633 Cause the type checker to issue warnings, but to always attempt to
8634 evaluate the expression. Evaluating the expression may still
8635 be impossible for other reasons. For example, @value{GDBN} cannot add
8636 numbers and structures.
8637
8638 @item show type
8639 Show the current setting of the type checker, and whether or not @value{GDBN}
8640 is setting it automatically.
8641 @end table
8642
8643 @cindex range checking
8644 @cindex checks, range
8645 @node Range Checking
8646 @subsection An overview of range checking
8647
8648 In some languages (such as Modula-2), it is an error to exceed the
8649 bounds of a type; this is enforced with run-time checks. Such range
8650 checking is meant to ensure program correctness by making sure
8651 computations do not overflow, or indices on an array element access do
8652 not exceed the bounds of the array.
8653
8654 For expressions you use in @value{GDBN} commands, you can tell
8655 @value{GDBN} to treat range errors in one of three ways: ignore them,
8656 always treat them as errors and abandon the expression, or issue
8657 warnings but evaluate the expression anyway.
8658
8659 A range error can result from numerical overflow, from exceeding an
8660 array index bound, or when you type a constant that is not a member
8661 of any type. Some languages, however, do not treat overflows as an
8662 error. In many implementations of C, mathematical overflow causes the
8663 result to ``wrap around'' to lower values---for example, if @var{m} is
8664 the largest integer value, and @var{s} is the smallest, then
8665
8666 @smallexample
8667 @var{m} + 1 @result{} @var{s}
8668 @end smallexample
8669
8670 This, too, is specific to individual languages, and in some cases
8671 specific to individual compilers or machines. @xref{Supported languages, ,
8672 Supported languages}, for further details on specific languages.
8673
8674 @value{GDBN} provides some additional commands for controlling the range checker:
8675
8676 @kindex set check range
8677 @kindex show check range
8678 @table @code
8679 @item set check range auto
8680 Set range checking on or off based on the current working language.
8681 @xref{Supported languages, ,Supported languages}, for the default settings for
8682 each language.
8683
8684 @item set check range on
8685 @itemx set check range off
8686 Set range checking on or off, overriding the default setting for the
8687 current working language. A warning is issued if the setting does not
8688 match the language default. If a range error occurs and range checking is on,
8689 then a message is printed and evaluation of the expression is aborted.
8690
8691 @item set check range warn
8692 Output messages when the @value{GDBN} range checker detects a range error,
8693 but attempt to evaluate the expression anyway. Evaluating the
8694 expression may still be impossible for other reasons, such as accessing
8695 memory that the process does not own (a typical example from many Unix
8696 systems).
8697
8698 @item show range
8699 Show the current setting of the range checker, and whether or not it is
8700 being set automatically by @value{GDBN}.
8701 @end table
8702
8703 @node Supported languages
8704 @section Supported languages
8705
8706 @value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8707 assembly, Modula-2, and Ada.
8708 @c This is false ...
8709 Some @value{GDBN} features may be used in expressions regardless of the
8710 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8711 and the @samp{@{type@}addr} construct (@pxref{Expressions,
8712 ,Expressions}) can be used with the constructs of any supported
8713 language.
8714
8715 The following sections detail to what degree each source language is
8716 supported by @value{GDBN}. These sections are not meant to be language
8717 tutorials or references, but serve only as a reference guide to what the
8718 @value{GDBN} expression parser accepts, and what input and output
8719 formats should look like for different languages. There are many good
8720 books written on each of these languages; please look to these for a
8721 language reference or tutorial.
8722
8723 @menu
8724 * C:: C and C@t{++}
8725 * Objective-C:: Objective-C
8726 * Fortran:: Fortran
8727 * Pascal:: Pascal
8728 * Modula-2:: Modula-2
8729 * Ada:: Ada
8730 @end menu
8731
8732 @node C
8733 @subsection C and C@t{++}
8734
8735 @cindex C and C@t{++}
8736 @cindex expressions in C or C@t{++}
8737
8738 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
8739 to both languages. Whenever this is the case, we discuss those languages
8740 together.
8741
8742 @cindex C@t{++}
8743 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
8744 @cindex @sc{gnu} C@t{++}
8745 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8746 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8747 effectively, you must compile your C@t{++} programs with a supported
8748 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
8749 compiler (@code{aCC}).
8750
8751 For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8752 format; if it doesn't work on your system, try the stabs+ debugging
8753 format. You can select those formats explicitly with the @code{g++}
8754 command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8755 @xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8756 CC, gcc.info, Using @sc{gnu} CC}.
8757
8758 @menu
8759 * C Operators:: C and C@t{++} operators
8760 * C Constants:: C and C@t{++} constants
8761 * C plus plus expressions:: C@t{++} expressions
8762 * C Defaults:: Default settings for C and C@t{++}
8763 * C Checks:: C and C@t{++} type and range checks
8764 * Debugging C:: @value{GDBN} and C
8765 * Debugging C plus plus:: @value{GDBN} features for C@t{++}
8766 @end menu
8767
8768 @node C Operators
8769 @subsubsection C and C@t{++} operators
8770
8771 @cindex C and C@t{++} operators
8772
8773 Operators must be defined on values of specific types. For instance,
8774 @code{+} is defined on numbers, but not on structures. Operators are
8775 often defined on groups of types.
8776
8777 For the purposes of C and C@t{++}, the following definitions hold:
8778
8779 @itemize @bullet
8780
8781 @item
8782 @emph{Integral types} include @code{int} with any of its storage-class
8783 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
8784
8785 @item
8786 @emph{Floating-point types} include @code{float}, @code{double}, and
8787 @code{long double} (if supported by the target platform).
8788
8789 @item
8790 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
8791
8792 @item
8793 @emph{Scalar types} include all of the above.
8794
8795 @end itemize
8796
8797 @noindent
8798 The following operators are supported. They are listed here
8799 in order of increasing precedence:
8800
8801 @table @code
8802 @item ,
8803 The comma or sequencing operator. Expressions in a comma-separated list
8804 are evaluated from left to right, with the result of the entire
8805 expression being the last expression evaluated.
8806
8807 @item =
8808 Assignment. The value of an assignment expression is the value
8809 assigned. Defined on scalar types.
8810
8811 @item @var{op}=
8812 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8813 and translated to @w{@code{@var{a} = @var{a op b}}}.
8814 @w{@code{@var{op}=}} and @code{=} have the same precedence.
8815 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8816 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8817
8818 @item ?:
8819 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8820 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8821 integral type.
8822
8823 @item ||
8824 Logical @sc{or}. Defined on integral types.
8825
8826 @item &&
8827 Logical @sc{and}. Defined on integral types.
8828
8829 @item |
8830 Bitwise @sc{or}. Defined on integral types.
8831
8832 @item ^
8833 Bitwise exclusive-@sc{or}. Defined on integral types.
8834
8835 @item &
8836 Bitwise @sc{and}. Defined on integral types.
8837
8838 @item ==@r{, }!=
8839 Equality and inequality. Defined on scalar types. The value of these
8840 expressions is 0 for false and non-zero for true.
8841
8842 @item <@r{, }>@r{, }<=@r{, }>=
8843 Less than, greater than, less than or equal, greater than or equal.
8844 Defined on scalar types. The value of these expressions is 0 for false
8845 and non-zero for true.
8846
8847 @item <<@r{, }>>
8848 left shift, and right shift. Defined on integral types.
8849
8850 @item @@
8851 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8852
8853 @item +@r{, }-
8854 Addition and subtraction. Defined on integral types, floating-point types and
8855 pointer types.
8856
8857 @item *@r{, }/@r{, }%
8858 Multiplication, division, and modulus. Multiplication and division are
8859 defined on integral and floating-point types. Modulus is defined on
8860 integral types.
8861
8862 @item ++@r{, }--
8863 Increment and decrement. When appearing before a variable, the
8864 operation is performed before the variable is used in an expression;
8865 when appearing after it, the variable's value is used before the
8866 operation takes place.
8867
8868 @item *
8869 Pointer dereferencing. Defined on pointer types. Same precedence as
8870 @code{++}.
8871
8872 @item &
8873 Address operator. Defined on variables. Same precedence as @code{++}.
8874
8875 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8876 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
8877 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
8878 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
8879 stored.
8880
8881 @item -
8882 Negative. Defined on integral and floating-point types. Same
8883 precedence as @code{++}.
8884
8885 @item !
8886 Logical negation. Defined on integral types. Same precedence as
8887 @code{++}.
8888
8889 @item ~
8890 Bitwise complement operator. Defined on integral types. Same precedence as
8891 @code{++}.
8892
8893
8894 @item .@r{, }->
8895 Structure member, and pointer-to-structure member. For convenience,
8896 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
8897 pointer based on the stored type information.
8898 Defined on @code{struct} and @code{union} data.
8899
8900 @item .*@r{, }->*
8901 Dereferences of pointers to members.
8902
8903 @item []
8904 Array indexing. @code{@var{a}[@var{i}]} is defined as
8905 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8906
8907 @item ()
8908 Function parameter list. Same precedence as @code{->}.
8909
8910 @item ::
8911 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
8912 and @code{class} types.
8913
8914 @item ::
8915 Doubled colons also represent the @value{GDBN} scope operator
8916 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8917 above.
8918 @end table
8919
8920 If an operator is redefined in the user code, @value{GDBN} usually
8921 attempts to invoke the redefined version instead of using the operator's
8922 predefined meaning.
8923
8924 @menu
8925 * C Constants::
8926 @end menu
8927
8928 @node C Constants
8929 @subsubsection C and C@t{++} constants
8930
8931 @cindex C and C@t{++} constants
8932
8933 @value{GDBN} allows you to express the constants of C and C@t{++} in the
8934 following ways:
8935
8936 @itemize @bullet
8937 @item
8938 Integer constants are a sequence of digits. Octal constants are
8939 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8940 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
8941 @samp{l}, specifying that the constant should be treated as a
8942 @code{long} value.
8943
8944 @item
8945 Floating point constants are a sequence of digits, followed by a decimal
8946 point, followed by a sequence of digits, and optionally followed by an
8947 exponent. An exponent is of the form:
8948 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8949 sequence of digits. The @samp{+} is optional for positive exponents.
8950 A floating-point constant may also end with a letter @samp{f} or
8951 @samp{F}, specifying that the constant should be treated as being of
8952 the @code{float} (as opposed to the default @code{double}) type; or with
8953 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8954 constant.
8955
8956 @item
8957 Enumerated constants consist of enumerated identifiers, or their
8958 integral equivalents.
8959
8960 @item
8961 Character constants are a single character surrounded by single quotes
8962 (@code{'}), or a number---the ordinal value of the corresponding character
8963 (usually its @sc{ascii} value). Within quotes, the single character may
8964 be represented by a letter or by @dfn{escape sequences}, which are of
8965 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8966 of the character's ordinal value; or of the form @samp{\@var{x}}, where
8967 @samp{@var{x}} is a predefined special character---for example,
8968 @samp{\n} for newline.
8969
8970 @item
8971 String constants are a sequence of character constants surrounded by
8972 double quotes (@code{"}). Any valid character constant (as described
8973 above) may appear. Double quotes within the string must be preceded by
8974 a backslash, so for instance @samp{"a\"b'c"} is a string of five
8975 characters.
8976
8977 @item
8978 Pointer constants are an integral value. You can also write pointers
8979 to constants using the C operator @samp{&}.
8980
8981 @item
8982 Array constants are comma-separated lists surrounded by braces @samp{@{}
8983 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8984 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8985 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8986 @end itemize
8987
8988 @menu
8989 * C plus plus expressions::
8990 * C Defaults::
8991 * C Checks::
8992
8993 * Debugging C::
8994 @end menu
8995
8996 @node C plus plus expressions
8997 @subsubsection C@t{++} expressions
8998
8999 @cindex expressions in C@t{++}
9000 @value{GDBN} expression handling can interpret most C@t{++} expressions.
9001
9002 @cindex debugging C@t{++} programs
9003 @cindex C@t{++} compilers
9004 @cindex debug formats and C@t{++}
9005 @cindex @value{NGCC} and C@t{++}
9006 @quotation
9007 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
9008 proper compiler and the proper debug format. Currently, @value{GDBN}
9009 works best when debugging C@t{++} code that is compiled with
9010 @value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9011 @option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
9012 stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
9013 stabs+ as their default debug format, so you usually don't need to
9014 specify a debug format explicitly. Other compilers and/or debug formats
9015 are likely to work badly or not at all when using @value{GDBN} to debug
9016 C@t{++} code.
9017 @end quotation
9018
9019 @enumerate
9020
9021 @cindex member functions
9022 @item
9023 Member function calls are allowed; you can use expressions like
9024
9025 @smallexample
9026 count = aml->GetOriginal(x, y)
9027 @end smallexample
9028
9029 @vindex this@r{, inside C@t{++} member functions}
9030 @cindex namespace in C@t{++}
9031 @item
9032 While a member function is active (in the selected stack frame), your
9033 expressions have the same namespace available as the member function;
9034 that is, @value{GDBN} allows implicit references to the class instance
9035 pointer @code{this} following the same rules as C@t{++}.
9036
9037 @cindex call overloaded functions
9038 @cindex overloaded functions, calling
9039 @cindex type conversions in C@t{++}
9040 @item
9041 You can call overloaded functions; @value{GDBN} resolves the function
9042 call to the right definition, with some restrictions. @value{GDBN} does not
9043 perform overload resolution involving user-defined type conversions,
9044 calls to constructors, or instantiations of templates that do not exist
9045 in the program. It also cannot handle ellipsis argument lists or
9046 default arguments.
9047
9048 It does perform integral conversions and promotions, floating-point
9049 promotions, arithmetic conversions, pointer conversions, conversions of
9050 class objects to base classes, and standard conversions such as those of
9051 functions or arrays to pointers; it requires an exact match on the
9052 number of function arguments.
9053
9054 Overload resolution is always performed, unless you have specified
9055 @code{set overload-resolution off}. @xref{Debugging C plus plus,
9056 ,@value{GDBN} features for C@t{++}}.
9057
9058 You must specify @code{set overload-resolution off} in order to use an
9059 explicit function signature to call an overloaded function, as in
9060 @smallexample
9061 p 'foo(char,int)'('x', 13)
9062 @end smallexample
9063
9064 The @value{GDBN} command-completion facility can simplify this;
9065 see @ref{Completion, ,Command completion}.
9066
9067 @cindex reference declarations
9068 @item
9069 @value{GDBN} understands variables declared as C@t{++} references; you can use
9070 them in expressions just as you do in C@t{++} source---they are automatically
9071 dereferenced.
9072
9073 In the parameter list shown when @value{GDBN} displays a frame, the values of
9074 reference variables are not displayed (unlike other variables); this
9075 avoids clutter, since references are often used for large structures.
9076 The @emph{address} of a reference variable is always shown, unless
9077 you have specified @samp{set print address off}.
9078
9079 @item
9080 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
9081 expressions can use it just as expressions in your program do. Since
9082 one scope may be defined in another, you can use @code{::} repeatedly if
9083 necessary, for example in an expression like
9084 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
9085 resolving name scope by reference to source files, in both C and C@t{++}
9086 debugging (@pxref{Variables, ,Program variables}).
9087 @end enumerate
9088
9089 In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
9090 calling virtual functions correctly, printing out virtual bases of
9091 objects, calling functions in a base subobject, casting objects, and
9092 invoking user-defined operators.
9093
9094 @node C Defaults
9095 @subsubsection C and C@t{++} defaults
9096
9097 @cindex C and C@t{++} defaults
9098
9099 If you allow @value{GDBN} to set type and range checking automatically, they
9100 both default to @code{off} whenever the working language changes to
9101 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
9102 selects the working language.
9103
9104 If you allow @value{GDBN} to set the language automatically, it
9105 recognizes source files whose names end with @file{.c}, @file{.C}, or
9106 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
9107 these files, it sets the working language to C or C@t{++}.
9108 @xref{Automatically, ,Having @value{GDBN} infer the source language},
9109 for further details.
9110
9111 @c Type checking is (a) primarily motivated by Modula-2, and (b)
9112 @c unimplemented. If (b) changes, it might make sense to let this node
9113 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
9114
9115 @node C Checks
9116 @subsubsection C and C@t{++} type and range checks
9117
9118 @cindex C and C@t{++} checks
9119
9120 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
9121 is not used. However, if you turn type checking on, @value{GDBN}
9122 considers two variables type equivalent if:
9123
9124 @itemize @bullet
9125 @item
9126 The two variables are structured and have the same structure, union, or
9127 enumerated tag.
9128
9129 @item
9130 The two variables have the same type name, or types that have been
9131 declared equivalent through @code{typedef}.
9132
9133 @ignore
9134 @c leaving this out because neither J Gilmore nor R Pesch understand it.
9135 @c FIXME--beers?
9136 @item
9137 The two @code{struct}, @code{union}, or @code{enum} variables are
9138 declared in the same declaration. (Note: this may not be true for all C
9139 compilers.)
9140 @end ignore
9141 @end itemize
9142
9143 Range checking, if turned on, is done on mathematical operations. Array
9144 indices are not checked, since they are often used to index a pointer
9145 that is not itself an array.
9146
9147 @node Debugging C
9148 @subsubsection @value{GDBN} and C
9149
9150 The @code{set print union} and @code{show print union} commands apply to
9151 the @code{union} type. When set to @samp{on}, any @code{union} that is
9152 inside a @code{struct} or @code{class} is also printed. Otherwise, it
9153 appears as @samp{@{...@}}.
9154
9155 The @code{@@} operator aids in the debugging of dynamic arrays, formed
9156 with pointers and a memory allocation function. @xref{Expressions,
9157 ,Expressions}.
9158
9159 @menu
9160 * Debugging C plus plus::
9161 @end menu
9162
9163 @node Debugging C plus plus
9164 @subsubsection @value{GDBN} features for C@t{++}
9165
9166 @cindex commands for C@t{++}
9167
9168 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9169 designed specifically for use with C@t{++}. Here is a summary:
9170
9171 @table @code
9172 @cindex break in overloaded functions
9173 @item @r{breakpoint menus}
9174 When you want a breakpoint in a function whose name is overloaded,
9175 @value{GDBN} breakpoint menus help you specify which function definition
9176 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
9177
9178 @cindex overloading in C@t{++}
9179 @item rbreak @var{regex}
9180 Setting breakpoints using regular expressions is helpful for setting
9181 breakpoints on overloaded functions that are not members of any special
9182 classes.
9183 @xref{Set Breaks, ,Setting breakpoints}.
9184
9185 @cindex C@t{++} exception handling
9186 @item catch throw
9187 @itemx catch catch
9188 Debug C@t{++} exception handling using these commands. @xref{Set
9189 Catchpoints, , Setting catchpoints}.
9190
9191 @cindex inheritance
9192 @item ptype @var{typename}
9193 Print inheritance relationships as well as other information for type
9194 @var{typename}.
9195 @xref{Symbols, ,Examining the Symbol Table}.
9196
9197 @cindex C@t{++} symbol display
9198 @item set print demangle
9199 @itemx show print demangle
9200 @itemx set print asm-demangle
9201 @itemx show print asm-demangle
9202 Control whether C@t{++} symbols display in their source form, both when
9203 displaying code as C@t{++} source and when displaying disassemblies.
9204 @xref{Print Settings, ,Print settings}.
9205
9206 @item set print object
9207 @itemx show print object
9208 Choose whether to print derived (actual) or declared types of objects.
9209 @xref{Print Settings, ,Print settings}.
9210
9211 @item set print vtbl
9212 @itemx show print vtbl
9213 Control the format for printing virtual function tables.
9214 @xref{Print Settings, ,Print settings}.
9215 (The @code{vtbl} commands do not work on programs compiled with the HP
9216 ANSI C@t{++} compiler (@code{aCC}).)
9217
9218 @kindex set overload-resolution
9219 @cindex overloaded functions, overload resolution
9220 @item set overload-resolution on
9221 Enable overload resolution for C@t{++} expression evaluation. The default
9222 is on. For overloaded functions, @value{GDBN} evaluates the arguments
9223 and searches for a function whose signature matches the argument types,
9224 using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
9225 expressions}, for details). If it cannot find a match, it emits a
9226 message.
9227
9228 @item set overload-resolution off
9229 Disable overload resolution for C@t{++} expression evaluation. For
9230 overloaded functions that are not class member functions, @value{GDBN}
9231 chooses the first function of the specified name that it finds in the
9232 symbol table, whether or not its arguments are of the correct type. For
9233 overloaded functions that are class member functions, @value{GDBN}
9234 searches for a function whose signature @emph{exactly} matches the
9235 argument types.
9236
9237 @kindex show overload-resolution
9238 @item show overload-resolution
9239 Show the current setting of overload resolution.
9240
9241 @item @r{Overloaded symbol names}
9242 You can specify a particular definition of an overloaded symbol, using
9243 the same notation that is used to declare such symbols in C@t{++}: type
9244 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9245 also use the @value{GDBN} command-line word completion facilities to list the
9246 available choices, or to finish the type list for you.
9247 @xref{Completion,, Command completion}, for details on how to do this.
9248 @end table
9249
9250 @node Objective-C
9251 @subsection Objective-C
9252
9253 @cindex Objective-C
9254 This section provides information about some commands and command
9255 options that are useful for debugging Objective-C code. See also
9256 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9257 few more commands specific to Objective-C support.
9258
9259 @menu
9260 * Method Names in Commands::
9261 * The Print Command with Objective-C::
9262 @end menu
9263
9264 @node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9265 @subsubsection Method Names in Commands
9266
9267 The following commands have been extended to accept Objective-C method
9268 names as line specifications:
9269
9270 @kindex clear@r{, and Objective-C}
9271 @kindex break@r{, and Objective-C}
9272 @kindex info line@r{, and Objective-C}
9273 @kindex jump@r{, and Objective-C}
9274 @kindex list@r{, and Objective-C}
9275 @itemize
9276 @item @code{clear}
9277 @item @code{break}
9278 @item @code{info line}
9279 @item @code{jump}
9280 @item @code{list}
9281 @end itemize
9282
9283 A fully qualified Objective-C method name is specified as
9284
9285 @smallexample
9286 -[@var{Class} @var{methodName}]
9287 @end smallexample
9288
9289 where the minus sign is used to indicate an instance method and a
9290 plus sign (not shown) is used to indicate a class method. The class
9291 name @var{Class} and method name @var{methodName} are enclosed in
9292 brackets, similar to the way messages are specified in Objective-C
9293 source code. For example, to set a breakpoint at the @code{create}
9294 instance method of class @code{Fruit} in the program currently being
9295 debugged, enter:
9296
9297 @smallexample
9298 break -[Fruit create]
9299 @end smallexample
9300
9301 To list ten program lines around the @code{initialize} class method,
9302 enter:
9303
9304 @smallexample
9305 list +[NSText initialize]
9306 @end smallexample
9307
9308 In the current version of @value{GDBN}, the plus or minus sign is
9309 required. In future versions of @value{GDBN}, the plus or minus
9310 sign will be optional, but you can use it to narrow the search. It
9311 is also possible to specify just a method name:
9312
9313 @smallexample
9314 break create
9315 @end smallexample
9316
9317 You must specify the complete method name, including any colons. If
9318 your program's source files contain more than one @code{create} method,
9319 you'll be presented with a numbered list of classes that implement that
9320 method. Indicate your choice by number, or type @samp{0} to exit if
9321 none apply.
9322
9323 As another example, to clear a breakpoint established at the
9324 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9325
9326 @smallexample
9327 clear -[NSWindow makeKeyAndOrderFront:]
9328 @end smallexample
9329
9330 @node The Print Command with Objective-C
9331 @subsubsection The Print Command With Objective-C
9332 @cindex Objective-C, print objects
9333 @kindex print-object
9334 @kindex po @r{(@code{print-object})}
9335
9336 The print command has also been extended to accept methods. For example:
9337
9338 @smallexample
9339 print -[@var{object} hash]
9340 @end smallexample
9341
9342 @cindex print an Objective-C object description
9343 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9344 @noindent
9345 will tell @value{GDBN} to send the @code{hash} message to @var{object}
9346 and print the result. Also, an additional command has been added,
9347 @code{print-object} or @code{po} for short, which is meant to print
9348 the description of an object. However, this command may only work
9349 with certain Objective-C libraries that have a particular hook
9350 function, @code{_NSPrintForDebugger}, defined.
9351
9352 @node Fortran
9353 @subsection Fortran
9354 @cindex Fortran-specific support in @value{GDBN}
9355
9356 @value{GDBN} can be used to debug programs written in Fortran, but it
9357 currently supports only the features of Fortran 77 language.
9358
9359 @cindex trailing underscore, in Fortran symbols
9360 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9361 among them) append an underscore to the names of variables and
9362 functions. When you debug programs compiled by those compilers, you
9363 will need to refer to variables and functions with a trailing
9364 underscore.
9365
9366 @menu
9367 * Fortran Operators:: Fortran operators and expressions
9368 * Fortran Defaults:: Default settings for Fortran
9369 * Special Fortran commands:: Special @value{GDBN} commands for Fortran
9370 @end menu
9371
9372 @node Fortran Operators
9373 @subsubsection Fortran operators and expressions
9374
9375 @cindex Fortran operators and expressions
9376
9377 Operators must be defined on values of specific types. For instance,
9378 @code{+} is defined on numbers, but not on characters or other non-
9379 arithmetic types. Operators are often defined on groups of types.
9380
9381 @table @code
9382 @item **
9383 The exponentiation operator. It raises the first operand to the power
9384 of the second one.
9385
9386 @item :
9387 The range operator. Normally used in the form of array(low:high) to
9388 represent a section of array.
9389 @end table
9390
9391 @node Fortran Defaults
9392 @subsubsection Fortran Defaults
9393
9394 @cindex Fortran Defaults
9395
9396 Fortran symbols are usually case-insensitive, so @value{GDBN} by
9397 default uses case-insensitive matches for Fortran symbols. You can
9398 change that with the @samp{set case-insensitive} command, see
9399 @ref{Symbols}, for the details.
9400
9401 @node Special Fortran commands
9402 @subsubsection Special Fortran commands
9403
9404 @cindex Special Fortran commands
9405
9406 @value{GDBN} had some commands to support Fortran specific feature,
9407 such as common block displaying.
9408
9409 @table @code
9410 @cindex @code{COMMON} blocks, Fortran
9411 @kindex info common
9412 @item info common @r{[}@var{common-name}@r{]}
9413 This command prints the values contained in the Fortran @code{COMMON}
9414 block whose name is @var{common-name}. With no argument, the names of
9415 all @code{COMMON} blocks visible at current program location are
9416 printed.
9417 @end table
9418
9419 @node Pascal
9420 @subsection Pascal
9421
9422 @cindex Pascal support in @value{GDBN}, limitations
9423 Debugging Pascal programs which use sets, subranges, file variables, or
9424 nested functions does not currently work. @value{GDBN} does not support
9425 entering expressions, printing values, or similar features using Pascal
9426 syntax.
9427
9428 The Pascal-specific command @code{set print pascal_static-members}
9429 controls whether static members of Pascal objects are displayed.
9430 @xref{Print Settings, pascal_static-members}.
9431
9432 @node Modula-2
9433 @subsection Modula-2
9434
9435 @cindex Modula-2, @value{GDBN} support
9436
9437 The extensions made to @value{GDBN} to support Modula-2 only support
9438 output from the @sc{gnu} Modula-2 compiler (which is currently being
9439 developed). Other Modula-2 compilers are not currently supported, and
9440 attempting to debug executables produced by them is most likely
9441 to give an error as @value{GDBN} reads in the executable's symbol
9442 table.
9443
9444 @cindex expressions in Modula-2
9445 @menu
9446 * M2 Operators:: Built-in operators
9447 * Built-In Func/Proc:: Built-in functions and procedures
9448 * M2 Constants:: Modula-2 constants
9449 * M2 Defaults:: Default settings for Modula-2
9450 * Deviations:: Deviations from standard Modula-2
9451 * M2 Checks:: Modula-2 type and range checks
9452 * M2 Scope:: The scope operators @code{::} and @code{.}
9453 * GDB/M2:: @value{GDBN} and Modula-2
9454 @end menu
9455
9456 @node M2 Operators
9457 @subsubsection Operators
9458 @cindex Modula-2 operators
9459
9460 Operators must be defined on values of specific types. For instance,
9461 @code{+} is defined on numbers, but not on structures. Operators are
9462 often defined on groups of types. For the purposes of Modula-2, the
9463 following definitions hold:
9464
9465 @itemize @bullet
9466
9467 @item
9468 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9469 their subranges.
9470
9471 @item
9472 @emph{Character types} consist of @code{CHAR} and its subranges.
9473
9474 @item
9475 @emph{Floating-point types} consist of @code{REAL}.
9476
9477 @item
9478 @emph{Pointer types} consist of anything declared as @code{POINTER TO
9479 @var{type}}.
9480
9481 @item
9482 @emph{Scalar types} consist of all of the above.
9483
9484 @item
9485 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
9486
9487 @item
9488 @emph{Boolean types} consist of @code{BOOLEAN}.
9489 @end itemize
9490
9491 @noindent
9492 The following operators are supported, and appear in order of
9493 increasing precedence:
9494
9495 @table @code
9496 @item ,
9497 Function argument or array index separator.
9498
9499 @item :=
9500 Assignment. The value of @var{var} @code{:=} @var{value} is
9501 @var{value}.
9502
9503 @item <@r{, }>
9504 Less than, greater than on integral, floating-point, or enumerated
9505 types.
9506
9507 @item <=@r{, }>=
9508 Less than or equal to, greater than or equal to
9509 on integral, floating-point and enumerated types, or set inclusion on
9510 set types. Same precedence as @code{<}.
9511
9512 @item =@r{, }<>@r{, }#
9513 Equality and two ways of expressing inequality, valid on scalar types.
9514 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9515 available for inequality, since @code{#} conflicts with the script
9516 comment character.
9517
9518 @item IN
9519 Set membership. Defined on set types and the types of their members.
9520 Same precedence as @code{<}.
9521
9522 @item OR
9523 Boolean disjunction. Defined on boolean types.
9524
9525 @item AND@r{, }&
9526 Boolean conjunction. Defined on boolean types.
9527
9528 @item @@
9529 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9530
9531 @item +@r{, }-
9532 Addition and subtraction on integral and floating-point types, or union
9533 and difference on set types.
9534
9535 @item *
9536 Multiplication on integral and floating-point types, or set intersection
9537 on set types.
9538
9539 @item /
9540 Division on floating-point types, or symmetric set difference on set
9541 types. Same precedence as @code{*}.
9542
9543 @item DIV@r{, }MOD
9544 Integer division and remainder. Defined on integral types. Same
9545 precedence as @code{*}.
9546
9547 @item -
9548 Negative. Defined on @code{INTEGER} and @code{REAL} data.
9549
9550 @item ^
9551 Pointer dereferencing. Defined on pointer types.
9552
9553 @item NOT
9554 Boolean negation. Defined on boolean types. Same precedence as
9555 @code{^}.
9556
9557 @item .
9558 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
9559 precedence as @code{^}.
9560
9561 @item []
9562 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9563
9564 @item ()
9565 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9566 as @code{^}.
9567
9568 @item ::@r{, }.
9569 @value{GDBN} and Modula-2 scope operators.
9570 @end table
9571
9572 @quotation
9573 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9574 treats the use of the operator @code{IN}, or the use of operators
9575 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9576 @code{<=}, and @code{>=} on sets as an error.
9577 @end quotation
9578
9579
9580 @node Built-In Func/Proc
9581 @subsubsection Built-in functions and procedures
9582 @cindex Modula-2 built-ins
9583
9584 Modula-2 also makes available several built-in procedures and functions.
9585 In describing these, the following metavariables are used:
9586
9587 @table @var
9588
9589 @item a
9590 represents an @code{ARRAY} variable.
9591
9592 @item c
9593 represents a @code{CHAR} constant or variable.
9594
9595 @item i
9596 represents a variable or constant of integral type.
9597
9598 @item m
9599 represents an identifier that belongs to a set. Generally used in the
9600 same function with the metavariable @var{s}. The type of @var{s} should
9601 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9602
9603 @item n
9604 represents a variable or constant of integral or floating-point type.
9605
9606 @item r
9607 represents a variable or constant of floating-point type.
9608
9609 @item t
9610 represents a type.
9611
9612 @item v
9613 represents a variable.
9614
9615 @item x
9616 represents a variable or constant of one of many types. See the
9617 explanation of the function for details.
9618 @end table
9619
9620 All Modula-2 built-in procedures also return a result, described below.
9621
9622 @table @code
9623 @item ABS(@var{n})
9624 Returns the absolute value of @var{n}.
9625
9626 @item CAP(@var{c})
9627 If @var{c} is a lower case letter, it returns its upper case
9628 equivalent, otherwise it returns its argument.
9629
9630 @item CHR(@var{i})
9631 Returns the character whose ordinal value is @var{i}.
9632
9633 @item DEC(@var{v})
9634 Decrements the value in the variable @var{v} by one. Returns the new value.
9635
9636 @item DEC(@var{v},@var{i})
9637 Decrements the value in the variable @var{v} by @var{i}. Returns the
9638 new value.
9639
9640 @item EXCL(@var{m},@var{s})
9641 Removes the element @var{m} from the set @var{s}. Returns the new
9642 set.
9643
9644 @item FLOAT(@var{i})
9645 Returns the floating point equivalent of the integer @var{i}.
9646
9647 @item HIGH(@var{a})
9648 Returns the index of the last member of @var{a}.
9649
9650 @item INC(@var{v})
9651 Increments the value in the variable @var{v} by one. Returns the new value.
9652
9653 @item INC(@var{v},@var{i})
9654 Increments the value in the variable @var{v} by @var{i}. Returns the
9655 new value.
9656
9657 @item INCL(@var{m},@var{s})
9658 Adds the element @var{m} to the set @var{s} if it is not already
9659 there. Returns the new set.
9660
9661 @item MAX(@var{t})
9662 Returns the maximum value of the type @var{t}.
9663
9664 @item MIN(@var{t})
9665 Returns the minimum value of the type @var{t}.
9666
9667 @item ODD(@var{i})
9668 Returns boolean TRUE if @var{i} is an odd number.
9669
9670 @item ORD(@var{x})
9671 Returns the ordinal value of its argument. For example, the ordinal
9672 value of a character is its @sc{ascii} value (on machines supporting the
9673 @sc{ascii} character set). @var{x} must be of an ordered type, which include
9674 integral, character and enumerated types.
9675
9676 @item SIZE(@var{x})
9677 Returns the size of its argument. @var{x} can be a variable or a type.
9678
9679 @item TRUNC(@var{r})
9680 Returns the integral part of @var{r}.
9681
9682 @item VAL(@var{t},@var{i})
9683 Returns the member of the type @var{t} whose ordinal value is @var{i}.
9684 @end table
9685
9686 @quotation
9687 @emph{Warning:} Sets and their operations are not yet supported, so
9688 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9689 an error.
9690 @end quotation
9691
9692 @cindex Modula-2 constants
9693 @node M2 Constants
9694 @subsubsection Constants
9695
9696 @value{GDBN} allows you to express the constants of Modula-2 in the following
9697 ways:
9698
9699 @itemize @bullet
9700
9701 @item
9702 Integer constants are simply a sequence of digits. When used in an
9703 expression, a constant is interpreted to be type-compatible with the
9704 rest of the expression. Hexadecimal integers are specified by a
9705 trailing @samp{H}, and octal integers by a trailing @samp{B}.
9706
9707 @item
9708 Floating point constants appear as a sequence of digits, followed by a
9709 decimal point and another sequence of digits. An optional exponent can
9710 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9711 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9712 digits of the floating point constant must be valid decimal (base 10)
9713 digits.
9714
9715 @item
9716 Character constants consist of a single character enclosed by a pair of
9717 like quotes, either single (@code{'}) or double (@code{"}). They may
9718 also be expressed by their ordinal value (their @sc{ascii} value, usually)
9719 followed by a @samp{C}.
9720
9721 @item
9722 String constants consist of a sequence of characters enclosed by a
9723 pair of like quotes, either single (@code{'}) or double (@code{"}).
9724 Escape sequences in the style of C are also allowed. @xref{C
9725 Constants, ,C and C@t{++} constants}, for a brief explanation of escape
9726 sequences.
9727
9728 @item
9729 Enumerated constants consist of an enumerated identifier.
9730
9731 @item
9732 Boolean constants consist of the identifiers @code{TRUE} and
9733 @code{FALSE}.
9734
9735 @item
9736 Pointer constants consist of integral values only.
9737
9738 @item
9739 Set constants are not yet supported.
9740 @end itemize
9741
9742 @node M2 Defaults
9743 @subsubsection Modula-2 defaults
9744 @cindex Modula-2 defaults
9745
9746 If type and range checking are set automatically by @value{GDBN}, they
9747 both default to @code{on} whenever the working language changes to
9748 Modula-2. This happens regardless of whether you or @value{GDBN}
9749 selected the working language.
9750
9751 If you allow @value{GDBN} to set the language automatically, then entering
9752 code compiled from a file whose name ends with @file{.mod} sets the
9753 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
9754 the language automatically}, for further details.
9755
9756 @node Deviations
9757 @subsubsection Deviations from standard Modula-2
9758 @cindex Modula-2, deviations from
9759
9760 A few changes have been made to make Modula-2 programs easier to debug.
9761 This is done primarily via loosening its type strictness:
9762
9763 @itemize @bullet
9764 @item
9765 Unlike in standard Modula-2, pointer constants can be formed by
9766 integers. This allows you to modify pointer variables during
9767 debugging. (In standard Modula-2, the actual address contained in a
9768 pointer variable is hidden from you; it can only be modified
9769 through direct assignment to another pointer variable or expression that
9770 returned a pointer.)
9771
9772 @item
9773 C escape sequences can be used in strings and characters to represent
9774 non-printable characters. @value{GDBN} prints out strings with these
9775 escape sequences embedded. Single non-printable characters are
9776 printed using the @samp{CHR(@var{nnn})} format.
9777
9778 @item
9779 The assignment operator (@code{:=}) returns the value of its right-hand
9780 argument.
9781
9782 @item
9783 All built-in procedures both modify @emph{and} return their argument.
9784 @end itemize
9785
9786 @node M2 Checks
9787 @subsubsection Modula-2 type and range checks
9788 @cindex Modula-2 checks
9789
9790 @quotation
9791 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9792 range checking.
9793 @end quotation
9794 @c FIXME remove warning when type/range checks added
9795
9796 @value{GDBN} considers two Modula-2 variables type equivalent if:
9797
9798 @itemize @bullet
9799 @item
9800 They are of types that have been declared equivalent via a @code{TYPE
9801 @var{t1} = @var{t2}} statement
9802
9803 @item
9804 They have been declared on the same line. (Note: This is true of the
9805 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9806 @end itemize
9807
9808 As long as type checking is enabled, any attempt to combine variables
9809 whose types are not equivalent is an error.
9810
9811 Range checking is done on all mathematical operations, assignment, array
9812 index bounds, and all built-in functions and procedures.
9813
9814 @node M2 Scope
9815 @subsubsection The scope operators @code{::} and @code{.}
9816 @cindex scope
9817 @cindex @code{.}, Modula-2 scope operator
9818 @cindex colon, doubled as scope operator
9819 @ifinfo
9820 @vindex colon-colon@r{, in Modula-2}
9821 @c Info cannot handle :: but TeX can.
9822 @end ifinfo
9823 @iftex
9824 @vindex ::@r{, in Modula-2}
9825 @end iftex
9826
9827 There are a few subtle differences between the Modula-2 scope operator
9828 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9829 similar syntax:
9830
9831 @smallexample
9832
9833 @var{module} . @var{id}
9834 @var{scope} :: @var{id}
9835 @end smallexample
9836
9837 @noindent
9838 where @var{scope} is the name of a module or a procedure,
9839 @var{module} the name of a module, and @var{id} is any declared
9840 identifier within your program, except another module.
9841
9842 Using the @code{::} operator makes @value{GDBN} search the scope
9843 specified by @var{scope} for the identifier @var{id}. If it is not
9844 found in the specified scope, then @value{GDBN} searches all scopes
9845 enclosing the one specified by @var{scope}.
9846
9847 Using the @code{.} operator makes @value{GDBN} search the current scope for
9848 the identifier specified by @var{id} that was imported from the
9849 definition module specified by @var{module}. With this operator, it is
9850 an error if the identifier @var{id} was not imported from definition
9851 module @var{module}, or if @var{id} is not an identifier in
9852 @var{module}.
9853
9854 @node GDB/M2
9855 @subsubsection @value{GDBN} and Modula-2
9856
9857 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9858 Five subcommands of @code{set print} and @code{show print} apply
9859 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
9860 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
9861 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
9862 analogue in Modula-2.
9863
9864 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
9865 with any language, is not useful with Modula-2. Its
9866 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
9867 created in Modula-2 as they can in C or C@t{++}. However, because an
9868 address can be specified by an integral constant, the construct
9869 @samp{@{@var{type}@}@var{adrexp}} is still useful.
9870
9871 @cindex @code{#} in Modula-2
9872 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9873 interpreted as the beginning of a comment. Use @code{<>} instead.
9874
9875 @node Ada
9876 @subsection Ada
9877 @cindex Ada
9878
9879 The extensions made to @value{GDBN} for Ada only support
9880 output from the @sc{gnu} Ada (GNAT) compiler.
9881 Other Ada compilers are not currently supported, and
9882 attempting to debug executables produced by them is most likely
9883 to be difficult.
9884
9885
9886 @cindex expressions in Ada
9887 @menu
9888 * Ada Mode Intro:: General remarks on the Ada syntax
9889 and semantics supported by Ada mode
9890 in @value{GDBN}.
9891 * Omissions from Ada:: Restrictions on the Ada expression syntax.
9892 * Additions to Ada:: Extensions of the Ada expression syntax.
9893 * Stopping Before Main Program:: Debugging the program during elaboration.
9894 * Ada Glitches:: Known peculiarities of Ada mode.
9895 @end menu
9896
9897 @node Ada Mode Intro
9898 @subsubsection Introduction
9899 @cindex Ada mode, general
9900
9901 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9902 syntax, with some extensions.
9903 The philosophy behind the design of this subset is
9904
9905 @itemize @bullet
9906 @item
9907 That @value{GDBN} should provide basic literals and access to operations for
9908 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9909 leaving more sophisticated computations to subprograms written into the
9910 program (which therefore may be called from @value{GDBN}).
9911
9912 @item
9913 That type safety and strict adherence to Ada language restrictions
9914 are not particularly important to the @value{GDBN} user.
9915
9916 @item
9917 That brevity is important to the @value{GDBN} user.
9918 @end itemize
9919
9920 Thus, for brevity, the debugger acts as if there were
9921 implicit @code{with} and @code{use} clauses in effect for all user-written
9922 packages, making it unnecessary to fully qualify most names with
9923 their packages, regardless of context. Where this causes ambiguity,
9924 @value{GDBN} asks the user's intent.
9925
9926 The debugger will start in Ada mode if it detects an Ada main program.
9927 As for other languages, it will enter Ada mode when stopped in a program that
9928 was translated from an Ada source file.
9929
9930 While in Ada mode, you may use `@t{--}' for comments. This is useful
9931 mostly for documenting command files. The standard @value{GDBN} comment
9932 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9933 middle (to allow based literals).
9934
9935 The debugger supports limited overloading. Given a subprogram call in which
9936 the function symbol has multiple definitions, it will use the number of
9937 actual parameters and some information about their types to attempt to narrow
9938 the set of definitions. It also makes very limited use of context, preferring
9939 procedures to functions in the context of the @code{call} command, and
9940 functions to procedures elsewhere.
9941
9942 @node Omissions from Ada
9943 @subsubsection Omissions from Ada
9944 @cindex Ada, omissions from
9945
9946 Here are the notable omissions from the subset:
9947
9948 @itemize @bullet
9949 @item
9950 Only a subset of the attributes are supported:
9951
9952 @itemize @minus
9953 @item
9954 @t{'First}, @t{'Last}, and @t{'Length}
9955 on array objects (not on types and subtypes).
9956
9957 @item
9958 @t{'Min} and @t{'Max}.
9959
9960 @item
9961 @t{'Pos} and @t{'Val}.
9962
9963 @item
9964 @t{'Tag}.
9965
9966 @item
9967 @t{'Range} on array objects (not subtypes), but only as the right
9968 operand of the membership (@code{in}) operator.
9969
9970 @item
9971 @t{'Access}, @t{'Unchecked_Access}, and
9972 @t{'Unrestricted_Access} (a GNAT extension).
9973
9974 @item
9975 @t{'Address}.
9976 @end itemize
9977
9978 @item
9979 The names in
9980 @code{Characters.Latin_1} are not available and
9981 concatenation is not implemented. Thus, escape characters in strings are
9982 not currently available.
9983
9984 @item
9985 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9986 equality of representations. They will generally work correctly
9987 for strings and arrays whose elements have integer or enumeration types.
9988 They may not work correctly for arrays whose element
9989 types have user-defined equality, for arrays of real values
9990 (in particular, IEEE-conformant floating point, because of negative
9991 zeroes and NaNs), and for arrays whose elements contain unused bits with
9992 indeterminate values.
9993
9994 @item
9995 The other component-by-component array operations (@code{and}, @code{or},
9996 @code{xor}, @code{not}, and relational tests other than equality)
9997 are not implemented.
9998
9999 @item
10000 @cindex array aggregates (Ada)
10001 @cindex record aggregates (Ada)
10002 @cindex aggregates (Ada)
10003 There is limited support for array and record aggregates. They are
10004 permitted only on the right sides of assignments, as in these examples:
10005
10006 @smallexample
10007 set An_Array := (1, 2, 3, 4, 5, 6)
10008 set An_Array := (1, others => 0)
10009 set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10010 set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10011 set A_Record := (1, "Peter", True);
10012 set A_Record := (Name => "Peter", Id => 1, Alive => True)
10013 @end smallexample
10014
10015 Changing a
10016 discriminant's value by assigning an aggregate has an
10017 undefined effect if that discriminant is used within the record.
10018 However, you can first modify discriminants by directly assigning to
10019 them (which normally would not be allowed in Ada), and then performing an
10020 aggregate assignment. For example, given a variable @code{A_Rec}
10021 declared to have a type such as:
10022
10023 @smallexample
10024 type Rec (Len : Small_Integer := 0) is record
10025 Id : Integer;
10026 Vals : IntArray (1 .. Len);
10027 end record;
10028 @end smallexample
10029
10030 you can assign a value with a different size of @code{Vals} with two
10031 assignments:
10032
10033 @smallexample
10034 set A_Rec.Len := 4
10035 set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10036 @end smallexample
10037
10038 As this example also illustrates, @value{GDBN} is very loose about the usual
10039 rules concerning aggregates. You may leave out some of the
10040 components of an array or record aggregate (such as the @code{Len}
10041 component in the assignment to @code{A_Rec} above); they will retain their
10042 original values upon assignment. You may freely use dynamic values as
10043 indices in component associations. You may even use overlapping or
10044 redundant component associations, although which component values are
10045 assigned in such cases is not defined.
10046
10047 @item
10048 Calls to dispatching subprograms are not implemented.
10049
10050 @item
10051 The overloading algorithm is much more limited (i.e., less selective)
10052 than that of real Ada. It makes only limited use of the context in which a subexpression
10053 appears to resolve its meaning, and it is much looser in its rules for allowing
10054 type matches. As a result, some function calls will be ambiguous, and the user
10055 will be asked to choose the proper resolution.
10056
10057 @item
10058 The @code{new} operator is not implemented.
10059
10060 @item
10061 Entry calls are not implemented.
10062
10063 @item
10064 Aside from printing, arithmetic operations on the native VAX floating-point
10065 formats are not supported.
10066
10067 @item
10068 It is not possible to slice a packed array.
10069 @end itemize
10070
10071 @node Additions to Ada
10072 @subsubsection Additions to Ada
10073 @cindex Ada, deviations from
10074
10075 As it does for other languages, @value{GDBN} makes certain generic
10076 extensions to Ada (@pxref{Expressions}):
10077
10078 @itemize @bullet
10079 @item
10080 If the expression @var{E} is a variable residing in memory
10081 (typically a local variable or array element) and @var{N} is
10082 a positive integer, then @code{@var{E}@@@var{N}} displays the values of
10083 @var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
10084 In Ada, this operator is generally not necessary, since its prime use
10085 is in displaying parts of an array, and slicing will usually do this in Ada.
10086 However, there are occasional uses when debugging programs
10087 in which certain debugging information has been optimized away.
10088
10089 @item
10090 @code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
10091 in function or file @var{B}.'' When @var{B} is a file name, you must typically
10092 surround it in single quotes.
10093
10094 @item
10095 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10096 @var{type} that appears at address @var{addr}.''
10097
10098 @item
10099 A name starting with @samp{$} is a convenience variable
10100 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10101 @end itemize
10102
10103 In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
10104 to Ada:
10105
10106 @itemize @bullet
10107 @item
10108 The assignment statement is allowed as an expression, returning
10109 its right-hand operand as its value. Thus, you may enter
10110
10111 @smallexample
10112 set x := y + 3
10113 print A(tmp := y + 1)
10114 @end smallexample
10115
10116 @item
10117 The semicolon is allowed as an ``operator,'' returning as its value
10118 the value of its right-hand operand.
10119 This allows, for example,
10120 complex conditional breaks:
10121
10122 @smallexample
10123 break f
10124 condition 1 (report(i); k += 1; A(k) > 100)
10125 @end smallexample
10126
10127 @item
10128 Rather than use catenation and symbolic character names to introduce special
10129 characters into strings, one may instead use a special bracket notation,
10130 which is also used to print strings. A sequence of characters of the form
10131 @samp{["@var{XX}"]} within a string or character literal denotes the
10132 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
10133 sequence of characters @samp{["""]} also denotes a single quotation mark
10134 in strings. For example,
10135 @smallexample
10136 "One line.["0a"]Next line.["0a"]"
10137 @end smallexample
10138 @noindent
10139 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
10140 period.
10141
10142 @item
10143 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10144 @t{'Max} is optional (and is ignored in any case). For example, it is valid
10145 to write
10146
10147 @smallexample
10148 print 'max(x, y)
10149 @end smallexample
10150
10151 @item
10152 When printing arrays, @value{GDBN} uses positional notation when the
10153 array has a lower bound of 1, and uses a modified named notation otherwise.
10154 For example, a one-dimensional array of three integers with a lower bound of 3 might print as
10155
10156 @smallexample
10157 (3 => 10, 17, 1)
10158 @end smallexample
10159
10160 @noindent
10161 That is, in contrast to valid Ada, only the first component has a @code{=>}
10162 clause.
10163
10164 @item
10165 You may abbreviate attributes in expressions with any unique,
10166 multi-character subsequence of
10167 their names (an exact match gets preference).
10168 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10169 in place of @t{a'length}.
10170
10171 @item
10172 @cindex quoting Ada internal identifiers
10173 Since Ada is case-insensitive, the debugger normally maps identifiers you type
10174 to lower case. The GNAT compiler uses upper-case characters for
10175 some of its internal identifiers, which are normally of no interest to users.
10176 For the rare occasions when you actually have to look at them,
10177 enclose them in angle brackets to avoid the lower-case mapping.
10178 For example,
10179 @smallexample
10180 @value{GDBP} print <JMPBUF_SAVE>[0]
10181 @end smallexample
10182
10183 @item
10184 Printing an object of class-wide type or dereferencing an
10185 access-to-class-wide value will display all the components of the object's
10186 specific type (as indicated by its run-time tag). Likewise, component
10187 selection on such a value will operate on the specific type of the
10188 object.
10189
10190 @end itemize
10191
10192 @node Stopping Before Main Program
10193 @subsubsection Stopping at the Very Beginning
10194
10195 @cindex breakpointing Ada elaboration code
10196 It is sometimes necessary to debug the program during elaboration, and
10197 before reaching the main procedure.
10198 As defined in the Ada Reference
10199 Manual, the elaboration code is invoked from a procedure called
10200 @code{adainit}. To run your program up to the beginning of
10201 elaboration, simply use the following two commands:
10202 @code{tbreak adainit} and @code{run}.
10203
10204 @node Ada Glitches
10205 @subsubsection Known Peculiarities of Ada Mode
10206 @cindex Ada, problems
10207
10208 Besides the omissions listed previously (@pxref{Omissions from Ada}),
10209 we know of several problems with and limitations of Ada mode in
10210 @value{GDBN},
10211 some of which will be fixed with planned future releases of the debugger
10212 and the GNU Ada compiler.
10213
10214 @itemize @bullet
10215 @item
10216 Currently, the debugger
10217 has insufficient information to determine whether certain pointers represent
10218 pointers to objects or the objects themselves.
10219 Thus, the user may have to tack an extra @code{.all} after an expression
10220 to get it printed properly.
10221
10222 @item
10223 Static constants that the compiler chooses not to materialize as objects in
10224 storage are invisible to the debugger.
10225
10226 @item
10227 Named parameter associations in function argument lists are ignored (the
10228 argument lists are treated as positional).
10229
10230 @item
10231 Many useful library packages are currently invisible to the debugger.
10232
10233 @item
10234 Fixed-point arithmetic, conversions, input, and output is carried out using
10235 floating-point arithmetic, and may give results that only approximate those on
10236 the host machine.
10237
10238 @item
10239 The type of the @t{'Address} attribute may not be @code{System.Address}.
10240
10241 @item
10242 The GNAT compiler never generates the prefix @code{Standard} for any of
10243 the standard symbols defined by the Ada language. @value{GDBN} knows about
10244 this: it will strip the prefix from names when you use it, and will never
10245 look for a name you have so qualified among local symbols, nor match against
10246 symbols in other packages or subprograms. If you have
10247 defined entities anywhere in your program other than parameters and
10248 local variables whose simple names match names in @code{Standard},
10249 GNAT's lack of qualification here can cause confusion. When this happens,
10250 you can usually resolve the confusion
10251 by qualifying the problematic names with package
10252 @code{Standard} explicitly.
10253 @end itemize
10254
10255 @node Unsupported languages
10256 @section Unsupported languages
10257
10258 @cindex unsupported languages
10259 @cindex minimal language
10260 In addition to the other fully-supported programming languages,
10261 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
10262 It does not represent a real programming language, but provides a set
10263 of capabilities close to what the C or assembly languages provide.
10264 This should allow most simple operations to be performed while debugging
10265 an application that uses a language currently not supported by @value{GDBN}.
10266
10267 If the language is set to @code{auto}, @value{GDBN} will automatically
10268 select this language if the current frame corresponds to an unsupported
10269 language.
10270
10271 @node Symbols
10272 @chapter Examining the Symbol Table
10273
10274 The commands described in this chapter allow you to inquire about the
10275 symbols (names of variables, functions and types) defined in your
10276 program. This information is inherent in the text of your program and
10277 does not change as your program executes. @value{GDBN} finds it in your
10278 program's symbol table, in the file indicated when you started @value{GDBN}
10279 (@pxref{File Options, ,Choosing files}), or by one of the
10280 file-management commands (@pxref{Files, ,Commands to specify files}).
10281
10282 @cindex symbol names
10283 @cindex names of symbols
10284 @cindex quoting names
10285 Occasionally, you may need to refer to symbols that contain unusual
10286 characters, which @value{GDBN} ordinarily treats as word delimiters. The
10287 most frequent case is in referring to static variables in other
10288 source files (@pxref{Variables,,Program variables}). File names
10289 are recorded in object files as debugging symbols, but @value{GDBN} would
10290 ordinarily parse a typical file name, like @file{foo.c}, as the three words
10291 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
10292 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10293
10294 @smallexample
10295 p 'foo.c'::x
10296 @end smallexample
10297
10298 @noindent
10299 looks up the value of @code{x} in the scope of the file @file{foo.c}.
10300
10301 @table @code
10302 @cindex case-insensitive symbol names
10303 @cindex case sensitivity in symbol names
10304 @kindex set case-sensitive
10305 @item set case-sensitive on
10306 @itemx set case-sensitive off
10307 @itemx set case-sensitive auto
10308 Normally, when @value{GDBN} looks up symbols, it matches their names
10309 with case sensitivity determined by the current source language.
10310 Occasionally, you may wish to control that. The command @code{set
10311 case-sensitive} lets you do that by specifying @code{on} for
10312 case-sensitive matches or @code{off} for case-insensitive ones. If
10313 you specify @code{auto}, case sensitivity is reset to the default
10314 suitable for the source language. The default is case-sensitive
10315 matches for all languages except for Fortran, for which the default is
10316 case-insensitive matches.
10317
10318 @kindex show case-sensitive
10319 @item show case-sensitive
10320 This command shows the current setting of case sensitivity for symbols
10321 lookups.
10322
10323 @kindex info address
10324 @cindex address of a symbol
10325 @item info address @var{symbol}
10326 Describe where the data for @var{symbol} is stored. For a register
10327 variable, this says which register it is kept in. For a non-register
10328 local variable, this prints the stack-frame offset at which the variable
10329 is always stored.
10330
10331 Note the contrast with @samp{print &@var{symbol}}, which does not work
10332 at all for a register variable, and for a stack local variable prints
10333 the exact address of the current instantiation of the variable.
10334
10335 @kindex info symbol
10336 @cindex symbol from address
10337 @cindex closest symbol and offset for an address
10338 @item info symbol @var{addr}
10339 Print the name of a symbol which is stored at the address @var{addr}.
10340 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10341 nearest symbol and an offset from it:
10342
10343 @smallexample
10344 (@value{GDBP}) info symbol 0x54320
10345 _initialize_vx + 396 in section .text
10346 @end smallexample
10347
10348 @noindent
10349 This is the opposite of the @code{info address} command. You can use
10350 it to find out the name of a variable or a function given its address.
10351
10352 @kindex whatis
10353 @item whatis @var{expr}
10354 Print the data type of expression @var{expr}. @var{expr} is not
10355 actually evaluated, and any side-effecting operations (such as
10356 assignments or function calls) inside it do not take place.
10357 @xref{Expressions, ,Expressions}.
10358
10359 @item whatis
10360 Print the data type of @code{$}, the last value in the value history.
10361
10362 @kindex ptype
10363 @item ptype @var{typename}
10364 Print a description of data type @var{typename}. @var{typename} may be
10365 the name of a type, or for C code it may have the form @samp{class
10366 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10367 @var{union-tag}} or @samp{enum @var{enum-tag}}.
10368
10369 @item ptype @var{expr}
10370 @itemx ptype
10371 Print a description of the type of expression @var{expr}. @code{ptype}
10372 differs from @code{whatis} by printing a detailed description, instead
10373 of just the name of the type.
10374
10375 For example, for this variable declaration:
10376
10377 @smallexample
10378 struct complex @{double real; double imag;@} v;
10379 @end smallexample
10380
10381 @noindent
10382 the two commands give this output:
10383
10384 @smallexample
10385 @group
10386 (@value{GDBP}) whatis v
10387 type = struct complex
10388 (@value{GDBP}) ptype v
10389 type = struct complex @{
10390 double real;
10391 double imag;
10392 @}
10393 @end group
10394 @end smallexample
10395
10396 @noindent
10397 As with @code{whatis}, using @code{ptype} without an argument refers to
10398 the type of @code{$}, the last value in the value history.
10399
10400 @cindex incomplete type
10401 Sometimes, programs use opaque data types or incomplete specifications
10402 of complex data structure. If the debug information included in the
10403 program does not allow @value{GDBN} to display a full declaration of
10404 the data type, it will say @samp{<incomplete type>}. For example,
10405 given these declarations:
10406
10407 @smallexample
10408 struct foo;
10409 struct foo *fooptr;
10410 @end smallexample
10411
10412 @noindent
10413 but no definition for @code{struct foo} itself, @value{GDBN} will say:
10414
10415 @smallexample
10416 (gdb) ptype foo
10417 $1 = <incomplete type>
10418 @end smallexample
10419
10420 @noindent
10421 ``Incomplete type'' is C terminology for data types that are not
10422 completely specified.
10423
10424 @kindex info types
10425 @item info types @var{regexp}
10426 @itemx info types
10427 Print a brief description of all types whose names match the regular
10428 expression @var{regexp} (or all types in your program, if you supply
10429 no argument). Each complete typename is matched as though it were a
10430 complete line; thus, @samp{i type value} gives information on all
10431 types in your program whose names include the string @code{value}, but
10432 @samp{i type ^value$} gives information only on types whose complete
10433 name is @code{value}.
10434
10435 This command differs from @code{ptype} in two ways: first, like
10436 @code{whatis}, it does not print a detailed description; second, it
10437 lists all source files where a type is defined.
10438
10439 @kindex info scope
10440 @cindex local variables
10441 @item info scope @var{location}
10442 List all the variables local to a particular scope. This command
10443 accepts a @var{location} argument---a function name, a source line, or
10444 an address preceded by a @samp{*}, and prints all the variables local
10445 to the scope defined by that location. For example:
10446
10447 @smallexample
10448 (@value{GDBP}) @b{info scope command_line_handler}
10449 Scope for command_line_handler:
10450 Symbol rl is an argument at stack/frame offset 8, length 4.
10451 Symbol linebuffer is in static storage at address 0x150a18, length 4.
10452 Symbol linelength is in static storage at address 0x150a1c, length 4.
10453 Symbol p is a local variable in register $esi, length 4.
10454 Symbol p1 is a local variable in register $ebx, length 4.
10455 Symbol nline is a local variable in register $edx, length 4.
10456 Symbol repeat is a local variable at frame offset -8, length 4.
10457 @end smallexample
10458
10459 @noindent
10460 This command is especially useful for determining what data to collect
10461 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10462 collect}.
10463
10464 @kindex info source
10465 @item info source
10466 Show information about the current source file---that is, the source file for
10467 the function containing the current point of execution:
10468 @itemize @bullet
10469 @item
10470 the name of the source file, and the directory containing it,
10471 @item
10472 the directory it was compiled in,
10473 @item
10474 its length, in lines,
10475 @item
10476 which programming language it is written in,
10477 @item
10478 whether the executable includes debugging information for that file, and
10479 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10480 @item
10481 whether the debugging information includes information about
10482 preprocessor macros.
10483 @end itemize
10484
10485
10486 @kindex info sources
10487 @item info sources
10488 Print the names of all source files in your program for which there is
10489 debugging information, organized into two lists: files whose symbols
10490 have already been read, and files whose symbols will be read when needed.
10491
10492 @kindex info functions
10493 @item info functions
10494 Print the names and data types of all defined functions.
10495
10496 @item info functions @var{regexp}
10497 Print the names and data types of all defined functions
10498 whose names contain a match for regular expression @var{regexp}.
10499 Thus, @samp{info fun step} finds all functions whose names
10500 include @code{step}; @samp{info fun ^step} finds those whose names
10501 start with @code{step}. If a function name contains characters
10502 that conflict with the regular expression language (e.g.@:
10503 @samp{operator*()}), they may be quoted with a backslash.
10504
10505 @kindex info variables
10506 @item info variables
10507 Print the names and data types of all variables that are declared
10508 outside of functions (i.e.@: excluding local variables).
10509
10510 @item info variables @var{regexp}
10511 Print the names and data types of all variables (except for local
10512 variables) whose names contain a match for regular expression
10513 @var{regexp}.
10514
10515 @kindex info classes
10516 @cindex Objective-C, classes and selectors
10517 @item info classes
10518 @itemx info classes @var{regexp}
10519 Display all Objective-C classes in your program, or
10520 (with the @var{regexp} argument) all those matching a particular regular
10521 expression.
10522
10523 @kindex info selectors
10524 @item info selectors
10525 @itemx info selectors @var{regexp}
10526 Display all Objective-C selectors in your program, or
10527 (with the @var{regexp} argument) all those matching a particular regular
10528 expression.
10529
10530 @ignore
10531 This was never implemented.
10532 @kindex info methods
10533 @item info methods
10534 @itemx info methods @var{regexp}
10535 The @code{info methods} command permits the user to examine all defined
10536 methods within C@t{++} program, or (with the @var{regexp} argument) a
10537 specific set of methods found in the various C@t{++} classes. Many
10538 C@t{++} classes provide a large number of methods. Thus, the output
10539 from the @code{ptype} command can be overwhelming and hard to use. The
10540 @code{info-methods} command filters the methods, printing only those
10541 which match the regular-expression @var{regexp}.
10542 @end ignore
10543
10544 @cindex reloading symbols
10545 Some systems allow individual object files that make up your program to
10546 be replaced without stopping and restarting your program. For example,
10547 in VxWorks you can simply recompile a defective object file and keep on
10548 running. If you are running on one of these systems, you can allow
10549 @value{GDBN} to reload the symbols for automatically relinked modules:
10550
10551 @table @code
10552 @kindex set symbol-reloading
10553 @item set symbol-reloading on
10554 Replace symbol definitions for the corresponding source file when an
10555 object file with a particular name is seen again.
10556
10557 @item set symbol-reloading off
10558 Do not replace symbol definitions when encountering object files of the
10559 same name more than once. This is the default state; if you are not
10560 running on a system that permits automatic relinking of modules, you
10561 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10562 may discard symbols when linking large programs, that may contain
10563 several modules (from different directories or libraries) with the same
10564 name.
10565
10566 @kindex show symbol-reloading
10567 @item show symbol-reloading
10568 Show the current @code{on} or @code{off} setting.
10569 @end table
10570
10571 @cindex opaque data types
10572 @kindex set opaque-type-resolution
10573 @item set opaque-type-resolution on
10574 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10575 declared as a pointer to a @code{struct}, @code{class}, or
10576 @code{union}---for example, @code{struct MyType *}---that is used in one
10577 source file although the full declaration of @code{struct MyType} is in
10578 another source file. The default is on.
10579
10580 A change in the setting of this subcommand will not take effect until
10581 the next time symbols for a file are loaded.
10582
10583 @item set opaque-type-resolution off
10584 Tell @value{GDBN} not to resolve opaque types. In this case, the type
10585 is printed as follows:
10586 @smallexample
10587 @{<no data fields>@}
10588 @end smallexample
10589
10590 @kindex show opaque-type-resolution
10591 @item show opaque-type-resolution
10592 Show whether opaque types are resolved or not.
10593
10594 @kindex maint print symbols
10595 @cindex symbol dump
10596 @kindex maint print psymbols
10597 @cindex partial symbol dump
10598 @item maint print symbols @var{filename}
10599 @itemx maint print psymbols @var{filename}
10600 @itemx maint print msymbols @var{filename}
10601 Write a dump of debugging symbol data into the file @var{filename}.
10602 These commands are used to debug the @value{GDBN} symbol-reading code. Only
10603 symbols with debugging data are included. If you use @samp{maint print
10604 symbols}, @value{GDBN} includes all the symbols for which it has already
10605 collected full details: that is, @var{filename} reflects symbols for
10606 only those files whose symbols @value{GDBN} has read. You can use the
10607 command @code{info sources} to find out which files these are. If you
10608 use @samp{maint print psymbols} instead, the dump shows information about
10609 symbols that @value{GDBN} only knows partially---that is, symbols defined in
10610 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10611 @samp{maint print msymbols} dumps just the minimal symbol information
10612 required for each object file from which @value{GDBN} has read some symbols.
10613 @xref{Files, ,Commands to specify files}, for a discussion of how
10614 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
10615
10616 @kindex maint info symtabs
10617 @kindex maint info psymtabs
10618 @cindex listing @value{GDBN}'s internal symbol tables
10619 @cindex symbol tables, listing @value{GDBN}'s internal
10620 @cindex full symbol tables, listing @value{GDBN}'s internal
10621 @cindex partial symbol tables, listing @value{GDBN}'s internal
10622 @item maint info symtabs @r{[} @var{regexp} @r{]}
10623 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
10624
10625 List the @code{struct symtab} or @code{struct partial_symtab}
10626 structures whose names match @var{regexp}. If @var{regexp} is not
10627 given, list them all. The output includes expressions which you can
10628 copy into a @value{GDBN} debugging this one to examine a particular
10629 structure in more detail. For example:
10630
10631 @smallexample
10632 (@value{GDBP}) maint info psymtabs dwarf2read
10633 @{ objfile /home/gnu/build/gdb/gdb
10634 ((struct objfile *) 0x82e69d0)
10635 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
10636 ((struct partial_symtab *) 0x8474b10)
10637 readin no
10638 fullname (null)
10639 text addresses 0x814d3c8 -- 0x8158074
10640 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10641 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10642 dependencies (none)
10643 @}
10644 @}
10645 (@value{GDBP}) maint info symtabs
10646 (@value{GDBP})
10647 @end smallexample
10648 @noindent
10649 We see that there is one partial symbol table whose filename contains
10650 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10651 and we see that @value{GDBN} has not read in any symtabs yet at all.
10652 If we set a breakpoint on a function, that will cause @value{GDBN} to
10653 read the symtab for the compilation unit containing that function:
10654
10655 @smallexample
10656 (@value{GDBP}) break dwarf2_psymtab_to_symtab
10657 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10658 line 1574.
10659 (@value{GDBP}) maint info symtabs
10660 @{ objfile /home/gnu/build/gdb/gdb
10661 ((struct objfile *) 0x82e69d0)
10662 @{ symtab /home/gnu/src/gdb/dwarf2read.c
10663 ((struct symtab *) 0x86c1f38)
10664 dirname (null)
10665 fullname (null)
10666 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10667 debugformat DWARF 2
10668 @}
10669 @}
10670 (@value{GDBP})
10671 @end smallexample
10672 @end table
10673
10674
10675 @node Altering
10676 @chapter Altering Execution
10677
10678 Once you think you have found an error in your program, you might want to
10679 find out for certain whether correcting the apparent error would lead to
10680 correct results in the rest of the run. You can find the answer by
10681 experiment, using the @value{GDBN} features for altering execution of the
10682 program.
10683
10684 For example, you can store new values into variables or memory
10685 locations, give your program a signal, restart it at a different
10686 address, or even return prematurely from a function.
10687
10688 @menu
10689 * Assignment:: Assignment to variables
10690 * Jumping:: Continuing at a different address
10691 * Signaling:: Giving your program a signal
10692 * Returning:: Returning from a function
10693 * Calling:: Calling your program's functions
10694 * Patching:: Patching your program
10695 @end menu
10696
10697 @node Assignment
10698 @section Assignment to variables
10699
10700 @cindex assignment
10701 @cindex setting variables
10702 To alter the value of a variable, evaluate an assignment expression.
10703 @xref{Expressions, ,Expressions}. For example,
10704
10705 @smallexample
10706 print x=4
10707 @end smallexample
10708
10709 @noindent
10710 stores the value 4 into the variable @code{x}, and then prints the
10711 value of the assignment expression (which is 4).
10712 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10713 information on operators in supported languages.
10714
10715 @kindex set variable
10716 @cindex variables, setting
10717 If you are not interested in seeing the value of the assignment, use the
10718 @code{set} command instead of the @code{print} command. @code{set} is
10719 really the same as @code{print} except that the expression's value is
10720 not printed and is not put in the value history (@pxref{Value History,
10721 ,Value history}). The expression is evaluated only for its effects.
10722
10723 If the beginning of the argument string of the @code{set} command
10724 appears identical to a @code{set} subcommand, use the @code{set
10725 variable} command instead of just @code{set}. This command is identical
10726 to @code{set} except for its lack of subcommands. For example, if your
10727 program has a variable @code{width}, you get an error if you try to set
10728 a new value with just @samp{set width=13}, because @value{GDBN} has the
10729 command @code{set width}:
10730
10731 @smallexample
10732 (@value{GDBP}) whatis width
10733 type = double
10734 (@value{GDBP}) p width
10735 $4 = 13
10736 (@value{GDBP}) set width=47
10737 Invalid syntax in expression.
10738 @end smallexample
10739
10740 @noindent
10741 The invalid expression, of course, is @samp{=47}. In
10742 order to actually set the program's variable @code{width}, use
10743
10744 @smallexample
10745 (@value{GDBP}) set var width=47
10746 @end smallexample
10747
10748 Because the @code{set} command has many subcommands that can conflict
10749 with the names of program variables, it is a good idea to use the
10750 @code{set variable} command instead of just @code{set}. For example, if
10751 your program has a variable @code{g}, you run into problems if you try
10752 to set a new value with just @samp{set g=4}, because @value{GDBN} has
10753 the command @code{set gnutarget}, abbreviated @code{set g}:
10754
10755 @smallexample
10756 @group
10757 (@value{GDBP}) whatis g
10758 type = double
10759 (@value{GDBP}) p g
10760 $1 = 1
10761 (@value{GDBP}) set g=4
10762 (@value{GDBP}) p g
10763 $2 = 1
10764 (@value{GDBP}) r
10765 The program being debugged has been started already.
10766 Start it from the beginning? (y or n) y
10767 Starting program: /home/smith/cc_progs/a.out
10768 "/home/smith/cc_progs/a.out": can't open to read symbols:
10769 Invalid bfd target.
10770 (@value{GDBP}) show g
10771 The current BFD target is "=4".
10772 @end group
10773 @end smallexample
10774
10775 @noindent
10776 The program variable @code{g} did not change, and you silently set the
10777 @code{gnutarget} to an invalid value. In order to set the variable
10778 @code{g}, use
10779
10780 @smallexample
10781 (@value{GDBP}) set var g=4
10782 @end smallexample
10783
10784 @value{GDBN} allows more implicit conversions in assignments than C; you can
10785 freely store an integer value into a pointer variable or vice versa,
10786 and you can convert any structure to any other structure that is the
10787 same length or shorter.
10788 @comment FIXME: how do structs align/pad in these conversions?
10789 @comment /doc@cygnus.com 18dec1990
10790
10791 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10792 construct to generate a value of specified type at a specified address
10793 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10794 to memory location @code{0x83040} as an integer (which implies a certain size
10795 and representation in memory), and
10796
10797 @smallexample
10798 set @{int@}0x83040 = 4
10799 @end smallexample
10800
10801 @noindent
10802 stores the value 4 into that memory location.
10803
10804 @node Jumping
10805 @section Continuing at a different address
10806
10807 Ordinarily, when you continue your program, you do so at the place where
10808 it stopped, with the @code{continue} command. You can instead continue at
10809 an address of your own choosing, with the following commands:
10810
10811 @table @code
10812 @kindex jump
10813 @item jump @var{linespec}
10814 Resume execution at line @var{linespec}. Execution stops again
10815 immediately if there is a breakpoint there. @xref{List, ,Printing
10816 source lines}, for a description of the different forms of
10817 @var{linespec}. It is common practice to use the @code{tbreak} command
10818 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10819 breakpoints}.
10820
10821 The @code{jump} command does not change the current stack frame, or
10822 the stack pointer, or the contents of any memory location or any
10823 register other than the program counter. If line @var{linespec} is in
10824 a different function from the one currently executing, the results may
10825 be bizarre if the two functions expect different patterns of arguments or
10826 of local variables. For this reason, the @code{jump} command requests
10827 confirmation if the specified line is not in the function currently
10828 executing. However, even bizarre results are predictable if you are
10829 well acquainted with the machine-language code of your program.
10830
10831 @item jump *@var{address}
10832 Resume execution at the instruction at address @var{address}.
10833 @end table
10834
10835 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
10836 On many systems, you can get much the same effect as the @code{jump}
10837 command by storing a new value into the register @code{$pc}. The
10838 difference is that this does not start your program running; it only
10839 changes the address of where it @emph{will} run when you continue. For
10840 example,
10841
10842 @smallexample
10843 set $pc = 0x485
10844 @end smallexample
10845
10846 @noindent
10847 makes the next @code{continue} command or stepping command execute at
10848 address @code{0x485}, rather than at the address where your program stopped.
10849 @xref{Continuing and Stepping, ,Continuing and stepping}.
10850
10851 The most common occasion to use the @code{jump} command is to back
10852 up---perhaps with more breakpoints set---over a portion of a program
10853 that has already executed, in order to examine its execution in more
10854 detail.
10855
10856 @c @group
10857 @node Signaling
10858 @section Giving your program a signal
10859 @cindex deliver a signal to a program
10860
10861 @table @code
10862 @kindex signal
10863 @item signal @var{signal}
10864 Resume execution where your program stopped, but immediately give it the
10865 signal @var{signal}. @var{signal} can be the name or the number of a
10866 signal. For example, on many systems @code{signal 2} and @code{signal
10867 SIGINT} are both ways of sending an interrupt signal.
10868
10869 Alternatively, if @var{signal} is zero, continue execution without
10870 giving a signal. This is useful when your program stopped on account of
10871 a signal and would ordinary see the signal when resumed with the
10872 @code{continue} command; @samp{signal 0} causes it to resume without a
10873 signal.
10874
10875 @code{signal} does not repeat when you press @key{RET} a second time
10876 after executing the command.
10877 @end table
10878 @c @end group
10879
10880 Invoking the @code{signal} command is not the same as invoking the
10881 @code{kill} utility from the shell. Sending a signal with @code{kill}
10882 causes @value{GDBN} to decide what to do with the signal depending on
10883 the signal handling tables (@pxref{Signals}). The @code{signal} command
10884 passes the signal directly to your program.
10885
10886
10887 @node Returning
10888 @section Returning from a function
10889
10890 @table @code
10891 @cindex returning from a function
10892 @kindex return
10893 @item return
10894 @itemx return @var{expression}
10895 You can cancel execution of a function call with the @code{return}
10896 command. If you give an
10897 @var{expression} argument, its value is used as the function's return
10898 value.
10899 @end table
10900
10901 When you use @code{return}, @value{GDBN} discards the selected stack frame
10902 (and all frames within it). You can think of this as making the
10903 discarded frame return prematurely. If you wish to specify a value to
10904 be returned, give that value as the argument to @code{return}.
10905
10906 This pops the selected stack frame (@pxref{Selection, ,Selecting a
10907 frame}), and any other frames inside of it, leaving its caller as the
10908 innermost remaining frame. That frame becomes selected. The
10909 specified value is stored in the registers used for returning values
10910 of functions.
10911
10912 The @code{return} command does not resume execution; it leaves the
10913 program stopped in the state that would exist if the function had just
10914 returned. In contrast, the @code{finish} command (@pxref{Continuing
10915 and Stepping, ,Continuing and stepping}) resumes execution until the
10916 selected stack frame returns naturally.
10917
10918 @node Calling
10919 @section Calling program functions
10920
10921 @table @code
10922 @cindex calling functions
10923 @cindex inferior functions, calling
10924 @item print @var{expr}
10925 Evaluate the expression @var{expr} and display the resuling value.
10926 @var{expr} may include calls to functions in the program being
10927 debugged.
10928
10929 @kindex call
10930 @item call @var{expr}
10931 Evaluate the expression @var{expr} without displaying @code{void}
10932 returned values.
10933
10934 You can use this variant of the @code{print} command if you want to
10935 execute a function from your program that does not return anything
10936 (a.k.a.@: @dfn{a void function}), but without cluttering the output
10937 with @code{void} returned values that @value{GDBN} will otherwise
10938 print. If the result is not void, it is printed and saved in the
10939 value history.
10940 @end table
10941
10942 It is possible for the function you call via the @code{print} or
10943 @code{call} command to generate a signal (e.g., if there's a bug in
10944 the function, or if you passed it incorrect arguments). What happens
10945 in that case is controlled by the @code{set unwindonsignal} command.
10946
10947 @table @code
10948 @item set unwindonsignal
10949 @kindex set unwindonsignal
10950 @cindex unwind stack in called functions
10951 @cindex call dummy stack unwinding
10952 Set unwinding of the stack if a signal is received while in a function
10953 that @value{GDBN} called in the program being debugged. If set to on,
10954 @value{GDBN} unwinds the stack it created for the call and restores
10955 the context to what it was before the call. If set to off (the
10956 default), @value{GDBN} stops in the frame where the signal was
10957 received.
10958
10959 @item show unwindonsignal
10960 @kindex show unwindonsignal
10961 Show the current setting of stack unwinding in the functions called by
10962 @value{GDBN}.
10963 @end table
10964
10965 @cindex weak alias functions
10966 Sometimes, a function you wish to call is actually a @dfn{weak alias}
10967 for another function. In such case, @value{GDBN} might not pick up
10968 the type information, including the types of the function arguments,
10969 which causes @value{GDBN} to call the inferior function incorrectly.
10970 As a result, the called function will function erroneously and may
10971 even crash. A solution to that is to use the name of the aliased
10972 function instead.
10973
10974 @node Patching
10975 @section Patching programs
10976
10977 @cindex patching binaries
10978 @cindex writing into executables
10979 @cindex writing into corefiles
10980
10981 By default, @value{GDBN} opens the file containing your program's
10982 executable code (or the corefile) read-only. This prevents accidental
10983 alterations to machine code; but it also prevents you from intentionally
10984 patching your program's binary.
10985
10986 If you'd like to be able to patch the binary, you can specify that
10987 explicitly with the @code{set write} command. For example, you might
10988 want to turn on internal debugging flags, or even to make emergency
10989 repairs.
10990
10991 @table @code
10992 @kindex set write
10993 @item set write on
10994 @itemx set write off
10995 If you specify @samp{set write on}, @value{GDBN} opens executable and
10996 core files for both reading and writing; if you specify @samp{set write
10997 off} (the default), @value{GDBN} opens them read-only.
10998
10999 If you have already loaded a file, you must load it again (using the
11000 @code{exec-file} or @code{core-file} command) after changing @code{set
11001 write}, for your new setting to take effect.
11002
11003 @item show write
11004 @kindex show write
11005 Display whether executable files and core files are opened for writing
11006 as well as reading.
11007 @end table
11008
11009 @node GDB Files
11010 @chapter @value{GDBN} Files
11011
11012 @value{GDBN} needs to know the file name of the program to be debugged,
11013 both in order to read its symbol table and in order to start your
11014 program. To debug a core dump of a previous run, you must also tell
11015 @value{GDBN} the name of the core dump file.
11016
11017 @menu
11018 * Files:: Commands to specify files
11019 * Separate Debug Files:: Debugging information in separate files
11020 * Symbol Errors:: Errors reading symbol files
11021 @end menu
11022
11023 @node Files
11024 @section Commands to specify files
11025
11026 @cindex symbol table
11027 @cindex core dump file
11028
11029 You may want to specify executable and core dump file names. The usual
11030 way to do this is at start-up time, using the arguments to
11031 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11032 Out of @value{GDBN}}).
11033
11034 Occasionally it is necessary to change to a different file during a
11035 @value{GDBN} session. Or you may run @value{GDBN} and forget to
11036 specify a file you want to use. Or you are debugging a remote target
11037 via @code{gdbserver} (@pxref{Server, file}). In these situations the
11038 @value{GDBN} commands to specify new files are useful.
11039
11040 @table @code
11041 @cindex executable file
11042 @kindex file
11043 @item file @var{filename}
11044 Use @var{filename} as the program to be debugged. It is read for its
11045 symbols and for the contents of pure memory. It is also the program
11046 executed when you use the @code{run} command. If you do not specify a
11047 directory and the file is not found in the @value{GDBN} working directory,
11048 @value{GDBN} uses the environment variable @code{PATH} as a list of
11049 directories to search, just as the shell does when looking for a program
11050 to run. You can change the value of this variable, for both @value{GDBN}
11051 and your program, using the @code{path} command.
11052
11053 @cindex unlinked object files
11054 @cindex patching object files
11055 You can load unlinked object @file{.o} files into @value{GDBN} using
11056 the @code{file} command. You will not be able to ``run'' an object
11057 file, but you can disassemble functions and inspect variables. Also,
11058 if the underlying BFD functionality supports it, you could use
11059 @kbd{gdb -write} to patch object files using this technique. Note
11060 that @value{GDBN} can neither interpret nor modify relocations in this
11061 case, so branches and some initialized variables will appear to go to
11062 the wrong place. But this feature is still handy from time to time.
11063
11064 @item file
11065 @code{file} with no argument makes @value{GDBN} discard any information it
11066 has on both executable file and the symbol table.
11067
11068 @kindex exec-file
11069 @item exec-file @r{[} @var{filename} @r{]}
11070 Specify that the program to be run (but not the symbol table) is found
11071 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
11072 if necessary to locate your program. Omitting @var{filename} means to
11073 discard information on the executable file.
11074
11075 @kindex symbol-file
11076 @item symbol-file @r{[} @var{filename} @r{]}
11077 Read symbol table information from file @var{filename}. @code{PATH} is
11078 searched when necessary. Use the @code{file} command to get both symbol
11079 table and program to run from the same file.
11080
11081 @code{symbol-file} with no argument clears out @value{GDBN} information on your
11082 program's symbol table.
11083
11084 The @code{symbol-file} command causes @value{GDBN} to forget the contents
11085 of its convenience variables, the value history, and all breakpoints and
11086 auto-display expressions. This is because they may contain pointers to
11087 the internal data recording symbols and data types, which are part of
11088 the old symbol table data being discarded inside @value{GDBN}.
11089
11090 @code{symbol-file} does not repeat if you press @key{RET} again after
11091 executing it once.
11092
11093 When @value{GDBN} is configured for a particular environment, it
11094 understands debugging information in whatever format is the standard
11095 generated for that environment; you may use either a @sc{gnu} compiler, or
11096 other compilers that adhere to the local conventions.
11097 Best results are usually obtained from @sc{gnu} compilers; for example,
11098 using @code{@value{GCC}} you can generate debugging information for
11099 optimized code.
11100
11101 For most kinds of object files, with the exception of old SVR3 systems
11102 using COFF, the @code{symbol-file} command does not normally read the
11103 symbol table in full right away. Instead, it scans the symbol table
11104 quickly to find which source files and which symbols are present. The
11105 details are read later, one source file at a time, as they are needed.
11106
11107 The purpose of this two-stage reading strategy is to make @value{GDBN}
11108 start up faster. For the most part, it is invisible except for
11109 occasional pauses while the symbol table details for a particular source
11110 file are being read. (The @code{set verbose} command can turn these
11111 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
11112 warnings and messages}.)
11113
11114 We have not implemented the two-stage strategy for COFF yet. When the
11115 symbol table is stored in COFF format, @code{symbol-file} reads the
11116 symbol table data in full right away. Note that ``stabs-in-COFF''
11117 still does the two-stage strategy, since the debug info is actually
11118 in stabs format.
11119
11120 @kindex readnow
11121 @cindex reading symbols immediately
11122 @cindex symbols, reading immediately
11123 @item symbol-file @var{filename} @r{[} -readnow @r{]}
11124 @itemx file @var{filename} @r{[} -readnow @r{]}
11125 You can override the @value{GDBN} two-stage strategy for reading symbol
11126 tables by using the @samp{-readnow} option with any of the commands that
11127 load symbol table information, if you want to be sure @value{GDBN} has the
11128 entire symbol table available.
11129
11130 @c FIXME: for now no mention of directories, since this seems to be in
11131 @c flux. 13mar1992 status is that in theory GDB would look either in
11132 @c current dir or in same dir as myprog; but issues like competing
11133 @c GDB's, or clutter in system dirs, mean that in practice right now
11134 @c only current dir is used. FFish says maybe a special GDB hierarchy
11135 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11136 @c files.
11137
11138 @kindex core-file
11139 @item core-file @r{[}@var{filename}@r{]}
11140 @itemx core
11141 Specify the whereabouts of a core dump file to be used as the ``contents
11142 of memory''. Traditionally, core files contain only some parts of the
11143 address space of the process that generated them; @value{GDBN} can access the
11144 executable file itself for other parts.
11145
11146 @code{core-file} with no argument specifies that no core file is
11147 to be used.
11148
11149 Note that the core file is ignored when your program is actually running
11150 under @value{GDBN}. So, if you have been running your program and you
11151 wish to debug a core file instead, you must kill the subprocess in which
11152 the program is running. To do this, use the @code{kill} command
11153 (@pxref{Kill Process, ,Killing the child process}).
11154
11155 @kindex add-symbol-file
11156 @cindex dynamic linking
11157 @item add-symbol-file @var{filename} @var{address}
11158 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
11159 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
11160 The @code{add-symbol-file} command reads additional symbol table
11161 information from the file @var{filename}. You would use this command
11162 when @var{filename} has been dynamically loaded (by some other means)
11163 into the program that is running. @var{address} should be the memory
11164 address at which the file has been loaded; @value{GDBN} cannot figure
11165 this out for itself. You can additionally specify an arbitrary number
11166 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11167 section name and base address for that section. You can specify any
11168 @var{address} as an expression.
11169
11170 The symbol table of the file @var{filename} is added to the symbol table
11171 originally read with the @code{symbol-file} command. You can use the
11172 @code{add-symbol-file} command any number of times; the new symbol data
11173 thus read keeps adding to the old. To discard all old symbol data
11174 instead, use the @code{symbol-file} command without any arguments.
11175
11176 @cindex relocatable object files, reading symbols from
11177 @cindex object files, relocatable, reading symbols from
11178 @cindex reading symbols from relocatable object files
11179 @cindex symbols, reading from relocatable object files
11180 @cindex @file{.o} files, reading symbols from
11181 Although @var{filename} is typically a shared library file, an
11182 executable file, or some other object file which has been fully
11183 relocated for loading into a process, you can also load symbolic
11184 information from relocatable @file{.o} files, as long as:
11185
11186 @itemize @bullet
11187 @item
11188 the file's symbolic information refers only to linker symbols defined in
11189 that file, not to symbols defined by other object files,
11190 @item
11191 every section the file's symbolic information refers to has actually
11192 been loaded into the inferior, as it appears in the file, and
11193 @item
11194 you can determine the address at which every section was loaded, and
11195 provide these to the @code{add-symbol-file} command.
11196 @end itemize
11197
11198 @noindent
11199 Some embedded operating systems, like Sun Chorus and VxWorks, can load
11200 relocatable files into an already running program; such systems
11201 typically make the requirements above easy to meet. However, it's
11202 important to recognize that many native systems use complex link
11203 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
11204 assembly, for example) that make the requirements difficult to meet. In
11205 general, one cannot assume that using @code{add-symbol-file} to read a
11206 relocatable object file's symbolic information will have the same effect
11207 as linking the relocatable object file into the program in the normal
11208 way.
11209
11210 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11211
11212 @kindex add-symbol-file-from-memory
11213 @cindex @code{syscall DSO}
11214 @cindex load symbols from memory
11215 @item add-symbol-file-from-memory @var{address}
11216 Load symbols from the given @var{address} in a dynamically loaded
11217 object file whose image is mapped directly into the inferior's memory.
11218 For example, the Linux kernel maps a @code{syscall DSO} into each
11219 process's address space; this DSO provides kernel-specific code for
11220 some system calls. The argument can be any expression whose
11221 evaluation yields the address of the file's shared object file header.
11222 For this command to work, you must have used @code{symbol-file} or
11223 @code{exec-file} commands in advance.
11224
11225 @kindex add-shared-symbol-files
11226 @kindex assf
11227 @item add-shared-symbol-files @var{library-file}
11228 @itemx assf @var{library-file}
11229 The @code{add-shared-symbol-files} command can currently be used only
11230 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11231 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11232 @value{GDBN} automatically looks for shared libraries, however if
11233 @value{GDBN} does not find yours, you can invoke
11234 @code{add-shared-symbol-files}. It takes one argument: the shared
11235 library's file name. @code{assf} is a shorthand alias for
11236 @code{add-shared-symbol-files}.
11237
11238 @kindex section
11239 @item section @var{section} @var{addr}
11240 The @code{section} command changes the base address of the named
11241 @var{section} of the exec file to @var{addr}. This can be used if the
11242 exec file does not contain section addresses, (such as in the
11243 @code{a.out} format), or when the addresses specified in the file
11244 itself are wrong. Each section must be changed separately. The
11245 @code{info files} command, described below, lists all the sections and
11246 their addresses.
11247
11248 @kindex info files
11249 @kindex info target
11250 @item info files
11251 @itemx info target
11252 @code{info files} and @code{info target} are synonymous; both print the
11253 current target (@pxref{Targets, ,Specifying a Debugging Target}),
11254 including the names of the executable and core dump files currently in
11255 use by @value{GDBN}, and the files from which symbols were loaded. The
11256 command @code{help target} lists all possible targets rather than
11257 current ones.
11258
11259 @kindex maint info sections
11260 @item maint info sections
11261 Another command that can give you extra information about program sections
11262 is @code{maint info sections}. In addition to the section information
11263 displayed by @code{info files}, this command displays the flags and file
11264 offset of each section in the executable and core dump files. In addition,
11265 @code{maint info sections} provides the following command options (which
11266 may be arbitrarily combined):
11267
11268 @table @code
11269 @item ALLOBJ
11270 Display sections for all loaded object files, including shared libraries.
11271 @item @var{sections}
11272 Display info only for named @var{sections}.
11273 @item @var{section-flags}
11274 Display info only for sections for which @var{section-flags} are true.
11275 The section flags that @value{GDBN} currently knows about are:
11276 @table @code
11277 @item ALLOC
11278 Section will have space allocated in the process when loaded.
11279 Set for all sections except those containing debug information.
11280 @item LOAD
11281 Section will be loaded from the file into the child process memory.
11282 Set for pre-initialized code and data, clear for @code{.bss} sections.
11283 @item RELOC
11284 Section needs to be relocated before loading.
11285 @item READONLY
11286 Section cannot be modified by the child process.
11287 @item CODE
11288 Section contains executable code only.
11289 @item DATA
11290 Section contains data only (no executable code).
11291 @item ROM
11292 Section will reside in ROM.
11293 @item CONSTRUCTOR
11294 Section contains data for constructor/destructor lists.
11295 @item HAS_CONTENTS
11296 Section is not empty.
11297 @item NEVER_LOAD
11298 An instruction to the linker to not output the section.
11299 @item COFF_SHARED_LIBRARY
11300 A notification to the linker that the section contains
11301 COFF shared library information.
11302 @item IS_COMMON
11303 Section contains common symbols.
11304 @end table
11305 @end table
11306 @kindex set trust-readonly-sections
11307 @cindex read-only sections
11308 @item set trust-readonly-sections on
11309 Tell @value{GDBN} that readonly sections in your object file
11310 really are read-only (i.e.@: that their contents will not change).
11311 In that case, @value{GDBN} can fetch values from these sections
11312 out of the object file, rather than from the target program.
11313 For some targets (notably embedded ones), this can be a significant
11314 enhancement to debugging performance.
11315
11316 The default is off.
11317
11318 @item set trust-readonly-sections off
11319 Tell @value{GDBN} not to trust readonly sections. This means that
11320 the contents of the section might change while the program is running,
11321 and must therefore be fetched from the target when needed.
11322
11323 @item show trust-readonly-sections
11324 Show the current setting of trusting readonly sections.
11325 @end table
11326
11327 All file-specifying commands allow both absolute and relative file names
11328 as arguments. @value{GDBN} always converts the file name to an absolute file
11329 name and remembers it that way.
11330
11331 @cindex shared libraries
11332 @value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
11333 and IBM RS/6000 AIX shared libraries.
11334
11335 @value{GDBN} automatically loads symbol definitions from shared libraries
11336 when you use the @code{run} command, or when you examine a core file.
11337 (Before you issue the @code{run} command, @value{GDBN} does not understand
11338 references to a function in a shared library, however---unless you are
11339 debugging a core file).
11340
11341 On HP-UX, if the program loads a library explicitly, @value{GDBN}
11342 automatically loads the symbols at the time of the @code{shl_load} call.
11343
11344 @c FIXME: some @value{GDBN} release may permit some refs to undef
11345 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11346 @c FIXME...lib; check this from time to time when updating manual
11347
11348 There are times, however, when you may wish to not automatically load
11349 symbol definitions from shared libraries, such as when they are
11350 particularly large or there are many of them.
11351
11352 To control the automatic loading of shared library symbols, use the
11353 commands:
11354
11355 @table @code
11356 @kindex set auto-solib-add
11357 @item set auto-solib-add @var{mode}
11358 If @var{mode} is @code{on}, symbols from all shared object libraries
11359 will be loaded automatically when the inferior begins execution, you
11360 attach to an independently started inferior, or when the dynamic linker
11361 informs @value{GDBN} that a new library has been loaded. If @var{mode}
11362 is @code{off}, symbols must be loaded manually, using the
11363 @code{sharedlibrary} command. The default value is @code{on}.
11364
11365 @cindex memory used for symbol tables
11366 If your program uses lots of shared libraries with debug info that
11367 takes large amounts of memory, you can decrease the @value{GDBN}
11368 memory footprint by preventing it from automatically loading the
11369 symbols from shared libraries. To that end, type @kbd{set
11370 auto-solib-add off} before running the inferior, then load each
11371 library whose debug symbols you do need with @kbd{sharedlibrary
11372 @var{regexp}}, where @var{regexp} is a regular expresion that matches
11373 the libraries whose symbols you want to be loaded.
11374
11375 @kindex show auto-solib-add
11376 @item show auto-solib-add
11377 Display the current autoloading mode.
11378 @end table
11379
11380 @cindex load shared library
11381 To explicitly load shared library symbols, use the @code{sharedlibrary}
11382 command:
11383
11384 @table @code
11385 @kindex info sharedlibrary
11386 @kindex info share
11387 @item info share
11388 @itemx info sharedlibrary
11389 Print the names of the shared libraries which are currently loaded.
11390
11391 @kindex sharedlibrary
11392 @kindex share
11393 @item sharedlibrary @var{regex}
11394 @itemx share @var{regex}
11395 Load shared object library symbols for files matching a
11396 Unix regular expression.
11397 As with files loaded automatically, it only loads shared libraries
11398 required by your program for a core file or after typing @code{run}. If
11399 @var{regex} is omitted all shared libraries required by your program are
11400 loaded.
11401
11402 @item nosharedlibrary
11403 @kindex nosharedlibrary
11404 @cindex unload symbols from shared libraries
11405 Unload all shared object library symbols. This discards all symbols
11406 that have been loaded from all shared libraries. Symbols from shared
11407 libraries that were loaded by explicit user requests are not
11408 discarded.
11409 @end table
11410
11411 Sometimes you may wish that @value{GDBN} stops and gives you control
11412 when any of shared library events happen. Use the @code{set
11413 stop-on-solib-events} command for this:
11414
11415 @table @code
11416 @item set stop-on-solib-events
11417 @kindex set stop-on-solib-events
11418 This command controls whether @value{GDBN} should give you control
11419 when the dynamic linker notifies it about some shared library event.
11420 The most common event of interest is loading or unloading of a new
11421 shared library.
11422
11423 @item show stop-on-solib-events
11424 @kindex show stop-on-solib-events
11425 Show whether @value{GDBN} stops and gives you control when shared
11426 library events happen.
11427 @end table
11428
11429 Shared libraries are also supported in many cross or remote debugging
11430 configurations. A copy of the target's libraries need to be present on the
11431 host system; they need to be the same as the target libraries, although the
11432 copies on the target can be stripped as long as the copies on the host are
11433 not.
11434
11435 @cindex where to look for shared libraries
11436 For remote debugging, you need to tell @value{GDBN} where the target
11437 libraries are, so that it can load the correct copies---otherwise, it
11438 may try to load the host's libraries. @value{GDBN} has two variables
11439 to specify the search directories for target libraries.
11440
11441 @table @code
11442 @cindex prefix for shared library file names
11443 @kindex set solib-absolute-prefix
11444 @item set solib-absolute-prefix @var{path}
11445 If this variable is set, @var{path} will be used as a prefix for any
11446 absolute shared library paths; many runtime loaders store the absolute
11447 paths to the shared library in the target program's memory. If you use
11448 @samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11449 out in the same way that they are on the target, with e.g.@: a
11450 @file{/usr/lib} hierarchy under @var{path}.
11451
11452 @cindex default value of @samp{solib-absolute-prefix}
11453 @cindex @samp{--with-sysroot}
11454 You can set the default value of @samp{solib-absolute-prefix} by using the
11455 configure-time @samp{--with-sysroot} option.
11456
11457 @kindex show solib-absolute-prefix
11458 @item show solib-absolute-prefix
11459 Display the current shared library prefix.
11460
11461 @kindex set solib-search-path
11462 @item set solib-search-path @var{path}
11463 If this variable is set, @var{path} is a colon-separated list of directories
11464 to search for shared libraries. @samp{solib-search-path} is used after
11465 @samp{solib-absolute-prefix} fails to locate the library, or if the path to
11466 the library is relative instead of absolute. If you want to use
11467 @samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11468 set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11469 @value{GDBN} from finding your host's libraries.
11470
11471 @kindex show solib-search-path
11472 @item show solib-search-path
11473 Display the current shared library search path.
11474 @end table
11475
11476
11477 @node Separate Debug Files
11478 @section Debugging Information in Separate Files
11479 @cindex separate debugging information files
11480 @cindex debugging information in separate files
11481 @cindex @file{.debug} subdirectories
11482 @cindex debugging information directory, global
11483 @cindex global debugging information directory
11484
11485 @value{GDBN} allows you to put a program's debugging information in a
11486 file separate from the executable itself, in a way that allows
11487 @value{GDBN} to find and load the debugging information automatically.
11488 Since debugging information can be very large --- sometimes larger
11489 than the executable code itself --- some systems distribute debugging
11490 information for their executables in separate files, which users can
11491 install only when they need to debug a problem.
11492
11493 If an executable's debugging information has been extracted to a
11494 separate file, the executable should contain a @dfn{debug link} giving
11495 the name of the debugging information file (with no directory
11496 components), and a checksum of its contents. (The exact form of a
11497 debug link is described below.) If the full name of the directory
11498 containing the executable is @var{execdir}, and the executable has a
11499 debug link that specifies the name @var{debugfile}, then @value{GDBN}
11500 will automatically search for the debugging information file in three
11501 places:
11502
11503 @itemize @bullet
11504 @item
11505 the directory containing the executable file (that is, it will look
11506 for a file named @file{@var{execdir}/@var{debugfile}},
11507 @item
11508 a subdirectory of that directory named @file{.debug} (that is, the
11509 file @file{@var{execdir}/.debug/@var{debugfile}}, and
11510 @item
11511 a subdirectory of the global debug file directory that includes the
11512 executable's full path, and the name from the link (that is, the file
11513 @file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11514 @var{globaldebugdir} is the global debug file directory, and
11515 @var{execdir} has been turned into a relative path).
11516 @end itemize
11517 @noindent
11518 @value{GDBN} checks under each of these names for a debugging
11519 information file whose checksum matches that given in the link, and
11520 reads the debugging information from the first one it finds.
11521
11522 So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11523 which has a link containing the name @file{ls.debug}, and the global
11524 debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11525 for debug information in @file{/usr/bin/ls.debug},
11526 @file{/usr/bin/.debug/ls.debug}, and
11527 @file{/usr/lib/debug/usr/bin/ls.debug}.
11528
11529 You can set the global debugging info directory's name, and view the
11530 name @value{GDBN} is currently using.
11531
11532 @table @code
11533
11534 @kindex set debug-file-directory
11535 @item set debug-file-directory @var{directory}
11536 Set the directory which @value{GDBN} searches for separate debugging
11537 information files to @var{directory}.
11538
11539 @kindex show debug-file-directory
11540 @item show debug-file-directory
11541 Show the directory @value{GDBN} searches for separate debugging
11542 information files.
11543
11544 @end table
11545
11546 @cindex @code{.gnu_debuglink} sections
11547 @cindex debug links
11548 A debug link is a special section of the executable file named
11549 @code{.gnu_debuglink}. The section must contain:
11550
11551 @itemize
11552 @item
11553 A filename, with any leading directory components removed, followed by
11554 a zero byte,
11555 @item
11556 zero to three bytes of padding, as needed to reach the next four-byte
11557 boundary within the section, and
11558 @item
11559 a four-byte CRC checksum, stored in the same endianness used for the
11560 executable file itself. The checksum is computed on the debugging
11561 information file's full contents by the function given below, passing
11562 zero as the @var{crc} argument.
11563 @end itemize
11564
11565 Any executable file format can carry a debug link, as long as it can
11566 contain a section named @code{.gnu_debuglink} with the contents
11567 described above.
11568
11569 The debugging information file itself should be an ordinary
11570 executable, containing a full set of linker symbols, sections, and
11571 debugging information. The sections of the debugging information file
11572 should have the same names, addresses and sizes as the original file,
11573 but they need not contain any data --- much like a @code{.bss} section
11574 in an ordinary executable.
11575
11576 As of December 2002, there is no standard GNU utility to produce
11577 separated executable / debugging information file pairs. Ulrich
11578 Drepper's @file{elfutils} package, starting with version 0.53,
11579 contains a version of the @code{strip} command such that the command
11580 @kbd{strip foo -f foo.debug} removes the debugging information from
11581 the executable file @file{foo}, places it in the file
11582 @file{foo.debug}, and leaves behind a debug link in @file{foo}.
11583
11584 Since there are many different ways to compute CRC's (different
11585 polynomials, reversals, byte ordering, etc.), the simplest way to
11586 describe the CRC used in @code{.gnu_debuglink} sections is to give the
11587 complete code for a function that computes it:
11588
11589 @kindex gnu_debuglink_crc32
11590 @smallexample
11591 unsigned long
11592 gnu_debuglink_crc32 (unsigned long crc,
11593 unsigned char *buf, size_t len)
11594 @{
11595 static const unsigned long crc32_table[256] =
11596 @{
11597 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11598 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11599 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11600 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11601 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11602 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11603 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11604 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11605 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11606 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11607 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11608 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11609 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11610 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11611 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11612 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11613 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11614 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11615 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11616 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11617 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11618 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11619 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11620 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11621 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11622 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11623 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11624 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11625 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11626 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11627 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11628 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11629 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11630 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11631 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11632 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11633 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11634 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11635 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11636 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11637 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11638 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11639 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11640 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11641 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11642 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11643 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11644 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11645 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11646 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11647 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11648 0x2d02ef8d
11649 @};
11650 unsigned char *end;
11651
11652 crc = ~crc & 0xffffffff;
11653 for (end = buf + len; buf < end; ++buf)
11654 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
11655 return ~crc & 0xffffffff;
11656 @}
11657 @end smallexample
11658
11659
11660 @node Symbol Errors
11661 @section Errors reading symbol files
11662
11663 While reading a symbol file, @value{GDBN} occasionally encounters problems,
11664 such as symbol types it does not recognize, or known bugs in compiler
11665 output. By default, @value{GDBN} does not notify you of such problems, since
11666 they are relatively common and primarily of interest to people
11667 debugging compilers. If you are interested in seeing information
11668 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11669 only one message about each such type of problem, no matter how many
11670 times the problem occurs; or you can ask @value{GDBN} to print more messages,
11671 to see how many times the problems occur, with the @code{set
11672 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11673 messages}).
11674
11675 The messages currently printed, and their meanings, include:
11676
11677 @table @code
11678 @item inner block not inside outer block in @var{symbol}
11679
11680 The symbol information shows where symbol scopes begin and end
11681 (such as at the start of a function or a block of statements). This
11682 error indicates that an inner scope block is not fully contained
11683 in its outer scope blocks.
11684
11685 @value{GDBN} circumvents the problem by treating the inner block as if it had
11686 the same scope as the outer block. In the error message, @var{symbol}
11687 may be shown as ``@code{(don't know)}'' if the outer block is not a
11688 function.
11689
11690 @item block at @var{address} out of order
11691
11692 The symbol information for symbol scope blocks should occur in
11693 order of increasing addresses. This error indicates that it does not
11694 do so.
11695
11696 @value{GDBN} does not circumvent this problem, and has trouble
11697 locating symbols in the source file whose symbols it is reading. (You
11698 can often determine what source file is affected by specifying
11699 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11700 messages}.)
11701
11702 @item bad block start address patched
11703
11704 The symbol information for a symbol scope block has a start address
11705 smaller than the address of the preceding source line. This is known
11706 to occur in the SunOS 4.1.1 (and earlier) C compiler.
11707
11708 @value{GDBN} circumvents the problem by treating the symbol scope block as
11709 starting on the previous source line.
11710
11711 @item bad string table offset in symbol @var{n}
11712
11713 @cindex foo
11714 Symbol number @var{n} contains a pointer into the string table which is
11715 larger than the size of the string table.
11716
11717 @value{GDBN} circumvents the problem by considering the symbol to have the
11718 name @code{foo}, which may cause other problems if many symbols end up
11719 with this name.
11720
11721 @item unknown symbol type @code{0x@var{nn}}
11722
11723 The symbol information contains new data types that @value{GDBN} does
11724 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
11725 uncomprehended information, in hexadecimal.
11726
11727 @value{GDBN} circumvents the error by ignoring this symbol information.
11728 This usually allows you to debug your program, though certain symbols
11729 are not accessible. If you encounter such a problem and feel like
11730 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11731 on @code{complain}, then go up to the function @code{read_dbx_symtab}
11732 and examine @code{*bufp} to see the symbol.
11733
11734 @item stub type has NULL name
11735
11736 @value{GDBN} could not find the full definition for a struct or class.
11737
11738 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
11739 The symbol information for a C@t{++} member function is missing some
11740 information that recent versions of the compiler should have output for
11741 it.
11742
11743 @item info mismatch between compiler and debugger
11744
11745 @value{GDBN} could not parse a type specification output by the compiler.
11746
11747 @end table
11748
11749 @node Targets
11750 @chapter Specifying a Debugging Target
11751
11752 @cindex debugging target
11753 A @dfn{target} is the execution environment occupied by your program.
11754
11755 Often, @value{GDBN} runs in the same host environment as your program;
11756 in that case, the debugging target is specified as a side effect when
11757 you use the @code{file} or @code{core} commands. When you need more
11758 flexibility---for example, running @value{GDBN} on a physically separate
11759 host, or controlling a standalone system over a serial port or a
11760 realtime system over a TCP/IP connection---you can use the @code{target}
11761 command to specify one of the target types configured for @value{GDBN}
11762 (@pxref{Target Commands, ,Commands for managing targets}).
11763
11764 @cindex target architecture
11765 It is possible to build @value{GDBN} for several different @dfn{target
11766 architectures}. When @value{GDBN} is built like that, you can choose
11767 one of the available architectures with the @kbd{set architecture}
11768 command.
11769
11770 @table @code
11771 @kindex set architecture
11772 @kindex show architecture
11773 @item set architecture @var{arch}
11774 This command sets the current target architecture to @var{arch}. The
11775 value of @var{arch} can be @code{"auto"}, in addition to one of the
11776 supported architectures.
11777
11778 @item show architecture
11779 Show the current target architecture.
11780
11781 @item set processor
11782 @itemx processor
11783 @kindex set processor
11784 @kindex show processor
11785 These are alias commands for, respectively, @code{set architecture}
11786 and @code{show architecture}.
11787 @end table
11788
11789 @menu
11790 * Active Targets:: Active targets
11791 * Target Commands:: Commands for managing targets
11792 * Byte Order:: Choosing target byte order
11793 * Remote:: Remote debugging
11794 * KOD:: Kernel Object Display
11795
11796 @end menu
11797
11798 @node Active Targets
11799 @section Active targets
11800
11801 @cindex stacking targets
11802 @cindex active targets
11803 @cindex multiple targets
11804
11805 There are three classes of targets: processes, core files, and
11806 executable files. @value{GDBN} can work concurrently on up to three
11807 active targets, one in each class. This allows you to (for example)
11808 start a process and inspect its activity without abandoning your work on
11809 a core file.
11810
11811 For example, if you execute @samp{gdb a.out}, then the executable file
11812 @code{a.out} is the only active target. If you designate a core file as
11813 well---presumably from a prior run that crashed and coredumped---then
11814 @value{GDBN} has two active targets and uses them in tandem, looking
11815 first in the corefile target, then in the executable file, to satisfy
11816 requests for memory addresses. (Typically, these two classes of target
11817 are complementary, since core files contain only a program's
11818 read-write memory---variables and so on---plus machine status, while
11819 executable files contain only the program text and initialized data.)
11820
11821 When you type @code{run}, your executable file becomes an active process
11822 target as well. When a process target is active, all @value{GDBN}
11823 commands requesting memory addresses refer to that target; addresses in
11824 an active core file or executable file target are obscured while the
11825 process target is active.
11826
11827 Use the @code{core-file} and @code{exec-file} commands to select a new
11828 core file or executable target (@pxref{Files, ,Commands to specify
11829 files}). To specify as a target a process that is already running, use
11830 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11831 process}).
11832
11833 @node Target Commands
11834 @section Commands for managing targets
11835
11836 @table @code
11837 @item target @var{type} @var{parameters}
11838 Connects the @value{GDBN} host environment to a target machine or
11839 process. A target is typically a protocol for talking to debugging
11840 facilities. You use the argument @var{type} to specify the type or
11841 protocol of the target machine.
11842
11843 Further @var{parameters} are interpreted by the target protocol, but
11844 typically include things like device names or host names to connect
11845 with, process numbers, and baud rates.
11846
11847 The @code{target} command does not repeat if you press @key{RET} again
11848 after executing the command.
11849
11850 @kindex help target
11851 @item help target
11852 Displays the names of all targets available. To display targets
11853 currently selected, use either @code{info target} or @code{info files}
11854 (@pxref{Files, ,Commands to specify files}).
11855
11856 @item help target @var{name}
11857 Describe a particular target, including any parameters necessary to
11858 select it.
11859
11860 @kindex set gnutarget
11861 @item set gnutarget @var{args}
11862 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
11863 knows whether it is reading an @dfn{executable},
11864 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11865 with the @code{set gnutarget} command. Unlike most @code{target} commands,
11866 with @code{gnutarget} the @code{target} refers to a program, not a machine.
11867
11868 @quotation
11869 @emph{Warning:} To specify a file format with @code{set gnutarget},
11870 you must know the actual BFD name.
11871 @end quotation
11872
11873 @noindent
11874 @xref{Files, , Commands to specify files}.
11875
11876 @kindex show gnutarget
11877 @item show gnutarget
11878 Use the @code{show gnutarget} command to display what file format
11879 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
11880 @value{GDBN} will determine the file format for each file automatically,
11881 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11882 @end table
11883
11884 @cindex common targets
11885 Here are some common targets (available, or not, depending on the GDB
11886 configuration):
11887
11888 @table @code
11889 @kindex target
11890 @item target exec @var{program}
11891 @cindex executable file target
11892 An executable file. @samp{target exec @var{program}} is the same as
11893 @samp{exec-file @var{program}}.
11894
11895 @item target core @var{filename}
11896 @cindex core dump file target
11897 A core dump file. @samp{target core @var{filename}} is the same as
11898 @samp{core-file @var{filename}}.
11899
11900 @item target remote @var{dev}
11901 @cindex remote target
11902 Remote serial target in GDB-specific protocol. The argument @var{dev}
11903 specifies what serial device to use for the connection (e.g.@:
11904 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
11905 supports the @code{load} command. This is only useful if you have
11906 some other way of getting the stub to the target system, and you can put
11907 it somewhere in memory where it won't get clobbered by the download.
11908
11909 @item target sim
11910 @cindex built-in simulator target
11911 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
11912 In general,
11913 @smallexample
11914 target sim
11915 load
11916 run
11917 @end smallexample
11918 @noindent
11919 works; however, you cannot assume that a specific memory map, device
11920 drivers, or even basic I/O is available, although some simulators do
11921 provide these. For info about any processor-specific simulator details,
11922 see the appropriate section in @ref{Embedded Processors, ,Embedded
11923 Processors}.
11924
11925 @end table
11926
11927 Some configurations may include these targets as well:
11928
11929 @table @code
11930
11931 @item target nrom @var{dev}
11932 @cindex NetROM ROM emulator target
11933 NetROM ROM emulator. This target only supports downloading.
11934
11935 @end table
11936
11937 Different targets are available on different configurations of @value{GDBN};
11938 your configuration may have more or fewer targets.
11939
11940 Many remote targets require you to download the executable's code once
11941 you've successfully established a connection. You may wish to control
11942 various aspects of this process, such as the size of the data chunks
11943 used by @value{GDBN} to download program parts to the remote target.
11944
11945 @table @code
11946 @kindex set download-write-size
11947 @item set download-write-size @var{size}
11948 Set the write size used when downloading a program. Only used when
11949 downloading a program onto a remote target. Specify zero or a
11950 negative value to disable blocked writes. The actual size of each
11951 transfer is also limited by the size of the target packet and the
11952 memory cache.
11953
11954 @kindex show download-write-size
11955 @item show download-write-size
11956 @kindex show download-write-size
11957 Show the current value of the write size.
11958
11959 @item set hash
11960 @kindex set hash@r{, for remote monitors}
11961 @cindex hash mark while downloading
11962 This command controls whether a hash mark @samp{#} is displayed while
11963 downloading a file to the remote monitor. If on, a hash mark is
11964 displayed after each S-record is successfully downloaded to the
11965 monitor.
11966
11967 @item show hash
11968 @kindex show hash@r{, for remote monitors}
11969 Show the current status of displaying the hash mark.
11970
11971 @item set debug monitor
11972 @kindex set debug monitor
11973 @cindex display remote monitor communications
11974 Enable or disable display of communications messages between
11975 @value{GDBN} and the remote monitor.
11976
11977 @item show debug monitor
11978 @kindex show debug monitor
11979 Show the current status of displaying communications between
11980 @value{GDBN} and the remote monitor.
11981 @end table
11982
11983 @table @code
11984
11985 @kindex load @var{filename}
11986 @item load @var{filename}
11987 Depending on what remote debugging facilities are configured into
11988 @value{GDBN}, the @code{load} command may be available. Where it exists, it
11989 is meant to make @var{filename} (an executable) available for debugging
11990 on the remote system---by downloading, or dynamic linking, for example.
11991 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11992 the @code{add-symbol-file} command.
11993
11994 If your @value{GDBN} does not have a @code{load} command, attempting to
11995 execute it gets the error message ``@code{You can't do that when your
11996 target is @dots{}}''
11997
11998 The file is loaded at whatever address is specified in the executable.
11999 For some object file formats, you can specify the load address when you
12000 link the program; for other formats, like a.out, the object file format
12001 specifies a fixed address.
12002 @c FIXME! This would be a good place for an xref to the GNU linker doc.
12003
12004 @code{load} does not repeat if you press @key{RET} again after using it.
12005 @end table
12006
12007 @node Byte Order
12008 @section Choosing target byte order
12009
12010 @cindex choosing target byte order
12011 @cindex target byte order
12012
12013 Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
12014 offer the ability to run either big-endian or little-endian byte
12015 orders. Usually the executable or symbol will include a bit to
12016 designate the endian-ness, and you will not need to worry about
12017 which to use. However, you may still find it useful to adjust
12018 @value{GDBN}'s idea of processor endian-ness manually.
12019
12020 @table @code
12021 @kindex set endian
12022 @item set endian big
12023 Instruct @value{GDBN} to assume the target is big-endian.
12024
12025 @item set endian little
12026 Instruct @value{GDBN} to assume the target is little-endian.
12027
12028 @item set endian auto
12029 Instruct @value{GDBN} to use the byte order associated with the
12030 executable.
12031
12032 @item show endian
12033 Display @value{GDBN}'s current idea of the target byte order.
12034
12035 @end table
12036
12037 Note that these commands merely adjust interpretation of symbolic
12038 data on the host, and that they have absolutely no effect on the
12039 target system.
12040
12041 @node Remote
12042 @section Remote debugging
12043 @cindex remote debugging
12044
12045 If you are trying to debug a program running on a machine that cannot run
12046 @value{GDBN} in the usual way, it is often useful to use remote debugging.
12047 For example, you might use remote debugging on an operating system kernel,
12048 or on a small system which does not have a general purpose operating system
12049 powerful enough to run a full-featured debugger.
12050
12051 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12052 to make this work with particular debugging targets. In addition,
12053 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
12054 but not specific to any particular target system) which you can use if you
12055 write the remote stubs---the code that runs on the remote system to
12056 communicate with @value{GDBN}.
12057
12058 Other remote targets may be available in your
12059 configuration of @value{GDBN}; use @code{help target} to list them.
12060
12061 Once you've connected to the remote target, @value{GDBN} allows you to
12062 send arbitrary commands to the remote monitor:
12063
12064 @table @code
12065 @item remote @var{command}
12066 @kindex remote@r{, a command}
12067 @cindex send command to remote monitor
12068 Send an arbitrary @var{command} string to the remote monitor.
12069 @end table
12070
12071
12072 @node KOD
12073 @section Kernel Object Display
12074 @cindex kernel object display
12075 @cindex KOD
12076
12077 Some targets support kernel object display. Using this facility,
12078 @value{GDBN} communicates specially with the underlying operating system
12079 and can display information about operating system-level objects such as
12080 mutexes and other synchronization objects. Exactly which objects can be
12081 displayed is determined on a per-OS basis.
12082
12083 @kindex set os
12084 Use the @code{set os} command to set the operating system. This tells
12085 @value{GDBN} which kernel object display module to initialize:
12086
12087 @smallexample
12088 (@value{GDBP}) set os cisco
12089 @end smallexample
12090
12091 @kindex show os
12092 The associated command @code{show os} displays the operating system
12093 set with the @code{set os} command; if no operating system has been
12094 set, @code{show os} will display an empty string @samp{""}.
12095
12096 If @code{set os} succeeds, @value{GDBN} will display some information
12097 about the operating system, and will create a new @code{info} command
12098 which can be used to query the target. The @code{info} command is named
12099 after the operating system:
12100
12101 @kindex info cisco
12102 @smallexample
12103 (@value{GDBP}) info cisco
12104 List of Cisco Kernel Objects
12105 Object Description
12106 any Any and all objects
12107 @end smallexample
12108
12109 Further subcommands can be used to query about particular objects known
12110 by the kernel.
12111
12112 There is currently no way to determine whether a given operating
12113 system is supported other than to try setting it with @kbd{set os
12114 @var{name}}, where @var{name} is the name of the operating system you
12115 want to try.
12116
12117
12118 @node Remote Debugging
12119 @chapter Debugging remote programs
12120
12121 @menu
12122 * Connecting:: Connecting to a remote target
12123 * Server:: Using the gdbserver program
12124 * NetWare:: Using the gdbserve.nlm program
12125 * Remote configuration:: Remote configuration
12126 * remote stub:: Implementing a remote stub
12127 @end menu
12128
12129 @node Connecting
12130 @section Connecting to a remote target
12131
12132 On the @value{GDBN} host machine, you will need an unstripped copy of
12133 your program, since @value{GDBN} needs symobl and debugging information.
12134 Start up @value{GDBN} as usual, using the name of the local copy of your
12135 program as the first argument.
12136
12137 @cindex serial line, @code{target remote}
12138 If you're using a serial line, you may want to give @value{GDBN} the
12139 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
12140 (@pxref{Remote configuration, set remotebaud}) before the
12141 @code{target} command.
12142
12143 After that, use @code{target remote} to establish communications with
12144 the target machine. Its argument specifies how to communicate---either
12145 via a devicename attached to a direct serial line, or a TCP or UDP port
12146 (possibly to a terminal server which in turn has a serial line to the
12147 target). For example, to use a serial line connected to the device
12148 named @file{/dev/ttyb}:
12149
12150 @smallexample
12151 target remote /dev/ttyb
12152 @end smallexample
12153
12154 @cindex TCP port, @code{target remote}
12155 To use a TCP connection, use an argument of the form
12156 @code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
12157 For example, to connect to port 2828 on a
12158 terminal server named @code{manyfarms}:
12159
12160 @smallexample
12161 target remote manyfarms:2828
12162 @end smallexample
12163
12164 If your remote target is actually running on the same machine as
12165 your debugger session (e.g.@: a simulator of your target running on
12166 the same host), you can omit the hostname. For example, to connect
12167 to port 1234 on your local machine:
12168
12169 @smallexample
12170 target remote :1234
12171 @end smallexample
12172 @noindent
12173
12174 Note that the colon is still required here.
12175
12176 @cindex UDP port, @code{target remote}
12177 To use a UDP connection, use an argument of the form
12178 @code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
12179 on a terminal server named @code{manyfarms}:
12180
12181 @smallexample
12182 target remote udp:manyfarms:2828
12183 @end smallexample
12184
12185 When using a UDP connection for remote debugging, you should keep in mind
12186 that the `U' stands for ``Unreliable''. UDP can silently drop packets on
12187 busy or unreliable networks, which will cause havoc with your debugging
12188 session.
12189
12190 Now you can use all the usual commands to examine and change data and to
12191 step and continue the remote program.
12192
12193 @cindex interrupting remote programs
12194 @cindex remote programs, interrupting
12195 Whenever @value{GDBN} is waiting for the remote program, if you type the
12196 interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
12197 program. This may or may not succeed, depending in part on the hardware
12198 and the serial drivers the remote system uses. If you type the
12199 interrupt character once again, @value{GDBN} displays this prompt:
12200
12201 @smallexample
12202 Interrupted while waiting for the program.
12203 Give up (and stop debugging it)? (y or n)
12204 @end smallexample
12205
12206 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12207 (If you decide you want to try again later, you can use @samp{target
12208 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
12209 goes back to waiting.
12210
12211 @table @code
12212 @kindex detach (remote)
12213 @item detach
12214 When you have finished debugging the remote program, you can use the
12215 @code{detach} command to release it from @value{GDBN} control.
12216 Detaching from the target normally resumes its execution, but the results
12217 will depend on your particular remote stub. After the @code{detach}
12218 command, @value{GDBN} is free to connect to another target.
12219
12220 @kindex disconnect
12221 @item disconnect
12222 The @code{disconnect} command behaves like @code{detach}, except that
12223 the target is generally not resumed. It will wait for @value{GDBN}
12224 (this instance or another one) to connect and continue debugging. After
12225 the @code{disconnect} command, @value{GDBN} is again free to connect to
12226 another target.
12227
12228 @cindex send command to remote monitor
12229 @cindex extend @value{GDBN} for remote targets
12230 @cindex add new commands for external monitor
12231 @kindex monitor
12232 @item monitor @var{cmd}
12233 This command allows you to send arbitrary commands directly to the
12234 remote monitor. Since @value{GDBN} doesn't care about the commands it
12235 sends like this, this command is the way to extend @value{GDBN}---you
12236 can add new commands that only the external monitor will understand
12237 and implement.
12238 @end table
12239
12240 @node Server
12241 @section Using the @code{gdbserver} program
12242
12243 @kindex gdbserver
12244 @cindex remote connection without stubs
12245 @code{gdbserver} is a control program for Unix-like systems, which
12246 allows you to connect your program with a remote @value{GDBN} via
12247 @code{target remote}---but without linking in the usual debugging stub.
12248
12249 @code{gdbserver} is not a complete replacement for the debugging stubs,
12250 because it requires essentially the same operating-system facilities
12251 that @value{GDBN} itself does. In fact, a system that can run
12252 @code{gdbserver} to connect to a remote @value{GDBN} could also run
12253 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
12254 because it is a much smaller program than @value{GDBN} itself. It is
12255 also easier to port than all of @value{GDBN}, so you may be able to get
12256 started more quickly on a new system by using @code{gdbserver}.
12257 Finally, if you develop code for real-time systems, you may find that
12258 the tradeoffs involved in real-time operation make it more convenient to
12259 do as much development work as possible on another system, for example
12260 by cross-compiling. You can use @code{gdbserver} to make a similar
12261 choice for debugging.
12262
12263 @value{GDBN} and @code{gdbserver} communicate via either a serial line
12264 or a TCP connection, using the standard @value{GDBN} remote serial
12265 protocol.
12266
12267 @table @emph
12268 @item On the target machine,
12269 you need to have a copy of the program you want to debug.
12270 @code{gdbserver} does not need your program's symbol table, so you can
12271 strip the program if necessary to save space. @value{GDBN} on the host
12272 system does all the symbol handling.
12273
12274 To use the server, you must tell it how to communicate with @value{GDBN};
12275 the name of your program; and the arguments for your program. The usual
12276 syntax is:
12277
12278 @smallexample
12279 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12280 @end smallexample
12281
12282 @var{comm} is either a device name (to use a serial line) or a TCP
12283 hostname and portnumber. For example, to debug Emacs with the argument
12284 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
12285 @file{/dev/com1}:
12286
12287 @smallexample
12288 target> gdbserver /dev/com1 emacs foo.txt
12289 @end smallexample
12290
12291 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
12292 with it.
12293
12294 To use a TCP connection instead of a serial line:
12295
12296 @smallexample
12297 target> gdbserver host:2345 emacs foo.txt
12298 @end smallexample
12299
12300 The only difference from the previous example is the first argument,
12301 specifying that you are communicating with the host @value{GDBN} via
12302 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
12303 expect a TCP connection from machine @samp{host} to local TCP port 2345.
12304 (Currently, the @samp{host} part is ignored.) You can choose any number
12305 you want for the port number as long as it does not conflict with any
12306 TCP ports already in use on the target system (for example, @code{23} is
12307 reserved for @code{telnet}).@footnote{If you choose a port number that
12308 conflicts with another service, @code{gdbserver} prints an error message
12309 and exits.} You must use the same port number with the host @value{GDBN}
12310 @code{target remote} command.
12311
12312 On some targets, @code{gdbserver} can also attach to running programs.
12313 This is accomplished via the @code{--attach} argument. The syntax is:
12314
12315 @smallexample
12316 target> gdbserver @var{comm} --attach @var{pid}
12317 @end smallexample
12318
12319 @var{pid} is the process ID of a currently running process. It isn't necessary
12320 to point @code{gdbserver} at a binary for the running process.
12321
12322 @pindex pidof
12323 @cindex attach to a program by name
12324 You can debug processes by name instead of process ID if your target has the
12325 @code{pidof} utility:
12326
12327 @smallexample
12328 target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
12329 @end smallexample
12330
12331 In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
12332 has multiple threads, most versions of @code{pidof} support the
12333 @code{-s} option to only return the first process ID.
12334
12335 @item On the host machine,
12336 connect to your target (@pxref{Connecting,,Connecting to a remote target}).
12337 For TCP connections, you must start up @code{gdbserver} prior to using
12338 the @code{target remote} command. Otherwise you may get an error whose
12339 text depends on the host system, but which usually looks something like
12340 @samp{Connection refused}. You don't need to use the @code{load}
12341 command in @value{GDBN} when using @code{gdbserver}, since the program is
12342 already on the target. However, if you want to load the symbols (as
12343 you normally would), do that with the @code{file} command, and issue
12344 it @emph{before} connecting to the server; otherwise, you will get an
12345 error message saying @code{"Program is already running"}, since the
12346 program is considered running after the connection.
12347
12348 @end table
12349
12350 @node NetWare
12351 @section Using the @code{gdbserve.nlm} program
12352
12353 @kindex gdbserve.nlm
12354 @code{gdbserve.nlm} is a control program for NetWare systems, which
12355 allows you to connect your program with a remote @value{GDBN} via
12356 @code{target remote}.
12357
12358 @value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
12359 using the standard @value{GDBN} remote serial protocol.
12360
12361 @table @emph
12362 @item On the target machine,
12363 you need to have a copy of the program you want to debug.
12364 @code{gdbserve.nlm} does not need your program's symbol table, so you
12365 can strip the program if necessary to save space. @value{GDBN} on the
12366 host system does all the symbol handling.
12367
12368 To use the server, you must tell it how to communicate with
12369 @value{GDBN}; the name of your program; and the arguments for your
12370 program. The syntax is:
12371
12372 @smallexample
12373 load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12374 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12375 @end smallexample
12376
12377 @var{board} and @var{port} specify the serial line; @var{baud} specifies
12378 the baud rate used by the connection. @var{port} and @var{node} default
12379 to 0, @var{baud} defaults to 9600@dmn{bps}.
12380
12381 For example, to debug Emacs with the argument @samp{foo.txt}and
12382 communicate with @value{GDBN} over serial port number 2 or board 1
12383 using a 19200@dmn{bps} connection:
12384
12385 @smallexample
12386 load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12387 @end smallexample
12388
12389 @item
12390 On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12391 Connecting to a remote target}).
12392
12393 @end table
12394
12395 @node Remote configuration
12396 @section Remote configuration
12397
12398 @kindex set remote
12399 @kindex show remote
12400 This section documents the configuration options available when
12401 debugging remote programs. For the options related to the File I/O
12402 extensions of the remote protocol, see @ref{The system call,
12403 system-call-allowed}.
12404
12405 @table @code
12406 @item set remoteaddresssize @var{bits}
12407 @cindex adress size for remote targets
12408 @cindex bits in remote address
12409 Set the maximum size of address in a memory packet to the specified
12410 number of bits. @value{GDBN} will mask off the address bits above
12411 that number, when it passes addresses to the remote target. The
12412 default value is the number of bits in the target's address.
12413
12414 @item show remoteaddresssize
12415 Show the current value of remote address size in bits.
12416
12417 @item set remotebaud @var{n}
12418 @cindex baud rate for remote targets
12419 Set the baud rate for the remote serial I/O to @var{n} baud. The
12420 value is used to set the speed of the serial port used for debugging
12421 remote targets.
12422
12423 @item show remotebaud
12424 Show the current speed of the remote connection.
12425
12426 @item set remotebreak
12427 @cindex interrupt remote programs
12428 @cindex BREAK signal instead of Ctrl-C
12429 @anchor{set remotebreak}
12430 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12431 when you press the @key{Ctrl-C} key to interrupt the program running
12432 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
12433 character instead. The default is off, since most remote systems
12434 expect to see @samp{Ctrl-C} as the interrupt signal.
12435
12436 @item show remotebreak
12437 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12438 interrupt the remote program.
12439
12440 @item set remotedebug
12441 @cindex debug remote protocol
12442 @cindex remote protocol debugging
12443 @cindex display remote packets
12444 Control the debugging of the remote protocol. When enabled, each
12445 packet sent to or received from the remote target is displayed. The
12446 defaults is off.
12447
12448 @item show remotedebug
12449 Show the current setting of the remote protocol debugging.
12450
12451 @item set remotedevice @var{device}
12452 @cindex serial port name
12453 Set the name of the serial port through which to communicate to the
12454 remote target to @var{device}. This is the device used by
12455 @value{GDBN} to open the serial communications line to the remote
12456 target. There's no default, so you must set a valid port name for the
12457 remote serial communications to work. (Some varieties of the
12458 @code{target} command accept the port name as part of their
12459 arguments.)
12460
12461 @item show remotedevice
12462 Show the current name of the serial port.
12463
12464 @item set remotelogbase @var{base}
12465 Set the base (a.k.a.@: radix) of logging serial protocol
12466 communications to @var{base}. Supported values of @var{base} are:
12467 @code{ascii}, @code{octal}, and @code{hex}. The default is
12468 @code{ascii}.
12469
12470 @item show remotelogbase
12471 Show the current setting of the radix for logging remote serial
12472 protocol.
12473
12474 @item set remotelogfile @var{file}
12475 @cindex record serial communications on file
12476 Record remote serial communications on the named @var{file}. The
12477 default is not to record at all.
12478
12479 @item show remotelogfile.
12480 Show the current setting of the file name on which to record the
12481 serial communications.
12482
12483 @item set remotetimeout @var{num}
12484 @cindex timeout for serial communications
12485 @cindex remote timeout
12486 Set the timeout limit to wait for the remote target to respond to
12487 @var{num} seconds. The default is 2 seconds.
12488
12489 @item show remotetimeout
12490 Show the current number of seconds to wait for the remote target
12491 responses.
12492
12493 @cindex limit hardware breakpoints and watchpoints
12494 @cindex remote target, limit break- and watchpoints
12495 @anchor{set remote hardware-watchpoint-limit}
12496 @anchor{set remote hardware-breakpoint-limit}
12497 @item set remote hardware-watchpoint-limit @var{limit}
12498 @itemx set remote hardware-breakpoint-limit @var{limit}
12499 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12500 watchpoints. A limit of -1, the default, is treated as unlimited.
12501
12502 @item set remote fetch-register-packet
12503 @itemx set remote set-register-packet
12504 @itemx set remote P-packet
12505 @itemx set remote p-packet
12506 @cindex P-packet
12507 @cindex fetch registers from remote targets
12508 @cindex set registers in remote targets
12509 Determine whether @value{GDBN} can set and fetch registers from the
12510 remote target using the @samp{P} packets. The default depends on the
12511 remote stub's support of the @samp{P} packets (@value{GDBN} queries
12512 the stub when this packet is first required).
12513
12514 @item show remote fetch-register-packet
12515 @itemx show remote set-register-packet
12516 @itemx show remote P-packet
12517 @itemx show remote p-packet
12518 Show the current setting of using the @samp{P} packets for setting and
12519 fetching registers from the remote target.
12520
12521 @cindex binary downloads
12522 @cindex X-packet
12523 @item set remote binary-download-packet
12524 @itemx set remote X-packet
12525 Determine whether @value{GDBN} sends downloads in binary mode using
12526 the @samp{X} packets. The default is on.
12527
12528 @item show remote binary-download-packet
12529 @itemx show remote X-packet
12530 Show the current setting of using the @samp{X} packets for binary
12531 downloads.
12532
12533 @item set remote read-aux-vector-packet
12534 @cindex auxiliary vector of remote target
12535 @cindex @code{auxv}, and remote targets
12536 Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12537 auxiliary vector read) request. This request is used to fetch the
12538 remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12539 Auxiliary Vector}. The default setting depends on the remote stub's
12540 support of this request (@value{GDBN} queries the stub when this
12541 request is first required). @xref{General Query Packets, qPart}, for
12542 more information about this request.
12543
12544 @item show remote read-aux-vector-packet
12545 Show the current setting of use of the @samp{qPart:auxv:read} request.
12546
12547 @item set remote symbol-lookup-packet
12548 @cindex remote symbol lookup request
12549 Set the use of the remote protocol's @samp{qSymbol} (target symbol
12550 lookup) request. This request is used to communicate symbol
12551 information to the remote target, e.g., whenever a new shared library
12552 is loaded by the remote (@pxref{Files, shared libraries}). The
12553 default setting depends on the remote stub's support of this request
12554 (@value{GDBN} queries the stub when this request is first required).
12555 @xref{General Query Packets, qSymbol}, for more information about this
12556 request.
12557
12558 @item show remote symbol-lookup-packet
12559 Show the current setting of use of the @samp{qSymbol} request.
12560
12561 @item set remote verbose-resume-packet
12562 @cindex resume remote target
12563 @cindex signal thread, and remote targets
12564 @cindex single-step thread, and remote targets
12565 @cindex thread-specific operations on remote targets
12566 Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12567 request. This request is used to resume specific threads in the
12568 remote target, and to single-step or signal them. The default setting
12569 depends on the remote stub's support of this request (@value{GDBN}
12570 queries the stub when this request is first required). This setting
12571 affects debugging of multithreaded programs: if @samp{vCont} cannot be
12572 used, @value{GDBN} might be unable to single-step a specific thread,
12573 especially under @code{set scheduler-locking off}; it is also
12574 impossible to pause a specific thread. @xref{Packets, vCont}, for
12575 more details.
12576
12577 @item show remote verbose-resume-packet
12578 Show the current setting of use of the @samp{vCont} request
12579
12580 @item set remote software-breakpoint-packet
12581 @itemx set remote hardware-breakpoint-packet
12582 @itemx set remote write-watchpoint-packet
12583 @itemx set remote read-watchpoint-packet
12584 @itemx set remote access-watchpoint-packet
12585 @itemx set remote Z-packet
12586 @cindex Z-packet
12587 @cindex remote hardware breakpoints and watchpoints
12588 These commands enable or disable the use of @samp{Z} packets for
12589 setting breakpoints and watchpoints in the remote target. The default
12590 depends on the remote stub's support of the @samp{Z} packets
12591 (@value{GDBN} queries the stub when each packet is first required).
12592 The command @code{set remote Z-packet}, kept for back-compatibility,
12593 turns on or off all the features that require the use of @samp{Z}
12594 packets.
12595
12596 @item show remote software-breakpoint-packet
12597 @itemx show remote hardware-breakpoint-packet
12598 @itemx show remote write-watchpoint-packet
12599 @itemx show remote read-watchpoint-packet
12600 @itemx show remote access-watchpoint-packet
12601 @itemx show remote Z-packet
12602 Show the current setting of @samp{Z} packets usage.
12603
12604 @item set remote get-thread-local-storage-address
12605 @kindex set remote get-thread-local-storage-address
12606 @cindex thread local storage of remote targets
12607 This command enables or disables the use of the @samp{qGetTLSAddr}
12608 (Get Thread Local Storage Address) request packet. The default
12609 depends on whether the remote stub supports this request.
12610 @xref{General Query Packets, qGetTLSAddr}, for more details about this
12611 packet.
12612
12613 @item show remote get-thread-local-storage-address
12614 @kindex show remote get-thread-local-storage-address
12615 Show the current setting of @samp{qGetTLSAddr} packet usage.
12616 @end table
12617
12618 @node remote stub
12619 @section Implementing a remote stub
12620
12621 @cindex debugging stub, example
12622 @cindex remote stub, example
12623 @cindex stub example, remote debugging
12624 The stub files provided with @value{GDBN} implement the target side of the
12625 communication protocol, and the @value{GDBN} side is implemented in the
12626 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12627 these subroutines to communicate, and ignore the details. (If you're
12628 implementing your own stub file, you can still ignore the details: start
12629 with one of the existing stub files. @file{sparc-stub.c} is the best
12630 organized, and therefore the easiest to read.)
12631
12632 @cindex remote serial debugging, overview
12633 To debug a program running on another machine (the debugging
12634 @dfn{target} machine), you must first arrange for all the usual
12635 prerequisites for the program to run by itself. For example, for a C
12636 program, you need:
12637
12638 @enumerate
12639 @item
12640 A startup routine to set up the C runtime environment; these usually
12641 have a name like @file{crt0}. The startup routine may be supplied by
12642 your hardware supplier, or you may have to write your own.
12643
12644 @item
12645 A C subroutine library to support your program's
12646 subroutine calls, notably managing input and output.
12647
12648 @item
12649 A way of getting your program to the other machine---for example, a
12650 download program. These are often supplied by the hardware
12651 manufacturer, but you may have to write your own from hardware
12652 documentation.
12653 @end enumerate
12654
12655 The next step is to arrange for your program to use a serial port to
12656 communicate with the machine where @value{GDBN} is running (the @dfn{host}
12657 machine). In general terms, the scheme looks like this:
12658
12659 @table @emph
12660 @item On the host,
12661 @value{GDBN} already understands how to use this protocol; when everything
12662 else is set up, you can simply use the @samp{target remote} command
12663 (@pxref{Targets,,Specifying a Debugging Target}).
12664
12665 @item On the target,
12666 you must link with your program a few special-purpose subroutines that
12667 implement the @value{GDBN} remote serial protocol. The file containing these
12668 subroutines is called a @dfn{debugging stub}.
12669
12670 On certain remote targets, you can use an auxiliary program
12671 @code{gdbserver} instead of linking a stub into your program.
12672 @xref{Server,,Using the @code{gdbserver} program}, for details.
12673 @end table
12674
12675 The debugging stub is specific to the architecture of the remote
12676 machine; for example, use @file{sparc-stub.c} to debug programs on
12677 @sc{sparc} boards.
12678
12679 @cindex remote serial stub list
12680 These working remote stubs are distributed with @value{GDBN}:
12681
12682 @table @code
12683
12684 @item i386-stub.c
12685 @cindex @file{i386-stub.c}
12686 @cindex Intel
12687 @cindex i386
12688 For Intel 386 and compatible architectures.
12689
12690 @item m68k-stub.c
12691 @cindex @file{m68k-stub.c}
12692 @cindex Motorola 680x0
12693 @cindex m680x0
12694 For Motorola 680x0 architectures.
12695
12696 @item sh-stub.c
12697 @cindex @file{sh-stub.c}
12698 @cindex Renesas
12699 @cindex SH
12700 For Renesas SH architectures.
12701
12702 @item sparc-stub.c
12703 @cindex @file{sparc-stub.c}
12704 @cindex Sparc
12705 For @sc{sparc} architectures.
12706
12707 @item sparcl-stub.c
12708 @cindex @file{sparcl-stub.c}
12709 @cindex Fujitsu
12710 @cindex SparcLite
12711 For Fujitsu @sc{sparclite} architectures.
12712
12713 @end table
12714
12715 The @file{README} file in the @value{GDBN} distribution may list other
12716 recently added stubs.
12717
12718 @menu
12719 * Stub Contents:: What the stub can do for you
12720 * Bootstrapping:: What you must do for the stub
12721 * Debug Session:: Putting it all together
12722 @end menu
12723
12724 @node Stub Contents
12725 @subsection What the stub can do for you
12726
12727 @cindex remote serial stub
12728 The debugging stub for your architecture supplies these three
12729 subroutines:
12730
12731 @table @code
12732 @item set_debug_traps
12733 @findex set_debug_traps
12734 @cindex remote serial stub, initialization
12735 This routine arranges for @code{handle_exception} to run when your
12736 program stops. You must call this subroutine explicitly near the
12737 beginning of your program.
12738
12739 @item handle_exception
12740 @findex handle_exception
12741 @cindex remote serial stub, main routine
12742 This is the central workhorse, but your program never calls it
12743 explicitly---the setup code arranges for @code{handle_exception} to
12744 run when a trap is triggered.
12745
12746 @code{handle_exception} takes control when your program stops during
12747 execution (for example, on a breakpoint), and mediates communications
12748 with @value{GDBN} on the host machine. This is where the communications
12749 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
12750 representative on the target machine. It begins by sending summary
12751 information on the state of your program, then continues to execute,
12752 retrieving and transmitting any information @value{GDBN} needs, until you
12753 execute a @value{GDBN} command that makes your program resume; at that point,
12754 @code{handle_exception} returns control to your own code on the target
12755 machine.
12756
12757 @item breakpoint
12758 @cindex @code{breakpoint} subroutine, remote
12759 Use this auxiliary subroutine to make your program contain a
12760 breakpoint. Depending on the particular situation, this may be the only
12761 way for @value{GDBN} to get control. For instance, if your target
12762 machine has some sort of interrupt button, you won't need to call this;
12763 pressing the interrupt button transfers control to
12764 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12765 simply receiving characters on the serial port may also trigger a trap;
12766 again, in that situation, you don't need to call @code{breakpoint} from
12767 your own program---simply running @samp{target remote} from the host
12768 @value{GDBN} session gets control.
12769
12770 Call @code{breakpoint} if none of these is true, or if you simply want
12771 to make certain your program stops at a predetermined point for the
12772 start of your debugging session.
12773 @end table
12774
12775 @node Bootstrapping
12776 @subsection What you must do for the stub
12777
12778 @cindex remote stub, support routines
12779 The debugging stubs that come with @value{GDBN} are set up for a particular
12780 chip architecture, but they have no information about the rest of your
12781 debugging target machine.
12782
12783 First of all you need to tell the stub how to communicate with the
12784 serial port.
12785
12786 @table @code
12787 @item int getDebugChar()
12788 @findex getDebugChar
12789 Write this subroutine to read a single character from the serial port.
12790 It may be identical to @code{getchar} for your target system; a
12791 different name is used to allow you to distinguish the two if you wish.
12792
12793 @item void putDebugChar(int)
12794 @findex putDebugChar
12795 Write this subroutine to write a single character to the serial port.
12796 It may be identical to @code{putchar} for your target system; a
12797 different name is used to allow you to distinguish the two if you wish.
12798 @end table
12799
12800 @cindex control C, and remote debugging
12801 @cindex interrupting remote targets
12802 If you want @value{GDBN} to be able to stop your program while it is
12803 running, you need to use an interrupt-driven serial driver, and arrange
12804 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12805 character). That is the character which @value{GDBN} uses to tell the
12806 remote system to stop.
12807
12808 Getting the debugging target to return the proper status to @value{GDBN}
12809 probably requires changes to the standard stub; one quick and dirty way
12810 is to just execute a breakpoint instruction (the ``dirty'' part is that
12811 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12812
12813 Other routines you need to supply are:
12814
12815 @table @code
12816 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
12817 @findex exceptionHandler
12818 Write this function to install @var{exception_address} in the exception
12819 handling tables. You need to do this because the stub does not have any
12820 way of knowing what the exception handling tables on your target system
12821 are like (for example, the processor's table might be in @sc{rom},
12822 containing entries which point to a table in @sc{ram}).
12823 @var{exception_number} is the exception number which should be changed;
12824 its meaning is architecture-dependent (for example, different numbers
12825 might represent divide by zero, misaligned access, etc). When this
12826 exception occurs, control should be transferred directly to
12827 @var{exception_address}, and the processor state (stack, registers,
12828 and so on) should be just as it is when a processor exception occurs. So if
12829 you want to use a jump instruction to reach @var{exception_address}, it
12830 should be a simple jump, not a jump to subroutine.
12831
12832 For the 386, @var{exception_address} should be installed as an interrupt
12833 gate so that interrupts are masked while the handler runs. The gate
12834 should be at privilege level 0 (the most privileged level). The
12835 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
12836 help from @code{exceptionHandler}.
12837
12838 @item void flush_i_cache()
12839 @findex flush_i_cache
12840 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
12841 instruction cache, if any, on your target machine. If there is no
12842 instruction cache, this subroutine may be a no-op.
12843
12844 On target machines that have instruction caches, @value{GDBN} requires this
12845 function to make certain that the state of your program is stable.
12846 @end table
12847
12848 @noindent
12849 You must also make sure this library routine is available:
12850
12851 @table @code
12852 @item void *memset(void *, int, int)
12853 @findex memset
12854 This is the standard library function @code{memset} that sets an area of
12855 memory to a known value. If you have one of the free versions of
12856 @code{libc.a}, @code{memset} can be found there; otherwise, you must
12857 either obtain it from your hardware manufacturer, or write your own.
12858 @end table
12859
12860 If you do not use the GNU C compiler, you may need other standard
12861 library subroutines as well; this varies from one stub to another,
12862 but in general the stubs are likely to use any of the common library
12863 subroutines which @code{@value{GCC}} generates as inline code.
12864
12865
12866 @node Debug Session
12867 @subsection Putting it all together
12868
12869 @cindex remote serial debugging summary
12870 In summary, when your program is ready to debug, you must follow these
12871 steps.
12872
12873 @enumerate
12874 @item
12875 Make sure you have defined the supporting low-level routines
12876 (@pxref{Bootstrapping,,What you must do for the stub}):
12877 @display
12878 @code{getDebugChar}, @code{putDebugChar},
12879 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12880 @end display
12881
12882 @item
12883 Insert these lines near the top of your program:
12884
12885 @smallexample
12886 set_debug_traps();
12887 breakpoint();
12888 @end smallexample
12889
12890 @item
12891 For the 680x0 stub only, you need to provide a variable called
12892 @code{exceptionHook}. Normally you just use:
12893
12894 @smallexample
12895 void (*exceptionHook)() = 0;
12896 @end smallexample
12897
12898 @noindent
12899 but if before calling @code{set_debug_traps}, you set it to point to a
12900 function in your program, that function is called when
12901 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
12902 error). The function indicated by @code{exceptionHook} is called with
12903 one parameter: an @code{int} which is the exception number.
12904
12905 @item
12906 Compile and link together: your program, the @value{GDBN} debugging stub for
12907 your target architecture, and the supporting subroutines.
12908
12909 @item
12910 Make sure you have a serial connection between your target machine and
12911 the @value{GDBN} host, and identify the serial port on the host.
12912
12913 @item
12914 @c The "remote" target now provides a `load' command, so we should
12915 @c document that. FIXME.
12916 Download your program to your target machine (or get it there by
12917 whatever means the manufacturer provides), and start it.
12918
12919 @item
12920 Start @value{GDBN} on the host, and connect to the target
12921 (@pxref{Connecting,,Connecting to a remote target}).
12922
12923 @end enumerate
12924
12925 @node Configurations
12926 @chapter Configuration-Specific Information
12927
12928 While nearly all @value{GDBN} commands are available for all native and
12929 cross versions of the debugger, there are some exceptions. This chapter
12930 describes things that are only available in certain configurations.
12931
12932 There are three major categories of configurations: native
12933 configurations, where the host and target are the same, embedded
12934 operating system configurations, which are usually the same for several
12935 different processor architectures, and bare embedded processors, which
12936 are quite different from each other.
12937
12938 @menu
12939 * Native::
12940 * Embedded OS::
12941 * Embedded Processors::
12942 * Architectures::
12943 @end menu
12944
12945 @node Native
12946 @section Native
12947
12948 This section describes details specific to particular native
12949 configurations.
12950
12951 @menu
12952 * HP-UX:: HP-UX
12953 * BSD libkvm Interface:: Debugging BSD kernel memory images
12954 * SVR4 Process Information:: SVR4 process information
12955 * DJGPP Native:: Features specific to the DJGPP port
12956 * Cygwin Native:: Features specific to the Cygwin port
12957 * Hurd Native:: Features specific to @sc{gnu} Hurd
12958 * Neutrino:: Features specific to QNX Neutrino
12959 @end menu
12960
12961 @node HP-UX
12962 @subsection HP-UX
12963
12964 On HP-UX systems, if you refer to a function or variable name that
12965 begins with a dollar sign, @value{GDBN} searches for a user or system
12966 name first, before it searches for a convenience variable.
12967
12968
12969 @node BSD libkvm Interface
12970 @subsection BSD libkvm Interface
12971
12972 @cindex libkvm
12973 @cindex kernel memory image
12974 @cindex kernel crash dump
12975
12976 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12977 interface that provides a uniform interface for accessing kernel virtual
12978 memory images, including live systems and crash dumps. @value{GDBN}
12979 uses this interface to allow you to debug live kernels and kernel crash
12980 dumps on many native BSD configurations. This is implemented as a
12981 special @code{kvm} debugging target. For debugging a live system, load
12982 the currently running kernel into @value{GDBN} and connect to the
12983 @code{kvm} target:
12984
12985 @smallexample
12986 (@value{GDBP}) @b{target kvm}
12987 @end smallexample
12988
12989 For debugging crash dumps, provide the file name of the crash dump as an
12990 argument:
12991
12992 @smallexample
12993 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12994 @end smallexample
12995
12996 Once connected to the @code{kvm} target, the following commands are
12997 available:
12998
12999 @table @code
13000 @kindex kvm
13001 @item kvm pcb
13002 Set current context from the @dfn{Process Control Block} (PCB) address.
13003
13004 @item kvm proc
13005 Set current context from proc address. This command isn't available on
13006 modern FreeBSD systems.
13007 @end table
13008
13009 @node SVR4 Process Information
13010 @subsection SVR4 process information
13011 @cindex /proc
13012 @cindex examine process image
13013 @cindex process info via @file{/proc}
13014
13015 Many versions of SVR4 and compatible systems provide a facility called
13016 @samp{/proc} that can be used to examine the image of a running
13017 process using file-system subroutines. If @value{GDBN} is configured
13018 for an operating system with this facility, the command @code{info
13019 proc} is available to report information about the process running
13020 your program, or about any process running on your system. @code{info
13021 proc} works only on SVR4 systems that include the @code{procfs} code.
13022 This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13023 Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
13024
13025 @table @code
13026 @kindex info proc
13027 @cindex process ID
13028 @item info proc
13029 @itemx info proc @var{process-id}
13030 Summarize available information about any running process. If a
13031 process ID is specified by @var{process-id}, display information about
13032 that process; otherwise display information about the program being
13033 debugged. The summary includes the debugged process ID, the command
13034 line used to invoke it, its current working directory, and its
13035 executable file's absolute file name.
13036
13037 On some systems, @var{process-id} can be of the form
13038 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13039 within a process. If the optional @var{pid} part is missing, it means
13040 a thread from the process being debugged (the leading @samp{/} still
13041 needs to be present, or else @value{GDBN} will interpret the number as
13042 a process ID rather than a thread ID).
13043
13044 @item info proc mappings
13045 @cindex memory address space mappings
13046 Report the memory address space ranges accessible in the program, with
13047 information on whether the process has read, write, or execute access
13048 rights to each range. On @sc{gnu}/Linux systems, each memory range
13049 includes the object file which is mapped to that range, instead of the
13050 memory access rights to that range.
13051
13052 @item info proc stat
13053 @itemx info proc status
13054 @cindex process detailed status information
13055 These subcommands are specific to @sc{gnu}/Linux systems. They show
13056 the process-related information, including the user ID and group ID;
13057 how many threads are there in the process; its virtual memory usage;
13058 the signals that are pending, blocked, and ignored; its TTY; its
13059 consumption of system and user time; its stack size; its @samp{nice}
13060 value; etc. For more information, see the @samp{proc} man page
13061 (type @kbd{man 5 proc} from your shell prompt).
13062
13063 @item info proc all
13064 Show all the information about the process described under all of the
13065 above @code{info proc} subcommands.
13066
13067 @ignore
13068 @comment These sub-options of 'info proc' were not included when
13069 @comment procfs.c was re-written. Keep their descriptions around
13070 @comment against the day when someone finds the time to put them back in.
13071 @kindex info proc times
13072 @item info proc times
13073 Starting time, user CPU time, and system CPU time for your program and
13074 its children.
13075
13076 @kindex info proc id
13077 @item info proc id
13078 Report on the process IDs related to your program: its own process ID,
13079 the ID of its parent, the process group ID, and the session ID.
13080 @end ignore
13081
13082 @item set procfs-trace
13083 @kindex set procfs-trace
13084 @cindex @code{procfs} API calls
13085 This command enables and disables tracing of @code{procfs} API calls.
13086
13087 @item show procfs-trace
13088 @kindex show procfs-trace
13089 Show the current state of @code{procfs} API call tracing.
13090
13091 @item set procfs-file @var{file}
13092 @kindex set procfs-file
13093 Tell @value{GDBN} to write @code{procfs} API trace to the named
13094 @var{file}. @value{GDBN} appends the trace info to the previous
13095 contents of the file. The default is to display the trace on the
13096 standard output.
13097
13098 @item show procfs-file
13099 @kindex show procfs-file
13100 Show the file to which @code{procfs} API trace is written.
13101
13102 @item proc-trace-entry
13103 @itemx proc-trace-exit
13104 @itemx proc-untrace-entry
13105 @itemx proc-untrace-exit
13106 @kindex proc-trace-entry
13107 @kindex proc-trace-exit
13108 @kindex proc-untrace-entry
13109 @kindex proc-untrace-exit
13110 These commands enable and disable tracing of entries into and exits
13111 from the @code{syscall} interface.
13112
13113 @item info pidlist
13114 @kindex info pidlist
13115 @cindex process list, QNX Neutrino
13116 For QNX Neutrino only, this command displays the list of all the
13117 processes and all the threads within each process.
13118
13119 @item info meminfo
13120 @kindex info meminfo
13121 @cindex mapinfo list, QNX Neutrino
13122 For QNX Neutrino only, this command displays the list of all mapinfos.
13123 @end table
13124
13125 @node DJGPP Native
13126 @subsection Features for Debugging @sc{djgpp} Programs
13127 @cindex @sc{djgpp} debugging
13128 @cindex native @sc{djgpp} debugging
13129 @cindex MS-DOS-specific commands
13130
13131 @cindex DPMI
13132 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
13133 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
13134 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13135 top of real-mode DOS systems and their emulations.
13136
13137 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
13138 defines a few commands specific to the @sc{djgpp} port. This
13139 subsection describes those commands.
13140
13141 @table @code
13142 @kindex info dos
13143 @item info dos
13144 This is a prefix of @sc{djgpp}-specific commands which print
13145 information about the target system and important OS structures.
13146
13147 @kindex sysinfo
13148 @cindex MS-DOS system info
13149 @cindex free memory information (MS-DOS)
13150 @item info dos sysinfo
13151 This command displays assorted information about the underlying
13152 platform: the CPU type and features, the OS version and flavor, the
13153 DPMI version, and the available conventional and DPMI memory.
13154
13155 @cindex GDT
13156 @cindex LDT
13157 @cindex IDT
13158 @cindex segment descriptor tables
13159 @cindex descriptor tables display
13160 @item info dos gdt
13161 @itemx info dos ldt
13162 @itemx info dos idt
13163 These 3 commands display entries from, respectively, Global, Local,
13164 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
13165 tables are data structures which store a descriptor for each segment
13166 that is currently in use. The segment's selector is an index into a
13167 descriptor table; the table entry for that index holds the
13168 descriptor's base address and limit, and its attributes and access
13169 rights.
13170
13171 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13172 segment (used for both data and the stack), and a DOS segment (which
13173 allows access to DOS/BIOS data structures and absolute addresses in
13174 conventional memory). However, the DPMI host will usually define
13175 additional segments in order to support the DPMI environment.
13176
13177 @cindex garbled pointers
13178 These commands allow to display entries from the descriptor tables.
13179 Without an argument, all entries from the specified table are
13180 displayed. An argument, which should be an integer expression, means
13181 display a single entry whose index is given by the argument. For
13182 example, here's a convenient way to display information about the
13183 debugged program's data segment:
13184
13185 @smallexample
13186 @exdent @code{(@value{GDBP}) info dos ldt $ds}
13187 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13188 @end smallexample
13189
13190 @noindent
13191 This comes in handy when you want to see whether a pointer is outside
13192 the data segment's limit (i.e.@: @dfn{garbled}).
13193
13194 @cindex page tables display (MS-DOS)
13195 @item info dos pde
13196 @itemx info dos pte
13197 These two commands display entries from, respectively, the Page
13198 Directory and the Page Tables. Page Directories and Page Tables are
13199 data structures which control how virtual memory addresses are mapped
13200 into physical addresses. A Page Table includes an entry for every
13201 page of memory that is mapped into the program's address space; there
13202 may be several Page Tables, each one holding up to 4096 entries. A
13203 Page Directory has up to 4096 entries, one each for every Page Table
13204 that is currently in use.
13205
13206 Without an argument, @kbd{info dos pde} displays the entire Page
13207 Directory, and @kbd{info dos pte} displays all the entries in all of
13208 the Page Tables. An argument, an integer expression, given to the
13209 @kbd{info dos pde} command means display only that entry from the Page
13210 Directory table. An argument given to the @kbd{info dos pte} command
13211 means display entries from a single Page Table, the one pointed to by
13212 the specified entry in the Page Directory.
13213
13214 @cindex direct memory access (DMA) on MS-DOS
13215 These commands are useful when your program uses @dfn{DMA} (Direct
13216 Memory Access), which needs physical addresses to program the DMA
13217 controller.
13218
13219 These commands are supported only with some DPMI servers.
13220
13221 @cindex physical address from linear address
13222 @item info dos address-pte @var{addr}
13223 This command displays the Page Table entry for a specified linear
13224 address. The argument @var{addr} is a linear address which should
13225 already have the appropriate segment's base address added to it,
13226 because this command accepts addresses which may belong to @emph{any}
13227 segment. For example, here's how to display the Page Table entry for
13228 the page where a variable @code{i} is stored:
13229
13230 @smallexample
13231 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13232 @exdent @code{Page Table entry for address 0x11a00d30:}
13233 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
13234 @end smallexample
13235
13236 @noindent
13237 This says that @code{i} is stored at offset @code{0xd30} from the page
13238 whose physical base address is @code{0x02698000}, and shows all the
13239 attributes of that page.
13240
13241 Note that you must cast the addresses of variables to a @code{char *},
13242 since otherwise the value of @code{__djgpp_base_address}, the base
13243 address of all variables and functions in a @sc{djgpp} program, will
13244 be added using the rules of C pointer arithmetics: if @code{i} is
13245 declared an @code{int}, @value{GDBN} will add 4 times the value of
13246 @code{__djgpp_base_address} to the address of @code{i}.
13247
13248 Here's another example, it displays the Page Table entry for the
13249 transfer buffer:
13250
13251 @smallexample
13252 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
13253 @exdent @code{Page Table entry for address 0x29110:}
13254 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
13255 @end smallexample
13256
13257 @noindent
13258 (The @code{+ 3} offset is because the transfer buffer's address is the
13259 3rd member of the @code{_go32_info_block} structure.) The output
13260 clearly shows that this DPMI server maps the addresses in conventional
13261 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
13262 linear (@code{0x29110}) addresses are identical.
13263
13264 This command is supported only with some DPMI servers.
13265 @end table
13266
13267 @cindex DOS serial data link, remote debugging
13268 In addition to native debugging, the DJGPP port supports remote
13269 debugging via a serial data link. The following commands are specific
13270 to remote serial debugging in the DJGPP port of @value{GDBN}.
13271
13272 @table @code
13273 @kindex set com1base
13274 @kindex set com1irq
13275 @kindex set com2base
13276 @kindex set com2irq
13277 @kindex set com3base
13278 @kindex set com3irq
13279 @kindex set com4base
13280 @kindex set com4irq
13281 @item set com1base @var{addr}
13282 This command sets the base I/O port address of the @file{COM1} serial
13283 port.
13284
13285 @item set com1irq @var{irq}
13286 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
13287 for the @file{COM1} serial port.
13288
13289 There are similar commands @samp{set com2base}, @samp{set com3irq},
13290 etc.@: for setting the port address and the @code{IRQ} lines for the
13291 other 3 COM ports.
13292
13293 @kindex show com1base
13294 @kindex show com1irq
13295 @kindex show com2base
13296 @kindex show com2irq
13297 @kindex show com3base
13298 @kindex show com3irq
13299 @kindex show com4base
13300 @kindex show com4irq
13301 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
13302 display the current settings of the base address and the @code{IRQ}
13303 lines used by the COM ports.
13304
13305 @item info serial
13306 @kindex info serial
13307 @cindex DOS serial port status
13308 This command prints the status of the 4 DOS serial ports. For each
13309 port, it prints whether it's active or not, its I/O base address and
13310 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
13311 counts of various errors encountered so far.
13312 @end table
13313
13314
13315 @node Cygwin Native
13316 @subsection Features for Debugging MS Windows PE executables
13317 @cindex MS Windows debugging
13318 @cindex native Cygwin debugging
13319 @cindex Cygwin-specific commands
13320
13321 @value{GDBN} supports native debugging of MS Windows programs, including
13322 DLLs with and without symbolic debugging information. There are various
13323 additional Cygwin-specific commands, described in this subsection. The
13324 subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
13325 that have no debugging symbols.
13326
13327
13328 @table @code
13329 @kindex info w32
13330 @item info w32
13331 This is a prefix of MS Windows specific commands which print
13332 information about the target system and important OS structures.
13333
13334 @item info w32 selector
13335 This command displays information returned by
13336 the Win32 API @code{GetThreadSelectorEntry} function.
13337 It takes an optional argument that is evaluated to
13338 a long value to give the information about this given selector.
13339 Without argument, this command displays information
13340 about the the six segment registers.
13341
13342 @kindex info dll
13343 @item info dll
13344 This is a Cygwin specific alias of info shared.
13345
13346 @kindex dll-symbols
13347 @item dll-symbols
13348 This command loads symbols from a dll similarly to
13349 add-sym command but without the need to specify a base address.
13350
13351 @kindex set new-console
13352 @item set new-console @var{mode}
13353 If @var{mode} is @code{on} the debuggee will
13354 be started in a new console on next start.
13355 If @var{mode} is @code{off}i, the debuggee will
13356 be started in the same console as the debugger.
13357
13358 @kindex show new-console
13359 @item show new-console
13360 Displays whether a new console is used
13361 when the debuggee is started.
13362
13363 @kindex set new-group
13364 @item set new-group @var{mode}
13365 This boolean value controls whether the debuggee should
13366 start a new group or stay in the same group as the debugger.
13367 This affects the way the Windows OS handles
13368 Ctrl-C.
13369
13370 @kindex show new-group
13371 @item show new-group
13372 Displays current value of new-group boolean.
13373
13374 @kindex set debugevents
13375 @item set debugevents
13376 This boolean value adds debug output concerning events seen by the debugger.
13377
13378 @kindex set debugexec
13379 @item set debugexec
13380 This boolean value adds debug output concerning execute events
13381 seen by the debugger.
13382
13383 @kindex set debugexceptions
13384 @item set debugexceptions
13385 This boolean value adds debug ouptut concerning exception events
13386 seen by the debugger.
13387
13388 @kindex set debugmemory
13389 @item set debugmemory
13390 This boolean value adds debug ouptut concerning memory events
13391 seen by the debugger.
13392
13393 @kindex set shell
13394 @item set shell
13395 This boolean values specifies whether the debuggee is called
13396 via a shell or directly (default value is on).
13397
13398 @kindex show shell
13399 @item show shell
13400 Displays if the debuggee will be started with a shell.
13401
13402 @end table
13403
13404 @menu
13405 * Non-debug DLL symbols:: Support for DLLs without debugging symbols
13406 @end menu
13407
13408 @node Non-debug DLL symbols
13409 @subsubsection Support for DLLs without debugging symbols
13410 @cindex DLLs with no debugging symbols
13411 @cindex Minimal symbols and DLLs
13412
13413 Very often on windows, some of the DLLs that your program relies on do
13414 not include symbolic debugging information (for example,
13415 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13416 symbols in a DLL, it relies on the minimal amount of symbolic
13417 information contained in the DLL's export table. This subsubsection
13418 describes working with such symbols, known internally to @value{GDBN} as
13419 ``minimal symbols''.
13420
13421 Note that before the debugged program has started execution, no DLLs
13422 will have been loaded. The easiest way around this problem is simply to
13423 start the program --- either by setting a breakpoint or letting the
13424 program run once to completion. It is also possible to force
13425 @value{GDBN} to load a particular DLL before starting the executable ---
13426 see the shared library information in @pxref{Files} or the
13427 @code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13428 explicitly loading symbols from a DLL with no debugging information will
13429 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13430 which may adversely affect symbol lookup performance.
13431
13432 @subsubsection DLL name prefixes
13433
13434 In keeping with the naming conventions used by the Microsoft debugging
13435 tools, DLL export symbols are made available with a prefix based on the
13436 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13437 also entered into the symbol table, so @code{CreateFileA} is often
13438 sufficient. In some cases there will be name clashes within a program
13439 (particularly if the executable itself includes full debugging symbols)
13440 necessitating the use of the fully qualified name when referring to the
13441 contents of the DLL. Use single-quotes around the name to avoid the
13442 exclamation mark (``!'') being interpreted as a language operator.
13443
13444 Note that the internal name of the DLL may be all upper-case, even
13445 though the file name of the DLL is lower-case, or vice-versa. Since
13446 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13447 some confusion. If in doubt, try the @code{info functions} and
13448 @code{info variables} commands or even @code{maint print msymbols} (see
13449 @pxref{Symbols}). Here's an example:
13450
13451 @smallexample
13452 (@value{GDBP}) info function CreateFileA
13453 All functions matching regular expression "CreateFileA":
13454
13455 Non-debugging symbols:
13456 0x77e885f4 CreateFileA
13457 0x77e885f4 KERNEL32!CreateFileA
13458 @end smallexample
13459
13460 @smallexample
13461 (@value{GDBP}) info function !
13462 All functions matching regular expression "!":
13463
13464 Non-debugging symbols:
13465 0x6100114c cygwin1!__assert
13466 0x61004034 cygwin1!_dll_crt0@@0
13467 0x61004240 cygwin1!dll_crt0(per_process *)
13468 [etc...]
13469 @end smallexample
13470
13471 @subsubsection Working with minimal symbols
13472
13473 Symbols extracted from a DLL's export table do not contain very much
13474 type information. All that @value{GDBN} can do is guess whether a symbol
13475 refers to a function or variable depending on the linker section that
13476 contains the symbol. Also note that the actual contents of the memory
13477 contained in a DLL are not available unless the program is running. This
13478 means that you cannot examine the contents of a variable or disassemble
13479 a function within a DLL without a running program.
13480
13481 Variables are generally treated as pointers and dereferenced
13482 automatically. For this reason, it is often necessary to prefix a
13483 variable name with the address-of operator (``&'') and provide explicit
13484 type information in the command. Here's an example of the type of
13485 problem:
13486
13487 @smallexample
13488 (@value{GDBP}) print 'cygwin1!__argv'
13489 $1 = 268572168
13490 @end smallexample
13491
13492 @smallexample
13493 (@value{GDBP}) x 'cygwin1!__argv'
13494 0x10021610: "\230y\""
13495 @end smallexample
13496
13497 And two possible solutions:
13498
13499 @smallexample
13500 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
13501 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13502 @end smallexample
13503
13504 @smallexample
13505 (@value{GDBP}) x/2x &'cygwin1!__argv'
13506 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
13507 (@value{GDBP}) x/x 0x10021608
13508 0x10021608: 0x0022fd98
13509 (@value{GDBP}) x/s 0x0022fd98
13510 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
13511 @end smallexample
13512
13513 Setting a break point within a DLL is possible even before the program
13514 starts execution. However, under these circumstances, @value{GDBN} can't
13515 examine the initial instructions of the function in order to skip the
13516 function's frame set-up code. You can work around this by using ``*&''
13517 to set the breakpoint at a raw memory address:
13518
13519 @smallexample
13520 (@value{GDBP}) break *&'python22!PyOS_Readline'
13521 Breakpoint 1 at 0x1e04eff0
13522 @end smallexample
13523
13524 The author of these extensions is not entirely convinced that setting a
13525 break point within a shared DLL like @file{kernel32.dll} is completely
13526 safe.
13527
13528 @node Hurd Native
13529 @subsection Commands specific to @sc{gnu} Hurd systems
13530 @cindex @sc{gnu} Hurd debugging
13531
13532 This subsection describes @value{GDBN} commands specific to the
13533 @sc{gnu} Hurd native debugging.
13534
13535 @table @code
13536 @item set signals
13537 @itemx set sigs
13538 @kindex set signals@r{, Hurd command}
13539 @kindex set sigs@r{, Hurd command}
13540 This command toggles the state of inferior signal interception by
13541 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13542 affected by this command. @code{sigs} is a shorthand alias for
13543 @code{signals}.
13544
13545 @item show signals
13546 @itemx show sigs
13547 @kindex show signals@r{, Hurd command}
13548 @kindex show sigs@r{, Hurd command}
13549 Show the current state of intercepting inferior's signals.
13550
13551 @item set signal-thread
13552 @itemx set sigthread
13553 @kindex set signal-thread
13554 @kindex set sigthread
13555 This command tells @value{GDBN} which thread is the @code{libc} signal
13556 thread. That thread is run when a signal is delivered to a running
13557 process. @code{set sigthread} is the shorthand alias of @code{set
13558 signal-thread}.
13559
13560 @item show signal-thread
13561 @itemx show sigthread
13562 @kindex show signal-thread
13563 @kindex show sigthread
13564 These two commands show which thread will run when the inferior is
13565 delivered a signal.
13566
13567 @item set stopped
13568 @kindex set stopped@r{, Hurd command}
13569 This commands tells @value{GDBN} that the inferior process is stopped,
13570 as with the @code{SIGSTOP} signal. The stopped process can be
13571 continued by delivering a signal to it.
13572
13573 @item show stopped
13574 @kindex show stopped@r{, Hurd command}
13575 This command shows whether @value{GDBN} thinks the debuggee is
13576 stopped.
13577
13578 @item set exceptions
13579 @kindex set exceptions@r{, Hurd command}
13580 Use this command to turn off trapping of exceptions in the inferior.
13581 When exception trapping is off, neither breakpoints nor
13582 single-stepping will work. To restore the default, set exception
13583 trapping on.
13584
13585 @item show exceptions
13586 @kindex show exceptions@r{, Hurd command}
13587 Show the current state of trapping exceptions in the inferior.
13588
13589 @item set task pause
13590 @kindex set task@r{, Hurd commands}
13591 @cindex task attributes (@sc{gnu} Hurd)
13592 @cindex pause current task (@sc{gnu} Hurd)
13593 This command toggles task suspension when @value{GDBN} has control.
13594 Setting it to on takes effect immediately, and the task is suspended
13595 whenever @value{GDBN} gets control. Setting it to off will take
13596 effect the next time the inferior is continued. If this option is set
13597 to off, you can use @code{set thread default pause on} or @code{set
13598 thread pause on} (see below) to pause individual threads.
13599
13600 @item show task pause
13601 @kindex show task@r{, Hurd commands}
13602 Show the current state of task suspension.
13603
13604 @item set task detach-suspend-count
13605 @cindex task suspend count
13606 @cindex detach from task, @sc{gnu} Hurd
13607 This command sets the suspend count the task will be left with when
13608 @value{GDBN} detaches from it.
13609
13610 @item show task detach-suspend-count
13611 Show the suspend count the task will be left with when detaching.
13612
13613 @item set task exception-port
13614 @itemx set task excp
13615 @cindex task exception port, @sc{gnu} Hurd
13616 This command sets the task exception port to which @value{GDBN} will
13617 forward exceptions. The argument should be the value of the @dfn{send
13618 rights} of the task. @code{set task excp} is a shorthand alias.
13619
13620 @item set noninvasive
13621 @cindex noninvasive task options
13622 This command switches @value{GDBN} to a mode that is the least
13623 invasive as far as interfering with the inferior is concerned. This
13624 is the same as using @code{set task pause}, @code{set exceptions}, and
13625 @code{set signals} to values opposite to the defaults.
13626
13627 @item info send-rights
13628 @itemx info receive-rights
13629 @itemx info port-rights
13630 @itemx info port-sets
13631 @itemx info dead-names
13632 @itemx info ports
13633 @itemx info psets
13634 @cindex send rights, @sc{gnu} Hurd
13635 @cindex receive rights, @sc{gnu} Hurd
13636 @cindex port rights, @sc{gnu} Hurd
13637 @cindex port sets, @sc{gnu} Hurd
13638 @cindex dead names, @sc{gnu} Hurd
13639 These commands display information about, respectively, send rights,
13640 receive rights, port rights, port sets, and dead names of a task.
13641 There are also shorthand aliases: @code{info ports} for @code{info
13642 port-rights} and @code{info psets} for @code{info port-sets}.
13643
13644 @item set thread pause
13645 @kindex set thread@r{, Hurd command}
13646 @cindex thread properties, @sc{gnu} Hurd
13647 @cindex pause current thread (@sc{gnu} Hurd)
13648 This command toggles current thread suspension when @value{GDBN} has
13649 control. Setting it to on takes effect immediately, and the current
13650 thread is suspended whenever @value{GDBN} gets control. Setting it to
13651 off will take effect the next time the inferior is continued.
13652 Normally, this command has no effect, since when @value{GDBN} has
13653 control, the whole task is suspended. However, if you used @code{set
13654 task pause off} (see above), this command comes in handy to suspend
13655 only the current thread.
13656
13657 @item show thread pause
13658 @kindex show thread@r{, Hurd command}
13659 This command shows the state of current thread suspension.
13660
13661 @item set thread run
13662 This comamnd sets whether the current thread is allowed to run.
13663
13664 @item show thread run
13665 Show whether the current thread is allowed to run.
13666
13667 @item set thread detach-suspend-count
13668 @cindex thread suspend count, @sc{gnu} Hurd
13669 @cindex detach from thread, @sc{gnu} Hurd
13670 This command sets the suspend count @value{GDBN} will leave on a
13671 thread when detaching. This number is relative to the suspend count
13672 found by @value{GDBN} when it notices the thread; use @code{set thread
13673 takeover-suspend-count} to force it to an absolute value.
13674
13675 @item show thread detach-suspend-count
13676 Show the suspend count @value{GDBN} will leave on the thread when
13677 detaching.
13678
13679 @item set thread exception-port
13680 @itemx set thread excp
13681 Set the thread exception port to which to forward exceptions. This
13682 overrides the port set by @code{set task exception-port} (see above).
13683 @code{set thread excp} is the shorthand alias.
13684
13685 @item set thread takeover-suspend-count
13686 Normally, @value{GDBN}'s thread suspend counts are relative to the
13687 value @value{GDBN} finds when it notices each thread. This command
13688 changes the suspend counts to be absolute instead.
13689
13690 @item set thread default
13691 @itemx show thread default
13692 @cindex thread default settings, @sc{gnu} Hurd
13693 Each of the above @code{set thread} commands has a @code{set thread
13694 default} counterpart (e.g., @code{set thread default pause}, @code{set
13695 thread default exception-port}, etc.). The @code{thread default}
13696 variety of commands sets the default thread properties for all
13697 threads; you can then change the properties of individual threads with
13698 the non-default commands.
13699 @end table
13700
13701
13702 @node Neutrino
13703 @subsection QNX Neutrino
13704 @cindex QNX Neutrino
13705
13706 @value{GDBN} provides the following commands specific to the QNX
13707 Neutrino target:
13708
13709 @table @code
13710 @item set debug nto-debug
13711 @kindex set debug nto-debug
13712 When set to on, enables debugging messages specific to the QNX
13713 Neutrino support.
13714
13715 @item show debug nto-debug
13716 @kindex show debug nto-debug
13717 Show the current state of QNX Neutrino messages.
13718 @end table
13719
13720
13721 @node Embedded OS
13722 @section Embedded Operating Systems
13723
13724 This section describes configurations involving the debugging of
13725 embedded operating systems that are available for several different
13726 architectures.
13727
13728 @menu
13729 * VxWorks:: Using @value{GDBN} with VxWorks
13730 @end menu
13731
13732 @value{GDBN} includes the ability to debug programs running on
13733 various real-time operating systems.
13734
13735 @node VxWorks
13736 @subsection Using @value{GDBN} with VxWorks
13737
13738 @cindex VxWorks
13739
13740 @table @code
13741
13742 @kindex target vxworks
13743 @item target vxworks @var{machinename}
13744 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13745 is the target system's machine name or IP address.
13746
13747 @end table
13748
13749 On VxWorks, @code{load} links @var{filename} dynamically on the
13750 current target system as well as adding its symbols in @value{GDBN}.
13751
13752 @value{GDBN} enables developers to spawn and debug tasks running on networked
13753 VxWorks targets from a Unix host. Already-running tasks spawned from
13754 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13755 both the Unix host and on the VxWorks target. The program
13756 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13757 installed with the name @code{vxgdb}, to distinguish it from a
13758 @value{GDBN} for debugging programs on the host itself.)
13759
13760 @table @code
13761 @item VxWorks-timeout @var{args}
13762 @kindex vxworks-timeout
13763 All VxWorks-based targets now support the option @code{vxworks-timeout}.
13764 This option is set by the user, and @var{args} represents the number of
13765 seconds @value{GDBN} waits for responses to rpc's. You might use this if
13766 your VxWorks target is a slow software simulator or is on the far side
13767 of a thin network line.
13768 @end table
13769
13770 The following information on connecting to VxWorks was current when
13771 this manual was produced; newer releases of VxWorks may use revised
13772 procedures.
13773
13774 @findex INCLUDE_RDB
13775 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13776 to include the remote debugging interface routines in the VxWorks
13777 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13778 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13779 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13780 source debugging task @code{tRdbTask} when VxWorks is booted. For more
13781 information on configuring and remaking VxWorks, see the manufacturer's
13782 manual.
13783 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
13784
13785 Once you have included @file{rdb.a} in your VxWorks system image and set
13786 your Unix execution search path to find @value{GDBN}, you are ready to
13787 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13788 @code{vxgdb}, depending on your installation).
13789
13790 @value{GDBN} comes up showing the prompt:
13791
13792 @smallexample
13793 (vxgdb)
13794 @end smallexample
13795
13796 @menu
13797 * VxWorks Connection:: Connecting to VxWorks
13798 * VxWorks Download:: VxWorks download
13799 * VxWorks Attach:: Running tasks
13800 @end menu
13801
13802 @node VxWorks Connection
13803 @subsubsection Connecting to VxWorks
13804
13805 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13806 network. To connect to a target whose host name is ``@code{tt}'', type:
13807
13808 @smallexample
13809 (vxgdb) target vxworks tt
13810 @end smallexample
13811
13812 @need 750
13813 @value{GDBN} displays messages like these:
13814
13815 @smallexample
13816 Attaching remote machine across net...
13817 Connected to tt.
13818 @end smallexample
13819
13820 @need 1000
13821 @value{GDBN} then attempts to read the symbol tables of any object modules
13822 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13823 these files by searching the directories listed in the command search
13824 path (@pxref{Environment, ,Your program's environment}); if it fails
13825 to find an object file, it displays a message such as:
13826
13827 @smallexample
13828 prog.o: No such file or directory.
13829 @end smallexample
13830
13831 When this happens, add the appropriate directory to the search path with
13832 the @value{GDBN} command @code{path}, and execute the @code{target}
13833 command again.
13834
13835 @node VxWorks Download
13836 @subsubsection VxWorks download
13837
13838 @cindex download to VxWorks
13839 If you have connected to the VxWorks target and you want to debug an
13840 object that has not yet been loaded, you can use the @value{GDBN}
13841 @code{load} command to download a file from Unix to VxWorks
13842 incrementally. The object file given as an argument to the @code{load}
13843 command is actually opened twice: first by the VxWorks target in order
13844 to download the code, then by @value{GDBN} in order to read the symbol
13845 table. This can lead to problems if the current working directories on
13846 the two systems differ. If both systems have NFS mounted the same
13847 filesystems, you can avoid these problems by using absolute paths.
13848 Otherwise, it is simplest to set the working directory on both systems
13849 to the directory in which the object file resides, and then to reference
13850 the file by its name, without any path. For instance, a program
13851 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13852 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13853 program, type this on VxWorks:
13854
13855 @smallexample
13856 -> cd "@var{vxpath}/vw/demo/rdb"
13857 @end smallexample
13858
13859 @noindent
13860 Then, in @value{GDBN}, type:
13861
13862 @smallexample
13863 (vxgdb) cd @var{hostpath}/vw/demo/rdb
13864 (vxgdb) load prog.o
13865 @end smallexample
13866
13867 @value{GDBN} displays a response similar to this:
13868
13869 @smallexample
13870 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13871 @end smallexample
13872
13873 You can also use the @code{load} command to reload an object module
13874 after editing and recompiling the corresponding source file. Note that
13875 this makes @value{GDBN} delete all currently-defined breakpoints,
13876 auto-displays, and convenience variables, and to clear the value
13877 history. (This is necessary in order to preserve the integrity of
13878 debugger's data structures that reference the target system's symbol
13879 table.)
13880
13881 @node VxWorks Attach
13882 @subsubsection Running tasks
13883
13884 @cindex running VxWorks tasks
13885 You can also attach to an existing task using the @code{attach} command as
13886 follows:
13887
13888 @smallexample
13889 (vxgdb) attach @var{task}
13890 @end smallexample
13891
13892 @noindent
13893 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13894 or suspended when you attach to it. Running tasks are suspended at
13895 the time of attachment.
13896
13897 @node Embedded Processors
13898 @section Embedded Processors
13899
13900 This section goes into details specific to particular embedded
13901 configurations.
13902
13903 @cindex send command to simulator
13904 Whenever a specific embedded processor has a simulator, @value{GDBN}
13905 allows to send an arbitrary command to the simulator.
13906
13907 @table @code
13908 @item sim @var{command}
13909 @kindex sim@r{, a command}
13910 Send an arbitrary @var{command} string to the simulator. Consult the
13911 documentation for the specific simulator in use for information about
13912 acceptable commands.
13913 @end table
13914
13915
13916 @menu
13917 * ARM:: ARM RDI
13918 * H8/300:: Renesas H8/300
13919 * H8/500:: Renesas H8/500
13920 * M32R/D:: Renesas M32R/D
13921 * M68K:: Motorola M68K
13922 * MIPS Embedded:: MIPS Embedded
13923 * OpenRISC 1000:: OpenRisc 1000
13924 * PA:: HP PA Embedded
13925 * PowerPC: PowerPC
13926 * SH:: Renesas SH
13927 * Sparclet:: Tsqware Sparclet
13928 * Sparclite:: Fujitsu Sparclite
13929 * ST2000:: Tandem ST2000
13930 * Z8000:: Zilog Z8000
13931 * AVR:: Atmel AVR
13932 * CRIS:: CRIS
13933 * Super-H:: Renesas Super-H
13934 * WinCE:: Windows CE child processes
13935 @end menu
13936
13937 @node ARM
13938 @subsection ARM
13939 @cindex ARM RDI
13940
13941 @table @code
13942 @kindex target rdi
13943 @item target rdi @var{dev}
13944 ARM Angel monitor, via RDI library interface to ADP protocol. You may
13945 use this target to communicate with both boards running the Angel
13946 monitor, or with the EmbeddedICE JTAG debug device.
13947
13948 @kindex target rdp
13949 @item target rdp @var{dev}
13950 ARM Demon monitor.
13951
13952 @end table
13953
13954 @value{GDBN} provides the following ARM-specific commands:
13955
13956 @table @code
13957 @item set arm disassembler
13958 @kindex set arm
13959 This commands selects from a list of disassembly styles. The
13960 @code{"std"} style is the standard style.
13961
13962 @item show arm disassembler
13963 @kindex show arm
13964 Show the current disassembly style.
13965
13966 @item set arm apcs32
13967 @cindex ARM 32-bit mode
13968 This command toggles ARM operation mode between 32-bit and 26-bit.
13969
13970 @item show arm apcs32
13971 Display the current usage of the ARM 32-bit mode.
13972
13973 @item set arm fpu @var{fputype}
13974 This command sets the ARM floating-point unit (FPU) type. The
13975 argument @var{fputype} can be one of these:
13976
13977 @table @code
13978 @item auto
13979 Determine the FPU type by querying the OS ABI.
13980 @item softfpa
13981 Software FPU, with mixed-endian doubles on little-endian ARM
13982 processors.
13983 @item fpa
13984 GCC-compiled FPA co-processor.
13985 @item softvfp
13986 Software FPU with pure-endian doubles.
13987 @item vfp
13988 VFP co-processor.
13989 @end table
13990
13991 @item show arm fpu
13992 Show the current type of the FPU.
13993
13994 @item set arm abi
13995 This command forces @value{GDBN} to use the specified ABI.
13996
13997 @item show arm abi
13998 Show the currently used ABI.
13999
14000 @item set debug arm
14001 Toggle whether to display ARM-specific debugging messages from the ARM
14002 target support subsystem.
14003
14004 @item show debug arm
14005 Show whether ARM-specific debugging messages are enabled.
14006 @end table
14007
14008 The following commands are available when an ARM target is debugged
14009 using the RDI interface:
14010
14011 @table @code
14012 @item rdilogfile @r{[}@var{file}@r{]}
14013 @kindex rdilogfile
14014 @cindex ADP (Angel Debugger Protocol) logging
14015 Set the filename for the ADP (Angel Debugger Protocol) packet log.
14016 With an argument, sets the log file to the specified @var{file}. With
14017 no argument, show the current log file name. The default log file is
14018 @file{rdi.log}.
14019
14020 @item rdilogenable @r{[}@var{arg}@r{]}
14021 @kindex rdilogenable
14022 Control logging of ADP packets. With an argument of 1 or @code{"yes"}
14023 enables logging, with an argument 0 or @code{"no"} disables it. With
14024 no arguments displays the current setting. When logging is enabled,
14025 ADP packets exchanged between @value{GDBN} and the RDI target device
14026 are logged to a file.
14027
14028 @item set rdiromatzero
14029 @kindex set rdiromatzero
14030 @cindex ROM at zero address, RDI
14031 Tell @value{GDBN} whether the target has ROM at address 0. If on,
14032 vector catching is disabled, so that zero address can be used. If off
14033 (the default), vector catching is enabled. For this command to take
14034 effect, it needs to be invoked prior to the @code{target rdi} command.
14035
14036 @item show rdiromatzero
14037 @kindex show rdiromatzero
14038 Show the current setting of ROM at zero address.
14039
14040 @item set rdiheartbeat
14041 @kindex set rdiheartbeat
14042 @cindex RDI heartbeat
14043 Enable or disable RDI heartbeat packets. It is not recommended to
14044 turn on this option, since it confuses ARM and EPI JTAG interface, as
14045 well as the Angel monitor.
14046
14047 @item show rdiheartbeat
14048 @kindex show rdiheartbeat
14049 Show the setting of RDI heartbeat packets.
14050 @end table
14051
14052
14053 @node H8/300
14054 @subsection Renesas H8/300
14055
14056 @table @code
14057
14058 @kindex target hms@r{, with H8/300}
14059 @item target hms @var{dev}
14060 A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
14061 Use special commands @code{device} and @code{speed} to control the serial
14062 line and the communications speed used.
14063
14064 @kindex target e7000@r{, with H8/300}
14065 @item target e7000 @var{dev}
14066 E7000 emulator for Renesas H8 and SH.
14067
14068 @kindex target sh3@r{, with H8/300}
14069 @kindex target sh3e@r{, with H8/300}
14070 @item target sh3 @var{dev}
14071 @itemx target sh3e @var{dev}
14072 Renesas SH-3 and SH-3E target systems.
14073
14074 @end table
14075
14076 @cindex download to H8/300 or H8/500
14077 @cindex H8/300 or H8/500 download
14078 @cindex download to Renesas SH
14079 @cindex Renesas SH download
14080 When you select remote debugging to a Renesas SH, H8/300, or H8/500
14081 board, the @code{load} command downloads your program to the Renesas
14082 board and also opens it as the current executable target for
14083 @value{GDBN} on your host (like the @code{file} command).
14084
14085 @value{GDBN} needs to know these things to talk to your
14086 Renesas SH, H8/300, or H8/500:
14087
14088 @enumerate
14089 @item
14090 that you want to use @samp{target hms}, the remote debugging interface
14091 for Renesas microprocessors, or @samp{target e7000}, the in-circuit
14092 emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
14093 the default when @value{GDBN} is configured specifically for the Renesas SH,
14094 H8/300, or H8/500.)
14095
14096 @item
14097 what serial device connects your host to your Renesas board (the first
14098 serial device available on your host is the default).
14099
14100 @item
14101 what speed to use over the serial device.
14102 @end enumerate
14103
14104 @menu
14105 * Renesas Boards:: Connecting to Renesas boards.
14106 * Renesas ICE:: Using the E7000 In-Circuit Emulator.
14107 * Renesas Special:: Special @value{GDBN} commands for Renesas micros.
14108 @end menu
14109
14110 @node Renesas Boards
14111 @subsubsection Connecting to Renesas boards
14112
14113 @c only for Unix hosts
14114 @kindex device
14115 @cindex serial device, Renesas micros
14116 Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
14117 need to explicitly set the serial device. The default @var{port} is the
14118 first available port on your host. This is only necessary on Unix
14119 hosts, where it is typically something like @file{/dev/ttya}.
14120
14121 @kindex speed
14122 @cindex serial line speed, Renesas micros
14123 @code{@value{GDBN}} has another special command to set the communications
14124 speed: @samp{speed @var{bps}}. This command also is only used from Unix
14125 hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
14126 the DOS @code{mode} command (for instance,
14127 @w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
14128
14129 The @samp{device} and @samp{speed} commands are available only when you
14130 use a Unix host to debug your Renesas microprocessor programs. If you
14131 use a DOS host,
14132 @value{GDBN} depends on an auxiliary terminate-and-stay-resident program
14133 called @code{asynctsr} to communicate with the development board
14134 through a PC serial port. You must also use the DOS @code{mode} command
14135 to set up the serial port on the DOS side.
14136
14137 The following sample session illustrates the steps needed to start a
14138 program under @value{GDBN} control on an H8/300. The example uses a
14139 sample H8/300 program called @file{t.x}. The procedure is the same for
14140 the Renesas SH and the H8/500.
14141
14142 First hook up your development board. In this example, we use a
14143 board attached to serial port @code{COM2}; if you use a different serial
14144 port, substitute its name in the argument of the @code{mode} command.
14145 When you call @code{asynctsr}, the auxiliary comms program used by the
14146 debugger, you give it just the numeric part of the serial port's name;
14147 for example, @samp{asyncstr 2} below runs @code{asyncstr} on
14148 @code{COM2}.
14149
14150 @smallexample
14151 C:\H8300\TEST> asynctsr 2
14152 C:\H8300\TEST> mode com2:9600,n,8,1,p
14153
14154 Resident portion of MODE loaded
14155
14156 COM2: 9600, n, 8, 1, p
14157
14158 @end smallexample
14159
14160 @quotation
14161 @emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
14162 @code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
14163 disable it, or even boot without it, to use @code{asynctsr} to control
14164 your development board.
14165 @end quotation
14166
14167 @kindex target hms@r{, and serial protocol}
14168 Now that serial communications are set up, and the development board is
14169 connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
14170 the name of your program as the argument. @code{@value{GDBN}} prompts
14171 you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
14172 commands to begin your debugging session: @samp{target hms} to specify
14173 cross-debugging to the Renesas board, and the @code{load} command to
14174 download your program to the board. @code{load} displays the names of
14175 the program's sections, and a @samp{*} for each 2K of data downloaded.
14176 (If you want to refresh @value{GDBN} data on symbols or on the
14177 executable file without downloading, use the @value{GDBN} commands
14178 @code{file} or @code{symbol-file}. These commands, and @code{load}
14179 itself, are described in @ref{Files,,Commands to specify files}.)
14180
14181 @smallexample
14182 (eg-C:\H8300\TEST) @value{GDBP} t.x
14183 @value{GDBN} is free software and you are welcome to distribute copies
14184 of it under certain conditions; type "show copying" to see
14185 the conditions.
14186 There is absolutely no warranty for @value{GDBN}; type "show warranty"
14187 for details.
14188 @value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
14189 (@value{GDBP}) target hms
14190 Connected to remote H8/300 HMS system.
14191 (@value{GDBP}) load t.x
14192 .text : 0x8000 .. 0xabde ***********
14193 .data : 0xabde .. 0xad30 *
14194 .stack : 0xf000 .. 0xf014 *
14195 @end smallexample
14196
14197 At this point, you're ready to run or debug your program. From here on,
14198 you can use all the usual @value{GDBN} commands. The @code{break} command
14199 sets breakpoints; the @code{run} command starts your program;
14200 @code{print} or @code{x} display data; the @code{continue} command
14201 resumes execution after stopping at a breakpoint. You can use the
14202 @code{help} command at any time to find out more about @value{GDBN} commands.
14203
14204 Remember, however, that @emph{operating system} facilities aren't
14205 available on your development board; for example, if your program hangs,
14206 you can't send an interrupt---but you can press the @sc{reset} switch!
14207
14208 Use the @sc{reset} button on the development board
14209 @itemize @bullet
14210 @item
14211 to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
14212 no way to pass an interrupt signal to the development board); and
14213
14214 @item
14215 to return to the @value{GDBN} command prompt after your program finishes
14216 normally. The communications protocol provides no other way for @value{GDBN}
14217 to detect program completion.
14218 @end itemize
14219
14220 In either case, @value{GDBN} sees the effect of a @sc{reset} on the
14221 development board as a ``normal exit'' of your program.
14222
14223 @node Renesas ICE
14224 @subsubsection Using the E7000 in-circuit emulator
14225
14226 @kindex target e7000@r{, with Renesas ICE}
14227 You can use the E7000 in-circuit emulator to develop code for either the
14228 Renesas SH or the H8/300H. Use one of these forms of the @samp{target
14229 e7000} command to connect @value{GDBN} to your E7000:
14230
14231 @table @code
14232 @item target e7000 @var{port} @var{speed}
14233 Use this form if your E7000 is connected to a serial port. The
14234 @var{port} argument identifies what serial port to use (for example,
14235 @samp{com2}). The third argument is the line speed in bits per second
14236 (for example, @samp{9600}).
14237
14238 @item target e7000 @var{hostname}
14239 If your E7000 is installed as a host on a TCP/IP network, you can just
14240 specify its hostname; @value{GDBN} uses @code{telnet} to connect.
14241 @end table
14242
14243 The following special commands are available when debugging with the
14244 Renesas E7000 ICE:
14245
14246 @table @code
14247 @item e7000 @var{command}
14248 @kindex e7000
14249 @cindex send command to E7000 monitor
14250 This sends the specified @var{command} to the E7000 monitor.
14251
14252 @item ftplogin @var{machine} @var{username} @var{password} @var{dir}
14253 @kindex ftplogin@r{, E7000}
14254 This command records information for subsequent interface with the
14255 E7000 monitor via the FTP protocol: @value{GDBN} will log into the
14256 named @var{machine} using specified @var{username} and @var{password},
14257 and then chdir to the named directory @var{dir}.
14258
14259 @item ftpload @var{file}
14260 @kindex ftpload@r{, E7000}
14261 This command uses credentials recorded by @code{ftplogin} to fetch and
14262 load the named @var{file} from the E7000 monitor.
14263
14264 @item drain
14265 @kindex drain@r{, E7000}
14266 This command drains any pending text buffers stored on the E7000.
14267
14268 @item set usehardbreakpoints
14269 @itemx show usehardbreakpoints
14270 @kindex set usehardbreakpoints@r{, E7000}
14271 @kindex show usehardbreakpoints@r{, E7000}
14272 @cindex hardware breakpoints, and E7000
14273 These commands set and show the use of hardware breakpoints for all
14274 breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
14275 more information about using hardware breakpoints selectively.
14276 @end table
14277
14278 @node Renesas Special
14279 @subsubsection Special @value{GDBN} commands for Renesas micros
14280
14281 Some @value{GDBN} commands are available only for the H8/300:
14282
14283 @table @code
14284
14285 @kindex set machine
14286 @kindex show machine
14287 @item set machine h8300
14288 @itemx set machine h8300h
14289 Condition @value{GDBN} for one of the two variants of the H8/300
14290 architecture with @samp{set machine}. You can use @samp{show machine}
14291 to check which variant is currently in effect.
14292
14293 @end table
14294
14295 @node H8/500
14296 @subsection H8/500
14297
14298 @table @code
14299
14300 @kindex set memory @var{mod}
14301 @cindex memory models, H8/500
14302 @item set memory @var{mod}
14303 @itemx show memory
14304 Specify which H8/500 memory model (@var{mod}) you are using with
14305 @samp{set memory}; check which memory model is in effect with @samp{show
14306 memory}. The accepted values for @var{mod} are @code{small},
14307 @code{big}, @code{medium}, and @code{compact}.
14308
14309 @end table
14310
14311 @node M32R/D
14312 @subsection Renesas M32R/D and M32R/SDI
14313
14314 @table @code
14315 @kindex target m32r
14316 @item target m32r @var{dev}
14317 Renesas M32R/D ROM monitor.
14318
14319 @kindex target m32rsdi
14320 @item target m32rsdi @var{dev}
14321 Renesas M32R SDI server, connected via parallel port to the board.
14322 @end table
14323
14324 The following @value{GDBN} commands are specific to the M32R monitor:
14325
14326 @table @code
14327 @item set download-path @var{path}
14328 @kindex set download-path
14329 @cindex find downloadable @sc{srec} files (M32R)
14330 Set the default path for finding donwloadable @sc{srec} files.
14331
14332 @item show download-path
14333 @kindex show download-path
14334 Show the default path for downloadable @sc{srec} files.
14335
14336 @item set board-address @var{addr}
14337 @kindex set board-address
14338 @cindex M32-EVA target board address
14339 Set the IP address for the M32R-EVA target board.
14340
14341 @item show board-address
14342 @kindex show board-address
14343 Show the current IP address of the target board.
14344
14345 @item set server-address @var{addr}
14346 @kindex set server-address
14347 @cindex download server address (M32R)
14348 Set the IP address for the download server, which is the @value{GDBN}'s
14349 host machine.
14350
14351 @item show server-address
14352 @kindex show server-address
14353 Display the IP address of the download server.
14354
14355 @item upload @r{[}@var{file}@r{]}
14356 @kindex upload@r{, M32R}
14357 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14358 upload capability. If no @var{file} argument is given, the current
14359 executable file is uploaded.
14360
14361 @item tload @r{[}@var{file}@r{]}
14362 @kindex tload@r{, M32R}
14363 Test the @code{upload} command.
14364 @end table
14365
14366 The following commands are available for M32R/SDI:
14367
14368 @table @code
14369 @item sdireset
14370 @kindex sdireset
14371 @cindex reset SDI connection, M32R
14372 This command resets the SDI connection.
14373
14374 @item sdistatus
14375 @kindex sdistatus
14376 This command shows the SDI connection status.
14377
14378 @item debug_chaos
14379 @kindex debug_chaos
14380 @cindex M32R/Chaos debugging
14381 Instructs the remote that M32R/Chaos debugging is to be used.
14382
14383 @item use_debug_dma
14384 @kindex use_debug_dma
14385 Instructs the remote to use the DEBUG_DMA method of accessing memory.
14386
14387 @item use_mon_code
14388 @kindex use_mon_code
14389 Instructs the remote to use the MON_CODE method of accessing memory.
14390
14391 @item use_ib_break
14392 @kindex use_ib_break
14393 Instructs the remote to set breakpoints by IB break.
14394
14395 @item use_dbt_break
14396 @kindex use_dbt_break
14397 Instructs the remote to set breakpoints by DBT.
14398 @end table
14399
14400 @node M68K
14401 @subsection M68k
14402
14403 The Motorola m68k configuration includes ColdFire support, and
14404 target command for the following ROM monitors.
14405
14406 @table @code
14407
14408 @kindex target abug
14409 @item target abug @var{dev}
14410 ABug ROM monitor for M68K.
14411
14412 @kindex target cpu32bug
14413 @item target cpu32bug @var{dev}
14414 CPU32BUG monitor, running on a CPU32 (M68K) board.
14415
14416 @kindex target dbug
14417 @item target dbug @var{dev}
14418 dBUG ROM monitor for Motorola ColdFire.
14419
14420 @kindex target est
14421 @item target est @var{dev}
14422 EST-300 ICE monitor, running on a CPU32 (M68K) board.
14423
14424 @kindex target rom68k
14425 @item target rom68k @var{dev}
14426 ROM 68K monitor, running on an M68K IDP board.
14427
14428 @end table
14429
14430 @table @code
14431
14432 @kindex target rombug
14433 @item target rombug @var{dev}
14434 ROMBUG ROM monitor for OS/9000.
14435
14436 @end table
14437
14438 @node MIPS Embedded
14439 @subsection MIPS Embedded
14440
14441 @cindex MIPS boards
14442 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
14443 MIPS board attached to a serial line. This is available when
14444 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
14445
14446 @need 1000
14447 Use these @value{GDBN} commands to specify the connection to your target board:
14448
14449 @table @code
14450 @item target mips @var{port}
14451 @kindex target mips @var{port}
14452 To run a program on the board, start up @code{@value{GDBP}} with the
14453 name of your program as the argument. To connect to the board, use the
14454 command @samp{target mips @var{port}}, where @var{port} is the name of
14455 the serial port connected to the board. If the program has not already
14456 been downloaded to the board, you may use the @code{load} command to
14457 download it. You can then use all the usual @value{GDBN} commands.
14458
14459 For example, this sequence connects to the target board through a serial
14460 port, and loads and runs a program called @var{prog} through the
14461 debugger:
14462
14463 @smallexample
14464 host$ @value{GDBP} @var{prog}
14465 @value{GDBN} is free software and @dots{}
14466 (@value{GDBP}) target mips /dev/ttyb
14467 (@value{GDBP}) load @var{prog}
14468 (@value{GDBP}) run
14469 @end smallexample
14470
14471 @item target mips @var{hostname}:@var{portnumber}
14472 On some @value{GDBN} host configurations, you can specify a TCP
14473 connection (for instance, to a serial line managed by a terminal
14474 concentrator) instead of a serial port, using the syntax
14475 @samp{@var{hostname}:@var{portnumber}}.
14476
14477 @item target pmon @var{port}
14478 @kindex target pmon @var{port}
14479 PMON ROM monitor.
14480
14481 @item target ddb @var{port}
14482 @kindex target ddb @var{port}
14483 NEC's DDB variant of PMON for Vr4300.
14484
14485 @item target lsi @var{port}
14486 @kindex target lsi @var{port}
14487 LSI variant of PMON.
14488
14489 @kindex target r3900
14490 @item target r3900 @var{dev}
14491 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
14492
14493 @kindex target array
14494 @item target array @var{dev}
14495 Array Tech LSI33K RAID controller board.
14496
14497 @end table
14498
14499
14500 @noindent
14501 @value{GDBN} also supports these special commands for MIPS targets:
14502
14503 @table @code
14504 @item set mipsfpu double
14505 @itemx set mipsfpu single
14506 @itemx set mipsfpu none
14507 @itemx set mipsfpu auto
14508 @itemx show mipsfpu
14509 @kindex set mipsfpu
14510 @kindex show mipsfpu
14511 @cindex MIPS remote floating point
14512 @cindex floating point, MIPS remote
14513 If your target board does not support the MIPS floating point
14514 coprocessor, you should use the command @samp{set mipsfpu none} (if you
14515 need this, you may wish to put the command in your @value{GDBN} init
14516 file). This tells @value{GDBN} how to find the return value of
14517 functions which return floating point values. It also allows
14518 @value{GDBN} to avoid saving the floating point registers when calling
14519 functions on the board. If you are using a floating point coprocessor
14520 with only single precision floating point support, as on the @sc{r4650}
14521 processor, use the command @samp{set mipsfpu single}. The default
14522 double precision floating point coprocessor may be selected using
14523 @samp{set mipsfpu double}.
14524
14525 In previous versions the only choices were double precision or no
14526 floating point, so @samp{set mipsfpu on} will select double precision
14527 and @samp{set mipsfpu off} will select no floating point.
14528
14529 As usual, you can inquire about the @code{mipsfpu} variable with
14530 @samp{show mipsfpu}.
14531
14532 @item set timeout @var{seconds}
14533 @itemx set retransmit-timeout @var{seconds}
14534 @itemx show timeout
14535 @itemx show retransmit-timeout
14536 @cindex @code{timeout}, MIPS protocol
14537 @cindex @code{retransmit-timeout}, MIPS protocol
14538 @kindex set timeout
14539 @kindex show timeout
14540 @kindex set retransmit-timeout
14541 @kindex show retransmit-timeout
14542 You can control the timeout used while waiting for a packet, in the MIPS
14543 remote protocol, with the @code{set timeout @var{seconds}} command. The
14544 default is 5 seconds. Similarly, you can control the timeout used while
14545 waiting for an acknowledgement of a packet with the @code{set
14546 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14547 You can inspect both values with @code{show timeout} and @code{show
14548 retransmit-timeout}. (These commands are @emph{only} available when
14549 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
14550
14551 The timeout set by @code{set timeout} does not apply when @value{GDBN}
14552 is waiting for your program to stop. In that case, @value{GDBN} waits
14553 forever because it has no way of knowing how long the program is going
14554 to run before stopping.
14555
14556 @item set syn-garbage-limit @var{num}
14557 @kindex set syn-garbage-limit@r{, MIPS remote}
14558 @cindex synchronize with remote MIPS target
14559 Limit the maximum number of characters @value{GDBN} should ignore when
14560 it tries to synchronize with the remote target. The default is 10
14561 characters. Setting the limit to -1 means there's no limit.
14562
14563 @item show syn-garbage-limit
14564 @kindex show syn-garbage-limit@r{, MIPS remote}
14565 Show the current limit on the number of characters to ignore when
14566 trying to synchronize with the remote system.
14567
14568 @item set monitor-prompt @var{prompt}
14569 @kindex set monitor-prompt@r{, MIPS remote}
14570 @cindex remote monitor prompt
14571 Tell @value{GDBN} to expect the specified @var{prompt} string from the
14572 remote monitor. The default depends on the target:
14573 @table @asis
14574 @item pmon target
14575 @samp{PMON}
14576 @item ddb target
14577 @samp{NEC010}
14578 @item lsi target
14579 @samp{PMON>}
14580 @end table
14581
14582 @item show monitor-prompt
14583 @kindex show monitor-prompt@r{, MIPS remote}
14584 Show the current strings @value{GDBN} expects as the prompt from the
14585 remote monitor.
14586
14587 @item set monitor-warnings
14588 @kindex set monitor-warnings@r{, MIPS remote}
14589 Enable or disable monitor warnings about hardware breakpoints. This
14590 has effect only for the @code{lsi} target. When on, @value{GDBN} will
14591 display warning messages whose codes are returned by the @code{lsi}
14592 PMON monitor for breakpoint commands.
14593
14594 @item show monitor-warnings
14595 @kindex show monitor-warnings@r{, MIPS remote}
14596 Show the current setting of printing monitor warnings.
14597
14598 @item pmon @var{command}
14599 @kindex pmon@r{, MIPS remote}
14600 @cindex send PMON command
14601 This command allows sending an arbitrary @var{command} string to the
14602 monitor. The monitor must be in debug mode for this to work.
14603 @end table
14604
14605 @node OpenRISC 1000
14606 @subsection OpenRISC 1000
14607 @cindex OpenRISC 1000
14608
14609 @cindex or1k boards
14610 See OR1k Architecture document (@uref{www.opencores.org}) for more information
14611 about platform and commands.
14612
14613 @table @code
14614
14615 @kindex target jtag
14616 @item target jtag jtag://@var{host}:@var{port}
14617
14618 Connects to remote JTAG server.
14619 JTAG remote server can be either an or1ksim or JTAG server,
14620 connected via parallel port to the board.
14621
14622 Example: @code{target jtag jtag://localhost:9999}
14623
14624 @kindex or1ksim
14625 @item or1ksim @var{command}
14626 If connected to @code{or1ksim} OpenRISC 1000 Architectural
14627 Simulator, proprietary commands can be executed.
14628
14629 @kindex info or1k spr
14630 @item info or1k spr
14631 Displays spr groups.
14632
14633 @item info or1k spr @var{group}
14634 @itemx info or1k spr @var{groupno}
14635 Displays register names in selected group.
14636
14637 @item info or1k spr @var{group} @var{register}
14638 @itemx info or1k spr @var{register}
14639 @itemx info or1k spr @var{groupno} @var{registerno}
14640 @itemx info or1k spr @var{registerno}
14641 Shows information about specified spr register.
14642
14643 @kindex spr
14644 @item spr @var{group} @var{register} @var{value}
14645 @itemx spr @var{register @var{value}}
14646 @itemx spr @var{groupno} @var{registerno @var{value}}
14647 @itemx spr @var{registerno @var{value}}
14648 Writes @var{value} to specified spr register.
14649 @end table
14650
14651 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14652 It is very similar to @value{GDBN} trace, except it does not interfere with normal
14653 program execution and is thus much faster. Hardware breakpoints/watchpoint
14654 triggers can be set using:
14655 @table @code
14656 @item $LEA/$LDATA
14657 Load effective address/data
14658 @item $SEA/$SDATA
14659 Store effective address/data
14660 @item $AEA/$ADATA
14661 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14662 @item $FETCH
14663 Fetch data
14664 @end table
14665
14666 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14667 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14668
14669 @code{htrace} commands:
14670 @cindex OpenRISC 1000 htrace
14671 @table @code
14672 @kindex hwatch
14673 @item hwatch @var{conditional}
14674 Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14675 or Data. For example:
14676
14677 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14678
14679 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14680
14681 @kindex htrace
14682 @item htrace info
14683 Display information about current HW trace configuration.
14684
14685 @item htrace trigger @var{conditional}
14686 Set starting criteria for HW trace.
14687
14688 @item htrace qualifier @var{conditional}
14689 Set acquisition qualifier for HW trace.
14690
14691 @item htrace stop @var{conditional}
14692 Set HW trace stopping criteria.
14693
14694 @item htrace record [@var{data}]*
14695 Selects the data to be recorded, when qualifier is met and HW trace was
14696 triggered.
14697
14698 @item htrace enable
14699 @itemx htrace disable
14700 Enables/disables the HW trace.
14701
14702 @item htrace rewind [@var{filename}]
14703 Clears currently recorded trace data.
14704
14705 If filename is specified, new trace file is made and any newly collected data
14706 will be written there.
14707
14708 @item htrace print [@var{start} [@var{len}]]
14709 Prints trace buffer, using current record configuration.
14710
14711 @item htrace mode continuous
14712 Set continuous trace mode.
14713
14714 @item htrace mode suspend
14715 Set suspend trace mode.
14716
14717 @end table
14718
14719 @node PowerPC
14720 @subsection PowerPC
14721
14722 @table @code
14723 @kindex target dink32
14724 @item target dink32 @var{dev}
14725 DINK32 ROM monitor.
14726
14727 @kindex target ppcbug
14728 @item target ppcbug @var{dev}
14729 @kindex target ppcbug1
14730 @item target ppcbug1 @var{dev}
14731 PPCBUG ROM monitor for PowerPC.
14732
14733 @kindex target sds
14734 @item target sds @var{dev}
14735 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
14736 @end table
14737
14738 @cindex SDS protocol
14739 The following commands specifi to the SDS protocol are supported
14740 by@value{GDBN}:
14741
14742 @table @code
14743 @item set sdstimeout @var{nsec}
14744 @kindex set sdstimeout
14745 Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14746 default is 2 seconds.
14747
14748 @item show sdstimeout
14749 @kindex show sdstimeout
14750 Show the current value of the SDS timeout.
14751
14752 @item sds @var{command}
14753 @kindex sds@r{, a command}
14754 Send the specified @var{command} string to the SDS monitor.
14755 @end table
14756
14757
14758 @node PA
14759 @subsection HP PA Embedded
14760
14761 @table @code
14762
14763 @kindex target op50n
14764 @item target op50n @var{dev}
14765 OP50N monitor, running on an OKI HPPA board.
14766
14767 @kindex target w89k
14768 @item target w89k @var{dev}
14769 W89K monitor, running on a Winbond HPPA board.
14770
14771 @end table
14772
14773 @node SH
14774 @subsection Renesas SH
14775
14776 @table @code
14777
14778 @kindex target hms@r{, with Renesas SH}
14779 @item target hms @var{dev}
14780 A Renesas SH board attached via serial line to your host. Use special
14781 commands @code{device} and @code{speed} to control the serial line and
14782 the communications speed used.
14783
14784 @kindex target e7000@r{, with Renesas SH}
14785 @item target e7000 @var{dev}
14786 E7000 emulator for Renesas SH.
14787
14788 @kindex target sh3@r{, with SH}
14789 @kindex target sh3e@r{, with SH}
14790 @item target sh3 @var{dev}
14791 @item target sh3e @var{dev}
14792 Renesas SH-3 and SH-3E target systems.
14793
14794 @end table
14795
14796 @node Sparclet
14797 @subsection Tsqware Sparclet
14798
14799 @cindex Sparclet
14800
14801 @value{GDBN} enables developers to debug tasks running on
14802 Sparclet targets from a Unix host.
14803 @value{GDBN} uses code that runs on
14804 both the Unix host and on the Sparclet target. The program
14805 @code{@value{GDBP}} is installed and executed on the Unix host.
14806
14807 @table @code
14808 @item remotetimeout @var{args}
14809 @kindex remotetimeout
14810 @value{GDBN} supports the option @code{remotetimeout}.
14811 This option is set by the user, and @var{args} represents the number of
14812 seconds @value{GDBN} waits for responses.
14813 @end table
14814
14815 @cindex compiling, on Sparclet
14816 When compiling for debugging, include the options @samp{-g} to get debug
14817 information and @samp{-Ttext} to relocate the program to where you wish to
14818 load it on the target. You may also want to add the options @samp{-n} or
14819 @samp{-N} in order to reduce the size of the sections. Example:
14820
14821 @smallexample
14822 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
14823 @end smallexample
14824
14825 You can use @code{objdump} to verify that the addresses are what you intended:
14826
14827 @smallexample
14828 sparclet-aout-objdump --headers --syms prog
14829 @end smallexample
14830
14831 @cindex running, on Sparclet
14832 Once you have set
14833 your Unix execution search path to find @value{GDBN}, you are ready to
14834 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14835 (or @code{sparclet-aout-gdb}, depending on your installation).
14836
14837 @value{GDBN} comes up showing the prompt:
14838
14839 @smallexample
14840 (gdbslet)
14841 @end smallexample
14842
14843 @menu
14844 * Sparclet File:: Setting the file to debug
14845 * Sparclet Connection:: Connecting to Sparclet
14846 * Sparclet Download:: Sparclet download
14847 * Sparclet Execution:: Running and debugging
14848 @end menu
14849
14850 @node Sparclet File
14851 @subsubsection Setting file to debug
14852
14853 The @value{GDBN} command @code{file} lets you choose with program to debug.
14854
14855 @smallexample
14856 (gdbslet) file prog
14857 @end smallexample
14858
14859 @need 1000
14860 @value{GDBN} then attempts to read the symbol table of @file{prog}.
14861 @value{GDBN} locates
14862 the file by searching the directories listed in the command search
14863 path.
14864 If the file was compiled with debug information (option "-g"), source
14865 files will be searched as well.
14866 @value{GDBN} locates
14867 the source files by searching the directories listed in the directory search
14868 path (@pxref{Environment, ,Your program's environment}).
14869 If it fails
14870 to find a file, it displays a message such as:
14871
14872 @smallexample
14873 prog: No such file or directory.
14874 @end smallexample
14875
14876 When this happens, add the appropriate directories to the search paths with
14877 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14878 @code{target} command again.
14879
14880 @node Sparclet Connection
14881 @subsubsection Connecting to Sparclet
14882
14883 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14884 To connect to a target on serial port ``@code{ttya}'', type:
14885
14886 @smallexample
14887 (gdbslet) target sparclet /dev/ttya
14888 Remote target sparclet connected to /dev/ttya
14889 main () at ../prog.c:3
14890 @end smallexample
14891
14892 @need 750
14893 @value{GDBN} displays messages like these:
14894
14895 @smallexample
14896 Connected to ttya.
14897 @end smallexample
14898
14899 @node Sparclet Download
14900 @subsubsection Sparclet download
14901
14902 @cindex download to Sparclet
14903 Once connected to the Sparclet target,
14904 you can use the @value{GDBN}
14905 @code{load} command to download the file from the host to the target.
14906 The file name and load offset should be given as arguments to the @code{load}
14907 command.
14908 Since the file format is aout, the program must be loaded to the starting
14909 address. You can use @code{objdump} to find out what this value is. The load
14910 offset is an offset which is added to the VMA (virtual memory address)
14911 of each of the file's sections.
14912 For instance, if the program
14913 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
14914 and bss at 0x12010170, in @value{GDBN}, type:
14915
14916 @smallexample
14917 (gdbslet) load prog 0x12010000
14918 Loading section .text, size 0xdb0 vma 0x12010000
14919 @end smallexample
14920
14921 If the code is loaded at a different address then what the program was linked
14922 to, you may need to use the @code{section} and @code{add-symbol-file} commands
14923 to tell @value{GDBN} where to map the symbol table.
14924
14925 @node Sparclet Execution
14926 @subsubsection Running and debugging
14927
14928 @cindex running and debugging Sparclet programs
14929 You can now begin debugging the task using @value{GDBN}'s execution control
14930 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14931 manual for the list of commands.
14932
14933 @smallexample
14934 (gdbslet) b main
14935 Breakpoint 1 at 0x12010000: file prog.c, line 3.
14936 (gdbslet) run
14937 Starting program: prog
14938 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
14939 3 char *symarg = 0;
14940 (gdbslet) step
14941 4 char *execarg = "hello!";
14942 (gdbslet)
14943 @end smallexample
14944
14945 @node Sparclite
14946 @subsection Fujitsu Sparclite
14947
14948 @table @code
14949
14950 @kindex target sparclite
14951 @item target sparclite @var{dev}
14952 Fujitsu sparclite boards, used only for the purpose of loading.
14953 You must use an additional command to debug the program.
14954 For example: target remote @var{dev} using @value{GDBN} standard
14955 remote protocol.
14956
14957 @end table
14958
14959 @node ST2000
14960 @subsection Tandem ST2000
14961
14962 @value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14963 STDBUG protocol.
14964
14965 To connect your ST2000 to the host system, see the manufacturer's
14966 manual. Once the ST2000 is physically attached, you can run:
14967
14968 @smallexample
14969 target st2000 @var{dev} @var{speed}
14970 @end smallexample
14971
14972 @noindent
14973 to establish it as your debugging environment. @var{dev} is normally
14974 the name of a serial device, such as @file{/dev/ttya}, connected to the
14975 ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14976 connection (for example, to a serial line attached via a terminal
14977 concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
14978
14979 The @code{load} and @code{attach} commands are @emph{not} defined for
14980 this target; you must load your program into the ST2000 as you normally
14981 would for standalone operation. @value{GDBN} reads debugging information
14982 (such as symbols) from a separate, debugging version of the program
14983 available on your host computer.
14984 @c FIXME!! This is terribly vague; what little content is here is
14985 @c basically hearsay.
14986
14987 @cindex ST2000 auxiliary commands
14988 These auxiliary @value{GDBN} commands are available to help you with the ST2000
14989 environment:
14990
14991 @table @code
14992 @item st2000 @var{command}
14993 @kindex st2000 @var{cmd}
14994 @cindex STDBUG commands (ST2000)
14995 @cindex commands to STDBUG (ST2000)
14996 Send a @var{command} to the STDBUG monitor. See the manufacturer's
14997 manual for available commands.
14998
14999 @item connect
15000 @cindex connect (to STDBUG)
15001 Connect the controlling terminal to the STDBUG command monitor. When
15002 you are done interacting with STDBUG, typing either of two character
15003 sequences gets you back to the @value{GDBN} command prompt:
15004 @kbd{@key{RET}~.} (Return, followed by tilde and period) or
15005 @kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
15006 @end table
15007
15008 @node Z8000
15009 @subsection Zilog Z8000
15010
15011 @cindex Z8000
15012 @cindex simulator, Z8000
15013 @cindex Zilog Z8000 simulator
15014
15015 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15016 a Z8000 simulator.
15017
15018 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15019 unsegmented variant of the Z8000 architecture) or the Z8001 (the
15020 segmented variant). The simulator recognizes which architecture is
15021 appropriate by inspecting the object code.
15022
15023 @table @code
15024 @item target sim @var{args}
15025 @kindex sim
15026 @kindex target sim@r{, with Z8000}
15027 Debug programs on a simulated CPU. If the simulator supports setup
15028 options, specify them via @var{args}.
15029 @end table
15030
15031 @noindent
15032 After specifying this target, you can debug programs for the simulated
15033 CPU in the same style as programs for your host computer; use the
15034 @code{file} command to load a new program image, the @code{run} command
15035 to run your program, and so on.
15036
15037 As well as making available all the usual machine registers
15038 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15039 additional items of information as specially named registers:
15040
15041 @table @code
15042
15043 @item cycles
15044 Counts clock-ticks in the simulator.
15045
15046 @item insts
15047 Counts instructions run in the simulator.
15048
15049 @item time
15050 Execution time in 60ths of a second.
15051
15052 @end table
15053
15054 You can refer to these values in @value{GDBN} expressions with the usual
15055 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15056 conditional breakpoint that suspends only after at least 5000
15057 simulated clock ticks.
15058
15059 @node AVR
15060 @subsection Atmel AVR
15061 @cindex AVR
15062
15063 When configured for debugging the Atmel AVR, @value{GDBN} supports the
15064 following AVR-specific commands:
15065
15066 @table @code
15067 @item info io_registers
15068 @kindex info io_registers@r{, AVR}
15069 @cindex I/O registers (Atmel AVR)
15070 This command displays information about the AVR I/O registers. For
15071 each register, @value{GDBN} prints its number and value.
15072 @end table
15073
15074 @node CRIS
15075 @subsection CRIS
15076 @cindex CRIS
15077
15078 When configured for debugging CRIS, @value{GDBN} provides the
15079 following CRIS-specific commands:
15080
15081 @table @code
15082 @item set cris-version @var{ver}
15083 @cindex CRIS version
15084 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15085 The CRIS version affects register names and sizes. This command is useful in
15086 case autodetection of the CRIS version fails.
15087
15088 @item show cris-version
15089 Show the current CRIS version.
15090
15091 @item set cris-dwarf2-cfi
15092 @cindex DWARF-2 CFI and CRIS
15093 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
15094 Change to @samp{off} when using @code{gcc-cris} whose version is below
15095 @code{R59}.
15096
15097 @item show cris-dwarf2-cfi
15098 Show the current state of using DWARF-2 CFI.
15099
15100 @item set cris-mode @var{mode}
15101 @cindex CRIS mode
15102 Set the current CRIS mode to @var{mode}. It should only be changed when
15103 debugging in guru mode, in which case it should be set to
15104 @samp{guru} (the default is @samp{normal}).
15105
15106 @item show cris-mode
15107 Show the current CRIS mode.
15108 @end table
15109
15110 @node Super-H
15111 @subsection Renesas Super-H
15112 @cindex Super-H
15113
15114 For the Renesas Super-H processor, @value{GDBN} provides these
15115 commands:
15116
15117 @table @code
15118 @item regs
15119 @kindex regs@r{, Super-H}
15120 Show the values of all Super-H registers.
15121 @end table
15122
15123 @node WinCE
15124 @subsection Windows CE
15125 @cindex Windows CE
15126
15127 The following commands are available for Windows CE:
15128
15129 @table @code
15130 @item set remotedirectory @var{dir}
15131 @kindex set remotedirectory
15132 Tell @value{GDBN} to upload files from the named directory @var{dir}.
15133 The default is @file{/gdb}, i.e.@: the root directory on the current
15134 drive.
15135
15136 @item show remotedirectory
15137 @kindex show remotedirectory
15138 Show the current value of the upload directory.
15139
15140 @item set remoteupload @var{method}
15141 @kindex set remoteupload
15142 Set the method used to upload files to remote device. Valid values
15143 for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
15144 The default is @samp{newer}.
15145
15146 @item show remoteupload
15147 @kindex show remoteupload
15148 Show the current setting of the upload method.
15149
15150 @item set remoteaddhost
15151 @kindex set remoteaddhost
15152 Tell @value{GDBN} whether to add this host to the remote stub's
15153 arguments when you debug over a network.
15154
15155 @item show remoteaddhost
15156 @kindex show remoteaddhost
15157 Show whether to add this host to remote stub's arguments when
15158 debugging over a network.
15159 @end table
15160
15161
15162 @node Architectures
15163 @section Architectures
15164
15165 This section describes characteristics of architectures that affect
15166 all uses of @value{GDBN} with the architecture, both native and cross.
15167
15168 @menu
15169 * i386::
15170 * A29K::
15171 * Alpha::
15172 * MIPS::
15173 * HPPA:: HP PA architecture
15174 @end menu
15175
15176 @node i386
15177 @subsection x86 Architecture-specific issues.
15178
15179 @table @code
15180 @item set struct-convention @var{mode}
15181 @kindex set struct-convention
15182 @cindex struct return convention
15183 @cindex struct/union returned in registers
15184 Set the convention used by the inferior to return @code{struct}s and
15185 @code{union}s from functions to @var{mode}. Possible values of
15186 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15187 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
15188 are returned on the stack, while @code{"reg"} means that a
15189 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15190 be returned in a register.
15191
15192 @item show struct-convention
15193 @kindex show struct-convention
15194 Show the current setting of the convention to return @code{struct}s
15195 from functions.
15196 @end table
15197
15198 @node A29K
15199 @subsection A29K
15200
15201 @table @code
15202
15203 @kindex set rstack_high_address
15204 @cindex AMD 29K register stack
15205 @cindex register stack, AMD29K
15206 @item set rstack_high_address @var{address}
15207 On AMD 29000 family processors, registers are saved in a separate
15208 @dfn{register stack}. There is no way for @value{GDBN} to determine the
15209 extent of this stack. Normally, @value{GDBN} just assumes that the
15210 stack is ``large enough''. This may result in @value{GDBN} referencing
15211 memory locations that do not exist. If necessary, you can get around
15212 this problem by specifying the ending address of the register stack with
15213 the @code{set rstack_high_address} command. The argument should be an
15214 address, which you probably want to precede with @samp{0x} to specify in
15215 hexadecimal.
15216
15217 @kindex show rstack_high_address
15218 @item show rstack_high_address
15219 Display the current limit of the register stack, on AMD 29000 family
15220 processors.
15221
15222 @end table
15223
15224 @node Alpha
15225 @subsection Alpha
15226
15227 See the following section.
15228
15229 @node MIPS
15230 @subsection MIPS
15231
15232 @cindex stack on Alpha
15233 @cindex stack on MIPS
15234 @cindex Alpha stack
15235 @cindex MIPS stack
15236 Alpha- and MIPS-based computers use an unusual stack frame, which
15237 sometimes requires @value{GDBN} to search backward in the object code to
15238 find the beginning of a function.
15239
15240 @cindex response time, MIPS debugging
15241 To improve response time (especially for embedded applications, where
15242 @value{GDBN} may be restricted to a slow serial line for this search)
15243 you may want to limit the size of this search, using one of these
15244 commands:
15245
15246 @table @code
15247 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
15248 @item set heuristic-fence-post @var{limit}
15249 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15250 search for the beginning of a function. A value of @var{0} (the
15251 default) means there is no limit. However, except for @var{0}, the
15252 larger the limit the more bytes @code{heuristic-fence-post} must search
15253 and therefore the longer it takes to run. You should only need to use
15254 this command when debugging a stripped executable.
15255
15256 @item show heuristic-fence-post
15257 Display the current limit.
15258 @end table
15259
15260 @noindent
15261 These commands are available @emph{only} when @value{GDBN} is configured
15262 for debugging programs on Alpha or MIPS processors.
15263
15264 Several MIPS-specific commands are available when debugging MIPS
15265 programs:
15266
15267 @table @code
15268 @item set mips saved-gpreg-size @var{size}
15269 @kindex set mips saved-gpreg-size
15270 @cindex MIPS GP register size on stack
15271 Set the size of MIPS general-purpose registers saved on the stack.
15272 The argument @var{size} can be one of the following:
15273
15274 @table @samp
15275 @item 32
15276 32-bit GP registers
15277 @item 64
15278 64-bit GP registers
15279 @item auto
15280 Use the target's default setting or autodetect the saved size from the
15281 information contained in the executable. This is the default
15282 @end table
15283
15284 @item show mips saved-gpreg-size
15285 @kindex show mips saved-gpreg-size
15286 Show the current size of MIPS GP registers on the stack.
15287
15288 @item set mips stack-arg-size @var{size}
15289 @kindex set mips stack-arg-size
15290 @cindex MIPS stack space for arguments
15291 Set the amount of stack space reserved for arguments to functions.
15292 The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
15293 (the default).
15294
15295 @item set mips abi @var{arg}
15296 @kindex set mips abi
15297 @cindex set ABI for MIPS
15298 Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
15299 values of @var{arg} are:
15300
15301 @table @samp
15302 @item auto
15303 The default ABI associated with the current binary (this is the
15304 default).
15305 @item o32
15306 @item o64
15307 @item n32
15308 @item n64
15309 @item eabi32
15310 @item eabi64
15311 @item auto
15312 @end table
15313
15314 @item show mips abi
15315 @kindex show mips abi
15316 Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15317
15318 @item set mipsfpu
15319 @itemx show mipsfpu
15320 @xref{MIPS Embedded, set mipsfpu}.
15321
15322 @item set mips mask-address @var{arg}
15323 @kindex set mips mask-address
15324 @cindex MIPS addresses, masking
15325 This command determines whether the most-significant 32 bits of 64-bit
15326 MIPS addresses are masked off. The argument @var{arg} can be
15327 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
15328 setting, which lets @value{GDBN} determine the correct value.
15329
15330 @item show mips mask-address
15331 @kindex show mips mask-address
15332 Show whether the upper 32 bits of MIPS addresses are masked off or
15333 not.
15334
15335 @item set remote-mips64-transfers-32bit-regs
15336 @kindex set remote-mips64-transfers-32bit-regs
15337 This command controls compatibility with 64-bit MIPS targets that
15338 transfer data in 32-bit quantities. If you have an old MIPS 64 target
15339 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15340 and 64 bits for other registers, set this option to @samp{on}.
15341
15342 @item show remote-mips64-transfers-32bit-regs
15343 @kindex show remote-mips64-transfers-32bit-regs
15344 Show the current setting of compatibility with older MIPS 64 targets.
15345
15346 @item set debug mips
15347 @kindex set debug mips
15348 This command turns on and off debugging messages for the MIPS-specific
15349 target code in @value{GDBN}.
15350
15351 @item show debug mips
15352 @kindex show debug mips
15353 Show the current setting of MIPS debugging messages.
15354 @end table
15355
15356
15357 @node HPPA
15358 @subsection HPPA
15359 @cindex HPPA support
15360
15361 When @value{GDBN} is debugging te HP PA architecture, it provides the
15362 following special commands:
15363
15364 @table @code
15365 @item set debug hppa
15366 @kindex set debug hppa
15367 THis command determines whether HPPA architecture specific debugging
15368 messages are to be displayed.
15369
15370 @item show debug hppa
15371 Show whether HPPA debugging messages are displayed.
15372
15373 @item maint print unwind @var{address}
15374 @kindex maint print unwind@r{, HPPA}
15375 This command displays the contents of the unwind table entry at the
15376 given @var{address}.
15377
15378 @end table
15379
15380
15381 @node Controlling GDB
15382 @chapter Controlling @value{GDBN}
15383
15384 You can alter the way @value{GDBN} interacts with you by using the
15385 @code{set} command. For commands controlling how @value{GDBN} displays
15386 data, see @ref{Print Settings, ,Print settings}. Other settings are
15387 described here.
15388
15389 @menu
15390 * Prompt:: Prompt
15391 * Editing:: Command editing
15392 * Command History:: Command history
15393 * Screen Size:: Screen size
15394 * Numbers:: Numbers
15395 * ABI:: Configuring the current ABI
15396 * Messages/Warnings:: Optional warnings and messages
15397 * Debugging Output:: Optional messages about internal happenings
15398 @end menu
15399
15400 @node Prompt
15401 @section Prompt
15402
15403 @cindex prompt
15404
15405 @value{GDBN} indicates its readiness to read a command by printing a string
15406 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15407 can change the prompt string with the @code{set prompt} command. For
15408 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15409 the prompt in one of the @value{GDBN} sessions so that you can always tell
15410 which one you are talking to.
15411
15412 @emph{Note:} @code{set prompt} does not add a space for you after the
15413 prompt you set. This allows you to set a prompt which ends in a space
15414 or a prompt that does not.
15415
15416 @table @code
15417 @kindex set prompt
15418 @item set prompt @var{newprompt}
15419 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
15420
15421 @kindex show prompt
15422 @item show prompt
15423 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
15424 @end table
15425
15426 @node Editing
15427 @section Command editing
15428 @cindex readline
15429 @cindex command line editing
15430
15431 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
15432 @sc{gnu} library provides consistent behavior for programs which provide a
15433 command line interface to the user. Advantages are @sc{gnu} Emacs-style
15434 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15435 substitution, and a storage and recall of command history across
15436 debugging sessions.
15437
15438 You may control the behavior of command line editing in @value{GDBN} with the
15439 command @code{set}.
15440
15441 @table @code
15442 @kindex set editing
15443 @cindex editing
15444 @item set editing
15445 @itemx set editing on
15446 Enable command line editing (enabled by default).
15447
15448 @item set editing off
15449 Disable command line editing.
15450
15451 @kindex show editing
15452 @item show editing
15453 Show whether command line editing is enabled.
15454 @end table
15455
15456 @xref{Command Line Editing}, for more details about the Readline
15457 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15458 encouraged to read that chapter.
15459
15460 @node Command History
15461 @section Command history
15462 @cindex command history
15463
15464 @value{GDBN} can keep track of the commands you type during your
15465 debugging sessions, so that you can be certain of precisely what
15466 happened. Use these commands to manage the @value{GDBN} command
15467 history facility.
15468
15469 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15470 package, to provide the history facility. @xref{Using History
15471 Interactively}, for the detailed description of the History library.
15472
15473 To issue a command to @value{GDBN} without affecting certain aspects of
15474 the state which is seen by users, prefix it with @samp{server }. This
15475 means that this command will not affect the command history, nor will it
15476 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15477 pressed on a line by itself.
15478
15479 @cindex @code{server}, command prefix
15480 The server prefix does not affect the recording of values into the value
15481 history; to print a value without recording it into the value history,
15482 use the @code{output} command instead of the @code{print} command.
15483
15484 Here is the description of @value{GDBN} commands related to command
15485 history.
15486
15487 @table @code
15488 @cindex history substitution
15489 @cindex history file
15490 @kindex set history filename
15491 @cindex @env{GDBHISTFILE}, environment variable
15492 @item set history filename @var{fname}
15493 Set the name of the @value{GDBN} command history file to @var{fname}.
15494 This is the file where @value{GDBN} reads an initial command history
15495 list, and where it writes the command history from this session when it
15496 exits. You can access this list through history expansion or through
15497 the history command editing characters listed below. This file defaults
15498 to the value of the environment variable @code{GDBHISTFILE}, or to
15499 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15500 is not set.
15501
15502 @cindex save command history
15503 @kindex set history save
15504 @item set history save
15505 @itemx set history save on
15506 Record command history in a file, whose name may be specified with the
15507 @code{set history filename} command. By default, this option is disabled.
15508
15509 @item set history save off
15510 Stop recording command history in a file.
15511
15512 @cindex history size
15513 @kindex set history size
15514 @cindex @env{HISTSIZE}, environment variable
15515 @item set history size @var{size}
15516 Set the number of commands which @value{GDBN} keeps in its history list.
15517 This defaults to the value of the environment variable
15518 @code{HISTSIZE}, or to 256 if this variable is not set.
15519 @end table
15520
15521 History expansion assigns special meaning to the character @kbd{!}.
15522 @xref{Event Designators}, for more details.
15523
15524 @cindex history expansion, turn on/off
15525 Since @kbd{!} is also the logical not operator in C, history expansion
15526 is off by default. If you decide to enable history expansion with the
15527 @code{set history expansion on} command, you may sometimes need to
15528 follow @kbd{!} (when it is used as logical not, in an expression) with
15529 a space or a tab to prevent it from being expanded. The readline
15530 history facilities do not attempt substitution on the strings
15531 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15532
15533 The commands to control history expansion are:
15534
15535 @table @code
15536 @item set history expansion on
15537 @itemx set history expansion
15538 @kindex set history expansion
15539 Enable history expansion. History expansion is off by default.
15540
15541 @item set history expansion off
15542 Disable history expansion.
15543
15544 @c @group
15545 @kindex show history
15546 @item show history
15547 @itemx show history filename
15548 @itemx show history save
15549 @itemx show history size
15550 @itemx show history expansion
15551 These commands display the state of the @value{GDBN} history parameters.
15552 @code{show history} by itself displays all four states.
15553 @c @end group
15554 @end table
15555
15556 @table @code
15557 @kindex show commands
15558 @cindex show last commands
15559 @cindex display command history
15560 @item show commands
15561 Display the last ten commands in the command history.
15562
15563 @item show commands @var{n}
15564 Print ten commands centered on command number @var{n}.
15565
15566 @item show commands +
15567 Print ten commands just after the commands last printed.
15568 @end table
15569
15570 @node Screen Size
15571 @section Screen size
15572 @cindex size of screen
15573 @cindex pauses in output
15574
15575 Certain commands to @value{GDBN} may produce large amounts of
15576 information output to the screen. To help you read all of it,
15577 @value{GDBN} pauses and asks you for input at the end of each page of
15578 output. Type @key{RET} when you want to continue the output, or @kbd{q}
15579 to discard the remaining output. Also, the screen width setting
15580 determines when to wrap lines of output. Depending on what is being
15581 printed, @value{GDBN} tries to break the line at a readable place,
15582 rather than simply letting it overflow onto the following line.
15583
15584 Normally @value{GDBN} knows the size of the screen from the terminal
15585 driver software. For example, on Unix @value{GDBN} uses the termcap data base
15586 together with the value of the @code{TERM} environment variable and the
15587 @code{stty rows} and @code{stty cols} settings. If this is not correct,
15588 you can override it with the @code{set height} and @code{set
15589 width} commands:
15590
15591 @table @code
15592 @kindex set height
15593 @kindex set width
15594 @kindex show width
15595 @kindex show height
15596 @item set height @var{lpp}
15597 @itemx show height
15598 @itemx set width @var{cpl}
15599 @itemx show width
15600 These @code{set} commands specify a screen height of @var{lpp} lines and
15601 a screen width of @var{cpl} characters. The associated @code{show}
15602 commands display the current settings.
15603
15604 If you specify a height of zero lines, @value{GDBN} does not pause during
15605 output no matter how long the output is. This is useful if output is to a
15606 file or to an editor buffer.
15607
15608 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15609 from wrapping its output.
15610
15611 @item set pagination on
15612 @itemx set pagination off
15613 @kindex set pagination
15614 Turn the output pagination on or off; the default is on. Turning
15615 pagination off is the alternative to @code{set height 0}.
15616
15617 @item show pagination
15618 @kindex show pagination
15619 Show the current pagination mode.
15620 @end table
15621
15622 @node Numbers
15623 @section Numbers
15624 @cindex number representation
15625 @cindex entering numbers
15626
15627 You can always enter numbers in octal, decimal, or hexadecimal in
15628 @value{GDBN} by the usual conventions: octal numbers begin with
15629 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
15630 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15631 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
15632 10; likewise, the default display for numbers---when no particular
15633 format is specified---is base 10. You can change the default base for
15634 both input and output with the commands described below.
15635
15636 @table @code
15637 @kindex set input-radix
15638 @item set input-radix @var{base}
15639 Set the default base for numeric input. Supported choices
15640 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
15641 specified either unambiguously or using the current input radix; for
15642 example, any of
15643
15644 @smallexample
15645 set input-radix 012
15646 set input-radix 10.
15647 set input-radix 0xa
15648 @end smallexample
15649
15650 @noindent
15651 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
15652 leaves the input radix unchanged, no matter what it was, since
15653 @samp{10}, being without any leading or trailing signs of its base, is
15654 interpreted in the current radix. Thus, if the current radix is 16,
15655 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15656 change the radix.
15657
15658 @kindex set output-radix
15659 @item set output-radix @var{base}
15660 Set the default base for numeric display. Supported choices
15661 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
15662 specified either unambiguously or using the current input radix.
15663
15664 @kindex show input-radix
15665 @item show input-radix
15666 Display the current default base for numeric input.
15667
15668 @kindex show output-radix
15669 @item show output-radix
15670 Display the current default base for numeric display.
15671
15672 @item set radix @r{[}@var{base}@r{]}
15673 @itemx show radix
15674 @kindex set radix
15675 @kindex show radix
15676 These commands set and show the default base for both input and output
15677 of numbers. @code{set radix} sets the radix of input and output to
15678 the same base; without an argument, it resets the radix back to its
15679 default value of 10.
15680
15681 @end table
15682
15683 @node ABI
15684 @section Configuring the current ABI
15685
15686 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15687 application automatically. However, sometimes you need to override its
15688 conclusions. Use these commands to manage @value{GDBN}'s view of the
15689 current ABI.
15690
15691 @cindex OS ABI
15692 @kindex set osabi
15693 @kindex show osabi
15694
15695 One @value{GDBN} configuration can debug binaries for multiple operating
15696 system targets, either via remote debugging or native emulation.
15697 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15698 but you can override its conclusion using the @code{set osabi} command.
15699 One example where this is useful is in debugging of binaries which use
15700 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15701 not have the same identifying marks that the standard C library for your
15702 platform provides.
15703
15704 @table @code
15705 @item show osabi
15706 Show the OS ABI currently in use.
15707
15708 @item set osabi
15709 With no argument, show the list of registered available OS ABI's.
15710
15711 @item set osabi @var{abi}
15712 Set the current OS ABI to @var{abi}.
15713 @end table
15714
15715 @cindex float promotion
15716
15717 Generally, the way that an argument of type @code{float} is passed to a
15718 function depends on whether the function is prototyped. For a prototyped
15719 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15720 according to the architecture's convention for @code{float}. For unprototyped
15721 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15722 @code{double} and then passed.
15723
15724 Unfortunately, some forms of debug information do not reliably indicate whether
15725 a function is prototyped. If @value{GDBN} calls a function that is not marked
15726 as prototyped, it consults @kbd{set coerce-float-to-double}.
15727
15728 @table @code
15729 @kindex set coerce-float-to-double
15730 @item set coerce-float-to-double
15731 @itemx set coerce-float-to-double on
15732 Arguments of type @code{float} will be promoted to @code{double} when passed
15733 to an unprototyped function. This is the default setting.
15734
15735 @item set coerce-float-to-double off
15736 Arguments of type @code{float} will be passed directly to unprototyped
15737 functions.
15738
15739 @kindex show coerce-float-to-double
15740 @item show coerce-float-to-double
15741 Show the current setting of promoting @code{float} to @code{double}.
15742 @end table
15743
15744 @kindex set cp-abi
15745 @kindex show cp-abi
15746 @value{GDBN} needs to know the ABI used for your program's C@t{++}
15747 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15748 used to build your application. @value{GDBN} only fully supports
15749 programs with a single C@t{++} ABI; if your program contains code using
15750 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15751 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15752 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15753 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15754 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15755 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15756 ``auto''.
15757
15758 @table @code
15759 @item show cp-abi
15760 Show the C@t{++} ABI currently in use.
15761
15762 @item set cp-abi
15763 With no argument, show the list of supported C@t{++} ABI's.
15764
15765 @item set cp-abi @var{abi}
15766 @itemx set cp-abi auto
15767 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15768 @end table
15769
15770 @node Messages/Warnings
15771 @section Optional warnings and messages
15772
15773 @cindex verbose operation
15774 @cindex optional warnings
15775 By default, @value{GDBN} is silent about its inner workings. If you are
15776 running on a slow machine, you may want to use the @code{set verbose}
15777 command. This makes @value{GDBN} tell you when it does a lengthy
15778 internal operation, so you will not think it has crashed.
15779
15780 Currently, the messages controlled by @code{set verbose} are those
15781 which announce that the symbol table for a source file is being read;
15782 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
15783
15784 @table @code
15785 @kindex set verbose
15786 @item set verbose on
15787 Enables @value{GDBN} output of certain informational messages.
15788
15789 @item set verbose off
15790 Disables @value{GDBN} output of certain informational messages.
15791
15792 @kindex show verbose
15793 @item show verbose
15794 Displays whether @code{set verbose} is on or off.
15795 @end table
15796
15797 By default, if @value{GDBN} encounters bugs in the symbol table of an
15798 object file, it is silent; but if you are debugging a compiler, you may
15799 find this information useful (@pxref{Symbol Errors, ,Errors reading
15800 symbol files}).
15801
15802 @table @code
15803
15804 @kindex set complaints
15805 @item set complaints @var{limit}
15806 Permits @value{GDBN} to output @var{limit} complaints about each type of
15807 unusual symbols before becoming silent about the problem. Set
15808 @var{limit} to zero to suppress all complaints; set it to a large number
15809 to prevent complaints from being suppressed.
15810
15811 @kindex show complaints
15812 @item show complaints
15813 Displays how many symbol complaints @value{GDBN} is permitted to produce.
15814
15815 @end table
15816
15817 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15818 lot of stupid questions to confirm certain commands. For example, if
15819 you try to run a program which is already running:
15820
15821 @smallexample
15822 (@value{GDBP}) run
15823 The program being debugged has been started already.
15824 Start it from the beginning? (y or n)
15825 @end smallexample
15826
15827 If you are willing to unflinchingly face the consequences of your own
15828 commands, you can disable this ``feature'':
15829
15830 @table @code
15831
15832 @kindex set confirm
15833 @cindex flinching
15834 @cindex confirmation
15835 @cindex stupid questions
15836 @item set confirm off
15837 Disables confirmation requests.
15838
15839 @item set confirm on
15840 Enables confirmation requests (the default).
15841
15842 @kindex show confirm
15843 @item show confirm
15844 Displays state of confirmation requests.
15845
15846 @end table
15847
15848 @node Debugging Output
15849 @section Optional messages about internal happenings
15850 @cindex optional debugging messages
15851
15852 @value{GDBN} has commands that enable optional debugging messages from
15853 various @value{GDBN} subsystems; normally these commands are of
15854 interest to @value{GDBN} maintainers, or when reporting a bug. This
15855 section documents those commands.
15856
15857 @table @code
15858 @kindex set exec-done-display
15859 @item set exec-done-display
15860 Turns on or off the notification of asynchronous commands'
15861 completion. When on, @value{GDBN} will print a message when an
15862 asynchronous command finishes its execution. The default is off.
15863 @kindex show exec-done-display
15864 @item show exec-done-display
15865 Displays the current setting of asynchronous command completion
15866 notification.
15867 @kindex set debug
15868 @cindex gdbarch debugging info
15869 @cindex architecture debugging info
15870 @item set debug arch
15871 Turns on or off display of gdbarch debugging info. The default is off
15872 @kindex show debug
15873 @item show debug arch
15874 Displays the current state of displaying gdbarch debugging info.
15875 @item set debug aix-thread
15876 @cindex AIX threads
15877 Display debugging messages about inner workings of the AIX thread
15878 module.
15879 @item show debug aix-thread
15880 Show the current state of AIX thread debugging info display.
15881 @item set debug event
15882 @cindex event debugging info
15883 Turns on or off display of @value{GDBN} event debugging info. The
15884 default is off.
15885 @item show debug event
15886 Displays the current state of displaying @value{GDBN} event debugging
15887 info.
15888 @item set debug expression
15889 @cindex expression debugging info
15890 Turns on or off display of debugging info about @value{GDBN}
15891 expression parsing. The default is off.
15892 @item show debug expression
15893 Displays the current state of displaying debugging info about
15894 @value{GDBN} expression parsing.
15895 @item set debug frame
15896 @cindex frame debugging info
15897 Turns on or off display of @value{GDBN} frame debugging info. The
15898 default is off.
15899 @item show debug frame
15900 Displays the current state of displaying @value{GDBN} frame debugging
15901 info.
15902 @item set debug infrun
15903 @cindex inferior debugging info
15904 Turns on or off display of @value{GDBN} debugging info for running the inferior.
15905 The default is off. @file{infrun.c} contains GDB's runtime state machine used
15906 for implementing operations such as single-stepping the inferior.
15907 @item show debug infrun
15908 Displays the current state of @value{GDBN} inferior debugging.
15909 @item set debug lin-lwp
15910 @cindex @sc{gnu}/Linux LWP debug messages
15911 @cindex Linux lightweight processes
15912 Turns on or off debugging messages from the Linux LWP debug support.
15913 @item show debug lin-lwp
15914 Show the current state of Linux LWP debugging messages.
15915 @item set debug observer
15916 @cindex observer debugging info
15917 Turns on or off display of @value{GDBN} observer debugging. This
15918 includes info such as the notification of observable events.
15919 @item show debug observer
15920 Displays the current state of observer debugging.
15921 @item set debug overload
15922 @cindex C@t{++} overload debugging info
15923 Turns on or off display of @value{GDBN} C@t{++} overload debugging
15924 info. This includes info such as ranking of functions, etc. The default
15925 is off.
15926 @item show debug overload
15927 Displays the current state of displaying @value{GDBN} C@t{++} overload
15928 debugging info.
15929 @cindex packets, reporting on stdout
15930 @cindex serial connections, debugging
15931 @item set debug remote
15932 Turns on or off display of reports on all packets sent back and forth across
15933 the serial line to the remote machine. The info is printed on the
15934 @value{GDBN} standard output stream. The default is off.
15935 @item show debug remote
15936 Displays the state of display of remote packets.
15937 @item set debug serial
15938 Turns on or off display of @value{GDBN} serial debugging info. The
15939 default is off.
15940 @item show debug serial
15941 Displays the current state of displaying @value{GDBN} serial debugging
15942 info.
15943 @item set debug solib-frv
15944 @cindex FR-V shared-library debugging
15945 Turns on or off debugging messages for FR-V shared-library code.
15946 @item show debug solib-frv
15947 Display the current state of FR-V shared-library code debugging
15948 messages.
15949 @item set debug target
15950 @cindex target debugging info
15951 Turns on or off display of @value{GDBN} target debugging info. This info
15952 includes what is going on at the target level of GDB, as it happens. The
15953 default is 0. Set it to 1 to track events, and to 2 to also track the
15954 value of large memory transfers. Changes to this flag do not take effect
15955 until the next time you connect to a target or use the @code{run} command.
15956 @item show debug target
15957 Displays the current state of displaying @value{GDBN} target debugging
15958 info.
15959 @item set debugvarobj
15960 @cindex variable object debugging info
15961 Turns on or off display of @value{GDBN} variable object debugging
15962 info. The default is off.
15963 @item show debugvarobj
15964 Displays the current state of displaying @value{GDBN} variable object
15965 debugging info.
15966 @end table
15967
15968 @node Sequences
15969 @chapter Canned Sequences of Commands
15970
15971 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15972 command lists}), @value{GDBN} provides two ways to store sequences of
15973 commands for execution as a unit: user-defined commands and command
15974 files.
15975
15976 @menu
15977 * Define:: How to define your own commands
15978 * Hooks:: Hooks for user-defined commands
15979 * Command Files:: How to write scripts of commands to be stored in a file
15980 * Output:: Commands for controlled output
15981 @end menu
15982
15983 @node Define
15984 @section User-defined commands
15985
15986 @cindex user-defined command
15987 @cindex arguments, to user-defined commands
15988 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15989 which you assign a new name as a command. This is done with the
15990 @code{define} command. User commands may accept up to 10 arguments
15991 separated by whitespace. Arguments are accessed within the user command
15992 via @code{$arg0@dots{}$arg9}. A trivial example:
15993
15994 @smallexample
15995 define adder
15996 print $arg0 + $arg1 + $arg2
15997 end
15998 @end smallexample
15999
16000 @noindent
16001 To execute the command use:
16002
16003 @smallexample
16004 adder 1 2 3
16005 @end smallexample
16006
16007 @noindent
16008 This defines the command @code{adder}, which prints the sum of
16009 its three arguments. Note the arguments are text substitutions, so they may
16010 reference variables, use complex expressions, or even perform inferior
16011 functions calls.
16012
16013 @cindex argument count in user-defined commands
16014 @cindex how many arguments (user-defined commands)
16015 In addition, @code{$argc} may be used to find out how many arguments have
16016 been passed. This expands to a number in the range 0@dots{}10.
16017
16018 @smallexample
16019 define adder
16020 if $argc == 2
16021 print $arg0 + $arg1
16022 end
16023 if $argc == 3
16024 print $arg0 + $arg1 + $arg2
16025 end
16026 end
16027 @end smallexample
16028
16029 @table @code
16030
16031 @kindex define
16032 @item define @var{commandname}
16033 Define a command named @var{commandname}. If there is already a command
16034 by that name, you are asked to confirm that you want to redefine it.
16035
16036 The definition of the command is made up of other @value{GDBN} command lines,
16037 which are given following the @code{define} command. The end of these
16038 commands is marked by a line containing @code{end}.
16039
16040 @kindex document
16041 @kindex end@r{ (user-defined commands)}
16042 @item document @var{commandname}
16043 Document the user-defined command @var{commandname}, so that it can be
16044 accessed by @code{help}. The command @var{commandname} must already be
16045 defined. This command reads lines of documentation just as @code{define}
16046 reads the lines of the command definition, ending with @code{end}.
16047 After the @code{document} command is finished, @code{help} on command
16048 @var{commandname} displays the documentation you have written.
16049
16050 You may use the @code{document} command again to change the
16051 documentation of a command. Redefining the command with @code{define}
16052 does not change the documentation.
16053
16054 @kindex dont-repeat
16055 @cindex don't repeat command
16056 @item dont-repeat
16057 Used inside a user-defined command, this tells @value{GDBN} that this
16058 command should not be repeated when the user hits @key{RET}
16059 (@pxref{Command Syntax, repeat last command}).
16060
16061 @kindex help user-defined
16062 @item help user-defined
16063 List all user-defined commands, with the first line of the documentation
16064 (if any) for each.
16065
16066 @kindex show user
16067 @item show user
16068 @itemx show user @var{commandname}
16069 Display the @value{GDBN} commands used to define @var{commandname} (but
16070 not its documentation). If no @var{commandname} is given, display the
16071 definitions for all user-defined commands.
16072
16073 @cindex infinite recursion in user-defined commands
16074 @kindex show max-user-call-depth
16075 @kindex set max-user-call-depth
16076 @item show max-user-call-depth
16077 @itemx set max-user-call-depth
16078 The value of @code{max-user-call-depth} controls how many recursion
16079 levels are allowed in user-defined commands before GDB suspects an
16080 infinite recursion and aborts the command.
16081 @end table
16082
16083 In addition to the above commands, user-defined commands frequently
16084 use control flow commands, described in @ref{Command Files}.
16085
16086 When user-defined commands are executed, the
16087 commands of the definition are not printed. An error in any command
16088 stops execution of the user-defined command.
16089
16090 If used interactively, commands that would ask for confirmation proceed
16091 without asking when used inside a user-defined command. Many @value{GDBN}
16092 commands that normally print messages to say what they are doing omit the
16093 messages when used in a user-defined command.
16094
16095 @node Hooks
16096 @section User-defined command hooks
16097 @cindex command hooks
16098 @cindex hooks, for commands
16099 @cindex hooks, pre-command
16100
16101 @kindex hook
16102 You may define @dfn{hooks}, which are a special kind of user-defined
16103 command. Whenever you run the command @samp{foo}, if the user-defined
16104 command @samp{hook-foo} exists, it is executed (with no arguments)
16105 before that command.
16106
16107 @cindex hooks, post-command
16108 @kindex hookpost
16109 A hook may also be defined which is run after the command you executed.
16110 Whenever you run the command @samp{foo}, if the user-defined command
16111 @samp{hookpost-foo} exists, it is executed (with no arguments) after
16112 that command. Post-execution hooks may exist simultaneously with
16113 pre-execution hooks, for the same command.
16114
16115 It is valid for a hook to call the command which it hooks. If this
16116 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
16117
16118 @c It would be nice if hookpost could be passed a parameter indicating
16119 @c if the command it hooks executed properly or not. FIXME!
16120
16121 @kindex stop@r{, a pseudo-command}
16122 In addition, a pseudo-command, @samp{stop} exists. Defining
16123 (@samp{hook-stop}) makes the associated commands execute every time
16124 execution stops in your program: before breakpoint commands are run,
16125 displays are printed, or the stack frame is printed.
16126
16127 For example, to ignore @code{SIGALRM} signals while
16128 single-stepping, but treat them normally during normal execution,
16129 you could define:
16130
16131 @smallexample
16132 define hook-stop
16133 handle SIGALRM nopass
16134 end
16135
16136 define hook-run
16137 handle SIGALRM pass
16138 end
16139
16140 define hook-continue
16141 handle SIGLARM pass
16142 end
16143 @end smallexample
16144
16145 As a further example, to hook at the begining and end of the @code{echo}
16146 command, and to add extra text to the beginning and end of the message,
16147 you could define:
16148
16149 @smallexample
16150 define hook-echo
16151 echo <<<---
16152 end
16153
16154 define hookpost-echo
16155 echo --->>>\n
16156 end
16157
16158 (@value{GDBP}) echo Hello World
16159 <<<---Hello World--->>>
16160 (@value{GDBP})
16161
16162 @end smallexample
16163
16164 You can define a hook for any single-word command in @value{GDBN}, but
16165 not for command aliases; you should define a hook for the basic command
16166 name, e.g.@: @code{backtrace} rather than @code{bt}.
16167 @c FIXME! So how does Joe User discover whether a command is an alias
16168 @c or not?
16169 If an error occurs during the execution of your hook, execution of
16170 @value{GDBN} commands stops and @value{GDBN} issues a prompt
16171 (before the command that you actually typed had a chance to run).
16172
16173 If you try to define a hook which does not match any known command, you
16174 get a warning from the @code{define} command.
16175
16176 @node Command Files
16177 @section Command files
16178
16179 @cindex command files
16180 @cindex scripting commands
16181 A command file for @value{GDBN} is a text file made of lines that are
16182 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
16183 also be included. An empty line in a command file does nothing; it
16184 does not mean to repeat the last command, as it would from the
16185 terminal.
16186
16187 You can request the execution of a command file with the @code{source}
16188 command:
16189
16190 @table @code
16191 @kindex source
16192 @cindex execute commands from a file
16193 @item source @var{filename}
16194 Execute the command file @var{filename}.
16195 @end table
16196
16197 The lines in a command file are generally executed sequentially,
16198 unless the order of execution is changed by one of the
16199 @emph{flow-control commands} described below. The commands are not
16200 printed as they are executed. An error in any command terminates
16201 execution of the command file and control is returned to the console.
16202
16203 Commands that would ask for confirmation if used interactively proceed
16204 without asking when used in a command file. Many @value{GDBN} commands that
16205 normally print messages to say what they are doing omit the messages
16206 when called from command files.
16207
16208 @value{GDBN} also accepts command input from standard input. In this
16209 mode, normal output goes to standard output and error output goes to
16210 standard error. Errors in a command file supplied on standard input do
16211 not terminate execution of the command file---execution continues with
16212 the next command.
16213
16214 @smallexample
16215 gdb < cmds > log 2>&1
16216 @end smallexample
16217
16218 (The syntax above will vary depending on the shell used.) This example
16219 will execute commands from the file @file{cmds}. All output and errors
16220 would be directed to @file{log}.
16221
16222 Since commands stored on command files tend to be more general than
16223 commands typed interactively, they frequently need to deal with
16224 complicated situations, such as different or unexpected values of
16225 variables and symbols, changes in how the program being debugged is
16226 built, etc. @value{GDBN} provides a set of flow-control commands to
16227 deal with these complexities. Using these commands, you can write
16228 complex scripts that loop over data structures, execute commands
16229 conditionally, etc.
16230
16231 @table @code
16232 @kindex if
16233 @kindex else
16234 @item if
16235 @itemx else
16236 This command allows to include in your script conditionally executed
16237 commands. The @code{if} command takes a single argument, which is an
16238 expression to evaluate. It is followed by a series of commands that
16239 are executed only if the expression is true (its value is nonzero).
16240 There can then optionally be an @code{else} line, followed by a series
16241 of commands that are only executed if the expression was false. The
16242 end of the list is marked by a line containing @code{end}.
16243
16244 @kindex while
16245 @item while
16246 This command allows to write loops. Its syntax is similar to
16247 @code{if}: the command takes a single argument, which is an expression
16248 to evaluate, and must be followed by the commands to execute, one per
16249 line, terminated by an @code{end}. These commands are called the
16250 @dfn{body} of the loop. The commands in the body of @code{while} are
16251 executed repeatedly as long as the expression evaluates to true.
16252
16253 @kindex loop_break
16254 @item loop_break
16255 This command exits the @code{while} loop in whose body it is included.
16256 Execution of the script continues after that @code{while}s @code{end}
16257 line.
16258
16259 @kindex loop_continue
16260 @item loop_continue
16261 This command skips the execution of the rest of the body of commands
16262 in the @code{while} loop in whose body it is included. Execution
16263 branches to the beginning of the @code{while} loop, where it evaluates
16264 the controlling expression.
16265
16266 @kindex end@r{ (if/else/while commands)}
16267 @item end
16268 Terminate the block of commands that are the body of @code{if},
16269 @code{else}, or @code{while} flow-control commands.
16270 @end table
16271
16272
16273 @node Output
16274 @section Commands for controlled output
16275
16276 During the execution of a command file or a user-defined command, normal
16277 @value{GDBN} output is suppressed; the only output that appears is what is
16278 explicitly printed by the commands in the definition. This section
16279 describes three commands useful for generating exactly the output you
16280 want.
16281
16282 @table @code
16283 @kindex echo
16284 @item echo @var{text}
16285 @c I do not consider backslash-space a standard C escape sequence
16286 @c because it is not in ANSI.
16287 Print @var{text}. Nonprinting characters can be included in
16288 @var{text} using C escape sequences, such as @samp{\n} to print a
16289 newline. @strong{No newline is printed unless you specify one.}
16290 In addition to the standard C escape sequences, a backslash followed
16291 by a space stands for a space. This is useful for displaying a
16292 string with spaces at the beginning or the end, since leading and
16293 trailing spaces are otherwise trimmed from all arguments.
16294 To print @samp{@w{ }and foo =@w{ }}, use the command
16295 @samp{echo \@w{ }and foo = \@w{ }}.
16296
16297 A backslash at the end of @var{text} can be used, as in C, to continue
16298 the command onto subsequent lines. For example,
16299
16300 @smallexample
16301 echo This is some text\n\
16302 which is continued\n\
16303 onto several lines.\n
16304 @end smallexample
16305
16306 produces the same output as
16307
16308 @smallexample
16309 echo This is some text\n
16310 echo which is continued\n
16311 echo onto several lines.\n
16312 @end smallexample
16313
16314 @kindex output
16315 @item output @var{expression}
16316 Print the value of @var{expression} and nothing but that value: no
16317 newlines, no @samp{$@var{nn} = }. The value is not entered in the
16318 value history either. @xref{Expressions, ,Expressions}, for more information
16319 on expressions.
16320
16321 @item output/@var{fmt} @var{expression}
16322 Print the value of @var{expression} in format @var{fmt}. You can use
16323 the same formats as for @code{print}. @xref{Output Formats,,Output
16324 formats}, for more information.
16325
16326 @kindex printf
16327 @item printf @var{string}, @var{expressions}@dots{}
16328 Print the values of the @var{expressions} under the control of
16329 @var{string}. The @var{expressions} are separated by commas and may be
16330 either numbers or pointers. Their values are printed as specified by
16331 @var{string}, exactly as if your program were to execute the C
16332 subroutine
16333 @c FIXME: the above implies that at least all ANSI C formats are
16334 @c supported, but it isn't true: %E and %G don't work (or so it seems).
16335 @c Either this is a bug, or the manual should document what formats are
16336 @c supported.
16337
16338 @smallexample
16339 printf (@var{string}, @var{expressions}@dots{});
16340 @end smallexample
16341
16342 For example, you can print two values in hex like this:
16343
16344 @smallexample
16345 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16346 @end smallexample
16347
16348 The only backslash-escape sequences that you can use in the format
16349 string are the simple ones that consist of backslash followed by a
16350 letter.
16351 @end table
16352
16353 @node Interpreters
16354 @chapter Command Interpreters
16355 @cindex command interpreters
16356
16357 @value{GDBN} supports multiple command interpreters, and some command
16358 infrastructure to allow users or user interface writers to switch
16359 between interpreters or run commands in other interpreters.
16360
16361 @value{GDBN} currently supports two command interpreters, the console
16362 interpreter (sometimes called the command-line interpreter or @sc{cli})
16363 and the machine interface interpreter (or @sc{gdb/mi}). This manual
16364 describes both of these interfaces in great detail.
16365
16366 By default, @value{GDBN} will start with the console interpreter.
16367 However, the user may choose to start @value{GDBN} with another
16368 interpreter by specifying the @option{-i} or @option{--interpreter}
16369 startup options. Defined interpreters include:
16370
16371 @table @code
16372 @item console
16373 @cindex console interpreter
16374 The traditional console or command-line interpreter. This is the most often
16375 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16376 @value{GDBN} will use this interpreter.
16377
16378 @item mi
16379 @cindex mi interpreter
16380 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
16381 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16382 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16383 Interface}.
16384
16385 @item mi2
16386 @cindex mi2 interpreter
16387 The current @sc{gdb/mi} interface.
16388
16389 @item mi1
16390 @cindex mi1 interpreter
16391 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16392
16393 @end table
16394
16395 @cindex invoke another interpreter
16396 The interpreter being used by @value{GDBN} may not be dynamically
16397 switched at runtime. Although possible, this could lead to a very
16398 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16399 enters the command "interpreter-set console" in a console view,
16400 @value{GDBN} would switch to using the console interpreter, rendering
16401 the IDE inoperable!
16402
16403 @kindex interpreter-exec
16404 Although you may only choose a single interpreter at startup, you may execute
16405 commands in any interpreter from the current interpreter using the appropriate
16406 command. If you are running the console interpreter, simply use the
16407 @code{interpreter-exec} command:
16408
16409 @smallexample
16410 interpreter-exec mi "-data-list-register-names"
16411 @end smallexample
16412
16413 @sc{gdb/mi} has a similar command, although it is only available in versions of
16414 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16415
16416 @node TUI
16417 @chapter @value{GDBN} Text User Interface
16418 @cindex TUI
16419 @cindex Text User Interface
16420
16421 @menu
16422 * TUI Overview:: TUI overview
16423 * TUI Keys:: TUI key bindings
16424 * TUI Single Key Mode:: TUI single key mode
16425 * TUI Commands:: TUI specific commands
16426 * TUI Configuration:: TUI configuration variables
16427 @end menu
16428
16429 The @value{GDBN} Text User Interface, TUI in short, is a terminal
16430 interface which uses the @code{curses} library to show the source
16431 file, the assembly output, the program registers and @value{GDBN}
16432 commands in separate text windows.
16433
16434 The TUI is enabled by invoking @value{GDBN} using either
16435 @pindex gdbtui
16436 @samp{gdbtui} or @samp{gdb -tui}.
16437
16438 @node TUI Overview
16439 @section TUI overview
16440
16441 The TUI has two display modes that can be switched while
16442 @value{GDBN} runs:
16443
16444 @itemize @bullet
16445 @item
16446 A curses (or TUI) mode in which it displays several text
16447 windows on the terminal.
16448
16449 @item
16450 A standard mode which corresponds to the @value{GDBN} configured without
16451 the TUI.
16452 @end itemize
16453
16454 In the TUI mode, @value{GDBN} can display several text window
16455 on the terminal:
16456
16457 @table @emph
16458 @item command
16459 This window is the @value{GDBN} command window with the @value{GDBN}
16460 prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16461 managed using readline but through the TUI. The @emph{command}
16462 window is always visible.
16463
16464 @item source
16465 The source window shows the source file of the program. The current
16466 line as well as active breakpoints are displayed in this window.
16467
16468 @item assembly
16469 The assembly window shows the disassembly output of the program.
16470
16471 @item register
16472 This window shows the processor registers. It detects when
16473 a register is changed and when this is the case, registers that have
16474 changed are highlighted.
16475
16476 @end table
16477
16478 The source and assembly windows show the current program position
16479 by highlighting the current line and marking them with the @samp{>} marker.
16480 Breakpoints are also indicated with two markers. A first one
16481 indicates the breakpoint type:
16482
16483 @table @code
16484 @item B
16485 Breakpoint which was hit at least once.
16486
16487 @item b
16488 Breakpoint which was never hit.
16489
16490 @item H
16491 Hardware breakpoint which was hit at least once.
16492
16493 @item h
16494 Hardware breakpoint which was never hit.
16495
16496 @end table
16497
16498 The second marker indicates whether the breakpoint is enabled or not:
16499
16500 @table @code
16501 @item +
16502 Breakpoint is enabled.
16503
16504 @item -
16505 Breakpoint is disabled.
16506
16507 @end table
16508
16509 The source, assembly and register windows are attached to the thread
16510 and the frame position. They are updated when the current thread
16511 changes, when the frame changes or when the program counter changes.
16512 These three windows are arranged by the TUI according to several
16513 layouts. The layout defines which of these three windows are visible.
16514 The following layouts are available:
16515
16516 @itemize @bullet
16517 @item
16518 source
16519
16520 @item
16521 assembly
16522
16523 @item
16524 source and assembly
16525
16526 @item
16527 source and registers
16528
16529 @item
16530 assembly and registers
16531
16532 @end itemize
16533
16534 On top of the command window a status line gives various information
16535 concerning the current process begin debugged. The status line is
16536 updated when the information it shows changes. The following fields
16537 are displayed:
16538
16539 @table @emph
16540 @item target
16541 Indicates the current gdb target
16542 (@pxref{Targets, ,Specifying a Debugging Target}).
16543
16544 @item process
16545 Gives information about the current process or thread number.
16546 When no process is being debugged, this field is set to @code{No process}.
16547
16548 @item function
16549 Gives the current function name for the selected frame.
16550 The name is demangled if demangling is turned on (@pxref{Print Settings}).
16551 When there is no symbol corresponding to the current program counter
16552 the string @code{??} is displayed.
16553
16554 @item line
16555 Indicates the current line number for the selected frame.
16556 When the current line number is not known the string @code{??} is displayed.
16557
16558 @item pc
16559 Indicates the current program counter address.
16560
16561 @end table
16562
16563 @node TUI Keys
16564 @section TUI Key Bindings
16565 @cindex TUI key bindings
16566
16567 The TUI installs several key bindings in the readline keymaps
16568 (@pxref{Command Line Editing}).
16569 They allow to leave or enter in the TUI mode or they operate
16570 directly on the TUI layout and windows. The TUI also provides
16571 a @emph{SingleKey} keymap which binds several keys directly to
16572 @value{GDBN} commands. The following key bindings
16573 are installed for both TUI mode and the @value{GDBN} standard mode.
16574
16575 @table @kbd
16576 @kindex C-x C-a
16577 @item C-x C-a
16578 @kindex C-x a
16579 @itemx C-x a
16580 @kindex C-x A
16581 @itemx C-x A
16582 Enter or leave the TUI mode. When the TUI mode is left,
16583 the curses window management is left and @value{GDBN} operates using
16584 its standard mode writing on the terminal directly. When the TUI
16585 mode is entered, the control is given back to the curses windows.
16586 The screen is then refreshed.
16587
16588 @kindex C-x 1
16589 @item C-x 1
16590 Use a TUI layout with only one window. The layout will
16591 either be @samp{source} or @samp{assembly}. When the TUI mode
16592 is not active, it will switch to the TUI mode.
16593
16594 Think of this key binding as the Emacs @kbd{C-x 1} binding.
16595
16596 @kindex C-x 2
16597 @item C-x 2
16598 Use a TUI layout with at least two windows. When the current
16599 layout shows already two windows, a next layout with two windows is used.
16600 When a new layout is chosen, one window will always be common to the
16601 previous layout and the new one.
16602
16603 Think of it as the Emacs @kbd{C-x 2} binding.
16604
16605 @kindex C-x o
16606 @item C-x o
16607 Change the active window. The TUI associates several key bindings
16608 (like scrolling and arrow keys) to the active window. This command
16609 gives the focus to the next TUI window.
16610
16611 Think of it as the Emacs @kbd{C-x o} binding.
16612
16613 @kindex C-x s
16614 @item C-x s
16615 Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16616 (@pxref{TUI Single Key Mode}).
16617
16618 @end table
16619
16620 The following key bindings are handled only by the TUI mode:
16621
16622 @table @key
16623 @kindex PgUp
16624 @item PgUp
16625 Scroll the active window one page up.
16626
16627 @kindex PgDn
16628 @item PgDn
16629 Scroll the active window one page down.
16630
16631 @kindex Up
16632 @item Up
16633 Scroll the active window one line up.
16634
16635 @kindex Down
16636 @item Down
16637 Scroll the active window one line down.
16638
16639 @kindex Left
16640 @item Left
16641 Scroll the active window one column left.
16642
16643 @kindex Right
16644 @item Right
16645 Scroll the active window one column right.
16646
16647 @kindex C-L
16648 @item C-L
16649 Refresh the screen.
16650
16651 @end table
16652
16653 In the TUI mode, the arrow keys are used by the active window
16654 for scrolling. This means they are available for readline when the
16655 active window is the command window. When the command window
16656 does not have the focus, it is necessary to use other readline
16657 key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
16658
16659 @node TUI Single Key Mode
16660 @section TUI Single Key Mode
16661 @cindex TUI single key mode
16662
16663 The TUI provides a @emph{SingleKey} mode in which it installs a particular
16664 key binding in the readline keymaps to connect single keys to
16665 some gdb commands.
16666
16667 @table @kbd
16668 @kindex c @r{(SingleKey TUI key)}
16669 @item c
16670 continue
16671
16672 @kindex d @r{(SingleKey TUI key)}
16673 @item d
16674 down
16675
16676 @kindex f @r{(SingleKey TUI key)}
16677 @item f
16678 finish
16679
16680 @kindex n @r{(SingleKey TUI key)}
16681 @item n
16682 next
16683
16684 @kindex q @r{(SingleKey TUI key)}
16685 @item q
16686 exit the @emph{SingleKey} mode.
16687
16688 @kindex r @r{(SingleKey TUI key)}
16689 @item r
16690 run
16691
16692 @kindex s @r{(SingleKey TUI key)}
16693 @item s
16694 step
16695
16696 @kindex u @r{(SingleKey TUI key)}
16697 @item u
16698 up
16699
16700 @kindex v @r{(SingleKey TUI key)}
16701 @item v
16702 info locals
16703
16704 @kindex w @r{(SingleKey TUI key)}
16705 @item w
16706 where
16707
16708 @end table
16709
16710 Other keys temporarily switch to the @value{GDBN} command prompt.
16711 The key that was pressed is inserted in the editing buffer so that
16712 it is possible to type most @value{GDBN} commands without interaction
16713 with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16714 @emph{SingleKey} mode is restored. The only way to permanently leave
16715 this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16716
16717
16718 @node TUI Commands
16719 @section TUI specific commands
16720 @cindex TUI commands
16721
16722 The TUI has specific commands to control the text windows.
16723 These commands are always available, that is they do not depend on
16724 the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16725 is in the standard mode, using these commands will automatically switch
16726 in the TUI mode.
16727
16728 @table @code
16729 @item info win
16730 @kindex info win
16731 List and give the size of all displayed windows.
16732
16733 @item layout next
16734 @kindex layout
16735 Display the next layout.
16736
16737 @item layout prev
16738 Display the previous layout.
16739
16740 @item layout src
16741 Display the source window only.
16742
16743 @item layout asm
16744 Display the assembly window only.
16745
16746 @item layout split
16747 Display the source and assembly window.
16748
16749 @item layout regs
16750 Display the register window together with the source or assembly window.
16751
16752 @item focus next | prev | src | asm | regs | split
16753 @kindex focus
16754 Set the focus to the named window.
16755 This command allows to change the active window so that scrolling keys
16756 can be affected to another window.
16757
16758 @item refresh
16759 @kindex refresh
16760 Refresh the screen. This is similar to using @key{C-L} key.
16761
16762 @item tui reg float
16763 @kindex tui reg
16764 Show the floating point registers in the register window.
16765
16766 @item tui reg general
16767 Show the general registers in the register window.
16768
16769 @item tui reg next
16770 Show the next register group. The list of register groups as well as
16771 their order is target specific. The predefined register groups are the
16772 following: @code{general}, @code{float}, @code{system}, @code{vector},
16773 @code{all}, @code{save}, @code{restore}.
16774
16775 @item tui reg system
16776 Show the system registers in the register window.
16777
16778 @item update
16779 @kindex update
16780 Update the source window and the current execution point.
16781
16782 @item winheight @var{name} +@var{count}
16783 @itemx winheight @var{name} -@var{count}
16784 @kindex winheight
16785 Change the height of the window @var{name} by @var{count}
16786 lines. Positive counts increase the height, while negative counts
16787 decrease it.
16788
16789 @item tabset
16790 @kindex tabset @var{nchars}
16791 Set the width of tab stops to be @var{nchars} characters.
16792
16793 @end table
16794
16795 @node TUI Configuration
16796 @section TUI configuration variables
16797 @cindex TUI configuration variables
16798
16799 The TUI has several configuration variables that control the
16800 appearance of windows on the terminal.
16801
16802 @table @code
16803 @item set tui border-kind @var{kind}
16804 @kindex set tui border-kind
16805 Select the border appearance for the source, assembly and register windows.
16806 The possible values are the following:
16807 @table @code
16808 @item space
16809 Use a space character to draw the border.
16810
16811 @item ascii
16812 Use ascii characters + - and | to draw the border.
16813
16814 @item acs
16815 Use the Alternate Character Set to draw the border. The border is
16816 drawn using character line graphics if the terminal supports them.
16817
16818 @end table
16819
16820 @item set tui active-border-mode @var{mode}
16821 @kindex set tui active-border-mode
16822 Select the attributes to display the border of the active window.
16823 The possible values are @code{normal}, @code{standout}, @code{reverse},
16824 @code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
16825
16826 @item set tui border-mode @var{mode}
16827 @kindex set tui border-mode
16828 Select the attributes to display the border of other windows.
16829 The @var{mode} can be one of the following:
16830 @table @code
16831 @item normal
16832 Use normal attributes to display the border.
16833
16834 @item standout
16835 Use standout mode.
16836
16837 @item reverse
16838 Use reverse video mode.
16839
16840 @item half
16841 Use half bright mode.
16842
16843 @item half-standout
16844 Use half bright and standout mode.
16845
16846 @item bold
16847 Use extra bright or bold mode.
16848
16849 @item bold-standout
16850 Use extra bright or bold and standout mode.
16851
16852 @end table
16853
16854 @end table
16855
16856 @node Emacs
16857 @chapter Using @value{GDBN} under @sc{gnu} Emacs
16858
16859 @cindex Emacs
16860 @cindex @sc{gnu} Emacs
16861 A special interface allows you to use @sc{gnu} Emacs to view (and
16862 edit) the source files for the program you are debugging with
16863 @value{GDBN}.
16864
16865 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16866 executable file you want to debug as an argument. This command starts
16867 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
16868 created Emacs buffer.
16869 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
16870
16871 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16872 things:
16873
16874 @itemize @bullet
16875 @item
16876 All ``terminal'' input and output goes through the Emacs buffer.
16877 @end itemize
16878
16879 This applies both to @value{GDBN} commands and their output, and to the input
16880 and output done by the program you are debugging.
16881
16882 This is useful because it means that you can copy the text of previous
16883 commands and input them again; you can even use parts of the output
16884 in this way.
16885
16886 All the facilities of Emacs' Shell mode are available for interacting
16887 with your program. In particular, you can send signals the usual
16888 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16889 stop.
16890
16891 @itemize @bullet
16892 @item
16893 @value{GDBN} displays source code through Emacs.
16894 @end itemize
16895
16896 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16897 source file for that frame and puts an arrow (@samp{=>}) at the
16898 left margin of the current line. Emacs uses a separate buffer for
16899 source display, and splits the screen to show both your @value{GDBN} session
16900 and the source.
16901
16902 Explicit @value{GDBN} @code{list} or search commands still produce output as
16903 usual, but you probably have no reason to use them from Emacs.
16904
16905 If you specify an absolute file name when prompted for the @kbd{M-x
16906 gdb} argument, then Emacs sets your current working directory to where
16907 your program resides. If you only specify the file name, then Emacs
16908 sets your current working directory to to the directory associated
16909 with the previous buffer. In this case, @value{GDBN} may find your
16910 program by searching your environment's @code{PATH} variable, but on
16911 some operating systems it might not find the source. So, although the
16912 @value{GDBN} input and output session proceeds normally, the auxiliary
16913 buffer does not display the current source and line of execution.
16914
16915 The initial working directory of @value{GDBN} is printed on the top
16916 line of the @value{GDBN} I/O buffer and this serves as a default for
16917 the commands that specify files for @value{GDBN} to operate
16918 on. @xref{Files, ,Commands to specify files}.
16919
16920 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16921 need to call @value{GDBN} by a different name (for example, if you
16922 keep several configurations around, with different names) you can
16923 customize the Emacs variable @code{gud-gdb-command-name} to run the
16924 one you want.
16925
16926 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16927 addition to the standard Shell mode commands:
16928
16929 @table @kbd
16930 @item C-h m
16931 Describe the features of Emacs' @value{GDBN} Mode.
16932
16933 @item C-c C-s
16934 Execute to another source line, like the @value{GDBN} @code{step} command; also
16935 update the display window to show the current file and location.
16936
16937 @item C-c C-n
16938 Execute to next source line in this function, skipping all function
16939 calls, like the @value{GDBN} @code{next} command. Then update the display window
16940 to show the current file and location.
16941
16942 @item C-c C-i
16943 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16944 display window accordingly.
16945
16946 @item C-c C-f
16947 Execute until exit from the selected stack frame, like the @value{GDBN}
16948 @code{finish} command.
16949
16950 @item C-c C-r
16951 Continue execution of your program, like the @value{GDBN} @code{continue}
16952 command.
16953
16954 @item C-c <
16955 Go up the number of frames indicated by the numeric argument
16956 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16957 like the @value{GDBN} @code{up} command.
16958
16959 @item C-c >
16960 Go down the number of frames indicated by the numeric argument, like the
16961 @value{GDBN} @code{down} command.
16962 @end table
16963
16964 In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
16965 tells @value{GDBN} to set a breakpoint on the source line point is on.
16966
16967 If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16968 shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16969 point to any frame in the stack and type @key{RET} to make it become the
16970 current frame and display the associated source in the source buffer.
16971 Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16972 current one.
16973
16974 If you accidentally delete the source-display buffer, an easy way to get
16975 it back is to type the command @code{f} in the @value{GDBN} buffer, to
16976 request a frame display; when you run under Emacs, this recreates
16977 the source buffer if necessary to show you the context of the current
16978 frame.
16979
16980 The source files displayed in Emacs are in ordinary Emacs buffers
16981 which are visiting the source files in the usual way. You can edit
16982 the files with these buffers if you wish; but keep in mind that @value{GDBN}
16983 communicates with Emacs in terms of line numbers. If you add or
16984 delete lines from the text, the line numbers that @value{GDBN} knows cease
16985 to correspond properly with the code.
16986
16987 The description given here is for GNU Emacs version 21.3 and a more
16988 detailed description of its interaction with @value{GDBN} is given in
16989 the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
16990
16991 @c The following dropped because Epoch is nonstandard. Reactivate
16992 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16993 @ignore
16994 @kindex Emacs Epoch environment
16995 @kindex Epoch
16996 @kindex inspect
16997
16998 Version 18 of @sc{gnu} Emacs has a built-in window system
16999 called the @code{epoch}
17000 environment. Users of this environment can use a new command,
17001 @code{inspect} which performs identically to @code{print} except that
17002 each value is printed in its own window.
17003 @end ignore
17004
17005
17006 @node GDB/MI
17007 @chapter The @sc{gdb/mi} Interface
17008
17009 @unnumberedsec Function and Purpose
17010
17011 @cindex @sc{gdb/mi}, its purpose
17012 @sc{gdb/mi} is a line based machine oriented text interface to
17013 @value{GDBN} and is activated by specifying using the
17014 @option{--interpreter} command line option (@pxref{Mode Options}). It
17015 is specifically intended to support the development of systems which
17016 use the debugger as just one small component of a larger system.
17017
17018 This chapter is a specification of the @sc{gdb/mi} interface. It is written
17019 in the form of a reference manual.
17020
17021 Note that @sc{gdb/mi} is still under construction, so some of the
17022 features described below are incomplete and subject to change.
17023
17024 @unnumberedsec Notation and Terminology
17025
17026 @cindex notational conventions, for @sc{gdb/mi}
17027 This chapter uses the following notation:
17028
17029 @itemize @bullet
17030 @item
17031 @code{|} separates two alternatives.
17032
17033 @item
17034 @code{[ @var{something} ]} indicates that @var{something} is optional:
17035 it may or may not be given.
17036
17037 @item
17038 @code{( @var{group} )*} means that @var{group} inside the parentheses
17039 may repeat zero or more times.
17040
17041 @item
17042 @code{( @var{group} )+} means that @var{group} inside the parentheses
17043 may repeat one or more times.
17044
17045 @item
17046 @code{"@var{string}"} means a literal @var{string}.
17047 @end itemize
17048
17049 @ignore
17050 @heading Dependencies
17051 @end ignore
17052
17053 @heading Acknowledgments
17054
17055 In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
17056 Elena Zannoni.
17057
17058 @menu
17059 * GDB/MI Command Syntax::
17060 * GDB/MI Compatibility with CLI::
17061 * GDB/MI Output Records::
17062 * GDB/MI Command Description Format::
17063 * GDB/MI Breakpoint Table Commands::
17064 * GDB/MI Data Manipulation::
17065 * GDB/MI Program Control::
17066 * GDB/MI Miscellaneous Commands::
17067 @ignore
17068 * GDB/MI Kod Commands::
17069 * GDB/MI Memory Overlay Commands::
17070 * GDB/MI Signal Handling Commands::
17071 @end ignore
17072 * GDB/MI Stack Manipulation::
17073 * GDB/MI Symbol Query::
17074 * GDB/MI Target Manipulation::
17075 * GDB/MI Thread Commands::
17076 * GDB/MI Tracepoint Commands::
17077 * GDB/MI Variable Objects::
17078 @end menu
17079
17080 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17081 @node GDB/MI Command Syntax
17082 @section @sc{gdb/mi} Command Syntax
17083
17084 @menu
17085 * GDB/MI Input Syntax::
17086 * GDB/MI Output Syntax::
17087 * GDB/MI Simple Examples::
17088 @end menu
17089
17090 @node GDB/MI Input Syntax
17091 @subsection @sc{gdb/mi} Input Syntax
17092
17093 @cindex input syntax for @sc{gdb/mi}
17094 @cindex @sc{gdb/mi}, input syntax
17095 @table @code
17096 @item @var{command} @expansion{}
17097 @code{@var{cli-command} | @var{mi-command}}
17098
17099 @item @var{cli-command} @expansion{}
17100 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17101 @var{cli-command} is any existing @value{GDBN} CLI command.
17102
17103 @item @var{mi-command} @expansion{}
17104 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17105 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17106
17107 @item @var{token} @expansion{}
17108 "any sequence of digits"
17109
17110 @item @var{option} @expansion{}
17111 @code{"-" @var{parameter} [ " " @var{parameter} ]}
17112
17113 @item @var{parameter} @expansion{}
17114 @code{@var{non-blank-sequence} | @var{c-string}}
17115
17116 @item @var{operation} @expansion{}
17117 @emph{any of the operations described in this chapter}
17118
17119 @item @var{non-blank-sequence} @expansion{}
17120 @emph{anything, provided it doesn't contain special characters such as
17121 "-", @var{nl}, """ and of course " "}
17122
17123 @item @var{c-string} @expansion{}
17124 @code{""" @var{seven-bit-iso-c-string-content} """}
17125
17126 @item @var{nl} @expansion{}
17127 @code{CR | CR-LF}
17128 @end table
17129
17130 @noindent
17131 Notes:
17132
17133 @itemize @bullet
17134 @item
17135 The CLI commands are still handled by the @sc{mi} interpreter; their
17136 output is described below.
17137
17138 @item
17139 The @code{@var{token}}, when present, is passed back when the command
17140 finishes.
17141
17142 @item
17143 Some @sc{mi} commands accept optional arguments as part of the parameter
17144 list. Each option is identified by a leading @samp{-} (dash) and may be
17145 followed by an optional argument parameter. Options occur first in the
17146 parameter list and can be delimited from normal parameters using
17147 @samp{--} (this is useful when some parameters begin with a dash).
17148 @end itemize
17149
17150 Pragmatics:
17151
17152 @itemize @bullet
17153 @item
17154 We want easy access to the existing CLI syntax (for debugging).
17155
17156 @item
17157 We want it to be easy to spot a @sc{mi} operation.
17158 @end itemize
17159
17160 @node GDB/MI Output Syntax
17161 @subsection @sc{gdb/mi} Output Syntax
17162
17163 @cindex output syntax of @sc{gdb/mi}
17164 @cindex @sc{gdb/mi}, output syntax
17165 The output from @sc{gdb/mi} consists of zero or more out-of-band records
17166 followed, optionally, by a single result record. This result record
17167 is for the most recent command. The sequence of output records is
17168 terminated by @samp{(@value{GDBP})}.
17169
17170 If an input command was prefixed with a @code{@var{token}} then the
17171 corresponding output for that command will also be prefixed by that same
17172 @var{token}.
17173
17174 @table @code
17175 @item @var{output} @expansion{}
17176 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
17177
17178 @item @var{result-record} @expansion{}
17179 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17180
17181 @item @var{out-of-band-record} @expansion{}
17182 @code{@var{async-record} | @var{stream-record}}
17183
17184 @item @var{async-record} @expansion{}
17185 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17186
17187 @item @var{exec-async-output} @expansion{}
17188 @code{[ @var{token} ] "*" @var{async-output}}
17189
17190 @item @var{status-async-output} @expansion{}
17191 @code{[ @var{token} ] "+" @var{async-output}}
17192
17193 @item @var{notify-async-output} @expansion{}
17194 @code{[ @var{token} ] "=" @var{async-output}}
17195
17196 @item @var{async-output} @expansion{}
17197 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
17198
17199 @item @var{result-class} @expansion{}
17200 @code{"done" | "running" | "connected" | "error" | "exit"}
17201
17202 @item @var{async-class} @expansion{}
17203 @code{"stopped" | @var{others}} (where @var{others} will be added
17204 depending on the needs---this is still in development).
17205
17206 @item @var{result} @expansion{}
17207 @code{ @var{variable} "=" @var{value}}
17208
17209 @item @var{variable} @expansion{}
17210 @code{ @var{string} }
17211
17212 @item @var{value} @expansion{}
17213 @code{ @var{const} | @var{tuple} | @var{list} }
17214
17215 @item @var{const} @expansion{}
17216 @code{@var{c-string}}
17217
17218 @item @var{tuple} @expansion{}
17219 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17220
17221 @item @var{list} @expansion{}
17222 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17223 @var{result} ( "," @var{result} )* "]" }
17224
17225 @item @var{stream-record} @expansion{}
17226 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17227
17228 @item @var{console-stream-output} @expansion{}
17229 @code{"~" @var{c-string}}
17230
17231 @item @var{target-stream-output} @expansion{}
17232 @code{"@@" @var{c-string}}
17233
17234 @item @var{log-stream-output} @expansion{}
17235 @code{"&" @var{c-string}}
17236
17237 @item @var{nl} @expansion{}
17238 @code{CR | CR-LF}
17239
17240 @item @var{token} @expansion{}
17241 @emph{any sequence of digits}.
17242 @end table
17243
17244 @noindent
17245 Notes:
17246
17247 @itemize @bullet
17248 @item
17249 All output sequences end in a single line containing a period.
17250
17251 @item
17252 The @code{@var{token}} is from the corresponding request. If an execution
17253 command is interrupted by the @samp{-exec-interrupt} command, the
17254 @var{token} associated with the @samp{*stopped} message is the one of the
17255 original execution command, not the one of the interrupt command.
17256
17257 @item
17258 @cindex status output in @sc{gdb/mi}
17259 @var{status-async-output} contains on-going status information about the
17260 progress of a slow operation. It can be discarded. All status output is
17261 prefixed by @samp{+}.
17262
17263 @item
17264 @cindex async output in @sc{gdb/mi}
17265 @var{exec-async-output} contains asynchronous state change on the target
17266 (stopped, started, disappeared). All async output is prefixed by
17267 @samp{*}.
17268
17269 @item
17270 @cindex notify output in @sc{gdb/mi}
17271 @var{notify-async-output} contains supplementary information that the
17272 client should handle (e.g., a new breakpoint information). All notify
17273 output is prefixed by @samp{=}.
17274
17275 @item
17276 @cindex console output in @sc{gdb/mi}
17277 @var{console-stream-output} is output that should be displayed as is in the
17278 console. It is the textual response to a CLI command. All the console
17279 output is prefixed by @samp{~}.
17280
17281 @item
17282 @cindex target output in @sc{gdb/mi}
17283 @var{target-stream-output} is the output produced by the target program.
17284 All the target output is prefixed by @samp{@@}.
17285
17286 @item
17287 @cindex log output in @sc{gdb/mi}
17288 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17289 instance messages that should be displayed as part of an error log. All
17290 the log output is prefixed by @samp{&}.
17291
17292 @item
17293 @cindex list output in @sc{gdb/mi}
17294 New @sc{gdb/mi} commands should only output @var{lists} containing
17295 @var{values}.
17296
17297
17298 @end itemize
17299
17300 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17301 details about the various output records.
17302
17303 @node GDB/MI Simple Examples
17304 @subsection Simple Examples of @sc{gdb/mi} Interaction
17305 @cindex @sc{gdb/mi}, simple examples
17306
17307 This subsection presents several simple examples of interaction using
17308 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
17309 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
17310 the output received from @sc{gdb/mi}.
17311
17312 @subsubheading Target Stop
17313 @c Ummm... There is no "-stop" command. This assumes async, no?
17314 Here's an example of stopping the inferior process:
17315
17316 @smallexample
17317 -> -stop
17318 <- (@value{GDBP})
17319 @end smallexample
17320
17321 @noindent
17322 and later:
17323
17324 @smallexample
17325 <- *stop,reason="stop",address="0x123",source="a.c:123"
17326 <- (@value{GDBP})
17327 @end smallexample
17328
17329 @subsubheading Simple CLI Command
17330
17331 Here's an example of a simple CLI command being passed through
17332 @sc{gdb/mi} and on to the CLI.
17333
17334 @smallexample
17335 -> print 1+2
17336 <- &"print 1+2\n"
17337 <- ~"$1 = 3\n"
17338 <- ^done
17339 <- (@value{GDBP})
17340 @end smallexample
17341
17342 @subsubheading Command With Side Effects
17343
17344 @smallexample
17345 -> -symbol-file xyz.exe
17346 <- *breakpoint,nr="3",address="0x123",source="a.c:123"
17347 <- (@value{GDBP})
17348 @end smallexample
17349
17350 @subsubheading A Bad Command
17351
17352 Here's what happens if you pass a non-existent command:
17353
17354 @smallexample
17355 -> -rubbish
17356 <- ^error,msg="Undefined MI command: rubbish"
17357 <- (@value{GDBP})
17358 @end smallexample
17359
17360 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17361 @node GDB/MI Compatibility with CLI
17362 @section @sc{gdb/mi} Compatibility with CLI
17363
17364 @cindex compatibility, @sc{gdb/mi} and CLI
17365 @cindex @sc{gdb/mi}, compatibility with CLI
17366 To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
17367 accepts existing CLI commands. As specified by the syntax, such
17368 commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
17369 respond.
17370
17371 This mechanism is provided as an aid to developers of @sc{gdb/mi}
17372 clients and not as a reliable interface into the CLI. Since the command
17373 is being interpreteted in an environment that assumes @sc{gdb/mi}
17374 behaviour, the exact output of such commands is likely to end up being
17375 an un-supported hybrid of @sc{gdb/mi} and CLI output.
17376
17377 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17378 @node GDB/MI Output Records
17379 @section @sc{gdb/mi} Output Records
17380
17381 @menu
17382 * GDB/MI Result Records::
17383 * GDB/MI Stream Records::
17384 * GDB/MI Out-of-band Records::
17385 @end menu
17386
17387 @node GDB/MI Result Records
17388 @subsection @sc{gdb/mi} Result Records
17389
17390 @cindex result records in @sc{gdb/mi}
17391 @cindex @sc{gdb/mi}, result records
17392 In addition to a number of out-of-band notifications, the response to a
17393 @sc{gdb/mi} command includes one of the following result indications:
17394
17395 @table @code
17396 @findex ^done
17397 @item "^done" [ "," @var{results} ]
17398 The synchronous operation was successful, @code{@var{results}} are the return
17399 values.
17400
17401 @item "^running"
17402 @findex ^running
17403 @c Is this one correct? Should it be an out-of-band notification?
17404 The asynchronous operation was successfully started. The target is
17405 running.
17406
17407 @item "^error" "," @var{c-string}
17408 @findex ^error
17409 The operation failed. The @code{@var{c-string}} contains the corresponding
17410 error message.
17411 @end table
17412
17413 @node GDB/MI Stream Records
17414 @subsection @sc{gdb/mi} Stream Records
17415
17416 @cindex @sc{gdb/mi}, stream records
17417 @cindex stream records in @sc{gdb/mi}
17418 @value{GDBN} internally maintains a number of output streams: the console, the
17419 target, and the log. The output intended for each of these streams is
17420 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17421
17422 Each stream record begins with a unique @dfn{prefix character} which
17423 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17424 Syntax}). In addition to the prefix, each stream record contains a
17425 @code{@var{string-output}}. This is either raw text (with an implicit new
17426 line) or a quoted C string (which does not contain an implicit newline).
17427
17428 @table @code
17429 @item "~" @var{string-output}
17430 The console output stream contains text that should be displayed in the
17431 CLI console window. It contains the textual responses to CLI commands.
17432
17433 @item "@@" @var{string-output}
17434 The target output stream contains any textual output from the running
17435 target.
17436
17437 @item "&" @var{string-output}
17438 The log stream contains debugging messages being produced by @value{GDBN}'s
17439 internals.
17440 @end table
17441
17442 @node GDB/MI Out-of-band Records
17443 @subsection @sc{gdb/mi} Out-of-band Records
17444
17445 @cindex out-of-band records in @sc{gdb/mi}
17446 @cindex @sc{gdb/mi}, out-of-band records
17447 @dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17448 additional changes that have occurred. Those changes can either be a
17449 consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17450 target activity (e.g., target stopped).
17451
17452 The following is a preliminary list of possible out-of-band records.
17453 In particular, the @var{exec-async-output} records.
17454
17455 @table @code
17456 @item *stopped,reason="@var{reason}"
17457 @end table
17458
17459 @var{reason} can be one of the following:
17460
17461 @table @code
17462 @item breakpoint-hit
17463 A breakpoint was reached.
17464 @item watchpoint-trigger
17465 A watchpoint was triggered.
17466 @item read-watchpoint-trigger
17467 A read watchpoint was triggered.
17468 @item access-watchpoint-trigger
17469 An access watchpoint was triggered.
17470 @item function-finished
17471 An -exec-finish or similar CLI command was accomplished.
17472 @item location-reached
17473 An -exec-until or similar CLI command was accomplished.
17474 @item watchpoint-scope
17475 A watchpoint has gone out of scope.
17476 @item end-stepping-range
17477 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17478 similar CLI command was accomplished.
17479 @item exited-signalled
17480 The inferior exited because of a signal.
17481 @item exited
17482 The inferior exited.
17483 @item exited-normally
17484 The inferior exited normally.
17485 @item signal-received
17486 A signal was received by the inferior.
17487 @end table
17488
17489
17490 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17491 @node GDB/MI Command Description Format
17492 @section @sc{gdb/mi} Command Description Format
17493
17494 The remaining sections describe blocks of commands. Each block of
17495 commands is laid out in a fashion similar to this section.
17496
17497 Note the the line breaks shown in the examples are here only for
17498 readability. They don't appear in the real output.
17499 Also note that the commands with a non-available example (N.A.@:) are
17500 not yet implemented.
17501
17502 @subheading Motivation
17503
17504 The motivation for this collection of commands.
17505
17506 @subheading Introduction
17507
17508 A brief introduction to this collection of commands as a whole.
17509
17510 @subheading Commands
17511
17512 For each command in the block, the following is described:
17513
17514 @subsubheading Synopsis
17515
17516 @smallexample
17517 -command @var{args}@dots{}
17518 @end smallexample
17519
17520 @subsubheading Result
17521
17522 @subsubheading @value{GDBN} Command
17523
17524 The corresponding @value{GDBN} CLI command(s), if any.
17525
17526 @subsubheading Example
17527
17528 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17529 @node GDB/MI Breakpoint Table Commands
17530 @section @sc{gdb/mi} Breakpoint table commands
17531
17532 @cindex breakpoint commands for @sc{gdb/mi}
17533 @cindex @sc{gdb/mi}, breakpoint commands
17534 This section documents @sc{gdb/mi} commands for manipulating
17535 breakpoints.
17536
17537 @subheading The @code{-break-after} Command
17538 @findex -break-after
17539
17540 @subsubheading Synopsis
17541
17542 @smallexample
17543 -break-after @var{number} @var{count}
17544 @end smallexample
17545
17546 The breakpoint number @var{number} is not in effect until it has been
17547 hit @var{count} times. To see how this is reflected in the output of
17548 the @samp{-break-list} command, see the description of the
17549 @samp{-break-list} command below.
17550
17551 @subsubheading @value{GDBN} Command
17552
17553 The corresponding @value{GDBN} command is @samp{ignore}.
17554
17555 @subsubheading Example
17556
17557 @smallexample
17558 (@value{GDBP})
17559 -break-insert main
17560 ^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17561 (@value{GDBP})
17562 -break-after 1 3
17563 ~
17564 ^done
17565 (@value{GDBP})
17566 -break-list
17567 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17568 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17569 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17570 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17571 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17572 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17573 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17574 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17575 addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17576 ignore="3"@}]@}
17577 (@value{GDBP})
17578 @end smallexample
17579
17580 @ignore
17581 @subheading The @code{-break-catch} Command
17582 @findex -break-catch
17583
17584 @subheading The @code{-break-commands} Command
17585 @findex -break-commands
17586 @end ignore
17587
17588
17589 @subheading The @code{-break-condition} Command
17590 @findex -break-condition
17591
17592 @subsubheading Synopsis
17593
17594 @smallexample
17595 -break-condition @var{number} @var{expr}
17596 @end smallexample
17597
17598 Breakpoint @var{number} will stop the program only if the condition in
17599 @var{expr} is true. The condition becomes part of the
17600 @samp{-break-list} output (see the description of the @samp{-break-list}
17601 command below).
17602
17603 @subsubheading @value{GDBN} Command
17604
17605 The corresponding @value{GDBN} command is @samp{condition}.
17606
17607 @subsubheading Example
17608
17609 @smallexample
17610 (@value{GDBP})
17611 -break-condition 1 1
17612 ^done
17613 (@value{GDBP})
17614 -break-list
17615 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17616 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17617 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17618 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17619 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17620 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17621 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17622 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17623 addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17624 times="0",ignore="3"@}]@}
17625 (@value{GDBP})
17626 @end smallexample
17627
17628 @subheading The @code{-break-delete} Command
17629 @findex -break-delete
17630
17631 @subsubheading Synopsis
17632
17633 @smallexample
17634 -break-delete ( @var{breakpoint} )+
17635 @end smallexample
17636
17637 Delete the breakpoint(s) whose number(s) are specified in the argument
17638 list. This is obviously reflected in the breakpoint list.
17639
17640 @subsubheading @value{GDBN} command
17641
17642 The corresponding @value{GDBN} command is @samp{delete}.
17643
17644 @subsubheading Example
17645
17646 @smallexample
17647 (@value{GDBP})
17648 -break-delete 1
17649 ^done
17650 (@value{GDBP})
17651 -break-list
17652 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17653 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17654 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17655 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17656 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17657 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17658 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17659 body=[]@}
17660 (@value{GDBP})
17661 @end smallexample
17662
17663 @subheading The @code{-break-disable} Command
17664 @findex -break-disable
17665
17666 @subsubheading Synopsis
17667
17668 @smallexample
17669 -break-disable ( @var{breakpoint} )+
17670 @end smallexample
17671
17672 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17673 break list is now set to @samp{n} for the named @var{breakpoint}(s).
17674
17675 @subsubheading @value{GDBN} Command
17676
17677 The corresponding @value{GDBN} command is @samp{disable}.
17678
17679 @subsubheading Example
17680
17681 @smallexample
17682 (@value{GDBP})
17683 -break-disable 2
17684 ^done
17685 (@value{GDBP})
17686 -break-list
17687 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17688 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17689 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17690 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17691 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17692 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17693 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17694 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17695 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17696 (@value{GDBP})
17697 @end smallexample
17698
17699 @subheading The @code{-break-enable} Command
17700 @findex -break-enable
17701
17702 @subsubheading Synopsis
17703
17704 @smallexample
17705 -break-enable ( @var{breakpoint} )+
17706 @end smallexample
17707
17708 Enable (previously disabled) @var{breakpoint}(s).
17709
17710 @subsubheading @value{GDBN} Command
17711
17712 The corresponding @value{GDBN} command is @samp{enable}.
17713
17714 @subsubheading Example
17715
17716 @smallexample
17717 (@value{GDBP})
17718 -break-enable 2
17719 ^done
17720 (@value{GDBP})
17721 -break-list
17722 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17723 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17724 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17725 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17726 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17727 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17728 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17729 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17730 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17731 (@value{GDBP})
17732 @end smallexample
17733
17734 @subheading The @code{-break-info} Command
17735 @findex -break-info
17736
17737 @subsubheading Synopsis
17738
17739 @smallexample
17740 -break-info @var{breakpoint}
17741 @end smallexample
17742
17743 @c REDUNDANT???
17744 Get information about a single breakpoint.
17745
17746 @subsubheading @value{GDBN} command
17747
17748 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17749
17750 @subsubheading Example
17751 N.A.
17752
17753 @subheading The @code{-break-insert} Command
17754 @findex -break-insert
17755
17756 @subsubheading Synopsis
17757
17758 @smallexample
17759 -break-insert [ -t ] [ -h ] [ -r ]
17760 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17761 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17762 @end smallexample
17763
17764 @noindent
17765 If specified, @var{line}, can be one of:
17766
17767 @itemize @bullet
17768 @item function
17769 @c @item +offset
17770 @c @item -offset
17771 @c @item linenum
17772 @item filename:linenum
17773 @item filename:function
17774 @item *address
17775 @end itemize
17776
17777 The possible optional parameters of this command are:
17778
17779 @table @samp
17780 @item -t
17781 Insert a tempoary breakpoint.
17782 @item -h
17783 Insert a hardware breakpoint.
17784 @item -c @var{condition}
17785 Make the breakpoint conditional on @var{condition}.
17786 @item -i @var{ignore-count}
17787 Initialize the @var{ignore-count}.
17788 @item -r
17789 Insert a regular breakpoint in all the functions whose names match the
17790 given regular expression. Other flags are not applicable to regular
17791 expresson.
17792 @end table
17793
17794 @subsubheading Result
17795
17796 The result is in the form:
17797
17798 @smallexample
17799 ^done,bkptno="@var{number}",func="@var{funcname}",
17800 file="@var{filename}",line="@var{lineno}"
17801 @end smallexample
17802
17803 @noindent
17804 where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17805 is the name of the function where the breakpoint was inserted,
17806 @var{filename} is the name of the source file which contains this
17807 function, and @var{lineno} is the source line number within that file.
17808
17809 Note: this format is open to change.
17810 @c An out-of-band breakpoint instead of part of the result?
17811
17812 @subsubheading @value{GDBN} Command
17813
17814 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17815 @samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17816
17817 @subsubheading Example
17818
17819 @smallexample
17820 (@value{GDBP})
17821 -break-insert main
17822 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17823 (@value{GDBP})
17824 -break-insert -t foo
17825 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17826 (@value{GDBP})
17827 -break-list
17828 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17829 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17830 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17831 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17832 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17833 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17834 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17835 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17836 addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17837 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17838 addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17839 (@value{GDBP})
17840 -break-insert -r foo.*
17841 ~int foo(int, int);
17842 ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17843 (@value{GDBP})
17844 @end smallexample
17845
17846 @subheading The @code{-break-list} Command
17847 @findex -break-list
17848
17849 @subsubheading Synopsis
17850
17851 @smallexample
17852 -break-list
17853 @end smallexample
17854
17855 Displays the list of inserted breakpoints, showing the following fields:
17856
17857 @table @samp
17858 @item Number
17859 number of the breakpoint
17860 @item Type
17861 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17862 @item Disposition
17863 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17864 or @samp{nokeep}
17865 @item Enabled
17866 is the breakpoint enabled or no: @samp{y} or @samp{n}
17867 @item Address
17868 memory location at which the breakpoint is set
17869 @item What
17870 logical location of the breakpoint, expressed by function name, file
17871 name, line number
17872 @item Times
17873 number of times the breakpoint has been hit
17874 @end table
17875
17876 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17877 @code{body} field is an empty list.
17878
17879 @subsubheading @value{GDBN} Command
17880
17881 The corresponding @value{GDBN} command is @samp{info break}.
17882
17883 @subsubheading Example
17884
17885 @smallexample
17886 (@value{GDBP})
17887 -break-list
17888 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17889 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17890 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17891 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17892 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17893 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17894 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17895 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17896 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17897 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17898 addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17899 (@value{GDBP})
17900 @end smallexample
17901
17902 Here's an example of the result when there are no breakpoints:
17903
17904 @smallexample
17905 (@value{GDBP})
17906 -break-list
17907 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17908 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17909 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17910 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17911 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17912 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17913 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17914 body=[]@}
17915 (@value{GDBP})
17916 @end smallexample
17917
17918 @subheading The @code{-break-watch} Command
17919 @findex -break-watch
17920
17921 @subsubheading Synopsis
17922
17923 @smallexample
17924 -break-watch [ -a | -r ]
17925 @end smallexample
17926
17927 Create a watchpoint. With the @samp{-a} option it will create an
17928 @dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17929 read from or on a write to the memory location. With the @samp{-r}
17930 option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17931 trigger only when the memory location is accessed for reading. Without
17932 either of the options, the watchpoint created is a regular watchpoint,
17933 i.e. it will trigger when the memory location is accessed for writing.
17934 @xref{Set Watchpoints, , Setting watchpoints}.
17935
17936 Note that @samp{-break-list} will report a single list of watchpoints and
17937 breakpoints inserted.
17938
17939 @subsubheading @value{GDBN} Command
17940
17941 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17942 @samp{rwatch}.
17943
17944 @subsubheading Example
17945
17946 Setting a watchpoint on a variable in the @code{main} function:
17947
17948 @smallexample
17949 (@value{GDBP})
17950 -break-watch x
17951 ^done,wpt=@{number="2",exp="x"@}
17952 (@value{GDBP})
17953 -exec-continue
17954 ^running
17955 ^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17956 value=@{old="-268439212",new="55"@},
17957 frame=@{func="main",args=[],file="recursive2.c",
17958 fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
17959 (@value{GDBP})
17960 @end smallexample
17961
17962 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17963 the program execution twice: first for the variable changing value, then
17964 for the watchpoint going out of scope.
17965
17966 @smallexample
17967 (@value{GDBP})
17968 -break-watch C
17969 ^done,wpt=@{number="5",exp="C"@}
17970 (@value{GDBP})
17971 -exec-continue
17972 ^running
17973 ^done,reason="watchpoint-trigger",
17974 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17975 frame=@{func="callee4",args=[],
17976 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17977 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
17978 (@value{GDBP})
17979 -exec-continue
17980 ^running
17981 ^done,reason="watchpoint-scope",wpnum="5",
17982 frame=@{func="callee3",args=[@{name="strarg",
17983 value="0x11940 \"A string argument.\""@}],
17984 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17985 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17986 (@value{GDBP})
17987 @end smallexample
17988
17989 Listing breakpoints and watchpoints, at different points in the program
17990 execution. Note that once the watchpoint goes out of scope, it is
17991 deleted.
17992
17993 @smallexample
17994 (@value{GDBP})
17995 -break-watch C
17996 ^done,wpt=@{number="2",exp="C"@}
17997 (@value{GDBP})
17998 -break-list
17999 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18000 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18001 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18002 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18003 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18004 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18005 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18006 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18007 addr="0x00010734",func="callee4",
18008 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18009 bkpt=@{number="2",type="watchpoint",disp="keep",
18010 enabled="y",addr="",what="C",times="0"@}]@}
18011 (@value{GDBP})
18012 -exec-continue
18013 ^running
18014 ^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
18015 value=@{old="-276895068",new="3"@},
18016 frame=@{func="callee4",args=[],
18017 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18018 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
18019 (@value{GDBP})
18020 -break-list
18021 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18022 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18023 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18024 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18025 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18026 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18027 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18028 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18029 addr="0x00010734",func="callee4",
18030 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18031 bkpt=@{number="2",type="watchpoint",disp="keep",
18032 enabled="y",addr="",what="C",times="-5"@}]@}
18033 (@value{GDBP})
18034 -exec-continue
18035 ^running
18036 ^done,reason="watchpoint-scope",wpnum="2",
18037 frame=@{func="callee3",args=[@{name="strarg",
18038 value="0x11940 \"A string argument.\""@}],
18039 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18040 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18041 (@value{GDBP})
18042 -break-list
18043 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18044 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18045 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18046 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18047 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18048 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18049 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18050 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18051 addr="0x00010734",func="callee4",
18052 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
18053 (@value{GDBP})
18054 @end smallexample
18055
18056 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18057 @node GDB/MI Data Manipulation
18058 @section @sc{gdb/mi} Data Manipulation
18059
18060 @cindex data manipulation, in @sc{gdb/mi}
18061 @cindex @sc{gdb/mi}, data manipulation
18062 This section describes the @sc{gdb/mi} commands that manipulate data:
18063 examine memory and registers, evaluate expressions, etc.
18064
18065 @c REMOVED FROM THE INTERFACE.
18066 @c @subheading -data-assign
18067 @c Change the value of a program variable. Plenty of side effects.
18068 @c @subsubheading GDB command
18069 @c set variable
18070 @c @subsubheading Example
18071 @c N.A.
18072
18073 @subheading The @code{-data-disassemble} Command
18074 @findex -data-disassemble
18075
18076 @subsubheading Synopsis
18077
18078 @smallexample
18079 -data-disassemble
18080 [ -s @var{start-addr} -e @var{end-addr} ]
18081 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
18082 -- @var{mode}
18083 @end smallexample
18084
18085 @noindent
18086 Where:
18087
18088 @table @samp
18089 @item @var{start-addr}
18090 is the beginning address (or @code{$pc})
18091 @item @var{end-addr}
18092 is the end address
18093 @item @var{filename}
18094 is the name of the file to disassemble
18095 @item @var{linenum}
18096 is the line number to disassemble around
18097 @item @var{lines}
18098 is the the number of disassembly lines to be produced. If it is -1,
18099 the whole function will be disassembled, in case no @var{end-addr} is
18100 specified. If @var{end-addr} is specified as a non-zero value, and
18101 @var{lines} is lower than the number of disassembly lines between
18102 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
18103 displayed; if @var{lines} is higher than the number of lines between
18104 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
18105 are displayed.
18106 @item @var{mode}
18107 is either 0 (meaning only disassembly) or 1 (meaning mixed source and
18108 disassembly).
18109 @end table
18110
18111 @subsubheading Result
18112
18113 The output for each instruction is composed of four fields:
18114
18115 @itemize @bullet
18116 @item Address
18117 @item Func-name
18118 @item Offset
18119 @item Instruction
18120 @end itemize
18121
18122 Note that whatever included in the instruction field, is not manipulated
18123 directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
18124
18125 @subsubheading @value{GDBN} Command
18126
18127 There's no direct mapping from this command to the CLI.
18128
18129 @subsubheading Example
18130
18131 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
18132
18133 @smallexample
18134 (@value{GDBP})
18135 -data-disassemble -s $pc -e "$pc + 20" -- 0
18136 ^done,
18137 asm_insns=[
18138 @{address="0x000107c0",func-name="main",offset="4",
18139 inst="mov 2, %o0"@},
18140 @{address="0x000107c4",func-name="main",offset="8",
18141 inst="sethi %hi(0x11800), %o2"@},
18142 @{address="0x000107c8",func-name="main",offset="12",
18143 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
18144 @{address="0x000107cc",func-name="main",offset="16",
18145 inst="sethi %hi(0x11800), %o2"@},
18146 @{address="0x000107d0",func-name="main",offset="20",
18147 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
18148 (@value{GDBP})
18149 @end smallexample
18150
18151 Disassemble the whole @code{main} function. Line 32 is part of
18152 @code{main}.
18153
18154 @smallexample
18155 -data-disassemble -f basics.c -l 32 -- 0
18156 ^done,asm_insns=[
18157 @{address="0x000107bc",func-name="main",offset="0",
18158 inst="save %sp, -112, %sp"@},
18159 @{address="0x000107c0",func-name="main",offset="4",
18160 inst="mov 2, %o0"@},
18161 @{address="0x000107c4",func-name="main",offset="8",
18162 inst="sethi %hi(0x11800), %o2"@},
18163 [@dots{}]
18164 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
18165 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
18166 (@value{GDBP})
18167 @end smallexample
18168
18169 Disassemble 3 instructions from the start of @code{main}:
18170
18171 @smallexample
18172 (@value{GDBP})
18173 -data-disassemble -f basics.c -l 32 -n 3 -- 0
18174 ^done,asm_insns=[
18175 @{address="0x000107bc",func-name="main",offset="0",
18176 inst="save %sp, -112, %sp"@},
18177 @{address="0x000107c0",func-name="main",offset="4",
18178 inst="mov 2, %o0"@},
18179 @{address="0x000107c4",func-name="main",offset="8",
18180 inst="sethi %hi(0x11800), %o2"@}]
18181 (@value{GDBP})
18182 @end smallexample
18183
18184 Disassemble 3 instructions from the start of @code{main} in mixed mode:
18185
18186 @smallexample
18187 (@value{GDBP})
18188 -data-disassemble -f basics.c -l 32 -n 3 -- 1
18189 ^done,asm_insns=[
18190 src_and_asm_line=@{line="31",
18191 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
18192 testsuite/gdb.mi/basics.c",line_asm_insn=[
18193 @{address="0x000107bc",func-name="main",offset="0",
18194 inst="save %sp, -112, %sp"@}]@},
18195 src_and_asm_line=@{line="32",
18196 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
18197 testsuite/gdb.mi/basics.c",line_asm_insn=[
18198 @{address="0x000107c0",func-name="main",offset="4",
18199 inst="mov 2, %o0"@},
18200 @{address="0x000107c4",func-name="main",offset="8",
18201 inst="sethi %hi(0x11800), %o2"@}]@}]
18202 (@value{GDBP})
18203 @end smallexample
18204
18205
18206 @subheading The @code{-data-evaluate-expression} Command
18207 @findex -data-evaluate-expression
18208
18209 @subsubheading Synopsis
18210
18211 @smallexample
18212 -data-evaluate-expression @var{expr}
18213 @end smallexample
18214
18215 Evaluate @var{expr} as an expression. The expression could contain an
18216 inferior function call. The function call will execute synchronously.
18217 If the expression contains spaces, it must be enclosed in double quotes.
18218
18219 @subsubheading @value{GDBN} Command
18220
18221 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
18222 @samp{call}. In @code{gdbtk} only, there's a corresponding
18223 @samp{gdb_eval} command.
18224
18225 @subsubheading Example
18226
18227 In the following example, the numbers that precede the commands are the
18228 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
18229 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
18230 output.
18231
18232 @smallexample
18233 211-data-evaluate-expression A
18234 211^done,value="1"
18235 (@value{GDBP})
18236 311-data-evaluate-expression &A
18237 311^done,value="0xefffeb7c"
18238 (@value{GDBP})
18239 411-data-evaluate-expression A+3
18240 411^done,value="4"
18241 (@value{GDBP})
18242 511-data-evaluate-expression "A + 3"
18243 511^done,value="4"
18244 (@value{GDBP})
18245 @end smallexample
18246
18247
18248 @subheading The @code{-data-list-changed-registers} Command
18249 @findex -data-list-changed-registers
18250
18251 @subsubheading Synopsis
18252
18253 @smallexample
18254 -data-list-changed-registers
18255 @end smallexample
18256
18257 Display a list of the registers that have changed.
18258
18259 @subsubheading @value{GDBN} Command
18260
18261 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
18262 has the corresponding command @samp{gdb_changed_register_list}.
18263
18264 @subsubheading Example
18265
18266 On a PPC MBX board:
18267
18268 @smallexample
18269 (@value{GDBP})
18270 -exec-continue
18271 ^running
18272
18273 (@value{GDBP})
18274 *stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
18275 args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
18276 (@value{GDBP})
18277 -data-list-changed-registers
18278 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
18279 "10","11","13","14","15","16","17","18","19","20","21","22","23",
18280 "24","25","26","27","28","30","31","64","65","66","67","69"]
18281 (@value{GDBP})
18282 @end smallexample
18283
18284
18285 @subheading The @code{-data-list-register-names} Command
18286 @findex -data-list-register-names
18287
18288 @subsubheading Synopsis
18289
18290 @smallexample
18291 -data-list-register-names [ ( @var{regno} )+ ]
18292 @end smallexample
18293
18294 Show a list of register names for the current target. If no arguments
18295 are given, it shows a list of the names of all the registers. If
18296 integer numbers are given as arguments, it will print a list of the
18297 names of the registers corresponding to the arguments. To ensure
18298 consistency between a register name and its number, the output list may
18299 include empty register names.
18300
18301 @subsubheading @value{GDBN} Command
18302
18303 @value{GDBN} does not have a command which corresponds to
18304 @samp{-data-list-register-names}. In @code{gdbtk} there is a
18305 corresponding command @samp{gdb_regnames}.
18306
18307 @subsubheading Example
18308
18309 For the PPC MBX board:
18310 @smallexample
18311 (@value{GDBP})
18312 -data-list-register-names
18313 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
18314 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
18315 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
18316 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
18317 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
18318 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
18319 "", "pc","ps","cr","lr","ctr","xer"]
18320 (@value{GDBP})
18321 -data-list-register-names 1 2 3
18322 ^done,register-names=["r1","r2","r3"]
18323 (@value{GDBP})
18324 @end smallexample
18325
18326 @subheading The @code{-data-list-register-values} Command
18327 @findex -data-list-register-values
18328
18329 @subsubheading Synopsis
18330
18331 @smallexample
18332 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
18333 @end smallexample
18334
18335 Display the registers' contents. @var{fmt} is the format according to
18336 which the registers' contents are to be returned, followed by an optional
18337 list of numbers specifying the registers to display. A missing list of
18338 numbers indicates that the contents of all the registers must be returned.
18339
18340 Allowed formats for @var{fmt} are:
18341
18342 @table @code
18343 @item x
18344 Hexadecimal
18345 @item o
18346 Octal
18347 @item t
18348 Binary
18349 @item d
18350 Decimal
18351 @item r
18352 Raw
18353 @item N
18354 Natural
18355 @end table
18356
18357 @subsubheading @value{GDBN} Command
18358
18359 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
18360 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
18361
18362 @subsubheading Example
18363
18364 For a PPC MBX board (note: line breaks are for readability only, they
18365 don't appear in the actual output):
18366
18367 @smallexample
18368 (@value{GDBP})
18369 -data-list-register-values r 64 65
18370 ^done,register-values=[@{number="64",value="0xfe00a300"@},
18371 @{number="65",value="0x00029002"@}]
18372 (@value{GDBP})
18373 -data-list-register-values x
18374 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
18375 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
18376 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
18377 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
18378 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
18379 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
18380 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
18381 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
18382 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
18383 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
18384 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
18385 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
18386 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
18387 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
18388 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
18389 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
18390 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
18391 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
18392 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
18393 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
18394 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
18395 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
18396 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
18397 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
18398 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
18399 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
18400 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
18401 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
18402 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
18403 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
18404 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
18405 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
18406 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
18407 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
18408 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
18409 @{number="69",value="0x20002b03"@}]
18410 (@value{GDBP})
18411 @end smallexample
18412
18413
18414 @subheading The @code{-data-read-memory} Command
18415 @findex -data-read-memory
18416
18417 @subsubheading Synopsis
18418
18419 @smallexample
18420 -data-read-memory [ -o @var{byte-offset} ]
18421 @var{address} @var{word-format} @var{word-size}
18422 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18423 @end smallexample
18424
18425 @noindent
18426 where:
18427
18428 @table @samp
18429 @item @var{address}
18430 An expression specifying the address of the first memory word to be
18431 read. Complex expressions containing embedded white space should be
18432 quoted using the C convention.
18433
18434 @item @var{word-format}
18435 The format to be used to print the memory words. The notation is the
18436 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18437 ,Output formats}).
18438
18439 @item @var{word-size}
18440 The size of each memory word in bytes.
18441
18442 @item @var{nr-rows}
18443 The number of rows in the output table.
18444
18445 @item @var{nr-cols}
18446 The number of columns in the output table.
18447
18448 @item @var{aschar}
18449 If present, indicates that each row should include an @sc{ascii} dump. The
18450 value of @var{aschar} is used as a padding character when a byte is not a
18451 member of the printable @sc{ascii} character set (printable @sc{ascii}
18452 characters are those whose code is between 32 and 126, inclusively).
18453
18454 @item @var{byte-offset}
18455 An offset to add to the @var{address} before fetching memory.
18456 @end table
18457
18458 This command displays memory contents as a table of @var{nr-rows} by
18459 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
18460 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18461 (returned as @samp{total-bytes}). Should less than the requested number
18462 of bytes be returned by the target, the missing words are identified
18463 using @samp{N/A}. The number of bytes read from the target is returned
18464 in @samp{nr-bytes} and the starting address used to read memory in
18465 @samp{addr}.
18466
18467 The address of the next/previous row or page is available in
18468 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
18469 @samp{prev-page}.
18470
18471 @subsubheading @value{GDBN} Command
18472
18473 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18474 @samp{gdb_get_mem} memory read command.
18475
18476 @subsubheading Example
18477
18478 Read six bytes of memory starting at @code{bytes+6} but then offset by
18479 @code{-6} bytes. Format as three rows of two columns. One byte per
18480 word. Display each word in hex.
18481
18482 @smallexample
18483 (@value{GDBP})
18484 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
18485 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18486 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18487 prev-page="0x0000138a",memory=[
18488 @{addr="0x00001390",data=["0x00","0x01"]@},
18489 @{addr="0x00001392",data=["0x02","0x03"]@},
18490 @{addr="0x00001394",data=["0x04","0x05"]@}]
18491 (@value{GDBP})
18492 @end smallexample
18493
18494 Read two bytes of memory starting at address @code{shorts + 64} and
18495 display as a single word formatted in decimal.
18496
18497 @smallexample
18498 (@value{GDBP})
18499 5-data-read-memory shorts+64 d 2 1 1
18500 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18501 next-row="0x00001512",prev-row="0x0000150e",
18502 next-page="0x00001512",prev-page="0x0000150e",memory=[
18503 @{addr="0x00001510",data=["128"]@}]
18504 (@value{GDBP})
18505 @end smallexample
18506
18507 Read thirty two bytes of memory starting at @code{bytes+16} and format
18508 as eight rows of four columns. Include a string encoding with @samp{x}
18509 used as the non-printable character.
18510
18511 @smallexample
18512 (@value{GDBP})
18513 4-data-read-memory bytes+16 x 1 8 4 x
18514 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18515 next-row="0x000013c0",prev-row="0x0000139c",
18516 next-page="0x000013c0",prev-page="0x00001380",memory=[
18517 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18518 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18519 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18520 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18521 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18522 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18523 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18524 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18525 (@value{GDBP})
18526 @end smallexample
18527
18528 @subheading The @code{-display-delete} Command
18529 @findex -display-delete
18530
18531 @subsubheading Synopsis
18532
18533 @smallexample
18534 -display-delete @var{number}
18535 @end smallexample
18536
18537 Delete the display @var{number}.
18538
18539 @subsubheading @value{GDBN} Command
18540
18541 The corresponding @value{GDBN} command is @samp{delete display}.
18542
18543 @subsubheading Example
18544 N.A.
18545
18546
18547 @subheading The @code{-display-disable} Command
18548 @findex -display-disable
18549
18550 @subsubheading Synopsis
18551
18552 @smallexample
18553 -display-disable @var{number}
18554 @end smallexample
18555
18556 Disable display @var{number}.
18557
18558 @subsubheading @value{GDBN} Command
18559
18560 The corresponding @value{GDBN} command is @samp{disable display}.
18561
18562 @subsubheading Example
18563 N.A.
18564
18565
18566 @subheading The @code{-display-enable} Command
18567 @findex -display-enable
18568
18569 @subsubheading Synopsis
18570
18571 @smallexample
18572 -display-enable @var{number}
18573 @end smallexample
18574
18575 Enable display @var{number}.
18576
18577 @subsubheading @value{GDBN} Command
18578
18579 The corresponding @value{GDBN} command is @samp{enable display}.
18580
18581 @subsubheading Example
18582 N.A.
18583
18584
18585 @subheading The @code{-display-insert} Command
18586 @findex -display-insert
18587
18588 @subsubheading Synopsis
18589
18590 @smallexample
18591 -display-insert @var{expression}
18592 @end smallexample
18593
18594 Display @var{expression} every time the program stops.
18595
18596 @subsubheading @value{GDBN} Command
18597
18598 The corresponding @value{GDBN} command is @samp{display}.
18599
18600 @subsubheading Example
18601 N.A.
18602
18603
18604 @subheading The @code{-display-list} Command
18605 @findex -display-list
18606
18607 @subsubheading Synopsis
18608
18609 @smallexample
18610 -display-list
18611 @end smallexample
18612
18613 List the displays. Do not show the current values.
18614
18615 @subsubheading @value{GDBN} Command
18616
18617 The corresponding @value{GDBN} command is @samp{info display}.
18618
18619 @subsubheading Example
18620 N.A.
18621
18622
18623 @subheading The @code{-environment-cd} Command
18624 @findex -environment-cd
18625
18626 @subsubheading Synopsis
18627
18628 @smallexample
18629 -environment-cd @var{pathdir}
18630 @end smallexample
18631
18632 Set @value{GDBN}'s working directory.
18633
18634 @subsubheading @value{GDBN} Command
18635
18636 The corresponding @value{GDBN} command is @samp{cd}.
18637
18638 @subsubheading Example
18639
18640 @smallexample
18641 (@value{GDBP})
18642 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18643 ^done
18644 (@value{GDBP})
18645 @end smallexample
18646
18647
18648 @subheading The @code{-environment-directory} Command
18649 @findex -environment-directory
18650
18651 @subsubheading Synopsis
18652
18653 @smallexample
18654 -environment-directory [ -r ] [ @var{pathdir} ]+
18655 @end smallexample
18656
18657 Add directories @var{pathdir} to beginning of search path for source files.
18658 If the @samp{-r} option is used, the search path is reset to the default
18659 search path. If directories @var{pathdir} are supplied in addition to the
18660 @samp{-r} option, the search path is first reset and then addition
18661 occurs as normal.
18662 Multiple directories may be specified, separated by blanks. Specifying
18663 multiple directories in a single command
18664 results in the directories added to the beginning of the
18665 search path in the same order they were presented in the command.
18666 If blanks are needed as
18667 part of a directory name, double-quotes should be used around
18668 the name. In the command output, the path will show up separated
18669 by the system directory-separator character. The directory-seperator
18670 character must not be used
18671 in any directory name.
18672 If no directories are specified, the current search path is displayed.
18673
18674 @subsubheading @value{GDBN} Command
18675
18676 The corresponding @value{GDBN} command is @samp{dir}.
18677
18678 @subsubheading Example
18679
18680 @smallexample
18681 (@value{GDBP})
18682 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18683 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18684 (@value{GDBP})
18685 -environment-directory ""
18686 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18687 (@value{GDBP})
18688 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
18689 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18690 (@value{GDBP})
18691 -environment-directory -r
18692 ^done,source-path="$cdir:$cwd"
18693 (@value{GDBP})
18694 @end smallexample
18695
18696
18697 @subheading The @code{-environment-path} Command
18698 @findex -environment-path
18699
18700 @subsubheading Synopsis
18701
18702 @smallexample
18703 -environment-path [ -r ] [ @var{pathdir} ]+
18704 @end smallexample
18705
18706 Add directories @var{pathdir} to beginning of search path for object files.
18707 If the @samp{-r} option is used, the search path is reset to the original
18708 search path that existed at gdb start-up. If directories @var{pathdir} are
18709 supplied in addition to the
18710 @samp{-r} option, the search path is first reset and then addition
18711 occurs as normal.
18712 Multiple directories may be specified, separated by blanks. Specifying
18713 multiple directories in a single command
18714 results in the directories added to the beginning of the
18715 search path in the same order they were presented in the command.
18716 If blanks are needed as
18717 part of a directory name, double-quotes should be used around
18718 the name. In the command output, the path will show up separated
18719 by the system directory-separator character. The directory-seperator
18720 character must not be used
18721 in any directory name.
18722 If no directories are specified, the current path is displayed.
18723
18724
18725 @subsubheading @value{GDBN} Command
18726
18727 The corresponding @value{GDBN} command is @samp{path}.
18728
18729 @subsubheading Example
18730
18731 @smallexample
18732 (@value{GDBP})
18733 -environment-path
18734 ^done,path="/usr/bin"
18735 (@value{GDBP})
18736 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18737 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18738 (@value{GDBP})
18739 -environment-path -r /usr/local/bin
18740 ^done,path="/usr/local/bin:/usr/bin"
18741 (@value{GDBP})
18742 @end smallexample
18743
18744
18745 @subheading The @code{-environment-pwd} Command
18746 @findex -environment-pwd
18747
18748 @subsubheading Synopsis
18749
18750 @smallexample
18751 -environment-pwd
18752 @end smallexample
18753
18754 Show the current working directory.
18755
18756 @subsubheading @value{GDBN} command
18757
18758 The corresponding @value{GDBN} command is @samp{pwd}.
18759
18760 @subsubheading Example
18761
18762 @smallexample
18763 (@value{GDBP})
18764 -environment-pwd
18765 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18766 (@value{GDBP})
18767 @end smallexample
18768
18769 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18770 @node GDB/MI Program Control
18771 @section @sc{gdb/mi} Program control
18772
18773 @subsubheading Program termination
18774
18775 As a result of execution, the inferior program can run to completion, if
18776 it doesn't encounter any breakpoints. In this case the output will
18777 include an exit code, if the program has exited exceptionally.
18778
18779 @subsubheading Examples
18780
18781 @noindent
18782 Program exited normally:
18783
18784 @smallexample
18785 (@value{GDBP})
18786 -exec-run
18787 ^running
18788 (@value{GDBP})
18789 x = 55
18790 *stopped,reason="exited-normally"
18791 (@value{GDBP})
18792 @end smallexample
18793
18794 @noindent
18795 Program exited exceptionally:
18796
18797 @smallexample
18798 (@value{GDBP})
18799 -exec-run
18800 ^running
18801 (@value{GDBP})
18802 x = 55
18803 *stopped,reason="exited",exit-code="01"
18804 (@value{GDBP})
18805 @end smallexample
18806
18807 Another way the program can terminate is if it receives a signal such as
18808 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18809
18810 @smallexample
18811 (@value{GDBP})
18812 *stopped,reason="exited-signalled",signal-name="SIGINT",
18813 signal-meaning="Interrupt"
18814 @end smallexample
18815
18816
18817 @subheading The @code{-exec-abort} Command
18818 @findex -exec-abort
18819
18820 @subsubheading Synopsis
18821
18822 @smallexample
18823 -exec-abort
18824 @end smallexample
18825
18826 Kill the inferior running program.
18827
18828 @subsubheading @value{GDBN} Command
18829
18830 The corresponding @value{GDBN} command is @samp{kill}.
18831
18832 @subsubheading Example
18833 N.A.
18834
18835
18836 @subheading The @code{-exec-arguments} Command
18837 @findex -exec-arguments
18838
18839 @subsubheading Synopsis
18840
18841 @smallexample
18842 -exec-arguments @var{args}
18843 @end smallexample
18844
18845 Set the inferior program arguments, to be used in the next
18846 @samp{-exec-run}.
18847
18848 @subsubheading @value{GDBN} Command
18849
18850 The corresponding @value{GDBN} command is @samp{set args}.
18851
18852 @subsubheading Example
18853
18854 @c FIXME!
18855 Don't have one around.
18856
18857
18858 @subheading The @code{-exec-continue} Command
18859 @findex -exec-continue
18860
18861 @subsubheading Synopsis
18862
18863 @smallexample
18864 -exec-continue
18865 @end smallexample
18866
18867 Asynchronous command. Resumes the execution of the inferior program
18868 until a breakpoint is encountered, or until the inferior exits.
18869
18870 @subsubheading @value{GDBN} Command
18871
18872 The corresponding @value{GDBN} corresponding is @samp{continue}.
18873
18874 @subsubheading Example
18875
18876 @smallexample
18877 -exec-continue
18878 ^running
18879 (@value{GDBP})
18880 @@Hello world
18881 *stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
18882 file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
18883 (@value{GDBP})
18884 @end smallexample
18885
18886
18887 @subheading The @code{-exec-finish} Command
18888 @findex -exec-finish
18889
18890 @subsubheading Synopsis
18891
18892 @smallexample
18893 -exec-finish
18894 @end smallexample
18895
18896 Asynchronous command. Resumes the execution of the inferior program
18897 until the current function is exited. Displays the results returned by
18898 the function.
18899
18900 @subsubheading @value{GDBN} Command
18901
18902 The corresponding @value{GDBN} command is @samp{finish}.
18903
18904 @subsubheading Example
18905
18906 Function returning @code{void}.
18907
18908 @smallexample
18909 -exec-finish
18910 ^running
18911 (@value{GDBP})
18912 @@hello from foo
18913 *stopped,reason="function-finished",frame=@{func="main",args=[],
18914 file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
18915 (@value{GDBP})
18916 @end smallexample
18917
18918 Function returning other than @code{void}. The name of the internal
18919 @value{GDBN} variable storing the result is printed, together with the
18920 value itself.
18921
18922 @smallexample
18923 -exec-finish
18924 ^running
18925 (@value{GDBP})
18926 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18927 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
18928 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
18929 gdb-result-var="$1",return-value="0"
18930 (@value{GDBP})
18931 @end smallexample
18932
18933
18934 @subheading The @code{-exec-interrupt} Command
18935 @findex -exec-interrupt
18936
18937 @subsubheading Synopsis
18938
18939 @smallexample
18940 -exec-interrupt
18941 @end smallexample
18942
18943 Asynchronous command. Interrupts the background execution of the target.
18944 Note how the token associated with the stop message is the one for the
18945 execution command that has been interrupted. The token for the interrupt
18946 itself only appears in the @samp{^done} output. If the user is trying to
18947 interrupt a non-running program, an error message will be printed.
18948
18949 @subsubheading @value{GDBN} Command
18950
18951 The corresponding @value{GDBN} command is @samp{interrupt}.
18952
18953 @subsubheading Example
18954
18955 @smallexample
18956 (@value{GDBP})
18957 111-exec-continue
18958 111^running
18959
18960 (@value{GDBP})
18961 222-exec-interrupt
18962 222^done
18963 (@value{GDBP})
18964 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
18965 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18966 fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
18967 (@value{GDBP})
18968
18969 (@value{GDBP})
18970 -exec-interrupt
18971 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18972 (@value{GDBP})
18973 @end smallexample
18974
18975
18976 @subheading The @code{-exec-next} Command
18977 @findex -exec-next
18978
18979 @subsubheading Synopsis
18980
18981 @smallexample
18982 -exec-next
18983 @end smallexample
18984
18985 Asynchronous command. Resumes execution of the inferior program, stopping
18986 when the beginning of the next source line is reached.
18987
18988 @subsubheading @value{GDBN} Command
18989
18990 The corresponding @value{GDBN} command is @samp{next}.
18991
18992 @subsubheading Example
18993
18994 @smallexample
18995 -exec-next
18996 ^running
18997 (@value{GDBP})
18998 *stopped,reason="end-stepping-range",line="8",file="hello.c"
18999 (@value{GDBP})
19000 @end smallexample
19001
19002
19003 @subheading The @code{-exec-next-instruction} Command
19004 @findex -exec-next-instruction
19005
19006 @subsubheading Synopsis
19007
19008 @smallexample
19009 -exec-next-instruction
19010 @end smallexample
19011
19012 Asynchronous command. Executes one machine instruction. If the
19013 instruction is a function call continues until the function returns. If
19014 the program stops at an instruction in the middle of a source line, the
19015 address will be printed as well.
19016
19017 @subsubheading @value{GDBN} Command
19018
19019 The corresponding @value{GDBN} command is @samp{nexti}.
19020
19021 @subsubheading Example
19022
19023 @smallexample
19024 (@value{GDBP})
19025 -exec-next-instruction
19026 ^running
19027
19028 (@value{GDBP})
19029 *stopped,reason="end-stepping-range",
19030 addr="0x000100d4",line="5",file="hello.c"
19031 (@value{GDBP})
19032 @end smallexample
19033
19034
19035 @subheading The @code{-exec-return} Command
19036 @findex -exec-return
19037
19038 @subsubheading Synopsis
19039
19040 @smallexample
19041 -exec-return
19042 @end smallexample
19043
19044 Makes current function return immediately. Doesn't execute the inferior.
19045 Displays the new current frame.
19046
19047 @subsubheading @value{GDBN} Command
19048
19049 The corresponding @value{GDBN} command is @samp{return}.
19050
19051 @subsubheading Example
19052
19053 @smallexample
19054 (@value{GDBP})
19055 200-break-insert callee4
19056 200^done,bkpt=@{number="1",addr="0x00010734",
19057 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19058 (@value{GDBP})
19059 000-exec-run
19060 000^running
19061 (@value{GDBP})
19062 000*stopped,reason="breakpoint-hit",bkptno="1",
19063 frame=@{func="callee4",args=[],
19064 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19065 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19066 (@value{GDBP})
19067 205-break-delete
19068 205^done
19069 (@value{GDBP})
19070 111-exec-return
19071 111^done,frame=@{level="0",func="callee3",
19072 args=[@{name="strarg",
19073 value="0x11940 \"A string argument.\""@}],
19074 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19075 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
19076 (@value{GDBP})
19077 @end smallexample
19078
19079
19080 @subheading The @code{-exec-run} Command
19081 @findex -exec-run
19082
19083 @subsubheading Synopsis
19084
19085 @smallexample
19086 -exec-run
19087 @end smallexample
19088
19089 Asynchronous command. Starts execution of the inferior from the
19090 beginning. The inferior executes until either a breakpoint is
19091 encountered or the program exits.
19092
19093 @subsubheading @value{GDBN} Command
19094
19095 The corresponding @value{GDBN} command is @samp{run}.
19096
19097 @subsubheading Example
19098
19099 @smallexample
19100 (@value{GDBP})
19101 -break-insert main
19102 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
19103 (@value{GDBP})
19104 -exec-run
19105 ^running
19106 (@value{GDBP})
19107 *stopped,reason="breakpoint-hit",bkptno="1",
19108 frame=@{func="main",args=[],file="recursive2.c",
19109 fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
19110 (@value{GDBP})
19111 @end smallexample
19112
19113
19114 @subheading The @code{-exec-show-arguments} Command
19115 @findex -exec-show-arguments
19116
19117 @subsubheading Synopsis
19118
19119 @smallexample
19120 -exec-show-arguments
19121 @end smallexample
19122
19123 Print the arguments of the program.
19124
19125 @subsubheading @value{GDBN} Command
19126
19127 The corresponding @value{GDBN} command is @samp{show args}.
19128
19129 @subsubheading Example
19130 N.A.
19131
19132 @c @subheading -exec-signal
19133
19134 @subheading The @code{-exec-step} Command
19135 @findex -exec-step
19136
19137 @subsubheading Synopsis
19138
19139 @smallexample
19140 -exec-step
19141 @end smallexample
19142
19143 Asynchronous command. Resumes execution of the inferior program, stopping
19144 when the beginning of the next source line is reached, if the next
19145 source line is not a function call. If it is, stop at the first
19146 instruction of the called function.
19147
19148 @subsubheading @value{GDBN} Command
19149
19150 The corresponding @value{GDBN} command is @samp{step}.
19151
19152 @subsubheading Example
19153
19154 Stepping into a function:
19155
19156 @smallexample
19157 -exec-step
19158 ^running
19159 (@value{GDBP})
19160 *stopped,reason="end-stepping-range",
19161 frame=@{func="foo",args=[@{name="a",value="10"@},
19162 @{name="b",value="0"@}],file="recursive2.c",
19163 fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
19164 (@value{GDBP})
19165 @end smallexample
19166
19167 Regular stepping:
19168
19169 @smallexample
19170 -exec-step
19171 ^running
19172 (@value{GDBP})
19173 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
19174 (@value{GDBP})
19175 @end smallexample
19176
19177
19178 @subheading The @code{-exec-step-instruction} Command
19179 @findex -exec-step-instruction
19180
19181 @subsubheading Synopsis
19182
19183 @smallexample
19184 -exec-step-instruction
19185 @end smallexample
19186
19187 Asynchronous command. Resumes the inferior which executes one machine
19188 instruction. The output, once @value{GDBN} has stopped, will vary depending on
19189 whether we have stopped in the middle of a source line or not. In the
19190 former case, the address at which the program stopped will be printed as
19191 well.
19192
19193 @subsubheading @value{GDBN} Command
19194
19195 The corresponding @value{GDBN} command is @samp{stepi}.
19196
19197 @subsubheading Example
19198
19199 @smallexample
19200 (@value{GDBP})
19201 -exec-step-instruction
19202 ^running
19203
19204 (@value{GDBP})
19205 *stopped,reason="end-stepping-range",
19206 frame=@{func="foo",args=[],file="try.c",
19207 fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
19208 (@value{GDBP})
19209 -exec-step-instruction
19210 ^running
19211
19212 (@value{GDBP})
19213 *stopped,reason="end-stepping-range",
19214 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
19215 fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
19216 (@value{GDBP})
19217 @end smallexample
19218
19219
19220 @subheading The @code{-exec-until} Command
19221 @findex -exec-until
19222
19223 @subsubheading Synopsis
19224
19225 @smallexample
19226 -exec-until [ @var{location} ]
19227 @end smallexample
19228
19229 Asynchronous command. Executes the inferior until the @var{location}
19230 specified in the argument is reached. If there is no argument, the inferior
19231 executes until a source line greater than the current one is reached.
19232 The reason for stopping in this case will be @samp{location-reached}.
19233
19234 @subsubheading @value{GDBN} Command
19235
19236 The corresponding @value{GDBN} command is @samp{until}.
19237
19238 @subsubheading Example
19239
19240 @smallexample
19241 (@value{GDBP})
19242 -exec-until recursive2.c:6
19243 ^running
19244 (@value{GDBP})
19245 x = 55
19246 *stopped,reason="location-reached",frame=@{func="main",args=[],
19247 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
19248 (@value{GDBP})
19249 @end smallexample
19250
19251 @ignore
19252 @subheading -file-clear
19253 Is this going away????
19254 @end ignore
19255
19256
19257 @subheading The @code{-file-exec-and-symbols} Command
19258 @findex -file-exec-and-symbols
19259
19260 @subsubheading Synopsis
19261
19262 @smallexample
19263 -file-exec-and-symbols @var{file}
19264 @end smallexample
19265
19266 Specify the executable file to be debugged. This file is the one from
19267 which the symbol table is also read. If no file is specified, the
19268 command clears the executable and symbol information. If breakpoints
19269 are set when using this command with no arguments, @value{GDBN} will produce
19270 error messages. Otherwise, no output is produced, except a completion
19271 notification.
19272
19273 @subsubheading @value{GDBN} Command
19274
19275 The corresponding @value{GDBN} command is @samp{file}.
19276
19277 @subsubheading Example
19278
19279 @smallexample
19280 (@value{GDBP})
19281 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19282 ^done
19283 (@value{GDBP})
19284 @end smallexample
19285
19286
19287 @subheading The @code{-file-exec-file} Command
19288 @findex -file-exec-file
19289
19290 @subsubheading Synopsis
19291
19292 @smallexample
19293 -file-exec-file @var{file}
19294 @end smallexample
19295
19296 Specify the executable file to be debugged. Unlike
19297 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
19298 from this file. If used without argument, @value{GDBN} clears the information
19299 about the executable file. No output is produced, except a completion
19300 notification.
19301
19302 @subsubheading @value{GDBN} Command
19303
19304 The corresponding @value{GDBN} command is @samp{exec-file}.
19305
19306 @subsubheading Example
19307
19308 @smallexample
19309 (@value{GDBP})
19310 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19311 ^done
19312 (@value{GDBP})
19313 @end smallexample
19314
19315
19316 @subheading The @code{-file-list-exec-sections} Command
19317 @findex -file-list-exec-sections
19318
19319 @subsubheading Synopsis
19320
19321 @smallexample
19322 -file-list-exec-sections
19323 @end smallexample
19324
19325 List the sections of the current executable file.
19326
19327 @subsubheading @value{GDBN} Command
19328
19329 The @value{GDBN} command @samp{info file} shows, among the rest, the same
19330 information as this command. @code{gdbtk} has a corresponding command
19331 @samp{gdb_load_info}.
19332
19333 @subsubheading Example
19334 N.A.
19335
19336
19337 @subheading The @code{-file-list-exec-source-file} Command
19338 @findex -file-list-exec-source-file
19339
19340 @subsubheading Synopsis
19341
19342 @smallexample
19343 -file-list-exec-source-file
19344 @end smallexample
19345
19346 List the line number, the current source file, and the absolute path
19347 to the current source file for the current executable.
19348
19349 @subsubheading @value{GDBN} Command
19350
19351 There's no @value{GDBN} command which directly corresponds to this one.
19352
19353 @subsubheading Example
19354
19355 @smallexample
19356 (@value{GDBP})
19357 123-file-list-exec-source-file
19358 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
19359 (@value{GDBP})
19360 @end smallexample
19361
19362
19363 @subheading The @code{-file-list-exec-source-files} Command
19364 @findex -file-list-exec-source-files
19365
19366 @subsubheading Synopsis
19367
19368 @smallexample
19369 -file-list-exec-source-files
19370 @end smallexample
19371
19372 List the source files for the current executable.
19373
19374 It will always output the filename, but only when GDB can find the absolute
19375 file name of a source file, will it output the fullname.
19376
19377 @subsubheading @value{GDBN} Command
19378
19379 There's no @value{GDBN} command which directly corresponds to this one.
19380 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
19381
19382 @subsubheading Example
19383 @smallexample
19384 (@value{GDBP})
19385 -file-list-exec-source-files
19386 ^done,files=[
19387 @{file=foo.c,fullname=/home/foo.c@},
19388 @{file=/home/bar.c,fullname=/home/bar.c@},
19389 @{file=gdb_could_not_find_fullpath.c@}]
19390 (@value{GDBP})
19391 @end smallexample
19392
19393 @subheading The @code{-file-list-shared-libraries} Command
19394 @findex -file-list-shared-libraries
19395
19396 @subsubheading Synopsis
19397
19398 @smallexample
19399 -file-list-shared-libraries
19400 @end smallexample
19401
19402 List the shared libraries in the program.
19403
19404 @subsubheading @value{GDBN} Command
19405
19406 The corresponding @value{GDBN} command is @samp{info shared}.
19407
19408 @subsubheading Example
19409 N.A.
19410
19411
19412 @subheading The @code{-file-list-symbol-files} Command
19413 @findex -file-list-symbol-files
19414
19415 @subsubheading Synopsis
19416
19417 @smallexample
19418 -file-list-symbol-files
19419 @end smallexample
19420
19421 List symbol files.
19422
19423 @subsubheading @value{GDBN} Command
19424
19425 The corresponding @value{GDBN} command is @samp{info file} (part of it).
19426
19427 @subsubheading Example
19428 N.A.
19429
19430
19431 @subheading The @code{-file-symbol-file} Command
19432 @findex -file-symbol-file
19433
19434 @subsubheading Synopsis
19435
19436 @smallexample
19437 -file-symbol-file @var{file}
19438 @end smallexample
19439
19440 Read symbol table info from the specified @var{file} argument. When
19441 used without arguments, clears @value{GDBN}'s symbol table info. No output is
19442 produced, except for a completion notification.
19443
19444 @subsubheading @value{GDBN} Command
19445
19446 The corresponding @value{GDBN} command is @samp{symbol-file}.
19447
19448 @subsubheading Example
19449
19450 @smallexample
19451 (@value{GDBP})
19452 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19453 ^done
19454 (@value{GDBP})
19455 @end smallexample
19456
19457 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19458 @node GDB/MI Miscellaneous Commands
19459 @section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19460
19461 @c @subheading -gdb-complete
19462
19463 @subheading The @code{-gdb-exit} Command
19464 @findex -gdb-exit
19465
19466 @subsubheading Synopsis
19467
19468 @smallexample
19469 -gdb-exit
19470 @end smallexample
19471
19472 Exit @value{GDBN} immediately.
19473
19474 @subsubheading @value{GDBN} Command
19475
19476 Approximately corresponds to @samp{quit}.
19477
19478 @subsubheading Example
19479
19480 @smallexample
19481 (@value{GDBP})
19482 -gdb-exit
19483 @end smallexample
19484
19485 @subheading The @code{-gdb-set} Command
19486 @findex -gdb-set
19487
19488 @subsubheading Synopsis
19489
19490 @smallexample
19491 -gdb-set
19492 @end smallexample
19493
19494 Set an internal @value{GDBN} variable.
19495 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19496
19497 @subsubheading @value{GDBN} Command
19498
19499 The corresponding @value{GDBN} command is @samp{set}.
19500
19501 @subsubheading Example
19502
19503 @smallexample
19504 (@value{GDBP})
19505 -gdb-set $foo=3
19506 ^done
19507 (@value{GDBP})
19508 @end smallexample
19509
19510
19511 @subheading The @code{-gdb-show} Command
19512 @findex -gdb-show
19513
19514 @subsubheading Synopsis
19515
19516 @smallexample
19517 -gdb-show
19518 @end smallexample
19519
19520 Show the current value of a @value{GDBN} variable.
19521
19522 @subsubheading @value{GDBN} command
19523
19524 The corresponding @value{GDBN} command is @samp{show}.
19525
19526 @subsubheading Example
19527
19528 @smallexample
19529 (@value{GDBP})
19530 -gdb-show annotate
19531 ^done,value="0"
19532 (@value{GDBP})
19533 @end smallexample
19534
19535 @c @subheading -gdb-source
19536
19537
19538 @subheading The @code{-gdb-version} Command
19539 @findex -gdb-version
19540
19541 @subsubheading Synopsis
19542
19543 @smallexample
19544 -gdb-version
19545 @end smallexample
19546
19547 Show version information for @value{GDBN}. Used mostly in testing.
19548
19549 @subsubheading @value{GDBN} Command
19550
19551 There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19552 information when you start an interactive session.
19553
19554 @subsubheading Example
19555
19556 @c This example modifies the actual output from GDB to avoid overfull
19557 @c box in TeX.
19558 @smallexample
19559 (@value{GDBP})
19560 -gdb-version
19561 ~GNU gdb 5.2.1
19562 ~Copyright 2000 Free Software Foundation, Inc.
19563 ~GDB is free software, covered by the GNU General Public License, and
19564 ~you are welcome to change it and/or distribute copies of it under
19565 ~ certain conditions.
19566 ~Type "show copying" to see the conditions.
19567 ~There is absolutely no warranty for GDB. Type "show warranty" for
19568 ~ details.
19569 ~This GDB was configured as
19570 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19571 ^done
19572 (@value{GDBP})
19573 @end smallexample
19574
19575 @subheading The @code{-interpreter-exec} Command
19576 @findex -interpreter-exec
19577
19578 @subheading Synopsis
19579
19580 @smallexample
19581 -interpreter-exec @var{interpreter} @var{command}
19582 @end smallexample
19583
19584 Execute the specified @var{command} in the given @var{interpreter}.
19585
19586 @subheading @value{GDBN} Command
19587
19588 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19589
19590 @subheading Example
19591
19592 @smallexample
19593 (@value{GDBP})
19594 -interpreter-exec console "break main"
19595 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
19596 &"During symbol reading, bad structure-type format.\n"
19597 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19598 ^done
19599 (@value{GDBP})
19600 @end smallexample
19601
19602 @subheading The @code{-inferior-tty-set} Command
19603 @findex -inferior-tty-set
19604
19605 @subheading Synopsis
19606
19607 @smallexample
19608 -inferior-tty-set /dev/pts/1
19609 @end smallexample
19610
19611 Set terminal for future runs of the program being debugged.
19612
19613 @subheading @value{GDBN} Command
19614
19615 The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19616
19617 @subheading Example
19618
19619 @smallexample
19620 (@value{GDBP})
19621 -inferior-tty-set /dev/pts/1
19622 ^done
19623 (@value{GDBP})
19624 @end smallexample
19625
19626 @subheading The @code{-inferior-tty-show} Command
19627 @findex -inferior-tty-show
19628
19629 @subheading Synopsis
19630
19631 @smallexample
19632 -inferior-tty-show
19633 @end smallexample
19634
19635 Show terminal for future runs of program being debugged.
19636
19637 @subheading @value{GDBN} Command
19638
19639 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
19640
19641 @subheading Example
19642
19643 @smallexample
19644 (@value{GDBP})
19645 -inferior-tty-set /dev/pts/1
19646 ^done
19647 (@value{GDBP})
19648 -inferior-tty-show
19649 ^done,inferior_tty_terminal="/dev/pts/1"
19650 (@value{GDBP})
19651 @end smallexample
19652
19653 @ignore
19654 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19655 @node GDB/MI Kod Commands
19656 @section @sc{gdb/mi} Kod Commands
19657
19658 The Kod commands are not implemented.
19659
19660 @c @subheading -kod-info
19661
19662 @c @subheading -kod-list
19663
19664 @c @subheading -kod-list-object-types
19665
19666 @c @subheading -kod-show
19667
19668 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19669 @node GDB/MI Memory Overlay Commands
19670 @section @sc{gdb/mi} Memory Overlay Commands
19671
19672 The memory overlay commands are not implemented.
19673
19674 @c @subheading -overlay-auto
19675
19676 @c @subheading -overlay-list-mapping-state
19677
19678 @c @subheading -overlay-list-overlays
19679
19680 @c @subheading -overlay-map
19681
19682 @c @subheading -overlay-off
19683
19684 @c @subheading -overlay-on
19685
19686 @c @subheading -overlay-unmap
19687
19688 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19689 @node GDB/MI Signal Handling Commands
19690 @section @sc{gdb/mi} Signal Handling Commands
19691
19692 Signal handling commands are not implemented.
19693
19694 @c @subheading -signal-handle
19695
19696 @c @subheading -signal-list-handle-actions
19697
19698 @c @subheading -signal-list-signal-types
19699 @end ignore
19700
19701
19702 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19703 @node GDB/MI Stack Manipulation
19704 @section @sc{gdb/mi} Stack Manipulation Commands
19705
19706
19707 @subheading The @code{-stack-info-frame} Command
19708 @findex -stack-info-frame
19709
19710 @subsubheading Synopsis
19711
19712 @smallexample
19713 -stack-info-frame
19714 @end smallexample
19715
19716 Get info on the selected frame.
19717
19718 @subsubheading @value{GDBN} Command
19719
19720 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19721 (without arguments).
19722
19723 @subsubheading Example
19724
19725 @smallexample
19726 (@value{GDBP})
19727 -stack-info-frame
19728 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19729 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19730 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19731 (@value{GDBP})
19732 @end smallexample
19733
19734 @subheading The @code{-stack-info-depth} Command
19735 @findex -stack-info-depth
19736
19737 @subsubheading Synopsis
19738
19739 @smallexample
19740 -stack-info-depth [ @var{max-depth} ]
19741 @end smallexample
19742
19743 Return the depth of the stack. If the integer argument @var{max-depth}
19744 is specified, do not count beyond @var{max-depth} frames.
19745
19746 @subsubheading @value{GDBN} Command
19747
19748 There's no equivalent @value{GDBN} command.
19749
19750 @subsubheading Example
19751
19752 For a stack with frame levels 0 through 11:
19753
19754 @smallexample
19755 (@value{GDBP})
19756 -stack-info-depth
19757 ^done,depth="12"
19758 (@value{GDBP})
19759 -stack-info-depth 4
19760 ^done,depth="4"
19761 (@value{GDBP})
19762 -stack-info-depth 12
19763 ^done,depth="12"
19764 (@value{GDBP})
19765 -stack-info-depth 11
19766 ^done,depth="11"
19767 (@value{GDBP})
19768 -stack-info-depth 13
19769 ^done,depth="12"
19770 (@value{GDBP})
19771 @end smallexample
19772
19773 @subheading The @code{-stack-list-arguments} Command
19774 @findex -stack-list-arguments
19775
19776 @subsubheading Synopsis
19777
19778 @smallexample
19779 -stack-list-arguments @var{show-values}
19780 [ @var{low-frame} @var{high-frame} ]
19781 @end smallexample
19782
19783 Display a list of the arguments for the frames between @var{low-frame}
19784 and @var{high-frame} (inclusive). If @var{low-frame} and
19785 @var{high-frame} are not provided, list the arguments for the whole call
19786 stack.
19787
19788 The @var{show-values} argument must have a value of 0 or 1. A value of
19789 0 means that only the names of the arguments are listed, a value of 1
19790 means that both names and values of the arguments are printed.
19791
19792 @subsubheading @value{GDBN} Command
19793
19794 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19795 @samp{gdb_get_args} command which partially overlaps with the
19796 functionality of @samp{-stack-list-arguments}.
19797
19798 @subsubheading Example
19799
19800 @smallexample
19801 (@value{GDBP})
19802 -stack-list-frames
19803 ^done,
19804 stack=[
19805 frame=@{level="0",addr="0x00010734",func="callee4",
19806 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19807 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
19808 frame=@{level="1",addr="0x0001076c",func="callee3",
19809 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19810 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
19811 frame=@{level="2",addr="0x0001078c",func="callee2",
19812 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19813 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
19814 frame=@{level="3",addr="0x000107b4",func="callee1",
19815 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19816 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
19817 frame=@{level="4",addr="0x000107e0",func="main",
19818 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19819 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
19820 (@value{GDBP})
19821 -stack-list-arguments 0
19822 ^done,
19823 stack-args=[
19824 frame=@{level="0",args=[]@},
19825 frame=@{level="1",args=[name="strarg"]@},
19826 frame=@{level="2",args=[name="intarg",name="strarg"]@},
19827 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19828 frame=@{level="4",args=[]@}]
19829 (@value{GDBP})
19830 -stack-list-arguments 1
19831 ^done,
19832 stack-args=[
19833 frame=@{level="0",args=[]@},
19834 frame=@{level="1",
19835 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19836 frame=@{level="2",args=[
19837 @{name="intarg",value="2"@},
19838 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19839 @{frame=@{level="3",args=[
19840 @{name="intarg",value="2"@},
19841 @{name="strarg",value="0x11940 \"A string argument.\""@},
19842 @{name="fltarg",value="3.5"@}]@},
19843 frame=@{level="4",args=[]@}]
19844 (@value{GDBP})
19845 -stack-list-arguments 0 2 2
19846 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19847 (@value{GDBP})
19848 -stack-list-arguments 1 2 2
19849 ^done,stack-args=[frame=@{level="2",
19850 args=[@{name="intarg",value="2"@},
19851 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19852 (@value{GDBP})
19853 @end smallexample
19854
19855 @c @subheading -stack-list-exception-handlers
19856
19857
19858 @subheading The @code{-stack-list-frames} Command
19859 @findex -stack-list-frames
19860
19861 @subsubheading Synopsis
19862
19863 @smallexample
19864 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19865 @end smallexample
19866
19867 List the frames currently on the stack. For each frame it displays the
19868 following info:
19869
19870 @table @samp
19871 @item @var{level}
19872 The frame number, 0 being the topmost frame, i.e. the innermost function.
19873 @item @var{addr}
19874 The @code{$pc} value for that frame.
19875 @item @var{func}
19876 Function name.
19877 @item @var{file}
19878 File name of the source file where the function lives.
19879 @item @var{line}
19880 Line number corresponding to the @code{$pc}.
19881 @end table
19882
19883 If invoked without arguments, this command prints a backtrace for the
19884 whole stack. If given two integer arguments, it shows the frames whose
19885 levels are between the two arguments (inclusive). If the two arguments
19886 are equal, it shows the single frame at the corresponding level.
19887
19888 @subsubheading @value{GDBN} Command
19889
19890 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19891
19892 @subsubheading Example
19893
19894 Full stack backtrace:
19895
19896 @smallexample
19897 (@value{GDBP})
19898 -stack-list-frames
19899 ^done,stack=
19900 [frame=@{level="0",addr="0x0001076c",func="foo",
19901 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
19902 frame=@{level="1",addr="0x000107a4",func="foo",
19903 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19904 frame=@{level="2",addr="0x000107a4",func="foo",
19905 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19906 frame=@{level="3",addr="0x000107a4",func="foo",
19907 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19908 frame=@{level="4",addr="0x000107a4",func="foo",
19909 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19910 frame=@{level="5",addr="0x000107a4",func="foo",
19911 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19912 frame=@{level="6",addr="0x000107a4",func="foo",
19913 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19914 frame=@{level="7",addr="0x000107a4",func="foo",
19915 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19916 frame=@{level="8",addr="0x000107a4",func="foo",
19917 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19918 frame=@{level="9",addr="0x000107a4",func="foo",
19919 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19920 frame=@{level="10",addr="0x000107a4",func="foo",
19921 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19922 frame=@{level="11",addr="0x00010738",func="main",
19923 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
19924 (@value{GDBP})
19925 @end smallexample
19926
19927 Show frames between @var{low_frame} and @var{high_frame}:
19928
19929 @smallexample
19930 (@value{GDBP})
19931 -stack-list-frames 3 5
19932 ^done,stack=
19933 [frame=@{level="3",addr="0x000107a4",func="foo",
19934 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19935 frame=@{level="4",addr="0x000107a4",func="foo",
19936 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
19937 frame=@{level="5",addr="0x000107a4",func="foo",
19938 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
19939 (@value{GDBP})
19940 @end smallexample
19941
19942 Show a single frame:
19943
19944 @smallexample
19945 (@value{GDBP})
19946 -stack-list-frames 3 3
19947 ^done,stack=
19948 [frame=@{level="3",addr="0x000107a4",func="foo",
19949 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
19950 (@value{GDBP})
19951 @end smallexample
19952
19953
19954 @subheading The @code{-stack-list-locals} Command
19955 @findex -stack-list-locals
19956
19957 @subsubheading Synopsis
19958
19959 @smallexample
19960 -stack-list-locals @var{print-values}
19961 @end smallexample
19962
19963 Display the local variable names for the selected frame. If
19964 @var{print-values} is 0 or @code{--no-values}, print only the names of
19965 the variables; if it is 1 or @code{--all-values}, print also their
19966 values; and if it is 2 or @code{--simple-values}, print the name,
19967 type and value for simple data types and the name and type for arrays,
19968 structures and unions. In this last case, a frontend can immediately
19969 display the value of simple data types and create variable objects for
19970 other data types when the the user wishes to explore their values in
19971 more detail.
19972
19973 @subsubheading @value{GDBN} Command
19974
19975 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19976
19977 @subsubheading Example
19978
19979 @smallexample
19980 (@value{GDBP})
19981 -stack-list-locals 0
19982 ^done,locals=[name="A",name="B",name="C"]
19983 (@value{GDBP})
19984 -stack-list-locals --all-values
19985 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
19986 @{name="C",value="@{1, 2, 3@}"@}]
19987 -stack-list-locals --simple-values
19988 ^done,locals=[@{name="A",type="int",value="1"@},
19989 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
19990 (@value{GDBP})
19991 @end smallexample
19992
19993
19994 @subheading The @code{-stack-select-frame} Command
19995 @findex -stack-select-frame
19996
19997 @subsubheading Synopsis
19998
19999 @smallexample
20000 -stack-select-frame @var{framenum}
20001 @end smallexample
20002
20003 Change the selected frame. Select a different frame @var{framenum} on
20004 the stack.
20005
20006 @subsubheading @value{GDBN} Command
20007
20008 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
20009 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
20010
20011 @subsubheading Example
20012
20013 @smallexample
20014 (@value{GDBP})
20015 -stack-select-frame 2
20016 ^done
20017 (@value{GDBP})
20018 @end smallexample
20019
20020 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20021 @node GDB/MI Symbol Query
20022 @section @sc{gdb/mi} Symbol Query Commands
20023
20024
20025 @subheading The @code{-symbol-info-address} Command
20026 @findex -symbol-info-address
20027
20028 @subsubheading Synopsis
20029
20030 @smallexample
20031 -symbol-info-address @var{symbol}
20032 @end smallexample
20033
20034 Describe where @var{symbol} is stored.
20035
20036 @subsubheading @value{GDBN} Command
20037
20038 The corresponding @value{GDBN} command is @samp{info address}.
20039
20040 @subsubheading Example
20041 N.A.
20042
20043
20044 @subheading The @code{-symbol-info-file} Command
20045 @findex -symbol-info-file
20046
20047 @subsubheading Synopsis
20048
20049 @smallexample
20050 -symbol-info-file
20051 @end smallexample
20052
20053 Show the file for the symbol.
20054
20055 @subsubheading @value{GDBN} Command
20056
20057 There's no equivalent @value{GDBN} command. @code{gdbtk} has
20058 @samp{gdb_find_file}.
20059
20060 @subsubheading Example
20061 N.A.
20062
20063
20064 @subheading The @code{-symbol-info-function} Command
20065 @findex -symbol-info-function
20066
20067 @subsubheading Synopsis
20068
20069 @smallexample
20070 -symbol-info-function
20071 @end smallexample
20072
20073 Show which function the symbol lives in.
20074
20075 @subsubheading @value{GDBN} Command
20076
20077 @samp{gdb_get_function} in @code{gdbtk}.
20078
20079 @subsubheading Example
20080 N.A.
20081
20082
20083 @subheading The @code{-symbol-info-line} Command
20084 @findex -symbol-info-line
20085
20086 @subsubheading Synopsis
20087
20088 @smallexample
20089 -symbol-info-line
20090 @end smallexample
20091
20092 Show the core addresses of the code for a source line.
20093
20094 @subsubheading @value{GDBN} Command
20095
20096 The corresponding @value{GDBN} command is @samp{info line}.
20097 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
20098
20099 @subsubheading Example
20100 N.A.
20101
20102
20103 @subheading The @code{-symbol-info-symbol} Command
20104 @findex -symbol-info-symbol
20105
20106 @subsubheading Synopsis
20107
20108 @smallexample
20109 -symbol-info-symbol @var{addr}
20110 @end smallexample
20111
20112 Describe what symbol is at location @var{addr}.
20113
20114 @subsubheading @value{GDBN} Command
20115
20116 The corresponding @value{GDBN} command is @samp{info symbol}.
20117
20118 @subsubheading Example
20119 N.A.
20120
20121
20122 @subheading The @code{-symbol-list-functions} Command
20123 @findex -symbol-list-functions
20124
20125 @subsubheading Synopsis
20126
20127 @smallexample
20128 -symbol-list-functions
20129 @end smallexample
20130
20131 List the functions in the executable.
20132
20133 @subsubheading @value{GDBN} Command
20134
20135 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20136 @samp{gdb_search} in @code{gdbtk}.
20137
20138 @subsubheading Example
20139 N.A.
20140
20141
20142 @subheading The @code{-symbol-list-lines} Command
20143 @findex -symbol-list-lines
20144
20145 @subsubheading Synopsis
20146
20147 @smallexample
20148 -symbol-list-lines @var{filename}
20149 @end smallexample
20150
20151 Print the list of lines that contain code and their associated program
20152 addresses for the given source filename. The entries are sorted in
20153 ascending PC order.
20154
20155 @subsubheading @value{GDBN} Command
20156
20157 There is no corresponding @value{GDBN} command.
20158
20159 @subsubheading Example
20160 @smallexample
20161 (@value{GDBP})
20162 -symbol-list-lines basics.c
20163 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
20164 (@value{GDBP})
20165 @end smallexample
20166
20167
20168 @subheading The @code{-symbol-list-types} Command
20169 @findex -symbol-list-types
20170
20171 @subsubheading Synopsis
20172
20173 @smallexample
20174 -symbol-list-types
20175 @end smallexample
20176
20177 List all the type names.
20178
20179 @subsubheading @value{GDBN} Command
20180
20181 The corresponding commands are @samp{info types} in @value{GDBN},
20182 @samp{gdb_search} in @code{gdbtk}.
20183
20184 @subsubheading Example
20185 N.A.
20186
20187
20188 @subheading The @code{-symbol-list-variables} Command
20189 @findex -symbol-list-variables
20190
20191 @subsubheading Synopsis
20192
20193 @smallexample
20194 -symbol-list-variables
20195 @end smallexample
20196
20197 List all the global and static variable names.
20198
20199 @subsubheading @value{GDBN} Command
20200
20201 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
20202
20203 @subsubheading Example
20204 N.A.
20205
20206
20207 @subheading The @code{-symbol-locate} Command
20208 @findex -symbol-locate
20209
20210 @subsubheading Synopsis
20211
20212 @smallexample
20213 -symbol-locate
20214 @end smallexample
20215
20216 @subsubheading @value{GDBN} Command
20217
20218 @samp{gdb_loc} in @code{gdbtk}.
20219
20220 @subsubheading Example
20221 N.A.
20222
20223
20224 @subheading The @code{-symbol-type} Command
20225 @findex -symbol-type
20226
20227 @subsubheading Synopsis
20228
20229 @smallexample
20230 -symbol-type @var{variable}
20231 @end smallexample
20232
20233 Show type of @var{variable}.
20234
20235 @subsubheading @value{GDBN} Command
20236
20237 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20238 @samp{gdb_obj_variable}.
20239
20240 @subsubheading Example
20241 N.A.
20242
20243
20244 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20245 @node GDB/MI Target Manipulation
20246 @section @sc{gdb/mi} Target Manipulation Commands
20247
20248
20249 @subheading The @code{-target-attach} Command
20250 @findex -target-attach
20251
20252 @subsubheading Synopsis
20253
20254 @smallexample
20255 -target-attach @var{pid} | @var{file}
20256 @end smallexample
20257
20258 Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
20259
20260 @subsubheading @value{GDBN} command
20261
20262 The corresponding @value{GDBN} command is @samp{attach}.
20263
20264 @subsubheading Example
20265 N.A.
20266
20267
20268 @subheading The @code{-target-compare-sections} Command
20269 @findex -target-compare-sections
20270
20271 @subsubheading Synopsis
20272
20273 @smallexample
20274 -target-compare-sections [ @var{section} ]
20275 @end smallexample
20276
20277 Compare data of section @var{section} on target to the exec file.
20278 Without the argument, all sections are compared.
20279
20280 @subsubheading @value{GDBN} Command
20281
20282 The @value{GDBN} equivalent is @samp{compare-sections}.
20283
20284 @subsubheading Example
20285 N.A.
20286
20287
20288 @subheading The @code{-target-detach} Command
20289 @findex -target-detach
20290
20291 @subsubheading Synopsis
20292
20293 @smallexample
20294 -target-detach
20295 @end smallexample
20296
20297 Disconnect from the remote target. There's no output.
20298
20299 @subsubheading @value{GDBN} command
20300
20301 The corresponding @value{GDBN} command is @samp{detach}.
20302
20303 @subsubheading Example
20304
20305 @smallexample
20306 (@value{GDBP})
20307 -target-detach
20308 ^done
20309 (@value{GDBP})
20310 @end smallexample
20311
20312
20313 @subheading The @code{-target-disconnect} Command
20314 @findex -target-disconnect
20315
20316 @subsubheading Synopsis
20317
20318 @example
20319 -target-disconnect
20320 @end example
20321
20322 Disconnect from the remote target. There's no output.
20323
20324 @subsubheading @value{GDBN} command
20325
20326 The corresponding @value{GDBN} command is @samp{disconnect}.
20327
20328 @subsubheading Example
20329
20330 @smallexample
20331 (@value{GDBP})
20332 -target-disconnect
20333 ^done
20334 (@value{GDBP})
20335 @end smallexample
20336
20337
20338 @subheading The @code{-target-download} Command
20339 @findex -target-download
20340
20341 @subsubheading Synopsis
20342
20343 @smallexample
20344 -target-download
20345 @end smallexample
20346
20347 Loads the executable onto the remote target.
20348 It prints out an update message every half second, which includes the fields:
20349
20350 @table @samp
20351 @item section
20352 The name of the section.
20353 @item section-sent
20354 The size of what has been sent so far for that section.
20355 @item section-size
20356 The size of the section.
20357 @item total-sent
20358 The total size of what was sent so far (the current and the previous sections).
20359 @item total-size
20360 The size of the overall executable to download.
20361 @end table
20362
20363 @noindent
20364 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
20365 @sc{gdb/mi} Output Syntax}).
20366
20367 In addition, it prints the name and size of the sections, as they are
20368 downloaded. These messages include the following fields:
20369
20370 @table @samp
20371 @item section
20372 The name of the section.
20373 @item section-size
20374 The size of the section.
20375 @item total-size
20376 The size of the overall executable to download.
20377 @end table
20378
20379 @noindent
20380 At the end, a summary is printed.
20381
20382 @subsubheading @value{GDBN} Command
20383
20384 The corresponding @value{GDBN} command is @samp{load}.
20385
20386 @subsubheading Example
20387
20388 Note: each status message appears on a single line. Here the messages
20389 have been broken down so that they can fit onto a page.
20390
20391 @smallexample
20392 (@value{GDBP})
20393 -target-download
20394 +download,@{section=".text",section-size="6668",total-size="9880"@}
20395 +download,@{section=".text",section-sent="512",section-size="6668",
20396 total-sent="512",total-size="9880"@}
20397 +download,@{section=".text",section-sent="1024",section-size="6668",
20398 total-sent="1024",total-size="9880"@}
20399 +download,@{section=".text",section-sent="1536",section-size="6668",
20400 total-sent="1536",total-size="9880"@}
20401 +download,@{section=".text",section-sent="2048",section-size="6668",
20402 total-sent="2048",total-size="9880"@}
20403 +download,@{section=".text",section-sent="2560",section-size="6668",
20404 total-sent="2560",total-size="9880"@}
20405 +download,@{section=".text",section-sent="3072",section-size="6668",
20406 total-sent="3072",total-size="9880"@}
20407 +download,@{section=".text",section-sent="3584",section-size="6668",
20408 total-sent="3584",total-size="9880"@}
20409 +download,@{section=".text",section-sent="4096",section-size="6668",
20410 total-sent="4096",total-size="9880"@}
20411 +download,@{section=".text",section-sent="4608",section-size="6668",
20412 total-sent="4608",total-size="9880"@}
20413 +download,@{section=".text",section-sent="5120",section-size="6668",
20414 total-sent="5120",total-size="9880"@}
20415 +download,@{section=".text",section-sent="5632",section-size="6668",
20416 total-sent="5632",total-size="9880"@}
20417 +download,@{section=".text",section-sent="6144",section-size="6668",
20418 total-sent="6144",total-size="9880"@}
20419 +download,@{section=".text",section-sent="6656",section-size="6668",
20420 total-sent="6656",total-size="9880"@}
20421 +download,@{section=".init",section-size="28",total-size="9880"@}
20422 +download,@{section=".fini",section-size="28",total-size="9880"@}
20423 +download,@{section=".data",section-size="3156",total-size="9880"@}
20424 +download,@{section=".data",section-sent="512",section-size="3156",
20425 total-sent="7236",total-size="9880"@}
20426 +download,@{section=".data",section-sent="1024",section-size="3156",
20427 total-sent="7748",total-size="9880"@}
20428 +download,@{section=".data",section-sent="1536",section-size="3156",
20429 total-sent="8260",total-size="9880"@}
20430 +download,@{section=".data",section-sent="2048",section-size="3156",
20431 total-sent="8772",total-size="9880"@}
20432 +download,@{section=".data",section-sent="2560",section-size="3156",
20433 total-sent="9284",total-size="9880"@}
20434 +download,@{section=".data",section-sent="3072",section-size="3156",
20435 total-sent="9796",total-size="9880"@}
20436 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
20437 write-rate="429"
20438 (@value{GDBP})
20439 @end smallexample
20440
20441
20442 @subheading The @code{-target-exec-status} Command
20443 @findex -target-exec-status
20444
20445 @subsubheading Synopsis
20446
20447 @smallexample
20448 -target-exec-status
20449 @end smallexample
20450
20451 Provide information on the state of the target (whether it is running or
20452 not, for instance).
20453
20454 @subsubheading @value{GDBN} Command
20455
20456 There's no equivalent @value{GDBN} command.
20457
20458 @subsubheading Example
20459 N.A.
20460
20461
20462 @subheading The @code{-target-list-available-targets} Command
20463 @findex -target-list-available-targets
20464
20465 @subsubheading Synopsis
20466
20467 @smallexample
20468 -target-list-available-targets
20469 @end smallexample
20470
20471 List the possible targets to connect to.
20472
20473 @subsubheading @value{GDBN} Command
20474
20475 The corresponding @value{GDBN} command is @samp{help target}.
20476
20477 @subsubheading Example
20478 N.A.
20479
20480
20481 @subheading The @code{-target-list-current-targets} Command
20482 @findex -target-list-current-targets
20483
20484 @subsubheading Synopsis
20485
20486 @smallexample
20487 -target-list-current-targets
20488 @end smallexample
20489
20490 Describe the current target.
20491
20492 @subsubheading @value{GDBN} Command
20493
20494 The corresponding information is printed by @samp{info file} (among
20495 other things).
20496
20497 @subsubheading Example
20498 N.A.
20499
20500
20501 @subheading The @code{-target-list-parameters} Command
20502 @findex -target-list-parameters
20503
20504 @subsubheading Synopsis
20505
20506 @smallexample
20507 -target-list-parameters
20508 @end smallexample
20509
20510 @c ????
20511
20512 @subsubheading @value{GDBN} Command
20513
20514 No equivalent.
20515
20516 @subsubheading Example
20517 N.A.
20518
20519
20520 @subheading The @code{-target-select} Command
20521 @findex -target-select
20522
20523 @subsubheading Synopsis
20524
20525 @smallexample
20526 -target-select @var{type} @var{parameters @dots{}}
20527 @end smallexample
20528
20529 Connect @value{GDBN} to the remote target. This command takes two args:
20530
20531 @table @samp
20532 @item @var{type}
20533 The type of target, for instance @samp{async}, @samp{remote}, etc.
20534 @item @var{parameters}
20535 Device names, host names and the like. @xref{Target Commands, ,
20536 Commands for managing targets}, for more details.
20537 @end table
20538
20539 The output is a connection notification, followed by the address at
20540 which the target program is, in the following form:
20541
20542 @smallexample
20543 ^connected,addr="@var{address}",func="@var{function name}",
20544 args=[@var{arg list}]
20545 @end smallexample
20546
20547 @subsubheading @value{GDBN} Command
20548
20549 The corresponding @value{GDBN} command is @samp{target}.
20550
20551 @subsubheading Example
20552
20553 @smallexample
20554 (@value{GDBP})
20555 -target-select async /dev/ttya
20556 ^connected,addr="0xfe00a300",func="??",args=[]
20557 (@value{GDBP})
20558 @end smallexample
20559
20560 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20561 @node GDB/MI Thread Commands
20562 @section @sc{gdb/mi} Thread Commands
20563
20564
20565 @subheading The @code{-thread-info} Command
20566 @findex -thread-info
20567
20568 @subsubheading Synopsis
20569
20570 @smallexample
20571 -thread-info
20572 @end smallexample
20573
20574 @subsubheading @value{GDBN} command
20575
20576 No equivalent.
20577
20578 @subsubheading Example
20579 N.A.
20580
20581
20582 @subheading The @code{-thread-list-all-threads} Command
20583 @findex -thread-list-all-threads
20584
20585 @subsubheading Synopsis
20586
20587 @smallexample
20588 -thread-list-all-threads
20589 @end smallexample
20590
20591 @subsubheading @value{GDBN} Command
20592
20593 The equivalent @value{GDBN} command is @samp{info threads}.
20594
20595 @subsubheading Example
20596 N.A.
20597
20598
20599 @subheading The @code{-thread-list-ids} Command
20600 @findex -thread-list-ids
20601
20602 @subsubheading Synopsis
20603
20604 @smallexample
20605 -thread-list-ids
20606 @end smallexample
20607
20608 Produces a list of the currently known @value{GDBN} thread ids. At the
20609 end of the list it also prints the total number of such threads.
20610
20611 @subsubheading @value{GDBN} Command
20612
20613 Part of @samp{info threads} supplies the same information.
20614
20615 @subsubheading Example
20616
20617 No threads present, besides the main process:
20618
20619 @smallexample
20620 (@value{GDBP})
20621 -thread-list-ids
20622 ^done,thread-ids=@{@},number-of-threads="0"
20623 (@value{GDBP})
20624 @end smallexample
20625
20626
20627 Several threads:
20628
20629 @smallexample
20630 (@value{GDBP})
20631 -thread-list-ids
20632 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20633 number-of-threads="3"
20634 (@value{GDBP})
20635 @end smallexample
20636
20637
20638 @subheading The @code{-thread-select} Command
20639 @findex -thread-select
20640
20641 @subsubheading Synopsis
20642
20643 @smallexample
20644 -thread-select @var{threadnum}
20645 @end smallexample
20646
20647 Make @var{threadnum} the current thread. It prints the number of the new
20648 current thread, and the topmost frame for that thread.
20649
20650 @subsubheading @value{GDBN} Command
20651
20652 The corresponding @value{GDBN} command is @samp{thread}.
20653
20654 @subsubheading Example
20655
20656 @smallexample
20657 (@value{GDBP})
20658 -exec-next
20659 ^running
20660 (@value{GDBP})
20661 *stopped,reason="end-stepping-range",thread-id="2",line="187",
20662 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20663 (@value{GDBP})
20664 -thread-list-ids
20665 ^done,
20666 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20667 number-of-threads="3"
20668 (@value{GDBP})
20669 -thread-select 3
20670 ^done,new-thread-id="3",
20671 frame=@{level="0",func="vprintf",
20672 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20673 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20674 (@value{GDBP})
20675 @end smallexample
20676
20677 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20678 @node GDB/MI Tracepoint Commands
20679 @section @sc{gdb/mi} Tracepoint Commands
20680
20681 The tracepoint commands are not yet implemented.
20682
20683 @c @subheading -trace-actions
20684
20685 @c @subheading -trace-delete
20686
20687 @c @subheading -trace-disable
20688
20689 @c @subheading -trace-dump
20690
20691 @c @subheading -trace-enable
20692
20693 @c @subheading -trace-exists
20694
20695 @c @subheading -trace-find
20696
20697 @c @subheading -trace-frame-number
20698
20699 @c @subheading -trace-info
20700
20701 @c @subheading -trace-insert
20702
20703 @c @subheading -trace-list
20704
20705 @c @subheading -trace-pass-count
20706
20707 @c @subheading -trace-save
20708
20709 @c @subheading -trace-start
20710
20711 @c @subheading -trace-stop
20712
20713
20714 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20715 @node GDB/MI Variable Objects
20716 @section @sc{gdb/mi} Variable Objects
20717
20718
20719 @subheading Motivation for Variable Objects in @sc{gdb/mi}
20720
20721 For the implementation of a variable debugger window (locals, watched
20722 expressions, etc.), we are proposing the adaptation of the existing code
20723 used by @code{Insight}.
20724
20725 The two main reasons for that are:
20726
20727 @enumerate 1
20728 @item
20729 It has been proven in practice (it is already on its second generation).
20730
20731 @item
20732 It will shorten development time (needless to say how important it is
20733 now).
20734 @end enumerate
20735
20736 The original interface was designed to be used by Tcl code, so it was
20737 slightly changed so it could be used through @sc{gdb/mi}. This section
20738 describes the @sc{gdb/mi} operations that will be available and gives some
20739 hints about their use.
20740
20741 @emph{Note}: In addition to the set of operations described here, we
20742 expect the @sc{gui} implementation of a variable window to require, at
20743 least, the following operations:
20744
20745 @itemize @bullet
20746 @item @code{-gdb-show} @code{output-radix}
20747 @item @code{-stack-list-arguments}
20748 @item @code{-stack-list-locals}
20749 @item @code{-stack-select-frame}
20750 @end itemize
20751
20752 @subheading Introduction to Variable Objects in @sc{gdb/mi}
20753
20754 @cindex variable objects in @sc{gdb/mi}
20755 The basic idea behind variable objects is the creation of a named object
20756 to represent a variable, an expression, a memory location or even a CPU
20757 register. For each object created, a set of operations is available for
20758 examining or changing its properties.
20759
20760 Furthermore, complex data types, such as C structures, are represented
20761 in a tree format. For instance, the @code{struct} type variable is the
20762 root and the children will represent the struct members. If a child
20763 is itself of a complex type, it will also have children of its own.
20764 Appropriate language differences are handled for C, C@t{++} and Java.
20765
20766 When returning the actual values of the objects, this facility allows
20767 for the individual selection of the display format used in the result
20768 creation. It can be chosen among: binary, decimal, hexadecimal, octal
20769 and natural. Natural refers to a default format automatically
20770 chosen based on the variable type (like decimal for an @code{int}, hex
20771 for pointers, etc.).
20772
20773 The following is the complete set of @sc{gdb/mi} operations defined to
20774 access this functionality:
20775
20776 @multitable @columnfractions .4 .6
20777 @item @strong{Operation}
20778 @tab @strong{Description}
20779
20780 @item @code{-var-create}
20781 @tab create a variable object
20782 @item @code{-var-delete}
20783 @tab delete the variable object and its children
20784 @item @code{-var-set-format}
20785 @tab set the display format of this variable
20786 @item @code{-var-show-format}
20787 @tab show the display format of this variable
20788 @item @code{-var-info-num-children}
20789 @tab tells how many children this object has
20790 @item @code{-var-list-children}
20791 @tab return a list of the object's children
20792 @item @code{-var-info-type}
20793 @tab show the type of this variable object
20794 @item @code{-var-info-expression}
20795 @tab print what this variable object represents
20796 @item @code{-var-show-attributes}
20797 @tab is this variable editable? does it exist here?
20798 @item @code{-var-evaluate-expression}
20799 @tab get the value of this variable
20800 @item @code{-var-assign}
20801 @tab set the value of this variable
20802 @item @code{-var-update}
20803 @tab update the variable and its children
20804 @end multitable
20805
20806 In the next subsection we describe each operation in detail and suggest
20807 how it can be used.
20808
20809 @subheading Description And Use of Operations on Variable Objects
20810
20811 @subheading The @code{-var-create} Command
20812 @findex -var-create
20813
20814 @subsubheading Synopsis
20815
20816 @smallexample
20817 -var-create @{@var{name} | "-"@}
20818 @{@var{frame-addr} | "*"@} @var{expression}
20819 @end smallexample
20820
20821 This operation creates a variable object, which allows the monitoring of
20822 a variable, the result of an expression, a memory cell or a CPU
20823 register.
20824
20825 The @var{name} parameter is the string by which the object can be
20826 referenced. It must be unique. If @samp{-} is specified, the varobj
20827 system will generate a string ``varNNNNNN'' automatically. It will be
20828 unique provided that one does not specify @var{name} on that format.
20829 The command fails if a duplicate name is found.
20830
20831 The frame under which the expression should be evaluated can be
20832 specified by @var{frame-addr}. A @samp{*} indicates that the current
20833 frame should be used.
20834
20835 @var{expression} is any expression valid on the current language set (must not
20836 begin with a @samp{*}), or one of the following:
20837
20838 @itemize @bullet
20839 @item
20840 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20841
20842 @item
20843 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20844
20845 @item
20846 @samp{$@var{regname}} --- a CPU register name
20847 @end itemize
20848
20849 @subsubheading Result
20850
20851 This operation returns the name, number of children and the type of the
20852 object created. Type is returned as a string as the ones generated by
20853 the @value{GDBN} CLI:
20854
20855 @smallexample
20856 name="@var{name}",numchild="N",type="@var{type}"
20857 @end smallexample
20858
20859
20860 @subheading The @code{-var-delete} Command
20861 @findex -var-delete
20862
20863 @subsubheading Synopsis
20864
20865 @smallexample
20866 -var-delete @var{name}
20867 @end smallexample
20868
20869 Deletes a previously created variable object and all of its children.
20870
20871 Returns an error if the object @var{name} is not found.
20872
20873
20874 @subheading The @code{-var-set-format} Command
20875 @findex -var-set-format
20876
20877 @subsubheading Synopsis
20878
20879 @smallexample
20880 -var-set-format @var{name} @var{format-spec}
20881 @end smallexample
20882
20883 Sets the output format for the value of the object @var{name} to be
20884 @var{format-spec}.
20885
20886 The syntax for the @var{format-spec} is as follows:
20887
20888 @smallexample
20889 @var{format-spec} @expansion{}
20890 @{binary | decimal | hexadecimal | octal | natural@}
20891 @end smallexample
20892
20893
20894 @subheading The @code{-var-show-format} Command
20895 @findex -var-show-format
20896
20897 @subsubheading Synopsis
20898
20899 @smallexample
20900 -var-show-format @var{name}
20901 @end smallexample
20902
20903 Returns the format used to display the value of the object @var{name}.
20904
20905 @smallexample
20906 @var{format} @expansion{}
20907 @var{format-spec}
20908 @end smallexample
20909
20910
20911 @subheading The @code{-var-info-num-children} Command
20912 @findex -var-info-num-children
20913
20914 @subsubheading Synopsis
20915
20916 @smallexample
20917 -var-info-num-children @var{name}
20918 @end smallexample
20919
20920 Returns the number of children of a variable object @var{name}:
20921
20922 @smallexample
20923 numchild=@var{n}
20924 @end smallexample
20925
20926
20927 @subheading The @code{-var-list-children} Command
20928 @findex -var-list-children
20929
20930 @subsubheading Synopsis
20931
20932 @smallexample
20933 -var-list-children [@var{print-values}] @var{name}
20934 @end smallexample
20935 @anchor{-var-list-children}
20936
20937 Return a list of the children of the specified variable object and
20938 create variable objects for them, if they do not already exist. With
20939 a single argument or if @var{print-values} has a value for of 0 or
20940 @code{--no-values}, print only the names of the variables; if
20941 @var{print-values} is 1 or @code{--all-values}, also print their
20942 values; and if it is 2 or @code{--simple-values} print the name and
20943 value for simple data types and just the name for arrays, structures
20944 and unions.
20945
20946 @subsubheading Example
20947
20948 @smallexample
20949 (@value{GDBP})
20950 -var-list-children n
20951 ^done,numchild=@var{n},children=[@{name=@var{name},
20952 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
20953 (@value{GDBP})
20954 -var-list-children --all-values n
20955 ^done,numchild=@var{n},children=[@{name=@var{name},
20956 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
20957 @end smallexample
20958
20959
20960 @subheading The @code{-var-info-type} Command
20961 @findex -var-info-type
20962
20963 @subsubheading Synopsis
20964
20965 @smallexample
20966 -var-info-type @var{name}
20967 @end smallexample
20968
20969 Returns the type of the specified variable @var{name}. The type is
20970 returned as a string in the same format as it is output by the
20971 @value{GDBN} CLI:
20972
20973 @smallexample
20974 type=@var{typename}
20975 @end smallexample
20976
20977
20978 @subheading The @code{-var-info-expression} Command
20979 @findex -var-info-expression
20980
20981 @subsubheading Synopsis
20982
20983 @smallexample
20984 -var-info-expression @var{name}
20985 @end smallexample
20986
20987 Returns what is represented by the variable object @var{name}:
20988
20989 @smallexample
20990 lang=@var{lang-spec},exp=@var{expression}
20991 @end smallexample
20992
20993 @noindent
20994 where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20995
20996 @subheading The @code{-var-show-attributes} Command
20997 @findex -var-show-attributes
20998
20999 @subsubheading Synopsis
21000
21001 @smallexample
21002 -var-show-attributes @var{name}
21003 @end smallexample
21004
21005 List attributes of the specified variable object @var{name}:
21006
21007 @smallexample
21008 status=@var{attr} [ ( ,@var{attr} )* ]
21009 @end smallexample
21010
21011 @noindent
21012 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
21013
21014 @subheading The @code{-var-evaluate-expression} Command
21015 @findex -var-evaluate-expression
21016
21017 @subsubheading Synopsis
21018
21019 @smallexample
21020 -var-evaluate-expression @var{name}
21021 @end smallexample
21022
21023 Evaluates the expression that is represented by the specified variable
21024 object and returns its value as a string in the current format specified
21025 for the object:
21026
21027 @smallexample
21028 value=@var{value}
21029 @end smallexample
21030
21031 Note that one must invoke @code{-var-list-children} for a variable
21032 before the value of a child variable can be evaluated.
21033
21034 @subheading The @code{-var-assign} Command
21035 @findex -var-assign
21036
21037 @subsubheading Synopsis
21038
21039 @smallexample
21040 -var-assign @var{name} @var{expression}
21041 @end smallexample
21042
21043 Assigns the value of @var{expression} to the variable object specified
21044 by @var{name}. The object must be @samp{editable}. If the variable's
21045 value is altered by the assign, the variable will show up in any
21046 subsequent @code{-var-update} list.
21047
21048 @subsubheading Example
21049
21050 @smallexample
21051 (@value{GDBP})
21052 -var-assign var1 3
21053 ^done,value="3"
21054 (@value{GDBP})
21055 -var-update *
21056 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
21057 (@value{GDBP})
21058 @end smallexample
21059
21060 @subheading The @code{-var-update} Command
21061 @findex -var-update
21062
21063 @subsubheading Synopsis
21064
21065 @smallexample
21066 -var-update [@var{print-values}] @{@var{name} | "*"@}
21067 @end smallexample
21068
21069 Update the value of the variable object @var{name} by evaluating its
21070 expression after fetching all the new values from memory or registers.
21071 A @samp{*} causes all existing variable objects to be updated. The
21072 option @var{print-values} determines whether names both and values, or
21073 just names are printed in the manner described for
21074 @code{-var-list-children} (@pxref{-var-list-children}).
21075
21076 @subsubheading Example
21077
21078 @smallexample
21079 (@value{GDBP})
21080 -var-assign var1 3
21081 ^done,value="3"
21082 (@value{GDBP})
21083 -var-update --all-values var1
21084 ^done,changelist=[@{name="var1",value="3",in_scope="true",
21085 type_changed="false"@}]
21086 (@value{GDBP})
21087 @end smallexample
21088
21089 @node Annotations
21090 @chapter @value{GDBN} Annotations
21091
21092 This chapter describes annotations in @value{GDBN}. Annotations were
21093 designed to interface @value{GDBN} to graphical user interfaces or other
21094 similar programs which want to interact with @value{GDBN} at a
21095 relatively high level.
21096
21097 The annotation mechanism has largely been superseeded by @sc{gdb/mi}
21098 (@pxref{GDB/MI}).
21099
21100 @ignore
21101 This is Edition @value{EDITION}, @value{DATE}.
21102 @end ignore
21103
21104 @menu
21105 * Annotations Overview:: What annotations are; the general syntax.
21106 * Prompting:: Annotations marking @value{GDBN}'s need for input.
21107 * Errors:: Annotations for error messages.
21108 * Invalidation:: Some annotations describe things now invalid.
21109 * Annotations for Running::
21110 Whether the program is running, how it stopped, etc.
21111 * Source Annotations:: Annotations describing source code.
21112 @end menu
21113
21114 @node Annotations Overview
21115 @section What is an Annotation?
21116 @cindex annotations
21117
21118 Annotations start with a newline character, two @samp{control-z}
21119 characters, and the name of the annotation. If there is no additional
21120 information associated with this annotation, the name of the annotation
21121 is followed immediately by a newline. If there is additional
21122 information, the name of the annotation is followed by a space, the
21123 additional information, and a newline. The additional information
21124 cannot contain newline characters.
21125
21126 Any output not beginning with a newline and two @samp{control-z}
21127 characters denotes literal output from @value{GDBN}. Currently there is
21128 no need for @value{GDBN} to output a newline followed by two
21129 @samp{control-z} characters, but if there was such a need, the
21130 annotations could be extended with an @samp{escape} annotation which
21131 means those three characters as output.
21132
21133 The annotation @var{level}, which is specified using the
21134 @option{--annotate} command line option (@pxref{Mode Options}), controls
21135 how much information @value{GDBN} prints together with its prompt,
21136 values of expressions, source lines, and other types of output. Level 0
21137 is for no anntations, level 1 is for use when @value{GDBN} is run as a
21138 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21139 for programs that control @value{GDBN}, and level 2 annotations have
21140 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
21141 Interface, annotate, GDB's Obsolete Annotations}).
21142
21143 @table @code
21144 @kindex set annotate
21145 @item set annotate @var{level}
21146 The @value{GDBN} command @code{set annotate} sets the level of
21147 annotations to the specified @var{level}.
21148
21149 @item show annotate
21150 @kindex show annotate
21151 Show the current annotation level.
21152 @end table
21153
21154 This chapter describes level 3 annotations.
21155
21156 A simple example of starting up @value{GDBN} with annotations is:
21157
21158 @smallexample
21159 $ @kbd{gdb --annotate=3}
21160 GNU gdb 6.0
21161 Copyright 2003 Free Software Foundation, Inc.
21162 GDB is free software, covered by the GNU General Public License,
21163 and you are welcome to change it and/or distribute copies of it
21164 under certain conditions.
21165 Type "show copying" to see the conditions.
21166 There is absolutely no warranty for GDB. Type "show warranty"
21167 for details.
21168 This GDB was configured as "i386-pc-linux-gnu"
21169
21170 ^Z^Zpre-prompt
21171 (@value{GDBP})
21172 ^Z^Zprompt
21173 @kbd{quit}
21174
21175 ^Z^Zpost-prompt
21176 $
21177 @end smallexample
21178
21179 Here @samp{quit} is input to @value{GDBN}; the rest is output from
21180 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
21181 denotes a @samp{control-z} character) are annotations; the rest is
21182 output from @value{GDBN}.
21183
21184 @node Prompting
21185 @section Annotation for @value{GDBN} Input
21186
21187 @cindex annotations for prompts
21188 When @value{GDBN} prompts for input, it annotates this fact so it is possible
21189 to know when to send output, when the output from a given command is
21190 over, etc.
21191
21192 Different kinds of input each have a different @dfn{input type}. Each
21193 input type has three annotations: a @code{pre-} annotation, which
21194 denotes the beginning of any prompt which is being output, a plain
21195 annotation, which denotes the end of the prompt, and then a @code{post-}
21196 annotation which denotes the end of any echo which may (or may not) be
21197 associated with the input. For example, the @code{prompt} input type
21198 features the following annotations:
21199
21200 @smallexample
21201 ^Z^Zpre-prompt
21202 ^Z^Zprompt
21203 ^Z^Zpost-prompt
21204 @end smallexample
21205
21206 The input types are
21207
21208 @table @code
21209 @findex pre-prompt
21210 @findex prompt
21211 @findex post-prompt
21212 @item prompt
21213 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
21214
21215 @findex pre-commands
21216 @findex commands
21217 @findex post-commands
21218 @item commands
21219 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
21220 command. The annotations are repeated for each command which is input.
21221
21222 @findex pre-overload-choice
21223 @findex overload-choice
21224 @findex post-overload-choice
21225 @item overload-choice
21226 When @value{GDBN} wants the user to select between various overloaded functions.
21227
21228 @findex pre-query
21229 @findex query
21230 @findex post-query
21231 @item query
21232 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
21233
21234 @findex pre-prompt-for-continue
21235 @findex prompt-for-continue
21236 @findex post-prompt-for-continue
21237 @item prompt-for-continue
21238 When @value{GDBN} is asking the user to press return to continue. Note: Don't
21239 expect this to work well; instead use @code{set height 0} to disable
21240 prompting. This is because the counting of lines is buggy in the
21241 presence of annotations.
21242 @end table
21243
21244 @node Errors
21245 @section Errors
21246 @cindex annotations for errors, warnings and interrupts
21247
21248 @findex quit
21249 @smallexample
21250 ^Z^Zquit
21251 @end smallexample
21252
21253 This annotation occurs right before @value{GDBN} responds to an interrupt.
21254
21255 @findex error
21256 @smallexample
21257 ^Z^Zerror
21258 @end smallexample
21259
21260 This annotation occurs right before @value{GDBN} responds to an error.
21261
21262 Quit and error annotations indicate that any annotations which @value{GDBN} was
21263 in the middle of may end abruptly. For example, if a
21264 @code{value-history-begin} annotation is followed by a @code{error}, one
21265 cannot expect to receive the matching @code{value-history-end}. One
21266 cannot expect not to receive it either, however; an error annotation
21267 does not necessarily mean that @value{GDBN} is immediately returning all the way
21268 to the top level.
21269
21270 @findex error-begin
21271 A quit or error annotation may be preceded by
21272
21273 @smallexample
21274 ^Z^Zerror-begin
21275 @end smallexample
21276
21277 Any output between that and the quit or error annotation is the error
21278 message.
21279
21280 Warning messages are not yet annotated.
21281 @c If we want to change that, need to fix warning(), type_error(),
21282 @c range_error(), and possibly other places.
21283
21284 @node Invalidation
21285 @section Invalidation Notices
21286
21287 @cindex annotations for invalidation messages
21288 The following annotations say that certain pieces of state may have
21289 changed.
21290
21291 @table @code
21292 @findex frames-invalid
21293 @item ^Z^Zframes-invalid
21294
21295 The frames (for example, output from the @code{backtrace} command) may
21296 have changed.
21297
21298 @findex breakpoints-invalid
21299 @item ^Z^Zbreakpoints-invalid
21300
21301 The breakpoints may have changed. For example, the user just added or
21302 deleted a breakpoint.
21303 @end table
21304
21305 @node Annotations for Running
21306 @section Running the Program
21307 @cindex annotations for running programs
21308
21309 @findex starting
21310 @findex stopping
21311 When the program starts executing due to a @value{GDBN} command such as
21312 @code{step} or @code{continue},
21313
21314 @smallexample
21315 ^Z^Zstarting
21316 @end smallexample
21317
21318 is output. When the program stops,
21319
21320 @smallexample
21321 ^Z^Zstopped
21322 @end smallexample
21323
21324 is output. Before the @code{stopped} annotation, a variety of
21325 annotations describe how the program stopped.
21326
21327 @table @code
21328 @findex exited
21329 @item ^Z^Zexited @var{exit-status}
21330 The program exited, and @var{exit-status} is the exit status (zero for
21331 successful exit, otherwise nonzero).
21332
21333 @findex signalled
21334 @findex signal-name
21335 @findex signal-name-end
21336 @findex signal-string
21337 @findex signal-string-end
21338 @item ^Z^Zsignalled
21339 The program exited with a signal. After the @code{^Z^Zsignalled}, the
21340 annotation continues:
21341
21342 @smallexample
21343 @var{intro-text}
21344 ^Z^Zsignal-name
21345 @var{name}
21346 ^Z^Zsignal-name-end
21347 @var{middle-text}
21348 ^Z^Zsignal-string
21349 @var{string}
21350 ^Z^Zsignal-string-end
21351 @var{end-text}
21352 @end smallexample
21353
21354 @noindent
21355 where @var{name} is the name of the signal, such as @code{SIGILL} or
21356 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
21357 as @code{Illegal Instruction} or @code{Segmentation fault}.
21358 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
21359 user's benefit and have no particular format.
21360
21361 @findex signal
21362 @item ^Z^Zsignal
21363 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
21364 just saying that the program received the signal, not that it was
21365 terminated with it.
21366
21367 @findex breakpoint
21368 @item ^Z^Zbreakpoint @var{number}
21369 The program hit breakpoint number @var{number}.
21370
21371 @findex watchpoint
21372 @item ^Z^Zwatchpoint @var{number}
21373 The program hit watchpoint number @var{number}.
21374 @end table
21375
21376 @node Source Annotations
21377 @section Displaying Source
21378 @cindex annotations for source display
21379
21380 @findex source
21381 The following annotation is used instead of displaying source code:
21382
21383 @smallexample
21384 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
21385 @end smallexample
21386
21387 where @var{filename} is an absolute file name indicating which source
21388 file, @var{line} is the line number within that file (where 1 is the
21389 first line in the file), @var{character} is the character position
21390 within the file (where 0 is the first character in the file) (for most
21391 debug formats this will necessarily point to the beginning of a line),
21392 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
21393 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
21394 @var{addr} is the address in the target program associated with the
21395 source which is being displayed. @var{addr} is in the form @samp{0x}
21396 followed by one or more lowercase hex digits (note that this does not
21397 depend on the language).
21398
21399 @node GDB Bugs
21400 @chapter Reporting Bugs in @value{GDBN}
21401 @cindex bugs in @value{GDBN}
21402 @cindex reporting bugs in @value{GDBN}
21403
21404 Your bug reports play an essential role in making @value{GDBN} reliable.
21405
21406 Reporting a bug may help you by bringing a solution to your problem, or it
21407 may not. But in any case the principal function of a bug report is to help
21408 the entire community by making the next version of @value{GDBN} work better. Bug
21409 reports are your contribution to the maintenance of @value{GDBN}.
21410
21411 In order for a bug report to serve its purpose, you must include the
21412 information that enables us to fix the bug.
21413
21414 @menu
21415 * Bug Criteria:: Have you found a bug?
21416 * Bug Reporting:: How to report bugs
21417 @end menu
21418
21419 @node Bug Criteria
21420 @section Have you found a bug?
21421 @cindex bug criteria
21422
21423 If you are not sure whether you have found a bug, here are some guidelines:
21424
21425 @itemize @bullet
21426 @cindex fatal signal
21427 @cindex debugger crash
21428 @cindex crash of debugger
21429 @item
21430 If the debugger gets a fatal signal, for any input whatever, that is a
21431 @value{GDBN} bug. Reliable debuggers never crash.
21432
21433 @cindex error on valid input
21434 @item
21435 If @value{GDBN} produces an error message for valid input, that is a
21436 bug. (Note that if you're cross debugging, the problem may also be
21437 somewhere in the connection to the target.)
21438
21439 @cindex invalid input
21440 @item
21441 If @value{GDBN} does not produce an error message for invalid input,
21442 that is a bug. However, you should note that your idea of
21443 ``invalid input'' might be our idea of ``an extension'' or ``support
21444 for traditional practice''.
21445
21446 @item
21447 If you are an experienced user of debugging tools, your suggestions
21448 for improvement of @value{GDBN} are welcome in any case.
21449 @end itemize
21450
21451 @node Bug Reporting
21452 @section How to report bugs
21453 @cindex bug reports
21454 @cindex @value{GDBN} bugs, reporting
21455
21456 A number of companies and individuals offer support for @sc{gnu} products.
21457 If you obtained @value{GDBN} from a support organization, we recommend you
21458 contact that organization first.
21459
21460 You can find contact information for many support companies and
21461 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21462 distribution.
21463 @c should add a web page ref...
21464
21465 In any event, we also recommend that you submit bug reports for
21466 @value{GDBN}. The prefered method is to submit them directly using
21467 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21468 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21469 be used.
21470
21471 @strong{Do not send bug reports to @samp{info-gdb}, or to
21472 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21473 not want to receive bug reports. Those that do have arranged to receive
21474 @samp{bug-gdb}.
21475
21476 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21477 serves as a repeater. The mailing list and the newsgroup carry exactly
21478 the same messages. Often people think of posting bug reports to the
21479 newsgroup instead of mailing them. This appears to work, but it has one
21480 problem which can be crucial: a newsgroup posting often lacks a mail
21481 path back to the sender. Thus, if we need to ask for more information,
21482 we may be unable to reach you. For this reason, it is better to send
21483 bug reports to the mailing list.
21484
21485 The fundamental principle of reporting bugs usefully is this:
21486 @strong{report all the facts}. If you are not sure whether to state a
21487 fact or leave it out, state it!
21488
21489 Often people omit facts because they think they know what causes the
21490 problem and assume that some details do not matter. Thus, you might
21491 assume that the name of the variable you use in an example does not matter.
21492 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21493 stray memory reference which happens to fetch from the location where that
21494 name is stored in memory; perhaps, if the name were different, the contents
21495 of that location would fool the debugger into doing the right thing despite
21496 the bug. Play it safe and give a specific, complete example. That is the
21497 easiest thing for you to do, and the most helpful.
21498
21499 Keep in mind that the purpose of a bug report is to enable us to fix the
21500 bug. It may be that the bug has been reported previously, but neither
21501 you nor we can know that unless your bug report is complete and
21502 self-contained.
21503
21504 Sometimes people give a few sketchy facts and ask, ``Does this ring a
21505 bell?'' Those bug reports are useless, and we urge everyone to
21506 @emph{refuse to respond to them} except to chide the sender to report
21507 bugs properly.
21508
21509 To enable us to fix the bug, you should include all these things:
21510
21511 @itemize @bullet
21512 @item
21513 The version of @value{GDBN}. @value{GDBN} announces it if you start
21514 with no arguments; you can also print it at any time using @code{show
21515 version}.
21516
21517 Without this, we will not know whether there is any point in looking for
21518 the bug in the current version of @value{GDBN}.
21519
21520 @item
21521 The type of machine you are using, and the operating system name and
21522 version number.
21523
21524 @item
21525 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
21526 ``@value{GCC}--2.8.1''.
21527
21528 @item
21529 What compiler (and its version) was used to compile the program you are
21530 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21531 C Compiler''. For GCC, you can say @code{gcc --version} to get this
21532 information; for other compilers, see the documentation for those
21533 compilers.
21534
21535 @item
21536 The command arguments you gave the compiler to compile your example and
21537 observe the bug. For example, did you use @samp{-O}? To guarantee
21538 you will not omit something important, list them all. A copy of the
21539 Makefile (or the output from make) is sufficient.
21540
21541 If we were to try to guess the arguments, we would probably guess wrong
21542 and then we might not encounter the bug.
21543
21544 @item
21545 A complete input script, and all necessary source files, that will
21546 reproduce the bug.
21547
21548 @item
21549 A description of what behavior you observe that you believe is
21550 incorrect. For example, ``It gets a fatal signal.''
21551
21552 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21553 will certainly notice it. But if the bug is incorrect output, we might
21554 not notice unless it is glaringly wrong. You might as well not give us
21555 a chance to make a mistake.
21556
21557 Even if the problem you experience is a fatal signal, you should still
21558 say so explicitly. Suppose something strange is going on, such as, your
21559 copy of @value{GDBN} is out of synch, or you have encountered a bug in
21560 the C library on your system. (This has happened!) Your copy might
21561 crash and ours would not. If you told us to expect a crash, then when
21562 ours fails to crash, we would know that the bug was not happening for
21563 us. If you had not told us to expect a crash, then we would not be able
21564 to draw any conclusion from our observations.
21565
21566 @pindex script
21567 @cindex recording a session script
21568 To collect all this information, you can use a session recording program
21569 such as @command{script}, which is available on many Unix systems.
21570 Just run your @value{GDBN} session inside @command{script} and then
21571 include the @file{typescript} file with your bug report.
21572
21573 Another way to record a @value{GDBN} session is to run @value{GDBN}
21574 inside Emacs and then save the entire buffer to a file.
21575
21576 @item
21577 If you wish to suggest changes to the @value{GDBN} source, send us context
21578 diffs. If you even discuss something in the @value{GDBN} source, refer to
21579 it by context, not by line number.
21580
21581 The line numbers in our development sources will not match those in your
21582 sources. Your line numbers would convey no useful information to us.
21583
21584 @end itemize
21585
21586 Here are some things that are not necessary:
21587
21588 @itemize @bullet
21589 @item
21590 A description of the envelope of the bug.
21591
21592 Often people who encounter a bug spend a lot of time investigating
21593 which changes to the input file will make the bug go away and which
21594 changes will not affect it.
21595
21596 This is often time consuming and not very useful, because the way we
21597 will find the bug is by running a single example under the debugger
21598 with breakpoints, not by pure deduction from a series of examples.
21599 We recommend that you save your time for something else.
21600
21601 Of course, if you can find a simpler example to report @emph{instead}
21602 of the original one, that is a convenience for us. Errors in the
21603 output will be easier to spot, running under the debugger will take
21604 less time, and so on.
21605
21606 However, simplification is not vital; if you do not want to do this,
21607 report the bug anyway and send us the entire test case you used.
21608
21609 @item
21610 A patch for the bug.
21611
21612 A patch for the bug does help us if it is a good one. But do not omit
21613 the necessary information, such as the test case, on the assumption that
21614 a patch is all we need. We might see problems with your patch and decide
21615 to fix the problem another way, or we might not understand it at all.
21616
21617 Sometimes with a program as complicated as @value{GDBN} it is very hard to
21618 construct an example that will make the program follow a certain path
21619 through the code. If you do not send us the example, we will not be able
21620 to construct one, so we will not be able to verify that the bug is fixed.
21621
21622 And if we cannot understand what bug you are trying to fix, or why your
21623 patch should be an improvement, we will not install it. A test case will
21624 help us to understand.
21625
21626 @item
21627 A guess about what the bug is or what it depends on.
21628
21629 Such guesses are usually wrong. Even we cannot guess right about such
21630 things without first using the debugger to find the facts.
21631 @end itemize
21632
21633 @c The readline documentation is distributed with the readline code
21634 @c and consists of the two following files:
21635 @c rluser.texinfo
21636 @c inc-hist.texinfo
21637 @c Use -I with makeinfo to point to the appropriate directory,
21638 @c environment var TEXINPUTS with TeX.
21639 @include rluser.texinfo
21640 @include inc-hist.texinfo
21641
21642
21643 @node Formatting Documentation
21644 @appendix Formatting Documentation
21645
21646 @cindex @value{GDBN} reference card
21647 @cindex reference card
21648 The @value{GDBN} 4 release includes an already-formatted reference card, ready
21649 for printing with PostScript or Ghostscript, in the @file{gdb}
21650 subdirectory of the main source directory@footnote{In
21651 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21652 release.}. If you can use PostScript or Ghostscript with your printer,
21653 you can print the reference card immediately with @file{refcard.ps}.
21654
21655 The release also includes the source for the reference card. You
21656 can format it, using @TeX{}, by typing:
21657
21658 @smallexample
21659 make refcard.dvi
21660 @end smallexample
21661
21662 The @value{GDBN} reference card is designed to print in @dfn{landscape}
21663 mode on US ``letter'' size paper;
21664 that is, on a sheet 11 inches wide by 8.5 inches
21665 high. You will need to specify this form of printing as an option to
21666 your @sc{dvi} output program.
21667
21668 @cindex documentation
21669
21670 All the documentation for @value{GDBN} comes as part of the machine-readable
21671 distribution. The documentation is written in Texinfo format, which is
21672 a documentation system that uses a single source file to produce both
21673 on-line information and a printed manual. You can use one of the Info
21674 formatting commands to create the on-line version of the documentation
21675 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
21676
21677 @value{GDBN} includes an already formatted copy of the on-line Info
21678 version of this manual in the @file{gdb} subdirectory. The main Info
21679 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21680 subordinate files matching @samp{gdb.info*} in the same directory. If
21681 necessary, you can print out these files, or read them with any editor;
21682 but they are easier to read using the @code{info} subsystem in @sc{gnu}
21683 Emacs or the standalone @code{info} program, available as part of the
21684 @sc{gnu} Texinfo distribution.
21685
21686 If you want to format these Info files yourself, you need one of the
21687 Info formatting programs, such as @code{texinfo-format-buffer} or
21688 @code{makeinfo}.
21689
21690 If you have @code{makeinfo} installed, and are in the top level
21691 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21692 version @value{GDBVN}), you can make the Info file by typing:
21693
21694 @smallexample
21695 cd gdb
21696 make gdb.info
21697 @end smallexample
21698
21699 If you want to typeset and print copies of this manual, you need @TeX{},
21700 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21701 Texinfo definitions file.
21702
21703 @TeX{} is a typesetting program; it does not print files directly, but
21704 produces output files called @sc{dvi} files. To print a typeset
21705 document, you need a program to print @sc{dvi} files. If your system
21706 has @TeX{} installed, chances are it has such a program. The precise
21707 command to use depends on your system; @kbd{lpr -d} is common; another
21708 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21709 require a file name without any extension or a @samp{.dvi} extension.
21710
21711 @TeX{} also requires a macro definitions file called
21712 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21713 written in Texinfo format. On its own, @TeX{} cannot either read or
21714 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21715 and is located in the @file{gdb-@var{version-number}/texinfo}
21716 directory.
21717
21718 If you have @TeX{} and a @sc{dvi} printer program installed, you can
21719 typeset and print this manual. First switch to the the @file{gdb}
21720 subdirectory of the main source directory (for example, to
21721 @file{gdb-@value{GDBVN}/gdb}) and type:
21722
21723 @smallexample
21724 make gdb.dvi
21725 @end smallexample
21726
21727 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
21728
21729 @node Installing GDB
21730 @appendix Installing @value{GDBN}
21731 @cindex configuring @value{GDBN}
21732 @cindex installation
21733 @cindex configuring @value{GDBN}, and source tree subdirectories
21734
21735 @value{GDBN} comes with a @code{configure} script that automates the process
21736 of preparing @value{GDBN} for installation; you can then use @code{make} to
21737 build the @code{gdb} program.
21738 @iftex
21739 @c irrelevant in info file; it's as current as the code it lives with.
21740 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21741 look at the @file{README} file in the sources; we may have improved the
21742 installation procedures since publishing this manual.}
21743 @end iftex
21744
21745 The @value{GDBN} distribution includes all the source code you need for
21746 @value{GDBN} in a single directory, whose name is usually composed by
21747 appending the version number to @samp{gdb}.
21748
21749 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21750 @file{gdb-@value{GDBVN}} directory. That directory contains:
21751
21752 @table @code
21753 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21754 script for configuring @value{GDBN} and all its supporting libraries
21755
21756 @item gdb-@value{GDBVN}/gdb
21757 the source specific to @value{GDBN} itself
21758
21759 @item gdb-@value{GDBVN}/bfd
21760 source for the Binary File Descriptor library
21761
21762 @item gdb-@value{GDBVN}/include
21763 @sc{gnu} include files
21764
21765 @item gdb-@value{GDBVN}/libiberty
21766 source for the @samp{-liberty} free software library
21767
21768 @item gdb-@value{GDBVN}/opcodes
21769 source for the library of opcode tables and disassemblers
21770
21771 @item gdb-@value{GDBVN}/readline
21772 source for the @sc{gnu} command-line interface
21773
21774 @item gdb-@value{GDBVN}/glob
21775 source for the @sc{gnu} filename pattern-matching subroutine
21776
21777 @item gdb-@value{GDBVN}/mmalloc
21778 source for the @sc{gnu} memory-mapped malloc package
21779 @end table
21780
21781 The simplest way to configure and build @value{GDBN} is to run @code{configure}
21782 from the @file{gdb-@var{version-number}} source directory, which in
21783 this example is the @file{gdb-@value{GDBVN}} directory.
21784
21785 First switch to the @file{gdb-@var{version-number}} source directory
21786 if you are not already in it; then run @code{configure}. Pass the
21787 identifier for the platform on which @value{GDBN} will run as an
21788 argument.
21789
21790 For example:
21791
21792 @smallexample
21793 cd gdb-@value{GDBVN}
21794 ./configure @var{host}
21795 make
21796 @end smallexample
21797
21798 @noindent
21799 where @var{host} is an identifier such as @samp{sun4} or
21800 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
21801 (You can often leave off @var{host}; @code{configure} tries to guess the
21802 correct value by examining your system.)
21803
21804 Running @samp{configure @var{host}} and then running @code{make} builds the
21805 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21806 libraries, then @code{gdb} itself. The configured source files, and the
21807 binaries, are left in the corresponding source directories.
21808
21809 @need 750
21810 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21811 system does not recognize this automatically when you run a different
21812 shell, you may need to run @code{sh} on it explicitly:
21813
21814 @smallexample
21815 sh configure @var{host}
21816 @end smallexample
21817
21818 If you run @code{configure} from a directory that contains source
21819 directories for multiple libraries or programs, such as the
21820 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21821 creates configuration files for every directory level underneath (unless
21822 you tell it not to, with the @samp{--norecursion} option).
21823
21824 You should run the @code{configure} script from the top directory in the
21825 source tree, the @file{gdb-@var{version-number}} directory. If you run
21826 @code{configure} from one of the subdirectories, you will configure only
21827 that subdirectory. That is usually not what you want. In particular,
21828 if you run the first @code{configure} from the @file{gdb} subdirectory
21829 of the @file{gdb-@var{version-number}} directory, you will omit the
21830 configuration of @file{bfd}, @file{readline}, and other sibling
21831 directories of the @file{gdb} subdirectory. This leads to build errors
21832 about missing include files such as @file{bfd/bfd.h}.
21833
21834 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21835 However, you should make sure that the shell on your path (named by
21836 the @samp{SHELL} environment variable) is publicly readable. Remember
21837 that @value{GDBN} uses the shell to start your program---some systems refuse to
21838 let @value{GDBN} debug child processes whose programs are not readable.
21839
21840 @menu
21841 * Separate Objdir:: Compiling @value{GDBN} in another directory
21842 * Config Names:: Specifying names for hosts and targets
21843 * Configure Options:: Summary of options for configure
21844 @end menu
21845
21846 @node Separate Objdir
21847 @section Compiling @value{GDBN} in another directory
21848
21849 If you want to run @value{GDBN} versions for several host or target machines,
21850 you need a different @code{gdb} compiled for each combination of
21851 host and target. @code{configure} is designed to make this easy by
21852 allowing you to generate each configuration in a separate subdirectory,
21853 rather than in the source directory. If your @code{make} program
21854 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21855 @code{make} in each of these directories builds the @code{gdb}
21856 program specified there.
21857
21858 To build @code{gdb} in a separate directory, run @code{configure}
21859 with the @samp{--srcdir} option to specify where to find the source.
21860 (You also need to specify a path to find @code{configure}
21861 itself from your working directory. If the path to @code{configure}
21862 would be the same as the argument to @samp{--srcdir}, you can leave out
21863 the @samp{--srcdir} option; it is assumed.)
21864
21865 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21866 separate directory for a Sun 4 like this:
21867
21868 @smallexample
21869 @group
21870 cd gdb-@value{GDBVN}
21871 mkdir ../gdb-sun4
21872 cd ../gdb-sun4
21873 ../gdb-@value{GDBVN}/configure sun4
21874 make
21875 @end group
21876 @end smallexample
21877
21878 When @code{configure} builds a configuration using a remote source
21879 directory, it creates a tree for the binaries with the same structure
21880 (and using the same names) as the tree under the source directory. In
21881 the example, you'd find the Sun 4 library @file{libiberty.a} in the
21882 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21883 @file{gdb-sun4/gdb}.
21884
21885 Make sure that your path to the @file{configure} script has just one
21886 instance of @file{gdb} in it. If your path to @file{configure} looks
21887 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21888 one subdirectory of @value{GDBN}, not the whole package. This leads to
21889 build errors about missing include files such as @file{bfd/bfd.h}.
21890
21891 One popular reason to build several @value{GDBN} configurations in separate
21892 directories is to configure @value{GDBN} for cross-compiling (where
21893 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
21894 programs that run on another machine---the @dfn{target}).
21895 You specify a cross-debugging target by
21896 giving the @samp{--target=@var{target}} option to @code{configure}.
21897
21898 When you run @code{make} to build a program or library, you must run
21899 it in a configured directory---whatever directory you were in when you
21900 called @code{configure} (or one of its subdirectories).
21901
21902 The @code{Makefile} that @code{configure} generates in each source
21903 directory also runs recursively. If you type @code{make} in a source
21904 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21905 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21906 will build all the required libraries, and then build GDB.
21907
21908 When you have multiple hosts or targets configured in separate
21909 directories, you can run @code{make} on them in parallel (for example,
21910 if they are NFS-mounted on each of the hosts); they will not interfere
21911 with each other.
21912
21913 @node Config Names
21914 @section Specifying names for hosts and targets
21915
21916 The specifications used for hosts and targets in the @code{configure}
21917 script are based on a three-part naming scheme, but some short predefined
21918 aliases are also supported. The full naming scheme encodes three pieces
21919 of information in the following pattern:
21920
21921 @smallexample
21922 @var{architecture}-@var{vendor}-@var{os}
21923 @end smallexample
21924
21925 For example, you can use the alias @code{sun4} as a @var{host} argument,
21926 or as the value for @var{target} in a @code{--target=@var{target}}
21927 option. The equivalent full name is @samp{sparc-sun-sunos4}.
21928
21929 The @code{configure} script accompanying @value{GDBN} does not provide
21930 any query facility to list all supported host and target names or
21931 aliases. @code{configure} calls the Bourne shell script
21932 @code{config.sub} to map abbreviations to full names; you can read the
21933 script, if you wish, or you can use it to test your guesses on
21934 abbreviations---for example:
21935
21936 @smallexample
21937 % sh config.sub i386-linux
21938 i386-pc-linux-gnu
21939 % sh config.sub alpha-linux
21940 alpha-unknown-linux-gnu
21941 % sh config.sub hp9k700
21942 hppa1.1-hp-hpux
21943 % sh config.sub sun4
21944 sparc-sun-sunos4.1.1
21945 % sh config.sub sun3
21946 m68k-sun-sunos4.1.1
21947 % sh config.sub i986v
21948 Invalid configuration `i986v': machine `i986v' not recognized
21949 @end smallexample
21950
21951 @noindent
21952 @code{config.sub} is also distributed in the @value{GDBN} source
21953 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
21954
21955 @node Configure Options
21956 @section @code{configure} options
21957
21958 Here is a summary of the @code{configure} options and arguments that
21959 are most often useful for building @value{GDBN}. @code{configure} also has
21960 several other options not listed here. @inforef{What Configure
21961 Does,,configure.info}, for a full explanation of @code{configure}.
21962
21963 @smallexample
21964 configure @r{[}--help@r{]}
21965 @r{[}--prefix=@var{dir}@r{]}
21966 @r{[}--exec-prefix=@var{dir}@r{]}
21967 @r{[}--srcdir=@var{dirname}@r{]}
21968 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21969 @r{[}--target=@var{target}@r{]}
21970 @var{host}
21971 @end smallexample
21972
21973 @noindent
21974 You may introduce options with a single @samp{-} rather than
21975 @samp{--} if you prefer; but you may abbreviate option names if you use
21976 @samp{--}.
21977
21978 @table @code
21979 @item --help
21980 Display a quick summary of how to invoke @code{configure}.
21981
21982 @item --prefix=@var{dir}
21983 Configure the source to install programs and files under directory
21984 @file{@var{dir}}.
21985
21986 @item --exec-prefix=@var{dir}
21987 Configure the source to install programs under directory
21988 @file{@var{dir}}.
21989
21990 @c avoid splitting the warning from the explanation:
21991 @need 2000
21992 @item --srcdir=@var{dirname}
21993 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21994 @code{make} that implements the @code{VPATH} feature.}@*
21995 Use this option to make configurations in directories separate from the
21996 @value{GDBN} source directories. Among other things, you can use this to
21997 build (or maintain) several configurations simultaneously, in separate
21998 directories. @code{configure} writes configuration specific files in
21999 the current directory, but arranges for them to use the source in the
22000 directory @var{dirname}. @code{configure} creates directories under
22001 the working directory in parallel to the source directories below
22002 @var{dirname}.
22003
22004 @item --norecursion
22005 Configure only the directory level where @code{configure} is executed; do not
22006 propagate configuration to subdirectories.
22007
22008 @item --target=@var{target}
22009 Configure @value{GDBN} for cross-debugging programs running on the specified
22010 @var{target}. Without this option, @value{GDBN} is configured to debug
22011 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
22012
22013 There is no convenient way to generate a list of all available targets.
22014
22015 @item @var{host} @dots{}
22016 Configure @value{GDBN} to run on the specified @var{host}.
22017
22018 There is no convenient way to generate a list of all available hosts.
22019 @end table
22020
22021 There are many other options available as well, but they are generally
22022 needed for special purposes only.
22023
22024 @node Maintenance Commands
22025 @appendix Maintenance Commands
22026 @cindex maintenance commands
22027 @cindex internal commands
22028
22029 In addition to commands intended for @value{GDBN} users, @value{GDBN}
22030 includes a number of commands intended for @value{GDBN} developers,
22031 that are not documented elsewhere in this manual. These commands are
22032 provided here for reference. (For commands that turn on debugging
22033 messages, see @ref{Debugging Output}.)
22034
22035 @table @code
22036 @kindex maint agent
22037 @item maint agent @var{expression}
22038 Translate the given @var{expression} into remote agent bytecodes.
22039 This command is useful for debugging the Agent Expression mechanism
22040 (@pxref{Agent Expressions}).
22041
22042 @kindex maint info breakpoints
22043 @item @anchor{maint info breakpoints}maint info breakpoints
22044 Using the same format as @samp{info breakpoints}, display both the
22045 breakpoints you've set explicitly, and those @value{GDBN} is using for
22046 internal purposes. Internal breakpoints are shown with negative
22047 breakpoint numbers. The type column identifies what kind of breakpoint
22048 is shown:
22049
22050 @table @code
22051 @item breakpoint
22052 Normal, explicitly set breakpoint.
22053
22054 @item watchpoint
22055 Normal, explicitly set watchpoint.
22056
22057 @item longjmp
22058 Internal breakpoint, used to handle correctly stepping through
22059 @code{longjmp} calls.
22060
22061 @item longjmp resume
22062 Internal breakpoint at the target of a @code{longjmp}.
22063
22064 @item until
22065 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
22066
22067 @item finish
22068 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
22069
22070 @item shlib events
22071 Shared library events.
22072
22073 @end table
22074
22075 @kindex maint check-symtabs
22076 @item maint check-symtabs
22077 Check the consistency of psymtabs and symtabs.
22078
22079 @kindex maint cplus first_component
22080 @item maint cplus first_component @var{name}
22081 Print the first C@t{++} class/namespace component of @var{name}.
22082
22083 @kindex maint cplus namespace
22084 @item maint cplus namespace
22085 Print the list of possible C@t{++} namespaces.
22086
22087 @kindex maint demangle
22088 @item maint demangle @var{name}
22089 Demangle a C@t{++} or Objective-C manled @var{name}.
22090
22091 @kindex maint deprecate
22092 @kindex maint undeprecate
22093 @cindex deprecated commands
22094 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22095 @itemx maint undeprecate @var{command}
22096 Deprecate or undeprecate the named @var{command}. Deprecated commands
22097 cause @value{GDBN} to issue a warning when you use them. The optional
22098 argument @var{replacement} says which newer command should be used in
22099 favor of the deprecated one; if it is given, @value{GDBN} will mention
22100 the replacement as part of the warning.
22101
22102 @kindex maint dump-me
22103 @item maint dump-me
22104 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
22105 Cause a fatal signal in the debugger and force it to dump its core.
22106 This is supported only on systems which support aborting a program
22107 with the @code{SIGQUIT} signal.
22108
22109 @kindex maint internal-error
22110 @kindex maint internal-warning
22111 @item maint internal-error @r{[}@var{message-text}@r{]}
22112 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
22113 Cause @value{GDBN} to call the internal function @code{internal_error}
22114 or @code{internal_warning} and hence behave as though an internal error
22115 or internal warning has been detected. In addition to reporting the
22116 internal problem, these functions give the user the opportunity to
22117 either quit @value{GDBN} or create a core file of the current
22118 @value{GDBN} session.
22119
22120 These commands take an optional parameter @var{message-text} that is
22121 used as the text of the error or warning message.
22122
22123 Here's an example of using @code{indernal-error}:
22124
22125 @smallexample
22126 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
22127 @dots{}/maint.c:121: internal-error: testing, 1, 2
22128 A problem internal to GDB has been detected. Further
22129 debugging may prove unreliable.
22130 Quit this debugging session? (y or n) @kbd{n}
22131 Create a core file? (y or n) @kbd{n}
22132 (@value{GDBP})
22133 @end smallexample
22134
22135 @kindex maint packet
22136 @item maint packet @var{text}
22137 If @value{GDBN} is talking to an inferior via the serial protocol,
22138 then this command sends the string @var{text} to the inferior, and
22139 displays the response packet. @value{GDBN} supplies the initial
22140 @samp{$} character, the terminating @samp{#} character, and the
22141 checksum.
22142
22143 @kindex maint print architecture
22144 @item maint print architecture @r{[}@var{file}@r{]}
22145 Print the entire architecture configuration. The optional argument
22146 @var{file} names the file where the output goes.
22147
22148 @kindex maint print dummy-frames
22149 @item maint print dummy-frames
22150 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
22151
22152 @smallexample
22153 (@value{GDBP}) @kbd{b add}
22154 @dots{}
22155 (@value{GDBP}) @kbd{print add(2,3)}
22156 Breakpoint 2, add (a=2, b=3) at @dots{}
22157 58 return (a + b);
22158 The program being debugged stopped while in a function called from GDB.
22159 @dots{}
22160 (@value{GDBP}) @kbd{maint print dummy-frames}
22161 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
22162 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
22163 call_lo=0x01014000 call_hi=0x01014001
22164 (@value{GDBP})
22165 @end smallexample
22166
22167 Takes an optional file parameter.
22168
22169 @kindex maint print registers
22170 @kindex maint print raw-registers
22171 @kindex maint print cooked-registers
22172 @kindex maint print register-groups
22173 @item maint print registers @r{[}@var{file}@r{]}
22174 @itemx maint print raw-registers @r{[}@var{file}@r{]}
22175 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
22176 @itemx maint print register-groups @r{[}@var{file}@r{]}
22177 Print @value{GDBN}'s internal register data structures.
22178
22179 The command @code{maint print raw-registers} includes the contents of
22180 the raw register cache; the command @code{maint print cooked-registers}
22181 includes the (cooked) value of all registers; and the command
22182 @code{maint print register-groups} includes the groups that each
22183 register is a member of. @xref{Registers,, Registers, gdbint,
22184 @value{GDBN} Internals}.
22185
22186 These commands take an optional parameter, a file name to which to
22187 write the information.
22188
22189 @kindex maint print reggroups
22190 @item maint print reggroups @r{[}@var{file}@r{]}
22191 Print @value{GDBN}'s internal register group data structures. The
22192 optional argument @var{file} tells to what file to write the
22193 information.
22194
22195 The register groups info looks like this:
22196
22197 @smallexample
22198 (@value{GDBP}) @kbd{maint print reggroups}
22199 Group Type
22200 general user
22201 float user
22202 all user
22203 vector user
22204 system user
22205 save internal
22206 restore internal
22207 @end smallexample
22208
22209 @kindex flushregs
22210 @item flushregs
22211 This command forces @value{GDBN} to flush its internal register cache.
22212
22213 @kindex maint print objfiles
22214 @cindex info for known object files
22215 @item maint print objfiles
22216 Print a dump of all known object files. For each object file, this
22217 command prints its name, address in memory, and all of its psymtabs
22218 and symtabs.
22219
22220 @kindex maint print statistics
22221 @cindex bcache statistics
22222 @item maint print statistics
22223 This command prints, for each object file in the program, various data
22224 about that object file followed by the byte cache (@dfn{bcache})
22225 statistics for the object file. The objfile data includes the number
22226 of minimal, partical, full, and stabs symbols, the number of types
22227 defined by the objfile, the number of as yet unexpanded psym tables,
22228 the number of line tables and string tables, and the amount of memory
22229 used by the various tables. The bcache statistics include the counts,
22230 sizes, and counts of duplicates of all and unique objects, max,
22231 average, and median entry size, total memory used and its overhead and
22232 savings, and various measures of the hash table size and chain
22233 lengths.
22234
22235 @kindex maint print type
22236 @cindex type chain of a data type
22237 @item maint print type @var{expr}
22238 Print the type chain for a type specified by @var{expr}. The argument
22239 can be either a type name or a symbol. If it is a symbol, the type of
22240 that symbol is described. The type chain produced by this command is
22241 a recursive definition of the data type as stored in @value{GDBN}'s
22242 data structures, including its flags and contained types.
22243
22244 @kindex maint set dwarf2 max-cache-age
22245 @kindex maint show dwarf2 max-cache-age
22246 @item maint set dwarf2 max-cache-age
22247 @itemx maint show dwarf2 max-cache-age
22248 Control the DWARF 2 compilation unit cache.
22249
22250 @cindex DWARF 2 compilation units cache
22251 In object files with inter-compilation-unit references, such as those
22252 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
22253 reader needs to frequently refer to previously read compilation units.
22254 This setting controls how long a compilation unit will remain in the
22255 cache if it is not referenced. A higher limit means that cached
22256 compilation units will be stored in memory longer, and more total
22257 memory will be used. Setting it to zero disables caching, which will
22258 slow down @value{GDBN} startup, but reduce memory consumption.
22259
22260 @kindex maint set profile
22261 @kindex maint show profile
22262 @cindex profiling GDB
22263 @item maint set profile
22264 @itemx maint show profile
22265 Control profiling of @value{GDBN}.
22266
22267 Profiling will be disabled until you use the @samp{maint set profile}
22268 command to enable it. When you enable profiling, the system will begin
22269 collecting timing and execution count data; when you disable profiling or
22270 exit @value{GDBN}, the results will be written to a log file. Remember that
22271 if you use profiling, @value{GDBN} will overwrite the profiling log file
22272 (often called @file{gmon.out}). If you have a record of important profiling
22273 data in a @file{gmon.out} file, be sure to move it to a safe location.
22274
22275 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
22276 compiled with the @samp{-pg} compiler option.
22277
22278 @kindex maint show-debug-regs
22279 @cindex x86 hardware debug registers
22280 @item maint show-debug-regs
22281 Control whether to show variables that mirror the x86 hardware debug
22282 registers. Use @code{ON} to enable, @code{OFF} to disable. If
22283 enabled, the debug registers values are shown when GDB inserts or
22284 removes a hardware breakpoint or watchpoint, and when the inferior
22285 triggers a hardware-assisted breakpoint or watchpoint.
22286
22287 @kindex maint space
22288 @cindex memory used by commands
22289 @item maint space
22290 Control whether to display memory usage for each command. If set to a
22291 nonzero value, @value{GDBN} will display how much memory each command
22292 took, following the command's own output. This can also be requested
22293 by invoking @value{GDBN} with the @option{--statistics} command-line
22294 switch (@pxref{Mode Options}).
22295
22296 @kindex maint time
22297 @cindex time of command execution
22298 @item maint time
22299 Control whether to display the execution time for each command. If
22300 set to a nonzero value, @value{GDBN} will display how much time it
22301 took to execute each command, following the command's own output.
22302 This can also be requested by invoking @value{GDBN} with the
22303 @option{--statistics} command-line switch (@pxref{Mode Options}).
22304
22305 @kindex maint translate-address
22306 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
22307 Find the symbol stored at the location specified by the address
22308 @var{addr} and an optional section name @var{section}. If found,
22309 @value{GDBN} prints the name of the closest symbol and an offset from
22310 the symbol's location to the specified address. This is similar to
22311 the @code{info address} command (@pxref{Symbols}), except that this
22312 command also allows to find symbols in other sections.
22313
22314 @end table
22315
22316 The following command is useful for non-interactive invocations of
22317 @value{GDBN}, such as in the test suite.
22318
22319 @table @code
22320 @item set watchdog @var{nsec}
22321 @kindex set watchdog
22322 @cindex watchdog timer
22323 @cindex timeout for commands
22324 Set the maximum number of seconds @value{GDBN} will wait for the
22325 target operation to finish. If this time expires, @value{GDBN}
22326 reports and error and the command is aborted.
22327
22328 @item show watchdog
22329 Show the current setting of the target wait timeout.
22330 @end table
22331
22332 @node Remote Protocol
22333 @appendix @value{GDBN} Remote Serial Protocol
22334
22335 @menu
22336 * Overview::
22337 * Packets::
22338 * Stop Reply Packets::
22339 * General Query Packets::
22340 * Register Packet Format::
22341 * Tracepoint Packets::
22342 * Interrupts::
22343 * Examples::
22344 * File-I/O remote protocol extension::
22345 @end menu
22346
22347 @node Overview
22348 @section Overview
22349
22350 There may be occasions when you need to know something about the
22351 protocol---for example, if there is only one serial port to your target
22352 machine, you might want your program to do something special if it
22353 recognizes a packet meant for @value{GDBN}.
22354
22355 In the examples below, @samp{->} and @samp{<-} are used to indicate
22356 transmitted and received data respectfully.
22357
22358 @cindex protocol, @value{GDBN} remote serial
22359 @cindex serial protocol, @value{GDBN} remote
22360 @cindex remote serial protocol
22361 All @value{GDBN} commands and responses (other than acknowledgments) are
22362 sent as a @var{packet}. A @var{packet} is introduced with the character
22363 @samp{$}, the actual @var{packet-data}, and the terminating character
22364 @samp{#} followed by a two-digit @var{checksum}:
22365
22366 @smallexample
22367 @code{$}@var{packet-data}@code{#}@var{checksum}
22368 @end smallexample
22369 @noindent
22370
22371 @cindex checksum, for @value{GDBN} remote
22372 @noindent
22373 The two-digit @var{checksum} is computed as the modulo 256 sum of all
22374 characters between the leading @samp{$} and the trailing @samp{#} (an
22375 eight bit unsigned checksum).
22376
22377 Implementors should note that prior to @value{GDBN} 5.0 the protocol
22378 specification also included an optional two-digit @var{sequence-id}:
22379
22380 @smallexample
22381 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
22382 @end smallexample
22383
22384 @cindex sequence-id, for @value{GDBN} remote
22385 @noindent
22386 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
22387 has never output @var{sequence-id}s. Stubs that handle packets added
22388 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
22389
22390 @cindex acknowledgment, for @value{GDBN} remote
22391 When either the host or the target machine receives a packet, the first
22392 response expected is an acknowledgment: either @samp{+} (to indicate
22393 the package was received correctly) or @samp{-} (to request
22394 retransmission):
22395
22396 @smallexample
22397 -> @code{$}@var{packet-data}@code{#}@var{checksum}
22398 <- @code{+}
22399 @end smallexample
22400 @noindent
22401
22402 The host (@value{GDBN}) sends @var{command}s, and the target (the
22403 debugging stub incorporated in your program) sends a @var{response}. In
22404 the case of step and continue @var{command}s, the response is only sent
22405 when the operation has completed (the target has again stopped).
22406
22407 @var{packet-data} consists of a sequence of characters with the
22408 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
22409 exceptions).
22410
22411 Fields within the packet should be separated using @samp{,} @samp{;} or
22412 @cindex remote protocol, field separator
22413 @samp{:}. Except where otherwise noted all numbers are represented in
22414 @sc{hex} with leading zeros suppressed.
22415
22416 Implementors should note that prior to @value{GDBN} 5.0, the character
22417 @samp{:} could not appear as the third character in a packet (as it
22418 would potentially conflict with the @var{sequence-id}).
22419
22420 Response @var{data} can be run-length encoded to save space. A @samp{*}
22421 means that the next character is an @sc{ascii} encoding giving a repeat count
22422 which stands for that many repetitions of the character preceding the
22423 @samp{*}. The encoding is @code{n+29}, yielding a printable character
22424 where @code{n >=3} (which is where rle starts to win). The printable
22425 characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22426 value greater than 126 should not be used.
22427
22428 So:
22429 @smallexample
22430 "@code{0* }"
22431 @end smallexample
22432 @noindent
22433 means the same as "0000".
22434
22435 The error response returned for some packets includes a two character
22436 error number. That number is not well defined.
22437
22438 For any @var{command} not supported by the stub, an empty response
22439 (@samp{$#00}) should be returned. That way it is possible to extend the
22440 protocol. A newer @value{GDBN} can tell if a packet is supported based
22441 on that response.
22442
22443 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22444 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
22445 optional.
22446
22447 @node Packets
22448 @section Packets
22449
22450 The following table provides a complete list of all currently defined
22451 @var{command}s and their corresponding response @var{data}.
22452 @xref{File-I/O remote protocol extension}, for details about the File
22453 I/O extension of the remote protocol.
22454
22455 Each packet's description has a template showing the packet's overall
22456 syntax, followed by an explanation of the packet's meaning. We
22457 include spaces in some of the templates for clarity; these are not
22458 part of the packet's syntax. No @value{GDBN} packet uses spaces to
22459 separate its components. For example, a template like @samp{foo
22460 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
22461 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
22462 @var{baz}. GDB does not transmit a space character between the
22463 @samp{foo} and the @var{bar}, or between the @var{bar} and the
22464 @var{baz}.
22465
22466 Note that all packet forms beginning with an upper- or lower-case
22467 letter, other than those described here, are reserved for future use.
22468
22469 Here are the packet descriptions.
22470
22471 @table @samp
22472
22473 @item !
22474 @cindex @samp{!} packet
22475 Enable extended mode. In extended mode, the remote server is made
22476 persistent. The @samp{R} packet is used to restart the program being
22477 debugged.
22478
22479 Reply:
22480 @table @samp
22481 @item OK
22482 The remote target both supports and has enabled extended mode.
22483 @end table
22484
22485 @item ?
22486 @cindex @samp{?} packet
22487 Indicate the reason the target halted. The reply is the same as for
22488 step and continue.
22489
22490 Reply:
22491 @xref{Stop Reply Packets}, for the reply specifications.
22492
22493 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
22494 @cindex @samp{A} packet
22495 Initialized @code{argv[]} array passed into program. @var{arglen}
22496 specifies the number of bytes in the hex encoded byte stream
22497 @var{arg}. See @code{gdbserver} for more details.
22498
22499 Reply:
22500 @table @samp
22501 @item OK
22502 The arguments were set.
22503 @item E @var{NN}
22504 An error occurred.
22505 @end table
22506
22507 @item b @var{baud}
22508 @cindex @samp{b} packet
22509 (Don't use this packet; its behavior is not well-defined.)
22510 Change the serial line speed to @var{baud}.
22511
22512 JTC: @emph{When does the transport layer state change? When it's
22513 received, or after the ACK is transmitted. In either case, there are
22514 problems if the command or the acknowledgment packet is dropped.}
22515
22516 Stan: @emph{If people really wanted to add something like this, and get
22517 it working for the first time, they ought to modify ser-unix.c to send
22518 some kind of out-of-band message to a specially-setup stub and have the
22519 switch happen "in between" packets, so that from remote protocol's point
22520 of view, nothing actually happened.}
22521
22522 @item B @var{addr},@var{mode}
22523 @cindex @samp{B} packet
22524 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
22525 breakpoint at @var{addr}.
22526
22527 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
22528 (@pxref{insert breakpoint or watchpoint packet}).
22529
22530 @item c @var{addr}
22531 @cindex @samp{c} packet
22532 Continue. @var{addr} is address to resume. If @var{addr} is omitted,
22533 resume at current address.
22534
22535 Reply:
22536 @xref{Stop Reply Packets}, for the reply specifications.
22537
22538 @item C @var{sig};@var{addr}
22539 @cindex @samp{C} packet
22540 Continue with signal @var{sig} (hex signal number). If
22541 @samp{;@var{addr}} is omitted, resume at same address.
22542
22543 Reply:
22544 @xref{Stop Reply Packets}, for the reply specifications.
22545
22546 @item d
22547 @cindex @samp{d} packet
22548 Toggle debug flag.
22549
22550 Don't use this packet; instead, define a general set packet
22551 (@pxref{General Query Packets}).
22552
22553 @item D
22554 @cindex @samp{D} packet
22555 Detach @value{GDBN} from the remote system. Sent to the remote target
22556 before @value{GDBN} disconnects via the @code{detach} command.
22557
22558 Reply:
22559 @table @samp
22560 @item OK
22561 for success
22562 @item E @var{NN}
22563 for an error
22564 @end table
22565
22566 @item F @var{RC},@var{EE},@var{CF};@var{XX}
22567 @cindex @samp{F} packet
22568 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
22569 This is part of the File-I/O protocol extension. @xref{File-I/O
22570 remote protocol extension}, for the specification.
22571
22572 @item g
22573 @anchor{read registers packet}
22574 @cindex @samp{g} packet
22575 Read general registers.
22576
22577 Reply:
22578 @table @samp
22579 @item @var{XX@dots{}}
22580 Each byte of register data is described by two hex digits. The bytes
22581 with the register are transmitted in target byte order. The size of
22582 each register and their position within the @samp{g} packet are
22583 determined by the @value{GDBN} internal macros
22584 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{REGISTER_NAME} macros. The
22585 specification of several standard @samp{g} packets is specified below.
22586 @item E @var{NN}
22587 for an error.
22588 @end table
22589
22590 @item G @var{XX@dots{}}
22591 @cindex @samp{G} packet
22592 Write general registers. @xref{read registers packet}, for a
22593 description of the @var{XX@dots{}} data.
22594
22595 Reply:
22596 @table @samp
22597 @item OK
22598 for success
22599 @item E @var{NN}
22600 for an error
22601 @end table
22602
22603 @item H @var{c} @var{t}
22604 @cindex @samp{H} packet
22605 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
22606 @samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22607 should be @samp{c} for step and continue operations, @samp{g} for other
22608 operations. The thread designator @var{t} may be @samp{-1}, meaning all
22609 the threads, a thread number, or @samp{0} which means pick any thread.
22610
22611 Reply:
22612 @table @samp
22613 @item OK
22614 for success
22615 @item E @var{NN}
22616 for an error
22617 @end table
22618
22619 @c FIXME: JTC:
22620 @c 'H': How restrictive (or permissive) is the thread model. If a
22621 @c thread is selected and stopped, are other threads allowed
22622 @c to continue to execute? As I mentioned above, I think the
22623 @c semantics of each command when a thread is selected must be
22624 @c described. For example:
22625 @c
22626 @c 'g': If the stub supports threads and a specific thread is
22627 @c selected, returns the register block from that thread;
22628 @c otherwise returns current registers.
22629 @c
22630 @c 'G' If the stub supports threads and a specific thread is
22631 @c selected, sets the registers of the register block of
22632 @c that thread; otherwise sets current registers.
22633
22634 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
22635 @anchor{cycle step packet}
22636 @cindex @samp{i} packet
22637 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
22638 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22639 step starting at that address.
22640
22641 @item I
22642 @cindex @samp{I} packet
22643 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
22644 step packet}.
22645
22646 @item k
22647 @cindex @samp{k} packet
22648 Kill request.
22649
22650 FIXME: @emph{There is no description of how to operate when a specific
22651 thread context has been selected (i.e.@: does 'k' kill only that
22652 thread?)}.
22653
22654 @item m @var{addr},@var{length}
22655 @cindex @samp{m} packet
22656 Read @var{length} bytes of memory starting at address @var{addr}.
22657 Note that @var{addr} may not be aligned to any particular boundary.
22658
22659 The stub need not use any particular size or alignment when gathering
22660 data from memory for the response; even if @var{addr} is word-aligned
22661 and @var{length} is a multiple of the word size, the stub is free to
22662 use byte accesses, or not. For this reason, this packet may not be
22663 suitable for accessing memory-mapped I/O devices.
22664 @cindex alignment of remote memory accesses
22665 @cindex size of remote memory accesses
22666 @cindex memory, alignment and size of remote accesses
22667
22668 Reply:
22669 @table @samp
22670 @item @var{XX@dots{}}
22671 Memory contents; each byte is transmitted as a two-digit hexidecimal
22672 number. The reply may contain fewer bytes than requested if the
22673 server was able to read only part of the region of memory.
22674 @item E @var{NN}
22675 @var{NN} is errno
22676 @end table
22677
22678 @item M @var{addr},@var{length}:@var{XX@dots{}}
22679 @cindex @samp{M} packet
22680 Write @var{length} bytes of memory starting at address @var{addr}.
22681 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
22682 hexidecimal number.
22683
22684 Reply:
22685 @table @samp
22686 @item OK
22687 for success
22688 @item E @var{NN}
22689 for an error (this includes the case where only part of the data was
22690 written).
22691 @end table
22692
22693 @item p @var{n}
22694 @cindex @samp{p} packet
22695 Read the value of register @var{n}; @var{n} is in hex.
22696 @xref{read registers packet}, for a description of how the returned
22697 register value is encoded.
22698
22699 Reply:
22700 @table @samp
22701 @item @var{XX@dots{}}
22702 the register's value
22703 @item E @var{NN}
22704 for an error
22705 @item
22706 Indicating an unrecognized @var{query}.
22707 @end table
22708
22709 @item P @var{n@dots{}}=@var{r@dots{}}
22710 @anchor{write register packet}
22711 @cindex @samp{P} packet
22712 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
22713 number @var{n} is in hexidecimal, and @var{r@dots{}} contains two hex
22714 digits for each byte in the register (target byte order).
22715
22716 Reply:
22717 @table @samp
22718 @item OK
22719 for success
22720 @item E @var{NN}
22721 for an error
22722 @end table
22723
22724 @item q @var{name} @var{params}@dots{}
22725 @itemx Q @var{name} @var{params}@dots{}
22726 @cindex @samp{q} packet
22727 @cindex @samp{Q} packet
22728 General query (@samp{q}) and set (@samp{Q}). These packets are
22729 described fully in @ref{General Query Packets}.
22730
22731 @item r
22732 @cindex @samp{r} packet
22733 Reset the entire system.
22734
22735 Don't use this packet; use the @samp{R} packet instead.
22736
22737 @item R @var{XX}
22738 @cindex @samp{R} packet
22739 Restart the program being debugged. @var{XX}, while needed, is ignored.
22740 This packet is only available in extended mode.
22741
22742 The @samp{R} packet has no reply.
22743
22744 @item s @var{addr}
22745 @cindex @samp{s} packet
22746 Single step. @var{addr} is the address at which to resume. If
22747 @var{addr} is omitted, resume at same address.
22748
22749 Reply:
22750 @xref{Stop Reply Packets}, for the reply specifications.
22751
22752 @item S @var{sig};@var{addr}
22753 @anchor{step with signal packet}
22754 @cindex @samp{S} packet
22755 Step with signal. This is analogous to the @samp{C} packet, but
22756 requests a single-step, rather than a normal resumption of execution.
22757
22758 Reply:
22759 @xref{Stop Reply Packets}, for the reply specifications.
22760
22761 @item t @var{addr}:@var{PP},@var{MM}
22762 @cindex @samp{t} packet
22763 Search backwards starting at address @var{addr} for a match with pattern
22764 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22765 @var{addr} must be at least 3 digits.
22766
22767 @item T @var{XX}
22768 @cindex @samp{T} packet
22769 Find out if the thread XX is alive.
22770
22771 Reply:
22772 @table @samp
22773 @item OK
22774 thread is still alive
22775 @item E @var{NN}
22776 thread is dead
22777 @end table
22778
22779 @item v
22780 Packets starting with @samp{v} are identified by a multi-letter name,
22781 up to the first @samp{;} or @samp{?} (or the end of the packet).
22782
22783 @item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
22784 @cindex @samp{vCont} packet
22785 Resume the inferior, specifying different actions for each thread.
22786 If an action is specified with no @var{tid}, then it is applied to any
22787 threads that don't have a specific action specified; if no default action is
22788 specified then other threads should remain stopped. Specifying multiple
22789 default actions is an error; specifying no actions is also an error.
22790 Thread IDs are specified in hexadecimal. Currently supported actions are:
22791
22792 @table @samp
22793 @item c
22794 Continue.
22795 @item C @var{sig}
22796 Continue with signal @var{sig}. @var{sig} should be two hex digits.
22797 @item s
22798 Step.
22799 @item S @var{sig}
22800 Step with signal @var{sig}. @var{sig} should be two hex digits.
22801 @end table
22802
22803 The optional @var{addr} argument normally associated with these packets is
22804 not supported in @samp{vCont}.
22805
22806 Reply:
22807 @xref{Stop Reply Packets}, for the reply specifications.
22808
22809 @item vCont?
22810 @cindex @samp{vCont?} packet
22811 Request a list of actions supporetd by the @samp{vCont} packet.
22812
22813 Reply:
22814 @table @samp
22815 @item vCont@r{[};@var{action}@dots{}@r{]}
22816 The @samp{vCont} packet is supported. Each @var{action} is a supported
22817 command in the @samp{vCont} packet.
22818 @item
22819 The @samp{vCont} packet is not supported.
22820 @end table
22821
22822 @item X @var{addr},@var{length}:@var{XX@dots{}}
22823 @anchor{X packet}
22824 @cindex @samp{X} packet
22825 Write data to memory, where the data is transmitted in binary.
22826 @var{addr} is address, @var{length} is number of bytes,
22827 @samp{@var{XX}@dots{}} is binary data. The bytes @code{0x23}
22828 (@sc{ascii} @samp{#}), @code{0x24} (@sc{ascii} @samp{$}), and
22829 @code{0x7d} (@sc{ascii} @samp{@}}) are escaped using @code{0x7d}
22830 (@sc{ascii} @samp{@}}), and then XORed with @code{0x20}. For example,
22831 the byte @code{0x7d} would be transmitted as the two bytes @code{0x7d
22832 0x5d}.
22833
22834 Reply:
22835 @table @samp
22836 @item OK
22837 for success
22838 @item E @var{NN}
22839 for an error
22840 @end table
22841
22842 @item z @var{type},@var{addr},@var{length}
22843 @itemx Z @var{type},@var{addr},@var{length}
22844 @anchor{insert breakpoint or watchpoint packet}
22845 @cindex @samp{z} packet
22846 @cindex @samp{Z} packets
22847 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
22848 watchpoint starting at address @var{address} and covering the next
22849 @var{length} bytes.
22850
22851 Each breakpoint and watchpoint packet @var{type} is documented
22852 separately.
22853
22854 @emph{Implementation notes: A remote target shall return an empty string
22855 for an unrecognized breakpoint or watchpoint packet @var{type}. A
22856 remote target shall support either both or neither of a given
22857 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
22858 avoid potential problems with duplicate packets, the operations should
22859 be implemented in an idempotent way.}
22860
22861 @item z0,@var{addr},@var{length}
22862 @itemx Z0,@var{addr},@var{length}
22863 @cindex @samp{z0} packet
22864 @cindex @samp{Z0} packet
22865 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
22866 @var{addr} of size @var{length}.
22867
22868 A memory breakpoint is implemented by replacing the instruction at
22869 @var{addr} with a software breakpoint or trap instruction. The
22870 @var{length} is used by targets that indicates the size of the
22871 breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22872 @sc{mips} can insert either a 2 or 4 byte breakpoint).
22873
22874 @emph{Implementation note: It is possible for a target to copy or move
22875 code that contains memory breakpoints (e.g., when implementing
22876 overlays). The behavior of this packet, in the presence of such a
22877 target, is not defined.}
22878
22879 Reply:
22880 @table @samp
22881 @item OK
22882 success
22883 @item
22884 not supported
22885 @item E @var{NN}
22886 for an error
22887 @end table
22888
22889 @item z1,@var{addr},@var{length}
22890 @itemx Z1,@var{addr},@var{length}
22891 @cindex @samp{z1} packet
22892 @cindex @samp{Z1} packet
22893 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
22894 address @var{addr} of size @var{length}.
22895
22896 A hardware breakpoint is implemented using a mechanism that is not
22897 dependant on being able to modify the target's memory.
22898
22899 @emph{Implementation note: A hardware breakpoint is not affected by code
22900 movement.}
22901
22902 Reply:
22903 @table @samp
22904 @item OK
22905 success
22906 @item
22907 not supported
22908 @item E @var{NN}
22909 for an error
22910 @end table
22911
22912 @item z2,@var{addr},@var{length}
22913 @itemx Z2,@var{addr},@var{length}
22914 @cindex @samp{z2} packet
22915 @cindex @samp{Z2} packet
22916 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
22917
22918 Reply:
22919 @table @samp
22920 @item OK
22921 success
22922 @item
22923 not supported
22924 @item E @var{NN}
22925 for an error
22926 @end table
22927
22928 @item z3,@var{addr},@var{length}
22929 @itemx Z3,@var{addr},@var{length}
22930 @cindex @samp{z3} packet
22931 @cindex @samp{Z3} packet
22932 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
22933
22934 Reply:
22935 @table @samp
22936 @item OK
22937 success
22938 @item
22939 not supported
22940 @item E @var{NN}
22941 for an error
22942 @end table
22943
22944 @item z4,@var{addr},@var{length}
22945 @itemx Z4,@var{addr},@var{length}
22946 @cindex @samp{z4} packet
22947 @cindex @samp{Z4} packet
22948 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
22949
22950 Reply:
22951 @table @samp
22952 @item OK
22953 success
22954 @item
22955 not supported
22956 @item E @var{NN}
22957 for an error
22958 @end table
22959
22960 @end table
22961
22962 @node Stop Reply Packets
22963 @section Stop Reply Packets
22964 @cindex stop reply packets
22965
22966 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22967 receive any of the below as a reply. In the case of the @samp{C},
22968 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22969 when the target halts. In the below the exact meaning of @dfn{signal
22970 number} is poorly defined. In general one of the UNIX signal
22971 numbering conventions is used.
22972
22973 As in the description of request packets, we include spaces in the
22974 reply templates for clarity; these are not part of the reply packet's
22975 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
22976 components.
22977
22978 @table @samp
22979
22980 @item S @var{AA}
22981 The program received signal number @var{AA} (a two-digit hexidecimal
22982 number).
22983
22984 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
22985 @cindex @samp{T} packet reply
22986 The program received signal number @var{AA} (a two-digit hexidecimal
22987 number). Single-step and breakpoint traps are reported this way. The
22988 @samp{@var{n}:@var{r}} pairs give the values of important registers or
22989 other information:
22990 @enumerate
22991 @item
22992 If @var{n} is a hexidecimal number, it is a register number, and the
22993 corresponding @var{r} gives that register's value. @var{r} is a
22994 series of bytes in target byte order, with each byte given by a
22995 two-digit hex number.
22996 @item
22997 If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
22998 hex.
22999 @item
23000 If @var{n} is @samp{watch}, @samp{rwatch}, or @samp{awatch}, then the
23001 packet indicates a watchpoint hit, and @var{r} is the data address, in
23002 hex.
23003 @item
23004 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
23005 and go on to the next; this allows us to extend the protocol in the
23006 future.
23007 @end enumerate
23008
23009 @item W @var{AA}
23010 The process exited, and @var{AA} is the exit status. This is only
23011 applicable to certain targets.
23012
23013 @item X @var{AA}
23014 The process terminated with signal @var{AA}.
23015
23016 @item O @var{XX}@dots{}
23017 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
23018 written as the program's console output. This can happen at any time
23019 while the program is running and the debugger should continue to wait
23020 for @samp{W}, @samp{T}, etc.
23021
23022 @item F @var{call-id},@var{parameter}@dots{}
23023 @var{call-id} is the identifier which says which host system call should
23024 be called. This is just the name of the function. Translation into the
23025 correct system call is only applicable as it's defined in @value{GDBN}.
23026 @xref{File-I/O remote protocol extension}, for a list of implemented
23027 system calls.
23028
23029 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
23030 this very system call.
23031
23032 The target replies with this packet when it expects @value{GDBN} to
23033 call a host system call on behalf of the target. @value{GDBN} replies
23034 with an appropriate @samp{F} packet and keeps up waiting for the next
23035 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
23036 or @samp{s} action is expected to be continued. @xref{File-I/O remote
23037 protocol extension}, for more details.
23038
23039 @end table
23040
23041 @node General Query Packets
23042 @section General Query Packets
23043 @cindex remote query requests
23044
23045 Packets starting with @samp{q} are @dfn{general query packets};
23046 packets starting with @samp{Q} are @dfn{general set packets}. General
23047 query and set packets are a semi-unified form for retrieving and
23048 sending information to and from the stub.
23049
23050 The initial letter of a query or set packet is followed by a name
23051 indicating what sort of thing the packet applies to. For example,
23052 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
23053 definitions with the stub. These packet names follow some
23054 conventions:
23055
23056 @itemize @bullet
23057 @item
23058 The name must not contain commas, colons or semicolons.
23059 @item
23060 Most @value{GDBN} query and set packets have a leading upper case
23061 letter.
23062 @item
23063 The names of custom vendor packets should use a company prefix, in
23064 lower case, followed by a period. For example, packets designed at
23065 the Acme Corporation might begin with @samp{qacme.foo} (for querying
23066 foos) or @samp{Qacme.bar} (for setting bars).
23067 @end itemize
23068
23069 A query or set packet may optionally be followed by a @samp{,} or
23070 @samp{;} separated list. Stubs must be careful to match the full
23071 packet name, in case packet names have common prefixes.
23072
23073 Like the descriptions of the other packets, each description here
23074 has a template showing the packet's overall syntax, followed by an
23075 explanation of the packet's meaning. We include spaces in some of the
23076 templates for clarity; these are not part of the packet's syntax. No
23077 @value{GDBN} packet uses spaces to separate its components.
23078
23079 Here are the currently defined query and set packets:
23080
23081 @table @samp
23082
23083 @item qC
23084 @cindex current thread, remote request
23085 @cindex @samp{qC} packet
23086 Return the current thread id.
23087
23088 Reply:
23089 @table @samp
23090 @item QC @var{pid}
23091 Where @var{pid} is an unsigned hexidecimal process id.
23092 @item @r{(anything else)}
23093 Any other reply implies the old pid.
23094 @end table
23095
23096 @item qCRC:@var{addr},@var{length}
23097 @cindex CRC of memory block, remote request
23098 @cindex @samp{qCRC} packet
23099 Compute the CRC checksum of a block of memory.
23100 Reply:
23101 @table @samp
23102 @item E @var{NN}
23103 An error (such as memory fault)
23104 @item C @var{crc32}
23105 The specified memory region's checksum is @var{crc32}.
23106 @end table
23107
23108 @item qfThreadInfo
23109 @itemx qsThreadInfo
23110 @cindex list active threads, remote request
23111 @cindex @samp{qfThreadInfo} packet
23112 @cindex @samp{qsThreadInfo} packet
23113 Obtain a list of all active thread ids from the target (OS). Since there
23114 may be too many active threads to fit into one reply packet, this query
23115 works iteratively: it may require more than one query/reply sequence to
23116 obtain the entire list of threads. The first query of the sequence will
23117 be the @samp{qfThreadInfo} query; subsequent queries in the
23118 sequence will be the @samp{qsThreadInfo} query.
23119
23120 NOTE: This packet replaces the @samp{qL} query (see below).
23121
23122 Reply:
23123 @table @samp
23124 @item m @var{id}
23125 A single thread id
23126 @item m @var{id},@var{id}@dots{}
23127 a comma-separated list of thread ids
23128 @item l
23129 (lower case letter @samp{L}) denotes end of list.
23130 @end table
23131
23132 In response to each query, the target will reply with a list of one or
23133 more thread ids, in big-endian unsigned hex, separated by commas.
23134 @value{GDBN} will respond to each reply with a request for more thread
23135 ids (using the @samp{qs} form of the query), until the target responds
23136 with @samp{l} (lower-case el, for @dfn{last}).
23137
23138 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
23139 @cindex get thread-local storage address, remote request
23140 @cindex @samp{qGetTLSAddr} packet
23141 Fetch the address associated with thread local storage specified
23142 by @var{thread-id}, @var{offset}, and @var{lm}.
23143
23144 @var{thread-id} is the (big endian, hex encoded) thread id associated with the
23145 thread for which to fetch the TLS address.
23146
23147 @var{offset} is the (big endian, hex encoded) offset associated with the
23148 thread local variable. (This offset is obtained from the debug
23149 information associated with the variable.)
23150
23151 @var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
23152 the load module associated with the thread local storage. For example,
23153 a @sc{gnu}/Linux system will pass the link map address of the shared
23154 object associated with the thread local storage under consideration.
23155 Other operating environments may choose to represent the load module
23156 differently, so the precise meaning of this parameter will vary.
23157
23158 Reply:
23159 @table @samp
23160 @item @var{XX}@dots{}
23161 Hex encoded (big endian) bytes representing the address of the thread
23162 local storage requested.
23163
23164 @item E @var{nn}
23165 An error occurred. @var{nn} are hex digits.
23166
23167 @item
23168 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
23169 @end table
23170
23171 Use of this request packet is controlled by the @code{set remote
23172 get-thread-local-storage-address} command (@pxref{Remote
23173 configuration, set remote get-thread-local-storage-address}).
23174
23175 @item qL @var{startflag} @var{threadcount} @var{nextthread}
23176 Obtain thread information from RTOS. Where: @var{startflag} (one hex
23177 digit) is one to indicate the first query and zero to indicate a
23178 subsequent query; @var{threadcount} (two hex digits) is the maximum
23179 number of threads the response packet can contain; and @var{nextthread}
23180 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
23181 returned in the response as @var{argthread}.
23182
23183 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
23184
23185 Reply:
23186 @table @samp
23187 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
23188 Where: @var{count} (two hex digits) is the number of threads being
23189 returned; @var{done} (one hex digit) is zero to indicate more threads
23190 and one indicates no further threads; @var{argthreadid} (eight hex
23191 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
23192 is a sequence of thread IDs from the target. @var{threadid} (eight hex
23193 digits). See @code{remote.c:parse_threadlist_response()}.
23194 @end table
23195
23196 @item qOffsets
23197 @cindex section offsets, remote request
23198 @cindex @samp{qOffsets} packet
23199 Get section offsets that the target used when re-locating the downloaded
23200 image. @emph{Note: while a @code{Bss} offset is included in the
23201 response, @value{GDBN} ignores this and instead applies the @code{Data}
23202 offset to the @code{Bss} section.}
23203
23204 Reply:
23205 @table @samp
23206 @item Text=@var{xxx};Data=@var{yyy};Bss=@var{zzz}
23207 @end table
23208
23209 @item qP @var{mode} @var{threadid}
23210 @cindex thread information, remote request
23211 @cindex @samp{qP} packet
23212 Returns information on @var{threadid}. Where: @var{mode} is a hex
23213 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
23214
23215 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
23216
23217 @item qPart:@var{object}:read:@var{annex}:@var{offset},@var{length}
23218 @cindex read special object, remote request
23219 @cindex @samp{qPart} packet
23220 Read uninterpreted bytes from the target's special data area
23221 identified by the keyword @var{object}. Request @var{length} bytes
23222 starting at @var{offset} bytes into the data. The content and
23223 encoding of @var{annex} is specific to the object; it can supply
23224 additional details about what data to access.
23225
23226 Here are the specific requests of this form defined so far. All
23227 @samp{qPart:@var{object}:read:@dots{}} requests use the same reply
23228 formats, listed below.
23229
23230 @table @samp
23231 @item qPart:auxv:read::@var{offset},@var{length}
23232 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
23233 auxiliary vector}, and see @ref{Remote configuration,
23234 read-aux-vector-packet}. Note @var{annex} must be empty.
23235 @end table
23236
23237 Reply:
23238 @table @samp
23239 @item OK
23240 The @var{offset} in the request is at the end of the data.
23241 There is no more data to be read.
23242
23243 @item @var{XX}@dots{}
23244 Hex encoded data bytes read.
23245 This may be fewer bytes than the @var{length} in the request.
23246
23247 @item E00
23248 The request was malformed, or @var{annex} was invalid.
23249
23250 @item E @var{nn}
23251 The offset was invalid, or there was an error encountered reading the data.
23252 @var{nn} is a hex-encoded @code{errno} value.
23253
23254 @item
23255 An empty reply indicates the @var{object} or @var{annex} string was not
23256 recognized by the stub.
23257 @end table
23258
23259 @item qPart:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
23260 @cindex write data into object, remote request
23261 Write uninterpreted bytes into the target's special data area
23262 identified by the keyword @var{object}, starting at @var{offset} bytes
23263 into the data. @samp{@var{data}@dots{}} is the hex-encoded data to be
23264 written. The content and encoding of @var{annex} is specific to the
23265 object; it can supply additional details about what data to access.
23266
23267 No requests of this form are presently in use. This specification
23268 serves as a placeholder to document the common format that new
23269 specific request specifications ought to use.
23270
23271 Reply:
23272 @table @samp
23273 @item @var{nn}
23274 @var{nn} (hex encoded) is the number of bytes written.
23275 This may be fewer bytes than supplied in the request.
23276
23277 @item E00
23278 The request was malformed, or @var{annex} was invalid.
23279
23280 @item E @var{nn}
23281 The offset was invalid, or there was an error encountered writing the data.
23282 @var{nn} is a hex-encoded @code{errno} value.
23283
23284 @item
23285 An empty reply indicates the @var{object} or @var{annex} string was not
23286 recognized by the stub, or that the object does not support writing.
23287 @end table
23288
23289 @item qPart:@var{object}:@var{operation}:@dots{}
23290 Requests of this form may be added in the future. When a stub does
23291 not recognize the @var{object} keyword, or its support for
23292 @var{object} does not recognize the @var{operation} keyword, the stub
23293 must respond with an empty packet.
23294
23295 @item qRcmd,@var{command}
23296 @cindex execute remote command, remote request
23297 @cindex @samp{qRcmd} packet
23298 @var{command} (hex encoded) is passed to the local interpreter for
23299 execution. Invalid commands should be reported using the output
23300 string. Before the final result packet, the target may also respond
23301 with a number of intermediate @samp{O@var{output}} console output
23302 packets. @emph{Implementors should note that providing access to a
23303 stubs's interpreter may have security implications}.
23304
23305 Reply:
23306 @table @samp
23307 @item OK
23308 A command response with no output.
23309 @item @var{OUTPUT}
23310 A command response with the hex encoded output string @var{OUTPUT}.
23311 @item E @var{NN}
23312 Indicate a badly formed request.
23313 @item
23314 An empty reply indicates that @samp{qRcmd} is not recognized.
23315 @end table
23316
23317 @item qSymbol::
23318 @cindex symbol lookup, remote request
23319 @cindex @samp{qSymbol} packet
23320 Notify the target that @value{GDBN} is prepared to serve symbol lookup
23321 requests. Accept requests from the target for the values of symbols.
23322
23323 Reply:
23324 @table @samp
23325 @item OK
23326 The target does not need to look up any (more) symbols.
23327 @item qSymbol:@var{sym_name}
23328 The target requests the value of symbol @var{sym_name} (hex encoded).
23329 @value{GDBN} may provide the value by using the
23330 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
23331 below.
23332 @end table
23333
23334 @item qSymbol:@var{sym_value}:@var{sym_name}
23335 Set the value of @var{sym_name} to @var{sym_value}.
23336
23337 @var{sym_name} (hex encoded) is the name of a symbol whose value the
23338 target has previously requested.
23339
23340 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
23341 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
23342 will be empty.
23343
23344 Reply:
23345 @table @samp
23346 @item OK
23347 The target does not need to look up any (more) symbols.
23348 @item qSymbol:@var{sym_name}
23349 The target requests the value of a new symbol @var{sym_name} (hex
23350 encoded). @value{GDBN} will continue to supply the values of symbols
23351 (if available), until the target ceases to request them.
23352 @end table
23353
23354 @item QTDP
23355 @itemx QTFrame
23356 @xref{Tracepoint Packets}.
23357
23358 @item qThreadExtraInfo,@var{id}
23359 @cindex thread attributes info, remote request
23360 @cindex @samp{qThreadExtraInfo} packet
23361 Obtain a printable string description of a thread's attributes from
23362 the target OS. @var{id} is a thread-id in big-endian hex. This
23363 string may contain anything that the target OS thinks is interesting
23364 for @value{GDBN} to tell the user about the thread. The string is
23365 displayed in @value{GDBN}'s @code{info threads} display. Some
23366 examples of possible thread extra info strings are @samp{Runnable}, or
23367 @samp{Blocked on Mutex}.
23368
23369 Reply:
23370 @table @samp
23371 @item @var{XX}@dots{}
23372 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
23373 comprising the printable string containing the extra information about
23374 the thread's attributes.
23375 @end table
23376
23377 @item QTStart
23378 @itemx QTStop
23379 @itemx QTinit
23380 @itemx QTro
23381 @itemx qTStatus
23382 @xref{Tracepoint Packets}.
23383
23384 @end table
23385
23386 @node Register Packet Format
23387 @section Register Packet Format
23388
23389 The following @code{g}/@code{G} packets have previously been defined.
23390 In the below, some thirty-two bit registers are transferred as
23391 sixty-four bits. Those registers should be zero/sign extended (which?)
23392 to fill the space allocated. Register bytes are transfered in target
23393 byte order. The two nibbles within a register byte are transfered
23394 most-significant - least-significant.
23395
23396 @table @r
23397
23398 @item MIPS32
23399
23400 All registers are transfered as thirty-two bit quantities in the order:
23401 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23402 registers; fsr; fir; fp.
23403
23404 @item MIPS64
23405
23406 All registers are transfered as sixty-four bit quantities (including
23407 thirty-two bit registers such as @code{sr}). The ordering is the same
23408 as @code{MIPS32}.
23409
23410 @end table
23411
23412 @node Tracepoint Packets
23413 @section Tracepoint Packets
23414 @cindex tracepoint packets
23415 @cindex packets, tracepoint
23416
23417 Here we describe the packets @value{GDBN} uses to implement
23418 tracepoints (@pxref{Tracepoints}).
23419
23420 @table @samp
23421
23422 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
23423 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
23424 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
23425 the tracepoint is disabled. @var{step} is the tracepoint's step
23426 count, and @var{pass} is its pass count. If the trailing @samp{-} is
23427 present, further @samp{QTDP} packets will follow to specify this
23428 tracepoint's actions.
23429
23430 Replies:
23431 @table @samp
23432 @item OK
23433 The packet was understood and carried out.
23434 @item
23435 The packet was not recognized.
23436 @end table
23437
23438 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
23439 Define actions to be taken when a tracepoint is hit. @var{n} and
23440 @var{addr} must be the same as in the initial @samp{QTDP} packet for
23441 this tracepoint. This packet may only be sent immediately after
23442 another @samp{QTDP} packet that ended with a @samp{-}. If the
23443 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
23444 specifying more actions for this tracepoint.
23445
23446 In the series of action packets for a given tracepoint, at most one
23447 can have an @samp{S} before its first @var{action}. If such a packet
23448 is sent, it and the following packets define ``while-stepping''
23449 actions. Any prior packets define ordinary actions --- that is, those
23450 taken when the tracepoint is first hit. If no action packet has an
23451 @samp{S}, then all the packets in the series specify ordinary
23452 tracepoint actions.
23453
23454 The @samp{@var{action}@dots{}} portion of the packet is a series of
23455 actions, concatenated without separators. Each action has one of the
23456 following forms:
23457
23458 @table @samp
23459
23460 @item R @var{mask}
23461 Collect the registers whose bits are set in @var{mask}. @var{mask} is
23462 a hexidecimal number whose @var{i}'th bit is set if register number
23463 @var{i} should be collected. (The least significant bit is numbered
23464 zero.) Note that @var{mask} may be any number of digits long; it may
23465 not fit in a 32-bit word.
23466
23467 @item M @var{basereg},@var{offset},@var{len}
23468 Collect @var{len} bytes of memory starting at the address in register
23469 number @var{basereg}, plus @var{offset}. If @var{basereg} is
23470 @samp{-1}, then the range has a fixed address: @var{offset} is the
23471 address of the lowest byte to collect. The @var{basereg},
23472 @var{offset}, and @var{len} parameters are all unsigned hexidecimal
23473 values (the @samp{-1} value for @var{basereg} is a special case).
23474
23475 @item X @var{len},@var{expr}
23476 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
23477 it directs. @var{expr} is an agent expression, as described in
23478 @ref{Agent Expressions}. Each byte of the expression is encoded as a
23479 two-digit hex number in the packet; @var{len} is the number of bytes
23480 in the expression (and thus one-half the number of hex digits in the
23481 packet).
23482
23483 @end table
23484
23485 Any number of actions may be packed together in a single @samp{QTDP}
23486 packet, as long as the packet does not exceed the maximum packet
23487 length (400 bytes, for many stubs). There may be only one @samp{R}
23488 action per tracepoint, and it must precede any @samp{M} or @samp{X}
23489 actions. Any registers referred to by @samp{M} and @samp{X} actions
23490 must be collected by a preceding @samp{R} action. (The
23491 ``while-stepping'' actions are treated as if they were attached to a
23492 separate tracepoint, as far as these restrictions are concerned.)
23493
23494 Replies:
23495 @table @samp
23496 @item OK
23497 The packet was understood and carried out.
23498 @item
23499 The packet was not recognized.
23500 @end table
23501
23502 @item QTFrame:@var{n}
23503 Select the @var{n}'th tracepoint frame from the buffer, and use the
23504 register and memory contents recorded there to answer subsequent
23505 request packets from @value{GDBN}.
23506
23507 A successful reply from the stub indicates that the stub has found the
23508 requested frame. The response is a series of parts, concatenated
23509 without separators, describing the frame we selected. Each part has
23510 one of the following forms:
23511
23512 @table @samp
23513 @item F @var{f}
23514 The selected frame is number @var{n} in the trace frame buffer;
23515 @var{f} is a hexidecimal number. If @var{f} is @samp{-1}, then there
23516 was no frame matching the criteria in the request packet.
23517
23518 @item T @var{t}
23519 The selected trace frame records a hit of tracepoint number @var{t};
23520 @var{t} is a hexidecimal number.
23521
23522 @end table
23523
23524 @item QTFrame:pc:@var{addr}
23525 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23526 currently selected frame whose PC is @var{addr};
23527 @var{addr} is a hexidecimal number.
23528
23529 @item QTFrame:tdp:@var{t}
23530 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23531 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
23532 is a hexidecimal number.
23533
23534 @item QTFrame:range:@var{start}:@var{end}
23535 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
23536 currently selected frame whose PC is between @var{start} (inclusive)
23537 and @var{end} (exclusive); @var{start} and @var{end} are hexidecimal
23538 numbers.
23539
23540 @item QTFrame:outside:@var{start}:@var{end}
23541 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
23542 frame @emph{outside} the given range of addresses.
23543
23544 @item QTStart
23545 Begin the tracepoint experiment. Begin collecting data from tracepoint
23546 hits in the trace frame buffer.
23547
23548 @item QTStop
23549 End the tracepoint experiment. Stop collecting trace frames.
23550
23551 @item QTinit
23552 Clear the table of tracepoints, and empty the trace frame buffer.
23553
23554 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
23555 Establish the given ranges of memory as ``transparent''. The stub
23556 will answer requests for these ranges from memory's current contents,
23557 if they were not collected as part of the tracepoint hit.
23558
23559 @value{GDBN} uses this to mark read-only regions of memory, like those
23560 containing program code. Since these areas never change, they should
23561 still have the same contents they did when the tracepoint was hit, so
23562 there's no reason for the stub to refuse to provide their contents.
23563
23564 @item qTStatus
23565 Ask the stub if there is a trace experiment running right now.
23566
23567 Replies:
23568 @table @samp
23569 @item T0
23570 There is no trace experiment running.
23571 @item T1
23572 There is a trace experiment running.
23573 @end table
23574
23575 @end table
23576
23577
23578 @node Interrupts
23579 @section Interrupts
23580 @cindex interrupts (remote protocol)
23581
23582 When a program on the remote target is running, @value{GDBN} may
23583 attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
23584 control of which is specified via @value{GDBN}'s @samp{remotebreak}
23585 setting (@pxref{set remotebreak}).
23586
23587 The precise meaning of @code{BREAK} is defined by the transport
23588 mechanism and may, in fact, be undefined. @value{GDBN} does
23589 not currently define a @code{BREAK} mechanism for any of the network
23590 interfaces.
23591
23592 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
23593 transport mechanisms. It is represented by sending the single byte
23594 @code{0x03} without any of the usual packet overhead described in
23595 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
23596 transmitted as part of a packet, it is considered to be packet data
23597 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
23598 (@pxref{X packet}, used for binary downloads, may include an unescaped
23599 @code{0x03} as part of its packet.
23600
23601 Stubs are not required to recognize these interrupt mechanisms and the
23602 precise meaning associated with receipt of the interrupt is
23603 implementation defined. If the stub is successful at interrupting the
23604 running program, it is expected that it will send one of the Stop
23605 Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
23606 of successfully stopping the program. Interrupts received while the
23607 program is stopped will be discarded.
23608
23609 @node Examples
23610 @section Examples
23611
23612 Example sequence of a target being re-started. Notice how the restart
23613 does not get any direct output:
23614
23615 @smallexample
23616 -> @code{R00}
23617 <- @code{+}
23618 @emph{target restarts}
23619 -> @code{?}
23620 <- @code{+}
23621 <- @code{T001:1234123412341234}
23622 -> @code{+}
23623 @end smallexample
23624
23625 Example sequence of a target being stepped by a single instruction:
23626
23627 @smallexample
23628 -> @code{G1445@dots{}}
23629 <- @code{+}
23630 -> @code{s}
23631 <- @code{+}
23632 @emph{time passes}
23633 <- @code{T001:1234123412341234}
23634 -> @code{+}
23635 -> @code{g}
23636 <- @code{+}
23637 <- @code{1455@dots{}}
23638 -> @code{+}
23639 @end smallexample
23640
23641 @node File-I/O remote protocol extension
23642 @section File-I/O remote protocol extension
23643 @cindex File-I/O remote protocol extension
23644
23645 @menu
23646 * File-I/O Overview::
23647 * Protocol basics::
23648 * The F request packet::
23649 * The F reply packet::
23650 * Memory transfer::
23651 * The Ctrl-C message::
23652 * Console I/O::
23653 * The isatty call::
23654 * The system call::
23655 * List of supported calls::
23656 * Protocol specific representation of datatypes::
23657 * Constants::
23658 * File-I/O Examples::
23659 @end menu
23660
23661 @node File-I/O Overview
23662 @subsection File-I/O Overview
23663 @cindex file-i/o overview
23664
23665 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23666 target to use the host's file system and console I/O when calling various
23667 system calls. System calls on the target system are translated into a
23668 remote protocol packet to the host system which then performs the needed
23669 actions and returns with an adequate response packet to the target system.
23670 This simulates file system operations even on targets that lack file systems.
23671
23672 The protocol is defined host- and target-system independent. It uses
23673 its own independent representation of datatypes and values. Both,
23674 @value{GDBN} and the target's @value{GDBN} stub are responsible for
23675 translating the system dependent values into the unified protocol values
23676 when data is transmitted.
23677
23678 The communication is synchronous. A system call is possible only
23679 when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23680 packets. While @value{GDBN} handles the request for a system call,
23681 the target is stopped to allow deterministic access to the target's
23682 memory. Therefore File-I/O is not interuptible by target signals. It
23683 is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23684
23685 The target's request to perform a host system call does not finish
23686 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23687 after finishing the system call, the target returns to continuing the
23688 previous activity (continue, step). No additional continue or step
23689 request from @value{GDBN} is required.
23690
23691 @smallexample
23692 (@value{GDBP}) continue
23693 <- target requests 'system call X'
23694 target is stopped, @value{GDBN} executes system call
23695 -> GDB returns result
23696 ... target continues, GDB returns to wait for the target
23697 <- target hits breakpoint and sends a Txx packet
23698 @end smallexample
23699
23700 The protocol is only used for files on the host file system and
23701 for I/O on the console. Character or block special devices, pipes,
23702 named pipes or sockets or any other communication method on the host
23703 system are not supported by this protocol.
23704
23705 @node Protocol basics
23706 @subsection Protocol basics
23707 @cindex protocol basics, file-i/o
23708
23709 The File-I/O protocol uses the @code{F} packet, as request as well
23710 as as reply packet. Since a File-I/O system call can only occur when
23711 @value{GDBN} is waiting for the continuing or stepping target, the
23712 File-I/O request is a reply that @value{GDBN} has to expect as a result
23713 of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23714 This @code{F} packet contains all information needed to allow @value{GDBN}
23715 to call the appropriate host system call:
23716
23717 @itemize @bullet
23718 @item
23719 A unique identifier for the requested system call.
23720
23721 @item
23722 All parameters to the system call. Pointers are given as addresses
23723 in the target memory address space. Pointers to strings are given as
23724 pointer/length pair. Numerical values are given as they are.
23725 Numerical control values are given in a protocol specific representation.
23726
23727 @end itemize
23728
23729 At that point @value{GDBN} has to perform the following actions.
23730
23731 @itemize @bullet
23732 @item
23733 If parameter pointer values are given, which point to data needed as input
23734 to a system call, @value{GDBN} requests this data from the target with a
23735 standard @code{m} packet request. This additional communication has to be
23736 expected by the target implementation and is handled as any other @code{m}
23737 packet.
23738
23739 @item
23740 @value{GDBN} translates all value from protocol representation to host
23741 representation as needed. Datatypes are coerced into the host types.
23742
23743 @item
23744 @value{GDBN} calls the system call
23745
23746 @item
23747 It then coerces datatypes back to protocol representation.
23748
23749 @item
23750 If pointer parameters in the request packet point to buffer space in which
23751 a system call is expected to copy data to, the data is transmitted to the
23752 target using a @code{M} or @code{X} packet. This packet has to be expected
23753 by the target implementation and is handled as any other @code{M} or @code{X}
23754 packet.
23755
23756 @end itemize
23757
23758 Eventually @value{GDBN} replies with another @code{F} packet which contains all
23759 necessary information for the target to continue. This at least contains
23760
23761 @itemize @bullet
23762 @item
23763 Return value.
23764
23765 @item
23766 @code{errno}, if has been changed by the system call.
23767
23768 @item
23769 ``Ctrl-C'' flag.
23770
23771 @end itemize
23772
23773 After having done the needed type and value coercion, the target continues
23774 the latest continue or step action.
23775
23776 @node The F request packet
23777 @subsection The @code{F} request packet
23778 @cindex file-i/o request packet
23779 @cindex @code{F} request packet
23780
23781 The @code{F} request packet has the following format:
23782
23783 @table @samp
23784
23785 @smallexample
23786 @code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23787 @end smallexample
23788
23789 @var{call-id} is the identifier to indicate the host system call to be called.
23790 This is just the name of the function.
23791
23792 @var{parameter@dots{}} are the parameters to the system call.
23793
23794 @end table
23795
23796 Parameters are hexadecimal integer values, either the real values in case
23797 of scalar datatypes, as pointers to target buffer space in case of compound
23798 datatypes and unspecified memory areas or as pointer/length pairs in case
23799 of string parameters. These are appended to the call-id, each separated
23800 from its predecessor by a comma. All values are transmitted in ASCII
23801 string representation, pointer/length pairs separated by a slash.
23802
23803 @node The F reply packet
23804 @subsection The @code{F} reply packet
23805 @cindex file-i/o reply packet
23806 @cindex @code{F} reply packet
23807
23808 The @code{F} reply packet has the following format:
23809
23810 @table @samp
23811
23812 @smallexample
23813 @code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23814 @end smallexample
23815
23816 @var{retcode} is the return code of the system call as hexadecimal value.
23817
23818 @var{errno} is the errno set by the call, in protocol specific representation.
23819 This parameter can be omitted if the call was successful.
23820
23821 @var{Ctrl-C flag} is only send if the user requested a break. In this
23822 case, @var{errno} must be send as well, even if the call was successful.
23823 The @var{Ctrl-C flag} itself consists of the character 'C':
23824
23825 @smallexample
23826 F0,0,C
23827 @end smallexample
23828
23829 @noindent
23830 or, if the call was interupted before the host call has been performed:
23831
23832 @smallexample
23833 F-1,4,C
23834 @end smallexample
23835
23836 @noindent
23837 assuming 4 is the protocol specific representation of @code{EINTR}.
23838
23839 @end table
23840
23841 @node Memory transfer
23842 @subsection Memory transfer
23843 @cindex memory transfer, in file-i/o protocol
23844
23845 Structured data which is transferred using a memory read or write as e.g.@:
23846 a @code{struct stat} is expected to be in a protocol specific format with
23847 all scalar multibyte datatypes being big endian. This should be done by
23848 the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23849 it transfers memory to the target. Transferred pointers to structured
23850 data should point to the already coerced data at any time.
23851
23852 @node The Ctrl-C message
23853 @subsection The Ctrl-C message
23854 @cindex ctrl-c message, in file-i/o protocol
23855
23856 A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23857 reply packet. In this case the target should behave, as if it had
23858 gotten a break message. The meaning for the target is ``system call
23859 interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23860 (as with a break message) and return to @value{GDBN} with a @code{T02}
23861 packet. In this case, it's important for the target to know, in which
23862 state the system call was interrupted. Since this action is by design
23863 not an atomic operation, we have to differ between two cases:
23864
23865 @itemize @bullet
23866 @item
23867 The system call hasn't been performed on the host yet.
23868
23869 @item
23870 The system call on the host has been finished.
23871
23872 @end itemize
23873
23874 These two states can be distinguished by the target by the value of the
23875 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23876 call hasn't been performed. This is equivalent to the @code{EINTR} handling
23877 on POSIX systems. In any other case, the target may presume that the
23878 system call has been finished --- successful or not --- and should behave
23879 as if the break message arrived right after the system call.
23880
23881 @value{GDBN} must behave reliable. If the system call has not been called
23882 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23883 @code{errno} in the packet. If the system call on the host has been finished
23884 before the user requests a break, the full action must be finshed by
23885 @value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23886 The @code{F} packet may only be send when either nothing has happened
23887 or the full action has been completed.
23888
23889 @node Console I/O
23890 @subsection Console I/O
23891 @cindex console i/o as part of file-i/o
23892
23893 By default and if not explicitely closed by the target system, the file
23894 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23895 on the @value{GDBN} console is handled as any other file output operation
23896 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23897 by @value{GDBN} so that after the target read request from file descriptor
23898 0 all following typing is buffered until either one of the following
23899 conditions is met:
23900
23901 @itemize @bullet
23902 @item
23903 The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23904 @code{read}
23905 system call is treated as finished.
23906
23907 @item
23908 The user presses @kbd{Enter}. This is treated as end of input with a trailing
23909 line feed.
23910
23911 @item
23912 The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23913 character, especially no Ctrl-D is appended to the input.
23914
23915 @end itemize
23916
23917 If the user has typed more characters as fit in the buffer given to
23918 the read call, the trailing characters are buffered in @value{GDBN} until
23919 either another @code{read(0, @dots{})} is requested by the target or debugging
23920 is stopped on users request.
23921
23922 @node The isatty call
23923 @subsection The @samp{isatty} function call
23924 @cindex isatty call, file-i/o protocol
23925
23926 A special case in this protocol is the library call @code{isatty} which
23927 is implemented as its own call inside of this protocol. It returns
23928 1 to the target if the file descriptor given as parameter is attached
23929 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23930 would require implementing @code{ioctl} and would be more complex than
23931 needed.
23932
23933 @node The system call
23934 @subsection The @samp{system} function call
23935 @cindex system call, file-i/o protocol
23936
23937 The other special case in this protocol is the @code{system} call which
23938 is implemented as its own call, too. @value{GDBN} is taking over the full
23939 task of calling the necessary host calls to perform the @code{system}
23940 call. The return value of @code{system} is simplified before it's returned
23941 to the target. Basically, the only signal transmitted back is @code{EINTR}
23942 in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23943 entirely of the exit status of the called command.
23944
23945 Due to security concerns, the @code{system} call is by default refused
23946 by @value{GDBN}. The user has to allow this call explicitly with the
23947 @kbd{set remote system-call-allowed 1} command.
23948
23949 @table @code
23950 @item set remote system-call-allowed
23951 @kindex set remote system-call-allowed
23952 Control whether to allow the @code{system} calls in the File I/O
23953 protocol for the remote target. The default is zero (disabled).
23954
23955 @item show remote system-call-allowed
23956 @kindex show remote system-call-allowed
23957 Show the current setting of system calls for the remote File I/O
23958 protocol.
23959 @end table
23960
23961 @node List of supported calls
23962 @subsection List of supported calls
23963 @cindex list of supported file-i/o calls
23964
23965 @menu
23966 * open::
23967 * close::
23968 * read::
23969 * write::
23970 * lseek::
23971 * rename::
23972 * unlink::
23973 * stat/fstat::
23974 * gettimeofday::
23975 * isatty::
23976 * system::
23977 @end menu
23978
23979 @node open
23980 @unnumberedsubsubsec open
23981 @cindex open, file-i/o system call
23982
23983 @smallexample
23984 @exdent Synopsis:
23985 int open(const char *pathname, int flags);
23986 int open(const char *pathname, int flags, mode_t mode);
23987
23988 @exdent Request:
23989 Fopen,pathptr/len,flags,mode
23990 @end smallexample
23991
23992 @noindent
23993 @code{flags} is the bitwise or of the following values:
23994
23995 @table @code
23996 @item O_CREAT
23997 If the file does not exist it will be created. The host
23998 rules apply as far as file ownership and time stamps
23999 are concerned.
24000
24001 @item O_EXCL
24002 When used with O_CREAT, if the file already exists it is
24003 an error and open() fails.
24004
24005 @item O_TRUNC
24006 If the file already exists and the open mode allows
24007 writing (O_RDWR or O_WRONLY is given) it will be
24008 truncated to length 0.
24009
24010 @item O_APPEND
24011 The file is opened in append mode.
24012
24013 @item O_RDONLY
24014 The file is opened for reading only.
24015
24016 @item O_WRONLY
24017 The file is opened for writing only.
24018
24019 @item O_RDWR
24020 The file is opened for reading and writing.
24021
24022 @noindent
24023 Each other bit is silently ignored.
24024
24025 @end table
24026
24027 @noindent
24028 @code{mode} is the bitwise or of the following values:
24029
24030 @table @code
24031 @item S_IRUSR
24032 User has read permission.
24033
24034 @item S_IWUSR
24035 User has write permission.
24036
24037 @item S_IRGRP
24038 Group has read permission.
24039
24040 @item S_IWGRP
24041 Group has write permission.
24042
24043 @item S_IROTH
24044 Others have read permission.
24045
24046 @item S_IWOTH
24047 Others have write permission.
24048
24049 @noindent
24050 Each other bit is silently ignored.
24051
24052 @end table
24053
24054 @smallexample
24055 @exdent Return value:
24056 open returns the new file descriptor or -1 if an error
24057 occured.
24058
24059 @exdent Errors:
24060 @end smallexample
24061
24062 @table @code
24063 @item EEXIST
24064 pathname already exists and O_CREAT and O_EXCL were used.
24065
24066 @item EISDIR
24067 pathname refers to a directory.
24068
24069 @item EACCES
24070 The requested access is not allowed.
24071
24072 @item ENAMETOOLONG
24073 pathname was too long.
24074
24075 @item ENOENT
24076 A directory component in pathname does not exist.
24077
24078 @item ENODEV
24079 pathname refers to a device, pipe, named pipe or socket.
24080
24081 @item EROFS
24082 pathname refers to a file on a read-only filesystem and
24083 write access was requested.
24084
24085 @item EFAULT
24086 pathname is an invalid pointer value.
24087
24088 @item ENOSPC
24089 No space on device to create the file.
24090
24091 @item EMFILE
24092 The process already has the maximum number of files open.
24093
24094 @item ENFILE
24095 The limit on the total number of files open on the system
24096 has been reached.
24097
24098 @item EINTR
24099 The call was interrupted by the user.
24100 @end table
24101
24102 @node close
24103 @unnumberedsubsubsec close
24104 @cindex close, file-i/o system call
24105
24106 @smallexample
24107 @exdent Synopsis:
24108 int close(int fd);
24109
24110 @exdent Request:
24111 Fclose,fd
24112
24113 @exdent Return value:
24114 close returns zero on success, or -1 if an error occurred.
24115
24116 @exdent Errors:
24117 @end smallexample
24118
24119 @table @code
24120 @item EBADF
24121 fd isn't a valid open file descriptor.
24122
24123 @item EINTR
24124 The call was interrupted by the user.
24125 @end table
24126
24127 @node read
24128 @unnumberedsubsubsec read
24129 @cindex read, file-i/o system call
24130
24131 @smallexample
24132 @exdent Synopsis:
24133 int read(int fd, void *buf, unsigned int count);
24134
24135 @exdent Request:
24136 Fread,fd,bufptr,count
24137
24138 @exdent Return value:
24139 On success, the number of bytes read is returned.
24140 Zero indicates end of file. If count is zero, read
24141 returns zero as well. On error, -1 is returned.
24142
24143 @exdent Errors:
24144 @end smallexample
24145
24146 @table @code
24147 @item EBADF
24148 fd is not a valid file descriptor or is not open for
24149 reading.
24150
24151 @item EFAULT
24152 buf is an invalid pointer value.
24153
24154 @item EINTR
24155 The call was interrupted by the user.
24156 @end table
24157
24158 @node write
24159 @unnumberedsubsubsec write
24160 @cindex write, file-i/o system call
24161
24162 @smallexample
24163 @exdent Synopsis:
24164 int write(int fd, const void *buf, unsigned int count);
24165
24166 @exdent Request:
24167 Fwrite,fd,bufptr,count
24168
24169 @exdent Return value:
24170 On success, the number of bytes written are returned.
24171 Zero indicates nothing was written. On error, -1
24172 is returned.
24173
24174 @exdent Errors:
24175 @end smallexample
24176
24177 @table @code
24178 @item EBADF
24179 fd is not a valid file descriptor or is not open for
24180 writing.
24181
24182 @item EFAULT
24183 buf is an invalid pointer value.
24184
24185 @item EFBIG
24186 An attempt was made to write a file that exceeds the
24187 host specific maximum file size allowed.
24188
24189 @item ENOSPC
24190 No space on device to write the data.
24191
24192 @item EINTR
24193 The call was interrupted by the user.
24194 @end table
24195
24196 @node lseek
24197 @unnumberedsubsubsec lseek
24198 @cindex lseek, file-i/o system call
24199
24200 @smallexample
24201 @exdent Synopsis:
24202 long lseek (int fd, long offset, int flag);
24203
24204 @exdent Request:
24205 Flseek,fd,offset,flag
24206 @end smallexample
24207
24208 @code{flag} is one of:
24209
24210 @table @code
24211 @item SEEK_SET
24212 The offset is set to offset bytes.
24213
24214 @item SEEK_CUR
24215 The offset is set to its current location plus offset
24216 bytes.
24217
24218 @item SEEK_END
24219 The offset is set to the size of the file plus offset
24220 bytes.
24221 @end table
24222
24223 @smallexample
24224 @exdent Return value:
24225 On success, the resulting unsigned offset in bytes from
24226 the beginning of the file is returned. Otherwise, a
24227 value of -1 is returned.
24228
24229 @exdent Errors:
24230 @end smallexample
24231
24232 @table @code
24233 @item EBADF
24234 fd is not a valid open file descriptor.
24235
24236 @item ESPIPE
24237 fd is associated with the @value{GDBN} console.
24238
24239 @item EINVAL
24240 flag is not a proper value.
24241
24242 @item EINTR
24243 The call was interrupted by the user.
24244 @end table
24245
24246 @node rename
24247 @unnumberedsubsubsec rename
24248 @cindex rename, file-i/o system call
24249
24250 @smallexample
24251 @exdent Synopsis:
24252 int rename(const char *oldpath, const char *newpath);
24253
24254 @exdent Request:
24255 Frename,oldpathptr/len,newpathptr/len
24256
24257 @exdent Return value:
24258 On success, zero is returned. On error, -1 is returned.
24259
24260 @exdent Errors:
24261 @end smallexample
24262
24263 @table @code
24264 @item EISDIR
24265 newpath is an existing directory, but oldpath is not a
24266 directory.
24267
24268 @item EEXIST
24269 newpath is a non-empty directory.
24270
24271 @item EBUSY
24272 oldpath or newpath is a directory that is in use by some
24273 process.
24274
24275 @item EINVAL
24276 An attempt was made to make a directory a subdirectory
24277 of itself.
24278
24279 @item ENOTDIR
24280 A component used as a directory in oldpath or new
24281 path is not a directory. Or oldpath is a directory
24282 and newpath exists but is not a directory.
24283
24284 @item EFAULT
24285 oldpathptr or newpathptr are invalid pointer values.
24286
24287 @item EACCES
24288 No access to the file or the path of the file.
24289
24290 @item ENAMETOOLONG
24291
24292 oldpath or newpath was too long.
24293
24294 @item ENOENT
24295 A directory component in oldpath or newpath does not exist.
24296
24297 @item EROFS
24298 The file is on a read-only filesystem.
24299
24300 @item ENOSPC
24301 The device containing the file has no room for the new
24302 directory entry.
24303
24304 @item EINTR
24305 The call was interrupted by the user.
24306 @end table
24307
24308 @node unlink
24309 @unnumberedsubsubsec unlink
24310 @cindex unlink, file-i/o system call
24311
24312 @smallexample
24313 @exdent Synopsis:
24314 int unlink(const char *pathname);
24315
24316 @exdent Request:
24317 Funlink,pathnameptr/len
24318
24319 @exdent Return value:
24320 On success, zero is returned. On error, -1 is returned.
24321
24322 @exdent Errors:
24323 @end smallexample
24324
24325 @table @code
24326 @item EACCES
24327 No access to the file or the path of the file.
24328
24329 @item EPERM
24330 The system does not allow unlinking of directories.
24331
24332 @item EBUSY
24333 The file pathname cannot be unlinked because it's
24334 being used by another process.
24335
24336 @item EFAULT
24337 pathnameptr is an invalid pointer value.
24338
24339 @item ENAMETOOLONG
24340 pathname was too long.
24341
24342 @item ENOENT
24343 A directory component in pathname does not exist.
24344
24345 @item ENOTDIR
24346 A component of the path is not a directory.
24347
24348 @item EROFS
24349 The file is on a read-only filesystem.
24350
24351 @item EINTR
24352 The call was interrupted by the user.
24353 @end table
24354
24355 @node stat/fstat
24356 @unnumberedsubsubsec stat/fstat
24357 @cindex fstat, file-i/o system call
24358 @cindex stat, file-i/o system call
24359
24360 @smallexample
24361 @exdent Synopsis:
24362 int stat(const char *pathname, struct stat *buf);
24363 int fstat(int fd, struct stat *buf);
24364
24365 @exdent Request:
24366 Fstat,pathnameptr/len,bufptr
24367 Ffstat,fd,bufptr
24368
24369 @exdent Return value:
24370 On success, zero is returned. On error, -1 is returned.
24371
24372 @exdent Errors:
24373 @end smallexample
24374
24375 @table @code
24376 @item EBADF
24377 fd is not a valid open file.
24378
24379 @item ENOENT
24380 A directory component in pathname does not exist or the
24381 path is an empty string.
24382
24383 @item ENOTDIR
24384 A component of the path is not a directory.
24385
24386 @item EFAULT
24387 pathnameptr is an invalid pointer value.
24388
24389 @item EACCES
24390 No access to the file or the path of the file.
24391
24392 @item ENAMETOOLONG
24393 pathname was too long.
24394
24395 @item EINTR
24396 The call was interrupted by the user.
24397 @end table
24398
24399 @node gettimeofday
24400 @unnumberedsubsubsec gettimeofday
24401 @cindex gettimeofday, file-i/o system call
24402
24403 @smallexample
24404 @exdent Synopsis:
24405 int gettimeofday(struct timeval *tv, void *tz);
24406
24407 @exdent Request:
24408 Fgettimeofday,tvptr,tzptr
24409
24410 @exdent Return value:
24411 On success, 0 is returned, -1 otherwise.
24412
24413 @exdent Errors:
24414 @end smallexample
24415
24416 @table @code
24417 @item EINVAL
24418 tz is a non-NULL pointer.
24419
24420 @item EFAULT
24421 tvptr and/or tzptr is an invalid pointer value.
24422 @end table
24423
24424 @node isatty
24425 @unnumberedsubsubsec isatty
24426 @cindex isatty, file-i/o system call
24427
24428 @smallexample
24429 @exdent Synopsis:
24430 int isatty(int fd);
24431
24432 @exdent Request:
24433 Fisatty,fd
24434
24435 @exdent Return value:
24436 Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
24437
24438 @exdent Errors:
24439 @end smallexample
24440
24441 @table @code
24442 @item EINTR
24443 The call was interrupted by the user.
24444 @end table
24445
24446 @node system
24447 @unnumberedsubsubsec system
24448 @cindex system, file-i/o system call
24449
24450 @smallexample
24451 @exdent Synopsis:
24452 int system(const char *command);
24453
24454 @exdent Request:
24455 Fsystem,commandptr/len
24456
24457 @exdent Return value:
24458 The value returned is -1 on error and the return status
24459 of the command otherwise. Only the exit status of the
24460 command is returned, which is extracted from the hosts
24461 system return value by calling WEXITSTATUS(retval).
24462 In case /bin/sh could not be executed, 127 is returned.
24463
24464 @exdent Errors:
24465 @end smallexample
24466
24467 @table @code
24468 @item EINTR
24469 The call was interrupted by the user.
24470 @end table
24471
24472 @node Protocol specific representation of datatypes
24473 @subsection Protocol specific representation of datatypes
24474 @cindex protocol specific representation of datatypes, in file-i/o protocol
24475
24476 @menu
24477 * Integral datatypes::
24478 * Pointer values::
24479 * struct stat::
24480 * struct timeval::
24481 @end menu
24482
24483 @node Integral datatypes
24484 @unnumberedsubsubsec Integral datatypes
24485 @cindex integral datatypes, in file-i/o protocol
24486
24487 The integral datatypes used in the system calls are
24488
24489 @smallexample
24490 int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
24491 @end smallexample
24492
24493 @code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
24494 implemented as 32 bit values in this protocol.
24495
24496 @code{Long} and @code{unsigned long} are implemented as 64 bit types.
24497
24498 @xref{Limits}, for corresponding MIN and MAX values (similar to those
24499 in @file{limits.h}) to allow range checking on host and target.
24500
24501 @code{time_t} datatypes are defined as seconds since the Epoch.
24502
24503 All integral datatypes transferred as part of a memory read or write of a
24504 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
24505 byte order.
24506
24507 @node Pointer values
24508 @unnumberedsubsubsec Pointer values
24509 @cindex pointer values, in file-i/o protocol
24510
24511 Pointers to target data are transmitted as they are. An exception
24512 is made for pointers to buffers for which the length isn't
24513 transmitted as part of the function call, namely strings. Strings
24514 are transmitted as a pointer/length pair, both as hex values, e.g.@:
24515
24516 @smallexample
24517 @code{1aaf/12}
24518 @end smallexample
24519
24520 @noindent
24521 which is a pointer to data of length 18 bytes at position 0x1aaf.
24522 The length is defined as the full string length in bytes, including
24523 the trailing null byte. Example:
24524
24525 @smallexample
24526 ``hello, world'' at address 0x123456
24527 @end smallexample
24528
24529 @noindent
24530 is transmitted as
24531
24532 @smallexample
24533 @code{123456/d}
24534 @end smallexample
24535
24536 @node struct stat
24537 @unnumberedsubsubsec struct stat
24538 @cindex struct stat, in file-i/o protocol
24539
24540 The buffer of type struct stat used by the target and @value{GDBN} is defined
24541 as follows:
24542
24543 @smallexample
24544 struct stat @{
24545 unsigned int st_dev; /* device */
24546 unsigned int st_ino; /* inode */
24547 mode_t st_mode; /* protection */
24548 unsigned int st_nlink; /* number of hard links */
24549 unsigned int st_uid; /* user ID of owner */
24550 unsigned int st_gid; /* group ID of owner */
24551 unsigned int st_rdev; /* device type (if inode device) */
24552 unsigned long st_size; /* total size, in bytes */
24553 unsigned long st_blksize; /* blocksize for filesystem I/O */
24554 unsigned long st_blocks; /* number of blocks allocated */
24555 time_t st_atime; /* time of last access */
24556 time_t st_mtime; /* time of last modification */
24557 time_t st_ctime; /* time of last change */
24558 @};
24559 @end smallexample
24560
24561 The integral datatypes are conforming to the definitions given in the
24562 approriate section (see @ref{Integral datatypes}, for details) so this
24563 structure is of size 64 bytes.
24564
24565 The values of several fields have a restricted meaning and/or
24566 range of values.
24567
24568 @smallexample
24569 st_dev: 0 file
24570 1 console
24571
24572 st_ino: No valid meaning for the target. Transmitted unchanged.
24573
24574 st_mode: Valid mode bits are described in Appendix C. Any other
24575 bits have currently no meaning for the target.
24576
24577 st_uid: No valid meaning for the target. Transmitted unchanged.
24578
24579 st_gid: No valid meaning for the target. Transmitted unchanged.
24580
24581 st_rdev: No valid meaning for the target. Transmitted unchanged.
24582
24583 st_atime, st_mtime, st_ctime:
24584 These values have a host and file system dependent
24585 accuracy. Especially on Windows hosts the file systems
24586 don't support exact timing values.
24587 @end smallexample
24588
24589 The target gets a struct stat of the above representation and is
24590 responsible to coerce it to the target representation before
24591 continuing.
24592
24593 Note that due to size differences between the host and target
24594 representation of stat members, these members could eventually
24595 get truncated on the target.
24596
24597 @node struct timeval
24598 @unnumberedsubsubsec struct timeval
24599 @cindex struct timeval, in file-i/o protocol
24600
24601 The buffer of type struct timeval used by the target and @value{GDBN}
24602 is defined as follows:
24603
24604 @smallexample
24605 struct timeval @{
24606 time_t tv_sec; /* second */
24607 long tv_usec; /* microsecond */
24608 @};
24609 @end smallexample
24610
24611 The integral datatypes are conforming to the definitions given in the
24612 approriate section (see @ref{Integral datatypes}, for details) so this
24613 structure is of size 8 bytes.
24614
24615 @node Constants
24616 @subsection Constants
24617 @cindex constants, in file-i/o protocol
24618
24619 The following values are used for the constants inside of the
24620 protocol. @value{GDBN} and target are resposible to translate these
24621 values before and after the call as needed.
24622
24623 @menu
24624 * Open flags::
24625 * mode_t values::
24626 * Errno values::
24627 * Lseek flags::
24628 * Limits::
24629 @end menu
24630
24631 @node Open flags
24632 @unnumberedsubsubsec Open flags
24633 @cindex open flags, in file-i/o protocol
24634
24635 All values are given in hexadecimal representation.
24636
24637 @smallexample
24638 O_RDONLY 0x0
24639 O_WRONLY 0x1
24640 O_RDWR 0x2
24641 O_APPEND 0x8
24642 O_CREAT 0x200
24643 O_TRUNC 0x400
24644 O_EXCL 0x800
24645 @end smallexample
24646
24647 @node mode_t values
24648 @unnumberedsubsubsec mode_t values
24649 @cindex mode_t values, in file-i/o protocol
24650
24651 All values are given in octal representation.
24652
24653 @smallexample
24654 S_IFREG 0100000
24655 S_IFDIR 040000
24656 S_IRUSR 0400
24657 S_IWUSR 0200
24658 S_IXUSR 0100
24659 S_IRGRP 040
24660 S_IWGRP 020
24661 S_IXGRP 010
24662 S_IROTH 04
24663 S_IWOTH 02
24664 S_IXOTH 01
24665 @end smallexample
24666
24667 @node Errno values
24668 @unnumberedsubsubsec Errno values
24669 @cindex errno values, in file-i/o protocol
24670
24671 All values are given in decimal representation.
24672
24673 @smallexample
24674 EPERM 1
24675 ENOENT 2
24676 EINTR 4
24677 EBADF 9
24678 EACCES 13
24679 EFAULT 14
24680 EBUSY 16
24681 EEXIST 17
24682 ENODEV 19
24683 ENOTDIR 20
24684 EISDIR 21
24685 EINVAL 22
24686 ENFILE 23
24687 EMFILE 24
24688 EFBIG 27
24689 ENOSPC 28
24690 ESPIPE 29
24691 EROFS 30
24692 ENAMETOOLONG 91
24693 EUNKNOWN 9999
24694 @end smallexample
24695
24696 EUNKNOWN is used as a fallback error value if a host system returns
24697 any error value not in the list of supported error numbers.
24698
24699 @node Lseek flags
24700 @unnumberedsubsubsec Lseek flags
24701 @cindex lseek flags, in file-i/o protocol
24702
24703 @smallexample
24704 SEEK_SET 0
24705 SEEK_CUR 1
24706 SEEK_END 2
24707 @end smallexample
24708
24709 @node Limits
24710 @unnumberedsubsubsec Limits
24711 @cindex limits, in file-i/o protocol
24712
24713 All values are given in decimal representation.
24714
24715 @smallexample
24716 INT_MIN -2147483648
24717 INT_MAX 2147483647
24718 UINT_MAX 4294967295
24719 LONG_MIN -9223372036854775808
24720 LONG_MAX 9223372036854775807
24721 ULONG_MAX 18446744073709551615
24722 @end smallexample
24723
24724 @node File-I/O Examples
24725 @subsection File-I/O Examples
24726 @cindex file-i/o examples
24727
24728 Example sequence of a write call, file descriptor 3, buffer is at target
24729 address 0x1234, 6 bytes should be written:
24730
24731 @smallexample
24732 <- @code{Fwrite,3,1234,6}
24733 @emph{request memory read from target}
24734 -> @code{m1234,6}
24735 <- XXXXXX
24736 @emph{return "6 bytes written"}
24737 -> @code{F6}
24738 @end smallexample
24739
24740 Example sequence of a read call, file descriptor 3, buffer is at target
24741 address 0x1234, 6 bytes should be read:
24742
24743 @smallexample
24744 <- @code{Fread,3,1234,6}
24745 @emph{request memory write to target}
24746 -> @code{X1234,6:XXXXXX}
24747 @emph{return "6 bytes read"}
24748 -> @code{F6}
24749 @end smallexample
24750
24751 Example sequence of a read call, call fails on the host due to invalid
24752 file descriptor (EBADF):
24753
24754 @smallexample
24755 <- @code{Fread,3,1234,6}
24756 -> @code{F-1,9}
24757 @end smallexample
24758
24759 Example sequence of a read call, user presses Ctrl-C before syscall on
24760 host is called:
24761
24762 @smallexample
24763 <- @code{Fread,3,1234,6}
24764 -> @code{F-1,4,C}
24765 <- @code{T02}
24766 @end smallexample
24767
24768 Example sequence of a read call, user presses Ctrl-C after syscall on
24769 host is called:
24770
24771 @smallexample
24772 <- @code{Fread,3,1234,6}
24773 -> @code{X1234,6:XXXXXX}
24774 <- @code{T02}
24775 @end smallexample
24776
24777 @include agentexpr.texi
24778
24779 @include gpl.texi
24780
24781 @raisesections
24782 @include fdl.texi
24783 @lowersections
24784
24785 @node Index
24786 @unnumbered Index
24787
24788 @printindex cp
24789
24790 @tex
24791 % I think something like @colophon should be in texinfo. In the
24792 % meantime:
24793 \long\def\colophon{\hbox to0pt{}\vfill
24794 \centerline{The body of this manual is set in}
24795 \centerline{\fontname\tenrm,}
24796 \centerline{with headings in {\bf\fontname\tenbf}}
24797 \centerline{and examples in {\tt\fontname\tentt}.}
24798 \centerline{{\it\fontname\tenit\/},}
24799 \centerline{{\bf\fontname\tenbf}, and}
24800 \centerline{{\sl\fontname\tensl\/}}
24801 \centerline{are used for emphasis.}\vfill}
24802 \page\colophon
24803 % Blame: doc@cygnus.com, 1991.
24804 @end tex
24805
24806 @bye
This page took 0.505723 seconds and 5 git commands to generate.