(M32R/D): Document "sdireset", "sdistatus", "debug_chaos",
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright 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 59 Temple Place - Suite 330, @*
93 Boston, MA 02111-1307 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.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 Jim Blandy added support for preprocessor macros, while working for Red
475 Hat.
476
477 @node Sample Session
478 @chapter A Sample @value{GDBN} Session
479
480 You can use this manual at your leisure to read all about @value{GDBN}.
481 However, a handful of commands are enough to get started using the
482 debugger. This chapter illustrates those commands.
483
484 @iftex
485 In this sample session, we emphasize user input like this: @b{input},
486 to make it easier to pick out from the surrounding output.
487 @end iftex
488
489 @c FIXME: this example may not be appropriate for some configs, where
490 @c FIXME...primary interest is in remote use.
491
492 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
493 processor) exhibits the following bug: sometimes, when we change its
494 quote strings from the default, the commands used to capture one macro
495 definition within another stop working. In the following short @code{m4}
496 session, we define a macro @code{foo} which expands to @code{0000}; we
497 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
498 same thing. However, when we change the open quote string to
499 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
500 procedure fails to define a new synonym @code{baz}:
501
502 @smallexample
503 $ @b{cd gnu/m4}
504 $ @b{./m4}
505 @b{define(foo,0000)}
506
507 @b{foo}
508 0000
509 @b{define(bar,defn(`foo'))}
510
511 @b{bar}
512 0000
513 @b{changequote(<QUOTE>,<UNQUOTE>)}
514
515 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
516 @b{baz}
517 @b{C-d}
518 m4: End of input: 0: fatal error: EOF in string
519 @end smallexample
520
521 @noindent
522 Let us use @value{GDBN} to try to see what is going on.
523
524 @smallexample
525 $ @b{@value{GDBP} m4}
526 @c FIXME: this falsifies the exact text played out, to permit smallbook
527 @c FIXME... format to come out better.
528 @value{GDBN} is free software and you are welcome to distribute copies
529 of it under certain conditions; type "show copying" to see
530 the conditions.
531 There is absolutely no warranty for @value{GDBN}; type "show warranty"
532 for details.
533
534 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
535 (@value{GDBP})
536 @end smallexample
537
538 @noindent
539 @value{GDBN} reads only enough symbol data to know where to find the
540 rest when needed; as a result, the first prompt comes up very quickly.
541 We now tell @value{GDBN} to use a narrower display width than usual, so
542 that examples fit in this manual.
543
544 @smallexample
545 (@value{GDBP}) @b{set width 70}
546 @end smallexample
547
548 @noindent
549 We need to see how the @code{m4} built-in @code{changequote} works.
550 Having looked at the source, we know the relevant subroutine is
551 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
552 @code{break} command.
553
554 @smallexample
555 (@value{GDBP}) @b{break m4_changequote}
556 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
557 @end smallexample
558
559 @noindent
560 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
561 control; as long as control does not reach the @code{m4_changequote}
562 subroutine, the program runs as usual:
563
564 @smallexample
565 (@value{GDBP}) @b{run}
566 Starting program: /work/Editorial/gdb/gnu/m4/m4
567 @b{define(foo,0000)}
568
569 @b{foo}
570 0000
571 @end smallexample
572
573 @noindent
574 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
575 suspends execution of @code{m4}, displaying information about the
576 context where it stops.
577
578 @smallexample
579 @b{changequote(<QUOTE>,<UNQUOTE>)}
580
581 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
582 at builtin.c:879
583 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
584 @end smallexample
585
586 @noindent
587 Now we use the command @code{n} (@code{next}) to advance execution to
588 the next line of the current function.
589
590 @smallexample
591 (@value{GDBP}) @b{n}
592 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
593 : nil,
594 @end smallexample
595
596 @noindent
597 @code{set_quotes} looks like a promising subroutine. We can go into it
598 by using the command @code{s} (@code{step}) instead of @code{next}.
599 @code{step} goes to the next line to be executed in @emph{any}
600 subroutine, so it steps into @code{set_quotes}.
601
602 @smallexample
603 (@value{GDBP}) @b{s}
604 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
605 at input.c:530
606 530 if (lquote != def_lquote)
607 @end smallexample
608
609 @noindent
610 The display that shows the subroutine where @code{m4} is now
611 suspended (and its arguments) is called a stack frame display. It
612 shows a summary of the stack. We can use the @code{backtrace}
613 command (which can also be spelled @code{bt}), to see where we are
614 in the stack as a whole: the @code{backtrace} command displays a
615 stack frame for each active subroutine.
616
617 @smallexample
618 (@value{GDBP}) @b{bt}
619 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
620 at input.c:530
621 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
622 at builtin.c:882
623 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
624 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
625 at macro.c:71
626 #4 0x79dc in expand_input () at macro.c:40
627 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
628 @end smallexample
629
630 @noindent
631 We step through a few more lines to see what happens. The first two
632 times, we can use @samp{s}; the next two times we use @code{n} to avoid
633 falling into the @code{xstrdup} subroutine.
634
635 @smallexample
636 (@value{GDBP}) @b{s}
637 0x3b5c 532 if (rquote != def_rquote)
638 (@value{GDBP}) @b{s}
639 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
640 def_lquote : xstrdup(lq);
641 (@value{GDBP}) @b{n}
642 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
643 : xstrdup(rq);
644 (@value{GDBP}) @b{n}
645 538 len_lquote = strlen(rquote);
646 @end smallexample
647
648 @noindent
649 The last line displayed looks a little odd; we can examine the variables
650 @code{lquote} and @code{rquote} to see if they are in fact the new left
651 and right quotes we specified. We use the command @code{p}
652 (@code{print}) to see their values.
653
654 @smallexample
655 (@value{GDBP}) @b{p lquote}
656 $1 = 0x35d40 "<QUOTE>"
657 (@value{GDBP}) @b{p rquote}
658 $2 = 0x35d50 "<UNQUOTE>"
659 @end smallexample
660
661 @noindent
662 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
663 To look at some context, we can display ten lines of source
664 surrounding the current line with the @code{l} (@code{list}) command.
665
666 @smallexample
667 (@value{GDBP}) @b{l}
668 533 xfree(rquote);
669 534
670 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
671 : xstrdup (lq);
672 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
673 : xstrdup (rq);
674 537
675 538 len_lquote = strlen(rquote);
676 539 len_rquote = strlen(lquote);
677 540 @}
678 541
679 542 void
680 @end smallexample
681
682 @noindent
683 Let us step past the two lines that set @code{len_lquote} and
684 @code{len_rquote}, and then examine the values of those variables.
685
686 @smallexample
687 (@value{GDBP}) @b{n}
688 539 len_rquote = strlen(lquote);
689 (@value{GDBP}) @b{n}
690 540 @}
691 (@value{GDBP}) @b{p len_lquote}
692 $3 = 9
693 (@value{GDBP}) @b{p len_rquote}
694 $4 = 7
695 @end smallexample
696
697 @noindent
698 That certainly looks wrong, assuming @code{len_lquote} and
699 @code{len_rquote} are meant to be the lengths of @code{lquote} and
700 @code{rquote} respectively. We can set them to better values using
701 the @code{p} command, since it can print the value of
702 any expression---and that expression can include subroutine calls and
703 assignments.
704
705 @smallexample
706 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
707 $5 = 7
708 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
709 $6 = 9
710 @end smallexample
711
712 @noindent
713 Is that enough to fix the problem of using the new quotes with the
714 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
715 executing with the @code{c} (@code{continue}) command, and then try the
716 example that caused trouble initially:
717
718 @smallexample
719 (@value{GDBP}) @b{c}
720 Continuing.
721
722 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
723
724 baz
725 0000
726 @end smallexample
727
728 @noindent
729 Success! The new quotes now work just as well as the default ones. The
730 problem seems to have been just the two typos defining the wrong
731 lengths. We allow @code{m4} exit by giving it an EOF as input:
732
733 @smallexample
734 @b{C-d}
735 Program exited normally.
736 @end smallexample
737
738 @noindent
739 The message @samp{Program exited normally.} is from @value{GDBN}; it
740 indicates @code{m4} has finished executing. We can end our @value{GDBN}
741 session with the @value{GDBN} @code{quit} command.
742
743 @smallexample
744 (@value{GDBP}) @b{quit}
745 @end smallexample
746
747 @node Invocation
748 @chapter Getting In and Out of @value{GDBN}
749
750 This chapter discusses how to start @value{GDBN}, and how to get out of it.
751 The essentials are:
752 @itemize @bullet
753 @item
754 type @samp{@value{GDBP}} to start @value{GDBN}.
755 @item
756 type @kbd{quit} or @kbd{C-d} to exit.
757 @end itemize
758
759 @menu
760 * Invoking GDB:: How to start @value{GDBN}
761 * Quitting GDB:: How to quit @value{GDBN}
762 * Shell Commands:: How to use shell commands inside @value{GDBN}
763 * Logging output:: How to log @value{GDBN}'s output to a file
764 @end menu
765
766 @node Invoking GDB
767 @section Invoking @value{GDBN}
768
769 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
770 @value{GDBN} reads commands from the terminal until you tell it to exit.
771
772 You can also run @code{@value{GDBP}} with a variety of arguments and options,
773 to specify more of your debugging environment at the outset.
774
775 The command-line options described here are designed
776 to cover a variety of situations; in some environments, some of these
777 options may effectively be unavailable.
778
779 The most usual way to start @value{GDBN} is with one argument,
780 specifying an executable program:
781
782 @smallexample
783 @value{GDBP} @var{program}
784 @end smallexample
785
786 @noindent
787 You can also start with both an executable program and a core file
788 specified:
789
790 @smallexample
791 @value{GDBP} @var{program} @var{core}
792 @end smallexample
793
794 You can, instead, specify a process ID as a second argument, if you want
795 to debug a running process:
796
797 @smallexample
798 @value{GDBP} @var{program} 1234
799 @end smallexample
800
801 @noindent
802 would attach @value{GDBN} to process @code{1234} (unless you also have a file
803 named @file{1234}; @value{GDBN} does check for a core file first).
804
805 Taking advantage of the second command-line argument requires a fairly
806 complete operating system; when you use @value{GDBN} as a remote
807 debugger attached to a bare board, there may not be any notion of
808 ``process'', and there is often no way to get a core dump. @value{GDBN}
809 will warn you if it is unable to attach or to read core dumps.
810
811 You can optionally have @code{@value{GDBP}} pass any arguments after the
812 executable file to the inferior using @code{--args}. This option stops
813 option processing.
814 @smallexample
815 gdb --args gcc -O2 -c foo.c
816 @end smallexample
817 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
818 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
819
820 You can run @code{@value{GDBP}} without printing the front material, which describes
821 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
822
823 @smallexample
824 @value{GDBP} -silent
825 @end smallexample
826
827 @noindent
828 You can further control how @value{GDBN} starts up by using command-line
829 options. @value{GDBN} itself can remind you of the options available.
830
831 @noindent
832 Type
833
834 @smallexample
835 @value{GDBP} -help
836 @end smallexample
837
838 @noindent
839 to display all available options and briefly describe their use
840 (@samp{@value{GDBP} -h} is a shorter equivalent).
841
842 All options and command line arguments you give are processed
843 in sequential order. The order makes a difference when the
844 @samp{-x} option is used.
845
846
847 @menu
848 * File Options:: Choosing files
849 * Mode Options:: Choosing modes
850 @end menu
851
852 @node File Options
853 @subsection Choosing files
854
855 When @value{GDBN} starts, it reads any arguments other than options as
856 specifying an executable file and core file (or process ID). This is
857 the same as if the arguments were specified by the @samp{-se} and
858 @samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
859 first argument that does not have an associated option flag as
860 equivalent to the @samp{-se} option followed by that argument; and the
861 second argument that does not have an associated option flag, if any, as
862 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
863 If the second argument begins with a decimal digit, @value{GDBN} will
864 first attempt to attach to it as a process, and if that fails, attempt
865 to open it as a corefile. If you have a corefile whose name begins with
866 a digit, you can prevent @value{GDBN} from treating it as a pid by
867 prefixing it with @file{./}, eg. @file{./12345}.
868
869 If @value{GDBN} has not been configured to included core file support,
870 such as for most embedded targets, then it will complain about a second
871 argument and ignore it.
872
873 Many options have both long and short forms; both are shown in the
874 following list. @value{GDBN} also recognizes the long forms if you truncate
875 them, so long as enough of the option is present to be unambiguous.
876 (If you prefer, you can flag option arguments with @samp{--} rather
877 than @samp{-}, though we illustrate the more usual convention.)
878
879 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
880 @c way, both those who look for -foo and --foo in the index, will find
881 @c it.
882
883 @table @code
884 @item -symbols @var{file}
885 @itemx -s @var{file}
886 @cindex @code{--symbols}
887 @cindex @code{-s}
888 Read symbol table from file @var{file}.
889
890 @item -exec @var{file}
891 @itemx -e @var{file}
892 @cindex @code{--exec}
893 @cindex @code{-e}
894 Use file @var{file} as the executable file to execute when appropriate,
895 and for examining pure data in conjunction with a core dump.
896
897 @item -se @var{file}
898 @cindex @code{--se}
899 Read symbol table from file @var{file} and use it as the executable
900 file.
901
902 @item -core @var{file}
903 @itemx -c @var{file}
904 @cindex @code{--core}
905 @cindex @code{-c}
906 Use file @var{file} as a core dump to examine.
907
908 @item -c @var{number}
909 @item -pid @var{number}
910 @itemx -p @var{number}
911 @cindex @code{--pid}
912 @cindex @code{-p}
913 Connect to process ID @var{number}, as with the @code{attach} command.
914 If there is no such process, @value{GDBN} will attempt to open a core
915 file named @var{number}.
916
917 @item -command @var{file}
918 @itemx -x @var{file}
919 @cindex @code{--command}
920 @cindex @code{-x}
921 Execute @value{GDBN} commands from file @var{file}. @xref{Command
922 Files,, Command files}.
923
924 @item -directory @var{directory}
925 @itemx -d @var{directory}
926 @cindex @code{--directory}
927 @cindex @code{-d}
928 Add @var{directory} to the path to search for source files.
929
930 @item -m
931 @itemx -mapped
932 @cindex @code{--mapped}
933 @cindex @code{-m}
934 @emph{Warning: this option depends on operating system facilities that are not
935 supported on all systems.}@*
936 If memory-mapped files are available on your system through the @code{mmap}
937 system call, you can use this option
938 to have @value{GDBN} write the symbols from your
939 program into a reusable file in the current directory. If the program you are debugging is
940 called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
941 Future @value{GDBN} debugging sessions notice the presence of this file,
942 and can quickly map in symbol information from it, rather than reading
943 the symbol table from the executable program.
944
945 The @file{.syms} file is specific to the host machine where @value{GDBN}
946 is run. It holds an exact image of the internal @value{GDBN} symbol
947 table. It cannot be shared across multiple host platforms.
948
949 @item -r
950 @itemx -readnow
951 @cindex @code{--readnow}
952 @cindex @code{-r}
953 Read each symbol file's entire symbol table immediately, rather than
954 the default, which is to read it incrementally as it is needed.
955 This makes startup slower, but makes future operations faster.
956
957 @end table
958
959 You typically combine the @code{-mapped} and @code{-readnow} options in
960 order to build a @file{.syms} file that contains complete symbol
961 information. (@xref{Files,,Commands to specify files}, for information
962 on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
963 but build a @file{.syms} file for future use is:
964
965 @smallexample
966 gdb -batch -nx -mapped -readnow programname
967 @end smallexample
968
969 @node Mode Options
970 @subsection Choosing modes
971
972 You can run @value{GDBN} in various alternative modes---for example, in
973 batch mode or quiet mode.
974
975 @table @code
976 @item -nx
977 @itemx -n
978 @cindex @code{--nx}
979 @cindex @code{-n}
980 Do not execute commands found in any initialization files. Normally,
981 @value{GDBN} executes the commands in these files after all the command
982 options and arguments have been processed. @xref{Command Files,,Command
983 files}.
984
985 @item -quiet
986 @itemx -silent
987 @itemx -q
988 @cindex @code{--quiet}
989 @cindex @code{--silent}
990 @cindex @code{-q}
991 ``Quiet''. Do not print the introductory and copyright messages. These
992 messages are also suppressed in batch mode.
993
994 @item -batch
995 @cindex @code{--batch}
996 Run in batch mode. Exit with status @code{0} after processing all the
997 command files specified with @samp{-x} (and all commands from
998 initialization files, if not inhibited with @samp{-n}). Exit with
999 nonzero status if an error occurs in executing the @value{GDBN} commands
1000 in the command files.
1001
1002 Batch mode may be useful for running @value{GDBN} as a filter, for
1003 example to download and run a program on another computer; in order to
1004 make this more useful, the message
1005
1006 @smallexample
1007 Program exited normally.
1008 @end smallexample
1009
1010 @noindent
1011 (which is ordinarily issued whenever a program running under
1012 @value{GDBN} control terminates) is not issued when running in batch
1013 mode.
1014
1015 @item -nowindows
1016 @itemx -nw
1017 @cindex @code{--nowindows}
1018 @cindex @code{-nw}
1019 ``No windows''. If @value{GDBN} comes with a graphical user interface
1020 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1021 interface. If no GUI is available, this option has no effect.
1022
1023 @item -windows
1024 @itemx -w
1025 @cindex @code{--windows}
1026 @cindex @code{-w}
1027 If @value{GDBN} includes a GUI, then this option requires it to be
1028 used if possible.
1029
1030 @item -cd @var{directory}
1031 @cindex @code{--cd}
1032 Run @value{GDBN} using @var{directory} as its working directory,
1033 instead of the current directory.
1034
1035 @item -fullname
1036 @itemx -f
1037 @cindex @code{--fullname}
1038 @cindex @code{-f}
1039 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1040 subprocess. It tells @value{GDBN} to output the full file name and line
1041 number in a standard, recognizable fashion each time a stack frame is
1042 displayed (which includes each time your program stops). This
1043 recognizable format looks like two @samp{\032} characters, followed by
1044 the file name, line number and character position separated by colons,
1045 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1046 @samp{\032} characters as a signal to display the source code for the
1047 frame.
1048
1049 @item -epoch
1050 @cindex @code{--epoch}
1051 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1052 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1053 routines so as to allow Epoch to display values of expressions in a
1054 separate window.
1055
1056 @item -annotate @var{level}
1057 @cindex @code{--annotate}
1058 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1059 effect is identical to using @samp{set annotate @var{level}}
1060 (@pxref{Annotations}). The annotation @var{level} controls how much
1061 information @value{GDBN} prints together with its prompt, values of
1062 expressions, source lines, and other types of output. Level 0 is the
1063 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1064 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1065 that control @value{GDBN}, and level 2 has been deprecated.
1066
1067 The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1068 (@pxref{GDB/MI}).
1069
1070 @item --args
1071 @cindex @code{--args}
1072 Change interpretation of command line so that arguments following the
1073 executable file are passed as command line arguments to the inferior.
1074 This option stops option processing.
1075
1076 @item -baud @var{bps}
1077 @itemx -b @var{bps}
1078 @cindex @code{--baud}
1079 @cindex @code{-b}
1080 Set the line speed (baud rate or bits per second) of any serial
1081 interface used by @value{GDBN} for remote debugging.
1082
1083 @item -l @var{timeout}
1084 @cindex @code{-l}
1085 Set the timeout (in seconds) of any communication used by @value{GDBN}
1086 for remote debugging.
1087
1088 @item -tty @var{device}
1089 @itemx -t @var{device}
1090 @cindex @code{--tty}
1091 @cindex @code{-t}
1092 Run using @var{device} for your program's standard input and output.
1093 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1094
1095 @c resolve the situation of these eventually
1096 @item -tui
1097 @cindex @code{--tui}
1098 Activate the @dfn{Text User Interface} when starting. The Text User
1099 Interface manages several text windows on the terminal, showing
1100 source, assembly, registers and @value{GDBN} command outputs
1101 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1102 Text User Interface can be enabled by invoking the program
1103 @samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1104 Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1105
1106 @c @item -xdb
1107 @c @cindex @code{--xdb}
1108 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1109 @c For information, see the file @file{xdb_trans.html}, which is usually
1110 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1111 @c systems.
1112
1113 @item -interpreter @var{interp}
1114 @cindex @code{--interpreter}
1115 Use the interpreter @var{interp} for interface with the controlling
1116 program or device. This option is meant to be set by programs which
1117 communicate with @value{GDBN} using it as a back end.
1118 @xref{Interpreters, , Command Interpreters}.
1119
1120 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1121 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1122 The @sc{gdb/mi} Interface}) included since @var{GDBN} version 6.0. The
1123 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1124 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1125 @sc{gdb/mi} interfaces are no longer supported.
1126
1127 @item -write
1128 @cindex @code{--write}
1129 Open the executable and core files for both reading and writing. This
1130 is equivalent to the @samp{set write on} command inside @value{GDBN}
1131 (@pxref{Patching}).
1132
1133 @item -statistics
1134 @cindex @code{--statistics}
1135 This option causes @value{GDBN} to print statistics about time and
1136 memory usage after it completes each command and returns to the prompt.
1137
1138 @item -version
1139 @cindex @code{--version}
1140 This option causes @value{GDBN} to print its version number and
1141 no-warranty blurb, and exit.
1142
1143 @end table
1144
1145 @node Quitting GDB
1146 @section Quitting @value{GDBN}
1147 @cindex exiting @value{GDBN}
1148 @cindex leaving @value{GDBN}
1149
1150 @table @code
1151 @kindex quit @r{[}@var{expression}@r{]}
1152 @kindex q @r{(@code{quit})}
1153 @item quit @r{[}@var{expression}@r{]}
1154 @itemx q
1155 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1156 @code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1157 do not supply @var{expression}, @value{GDBN} will terminate normally;
1158 otherwise it will terminate using the result of @var{expression} as the
1159 error code.
1160 @end table
1161
1162 @cindex interrupt
1163 An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1164 terminates the action of any @value{GDBN} command that is in progress and
1165 returns to @value{GDBN} command level. It is safe to type the interrupt
1166 character at any time because @value{GDBN} does not allow it to take effect
1167 until a time when it is safe.
1168
1169 If you have been using @value{GDBN} to control an attached process or
1170 device, you can release it with the @code{detach} command
1171 (@pxref{Attach, ,Debugging an already-running process}).
1172
1173 @node Shell Commands
1174 @section Shell commands
1175
1176 If you need to execute occasional shell commands during your
1177 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1178 just use the @code{shell} command.
1179
1180 @table @code
1181 @kindex shell
1182 @cindex shell escape
1183 @item shell @var{command string}
1184 Invoke a standard shell to execute @var{command string}.
1185 If it exists, the environment variable @code{SHELL} determines which
1186 shell to run. Otherwise @value{GDBN} uses the default shell
1187 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1188 @end table
1189
1190 The utility @code{make} is often needed in development environments.
1191 You do not have to use the @code{shell} command for this purpose in
1192 @value{GDBN}:
1193
1194 @table @code
1195 @kindex make
1196 @cindex calling make
1197 @item make @var{make-args}
1198 Execute the @code{make} program with the specified
1199 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1200 @end table
1201
1202 @node Logging output
1203 @section Logging output
1204 @cindex logging @value{GDBN} output
1205 @cindex save @value{GDBN} output to a file
1206
1207 You may want to save the output of @value{GDBN} commands to a file.
1208 There are several commands to control @value{GDBN}'s logging.
1209
1210 @table @code
1211 @kindex set logging
1212 @item set logging on
1213 Enable logging.
1214 @item set logging off
1215 Disable logging.
1216 @cindex logging file name
1217 @item set logging file @var{file}
1218 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1219 @item set logging overwrite [on|off]
1220 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1221 you want @code{set logging on} to overwrite the logfile instead.
1222 @item set logging redirect [on|off]
1223 By default, @value{GDBN} output will go to both the terminal and the logfile.
1224 Set @code{redirect} if you want output to go only to the log file.
1225 @kindex show logging
1226 @item show logging
1227 Show the current values of the logging settings.
1228 @end table
1229
1230 @node Commands
1231 @chapter @value{GDBN} Commands
1232
1233 You can abbreviate a @value{GDBN} command to the first few letters of the command
1234 name, if that abbreviation is unambiguous; and you can repeat certain
1235 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1236 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1237 show you the alternatives available, if there is more than one possibility).
1238
1239 @menu
1240 * Command Syntax:: How to give commands to @value{GDBN}
1241 * Completion:: Command completion
1242 * Help:: How to ask @value{GDBN} for help
1243 @end menu
1244
1245 @node Command Syntax
1246 @section Command syntax
1247
1248 A @value{GDBN} command is a single line of input. There is no limit on
1249 how long it can be. It starts with a command name, which is followed by
1250 arguments whose meaning depends on the command name. For example, the
1251 command @code{step} accepts an argument which is the number of times to
1252 step, as in @samp{step 5}. You can also use the @code{step} command
1253 with no arguments. Some commands do not allow any arguments.
1254
1255 @cindex abbreviation
1256 @value{GDBN} command names may always be truncated if that abbreviation is
1257 unambiguous. Other possible command abbreviations are listed in the
1258 documentation for individual commands. In some cases, even ambiguous
1259 abbreviations are allowed; for example, @code{s} is specially defined as
1260 equivalent to @code{step} even though there are other commands whose
1261 names start with @code{s}. You can test abbreviations by using them as
1262 arguments to the @code{help} command.
1263
1264 @cindex repeating commands
1265 @kindex RET @r{(repeat last command)}
1266 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1267 repeat the previous command. Certain commands (for example, @code{run})
1268 will not repeat this way; these are commands whose unintentional
1269 repetition might cause trouble and which you are unlikely to want to
1270 repeat.
1271
1272 The @code{list} and @code{x} commands, when you repeat them with
1273 @key{RET}, construct new arguments rather than repeating
1274 exactly as typed. This permits easy scanning of source or memory.
1275
1276 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1277 output, in a way similar to the common utility @code{more}
1278 (@pxref{Screen Size,,Screen size}). Since it is easy to press one
1279 @key{RET} too many in this situation, @value{GDBN} disables command
1280 repetition after any command that generates this sort of display.
1281
1282 @kindex # @r{(a comment)}
1283 @cindex comment
1284 Any text from a @kbd{#} to the end of the line is a comment; it does
1285 nothing. This is useful mainly in command files (@pxref{Command
1286 Files,,Command files}).
1287
1288 @cindex repeating command sequences
1289 @kindex C-o @r{(operate-and-get-next)}
1290 The @kbd{C-o} binding is useful for repeating a complex sequence of
1291 commands. This command accepts the current line, like @kbd{RET}, and
1292 then fetches the next line relative to the current line from the history
1293 for editing.
1294
1295 @node Completion
1296 @section Command completion
1297
1298 @cindex completion
1299 @cindex word completion
1300 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1301 only one possibility; it can also show you what the valid possibilities
1302 are for the next word in a command, at any time. This works for @value{GDBN}
1303 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1304
1305 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1306 of a word. If there is only one possibility, @value{GDBN} fills in the
1307 word, and waits for you to finish the command (or press @key{RET} to
1308 enter it). For example, if you type
1309
1310 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1311 @c complete accuracy in these examples; space introduced for clarity.
1312 @c If texinfo enhancements make it unnecessary, it would be nice to
1313 @c replace " @key" by "@key" in the following...
1314 @smallexample
1315 (@value{GDBP}) info bre @key{TAB}
1316 @end smallexample
1317
1318 @noindent
1319 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1320 the only @code{info} subcommand beginning with @samp{bre}:
1321
1322 @smallexample
1323 (@value{GDBP}) info breakpoints
1324 @end smallexample
1325
1326 @noindent
1327 You can either press @key{RET} at this point, to run the @code{info
1328 breakpoints} command, or backspace and enter something else, if
1329 @samp{breakpoints} does not look like the command you expected. (If you
1330 were sure you wanted @code{info breakpoints} in the first place, you
1331 might as well just type @key{RET} immediately after @samp{info bre},
1332 to exploit command abbreviations rather than command completion).
1333
1334 If there is more than one possibility for the next word when you press
1335 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1336 characters and try again, or just press @key{TAB} a second time;
1337 @value{GDBN} displays all the possible completions for that word. For
1338 example, you might want to set a breakpoint on a subroutine whose name
1339 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1340 just sounds the bell. Typing @key{TAB} again displays all the
1341 function names in your program that begin with those characters, for
1342 example:
1343
1344 @smallexample
1345 (@value{GDBP}) b make_ @key{TAB}
1346 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1347 make_a_section_from_file make_environ
1348 make_abs_section make_function_type
1349 make_blockvector make_pointer_type
1350 make_cleanup make_reference_type
1351 make_command make_symbol_completion_list
1352 (@value{GDBP}) b make_
1353 @end smallexample
1354
1355 @noindent
1356 After displaying the available possibilities, @value{GDBN} copies your
1357 partial input (@samp{b make_} in the example) so you can finish the
1358 command.
1359
1360 If you just want to see the list of alternatives in the first place, you
1361 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1362 means @kbd{@key{META} ?}. You can type this either by holding down a
1363 key designated as the @key{META} shift on your keyboard (if there is
1364 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1365
1366 @cindex quotes in commands
1367 @cindex completion of quoted strings
1368 Sometimes the string you need, while logically a ``word'', may contain
1369 parentheses or other characters that @value{GDBN} normally excludes from
1370 its notion of a word. To permit word completion to work in this
1371 situation, you may enclose words in @code{'} (single quote marks) in
1372 @value{GDBN} commands.
1373
1374 The most likely situation where you might need this is in typing the
1375 name of a C@t{++} function. This is because C@t{++} allows function
1376 overloading (multiple definitions of the same function, distinguished
1377 by argument type). For example, when you want to set a breakpoint you
1378 may need to distinguish whether you mean the version of @code{name}
1379 that takes an @code{int} parameter, @code{name(int)}, or the version
1380 that takes a @code{float} parameter, @code{name(float)}. To use the
1381 word-completion facilities in this situation, type a single quote
1382 @code{'} at the beginning of the function name. This alerts
1383 @value{GDBN} that it may need to consider more information than usual
1384 when you press @key{TAB} or @kbd{M-?} to request word completion:
1385
1386 @smallexample
1387 (@value{GDBP}) b 'bubble( @kbd{M-?}
1388 bubble(double,double) bubble(int,int)
1389 (@value{GDBP}) b 'bubble(
1390 @end smallexample
1391
1392 In some cases, @value{GDBN} can tell that completing a name requires using
1393 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1394 completing as much as it can) if you do not type the quote in the first
1395 place:
1396
1397 @smallexample
1398 (@value{GDBP}) b bub @key{TAB}
1399 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1400 (@value{GDBP}) b 'bubble(
1401 @end smallexample
1402
1403 @noindent
1404 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1405 you have not yet started typing the argument list when you ask for
1406 completion on an overloaded symbol.
1407
1408 For more information about overloaded functions, see @ref{C plus plus
1409 expressions, ,C@t{++} expressions}. You can use the command @code{set
1410 overload-resolution off} to disable overload resolution;
1411 see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
1412
1413
1414 @node Help
1415 @section Getting help
1416 @cindex online documentation
1417 @kindex help
1418
1419 You can always ask @value{GDBN} itself for information on its commands,
1420 using the command @code{help}.
1421
1422 @table @code
1423 @kindex h @r{(@code{help})}
1424 @item help
1425 @itemx h
1426 You can use @code{help} (abbreviated @code{h}) with no arguments to
1427 display a short list of named classes of commands:
1428
1429 @smallexample
1430 (@value{GDBP}) help
1431 List of classes of commands:
1432
1433 aliases -- Aliases of other commands
1434 breakpoints -- Making program stop at certain points
1435 data -- Examining data
1436 files -- Specifying and examining files
1437 internals -- Maintenance commands
1438 obscure -- Obscure features
1439 running -- Running the program
1440 stack -- Examining the stack
1441 status -- Status inquiries
1442 support -- Support facilities
1443 tracepoints -- Tracing of program execution without@*
1444 stopping the program
1445 user-defined -- User-defined commands
1446
1447 Type "help" followed by a class name for a list of
1448 commands in that class.
1449 Type "help" followed by command name for full
1450 documentation.
1451 Command name abbreviations are allowed if unambiguous.
1452 (@value{GDBP})
1453 @end smallexample
1454 @c the above line break eliminates huge line overfull...
1455
1456 @item help @var{class}
1457 Using one of the general help classes as an argument, you can get a
1458 list of the individual commands in that class. For example, here is the
1459 help display for the class @code{status}:
1460
1461 @smallexample
1462 (@value{GDBP}) help status
1463 Status inquiries.
1464
1465 List of commands:
1466
1467 @c Line break in "show" line falsifies real output, but needed
1468 @c to fit in smallbook page size.
1469 info -- Generic command for showing things
1470 about the program being debugged
1471 show -- Generic command for showing things
1472 about the debugger
1473
1474 Type "help" followed by command name for full
1475 documentation.
1476 Command name abbreviations are allowed if unambiguous.
1477 (@value{GDBP})
1478 @end smallexample
1479
1480 @item help @var{command}
1481 With a command name as @code{help} argument, @value{GDBN} displays a
1482 short paragraph on how to use that command.
1483
1484 @kindex apropos
1485 @item apropos @var{args}
1486 The @code{apropos} command searches through all of the @value{GDBN}
1487 commands, and their documentation, for the regular expression specified in
1488 @var{args}. It prints out all matches found. For example:
1489
1490 @smallexample
1491 apropos reload
1492 @end smallexample
1493
1494 @noindent
1495 results in:
1496
1497 @smallexample
1498 @c @group
1499 set symbol-reloading -- Set dynamic symbol table reloading
1500 multiple times in one run
1501 show symbol-reloading -- Show dynamic symbol table reloading
1502 multiple times in one run
1503 @c @end group
1504 @end smallexample
1505
1506 @kindex complete
1507 @item complete @var{args}
1508 The @code{complete @var{args}} command lists all the possible completions
1509 for the beginning of a command. Use @var{args} to specify the beginning of the
1510 command you want completed. For example:
1511
1512 @smallexample
1513 complete i
1514 @end smallexample
1515
1516 @noindent results in:
1517
1518 @smallexample
1519 @group
1520 if
1521 ignore
1522 info
1523 inspect
1524 @end group
1525 @end smallexample
1526
1527 @noindent This is intended for use by @sc{gnu} Emacs.
1528 @end table
1529
1530 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1531 and @code{show} to inquire about the state of your program, or the state
1532 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1533 manual introduces each of them in the appropriate context. The listings
1534 under @code{info} and under @code{show} in the Index point to
1535 all the sub-commands. @xref{Index}.
1536
1537 @c @group
1538 @table @code
1539 @kindex info
1540 @kindex i @r{(@code{info})}
1541 @item info
1542 This command (abbreviated @code{i}) is for describing the state of your
1543 program. For example, you can list the arguments given to your program
1544 with @code{info args}, list the registers currently in use with @code{info
1545 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1546 You can get a complete list of the @code{info} sub-commands with
1547 @w{@code{help info}}.
1548
1549 @kindex set
1550 @item set
1551 You can assign the result of an expression to an environment variable with
1552 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1553 @code{set prompt $}.
1554
1555 @kindex show
1556 @item show
1557 In contrast to @code{info}, @code{show} is for describing the state of
1558 @value{GDBN} itself.
1559 You can change most of the things you can @code{show}, by using the
1560 related command @code{set}; for example, you can control what number
1561 system is used for displays with @code{set radix}, or simply inquire
1562 which is currently in use with @code{show radix}.
1563
1564 @kindex info set
1565 To display all the settable parameters and their current
1566 values, you can use @code{show} with no arguments; you may also use
1567 @code{info set}. Both commands produce the same display.
1568 @c FIXME: "info set" violates the rule that "info" is for state of
1569 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1570 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1571 @end table
1572 @c @end group
1573
1574 Here are three miscellaneous @code{show} subcommands, all of which are
1575 exceptional in lacking corresponding @code{set} commands:
1576
1577 @table @code
1578 @kindex show version
1579 @cindex @value{GDBN} version number
1580 @item show version
1581 Show what version of @value{GDBN} is running. You should include this
1582 information in @value{GDBN} bug-reports. If multiple versions of
1583 @value{GDBN} are in use at your site, you may need to determine which
1584 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1585 commands are introduced, and old ones may wither away. Also, many
1586 system vendors ship variant versions of @value{GDBN}, and there are
1587 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1588 The version number is the same as the one announced when you start
1589 @value{GDBN}.
1590
1591 @kindex show copying
1592 @kindex info copying
1593 @cindex display @value{GDBN} copyright
1594 @item show copying
1595 @itemx info copying
1596 Display information about permission for copying @value{GDBN}.
1597
1598 @kindex show warranty
1599 @kindex info warranty
1600 @item show warranty
1601 @itemx info warranty
1602 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1603 if your version of @value{GDBN} comes with one.
1604
1605 @end table
1606
1607 @node Running
1608 @chapter Running Programs Under @value{GDBN}
1609
1610 When you run a program under @value{GDBN}, you must first generate
1611 debugging information when you compile it.
1612
1613 You may start @value{GDBN} with its arguments, if any, in an environment
1614 of your choice. If you are doing native debugging, you may redirect
1615 your program's input and output, debug an already running process, or
1616 kill a child process.
1617
1618 @menu
1619 * Compilation:: Compiling for debugging
1620 * Starting:: Starting your program
1621 * Arguments:: Your program's arguments
1622 * Environment:: Your program's environment
1623
1624 * Working Directory:: Your program's working directory
1625 * Input/Output:: Your program's input and output
1626 * Attach:: Debugging an already-running process
1627 * Kill Process:: Killing the child process
1628
1629 * Threads:: Debugging programs with multiple threads
1630 * Processes:: Debugging programs with multiple processes
1631 @end menu
1632
1633 @node Compilation
1634 @section Compiling for debugging
1635
1636 In order to debug a program effectively, you need to generate
1637 debugging information when you compile it. This debugging information
1638 is stored in the object file; it describes the data type of each
1639 variable or function and the correspondence between source line numbers
1640 and addresses in the executable code.
1641
1642 To request debugging information, specify the @samp{-g} option when you run
1643 the compiler.
1644
1645 Most compilers do not include information about preprocessor macros in
1646 the debugging information if you specify the @option{-g} flag alone,
1647 because this information is rather large. Version 3.1 of @value{NGCC},
1648 the @sc{gnu} C compiler, provides macro information if you specify the
1649 options @option{-gdwarf-2} and @option{-g3}; the former option requests
1650 debugging information in the Dwarf 2 format, and the latter requests
1651 ``extra information''. In the future, we hope to find more compact ways
1652 to represent macro information, so that it can be included with
1653 @option{-g} alone.
1654
1655 Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1656 options together. Using those compilers, you cannot generate optimized
1657 executables containing debugging information.
1658
1659 @value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1660 without @samp{-O}, making it possible to debug optimized code. We
1661 recommend that you @emph{always} use @samp{-g} whenever you compile a
1662 program. You may think your program is correct, but there is no sense
1663 in pushing your luck.
1664
1665 @cindex optimized code, debugging
1666 @cindex debugging optimized code
1667 When you debug a program compiled with @samp{-g -O}, remember that the
1668 optimizer is rearranging your code; the debugger shows you what is
1669 really there. Do not be too surprised when the execution path does not
1670 exactly match your source file! An extreme example: if you define a
1671 variable, but never use it, @value{GDBN} never sees that
1672 variable---because the compiler optimizes it out of existence.
1673
1674 Some things do not work as well with @samp{-g -O} as with just
1675 @samp{-g}, particularly on machines with instruction scheduling. If in
1676 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1677 please report it to us as a bug (including a test case!).
1678 @xref{Variables}, for more information about debugging optimized code.
1679
1680 Older versions of the @sc{gnu} C compiler permitted a variant option
1681 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1682 format; if your @sc{gnu} C compiler has this option, do not use it.
1683
1684 @need 2000
1685 @node Starting
1686 @section Starting your program
1687 @cindex starting
1688 @cindex running
1689
1690 @table @code
1691 @kindex run
1692 @kindex r @r{(@code{run})}
1693 @item run
1694 @itemx r
1695 Use the @code{run} command to start your program under @value{GDBN}.
1696 You must first specify the program name (except on VxWorks) with an
1697 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1698 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1699 (@pxref{Files, ,Commands to specify files}).
1700
1701 @end table
1702
1703 If you are running your program in an execution environment that
1704 supports processes, @code{run} creates an inferior process and makes
1705 that process run your program. (In environments without processes,
1706 @code{run} jumps to the start of your program.)
1707
1708 The execution of a program is affected by certain information it
1709 receives from its superior. @value{GDBN} provides ways to specify this
1710 information, which you must do @emph{before} starting your program. (You
1711 can change it after starting your program, but such changes only affect
1712 your program the next time you start it.) This information may be
1713 divided into four categories:
1714
1715 @table @asis
1716 @item The @emph{arguments.}
1717 Specify the arguments to give your program as the arguments of the
1718 @code{run} command. If a shell is available on your target, the shell
1719 is used to pass the arguments, so that you may use normal conventions
1720 (such as wildcard expansion or variable substitution) in describing
1721 the arguments.
1722 In Unix systems, you can control which shell is used with the
1723 @code{SHELL} environment variable.
1724 @xref{Arguments, ,Your program's arguments}.
1725
1726 @item The @emph{environment.}
1727 Your program normally inherits its environment from @value{GDBN}, but you can
1728 use the @value{GDBN} commands @code{set environment} and @code{unset
1729 environment} to change parts of the environment that affect
1730 your program. @xref{Environment, ,Your program's environment}.
1731
1732 @item The @emph{working directory.}
1733 Your program inherits its working directory from @value{GDBN}. You can set
1734 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1735 @xref{Working Directory, ,Your program's working directory}.
1736
1737 @item The @emph{standard input and output.}
1738 Your program normally uses the same device for standard input and
1739 standard output as @value{GDBN} is using. You can redirect input and output
1740 in the @code{run} command line, or you can use the @code{tty} command to
1741 set a different device for your program.
1742 @xref{Input/Output, ,Your program's input and output}.
1743
1744 @cindex pipes
1745 @emph{Warning:} While input and output redirection work, you cannot use
1746 pipes to pass the output of the program you are debugging to another
1747 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1748 wrong program.
1749 @end table
1750
1751 When you issue the @code{run} command, your program begins to execute
1752 immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1753 of how to arrange for your program to stop. Once your program has
1754 stopped, you may call functions in your program, using the @code{print}
1755 or @code{call} commands. @xref{Data, ,Examining Data}.
1756
1757 If the modification time of your symbol file has changed since the last
1758 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1759 table, and reads it again. When it does this, @value{GDBN} tries to retain
1760 your current breakpoints.
1761
1762 @table @code
1763 @kindex start
1764 @item start
1765 @cindex run to main procedure
1766 The name of the main procedure can vary from language to language.
1767 With C or C@t{++}, the main procedure name is always @code{main}, but
1768 other languages such as Ada do not require a specific name for their
1769 main procedure. The debugger provides a convenient way to start the
1770 execution of the program and to stop at the beginning of the main
1771 procedure, depending on the language used.
1772
1773 The @samp{start} command does the equivalent of setting a temporary
1774 breakpoint at the beginning of the main procedure and then invoking
1775 the @samp{run} command.
1776
1777 @cindex elaboration phase
1778 Some programs contain an @dfn{elaboration} phase where some startup code is
1779 executed before the main procedure is called. This depends on the
1780 languages used to write your program. In C@t{++}, for instance,
1781 constructors for static and global objects are executed before
1782 @code{main} is called. It is therefore possible that the debugger stops
1783 before reaching the main procedure. However, the temporary breakpoint
1784 will remain to halt execution.
1785
1786 Specify the arguments to give to your program as arguments to the
1787 @samp{start} command. These arguments will be given verbatim to the
1788 underlying @samp{run} command. Note that the same arguments will be
1789 reused if no argument is provided during subsequent calls to
1790 @samp{start} or @samp{run}.
1791
1792 It is sometimes necessary to debug the program during elaboration. In
1793 these cases, using the @code{start} command would stop the execution of
1794 your program too late, as the program would have already completed the
1795 elaboration phase. Under these circumstances, insert breakpoints in your
1796 elaboration code before running your program.
1797 @end table
1798
1799 @node Arguments
1800 @section Your program's arguments
1801
1802 @cindex arguments (to your program)
1803 The arguments to your program can be specified by the arguments of the
1804 @code{run} command.
1805 They are passed to a shell, which expands wildcard characters and
1806 performs redirection of I/O, and thence to your program. Your
1807 @code{SHELL} environment variable (if it exists) specifies what shell
1808 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1809 the default shell (@file{/bin/sh} on Unix).
1810
1811 On non-Unix systems, the program is usually invoked directly by
1812 @value{GDBN}, which emulates I/O redirection via the appropriate system
1813 calls, and the wildcard characters are expanded by the startup code of
1814 the program, not by the shell.
1815
1816 @code{run} with no arguments uses the same arguments used by the previous
1817 @code{run}, or those set by the @code{set args} command.
1818
1819 @table @code
1820 @kindex set args
1821 @item set args
1822 Specify the arguments to be used the next time your program is run. If
1823 @code{set args} has no arguments, @code{run} executes your program
1824 with no arguments. Once you have run your program with arguments,
1825 using @code{set args} before the next @code{run} is the only way to run
1826 it again without arguments.
1827
1828 @kindex show args
1829 @item show args
1830 Show the arguments to give your program when it is started.
1831 @end table
1832
1833 @node Environment
1834 @section Your program's environment
1835
1836 @cindex environment (of your program)
1837 The @dfn{environment} consists of a set of environment variables and
1838 their values. Environment variables conventionally record such things as
1839 your user name, your home directory, your terminal type, and your search
1840 path for programs to run. Usually you set up environment variables with
1841 the shell and they are inherited by all the other programs you run. When
1842 debugging, it can be useful to try running your program with a modified
1843 environment without having to start @value{GDBN} over again.
1844
1845 @table @code
1846 @kindex path
1847 @item path @var{directory}
1848 Add @var{directory} to the front of the @code{PATH} environment variable
1849 (the search path for executables) that will be passed to your program.
1850 The value of @code{PATH} used by @value{GDBN} does not change.
1851 You may specify several directory names, separated by whitespace or by a
1852 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1853 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1854 is moved to the front, so it is searched sooner.
1855
1856 You can use the string @samp{$cwd} to refer to whatever is the current
1857 working directory at the time @value{GDBN} searches the path. If you
1858 use @samp{.} instead, it refers to the directory where you executed the
1859 @code{path} command. @value{GDBN} replaces @samp{.} in the
1860 @var{directory} argument (with the current path) before adding
1861 @var{directory} to the search path.
1862 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1863 @c document that, since repeating it would be a no-op.
1864
1865 @kindex show paths
1866 @item show paths
1867 Display the list of search paths for executables (the @code{PATH}
1868 environment variable).
1869
1870 @kindex show environment
1871 @item show environment @r{[}@var{varname}@r{]}
1872 Print the value of environment variable @var{varname} to be given to
1873 your program when it starts. If you do not supply @var{varname},
1874 print the names and values of all environment variables to be given to
1875 your program. You can abbreviate @code{environment} as @code{env}.
1876
1877 @kindex set environment
1878 @item set environment @var{varname} @r{[}=@var{value}@r{]}
1879 Set environment variable @var{varname} to @var{value}. The value
1880 changes for your program only, not for @value{GDBN} itself. @var{value} may
1881 be any string; the values of environment variables are just strings, and
1882 any interpretation is supplied by your program itself. The @var{value}
1883 parameter is optional; if it is eliminated, the variable is set to a
1884 null value.
1885 @c "any string" here does not include leading, trailing
1886 @c blanks. Gnu asks: does anyone care?
1887
1888 For example, this command:
1889
1890 @smallexample
1891 set env USER = foo
1892 @end smallexample
1893
1894 @noindent
1895 tells the debugged program, when subsequently run, that its user is named
1896 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1897 are not actually required.)
1898
1899 @kindex unset environment
1900 @item unset environment @var{varname}
1901 Remove variable @var{varname} from the environment to be passed to your
1902 program. This is different from @samp{set env @var{varname} =};
1903 @code{unset environment} removes the variable from the environment,
1904 rather than assigning it an empty value.
1905 @end table
1906
1907 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1908 the shell indicated
1909 by your @code{SHELL} environment variable if it exists (or
1910 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1911 that runs an initialization file---such as @file{.cshrc} for C-shell, or
1912 @file{.bashrc} for BASH---any variables you set in that file affect
1913 your program. You may wish to move setting of environment variables to
1914 files that are only run when you sign on, such as @file{.login} or
1915 @file{.profile}.
1916
1917 @node Working Directory
1918 @section Your program's working directory
1919
1920 @cindex working directory (of your program)
1921 Each time you start your program with @code{run}, it inherits its
1922 working directory from the current working directory of @value{GDBN}.
1923 The @value{GDBN} working directory is initially whatever it inherited
1924 from its parent process (typically the shell), but you can specify a new
1925 working directory in @value{GDBN} with the @code{cd} command.
1926
1927 The @value{GDBN} working directory also serves as a default for the commands
1928 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1929 specify files}.
1930
1931 @table @code
1932 @kindex cd
1933 @cindex change working directory
1934 @item cd @var{directory}
1935 Set the @value{GDBN} working directory to @var{directory}.
1936
1937 @kindex pwd
1938 @item pwd
1939 Print the @value{GDBN} working directory.
1940 @end table
1941
1942 It is generally impossible to find the current working directory of
1943 the process being debugged (since a program can change its directory
1944 during its run). If you work on a system where @value{GDBN} is
1945 configured with the @file{/proc} support, you can use the @code{info
1946 proc} command (@pxref{SVR4 Process Information}) to find out the
1947 current working directory of the debuggee.
1948
1949 @node Input/Output
1950 @section Your program's input and output
1951
1952 @cindex redirection
1953 @cindex i/o
1954 @cindex terminal
1955 By default, the program you run under @value{GDBN} does input and output to
1956 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
1957 to its own terminal modes to interact with you, but it records the terminal
1958 modes your program was using and switches back to them when you continue
1959 running your program.
1960
1961 @table @code
1962 @kindex info terminal
1963 @item info terminal
1964 Displays information recorded by @value{GDBN} about the terminal modes your
1965 program is using.
1966 @end table
1967
1968 You can redirect your program's input and/or output using shell
1969 redirection with the @code{run} command. For example,
1970
1971 @smallexample
1972 run > outfile
1973 @end smallexample
1974
1975 @noindent
1976 starts your program, diverting its output to the file @file{outfile}.
1977
1978 @kindex tty
1979 @cindex controlling terminal
1980 Another way to specify where your program should do input and output is
1981 with the @code{tty} command. This command accepts a file name as
1982 argument, and causes this file to be the default for future @code{run}
1983 commands. It also resets the controlling terminal for the child
1984 process, for future @code{run} commands. For example,
1985
1986 @smallexample
1987 tty /dev/ttyb
1988 @end smallexample
1989
1990 @noindent
1991 directs that processes started with subsequent @code{run} commands
1992 default to do input and output on the terminal @file{/dev/ttyb} and have
1993 that as their controlling terminal.
1994
1995 An explicit redirection in @code{run} overrides the @code{tty} command's
1996 effect on the input/output device, but not its effect on the controlling
1997 terminal.
1998
1999 When you use the @code{tty} command or redirect input in the @code{run}
2000 command, only the input @emph{for your program} is affected. The input
2001 for @value{GDBN} still comes from your terminal.
2002
2003 @node Attach
2004 @section Debugging an already-running process
2005 @kindex attach
2006 @cindex attach
2007
2008 @table @code
2009 @item attach @var{process-id}
2010 This command attaches to a running process---one that was started
2011 outside @value{GDBN}. (@code{info files} shows your active
2012 targets.) The command takes as argument a process ID. The usual way to
2013 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2014 or with the @samp{jobs -l} shell command.
2015
2016 @code{attach} does not repeat if you press @key{RET} a second time after
2017 executing the command.
2018 @end table
2019
2020 To use @code{attach}, your program must be running in an environment
2021 which supports processes; for example, @code{attach} does not work for
2022 programs on bare-board targets that lack an operating system. You must
2023 also have permission to send the process a signal.
2024
2025 When you use @code{attach}, the debugger finds the program running in
2026 the process first by looking in the current working directory, then (if
2027 the program is not found) by using the source file search path
2028 (@pxref{Source Path, ,Specifying source directories}). You can also use
2029 the @code{file} command to load the program. @xref{Files, ,Commands to
2030 Specify Files}.
2031
2032 The first thing @value{GDBN} does after arranging to debug the specified
2033 process is to stop it. You can examine and modify an attached process
2034 with all the @value{GDBN} commands that are ordinarily available when
2035 you start processes with @code{run}. You can insert breakpoints; you
2036 can step and continue; you can modify storage. If you would rather the
2037 process continue running, you may use the @code{continue} command after
2038 attaching @value{GDBN} to the process.
2039
2040 @table @code
2041 @kindex detach
2042 @item detach
2043 When you have finished debugging the attached process, you can use the
2044 @code{detach} command to release it from @value{GDBN} control. Detaching
2045 the process continues its execution. After the @code{detach} command,
2046 that process and @value{GDBN} become completely independent once more, and you
2047 are ready to @code{attach} another process or start one with @code{run}.
2048 @code{detach} does not repeat if you press @key{RET} again after
2049 executing the command.
2050 @end table
2051
2052 If you exit @value{GDBN} or use the @code{run} command while you have an
2053 attached process, you kill that process. By default, @value{GDBN} asks
2054 for confirmation if you try to do either of these things; you can
2055 control whether or not you need to confirm by using the @code{set
2056 confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2057 messages}).
2058
2059 @node Kill Process
2060 @section Killing the child process
2061
2062 @table @code
2063 @kindex kill
2064 @item kill
2065 Kill the child process in which your program is running under @value{GDBN}.
2066 @end table
2067
2068 This command is useful if you wish to debug a core dump instead of a
2069 running process. @value{GDBN} ignores any core dump file while your program
2070 is running.
2071
2072 On some operating systems, a program cannot be executed outside @value{GDBN}
2073 while you have breakpoints set on it inside @value{GDBN}. You can use the
2074 @code{kill} command in this situation to permit running your program
2075 outside the debugger.
2076
2077 The @code{kill} command is also useful if you wish to recompile and
2078 relink your program, since on many systems it is impossible to modify an
2079 executable file while it is running in a process. In this case, when you
2080 next type @code{run}, @value{GDBN} notices that the file has changed, and
2081 reads the symbol table again (while trying to preserve your current
2082 breakpoint settings).
2083
2084 @node Threads
2085 @section Debugging programs with multiple threads
2086
2087 @cindex threads of execution
2088 @cindex multiple threads
2089 @cindex switching threads
2090 In some operating systems, such as HP-UX and Solaris, a single program
2091 may have more than one @dfn{thread} of execution. The precise semantics
2092 of threads differ from one operating system to another, but in general
2093 the threads of a single program are akin to multiple processes---except
2094 that they share one address space (that is, they can all examine and
2095 modify the same variables). On the other hand, each thread has its own
2096 registers and execution stack, and perhaps private memory.
2097
2098 @value{GDBN} provides these facilities for debugging multi-thread
2099 programs:
2100
2101 @itemize @bullet
2102 @item automatic notification of new threads
2103 @item @samp{thread @var{threadno}}, a command to switch among threads
2104 @item @samp{info threads}, a command to inquire about existing threads
2105 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2106 a command to apply a command to a list of threads
2107 @item thread-specific breakpoints
2108 @end itemize
2109
2110 @quotation
2111 @emph{Warning:} These facilities are not yet available on every
2112 @value{GDBN} configuration where the operating system supports threads.
2113 If your @value{GDBN} does not support threads, these commands have no
2114 effect. For example, a system without thread support shows no output
2115 from @samp{info threads}, and always rejects the @code{thread} command,
2116 like this:
2117
2118 @smallexample
2119 (@value{GDBP}) info threads
2120 (@value{GDBP}) thread 1
2121 Thread ID 1 not known. Use the "info threads" command to
2122 see the IDs of currently known threads.
2123 @end smallexample
2124 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2125 @c doesn't support threads"?
2126 @end quotation
2127
2128 @cindex focus of debugging
2129 @cindex current thread
2130 The @value{GDBN} thread debugging facility allows you to observe all
2131 threads while your program runs---but whenever @value{GDBN} takes
2132 control, one thread in particular is always the focus of debugging.
2133 This thread is called the @dfn{current thread}. Debugging commands show
2134 program information from the perspective of the current thread.
2135
2136 @cindex @code{New} @var{systag} message
2137 @cindex thread identifier (system)
2138 @c FIXME-implementors!! It would be more helpful if the [New...] message
2139 @c included GDB's numeric thread handle, so you could just go to that
2140 @c thread without first checking `info threads'.
2141 Whenever @value{GDBN} detects a new thread in your program, it displays
2142 the target system's identification for the thread with a message in the
2143 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2144 whose form varies depending on the particular system. For example, on
2145 LynxOS, you might see
2146
2147 @smallexample
2148 [New process 35 thread 27]
2149 @end smallexample
2150
2151 @noindent
2152 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2153 the @var{systag} is simply something like @samp{process 368}, with no
2154 further qualifier.
2155
2156 @c FIXME!! (1) Does the [New...] message appear even for the very first
2157 @c thread of a program, or does it only appear for the
2158 @c second---i.e.@: when it becomes obvious we have a multithread
2159 @c program?
2160 @c (2) *Is* there necessarily a first thread always? Or do some
2161 @c multithread systems permit starting a program with multiple
2162 @c threads ab initio?
2163
2164 @cindex thread number
2165 @cindex thread identifier (GDB)
2166 For debugging purposes, @value{GDBN} associates its own thread
2167 number---always a single integer---with each thread in your program.
2168
2169 @table @code
2170 @kindex info threads
2171 @item info threads
2172 Display a summary of all threads currently in your
2173 program. @value{GDBN} displays for each thread (in this order):
2174
2175 @enumerate
2176 @item
2177 the thread number assigned by @value{GDBN}
2178
2179 @item
2180 the target system's thread identifier (@var{systag})
2181
2182 @item
2183 the current stack frame summary for that thread
2184 @end enumerate
2185
2186 @noindent
2187 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2188 indicates the current thread.
2189
2190 For example,
2191 @end table
2192 @c end table here to get a little more width for example
2193
2194 @smallexample
2195 (@value{GDBP}) info threads
2196 3 process 35 thread 27 0x34e5 in sigpause ()
2197 2 process 35 thread 23 0x34e5 in sigpause ()
2198 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2199 at threadtest.c:68
2200 @end smallexample
2201
2202 On HP-UX systems:
2203
2204 @cindex debugging multithreaded programs (on HP-UX)
2205 @cindex thread identifier (GDB), on HP-UX
2206 For debugging purposes, @value{GDBN} associates its own thread
2207 number---a small integer assigned in thread-creation order---with each
2208 thread in your program.
2209
2210 @cindex @code{New} @var{systag} message, on HP-UX
2211 @cindex thread identifier (system), on HP-UX
2212 @c FIXME-implementors!! It would be more helpful if the [New...] message
2213 @c included GDB's numeric thread handle, so you could just go to that
2214 @c thread without first checking `info threads'.
2215 Whenever @value{GDBN} detects a new thread in your program, it displays
2216 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2217 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2218 whose form varies depending on the particular system. For example, on
2219 HP-UX, you see
2220
2221 @smallexample
2222 [New thread 2 (system thread 26594)]
2223 @end smallexample
2224
2225 @noindent
2226 when @value{GDBN} notices a new thread.
2227
2228 @table @code
2229 @kindex info threads (HP-UX)
2230 @item info threads
2231 Display a summary of all threads currently in your
2232 program. @value{GDBN} displays for each thread (in this order):
2233
2234 @enumerate
2235 @item the thread number assigned by @value{GDBN}
2236
2237 @item the target system's thread identifier (@var{systag})
2238
2239 @item the current stack frame summary for that thread
2240 @end enumerate
2241
2242 @noindent
2243 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2244 indicates the current thread.
2245
2246 For example,
2247 @end table
2248 @c end table here to get a little more width for example
2249
2250 @smallexample
2251 (@value{GDBP}) info threads
2252 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2253 at quicksort.c:137
2254 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2255 from /usr/lib/libc.2
2256 1 system thread 27905 0x7b003498 in _brk () \@*
2257 from /usr/lib/libc.2
2258 @end smallexample
2259
2260 @table @code
2261 @kindex thread @var{threadno}
2262 @item thread @var{threadno}
2263 Make thread number @var{threadno} the current thread. The command
2264 argument @var{threadno} is the internal @value{GDBN} thread number, as
2265 shown in the first field of the @samp{info threads} display.
2266 @value{GDBN} responds by displaying the system identifier of the thread
2267 you selected, and its current stack frame summary:
2268
2269 @smallexample
2270 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2271 (@value{GDBP}) thread 2
2272 [Switching to process 35 thread 23]
2273 0x34e5 in sigpause ()
2274 @end smallexample
2275
2276 @noindent
2277 As with the @samp{[New @dots{}]} message, the form of the text after
2278 @samp{Switching to} depends on your system's conventions for identifying
2279 threads.
2280
2281 @kindex thread apply
2282 @item thread apply [@var{threadno}] [@var{all}] @var{args}
2283 The @code{thread apply} command allows you to apply a command to one or
2284 more threads. Specify the numbers of the threads that you want affected
2285 with the command argument @var{threadno}. @var{threadno} is the internal
2286 @value{GDBN} thread number, as shown in the first field of the @samp{info
2287 threads} display. To apply a command to all threads, use
2288 @code{thread apply all} @var{args}.
2289 @end table
2290
2291 @cindex automatic thread selection
2292 @cindex switching threads automatically
2293 @cindex threads, automatic switching
2294 Whenever @value{GDBN} stops your program, due to a breakpoint or a
2295 signal, it automatically selects the thread where that breakpoint or
2296 signal happened. @value{GDBN} alerts you to the context switch with a
2297 message of the form @samp{[Switching to @var{systag}]} to identify the
2298 thread.
2299
2300 @xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2301 more information about how @value{GDBN} behaves when you stop and start
2302 programs with multiple threads.
2303
2304 @xref{Set Watchpoints,,Setting watchpoints}, for information about
2305 watchpoints in programs with multiple threads.
2306
2307 @node Processes
2308 @section Debugging programs with multiple processes
2309
2310 @cindex fork, debugging programs which call
2311 @cindex multiple processes
2312 @cindex processes, multiple
2313 On most systems, @value{GDBN} has no special support for debugging
2314 programs which create additional processes using the @code{fork}
2315 function. When a program forks, @value{GDBN} will continue to debug the
2316 parent process and the child process will run unimpeded. If you have
2317 set a breakpoint in any code which the child then executes, the child
2318 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2319 will cause it to terminate.
2320
2321 However, if you want to debug the child process there is a workaround
2322 which isn't too painful. Put a call to @code{sleep} in the code which
2323 the child process executes after the fork. It may be useful to sleep
2324 only if a certain environment variable is set, or a certain file exists,
2325 so that the delay need not occur when you don't want to run @value{GDBN}
2326 on the child. While the child is sleeping, use the @code{ps} program to
2327 get its process ID. Then tell @value{GDBN} (a new invocation of
2328 @value{GDBN} if you are also debugging the parent process) to attach to
2329 the child process (@pxref{Attach}). From that point on you can debug
2330 the child process just like any other process which you attached to.
2331
2332 On some systems, @value{GDBN} provides support for debugging programs that
2333 create additional processes using the @code{fork} or @code{vfork} functions.
2334 Currently, the only platforms with this feature are HP-UX (11.x and later
2335 only?) and GNU/Linux (kernel version 2.5.60 and later).
2336
2337 By default, when a program forks, @value{GDBN} will continue to debug
2338 the parent process and the child process will run unimpeded.
2339
2340 If you want to follow the child process instead of the parent process,
2341 use the command @w{@code{set follow-fork-mode}}.
2342
2343 @table @code
2344 @kindex set follow-fork-mode
2345 @item set follow-fork-mode @var{mode}
2346 Set the debugger response to a program call of @code{fork} or
2347 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2348 process. The @var{mode} argument can be:
2349
2350 @table @code
2351 @item parent
2352 The original process is debugged after a fork. The child process runs
2353 unimpeded. This is the default.
2354
2355 @item child
2356 The new process is debugged after a fork. The parent process runs
2357 unimpeded.
2358
2359 @end table
2360
2361 @kindex show follow-fork-mode
2362 @item show follow-fork-mode
2363 Display the current debugger response to a @code{fork} or @code{vfork} call.
2364 @end table
2365
2366 If you ask to debug a child process and a @code{vfork} is followed by an
2367 @code{exec}, @value{GDBN} executes the new target up to the first
2368 breakpoint in the new target. If you have a breakpoint set on
2369 @code{main} in your original program, the breakpoint will also be set on
2370 the child process's @code{main}.
2371
2372 When a child process is spawned by @code{vfork}, you cannot debug the
2373 child or parent until an @code{exec} call completes.
2374
2375 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2376 call executes, the new target restarts. To restart the parent process,
2377 use the @code{file} command with the parent executable name as its
2378 argument.
2379
2380 You can use the @code{catch} command to make @value{GDBN} stop whenever
2381 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2382 Catchpoints, ,Setting catchpoints}.
2383
2384 @node Stopping
2385 @chapter Stopping and Continuing
2386
2387 The principal purposes of using a debugger are so that you can stop your
2388 program before it terminates; or so that, if your program runs into
2389 trouble, you can investigate and find out why.
2390
2391 Inside @value{GDBN}, your program may stop for any of several reasons,
2392 such as a signal, a breakpoint, or reaching a new line after a
2393 @value{GDBN} command such as @code{step}. You may then examine and
2394 change variables, set new breakpoints or remove old ones, and then
2395 continue execution. Usually, the messages shown by @value{GDBN} provide
2396 ample explanation of the status of your program---but you can also
2397 explicitly request this information at any time.
2398
2399 @table @code
2400 @kindex info program
2401 @item info program
2402 Display information about the status of your program: whether it is
2403 running or not, what process it is, and why it stopped.
2404 @end table
2405
2406 @menu
2407 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2408 * Continuing and Stepping:: Resuming execution
2409 * Signals:: Signals
2410 * Thread Stops:: Stopping and starting multi-thread programs
2411 @end menu
2412
2413 @node Breakpoints
2414 @section Breakpoints, watchpoints, and catchpoints
2415
2416 @cindex breakpoints
2417 A @dfn{breakpoint} makes your program stop whenever a certain point in
2418 the program is reached. For each breakpoint, you can add conditions to
2419 control in finer detail whether your program stops. You can set
2420 breakpoints with the @code{break} command and its variants (@pxref{Set
2421 Breaks, ,Setting breakpoints}), to specify the place where your program
2422 should stop by line number, function name or exact address in the
2423 program.
2424
2425 On some systems, you can set breakpoints in shared libraries before
2426 the executable is run. There is a minor limitation on HP-UX systems:
2427 you must wait until the executable is run in order to set breakpoints
2428 in shared library routines that are not called directly by the program
2429 (for example, routines that are arguments in a @code{pthread_create}
2430 call).
2431
2432 @cindex watchpoints
2433 @cindex memory tracing
2434 @cindex breakpoint on memory address
2435 @cindex breakpoint on variable modification
2436 A @dfn{watchpoint} is a special breakpoint that stops your program
2437 when the value of an expression changes. You must use a different
2438 command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2439 watchpoints}), but aside from that, you can manage a watchpoint like
2440 any other breakpoint: you enable, disable, and delete both breakpoints
2441 and watchpoints using the same commands.
2442
2443 You can arrange to have values from your program displayed automatically
2444 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2445 Automatic display}.
2446
2447 @cindex catchpoints
2448 @cindex breakpoint on events
2449 A @dfn{catchpoint} is another special breakpoint that stops your program
2450 when a certain kind of event occurs, such as the throwing of a C@t{++}
2451 exception or the loading of a library. As with watchpoints, you use a
2452 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2453 catchpoints}), but aside from that, you can manage a catchpoint like any
2454 other breakpoint. (To stop when your program receives a signal, use the
2455 @code{handle} command; see @ref{Signals, ,Signals}.)
2456
2457 @cindex breakpoint numbers
2458 @cindex numbers for breakpoints
2459 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2460 catchpoint when you create it; these numbers are successive integers
2461 starting with one. In many of the commands for controlling various
2462 features of breakpoints you use the breakpoint number to say which
2463 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2464 @dfn{disabled}; if disabled, it has no effect on your program until you
2465 enable it again.
2466
2467 @cindex breakpoint ranges
2468 @cindex ranges of breakpoints
2469 Some @value{GDBN} commands accept a range of breakpoints on which to
2470 operate. A breakpoint range is either a single breakpoint number, like
2471 @samp{5}, or two such numbers, in increasing order, separated by a
2472 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2473 all breakpoint in that range are operated on.
2474
2475 @menu
2476 * Set Breaks:: Setting breakpoints
2477 * Set Watchpoints:: Setting watchpoints
2478 * Set Catchpoints:: Setting catchpoints
2479 * Delete Breaks:: Deleting breakpoints
2480 * Disabling:: Disabling breakpoints
2481 * Conditions:: Break conditions
2482 * Break Commands:: Breakpoint command lists
2483 * Breakpoint Menus:: Breakpoint menus
2484 * Error in Breakpoints:: ``Cannot insert breakpoints''
2485 * Breakpoint related warnings:: ``Breakpoint address adjusted...''
2486 @end menu
2487
2488 @node Set Breaks
2489 @subsection Setting breakpoints
2490
2491 @c FIXME LMB what does GDB do if no code on line of breakpt?
2492 @c consider in particular declaration with/without initialization.
2493 @c
2494 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2495
2496 @kindex break
2497 @kindex b @r{(@code{break})}
2498 @vindex $bpnum@r{, convenience variable}
2499 @cindex latest breakpoint
2500 Breakpoints are set with the @code{break} command (abbreviated
2501 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2502 number of the breakpoint you've set most recently; see @ref{Convenience
2503 Vars,, Convenience variables}, for a discussion of what you can do with
2504 convenience variables.
2505
2506 You have several ways to say where the breakpoint should go.
2507
2508 @table @code
2509 @item break @var{function}
2510 Set a breakpoint at entry to function @var{function}.
2511 When using source languages that permit overloading of symbols, such as
2512 C@t{++}, @var{function} may refer to more than one possible place to break.
2513 @xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
2514
2515 @item break +@var{offset}
2516 @itemx break -@var{offset}
2517 Set a breakpoint some number of lines forward or back from the position
2518 at which execution stopped in the currently selected @dfn{stack frame}.
2519 (@xref{Frames, ,Frames}, for a description of stack frames.)
2520
2521 @item break @var{linenum}
2522 Set a breakpoint at line @var{linenum} in the current source file.
2523 The current source file is the last file whose source text was printed.
2524 The breakpoint will stop your program just before it executes any of the
2525 code on that line.
2526
2527 @item break @var{filename}:@var{linenum}
2528 Set a breakpoint at line @var{linenum} in source file @var{filename}.
2529
2530 @item break @var{filename}:@var{function}
2531 Set a breakpoint at entry to function @var{function} found in file
2532 @var{filename}. Specifying a file name as well as a function name is
2533 superfluous except when multiple files contain similarly named
2534 functions.
2535
2536 @item break *@var{address}
2537 Set a breakpoint at address @var{address}. You can use this to set
2538 breakpoints in parts of your program which do not have debugging
2539 information or source files.
2540
2541 @item break
2542 When called without any arguments, @code{break} sets a breakpoint at
2543 the next instruction to be executed in the selected stack frame
2544 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2545 innermost, this makes your program stop as soon as control
2546 returns to that frame. This is similar to the effect of a
2547 @code{finish} command in the frame inside the selected frame---except
2548 that @code{finish} does not leave an active breakpoint. If you use
2549 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2550 the next time it reaches the current location; this may be useful
2551 inside loops.
2552
2553 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2554 least one instruction has been executed. If it did not do this, you
2555 would be unable to proceed past a breakpoint without first disabling the
2556 breakpoint. This rule applies whether or not the breakpoint already
2557 existed when your program stopped.
2558
2559 @item break @dots{} if @var{cond}
2560 Set a breakpoint with condition @var{cond}; evaluate the expression
2561 @var{cond} each time the breakpoint is reached, and stop only if the
2562 value is nonzero---that is, if @var{cond} evaluates as true.
2563 @samp{@dots{}} stands for one of the possible arguments described
2564 above (or no argument) specifying where to break. @xref{Conditions,
2565 ,Break conditions}, for more information on breakpoint conditions.
2566
2567 @kindex tbreak
2568 @item tbreak @var{args}
2569 Set a breakpoint enabled only for one stop. @var{args} are the
2570 same as for the @code{break} command, and the breakpoint is set in the same
2571 way, but the breakpoint is automatically deleted after the first time your
2572 program stops there. @xref{Disabling, ,Disabling breakpoints}.
2573
2574 @kindex hbreak
2575 @cindex hardware breakpoints
2576 @item hbreak @var{args}
2577 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2578 @code{break} command and the breakpoint is set in the same way, but the
2579 breakpoint requires hardware support and some target hardware may not
2580 have this support. The main purpose of this is EPROM/ROM code
2581 debugging, so you can set a breakpoint at an instruction without
2582 changing the instruction. This can be used with the new trap-generation
2583 provided by SPARClite DSU and most x86-based targets. These targets
2584 will generate traps when a program accesses some data or instruction
2585 address that is assigned to the debug registers. However the hardware
2586 breakpoint registers can take a limited number of breakpoints. For
2587 example, on the DSU, only two data breakpoints can be set at a time, and
2588 @value{GDBN} will reject this command if more than two are used. Delete
2589 or disable unused hardware breakpoints before setting new ones
2590 (@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
2591 For remote targets, you can restrict the number of hardware
2592 breakpoints @value{GDBN} will use, see @ref{set remote
2593 hardware-breakpoint-limit}.
2594
2595
2596 @kindex thbreak
2597 @item thbreak @var{args}
2598 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2599 are the same as for the @code{hbreak} command and the breakpoint is set in
2600 the same way. However, like the @code{tbreak} command,
2601 the breakpoint is automatically deleted after the
2602 first time your program stops there. Also, like the @code{hbreak}
2603 command, the breakpoint requires hardware support and some target hardware
2604 may not have this support. @xref{Disabling, ,Disabling breakpoints}.
2605 See also @ref{Conditions, ,Break conditions}.
2606
2607 @kindex rbreak
2608 @cindex regular expression
2609 @item rbreak @var{regex}
2610 Set breakpoints on all functions matching the regular expression
2611 @var{regex}. This command sets an unconditional breakpoint on all
2612 matches, printing a list of all breakpoints it set. Once these
2613 breakpoints are set, they are treated just like the breakpoints set with
2614 the @code{break} command. You can delete them, disable them, or make
2615 them conditional the same way as any other breakpoint.
2616
2617 The syntax of the regular expression is the standard one used with tools
2618 like @file{grep}. Note that this is different from the syntax used by
2619 shells, so for instance @code{foo*} matches all functions that include
2620 an @code{fo} followed by zero or more @code{o}s. There is an implicit
2621 @code{.*} leading and trailing the regular expression you supply, so to
2622 match only functions that begin with @code{foo}, use @code{^foo}.
2623
2624 @cindex non-member C@t{++} functions, set breakpoint in
2625 When debugging C@t{++} programs, @code{rbreak} is useful for setting
2626 breakpoints on overloaded functions that are not members of any special
2627 classes.
2628
2629 @cindex set breakpoints on all functions
2630 The @code{rbreak} command can be used to set breakpoints in
2631 @strong{all} the functions in a program, like this:
2632
2633 @smallexample
2634 (@value{GDBP}) rbreak .
2635 @end smallexample
2636
2637 @kindex info breakpoints
2638 @cindex @code{$_} and @code{info breakpoints}
2639 @item info breakpoints @r{[}@var{n}@r{]}
2640 @itemx info break @r{[}@var{n}@r{]}
2641 @itemx info watchpoints @r{[}@var{n}@r{]}
2642 Print a table of all breakpoints, watchpoints, and catchpoints set and
2643 not deleted, with the following columns for each breakpoint:
2644
2645 @table @emph
2646 @item Breakpoint Numbers
2647 @item Type
2648 Breakpoint, watchpoint, or catchpoint.
2649 @item Disposition
2650 Whether the breakpoint is marked to be disabled or deleted when hit.
2651 @item Enabled or Disabled
2652 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2653 that are not enabled.
2654 @item Address
2655 Where the breakpoint is in your program, as a memory address. If the
2656 breakpoint is pending (see below for details) on a future load of a shared library, the address
2657 will be listed as @samp{<PENDING>}.
2658 @item What
2659 Where the breakpoint is in the source for your program, as a file and
2660 line number. For a pending breakpoint, the original string passed to
2661 the breakpoint command will be listed as it cannot be resolved until
2662 the appropriate shared library is loaded in the future.
2663 @end table
2664
2665 @noindent
2666 If a breakpoint is conditional, @code{info break} shows the condition on
2667 the line following the affected breakpoint; breakpoint commands, if any,
2668 are listed after that. A pending breakpoint is allowed to have a condition
2669 specified for it. The condition is not parsed for validity until a shared
2670 library is loaded that allows the pending breakpoint to resolve to a
2671 valid location.
2672
2673 @noindent
2674 @code{info break} with a breakpoint
2675 number @var{n} as argument lists only that breakpoint. The
2676 convenience variable @code{$_} and the default examining-address for
2677 the @code{x} command are set to the address of the last breakpoint
2678 listed (@pxref{Memory, ,Examining memory}).
2679
2680 @noindent
2681 @code{info break} displays a count of the number of times the breakpoint
2682 has been hit. This is especially useful in conjunction with the
2683 @code{ignore} command. You can ignore a large number of breakpoint
2684 hits, look at the breakpoint info to see how many times the breakpoint
2685 was hit, and then run again, ignoring one less than that number. This
2686 will get you quickly to the last hit of that breakpoint.
2687 @end table
2688
2689 @value{GDBN} allows you to set any number of breakpoints at the same place in
2690 your program. There is nothing silly or meaningless about this. When
2691 the breakpoints are conditional, this is even useful
2692 (@pxref{Conditions, ,Break conditions}).
2693
2694 @cindex pending breakpoints
2695 If a specified breakpoint location cannot be found, it may be due to the fact
2696 that the location is in a shared library that is yet to be loaded. In such
2697 a case, you may want @value{GDBN} to create a special breakpoint (known as
2698 a @dfn{pending breakpoint}) that
2699 attempts to resolve itself in the future when an appropriate shared library
2700 gets loaded.
2701
2702 Pending breakpoints are useful to set at the start of your
2703 @value{GDBN} session for locations that you know will be dynamically loaded
2704 later by the program being debugged. When shared libraries are loaded,
2705 a check is made to see if the load resolves any pending breakpoint locations.
2706 If a pending breakpoint location gets resolved,
2707 a regular breakpoint is created and the original pending breakpoint is removed.
2708
2709 @value{GDBN} provides some additional commands for controlling pending
2710 breakpoint support:
2711
2712 @kindex set breakpoint pending
2713 @kindex show breakpoint pending
2714 @table @code
2715 @item set breakpoint pending auto
2716 This is the default behavior. When @value{GDBN} cannot find the breakpoint
2717 location, it queries you whether a pending breakpoint should be created.
2718
2719 @item set breakpoint pending on
2720 This indicates that an unrecognized breakpoint location should automatically
2721 result in a pending breakpoint being created.
2722
2723 @item set breakpoint pending off
2724 This indicates that pending breakpoints are not to be created. Any
2725 unrecognized breakpoint location results in an error. This setting does
2726 not affect any pending breakpoints previously created.
2727
2728 @item show breakpoint pending
2729 Show the current behavior setting for creating pending breakpoints.
2730 @end table
2731
2732 @cindex operations allowed on pending breakpoints
2733 Normal breakpoint operations apply to pending breakpoints as well. You may
2734 specify a condition for a pending breakpoint and/or commands to run when the
2735 breakpoint is reached. You can also enable or disable
2736 the pending breakpoint. When you specify a condition for a pending breakpoint,
2737 the parsing of the condition will be deferred until the point where the
2738 pending breakpoint location is resolved. Disabling a pending breakpoint
2739 tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2740 shared library load. When a pending breakpoint is re-enabled,
2741 @value{GDBN} checks to see if the location is already resolved.
2742 This is done because any number of shared library loads could have
2743 occurred since the time the breakpoint was disabled and one or more
2744 of these loads could resolve the location.
2745
2746 @cindex negative breakpoint numbers
2747 @cindex internal @value{GDBN} breakpoints
2748 @value{GDBN} itself sometimes sets breakpoints in your program for
2749 special purposes, such as proper handling of @code{longjmp} (in C
2750 programs). These internal breakpoints are assigned negative numbers,
2751 starting with @code{-1}; @samp{info breakpoints} does not display them.
2752 You can see these breakpoints with the @value{GDBN} maintenance command
2753 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
2754
2755
2756 @node Set Watchpoints
2757 @subsection Setting watchpoints
2758
2759 @cindex setting watchpoints
2760 You can use a watchpoint to stop execution whenever the value of an
2761 expression changes, without having to predict a particular place where
2762 this may happen.
2763
2764 @cindex software watchpoints
2765 @cindex hardware watchpoints
2766 Depending on your system, watchpoints may be implemented in software or
2767 hardware. @value{GDBN} does software watchpointing by single-stepping your
2768 program and testing the variable's value each time, which is hundreds of
2769 times slower than normal execution. (But this may still be worth it, to
2770 catch errors where you have no clue what part of your program is the
2771 culprit.)
2772
2773 On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2774 x86-based targets, @value{GDBN} includes support for hardware
2775 watchpoints, which do not slow down the running of your program.
2776
2777 @table @code
2778 @kindex watch
2779 @item watch @var{expr}
2780 Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2781 is written into by the program and its value changes.
2782
2783 @kindex rwatch
2784 @item rwatch @var{expr}
2785 Set a watchpoint that will break when the value of @var{expr} is read
2786 by the program.
2787
2788 @kindex awatch
2789 @item awatch @var{expr}
2790 Set a watchpoint that will break when @var{expr} is either read from
2791 or written into by the program.
2792
2793 @kindex info watchpoints
2794 @item info watchpoints
2795 This command prints a list of watchpoints, breakpoints, and catchpoints;
2796 it is the same as @code{info break} (@pxref{Set Breaks}).
2797 @end table
2798
2799 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2800 watchpoints execute very quickly, and the debugger reports a change in
2801 value at the exact instruction where the change occurs. If @value{GDBN}
2802 cannot set a hardware watchpoint, it sets a software watchpoint, which
2803 executes more slowly and reports the change in value at the next
2804 @emph{statement}, not the instruction, after the change occurs.
2805
2806 @vindex can-use-hw-watchpoints
2807 @cindex use only software watchpoints
2808 You can force @value{GDBN} to use only software watchpoints with the
2809 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2810 zero, @value{GDBN} will never try to use hardware watchpoints, even if
2811 the underlying system supports them. (Note that hardware-assisted
2812 watchpoints that were set @emph{before} setting
2813 @code{can-use-hw-watchpoints} to zero will still use the hardware
2814 mechanism of watching expressiion values.)
2815
2816 @table @code
2817 @item set can-use-hw-watchpoints
2818 @kindex set can-use-hw-watchpoints
2819 Set whether or not to use hardware watchpoints.
2820
2821 @item show can-use-hw-watchpoints
2822 @kindex show can-use-hw-watchpoints
2823 Show the current mode of using hardware watchpoints.
2824 @end table
2825
2826 For remote targets, you can restrict the number of hardware
2827 watchpoints @value{GDBN} will use, see @ref{set remote
2828 hardware-breakpoint-limit}.
2829
2830 When you issue the @code{watch} command, @value{GDBN} reports
2831
2832 @smallexample
2833 Hardware watchpoint @var{num}: @var{expr}
2834 @end smallexample
2835
2836 @noindent
2837 if it was able to set a hardware watchpoint.
2838
2839 Currently, the @code{awatch} and @code{rwatch} commands can only set
2840 hardware watchpoints, because accesses to data that don't change the
2841 value of the watched expression cannot be detected without examining
2842 every instruction as it is being executed, and @value{GDBN} does not do
2843 that currently. If @value{GDBN} finds that it is unable to set a
2844 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2845 will print a message like this:
2846
2847 @smallexample
2848 Expression cannot be implemented with read/access watchpoint.
2849 @end smallexample
2850
2851 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2852 data type of the watched expression is wider than what a hardware
2853 watchpoint on the target machine can handle. For example, some systems
2854 can only watch regions that are up to 4 bytes wide; on such systems you
2855 cannot set hardware watchpoints for an expression that yields a
2856 double-precision floating-point number (which is typically 8 bytes
2857 wide). As a work-around, it might be possible to break the large region
2858 into a series of smaller ones and watch them with separate watchpoints.
2859
2860 If you set too many hardware watchpoints, @value{GDBN} might be unable
2861 to insert all of them when you resume the execution of your program.
2862 Since the precise number of active watchpoints is unknown until such
2863 time as the program is about to be resumed, @value{GDBN} might not be
2864 able to warn you about this when you set the watchpoints, and the
2865 warning will be printed only when the program is resumed:
2866
2867 @smallexample
2868 Hardware watchpoint @var{num}: Could not insert watchpoint
2869 @end smallexample
2870
2871 @noindent
2872 If this happens, delete or disable some of the watchpoints.
2873
2874 The SPARClite DSU will generate traps when a program accesses some data
2875 or instruction address that is assigned to the debug registers. For the
2876 data addresses, DSU facilitates the @code{watch} command. However the
2877 hardware breakpoint registers can only take two data watchpoints, and
2878 both watchpoints must be the same kind. For example, you can set two
2879 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2880 @strong{or} two with @code{awatch} commands, but you cannot set one
2881 watchpoint with one command and the other with a different command.
2882 @value{GDBN} will reject the command if you try to mix watchpoints.
2883 Delete or disable unused watchpoint commands before setting new ones.
2884
2885 If you call a function interactively using @code{print} or @code{call},
2886 any watchpoints you have set will be inactive until @value{GDBN} reaches another
2887 kind of breakpoint or the call completes.
2888
2889 @value{GDBN} automatically deletes watchpoints that watch local
2890 (automatic) variables, or expressions that involve such variables, when
2891 they go out of scope, that is, when the execution leaves the block in
2892 which these variables were defined. In particular, when the program
2893 being debugged terminates, @emph{all} local variables go out of scope,
2894 and so only watchpoints that watch global variables remain set. If you
2895 rerun the program, you will need to set all such watchpoints again. One
2896 way of doing that would be to set a code breakpoint at the entry to the
2897 @code{main} function and when it breaks, set all the watchpoints.
2898
2899 @quotation
2900 @cindex watchpoints and threads
2901 @cindex threads and watchpoints
2902 @emph{Warning:} In multi-thread programs, watchpoints have only limited
2903 usefulness. With the current watchpoint implementation, @value{GDBN}
2904 can only watch the value of an expression @emph{in a single thread}. If
2905 you are confident that the expression can only change due to the current
2906 thread's activity (and if you are also confident that no other thread
2907 can become current), then you can use watchpoints as usual. However,
2908 @value{GDBN} may not notice when a non-current thread's activity changes
2909 the expression.
2910
2911 @c FIXME: this is almost identical to the previous paragraph.
2912 @emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2913 have only limited usefulness. If @value{GDBN} creates a software
2914 watchpoint, it can only watch the value of an expression @emph{in a
2915 single thread}. If you are confident that the expression can only
2916 change due to the current thread's activity (and if you are also
2917 confident that no other thread can become current), then you can use
2918 software watchpoints as usual. However, @value{GDBN} may not notice
2919 when a non-current thread's activity changes the expression. (Hardware
2920 watchpoints, in contrast, watch an expression in all threads.)
2921 @end quotation
2922
2923 @xref{set remote hardware-watchpoint-limit}.
2924
2925 @node Set Catchpoints
2926 @subsection Setting catchpoints
2927 @cindex catchpoints, setting
2928 @cindex exception handlers
2929 @cindex event handling
2930
2931 You can use @dfn{catchpoints} to cause the debugger to stop for certain
2932 kinds of program events, such as C@t{++} exceptions or the loading of a
2933 shared library. Use the @code{catch} command to set a catchpoint.
2934
2935 @table @code
2936 @kindex catch
2937 @item catch @var{event}
2938 Stop when @var{event} occurs. @var{event} can be any of the following:
2939 @table @code
2940 @item throw
2941 @cindex stop on C@t{++} exceptions
2942 The throwing of a C@t{++} exception.
2943
2944 @item catch
2945 The catching of a C@t{++} exception.
2946
2947 @item exec
2948 @cindex break on fork/exec
2949 A call to @code{exec}. This is currently only available for HP-UX.
2950
2951 @item fork
2952 A call to @code{fork}. This is currently only available for HP-UX.
2953
2954 @item vfork
2955 A call to @code{vfork}. This is currently only available for HP-UX.
2956
2957 @item load
2958 @itemx load @var{libname}
2959 @cindex break on load/unload of shared library
2960 The dynamic loading of any shared library, or the loading of the library
2961 @var{libname}. This is currently only available for HP-UX.
2962
2963 @item unload
2964 @itemx unload @var{libname}
2965 The unloading of any dynamically loaded shared library, or the unloading
2966 of the library @var{libname}. This is currently only available for HP-UX.
2967 @end table
2968
2969 @item tcatch @var{event}
2970 Set a catchpoint that is enabled only for one stop. The catchpoint is
2971 automatically deleted after the first time the event is caught.
2972
2973 @end table
2974
2975 Use the @code{info break} command to list the current catchpoints.
2976
2977 There are currently some limitations to C@t{++} exception handling
2978 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2979
2980 @itemize @bullet
2981 @item
2982 If you call a function interactively, @value{GDBN} normally returns
2983 control to you when the function has finished executing. If the call
2984 raises an exception, however, the call may bypass the mechanism that
2985 returns control to you and cause your program either to abort or to
2986 simply continue running until it hits a breakpoint, catches a signal
2987 that @value{GDBN} is listening for, or exits. This is the case even if
2988 you set a catchpoint for the exception; catchpoints on exceptions are
2989 disabled within interactive calls.
2990
2991 @item
2992 You cannot raise an exception interactively.
2993
2994 @item
2995 You cannot install an exception handler interactively.
2996 @end itemize
2997
2998 @cindex raise exceptions
2999 Sometimes @code{catch} is not the best way to debug exception handling:
3000 if you need to know exactly where an exception is raised, it is better to
3001 stop @emph{before} the exception handler is called, since that way you
3002 can see the stack before any unwinding takes place. If you set a
3003 breakpoint in an exception handler instead, it may not be easy to find
3004 out where the exception was raised.
3005
3006 To stop just before an exception handler is called, you need some
3007 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
3008 raised by calling a library function named @code{__raise_exception}
3009 which has the following ANSI C interface:
3010
3011 @smallexample
3012 /* @var{addr} is where the exception identifier is stored.
3013 @var{id} is the exception identifier. */
3014 void __raise_exception (void **addr, void *id);
3015 @end smallexample
3016
3017 @noindent
3018 To make the debugger catch all exceptions before any stack
3019 unwinding takes place, set a breakpoint on @code{__raise_exception}
3020 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3021
3022 With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3023 that depends on the value of @var{id}, you can stop your program when
3024 a specific exception is raised. You can use multiple conditional
3025 breakpoints to stop your program when any of a number of exceptions are
3026 raised.
3027
3028
3029 @node Delete Breaks
3030 @subsection Deleting breakpoints
3031
3032 @cindex clearing breakpoints, watchpoints, catchpoints
3033 @cindex deleting breakpoints, watchpoints, catchpoints
3034 It is often necessary to eliminate a breakpoint, watchpoint, or
3035 catchpoint once it has done its job and you no longer want your program
3036 to stop there. This is called @dfn{deleting} the breakpoint. A
3037 breakpoint that has been deleted no longer exists; it is forgotten.
3038
3039 With the @code{clear} command you can delete breakpoints according to
3040 where they are in your program. With the @code{delete} command you can
3041 delete individual breakpoints, watchpoints, or catchpoints by specifying
3042 their breakpoint numbers.
3043
3044 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3045 automatically ignores breakpoints on the first instruction to be executed
3046 when you continue execution without changing the execution address.
3047
3048 @table @code
3049 @kindex clear
3050 @item clear
3051 Delete any breakpoints at the next instruction to be executed in the
3052 selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3053 the innermost frame is selected, this is a good way to delete a
3054 breakpoint where your program just stopped.
3055
3056 @item clear @var{function}
3057 @itemx clear @var{filename}:@var{function}
3058 Delete any breakpoints set at entry to the named @var{function}.
3059
3060 @item clear @var{linenum}
3061 @itemx clear @var{filename}:@var{linenum}
3062 Delete any breakpoints set at or within the code of the specified
3063 @var{linenum} of the specified @var{filename}.
3064
3065 @cindex delete breakpoints
3066 @kindex delete
3067 @kindex d @r{(@code{delete})}
3068 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3069 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3070 ranges specified as arguments. If no argument is specified, delete all
3071 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3072 confirm off}). You can abbreviate this command as @code{d}.
3073 @end table
3074
3075 @node Disabling
3076 @subsection Disabling breakpoints
3077
3078 @cindex enable/disable a breakpoint
3079 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3080 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3081 it had been deleted, but remembers the information on the breakpoint so
3082 that you can @dfn{enable} it again later.
3083
3084 You disable and enable breakpoints, watchpoints, and catchpoints with
3085 the @code{enable} and @code{disable} commands, optionally specifying one
3086 or more breakpoint numbers as arguments. Use @code{info break} or
3087 @code{info watch} to print a list of breakpoints, watchpoints, and
3088 catchpoints if you do not know which numbers to use.
3089
3090 A breakpoint, watchpoint, or catchpoint can have any of four different
3091 states of enablement:
3092
3093 @itemize @bullet
3094 @item
3095 Enabled. The breakpoint stops your program. A breakpoint set
3096 with the @code{break} command starts out in this state.
3097 @item
3098 Disabled. The breakpoint has no effect on your program.
3099 @item
3100 Enabled once. The breakpoint stops your program, but then becomes
3101 disabled.
3102 @item
3103 Enabled for deletion. The breakpoint stops your program, but
3104 immediately after it does so it is deleted permanently. A breakpoint
3105 set with the @code{tbreak} command starts out in this state.
3106 @end itemize
3107
3108 You can use the following commands to enable or disable breakpoints,
3109 watchpoints, and catchpoints:
3110
3111 @table @code
3112 @kindex disable
3113 @kindex dis @r{(@code{disable})}
3114 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3115 Disable the specified breakpoints---or all breakpoints, if none are
3116 listed. A disabled breakpoint has no effect but is not forgotten. All
3117 options such as ignore-counts, conditions and commands are remembered in
3118 case the breakpoint is enabled again later. You may abbreviate
3119 @code{disable} as @code{dis}.
3120
3121 @kindex enable
3122 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3123 Enable the specified breakpoints (or all defined breakpoints). They
3124 become effective once again in stopping your program.
3125
3126 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
3127 Enable the specified breakpoints temporarily. @value{GDBN} disables any
3128 of these breakpoints immediately after stopping your program.
3129
3130 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
3131 Enable the specified breakpoints to work once, then die. @value{GDBN}
3132 deletes any of these breakpoints as soon as your program stops there.
3133 Breakpoints set by the @code{tbreak} command start out in this state.
3134 @end table
3135
3136 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3137 @c confusing: tbreak is also initially enabled.
3138 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3139 ,Setting breakpoints}), breakpoints that you set are initially enabled;
3140 subsequently, they become disabled or enabled only when you use one of
3141 the commands above. (The command @code{until} can set and delete a
3142 breakpoint of its own, but it does not change the state of your other
3143 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3144 stepping}.)
3145
3146 @node Conditions
3147 @subsection Break conditions
3148 @cindex conditional breakpoints
3149 @cindex breakpoint conditions
3150
3151 @c FIXME what is scope of break condition expr? Context where wanted?
3152 @c in particular for a watchpoint?
3153 The simplest sort of breakpoint breaks every time your program reaches a
3154 specified place. You can also specify a @dfn{condition} for a
3155 breakpoint. A condition is just a Boolean expression in your
3156 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3157 a condition evaluates the expression each time your program reaches it,
3158 and your program stops only if the condition is @emph{true}.
3159
3160 This is the converse of using assertions for program validation; in that
3161 situation, you want to stop when the assertion is violated---that is,
3162 when the condition is false. In C, if you want to test an assertion expressed
3163 by the condition @var{assert}, you should set the condition
3164 @samp{! @var{assert}} on the appropriate breakpoint.
3165
3166 Conditions are also accepted for watchpoints; you may not need them,
3167 since a watchpoint is inspecting the value of an expression anyhow---but
3168 it might be simpler, say, to just set a watchpoint on a variable name,
3169 and specify a condition that tests whether the new value is an interesting
3170 one.
3171
3172 Break conditions can have side effects, and may even call functions in
3173 your program. This can be useful, for example, to activate functions
3174 that log program progress, or to use your own print functions to
3175 format special data structures. The effects are completely predictable
3176 unless there is another enabled breakpoint at the same address. (In
3177 that case, @value{GDBN} might see the other breakpoint first and stop your
3178 program without checking the condition of this one.) Note that
3179 breakpoint commands are usually more convenient and flexible than break
3180 conditions for the
3181 purpose of performing side effects when a breakpoint is reached
3182 (@pxref{Break Commands, ,Breakpoint command lists}).
3183
3184 Break conditions can be specified when a breakpoint is set, by using
3185 @samp{if} in the arguments to the @code{break} command. @xref{Set
3186 Breaks, ,Setting breakpoints}. They can also be changed at any time
3187 with the @code{condition} command.
3188
3189 You can also use the @code{if} keyword with the @code{watch} command.
3190 The @code{catch} command does not recognize the @code{if} keyword;
3191 @code{condition} is the only way to impose a further condition on a
3192 catchpoint.
3193
3194 @table @code
3195 @kindex condition
3196 @item condition @var{bnum} @var{expression}
3197 Specify @var{expression} as the break condition for breakpoint,
3198 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3199 breakpoint @var{bnum} stops your program only if the value of
3200 @var{expression} is true (nonzero, in C). When you use
3201 @code{condition}, @value{GDBN} checks @var{expression} immediately for
3202 syntactic correctness, and to determine whether symbols in it have
3203 referents in the context of your breakpoint. If @var{expression} uses
3204 symbols not referenced in the context of the breakpoint, @value{GDBN}
3205 prints an error message:
3206
3207 @smallexample
3208 No symbol "foo" in current context.
3209 @end smallexample
3210
3211 @noindent
3212 @value{GDBN} does
3213 not actually evaluate @var{expression} at the time the @code{condition}
3214 command (or a command that sets a breakpoint with a condition, like
3215 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
3216
3217 @item condition @var{bnum}
3218 Remove the condition from breakpoint number @var{bnum}. It becomes
3219 an ordinary unconditional breakpoint.
3220 @end table
3221
3222 @cindex ignore count (of breakpoint)
3223 A special case of a breakpoint condition is to stop only when the
3224 breakpoint has been reached a certain number of times. This is so
3225 useful that there is a special way to do it, using the @dfn{ignore
3226 count} of the breakpoint. Every breakpoint has an ignore count, which
3227 is an integer. Most of the time, the ignore count is zero, and
3228 therefore has no effect. But if your program reaches a breakpoint whose
3229 ignore count is positive, then instead of stopping, it just decrements
3230 the ignore count by one and continues. As a result, if the ignore count
3231 value is @var{n}, the breakpoint does not stop the next @var{n} times
3232 your program reaches it.
3233
3234 @table @code
3235 @kindex ignore
3236 @item ignore @var{bnum} @var{count}
3237 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3238 The next @var{count} times the breakpoint is reached, your program's
3239 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3240 takes no action.
3241
3242 To make the breakpoint stop the next time it is reached, specify
3243 a count of zero.
3244
3245 When you use @code{continue} to resume execution of your program from a
3246 breakpoint, you can specify an ignore count directly as an argument to
3247 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3248 Stepping,,Continuing and stepping}.
3249
3250 If a breakpoint has a positive ignore count and a condition, the
3251 condition is not checked. Once the ignore count reaches zero,
3252 @value{GDBN} resumes checking the condition.
3253
3254 You could achieve the effect of the ignore count with a condition such
3255 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3256 is decremented each time. @xref{Convenience Vars, ,Convenience
3257 variables}.
3258 @end table
3259
3260 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3261
3262
3263 @node Break Commands
3264 @subsection Breakpoint command lists
3265
3266 @cindex breakpoint commands
3267 You can give any breakpoint (or watchpoint or catchpoint) a series of
3268 commands to execute when your program stops due to that breakpoint. For
3269 example, you might want to print the values of certain expressions, or
3270 enable other breakpoints.
3271
3272 @table @code
3273 @kindex commands
3274 @kindex end
3275 @item commands @r{[}@var{bnum}@r{]}
3276 @itemx @dots{} @var{command-list} @dots{}
3277 @itemx end
3278 Specify a list of commands for breakpoint number @var{bnum}. The commands
3279 themselves appear on the following lines. Type a line containing just
3280 @code{end} to terminate the commands.
3281
3282 To remove all commands from a breakpoint, type @code{commands} and
3283 follow it immediately with @code{end}; that is, give no commands.
3284
3285 With no @var{bnum} argument, @code{commands} refers to the last
3286 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3287 recently encountered).
3288 @end table
3289
3290 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3291 disabled within a @var{command-list}.
3292
3293 You can use breakpoint commands to start your program up again. Simply
3294 use the @code{continue} command, or @code{step}, or any other command
3295 that resumes execution.
3296
3297 Any other commands in the command list, after a command that resumes
3298 execution, are ignored. This is because any time you resume execution
3299 (even with a simple @code{next} or @code{step}), you may encounter
3300 another breakpoint---which could have its own command list, leading to
3301 ambiguities about which list to execute.
3302
3303 @kindex silent
3304 If the first command you specify in a command list is @code{silent}, the
3305 usual message about stopping at a breakpoint is not printed. This may
3306 be desirable for breakpoints that are to print a specific message and
3307 then continue. If none of the remaining commands print anything, you
3308 see no sign that the breakpoint was reached. @code{silent} is
3309 meaningful only at the beginning of a breakpoint command list.
3310
3311 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3312 print precisely controlled output, and are often useful in silent
3313 breakpoints. @xref{Output, ,Commands for controlled output}.
3314
3315 For example, here is how you could use breakpoint commands to print the
3316 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3317
3318 @smallexample
3319 break foo if x>0
3320 commands
3321 silent
3322 printf "x is %d\n",x
3323 cont
3324 end
3325 @end smallexample
3326
3327 One application for breakpoint commands is to compensate for one bug so
3328 you can test for another. Put a breakpoint just after the erroneous line
3329 of code, give it a condition to detect the case in which something
3330 erroneous has been done, and give it commands to assign correct values
3331 to any variables that need them. End with the @code{continue} command
3332 so that your program does not stop, and start with the @code{silent}
3333 command so that no output is produced. Here is an example:
3334
3335 @smallexample
3336 break 403
3337 commands
3338 silent
3339 set x = y + 4
3340 cont
3341 end
3342 @end smallexample
3343
3344 @node Breakpoint Menus
3345 @subsection Breakpoint menus
3346 @cindex overloading
3347 @cindex symbol overloading
3348
3349 Some programming languages (notably C@t{++} and Objective-C) permit a
3350 single function name
3351 to be defined several times, for application in different contexts.
3352 This is called @dfn{overloading}. When a function name is overloaded,
3353 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3354 a breakpoint. If you realize this is a problem, you can use
3355 something like @samp{break @var{function}(@var{types})} to specify which
3356 particular version of the function you want. Otherwise, @value{GDBN} offers
3357 you a menu of numbered choices for different possible breakpoints, and
3358 waits for your selection with the prompt @samp{>}. The first two
3359 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3360 sets a breakpoint at each definition of @var{function}, and typing
3361 @kbd{0} aborts the @code{break} command without setting any new
3362 breakpoints.
3363
3364 For example, the following session excerpt shows an attempt to set a
3365 breakpoint at the overloaded symbol @code{String::after}.
3366 We choose three particular definitions of that function name:
3367
3368 @c FIXME! This is likely to change to show arg type lists, at least
3369 @smallexample
3370 @group
3371 (@value{GDBP}) b String::after
3372 [0] cancel
3373 [1] all
3374 [2] file:String.cc; line number:867
3375 [3] file:String.cc; line number:860
3376 [4] file:String.cc; line number:875
3377 [5] file:String.cc; line number:853
3378 [6] file:String.cc; line number:846
3379 [7] file:String.cc; line number:735
3380 > 2 4 6
3381 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3382 Breakpoint 2 at 0xb344: file String.cc, line 875.
3383 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3384 Multiple breakpoints were set.
3385 Use the "delete" command to delete unwanted
3386 breakpoints.
3387 (@value{GDBP})
3388 @end group
3389 @end smallexample
3390
3391 @c @ifclear BARETARGET
3392 @node Error in Breakpoints
3393 @subsection ``Cannot insert breakpoints''
3394 @c
3395 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3396 @c
3397 Under some operating systems, breakpoints cannot be used in a program if
3398 any other process is running that program. In this situation,
3399 attempting to run or continue a program with a breakpoint causes
3400 @value{GDBN} to print an error message:
3401
3402 @smallexample
3403 Cannot insert breakpoints.
3404 The same program may be running in another process.
3405 @end smallexample
3406
3407 When this happens, you have three ways to proceed:
3408
3409 @enumerate
3410 @item
3411 Remove or disable the breakpoints, then continue.
3412
3413 @item
3414 Suspend @value{GDBN}, and copy the file containing your program to a new
3415 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3416 that @value{GDBN} should run your program under that name.
3417 Then start your program again.
3418
3419 @item
3420 Relink your program so that the text segment is nonsharable, using the
3421 linker option @samp{-N}. The operating system limitation may not apply
3422 to nonsharable executables.
3423 @end enumerate
3424 @c @end ifclear
3425
3426 A similar message can be printed if you request too many active
3427 hardware-assisted breakpoints and watchpoints:
3428
3429 @c FIXME: the precise wording of this message may change; the relevant
3430 @c source change is not committed yet (Sep 3, 1999).
3431 @smallexample
3432 Stopped; cannot insert breakpoints.
3433 You may have requested too many hardware breakpoints and watchpoints.
3434 @end smallexample
3435
3436 @noindent
3437 This message is printed when you attempt to resume the program, since
3438 only then @value{GDBN} knows exactly how many hardware breakpoints and
3439 watchpoints it needs to insert.
3440
3441 When this message is printed, you need to disable or remove some of the
3442 hardware-assisted breakpoints and watchpoints, and then continue.
3443
3444 @node Breakpoint related warnings
3445 @subsection ``Breakpoint address adjusted...''
3446 @cindex breakpoint address adjusted
3447
3448 Some processor architectures place constraints on the addresses at
3449 which breakpoints may be placed. For architectures thus constrained,
3450 @value{GDBN} will attempt to adjust the breakpoint's address to comply
3451 with the constraints dictated by the architecture.
3452
3453 One example of such an architecture is the Fujitsu FR-V. The FR-V is
3454 a VLIW architecture in which a number of RISC-like instructions may be
3455 bundled together for parallel execution. The FR-V architecture
3456 constrains the location of a breakpoint instruction within such a
3457 bundle to the instruction with the lowest address. @value{GDBN}
3458 honors this constraint by adjusting a breakpoint's address to the
3459 first in the bundle.
3460
3461 It is not uncommon for optimized code to have bundles which contain
3462 instructions from different source statements, thus it may happen that
3463 a breakpoint's address will be adjusted from one source statement to
3464 another. Since this adjustment may significantly alter @value{GDBN}'s
3465 breakpoint related behavior from what the user expects, a warning is
3466 printed when the breakpoint is first set and also when the breakpoint
3467 is hit.
3468
3469 A warning like the one below is printed when setting a breakpoint
3470 that's been subject to address adjustment:
3471
3472 @smallexample
3473 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3474 @end smallexample
3475
3476 Such warnings are printed both for user settable and @value{GDBN}'s
3477 internal breakpoints. If you see one of these warnings, you should
3478 verify that a breakpoint set at the adjusted address will have the
3479 desired affect. If not, the breakpoint in question may be removed and
3480 other breakpoints may be set which will have the desired behavior.
3481 E.g., it may be sufficient to place the breakpoint at a later
3482 instruction. A conditional breakpoint may also be useful in some
3483 cases to prevent the breakpoint from triggering too often.
3484
3485 @value{GDBN} will also issue a warning when stopping at one of these
3486 adjusted breakpoints:
3487
3488 @smallexample
3489 warning: Breakpoint 1 address previously adjusted from 0x00010414
3490 to 0x00010410.
3491 @end smallexample
3492
3493 When this warning is encountered, it may be too late to take remedial
3494 action except in cases where the breakpoint is hit earlier or more
3495 frequently than expected.
3496
3497 @node Continuing and Stepping
3498 @section Continuing and stepping
3499
3500 @cindex stepping
3501 @cindex continuing
3502 @cindex resuming execution
3503 @dfn{Continuing} means resuming program execution until your program
3504 completes normally. In contrast, @dfn{stepping} means executing just
3505 one more ``step'' of your program, where ``step'' may mean either one
3506 line of source code, or one machine instruction (depending on what
3507 particular command you use). Either when continuing or when stepping,
3508 your program may stop even sooner, due to a breakpoint or a signal. (If
3509 it stops due to a signal, you may want to use @code{handle}, or use
3510 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
3511
3512 @table @code
3513 @kindex continue
3514 @kindex c @r{(@code{continue})}
3515 @kindex fg @r{(resume foreground execution)}
3516 @item continue @r{[}@var{ignore-count}@r{]}
3517 @itemx c @r{[}@var{ignore-count}@r{]}
3518 @itemx fg @r{[}@var{ignore-count}@r{]}
3519 Resume program execution, at the address where your program last stopped;
3520 any breakpoints set at that address are bypassed. The optional argument
3521 @var{ignore-count} allows you to specify a further number of times to
3522 ignore a breakpoint at this location; its effect is like that of
3523 @code{ignore} (@pxref{Conditions, ,Break conditions}).
3524
3525 The argument @var{ignore-count} is meaningful only when your program
3526 stopped due to a breakpoint. At other times, the argument to
3527 @code{continue} is ignored.
3528
3529 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3530 debugged program is deemed to be the foreground program) are provided
3531 purely for convenience, and have exactly the same behavior as
3532 @code{continue}.
3533 @end table
3534
3535 To resume execution at a different place, you can use @code{return}
3536 (@pxref{Returning, ,Returning from a function}) to go back to the
3537 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3538 different address}) to go to an arbitrary location in your program.
3539
3540 A typical technique for using stepping is to set a breakpoint
3541 (@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3542 beginning of the function or the section of your program where a problem
3543 is believed to lie, run your program until it stops at that breakpoint,
3544 and then step through the suspect area, examining the variables that are
3545 interesting, until you see the problem happen.
3546
3547 @table @code
3548 @kindex step
3549 @kindex s @r{(@code{step})}
3550 @item step
3551 Continue running your program until control reaches a different source
3552 line, then stop it and return control to @value{GDBN}. This command is
3553 abbreviated @code{s}.
3554
3555 @quotation
3556 @c "without debugging information" is imprecise; actually "without line
3557 @c numbers in the debugging information". (gcc -g1 has debugging info but
3558 @c not line numbers). But it seems complex to try to make that
3559 @c distinction here.
3560 @emph{Warning:} If you use the @code{step} command while control is
3561 within a function that was compiled without debugging information,
3562 execution proceeds until control reaches a function that does have
3563 debugging information. Likewise, it will not step into a function which
3564 is compiled without debugging information. To step through functions
3565 without debugging information, use the @code{stepi} command, described
3566 below.
3567 @end quotation
3568
3569 The @code{step} command only stops at the first instruction of a source
3570 line. This prevents the multiple stops that could otherwise occur in
3571 @code{switch} statements, @code{for} loops, etc. @code{step} continues
3572 to stop if a function that has debugging information is called within
3573 the line. In other words, @code{step} @emph{steps inside} any functions
3574 called within the line.
3575
3576 Also, the @code{step} command only enters a function if there is line
3577 number information for the function. Otherwise it acts like the
3578 @code{next} command. This avoids problems when using @code{cc -gl}
3579 on MIPS machines. Previously, @code{step} entered subroutines if there
3580 was any debugging information about the routine.
3581
3582 @item step @var{count}
3583 Continue running as in @code{step}, but do so @var{count} times. If a
3584 breakpoint is reached, or a signal not related to stepping occurs before
3585 @var{count} steps, stepping stops right away.
3586
3587 @kindex next
3588 @kindex n @r{(@code{next})}
3589 @item next @r{[}@var{count}@r{]}
3590 Continue to the next source line in the current (innermost) stack frame.
3591 This is similar to @code{step}, but function calls that appear within
3592 the line of code are executed without stopping. Execution stops when
3593 control reaches a different line of code at the original stack level
3594 that was executing when you gave the @code{next} command. This command
3595 is abbreviated @code{n}.
3596
3597 An argument @var{count} is a repeat count, as for @code{step}.
3598
3599
3600 @c FIX ME!! Do we delete this, or is there a way it fits in with
3601 @c the following paragraph? --- Vctoria
3602 @c
3603 @c @code{next} within a function that lacks debugging information acts like
3604 @c @code{step}, but any function calls appearing within the code of the
3605 @c function are executed without stopping.
3606
3607 The @code{next} command only stops at the first instruction of a
3608 source line. This prevents multiple stops that could otherwise occur in
3609 @code{switch} statements, @code{for} loops, etc.
3610
3611 @kindex set step-mode
3612 @item set step-mode
3613 @cindex functions without line info, and stepping
3614 @cindex stepping into functions with no line info
3615 @itemx set step-mode on
3616 The @code{set step-mode on} command causes the @code{step} command to
3617 stop at the first instruction of a function which contains no debug line
3618 information rather than stepping over it.
3619
3620 This is useful in cases where you may be interested in inspecting the
3621 machine instructions of a function which has no symbolic info and do not
3622 want @value{GDBN} to automatically skip over this function.
3623
3624 @item set step-mode off
3625 Causes the @code{step} command to step over any functions which contains no
3626 debug information. This is the default.
3627
3628 @item show step-mode
3629 Show whether @value{GDBN} will stop in or step over functions without
3630 source line debug information.
3631
3632 @kindex finish
3633 @item finish
3634 Continue running until just after function in the selected stack frame
3635 returns. Print the returned value (if any).
3636
3637 Contrast this with the @code{return} command (@pxref{Returning,
3638 ,Returning from a function}).
3639
3640 @kindex until
3641 @kindex u @r{(@code{until})}
3642 @cindex run until specified location
3643 @item until
3644 @itemx u
3645 Continue running until a source line past the current line, in the
3646 current stack frame, is reached. This command is used to avoid single
3647 stepping through a loop more than once. It is like the @code{next}
3648 command, except that when @code{until} encounters a jump, it
3649 automatically continues execution until the program counter is greater
3650 than the address of the jump.
3651
3652 This means that when you reach the end of a loop after single stepping
3653 though it, @code{until} makes your program continue execution until it
3654 exits the loop. In contrast, a @code{next} command at the end of a loop
3655 simply steps back to the beginning of the loop, which forces you to step
3656 through the next iteration.
3657
3658 @code{until} always stops your program if it attempts to exit the current
3659 stack frame.
3660
3661 @code{until} may produce somewhat counterintuitive results if the order
3662 of machine code does not match the order of the source lines. For
3663 example, in the following excerpt from a debugging session, the @code{f}
3664 (@code{frame}) command shows that execution is stopped at line
3665 @code{206}; yet when we use @code{until}, we get to line @code{195}:
3666
3667 @smallexample
3668 (@value{GDBP}) f
3669 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3670 206 expand_input();
3671 (@value{GDBP}) until
3672 195 for ( ; argc > 0; NEXTARG) @{
3673 @end smallexample
3674
3675 This happened because, for execution efficiency, the compiler had
3676 generated code for the loop closure test at the end, rather than the
3677 start, of the loop---even though the test in a C @code{for}-loop is
3678 written before the body of the loop. The @code{until} command appeared
3679 to step back to the beginning of the loop when it advanced to this
3680 expression; however, it has not really gone to an earlier
3681 statement---not in terms of the actual machine code.
3682
3683 @code{until} with no argument works by means of single
3684 instruction stepping, and hence is slower than @code{until} with an
3685 argument.
3686
3687 @item until @var{location}
3688 @itemx u @var{location}
3689 Continue running your program until either the specified location is
3690 reached, or the current stack frame returns. @var{location} is any of
3691 the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
3692 ,Setting breakpoints}). This form of the command uses breakpoints, and
3693 hence is quicker than @code{until} without an argument. The specified
3694 location is actually reached only if it is in the current frame. This
3695 implies that @code{until} can be used to skip over recursive function
3696 invocations. For instance in the code below, if the current location is
3697 line @code{96}, issuing @code{until 99} will execute the program up to
3698 line @code{99} in the same invocation of factorial, i.e. after the inner
3699 invocations have returned.
3700
3701 @smallexample
3702 94 int factorial (int value)
3703 95 @{
3704 96 if (value > 1) @{
3705 97 value *= factorial (value - 1);
3706 98 @}
3707 99 return (value);
3708 100 @}
3709 @end smallexample
3710
3711
3712 @kindex advance @var{location}
3713 @itemx advance @var{location}
3714 Continue running the program up to the given @var{location}. An argument is
3715 required, which should be of the same form as arguments for the @code{break}
3716 command. Execution will also stop upon exit from the current stack
3717 frame. This command is similar to @code{until}, but @code{advance} will
3718 not skip over recursive function calls, and the target location doesn't
3719 have to be in the same frame as the current one.
3720
3721
3722 @kindex stepi
3723 @kindex si @r{(@code{stepi})}
3724 @item stepi
3725 @itemx stepi @var{arg}
3726 @itemx si
3727 Execute one machine instruction, then stop and return to the debugger.
3728
3729 It is often useful to do @samp{display/i $pc} when stepping by machine
3730 instructions. This makes @value{GDBN} automatically display the next
3731 instruction to be executed, each time your program stops. @xref{Auto
3732 Display,, Automatic display}.
3733
3734 An argument is a repeat count, as in @code{step}.
3735
3736 @need 750
3737 @kindex nexti
3738 @kindex ni @r{(@code{nexti})}
3739 @item nexti
3740 @itemx nexti @var{arg}
3741 @itemx ni
3742 Execute one machine instruction, but if it is a function call,
3743 proceed until the function returns.
3744
3745 An argument is a repeat count, as in @code{next}.
3746 @end table
3747
3748 @node Signals
3749 @section Signals
3750 @cindex signals
3751
3752 A signal is an asynchronous event that can happen in a program. The
3753 operating system defines the possible kinds of signals, and gives each
3754 kind a name and a number. For example, in Unix @code{SIGINT} is the
3755 signal a program gets when you type an interrupt character (often @kbd{C-c});
3756 @code{SIGSEGV} is the signal a program gets from referencing a place in
3757 memory far away from all the areas in use; @code{SIGALRM} occurs when
3758 the alarm clock timer goes off (which happens only if your program has
3759 requested an alarm).
3760
3761 @cindex fatal signals
3762 Some signals, including @code{SIGALRM}, are a normal part of the
3763 functioning of your program. Others, such as @code{SIGSEGV}, indicate
3764 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
3765 program has not specified in advance some other way to handle the signal.
3766 @code{SIGINT} does not indicate an error in your program, but it is normally
3767 fatal so it can carry out the purpose of the interrupt: to kill the program.
3768
3769 @value{GDBN} has the ability to detect any occurrence of a signal in your
3770 program. You can tell @value{GDBN} in advance what to do for each kind of
3771 signal.
3772
3773 @cindex handling signals
3774 Normally, @value{GDBN} is set up to let the non-erroneous signals like
3775 @code{SIGALRM} be silently passed to your program
3776 (so as not to interfere with their role in the program's functioning)
3777 but to stop your program immediately whenever an error signal happens.
3778 You can change these settings with the @code{handle} command.
3779
3780 @table @code
3781 @kindex info signals
3782 @kindex info handle
3783 @item info signals
3784 @itemx info handle
3785 Print a table of all the kinds of signals and how @value{GDBN} has been told to
3786 handle each one. You can use this to see the signal numbers of all
3787 the defined types of signals.
3788
3789 @code{info handle} is an alias for @code{info signals}.
3790
3791 @kindex handle
3792 @item handle @var{signal} @var{keywords}@dots{}
3793 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3794 can be the number of a signal or its name (with or without the
3795 @samp{SIG} at the beginning); a list of signal numbers of the form
3796 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3797 known signals. The @var{keywords} say what change to make.
3798 @end table
3799
3800 @c @group
3801 The keywords allowed by the @code{handle} command can be abbreviated.
3802 Their full names are:
3803
3804 @table @code
3805 @item nostop
3806 @value{GDBN} should not stop your program when this signal happens. It may
3807 still print a message telling you that the signal has come in.
3808
3809 @item stop
3810 @value{GDBN} should stop your program when this signal happens. This implies
3811 the @code{print} keyword as well.
3812
3813 @item print
3814 @value{GDBN} should print a message when this signal happens.
3815
3816 @item noprint
3817 @value{GDBN} should not mention the occurrence of the signal at all. This
3818 implies the @code{nostop} keyword as well.
3819
3820 @item pass
3821 @itemx noignore
3822 @value{GDBN} should allow your program to see this signal; your program
3823 can handle the signal, or else it may terminate if the signal is fatal
3824 and not handled. @code{pass} and @code{noignore} are synonyms.
3825
3826 @item nopass
3827 @itemx ignore
3828 @value{GDBN} should not allow your program to see this signal.
3829 @code{nopass} and @code{ignore} are synonyms.
3830 @end table
3831 @c @end group
3832
3833 When a signal stops your program, the signal is not visible to the
3834 program until you
3835 continue. Your program sees the signal then, if @code{pass} is in
3836 effect for the signal in question @emph{at that time}. In other words,
3837 after @value{GDBN} reports a signal, you can use the @code{handle}
3838 command with @code{pass} or @code{nopass} to control whether your
3839 program sees that signal when you continue.
3840
3841 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3842 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3843 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3844 erroneous signals.
3845
3846 You can also use the @code{signal} command to prevent your program from
3847 seeing a signal, or cause it to see a signal it normally would not see,
3848 or to give it any signal at any time. For example, if your program stopped
3849 due to some sort of memory reference error, you might store correct
3850 values into the erroneous variables and continue, hoping to see more
3851 execution; but your program would probably terminate immediately as
3852 a result of the fatal signal once it saw the signal. To prevent this,
3853 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
3854 program a signal}.
3855
3856 @node Thread Stops
3857 @section Stopping and starting multi-thread programs
3858
3859 When your program has multiple threads (@pxref{Threads,, Debugging
3860 programs with multiple threads}), you can choose whether to set
3861 breakpoints on all threads, or on a particular thread.
3862
3863 @table @code
3864 @cindex breakpoints and threads
3865 @cindex thread breakpoints
3866 @kindex break @dots{} thread @var{threadno}
3867 @item break @var{linespec} thread @var{threadno}
3868 @itemx break @var{linespec} thread @var{threadno} if @dots{}
3869 @var{linespec} specifies source lines; there are several ways of
3870 writing them, but the effect is always to specify some source line.
3871
3872 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3873 to specify that you only want @value{GDBN} to stop the program when a
3874 particular thread reaches this breakpoint. @var{threadno} is one of the
3875 numeric thread identifiers assigned by @value{GDBN}, shown in the first
3876 column of the @samp{info threads} display.
3877
3878 If you do not specify @samp{thread @var{threadno}} when you set a
3879 breakpoint, the breakpoint applies to @emph{all} threads of your
3880 program.
3881
3882 You can use the @code{thread} qualifier on conditional breakpoints as
3883 well; in this case, place @samp{thread @var{threadno}} before the
3884 breakpoint condition, like this:
3885
3886 @smallexample
3887 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
3888 @end smallexample
3889
3890 @end table
3891
3892 @cindex stopped threads
3893 @cindex threads, stopped
3894 Whenever your program stops under @value{GDBN} for any reason,
3895 @emph{all} threads of execution stop, not just the current thread. This
3896 allows you to examine the overall state of the program, including
3897 switching between threads, without worrying that things may change
3898 underfoot.
3899
3900 @cindex thread breakpoints and system calls
3901 @cindex system calls and thread breakpoints
3902 @cindex premature return from system calls
3903 There is an unfortunate side effect. If one thread stops for a
3904 breakpoint, or for some other reason, and another thread is blocked in a
3905 system call, then the system call may return prematurely. This is a
3906 consequence of the interaction between multiple threads and the signals
3907 that @value{GDBN} uses to implement breakpoints and other events that
3908 stop execution.
3909
3910 To handle this problem, your program should check the return value of
3911 each system call and react appropriately. This is good programming
3912 style anyways.
3913
3914 For example, do not write code like this:
3915
3916 @smallexample
3917 sleep (10);
3918 @end smallexample
3919
3920 The call to @code{sleep} will return early if a different thread stops
3921 at a breakpoint or for some other reason.
3922
3923 Instead, write this:
3924
3925 @smallexample
3926 int unslept = 10;
3927 while (unslept > 0)
3928 unslept = sleep (unslept);
3929 @end smallexample
3930
3931 A system call is allowed to return early, so the system is still
3932 conforming to its specification. But @value{GDBN} does cause your
3933 multi-threaded program to behave differently than it would without
3934 @value{GDBN}.
3935
3936 Also, @value{GDBN} uses internal breakpoints in the thread library to
3937 monitor certain events such as thread creation and thread destruction.
3938 When such an event happens, a system call in another thread may return
3939 prematurely, even though your program does not appear to stop.
3940
3941 @cindex continuing threads
3942 @cindex threads, continuing
3943 Conversely, whenever you restart the program, @emph{all} threads start
3944 executing. @emph{This is true even when single-stepping} with commands
3945 like @code{step} or @code{next}.
3946
3947 In particular, @value{GDBN} cannot single-step all threads in lockstep.
3948 Since thread scheduling is up to your debugging target's operating
3949 system (not controlled by @value{GDBN}), other threads may
3950 execute more than one statement while the current thread completes a
3951 single step. Moreover, in general other threads stop in the middle of a
3952 statement, rather than at a clean statement boundary, when the program
3953 stops.
3954
3955 You might even find your program stopped in another thread after
3956 continuing or even single-stepping. This happens whenever some other
3957 thread runs into a breakpoint, a signal, or an exception before the
3958 first thread completes whatever you requested.
3959
3960 On some OSes, you can lock the OS scheduler and thus allow only a single
3961 thread to run.
3962
3963 @table @code
3964 @item set scheduler-locking @var{mode}
3965 @cindex scheduler locking mode
3966 @cindex lock scheduler
3967 Set the scheduler locking mode. If it is @code{off}, then there is no
3968 locking and any thread may run at any time. If @code{on}, then only the
3969 current thread may run when the inferior is resumed. The @code{step}
3970 mode optimizes for single-stepping. It stops other threads from
3971 ``seizing the prompt'' by preempting the current thread while you are
3972 stepping. Other threads will only rarely (or never) get a chance to run
3973 when you step. They are more likely to run when you @samp{next} over a
3974 function call, and they are completely free to run when you use commands
3975 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
3976 thread hits a breakpoint during its timeslice, they will never steal the
3977 @value{GDBN} prompt away from the thread that you are debugging.
3978
3979 @item show scheduler-locking
3980 Display the current scheduler locking mode.
3981 @end table
3982
3983
3984 @node Stack
3985 @chapter Examining the Stack
3986
3987 When your program has stopped, the first thing you need to know is where it
3988 stopped and how it got there.
3989
3990 @cindex call stack
3991 Each time your program performs a function call, information about the call
3992 is generated.
3993 That information includes the location of the call in your program,
3994 the arguments of the call,
3995 and the local variables of the function being called.
3996 The information is saved in a block of data called a @dfn{stack frame}.
3997 The stack frames are allocated in a region of memory called the @dfn{call
3998 stack}.
3999
4000 When your program stops, the @value{GDBN} commands for examining the
4001 stack allow you to see all of this information.
4002
4003 @cindex selected frame
4004 One of the stack frames is @dfn{selected} by @value{GDBN} and many
4005 @value{GDBN} commands refer implicitly to the selected frame. In
4006 particular, whenever you ask @value{GDBN} for the value of a variable in
4007 your program, the value is found in the selected frame. There are
4008 special @value{GDBN} commands to select whichever frame you are
4009 interested in. @xref{Selection, ,Selecting a frame}.
4010
4011 When your program stops, @value{GDBN} automatically selects the
4012 currently executing frame and describes it briefly, similar to the
4013 @code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4014
4015 @menu
4016 * Frames:: Stack frames
4017 * Backtrace:: Backtraces
4018 * Selection:: Selecting a frame
4019 * Frame Info:: Information on a frame
4020
4021 @end menu
4022
4023 @node Frames
4024 @section Stack frames
4025
4026 @cindex frame, definition
4027 @cindex stack frame
4028 The call stack is divided up into contiguous pieces called @dfn{stack
4029 frames}, or @dfn{frames} for short; each frame is the data associated
4030 with one call to one function. The frame contains the arguments given
4031 to the function, the function's local variables, and the address at
4032 which the function is executing.
4033
4034 @cindex initial frame
4035 @cindex outermost frame
4036 @cindex innermost frame
4037 When your program is started, the stack has only one frame, that of the
4038 function @code{main}. This is called the @dfn{initial} frame or the
4039 @dfn{outermost} frame. Each time a function is called, a new frame is
4040 made. Each time a function returns, the frame for that function invocation
4041 is eliminated. If a function is recursive, there can be many frames for
4042 the same function. The frame for the function in which execution is
4043 actually occurring is called the @dfn{innermost} frame. This is the most
4044 recently created of all the stack frames that still exist.
4045
4046 @cindex frame pointer
4047 Inside your program, stack frames are identified by their addresses. A
4048 stack frame consists of many bytes, each of which has its own address; each
4049 kind of computer has a convention for choosing one byte whose
4050 address serves as the address of the frame. Usually this address is kept
4051 in a register called the @dfn{frame pointer register} while execution is
4052 going on in that frame.
4053
4054 @cindex frame number
4055 @value{GDBN} assigns numbers to all existing stack frames, starting with
4056 zero for the innermost frame, one for the frame that called it,
4057 and so on upward. These numbers do not really exist in your program;
4058 they are assigned by @value{GDBN} to give you a way of designating stack
4059 frames in @value{GDBN} commands.
4060
4061 @c The -fomit-frame-pointer below perennially causes hbox overflow
4062 @c underflow problems.
4063 @cindex frameless execution
4064 Some compilers provide a way to compile functions so that they operate
4065 without stack frames. (For example, the @value{GCC} option
4066 @smallexample
4067 @samp{-fomit-frame-pointer}
4068 @end smallexample
4069 generates functions without a frame.)
4070 This is occasionally done with heavily used library functions to save
4071 the frame setup time. @value{GDBN} has limited facilities for dealing
4072 with these function invocations. If the innermost function invocation
4073 has no stack frame, @value{GDBN} nevertheless regards it as though
4074 it had a separate frame, which is numbered zero as usual, allowing
4075 correct tracing of the function call chain. However, @value{GDBN} has
4076 no provision for frameless functions elsewhere in the stack.
4077
4078 @table @code
4079 @kindex frame@r{, command}
4080 @cindex current stack frame
4081 @item frame @var{args}
4082 The @code{frame} command allows you to move from one stack frame to another,
4083 and to print the stack frame you select. @var{args} may be either the
4084 address of the frame or the stack frame number. Without an argument,
4085 @code{frame} prints the current stack frame.
4086
4087 @kindex select-frame
4088 @cindex selecting frame silently
4089 @item select-frame
4090 The @code{select-frame} command allows you to move from one stack frame
4091 to another without printing the frame. This is the silent version of
4092 @code{frame}.
4093 @end table
4094
4095 @node Backtrace
4096 @section Backtraces
4097
4098 @cindex traceback
4099 @cindex call stack traces
4100 A backtrace is a summary of how your program got where it is. It shows one
4101 line per frame, for many frames, starting with the currently executing
4102 frame (frame zero), followed by its caller (frame one), and on up the
4103 stack.
4104
4105 @table @code
4106 @kindex backtrace
4107 @kindex bt @r{(@code{backtrace})}
4108 @item backtrace
4109 @itemx bt
4110 Print a backtrace of the entire stack: one line per frame for all
4111 frames in the stack.
4112
4113 You can stop the backtrace at any time by typing the system interrupt
4114 character, normally @kbd{C-c}.
4115
4116 @item backtrace @var{n}
4117 @itemx bt @var{n}
4118 Similar, but print only the innermost @var{n} frames.
4119
4120 @item backtrace -@var{n}
4121 @itemx bt -@var{n}
4122 Similar, but print only the outermost @var{n} frames.
4123 @end table
4124
4125 @kindex where
4126 @kindex info stack
4127 The names @code{where} and @code{info stack} (abbreviated @code{info s})
4128 are additional aliases for @code{backtrace}.
4129
4130 Each line in the backtrace shows the frame number and the function name.
4131 The program counter value is also shown---unless you use @code{set
4132 print address off}. The backtrace also shows the source file name and
4133 line number, as well as the arguments to the function. The program
4134 counter value is omitted if it is at the beginning of the code for that
4135 line number.
4136
4137 Here is an example of a backtrace. It was made with the command
4138 @samp{bt 3}, so it shows the innermost three frames.
4139
4140 @smallexample
4141 @group
4142 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4143 at builtin.c:993
4144 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4145 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4146 at macro.c:71
4147 (More stack frames follow...)
4148 @end group
4149 @end smallexample
4150
4151 @noindent
4152 The display for frame zero does not begin with a program counter
4153 value, indicating that your program has stopped at the beginning of the
4154 code for line @code{993} of @code{builtin.c}.
4155
4156 @cindex backtrace beyond @code{main} function
4157 @cindex program entry point
4158 @cindex startup code, and backtrace
4159 Most programs have a standard user entry point---a place where system
4160 libraries and startup code transition into user code. For C this is
4161 @code{main}. When @value{GDBN} finds the entry function in a backtrace
4162 it will terminate the backtrace, to avoid tracing into highly
4163 system-specific (and generally uninteresting) code.
4164
4165 If you need to examine the startup code, or limit the number of levels
4166 in a backtrace, you can change this behavior:
4167
4168 @table @code
4169 @item set backtrace past-main
4170 @itemx set backtrace past-main on
4171 @kindex set backtrace
4172 Backtraces will continue past the user entry point.
4173
4174 @item set backtrace past-main off
4175 Backtraces will stop when they encounter the user entry point. This is the
4176 default.
4177
4178 @item show backtrace past-main
4179 @kindex show backtrace
4180 Display the current user entry point backtrace policy.
4181
4182 @item set backtrace past-entry
4183 @itemx set backtrace past-entry on
4184 Backtraces will continue past the internal entry point of an application.
4185 This entry point is encoded by the linker when the application is built,
4186 and is likely before the user entry point @code{main} (or equivalent) is called.
4187
4188 @item set backtrace past-entry off
4189 Backtraces will stop when they encouter the internal entry point of an
4190 application. This is the default.
4191
4192 @item show backtrace past-entry
4193 Display the current internal entry point backtrace policy.
4194
4195 @item set backtrace limit @var{n}
4196 @itemx set backtrace limit 0
4197 @cindex backtrace limit
4198 Limit the backtrace to @var{n} levels. A value of zero means
4199 unlimited.
4200
4201 @item show backtrace limit
4202 Display the current limit on backtrace levels.
4203 @end table
4204
4205 @node Selection
4206 @section Selecting a frame
4207
4208 Most commands for examining the stack and other data in your program work on
4209 whichever stack frame is selected at the moment. Here are the commands for
4210 selecting a stack frame; all of them finish by printing a brief description
4211 of the stack frame just selected.
4212
4213 @table @code
4214 @kindex frame@r{, selecting}
4215 @kindex f @r{(@code{frame})}
4216 @item frame @var{n}
4217 @itemx f @var{n}
4218 Select frame number @var{n}. Recall that frame zero is the innermost
4219 (currently executing) frame, frame one is the frame that called the
4220 innermost one, and so on. The highest-numbered frame is the one for
4221 @code{main}.
4222
4223 @item frame @var{addr}
4224 @itemx f @var{addr}
4225 Select the frame at address @var{addr}. This is useful mainly if the
4226 chaining of stack frames has been damaged by a bug, making it
4227 impossible for @value{GDBN} to assign numbers properly to all frames. In
4228 addition, this can be useful when your program has multiple stacks and
4229 switches between them.
4230
4231 On the SPARC architecture, @code{frame} needs two addresses to
4232 select an arbitrary frame: a frame pointer and a stack pointer.
4233
4234 On the MIPS and Alpha architecture, it needs two addresses: a stack
4235 pointer and a program counter.
4236
4237 On the 29k architecture, it needs three addresses: a register stack
4238 pointer, a program counter, and a memory stack pointer.
4239 @c note to future updaters: this is conditioned on a flag
4240 @c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4241 @c as of 27 Jan 1994.
4242
4243 @kindex up
4244 @item up @var{n}
4245 Move @var{n} frames up the stack. For positive numbers @var{n}, this
4246 advances toward the outermost frame, to higher frame numbers, to frames
4247 that have existed longer. @var{n} defaults to one.
4248
4249 @kindex down
4250 @kindex do @r{(@code{down})}
4251 @item down @var{n}
4252 Move @var{n} frames down the stack. For positive numbers @var{n}, this
4253 advances toward the innermost frame, to lower frame numbers, to frames
4254 that were created more recently. @var{n} defaults to one. You may
4255 abbreviate @code{down} as @code{do}.
4256 @end table
4257
4258 All of these commands end by printing two lines of output describing the
4259 frame. The first line shows the frame number, the function name, the
4260 arguments, and the source file and line number of execution in that
4261 frame. The second line shows the text of that source line.
4262
4263 @need 1000
4264 For example:
4265
4266 @smallexample
4267 @group
4268 (@value{GDBP}) up
4269 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4270 at env.c:10
4271 10 read_input_file (argv[i]);
4272 @end group
4273 @end smallexample
4274
4275 After such a printout, the @code{list} command with no arguments
4276 prints ten lines centered on the point of execution in the frame.
4277 You can also edit the program at the point of execution with your favorite
4278 editing program by typing @code{edit}.
4279 @xref{List, ,Printing source lines},
4280 for details.
4281
4282 @table @code
4283 @kindex down-silently
4284 @kindex up-silently
4285 @item up-silently @var{n}
4286 @itemx down-silently @var{n}
4287 These two commands are variants of @code{up} and @code{down},
4288 respectively; they differ in that they do their work silently, without
4289 causing display of the new frame. They are intended primarily for use
4290 in @value{GDBN} command scripts, where the output might be unnecessary and
4291 distracting.
4292 @end table
4293
4294 @node Frame Info
4295 @section Information about a frame
4296
4297 There are several other commands to print information about the selected
4298 stack frame.
4299
4300 @table @code
4301 @item frame
4302 @itemx f
4303 When used without any argument, this command does not change which
4304 frame is selected, but prints a brief description of the currently
4305 selected stack frame. It can be abbreviated @code{f}. With an
4306 argument, this command is used to select a stack frame.
4307 @xref{Selection, ,Selecting a frame}.
4308
4309 @kindex info frame
4310 @kindex info f @r{(@code{info frame})}
4311 @item info frame
4312 @itemx info f
4313 This command prints a verbose description of the selected stack frame,
4314 including:
4315
4316 @itemize @bullet
4317 @item
4318 the address of the frame
4319 @item
4320 the address of the next frame down (called by this frame)
4321 @item
4322 the address of the next frame up (caller of this frame)
4323 @item
4324 the language in which the source code corresponding to this frame is written
4325 @item
4326 the address of the frame's arguments
4327 @item
4328 the address of the frame's local variables
4329 @item
4330 the program counter saved in it (the address of execution in the caller frame)
4331 @item
4332 which registers were saved in the frame
4333 @end itemize
4334
4335 @noindent The verbose description is useful when
4336 something has gone wrong that has made the stack format fail to fit
4337 the usual conventions.
4338
4339 @item info frame @var{addr}
4340 @itemx info f @var{addr}
4341 Print a verbose description of the frame at address @var{addr}, without
4342 selecting that frame. The selected frame remains unchanged by this
4343 command. This requires the same kind of address (more than one for some
4344 architectures) that you specify in the @code{frame} command.
4345 @xref{Selection, ,Selecting a frame}.
4346
4347 @kindex info args
4348 @item info args
4349 Print the arguments of the selected frame, each on a separate line.
4350
4351 @item info locals
4352 @kindex info locals
4353 Print the local variables of the selected frame, each on a separate
4354 line. These are all variables (declared either static or automatic)
4355 accessible at the point of execution of the selected frame.
4356
4357 @kindex info catch
4358 @cindex catch exceptions, list active handlers
4359 @cindex exception handlers, how to list
4360 @item info catch
4361 Print a list of all the exception handlers that are active in the
4362 current stack frame at the current point of execution. To see other
4363 exception handlers, visit the associated frame (using the @code{up},
4364 @code{down}, or @code{frame} commands); then type @code{info catch}.
4365 @xref{Set Catchpoints, , Setting catchpoints}.
4366
4367 @end table
4368
4369
4370 @node Source
4371 @chapter Examining Source Files
4372
4373 @value{GDBN} can print parts of your program's source, since the debugging
4374 information recorded in the program tells @value{GDBN} what source files were
4375 used to build it. When your program stops, @value{GDBN} spontaneously prints
4376 the line where it stopped. Likewise, when you select a stack frame
4377 (@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4378 execution in that frame has stopped. You can print other portions of
4379 source files by explicit command.
4380
4381 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
4382 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
4383 @value{GDBN} under @sc{gnu} Emacs}.
4384
4385 @menu
4386 * List:: Printing source lines
4387 * Edit:: Editing source files
4388 * Search:: Searching source files
4389 * Source Path:: Specifying source directories
4390 * Machine Code:: Source and machine code
4391 @end menu
4392
4393 @node List
4394 @section Printing source lines
4395
4396 @kindex list
4397 @kindex l @r{(@code{list})}
4398 To print lines from a source file, use the @code{list} command
4399 (abbreviated @code{l}). By default, ten lines are printed.
4400 There are several ways to specify what part of the file you want to print.
4401
4402 Here are the forms of the @code{list} command most commonly used:
4403
4404 @table @code
4405 @item list @var{linenum}
4406 Print lines centered around line number @var{linenum} in the
4407 current source file.
4408
4409 @item list @var{function}
4410 Print lines centered around the beginning of function
4411 @var{function}.
4412
4413 @item list
4414 Print more lines. If the last lines printed were printed with a
4415 @code{list} command, this prints lines following the last lines
4416 printed; however, if the last line printed was a solitary line printed
4417 as part of displaying a stack frame (@pxref{Stack, ,Examining the
4418 Stack}), this prints lines centered around that line.
4419
4420 @item list -
4421 Print lines just before the lines last printed.
4422 @end table
4423
4424 @cindex @code{list}, how many lines to display
4425 By default, @value{GDBN} prints ten source lines with any of these forms of
4426 the @code{list} command. You can change this using @code{set listsize}:
4427
4428 @table @code
4429 @kindex set listsize
4430 @item set listsize @var{count}
4431 Make the @code{list} command display @var{count} source lines (unless
4432 the @code{list} argument explicitly specifies some other number).
4433
4434 @kindex show listsize
4435 @item show listsize
4436 Display the number of lines that @code{list} prints.
4437 @end table
4438
4439 Repeating a @code{list} command with @key{RET} discards the argument,
4440 so it is equivalent to typing just @code{list}. This is more useful
4441 than listing the same lines again. An exception is made for an
4442 argument of @samp{-}; that argument is preserved in repetition so that
4443 each repetition moves up in the source file.
4444
4445 @cindex linespec
4446 In general, the @code{list} command expects you to supply zero, one or two
4447 @dfn{linespecs}. Linespecs specify source lines; there are several ways
4448 of writing them, but the effect is always to specify some source line.
4449 Here is a complete description of the possible arguments for @code{list}:
4450
4451 @table @code
4452 @item list @var{linespec}
4453 Print lines centered around the line specified by @var{linespec}.
4454
4455 @item list @var{first},@var{last}
4456 Print lines from @var{first} to @var{last}. Both arguments are
4457 linespecs.
4458
4459 @item list ,@var{last}
4460 Print lines ending with @var{last}.
4461
4462 @item list @var{first},
4463 Print lines starting with @var{first}.
4464
4465 @item list +
4466 Print lines just after the lines last printed.
4467
4468 @item list -
4469 Print lines just before the lines last printed.
4470
4471 @item list
4472 As described in the preceding table.
4473 @end table
4474
4475 Here are the ways of specifying a single source line---all the
4476 kinds of linespec.
4477
4478 @table @code
4479 @item @var{number}
4480 Specifies line @var{number} of the current source file.
4481 When a @code{list} command has two linespecs, this refers to
4482 the same source file as the first linespec.
4483
4484 @item +@var{offset}
4485 Specifies the line @var{offset} lines after the last line printed.
4486 When used as the second linespec in a @code{list} command that has
4487 two, this specifies the line @var{offset} lines down from the
4488 first linespec.
4489
4490 @item -@var{offset}
4491 Specifies the line @var{offset} lines before the last line printed.
4492
4493 @item @var{filename}:@var{number}
4494 Specifies line @var{number} in the source file @var{filename}.
4495
4496 @item @var{function}
4497 Specifies the line that begins the body of the function @var{function}.
4498 For example: in C, this is the line with the open brace.
4499
4500 @item @var{filename}:@var{function}
4501 Specifies the line of the open-brace that begins the body of the
4502 function @var{function} in the file @var{filename}. You only need the
4503 file name with a function name to avoid ambiguity when there are
4504 identically named functions in different source files.
4505
4506 @item *@var{address}
4507 Specifies the line containing the program address @var{address}.
4508 @var{address} may be any expression.
4509 @end table
4510
4511 @node Edit
4512 @section Editing source files
4513 @cindex editing source files
4514
4515 @kindex edit
4516 @kindex e @r{(@code{edit})}
4517 To edit the lines in a source file, use the @code{edit} command.
4518 The editing program of your choice
4519 is invoked with the current line set to
4520 the active line in the program.
4521 Alternatively, there are several ways to specify what part of the file you
4522 want to print if you want to see other parts of the program.
4523
4524 Here are the forms of the @code{edit} command most commonly used:
4525
4526 @table @code
4527 @item edit
4528 Edit the current source file at the active line number in the program.
4529
4530 @item edit @var{number}
4531 Edit the current source file with @var{number} as the active line number.
4532
4533 @item edit @var{function}
4534 Edit the file containing @var{function} at the beginning of its definition.
4535
4536 @item edit @var{filename}:@var{number}
4537 Specifies line @var{number} in the source file @var{filename}.
4538
4539 @item edit @var{filename}:@var{function}
4540 Specifies the line that begins the body of the
4541 function @var{function} in the file @var{filename}. You only need the
4542 file name with a function name to avoid ambiguity when there are
4543 identically named functions in different source files.
4544
4545 @item edit *@var{address}
4546 Specifies the line containing the program address @var{address}.
4547 @var{address} may be any expression.
4548 @end table
4549
4550 @subsection Choosing your editor
4551 You can customize @value{GDBN} to use any editor you want
4552 @footnote{
4553 The only restriction is that your editor (say @code{ex}), recognizes the
4554 following command-line syntax:
4555 @smallexample
4556 ex +@var{number} file
4557 @end smallexample
4558 The optional numeric value +@var{number} specifies the number of the line in
4559 the file where to start editing.}.
4560 By default, it is @file{@value{EDITOR}}, but you can change this
4561 by setting the environment variable @code{EDITOR} before using
4562 @value{GDBN}. For example, to configure @value{GDBN} to use the
4563 @code{vi} editor, you could use these commands with the @code{sh} shell:
4564 @smallexample
4565 EDITOR=/usr/bin/vi
4566 export EDITOR
4567 gdb @dots{}
4568 @end smallexample
4569 or in the @code{csh} shell,
4570 @smallexample
4571 setenv EDITOR /usr/bin/vi
4572 gdb @dots{}
4573 @end smallexample
4574
4575 @node Search
4576 @section Searching source files
4577 @cindex searching source files
4578
4579 There are two commands for searching through the current source file for a
4580 regular expression.
4581
4582 @table @code
4583 @kindex search
4584 @kindex forward-search
4585 @item forward-search @var{regexp}
4586 @itemx search @var{regexp}
4587 The command @samp{forward-search @var{regexp}} checks each line,
4588 starting with the one following the last line listed, for a match for
4589 @var{regexp}. It lists the line that is found. You can use the
4590 synonym @samp{search @var{regexp}} or abbreviate the command name as
4591 @code{fo}.
4592
4593 @kindex reverse-search
4594 @item reverse-search @var{regexp}
4595 The command @samp{reverse-search @var{regexp}} checks each line, starting
4596 with the one before the last line listed and going backward, for a match
4597 for @var{regexp}. It lists the line that is found. You can abbreviate
4598 this command as @code{rev}.
4599 @end table
4600
4601 @node Source Path
4602 @section Specifying source directories
4603
4604 @cindex source path
4605 @cindex directories for source files
4606 Executable programs sometimes do not record the directories of the source
4607 files from which they were compiled, just the names. Even when they do,
4608 the directories could be moved between the compilation and your debugging
4609 session. @value{GDBN} has a list of directories to search for source files;
4610 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4611 it tries all the directories in the list, in the order they are present
4612 in the list, until it finds a file with the desired name.
4613
4614 For example, suppose an executable references the file
4615 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4616 @file{/mnt/cross}. The file is first looked up literally; if this
4617 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4618 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4619 message is printed. @value{GDBN} does not look up the parts of the
4620 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4621 Likewise, the subdirectories of the source path are not searched: if
4622 the source path is @file{/mnt/cross}, and the binary refers to
4623 @file{foo.c}, @value{GDBN} would not find it under
4624 @file{/mnt/cross/usr/src/foo-1.0/lib}.
4625
4626 Plain file names, relative file names with leading directories, file
4627 names containing dots, etc.@: are all treated as described above; for
4628 instance, if the source path is @file{/mnt/cross}, and the source file
4629 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4630 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4631 that---@file{/mnt/cross/foo.c}.
4632
4633 Note that the executable search path is @emph{not} used to locate the
4634 source files. Neither is the current working directory, unless it
4635 happens to be in the source path.
4636
4637 Whenever you reset or rearrange the source path, @value{GDBN} clears out
4638 any information it has cached about where source files are found and where
4639 each line is in the file.
4640
4641 @kindex directory
4642 @kindex dir
4643 When you start @value{GDBN}, its source path includes only @samp{cdir}
4644 and @samp{cwd}, in that order.
4645 To add other directories, use the @code{directory} command.
4646
4647 @table @code
4648 @item directory @var{dirname} @dots{}
4649 @item dir @var{dirname} @dots{}
4650 Add directory @var{dirname} to the front of the source path. Several
4651 directory names may be given to this command, separated by @samp{:}
4652 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4653 part of absolute file names) or
4654 whitespace. You may specify a directory that is already in the source
4655 path; this moves it forward, so @value{GDBN} searches it sooner.
4656
4657 @kindex cdir
4658 @kindex cwd
4659 @vindex $cdir@r{, convenience variable}
4660 @vindex $cwdr@r{, convenience variable}
4661 @cindex compilation directory
4662 @cindex current directory
4663 @cindex working directory
4664 @cindex directory, current
4665 @cindex directory, compilation
4666 You can use the string @samp{$cdir} to refer to the compilation
4667 directory (if one is recorded), and @samp{$cwd} to refer to the current
4668 working directory. @samp{$cwd} is not the same as @samp{.}---the former
4669 tracks the current working directory as it changes during your @value{GDBN}
4670 session, while the latter is immediately expanded to the current
4671 directory at the time you add an entry to the source path.
4672
4673 @item directory
4674 Reset the source path to empty again. This requires confirmation.
4675
4676 @c RET-repeat for @code{directory} is explicitly disabled, but since
4677 @c repeating it would be a no-op we do not say that. (thanks to RMS)
4678
4679 @item show directories
4680 @kindex show directories
4681 Print the source path: show which directories it contains.
4682 @end table
4683
4684 If your source path is cluttered with directories that are no longer of
4685 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4686 versions of source. You can correct the situation as follows:
4687
4688 @enumerate
4689 @item
4690 Use @code{directory} with no argument to reset the source path to empty.
4691
4692 @item
4693 Use @code{directory} with suitable arguments to reinstall the
4694 directories you want in the source path. You can add all the
4695 directories in one command.
4696 @end enumerate
4697
4698 @node Machine Code
4699 @section Source and machine code
4700 @cindex source line and its code address
4701
4702 You can use the command @code{info line} to map source lines to program
4703 addresses (and vice versa), and the command @code{disassemble} to display
4704 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
4705 mode, the @code{info line} command causes the arrow to point to the
4706 line specified. Also, @code{info line} prints addresses in symbolic form as
4707 well as hex.
4708
4709 @table @code
4710 @kindex info line
4711 @item info line @var{linespec}
4712 Print the starting and ending addresses of the compiled code for
4713 source line @var{linespec}. You can specify source lines in any of
4714 the ways understood by the @code{list} command (@pxref{List, ,Printing
4715 source lines}).
4716 @end table
4717
4718 For example, we can use @code{info line} to discover the location of
4719 the object code for the first line of function
4720 @code{m4_changequote}:
4721
4722 @c FIXME: I think this example should also show the addresses in
4723 @c symbolic form, as they usually would be displayed.
4724 @smallexample
4725 (@value{GDBP}) info line m4_changequote
4726 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4727 @end smallexample
4728
4729 @noindent
4730 @cindex code address and its source line
4731 We can also inquire (using @code{*@var{addr}} as the form for
4732 @var{linespec}) what source line covers a particular address:
4733 @smallexample
4734 (@value{GDBP}) info line *0x63ff
4735 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4736 @end smallexample
4737
4738 @cindex @code{$_} and @code{info line}
4739 @cindex @code{x} command, default address
4740 @kindex x@r{(examine), and} info line
4741 After @code{info line}, the default address for the @code{x} command
4742 is changed to the starting address of the line, so that @samp{x/i} is
4743 sufficient to begin examining the machine code (@pxref{Memory,
4744 ,Examining memory}). Also, this address is saved as the value of the
4745 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4746 variables}).
4747
4748 @table @code
4749 @kindex disassemble
4750 @cindex assembly instructions
4751 @cindex instructions, assembly
4752 @cindex machine instructions
4753 @cindex listing machine instructions
4754 @item disassemble
4755 This specialized command dumps a range of memory as machine
4756 instructions. The default memory range is the function surrounding the
4757 program counter of the selected frame. A single argument to this
4758 command is a program counter value; @value{GDBN} dumps the function
4759 surrounding this value. Two arguments specify a range of addresses
4760 (first inclusive, second exclusive) to dump.
4761 @end table
4762
4763 The following example shows the disassembly of a range of addresses of
4764 HP PA-RISC 2.0 code:
4765
4766 @smallexample
4767 (@value{GDBP}) disas 0x32c4 0x32e4
4768 Dump of assembler code from 0x32c4 to 0x32e4:
4769 0x32c4 <main+204>: addil 0,dp
4770 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
4771 0x32cc <main+212>: ldil 0x3000,r31
4772 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
4773 0x32d4 <main+220>: ldo 0(r31),rp
4774 0x32d8 <main+224>: addil -0x800,dp
4775 0x32dc <main+228>: ldo 0x588(r1),r26
4776 0x32e0 <main+232>: ldil 0x3000,r31
4777 End of assembler dump.
4778 @end smallexample
4779
4780 Some architectures have more than one commonly-used set of instruction
4781 mnemonics or other syntax.
4782
4783 @table @code
4784 @kindex set disassembly-flavor
4785 @cindex Intel disassembly flavor
4786 @cindex AT&T disassembly flavor
4787 @item set disassembly-flavor @var{instruction-set}
4788 Select the instruction set to use when disassembling the
4789 program via the @code{disassemble} or @code{x/i} commands.
4790
4791 Currently this command is only defined for the Intel x86 family. You
4792 can set @var{instruction-set} to either @code{intel} or @code{att}.
4793 The default is @code{att}, the AT&T flavor used by default by Unix
4794 assemblers for x86-based targets.
4795
4796 @kindex show disassembly-flavor
4797 @item show disassembly-flavor
4798 Show the current setting of the disassembly flavor.
4799 @end table
4800
4801
4802 @node Data
4803 @chapter Examining Data
4804
4805 @cindex printing data
4806 @cindex examining data
4807 @kindex print
4808 @kindex inspect
4809 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
4810 @c document because it is nonstandard... Under Epoch it displays in a
4811 @c different window or something like that.
4812 The usual way to examine data in your program is with the @code{print}
4813 command (abbreviated @code{p}), or its synonym @code{inspect}. It
4814 evaluates and prints the value of an expression of the language your
4815 program is written in (@pxref{Languages, ,Using @value{GDBN} with
4816 Different Languages}).
4817
4818 @table @code
4819 @item print @var{expr}
4820 @itemx print /@var{f} @var{expr}
4821 @var{expr} is an expression (in the source language). By default the
4822 value of @var{expr} is printed in a format appropriate to its data type;
4823 you can choose a different format by specifying @samp{/@var{f}}, where
4824 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
4825 formats}.
4826
4827 @item print
4828 @itemx print /@var{f}
4829 @cindex reprint the last value
4830 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
4831 @dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4832 conveniently inspect the same value in an alternative format.
4833 @end table
4834
4835 A more low-level way of examining data is with the @code{x} command.
4836 It examines data in memory at a specified address and prints it in a
4837 specified format. @xref{Memory, ,Examining memory}.
4838
4839 If you are interested in information about types, or about how the
4840 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4841 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
4842 Table}.
4843
4844 @menu
4845 * Expressions:: Expressions
4846 * Variables:: Program variables
4847 * Arrays:: Artificial arrays
4848 * Output Formats:: Output formats
4849 * Memory:: Examining memory
4850 * Auto Display:: Automatic display
4851 * Print Settings:: Print settings
4852 * Value History:: Value history
4853 * Convenience Vars:: Convenience variables
4854 * Registers:: Registers
4855 * Floating Point Hardware:: Floating point hardware
4856 * Vector Unit:: Vector Unit
4857 * OS Information:: Auxiliary data provided by operating system
4858 * Memory Region Attributes:: Memory region attributes
4859 * Dump/Restore Files:: Copy between memory and a file
4860 * Core File Generation:: Cause a program dump its core
4861 * Character Sets:: Debugging programs that use a different
4862 character set than GDB does
4863 * Caching Remote Data:: Data caching for remote targets
4864 @end menu
4865
4866 @node Expressions
4867 @section Expressions
4868
4869 @cindex expressions
4870 @code{print} and many other @value{GDBN} commands accept an expression and
4871 compute its value. Any kind of constant, variable or operator defined
4872 by the programming language you are using is valid in an expression in
4873 @value{GDBN}. This includes conditional expressions, function calls,
4874 casts, and string constants. It also includes preprocessor macros, if
4875 you compiled your program to include this information; see
4876 @ref{Compilation}.
4877
4878 @cindex arrays in expressions
4879 @value{GDBN} supports array constants in expressions input by
4880 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
4881 you can use the command @code{print @{1, 2, 3@}} to build up an array in
4882 memory that is @code{malloc}ed in the target program.
4883
4884 Because C is so widespread, most of the expressions shown in examples in
4885 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4886 Languages}, for information on how to use expressions in other
4887 languages.
4888
4889 In this section, we discuss operators that you can use in @value{GDBN}
4890 expressions regardless of your programming language.
4891
4892 @cindex casts, in expressions
4893 Casts are supported in all languages, not just in C, because it is so
4894 useful to cast a number into a pointer in order to examine a structure
4895 at that address in memory.
4896 @c FIXME: casts supported---Mod2 true?
4897
4898 @value{GDBN} supports these operators, in addition to those common
4899 to programming languages:
4900
4901 @table @code
4902 @item @@
4903 @samp{@@} is a binary operator for treating parts of memory as arrays.
4904 @xref{Arrays, ,Artificial arrays}, for more information.
4905
4906 @item ::
4907 @samp{::} allows you to specify a variable in terms of the file or
4908 function where it is defined. @xref{Variables, ,Program variables}.
4909
4910 @cindex @{@var{type}@}
4911 @cindex type casting memory
4912 @cindex memory, viewing as typed object
4913 @cindex casts, to view memory
4914 @item @{@var{type}@} @var{addr}
4915 Refers to an object of type @var{type} stored at address @var{addr} in
4916 memory. @var{addr} may be any expression whose value is an integer or
4917 pointer (but parentheses are required around binary operators, just as in
4918 a cast). This construct is allowed regardless of what kind of data is
4919 normally supposed to reside at @var{addr}.
4920 @end table
4921
4922 @node Variables
4923 @section Program variables
4924
4925 The most common kind of expression to use is the name of a variable
4926 in your program.
4927
4928 Variables in expressions are understood in the selected stack frame
4929 (@pxref{Selection, ,Selecting a frame}); they must be either:
4930
4931 @itemize @bullet
4932 @item
4933 global (or file-static)
4934 @end itemize
4935
4936 @noindent or
4937
4938 @itemize @bullet
4939 @item
4940 visible according to the scope rules of the
4941 programming language from the point of execution in that frame
4942 @end itemize
4943
4944 @noindent This means that in the function
4945
4946 @smallexample
4947 foo (a)
4948 int a;
4949 @{
4950 bar (a);
4951 @{
4952 int b = test ();
4953 bar (b);
4954 @}
4955 @}
4956 @end smallexample
4957
4958 @noindent
4959 you can examine and use the variable @code{a} whenever your program is
4960 executing within the function @code{foo}, but you can only use or
4961 examine the variable @code{b} while your program is executing inside
4962 the block where @code{b} is declared.
4963
4964 @cindex variable name conflict
4965 There is an exception: you can refer to a variable or function whose
4966 scope is a single source file even if the current execution point is not
4967 in this file. But it is possible to have more than one such variable or
4968 function with the same name (in different source files). If that
4969 happens, referring to that name has unpredictable effects. If you wish,
4970 you can specify a static variable in a particular function or file,
4971 using the colon-colon (@code{::}) notation:
4972
4973 @cindex colon-colon, context for variables/functions
4974 @iftex
4975 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
4976 @cindex @code{::}, context for variables/functions
4977 @end iftex
4978 @smallexample
4979 @var{file}::@var{variable}
4980 @var{function}::@var{variable}
4981 @end smallexample
4982
4983 @noindent
4984 Here @var{file} or @var{function} is the name of the context for the
4985 static @var{variable}. In the case of file names, you can use quotes to
4986 make sure @value{GDBN} parses the file name as a single word---for example,
4987 to print a global value of @code{x} defined in @file{f2.c}:
4988
4989 @smallexample
4990 (@value{GDBP}) p 'f2.c'::x
4991 @end smallexample
4992
4993 @cindex C@t{++} scope resolution
4994 This use of @samp{::} is very rarely in conflict with the very similar
4995 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
4996 scope resolution operator in @value{GDBN} expressions.
4997 @c FIXME: Um, so what happens in one of those rare cases where it's in
4998 @c conflict?? --mew
4999
5000 @cindex wrong values
5001 @cindex variable values, wrong
5002 @cindex function entry/exit, wrong values of variables
5003 @cindex optimized code, wrong values of variables
5004 @quotation
5005 @emph{Warning:} Occasionally, a local variable may appear to have the
5006 wrong value at certain points in a function---just after entry to a new
5007 scope, and just before exit.
5008 @end quotation
5009 You may see this problem when you are stepping by machine instructions.
5010 This is because, on most machines, it takes more than one instruction to
5011 set up a stack frame (including local variable definitions); if you are
5012 stepping by machine instructions, variables may appear to have the wrong
5013 values until the stack frame is completely built. On exit, it usually
5014 also takes more than one machine instruction to destroy a stack frame;
5015 after you begin stepping through that group of instructions, local
5016 variable definitions may be gone.
5017
5018 This may also happen when the compiler does significant optimizations.
5019 To be sure of always seeing accurate values, turn off all optimization
5020 when compiling.
5021
5022 @cindex ``No symbol "foo" in current context''
5023 Another possible effect of compiler optimizations is to optimize
5024 unused variables out of existence, or assign variables to registers (as
5025 opposed to memory addresses). Depending on the support for such cases
5026 offered by the debug info format used by the compiler, @value{GDBN}
5027 might not be able to display values for such local variables. If that
5028 happens, @value{GDBN} will print a message like this:
5029
5030 @smallexample
5031 No symbol "foo" in current context.
5032 @end smallexample
5033
5034 To solve such problems, either recompile without optimizations, or use a
5035 different debug info format, if the compiler supports several such
5036 formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
5037 usually supports the @option{-gstabs+} option. @option{-gstabs+}
5038 produces debug info in a format that is superior to formats such as
5039 COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5040 an effective form for debug info. @xref{Debugging Options,,Options
5041 for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
5042 @xref{C, , Debugging C++}, for more info about debug info formats
5043 that are best suited to C@t{++} programs.
5044
5045 @node Arrays
5046 @section Artificial arrays
5047
5048 @cindex artificial array
5049 @cindex arrays
5050 @kindex @@@r{, referencing memory as an array}
5051 It is often useful to print out several successive objects of the
5052 same type in memory; a section of an array, or an array of
5053 dynamically determined size for which only a pointer exists in the
5054 program.
5055
5056 You can do this by referring to a contiguous span of memory as an
5057 @dfn{artificial array}, using the binary operator @samp{@@}. The left
5058 operand of @samp{@@} should be the first element of the desired array
5059 and be an individual object. The right operand should be the desired length
5060 of the array. The result is an array value whose elements are all of
5061 the type of the left argument. The first element is actually the left
5062 argument; the second element comes from bytes of memory immediately
5063 following those that hold the first element, and so on. Here is an
5064 example. If a program says
5065
5066 @smallexample
5067 int *array = (int *) malloc (len * sizeof (int));
5068 @end smallexample
5069
5070 @noindent
5071 you can print the contents of @code{array} with
5072
5073 @smallexample
5074 p *array@@len
5075 @end smallexample
5076
5077 The left operand of @samp{@@} must reside in memory. Array values made
5078 with @samp{@@} in this way behave just like other arrays in terms of
5079 subscripting, and are coerced to pointers when used in expressions.
5080 Artificial arrays most often appear in expressions via the value history
5081 (@pxref{Value History, ,Value history}), after printing one out.
5082
5083 Another way to create an artificial array is to use a cast.
5084 This re-interprets a value as if it were an array.
5085 The value need not be in memory:
5086 @smallexample
5087 (@value{GDBP}) p/x (short[2])0x12345678
5088 $1 = @{0x1234, 0x5678@}
5089 @end smallexample
5090
5091 As a convenience, if you leave the array length out (as in
5092 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
5093 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
5094 @smallexample
5095 (@value{GDBP}) p/x (short[])0x12345678
5096 $2 = @{0x1234, 0x5678@}
5097 @end smallexample
5098
5099 Sometimes the artificial array mechanism is not quite enough; in
5100 moderately complex data structures, the elements of interest may not
5101 actually be adjacent---for example, if you are interested in the values
5102 of pointers in an array. One useful work-around in this situation is
5103 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5104 variables}) as a counter in an expression that prints the first
5105 interesting value, and then repeat that expression via @key{RET}. For
5106 instance, suppose you have an array @code{dtab} of pointers to
5107 structures, and you are interested in the values of a field @code{fv}
5108 in each structure. Here is an example of what you might type:
5109
5110 @smallexample
5111 set $i = 0
5112 p dtab[$i++]->fv
5113 @key{RET}
5114 @key{RET}
5115 @dots{}
5116 @end smallexample
5117
5118 @node Output Formats
5119 @section Output formats
5120
5121 @cindex formatted output
5122 @cindex output formats
5123 By default, @value{GDBN} prints a value according to its data type. Sometimes
5124 this is not what you want. For example, you might want to print a number
5125 in hex, or a pointer in decimal. Or you might want to view data in memory
5126 at a certain address as a character string or as an instruction. To do
5127 these things, specify an @dfn{output format} when you print a value.
5128
5129 The simplest use of output formats is to say how to print a value
5130 already computed. This is done by starting the arguments of the
5131 @code{print} command with a slash and a format letter. The format
5132 letters supported are:
5133
5134 @table @code
5135 @item x
5136 Regard the bits of the value as an integer, and print the integer in
5137 hexadecimal.
5138
5139 @item d
5140 Print as integer in signed decimal.
5141
5142 @item u
5143 Print as integer in unsigned decimal.
5144
5145 @item o
5146 Print as integer in octal.
5147
5148 @item t
5149 Print as integer in binary. The letter @samp{t} stands for ``two''.
5150 @footnote{@samp{b} cannot be used because these format letters are also
5151 used with the @code{x} command, where @samp{b} stands for ``byte'';
5152 see @ref{Memory,,Examining memory}.}
5153
5154 @item a
5155 @cindex unknown address, locating
5156 @cindex locate address
5157 Print as an address, both absolute in hexadecimal and as an offset from
5158 the nearest preceding symbol. You can use this format used to discover
5159 where (in what function) an unknown address is located:
5160
5161 @smallexample
5162 (@value{GDBP}) p/a 0x54320
5163 $3 = 0x54320 <_initialize_vx+396>
5164 @end smallexample
5165
5166 @noindent
5167 The command @code{info symbol 0x54320} yields similar results.
5168 @xref{Symbols, info symbol}.
5169
5170 @item c
5171 Regard as an integer and print it as a character constant.
5172
5173 @item f
5174 Regard the bits of the value as a floating point number and print
5175 using typical floating point syntax.
5176 @end table
5177
5178 For example, to print the program counter in hex (@pxref{Registers}), type
5179
5180 @smallexample
5181 p/x $pc
5182 @end smallexample
5183
5184 @noindent
5185 Note that no space is required before the slash; this is because command
5186 names in @value{GDBN} cannot contain a slash.
5187
5188 To reprint the last value in the value history with a different format,
5189 you can use the @code{print} command with just a format and no
5190 expression. For example, @samp{p/x} reprints the last value in hex.
5191
5192 @node Memory
5193 @section Examining memory
5194
5195 You can use the command @code{x} (for ``examine'') to examine memory in
5196 any of several formats, independently of your program's data types.
5197
5198 @cindex examining memory
5199 @table @code
5200 @kindex x @r{(examine memory)}
5201 @item x/@var{nfu} @var{addr}
5202 @itemx x @var{addr}
5203 @itemx x
5204 Use the @code{x} command to examine memory.
5205 @end table
5206
5207 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5208 much memory to display and how to format it; @var{addr} is an
5209 expression giving the address where you want to start displaying memory.
5210 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5211 Several commands set convenient defaults for @var{addr}.
5212
5213 @table @r
5214 @item @var{n}, the repeat count
5215 The repeat count is a decimal integer; the default is 1. It specifies
5216 how much memory (counting by units @var{u}) to display.
5217 @c This really is **decimal**; unaffected by 'set radix' as of GDB
5218 @c 4.1.2.
5219
5220 @item @var{f}, the display format
5221 The display format is one of the formats used by @code{print},
5222 @samp{s} (null-terminated string), or @samp{i} (machine instruction).
5223 The default is @samp{x} (hexadecimal) initially.
5224 The default changes each time you use either @code{x} or @code{print}.
5225
5226 @item @var{u}, the unit size
5227 The unit size is any of
5228
5229 @table @code
5230 @item b
5231 Bytes.
5232 @item h
5233 Halfwords (two bytes).
5234 @item w
5235 Words (four bytes). This is the initial default.
5236 @item g
5237 Giant words (eight bytes).
5238 @end table
5239
5240 Each time you specify a unit size with @code{x}, that size becomes the
5241 default unit the next time you use @code{x}. (For the @samp{s} and
5242 @samp{i} formats, the unit size is ignored and is normally not written.)
5243
5244 @item @var{addr}, starting display address
5245 @var{addr} is the address where you want @value{GDBN} to begin displaying
5246 memory. The expression need not have a pointer value (though it may);
5247 it is always interpreted as an integer address of a byte of memory.
5248 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
5249 @var{addr} is usually just after the last address examined---but several
5250 other commands also set the default address: @code{info breakpoints} (to
5251 the address of the last breakpoint listed), @code{info line} (to the
5252 starting address of a line), and @code{print} (if you use it to display
5253 a value from memory).
5254 @end table
5255
5256 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5257 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5258 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5259 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
5260 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
5261
5262 Since the letters indicating unit sizes are all distinct from the
5263 letters specifying output formats, you do not have to remember whether
5264 unit size or format comes first; either order works. The output
5265 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5266 (However, the count @var{n} must come first; @samp{wx4} does not work.)
5267
5268 Even though the unit size @var{u} is ignored for the formats @samp{s}
5269 and @samp{i}, you might still want to use a count @var{n}; for example,
5270 @samp{3i} specifies that you want to see three machine instructions,
5271 including any operands. The command @code{disassemble} gives an
5272 alternative way of inspecting machine instructions; see @ref{Machine
5273 Code,,Source and machine code}.
5274
5275 All the defaults for the arguments to @code{x} are designed to make it
5276 easy to continue scanning memory with minimal specifications each time
5277 you use @code{x}. For example, after you have inspected three machine
5278 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5279 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5280 the repeat count @var{n} is used again; the other arguments default as
5281 for successive uses of @code{x}.
5282
5283 @cindex @code{$_}, @code{$__}, and value history
5284 The addresses and contents printed by the @code{x} command are not saved
5285 in the value history because there is often too much of them and they
5286 would get in the way. Instead, @value{GDBN} makes these values available for
5287 subsequent use in expressions as values of the convenience variables
5288 @code{$_} and @code{$__}. After an @code{x} command, the last address
5289 examined is available for use in expressions in the convenience variable
5290 @code{$_}. The contents of that address, as examined, are available in
5291 the convenience variable @code{$__}.
5292
5293 If the @code{x} command has a repeat count, the address and contents saved
5294 are from the last memory unit printed; this is not the same as the last
5295 address printed if several units were printed on the last line of output.
5296
5297 @cindex remote memory comparison
5298 @cindex verify remote memory image
5299 When you are debugging a program running on a remote target machine
5300 (@pxref{Remote}), you may wish to verify the program's image in the
5301 remote machine's memory against the executable file you downloaded to
5302 the target. The @code{compare-sections} command is provided for such
5303 situations.
5304
5305 @table @code
5306 @kindex compare-sections
5307 @item compare-sections @r{[}@var{section-name}@r{]}
5308 Compare the data of a loadable section @var{section-name} in the
5309 executable file of the program being debugged with the same section in
5310 the remote machine's memory, and report any mismatches. With no
5311 arguments, compares all loadable sections. This command's
5312 availability depends on the target's support for the @code{"qCRC"}
5313 remote request.
5314 @end table
5315
5316 @node Auto Display
5317 @section Automatic display
5318 @cindex automatic display
5319 @cindex display of expressions
5320
5321 If you find that you want to print the value of an expression frequently
5322 (to see how it changes), you might want to add it to the @dfn{automatic
5323 display list} so that @value{GDBN} prints its value each time your program stops.
5324 Each expression added to the list is given a number to identify it;
5325 to remove an expression from the list, you specify that number.
5326 The automatic display looks like this:
5327
5328 @smallexample
5329 2: foo = 38
5330 3: bar[5] = (struct hack *) 0x3804
5331 @end smallexample
5332
5333 @noindent
5334 This display shows item numbers, expressions and their current values. As with
5335 displays you request manually using @code{x} or @code{print}, you can
5336 specify the output format you prefer; in fact, @code{display} decides
5337 whether to use @code{print} or @code{x} depending on how elaborate your
5338 format specification is---it uses @code{x} if you specify a unit size,
5339 or one of the two formats (@samp{i} and @samp{s}) that are only
5340 supported by @code{x}; otherwise it uses @code{print}.
5341
5342 @table @code
5343 @kindex display
5344 @item display @var{expr}
5345 Add the expression @var{expr} to the list of expressions to display
5346 each time your program stops. @xref{Expressions, ,Expressions}.
5347
5348 @code{display} does not repeat if you press @key{RET} again after using it.
5349
5350 @item display/@var{fmt} @var{expr}
5351 For @var{fmt} specifying only a display format and not a size or
5352 count, add the expression @var{expr} to the auto-display list but
5353 arrange to display it each time in the specified format @var{fmt}.
5354 @xref{Output Formats,,Output formats}.
5355
5356 @item display/@var{fmt} @var{addr}
5357 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5358 number of units, add the expression @var{addr} as a memory address to
5359 be examined each time your program stops. Examining means in effect
5360 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5361 @end table
5362
5363 For example, @samp{display/i $pc} can be helpful, to see the machine
5364 instruction about to be executed each time execution stops (@samp{$pc}
5365 is a common name for the program counter; @pxref{Registers, ,Registers}).
5366
5367 @table @code
5368 @kindex delete display
5369 @kindex undisplay
5370 @item undisplay @var{dnums}@dots{}
5371 @itemx delete display @var{dnums}@dots{}
5372 Remove item numbers @var{dnums} from the list of expressions to display.
5373
5374 @code{undisplay} does not repeat if you press @key{RET} after using it.
5375 (Otherwise you would just get the error @samp{No display number @dots{}}.)
5376
5377 @kindex disable display
5378 @item disable display @var{dnums}@dots{}
5379 Disable the display of item numbers @var{dnums}. A disabled display
5380 item is not printed automatically, but is not forgotten. It may be
5381 enabled again later.
5382
5383 @kindex enable display
5384 @item enable display @var{dnums}@dots{}
5385 Enable display of item numbers @var{dnums}. It becomes effective once
5386 again in auto display of its expression, until you specify otherwise.
5387
5388 @item display
5389 Display the current values of the expressions on the list, just as is
5390 done when your program stops.
5391
5392 @kindex info display
5393 @item info display
5394 Print the list of expressions previously set up to display
5395 automatically, each one with its item number, but without showing the
5396 values. This includes disabled expressions, which are marked as such.
5397 It also includes expressions which would not be displayed right now
5398 because they refer to automatic variables not currently available.
5399 @end table
5400
5401 @cindex display disabled out of scope
5402 If a display expression refers to local variables, then it does not make
5403 sense outside the lexical context for which it was set up. Such an
5404 expression is disabled when execution enters a context where one of its
5405 variables is not defined. For example, if you give the command
5406 @code{display last_char} while inside a function with an argument
5407 @code{last_char}, @value{GDBN} displays this argument while your program
5408 continues to stop inside that function. When it stops elsewhere---where
5409 there is no variable @code{last_char}---the display is disabled
5410 automatically. The next time your program stops where @code{last_char}
5411 is meaningful, you can enable the display expression once again.
5412
5413 @node Print Settings
5414 @section Print settings
5415
5416 @cindex format options
5417 @cindex print settings
5418 @value{GDBN} provides the following ways to control how arrays, structures,
5419 and symbols are printed.
5420
5421 @noindent
5422 These settings are useful for debugging programs in any language:
5423
5424 @table @code
5425 @kindex set print
5426 @item set print address
5427 @itemx set print address on
5428 @cindex print/don't print memory addresses
5429 @value{GDBN} prints memory addresses showing the location of stack
5430 traces, structure values, pointer values, breakpoints, and so forth,
5431 even when it also displays the contents of those addresses. The default
5432 is @code{on}. For example, this is what a stack frame display looks like with
5433 @code{set print address on}:
5434
5435 @smallexample
5436 @group
5437 (@value{GDBP}) f
5438 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5439 at input.c:530
5440 530 if (lquote != def_lquote)
5441 @end group
5442 @end smallexample
5443
5444 @item set print address off
5445 Do not print addresses when displaying their contents. For example,
5446 this is the same stack frame displayed with @code{set print address off}:
5447
5448 @smallexample
5449 @group
5450 (@value{GDBP}) set print addr off
5451 (@value{GDBP}) f
5452 #0 set_quotes (lq="<<", rq=">>") at input.c:530
5453 530 if (lquote != def_lquote)
5454 @end group
5455 @end smallexample
5456
5457 You can use @samp{set print address off} to eliminate all machine
5458 dependent displays from the @value{GDBN} interface. For example, with
5459 @code{print address off}, you should get the same text for backtraces on
5460 all machines---whether or not they involve pointer arguments.
5461
5462 @kindex show print
5463 @item show print address
5464 Show whether or not addresses are to be printed.
5465 @end table
5466
5467 When @value{GDBN} prints a symbolic address, it normally prints the
5468 closest earlier symbol plus an offset. If that symbol does not uniquely
5469 identify the address (for example, it is a name whose scope is a single
5470 source file), you may need to clarify. One way to do this is with
5471 @code{info line}, for example @samp{info line *0x4537}. Alternately,
5472 you can set @value{GDBN} to print the source file and line number when
5473 it prints a symbolic address:
5474
5475 @table @code
5476 @item set print symbol-filename on
5477 @cindex source file and line of a symbol
5478 @cindex symbol, source file and line
5479 Tell @value{GDBN} to print the source file name and line number of a
5480 symbol in the symbolic form of an address.
5481
5482 @item set print symbol-filename off
5483 Do not print source file name and line number of a symbol. This is the
5484 default.
5485
5486 @item show print symbol-filename
5487 Show whether or not @value{GDBN} will print the source file name and
5488 line number of a symbol in the symbolic form of an address.
5489 @end table
5490
5491 Another situation where it is helpful to show symbol filenames and line
5492 numbers is when disassembling code; @value{GDBN} shows you the line
5493 number and source file that corresponds to each instruction.
5494
5495 Also, you may wish to see the symbolic form only if the address being
5496 printed is reasonably close to the closest earlier symbol:
5497
5498 @table @code
5499 @item set print max-symbolic-offset @var{max-offset}
5500 @cindex maximum value for offset of closest symbol
5501 Tell @value{GDBN} to only display the symbolic form of an address if the
5502 offset between the closest earlier symbol and the address is less than
5503 @var{max-offset}. The default is 0, which tells @value{GDBN}
5504 to always print the symbolic form of an address if any symbol precedes it.
5505
5506 @item show print max-symbolic-offset
5507 Ask how large the maximum offset is that @value{GDBN} prints in a
5508 symbolic address.
5509 @end table
5510
5511 @cindex wild pointer, interpreting
5512 @cindex pointer, finding referent
5513 If you have a pointer and you are not sure where it points, try
5514 @samp{set print symbol-filename on}. Then you can determine the name
5515 and source file location of the variable where it points, using
5516 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5517 For example, here @value{GDBN} shows that a variable @code{ptt} points
5518 at another variable @code{t}, defined in @file{hi2.c}:
5519
5520 @smallexample
5521 (@value{GDBP}) set print symbol-filename on
5522 (@value{GDBP}) p/a ptt
5523 $4 = 0xe008 <t in hi2.c>
5524 @end smallexample
5525
5526 @quotation
5527 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5528 does not show the symbol name and filename of the referent, even with
5529 the appropriate @code{set print} options turned on.
5530 @end quotation
5531
5532 Other settings control how different kinds of objects are printed:
5533
5534 @table @code
5535 @item set print array
5536 @itemx set print array on
5537 @cindex pretty print arrays
5538 Pretty print arrays. This format is more convenient to read,
5539 but uses more space. The default is off.
5540
5541 @item set print array off
5542 Return to compressed format for arrays.
5543
5544 @item show print array
5545 Show whether compressed or pretty format is selected for displaying
5546 arrays.
5547
5548 @item set print elements @var{number-of-elements}
5549 @cindex number of array elements to print
5550 @cindex limit on number of printed array elements
5551 Set a limit on how many elements of an array @value{GDBN} will print.
5552 If @value{GDBN} is printing a large array, it stops printing after it has
5553 printed the number of elements set by the @code{set print elements} command.
5554 This limit also applies to the display of strings.
5555 When @value{GDBN} starts, this limit is set to 200.
5556 Setting @var{number-of-elements} to zero means that the printing is unlimited.
5557
5558 @item show print elements
5559 Display the number of elements of a large array that @value{GDBN} will print.
5560 If the number is 0, then the printing is unlimited.
5561
5562 @item set print repeats
5563 @cindex repeated array elements
5564 Set the threshold for suppressing display of repeated array
5565 elelments. When the number of consecutive identical elements of an
5566 array exceeds the threshold, @value{GDBN} prints the string
5567 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
5568 identical repetitions, instead of displaying the identical elements
5569 themselves. Setting the threshold to zero will cause all elements to
5570 be individually printed. The default threshold is 10.
5571
5572 @item show print repeats
5573 Display the current threshold for printing repeated identical
5574 elements.
5575
5576 @item set print null-stop
5577 @cindex @sc{null} elements in arrays
5578 Cause @value{GDBN} to stop printing the characters of an array when the first
5579 @sc{null} is encountered. This is useful when large arrays actually
5580 contain only short strings.
5581 The default is off.
5582
5583 @item show print null-stop
5584 Show whether @value{GDBN} stops printing an array on the first
5585 @sc{null} character.
5586
5587 @item set print pretty on
5588 @cindex print structures in indented form
5589 @cindex indentation in structure display
5590 Cause @value{GDBN} to print structures in an indented format with one member
5591 per line, like this:
5592
5593 @smallexample
5594 @group
5595 $1 = @{
5596 next = 0x0,
5597 flags = @{
5598 sweet = 1,
5599 sour = 1
5600 @},
5601 meat = 0x54 "Pork"
5602 @}
5603 @end group
5604 @end smallexample
5605
5606 @item set print pretty off
5607 Cause @value{GDBN} to print structures in a compact format, like this:
5608
5609 @smallexample
5610 @group
5611 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5612 meat = 0x54 "Pork"@}
5613 @end group
5614 @end smallexample
5615
5616 @noindent
5617 This is the default format.
5618
5619 @item show print pretty
5620 Show which format @value{GDBN} is using to print structures.
5621
5622 @item set print sevenbit-strings on
5623 @cindex eight-bit characters in strings
5624 @cindex octal escapes in strings
5625 Print using only seven-bit characters; if this option is set,
5626 @value{GDBN} displays any eight-bit characters (in strings or
5627 character values) using the notation @code{\}@var{nnn}. This setting is
5628 best if you are working in English (@sc{ascii}) and you use the
5629 high-order bit of characters as a marker or ``meta'' bit.
5630
5631 @item set print sevenbit-strings off
5632 Print full eight-bit characters. This allows the use of more
5633 international character sets, and is the default.
5634
5635 @item show print sevenbit-strings
5636 Show whether or not @value{GDBN} is printing only seven-bit characters.
5637
5638 @item set print union on
5639 @cindex unions in structures, printing
5640 Tell @value{GDBN} to print unions which are contained in structures
5641 and other unions. This is the default setting.
5642
5643 @item set print union off
5644 Tell @value{GDBN} not to print unions which are contained in
5645 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5646 instead.
5647
5648 @item show print union
5649 Ask @value{GDBN} whether or not it will print unions which are contained in
5650 structures and other unions.
5651
5652 For example, given the declarations
5653
5654 @smallexample
5655 typedef enum @{Tree, Bug@} Species;
5656 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5657 typedef enum @{Caterpillar, Cocoon, Butterfly@}
5658 Bug_forms;
5659
5660 struct thing @{
5661 Species it;
5662 union @{
5663 Tree_forms tree;
5664 Bug_forms bug;
5665 @} form;
5666 @};
5667
5668 struct thing foo = @{Tree, @{Acorn@}@};
5669 @end smallexample
5670
5671 @noindent
5672 with @code{set print union on} in effect @samp{p foo} would print
5673
5674 @smallexample
5675 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5676 @end smallexample
5677
5678 @noindent
5679 and with @code{set print union off} in effect it would print
5680
5681 @smallexample
5682 $1 = @{it = Tree, form = @{...@}@}
5683 @end smallexample
5684
5685 @noindent
5686 @code{set print union} affects programs written in C-like languages
5687 and in Pascal.
5688 @end table
5689
5690 @need 1000
5691 @noindent
5692 These settings are of interest when debugging C@t{++} programs:
5693
5694 @table @code
5695 @cindex demangling C@t{++} names
5696 @item set print demangle
5697 @itemx set print demangle on
5698 Print C@t{++} names in their source form rather than in the encoded
5699 (``mangled'') form passed to the assembler and linker for type-safe
5700 linkage. The default is on.
5701
5702 @item show print demangle
5703 Show whether C@t{++} names are printed in mangled or demangled form.
5704
5705 @item set print asm-demangle
5706 @itemx set print asm-demangle on
5707 Print C@t{++} names in their source form rather than their mangled form, even
5708 in assembler code printouts such as instruction disassemblies.
5709 The default is off.
5710
5711 @item show print asm-demangle
5712 Show whether C@t{++} names in assembly listings are printed in mangled
5713 or demangled form.
5714
5715 @cindex C@t{++} symbol decoding style
5716 @cindex symbol decoding style, C@t{++}
5717 @kindex set demangle-style
5718 @item set demangle-style @var{style}
5719 Choose among several encoding schemes used by different compilers to
5720 represent C@t{++} names. The choices for @var{style} are currently:
5721
5722 @table @code
5723 @item auto
5724 Allow @value{GDBN} to choose a decoding style by inspecting your program.
5725
5726 @item gnu
5727 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
5728 This is the default.
5729
5730 @item hp
5731 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
5732
5733 @item lucid
5734 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
5735
5736 @item arm
5737 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
5738 @strong{Warning:} this setting alone is not sufficient to allow
5739 debugging @code{cfront}-generated executables. @value{GDBN} would
5740 require further enhancement to permit that.
5741
5742 @end table
5743 If you omit @var{style}, you will see a list of possible formats.
5744
5745 @item show demangle-style
5746 Display the encoding style currently in use for decoding C@t{++} symbols.
5747
5748 @item set print object
5749 @itemx set print object on
5750 @cindex derived type of an object, printing
5751 @cindex display derived types
5752 When displaying a pointer to an object, identify the @emph{actual}
5753 (derived) type of the object rather than the @emph{declared} type, using
5754 the virtual function table.
5755
5756 @item set print object off
5757 Display only the declared type of objects, without reference to the
5758 virtual function table. This is the default setting.
5759
5760 @item show print object
5761 Show whether actual, or declared, object types are displayed.
5762
5763 @item set print static-members
5764 @itemx set print static-members on
5765 @cindex static members of C@t{++} objects
5766 Print static members when displaying a C@t{++} object. The default is on.
5767
5768 @item set print static-members off
5769 Do not print static members when displaying a C@t{++} object.
5770
5771 @item show print static-members
5772 Show whether C@t{++} static members are printed or not.
5773
5774 @item set print pascal_static-members
5775 @itemx set print pascal_static-members on
5776 @cindex static members of Pacal objects
5777 @cindex Pacal objects, static members display
5778 Print static members when displaying a Pascal object. The default is on.
5779
5780 @item set print pascal_static-members off
5781 Do not print static members when displaying a Pascal object.
5782
5783 @item show print pascal_static-members
5784 Show whether Pascal static members are printed or not.
5785
5786 @c These don't work with HP ANSI C++ yet.
5787 @item set print vtbl
5788 @itemx set print vtbl on
5789 @cindex pretty print C@t{++} virtual function tables
5790 @cindex virtual functions (C@t{++}) display
5791 @cindex VTBL display
5792 Pretty print C@t{++} virtual function tables. The default is off.
5793 (The @code{vtbl} commands do not work on programs compiled with the HP
5794 ANSI C@t{++} compiler (@code{aCC}).)
5795
5796 @item set print vtbl off
5797 Do not pretty print C@t{++} virtual function tables.
5798
5799 @item show print vtbl
5800 Show whether C@t{++} virtual function tables are pretty printed, or not.
5801 @end table
5802
5803 @node Value History
5804 @section Value history
5805
5806 @cindex value history
5807 @cindex history of values printed by @value{GDBN}
5808 Values printed by the @code{print} command are saved in the @value{GDBN}
5809 @dfn{value history}. This allows you to refer to them in other expressions.
5810 Values are kept until the symbol table is re-read or discarded
5811 (for example with the @code{file} or @code{symbol-file} commands).
5812 When the symbol table changes, the value history is discarded,
5813 since the values may contain pointers back to the types defined in the
5814 symbol table.
5815
5816 @cindex @code{$}
5817 @cindex @code{$$}
5818 @cindex history number
5819 The values printed are given @dfn{history numbers} by which you can
5820 refer to them. These are successive integers starting with one.
5821 @code{print} shows you the history number assigned to a value by
5822 printing @samp{$@var{num} = } before the value; here @var{num} is the
5823 history number.
5824
5825 To refer to any previous value, use @samp{$} followed by the value's
5826 history number. The way @code{print} labels its output is designed to
5827 remind you of this. Just @code{$} refers to the most recent value in
5828 the history, and @code{$$} refers to the value before that.
5829 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5830 is the value just prior to @code{$$}, @code{$$1} is equivalent to
5831 @code{$$}, and @code{$$0} is equivalent to @code{$}.
5832
5833 For example, suppose you have just printed a pointer to a structure and
5834 want to see the contents of the structure. It suffices to type
5835
5836 @smallexample
5837 p *$
5838 @end smallexample
5839
5840 If you have a chain of structures where the component @code{next} points
5841 to the next one, you can print the contents of the next one with this:
5842
5843 @smallexample
5844 p *$.next
5845 @end smallexample
5846
5847 @noindent
5848 You can print successive links in the chain by repeating this
5849 command---which you can do by just typing @key{RET}.
5850
5851 Note that the history records values, not expressions. If the value of
5852 @code{x} is 4 and you type these commands:
5853
5854 @smallexample
5855 print x
5856 set x=5
5857 @end smallexample
5858
5859 @noindent
5860 then the value recorded in the value history by the @code{print} command
5861 remains 4 even though the value of @code{x} has changed.
5862
5863 @table @code
5864 @kindex show values
5865 @item show values
5866 Print the last ten values in the value history, with their item numbers.
5867 This is like @samp{p@ $$9} repeated ten times, except that @code{show
5868 values} does not change the history.
5869
5870 @item show values @var{n}
5871 Print ten history values centered on history item number @var{n}.
5872
5873 @item show values +
5874 Print ten history values just after the values last printed. If no more
5875 values are available, @code{show values +} produces no display.
5876 @end table
5877
5878 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5879 same effect as @samp{show values +}.
5880
5881 @node Convenience Vars
5882 @section Convenience variables
5883
5884 @cindex convenience variables
5885 @cindex user-defined variables
5886 @value{GDBN} provides @dfn{convenience variables} that you can use within
5887 @value{GDBN} to hold on to a value and refer to it later. These variables
5888 exist entirely within @value{GDBN}; they are not part of your program, and
5889 setting a convenience variable has no direct effect on further execution
5890 of your program. That is why you can use them freely.
5891
5892 Convenience variables are prefixed with @samp{$}. Any name preceded by
5893 @samp{$} can be used for a convenience variable, unless it is one of
5894 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
5895 (Value history references, in contrast, are @emph{numbers} preceded
5896 by @samp{$}. @xref{Value History, ,Value history}.)
5897
5898 You can save a value in a convenience variable with an assignment
5899 expression, just as you would set a variable in your program.
5900 For example:
5901
5902 @smallexample
5903 set $foo = *object_ptr
5904 @end smallexample
5905
5906 @noindent
5907 would save in @code{$foo} the value contained in the object pointed to by
5908 @code{object_ptr}.
5909
5910 Using a convenience variable for the first time creates it, but its
5911 value is @code{void} until you assign a new value. You can alter the
5912 value with another assignment at any time.
5913
5914 Convenience variables have no fixed types. You can assign a convenience
5915 variable any type of value, including structures and arrays, even if
5916 that variable already has a value of a different type. The convenience
5917 variable, when used as an expression, has the type of its current value.
5918
5919 @table @code
5920 @kindex show convenience
5921 @cindex show all user variables
5922 @item show convenience
5923 Print a list of convenience variables used so far, and their values.
5924 Abbreviated @code{show conv}.
5925 @end table
5926
5927 One of the ways to use a convenience variable is as a counter to be
5928 incremented or a pointer to be advanced. For example, to print
5929 a field from successive elements of an array of structures:
5930
5931 @smallexample
5932 set $i = 0
5933 print bar[$i++]->contents
5934 @end smallexample
5935
5936 @noindent
5937 Repeat that command by typing @key{RET}.
5938
5939 Some convenience variables are created automatically by @value{GDBN} and given
5940 values likely to be useful.
5941
5942 @table @code
5943 @vindex $_@r{, convenience variable}
5944 @item $_
5945 The variable @code{$_} is automatically set by the @code{x} command to
5946 the last address examined (@pxref{Memory, ,Examining memory}). Other
5947 commands which provide a default address for @code{x} to examine also
5948 set @code{$_} to that address; these commands include @code{info line}
5949 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5950 except when set by the @code{x} command, in which case it is a pointer
5951 to the type of @code{$__}.
5952
5953 @vindex $__@r{, convenience variable}
5954 @item $__
5955 The variable @code{$__} is automatically set by the @code{x} command
5956 to the value found in the last address examined. Its type is chosen
5957 to match the format in which the data was printed.
5958
5959 @item $_exitcode
5960 @vindex $_exitcode@r{, convenience variable}
5961 The variable @code{$_exitcode} is automatically set to the exit code when
5962 the program being debugged terminates.
5963 @end table
5964
5965 On HP-UX systems, if you refer to a function or variable name that
5966 begins with a dollar sign, @value{GDBN} searches for a user or system
5967 name first, before it searches for a convenience variable.
5968
5969 @node Registers
5970 @section Registers
5971
5972 @cindex registers
5973 You can refer to machine register contents, in expressions, as variables
5974 with names starting with @samp{$}. The names of registers are different
5975 for each machine; use @code{info registers} to see the names used on
5976 your machine.
5977
5978 @table @code
5979 @kindex info registers
5980 @item info registers
5981 Print the names and values of all registers except floating-point
5982 and vector registers (in the selected stack frame).
5983
5984 @kindex info all-registers
5985 @cindex floating point registers
5986 @item info all-registers
5987 Print the names and values of all registers, including floating-point
5988 and vector registers (in the selected stack frame).
5989
5990 @item info registers @var{regname} @dots{}
5991 Print the @dfn{relativized} value of each specified register @var{regname}.
5992 As discussed in detail below, register values are normally relative to
5993 the selected stack frame. @var{regname} may be any register name valid on
5994 the machine you are using, with or without the initial @samp{$}.
5995 @end table
5996
5997 @value{GDBN} has four ``standard'' register names that are available (in
5998 expressions) on most machines---whenever they do not conflict with an
5999 architecture's canonical mnemonics for registers. The register names
6000 @code{$pc} and @code{$sp} are used for the program counter register and
6001 the stack pointer. @code{$fp} is used for a register that contains a
6002 pointer to the current stack frame, and @code{$ps} is used for a
6003 register that contains the processor status. For example,
6004 you could print the program counter in hex with
6005
6006 @smallexample
6007 p/x $pc
6008 @end smallexample
6009
6010 @noindent
6011 or print the instruction to be executed next with
6012
6013 @smallexample
6014 x/i $pc
6015 @end smallexample
6016
6017 @noindent
6018 or add four to the stack pointer@footnote{This is a way of removing
6019 one word from the stack, on machines where stacks grow downward in
6020 memory (most machines, nowadays). This assumes that the innermost
6021 stack frame is selected; setting @code{$sp} is not allowed when other
6022 stack frames are selected. To pop entire frames off the stack,
6023 regardless of machine architecture, use @code{return};
6024 see @ref{Returning, ,Returning from a function}.} with
6025
6026 @smallexample
6027 set $sp += 4
6028 @end smallexample
6029
6030 Whenever possible, these four standard register names are available on
6031 your machine even though the machine has different canonical mnemonics,
6032 so long as there is no conflict. The @code{info registers} command
6033 shows the canonical names. For example, on the SPARC, @code{info
6034 registers} displays the processor status register as @code{$psr} but you
6035 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6036 is an alias for the @sc{eflags} register.
6037
6038 @value{GDBN} always considers the contents of an ordinary register as an
6039 integer when the register is examined in this way. Some machines have
6040 special registers which can hold nothing but floating point; these
6041 registers are considered to have floating point values. There is no way
6042 to refer to the contents of an ordinary register as floating point value
6043 (although you can @emph{print} it as a floating point value with
6044 @samp{print/f $@var{regname}}).
6045
6046 Some registers have distinct ``raw'' and ``virtual'' data formats. This
6047 means that the data format in which the register contents are saved by
6048 the operating system is not the same one that your program normally
6049 sees. For example, the registers of the 68881 floating point
6050 coprocessor are always saved in ``extended'' (raw) format, but all C
6051 programs expect to work with ``double'' (virtual) format. In such
6052 cases, @value{GDBN} normally works with the virtual format only (the format
6053 that makes sense for your program), but the @code{info registers} command
6054 prints the data in both formats.
6055
6056 Normally, register values are relative to the selected stack frame
6057 (@pxref{Selection, ,Selecting a frame}). This means that you get the
6058 value that the register would contain if all stack frames farther in
6059 were exited and their saved registers restored. In order to see the
6060 true contents of hardware registers, you must select the innermost
6061 frame (with @samp{frame 0}).
6062
6063 However, @value{GDBN} must deduce where registers are saved, from the machine
6064 code generated by your compiler. If some registers are not saved, or if
6065 @value{GDBN} is unable to locate the saved registers, the selected stack
6066 frame makes no difference.
6067
6068 @node Floating Point Hardware
6069 @section Floating point hardware
6070 @cindex floating point
6071
6072 Depending on the configuration, @value{GDBN} may be able to give
6073 you more information about the status of the floating point hardware.
6074
6075 @table @code
6076 @kindex info float
6077 @item info float
6078 Display hardware-dependent information about the floating
6079 point unit. The exact contents and layout vary depending on the
6080 floating point chip. Currently, @samp{info float} is supported on
6081 the ARM and x86 machines.
6082 @end table
6083
6084 @node Vector Unit
6085 @section Vector Unit
6086 @cindex vector unit
6087
6088 Depending on the configuration, @value{GDBN} may be able to give you
6089 more information about the status of the vector unit.
6090
6091 @table @code
6092 @kindex info vector
6093 @item info vector
6094 Display information about the vector unit. The exact contents and
6095 layout vary depending on the hardware.
6096 @end table
6097
6098 @node OS Information
6099 @section Operating system auxiliary information
6100 @cindex OS information
6101
6102 @value{GDBN} provides interfaces to useful OS facilities that can help
6103 you debug your program.
6104
6105 @cindex @code{ptrace} system call
6106 @cindex @code{struct user} contents
6107 When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6108 machines), it interfaces with the inferior via the @code{ptrace}
6109 system call. The operating system creates a special sata structure,
6110 called @code{struct user}, for this interface. You can use the
6111 command @code{info udot} to display the contents of this data
6112 structure.
6113
6114 @table @code
6115 @item info udot
6116 @kindex info udot
6117 Display the contents of the @code{struct user} maintained by the OS
6118 kernel for the program being debugged. @value{GDBN} displays the
6119 contents of @code{struct user} as a list of hex numbers, similar to
6120 the @code{examine} command.
6121 @end table
6122
6123 @cindex auxiliary vector
6124 @cindex vector, auxiliary
6125 Some operating systems supply an @dfn{auxiliary vector} to programs at
6126 startup. This is akin to the arguments and environment that you
6127 specify for a program, but contains a system-dependent variety of
6128 binary values that tell system libraries important details about the
6129 hardware, operating system, and process. Each value's purpose is
6130 identified by an integer tag; the meanings are well-known but system-specific.
6131 Depending on the configuration and operating system facilities,
6132 @value{GDBN} may be able to show you this information. For remote
6133 targets, this functionality may further depend on the remote stub's
6134 support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6135 configuration, auxiliary vector}.
6136
6137 @table @code
6138 @kindex info auxv
6139 @item info auxv
6140 Display the auxiliary vector of the inferior, which can be either a
6141 live process or a core dump file. @value{GDBN} prints each tag value
6142 numerically, and also shows names and text descriptions for recognized
6143 tags. Some values in the vector are numbers, some bit masks, and some
6144 pointers to strings or other data. @value{GDBN} displays each value in the
6145 most appropriate form for a recognized tag, and in hexadecimal for
6146 an unrecognized tag.
6147 @end table
6148
6149
6150 @node Memory Region Attributes
6151 @section Memory region attributes
6152 @cindex memory region attributes
6153
6154 @dfn{Memory region attributes} allow you to describe special handling
6155 required by regions of your target's memory. @value{GDBN} uses attributes
6156 to determine whether to allow certain types of memory accesses; whether to
6157 use specific width accesses; and whether to cache target memory.
6158
6159 Defined memory regions can be individually enabled and disabled. When a
6160 memory region is disabled, @value{GDBN} uses the default attributes when
6161 accessing memory in that region. Similarly, if no memory regions have
6162 been defined, @value{GDBN} uses the default attributes when accessing
6163 all memory.
6164
6165 When a memory region is defined, it is given a number to identify it;
6166 to enable, disable, or remove a memory region, you specify that number.
6167
6168 @table @code
6169 @kindex mem
6170 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
6171 Define a memory region bounded by @var{lower} and @var{upper} with
6172 attributes @var{attributes}@dots{}, and add it to the list of regions
6173 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6174 case: it is treated as the the target's maximum memory address.
6175 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
6176
6177 @kindex delete mem
6178 @item delete mem @var{nums}@dots{}
6179 Remove memory regions @var{nums}@dots{} from the list of regions
6180 monitored by @value{GDBN}.
6181
6182 @kindex disable mem
6183 @item disable mem @var{nums}@dots{}
6184 Disable monitoring of memory regions @var{nums}@dots{}.
6185 A disabled memory region is not forgotten.
6186 It may be enabled again later.
6187
6188 @kindex enable mem
6189 @item enable mem @var{nums}@dots{}
6190 Enable monitoring of memory regions @var{nums}@dots{}.
6191
6192 @kindex info mem
6193 @item info mem
6194 Print a table of all defined memory regions, with the following columns
6195 for each region:
6196
6197 @table @emph
6198 @item Memory Region Number
6199 @item Enabled or Disabled.
6200 Enabled memory regions are marked with @samp{y}.
6201 Disabled memory regions are marked with @samp{n}.
6202
6203 @item Lo Address
6204 The address defining the inclusive lower bound of the memory region.
6205
6206 @item Hi Address
6207 The address defining the exclusive upper bound of the memory region.
6208
6209 @item Attributes
6210 The list of attributes set for this memory region.
6211 @end table
6212 @end table
6213
6214
6215 @subsection Attributes
6216
6217 @subsubsection Memory Access Mode
6218 The access mode attributes set whether @value{GDBN} may make read or
6219 write accesses to a memory region.
6220
6221 While these attributes prevent @value{GDBN} from performing invalid
6222 memory accesses, they do nothing to prevent the target system, I/O DMA,
6223 etc. from accessing memory.
6224
6225 @table @code
6226 @item ro
6227 Memory is read only.
6228 @item wo
6229 Memory is write only.
6230 @item rw
6231 Memory is read/write. This is the default.
6232 @end table
6233
6234 @subsubsection Memory Access Size
6235 The acccess size attributes tells @value{GDBN} to use specific sized
6236 accesses in the memory region. Often memory mapped device registers
6237 require specific sized accesses. If no access size attribute is
6238 specified, @value{GDBN} may use accesses of any size.
6239
6240 @table @code
6241 @item 8
6242 Use 8 bit memory accesses.
6243 @item 16
6244 Use 16 bit memory accesses.
6245 @item 32
6246 Use 32 bit memory accesses.
6247 @item 64
6248 Use 64 bit memory accesses.
6249 @end table
6250
6251 @c @subsubsection Hardware/Software Breakpoints
6252 @c The hardware/software breakpoint attributes set whether @value{GDBN}
6253 @c will use hardware or software breakpoints for the internal breakpoints
6254 @c used by the step, next, finish, until, etc. commands.
6255 @c
6256 @c @table @code
6257 @c @item hwbreak
6258 @c Always use hardware breakpoints
6259 @c @item swbreak (default)
6260 @c @end table
6261
6262 @subsubsection Data Cache
6263 The data cache attributes set whether @value{GDBN} will cache target
6264 memory. While this generally improves performance by reducing debug
6265 protocol overhead, it can lead to incorrect results because @value{GDBN}
6266 does not know about volatile variables or memory mapped device
6267 registers.
6268
6269 @table @code
6270 @item cache
6271 Enable @value{GDBN} to cache target memory.
6272 @item nocache
6273 Disable @value{GDBN} from caching target memory. This is the default.
6274 @end table
6275
6276 @c @subsubsection Memory Write Verification
6277 @c The memory write verification attributes set whether @value{GDBN}
6278 @c will re-reads data after each write to verify the write was successful.
6279 @c
6280 @c @table @code
6281 @c @item verify
6282 @c @item noverify (default)
6283 @c @end table
6284
6285 @node Dump/Restore Files
6286 @section Copy between memory and a file
6287 @cindex dump/restore files
6288 @cindex append data to a file
6289 @cindex dump data to a file
6290 @cindex restore data from a file
6291
6292 You can use the commands @code{dump}, @code{append}, and
6293 @code{restore} to copy data between target memory and a file. The
6294 @code{dump} and @code{append} commands write data to a file, and the
6295 @code{restore} command reads data from a file back into the inferior's
6296 memory. Files may be in binary, Motorola S-record, Intel hex, or
6297 Tektronix Hex format; however, @value{GDBN} can only append to binary
6298 files.
6299
6300 @table @code
6301
6302 @kindex dump
6303 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6304 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6305 Dump the contents of memory from @var{start_addr} to @var{end_addr},
6306 or the value of @var{expr}, to @var{filename} in the given format.
6307
6308 The @var{format} parameter may be any one of:
6309 @table @code
6310 @item binary
6311 Raw binary form.
6312 @item ihex
6313 Intel hex format.
6314 @item srec
6315 Motorola S-record format.
6316 @item tekhex
6317 Tektronix Hex format.
6318 @end table
6319
6320 @value{GDBN} uses the same definitions of these formats as the
6321 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6322 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
6323 form.
6324
6325 @kindex append
6326 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6327 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6328 Append the contents of memory from @var{start_addr} to @var{end_addr},
6329 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
6330 (@value{GDBN} can only append data to files in raw binary form.)
6331
6332 @kindex restore
6333 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6334 Restore the contents of file @var{filename} into memory. The
6335 @code{restore} command can automatically recognize any known @sc{bfd}
6336 file format, except for raw binary. To restore a raw binary file you
6337 must specify the optional keyword @code{binary} after the filename.
6338
6339 If @var{bias} is non-zero, its value will be added to the addresses
6340 contained in the file. Binary files always start at address zero, so
6341 they will be restored at address @var{bias}. Other bfd files have
6342 a built-in location; they will be restored at offset @var{bias}
6343 from that location.
6344
6345 If @var{start} and/or @var{end} are non-zero, then only data between
6346 file offset @var{start} and file offset @var{end} will be restored.
6347 These offsets are relative to the addresses in the file, before
6348 the @var{bias} argument is applied.
6349
6350 @end table
6351
6352 @node Core File Generation
6353 @section How to Produce a Core File from Your Program
6354 @cindex dump core from inferior
6355
6356 A @dfn{core file} or @dfn{core dump} is a file that records the memory
6357 image of a running process and its process status (register values
6358 etc.). Its primary use is post-mortem debugging of a program that
6359 crashed while it ran outside a debugger. A program that crashes
6360 automatically produces a core file, unless this feature is disabled by
6361 the user. @xref{Files}, for information on invoking @value{GDBN} in
6362 the post-mortem debugging mode.
6363
6364 Occasionally, you may wish to produce a core file of the program you
6365 are debugging in order to preserve a snapshot of its state.
6366 @value{GDBN} has a special command for that.
6367
6368 @table @code
6369 @kindex gcore
6370 @kindex generate-core-file
6371 @item generate-core-file [@var{file}]
6372 @itemx gcore [@var{file}]
6373 Produce a core dump of the inferior process. The optional argument
6374 @var{file} specifies the file name where to put the core dump. If not
6375 specified, the file name defaults to @file{core.@var{pid}}, where
6376 @var{pid} is the inferior process ID.
6377
6378 Note that this command is implemented only for some systems (as of
6379 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6380 @end table
6381
6382 @node Character Sets
6383 @section Character Sets
6384 @cindex character sets
6385 @cindex charset
6386 @cindex translating between character sets
6387 @cindex host character set
6388 @cindex target character set
6389
6390 If the program you are debugging uses a different character set to
6391 represent characters and strings than the one @value{GDBN} uses itself,
6392 @value{GDBN} can automatically translate between the character sets for
6393 you. The character set @value{GDBN} uses we call the @dfn{host
6394 character set}; the one the inferior program uses we call the
6395 @dfn{target character set}.
6396
6397 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6398 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6399 remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6400 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6401 then the host character set is Latin-1, and the target character set is
6402 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
6403 target-charset EBCDIC-US}, then @value{GDBN} translates between
6404 @sc{ebcdic} and Latin 1 as you print character or string values, or use
6405 character and string literals in expressions.
6406
6407 @value{GDBN} has no way to automatically recognize which character set
6408 the inferior program uses; you must tell it, using the @code{set
6409 target-charset} command, described below.
6410
6411 Here are the commands for controlling @value{GDBN}'s character set
6412 support:
6413
6414 @table @code
6415 @item set target-charset @var{charset}
6416 @kindex set target-charset
6417 Set the current target character set to @var{charset}. We list the
6418 character set names @value{GDBN} recognizes below, but if you type
6419 @code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6420 list the target character sets it supports.
6421 @end table
6422
6423 @table @code
6424 @item set host-charset @var{charset}
6425 @kindex set host-charset
6426 Set the current host character set to @var{charset}.
6427
6428 By default, @value{GDBN} uses a host character set appropriate to the
6429 system it is running on; you can override that default using the
6430 @code{set host-charset} command.
6431
6432 @value{GDBN} can only use certain character sets as its host character
6433 set. We list the character set names @value{GDBN} recognizes below, and
6434 indicate which can be host character sets, but if you type
6435 @code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6436 list the host character sets it supports.
6437
6438 @item set charset @var{charset}
6439 @kindex set charset
6440 Set the current host and target character sets to @var{charset}. As
6441 above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6442 @value{GDBN} will list the name of the character sets that can be used
6443 for both host and target.
6444
6445
6446 @item show charset
6447 @kindex show charset
6448 Show the names of the current host and target charsets.
6449
6450 @itemx show host-charset
6451 @kindex show host-charset
6452 Show the name of the current host charset.
6453
6454 @itemx show target-charset
6455 @kindex show target-charset
6456 Show the name of the current target charset.
6457
6458 @end table
6459
6460 @value{GDBN} currently includes support for the following character
6461 sets:
6462
6463 @table @code
6464
6465 @item ASCII
6466 @cindex ASCII character set
6467 Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6468 character set.
6469
6470 @item ISO-8859-1
6471 @cindex ISO 8859-1 character set
6472 @cindex ISO Latin 1 character set
6473 The ISO Latin 1 character set. This extends @sc{ascii} with accented
6474 characters needed for French, German, and Spanish. @value{GDBN} can use
6475 this as its host character set.
6476
6477 @item EBCDIC-US
6478 @itemx IBM1047
6479 @cindex EBCDIC character set
6480 @cindex IBM1047 character set
6481 Variants of the @sc{ebcdic} character set, used on some of IBM's
6482 mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6483 @value{GDBN} cannot use these as its host character set.
6484
6485 @end table
6486
6487 Note that these are all single-byte character sets. More work inside
6488 GDB is needed to support multi-byte or variable-width character
6489 encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6490
6491 Here is an example of @value{GDBN}'s character set support in action.
6492 Assume that the following source code has been placed in the file
6493 @file{charset-test.c}:
6494
6495 @smallexample
6496 #include <stdio.h>
6497
6498 char ascii_hello[]
6499 = @{72, 101, 108, 108, 111, 44, 32, 119,
6500 111, 114, 108, 100, 33, 10, 0@};
6501 char ibm1047_hello[]
6502 = @{200, 133, 147, 147, 150, 107, 64, 166,
6503 150, 153, 147, 132, 90, 37, 0@};
6504
6505 main ()
6506 @{
6507 printf ("Hello, world!\n");
6508 @}
6509 @end smallexample
6510
6511 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6512 containing the string @samp{Hello, world!} followed by a newline,
6513 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6514
6515 We compile the program, and invoke the debugger on it:
6516
6517 @smallexample
6518 $ gcc -g charset-test.c -o charset-test
6519 $ gdb -nw charset-test
6520 GNU gdb 2001-12-19-cvs
6521 Copyright 2001 Free Software Foundation, Inc.
6522 @dots{}
6523 (@value{GDBP})
6524 @end smallexample
6525
6526 We can use the @code{show charset} command to see what character sets
6527 @value{GDBN} is currently using to interpret and display characters and
6528 strings:
6529
6530 @smallexample
6531 (@value{GDBP}) show charset
6532 The current host and target character set is `ISO-8859-1'.
6533 (@value{GDBP})
6534 @end smallexample
6535
6536 For the sake of printing this manual, let's use @sc{ascii} as our
6537 initial character set:
6538 @smallexample
6539 (@value{GDBP}) set charset ASCII
6540 (@value{GDBP}) show charset
6541 The current host and target character set is `ASCII'.
6542 (@value{GDBP})
6543 @end smallexample
6544
6545 Let's assume that @sc{ascii} is indeed the correct character set for our
6546 host system --- in other words, let's assume that if @value{GDBN} prints
6547 characters using the @sc{ascii} character set, our terminal will display
6548 them properly. Since our current target character set is also
6549 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
6550
6551 @smallexample
6552 (@value{GDBP}) print ascii_hello
6553 $1 = 0x401698 "Hello, world!\n"
6554 (@value{GDBP}) print ascii_hello[0]
6555 $2 = 72 'H'
6556 (@value{GDBP})
6557 @end smallexample
6558
6559 @value{GDBN} uses the target character set for character and string
6560 literals you use in expressions:
6561
6562 @smallexample
6563 (@value{GDBP}) print '+'
6564 $3 = 43 '+'
6565 (@value{GDBP})
6566 @end smallexample
6567
6568 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6569 character.
6570
6571 @value{GDBN} relies on the user to tell it which character set the
6572 target program uses. If we print @code{ibm1047_hello} while our target
6573 character set is still @sc{ascii}, we get jibberish:
6574
6575 @smallexample
6576 (@value{GDBP}) print ibm1047_hello
6577 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
6578 (@value{GDBP}) print ibm1047_hello[0]
6579 $5 = 200 '\310'
6580 (@value{GDBP})
6581 @end smallexample
6582
6583 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
6584 @value{GDBN} tells us the character sets it supports:
6585
6586 @smallexample
6587 (@value{GDBP}) set target-charset
6588 ASCII EBCDIC-US IBM1047 ISO-8859-1
6589 (@value{GDBP}) set target-charset
6590 @end smallexample
6591
6592 We can select @sc{ibm1047} as our target character set, and examine the
6593 program's strings again. Now the @sc{ascii} string is wrong, but
6594 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
6595 target character set, @sc{ibm1047}, to the host character set,
6596 @sc{ascii}, and they display correctly:
6597
6598 @smallexample
6599 (@value{GDBP}) set target-charset IBM1047
6600 (@value{GDBP}) show charset
6601 The current host character set is `ASCII'.
6602 The current target character set is `IBM1047'.
6603 (@value{GDBP}) print ascii_hello
6604 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6605 (@value{GDBP}) print ascii_hello[0]
6606 $7 = 72 '\110'
6607 (@value{GDBP}) print ibm1047_hello
6608 $8 = 0x4016a8 "Hello, world!\n"
6609 (@value{GDBP}) print ibm1047_hello[0]
6610 $9 = 200 'H'
6611 (@value{GDBP})
6612 @end smallexample
6613
6614 As above, @value{GDBN} uses the target character set for character and
6615 string literals you use in expressions:
6616
6617 @smallexample
6618 (@value{GDBP}) print '+'
6619 $10 = 78 '+'
6620 (@value{GDBP})
6621 @end smallexample
6622
6623 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
6624 character.
6625
6626 @node Caching Remote Data
6627 @section Caching Data of Remote Targets
6628 @cindex caching data of remote targets
6629
6630 @value{GDBN} can cache data exchanged between the debugger and a
6631 remote target (@pxref{Remote}). Such caching generally improves
6632 performance, because it reduces the overhead of the remote protocol by
6633 bundling memory reads and writes into large chunks. Unfortunately,
6634 @value{GDBN} does not currently know anything about volatile
6635 registers, and thus data caching will produce incorrect results when
6636 volatile registers are in use.
6637
6638 @table @code
6639 @kindex set remotecache
6640 @item set remotecache on
6641 @itemx set remotecache off
6642 Set caching state for remote targets. When @code{ON}, use data
6643 caching. By default, this option is @code{OFF}.
6644
6645 @kindex show remotecache
6646 @item show remotecache
6647 Show the current state of data caching for remote targets.
6648
6649 @kindex info dcache
6650 @item info dcache
6651 Print the information about the data cache performance. The
6652 information displayed includes: the dcache width and depth; and for
6653 each cache line, how many times it was referenced, and its data and
6654 state (dirty, bad, ok, etc.). This command is useful for debugging
6655 the data cache operation.
6656 @end table
6657
6658
6659 @node Macros
6660 @chapter C Preprocessor Macros
6661
6662 Some languages, such as C and C@t{++}, provide a way to define and invoke
6663 ``preprocessor macros'' which expand into strings of tokens.
6664 @value{GDBN} can evaluate expressions containing macro invocations, show
6665 the result of macro expansion, and show a macro's definition, including
6666 where it was defined.
6667
6668 You may need to compile your program specially to provide @value{GDBN}
6669 with information about preprocessor macros. Most compilers do not
6670 include macros in their debugging information, even when you compile
6671 with the @option{-g} flag. @xref{Compilation}.
6672
6673 A program may define a macro at one point, remove that definition later,
6674 and then provide a different definition after that. Thus, at different
6675 points in the program, a macro may have different definitions, or have
6676 no definition at all. If there is a current stack frame, @value{GDBN}
6677 uses the macros in scope at that frame's source code line. Otherwise,
6678 @value{GDBN} uses the macros in scope at the current listing location;
6679 see @ref{List}.
6680
6681 At the moment, @value{GDBN} does not support the @code{##}
6682 token-splicing operator, the @code{#} stringification operator, or
6683 variable-arity macros.
6684
6685 Whenever @value{GDBN} evaluates an expression, it always expands any
6686 macro invocations present in the expression. @value{GDBN} also provides
6687 the following commands for working with macros explicitly.
6688
6689 @table @code
6690
6691 @kindex macro expand
6692 @cindex macro expansion, showing the results of preprocessor
6693 @cindex preprocessor macro expansion, showing the results of
6694 @cindex expanding preprocessor macros
6695 @item macro expand @var{expression}
6696 @itemx macro exp @var{expression}
6697 Show the results of expanding all preprocessor macro invocations in
6698 @var{expression}. Since @value{GDBN} simply expands macros, but does
6699 not parse the result, @var{expression} need not be a valid expression;
6700 it can be any string of tokens.
6701
6702 @kindex macro exp1
6703 @item macro expand-once @var{expression}
6704 @itemx macro exp1 @var{expression}
6705 @cindex expand macro once
6706 @i{(This command is not yet implemented.)} Show the results of
6707 expanding those preprocessor macro invocations that appear explicitly in
6708 @var{expression}. Macro invocations appearing in that expansion are
6709 left unchanged. This command allows you to see the effect of a
6710 particular macro more clearly, without being confused by further
6711 expansions. Since @value{GDBN} simply expands macros, but does not
6712 parse the result, @var{expression} need not be a valid expression; it
6713 can be any string of tokens.
6714
6715 @kindex info macro
6716 @cindex macro definition, showing
6717 @cindex definition, showing a macro's
6718 @item info macro @var{macro}
6719 Show the definition of the macro named @var{macro}, and describe the
6720 source location where that definition was established.
6721
6722 @kindex macro define
6723 @cindex user-defined macros
6724 @cindex defining macros interactively
6725 @cindex macros, user-defined
6726 @item macro define @var{macro} @var{replacement-list}
6727 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6728 @i{(This command is not yet implemented.)} Introduce a definition for a
6729 preprocessor macro named @var{macro}, invocations of which are replaced
6730 by the tokens given in @var{replacement-list}. The first form of this
6731 command defines an ``object-like'' macro, which takes no arguments; the
6732 second form defines a ``function-like'' macro, which takes the arguments
6733 given in @var{arglist}.
6734
6735 A definition introduced by this command is in scope in every expression
6736 evaluated in @value{GDBN}, until it is removed with the @command{macro
6737 undef} command, described below. The definition overrides all
6738 definitions for @var{macro} present in the program being debugged, as
6739 well as any previous user-supplied definition.
6740
6741 @kindex macro undef
6742 @item macro undef @var{macro}
6743 @i{(This command is not yet implemented.)} Remove any user-supplied
6744 definition for the macro named @var{macro}. This command only affects
6745 definitions provided with the @command{macro define} command, described
6746 above; it cannot remove definitions present in the program being
6747 debugged.
6748
6749 @kindex macro list
6750 @item macro list
6751 @i{(This command is not yet implemented.)} List all the macros
6752 defined using the @code{macro define} command.
6753 @end table
6754
6755 @cindex macros, example of debugging with
6756 Here is a transcript showing the above commands in action. First, we
6757 show our source files:
6758
6759 @smallexample
6760 $ cat sample.c
6761 #include <stdio.h>
6762 #include "sample.h"
6763
6764 #define M 42
6765 #define ADD(x) (M + x)
6766
6767 main ()
6768 @{
6769 #define N 28
6770 printf ("Hello, world!\n");
6771 #undef N
6772 printf ("We're so creative.\n");
6773 #define N 1729
6774 printf ("Goodbye, world!\n");
6775 @}
6776 $ cat sample.h
6777 #define Q <
6778 $
6779 @end smallexample
6780
6781 Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6782 We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6783 compiler includes information about preprocessor macros in the debugging
6784 information.
6785
6786 @smallexample
6787 $ gcc -gdwarf-2 -g3 sample.c -o sample
6788 $
6789 @end smallexample
6790
6791 Now, we start @value{GDBN} on our sample program:
6792
6793 @smallexample
6794 $ gdb -nw sample
6795 GNU gdb 2002-05-06-cvs
6796 Copyright 2002 Free Software Foundation, Inc.
6797 GDB is free software, @dots{}
6798 (@value{GDBP})
6799 @end smallexample
6800
6801 We can expand macros and examine their definitions, even when the
6802 program is not running. @value{GDBN} uses the current listing position
6803 to decide which macro definitions are in scope:
6804
6805 @smallexample
6806 (@value{GDBP}) list main
6807 3
6808 4 #define M 42
6809 5 #define ADD(x) (M + x)
6810 6
6811 7 main ()
6812 8 @{
6813 9 #define N 28
6814 10 printf ("Hello, world!\n");
6815 11 #undef N
6816 12 printf ("We're so creative.\n");
6817 (@value{GDBP}) info macro ADD
6818 Defined at /home/jimb/gdb/macros/play/sample.c:5
6819 #define ADD(x) (M + x)
6820 (@value{GDBP}) info macro Q
6821 Defined at /home/jimb/gdb/macros/play/sample.h:1
6822 included at /home/jimb/gdb/macros/play/sample.c:2
6823 #define Q <
6824 (@value{GDBP}) macro expand ADD(1)
6825 expands to: (42 + 1)
6826 (@value{GDBP}) macro expand-once ADD(1)
6827 expands to: once (M + 1)
6828 (@value{GDBP})
6829 @end smallexample
6830
6831 In the example above, note that @command{macro expand-once} expands only
6832 the macro invocation explicit in the original text --- the invocation of
6833 @code{ADD} --- but does not expand the invocation of the macro @code{M},
6834 which was introduced by @code{ADD}.
6835
6836 Once the program is running, GDB uses the macro definitions in force at
6837 the source line of the current stack frame:
6838
6839 @smallexample
6840 (@value{GDBP}) break main
6841 Breakpoint 1 at 0x8048370: file sample.c, line 10.
6842 (@value{GDBP}) run
6843 Starting program: /home/jimb/gdb/macros/play/sample
6844
6845 Breakpoint 1, main () at sample.c:10
6846 10 printf ("Hello, world!\n");
6847 (@value{GDBP})
6848 @end smallexample
6849
6850 At line 10, the definition of the macro @code{N} at line 9 is in force:
6851
6852 @smallexample
6853 (@value{GDBP}) info macro N
6854 Defined at /home/jimb/gdb/macros/play/sample.c:9
6855 #define N 28
6856 (@value{GDBP}) macro expand N Q M
6857 expands to: 28 < 42
6858 (@value{GDBP}) print N Q M
6859 $1 = 1
6860 (@value{GDBP})
6861 @end smallexample
6862
6863 As we step over directives that remove @code{N}'s definition, and then
6864 give it a new definition, @value{GDBN} finds the definition (or lack
6865 thereof) in force at each point:
6866
6867 @smallexample
6868 (@value{GDBP}) next
6869 Hello, world!
6870 12 printf ("We're so creative.\n");
6871 (@value{GDBP}) info macro N
6872 The symbol `N' has no definition as a C/C++ preprocessor macro
6873 at /home/jimb/gdb/macros/play/sample.c:12
6874 (@value{GDBP}) next
6875 We're so creative.
6876 14 printf ("Goodbye, world!\n");
6877 (@value{GDBP}) info macro N
6878 Defined at /home/jimb/gdb/macros/play/sample.c:13
6879 #define N 1729
6880 (@value{GDBP}) macro expand N Q M
6881 expands to: 1729 < 42
6882 (@value{GDBP}) print N Q M
6883 $2 = 0
6884 (@value{GDBP})
6885 @end smallexample
6886
6887
6888 @node Tracepoints
6889 @chapter Tracepoints
6890 @c This chapter is based on the documentation written by Michael
6891 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6892
6893 @cindex tracepoints
6894 In some applications, it is not feasible for the debugger to interrupt
6895 the program's execution long enough for the developer to learn
6896 anything helpful about its behavior. If the program's correctness
6897 depends on its real-time behavior, delays introduced by a debugger
6898 might cause the program to change its behavior drastically, or perhaps
6899 fail, even when the code itself is correct. It is useful to be able
6900 to observe the program's behavior without interrupting it.
6901
6902 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6903 specify locations in the program, called @dfn{tracepoints}, and
6904 arbitrary expressions to evaluate when those tracepoints are reached.
6905 Later, using the @code{tfind} command, you can examine the values
6906 those expressions had when the program hit the tracepoints. The
6907 expressions may also denote objects in memory---structures or arrays,
6908 for example---whose values @value{GDBN} should record; while visiting
6909 a particular tracepoint, you may inspect those objects as if they were
6910 in memory at that moment. However, because @value{GDBN} records these
6911 values without interacting with you, it can do so quickly and
6912 unobtrusively, hopefully not disturbing the program's behavior.
6913
6914 The tracepoint facility is currently available only for remote
6915 targets. @xref{Targets}. In addition, your remote target must know how
6916 to collect trace data. This functionality is implemented in the remote
6917 stub; however, none of the stubs distributed with @value{GDBN} support
6918 tracepoints as of this writing.
6919
6920 This chapter describes the tracepoint commands and features.
6921
6922 @menu
6923 * Set Tracepoints::
6924 * Analyze Collected Data::
6925 * Tracepoint Variables::
6926 @end menu
6927
6928 @node Set Tracepoints
6929 @section Commands to Set Tracepoints
6930
6931 Before running such a @dfn{trace experiment}, an arbitrary number of
6932 tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6933 tracepoint has a number assigned to it by @value{GDBN}. Like with
6934 breakpoints, tracepoint numbers are successive integers starting from
6935 one. Many of the commands associated with tracepoints take the
6936 tracepoint number as their argument, to identify which tracepoint to
6937 work on.
6938
6939 For each tracepoint, you can specify, in advance, some arbitrary set
6940 of data that you want the target to collect in the trace buffer when
6941 it hits that tracepoint. The collected data can include registers,
6942 local variables, or global data. Later, you can use @value{GDBN}
6943 commands to examine the values these data had at the time the
6944 tracepoint was hit.
6945
6946 This section describes commands to set tracepoints and associated
6947 conditions and actions.
6948
6949 @menu
6950 * Create and Delete Tracepoints::
6951 * Enable and Disable Tracepoints::
6952 * Tracepoint Passcounts::
6953 * Tracepoint Actions::
6954 * Listing Tracepoints::
6955 * Starting and Stopping Trace Experiment::
6956 @end menu
6957
6958 @node Create and Delete Tracepoints
6959 @subsection Create and Delete Tracepoints
6960
6961 @table @code
6962 @cindex set tracepoint
6963 @kindex trace
6964 @item trace
6965 The @code{trace} command is very similar to the @code{break} command.
6966 Its argument can be a source line, a function name, or an address in
6967 the target program. @xref{Set Breaks}. The @code{trace} command
6968 defines a tracepoint, which is a point in the target program where the
6969 debugger will briefly stop, collect some data, and then allow the
6970 program to continue. Setting a tracepoint or changing its commands
6971 doesn't take effect until the next @code{tstart} command; thus, you
6972 cannot change the tracepoint attributes once a trace experiment is
6973 running.
6974
6975 Here are some examples of using the @code{trace} command:
6976
6977 @smallexample
6978 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6979
6980 (@value{GDBP}) @b{trace +2} // 2 lines forward
6981
6982 (@value{GDBP}) @b{trace my_function} // first source line of function
6983
6984 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6985
6986 (@value{GDBP}) @b{trace *0x2117c4} // an address
6987 @end smallexample
6988
6989 @noindent
6990 You can abbreviate @code{trace} as @code{tr}.
6991
6992 @vindex $tpnum
6993 @cindex last tracepoint number
6994 @cindex recent tracepoint number
6995 @cindex tracepoint number
6996 The convenience variable @code{$tpnum} records the tracepoint number
6997 of the most recently set tracepoint.
6998
6999 @kindex delete tracepoint
7000 @cindex tracepoint deletion
7001 @item delete tracepoint @r{[}@var{num}@r{]}
7002 Permanently delete one or more tracepoints. With no argument, the
7003 default is to delete all tracepoints.
7004
7005 Examples:
7006
7007 @smallexample
7008 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7009
7010 (@value{GDBP}) @b{delete trace} // remove all tracepoints
7011 @end smallexample
7012
7013 @noindent
7014 You can abbreviate this command as @code{del tr}.
7015 @end table
7016
7017 @node Enable and Disable Tracepoints
7018 @subsection Enable and Disable Tracepoints
7019
7020 @table @code
7021 @kindex disable tracepoint
7022 @item disable tracepoint @r{[}@var{num}@r{]}
7023 Disable tracepoint @var{num}, or all tracepoints if no argument
7024 @var{num} is given. A disabled tracepoint will have no effect during
7025 the next trace experiment, but it is not forgotten. You can re-enable
7026 a disabled tracepoint using the @code{enable tracepoint} command.
7027
7028 @kindex enable tracepoint
7029 @item enable tracepoint @r{[}@var{num}@r{]}
7030 Enable tracepoint @var{num}, or all tracepoints. The enabled
7031 tracepoints will become effective the next time a trace experiment is
7032 run.
7033 @end table
7034
7035 @node Tracepoint Passcounts
7036 @subsection Tracepoint Passcounts
7037
7038 @table @code
7039 @kindex passcount
7040 @cindex tracepoint pass count
7041 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7042 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7043 automatically stop a trace experiment. If a tracepoint's passcount is
7044 @var{n}, then the trace experiment will be automatically stopped on
7045 the @var{n}'th time that tracepoint is hit. If the tracepoint number
7046 @var{num} is not specified, the @code{passcount} command sets the
7047 passcount of the most recently defined tracepoint. If no passcount is
7048 given, the trace experiment will run until stopped explicitly by the
7049 user.
7050
7051 Examples:
7052
7053 @smallexample
7054 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
7055 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
7056
7057 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
7058 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
7059 (@value{GDBP}) @b{trace foo}
7060 (@value{GDBP}) @b{pass 3}
7061 (@value{GDBP}) @b{trace bar}
7062 (@value{GDBP}) @b{pass 2}
7063 (@value{GDBP}) @b{trace baz}
7064 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
7065 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7066 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7067 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
7068 @end smallexample
7069 @end table
7070
7071 @node Tracepoint Actions
7072 @subsection Tracepoint Action Lists
7073
7074 @table @code
7075 @kindex actions
7076 @cindex tracepoint actions
7077 @item actions @r{[}@var{num}@r{]}
7078 This command will prompt for a list of actions to be taken when the
7079 tracepoint is hit. If the tracepoint number @var{num} is not
7080 specified, this command sets the actions for the one that was most
7081 recently defined (so that you can define a tracepoint and then say
7082 @code{actions} without bothering about its number). You specify the
7083 actions themselves on the following lines, one action at a time, and
7084 terminate the actions list with a line containing just @code{end}. So
7085 far, the only defined actions are @code{collect} and
7086 @code{while-stepping}.
7087
7088 @cindex remove actions from a tracepoint
7089 To remove all actions from a tracepoint, type @samp{actions @var{num}}
7090 and follow it immediately with @samp{end}.
7091
7092 @smallexample
7093 (@value{GDBP}) @b{collect @var{data}} // collect some data
7094
7095 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
7096
7097 (@value{GDBP}) @b{end} // signals the end of actions.
7098 @end smallexample
7099
7100 In the following example, the action list begins with @code{collect}
7101 commands indicating the things to be collected when the tracepoint is
7102 hit. Then, in order to single-step and collect additional data
7103 following the tracepoint, a @code{while-stepping} command is used,
7104 followed by the list of things to be collected while stepping. The
7105 @code{while-stepping} command is terminated by its own separate
7106 @code{end} command. Lastly, the action list is terminated by an
7107 @code{end} command.
7108
7109 @smallexample
7110 (@value{GDBP}) @b{trace foo}
7111 (@value{GDBP}) @b{actions}
7112 Enter actions for tracepoint 1, one per line:
7113 > collect bar,baz
7114 > collect $regs
7115 > while-stepping 12
7116 > collect $fp, $sp
7117 > end
7118 end
7119 @end smallexample
7120
7121 @kindex collect @r{(tracepoints)}
7122 @item collect @var{expr1}, @var{expr2}, @dots{}
7123 Collect values of the given expressions when the tracepoint is hit.
7124 This command accepts a comma-separated list of any valid expressions.
7125 In addition to global, static, or local variables, the following
7126 special arguments are supported:
7127
7128 @table @code
7129 @item $regs
7130 collect all registers
7131
7132 @item $args
7133 collect all function arguments
7134
7135 @item $locals
7136 collect all local variables.
7137 @end table
7138
7139 You can give several consecutive @code{collect} commands, each one
7140 with a single argument, or one @code{collect} command with several
7141 arguments separated by commas: the effect is the same.
7142
7143 The command @code{info scope} (@pxref{Symbols, info scope}) is
7144 particularly useful for figuring out what data to collect.
7145
7146 @kindex while-stepping @r{(tracepoints)}
7147 @item while-stepping @var{n}
7148 Perform @var{n} single-step traces after the tracepoint, collecting
7149 new data at each step. The @code{while-stepping} command is
7150 followed by the list of what to collect while stepping (followed by
7151 its own @code{end} command):
7152
7153 @smallexample
7154 > while-stepping 12
7155 > collect $regs, myglobal
7156 > end
7157 >
7158 @end smallexample
7159
7160 @noindent
7161 You may abbreviate @code{while-stepping} as @code{ws} or
7162 @code{stepping}.
7163 @end table
7164
7165 @node Listing Tracepoints
7166 @subsection Listing Tracepoints
7167
7168 @table @code
7169 @kindex info tracepoints
7170 @kindex info tp
7171 @cindex information about tracepoints
7172 @item info tracepoints @r{[}@var{num}@r{]}
7173 Display information about the tracepoint @var{num}. If you don't specify
7174 a tracepoint number, displays information about all the tracepoints
7175 defined so far. For each tracepoint, the following information is
7176 shown:
7177
7178 @itemize @bullet
7179 @item
7180 its number
7181 @item
7182 whether it is enabled or disabled
7183 @item
7184 its address
7185 @item
7186 its passcount as given by the @code{passcount @var{n}} command
7187 @item
7188 its step count as given by the @code{while-stepping @var{n}} command
7189 @item
7190 where in the source files is the tracepoint set
7191 @item
7192 its action list as given by the @code{actions} command
7193 @end itemize
7194
7195 @smallexample
7196 (@value{GDBP}) @b{info trace}
7197 Num Enb Address PassC StepC What
7198 1 y 0x002117c4 0 0 <gdb_asm>
7199 2 y 0x0020dc64 0 0 in g_test at g_test.c:1375
7200 3 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
7201 (@value{GDBP})
7202 @end smallexample
7203
7204 @noindent
7205 This command can be abbreviated @code{info tp}.
7206 @end table
7207
7208 @node Starting and Stopping Trace Experiment
7209 @subsection Starting and Stopping Trace Experiment
7210
7211 @table @code
7212 @kindex tstart
7213 @cindex start a new trace experiment
7214 @cindex collected data discarded
7215 @item tstart
7216 This command takes no arguments. It starts the trace experiment, and
7217 begins collecting data. This has the side effect of discarding all
7218 the data collected in the trace buffer during the previous trace
7219 experiment.
7220
7221 @kindex tstop
7222 @cindex stop a running trace experiment
7223 @item tstop
7224 This command takes no arguments. It ends the trace experiment, and
7225 stops collecting data.
7226
7227 @strong{Note}: a trace experiment and data collection may stop
7228 automatically if any tracepoint's passcount is reached
7229 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7230
7231 @kindex tstatus
7232 @cindex status of trace data collection
7233 @cindex trace experiment, status of
7234 @item tstatus
7235 This command displays the status of the current trace data
7236 collection.
7237 @end table
7238
7239 Here is an example of the commands we described so far:
7240
7241 @smallexample
7242 (@value{GDBP}) @b{trace gdb_c_test}
7243 (@value{GDBP}) @b{actions}
7244 Enter actions for tracepoint #1, one per line.
7245 > collect $regs,$locals,$args
7246 > while-stepping 11
7247 > collect $regs
7248 > end
7249 > end
7250 (@value{GDBP}) @b{tstart}
7251 [time passes @dots{}]
7252 (@value{GDBP}) @b{tstop}
7253 @end smallexample
7254
7255
7256 @node Analyze Collected Data
7257 @section Using the collected data
7258
7259 After the tracepoint experiment ends, you use @value{GDBN} commands
7260 for examining the trace data. The basic idea is that each tracepoint
7261 collects a trace @dfn{snapshot} every time it is hit and another
7262 snapshot every time it single-steps. All these snapshots are
7263 consecutively numbered from zero and go into a buffer, and you can
7264 examine them later. The way you examine them is to @dfn{focus} on a
7265 specific trace snapshot. When the remote stub is focused on a trace
7266 snapshot, it will respond to all @value{GDBN} requests for memory and
7267 registers by reading from the buffer which belongs to that snapshot,
7268 rather than from @emph{real} memory or registers of the program being
7269 debugged. This means that @strong{all} @value{GDBN} commands
7270 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7271 behave as if we were currently debugging the program state as it was
7272 when the tracepoint occurred. Any requests for data that are not in
7273 the buffer will fail.
7274
7275 @menu
7276 * tfind:: How to select a trace snapshot
7277 * tdump:: How to display all data for a snapshot
7278 * save-tracepoints:: How to save tracepoints for a future run
7279 @end menu
7280
7281 @node tfind
7282 @subsection @code{tfind @var{n}}
7283
7284 @kindex tfind
7285 @cindex select trace snapshot
7286 @cindex find trace snapshot
7287 The basic command for selecting a trace snapshot from the buffer is
7288 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
7289 counting from zero. If no argument @var{n} is given, the next
7290 snapshot is selected.
7291
7292 Here are the various forms of using the @code{tfind} command.
7293
7294 @table @code
7295 @item tfind start
7296 Find the first snapshot in the buffer. This is a synonym for
7297 @code{tfind 0} (since 0 is the number of the first snapshot).
7298
7299 @item tfind none
7300 Stop debugging trace snapshots, resume @emph{live} debugging.
7301
7302 @item tfind end
7303 Same as @samp{tfind none}.
7304
7305 @item tfind
7306 No argument means find the next trace snapshot.
7307
7308 @item tfind -
7309 Find the previous trace snapshot before the current one. This permits
7310 retracing earlier steps.
7311
7312 @item tfind tracepoint @var{num}
7313 Find the next snapshot associated with tracepoint @var{num}. Search
7314 proceeds forward from the last examined trace snapshot. If no
7315 argument @var{num} is given, it means find the next snapshot collected
7316 for the same tracepoint as the current snapshot.
7317
7318 @item tfind pc @var{addr}
7319 Find the next snapshot associated with the value @var{addr} of the
7320 program counter. Search proceeds forward from the last examined trace
7321 snapshot. If no argument @var{addr} is given, it means find the next
7322 snapshot with the same value of PC as the current snapshot.
7323
7324 @item tfind outside @var{addr1}, @var{addr2}
7325 Find the next snapshot whose PC is outside the given range of
7326 addresses.
7327
7328 @item tfind range @var{addr1}, @var{addr2}
7329 Find the next snapshot whose PC is between @var{addr1} and
7330 @var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7331
7332 @item tfind line @r{[}@var{file}:@r{]}@var{n}
7333 Find the next snapshot associated with the source line @var{n}. If
7334 the optional argument @var{file} is given, refer to line @var{n} in
7335 that source file. Search proceeds forward from the last examined
7336 trace snapshot. If no argument @var{n} is given, it means find the
7337 next line other than the one currently being examined; thus saying
7338 @code{tfind line} repeatedly can appear to have the same effect as
7339 stepping from line to line in a @emph{live} debugging session.
7340 @end table
7341
7342 The default arguments for the @code{tfind} commands are specifically
7343 designed to make it easy to scan through the trace buffer. For
7344 instance, @code{tfind} with no argument selects the next trace
7345 snapshot, and @code{tfind -} with no argument selects the previous
7346 trace snapshot. So, by giving one @code{tfind} command, and then
7347 simply hitting @key{RET} repeatedly you can examine all the trace
7348 snapshots in order. Or, by saying @code{tfind -} and then hitting
7349 @key{RET} repeatedly you can examine the snapshots in reverse order.
7350 The @code{tfind line} command with no argument selects the snapshot
7351 for the next source line executed. The @code{tfind pc} command with
7352 no argument selects the next snapshot with the same program counter
7353 (PC) as the current frame. The @code{tfind tracepoint} command with
7354 no argument selects the next trace snapshot collected by the same
7355 tracepoint as the current one.
7356
7357 In addition to letting you scan through the trace buffer manually,
7358 these commands make it easy to construct @value{GDBN} scripts that
7359 scan through the trace buffer and print out whatever collected data
7360 you are interested in. Thus, if we want to examine the PC, FP, and SP
7361 registers from each trace frame in the buffer, we can say this:
7362
7363 @smallexample
7364 (@value{GDBP}) @b{tfind start}
7365 (@value{GDBP}) @b{while ($trace_frame != -1)}
7366 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7367 $trace_frame, $pc, $sp, $fp
7368 > tfind
7369 > end
7370
7371 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7372 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7373 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7374 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7375 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7376 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7377 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7378 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7379 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7380 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7381 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7382 @end smallexample
7383
7384 Or, if we want to examine the variable @code{X} at each source line in
7385 the buffer:
7386
7387 @smallexample
7388 (@value{GDBP}) @b{tfind start}
7389 (@value{GDBP}) @b{while ($trace_frame != -1)}
7390 > printf "Frame %d, X == %d\n", $trace_frame, X
7391 > tfind line
7392 > end
7393
7394 Frame 0, X = 1
7395 Frame 7, X = 2
7396 Frame 13, X = 255
7397 @end smallexample
7398
7399 @node tdump
7400 @subsection @code{tdump}
7401 @kindex tdump
7402 @cindex dump all data collected at tracepoint
7403 @cindex tracepoint data, display
7404
7405 This command takes no arguments. It prints all the data collected at
7406 the current trace snapshot.
7407
7408 @smallexample
7409 (@value{GDBP}) @b{trace 444}
7410 (@value{GDBP}) @b{actions}
7411 Enter actions for tracepoint #2, one per line:
7412 > collect $regs, $locals, $args, gdb_long_test
7413 > end
7414
7415 (@value{GDBP}) @b{tstart}
7416
7417 (@value{GDBP}) @b{tfind line 444}
7418 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7419 at gdb_test.c:444
7420 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7421
7422 (@value{GDBP}) @b{tdump}
7423 Data collected at tracepoint 2, trace frame 1:
7424 d0 0xc4aa0085 -995491707
7425 d1 0x18 24
7426 d2 0x80 128
7427 d3 0x33 51
7428 d4 0x71aea3d 119204413
7429 d5 0x22 34
7430 d6 0xe0 224
7431 d7 0x380035 3670069
7432 a0 0x19e24a 1696330
7433 a1 0x3000668 50333288
7434 a2 0x100 256
7435 a3 0x322000 3284992
7436 a4 0x3000698 50333336
7437 a5 0x1ad3cc 1758156
7438 fp 0x30bf3c 0x30bf3c
7439 sp 0x30bf34 0x30bf34
7440 ps 0x0 0
7441 pc 0x20b2c8 0x20b2c8
7442 fpcontrol 0x0 0
7443 fpstatus 0x0 0
7444 fpiaddr 0x0 0
7445 p = 0x20e5b4 "gdb-test"
7446 p1 = (void *) 0x11
7447 p2 = (void *) 0x22
7448 p3 = (void *) 0x33
7449 p4 = (void *) 0x44
7450 p5 = (void *) 0x55
7451 p6 = (void *) 0x66
7452 gdb_long_test = 17 '\021'
7453
7454 (@value{GDBP})
7455 @end smallexample
7456
7457 @node save-tracepoints
7458 @subsection @code{save-tracepoints @var{filename}}
7459 @kindex save-tracepoints
7460 @cindex save tracepoints for future sessions
7461
7462 This command saves all current tracepoint definitions together with
7463 their actions and passcounts, into a file @file{@var{filename}}
7464 suitable for use in a later debugging session. To read the saved
7465 tracepoint definitions, use the @code{source} command (@pxref{Command
7466 Files}).
7467
7468 @node Tracepoint Variables
7469 @section Convenience Variables for Tracepoints
7470 @cindex tracepoint variables
7471 @cindex convenience variables for tracepoints
7472
7473 @table @code
7474 @vindex $trace_frame
7475 @item (int) $trace_frame
7476 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7477 snapshot is selected.
7478
7479 @vindex $tracepoint
7480 @item (int) $tracepoint
7481 The tracepoint for the current trace snapshot.
7482
7483 @vindex $trace_line
7484 @item (int) $trace_line
7485 The line number for the current trace snapshot.
7486
7487 @vindex $trace_file
7488 @item (char []) $trace_file
7489 The source file for the current trace snapshot.
7490
7491 @vindex $trace_func
7492 @item (char []) $trace_func
7493 The name of the function containing @code{$tracepoint}.
7494 @end table
7495
7496 Note: @code{$trace_file} is not suitable for use in @code{printf},
7497 use @code{output} instead.
7498
7499 Here's a simple example of using these convenience variables for
7500 stepping through all the trace snapshots and printing some of their
7501 data.
7502
7503 @smallexample
7504 (@value{GDBP}) @b{tfind start}
7505
7506 (@value{GDBP}) @b{while $trace_frame != -1}
7507 > output $trace_file
7508 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7509 > tfind
7510 > end
7511 @end smallexample
7512
7513 @node Overlays
7514 @chapter Debugging Programs That Use Overlays
7515 @cindex overlays
7516
7517 If your program is too large to fit completely in your target system's
7518 memory, you can sometimes use @dfn{overlays} to work around this
7519 problem. @value{GDBN} provides some support for debugging programs that
7520 use overlays.
7521
7522 @menu
7523 * How Overlays Work:: A general explanation of overlays.
7524 * Overlay Commands:: Managing overlays in @value{GDBN}.
7525 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7526 mapped by asking the inferior.
7527 * Overlay Sample Program:: A sample program using overlays.
7528 @end menu
7529
7530 @node How Overlays Work
7531 @section How Overlays Work
7532 @cindex mapped overlays
7533 @cindex unmapped overlays
7534 @cindex load address, overlay's
7535 @cindex mapped address
7536 @cindex overlay area
7537
7538 Suppose you have a computer whose instruction address space is only 64
7539 kilobytes long, but which has much more memory which can be accessed by
7540 other means: special instructions, segment registers, or memory
7541 management hardware, for example. Suppose further that you want to
7542 adapt a program which is larger than 64 kilobytes to run on this system.
7543
7544 One solution is to identify modules of your program which are relatively
7545 independent, and need not call each other directly; call these modules
7546 @dfn{overlays}. Separate the overlays from the main program, and place
7547 their machine code in the larger memory. Place your main program in
7548 instruction memory, but leave at least enough space there to hold the
7549 largest overlay as well.
7550
7551 Now, to call a function located in an overlay, you must first copy that
7552 overlay's machine code from the large memory into the space set aside
7553 for it in the instruction memory, and then jump to its entry point
7554 there.
7555
7556 @c NB: In the below the mapped area's size is greater or equal to the
7557 @c size of all overlays. This is intentional to remind the developer
7558 @c that overlays don't necessarily need to be the same size.
7559
7560 @smallexample
7561 @group
7562 Data Instruction Larger
7563 Address Space Address Space Address Space
7564 +-----------+ +-----------+ +-----------+
7565 | | | | | |
7566 +-----------+ +-----------+ +-----------+<-- overlay 1
7567 | program | | main | .----| overlay 1 | load address
7568 | variables | | program | | +-----------+
7569 | and heap | | | | | |
7570 +-----------+ | | | +-----------+<-- overlay 2
7571 | | +-----------+ | | | load address
7572 +-----------+ | | | .-| overlay 2 |
7573 | | | | | |
7574 mapped --->+-----------+ | | +-----------+
7575 address | | | | | |
7576 | overlay | <-' | | |
7577 | area | <---' +-----------+<-- overlay 3
7578 | | <---. | | load address
7579 +-----------+ `--| overlay 3 |
7580 | | | |
7581 +-----------+ | |
7582 +-----------+
7583 | |
7584 +-----------+
7585
7586 @anchor{A code overlay}A code overlay
7587 @end group
7588 @end smallexample
7589
7590 The diagram (@pxref{A code overlay}) shows a system with separate data
7591 and instruction address spaces. To map an overlay, the program copies
7592 its code from the larger address space to the instruction address space.
7593 Since the overlays shown here all use the same mapped address, only one
7594 may be mapped at a time. For a system with a single address space for
7595 data and instructions, the diagram would be similar, except that the
7596 program variables and heap would share an address space with the main
7597 program and the overlay area.
7598
7599 An overlay loaded into instruction memory and ready for use is called a
7600 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7601 instruction memory. An overlay not present (or only partially present)
7602 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7603 is its address in the larger memory. The mapped address is also called
7604 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7605 called the @dfn{load memory address}, or @dfn{LMA}.
7606
7607 Unfortunately, overlays are not a completely transparent way to adapt a
7608 program to limited instruction memory. They introduce a new set of
7609 global constraints you must keep in mind as you design your program:
7610
7611 @itemize @bullet
7612
7613 @item
7614 Before calling or returning to a function in an overlay, your program
7615 must make sure that overlay is actually mapped. Otherwise, the call or
7616 return will transfer control to the right address, but in the wrong
7617 overlay, and your program will probably crash.
7618
7619 @item
7620 If the process of mapping an overlay is expensive on your system, you
7621 will need to choose your overlays carefully to minimize their effect on
7622 your program's performance.
7623
7624 @item
7625 The executable file you load onto your system must contain each
7626 overlay's instructions, appearing at the overlay's load address, not its
7627 mapped address. However, each overlay's instructions must be relocated
7628 and its symbols defined as if the overlay were at its mapped address.
7629 You can use GNU linker scripts to specify different load and relocation
7630 addresses for pieces of your program; see @ref{Overlay Description,,,
7631 ld.info, Using ld: the GNU linker}.
7632
7633 @item
7634 The procedure for loading executable files onto your system must be able
7635 to load their contents into the larger address space as well as the
7636 instruction and data spaces.
7637
7638 @end itemize
7639
7640 The overlay system described above is rather simple, and could be
7641 improved in many ways:
7642
7643 @itemize @bullet
7644
7645 @item
7646 If your system has suitable bank switch registers or memory management
7647 hardware, you could use those facilities to make an overlay's load area
7648 contents simply appear at their mapped address in instruction space.
7649 This would probably be faster than copying the overlay to its mapped
7650 area in the usual way.
7651
7652 @item
7653 If your overlays are small enough, you could set aside more than one
7654 overlay area, and have more than one overlay mapped at a time.
7655
7656 @item
7657 You can use overlays to manage data, as well as instructions. In
7658 general, data overlays are even less transparent to your design than
7659 code overlays: whereas code overlays only require care when you call or
7660 return to functions, data overlays require care every time you access
7661 the data. Also, if you change the contents of a data overlay, you
7662 must copy its contents back out to its load address before you can copy a
7663 different data overlay into the same mapped area.
7664
7665 @end itemize
7666
7667
7668 @node Overlay Commands
7669 @section Overlay Commands
7670
7671 To use @value{GDBN}'s overlay support, each overlay in your program must
7672 correspond to a separate section of the executable file. The section's
7673 virtual memory address and load memory address must be the overlay's
7674 mapped and load addresses. Identifying overlays with sections allows
7675 @value{GDBN} to determine the appropriate address of a function or
7676 variable, depending on whether the overlay is mapped or not.
7677
7678 @value{GDBN}'s overlay commands all start with the word @code{overlay};
7679 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7680
7681 @table @code
7682 @item overlay off
7683 @kindex overlay
7684 Disable @value{GDBN}'s overlay support. When overlay support is
7685 disabled, @value{GDBN} assumes that all functions and variables are
7686 always present at their mapped addresses. By default, @value{GDBN}'s
7687 overlay support is disabled.
7688
7689 @item overlay manual
7690 @cindex manual overlay debugging
7691 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7692 relies on you to tell it which overlays are mapped, and which are not,
7693 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7694 commands described below.
7695
7696 @item overlay map-overlay @var{overlay}
7697 @itemx overlay map @var{overlay}
7698 @cindex map an overlay
7699 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7700 be the name of the object file section containing the overlay. When an
7701 overlay is mapped, @value{GDBN} assumes it can find the overlay's
7702 functions and variables at their mapped addresses. @value{GDBN} assumes
7703 that any other overlays whose mapped ranges overlap that of
7704 @var{overlay} are now unmapped.
7705
7706 @item overlay unmap-overlay @var{overlay}
7707 @itemx overlay unmap @var{overlay}
7708 @cindex unmap an overlay
7709 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7710 must be the name of the object file section containing the overlay.
7711 When an overlay is unmapped, @value{GDBN} assumes it can find the
7712 overlay's functions and variables at their load addresses.
7713
7714 @item overlay auto
7715 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7716 consults a data structure the overlay manager maintains in the inferior
7717 to see which overlays are mapped. For details, see @ref{Automatic
7718 Overlay Debugging}.
7719
7720 @item overlay load-target
7721 @itemx overlay load
7722 @cindex reloading the overlay table
7723 Re-read the overlay table from the inferior. Normally, @value{GDBN}
7724 re-reads the table @value{GDBN} automatically each time the inferior
7725 stops, so this command should only be necessary if you have changed the
7726 overlay mapping yourself using @value{GDBN}. This command is only
7727 useful when using automatic overlay debugging.
7728
7729 @item overlay list-overlays
7730 @itemx overlay list
7731 @cindex listing mapped overlays
7732 Display a list of the overlays currently mapped, along with their mapped
7733 addresses, load addresses, and sizes.
7734
7735 @end table
7736
7737 Normally, when @value{GDBN} prints a code address, it includes the name
7738 of the function the address falls in:
7739
7740 @smallexample
7741 (@value{GDBP}) print main
7742 $3 = @{int ()@} 0x11a0 <main>
7743 @end smallexample
7744 @noindent
7745 When overlay debugging is enabled, @value{GDBN} recognizes code in
7746 unmapped overlays, and prints the names of unmapped functions with
7747 asterisks around them. For example, if @code{foo} is a function in an
7748 unmapped overlay, @value{GDBN} prints it this way:
7749
7750 @smallexample
7751 (@value{GDBP}) overlay list
7752 No sections are mapped.
7753 (@value{GDBP}) print foo
7754 $5 = @{int (int)@} 0x100000 <*foo*>
7755 @end smallexample
7756 @noindent
7757 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7758 name normally:
7759
7760 @smallexample
7761 (@value{GDBP}) overlay list
7762 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
7763 mapped at 0x1016 - 0x104a
7764 (@value{GDBP}) print foo
7765 $6 = @{int (int)@} 0x1016 <foo>
7766 @end smallexample
7767
7768 When overlay debugging is enabled, @value{GDBN} can find the correct
7769 address for functions and variables in an overlay, whether or not the
7770 overlay is mapped. This allows most @value{GDBN} commands, like
7771 @code{break} and @code{disassemble}, to work normally, even on unmapped
7772 code. However, @value{GDBN}'s breakpoint support has some limitations:
7773
7774 @itemize @bullet
7775 @item
7776 @cindex breakpoints in overlays
7777 @cindex overlays, setting breakpoints in
7778 You can set breakpoints in functions in unmapped overlays, as long as
7779 @value{GDBN} can write to the overlay at its load address.
7780 @item
7781 @value{GDBN} can not set hardware or simulator-based breakpoints in
7782 unmapped overlays. However, if you set a breakpoint at the end of your
7783 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7784 you are using manual overlay management), @value{GDBN} will re-set its
7785 breakpoints properly.
7786 @end itemize
7787
7788
7789 @node Automatic Overlay Debugging
7790 @section Automatic Overlay Debugging
7791 @cindex automatic overlay debugging
7792
7793 @value{GDBN} can automatically track which overlays are mapped and which
7794 are not, given some simple co-operation from the overlay manager in the
7795 inferior. If you enable automatic overlay debugging with the
7796 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7797 looks in the inferior's memory for certain variables describing the
7798 current state of the overlays.
7799
7800 Here are the variables your overlay manager must define to support
7801 @value{GDBN}'s automatic overlay debugging:
7802
7803 @table @asis
7804
7805 @item @code{_ovly_table}:
7806 This variable must be an array of the following structures:
7807
7808 @smallexample
7809 struct
7810 @{
7811 /* The overlay's mapped address. */
7812 unsigned long vma;
7813
7814 /* The size of the overlay, in bytes. */
7815 unsigned long size;
7816
7817 /* The overlay's load address. */
7818 unsigned long lma;
7819
7820 /* Non-zero if the overlay is currently mapped;
7821 zero otherwise. */
7822 unsigned long mapped;
7823 @}
7824 @end smallexample
7825
7826 @item @code{_novlys}:
7827 This variable must be a four-byte signed integer, holding the total
7828 number of elements in @code{_ovly_table}.
7829
7830 @end table
7831
7832 To decide whether a particular overlay is mapped or not, @value{GDBN}
7833 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7834 @code{lma} members equal the VMA and LMA of the overlay's section in the
7835 executable file. When @value{GDBN} finds a matching entry, it consults
7836 the entry's @code{mapped} member to determine whether the overlay is
7837 currently mapped.
7838
7839 In addition, your overlay manager may define a function called
7840 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
7841 will silently set a breakpoint there. If the overlay manager then
7842 calls this function whenever it has changed the overlay table, this
7843 will enable @value{GDBN} to accurately keep track of which overlays
7844 are in program memory, and update any breakpoints that may be set
7845 in overlays. This will allow breakpoints to work even if the
7846 overlays are kept in ROM or other non-writable memory while they
7847 are not being executed.
7848
7849 @node Overlay Sample Program
7850 @section Overlay Sample Program
7851 @cindex overlay example program
7852
7853 When linking a program which uses overlays, you must place the overlays
7854 at their load addresses, while relocating them to run at their mapped
7855 addresses. To do this, you must write a linker script (@pxref{Overlay
7856 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7857 since linker scripts are specific to a particular host system, target
7858 architecture, and target memory layout, this manual cannot provide
7859 portable sample code demonstrating @value{GDBN}'s overlay support.
7860
7861 However, the @value{GDBN} source distribution does contain an overlaid
7862 program, with linker scripts for a few systems, as part of its test
7863 suite. The program consists of the following files from
7864 @file{gdb/testsuite/gdb.base}:
7865
7866 @table @file
7867 @item overlays.c
7868 The main program file.
7869 @item ovlymgr.c
7870 A simple overlay manager, used by @file{overlays.c}.
7871 @item foo.c
7872 @itemx bar.c
7873 @itemx baz.c
7874 @itemx grbx.c
7875 Overlay modules, loaded and used by @file{overlays.c}.
7876 @item d10v.ld
7877 @itemx m32r.ld
7878 Linker scripts for linking the test program on the @code{d10v-elf}
7879 and @code{m32r-elf} targets.
7880 @end table
7881
7882 You can build the test program using the @code{d10v-elf} GCC
7883 cross-compiler like this:
7884
7885 @smallexample
7886 $ d10v-elf-gcc -g -c overlays.c
7887 $ d10v-elf-gcc -g -c ovlymgr.c
7888 $ d10v-elf-gcc -g -c foo.c
7889 $ d10v-elf-gcc -g -c bar.c
7890 $ d10v-elf-gcc -g -c baz.c
7891 $ d10v-elf-gcc -g -c grbx.c
7892 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7893 baz.o grbx.o -Wl,-Td10v.ld -o overlays
7894 @end smallexample
7895
7896 The build process is identical for any other architecture, except that
7897 you must substitute the appropriate compiler and linker script for the
7898 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7899
7900
7901 @node Languages
7902 @chapter Using @value{GDBN} with Different Languages
7903 @cindex languages
7904
7905 Although programming languages generally have common aspects, they are
7906 rarely expressed in the same manner. For instance, in ANSI C,
7907 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7908 Modula-2, it is accomplished by @code{p^}. Values can also be
7909 represented (and displayed) differently. Hex numbers in C appear as
7910 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
7911
7912 @cindex working language
7913 Language-specific information is built into @value{GDBN} for some languages,
7914 allowing you to express operations like the above in your program's
7915 native language, and allowing @value{GDBN} to output values in a manner
7916 consistent with the syntax of your program's native language. The
7917 language you use to build expressions is called the @dfn{working
7918 language}.
7919
7920 @menu
7921 * Setting:: Switching between source languages
7922 * Show:: Displaying the language
7923 * Checks:: Type and range checks
7924 * Supported languages:: Supported languages
7925 * Unsupported languages:: Unsupported languages
7926 @end menu
7927
7928 @node Setting
7929 @section Switching between source languages
7930
7931 There are two ways to control the working language---either have @value{GDBN}
7932 set it automatically, or select it manually yourself. You can use the
7933 @code{set language} command for either purpose. On startup, @value{GDBN}
7934 defaults to setting the language automatically. The working language is
7935 used to determine how expressions you type are interpreted, how values
7936 are printed, etc.
7937
7938 In addition to the working language, every source file that
7939 @value{GDBN} knows about has its own working language. For some object
7940 file formats, the compiler might indicate which language a particular
7941 source file is in. However, most of the time @value{GDBN} infers the
7942 language from the name of the file. The language of a source file
7943 controls whether C@t{++} names are demangled---this way @code{backtrace} can
7944 show each frame appropriately for its own language. There is no way to
7945 set the language of a source file from within @value{GDBN}, but you can
7946 set the language associated with a filename extension. @xref{Show, ,
7947 Displaying the language}.
7948
7949 This is most commonly a problem when you use a program, such
7950 as @code{cfront} or @code{f2c}, that generates C but is written in
7951 another language. In that case, make the
7952 program use @code{#line} directives in its C output; that way
7953 @value{GDBN} will know the correct language of the source code of the original
7954 program, and will display that source code, not the generated C code.
7955
7956 @menu
7957 * Filenames:: Filename extensions and languages.
7958 * Manually:: Setting the working language manually
7959 * Automatically:: Having @value{GDBN} infer the source language
7960 @end menu
7961
7962 @node Filenames
7963 @subsection List of filename extensions and languages
7964
7965 If a source file name ends in one of the following extensions, then
7966 @value{GDBN} infers that its language is the one indicated.
7967
7968 @table @file
7969 @item .ada
7970 @itemx .ads
7971 @itemx .adb
7972 @itemx .a
7973 Ada source file.
7974
7975 @item .c
7976 C source file
7977
7978 @item .C
7979 @itemx .cc
7980 @itemx .cp
7981 @itemx .cpp
7982 @itemx .cxx
7983 @itemx .c++
7984 C@t{++} source file
7985
7986 @item .m
7987 Objective-C source file
7988
7989 @item .f
7990 @itemx .F
7991 Fortran source file
7992
7993 @item .mod
7994 Modula-2 source file
7995
7996 @item .s
7997 @itemx .S
7998 Assembler source file. This actually behaves almost like C, but
7999 @value{GDBN} does not skip over function prologues when stepping.
8000 @end table
8001
8002 In addition, you may set the language associated with a filename
8003 extension. @xref{Show, , Displaying the language}.
8004
8005 @node Manually
8006 @subsection Setting the working language
8007
8008 If you allow @value{GDBN} to set the language automatically,
8009 expressions are interpreted the same way in your debugging session and
8010 your program.
8011
8012 @kindex set language
8013 If you wish, you may set the language manually. To do this, issue the
8014 command @samp{set language @var{lang}}, where @var{lang} is the name of
8015 a language, such as
8016 @code{c} or @code{modula-2}.
8017 For a list of the supported languages, type @samp{set language}.
8018
8019 Setting the language manually prevents @value{GDBN} from updating the working
8020 language automatically. This can lead to confusion if you try
8021 to debug a program when the working language is not the same as the
8022 source language, when an expression is acceptable to both
8023 languages---but means different things. For instance, if the current
8024 source file were written in C, and @value{GDBN} was parsing Modula-2, a
8025 command such as:
8026
8027 @smallexample
8028 print a = b + c
8029 @end smallexample
8030
8031 @noindent
8032 might not have the effect you intended. In C, this means to add
8033 @code{b} and @code{c} and place the result in @code{a}. The result
8034 printed would be the value of @code{a}. In Modula-2, this means to compare
8035 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
8036
8037 @node Automatically
8038 @subsection Having @value{GDBN} infer the source language
8039
8040 To have @value{GDBN} set the working language automatically, use
8041 @samp{set language local} or @samp{set language auto}. @value{GDBN}
8042 then infers the working language. That is, when your program stops in a
8043 frame (usually by encountering a breakpoint), @value{GDBN} sets the
8044 working language to the language recorded for the function in that
8045 frame. If the language for a frame is unknown (that is, if the function
8046 or block corresponding to the frame was defined in a source file that
8047 does not have a recognized extension), the current working language is
8048 not changed, and @value{GDBN} issues a warning.
8049
8050 This may not seem necessary for most programs, which are written
8051 entirely in one source language. However, program modules and libraries
8052 written in one source language can be used by a main program written in
8053 a different source language. Using @samp{set language auto} in this
8054 case frees you from having to set the working language manually.
8055
8056 @node Show
8057 @section Displaying the language
8058
8059 The following commands help you find out which language is the
8060 working language, and also what language source files were written in.
8061
8062 @table @code
8063 @item show language
8064 @kindex show language
8065 Display the current working language. This is the
8066 language you can use with commands such as @code{print} to
8067 build and compute expressions that may involve variables in your program.
8068
8069 @item info frame
8070 @kindex info frame@r{, show the source language}
8071 Display the source language for this frame. This language becomes the
8072 working language if you use an identifier from this frame.
8073 @xref{Frame Info, ,Information about a frame}, to identify the other
8074 information listed here.
8075
8076 @item info source
8077 @kindex info source@r{, show the source language}
8078 Display the source language of this source file.
8079 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
8080 information listed here.
8081 @end table
8082
8083 In unusual circumstances, you may have source files with extensions
8084 not in the standard list. You can then set the extension associated
8085 with a language explicitly:
8086
8087 @table @code
8088 @item set extension-language @var{ext} @var{language}
8089 @kindex set extension-language
8090 Tell @value{GDBN} that source files with extension @var{ext} are to be
8091 assumed as written in the source language @var{language}.
8092
8093 @item info extensions
8094 @kindex info extensions
8095 List all the filename extensions and the associated languages.
8096 @end table
8097
8098 @node Checks
8099 @section Type and range checking
8100
8101 @quotation
8102 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
8103 checking are included, but they do not yet have any effect. This
8104 section documents the intended facilities.
8105 @end quotation
8106 @c FIXME remove warning when type/range code added
8107
8108 Some languages are designed to guard you against making seemingly common
8109 errors through a series of compile- and run-time checks. These include
8110 checking the type of arguments to functions and operators, and making
8111 sure mathematical overflows are caught at run time. Checks such as
8112 these help to ensure a program's correctness once it has been compiled
8113 by eliminating type mismatches, and providing active checks for range
8114 errors when your program is running.
8115
8116 @value{GDBN} can check for conditions like the above if you wish.
8117 Although @value{GDBN} does not check the statements in your program,
8118 it can check expressions entered directly into @value{GDBN} for
8119 evaluation via the @code{print} command, for example. As with the
8120 working language, @value{GDBN} can also decide whether or not to check
8121 automatically based on your program's source language.
8122 @xref{Supported languages, ,Supported languages}, for the default
8123 settings of supported languages.
8124
8125 @menu
8126 * Type Checking:: An overview of type checking
8127 * Range Checking:: An overview of range checking
8128 @end menu
8129
8130 @cindex type checking
8131 @cindex checks, type
8132 @node Type Checking
8133 @subsection An overview of type checking
8134
8135 Some languages, such as Modula-2, are strongly typed, meaning that the
8136 arguments to operators and functions have to be of the correct type,
8137 otherwise an error occurs. These checks prevent type mismatch
8138 errors from ever causing any run-time problems. For example,
8139
8140 @smallexample
8141 1 + 2 @result{} 3
8142 @exdent but
8143 @error{} 1 + 2.3
8144 @end smallexample
8145
8146 The second example fails because the @code{CARDINAL} 1 is not
8147 type-compatible with the @code{REAL} 2.3.
8148
8149 For the expressions you use in @value{GDBN} commands, you can tell the
8150 @value{GDBN} type checker to skip checking;
8151 to treat any mismatches as errors and abandon the expression;
8152 or to only issue warnings when type mismatches occur,
8153 but evaluate the expression anyway. When you choose the last of
8154 these, @value{GDBN} evaluates expressions like the second example above, but
8155 also issues a warning.
8156
8157 Even if you turn type checking off, there may be other reasons
8158 related to type that prevent @value{GDBN} from evaluating an expression.
8159 For instance, @value{GDBN} does not know how to add an @code{int} and
8160 a @code{struct foo}. These particular type errors have nothing to do
8161 with the language in use, and usually arise from expressions, such as
8162 the one described above, which make little sense to evaluate anyway.
8163
8164 Each language defines to what degree it is strict about type. For
8165 instance, both Modula-2 and C require the arguments to arithmetical
8166 operators to be numbers. In C, enumerated types and pointers can be
8167 represented as numbers, so that they are valid arguments to mathematical
8168 operators. @xref{Supported languages, ,Supported languages}, for further
8169 details on specific languages.
8170
8171 @value{GDBN} provides some additional commands for controlling the type checker:
8172
8173 @kindex set check type
8174 @kindex show check type
8175 @table @code
8176 @item set check type auto
8177 Set type checking on or off based on the current working language.
8178 @xref{Supported languages, ,Supported languages}, for the default settings for
8179 each language.
8180
8181 @item set check type on
8182 @itemx set check type off
8183 Set type checking on or off, overriding the default setting for the
8184 current working language. Issue a warning if the setting does not
8185 match the language default. If any type mismatches occur in
8186 evaluating an expression while type checking is on, @value{GDBN} prints a
8187 message and aborts evaluation of the expression.
8188
8189 @item set check type warn
8190 Cause the type checker to issue warnings, but to always attempt to
8191 evaluate the expression. Evaluating the expression may still
8192 be impossible for other reasons. For example, @value{GDBN} cannot add
8193 numbers and structures.
8194
8195 @item show type
8196 Show the current setting of the type checker, and whether or not @value{GDBN}
8197 is setting it automatically.
8198 @end table
8199
8200 @cindex range checking
8201 @cindex checks, range
8202 @node Range Checking
8203 @subsection An overview of range checking
8204
8205 In some languages (such as Modula-2), it is an error to exceed the
8206 bounds of a type; this is enforced with run-time checks. Such range
8207 checking is meant to ensure program correctness by making sure
8208 computations do not overflow, or indices on an array element access do
8209 not exceed the bounds of the array.
8210
8211 For expressions you use in @value{GDBN} commands, you can tell
8212 @value{GDBN} to treat range errors in one of three ways: ignore them,
8213 always treat them as errors and abandon the expression, or issue
8214 warnings but evaluate the expression anyway.
8215
8216 A range error can result from numerical overflow, from exceeding an
8217 array index bound, or when you type a constant that is not a member
8218 of any type. Some languages, however, do not treat overflows as an
8219 error. In many implementations of C, mathematical overflow causes the
8220 result to ``wrap around'' to lower values---for example, if @var{m} is
8221 the largest integer value, and @var{s} is the smallest, then
8222
8223 @smallexample
8224 @var{m} + 1 @result{} @var{s}
8225 @end smallexample
8226
8227 This, too, is specific to individual languages, and in some cases
8228 specific to individual compilers or machines. @xref{Supported languages, ,
8229 Supported languages}, for further details on specific languages.
8230
8231 @value{GDBN} provides some additional commands for controlling the range checker:
8232
8233 @kindex set check range
8234 @kindex show check range
8235 @table @code
8236 @item set check range auto
8237 Set range checking on or off based on the current working language.
8238 @xref{Supported languages, ,Supported languages}, for the default settings for
8239 each language.
8240
8241 @item set check range on
8242 @itemx set check range off
8243 Set range checking on or off, overriding the default setting for the
8244 current working language. A warning is issued if the setting does not
8245 match the language default. If a range error occurs and range checking is on,
8246 then a message is printed and evaluation of the expression is aborted.
8247
8248 @item set check range warn
8249 Output messages when the @value{GDBN} range checker detects a range error,
8250 but attempt to evaluate the expression anyway. Evaluating the
8251 expression may still be impossible for other reasons, such as accessing
8252 memory that the process does not own (a typical example from many Unix
8253 systems).
8254
8255 @item show range
8256 Show the current setting of the range checker, and whether or not it is
8257 being set automatically by @value{GDBN}.
8258 @end table
8259
8260 @node Supported languages
8261 @section Supported languages
8262
8263 @value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8264 assembly, Modula-2, and Ada.
8265 @c This is false ...
8266 Some @value{GDBN} features may be used in expressions regardless of the
8267 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8268 and the @samp{@{type@}addr} construct (@pxref{Expressions,
8269 ,Expressions}) can be used with the constructs of any supported
8270 language.
8271
8272 The following sections detail to what degree each source language is
8273 supported by @value{GDBN}. These sections are not meant to be language
8274 tutorials or references, but serve only as a reference guide to what the
8275 @value{GDBN} expression parser accepts, and what input and output
8276 formats should look like for different languages. There are many good
8277 books written on each of these languages; please look to these for a
8278 language reference or tutorial.
8279
8280 @menu
8281 * C:: C and C@t{++}
8282 * Objective-C:: Objective-C
8283 * Fortran:: Fortran
8284 * Pascal:: Pascal
8285 * Modula-2:: Modula-2
8286 * Ada:: Ada
8287 @end menu
8288
8289 @node C
8290 @subsection C and C@t{++}
8291
8292 @cindex C and C@t{++}
8293 @cindex expressions in C or C@t{++}
8294
8295 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
8296 to both languages. Whenever this is the case, we discuss those languages
8297 together.
8298
8299 @cindex C@t{++}
8300 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
8301 @cindex @sc{gnu} C@t{++}
8302 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8303 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8304 effectively, you must compile your C@t{++} programs with a supported
8305 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
8306 compiler (@code{aCC}).
8307
8308 For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8309 format; if it doesn't work on your system, try the stabs+ debugging
8310 format. You can select those formats explicitly with the @code{g++}
8311 command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8312 @xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8313 CC, gcc.info, Using @sc{gnu} CC}.
8314
8315 @menu
8316 * C Operators:: C and C@t{++} operators
8317 * C Constants:: C and C@t{++} constants
8318 * C plus plus expressions:: C@t{++} expressions
8319 * C Defaults:: Default settings for C and C@t{++}
8320 * C Checks:: C and C@t{++} type and range checks
8321 * Debugging C:: @value{GDBN} and C
8322 * Debugging C plus plus:: @value{GDBN} features for C@t{++}
8323 @end menu
8324
8325 @node C Operators
8326 @subsubsection C and C@t{++} operators
8327
8328 @cindex C and C@t{++} operators
8329
8330 Operators must be defined on values of specific types. For instance,
8331 @code{+} is defined on numbers, but not on structures. Operators are
8332 often defined on groups of types.
8333
8334 For the purposes of C and C@t{++}, the following definitions hold:
8335
8336 @itemize @bullet
8337
8338 @item
8339 @emph{Integral types} include @code{int} with any of its storage-class
8340 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
8341
8342 @item
8343 @emph{Floating-point types} include @code{float}, @code{double}, and
8344 @code{long double} (if supported by the target platform).
8345
8346 @item
8347 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
8348
8349 @item
8350 @emph{Scalar types} include all of the above.
8351
8352 @end itemize
8353
8354 @noindent
8355 The following operators are supported. They are listed here
8356 in order of increasing precedence:
8357
8358 @table @code
8359 @item ,
8360 The comma or sequencing operator. Expressions in a comma-separated list
8361 are evaluated from left to right, with the result of the entire
8362 expression being the last expression evaluated.
8363
8364 @item =
8365 Assignment. The value of an assignment expression is the value
8366 assigned. Defined on scalar types.
8367
8368 @item @var{op}=
8369 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8370 and translated to @w{@code{@var{a} = @var{a op b}}}.
8371 @w{@code{@var{op}=}} and @code{=} have the same precedence.
8372 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8373 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8374
8375 @item ?:
8376 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8377 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8378 integral type.
8379
8380 @item ||
8381 Logical @sc{or}. Defined on integral types.
8382
8383 @item &&
8384 Logical @sc{and}. Defined on integral types.
8385
8386 @item |
8387 Bitwise @sc{or}. Defined on integral types.
8388
8389 @item ^
8390 Bitwise exclusive-@sc{or}. Defined on integral types.
8391
8392 @item &
8393 Bitwise @sc{and}. Defined on integral types.
8394
8395 @item ==@r{, }!=
8396 Equality and inequality. Defined on scalar types. The value of these
8397 expressions is 0 for false and non-zero for true.
8398
8399 @item <@r{, }>@r{, }<=@r{, }>=
8400 Less than, greater than, less than or equal, greater than or equal.
8401 Defined on scalar types. The value of these expressions is 0 for false
8402 and non-zero for true.
8403
8404 @item <<@r{, }>>
8405 left shift, and right shift. Defined on integral types.
8406
8407 @item @@
8408 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8409
8410 @item +@r{, }-
8411 Addition and subtraction. Defined on integral types, floating-point types and
8412 pointer types.
8413
8414 @item *@r{, }/@r{, }%
8415 Multiplication, division, and modulus. Multiplication and division are
8416 defined on integral and floating-point types. Modulus is defined on
8417 integral types.
8418
8419 @item ++@r{, }--
8420 Increment and decrement. When appearing before a variable, the
8421 operation is performed before the variable is used in an expression;
8422 when appearing after it, the variable's value is used before the
8423 operation takes place.
8424
8425 @item *
8426 Pointer dereferencing. Defined on pointer types. Same precedence as
8427 @code{++}.
8428
8429 @item &
8430 Address operator. Defined on variables. Same precedence as @code{++}.
8431
8432 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8433 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
8434 (or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
8435 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
8436 stored.
8437
8438 @item -
8439 Negative. Defined on integral and floating-point types. Same
8440 precedence as @code{++}.
8441
8442 @item !
8443 Logical negation. Defined on integral types. Same precedence as
8444 @code{++}.
8445
8446 @item ~
8447 Bitwise complement operator. Defined on integral types. Same precedence as
8448 @code{++}.
8449
8450
8451 @item .@r{, }->
8452 Structure member, and pointer-to-structure member. For convenience,
8453 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
8454 pointer based on the stored type information.
8455 Defined on @code{struct} and @code{union} data.
8456
8457 @item .*@r{, }->*
8458 Dereferences of pointers to members.
8459
8460 @item []
8461 Array indexing. @code{@var{a}[@var{i}]} is defined as
8462 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8463
8464 @item ()
8465 Function parameter list. Same precedence as @code{->}.
8466
8467 @item ::
8468 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
8469 and @code{class} types.
8470
8471 @item ::
8472 Doubled colons also represent the @value{GDBN} scope operator
8473 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8474 above.
8475 @end table
8476
8477 If an operator is redefined in the user code, @value{GDBN} usually
8478 attempts to invoke the redefined version instead of using the operator's
8479 predefined meaning.
8480
8481 @menu
8482 * C Constants::
8483 @end menu
8484
8485 @node C Constants
8486 @subsubsection C and C@t{++} constants
8487
8488 @cindex C and C@t{++} constants
8489
8490 @value{GDBN} allows you to express the constants of C and C@t{++} in the
8491 following ways:
8492
8493 @itemize @bullet
8494 @item
8495 Integer constants are a sequence of digits. Octal constants are
8496 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8497 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
8498 @samp{l}, specifying that the constant should be treated as a
8499 @code{long} value.
8500
8501 @item
8502 Floating point constants are a sequence of digits, followed by a decimal
8503 point, followed by a sequence of digits, and optionally followed by an
8504 exponent. An exponent is of the form:
8505 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8506 sequence of digits. The @samp{+} is optional for positive exponents.
8507 A floating-point constant may also end with a letter @samp{f} or
8508 @samp{F}, specifying that the constant should be treated as being of
8509 the @code{float} (as opposed to the default @code{double}) type; or with
8510 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8511 constant.
8512
8513 @item
8514 Enumerated constants consist of enumerated identifiers, or their
8515 integral equivalents.
8516
8517 @item
8518 Character constants are a single character surrounded by single quotes
8519 (@code{'}), or a number---the ordinal value of the corresponding character
8520 (usually its @sc{ascii} value). Within quotes, the single character may
8521 be represented by a letter or by @dfn{escape sequences}, which are of
8522 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8523 of the character's ordinal value; or of the form @samp{\@var{x}}, where
8524 @samp{@var{x}} is a predefined special character---for example,
8525 @samp{\n} for newline.
8526
8527 @item
8528 String constants are a sequence of character constants surrounded by
8529 double quotes (@code{"}). Any valid character constant (as described
8530 above) may appear. Double quotes within the string must be preceded by
8531 a backslash, so for instance @samp{"a\"b'c"} is a string of five
8532 characters.
8533
8534 @item
8535 Pointer constants are an integral value. You can also write pointers
8536 to constants using the C operator @samp{&}.
8537
8538 @item
8539 Array constants are comma-separated lists surrounded by braces @samp{@{}
8540 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8541 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8542 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8543 @end itemize
8544
8545 @menu
8546 * C plus plus expressions::
8547 * C Defaults::
8548 * C Checks::
8549
8550 * Debugging C::
8551 @end menu
8552
8553 @node C plus plus expressions
8554 @subsubsection C@t{++} expressions
8555
8556 @cindex expressions in C@t{++}
8557 @value{GDBN} expression handling can interpret most C@t{++} expressions.
8558
8559 @cindex debugging C@t{++} programs
8560 @cindex C@t{++} compilers
8561 @cindex debug formats and C@t{++}
8562 @cindex @value{NGCC} and C@t{++}
8563 @quotation
8564 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
8565 proper compiler and the proper debug format. Currently, @value{GDBN}
8566 works best when debugging C@t{++} code that is compiled with
8567 @value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8568 @option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8569 stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8570 stabs+ as their default debug format, so you usually don't need to
8571 specify a debug format explicitly. Other compilers and/or debug formats
8572 are likely to work badly or not at all when using @value{GDBN} to debug
8573 C@t{++} code.
8574 @end quotation
8575
8576 @enumerate
8577
8578 @cindex member functions
8579 @item
8580 Member function calls are allowed; you can use expressions like
8581
8582 @smallexample
8583 count = aml->GetOriginal(x, y)
8584 @end smallexample
8585
8586 @vindex this@r{, inside C@t{++} member functions}
8587 @cindex namespace in C@t{++}
8588 @item
8589 While a member function is active (in the selected stack frame), your
8590 expressions have the same namespace available as the member function;
8591 that is, @value{GDBN} allows implicit references to the class instance
8592 pointer @code{this} following the same rules as C@t{++}.
8593
8594 @cindex call overloaded functions
8595 @cindex overloaded functions, calling
8596 @cindex type conversions in C@t{++}
8597 @item
8598 You can call overloaded functions; @value{GDBN} resolves the function
8599 call to the right definition, with some restrictions. @value{GDBN} does not
8600 perform overload resolution involving user-defined type conversions,
8601 calls to constructors, or instantiations of templates that do not exist
8602 in the program. It also cannot handle ellipsis argument lists or
8603 default arguments.
8604
8605 It does perform integral conversions and promotions, floating-point
8606 promotions, arithmetic conversions, pointer conversions, conversions of
8607 class objects to base classes, and standard conversions such as those of
8608 functions or arrays to pointers; it requires an exact match on the
8609 number of function arguments.
8610
8611 Overload resolution is always performed, unless you have specified
8612 @code{set overload-resolution off}. @xref{Debugging C plus plus,
8613 ,@value{GDBN} features for C@t{++}}.
8614
8615 You must specify @code{set overload-resolution off} in order to use an
8616 explicit function signature to call an overloaded function, as in
8617 @smallexample
8618 p 'foo(char,int)'('x', 13)
8619 @end smallexample
8620
8621 The @value{GDBN} command-completion facility can simplify this;
8622 see @ref{Completion, ,Command completion}.
8623
8624 @cindex reference declarations
8625 @item
8626 @value{GDBN} understands variables declared as C@t{++} references; you can use
8627 them in expressions just as you do in C@t{++} source---they are automatically
8628 dereferenced.
8629
8630 In the parameter list shown when @value{GDBN} displays a frame, the values of
8631 reference variables are not displayed (unlike other variables); this
8632 avoids clutter, since references are often used for large structures.
8633 The @emph{address} of a reference variable is always shown, unless
8634 you have specified @samp{set print address off}.
8635
8636 @item
8637 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
8638 expressions can use it just as expressions in your program do. Since
8639 one scope may be defined in another, you can use @code{::} repeatedly if
8640 necessary, for example in an expression like
8641 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
8642 resolving name scope by reference to source files, in both C and C@t{++}
8643 debugging (@pxref{Variables, ,Program variables}).
8644 @end enumerate
8645
8646 In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
8647 calling virtual functions correctly, printing out virtual bases of
8648 objects, calling functions in a base subobject, casting objects, and
8649 invoking user-defined operators.
8650
8651 @node C Defaults
8652 @subsubsection C and C@t{++} defaults
8653
8654 @cindex C and C@t{++} defaults
8655
8656 If you allow @value{GDBN} to set type and range checking automatically, they
8657 both default to @code{off} whenever the working language changes to
8658 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
8659 selects the working language.
8660
8661 If you allow @value{GDBN} to set the language automatically, it
8662 recognizes source files whose names end with @file{.c}, @file{.C}, or
8663 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
8664 these files, it sets the working language to C or C@t{++}.
8665 @xref{Automatically, ,Having @value{GDBN} infer the source language},
8666 for further details.
8667
8668 @c Type checking is (a) primarily motivated by Modula-2, and (b)
8669 @c unimplemented. If (b) changes, it might make sense to let this node
8670 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
8671
8672 @node C Checks
8673 @subsubsection C and C@t{++} type and range checks
8674
8675 @cindex C and C@t{++} checks
8676
8677 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
8678 is not used. However, if you turn type checking on, @value{GDBN}
8679 considers two variables type equivalent if:
8680
8681 @itemize @bullet
8682 @item
8683 The two variables are structured and have the same structure, union, or
8684 enumerated tag.
8685
8686 @item
8687 The two variables have the same type name, or types that have been
8688 declared equivalent through @code{typedef}.
8689
8690 @ignore
8691 @c leaving this out because neither J Gilmore nor R Pesch understand it.
8692 @c FIXME--beers?
8693 @item
8694 The two @code{struct}, @code{union}, or @code{enum} variables are
8695 declared in the same declaration. (Note: this may not be true for all C
8696 compilers.)
8697 @end ignore
8698 @end itemize
8699
8700 Range checking, if turned on, is done on mathematical operations. Array
8701 indices are not checked, since they are often used to index a pointer
8702 that is not itself an array.
8703
8704 @node Debugging C
8705 @subsubsection @value{GDBN} and C
8706
8707 The @code{set print union} and @code{show print union} commands apply to
8708 the @code{union} type. When set to @samp{on}, any @code{union} that is
8709 inside a @code{struct} or @code{class} is also printed. Otherwise, it
8710 appears as @samp{@{...@}}.
8711
8712 The @code{@@} operator aids in the debugging of dynamic arrays, formed
8713 with pointers and a memory allocation function. @xref{Expressions,
8714 ,Expressions}.
8715
8716 @menu
8717 * Debugging C plus plus::
8718 @end menu
8719
8720 @node Debugging C plus plus
8721 @subsubsection @value{GDBN} features for C@t{++}
8722
8723 @cindex commands for C@t{++}
8724
8725 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8726 designed specifically for use with C@t{++}. Here is a summary:
8727
8728 @table @code
8729 @cindex break in overloaded functions
8730 @item @r{breakpoint menus}
8731 When you want a breakpoint in a function whose name is overloaded,
8732 @value{GDBN} breakpoint menus help you specify which function definition
8733 you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8734
8735 @cindex overloading in C@t{++}
8736 @item rbreak @var{regex}
8737 Setting breakpoints using regular expressions is helpful for setting
8738 breakpoints on overloaded functions that are not members of any special
8739 classes.
8740 @xref{Set Breaks, ,Setting breakpoints}.
8741
8742 @cindex C@t{++} exception handling
8743 @item catch throw
8744 @itemx catch catch
8745 Debug C@t{++} exception handling using these commands. @xref{Set
8746 Catchpoints, , Setting catchpoints}.
8747
8748 @cindex inheritance
8749 @item ptype @var{typename}
8750 Print inheritance relationships as well as other information for type
8751 @var{typename}.
8752 @xref{Symbols, ,Examining the Symbol Table}.
8753
8754 @cindex C@t{++} symbol display
8755 @item set print demangle
8756 @itemx show print demangle
8757 @itemx set print asm-demangle
8758 @itemx show print asm-demangle
8759 Control whether C@t{++} symbols display in their source form, both when
8760 displaying code as C@t{++} source and when displaying disassemblies.
8761 @xref{Print Settings, ,Print settings}.
8762
8763 @item set print object
8764 @itemx show print object
8765 Choose whether to print derived (actual) or declared types of objects.
8766 @xref{Print Settings, ,Print settings}.
8767
8768 @item set print vtbl
8769 @itemx show print vtbl
8770 Control the format for printing virtual function tables.
8771 @xref{Print Settings, ,Print settings}.
8772 (The @code{vtbl} commands do not work on programs compiled with the HP
8773 ANSI C@t{++} compiler (@code{aCC}).)
8774
8775 @kindex set overload-resolution
8776 @cindex overloaded functions, overload resolution
8777 @item set overload-resolution on
8778 Enable overload resolution for C@t{++} expression evaluation. The default
8779 is on. For overloaded functions, @value{GDBN} evaluates the arguments
8780 and searches for a function whose signature matches the argument types,
8781 using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
8782 expressions}, for details). If it cannot find a match, it emits a
8783 message.
8784
8785 @item set overload-resolution off
8786 Disable overload resolution for C@t{++} expression evaluation. For
8787 overloaded functions that are not class member functions, @value{GDBN}
8788 chooses the first function of the specified name that it finds in the
8789 symbol table, whether or not its arguments are of the correct type. For
8790 overloaded functions that are class member functions, @value{GDBN}
8791 searches for a function whose signature @emph{exactly} matches the
8792 argument types.
8793
8794 @kindex show overload-resolution
8795 @item show overload-resolution
8796 Show the current setting of overload resolution.
8797
8798 @item @r{Overloaded symbol names}
8799 You can specify a particular definition of an overloaded symbol, using
8800 the same notation that is used to declare such symbols in C@t{++}: type
8801 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8802 also use the @value{GDBN} command-line word completion facilities to list the
8803 available choices, or to finish the type list for you.
8804 @xref{Completion,, Command completion}, for details on how to do this.
8805 @end table
8806
8807 @node Objective-C
8808 @subsection Objective-C
8809
8810 @cindex Objective-C
8811 This section provides information about some commands and command
8812 options that are useful for debugging Objective-C code. See also
8813 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8814 few more commands specific to Objective-C support.
8815
8816 @menu
8817 * Method Names in Commands::
8818 * The Print Command with Objective-C::
8819 @end menu
8820
8821 @node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8822 @subsubsection Method Names in Commands
8823
8824 The following commands have been extended to accept Objective-C method
8825 names as line specifications:
8826
8827 @kindex clear@r{, and Objective-C}
8828 @kindex break@r{, and Objective-C}
8829 @kindex info line@r{, and Objective-C}
8830 @kindex jump@r{, and Objective-C}
8831 @kindex list@r{, and Objective-C}
8832 @itemize
8833 @item @code{clear}
8834 @item @code{break}
8835 @item @code{info line}
8836 @item @code{jump}
8837 @item @code{list}
8838 @end itemize
8839
8840 A fully qualified Objective-C method name is specified as
8841
8842 @smallexample
8843 -[@var{Class} @var{methodName}]
8844 @end smallexample
8845
8846 where the minus sign is used to indicate an instance method and a
8847 plus sign (not shown) is used to indicate a class method. The class
8848 name @var{Class} and method name @var{methodName} are enclosed in
8849 brackets, similar to the way messages are specified in Objective-C
8850 source code. For example, to set a breakpoint at the @code{create}
8851 instance method of class @code{Fruit} in the program currently being
8852 debugged, enter:
8853
8854 @smallexample
8855 break -[Fruit create]
8856 @end smallexample
8857
8858 To list ten program lines around the @code{initialize} class method,
8859 enter:
8860
8861 @smallexample
8862 list +[NSText initialize]
8863 @end smallexample
8864
8865 In the current version of @value{GDBN}, the plus or minus sign is
8866 required. In future versions of @value{GDBN}, the plus or minus
8867 sign will be optional, but you can use it to narrow the search. It
8868 is also possible to specify just a method name:
8869
8870 @smallexample
8871 break create
8872 @end smallexample
8873
8874 You must specify the complete method name, including any colons. If
8875 your program's source files contain more than one @code{create} method,
8876 you'll be presented with a numbered list of classes that implement that
8877 method. Indicate your choice by number, or type @samp{0} to exit if
8878 none apply.
8879
8880 As another example, to clear a breakpoint established at the
8881 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8882
8883 @smallexample
8884 clear -[NSWindow makeKeyAndOrderFront:]
8885 @end smallexample
8886
8887 @node The Print Command with Objective-C
8888 @subsubsection The Print Command With Objective-C
8889 @cindex Objective-C, print objects
8890 @kindex print-object
8891 @kindex po @r{(@code{print-object})}
8892
8893 The print command has also been extended to accept methods. For example:
8894
8895 @smallexample
8896 print -[@var{object} hash]
8897 @end smallexample
8898
8899 @cindex print an Objective-C object description
8900 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8901 @noindent
8902 will tell @value{GDBN} to send the @code{hash} message to @var{object}
8903 and print the result. Also, an additional command has been added,
8904 @code{print-object} or @code{po} for short, which is meant to print
8905 the description of an object. However, this command may only work
8906 with certain Objective-C libraries that have a particular hook
8907 function, @code{_NSPrintForDebugger}, defined.
8908
8909 @node Fortran
8910 @subsection Fortran
8911 @cindex Fortran-specific support in @value{GDBN}
8912
8913 @table @code
8914 @cindex @code{COMMON} blocks, Fortran
8915 @kindex info common
8916 @item info common @r{[}@var{common-name}@r{]}
8917 This command prints the values contained in the Fortran @code{COMMON}
8918 block whose name is @var{common-name}. With no argument, the names of
8919 all @code{COMMON} blocks visible at current program location are
8920 printed.
8921 @end table
8922
8923 Fortran symbols are usually case-insensitive, so @value{GDBN} by
8924 default uses case-insensitive matches for Fortran symbols. You can
8925 change that with the @samp{set case-insensitive} command, see
8926 @ref{Symbols}, for the details.
8927
8928 @node Pascal
8929 @subsection Pascal
8930
8931 @cindex Pascal support in @value{GDBN}, limitations
8932 Debugging Pascal programs which use sets, subranges, file variables, or
8933 nested functions does not currently work. @value{GDBN} does not support
8934 entering expressions, printing values, or similar features using Pascal
8935 syntax.
8936
8937 The Pascal-specific command @code{set print pascal_static-members}
8938 controls whether static members of Pascal objects are displayed.
8939 @xref{Print Settings, pascal_static-members}.
8940
8941 @node Modula-2
8942 @subsection Modula-2
8943
8944 @cindex Modula-2, @value{GDBN} support
8945
8946 The extensions made to @value{GDBN} to support Modula-2 only support
8947 output from the @sc{gnu} Modula-2 compiler (which is currently being
8948 developed). Other Modula-2 compilers are not currently supported, and
8949 attempting to debug executables produced by them is most likely
8950 to give an error as @value{GDBN} reads in the executable's symbol
8951 table.
8952
8953 @cindex expressions in Modula-2
8954 @menu
8955 * M2 Operators:: Built-in operators
8956 * Built-In Func/Proc:: Built-in functions and procedures
8957 * M2 Constants:: Modula-2 constants
8958 * M2 Defaults:: Default settings for Modula-2
8959 * Deviations:: Deviations from standard Modula-2
8960 * M2 Checks:: Modula-2 type and range checks
8961 * M2 Scope:: The scope operators @code{::} and @code{.}
8962 * GDB/M2:: @value{GDBN} and Modula-2
8963 @end menu
8964
8965 @node M2 Operators
8966 @subsubsection Operators
8967 @cindex Modula-2 operators
8968
8969 Operators must be defined on values of specific types. For instance,
8970 @code{+} is defined on numbers, but not on structures. Operators are
8971 often defined on groups of types. For the purposes of Modula-2, the
8972 following definitions hold:
8973
8974 @itemize @bullet
8975
8976 @item
8977 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8978 their subranges.
8979
8980 @item
8981 @emph{Character types} consist of @code{CHAR} and its subranges.
8982
8983 @item
8984 @emph{Floating-point types} consist of @code{REAL}.
8985
8986 @item
8987 @emph{Pointer types} consist of anything declared as @code{POINTER TO
8988 @var{type}}.
8989
8990 @item
8991 @emph{Scalar types} consist of all of the above.
8992
8993 @item
8994 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
8995
8996 @item
8997 @emph{Boolean types} consist of @code{BOOLEAN}.
8998 @end itemize
8999
9000 @noindent
9001 The following operators are supported, and appear in order of
9002 increasing precedence:
9003
9004 @table @code
9005 @item ,
9006 Function argument or array index separator.
9007
9008 @item :=
9009 Assignment. The value of @var{var} @code{:=} @var{value} is
9010 @var{value}.
9011
9012 @item <@r{, }>
9013 Less than, greater than on integral, floating-point, or enumerated
9014 types.
9015
9016 @item <=@r{, }>=
9017 Less than or equal to, greater than or equal to
9018 on integral, floating-point and enumerated types, or set inclusion on
9019 set types. Same precedence as @code{<}.
9020
9021 @item =@r{, }<>@r{, }#
9022 Equality and two ways of expressing inequality, valid on scalar types.
9023 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9024 available for inequality, since @code{#} conflicts with the script
9025 comment character.
9026
9027 @item IN
9028 Set membership. Defined on set types and the types of their members.
9029 Same precedence as @code{<}.
9030
9031 @item OR
9032 Boolean disjunction. Defined on boolean types.
9033
9034 @item AND@r{, }&
9035 Boolean conjunction. Defined on boolean types.
9036
9037 @item @@
9038 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9039
9040 @item +@r{, }-
9041 Addition and subtraction on integral and floating-point types, or union
9042 and difference on set types.
9043
9044 @item *
9045 Multiplication on integral and floating-point types, or set intersection
9046 on set types.
9047
9048 @item /
9049 Division on floating-point types, or symmetric set difference on set
9050 types. Same precedence as @code{*}.
9051
9052 @item DIV@r{, }MOD
9053 Integer division and remainder. Defined on integral types. Same
9054 precedence as @code{*}.
9055
9056 @item -
9057 Negative. Defined on @code{INTEGER} and @code{REAL} data.
9058
9059 @item ^
9060 Pointer dereferencing. Defined on pointer types.
9061
9062 @item NOT
9063 Boolean negation. Defined on boolean types. Same precedence as
9064 @code{^}.
9065
9066 @item .
9067 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
9068 precedence as @code{^}.
9069
9070 @item []
9071 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9072
9073 @item ()
9074 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9075 as @code{^}.
9076
9077 @item ::@r{, }.
9078 @value{GDBN} and Modula-2 scope operators.
9079 @end table
9080
9081 @quotation
9082 @emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9083 treats the use of the operator @code{IN}, or the use of operators
9084 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9085 @code{<=}, and @code{>=} on sets as an error.
9086 @end quotation
9087
9088
9089 @node Built-In Func/Proc
9090 @subsubsection Built-in functions and procedures
9091 @cindex Modula-2 built-ins
9092
9093 Modula-2 also makes available several built-in procedures and functions.
9094 In describing these, the following metavariables are used:
9095
9096 @table @var
9097
9098 @item a
9099 represents an @code{ARRAY} variable.
9100
9101 @item c
9102 represents a @code{CHAR} constant or variable.
9103
9104 @item i
9105 represents a variable or constant of integral type.
9106
9107 @item m
9108 represents an identifier that belongs to a set. Generally used in the
9109 same function with the metavariable @var{s}. The type of @var{s} should
9110 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9111
9112 @item n
9113 represents a variable or constant of integral or floating-point type.
9114
9115 @item r
9116 represents a variable or constant of floating-point type.
9117
9118 @item t
9119 represents a type.
9120
9121 @item v
9122 represents a variable.
9123
9124 @item x
9125 represents a variable or constant of one of many types. See the
9126 explanation of the function for details.
9127 @end table
9128
9129 All Modula-2 built-in procedures also return a result, described below.
9130
9131 @table @code
9132 @item ABS(@var{n})
9133 Returns the absolute value of @var{n}.
9134
9135 @item CAP(@var{c})
9136 If @var{c} is a lower case letter, it returns its upper case
9137 equivalent, otherwise it returns its argument.
9138
9139 @item CHR(@var{i})
9140 Returns the character whose ordinal value is @var{i}.
9141
9142 @item DEC(@var{v})
9143 Decrements the value in the variable @var{v} by one. Returns the new value.
9144
9145 @item DEC(@var{v},@var{i})
9146 Decrements the value in the variable @var{v} by @var{i}. Returns the
9147 new value.
9148
9149 @item EXCL(@var{m},@var{s})
9150 Removes the element @var{m} from the set @var{s}. Returns the new
9151 set.
9152
9153 @item FLOAT(@var{i})
9154 Returns the floating point equivalent of the integer @var{i}.
9155
9156 @item HIGH(@var{a})
9157 Returns the index of the last member of @var{a}.
9158
9159 @item INC(@var{v})
9160 Increments the value in the variable @var{v} by one. Returns the new value.
9161
9162 @item INC(@var{v},@var{i})
9163 Increments the value in the variable @var{v} by @var{i}. Returns the
9164 new value.
9165
9166 @item INCL(@var{m},@var{s})
9167 Adds the element @var{m} to the set @var{s} if it is not already
9168 there. Returns the new set.
9169
9170 @item MAX(@var{t})
9171 Returns the maximum value of the type @var{t}.
9172
9173 @item MIN(@var{t})
9174 Returns the minimum value of the type @var{t}.
9175
9176 @item ODD(@var{i})
9177 Returns boolean TRUE if @var{i} is an odd number.
9178
9179 @item ORD(@var{x})
9180 Returns the ordinal value of its argument. For example, the ordinal
9181 value of a character is its @sc{ascii} value (on machines supporting the
9182 @sc{ascii} character set). @var{x} must be of an ordered type, which include
9183 integral, character and enumerated types.
9184
9185 @item SIZE(@var{x})
9186 Returns the size of its argument. @var{x} can be a variable or a type.
9187
9188 @item TRUNC(@var{r})
9189 Returns the integral part of @var{r}.
9190
9191 @item VAL(@var{t},@var{i})
9192 Returns the member of the type @var{t} whose ordinal value is @var{i}.
9193 @end table
9194
9195 @quotation
9196 @emph{Warning:} Sets and their operations are not yet supported, so
9197 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9198 an error.
9199 @end quotation
9200
9201 @cindex Modula-2 constants
9202 @node M2 Constants
9203 @subsubsection Constants
9204
9205 @value{GDBN} allows you to express the constants of Modula-2 in the following
9206 ways:
9207
9208 @itemize @bullet
9209
9210 @item
9211 Integer constants are simply a sequence of digits. When used in an
9212 expression, a constant is interpreted to be type-compatible with the
9213 rest of the expression. Hexadecimal integers are specified by a
9214 trailing @samp{H}, and octal integers by a trailing @samp{B}.
9215
9216 @item
9217 Floating point constants appear as a sequence of digits, followed by a
9218 decimal point and another sequence of digits. An optional exponent can
9219 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9220 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9221 digits of the floating point constant must be valid decimal (base 10)
9222 digits.
9223
9224 @item
9225 Character constants consist of a single character enclosed by a pair of
9226 like quotes, either single (@code{'}) or double (@code{"}). They may
9227 also be expressed by their ordinal value (their @sc{ascii} value, usually)
9228 followed by a @samp{C}.
9229
9230 @item
9231 String constants consist of a sequence of characters enclosed by a
9232 pair of like quotes, either single (@code{'}) or double (@code{"}).
9233 Escape sequences in the style of C are also allowed. @xref{C
9234 Constants, ,C and C@t{++} constants}, for a brief explanation of escape
9235 sequences.
9236
9237 @item
9238 Enumerated constants consist of an enumerated identifier.
9239
9240 @item
9241 Boolean constants consist of the identifiers @code{TRUE} and
9242 @code{FALSE}.
9243
9244 @item
9245 Pointer constants consist of integral values only.
9246
9247 @item
9248 Set constants are not yet supported.
9249 @end itemize
9250
9251 @node M2 Defaults
9252 @subsubsection Modula-2 defaults
9253 @cindex Modula-2 defaults
9254
9255 If type and range checking are set automatically by @value{GDBN}, they
9256 both default to @code{on} whenever the working language changes to
9257 Modula-2. This happens regardless of whether you or @value{GDBN}
9258 selected the working language.
9259
9260 If you allow @value{GDBN} to set the language automatically, then entering
9261 code compiled from a file whose name ends with @file{.mod} sets the
9262 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
9263 the language automatically}, for further details.
9264
9265 @node Deviations
9266 @subsubsection Deviations from standard Modula-2
9267 @cindex Modula-2, deviations from
9268
9269 A few changes have been made to make Modula-2 programs easier to debug.
9270 This is done primarily via loosening its type strictness:
9271
9272 @itemize @bullet
9273 @item
9274 Unlike in standard Modula-2, pointer constants can be formed by
9275 integers. This allows you to modify pointer variables during
9276 debugging. (In standard Modula-2, the actual address contained in a
9277 pointer variable is hidden from you; it can only be modified
9278 through direct assignment to another pointer variable or expression that
9279 returned a pointer.)
9280
9281 @item
9282 C escape sequences can be used in strings and characters to represent
9283 non-printable characters. @value{GDBN} prints out strings with these
9284 escape sequences embedded. Single non-printable characters are
9285 printed using the @samp{CHR(@var{nnn})} format.
9286
9287 @item
9288 The assignment operator (@code{:=}) returns the value of its right-hand
9289 argument.
9290
9291 @item
9292 All built-in procedures both modify @emph{and} return their argument.
9293 @end itemize
9294
9295 @node M2 Checks
9296 @subsubsection Modula-2 type and range checks
9297 @cindex Modula-2 checks
9298
9299 @quotation
9300 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9301 range checking.
9302 @end quotation
9303 @c FIXME remove warning when type/range checks added
9304
9305 @value{GDBN} considers two Modula-2 variables type equivalent if:
9306
9307 @itemize @bullet
9308 @item
9309 They are of types that have been declared equivalent via a @code{TYPE
9310 @var{t1} = @var{t2}} statement
9311
9312 @item
9313 They have been declared on the same line. (Note: This is true of the
9314 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9315 @end itemize
9316
9317 As long as type checking is enabled, any attempt to combine variables
9318 whose types are not equivalent is an error.
9319
9320 Range checking is done on all mathematical operations, assignment, array
9321 index bounds, and all built-in functions and procedures.
9322
9323 @node M2 Scope
9324 @subsubsection The scope operators @code{::} and @code{.}
9325 @cindex scope
9326 @cindex @code{.}, Modula-2 scope operator
9327 @cindex colon, doubled as scope operator
9328 @ifinfo
9329 @vindex colon-colon@r{, in Modula-2}
9330 @c Info cannot handle :: but TeX can.
9331 @end ifinfo
9332 @iftex
9333 @vindex ::@r{, in Modula-2}
9334 @end iftex
9335
9336 There are a few subtle differences between the Modula-2 scope operator
9337 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9338 similar syntax:
9339
9340 @smallexample
9341
9342 @var{module} . @var{id}
9343 @var{scope} :: @var{id}
9344 @end smallexample
9345
9346 @noindent
9347 where @var{scope} is the name of a module or a procedure,
9348 @var{module} the name of a module, and @var{id} is any declared
9349 identifier within your program, except another module.
9350
9351 Using the @code{::} operator makes @value{GDBN} search the scope
9352 specified by @var{scope} for the identifier @var{id}. If it is not
9353 found in the specified scope, then @value{GDBN} searches all scopes
9354 enclosing the one specified by @var{scope}.
9355
9356 Using the @code{.} operator makes @value{GDBN} search the current scope for
9357 the identifier specified by @var{id} that was imported from the
9358 definition module specified by @var{module}. With this operator, it is
9359 an error if the identifier @var{id} was not imported from definition
9360 module @var{module}, or if @var{id} is not an identifier in
9361 @var{module}.
9362
9363 @node GDB/M2
9364 @subsubsection @value{GDBN} and Modula-2
9365
9366 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9367 Five subcommands of @code{set print} and @code{show print} apply
9368 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
9369 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
9370 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
9371 analogue in Modula-2.
9372
9373 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
9374 with any language, is not useful with Modula-2. Its
9375 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
9376 created in Modula-2 as they can in C or C@t{++}. However, because an
9377 address can be specified by an integral constant, the construct
9378 @samp{@{@var{type}@}@var{adrexp}} is still useful.
9379
9380 @cindex @code{#} in Modula-2
9381 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9382 interpreted as the beginning of a comment. Use @code{<>} instead.
9383
9384 @node Ada
9385 @subsection Ada
9386 @cindex Ada
9387
9388 The extensions made to @value{GDBN} for Ada only support
9389 output from the @sc{gnu} Ada (GNAT) compiler.
9390 Other Ada compilers are not currently supported, and
9391 attempting to debug executables produced by them is most likely
9392 to be difficult.
9393
9394
9395 @cindex expressions in Ada
9396 @menu
9397 * Ada Mode Intro:: General remarks on the Ada syntax
9398 and semantics supported by Ada mode
9399 in @value{GDBN}.
9400 * Omissions from Ada:: Restrictions on the Ada expression syntax.
9401 * Additions to Ada:: Extensions of the Ada expression syntax.
9402 * Stopping Before Main Program:: Debugging the program during elaboration.
9403 * Ada Glitches:: Known peculiarities of Ada mode.
9404 @end menu
9405
9406 @node Ada Mode Intro
9407 @subsubsection Introduction
9408 @cindex Ada mode, general
9409
9410 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9411 syntax, with some extensions.
9412 The philosophy behind the design of this subset is
9413
9414 @itemize @bullet
9415 @item
9416 That @value{GDBN} should provide basic literals and access to operations for
9417 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9418 leaving more sophisticated computations to subprograms written into the
9419 program (which therefore may be called from @value{GDBN}).
9420
9421 @item
9422 That type safety and strict adherence to Ada language restrictions
9423 are not particularly important to the @value{GDBN} user.
9424
9425 @item
9426 That brevity is important to the @value{GDBN} user.
9427 @end itemize
9428
9429 Thus, for brevity, the debugger acts as if there were
9430 implicit @code{with} and @code{use} clauses in effect for all user-written
9431 packages, making it unnecessary to fully qualify most names with
9432 their packages, regardless of context. Where this causes ambiguity,
9433 @value{GDBN} asks the user's intent.
9434
9435 The debugger will start in Ada mode if it detects an Ada main program.
9436 As for other languages, it will enter Ada mode when stopped in a program that
9437 was translated from an Ada source file.
9438
9439 While in Ada mode, you may use `@t{--}' for comments. This is useful
9440 mostly for documenting command files. The standard @value{GDBN} comment
9441 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9442 middle (to allow based literals).
9443
9444 The debugger supports limited overloading. Given a subprogram call in which
9445 the function symbol has multiple definitions, it will use the number of
9446 actual parameters and some information about their types to attempt to narrow
9447 the set of definitions. It also makes very limited use of context, preferring
9448 procedures to functions in the context of the @code{call} command, and
9449 functions to procedures elsewhere.
9450
9451 @node Omissions from Ada
9452 @subsubsection Omissions from Ada
9453 @cindex Ada, omissions from
9454
9455 Here are the notable omissions from the subset:
9456
9457 @itemize @bullet
9458 @item
9459 Only a subset of the attributes are supported:
9460
9461 @itemize @minus
9462 @item
9463 @t{'First}, @t{'Last}, and @t{'Length}
9464 on array objects (not on types and subtypes).
9465
9466 @item
9467 @t{'Min} and @t{'Max}.
9468
9469 @item
9470 @t{'Pos} and @t{'Val}.
9471
9472 @item
9473 @t{'Tag}.
9474
9475 @item
9476 @t{'Range} on array objects (not subtypes), but only as the right
9477 operand of the membership (@code{in}) operator.
9478
9479 @item
9480 @t{'Access}, @t{'Unchecked_Access}, and
9481 @t{'Unrestricted_Access} (a GNAT extension).
9482
9483 @item
9484 @t{'Address}.
9485 @end itemize
9486
9487 @item
9488 The names in
9489 @code{Characters.Latin_1} are not available and
9490 concatenation is not implemented. Thus, escape characters in strings are
9491 not currently available.
9492
9493 @item
9494 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9495 equality of representations. They will generally work correctly
9496 for strings and arrays whose elements have integer or enumeration types.
9497 They may not work correctly for arrays whose element
9498 types have user-defined equality, for arrays of real values
9499 (in particular, IEEE-conformant floating point, because of negative
9500 zeroes and NaNs), and for arrays whose elements contain unused bits with
9501 indeterminate values.
9502
9503 @item
9504 The other component-by-component array operations (@code{and}, @code{or},
9505 @code{xor}, @code{not}, and relational tests other than equality)
9506 are not implemented.
9507
9508 @item
9509 There are no record or array aggregates.
9510
9511 @item
9512 Calls to dispatching subprograms are not implemented.
9513
9514 @item
9515 The overloading algorithm is much more limited (i.e., less selective)
9516 than that of real Ada. It makes only limited use of the context in which a subexpression
9517 appears to resolve its meaning, and it is much looser in its rules for allowing
9518 type matches. As a result, some function calls will be ambiguous, and the user
9519 will be asked to choose the proper resolution.
9520
9521 @item
9522 The @code{new} operator is not implemented.
9523
9524 @item
9525 Entry calls are not implemented.
9526
9527 @item
9528 Aside from printing, arithmetic operations on the native VAX floating-point
9529 formats are not supported.
9530
9531 @item
9532 It is not possible to slice a packed array.
9533 @end itemize
9534
9535 @node Additions to Ada
9536 @subsubsection Additions to Ada
9537 @cindex Ada, deviations from
9538
9539 As it does for other languages, @value{GDBN} makes certain generic
9540 extensions to Ada (@pxref{Expressions}):
9541
9542 @itemize @bullet
9543 @item
9544 If the expression @var{E} is a variable residing in memory
9545 (typically a local variable or array element) and @var{N} is
9546 a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9547 @var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9548 In Ada, this operator is generally not necessary, since its prime use
9549 is in displaying parts of an array, and slicing will usually do this in Ada.
9550 However, there are occasional uses when debugging programs
9551 in which certain debugging information has been optimized away.
9552
9553 @item
9554 @code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9555 in function or file @var{B}.'' When @var{B} is a file name, you must typically
9556 surround it in single quotes.
9557
9558 @item
9559 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9560 @var{type} that appears at address @var{addr}.''
9561
9562 @item
9563 A name starting with @samp{$} is a convenience variable
9564 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9565 @end itemize
9566
9567 In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9568 to Ada:
9569
9570 @itemize @bullet
9571 @item
9572 The assignment statement is allowed as an expression, returning
9573 its right-hand operand as its value. Thus, you may enter
9574
9575 @smallexample
9576 set x := y + 3
9577 print A(tmp := y + 1)
9578 @end smallexample
9579
9580 @item
9581 The semicolon is allowed as an ``operator,'' returning as its value
9582 the value of its right-hand operand.
9583 This allows, for example,
9584 complex conditional breaks:
9585
9586 @smallexample
9587 break f
9588 condition 1 (report(i); k += 1; A(k) > 100)
9589 @end smallexample
9590
9591 @item
9592 Rather than use catenation and symbolic character names to introduce special
9593 characters into strings, one may instead use a special bracket notation,
9594 which is also used to print strings. A sequence of characters of the form
9595 @samp{["@var{XX}"]} within a string or character literal denotes the
9596 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
9597 sequence of characters @samp{["""]} also denotes a single quotation mark
9598 in strings. For example,
9599 @smallexample
9600 "One line.["0a"]Next line.["0a"]"
9601 @end smallexample
9602 @noindent
9603 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9604 period.
9605
9606 @item
9607 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9608 @t{'Max} is optional (and is ignored in any case). For example, it is valid
9609 to write
9610
9611 @smallexample
9612 print 'max(x, y)
9613 @end smallexample
9614
9615 @item
9616 When printing arrays, @value{GDBN} uses positional notation when the
9617 array has a lower bound of 1, and uses a modified named notation otherwise.
9618 For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9619
9620 @smallexample
9621 (3 => 10, 17, 1)
9622 @end smallexample
9623
9624 @noindent
9625 That is, in contrast to valid Ada, only the first component has a @code{=>}
9626 clause.
9627
9628 @item
9629 You may abbreviate attributes in expressions with any unique,
9630 multi-character subsequence of
9631 their names (an exact match gets preference).
9632 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9633 in place of @t{a'length}.
9634
9635 @item
9636 @cindex quoting Ada internal identifiers
9637 Since Ada is case-insensitive, the debugger normally maps identifiers you type
9638 to lower case. The GNAT compiler uses upper-case characters for
9639 some of its internal identifiers, which are normally of no interest to users.
9640 For the rare occasions when you actually have to look at them,
9641 enclose them in angle brackets to avoid the lower-case mapping.
9642 For example,
9643 @smallexample
9644 @value{GDBP} print <JMPBUF_SAVE>[0]
9645 @end smallexample
9646
9647 @item
9648 Printing an object of class-wide type or dereferencing an
9649 access-to-class-wide value will display all the components of the object's
9650 specific type (as indicated by its run-time tag). Likewise, component
9651 selection on such a value will operate on the specific type of the
9652 object.
9653
9654 @end itemize
9655
9656 @node Stopping Before Main Program
9657 @subsubsection Stopping at the Very Beginning
9658
9659 @cindex breakpointing Ada elaboration code
9660 It is sometimes necessary to debug the program during elaboration, and
9661 before reaching the main procedure.
9662 As defined in the Ada Reference
9663 Manual, the elaboration code is invoked from a procedure called
9664 @code{adainit}. To run your program up to the beginning of
9665 elaboration, simply use the following two commands:
9666 @code{tbreak adainit} and @code{run}.
9667
9668 @node Ada Glitches
9669 @subsubsection Known Peculiarities of Ada Mode
9670 @cindex Ada, problems
9671
9672 Besides the omissions listed previously (@pxref{Omissions from Ada}),
9673 we know of several problems with and limitations of Ada mode in
9674 @value{GDBN},
9675 some of which will be fixed with planned future releases of the debugger
9676 and the GNU Ada compiler.
9677
9678 @itemize @bullet
9679 @item
9680 Currently, the debugger
9681 has insufficient information to determine whether certain pointers represent
9682 pointers to objects or the objects themselves.
9683 Thus, the user may have to tack an extra @code{.all} after an expression
9684 to get it printed properly.
9685
9686 @item
9687 Static constants that the compiler chooses not to materialize as objects in
9688 storage are invisible to the debugger.
9689
9690 @item
9691 Named parameter associations in function argument lists are ignored (the
9692 argument lists are treated as positional).
9693
9694 @item
9695 Many useful library packages are currently invisible to the debugger.
9696
9697 @item
9698 Fixed-point arithmetic, conversions, input, and output is carried out using
9699 floating-point arithmetic, and may give results that only approximate those on
9700 the host machine.
9701
9702 @item
9703 The type of the @t{'Address} attribute may not be @code{System.Address}.
9704
9705 @item
9706 The GNAT compiler never generates the prefix @code{Standard} for any of
9707 the standard symbols defined by the Ada language. @value{GDBN} knows about
9708 this: it will strip the prefix from names when you use it, and will never
9709 look for a name you have so qualified among local symbols, nor match against
9710 symbols in other packages or subprograms. If you have
9711 defined entities anywhere in your program other than parameters and
9712 local variables whose simple names match names in @code{Standard},
9713 GNAT's lack of qualification here can cause confusion. When this happens,
9714 you can usually resolve the confusion
9715 by qualifying the problematic names with package
9716 @code{Standard} explicitly.
9717 @end itemize
9718
9719 @node Unsupported languages
9720 @section Unsupported languages
9721
9722 @cindex unsupported languages
9723 @cindex minimal language
9724 In addition to the other fully-supported programming languages,
9725 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
9726 It does not represent a real programming language, but provides a set
9727 of capabilities close to what the C or assembly languages provide.
9728 This should allow most simple operations to be performed while debugging
9729 an application that uses a language currently not supported by @value{GDBN}.
9730
9731 If the language is set to @code{auto}, @value{GDBN} will automatically
9732 select this language if the current frame corresponds to an unsupported
9733 language.
9734
9735 @node Symbols
9736 @chapter Examining the Symbol Table
9737
9738 The commands described in this chapter allow you to inquire about the
9739 symbols (names of variables, functions and types) defined in your
9740 program. This information is inherent in the text of your program and
9741 does not change as your program executes. @value{GDBN} finds it in your
9742 program's symbol table, in the file indicated when you started @value{GDBN}
9743 (@pxref{File Options, ,Choosing files}), or by one of the
9744 file-management commands (@pxref{Files, ,Commands to specify files}).
9745
9746 @cindex symbol names
9747 @cindex names of symbols
9748 @cindex quoting names
9749 Occasionally, you may need to refer to symbols that contain unusual
9750 characters, which @value{GDBN} ordinarily treats as word delimiters. The
9751 most frequent case is in referring to static variables in other
9752 source files (@pxref{Variables,,Program variables}). File names
9753 are recorded in object files as debugging symbols, but @value{GDBN} would
9754 ordinarily parse a typical file name, like @file{foo.c}, as the three words
9755 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9756 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9757
9758 @smallexample
9759 p 'foo.c'::x
9760 @end smallexample
9761
9762 @noindent
9763 looks up the value of @code{x} in the scope of the file @file{foo.c}.
9764
9765 @table @code
9766 @cindex case-insensitive symbol names
9767 @cindex case sensitivity in symbol names
9768 @kindex set case-sensitive
9769 @item set case-sensitive on
9770 @itemx set case-sensitive off
9771 @itemx set case-sensitive auto
9772 Normally, when @value{GDBN} looks up symbols, it matches their names
9773 with case sensitivity determined by the current source language.
9774 Occasionally, you may wish to control that. The command @code{set
9775 case-sensitive} lets you do that by specifying @code{on} for
9776 case-sensitive matches or @code{off} for case-insensitive ones. If
9777 you specify @code{auto}, case sensitivity is reset to the default
9778 suitable for the source language. The default is case-sensitive
9779 matches for all languages except for Fortran, for which the default is
9780 case-insensitive matches.
9781
9782 @kindex show case-sensitive
9783 @item show case-sensitive
9784 This command shows the current setting of case sensitivity for symbols
9785 lookups.
9786
9787 @kindex info address
9788 @cindex address of a symbol
9789 @item info address @var{symbol}
9790 Describe where the data for @var{symbol} is stored. For a register
9791 variable, this says which register it is kept in. For a non-register
9792 local variable, this prints the stack-frame offset at which the variable
9793 is always stored.
9794
9795 Note the contrast with @samp{print &@var{symbol}}, which does not work
9796 at all for a register variable, and for a stack local variable prints
9797 the exact address of the current instantiation of the variable.
9798
9799 @kindex info symbol
9800 @cindex symbol from address
9801 @cindex closest symbol and offset for an address
9802 @item info symbol @var{addr}
9803 Print the name of a symbol which is stored at the address @var{addr}.
9804 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9805 nearest symbol and an offset from it:
9806
9807 @smallexample
9808 (@value{GDBP}) info symbol 0x54320
9809 _initialize_vx + 396 in section .text
9810 @end smallexample
9811
9812 @noindent
9813 This is the opposite of the @code{info address} command. You can use
9814 it to find out the name of a variable or a function given its address.
9815
9816 @kindex whatis
9817 @item whatis @var{expr}
9818 Print the data type of expression @var{expr}. @var{expr} is not
9819 actually evaluated, and any side-effecting operations (such as
9820 assignments or function calls) inside it do not take place.
9821 @xref{Expressions, ,Expressions}.
9822
9823 @item whatis
9824 Print the data type of @code{$}, the last value in the value history.
9825
9826 @kindex ptype
9827 @item ptype @var{typename}
9828 Print a description of data type @var{typename}. @var{typename} may be
9829 the name of a type, or for C code it may have the form @samp{class
9830 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9831 @var{union-tag}} or @samp{enum @var{enum-tag}}.
9832
9833 @item ptype @var{expr}
9834 @itemx ptype
9835 Print a description of the type of expression @var{expr}. @code{ptype}
9836 differs from @code{whatis} by printing a detailed description, instead
9837 of just the name of the type.
9838
9839 For example, for this variable declaration:
9840
9841 @smallexample
9842 struct complex @{double real; double imag;@} v;
9843 @end smallexample
9844
9845 @noindent
9846 the two commands give this output:
9847
9848 @smallexample
9849 @group
9850 (@value{GDBP}) whatis v
9851 type = struct complex
9852 (@value{GDBP}) ptype v
9853 type = struct complex @{
9854 double real;
9855 double imag;
9856 @}
9857 @end group
9858 @end smallexample
9859
9860 @noindent
9861 As with @code{whatis}, using @code{ptype} without an argument refers to
9862 the type of @code{$}, the last value in the value history.
9863
9864 @kindex info types
9865 @item info types @var{regexp}
9866 @itemx info types
9867 Print a brief description of all types whose names match the regular
9868 expression @var{regexp} (or all types in your program, if you supply
9869 no argument). Each complete typename is matched as though it were a
9870 complete line; thus, @samp{i type value} gives information on all
9871 types in your program whose names include the string @code{value}, but
9872 @samp{i type ^value$} gives information only on types whose complete
9873 name is @code{value}.
9874
9875 This command differs from @code{ptype} in two ways: first, like
9876 @code{whatis}, it does not print a detailed description; second, it
9877 lists all source files where a type is defined.
9878
9879 @kindex info scope
9880 @cindex local variables
9881 @item info scope @var{location}
9882 List all the variables local to a particular scope. This command
9883 accepts a @var{location} argument---a function name, a source line, or
9884 an address preceded by a @samp{*}, and prints all the variables local
9885 to the scope defined by that location. For example:
9886
9887 @smallexample
9888 (@value{GDBP}) @b{info scope command_line_handler}
9889 Scope for command_line_handler:
9890 Symbol rl is an argument at stack/frame offset 8, length 4.
9891 Symbol linebuffer is in static storage at address 0x150a18, length 4.
9892 Symbol linelength is in static storage at address 0x150a1c, length 4.
9893 Symbol p is a local variable in register $esi, length 4.
9894 Symbol p1 is a local variable in register $ebx, length 4.
9895 Symbol nline is a local variable in register $edx, length 4.
9896 Symbol repeat is a local variable at frame offset -8, length 4.
9897 @end smallexample
9898
9899 @noindent
9900 This command is especially useful for determining what data to collect
9901 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9902 collect}.
9903
9904 @kindex info source
9905 @item info source
9906 Show information about the current source file---that is, the source file for
9907 the function containing the current point of execution:
9908 @itemize @bullet
9909 @item
9910 the name of the source file, and the directory containing it,
9911 @item
9912 the directory it was compiled in,
9913 @item
9914 its length, in lines,
9915 @item
9916 which programming language it is written in,
9917 @item
9918 whether the executable includes debugging information for that file, and
9919 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9920 @item
9921 whether the debugging information includes information about
9922 preprocessor macros.
9923 @end itemize
9924
9925
9926 @kindex info sources
9927 @item info sources
9928 Print the names of all source files in your program for which there is
9929 debugging information, organized into two lists: files whose symbols
9930 have already been read, and files whose symbols will be read when needed.
9931
9932 @kindex info functions
9933 @item info functions
9934 Print the names and data types of all defined functions.
9935
9936 @item info functions @var{regexp}
9937 Print the names and data types of all defined functions
9938 whose names contain a match for regular expression @var{regexp}.
9939 Thus, @samp{info fun step} finds all functions whose names
9940 include @code{step}; @samp{info fun ^step} finds those whose names
9941 start with @code{step}. If a function name contains characters
9942 that conflict with the regular expression language (eg.
9943 @samp{operator*()}), they may be quoted with a backslash.
9944
9945 @kindex info variables
9946 @item info variables
9947 Print the names and data types of all variables that are declared
9948 outside of functions (i.e.@: excluding local variables).
9949
9950 @item info variables @var{regexp}
9951 Print the names and data types of all variables (except for local
9952 variables) whose names contain a match for regular expression
9953 @var{regexp}.
9954
9955 @kindex info classes
9956 @cindex Objective-C, classes and selectors
9957 @item info classes
9958 @itemx info classes @var{regexp}
9959 Display all Objective-C classes in your program, or
9960 (with the @var{regexp} argument) all those matching a particular regular
9961 expression.
9962
9963 @kindex info selectors
9964 @item info selectors
9965 @itemx info selectors @var{regexp}
9966 Display all Objective-C selectors in your program, or
9967 (with the @var{regexp} argument) all those matching a particular regular
9968 expression.
9969
9970 @ignore
9971 This was never implemented.
9972 @kindex info methods
9973 @item info methods
9974 @itemx info methods @var{regexp}
9975 The @code{info methods} command permits the user to examine all defined
9976 methods within C@t{++} program, or (with the @var{regexp} argument) a
9977 specific set of methods found in the various C@t{++} classes. Many
9978 C@t{++} classes provide a large number of methods. Thus, the output
9979 from the @code{ptype} command can be overwhelming and hard to use. The
9980 @code{info-methods} command filters the methods, printing only those
9981 which match the regular-expression @var{regexp}.
9982 @end ignore
9983
9984 @cindex reloading symbols
9985 Some systems allow individual object files that make up your program to
9986 be replaced without stopping and restarting your program. For example,
9987 in VxWorks you can simply recompile a defective object file and keep on
9988 running. If you are running on one of these systems, you can allow
9989 @value{GDBN} to reload the symbols for automatically relinked modules:
9990
9991 @table @code
9992 @kindex set symbol-reloading
9993 @item set symbol-reloading on
9994 Replace symbol definitions for the corresponding source file when an
9995 object file with a particular name is seen again.
9996
9997 @item set symbol-reloading off
9998 Do not replace symbol definitions when encountering object files of the
9999 same name more than once. This is the default state; if you are not
10000 running on a system that permits automatic relinking of modules, you
10001 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10002 may discard symbols when linking large programs, that may contain
10003 several modules (from different directories or libraries) with the same
10004 name.
10005
10006 @kindex show symbol-reloading
10007 @item show symbol-reloading
10008 Show the current @code{on} or @code{off} setting.
10009 @end table
10010
10011 @cindex opaque data types
10012 @kindex set opaque-type-resolution
10013 @item set opaque-type-resolution on
10014 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10015 declared as a pointer to a @code{struct}, @code{class}, or
10016 @code{union}---for example, @code{struct MyType *}---that is used in one
10017 source file although the full declaration of @code{struct MyType} is in
10018 another source file. The default is on.
10019
10020 A change in the setting of this subcommand will not take effect until
10021 the next time symbols for a file are loaded.
10022
10023 @item set opaque-type-resolution off
10024 Tell @value{GDBN} not to resolve opaque types. In this case, the type
10025 is printed as follows:
10026 @smallexample
10027 @{<no data fields>@}
10028 @end smallexample
10029
10030 @kindex show opaque-type-resolution
10031 @item show opaque-type-resolution
10032 Show whether opaque types are resolved or not.
10033
10034 @kindex maint print symbols
10035 @cindex symbol dump
10036 @kindex maint print psymbols
10037 @cindex partial symbol dump
10038 @item maint print symbols @var{filename}
10039 @itemx maint print psymbols @var{filename}
10040 @itemx maint print msymbols @var{filename}
10041 Write a dump of debugging symbol data into the file @var{filename}.
10042 These commands are used to debug the @value{GDBN} symbol-reading code. Only
10043 symbols with debugging data are included. If you use @samp{maint print
10044 symbols}, @value{GDBN} includes all the symbols for which it has already
10045 collected full details: that is, @var{filename} reflects symbols for
10046 only those files whose symbols @value{GDBN} has read. You can use the
10047 command @code{info sources} to find out which files these are. If you
10048 use @samp{maint print psymbols} instead, the dump shows information about
10049 symbols that @value{GDBN} only knows partially---that is, symbols defined in
10050 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10051 @samp{maint print msymbols} dumps just the minimal symbol information
10052 required for each object file from which @value{GDBN} has read some symbols.
10053 @xref{Files, ,Commands to specify files}, for a discussion of how
10054 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
10055
10056 @kindex maint info symtabs
10057 @kindex maint info psymtabs
10058 @cindex listing @value{GDBN}'s internal symbol tables
10059 @cindex symbol tables, listing @value{GDBN}'s internal
10060 @cindex full symbol tables, listing @value{GDBN}'s internal
10061 @cindex partial symbol tables, listing @value{GDBN}'s internal
10062 @item maint info symtabs @r{[} @var{regexp} @r{]}
10063 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
10064
10065 List the @code{struct symtab} or @code{struct partial_symtab}
10066 structures whose names match @var{regexp}. If @var{regexp} is not
10067 given, list them all. The output includes expressions which you can
10068 copy into a @value{GDBN} debugging this one to examine a particular
10069 structure in more detail. For example:
10070
10071 @smallexample
10072 (@value{GDBP}) maint info psymtabs dwarf2read
10073 @{ objfile /home/gnu/build/gdb/gdb
10074 ((struct objfile *) 0x82e69d0)
10075 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
10076 ((struct partial_symtab *) 0x8474b10)
10077 readin no
10078 fullname (null)
10079 text addresses 0x814d3c8 -- 0x8158074
10080 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10081 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10082 dependencies (none)
10083 @}
10084 @}
10085 (@value{GDBP}) maint info symtabs
10086 (@value{GDBP})
10087 @end smallexample
10088 @noindent
10089 We see that there is one partial symbol table whose filename contains
10090 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10091 and we see that @value{GDBN} has not read in any symtabs yet at all.
10092 If we set a breakpoint on a function, that will cause @value{GDBN} to
10093 read the symtab for the compilation unit containing that function:
10094
10095 @smallexample
10096 (@value{GDBP}) break dwarf2_psymtab_to_symtab
10097 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10098 line 1574.
10099 (@value{GDBP}) maint info symtabs
10100 @{ objfile /home/gnu/build/gdb/gdb
10101 ((struct objfile *) 0x82e69d0)
10102 @{ symtab /home/gnu/src/gdb/dwarf2read.c
10103 ((struct symtab *) 0x86c1f38)
10104 dirname (null)
10105 fullname (null)
10106 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10107 debugformat DWARF 2
10108 @}
10109 @}
10110 (@value{GDBP})
10111 @end smallexample
10112 @end table
10113
10114
10115 @node Altering
10116 @chapter Altering Execution
10117
10118 Once you think you have found an error in your program, you might want to
10119 find out for certain whether correcting the apparent error would lead to
10120 correct results in the rest of the run. You can find the answer by
10121 experiment, using the @value{GDBN} features for altering execution of the
10122 program.
10123
10124 For example, you can store new values into variables or memory
10125 locations, give your program a signal, restart it at a different
10126 address, or even return prematurely from a function.
10127
10128 @menu
10129 * Assignment:: Assignment to variables
10130 * Jumping:: Continuing at a different address
10131 * Signaling:: Giving your program a signal
10132 * Returning:: Returning from a function
10133 * Calling:: Calling your program's functions
10134 * Patching:: Patching your program
10135 @end menu
10136
10137 @node Assignment
10138 @section Assignment to variables
10139
10140 @cindex assignment
10141 @cindex setting variables
10142 To alter the value of a variable, evaluate an assignment expression.
10143 @xref{Expressions, ,Expressions}. For example,
10144
10145 @smallexample
10146 print x=4
10147 @end smallexample
10148
10149 @noindent
10150 stores the value 4 into the variable @code{x}, and then prints the
10151 value of the assignment expression (which is 4).
10152 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10153 information on operators in supported languages.
10154
10155 @kindex set variable
10156 @cindex variables, setting
10157 If you are not interested in seeing the value of the assignment, use the
10158 @code{set} command instead of the @code{print} command. @code{set} is
10159 really the same as @code{print} except that the expression's value is
10160 not printed and is not put in the value history (@pxref{Value History,
10161 ,Value history}). The expression is evaluated only for its effects.
10162
10163 If the beginning of the argument string of the @code{set} command
10164 appears identical to a @code{set} subcommand, use the @code{set
10165 variable} command instead of just @code{set}. This command is identical
10166 to @code{set} except for its lack of subcommands. For example, if your
10167 program has a variable @code{width}, you get an error if you try to set
10168 a new value with just @samp{set width=13}, because @value{GDBN} has the
10169 command @code{set width}:
10170
10171 @smallexample
10172 (@value{GDBP}) whatis width
10173 type = double
10174 (@value{GDBP}) p width
10175 $4 = 13
10176 (@value{GDBP}) set width=47
10177 Invalid syntax in expression.
10178 @end smallexample
10179
10180 @noindent
10181 The invalid expression, of course, is @samp{=47}. In
10182 order to actually set the program's variable @code{width}, use
10183
10184 @smallexample
10185 (@value{GDBP}) set var width=47
10186 @end smallexample
10187
10188 Because the @code{set} command has many subcommands that can conflict
10189 with the names of program variables, it is a good idea to use the
10190 @code{set variable} command instead of just @code{set}. For example, if
10191 your program has a variable @code{g}, you run into problems if you try
10192 to set a new value with just @samp{set g=4}, because @value{GDBN} has
10193 the command @code{set gnutarget}, abbreviated @code{set g}:
10194
10195 @smallexample
10196 @group
10197 (@value{GDBP}) whatis g
10198 type = double
10199 (@value{GDBP}) p g
10200 $1 = 1
10201 (@value{GDBP}) set g=4
10202 (@value{GDBP}) p g
10203 $2 = 1
10204 (@value{GDBP}) r
10205 The program being debugged has been started already.
10206 Start it from the beginning? (y or n) y
10207 Starting program: /home/smith/cc_progs/a.out
10208 "/home/smith/cc_progs/a.out": can't open to read symbols:
10209 Invalid bfd target.
10210 (@value{GDBP}) show g
10211 The current BFD target is "=4".
10212 @end group
10213 @end smallexample
10214
10215 @noindent
10216 The program variable @code{g} did not change, and you silently set the
10217 @code{gnutarget} to an invalid value. In order to set the variable
10218 @code{g}, use
10219
10220 @smallexample
10221 (@value{GDBP}) set var g=4
10222 @end smallexample
10223
10224 @value{GDBN} allows more implicit conversions in assignments than C; you can
10225 freely store an integer value into a pointer variable or vice versa,
10226 and you can convert any structure to any other structure that is the
10227 same length or shorter.
10228 @comment FIXME: how do structs align/pad in these conversions?
10229 @comment /doc@cygnus.com 18dec1990
10230
10231 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10232 construct to generate a value of specified type at a specified address
10233 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10234 to memory location @code{0x83040} as an integer (which implies a certain size
10235 and representation in memory), and
10236
10237 @smallexample
10238 set @{int@}0x83040 = 4
10239 @end smallexample
10240
10241 @noindent
10242 stores the value 4 into that memory location.
10243
10244 @node Jumping
10245 @section Continuing at a different address
10246
10247 Ordinarily, when you continue your program, you do so at the place where
10248 it stopped, with the @code{continue} command. You can instead continue at
10249 an address of your own choosing, with the following commands:
10250
10251 @table @code
10252 @kindex jump
10253 @item jump @var{linespec}
10254 Resume execution at line @var{linespec}. Execution stops again
10255 immediately if there is a breakpoint there. @xref{List, ,Printing
10256 source lines}, for a description of the different forms of
10257 @var{linespec}. It is common practice to use the @code{tbreak} command
10258 in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10259 breakpoints}.
10260
10261 The @code{jump} command does not change the current stack frame, or
10262 the stack pointer, or the contents of any memory location or any
10263 register other than the program counter. If line @var{linespec} is in
10264 a different function from the one currently executing, the results may
10265 be bizarre if the two functions expect different patterns of arguments or
10266 of local variables. For this reason, the @code{jump} command requests
10267 confirmation if the specified line is not in the function currently
10268 executing. However, even bizarre results are predictable if you are
10269 well acquainted with the machine-language code of your program.
10270
10271 @item jump *@var{address}
10272 Resume execution at the instruction at address @var{address}.
10273 @end table
10274
10275 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
10276 On many systems, you can get much the same effect as the @code{jump}
10277 command by storing a new value into the register @code{$pc}. The
10278 difference is that this does not start your program running; it only
10279 changes the address of where it @emph{will} run when you continue. For
10280 example,
10281
10282 @smallexample
10283 set $pc = 0x485
10284 @end smallexample
10285
10286 @noindent
10287 makes the next @code{continue} command or stepping command execute at
10288 address @code{0x485}, rather than at the address where your program stopped.
10289 @xref{Continuing and Stepping, ,Continuing and stepping}.
10290
10291 The most common occasion to use the @code{jump} command is to back
10292 up---perhaps with more breakpoints set---over a portion of a program
10293 that has already executed, in order to examine its execution in more
10294 detail.
10295
10296 @c @group
10297 @node Signaling
10298 @section Giving your program a signal
10299 @cindex deliver a signal to a program
10300
10301 @table @code
10302 @kindex signal
10303 @item signal @var{signal}
10304 Resume execution where your program stopped, but immediately give it the
10305 signal @var{signal}. @var{signal} can be the name or the number of a
10306 signal. For example, on many systems @code{signal 2} and @code{signal
10307 SIGINT} are both ways of sending an interrupt signal.
10308
10309 Alternatively, if @var{signal} is zero, continue execution without
10310 giving a signal. This is useful when your program stopped on account of
10311 a signal and would ordinary see the signal when resumed with the
10312 @code{continue} command; @samp{signal 0} causes it to resume without a
10313 signal.
10314
10315 @code{signal} does not repeat when you press @key{RET} a second time
10316 after executing the command.
10317 @end table
10318 @c @end group
10319
10320 Invoking the @code{signal} command is not the same as invoking the
10321 @code{kill} utility from the shell. Sending a signal with @code{kill}
10322 causes @value{GDBN} to decide what to do with the signal depending on
10323 the signal handling tables (@pxref{Signals}). The @code{signal} command
10324 passes the signal directly to your program.
10325
10326
10327 @node Returning
10328 @section Returning from a function
10329
10330 @table @code
10331 @cindex returning from a function
10332 @kindex return
10333 @item return
10334 @itemx return @var{expression}
10335 You can cancel execution of a function call with the @code{return}
10336 command. If you give an
10337 @var{expression} argument, its value is used as the function's return
10338 value.
10339 @end table
10340
10341 When you use @code{return}, @value{GDBN} discards the selected stack frame
10342 (and all frames within it). You can think of this as making the
10343 discarded frame return prematurely. If you wish to specify a value to
10344 be returned, give that value as the argument to @code{return}.
10345
10346 This pops the selected stack frame (@pxref{Selection, ,Selecting a
10347 frame}), and any other frames inside of it, leaving its caller as the
10348 innermost remaining frame. That frame becomes selected. The
10349 specified value is stored in the registers used for returning values
10350 of functions.
10351
10352 The @code{return} command does not resume execution; it leaves the
10353 program stopped in the state that would exist if the function had just
10354 returned. In contrast, the @code{finish} command (@pxref{Continuing
10355 and Stepping, ,Continuing and stepping}) resumes execution until the
10356 selected stack frame returns naturally.
10357
10358 @node Calling
10359 @section Calling program functions
10360
10361 @table @code
10362 @cindex calling functions
10363 @cindex inferior functions, calling
10364 @item print @var{expr}
10365 Evaluate the expression @var{expr} and display the resuling value.
10366 @var{expr} may include calls to functions in the program being
10367 debugged.
10368
10369 @kindex call
10370 @item call @var{expr}
10371 Evaluate the expression @var{expr} without displaying @code{void}
10372 returned values.
10373
10374 You can use this variant of the @code{print} command if you want to
10375 execute a function from your program that does not return anything
10376 (a.k.a.@: @dfn{a void function}), but without cluttering the output
10377 with @code{void} returned values that @value{GDBN} will otherwise
10378 print. If the result is not void, it is printed and saved in the
10379 value history.
10380 @end table
10381
10382 It is possible for the function you call via the @code{print} or
10383 @code{call} command to generate a signal (e.g., if there's a bug in
10384 the function, or if you passed it incorrect arguments). What happens
10385 in that case is controlled by the @code{set unwindonsignal} command.
10386
10387 @table @code
10388 @item set unwindonsignal
10389 @kindex set unwindonsignal
10390 @cindex unwind stack in called functions
10391 @cindex call dummy stack unwinding
10392 Set unwinding of the stack if a signal is received while in a function
10393 that @value{GDBN} called in the program being debugged. If set to on,
10394 @value{GDBN} unwinds the stack it created for the call and restores
10395 the context to what it was before the call. If set to off (the
10396 default), @value{GDBN} stops in the frame where the signal was
10397 received.
10398
10399 @item show unwindonsignal
10400 @kindex show unwindonsignal
10401 Show the current setting of stack unwinding in the functions called by
10402 @value{GDBN}.
10403 @end table
10404
10405 @cindex weak alias functions
10406 Sometimes, a function you wish to call is actually a @dfn{weak alias}
10407 for another function. In such case, @value{GDBN} might not pick up
10408 the type information, including the types of the function arguments,
10409 which causes @value{GDBN} to call the inferior function incorrectly.
10410 As a result, the called function will function erroneously and may
10411 even crash. A solution to that is to use the name of the aliased
10412 function instead.
10413
10414 @node Patching
10415 @section Patching programs
10416
10417 @cindex patching binaries
10418 @cindex writing into executables
10419 @cindex writing into corefiles
10420
10421 By default, @value{GDBN} opens the file containing your program's
10422 executable code (or the corefile) read-only. This prevents accidental
10423 alterations to machine code; but it also prevents you from intentionally
10424 patching your program's binary.
10425
10426 If you'd like to be able to patch the binary, you can specify that
10427 explicitly with the @code{set write} command. For example, you might
10428 want to turn on internal debugging flags, or even to make emergency
10429 repairs.
10430
10431 @table @code
10432 @kindex set write
10433 @item set write on
10434 @itemx set write off
10435 If you specify @samp{set write on}, @value{GDBN} opens executable and
10436 core files for both reading and writing; if you specify @samp{set write
10437 off} (the default), @value{GDBN} opens them read-only.
10438
10439 If you have already loaded a file, you must load it again (using the
10440 @code{exec-file} or @code{core-file} command) after changing @code{set
10441 write}, for your new setting to take effect.
10442
10443 @item show write
10444 @kindex show write
10445 Display whether executable files and core files are opened for writing
10446 as well as reading.
10447 @end table
10448
10449 @node GDB Files
10450 @chapter @value{GDBN} Files
10451
10452 @value{GDBN} needs to know the file name of the program to be debugged,
10453 both in order to read its symbol table and in order to start your
10454 program. To debug a core dump of a previous run, you must also tell
10455 @value{GDBN} the name of the core dump file.
10456
10457 @menu
10458 * Files:: Commands to specify files
10459 * Separate Debug Files:: Debugging information in separate files
10460 * Symbol Errors:: Errors reading symbol files
10461 @end menu
10462
10463 @node Files
10464 @section Commands to specify files
10465
10466 @cindex symbol table
10467 @cindex core dump file
10468
10469 You may want to specify executable and core dump file names. The usual
10470 way to do this is at start-up time, using the arguments to
10471 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10472 Out of @value{GDBN}}).
10473
10474 Occasionally it is necessary to change to a different file during a
10475 @value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10476 a file you want to use. In these situations the @value{GDBN} commands
10477 to specify new files are useful.
10478
10479 @table @code
10480 @cindex executable file
10481 @kindex file
10482 @item file @var{filename}
10483 Use @var{filename} as the program to be debugged. It is read for its
10484 symbols and for the contents of pure memory. It is also the program
10485 executed when you use the @code{run} command. If you do not specify a
10486 directory and the file is not found in the @value{GDBN} working directory,
10487 @value{GDBN} uses the environment variable @code{PATH} as a list of
10488 directories to search, just as the shell does when looking for a program
10489 to run. You can change the value of this variable, for both @value{GDBN}
10490 and your program, using the @code{path} command.
10491
10492 On systems with memory-mapped files, an auxiliary file named
10493 @file{@var{filename}.syms} may hold symbol table information for
10494 @var{filename}. If so, @value{GDBN} maps in the symbol table from
10495 @file{@var{filename}.syms}, starting up more quickly. See the
10496 descriptions of the file options @samp{-mapped} and @samp{-readnow}
10497 (available on the command line, see @ref{File Options, , -readnow},
10498 and with the commands @code{file}, @code{symbol-file}, or
10499 @code{add-symbol-file}, described below), for more information.
10500
10501 @item file
10502 @code{file} with no argument makes @value{GDBN} discard any information it
10503 has on both executable file and the symbol table.
10504
10505 @kindex exec-file
10506 @item exec-file @r{[} @var{filename} @r{]}
10507 Specify that the program to be run (but not the symbol table) is found
10508 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10509 if necessary to locate your program. Omitting @var{filename} means to
10510 discard information on the executable file.
10511
10512 @kindex symbol-file
10513 @item symbol-file @r{[} @var{filename} @r{]}
10514 Read symbol table information from file @var{filename}. @code{PATH} is
10515 searched when necessary. Use the @code{file} command to get both symbol
10516 table and program to run from the same file.
10517
10518 @code{symbol-file} with no argument clears out @value{GDBN} information on your
10519 program's symbol table.
10520
10521 The @code{symbol-file} command causes @value{GDBN} to forget the contents
10522 of its convenience variables, the value history, and all breakpoints and
10523 auto-display expressions. This is because they may contain pointers to
10524 the internal data recording symbols and data types, which are part of
10525 the old symbol table data being discarded inside @value{GDBN}.
10526
10527 @code{symbol-file} does not repeat if you press @key{RET} again after
10528 executing it once.
10529
10530 When @value{GDBN} is configured for a particular environment, it
10531 understands debugging information in whatever format is the standard
10532 generated for that environment; you may use either a @sc{gnu} compiler, or
10533 other compilers that adhere to the local conventions.
10534 Best results are usually obtained from @sc{gnu} compilers; for example,
10535 using @code{@value{GCC}} you can generate debugging information for
10536 optimized code.
10537
10538 For most kinds of object files, with the exception of old SVR3 systems
10539 using COFF, the @code{symbol-file} command does not normally read the
10540 symbol table in full right away. Instead, it scans the symbol table
10541 quickly to find which source files and which symbols are present. The
10542 details are read later, one source file at a time, as they are needed.
10543
10544 The purpose of this two-stage reading strategy is to make @value{GDBN}
10545 start up faster. For the most part, it is invisible except for
10546 occasional pauses while the symbol table details for a particular source
10547 file are being read. (The @code{set verbose} command can turn these
10548 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10549 warnings and messages}.)
10550
10551 We have not implemented the two-stage strategy for COFF yet. When the
10552 symbol table is stored in COFF format, @code{symbol-file} reads the
10553 symbol table data in full right away. Note that ``stabs-in-COFF''
10554 still does the two-stage strategy, since the debug info is actually
10555 in stabs format.
10556
10557 @kindex readnow
10558 @cindex reading symbols immediately
10559 @cindex symbols, reading immediately
10560 @kindex mapped
10561 @cindex memory-mapped symbol file
10562 @cindex saving symbol table
10563 @item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10564 @itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10565 You can override the @value{GDBN} two-stage strategy for reading symbol
10566 tables by using the @samp{-readnow} option with any of the commands that
10567 load symbol table information, if you want to be sure @value{GDBN} has the
10568 entire symbol table available.
10569
10570 If memory-mapped files are available on your system through the
10571 @code{mmap} system call, you can use another option, @samp{-mapped}, to
10572 cause @value{GDBN} to write the symbols for your program into a reusable
10573 file. Future @value{GDBN} debugging sessions map in symbol information
10574 from this auxiliary symbol file (if the program has not changed), rather
10575 than spending time reading the symbol table from the executable
10576 program. Using the @samp{-mapped} option has the same effect as
10577 starting @value{GDBN} with the @samp{-mapped} command-line option.
10578
10579 You can use both options together, to make sure the auxiliary symbol
10580 file has all the symbol information for your program.
10581
10582 The auxiliary symbol file for a program called @var{myprog} is called
10583 @samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10584 than the corresponding executable), @value{GDBN} always attempts to use
10585 it when you debug @var{myprog}; no special options or commands are
10586 needed.
10587
10588 The @file{.syms} file is specific to the host machine where you run
10589 @value{GDBN}. It holds an exact image of the internal @value{GDBN}
10590 symbol table. It cannot be shared across multiple host platforms.
10591
10592 @c FIXME: for now no mention of directories, since this seems to be in
10593 @c flux. 13mar1992 status is that in theory GDB would look either in
10594 @c current dir or in same dir as myprog; but issues like competing
10595 @c GDB's, or clutter in system dirs, mean that in practice right now
10596 @c only current dir is used. FFish says maybe a special GDB hierarchy
10597 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10598 @c files.
10599
10600 @kindex core-file
10601 @item core-file @r{[}@var{filename}@r{]}
10602 @itemx core
10603 Specify the whereabouts of a core dump file to be used as the ``contents
10604 of memory''. Traditionally, core files contain only some parts of the
10605 address space of the process that generated them; @value{GDBN} can access the
10606 executable file itself for other parts.
10607
10608 @code{core-file} with no argument specifies that no core file is
10609 to be used.
10610
10611 Note that the core file is ignored when your program is actually running
10612 under @value{GDBN}. So, if you have been running your program and you
10613 wish to debug a core file instead, you must kill the subprocess in which
10614 the program is running. To do this, use the @code{kill} command
10615 (@pxref{Kill Process, ,Killing the child process}).
10616
10617 @kindex add-symbol-file
10618 @cindex dynamic linking
10619 @item add-symbol-file @var{filename} @var{address}
10620 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10621 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
10622 The @code{add-symbol-file} command reads additional symbol table
10623 information from the file @var{filename}. You would use this command
10624 when @var{filename} has been dynamically loaded (by some other means)
10625 into the program that is running. @var{address} should be the memory
10626 address at which the file has been loaded; @value{GDBN} cannot figure
10627 this out for itself. You can additionally specify an arbitrary number
10628 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10629 section name and base address for that section. You can specify any
10630 @var{address} as an expression.
10631
10632 The symbol table of the file @var{filename} is added to the symbol table
10633 originally read with the @code{symbol-file} command. You can use the
10634 @code{add-symbol-file} command any number of times; the new symbol data
10635 thus read keeps adding to the old. To discard all old symbol data
10636 instead, use the @code{symbol-file} command without any arguments.
10637
10638 @cindex relocatable object files, reading symbols from
10639 @cindex object files, relocatable, reading symbols from
10640 @cindex reading symbols from relocatable object files
10641 @cindex symbols, reading from relocatable object files
10642 @cindex @file{.o} files, reading symbols from
10643 Although @var{filename} is typically a shared library file, an
10644 executable file, or some other object file which has been fully
10645 relocated for loading into a process, you can also load symbolic
10646 information from relocatable @file{.o} files, as long as:
10647
10648 @itemize @bullet
10649 @item
10650 the file's symbolic information refers only to linker symbols defined in
10651 that file, not to symbols defined by other object files,
10652 @item
10653 every section the file's symbolic information refers to has actually
10654 been loaded into the inferior, as it appears in the file, and
10655 @item
10656 you can determine the address at which every section was loaded, and
10657 provide these to the @code{add-symbol-file} command.
10658 @end itemize
10659
10660 @noindent
10661 Some embedded operating systems, like Sun Chorus and VxWorks, can load
10662 relocatable files into an already running program; such systems
10663 typically make the requirements above easy to meet. However, it's
10664 important to recognize that many native systems use complex link
10665 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
10666 assembly, for example) that make the requirements difficult to meet. In
10667 general, one cannot assume that using @code{add-symbol-file} to read a
10668 relocatable object file's symbolic information will have the same effect
10669 as linking the relocatable object file into the program in the normal
10670 way.
10671
10672 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10673
10674 You can use the @samp{-mapped} and @samp{-readnow} options just as with
10675 the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10676 table information for @var{filename}.
10677
10678 @kindex add-shared-symbol-files
10679 @kindex assf
10680 @item add-shared-symbol-files @var{library-file}
10681 @itemx assf @var{library-file}
10682 The @code{add-shared-symbol-files} command can currently be used only
10683 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10684 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10685 @value{GDBN} automatically looks for shared libraries, however if
10686 @value{GDBN} does not find yours, you can invoke
10687 @code{add-shared-symbol-files}. It takes one argument: the shared
10688 library's file name. @code{assf} is a shorthand alias for
10689 @code{add-shared-symbol-files}.
10690
10691 @kindex section
10692 @item section @var{section} @var{addr}
10693 The @code{section} command changes the base address of the named
10694 @var{section} of the exec file to @var{addr}. This can be used if the
10695 exec file does not contain section addresses, (such as in the
10696 @code{a.out} format), or when the addresses specified in the file
10697 itself are wrong. Each section must be changed separately. The
10698 @code{info files} command, described below, lists all the sections and
10699 their addresses.
10700
10701 @kindex info files
10702 @kindex info target
10703 @item info files
10704 @itemx info target
10705 @code{info files} and @code{info target} are synonymous; both print the
10706 current target (@pxref{Targets, ,Specifying a Debugging Target}),
10707 including the names of the executable and core dump files currently in
10708 use by @value{GDBN}, and the files from which symbols were loaded. The
10709 command @code{help target} lists all possible targets rather than
10710 current ones.
10711
10712 @kindex maint info sections
10713 @item maint info sections
10714 Another command that can give you extra information about program sections
10715 is @code{maint info sections}. In addition to the section information
10716 displayed by @code{info files}, this command displays the flags and file
10717 offset of each section in the executable and core dump files. In addition,
10718 @code{maint info sections} provides the following command options (which
10719 may be arbitrarily combined):
10720
10721 @table @code
10722 @item ALLOBJ
10723 Display sections for all loaded object files, including shared libraries.
10724 @item @var{sections}
10725 Display info only for named @var{sections}.
10726 @item @var{section-flags}
10727 Display info only for sections for which @var{section-flags} are true.
10728 The section flags that @value{GDBN} currently knows about are:
10729 @table @code
10730 @item ALLOC
10731 Section will have space allocated in the process when loaded.
10732 Set for all sections except those containing debug information.
10733 @item LOAD
10734 Section will be loaded from the file into the child process memory.
10735 Set for pre-initialized code and data, clear for @code{.bss} sections.
10736 @item RELOC
10737 Section needs to be relocated before loading.
10738 @item READONLY
10739 Section cannot be modified by the child process.
10740 @item CODE
10741 Section contains executable code only.
10742 @item DATA
10743 Section contains data only (no executable code).
10744 @item ROM
10745 Section will reside in ROM.
10746 @item CONSTRUCTOR
10747 Section contains data for constructor/destructor lists.
10748 @item HAS_CONTENTS
10749 Section is not empty.
10750 @item NEVER_LOAD
10751 An instruction to the linker to not output the section.
10752 @item COFF_SHARED_LIBRARY
10753 A notification to the linker that the section contains
10754 COFF shared library information.
10755 @item IS_COMMON
10756 Section contains common symbols.
10757 @end table
10758 @end table
10759 @kindex set trust-readonly-sections
10760 @cindex read-only sections
10761 @item set trust-readonly-sections on
10762 Tell @value{GDBN} that readonly sections in your object file
10763 really are read-only (i.e.@: that their contents will not change).
10764 In that case, @value{GDBN} can fetch values from these sections
10765 out of the object file, rather than from the target program.
10766 For some targets (notably embedded ones), this can be a significant
10767 enhancement to debugging performance.
10768
10769 The default is off.
10770
10771 @item set trust-readonly-sections off
10772 Tell @value{GDBN} not to trust readonly sections. This means that
10773 the contents of the section might change while the program is running,
10774 and must therefore be fetched from the target when needed.
10775
10776 @item show trust-readonly-sections
10777 Show the current setting of trusting readonly sections.
10778 @end table
10779
10780 All file-specifying commands allow both absolute and relative file names
10781 as arguments. @value{GDBN} always converts the file name to an absolute file
10782 name and remembers it that way.
10783
10784 @cindex shared libraries
10785 @value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10786 and IBM RS/6000 AIX shared libraries.
10787
10788 @value{GDBN} automatically loads symbol definitions from shared libraries
10789 when you use the @code{run} command, or when you examine a core file.
10790 (Before you issue the @code{run} command, @value{GDBN} does not understand
10791 references to a function in a shared library, however---unless you are
10792 debugging a core file).
10793
10794 On HP-UX, if the program loads a library explicitly, @value{GDBN}
10795 automatically loads the symbols at the time of the @code{shl_load} call.
10796
10797 @c FIXME: some @value{GDBN} release may permit some refs to undef
10798 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10799 @c FIXME...lib; check this from time to time when updating manual
10800
10801 There are times, however, when you may wish to not automatically load
10802 symbol definitions from shared libraries, such as when they are
10803 particularly large or there are many of them.
10804
10805 To control the automatic loading of shared library symbols, use the
10806 commands:
10807
10808 @table @code
10809 @kindex set auto-solib-add
10810 @item set auto-solib-add @var{mode}
10811 If @var{mode} is @code{on}, symbols from all shared object libraries
10812 will be loaded automatically when the inferior begins execution, you
10813 attach to an independently started inferior, or when the dynamic linker
10814 informs @value{GDBN} that a new library has been loaded. If @var{mode}
10815 is @code{off}, symbols must be loaded manually, using the
10816 @code{sharedlibrary} command. The default value is @code{on}.
10817
10818 @cindex memory used for symbol tables
10819 If your program uses lots of shared libraries with debug info that
10820 takes large amounts of memory, you can decrease the @value{GDBN}
10821 memory footprint by preventing it from automatically loading the
10822 symbols from shared libraries. To that end, type @kbd{set
10823 auto-solib-add off} before running the inferior, then load each
10824 library whose debug symbols you do need with @kbd{sharedlibrary
10825 @var{regexp}}, where @var{regexp} is a regular expresion that matches
10826 the libraries whose symbols you want to be loaded.
10827
10828 @kindex show auto-solib-add
10829 @item show auto-solib-add
10830 Display the current autoloading mode.
10831 @end table
10832
10833 To explicitly load shared library symbols, use the @code{sharedlibrary}
10834 command:
10835
10836 @table @code
10837 @kindex info sharedlibrary
10838 @kindex info share
10839 @item info share
10840 @itemx info sharedlibrary
10841 Print the names of the shared libraries which are currently loaded.
10842
10843 @kindex sharedlibrary
10844 @kindex share
10845 @item sharedlibrary @var{regex}
10846 @itemx share @var{regex}
10847 Load shared object library symbols for files matching a
10848 Unix regular expression.
10849 As with files loaded automatically, it only loads shared libraries
10850 required by your program for a core file or after typing @code{run}. If
10851 @var{regex} is omitted all shared libraries required by your program are
10852 loaded.
10853 @end table
10854
10855 On some systems, such as HP-UX systems, @value{GDBN} supports
10856 autoloading shared library symbols until a limiting threshold size is
10857 reached. This provides the benefit of allowing autoloading to remain on
10858 by default, but avoids autoloading excessively large shared libraries,
10859 up to a threshold that is initially set, but which you can modify if you
10860 wish.
10861
10862 Beyond that threshold, symbols from shared libraries must be explicitly
10863 loaded. To load these symbols, use the command @code{sharedlibrary
10864 @var{filename}}. The base address of the shared library is determined
10865 automatically by @value{GDBN} and need not be specified.
10866
10867 To display or set the threshold, use the commands:
10868
10869 @table @code
10870 @kindex set auto-solib-limit
10871 @item set auto-solib-limit @var{threshold}
10872 Set the autoloading size threshold, in an integral number of megabytes.
10873 If @var{threshold} is nonzero and shared library autoloading is enabled,
10874 symbols from all shared object libraries will be loaded until the total
10875 size of the loaded shared library symbols exceeds this threshold.
10876 Otherwise, symbols must be loaded manually, using the
10877 @code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
10878 Mb).
10879
10880 @kindex show auto-solib-limit
10881 @item show auto-solib-limit
10882 Display the current autoloading size threshold, in megabytes.
10883 @end table
10884
10885 Sometimes you may wish that @value{GDBN} stops and gives you control
10886 when any of shared library events happen. Use the @code{set
10887 stop-on-solib-events} command for this:
10888
10889 @table @code
10890 @item set stop-on-solib-events
10891 @kindex set stop-on-solib-events
10892 This command controls whether @value{GDBN} should give you control
10893 when the dynamic linker notifies it about some shared library event.
10894 The most common event of interest is loading or unloading of a new
10895 shared library.
10896
10897 @item show stop-on-solib-events
10898 @kindex show stop-on-solib-events
10899 Show whether @value{GDBN} stops and gives you control when shared
10900 library events happen.
10901 @end table
10902
10903 Shared libraries are also supported in many cross or remote debugging
10904 configurations. A copy of the target's libraries need to be present on the
10905 host system; they need to be the same as the target libraries, although the
10906 copies on the target can be stripped as long as the copies on the host are
10907 not.
10908
10909 You need to tell @value{GDBN} where the target libraries are, so that it can
10910 load the correct copies---otherwise, it may try to load the host's libraries.
10911 @value{GDBN} has two variables to specify the search directories for target
10912 libraries.
10913
10914 @table @code
10915 @kindex set solib-absolute-prefix
10916 @item set solib-absolute-prefix @var{path}
10917 If this variable is set, @var{path} will be used as a prefix for any
10918 absolute shared library paths; many runtime loaders store the absolute
10919 paths to the shared library in the target program's memory. If you use
10920 @samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10921 out in the same way that they are on the target, with e.g.@: a
10922 @file{/usr/lib} hierarchy under @var{path}.
10923
10924 You can set the default value of @samp{solib-absolute-prefix} by using the
10925 configure-time @samp{--with-sysroot} option.
10926
10927 @kindex show solib-absolute-prefix
10928 @item show solib-absolute-prefix
10929 Display the current shared library prefix.
10930
10931 @kindex set solib-search-path
10932 @item set solib-search-path @var{path}
10933 If this variable is set, @var{path} is a colon-separated list of directories
10934 to search for shared libraries. @samp{solib-search-path} is used after
10935 @samp{solib-absolute-prefix} fails to locate the library, or if the path to
10936 the library is relative instead of absolute. If you want to use
10937 @samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10938 set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10939 @value{GDBN} from finding your host's libraries.
10940
10941 @kindex show solib-search-path
10942 @item show solib-search-path
10943 Display the current shared library search path.
10944 @end table
10945
10946
10947 @node Separate Debug Files
10948 @section Debugging Information in Separate Files
10949 @cindex separate debugging information files
10950 @cindex debugging information in separate files
10951 @cindex @file{.debug} subdirectories
10952 @cindex debugging information directory, global
10953 @cindex global debugging information directory
10954
10955 @value{GDBN} allows you to put a program's debugging information in a
10956 file separate from the executable itself, in a way that allows
10957 @value{GDBN} to find and load the debugging information automatically.
10958 Since debugging information can be very large --- sometimes larger
10959 than the executable code itself --- some systems distribute debugging
10960 information for their executables in separate files, which users can
10961 install only when they need to debug a problem.
10962
10963 If an executable's debugging information has been extracted to a
10964 separate file, the executable should contain a @dfn{debug link} giving
10965 the name of the debugging information file (with no directory
10966 components), and a checksum of its contents. (The exact form of a
10967 debug link is described below.) If the full name of the directory
10968 containing the executable is @var{execdir}, and the executable has a
10969 debug link that specifies the name @var{debugfile}, then @value{GDBN}
10970 will automatically search for the debugging information file in three
10971 places:
10972
10973 @itemize @bullet
10974 @item
10975 the directory containing the executable file (that is, it will look
10976 for a file named @file{@var{execdir}/@var{debugfile}},
10977 @item
10978 a subdirectory of that directory named @file{.debug} (that is, the
10979 file @file{@var{execdir}/.debug/@var{debugfile}}, and
10980 @item
10981 a subdirectory of the global debug file directory that includes the
10982 executable's full path, and the name from the link (that is, the file
10983 @file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10984 @var{globaldebugdir} is the global debug file directory, and
10985 @var{execdir} has been turned into a relative path).
10986 @end itemize
10987 @noindent
10988 @value{GDBN} checks under each of these names for a debugging
10989 information file whose checksum matches that given in the link, and
10990 reads the debugging information from the first one it finds.
10991
10992 So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10993 which has a link containing the name @file{ls.debug}, and the global
10994 debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10995 for debug information in @file{/usr/bin/ls.debug},
10996 @file{/usr/bin/.debug/ls.debug}, and
10997 @file{/usr/lib/debug/usr/bin/ls.debug}.
10998
10999 You can set the global debugging info directory's name, and view the
11000 name @value{GDBN} is currently using.
11001
11002 @table @code
11003
11004 @kindex set debug-file-directory
11005 @item set debug-file-directory @var{directory}
11006 Set the directory which @value{GDBN} searches for separate debugging
11007 information files to @var{directory}.
11008
11009 @kindex show debug-file-directory
11010 @item show debug-file-directory
11011 Show the directory @value{GDBN} searches for separate debugging
11012 information files.
11013
11014 @end table
11015
11016 @cindex @code{.gnu_debuglink} sections
11017 @cindex debug links
11018 A debug link is a special section of the executable file named
11019 @code{.gnu_debuglink}. The section must contain:
11020
11021 @itemize
11022 @item
11023 A filename, with any leading directory components removed, followed by
11024 a zero byte,
11025 @item
11026 zero to three bytes of padding, as needed to reach the next four-byte
11027 boundary within the section, and
11028 @item
11029 a four-byte CRC checksum, stored in the same endianness used for the
11030 executable file itself. The checksum is computed on the debugging
11031 information file's full contents by the function given below, passing
11032 zero as the @var{crc} argument.
11033 @end itemize
11034
11035 Any executable file format can carry a debug link, as long as it can
11036 contain a section named @code{.gnu_debuglink} with the contents
11037 described above.
11038
11039 The debugging information file itself should be an ordinary
11040 executable, containing a full set of linker symbols, sections, and
11041 debugging information. The sections of the debugging information file
11042 should have the same names, addresses and sizes as the original file,
11043 but they need not contain any data --- much like a @code{.bss} section
11044 in an ordinary executable.
11045
11046 As of December 2002, there is no standard GNU utility to produce
11047 separated executable / debugging information file pairs. Ulrich
11048 Drepper's @file{elfutils} package, starting with version 0.53,
11049 contains a version of the @code{strip} command such that the command
11050 @kbd{strip foo -f foo.debug} removes the debugging information from
11051 the executable file @file{foo}, places it in the file
11052 @file{foo.debug}, and leaves behind a debug link in @file{foo}.
11053
11054 Since there are many different ways to compute CRC's (different
11055 polynomials, reversals, byte ordering, etc.), the simplest way to
11056 describe the CRC used in @code{.gnu_debuglink} sections is to give the
11057 complete code for a function that computes it:
11058
11059 @kindex gnu_debuglink_crc32
11060 @smallexample
11061 unsigned long
11062 gnu_debuglink_crc32 (unsigned long crc,
11063 unsigned char *buf, size_t len)
11064 @{
11065 static const unsigned long crc32_table[256] =
11066 @{
11067 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11068 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11069 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11070 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11071 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11072 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11073 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11074 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11075 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11076 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11077 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11078 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11079 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11080 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11081 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11082 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11083 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11084 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11085 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11086 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11087 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11088 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11089 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11090 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11091 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11092 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11093 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11094 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11095 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11096 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11097 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11098 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11099 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11100 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11101 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11102 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11103 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11104 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11105 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11106 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11107 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11108 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11109 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11110 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11111 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11112 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11113 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11114 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11115 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11116 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11117 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11118 0x2d02ef8d
11119 @};
11120 unsigned char *end;
11121
11122 crc = ~crc & 0xffffffff;
11123 for (end = buf + len; buf < end; ++buf)
11124 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
11125 return ~crc & 0xffffffff;
11126 @}
11127 @end smallexample
11128
11129
11130 @node Symbol Errors
11131 @section Errors reading symbol files
11132
11133 While reading a symbol file, @value{GDBN} occasionally encounters problems,
11134 such as symbol types it does not recognize, or known bugs in compiler
11135 output. By default, @value{GDBN} does not notify you of such problems, since
11136 they are relatively common and primarily of interest to people
11137 debugging compilers. If you are interested in seeing information
11138 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11139 only one message about each such type of problem, no matter how many
11140 times the problem occurs; or you can ask @value{GDBN} to print more messages,
11141 to see how many times the problems occur, with the @code{set
11142 complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11143 messages}).
11144
11145 The messages currently printed, and their meanings, include:
11146
11147 @table @code
11148 @item inner block not inside outer block in @var{symbol}
11149
11150 The symbol information shows where symbol scopes begin and end
11151 (such as at the start of a function or a block of statements). This
11152 error indicates that an inner scope block is not fully contained
11153 in its outer scope blocks.
11154
11155 @value{GDBN} circumvents the problem by treating the inner block as if it had
11156 the same scope as the outer block. In the error message, @var{symbol}
11157 may be shown as ``@code{(don't know)}'' if the outer block is not a
11158 function.
11159
11160 @item block at @var{address} out of order
11161
11162 The symbol information for symbol scope blocks should occur in
11163 order of increasing addresses. This error indicates that it does not
11164 do so.
11165
11166 @value{GDBN} does not circumvent this problem, and has trouble
11167 locating symbols in the source file whose symbols it is reading. (You
11168 can often determine what source file is affected by specifying
11169 @code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11170 messages}.)
11171
11172 @item bad block start address patched
11173
11174 The symbol information for a symbol scope block has a start address
11175 smaller than the address of the preceding source line. This is known
11176 to occur in the SunOS 4.1.1 (and earlier) C compiler.
11177
11178 @value{GDBN} circumvents the problem by treating the symbol scope block as
11179 starting on the previous source line.
11180
11181 @item bad string table offset in symbol @var{n}
11182
11183 @cindex foo
11184 Symbol number @var{n} contains a pointer into the string table which is
11185 larger than the size of the string table.
11186
11187 @value{GDBN} circumvents the problem by considering the symbol to have the
11188 name @code{foo}, which may cause other problems if many symbols end up
11189 with this name.
11190
11191 @item unknown symbol type @code{0x@var{nn}}
11192
11193 The symbol information contains new data types that @value{GDBN} does
11194 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
11195 uncomprehended information, in hexadecimal.
11196
11197 @value{GDBN} circumvents the error by ignoring this symbol information.
11198 This usually allows you to debug your program, though certain symbols
11199 are not accessible. If you encounter such a problem and feel like
11200 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11201 on @code{complain}, then go up to the function @code{read_dbx_symtab}
11202 and examine @code{*bufp} to see the symbol.
11203
11204 @item stub type has NULL name
11205
11206 @value{GDBN} could not find the full definition for a struct or class.
11207
11208 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
11209 The symbol information for a C@t{++} member function is missing some
11210 information that recent versions of the compiler should have output for
11211 it.
11212
11213 @item info mismatch between compiler and debugger
11214
11215 @value{GDBN} could not parse a type specification output by the compiler.
11216
11217 @end table
11218
11219 @node Targets
11220 @chapter Specifying a Debugging Target
11221
11222 @cindex debugging target
11223 A @dfn{target} is the execution environment occupied by your program.
11224
11225 Often, @value{GDBN} runs in the same host environment as your program;
11226 in that case, the debugging target is specified as a side effect when
11227 you use the @code{file} or @code{core} commands. When you need more
11228 flexibility---for example, running @value{GDBN} on a physically separate
11229 host, or controlling a standalone system over a serial port or a
11230 realtime system over a TCP/IP connection---you can use the @code{target}
11231 command to specify one of the target types configured for @value{GDBN}
11232 (@pxref{Target Commands, ,Commands for managing targets}).
11233
11234 @cindex target architecture
11235 It is possible to build @value{GDBN} for several different @dfn{target
11236 architectures}. When @value{GDBN} is built like that, you can choose
11237 one of the available architectures with the @kbd{set architecture}
11238 command.
11239
11240 @table @code
11241 @kindex set architecture
11242 @kindex show architecture
11243 @item set architecture @var{arch}
11244 This command sets the current target architecture to @var{arch}. The
11245 value of @var{arch} can be @code{"auto"}, in addition to one of the
11246 supported architectures.
11247
11248 @item show architecture
11249 Show the current target architecture.
11250
11251 @item set processor
11252 @itemx processor
11253 @kindex set processor
11254 @kindex show processor
11255 These are alias commands for, respectively, @code{set architecture}
11256 and @code{show architecture}.
11257 @end table
11258
11259 @menu
11260 * Active Targets:: Active targets
11261 * Target Commands:: Commands for managing targets
11262 * Byte Order:: Choosing target byte order
11263 * Remote:: Remote debugging
11264 * KOD:: Kernel Object Display
11265
11266 @end menu
11267
11268 @node Active Targets
11269 @section Active targets
11270
11271 @cindex stacking targets
11272 @cindex active targets
11273 @cindex multiple targets
11274
11275 There are three classes of targets: processes, core files, and
11276 executable files. @value{GDBN} can work concurrently on up to three
11277 active targets, one in each class. This allows you to (for example)
11278 start a process and inspect its activity without abandoning your work on
11279 a core file.
11280
11281 For example, if you execute @samp{gdb a.out}, then the executable file
11282 @code{a.out} is the only active target. If you designate a core file as
11283 well---presumably from a prior run that crashed and coredumped---then
11284 @value{GDBN} has two active targets and uses them in tandem, looking
11285 first in the corefile target, then in the executable file, to satisfy
11286 requests for memory addresses. (Typically, these two classes of target
11287 are complementary, since core files contain only a program's
11288 read-write memory---variables and so on---plus machine status, while
11289 executable files contain only the program text and initialized data.)
11290
11291 When you type @code{run}, your executable file becomes an active process
11292 target as well. When a process target is active, all @value{GDBN}
11293 commands requesting memory addresses refer to that target; addresses in
11294 an active core file or executable file target are obscured while the
11295 process target is active.
11296
11297 Use the @code{core-file} and @code{exec-file} commands to select a new
11298 core file or executable target (@pxref{Files, ,Commands to specify
11299 files}). To specify as a target a process that is already running, use
11300 the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11301 process}).
11302
11303 @node Target Commands
11304 @section Commands for managing targets
11305
11306 @table @code
11307 @item target @var{type} @var{parameters}
11308 Connects the @value{GDBN} host environment to a target machine or
11309 process. A target is typically a protocol for talking to debugging
11310 facilities. You use the argument @var{type} to specify the type or
11311 protocol of the target machine.
11312
11313 Further @var{parameters} are interpreted by the target protocol, but
11314 typically include things like device names or host names to connect
11315 with, process numbers, and baud rates.
11316
11317 The @code{target} command does not repeat if you press @key{RET} again
11318 after executing the command.
11319
11320 @kindex help target
11321 @item help target
11322 Displays the names of all targets available. To display targets
11323 currently selected, use either @code{info target} or @code{info files}
11324 (@pxref{Files, ,Commands to specify files}).
11325
11326 @item help target @var{name}
11327 Describe a particular target, including any parameters necessary to
11328 select it.
11329
11330 @kindex set gnutarget
11331 @item set gnutarget @var{args}
11332 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
11333 knows whether it is reading an @dfn{executable},
11334 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11335 with the @code{set gnutarget} command. Unlike most @code{target} commands,
11336 with @code{gnutarget} the @code{target} refers to a program, not a machine.
11337
11338 @quotation
11339 @emph{Warning:} To specify a file format with @code{set gnutarget},
11340 you must know the actual BFD name.
11341 @end quotation
11342
11343 @noindent
11344 @xref{Files, , Commands to specify files}.
11345
11346 @kindex show gnutarget
11347 @item show gnutarget
11348 Use the @code{show gnutarget} command to display what file format
11349 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
11350 @value{GDBN} will determine the file format for each file automatically,
11351 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11352 @end table
11353
11354 @cindex common targets
11355 Here are some common targets (available, or not, depending on the GDB
11356 configuration):
11357
11358 @table @code
11359 @kindex target
11360 @item target exec @var{program}
11361 @cindex executable file target
11362 An executable file. @samp{target exec @var{program}} is the same as
11363 @samp{exec-file @var{program}}.
11364
11365 @item target core @var{filename}
11366 @cindex core dump file target
11367 A core dump file. @samp{target core @var{filename}} is the same as
11368 @samp{core-file @var{filename}}.
11369
11370 @item target remote @var{dev}
11371 @cindex remote target
11372 Remote serial target in GDB-specific protocol. The argument @var{dev}
11373 specifies what serial device to use for the connection (e.g.
11374 @file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
11375 supports the @code{load} command. This is only useful if you have
11376 some other way of getting the stub to the target system, and you can put
11377 it somewhere in memory where it won't get clobbered by the download.
11378
11379 @item target sim
11380 @cindex built-in simulator target
11381 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
11382 In general,
11383 @smallexample
11384 target sim
11385 load
11386 run
11387 @end smallexample
11388 @noindent
11389 works; however, you cannot assume that a specific memory map, device
11390 drivers, or even basic I/O is available, although some simulators do
11391 provide these. For info about any processor-specific simulator details,
11392 see the appropriate section in @ref{Embedded Processors, ,Embedded
11393 Processors}.
11394
11395 @end table
11396
11397 Some configurations may include these targets as well:
11398
11399 @table @code
11400
11401 @item target nrom @var{dev}
11402 @cindex NetROM ROM emulator target
11403 NetROM ROM emulator. This target only supports downloading.
11404
11405 @end table
11406
11407 Different targets are available on different configurations of @value{GDBN};
11408 your configuration may have more or fewer targets.
11409
11410 Many remote targets require you to download the executable's code once
11411 you've successfully established a connection. You may wish to control
11412 various aspects of this process, such as the size of the data chunks
11413 used by @value{GDBN} to download program parts to the remote target.
11414
11415 @table @code
11416 @kindex set download-write-size
11417 @item set download-write-size @var{size}
11418 Set the write size used when downloading a program. Only used when
11419 downloading a program onto a remote target. Specify zero or a
11420 negative value to disable blocked writes. The actual size of each
11421 transfer is also limited by the size of the target packet and the
11422 memory cache.
11423
11424 @kindex show download-write-size
11425 @item show download-write-size
11426 @kindex show download-write-size
11427 Show the current value of the write size.
11428
11429 @item set hash
11430 @kindex set hash@r{, for remote monitors}
11431 @cindex hash mark while downloading
11432 This command controls whether a hash mark @samp{#} is displayed while
11433 downloading a file to the remote monitor. If on, a hash mark is
11434 displayed after each S-record is successfully downloaded to the
11435 monitor.
11436
11437 @item show hash
11438 @kindex show hash@r{, for remote monitors}
11439 Show the current status of displaying the hash mark.
11440
11441 @item set debug monitor
11442 @kindex set debug monitor
11443 @cindex display remote monitor communications
11444 Enable or disable display of communications messages between
11445 @value{GDBN} and the remote monitor.
11446
11447 @item show debug monitor
11448 @kindex show debug monitor
11449 Show the current status of displaying communications between
11450 @value{GDBN} and the remote monitor.
11451 @end table
11452
11453 @table @code
11454
11455 @kindex load @var{filename}
11456 @item load @var{filename}
11457 Depending on what remote debugging facilities are configured into
11458 @value{GDBN}, the @code{load} command may be available. Where it exists, it
11459 is meant to make @var{filename} (an executable) available for debugging
11460 on the remote system---by downloading, or dynamic linking, for example.
11461 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11462 the @code{add-symbol-file} command.
11463
11464 If your @value{GDBN} does not have a @code{load} command, attempting to
11465 execute it gets the error message ``@code{You can't do that when your
11466 target is @dots{}}''
11467
11468 The file is loaded at whatever address is specified in the executable.
11469 For some object file formats, you can specify the load address when you
11470 link the program; for other formats, like a.out, the object file format
11471 specifies a fixed address.
11472 @c FIXME! This would be a good place for an xref to the GNU linker doc.
11473
11474 @code{load} does not repeat if you press @key{RET} again after using it.
11475 @end table
11476
11477 @node Byte Order
11478 @section Choosing target byte order
11479
11480 @cindex choosing target byte order
11481 @cindex target byte order
11482
11483 Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
11484 offer the ability to run either big-endian or little-endian byte
11485 orders. Usually the executable or symbol will include a bit to
11486 designate the endian-ness, and you will not need to worry about
11487 which to use. However, you may still find it useful to adjust
11488 @value{GDBN}'s idea of processor endian-ness manually.
11489
11490 @table @code
11491 @kindex set endian
11492 @item set endian big
11493 Instruct @value{GDBN} to assume the target is big-endian.
11494
11495 @item set endian little
11496 Instruct @value{GDBN} to assume the target is little-endian.
11497
11498 @item set endian auto
11499 Instruct @value{GDBN} to use the byte order associated with the
11500 executable.
11501
11502 @item show endian
11503 Display @value{GDBN}'s current idea of the target byte order.
11504
11505 @end table
11506
11507 Note that these commands merely adjust interpretation of symbolic
11508 data on the host, and that they have absolutely no effect on the
11509 target system.
11510
11511 @node Remote
11512 @section Remote debugging
11513 @cindex remote debugging
11514
11515 If you are trying to debug a program running on a machine that cannot run
11516 @value{GDBN} in the usual way, it is often useful to use remote debugging.
11517 For example, you might use remote debugging on an operating system kernel,
11518 or on a small system which does not have a general purpose operating system
11519 powerful enough to run a full-featured debugger.
11520
11521 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11522 to make this work with particular debugging targets. In addition,
11523 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
11524 but not specific to any particular target system) which you can use if you
11525 write the remote stubs---the code that runs on the remote system to
11526 communicate with @value{GDBN}.
11527
11528 Other remote targets may be available in your
11529 configuration of @value{GDBN}; use @code{help target} to list them.
11530
11531 @node KOD
11532 @section Kernel Object Display
11533 @cindex kernel object display
11534 @cindex KOD
11535
11536 Some targets support kernel object display. Using this facility,
11537 @value{GDBN} communicates specially with the underlying operating system
11538 and can display information about operating system-level objects such as
11539 mutexes and other synchronization objects. Exactly which objects can be
11540 displayed is determined on a per-OS basis.
11541
11542 @kindex set os
11543 Use the @code{set os} command to set the operating system. This tells
11544 @value{GDBN} which kernel object display module to initialize:
11545
11546 @smallexample
11547 (@value{GDBP}) set os cisco
11548 @end smallexample
11549
11550 @kindex show os
11551 The associated command @code{show os} displays the operating system
11552 set with the @code{set os} command; if no operating system has been
11553 set, @code{show os} will display an empty string @samp{""}.
11554
11555 If @code{set os} succeeds, @value{GDBN} will display some information
11556 about the operating system, and will create a new @code{info} command
11557 which can be used to query the target. The @code{info} command is named
11558 after the operating system:
11559
11560 @kindex info cisco
11561 @smallexample
11562 (@value{GDBP}) info cisco
11563 List of Cisco Kernel Objects
11564 Object Description
11565 any Any and all objects
11566 @end smallexample
11567
11568 Further subcommands can be used to query about particular objects known
11569 by the kernel.
11570
11571 There is currently no way to determine whether a given operating
11572 system is supported other than to try setting it with @kbd{set os
11573 @var{name}}, where @var{name} is the name of the operating system you
11574 want to try.
11575
11576
11577 @node Remote Debugging
11578 @chapter Debugging remote programs
11579
11580 @menu
11581 * Connecting:: Connecting to a remote target
11582 * Server:: Using the gdbserver program
11583 * NetWare:: Using the gdbserve.nlm program
11584 * Remote configuration:: Remote configuration
11585 * remote stub:: Implementing a remote stub
11586 @end menu
11587
11588 @node Connecting
11589 @section Connecting to a remote target
11590
11591 On the @value{GDBN} host machine, you will need an unstripped copy of
11592 your program, since @value{GDBN} needs symobl and debugging information.
11593 Start up @value{GDBN} as usual, using the name of the local copy of your
11594 program as the first argument.
11595
11596 @cindex serial line, @code{target remote}
11597 If you're using a serial line, you may want to give @value{GDBN} the
11598 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
11599 (@pxref{Remote configuration, set remotebaud}) before the
11600 @code{target} command.
11601
11602 After that, use @code{target remote} to establish communications with
11603 the target machine. Its argument specifies how to communicate---either
11604 via a devicename attached to a direct serial line, or a TCP or UDP port
11605 (possibly to a terminal server which in turn has a serial line to the
11606 target). For example, to use a serial line connected to the device
11607 named @file{/dev/ttyb}:
11608
11609 @smallexample
11610 target remote /dev/ttyb
11611 @end smallexample
11612
11613 @cindex TCP port, @code{target remote}
11614 To use a TCP connection, use an argument of the form
11615 @code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11616 For example, to connect to port 2828 on a
11617 terminal server named @code{manyfarms}:
11618
11619 @smallexample
11620 target remote manyfarms:2828
11621 @end smallexample
11622
11623 If your remote target is actually running on the same machine as
11624 your debugger session (e.g.@: a simulator of your target running on
11625 the same host), you can omit the hostname. For example, to connect
11626 to port 1234 on your local machine:
11627
11628 @smallexample
11629 target remote :1234
11630 @end smallexample
11631 @noindent
11632
11633 Note that the colon is still required here.
11634
11635 @cindex UDP port, @code{target remote}
11636 To use a UDP connection, use an argument of the form
11637 @code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11638 on a terminal server named @code{manyfarms}:
11639
11640 @smallexample
11641 target remote udp:manyfarms:2828
11642 @end smallexample
11643
11644 When using a UDP connection for remote debugging, you should keep in mind
11645 that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11646 busy or unreliable networks, which will cause havoc with your debugging
11647 session.
11648
11649 Now you can use all the usual commands to examine and change data and to
11650 step and continue the remote program.
11651
11652 @cindex interrupting remote programs
11653 @cindex remote programs, interrupting
11654 Whenever @value{GDBN} is waiting for the remote program, if you type the
11655 interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11656 program. This may or may not succeed, depending in part on the hardware
11657 and the serial drivers the remote system uses. If you type the
11658 interrupt character once again, @value{GDBN} displays this prompt:
11659
11660 @smallexample
11661 Interrupted while waiting for the program.
11662 Give up (and stop debugging it)? (y or n)
11663 @end smallexample
11664
11665 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11666 (If you decide you want to try again later, you can use @samp{target
11667 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11668 goes back to waiting.
11669
11670 @table @code
11671 @kindex detach (remote)
11672 @item detach
11673 When you have finished debugging the remote program, you can use the
11674 @code{detach} command to release it from @value{GDBN} control.
11675 Detaching from the target normally resumes its execution, but the results
11676 will depend on your particular remote stub. After the @code{detach}
11677 command, @value{GDBN} is free to connect to another target.
11678
11679 @kindex disconnect
11680 @item disconnect
11681 The @code{disconnect} command behaves like @code{detach}, except that
11682 the target is generally not resumed. It will wait for @value{GDBN}
11683 (this instance or another one) to connect and continue debugging. After
11684 the @code{disconnect} command, @value{GDBN} is again free to connect to
11685 another target.
11686
11687 @cindex send command to remote monitor
11688 @kindex monitor
11689 @item monitor @var{cmd}
11690 This command allows you to send commands directly to the remote
11691 monitor.
11692 @end table
11693
11694 @node Server
11695 @section Using the @code{gdbserver} program
11696
11697 @kindex gdbserver
11698 @cindex remote connection without stubs
11699 @code{gdbserver} is a control program for Unix-like systems, which
11700 allows you to connect your program with a remote @value{GDBN} via
11701 @code{target remote}---but without linking in the usual debugging stub.
11702
11703 @code{gdbserver} is not a complete replacement for the debugging stubs,
11704 because it requires essentially the same operating-system facilities
11705 that @value{GDBN} itself does. In fact, a system that can run
11706 @code{gdbserver} to connect to a remote @value{GDBN} could also run
11707 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11708 because it is a much smaller program than @value{GDBN} itself. It is
11709 also easier to port than all of @value{GDBN}, so you may be able to get
11710 started more quickly on a new system by using @code{gdbserver}.
11711 Finally, if you develop code for real-time systems, you may find that
11712 the tradeoffs involved in real-time operation make it more convenient to
11713 do as much development work as possible on another system, for example
11714 by cross-compiling. You can use @code{gdbserver} to make a similar
11715 choice for debugging.
11716
11717 @value{GDBN} and @code{gdbserver} communicate via either a serial line
11718 or a TCP connection, using the standard @value{GDBN} remote serial
11719 protocol.
11720
11721 @table @emph
11722 @item On the target machine,
11723 you need to have a copy of the program you want to debug.
11724 @code{gdbserver} does not need your program's symbol table, so you can
11725 strip the program if necessary to save space. @value{GDBN} on the host
11726 system does all the symbol handling.
11727
11728 To use the server, you must tell it how to communicate with @value{GDBN};
11729 the name of your program; and the arguments for your program. The usual
11730 syntax is:
11731
11732 @smallexample
11733 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11734 @end smallexample
11735
11736 @var{comm} is either a device name (to use a serial line) or a TCP
11737 hostname and portnumber. For example, to debug Emacs with the argument
11738 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
11739 @file{/dev/com1}:
11740
11741 @smallexample
11742 target> gdbserver /dev/com1 emacs foo.txt
11743 @end smallexample
11744
11745 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
11746 with it.
11747
11748 To use a TCP connection instead of a serial line:
11749
11750 @smallexample
11751 target> gdbserver host:2345 emacs foo.txt
11752 @end smallexample
11753
11754 The only difference from the previous example is the first argument,
11755 specifying that you are communicating with the host @value{GDBN} via
11756 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11757 expect a TCP connection from machine @samp{host} to local TCP port 2345.
11758 (Currently, the @samp{host} part is ignored.) You can choose any number
11759 you want for the port number as long as it does not conflict with any
11760 TCP ports already in use on the target system (for example, @code{23} is
11761 reserved for @code{telnet}).@footnote{If you choose a port number that
11762 conflicts with another service, @code{gdbserver} prints an error message
11763 and exits.} You must use the same port number with the host @value{GDBN}
11764 @code{target remote} command.
11765
11766 On some targets, @code{gdbserver} can also attach to running programs.
11767 This is accomplished via the @code{--attach} argument. The syntax is:
11768
11769 @smallexample
11770 target> gdbserver @var{comm} --attach @var{pid}
11771 @end smallexample
11772
11773 @var{pid} is the process ID of a currently running process. It isn't necessary
11774 to point @code{gdbserver} at a binary for the running process.
11775
11776 @pindex pidof
11777 @cindex attach to a program by name
11778 You can debug processes by name instead of process ID if your target has the
11779 @code{pidof} utility:
11780
11781 @smallexample
11782 target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11783 @end smallexample
11784
11785 In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11786 has multiple threads, most versions of @code{pidof} support the
11787 @code{-s} option to only return the first process ID.
11788
11789 @item On the host machine,
11790 connect to your target (@pxref{Connecting,,Connecting to a remote target}).
11791 For TCP connections, you must start up @code{gdbserver} prior to using
11792 the @code{target remote} command. Otherwise you may get an error whose
11793 text depends on the host system, but which usually looks something like
11794 @samp{Connection refused}. You don't need to use the @code{load}
11795 command in @value{GDBN} when using gdbserver, since the program is
11796 already on the target.
11797
11798 @end table
11799
11800 @node NetWare
11801 @section Using the @code{gdbserve.nlm} program
11802
11803 @kindex gdbserve.nlm
11804 @code{gdbserve.nlm} is a control program for NetWare systems, which
11805 allows you to connect your program with a remote @value{GDBN} via
11806 @code{target remote}.
11807
11808 @value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11809 using the standard @value{GDBN} remote serial protocol.
11810
11811 @table @emph
11812 @item On the target machine,
11813 you need to have a copy of the program you want to debug.
11814 @code{gdbserve.nlm} does not need your program's symbol table, so you
11815 can strip the program if necessary to save space. @value{GDBN} on the
11816 host system does all the symbol handling.
11817
11818 To use the server, you must tell it how to communicate with
11819 @value{GDBN}; the name of your program; and the arguments for your
11820 program. The syntax is:
11821
11822 @smallexample
11823 load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11824 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11825 @end smallexample
11826
11827 @var{board} and @var{port} specify the serial line; @var{baud} specifies
11828 the baud rate used by the connection. @var{port} and @var{node} default
11829 to 0, @var{baud} defaults to 9600@dmn{bps}.
11830
11831 For example, to debug Emacs with the argument @samp{foo.txt}and
11832 communicate with @value{GDBN} over serial port number 2 or board 1
11833 using a 19200@dmn{bps} connection:
11834
11835 @smallexample
11836 load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11837 @end smallexample
11838
11839 @item
11840 On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11841 Connecting to a remote target}).
11842
11843 @end table
11844
11845 @node Remote configuration
11846 @section Remote configuration
11847
11848 @kindex set remote
11849 @kindex show remote
11850 This section documents the configuration options available when
11851 debugging remote programs. For the options related to the File I/O
11852 extensions of the remote protocol, see @ref{The system call,
11853 system-call-allowed}.
11854
11855 @table @code
11856 @item set remoteaddresssize @var{bits}
11857 @cindex adress size for remote targets
11858 @cindex bits in remote address
11859 Set the maximum size of address in a memory packet to the specified
11860 number of bits. @value{GDBN} will mask off the address bits above
11861 that number, when it passes addresses to the remote target. The
11862 default value is the number of bits in the target's address.
11863
11864 @item show remoteaddresssize
11865 Show the current value of remote address size in bits.
11866
11867 @item set remotebaud @var{n}
11868 @cindex baud rate for remote targets
11869 Set the baud rate for the remote serial I/O to @var{n} baud. The
11870 value is used to set the speed of the serial port used for debugging
11871 remote targets.
11872
11873 @item show remotebaud
11874 Show the current speed of the remote connection.
11875
11876 @item set remotebreak
11877 @cindex interrupt remote programs
11878 @cindex BREAK signal instead of Ctrl-C
11879 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
11880 when you press the @key{Ctrl-C} key to interrupt the program running
11881 on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
11882 character instead. The default is off, since most remote systems
11883 expect to see @samp{Ctrl-C} as the interrupt signal.
11884
11885 @item show remotebreak
11886 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
11887 interrupt the remote program.
11888
11889 @item set remotedebug
11890 @cindex debug remote protocol
11891 @cindex remote protocol debugging
11892 @cindex display remote packets
11893 Control the debugging of the remote protocol. When enabled, each
11894 packet sent to or received from the remote target is displayed. The
11895 defaults is off.
11896
11897 @item show remotedebug
11898 Show the current setting of the remote protocol debugging.
11899
11900 @item set remotedevice @var{device}
11901 @cindex serial port name
11902 Set the name of the serial port through which to communicate to the
11903 remote target to @var{device}. This is the device used by
11904 @value{GDBN} to open the serial communications line to the remote
11905 target. There's no default, so you must set a valid port name for the
11906 remote serial communications to work. (Some varieties of the
11907 @code{target} command accept the port name as part of their
11908 arguments.)
11909
11910 @item show remotedevice
11911 Show the current name of the serial port.
11912
11913 @item set remotelogbase @var{base}
11914 Set the base (a.k.a.@: radix) of logging serial protocol
11915 communications to @var{base}. Supported values of @var{base} are:
11916 @code{ascii}, @code{octal}, and @code{hex}. The default is
11917 @code{ascii}.
11918
11919 @item show remotelogbase
11920 Show the current setting of the radix for logging remote serial
11921 protocol.
11922
11923 @item set remotelogfile @var{file}
11924 @cindex record serial communications on file
11925 Record remote serial communications on the named @var{file}. The
11926 default is not to record at all.
11927
11928 @item show remotelogfile.
11929 Show the current setting of the file name on which to record the
11930 serial communications.
11931
11932 @item set remotetimeout @var{num}
11933 @cindex timeout for serial communications
11934 @cindex remote timeout
11935 Set the timeout limit to wait for the remote target to respond to
11936 @var{num} seconds. The default is 2 seconds.
11937
11938 @item show remotetimeout
11939 Show the current number of seconds to wait for the remote target
11940 responses.
11941
11942 @cindex limit hardware breakpoints and watchpoints
11943 @cindex remote target, limit break- and watchpoints
11944 @anchor{set remote hardware-watchpoint-limit}
11945 @anchor{set remote hardware-breakpoint-limit}
11946 @item set remote hardware-watchpoint-limit @var{limit}
11947 @itemx set remote hardware-breakpoint-limit @var{limit}
11948 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11949 watchpoints. A limit of -1, the default, is treated as unlimited.
11950
11951 @item set remote fetch-register-packet
11952 @itemx set remote set-register-packet
11953 @itemx set remote P-packet
11954 @itemx set remote p-packet
11955 @cindex P-packet
11956 @cindex fetch registers from remote targets
11957 @cindex set registers in remote targets
11958 Determine whether @value{GDBN} can set and fetch registers from the
11959 remote target using the @samp{P} packets. The default depends on the
11960 remote stub's support of the @samp{P} packets (@value{GDBN} queries
11961 the stub when this packet is first required).
11962
11963 @item show remote fetch-register-packet
11964 @itemx show remote set-register-packet
11965 @itemx show remote P-packet
11966 @itemx show remote p-packet
11967 Show the current setting of using the @samp{P} packets for setting and
11968 fetching registers from the remote target.
11969
11970 @cindex binary downloads
11971 @cindex X-packet
11972 @item set remote binary-download-packet
11973 @itemx set remote X-packet
11974 Determine whether @value{GDBN} sends downloads in binary mode using
11975 the @samp{X} packets. The default is on.
11976
11977 @item show remote binary-download-packet
11978 @itemx show remote X-packet
11979 Show the current setting of using the @samp{X} packets for binary
11980 downloads.
11981
11982 @item set remote read-aux-vector-packet
11983 @cindex auxiliary vector of remote target
11984 @cindex @code{auxv}, and remote targets
11985 Set the use of the remote protocol's @samp{qPart:auxv:read} (target
11986 auxiliary vector read) request. This request is used to fetch the
11987 remote target's @dfn{auxiliary vector}, see @ref{OS Information,
11988 Auxiliary Vector}. The default setting depends on the remote stub's
11989 support of this request (@value{GDBN} queries the stub when this
11990 request is first required). @xref{General Query Packets, qPart}, for
11991 more information about this request.
11992
11993 @item show remote read-aux-vector-packet
11994 Show the current setting of use of the @samp{qPart:auxv:read} request.
11995
11996 @item set remote symbol-lookup-packet
11997 @cindex remote symbol lookup request
11998 Set the use of the remote protocol's @samp{qSymbol} (target symbol
11999 lookup) request. This request is used to communicate symbol
12000 information to the remote target, e.g., whenever a new shared library
12001 is loaded by the remote (@pxref{Files, shared libraries}). The
12002 default setting depends on the remote stub's support of this request
12003 (@value{GDBN} queries the stub when this request is first required).
12004 @xref{General Query Packets, qSymbol}, for more information about this
12005 request.
12006
12007 @item show remote symbol-lookup-packet
12008 Show the current setting of use of the @samp{qSymbol} request.
12009
12010 @item set remote verbose-resume-packet
12011 @cindex resume remote target
12012 @cindex signal thread, and remote targets
12013 @cindex single-step thread, and remote targets
12014 @cindex thread-specific operations on remote targets
12015 Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12016 request. This request is used to resume specific threads in the
12017 remote target, and to single-step or signal them. The default setting
12018 depends on the remote stub's support of this request (@value{GDBN}
12019 queries the stub when this request is first required). This setting
12020 affects debugging of multithreaded programs: if @samp{vCont} cannot be
12021 used, @value{GDBN} might be unable to single-step a specific thread,
12022 especially under @code{set scheduler-locking off}; it is also
12023 impossible to pause a specific thread. @xref{Packets, vCont}, for
12024 more details.
12025
12026 @item show remote verbose-resume-packet
12027 Show the current setting of use of the @samp{vCont} request
12028
12029 @item set remote software-breakpoint-packet
12030 @itemx set remote hardware-breakpoint-packet
12031 @itemx set remote write-watchpoint-packet
12032 @itemx set remote read-watchpoint-packet
12033 @itemx set remote access-watchpoint-packet
12034 @itemx set remote Z-packet
12035 @cindex Z-packet
12036 @cindex remote hardware breakpoints and watchpoints
12037 These commands enable or disable the use of @samp{Z} packets for
12038 setting breakpoints and watchpoints in the remote target. The default
12039 depends on the remote stub's support of the @samp{Z} packets
12040 (@value{GDBN} queries the stub when each packet is first required).
12041 The command @code{set remote Z-packet}, kept for back-compatibility,
12042 turns on or off all the features that require the use of @samp{Z}
12043 packets.
12044
12045 @item show remote software-breakpoint-packet
12046 @itemx show remote hardware-breakpoint-packet
12047 @itemx show remote write-watchpoint-packet
12048 @itemx show remote read-watchpoint-packet
12049 @itemx show remote access-watchpoint-packet
12050 @itemx show remote Z-packet
12051 Show the current setting of @samp{Z} packets usage.
12052 @end table
12053
12054 @node remote stub
12055 @section Implementing a remote stub
12056
12057 @cindex debugging stub, example
12058 @cindex remote stub, example
12059 @cindex stub example, remote debugging
12060 The stub files provided with @value{GDBN} implement the target side of the
12061 communication protocol, and the @value{GDBN} side is implemented in the
12062 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12063 these subroutines to communicate, and ignore the details. (If you're
12064 implementing your own stub file, you can still ignore the details: start
12065 with one of the existing stub files. @file{sparc-stub.c} is the best
12066 organized, and therefore the easiest to read.)
12067
12068 @cindex remote serial debugging, overview
12069 To debug a program running on another machine (the debugging
12070 @dfn{target} machine), you must first arrange for all the usual
12071 prerequisites for the program to run by itself. For example, for a C
12072 program, you need:
12073
12074 @enumerate
12075 @item
12076 A startup routine to set up the C runtime environment; these usually
12077 have a name like @file{crt0}. The startup routine may be supplied by
12078 your hardware supplier, or you may have to write your own.
12079
12080 @item
12081 A C subroutine library to support your program's
12082 subroutine calls, notably managing input and output.
12083
12084 @item
12085 A way of getting your program to the other machine---for example, a
12086 download program. These are often supplied by the hardware
12087 manufacturer, but you may have to write your own from hardware
12088 documentation.
12089 @end enumerate
12090
12091 The next step is to arrange for your program to use a serial port to
12092 communicate with the machine where @value{GDBN} is running (the @dfn{host}
12093 machine). In general terms, the scheme looks like this:
12094
12095 @table @emph
12096 @item On the host,
12097 @value{GDBN} already understands how to use this protocol; when everything
12098 else is set up, you can simply use the @samp{target remote} command
12099 (@pxref{Targets,,Specifying a Debugging Target}).
12100
12101 @item On the target,
12102 you must link with your program a few special-purpose subroutines that
12103 implement the @value{GDBN} remote serial protocol. The file containing these
12104 subroutines is called a @dfn{debugging stub}.
12105
12106 On certain remote targets, you can use an auxiliary program
12107 @code{gdbserver} instead of linking a stub into your program.
12108 @xref{Server,,Using the @code{gdbserver} program}, for details.
12109 @end table
12110
12111 The debugging stub is specific to the architecture of the remote
12112 machine; for example, use @file{sparc-stub.c} to debug programs on
12113 @sc{sparc} boards.
12114
12115 @cindex remote serial stub list
12116 These working remote stubs are distributed with @value{GDBN}:
12117
12118 @table @code
12119
12120 @item i386-stub.c
12121 @cindex @file{i386-stub.c}
12122 @cindex Intel
12123 @cindex i386
12124 For Intel 386 and compatible architectures.
12125
12126 @item m68k-stub.c
12127 @cindex @file{m68k-stub.c}
12128 @cindex Motorola 680x0
12129 @cindex m680x0
12130 For Motorola 680x0 architectures.
12131
12132 @item sh-stub.c
12133 @cindex @file{sh-stub.c}
12134 @cindex Renesas
12135 @cindex SH
12136 For Renesas SH architectures.
12137
12138 @item sparc-stub.c
12139 @cindex @file{sparc-stub.c}
12140 @cindex Sparc
12141 For @sc{sparc} architectures.
12142
12143 @item sparcl-stub.c
12144 @cindex @file{sparcl-stub.c}
12145 @cindex Fujitsu
12146 @cindex SparcLite
12147 For Fujitsu @sc{sparclite} architectures.
12148
12149 @end table
12150
12151 The @file{README} file in the @value{GDBN} distribution may list other
12152 recently added stubs.
12153
12154 @menu
12155 * Stub Contents:: What the stub can do for you
12156 * Bootstrapping:: What you must do for the stub
12157 * Debug Session:: Putting it all together
12158 @end menu
12159
12160 @node Stub Contents
12161 @subsection What the stub can do for you
12162
12163 @cindex remote serial stub
12164 The debugging stub for your architecture supplies these three
12165 subroutines:
12166
12167 @table @code
12168 @item set_debug_traps
12169 @findex set_debug_traps
12170 @cindex remote serial stub, initialization
12171 This routine arranges for @code{handle_exception} to run when your
12172 program stops. You must call this subroutine explicitly near the
12173 beginning of your program.
12174
12175 @item handle_exception
12176 @findex handle_exception
12177 @cindex remote serial stub, main routine
12178 This is the central workhorse, but your program never calls it
12179 explicitly---the setup code arranges for @code{handle_exception} to
12180 run when a trap is triggered.
12181
12182 @code{handle_exception} takes control when your program stops during
12183 execution (for example, on a breakpoint), and mediates communications
12184 with @value{GDBN} on the host machine. This is where the communications
12185 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
12186 representative on the target machine. It begins by sending summary
12187 information on the state of your program, then continues to execute,
12188 retrieving and transmitting any information @value{GDBN} needs, until you
12189 execute a @value{GDBN} command that makes your program resume; at that point,
12190 @code{handle_exception} returns control to your own code on the target
12191 machine.
12192
12193 @item breakpoint
12194 @cindex @code{breakpoint} subroutine, remote
12195 Use this auxiliary subroutine to make your program contain a
12196 breakpoint. Depending on the particular situation, this may be the only
12197 way for @value{GDBN} to get control. For instance, if your target
12198 machine has some sort of interrupt button, you won't need to call this;
12199 pressing the interrupt button transfers control to
12200 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12201 simply receiving characters on the serial port may also trigger a trap;
12202 again, in that situation, you don't need to call @code{breakpoint} from
12203 your own program---simply running @samp{target remote} from the host
12204 @value{GDBN} session gets control.
12205
12206 Call @code{breakpoint} if none of these is true, or if you simply want
12207 to make certain your program stops at a predetermined point for the
12208 start of your debugging session.
12209 @end table
12210
12211 @node Bootstrapping
12212 @subsection What you must do for the stub
12213
12214 @cindex remote stub, support routines
12215 The debugging stubs that come with @value{GDBN} are set up for a particular
12216 chip architecture, but they have no information about the rest of your
12217 debugging target machine.
12218
12219 First of all you need to tell the stub how to communicate with the
12220 serial port.
12221
12222 @table @code
12223 @item int getDebugChar()
12224 @findex getDebugChar
12225 Write this subroutine to read a single character from the serial port.
12226 It may be identical to @code{getchar} for your target system; a
12227 different name is used to allow you to distinguish the two if you wish.
12228
12229 @item void putDebugChar(int)
12230 @findex putDebugChar
12231 Write this subroutine to write a single character to the serial port.
12232 It may be identical to @code{putchar} for your target system; a
12233 different name is used to allow you to distinguish the two if you wish.
12234 @end table
12235
12236 @cindex control C, and remote debugging
12237 @cindex interrupting remote targets
12238 If you want @value{GDBN} to be able to stop your program while it is
12239 running, you need to use an interrupt-driven serial driver, and arrange
12240 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12241 character). That is the character which @value{GDBN} uses to tell the
12242 remote system to stop.
12243
12244 Getting the debugging target to return the proper status to @value{GDBN}
12245 probably requires changes to the standard stub; one quick and dirty way
12246 is to just execute a breakpoint instruction (the ``dirty'' part is that
12247 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12248
12249 Other routines you need to supply are:
12250
12251 @table @code
12252 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
12253 @findex exceptionHandler
12254 Write this function to install @var{exception_address} in the exception
12255 handling tables. You need to do this because the stub does not have any
12256 way of knowing what the exception handling tables on your target system
12257 are like (for example, the processor's table might be in @sc{rom},
12258 containing entries which point to a table in @sc{ram}).
12259 @var{exception_number} is the exception number which should be changed;
12260 its meaning is architecture-dependent (for example, different numbers
12261 might represent divide by zero, misaligned access, etc). When this
12262 exception occurs, control should be transferred directly to
12263 @var{exception_address}, and the processor state (stack, registers,
12264 and so on) should be just as it is when a processor exception occurs. So if
12265 you want to use a jump instruction to reach @var{exception_address}, it
12266 should be a simple jump, not a jump to subroutine.
12267
12268 For the 386, @var{exception_address} should be installed as an interrupt
12269 gate so that interrupts are masked while the handler runs. The gate
12270 should be at privilege level 0 (the most privileged level). The
12271 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
12272 help from @code{exceptionHandler}.
12273
12274 @item void flush_i_cache()
12275 @findex flush_i_cache
12276 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
12277 instruction cache, if any, on your target machine. If there is no
12278 instruction cache, this subroutine may be a no-op.
12279
12280 On target machines that have instruction caches, @value{GDBN} requires this
12281 function to make certain that the state of your program is stable.
12282 @end table
12283
12284 @noindent
12285 You must also make sure this library routine is available:
12286
12287 @table @code
12288 @item void *memset(void *, int, int)
12289 @findex memset
12290 This is the standard library function @code{memset} that sets an area of
12291 memory to a known value. If you have one of the free versions of
12292 @code{libc.a}, @code{memset} can be found there; otherwise, you must
12293 either obtain it from your hardware manufacturer, or write your own.
12294 @end table
12295
12296 If you do not use the GNU C compiler, you may need other standard
12297 library subroutines as well; this varies from one stub to another,
12298 but in general the stubs are likely to use any of the common library
12299 subroutines which @code{@value{GCC}} generates as inline code.
12300
12301
12302 @node Debug Session
12303 @subsection Putting it all together
12304
12305 @cindex remote serial debugging summary
12306 In summary, when your program is ready to debug, you must follow these
12307 steps.
12308
12309 @enumerate
12310 @item
12311 Make sure you have defined the supporting low-level routines
12312 (@pxref{Bootstrapping,,What you must do for the stub}):
12313 @display
12314 @code{getDebugChar}, @code{putDebugChar},
12315 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12316 @end display
12317
12318 @item
12319 Insert these lines near the top of your program:
12320
12321 @smallexample
12322 set_debug_traps();
12323 breakpoint();
12324 @end smallexample
12325
12326 @item
12327 For the 680x0 stub only, you need to provide a variable called
12328 @code{exceptionHook}. Normally you just use:
12329
12330 @smallexample
12331 void (*exceptionHook)() = 0;
12332 @end smallexample
12333
12334 @noindent
12335 but if before calling @code{set_debug_traps}, you set it to point to a
12336 function in your program, that function is called when
12337 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
12338 error). The function indicated by @code{exceptionHook} is called with
12339 one parameter: an @code{int} which is the exception number.
12340
12341 @item
12342 Compile and link together: your program, the @value{GDBN} debugging stub for
12343 your target architecture, and the supporting subroutines.
12344
12345 @item
12346 Make sure you have a serial connection between your target machine and
12347 the @value{GDBN} host, and identify the serial port on the host.
12348
12349 @item
12350 @c The "remote" target now provides a `load' command, so we should
12351 @c document that. FIXME.
12352 Download your program to your target machine (or get it there by
12353 whatever means the manufacturer provides), and start it.
12354
12355 @item
12356 Start @value{GDBN} on the host, and connect to the target
12357 (@pxref{Connecting,,Connecting to a remote target}).
12358
12359 @end enumerate
12360
12361 @node Configurations
12362 @chapter Configuration-Specific Information
12363
12364 While nearly all @value{GDBN} commands are available for all native and
12365 cross versions of the debugger, there are some exceptions. This chapter
12366 describes things that are only available in certain configurations.
12367
12368 There are three major categories of configurations: native
12369 configurations, where the host and target are the same, embedded
12370 operating system configurations, which are usually the same for several
12371 different processor architectures, and bare embedded processors, which
12372 are quite different from each other.
12373
12374 @menu
12375 * Native::
12376 * Embedded OS::
12377 * Embedded Processors::
12378 * Architectures::
12379 @end menu
12380
12381 @node Native
12382 @section Native
12383
12384 This section describes details specific to particular native
12385 configurations.
12386
12387 @menu
12388 * HP-UX:: HP-UX
12389 * BSD libkvm Interface:: Debugging BSD kernel memory images
12390 * SVR4 Process Information:: SVR4 process information
12391 * DJGPP Native:: Features specific to the DJGPP port
12392 * Cygwin Native:: Features specific to the Cygwin port
12393 * Hurd Native:: Features specific to @sc{gnu} Hurd
12394 * Neutrino:: Features specific to QNX Neutrino
12395 @end menu
12396
12397 @node HP-UX
12398 @subsection HP-UX
12399
12400 On HP-UX systems, if you refer to a function or variable name that
12401 begins with a dollar sign, @value{GDBN} searches for a user or system
12402 name first, before it searches for a convenience variable.
12403
12404
12405 @node BSD libkvm Interface
12406 @subsection BSD libkvm Interface
12407
12408 @cindex libkvm
12409 @cindex kernel memory image
12410 @cindex kernel crash dump
12411
12412 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12413 interface that provides a uniform interface for accessing kernel virtual
12414 memory images, including live systems and crash dumps. @value{GDBN}
12415 uses this interface to allow you to debug live kernels and kernel crash
12416 dumps on many native BSD configurations. This is implemented as a
12417 special @code{kvm} debugging target. For debugging a live system, load
12418 the currently running kernel into @value{GDBN} and connect to the
12419 @code{kvm} target:
12420
12421 @smallexample
12422 (@value{GDBP}) @b{target kvm}
12423 @end smallexample
12424
12425 For debugging crash dumps, provide the file name of the crash dump as an
12426 argument:
12427
12428 @smallexample
12429 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12430 @end smallexample
12431
12432 Once connected to the @code{kvm} target, the following commands are
12433 available:
12434
12435 @table @code
12436 @kindex kvm
12437 @item kvm pcb
12438 Set current context from the @dfn{Process Control Block} (PCB) address.
12439
12440 @item kvm proc
12441 Set current context from proc address. This command isn't available on
12442 modern FreeBSD systems.
12443 @end table
12444
12445 @node SVR4 Process Information
12446 @subsection SVR4 process information
12447 @cindex /proc
12448 @cindex examine process image
12449 @cindex process info via @file{/proc}
12450
12451 Many versions of SVR4 and compatible systems provide a facility called
12452 @samp{/proc} that can be used to examine the image of a running
12453 process using file-system subroutines. If @value{GDBN} is configured
12454 for an operating system with this facility, the command @code{info
12455 proc} is available to report information about the process running
12456 your program, or about any process running on your system. @code{info
12457 proc} works only on SVR4 systems that include the @code{procfs} code.
12458 This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12459 Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
12460
12461 @table @code
12462 @kindex info proc
12463 @cindex process ID
12464 @item info proc
12465 @itemx info proc @var{process-id}
12466 Summarize available information about any running process. If a
12467 process ID is specified by @var{process-id}, display information about
12468 that process; otherwise display information about the program being
12469 debugged. The summary includes the debugged process ID, the command
12470 line used to invoke it, its current working directory, and its
12471 executable file's absolute file name.
12472
12473 On some systems, @var{process-id} can be of the form
12474 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12475 within a process. If the optional @var{pid} part is missing, it means
12476 a thread from the process being debugged (the leading @samp{/} still
12477 needs to be present, or else @value{GDBN} will interpret the number as
12478 a process ID rather than a thread ID).
12479
12480 @item info proc mappings
12481 @cindex memory address space mappings
12482 Report the memory address space ranges accessible in the program, with
12483 information on whether the process has read, write, or execute access
12484 rights to each range. On @sc{gnu}/Linux systems, each memory range
12485 includes the object file which is mapped to that range, instead of the
12486 memory access rights to that range.
12487
12488 @item info proc stat
12489 @itemx info proc status
12490 @cindex process detailed status information
12491 These subcommands are specific to @sc{gnu}/Linux systems. They show
12492 the process-related information, including the user ID and group ID;
12493 how many threads are there in the process; its virtual memory usage;
12494 the signals that are pending, blocked, and ignored; its TTY; its
12495 consumption of system and user time; its stack size; its @samp{nice}
12496 value; etc. For more information, see the @samp{proc(5)} man page
12497 (type @kbd{man 5 proc} from your shell prompt).
12498
12499 @item info proc all
12500 Show all the information about the process described under all of the
12501 above @code{info proc} subcommands.
12502
12503 @ignore
12504 @comment These sub-options of 'info proc' were not included when
12505 @comment procfs.c was re-written. Keep their descriptions around
12506 @comment against the day when someone finds the time to put them back in.
12507 @kindex info proc times
12508 @item info proc times
12509 Starting time, user CPU time, and system CPU time for your program and
12510 its children.
12511
12512 @kindex info proc id
12513 @item info proc id
12514 Report on the process IDs related to your program: its own process ID,
12515 the ID of its parent, the process group ID, and the session ID.
12516 @end ignore
12517
12518 @item set procfs-trace
12519 @kindex set procfs-trace
12520 @cindex @code{procfs} API calls
12521 This command enables and disables tracing of @code{procfs} API calls.
12522
12523 @item show procfs-trace
12524 @kindex show procfs-trace
12525 Show the current state of @code{procfs} API call tracing.
12526
12527 @item set procfs-file @var{file}
12528 @kindex set procfs-file
12529 Tell @value{GDBN} to write @code{procfs} API trace to the named
12530 @var{file}. @value{GDBN} appends the trace info to the previous
12531 contents of the file. The default is to display the trace on the
12532 standard output.
12533
12534 @item show procfs-file
12535 @kindex show procfs-file
12536 Show the file to which @code{procfs} API trace is written.
12537
12538 @item proc-trace-entry
12539 @itemx proc-trace-exit
12540 @itemx proc-untrace-entry
12541 @itemx proc-untrace-exit
12542 @kindex proc-trace-entry
12543 @kindex proc-trace-exit
12544 @kindex proc-untrace-entry
12545 @kindex proc-untrace-exit
12546 These commands enable and disable tracing of entries into and exits
12547 from the @code{syscall} interface.
12548
12549 @item info pidlist
12550 @kindex info pidlist
12551 @cindex process list, QNX Neutrino
12552 For QNX Neutrino only, this command displays the list of all the
12553 processes and all the threads within each process.
12554
12555 @item info meminfo
12556 @kindex info meminfo
12557 @cindex mapinfo list, QNX Neutrino
12558 For QNX Neutrino only, this command displays the list of all mapinfos.
12559 @end table
12560
12561 @node DJGPP Native
12562 @subsection Features for Debugging @sc{djgpp} Programs
12563 @cindex @sc{djgpp} debugging
12564 @cindex native @sc{djgpp} debugging
12565 @cindex MS-DOS-specific commands
12566
12567 @sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
12568 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12569 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12570 top of real-mode DOS systems and their emulations.
12571
12572 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
12573 defines a few commands specific to the @sc{djgpp} port. This
12574 subsection describes those commands.
12575
12576 @table @code
12577 @kindex info dos
12578 @item info dos
12579 This is a prefix of @sc{djgpp}-specific commands which print
12580 information about the target system and important OS structures.
12581
12582 @kindex sysinfo
12583 @cindex MS-DOS system info
12584 @cindex free memory information (MS-DOS)
12585 @item info dos sysinfo
12586 This command displays assorted information about the underlying
12587 platform: the CPU type and features, the OS version and flavor, the
12588 DPMI version, and the available conventional and DPMI memory.
12589
12590 @cindex GDT
12591 @cindex LDT
12592 @cindex IDT
12593 @cindex segment descriptor tables
12594 @cindex descriptor tables display
12595 @item info dos gdt
12596 @itemx info dos ldt
12597 @itemx info dos idt
12598 These 3 commands display entries from, respectively, Global, Local,
12599 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12600 tables are data structures which store a descriptor for each segment
12601 that is currently in use. The segment's selector is an index into a
12602 descriptor table; the table entry for that index holds the
12603 descriptor's base address and limit, and its attributes and access
12604 rights.
12605
12606 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12607 segment (used for both data and the stack), and a DOS segment (which
12608 allows access to DOS/BIOS data structures and absolute addresses in
12609 conventional memory). However, the DPMI host will usually define
12610 additional segments in order to support the DPMI environment.
12611
12612 @cindex garbled pointers
12613 These commands allow to display entries from the descriptor tables.
12614 Without an argument, all entries from the specified table are
12615 displayed. An argument, which should be an integer expression, means
12616 display a single entry whose index is given by the argument. For
12617 example, here's a convenient way to display information about the
12618 debugged program's data segment:
12619
12620 @smallexample
12621 @exdent @code{(@value{GDBP}) info dos ldt $ds}
12622 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12623 @end smallexample
12624
12625 @noindent
12626 This comes in handy when you want to see whether a pointer is outside
12627 the data segment's limit (i.e.@: @dfn{garbled}).
12628
12629 @cindex page tables display (MS-DOS)
12630 @item info dos pde
12631 @itemx info dos pte
12632 These two commands display entries from, respectively, the Page
12633 Directory and the Page Tables. Page Directories and Page Tables are
12634 data structures which control how virtual memory addresses are mapped
12635 into physical addresses. A Page Table includes an entry for every
12636 page of memory that is mapped into the program's address space; there
12637 may be several Page Tables, each one holding up to 4096 entries. A
12638 Page Directory has up to 4096 entries, one each for every Page Table
12639 that is currently in use.
12640
12641 Without an argument, @kbd{info dos pde} displays the entire Page
12642 Directory, and @kbd{info dos pte} displays all the entries in all of
12643 the Page Tables. An argument, an integer expression, given to the
12644 @kbd{info dos pde} command means display only that entry from the Page
12645 Directory table. An argument given to the @kbd{info dos pte} command
12646 means display entries from a single Page Table, the one pointed to by
12647 the specified entry in the Page Directory.
12648
12649 @cindex direct memory access (DMA) on MS-DOS
12650 These commands are useful when your program uses @dfn{DMA} (Direct
12651 Memory Access), which needs physical addresses to program the DMA
12652 controller.
12653
12654 These commands are supported only with some DPMI servers.
12655
12656 @cindex physical address from linear address
12657 @item info dos address-pte @var{addr}
12658 This command displays the Page Table entry for a specified linear
12659 address. The argument linear address @var{addr} should already have the
12660 appropriate segment's base address added to it, because this command
12661 accepts addresses which may belong to @emph{any} segment. For
12662 example, here's how to display the Page Table entry for the page where
12663 the variable @code{i} is stored:
12664
12665 @smallexample
12666 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12667 @exdent @code{Page Table entry for address 0x11a00d30:}
12668 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
12669 @end smallexample
12670
12671 @noindent
12672 This says that @code{i} is stored at offset @code{0xd30} from the page
12673 whose physical base address is @code{0x02698000}, and prints all the
12674 attributes of that page.
12675
12676 Note that you must cast the addresses of variables to a @code{char *},
12677 since otherwise the value of @code{__djgpp_base_address}, the base
12678 address of all variables and functions in a @sc{djgpp} program, will
12679 be added using the rules of C pointer arithmetics: if @code{i} is
12680 declared an @code{int}, @value{GDBN} will add 4 times the value of
12681 @code{__djgpp_base_address} to the address of @code{i}.
12682
12683 Here's another example, it displays the Page Table entry for the
12684 transfer buffer:
12685
12686 @smallexample
12687 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12688 @exdent @code{Page Table entry for address 0x29110:}
12689 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12690 @end smallexample
12691
12692 @noindent
12693 (The @code{+ 3} offset is because the transfer buffer's address is the
12694 3rd member of the @code{_go32_info_block} structure.) The output of
12695 this command clearly shows that addresses in conventional memory are
12696 mapped 1:1, i.e.@: the physical and linear addresses are identical.
12697
12698 This command is supported only with some DPMI servers.
12699 @end table
12700
12701 In addition to native debugging, the DJGPP port supports remote
12702 debugging via a serial data link. The following commands are specific
12703 to remote serial debugging in the DJGPP port of @value{GDBN}.
12704
12705 @table @code
12706 @kindex set com1base
12707 @kindex set com1irq
12708 @kindex set com2base
12709 @kindex set com2irq
12710 @kindex set com3base
12711 @kindex set com3irq
12712 @kindex set com4base
12713 @kindex set com4irq
12714 @item set com1base @var{addr}
12715 This command sets the base I/O port address of the @file{COM1} serial
12716 port.
12717
12718 @item set com1irq @var{irq}
12719 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12720 for the @file{COM1} serial port.
12721
12722 There are similar commands @samp{set com2base}, @samp{set com3irq},
12723 etc.@: for setting the port address and the @code{IRQ} lines for the
12724 other 3 COM ports.
12725
12726 @kindex show com1base
12727 @kindex show com1irq
12728 @kindex show com2base
12729 @kindex show com2irq
12730 @kindex show com3base
12731 @kindex show com3irq
12732 @kindex show com4base
12733 @kindex show com4irq
12734 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12735 display the current settings of the base address and the @code{IRQ}
12736 lines used by the COM ports.
12737 @end table
12738
12739
12740 @node Cygwin Native
12741 @subsection Features for Debugging MS Windows PE executables
12742 @cindex MS Windows debugging
12743 @cindex native Cygwin debugging
12744 @cindex Cygwin-specific commands
12745
12746 @value{GDBN} supports native debugging of MS Windows programs, including
12747 DLLs with and without symbolic debugging information. There are various
12748 additional Cygwin-specific commands, described in this subsection. The
12749 subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12750 that have no debugging symbols.
12751
12752
12753 @table @code
12754 @kindex info w32
12755 @item info w32
12756 This is a prefix of MS Windows specific commands which print
12757 information about the target system and important OS structures.
12758
12759 @item info w32 selector
12760 This command displays information returned by
12761 the Win32 API @code{GetThreadSelectorEntry} function.
12762 It takes an optional argument that is evaluated to
12763 a long value to give the information about this given selector.
12764 Without argument, this command displays information
12765 about the the six segment registers.
12766
12767 @kindex info dll
12768 @item info dll
12769 This is a Cygwin specific alias of info shared.
12770
12771 @kindex dll-symbols
12772 @item dll-symbols
12773 This command loads symbols from a dll similarly to
12774 add-sym command but without the need to specify a base address.
12775
12776 @kindex set new-console
12777 @item set new-console @var{mode}
12778 If @var{mode} is @code{on} the debuggee will
12779 be started in a new console on next start.
12780 If @var{mode} is @code{off}i, the debuggee will
12781 be started in the same console as the debugger.
12782
12783 @kindex show new-console
12784 @item show new-console
12785 Displays whether a new console is used
12786 when the debuggee is started.
12787
12788 @kindex set new-group
12789 @item set new-group @var{mode}
12790 This boolean value controls whether the debuggee should
12791 start a new group or stay in the same group as the debugger.
12792 This affects the way the Windows OS handles
12793 Ctrl-C.
12794
12795 @kindex show new-group
12796 @item show new-group
12797 Displays current value of new-group boolean.
12798
12799 @kindex set debugevents
12800 @item set debugevents
12801 This boolean value adds debug output concerning events seen by the debugger.
12802
12803 @kindex set debugexec
12804 @item set debugexec
12805 This boolean value adds debug output concerning execute events
12806 seen by the debugger.
12807
12808 @kindex set debugexceptions
12809 @item set debugexceptions
12810 This boolean value adds debug ouptut concerning exception events
12811 seen by the debugger.
12812
12813 @kindex set debugmemory
12814 @item set debugmemory
12815 This boolean value adds debug ouptut concerning memory events
12816 seen by the debugger.
12817
12818 @kindex set shell
12819 @item set shell
12820 This boolean values specifies whether the debuggee is called
12821 via a shell or directly (default value is on).
12822
12823 @kindex show shell
12824 @item show shell
12825 Displays if the debuggee will be started with a shell.
12826
12827 @end table
12828
12829 @menu
12830 * Non-debug DLL symbols:: Support for DLLs without debugging symbols
12831 @end menu
12832
12833 @node Non-debug DLL symbols
12834 @subsubsection Support for DLLs without debugging symbols
12835 @cindex DLLs with no debugging symbols
12836 @cindex Minimal symbols and DLLs
12837
12838 Very often on windows, some of the DLLs that your program relies on do
12839 not include symbolic debugging information (for example,
12840 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
12841 symbols in a DLL, it relies on the minimal amount of symbolic
12842 information contained in the DLL's export table. This subsubsection
12843 describes working with such symbols, known internally to @value{GDBN} as
12844 ``minimal symbols''.
12845
12846 Note that before the debugged program has started execution, no DLLs
12847 will have been loaded. The easiest way around this problem is simply to
12848 start the program --- either by setting a breakpoint or letting the
12849 program run once to completion. It is also possible to force
12850 @value{GDBN} to load a particular DLL before starting the executable ---
12851 see the shared library information in @pxref{Files} or the
12852 @code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
12853 explicitly loading symbols from a DLL with no debugging information will
12854 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
12855 which may adversely affect symbol lookup performance.
12856
12857 @subsubsection DLL name prefixes
12858
12859 In keeping with the naming conventions used by the Microsoft debugging
12860 tools, DLL export symbols are made available with a prefix based on the
12861 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
12862 also entered into the symbol table, so @code{CreateFileA} is often
12863 sufficient. In some cases there will be name clashes within a program
12864 (particularly if the executable itself includes full debugging symbols)
12865 necessitating the use of the fully qualified name when referring to the
12866 contents of the DLL. Use single-quotes around the name to avoid the
12867 exclamation mark (``!'') being interpreted as a language operator.
12868
12869 Note that the internal name of the DLL may be all upper-case, even
12870 though the file name of the DLL is lower-case, or vice-versa. Since
12871 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
12872 some confusion. If in doubt, try the @code{info functions} and
12873 @code{info variables} commands or even @code{maint print msymbols} (see
12874 @pxref{Symbols}). Here's an example:
12875
12876 @smallexample
12877 (@value{GDBP}) info function CreateFileA
12878 All functions matching regular expression "CreateFileA":
12879
12880 Non-debugging symbols:
12881 0x77e885f4 CreateFileA
12882 0x77e885f4 KERNEL32!CreateFileA
12883 @end smallexample
12884
12885 @smallexample
12886 (@value{GDBP}) info function !
12887 All functions matching regular expression "!":
12888
12889 Non-debugging symbols:
12890 0x6100114c cygwin1!__assert
12891 0x61004034 cygwin1!_dll_crt0@@0
12892 0x61004240 cygwin1!dll_crt0(per_process *)
12893 [etc...]
12894 @end smallexample
12895
12896 @subsubsection Working with minimal symbols
12897
12898 Symbols extracted from a DLL's export table do not contain very much
12899 type information. All that @value{GDBN} can do is guess whether a symbol
12900 refers to a function or variable depending on the linker section that
12901 contains the symbol. Also note that the actual contents of the memory
12902 contained in a DLL are not available unless the program is running. This
12903 means that you cannot examine the contents of a variable or disassemble
12904 a function within a DLL without a running program.
12905
12906 Variables are generally treated as pointers and dereferenced
12907 automatically. For this reason, it is often necessary to prefix a
12908 variable name with the address-of operator (``&'') and provide explicit
12909 type information in the command. Here's an example of the type of
12910 problem:
12911
12912 @smallexample
12913 (@value{GDBP}) print 'cygwin1!__argv'
12914 $1 = 268572168
12915 @end smallexample
12916
12917 @smallexample
12918 (@value{GDBP}) x 'cygwin1!__argv'
12919 0x10021610: "\230y\""
12920 @end smallexample
12921
12922 And two possible solutions:
12923
12924 @smallexample
12925 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
12926 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
12927 @end smallexample
12928
12929 @smallexample
12930 (@value{GDBP}) x/2x &'cygwin1!__argv'
12931 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
12932 (@value{GDBP}) x/x 0x10021608
12933 0x10021608: 0x0022fd98
12934 (@value{GDBP}) x/s 0x0022fd98
12935 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
12936 @end smallexample
12937
12938 Setting a break point within a DLL is possible even before the program
12939 starts execution. However, under these circumstances, @value{GDBN} can't
12940 examine the initial instructions of the function in order to skip the
12941 function's frame set-up code. You can work around this by using ``*&''
12942 to set the breakpoint at a raw memory address:
12943
12944 @smallexample
12945 (@value{GDBP}) break *&'python22!PyOS_Readline'
12946 Breakpoint 1 at 0x1e04eff0
12947 @end smallexample
12948
12949 The author of these extensions is not entirely convinced that setting a
12950 break point within a shared DLL like @file{kernel32.dll} is completely
12951 safe.
12952
12953 @node Hurd Native
12954 @subsection Commands specific to @sc{gnu} Hurd systems
12955 @cindex @sc{gnu} Hurd debugging
12956
12957 This subsection describes @value{GDBN} commands specific to the
12958 @sc{gnu} Hurd native debugging.
12959
12960 @table @code
12961 @item set signals
12962 @itemx set sigs
12963 @kindex set signals@r{, Hurd command}
12964 @kindex set sigs@r{, Hurd command}
12965 This command toggles the state of inferior signal interception by
12966 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
12967 affected by this command. @code{sigs} is a shorthand alias for
12968 @code{signals}.
12969
12970 @item show signals
12971 @itemx show sigs
12972 @kindex show signals@r{, Hurd command}
12973 @kindex show sigs@r{, Hurd command}
12974 Show the current state of intercepting inferior's signals.
12975
12976 @item set signal-thread
12977 @itemx set sigthread
12978 @kindex set signal-thread
12979 @kindex set sigthread
12980 This command tells @value{GDBN} which thread is the @code{libc} signal
12981 thread. That thread is run when a signal is delivered to a running
12982 process. @code{set sigthread} is the shorthand alias of @code{set
12983 signal-thread}.
12984
12985 @item show signal-thread
12986 @itemx show sigthread
12987 @kindex show signal-thread
12988 @kindex show sigthread
12989 These two commands show which thread will run when the inferior is
12990 delivered a signal.
12991
12992 @item set stopped
12993 @kindex set stopped@r{, Hurd command}
12994 This commands tells @value{GDBN} that the inferior process is stopped,
12995 as with the @code{SIGSTOP} signal. The stopped process can be
12996 continued by delivering a signal to it.
12997
12998 @item show stopped
12999 @kindex show stopped@r{, Hurd command}
13000 This command shows whether @value{GDBN} thinks the debuggee is
13001 stopped.
13002
13003 @item set exceptions
13004 @kindex set exceptions@r{, Hurd command}
13005 Use this command to turn off trapping of exceptions in the inferior.
13006 When exception trapping is off, neither breakpoints nor
13007 single-stepping will work. To restore the default, set exception
13008 trapping on.
13009
13010 @item show exceptions
13011 @kindex show exceptions@r{, Hurd command}
13012 Show the current state of trapping exceptions in the inferior.
13013
13014 @item set task pause
13015 @kindex set task@r{, Hurd commands}
13016 @cindex task attributes (@sc{gnu} Hurd)
13017 @cindex pause current task (@sc{gnu} Hurd)
13018 This command toggles task suspension when @value{GDBN} has control.
13019 Setting it to on takes effect immediately, and the task is suspended
13020 whenever @value{GDBN} gets control. Setting it to off will take
13021 effect the next time the inferior is continued. If this option is set
13022 to off, you can use @code{set thread default pause on} or @code{set
13023 thread pause on} (see below) to pause individual threads.
13024
13025 @item show task pause
13026 @kindex show task@r{, Hurd commands}
13027 Show the current state of task suspension.
13028
13029 @item set task detach-suspend-count
13030 @cindex task suspend count
13031 @cindex detach from task, @sc{gnu} Hurd
13032 This command sets the suspend count the task will be left with when
13033 @value{GDBN} detaches from it.
13034
13035 @item show task detach-suspend-count
13036 Show the suspend count the task will be left with when detaching.
13037
13038 @item set task exception-port
13039 @itemx set task excp
13040 @cindex task exception port, @sc{gnu} Hurd
13041 This command sets the task exception port to which @value{GDBN} will
13042 forward exceptions. The argument should be the value of the @dfn{send
13043 rights} of the task. @code{set task excp} is a shorthand alias.
13044
13045 @item set noninvasive
13046 @cindex noninvasive task options
13047 This command switches @value{GDBN} to a mode that is the least
13048 invasive as far as interfering with the inferior is concerned. This
13049 is the same as using @code{set task pause}, @code{set exceptions}, and
13050 @code{set signals} to values opposite to the defaults.
13051
13052 @item info send-rights
13053 @itemx info receive-rights
13054 @itemx info port-rights
13055 @itemx info port-sets
13056 @itemx info dead-names
13057 @itemx info ports
13058 @itemx info psets
13059 @cindex send rights, @sc{gnu} Hurd
13060 @cindex receive rights, @sc{gnu} Hurd
13061 @cindex port rights, @sc{gnu} Hurd
13062 @cindex port sets, @sc{gnu} Hurd
13063 @cindex dead names, @sc{gnu} Hurd
13064 These commands display information about, respectively, send rights,
13065 receive rights, port rights, port sets, and dead names of a task.
13066 There are also shorthand aliases: @code{info ports} for @code{info
13067 port-rights} and @code{info psets} for @code{info port-sets}.
13068
13069 @item set thread pause
13070 @kindex set thread@r{, Hurd command}
13071 @cindex thread properties, @sc{gnu} Hurd
13072 @cindex pause current thread (@sc{gnu} Hurd)
13073 This command toggles current thread suspension when @value{GDBN} has
13074 control. Setting it to on takes effect immediately, and the current
13075 thread is suspended whenever @value{GDBN} gets control. Setting it to
13076 off will take effect the next time the inferior is continued.
13077 Normally, this command has no effect, since when @value{GDBN} has
13078 control, the whole task is suspended. However, if you used @code{set
13079 task pause off} (see above), this command comes in handy to suspend
13080 only the current thread.
13081
13082 @item show thread pause
13083 @kindex show thread@r{, Hurd command}
13084 This command shows the state of current thread suspension.
13085
13086 @item set thread run
13087 This comamnd sets whether the current thread is allowed to run.
13088
13089 @item show thread run
13090 Show whether the current thread is allowed to run.
13091
13092 @item set thread detach-suspend-count
13093 @cindex thread suspend count, @sc{gnu} Hurd
13094 @cindex detach from thread, @sc{gnu} Hurd
13095 This command sets the suspend count @value{GDBN} will leave on a
13096 thread when detaching. This number is relative to the suspend count
13097 found by @value{GDBN} when it notices the thread; use @code{set thread
13098 takeover-suspend-count} to force it to an absolute value.
13099
13100 @item show thread detach-suspend-count
13101 Show the suspend count @value{GDBN} will leave on the thread when
13102 detaching.
13103
13104 @item set thread exception-port
13105 @itemx set thread excp
13106 Set the thread exception port to which to forward exceptions. This
13107 overrides the port set by @code{set task exception-port} (see above).
13108 @code{set thread excp} is the shorthand alias.
13109
13110 @item set thread takeover-suspend-count
13111 Normally, @value{GDBN}'s thread suspend counts are relative to the
13112 value @value{GDBN} finds when it notices each thread. This command
13113 changes the suspend counts to be absolute instead.
13114
13115 @item set thread default
13116 @itemx show thread default
13117 @cindex thread default settings, @sc{gnu} Hurd
13118 Each of the above @code{set thread} commands has a @code{set thread
13119 default} counterpart (e.g., @code{set thread default pause}, @code{set
13120 thread default exception-port}, etc.). The @code{thread default}
13121 variety of commands sets the default thread properties for all
13122 threads; you can then change the properties of individual threads with
13123 the non-default commands.
13124 @end table
13125
13126
13127 @node Neutrino
13128 @subsection QNX Neutrino
13129 @cindex QNX Neutrino
13130
13131 @value{GDBN} provides the following commands specific to the QNX
13132 Neutrino target:
13133
13134 @table @code
13135 @item set debug nto-debug
13136 @kindex set debug nto-debug
13137 When set to on, enables debugging messages specific to the QNX
13138 Neutrino support.
13139
13140 @item show debug nto-debug
13141 @kindex show debug nto-debug
13142 Show the current state of QNX Neutrino messages.
13143 @end table
13144
13145
13146 @node Embedded OS
13147 @section Embedded Operating Systems
13148
13149 This section describes configurations involving the debugging of
13150 embedded operating systems that are available for several different
13151 architectures.
13152
13153 @menu
13154 * VxWorks:: Using @value{GDBN} with VxWorks
13155 @end menu
13156
13157 @value{GDBN} includes the ability to debug programs running on
13158 various real-time operating systems.
13159
13160 @node VxWorks
13161 @subsection Using @value{GDBN} with VxWorks
13162
13163 @cindex VxWorks
13164
13165 @table @code
13166
13167 @kindex target vxworks
13168 @item target vxworks @var{machinename}
13169 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13170 is the target system's machine name or IP address.
13171
13172 @end table
13173
13174 On VxWorks, @code{load} links @var{filename} dynamically on the
13175 current target system as well as adding its symbols in @value{GDBN}.
13176
13177 @value{GDBN} enables developers to spawn and debug tasks running on networked
13178 VxWorks targets from a Unix host. Already-running tasks spawned from
13179 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13180 both the Unix host and on the VxWorks target. The program
13181 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13182 installed with the name @code{vxgdb}, to distinguish it from a
13183 @value{GDBN} for debugging programs on the host itself.)
13184
13185 @table @code
13186 @item VxWorks-timeout @var{args}
13187 @kindex vxworks-timeout
13188 All VxWorks-based targets now support the option @code{vxworks-timeout}.
13189 This option is set by the user, and @var{args} represents the number of
13190 seconds @value{GDBN} waits for responses to rpc's. You might use this if
13191 your VxWorks target is a slow software simulator or is on the far side
13192 of a thin network line.
13193 @end table
13194
13195 The following information on connecting to VxWorks was current when
13196 this manual was produced; newer releases of VxWorks may use revised
13197 procedures.
13198
13199 @findex INCLUDE_RDB
13200 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13201 to include the remote debugging interface routines in the VxWorks
13202 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13203 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13204 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13205 source debugging task @code{tRdbTask} when VxWorks is booted. For more
13206 information on configuring and remaking VxWorks, see the manufacturer's
13207 manual.
13208 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
13209
13210 Once you have included @file{rdb.a} in your VxWorks system image and set
13211 your Unix execution search path to find @value{GDBN}, you are ready to
13212 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13213 @code{vxgdb}, depending on your installation).
13214
13215 @value{GDBN} comes up showing the prompt:
13216
13217 @smallexample
13218 (vxgdb)
13219 @end smallexample
13220
13221 @menu
13222 * VxWorks Connection:: Connecting to VxWorks
13223 * VxWorks Download:: VxWorks download
13224 * VxWorks Attach:: Running tasks
13225 @end menu
13226
13227 @node VxWorks Connection
13228 @subsubsection Connecting to VxWorks
13229
13230 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13231 network. To connect to a target whose host name is ``@code{tt}'', type:
13232
13233 @smallexample
13234 (vxgdb) target vxworks tt
13235 @end smallexample
13236
13237 @need 750
13238 @value{GDBN} displays messages like these:
13239
13240 @smallexample
13241 Attaching remote machine across net...
13242 Connected to tt.
13243 @end smallexample
13244
13245 @need 1000
13246 @value{GDBN} then attempts to read the symbol tables of any object modules
13247 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13248 these files by searching the directories listed in the command search
13249 path (@pxref{Environment, ,Your program's environment}); if it fails
13250 to find an object file, it displays a message such as:
13251
13252 @smallexample
13253 prog.o: No such file or directory.
13254 @end smallexample
13255
13256 When this happens, add the appropriate directory to the search path with
13257 the @value{GDBN} command @code{path}, and execute the @code{target}
13258 command again.
13259
13260 @node VxWorks Download
13261 @subsubsection VxWorks download
13262
13263 @cindex download to VxWorks
13264 If you have connected to the VxWorks target and you want to debug an
13265 object that has not yet been loaded, you can use the @value{GDBN}
13266 @code{load} command to download a file from Unix to VxWorks
13267 incrementally. The object file given as an argument to the @code{load}
13268 command is actually opened twice: first by the VxWorks target in order
13269 to download the code, then by @value{GDBN} in order to read the symbol
13270 table. This can lead to problems if the current working directories on
13271 the two systems differ. If both systems have NFS mounted the same
13272 filesystems, you can avoid these problems by using absolute paths.
13273 Otherwise, it is simplest to set the working directory on both systems
13274 to the directory in which the object file resides, and then to reference
13275 the file by its name, without any path. For instance, a program
13276 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13277 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13278 program, type this on VxWorks:
13279
13280 @smallexample
13281 -> cd "@var{vxpath}/vw/demo/rdb"
13282 @end smallexample
13283
13284 @noindent
13285 Then, in @value{GDBN}, type:
13286
13287 @smallexample
13288 (vxgdb) cd @var{hostpath}/vw/demo/rdb
13289 (vxgdb) load prog.o
13290 @end smallexample
13291
13292 @value{GDBN} displays a response similar to this:
13293
13294 @smallexample
13295 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13296 @end smallexample
13297
13298 You can also use the @code{load} command to reload an object module
13299 after editing and recompiling the corresponding source file. Note that
13300 this makes @value{GDBN} delete all currently-defined breakpoints,
13301 auto-displays, and convenience variables, and to clear the value
13302 history. (This is necessary in order to preserve the integrity of
13303 debugger's data structures that reference the target system's symbol
13304 table.)
13305
13306 @node VxWorks Attach
13307 @subsubsection Running tasks
13308
13309 @cindex running VxWorks tasks
13310 You can also attach to an existing task using the @code{attach} command as
13311 follows:
13312
13313 @smallexample
13314 (vxgdb) attach @var{task}
13315 @end smallexample
13316
13317 @noindent
13318 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13319 or suspended when you attach to it. Running tasks are suspended at
13320 the time of attachment.
13321
13322 @node Embedded Processors
13323 @section Embedded Processors
13324
13325 This section goes into details specific to particular embedded
13326 configurations.
13327
13328
13329 @menu
13330 * ARM:: ARM
13331 * H8/300:: Renesas H8/300
13332 * H8/500:: Renesas H8/500
13333 * M32R/D:: Renesas M32R/D
13334 * M68K:: Motorola M68K
13335 * MIPS Embedded:: MIPS Embedded
13336 * OpenRISC 1000:: OpenRisc 1000
13337 * PA:: HP PA Embedded
13338 * PowerPC: PowerPC
13339 * SH:: Renesas SH
13340 * Sparclet:: Tsqware Sparclet
13341 * Sparclite:: Fujitsu Sparclite
13342 * ST2000:: Tandem ST2000
13343 * Z8000:: Zilog Z8000
13344 * AVR:: Atmel AVR
13345 * CRIS:: CRIS
13346 * Super-H:: Renesas Super-H
13347 @end menu
13348
13349 @node ARM
13350 @subsection ARM
13351
13352 @table @code
13353
13354 @kindex target rdi
13355 @item target rdi @var{dev}
13356 ARM Angel monitor, via RDI library interface to ADP protocol. You may
13357 use this target to communicate with both boards running the Angel
13358 monitor, or with the EmbeddedICE JTAG debug device.
13359
13360 @kindex target rdp
13361 @item target rdp @var{dev}
13362 ARM Demon monitor.
13363
13364 @end table
13365
13366 @value{GDBN} provides the following ARM-specific commands:
13367
13368 @table @code
13369 @item set arm disassembler
13370 @kindex set arm
13371 This commands selects from a list of disassembly styles. The
13372 @code{"std"} style is the standard style.
13373
13374 @item show arm disassembler
13375 @kindex show arm
13376 Show the current disassembly style.
13377
13378 @item set arm apcs32
13379 @cindex ARM 32-bit mode
13380 This command toggles ARM operation mode between 32-bit and 26-bit.
13381
13382 @item show arm apcs32
13383 Display the current usage of the ARM 32-bit mode.
13384
13385 @item set arm fpu @var{fputype}
13386 This command sets the ARM floating-point unit (FPU) type. The
13387 argument @var{fputype} can be one of these:
13388
13389 @table @code
13390 @item auto
13391 Determine the FPU type by querying the OS ABI.
13392 @item softfpa
13393 Software FPU, with mixed-endian doubles on little-endian ARM
13394 processors.
13395 @item fpa
13396 GCC-compiled FPA co-processor.
13397 @item softvfp
13398 Software FPU with pure-endian doubles.
13399 @item vfp
13400 VFP co-processor.
13401 @end table
13402
13403 @item show arm fpu
13404 Show the current type of the FPU.
13405
13406 @item set arm abi
13407 This command forces @value{GDBN} to use the specified ABI.
13408
13409 @item show arm abi
13410 Show the currently used ABI.
13411
13412 @item set debug arm
13413 Toggle whether to display ARM-specific debugging messages from the ARM
13414 target support subsystem.
13415
13416 @item show debug arm
13417 Show whether ARM-specific debugging messages are enabled.
13418 @end table
13419
13420
13421 @node H8/300
13422 @subsection Renesas H8/300
13423
13424 @table @code
13425
13426 @kindex target hms@r{, with H8/300}
13427 @item target hms @var{dev}
13428 A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
13429 Use special commands @code{device} and @code{speed} to control the serial
13430 line and the communications speed used.
13431
13432 @kindex target e7000@r{, with H8/300}
13433 @item target e7000 @var{dev}
13434 E7000 emulator for Renesas H8 and SH.
13435
13436 @kindex target sh3@r{, with H8/300}
13437 @kindex target sh3e@r{, with H8/300}
13438 @item target sh3 @var{dev}
13439 @itemx target sh3e @var{dev}
13440 Renesas SH-3 and SH-3E target systems.
13441
13442 @end table
13443
13444 @cindex download to H8/300 or H8/500
13445 @cindex H8/300 or H8/500 download
13446 @cindex download to Renesas SH
13447 @cindex Renesas SH download
13448 When you select remote debugging to a Renesas SH, H8/300, or H8/500
13449 board, the @code{load} command downloads your program to the Renesas
13450 board and also opens it as the current executable target for
13451 @value{GDBN} on your host (like the @code{file} command).
13452
13453 @value{GDBN} needs to know these things to talk to your
13454 Renesas SH, H8/300, or H8/500:
13455
13456 @enumerate
13457 @item
13458 that you want to use @samp{target hms}, the remote debugging interface
13459 for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13460 emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13461 the default when @value{GDBN} is configured specifically for the Renesas SH,
13462 H8/300, or H8/500.)
13463
13464 @item
13465 what serial device connects your host to your Renesas board (the first
13466 serial device available on your host is the default).
13467
13468 @item
13469 what speed to use over the serial device.
13470 @end enumerate
13471
13472 @menu
13473 * Renesas Boards:: Connecting to Renesas boards.
13474 * Renesas ICE:: Using the E7000 In-Circuit Emulator.
13475 * Renesas Special:: Special @value{GDBN} commands for Renesas micros.
13476 @end menu
13477
13478 @node Renesas Boards
13479 @subsubsection Connecting to Renesas boards
13480
13481 @c only for Unix hosts
13482 @kindex device
13483 @cindex serial device, Renesas micros
13484 Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13485 need to explicitly set the serial device. The default @var{port} is the
13486 first available port on your host. This is only necessary on Unix
13487 hosts, where it is typically something like @file{/dev/ttya}.
13488
13489 @kindex speed
13490 @cindex serial line speed, Renesas micros
13491 @code{@value{GDBN}} has another special command to set the communications
13492 speed: @samp{speed @var{bps}}. This command also is only used from Unix
13493 hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13494 the DOS @code{mode} command (for instance,
13495 @w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13496
13497 The @samp{device} and @samp{speed} commands are available only when you
13498 use a Unix host to debug your Renesas microprocessor programs. If you
13499 use a DOS host,
13500 @value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13501 called @code{asynctsr} to communicate with the development board
13502 through a PC serial port. You must also use the DOS @code{mode} command
13503 to set up the serial port on the DOS side.
13504
13505 The following sample session illustrates the steps needed to start a
13506 program under @value{GDBN} control on an H8/300. The example uses a
13507 sample H8/300 program called @file{t.x}. The procedure is the same for
13508 the Renesas SH and the H8/500.
13509
13510 First hook up your development board. In this example, we use a
13511 board attached to serial port @code{COM2}; if you use a different serial
13512 port, substitute its name in the argument of the @code{mode} command.
13513 When you call @code{asynctsr}, the auxiliary comms program used by the
13514 debugger, you give it just the numeric part of the serial port's name;
13515 for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13516 @code{COM2}.
13517
13518 @smallexample
13519 C:\H8300\TEST> asynctsr 2
13520 C:\H8300\TEST> mode com2:9600,n,8,1,p
13521
13522 Resident portion of MODE loaded
13523
13524 COM2: 9600, n, 8, 1, p
13525
13526 @end smallexample
13527
13528 @quotation
13529 @emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13530 @code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13531 disable it, or even boot without it, to use @code{asynctsr} to control
13532 your development board.
13533 @end quotation
13534
13535 @kindex target hms@r{, and serial protocol}
13536 Now that serial communications are set up, and the development board is
13537 connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
13538 the name of your program as the argument. @code{@value{GDBN}} prompts
13539 you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13540 commands to begin your debugging session: @samp{target hms} to specify
13541 cross-debugging to the Renesas board, and the @code{load} command to
13542 download your program to the board. @code{load} displays the names of
13543 the program's sections, and a @samp{*} for each 2K of data downloaded.
13544 (If you want to refresh @value{GDBN} data on symbols or on the
13545 executable file without downloading, use the @value{GDBN} commands
13546 @code{file} or @code{symbol-file}. These commands, and @code{load}
13547 itself, are described in @ref{Files,,Commands to specify files}.)
13548
13549 @smallexample
13550 (eg-C:\H8300\TEST) @value{GDBP} t.x
13551 @value{GDBN} is free software and you are welcome to distribute copies
13552 of it under certain conditions; type "show copying" to see
13553 the conditions.
13554 There is absolutely no warranty for @value{GDBN}; type "show warranty"
13555 for details.
13556 @value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13557 (@value{GDBP}) target hms
13558 Connected to remote H8/300 HMS system.
13559 (@value{GDBP}) load t.x
13560 .text : 0x8000 .. 0xabde ***********
13561 .data : 0xabde .. 0xad30 *
13562 .stack : 0xf000 .. 0xf014 *
13563 @end smallexample
13564
13565 At this point, you're ready to run or debug your program. From here on,
13566 you can use all the usual @value{GDBN} commands. The @code{break} command
13567 sets breakpoints; the @code{run} command starts your program;
13568 @code{print} or @code{x} display data; the @code{continue} command
13569 resumes execution after stopping at a breakpoint. You can use the
13570 @code{help} command at any time to find out more about @value{GDBN} commands.
13571
13572 Remember, however, that @emph{operating system} facilities aren't
13573 available on your development board; for example, if your program hangs,
13574 you can't send an interrupt---but you can press the @sc{reset} switch!
13575
13576 Use the @sc{reset} button on the development board
13577 @itemize @bullet
13578 @item
13579 to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13580 no way to pass an interrupt signal to the development board); and
13581
13582 @item
13583 to return to the @value{GDBN} command prompt after your program finishes
13584 normally. The communications protocol provides no other way for @value{GDBN}
13585 to detect program completion.
13586 @end itemize
13587
13588 In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13589 development board as a ``normal exit'' of your program.
13590
13591 @node Renesas ICE
13592 @subsubsection Using the E7000 in-circuit emulator
13593
13594 @kindex target e7000@r{, with Renesas ICE}
13595 You can use the E7000 in-circuit emulator to develop code for either the
13596 Renesas SH or the H8/300H. Use one of these forms of the @samp{target
13597 e7000} command to connect @value{GDBN} to your E7000:
13598
13599 @table @code
13600 @item target e7000 @var{port} @var{speed}
13601 Use this form if your E7000 is connected to a serial port. The
13602 @var{port} argument identifies what serial port to use (for example,
13603 @samp{com2}). The third argument is the line speed in bits per second
13604 (for example, @samp{9600}).
13605
13606 @item target e7000 @var{hostname}
13607 If your E7000 is installed as a host on a TCP/IP network, you can just
13608 specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13609 @end table
13610
13611 The following special commands are available when debugging with the
13612 Renesas E7000 ICE:
13613
13614 @table @code
13615 @item e7000 @var{command}
13616 @kindex e7000
13617 @cindex send command to E7000 monitor
13618 This sends the specified @var{command} to the E7000 monitor.
13619
13620 @item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13621 @kindex ftplogin@r{, E7000}
13622 This command records information for subsequent interface with the
13623 E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13624 named @var{machine} using specified @var{username} and @var{password},
13625 and then chdir to the named directory @var{dir}.
13626
13627 @item ftpload @var{file}
13628 @kindex ftpload@r{, E7000}
13629 This command uses credentials recorded by @code{ftplogin} to fetch and
13630 load the named @var{file} from the E7000 monitor.
13631
13632 @item drain
13633 @kindex drain@r{, E7000}
13634 This command drains any pending text buffers stored on the E7000.
13635
13636 @item set usehardbreakpoints
13637 @itemx show usehardbreakpoints
13638 @kindex set usehardbreakpoints@r{, E7000}
13639 @kindex show usehardbreakpoints@r{, E7000}
13640 @cindex hardware breakpoints, and E7000
13641 These commands set and show the use of hardware breakpoints for all
13642 breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13643 more information about using hardware breakpoints selectively.
13644 @end table
13645
13646 @node Renesas Special
13647 @subsubsection Special @value{GDBN} commands for Renesas micros
13648
13649 Some @value{GDBN} commands are available only for the H8/300:
13650
13651 @table @code
13652
13653 @kindex set machine
13654 @kindex show machine
13655 @item set machine h8300
13656 @itemx set machine h8300h
13657 Condition @value{GDBN} for one of the two variants of the H8/300
13658 architecture with @samp{set machine}. You can use @samp{show machine}
13659 to check which variant is currently in effect.
13660
13661 @end table
13662
13663 @node H8/500
13664 @subsection H8/500
13665
13666 @table @code
13667
13668 @kindex set memory @var{mod}
13669 @cindex memory models, H8/500
13670 @item set memory @var{mod}
13671 @itemx show memory
13672 Specify which H8/500 memory model (@var{mod}) you are using with
13673 @samp{set memory}; check which memory model is in effect with @samp{show
13674 memory}. The accepted values for @var{mod} are @code{small},
13675 @code{big}, @code{medium}, and @code{compact}.
13676
13677 @end table
13678
13679 @node M32R/D
13680 @subsection Renesas M32R/D and M32R/SDI
13681
13682 @table @code
13683 @kindex target m32r
13684 @item target m32r @var{dev}
13685 Renesas M32R/D ROM monitor.
13686
13687 @kindex target m32rsdi
13688 @item target m32rsdi @var{dev}
13689 Renesas M32R SDI server, connected via parallel port to the board.
13690 @end table
13691
13692 The following @value{GDBN} commands are specific to the M32R monitor:
13693
13694 @table @code
13695 @item set download-path @var{path}
13696 @kindex set download-path
13697 @cindex find downloadable @sc{srec} files (M32R)
13698 Set the default path for finding donwloadable @sc{srec} files.
13699
13700 @item show download-path
13701 @kindex show download-path
13702 Show the default path for downloadable @sc{srec} files.
13703
13704 @item set board-address @var{addr}
13705 @kindex set board-address
13706 @cindex M32-EVA target board address
13707 Set the IP address for the M32R-EVA target board.
13708
13709 @item show board-address
13710 @kindex show board-address
13711 Show the current IP address of the target board.
13712
13713 @item set server-address @var{addr}
13714 @kindex set server-address
13715 @cindex download server address (M32R)
13716 Set the IP address for the download server, which is the @value{GDBN}'s
13717 host machine.
13718
13719 @item show server-address
13720 @kindex show server-address
13721 Display the IP address of the download server.
13722
13723 @item upload @r{[}@var{file}@r{]}
13724 @kindex upload@r{, M32R}
13725 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13726 upload capability. If no @var{file} argument is given, the current
13727 executable file is uploaded.
13728
13729 @item tload @r{[}@var{file}@r{]}
13730 @kindex tload@r{, M32R}
13731 Test the @code{upload} command.
13732 @end table
13733
13734 The following commands are available for M32R/SDI:
13735
13736 @table @code
13737 @item sdireset
13738 @kindex sdireset
13739 @cindex reset SDI connection, M32R
13740 This command resets the SDI connection.
13741
13742 @item sdistatus
13743 @kindex sdistatus
13744 This command shows the SDI connection status.
13745
13746 @item debug_chaos
13747 @kindex debug_chaos
13748 @cindex M32R/Chaos debugging
13749 Instructs the remote that M32R/Chaos debugging is to be used.
13750
13751 @item use_debug_dma
13752 @kindex use_debug_dma
13753 Instructs the remote to use the DEBUG_DMA method of accessing memory.
13754
13755 @item use_mon_code
13756 @kindex use_mon_code
13757 Instructs the remote to use the MON_CODE method of accessing memory.
13758
13759 @item use_ib_break
13760 @kindex use_ib_break
13761 Instructs the remote to set breakpoints by IB break.
13762
13763 @item use_dbt_break
13764 @kindex use_dbt_break
13765 Instructs the remote to set breakpoints by DBT.
13766 @end table
13767
13768 @node M68K
13769 @subsection M68k
13770
13771 The Motorola m68k configuration includes ColdFire support, and
13772 target command for the following ROM monitors.
13773
13774 @table @code
13775
13776 @kindex target abug
13777 @item target abug @var{dev}
13778 ABug ROM monitor for M68K.
13779
13780 @kindex target cpu32bug
13781 @item target cpu32bug @var{dev}
13782 CPU32BUG monitor, running on a CPU32 (M68K) board.
13783
13784 @kindex target dbug
13785 @item target dbug @var{dev}
13786 dBUG ROM monitor for Motorola ColdFire.
13787
13788 @kindex target est
13789 @item target est @var{dev}
13790 EST-300 ICE monitor, running on a CPU32 (M68K) board.
13791
13792 @kindex target rom68k
13793 @item target rom68k @var{dev}
13794 ROM 68K monitor, running on an M68K IDP board.
13795
13796 @end table
13797
13798 @table @code
13799
13800 @kindex target rombug
13801 @item target rombug @var{dev}
13802 ROMBUG ROM monitor for OS/9000.
13803
13804 @end table
13805
13806 @node MIPS Embedded
13807 @subsection MIPS Embedded
13808
13809 @cindex MIPS boards
13810 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
13811 MIPS board attached to a serial line. This is available when
13812 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
13813
13814 @need 1000
13815 Use these @value{GDBN} commands to specify the connection to your target board:
13816
13817 @table @code
13818 @item target mips @var{port}
13819 @kindex target mips @var{port}
13820 To run a program on the board, start up @code{@value{GDBP}} with the
13821 name of your program as the argument. To connect to the board, use the
13822 command @samp{target mips @var{port}}, where @var{port} is the name of
13823 the serial port connected to the board. If the program has not already
13824 been downloaded to the board, you may use the @code{load} command to
13825 download it. You can then use all the usual @value{GDBN} commands.
13826
13827 For example, this sequence connects to the target board through a serial
13828 port, and loads and runs a program called @var{prog} through the
13829 debugger:
13830
13831 @smallexample
13832 host$ @value{GDBP} @var{prog}
13833 @value{GDBN} is free software and @dots{}
13834 (@value{GDBP}) target mips /dev/ttyb
13835 (@value{GDBP}) load @var{prog}
13836 (@value{GDBP}) run
13837 @end smallexample
13838
13839 @item target mips @var{hostname}:@var{portnumber}
13840 On some @value{GDBN} host configurations, you can specify a TCP
13841 connection (for instance, to a serial line managed by a terminal
13842 concentrator) instead of a serial port, using the syntax
13843 @samp{@var{hostname}:@var{portnumber}}.
13844
13845 @item target pmon @var{port}
13846 @kindex target pmon @var{port}
13847 PMON ROM monitor.
13848
13849 @item target ddb @var{port}
13850 @kindex target ddb @var{port}
13851 NEC's DDB variant of PMON for Vr4300.
13852
13853 @item target lsi @var{port}
13854 @kindex target lsi @var{port}
13855 LSI variant of PMON.
13856
13857 @kindex target r3900
13858 @item target r3900 @var{dev}
13859 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
13860
13861 @kindex target array
13862 @item target array @var{dev}
13863 Array Tech LSI33K RAID controller board.
13864
13865 @end table
13866
13867
13868 @noindent
13869 @value{GDBN} also supports these special commands for MIPS targets:
13870
13871 @table @code
13872 @item set mipsfpu double
13873 @itemx set mipsfpu single
13874 @itemx set mipsfpu none
13875 @itemx set mipsfpu auto
13876 @itemx show mipsfpu
13877 @kindex set mipsfpu
13878 @kindex show mipsfpu
13879 @cindex MIPS remote floating point
13880 @cindex floating point, MIPS remote
13881 If your target board does not support the MIPS floating point
13882 coprocessor, you should use the command @samp{set mipsfpu none} (if you
13883 need this, you may wish to put the command in your @value{GDBN} init
13884 file). This tells @value{GDBN} how to find the return value of
13885 functions which return floating point values. It also allows
13886 @value{GDBN} to avoid saving the floating point registers when calling
13887 functions on the board. If you are using a floating point coprocessor
13888 with only single precision floating point support, as on the @sc{r4650}
13889 processor, use the command @samp{set mipsfpu single}. The default
13890 double precision floating point coprocessor may be selected using
13891 @samp{set mipsfpu double}.
13892
13893 In previous versions the only choices were double precision or no
13894 floating point, so @samp{set mipsfpu on} will select double precision
13895 and @samp{set mipsfpu off} will select no floating point.
13896
13897 As usual, you can inquire about the @code{mipsfpu} variable with
13898 @samp{show mipsfpu}.
13899
13900 @item set timeout @var{seconds}
13901 @itemx set retransmit-timeout @var{seconds}
13902 @itemx show timeout
13903 @itemx show retransmit-timeout
13904 @cindex @code{timeout}, MIPS protocol
13905 @cindex @code{retransmit-timeout}, MIPS protocol
13906 @kindex set timeout
13907 @kindex show timeout
13908 @kindex set retransmit-timeout
13909 @kindex show retransmit-timeout
13910 You can control the timeout used while waiting for a packet, in the MIPS
13911 remote protocol, with the @code{set timeout @var{seconds}} command. The
13912 default is 5 seconds. Similarly, you can control the timeout used while
13913 waiting for an acknowledgement of a packet with the @code{set
13914 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
13915 You can inspect both values with @code{show timeout} and @code{show
13916 retransmit-timeout}. (These commands are @emph{only} available when
13917 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
13918
13919 The timeout set by @code{set timeout} does not apply when @value{GDBN}
13920 is waiting for your program to stop. In that case, @value{GDBN} waits
13921 forever because it has no way of knowing how long the program is going
13922 to run before stopping.
13923
13924 @item set syn-garbage-limit @var{num}
13925 @kindex set syn-garbage-limit@r{, MIPS remote}
13926 @cindex synchronize with remote MIPS target
13927 Limit the maximum number of characters @value{GDBN} should ignore when
13928 it tries to synchronize with the remote target. The default is 10
13929 characters. Setting the limit to -1 means there's no limit.
13930
13931 @item show syn-garbage-limit
13932 @kindex show syn-garbage-limit@r{, MIPS remote}
13933 Show the current limit on the number of characters to ignore when
13934 trying to synchronize with the remote system.
13935
13936 @item set monitor-prompt @var{prompt}
13937 @kindex set monitor-prompt@r{, MIPS remote}
13938 @cindex remote monitor prompt
13939 Tell @value{GDBN} to expect the specified @var{prompt} string from the
13940 remote monitor. The default depends on the target:
13941 @table @asis
13942 @item pmon target
13943 @samp{PMON}
13944 @item ddb target
13945 @samp{NEC010}
13946 @item lsi target
13947 @samp{PMON>}
13948 @end table
13949
13950 @item show monitor-prompt
13951 @kindex show monitor-prompt@r{, MIPS remote}
13952 Show the current strings @value{GDBN} expects as the prompt from the
13953 remote monitor.
13954
13955 @item set monitor-warnings
13956 @kindex set monitor-warnings@r{, MIPS remote}
13957 Enable or disable monitor warnings about hardware breakpoints. This
13958 has effect only for the @code{lsi} target. When on, @value{GDBN} will
13959 display warning messages whose codes are returned by the @code{lsi}
13960 PMON monitor for breakpoint commands.
13961
13962 @item show monitor-warnings
13963 @kindex show monitor-warnings@r{, MIPS remote}
13964 Show the current setting of printing monitor warnings.
13965
13966 @item pmon @var{command}
13967 @kindex pmon@r{, MIPS remote}
13968 @cindex send PMON command
13969 This command allows sending an arbitrary @var{command} string to the
13970 monitor. The monitor must be in debug mode for this to work.
13971 @end table
13972
13973 @node OpenRISC 1000
13974 @subsection OpenRISC 1000
13975 @cindex OpenRISC 1000
13976
13977 @cindex or1k boards
13978 See OR1k Architecture document (@uref{www.opencores.org}) for more information
13979 about platform and commands.
13980
13981 @table @code
13982
13983 @kindex target jtag
13984 @item target jtag jtag://@var{host}:@var{port}
13985
13986 Connects to remote JTAG server.
13987 JTAG remote server can be either an or1ksim or JTAG server,
13988 connected via parallel port to the board.
13989
13990 Example: @code{target jtag jtag://localhost:9999}
13991
13992 @kindex or1ksim
13993 @item or1ksim @var{command}
13994 If connected to @code{or1ksim} OpenRISC 1000 Architectural
13995 Simulator, proprietary commands can be executed.
13996
13997 @kindex info or1k spr
13998 @item info or1k spr
13999 Displays spr groups.
14000
14001 @item info or1k spr @var{group}
14002 @itemx info or1k spr @var{groupno}
14003 Displays register names in selected group.
14004
14005 @item info or1k spr @var{group} @var{register}
14006 @itemx info or1k spr @var{register}
14007 @itemx info or1k spr @var{groupno} @var{registerno}
14008 @itemx info or1k spr @var{registerno}
14009 Shows information about specified spr register.
14010
14011 @kindex spr
14012 @item spr @var{group} @var{register} @var{value}
14013 @itemx spr @var{register @var{value}}
14014 @itemx spr @var{groupno} @var{registerno @var{value}}
14015 @itemx spr @var{registerno @var{value}}
14016 Writes @var{value} to specified spr register.
14017 @end table
14018
14019 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14020 It is very similar to @value{GDBN} trace, except it does not interfere with normal
14021 program execution and is thus much faster. Hardware breakpoints/watchpoint
14022 triggers can be set using:
14023 @table @code
14024 @item $LEA/$LDATA
14025 Load effective address/data
14026 @item $SEA/$SDATA
14027 Store effective address/data
14028 @item $AEA/$ADATA
14029 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14030 @item $FETCH
14031 Fetch data
14032 @end table
14033
14034 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14035 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14036
14037 @code{htrace} commands:
14038 @cindex OpenRISC 1000 htrace
14039 @table @code
14040 @kindex hwatch
14041 @item hwatch @var{conditional}
14042 Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14043 or Data. For example:
14044
14045 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14046
14047 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14048
14049 @kindex htrace
14050 @item htrace info
14051 Display information about current HW trace configuration.
14052
14053 @item htrace trigger @var{conditional}
14054 Set starting criteria for HW trace.
14055
14056 @item htrace qualifier @var{conditional}
14057 Set acquisition qualifier for HW trace.
14058
14059 @item htrace stop @var{conditional}
14060 Set HW trace stopping criteria.
14061
14062 @item htrace record [@var{data}]*
14063 Selects the data to be recorded, when qualifier is met and HW trace was
14064 triggered.
14065
14066 @item htrace enable
14067 @itemx htrace disable
14068 Enables/disables the HW trace.
14069
14070 @item htrace rewind [@var{filename}]
14071 Clears currently recorded trace data.
14072
14073 If filename is specified, new trace file is made and any newly collected data
14074 will be written there.
14075
14076 @item htrace print [@var{start} [@var{len}]]
14077 Prints trace buffer, using current record configuration.
14078
14079 @item htrace mode continuous
14080 Set continuous trace mode.
14081
14082 @item htrace mode suspend
14083 Set suspend trace mode.
14084
14085 @end table
14086
14087 @node PowerPC
14088 @subsection PowerPC
14089
14090 @table @code
14091
14092 @kindex target dink32
14093 @item target dink32 @var{dev}
14094 DINK32 ROM monitor.
14095
14096 @kindex target ppcbug
14097 @item target ppcbug @var{dev}
14098 @kindex target ppcbug1
14099 @item target ppcbug1 @var{dev}
14100 PPCBUG ROM monitor for PowerPC.
14101
14102 @kindex target sds
14103 @item target sds @var{dev}
14104 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
14105
14106 @end table
14107
14108 @node PA
14109 @subsection HP PA Embedded
14110
14111 @table @code
14112
14113 @kindex target op50n
14114 @item target op50n @var{dev}
14115 OP50N monitor, running on an OKI HPPA board.
14116
14117 @kindex target w89k
14118 @item target w89k @var{dev}
14119 W89K monitor, running on a Winbond HPPA board.
14120
14121 @end table
14122
14123 @node SH
14124 @subsection Renesas SH
14125
14126 @table @code
14127
14128 @kindex target hms@r{, with Renesas SH}
14129 @item target hms @var{dev}
14130 A Renesas SH board attached via serial line to your host. Use special
14131 commands @code{device} and @code{speed} to control the serial line and
14132 the communications speed used.
14133
14134 @kindex target e7000@r{, with Renesas SH}
14135 @item target e7000 @var{dev}
14136 E7000 emulator for Renesas SH.
14137
14138 @kindex target sh3@r{, with SH}
14139 @kindex target sh3e@r{, with SH}
14140 @item target sh3 @var{dev}
14141 @item target sh3e @var{dev}
14142 Renesas SH-3 and SH-3E target systems.
14143
14144 @end table
14145
14146 @node Sparclet
14147 @subsection Tsqware Sparclet
14148
14149 @cindex Sparclet
14150
14151 @value{GDBN} enables developers to debug tasks running on
14152 Sparclet targets from a Unix host.
14153 @value{GDBN} uses code that runs on
14154 both the Unix host and on the Sparclet target. The program
14155 @code{@value{GDBP}} is installed and executed on the Unix host.
14156
14157 @table @code
14158 @item remotetimeout @var{args}
14159 @kindex remotetimeout
14160 @value{GDBN} supports the option @code{remotetimeout}.
14161 This option is set by the user, and @var{args} represents the number of
14162 seconds @value{GDBN} waits for responses.
14163 @end table
14164
14165 @cindex compiling, on Sparclet
14166 When compiling for debugging, include the options @samp{-g} to get debug
14167 information and @samp{-Ttext} to relocate the program to where you wish to
14168 load it on the target. You may also want to add the options @samp{-n} or
14169 @samp{-N} in order to reduce the size of the sections. Example:
14170
14171 @smallexample
14172 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
14173 @end smallexample
14174
14175 You can use @code{objdump} to verify that the addresses are what you intended:
14176
14177 @smallexample
14178 sparclet-aout-objdump --headers --syms prog
14179 @end smallexample
14180
14181 @cindex running, on Sparclet
14182 Once you have set
14183 your Unix execution search path to find @value{GDBN}, you are ready to
14184 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14185 (or @code{sparclet-aout-gdb}, depending on your installation).
14186
14187 @value{GDBN} comes up showing the prompt:
14188
14189 @smallexample
14190 (gdbslet)
14191 @end smallexample
14192
14193 @menu
14194 * Sparclet File:: Setting the file to debug
14195 * Sparclet Connection:: Connecting to Sparclet
14196 * Sparclet Download:: Sparclet download
14197 * Sparclet Execution:: Running and debugging
14198 @end menu
14199
14200 @node Sparclet File
14201 @subsubsection Setting file to debug
14202
14203 The @value{GDBN} command @code{file} lets you choose with program to debug.
14204
14205 @smallexample
14206 (gdbslet) file prog
14207 @end smallexample
14208
14209 @need 1000
14210 @value{GDBN} then attempts to read the symbol table of @file{prog}.
14211 @value{GDBN} locates
14212 the file by searching the directories listed in the command search
14213 path.
14214 If the file was compiled with debug information (option "-g"), source
14215 files will be searched as well.
14216 @value{GDBN} locates
14217 the source files by searching the directories listed in the directory search
14218 path (@pxref{Environment, ,Your program's environment}).
14219 If it fails
14220 to find a file, it displays a message such as:
14221
14222 @smallexample
14223 prog: No such file or directory.
14224 @end smallexample
14225
14226 When this happens, add the appropriate directories to the search paths with
14227 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14228 @code{target} command again.
14229
14230 @node Sparclet Connection
14231 @subsubsection Connecting to Sparclet
14232
14233 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14234 To connect to a target on serial port ``@code{ttya}'', type:
14235
14236 @smallexample
14237 (gdbslet) target sparclet /dev/ttya
14238 Remote target sparclet connected to /dev/ttya
14239 main () at ../prog.c:3
14240 @end smallexample
14241
14242 @need 750
14243 @value{GDBN} displays messages like these:
14244
14245 @smallexample
14246 Connected to ttya.
14247 @end smallexample
14248
14249 @node Sparclet Download
14250 @subsubsection Sparclet download
14251
14252 @cindex download to Sparclet
14253 Once connected to the Sparclet target,
14254 you can use the @value{GDBN}
14255 @code{load} command to download the file from the host to the target.
14256 The file name and load offset should be given as arguments to the @code{load}
14257 command.
14258 Since the file format is aout, the program must be loaded to the starting
14259 address. You can use @code{objdump} to find out what this value is. The load
14260 offset is an offset which is added to the VMA (virtual memory address)
14261 of each of the file's sections.
14262 For instance, if the program
14263 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
14264 and bss at 0x12010170, in @value{GDBN}, type:
14265
14266 @smallexample
14267 (gdbslet) load prog 0x12010000
14268 Loading section .text, size 0xdb0 vma 0x12010000
14269 @end smallexample
14270
14271 If the code is loaded at a different address then what the program was linked
14272 to, you may need to use the @code{section} and @code{add-symbol-file} commands
14273 to tell @value{GDBN} where to map the symbol table.
14274
14275 @node Sparclet Execution
14276 @subsubsection Running and debugging
14277
14278 @cindex running and debugging Sparclet programs
14279 You can now begin debugging the task using @value{GDBN}'s execution control
14280 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14281 manual for the list of commands.
14282
14283 @smallexample
14284 (gdbslet) b main
14285 Breakpoint 1 at 0x12010000: file prog.c, line 3.
14286 (gdbslet) run
14287 Starting program: prog
14288 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
14289 3 char *symarg = 0;
14290 (gdbslet) step
14291 4 char *execarg = "hello!";
14292 (gdbslet)
14293 @end smallexample
14294
14295 @node Sparclite
14296 @subsection Fujitsu Sparclite
14297
14298 @table @code
14299
14300 @kindex target sparclite
14301 @item target sparclite @var{dev}
14302 Fujitsu sparclite boards, used only for the purpose of loading.
14303 You must use an additional command to debug the program.
14304 For example: target remote @var{dev} using @value{GDBN} standard
14305 remote protocol.
14306
14307 @end table
14308
14309 @node ST2000
14310 @subsection Tandem ST2000
14311
14312 @value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14313 STDBUG protocol.
14314
14315 To connect your ST2000 to the host system, see the manufacturer's
14316 manual. Once the ST2000 is physically attached, you can run:
14317
14318 @smallexample
14319 target st2000 @var{dev} @var{speed}
14320 @end smallexample
14321
14322 @noindent
14323 to establish it as your debugging environment. @var{dev} is normally
14324 the name of a serial device, such as @file{/dev/ttya}, connected to the
14325 ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14326 connection (for example, to a serial line attached via a terminal
14327 concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
14328
14329 The @code{load} and @code{attach} commands are @emph{not} defined for
14330 this target; you must load your program into the ST2000 as you normally
14331 would for standalone operation. @value{GDBN} reads debugging information
14332 (such as symbols) from a separate, debugging version of the program
14333 available on your host computer.
14334 @c FIXME!! This is terribly vague; what little content is here is
14335 @c basically hearsay.
14336
14337 @cindex ST2000 auxiliary commands
14338 These auxiliary @value{GDBN} commands are available to help you with the ST2000
14339 environment:
14340
14341 @table @code
14342 @item st2000 @var{command}
14343 @kindex st2000 @var{cmd}
14344 @cindex STDBUG commands (ST2000)
14345 @cindex commands to STDBUG (ST2000)
14346 Send a @var{command} to the STDBUG monitor. See the manufacturer's
14347 manual for available commands.
14348
14349 @item connect
14350 @cindex connect (to STDBUG)
14351 Connect the controlling terminal to the STDBUG command monitor. When
14352 you are done interacting with STDBUG, typing either of two character
14353 sequences gets you back to the @value{GDBN} command prompt:
14354 @kbd{@key{RET}~.} (Return, followed by tilde and period) or
14355 @kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
14356 @end table
14357
14358 @node Z8000
14359 @subsection Zilog Z8000
14360
14361 @cindex Z8000
14362 @cindex simulator, Z8000
14363 @cindex Zilog Z8000 simulator
14364
14365 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14366 a Z8000 simulator.
14367
14368 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14369 unsegmented variant of the Z8000 architecture) or the Z8001 (the
14370 segmented variant). The simulator recognizes which architecture is
14371 appropriate by inspecting the object code.
14372
14373 @table @code
14374 @item target sim @var{args}
14375 @kindex sim
14376 @kindex target sim@r{, with Z8000}
14377 Debug programs on a simulated CPU. If the simulator supports setup
14378 options, specify them via @var{args}.
14379 @end table
14380
14381 @noindent
14382 After specifying this target, you can debug programs for the simulated
14383 CPU in the same style as programs for your host computer; use the
14384 @code{file} command to load a new program image, the @code{run} command
14385 to run your program, and so on.
14386
14387 As well as making available all the usual machine registers
14388 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14389 additional items of information as specially named registers:
14390
14391 @table @code
14392
14393 @item cycles
14394 Counts clock-ticks in the simulator.
14395
14396 @item insts
14397 Counts instructions run in the simulator.
14398
14399 @item time
14400 Execution time in 60ths of a second.
14401
14402 @end table
14403
14404 You can refer to these values in @value{GDBN} expressions with the usual
14405 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14406 conditional breakpoint that suspends only after at least 5000
14407 simulated clock ticks.
14408
14409 @node AVR
14410 @subsection Atmel AVR
14411 @cindex AVR
14412
14413 When configured for debugging the Atmel AVR, @value{GDBN} supports the
14414 following AVR-specific commands:
14415
14416 @table @code
14417 @item info io_registers
14418 @kindex info io_registers@r{, AVR}
14419 @cindex I/O registers (Atmel AVR)
14420 This command displays information about the AVR I/O registers. For
14421 each register, @value{GDBN} prints its number and value.
14422 @end table
14423
14424 @node CRIS
14425 @subsection CRIS
14426 @cindex CRIS
14427
14428 When configured for debugging CRIS, @value{GDBN} provides the
14429 following CRIS-specific commands:
14430
14431 @table @code
14432 @item set cris-version @var{ver}
14433 @cindex CRIS version
14434 Set the current CRIS version to @var{ver}. The CRIS version affects
14435 register names and sizes. This command is useful in case
14436 autodetection of the CRIS version fails.
14437
14438 @item show cris-version
14439 Show the current CRIS version.
14440
14441 @item set cris-dwarf2-cfi
14442 @cindex DWARF-2 CFI and CRIS
14443 Set the usage of DWARF-2 CFI for CRIS debugging. The default is off
14444 if using @code{gcc-cris} whose version is below @code{R59}, otherwise
14445 on.
14446
14447 @item show cris-dwarf2-cfi
14448 Show the current state of using DWARF-2 CFI.
14449 @end table
14450
14451 @node Super-H
14452 @subsection Renesas Super-H
14453 @cindex Super-H
14454
14455 For the Renesas Super-H processor, @value{GDBN} provides these
14456 commands:
14457
14458 @table @code
14459 @item regs
14460 @kindex regs@r{, Super-H}
14461 Show the values of all Super-H registers.
14462 @end table
14463
14464
14465 @node Architectures
14466 @section Architectures
14467
14468 This section describes characteristics of architectures that affect
14469 all uses of @value{GDBN} with the architecture, both native and cross.
14470
14471 @menu
14472 * i386::
14473 * A29K::
14474 * Alpha::
14475 * MIPS::
14476 * HPPA:: HP PA architecture
14477 @end menu
14478
14479 @node i386
14480 @subsection x86 Architecture-specific issues.
14481
14482 @table @code
14483 @item set struct-convention @var{mode}
14484 @kindex set struct-convention
14485 @cindex struct return convention
14486 @cindex struct/union returned in registers
14487 Set the convention used by the inferior to return @code{struct}s and
14488 @code{union}s from functions to @var{mode}. Possible values of
14489 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14490 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14491 are returned on the stack, while @code{"reg"} means that a
14492 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14493 be returned in a register.
14494
14495 @item show struct-convention
14496 @kindex show struct-convention
14497 Show the current setting of the convention to return @code{struct}s
14498 from functions.
14499 @end table
14500
14501 @node A29K
14502 @subsection A29K
14503
14504 @table @code
14505
14506 @kindex set rstack_high_address
14507 @cindex AMD 29K register stack
14508 @cindex register stack, AMD29K
14509 @item set rstack_high_address @var{address}
14510 On AMD 29000 family processors, registers are saved in a separate
14511 @dfn{register stack}. There is no way for @value{GDBN} to determine the
14512 extent of this stack. Normally, @value{GDBN} just assumes that the
14513 stack is ``large enough''. This may result in @value{GDBN} referencing
14514 memory locations that do not exist. If necessary, you can get around
14515 this problem by specifying the ending address of the register stack with
14516 the @code{set rstack_high_address} command. The argument should be an
14517 address, which you probably want to precede with @samp{0x} to specify in
14518 hexadecimal.
14519
14520 @kindex show rstack_high_address
14521 @item show rstack_high_address
14522 Display the current limit of the register stack, on AMD 29000 family
14523 processors.
14524
14525 @end table
14526
14527 @node Alpha
14528 @subsection Alpha
14529
14530 See the following section.
14531
14532 @node MIPS
14533 @subsection MIPS
14534
14535 @cindex stack on Alpha
14536 @cindex stack on MIPS
14537 @cindex Alpha stack
14538 @cindex MIPS stack
14539 Alpha- and MIPS-based computers use an unusual stack frame, which
14540 sometimes requires @value{GDBN} to search backward in the object code to
14541 find the beginning of a function.
14542
14543 @cindex response time, MIPS debugging
14544 To improve response time (especially for embedded applications, where
14545 @value{GDBN} may be restricted to a slow serial line for this search)
14546 you may want to limit the size of this search, using one of these
14547 commands:
14548
14549 @table @code
14550 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
14551 @item set heuristic-fence-post @var{limit}
14552 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14553 search for the beginning of a function. A value of @var{0} (the
14554 default) means there is no limit. However, except for @var{0}, the
14555 larger the limit the more bytes @code{heuristic-fence-post} must search
14556 and therefore the longer it takes to run. You should only need to use
14557 this command when debugging a stripped executable.
14558
14559 @item show heuristic-fence-post
14560 Display the current limit.
14561 @end table
14562
14563 @noindent
14564 These commands are available @emph{only} when @value{GDBN} is configured
14565 for debugging programs on Alpha or MIPS processors.
14566
14567 Several MIPS-specific commands are available when debugging MIPS
14568 programs:
14569
14570 @table @code
14571 @item set mips saved-gpreg-size @var{size}
14572 @kindex set mips saved-gpreg-size
14573 @cindex MIPS GP register size on stack
14574 Set the size of MIPS general-purpose registers saved on the stack.
14575 The argument @var{size} can be one of the following:
14576
14577 @table @samp
14578 @item 32
14579 32-bit GP registers
14580 @item 64
14581 64-bit GP registers
14582 @item auto
14583 Use the target's default setting or autodetect the saved size from the
14584 information contained in the executable. This is the default
14585 @end table
14586
14587 @item show mips saved-gpreg-size
14588 @kindex show mips saved-gpreg-size
14589 Show the current size of MIPS GP registers on the stack.
14590
14591 @item set mips stack-arg-size @var{size}
14592 @kindex set mips stack-arg-size
14593 @cindex MIPS stack space for arguments
14594 Set the amount of stack space reserved for arguments to functions.
14595 The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14596 (the default).
14597
14598 @item set mips abi @var{arg}
14599 @kindex set mips abi
14600 @cindex set ABI for MIPS
14601 Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14602 values of @var{arg} are:
14603
14604 @table @samp
14605 @item auto
14606 The default ABI associated with the current binary (this is the
14607 default).
14608 @item o32
14609 @item o64
14610 @item n32
14611 @item n64
14612 @item eabi32
14613 @item eabi64
14614 @item auto
14615 @end table
14616
14617 @item show mips abi
14618 @kindex show mips abi
14619 Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14620
14621 @item set mipsfpu
14622 @itemx show mipsfpu
14623 @xref{MIPS Embedded, set mipsfpu}.
14624
14625 @item set mips mask-address @var{arg}
14626 @kindex set mips mask-address
14627 @cindex MIPS addresses, masking
14628 This command determines whether the most-significant 32 bits of 64-bit
14629 MIPS addresses are masked off. The argument @var{arg} can be
14630 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14631 setting, which lets @value{GDBN} determine the correct value.
14632
14633 @item show mips mask-address
14634 @kindex show mips mask-address
14635 Show whether the upper 32 bits of MIPS addresses are masked off or
14636 not.
14637
14638 @item set remote-mips64-transfers-32bit-regs
14639 @kindex set remote-mips64-transfers-32bit-regs
14640 This command controls compatibility with 64-bit MIPS targets that
14641 transfer data in 32-bit quantities. If you have an old MIPS 64 target
14642 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14643 and 64 bits for other registers, set this option to @samp{on}.
14644
14645 @item show remote-mips64-transfers-32bit-regs
14646 @kindex show remote-mips64-transfers-32bit-regs
14647 Show the current setting of compatibility with older MIPS 64 targets.
14648
14649 @item set debug mips
14650 @kindex set debug mips
14651 This command turns on and off debugging messages for the MIPS-specific
14652 target code in @value{GDBN}.
14653
14654 @item show debug mips
14655 @kindex show debug mips
14656 Show the current setting of MIPS debugging messages.
14657 @end table
14658
14659
14660 @node HPPA
14661 @subsection HPPA
14662 @cindex HPPA support
14663
14664 When @value{GDBN} is debugging te HP PA architecture, it provides the
14665 following special commands:
14666
14667 @table @code
14668 @item set debug hppa
14669 @kindex set debug hppa
14670 THis command determines whether HPPA architecture specific debugging
14671 messages are to be displayed.
14672
14673 @item show debug hppa
14674 Show whether HPPA debugging messages are displayed.
14675
14676 @item maint print unwind @var{address}
14677 @kindex maint print unwind@r{, HPPA}
14678 This command displays the contents of the unwind table entry at the
14679 given @var{address}.
14680
14681 @end table
14682
14683
14684 @node Controlling GDB
14685 @chapter Controlling @value{GDBN}
14686
14687 You can alter the way @value{GDBN} interacts with you by using the
14688 @code{set} command. For commands controlling how @value{GDBN} displays
14689 data, see @ref{Print Settings, ,Print settings}. Other settings are
14690 described here.
14691
14692 @menu
14693 * Prompt:: Prompt
14694 * Editing:: Command editing
14695 * History:: Command history
14696 * Screen Size:: Screen size
14697 * Numbers:: Numbers
14698 * ABI:: Configuring the current ABI
14699 * Messages/Warnings:: Optional warnings and messages
14700 * Debugging Output:: Optional messages about internal happenings
14701 @end menu
14702
14703 @node Prompt
14704 @section Prompt
14705
14706 @cindex prompt
14707
14708 @value{GDBN} indicates its readiness to read a command by printing a string
14709 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
14710 can change the prompt string with the @code{set prompt} command. For
14711 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
14712 the prompt in one of the @value{GDBN} sessions so that you can always tell
14713 which one you are talking to.
14714
14715 @emph{Note:} @code{set prompt} does not add a space for you after the
14716 prompt you set. This allows you to set a prompt which ends in a space
14717 or a prompt that does not.
14718
14719 @table @code
14720 @kindex set prompt
14721 @item set prompt @var{newprompt}
14722 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
14723
14724 @kindex show prompt
14725 @item show prompt
14726 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
14727 @end table
14728
14729 @node Editing
14730 @section Command editing
14731 @cindex readline
14732 @cindex command line editing
14733
14734 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
14735 @sc{gnu} library provides consistent behavior for programs which provide a
14736 command line interface to the user. Advantages are @sc{gnu} Emacs-style
14737 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
14738 substitution, and a storage and recall of command history across
14739 debugging sessions.
14740
14741 You may control the behavior of command line editing in @value{GDBN} with the
14742 command @code{set}.
14743
14744 @table @code
14745 @kindex set editing
14746 @cindex editing
14747 @item set editing
14748 @itemx set editing on
14749 Enable command line editing (enabled by default).
14750
14751 @item set editing off
14752 Disable command line editing.
14753
14754 @kindex show editing
14755 @item show editing
14756 Show whether command line editing is enabled.
14757 @end table
14758
14759 @xref{Command Line Editing}, for more details about the Readline
14760 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
14761 encouraged to read that chapter.
14762
14763 @node History
14764 @section Command history
14765 @cindex command history
14766
14767 @value{GDBN} can keep track of the commands you type during your
14768 debugging sessions, so that you can be certain of precisely what
14769 happened. Use these commands to manage the @value{GDBN} command
14770 history facility.
14771
14772 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
14773 package, to provide the history facility. @xref{Using History
14774 Interactively}, for the detailed description of the History library.
14775
14776 Here is the description of @value{GDBN} commands related to command
14777 history.
14778
14779 @table @code
14780 @cindex history substitution
14781 @cindex history file
14782 @kindex set history filename
14783 @cindex @env{GDBHISTFILE}, environment variable
14784 @item set history filename @var{fname}
14785 Set the name of the @value{GDBN} command history file to @var{fname}.
14786 This is the file where @value{GDBN} reads an initial command history
14787 list, and where it writes the command history from this session when it
14788 exits. You can access this list through history expansion or through
14789 the history command editing characters listed below. This file defaults
14790 to the value of the environment variable @code{GDBHISTFILE}, or to
14791 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
14792 is not set.
14793
14794 @cindex save command history
14795 @kindex set history save
14796 @item set history save
14797 @itemx set history save on
14798 Record command history in a file, whose name may be specified with the
14799 @code{set history filename} command. By default, this option is disabled.
14800
14801 @item set history save off
14802 Stop recording command history in a file.
14803
14804 @cindex history size
14805 @kindex set history size
14806 @item set history size @var{size}
14807 Set the number of commands which @value{GDBN} keeps in its history list.
14808 This defaults to the value of the environment variable
14809 @code{HISTSIZE}, or to 256 if this variable is not set.
14810 @end table
14811
14812 History expansion assigns special meaning to the character @kbd{!}.
14813 @xref{Event Designators}, for more details.
14814
14815 @cindex history expansion, turn on/off
14816 Since @kbd{!} is also the logical not operator in C, history expansion
14817 is off by default. If you decide to enable history expansion with the
14818 @code{set history expansion on} command, you may sometimes need to
14819 follow @kbd{!} (when it is used as logical not, in an expression) with
14820 a space or a tab to prevent it from being expanded. The readline
14821 history facilities do not attempt substitution on the strings
14822 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
14823
14824 The commands to control history expansion are:
14825
14826 @table @code
14827 @item set history expansion on
14828 @itemx set history expansion
14829 @kindex set history expansion
14830 Enable history expansion. History expansion is off by default.
14831
14832 @item set history expansion off
14833 Disable history expansion.
14834
14835 @c @group
14836 @kindex show history
14837 @item show history
14838 @itemx show history filename
14839 @itemx show history save
14840 @itemx show history size
14841 @itemx show history expansion
14842 These commands display the state of the @value{GDBN} history parameters.
14843 @code{show history} by itself displays all four states.
14844 @c @end group
14845 @end table
14846
14847 @table @code
14848 @kindex show commands
14849 @cindex show last commands
14850 @cindex display command history
14851 @item show commands
14852 Display the last ten commands in the command history.
14853
14854 @item show commands @var{n}
14855 Print ten commands centered on command number @var{n}.
14856
14857 @item show commands +
14858 Print ten commands just after the commands last printed.
14859 @end table
14860
14861 @node Screen Size
14862 @section Screen size
14863 @cindex size of screen
14864 @cindex pauses in output
14865
14866 Certain commands to @value{GDBN} may produce large amounts of
14867 information output to the screen. To help you read all of it,
14868 @value{GDBN} pauses and asks you for input at the end of each page of
14869 output. Type @key{RET} when you want to continue the output, or @kbd{q}
14870 to discard the remaining output. Also, the screen width setting
14871 determines when to wrap lines of output. Depending on what is being
14872 printed, @value{GDBN} tries to break the line at a readable place,
14873 rather than simply letting it overflow onto the following line.
14874
14875 Normally @value{GDBN} knows the size of the screen from the terminal
14876 driver software. For example, on Unix @value{GDBN} uses the termcap data base
14877 together with the value of the @code{TERM} environment variable and the
14878 @code{stty rows} and @code{stty cols} settings. If this is not correct,
14879 you can override it with the @code{set height} and @code{set
14880 width} commands:
14881
14882 @table @code
14883 @kindex set height
14884 @kindex set width
14885 @kindex show width
14886 @kindex show height
14887 @item set height @var{lpp}
14888 @itemx show height
14889 @itemx set width @var{cpl}
14890 @itemx show width
14891 These @code{set} commands specify a screen height of @var{lpp} lines and
14892 a screen width of @var{cpl} characters. The associated @code{show}
14893 commands display the current settings.
14894
14895 If you specify a height of zero lines, @value{GDBN} does not pause during
14896 output no matter how long the output is. This is useful if output is to a
14897 file or to an editor buffer.
14898
14899 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
14900 from wrapping its output.
14901
14902 @item set pagination on
14903 @itemx set pagination off
14904 @kindex set pagination
14905 Turn the output pagination on or off; the default is on. Turning
14906 pagination off is the alternative to @code{set height 0}.
14907
14908 @item show pagination
14909 @kindex show pagination
14910 Show the current pagination mode.
14911 @end table
14912
14913 @node Numbers
14914 @section Numbers
14915 @cindex number representation
14916 @cindex entering numbers
14917
14918 You can always enter numbers in octal, decimal, or hexadecimal in
14919 @value{GDBN} by the usual conventions: octal numbers begin with
14920 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
14921 begin with @samp{0x}. Numbers that begin with none of these are, by
14922 default, entered in base 10; likewise, the default display for
14923 numbers---when no particular format is specified---is base 10. You can
14924 change the default base for both input and output with the @code{set
14925 radix} command.
14926
14927 @table @code
14928 @kindex set input-radix
14929 @item set input-radix @var{base}
14930 Set the default base for numeric input. Supported choices
14931 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
14932 specified either unambiguously or using the current default radix; for
14933 example, any of
14934
14935 @smallexample
14936 set input-radix 012
14937 set input-radix 10.
14938 set input-radix 0xa
14939 @end smallexample
14940
14941 @noindent
14942 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
14943 leaves the input radix unchanged, no matter what it was.
14944
14945 @kindex set output-radix
14946 @item set output-radix @var{base}
14947 Set the default base for numeric display. Supported choices
14948 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
14949 specified either unambiguously or using the current default radix.
14950
14951 @kindex show input-radix
14952 @item show input-radix
14953 Display the current default base for numeric input.
14954
14955 @kindex show output-radix
14956 @item show output-radix
14957 Display the current default base for numeric display.
14958
14959 @item set radix @r{[}@var{base}@r{]}
14960 @itemx show radix
14961 @kindex set radix
14962 @kindex show radix
14963 These commands set and show the default base for both input and output
14964 of numbers. @code{set radix} sets the radix of input and output to
14965 the same base; without an argument, it resets the radix back to its
14966 default value of 10.
14967
14968 @end table
14969
14970 @node ABI
14971 @section Configuring the current ABI
14972
14973 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
14974 application automatically. However, sometimes you need to override its
14975 conclusions. Use these commands to manage @value{GDBN}'s view of the
14976 current ABI.
14977
14978 @cindex OS ABI
14979 @kindex set osabi
14980 @kindex show osabi
14981
14982 One @value{GDBN} configuration can debug binaries for multiple operating
14983 system targets, either via remote debugging or native emulation.
14984 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
14985 but you can override its conclusion using the @code{set osabi} command.
14986 One example where this is useful is in debugging of binaries which use
14987 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
14988 not have the same identifying marks that the standard C library for your
14989 platform provides.
14990
14991 @table @code
14992 @item show osabi
14993 Show the OS ABI currently in use.
14994
14995 @item set osabi
14996 With no argument, show the list of registered available OS ABI's.
14997
14998 @item set osabi @var{abi}
14999 Set the current OS ABI to @var{abi}.
15000 @end table
15001
15002 @cindex float promotion
15003
15004 Generally, the way that an argument of type @code{float} is passed to a
15005 function depends on whether the function is prototyped. For a prototyped
15006 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15007 according to the architecture's convention for @code{float}. For unprototyped
15008 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15009 @code{double} and then passed.
15010
15011 Unfortunately, some forms of debug information do not reliably indicate whether
15012 a function is prototyped. If @value{GDBN} calls a function that is not marked
15013 as prototyped, it consults @kbd{set coerce-float-to-double}.
15014
15015 @table @code
15016 @kindex set coerce-float-to-double
15017 @item set coerce-float-to-double
15018 @itemx set coerce-float-to-double on
15019 Arguments of type @code{float} will be promoted to @code{double} when passed
15020 to an unprototyped function. This is the default setting.
15021
15022 @item set coerce-float-to-double off
15023 Arguments of type @code{float} will be passed directly to unprototyped
15024 functions.
15025
15026 @kindex show coerce-float-to-double
15027 @item show coerce-float-to-double
15028 Show the current setting of promoting @code{float} to @code{double}.
15029 @end table
15030
15031 @kindex set cp-abi
15032 @kindex show cp-abi
15033 @value{GDBN} needs to know the ABI used for your program's C@t{++}
15034 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15035 used to build your application. @value{GDBN} only fully supports
15036 programs with a single C@t{++} ABI; if your program contains code using
15037 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15038 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15039 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15040 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15041 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15042 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15043 ``auto''.
15044
15045 @table @code
15046 @item show cp-abi
15047 Show the C@t{++} ABI currently in use.
15048
15049 @item set cp-abi
15050 With no argument, show the list of supported C@t{++} ABI's.
15051
15052 @item set cp-abi @var{abi}
15053 @itemx set cp-abi auto
15054 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15055 @end table
15056
15057 @node Messages/Warnings
15058 @section Optional warnings and messages
15059
15060 @cindex verbose operation
15061 @cindex optional warnings
15062 By default, @value{GDBN} is silent about its inner workings. If you are
15063 running on a slow machine, you may want to use the @code{set verbose}
15064 command. This makes @value{GDBN} tell you when it does a lengthy
15065 internal operation, so you will not think it has crashed.
15066
15067 Currently, the messages controlled by @code{set verbose} are those
15068 which announce that the symbol table for a source file is being read;
15069 see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
15070
15071 @table @code
15072 @kindex set verbose
15073 @item set verbose on
15074 Enables @value{GDBN} output of certain informational messages.
15075
15076 @item set verbose off
15077 Disables @value{GDBN} output of certain informational messages.
15078
15079 @kindex show verbose
15080 @item show verbose
15081 Displays whether @code{set verbose} is on or off.
15082 @end table
15083
15084 By default, if @value{GDBN} encounters bugs in the symbol table of an
15085 object file, it is silent; but if you are debugging a compiler, you may
15086 find this information useful (@pxref{Symbol Errors, ,Errors reading
15087 symbol files}).
15088
15089 @table @code
15090
15091 @kindex set complaints
15092 @item set complaints @var{limit}
15093 Permits @value{GDBN} to output @var{limit} complaints about each type of
15094 unusual symbols before becoming silent about the problem. Set
15095 @var{limit} to zero to suppress all complaints; set it to a large number
15096 to prevent complaints from being suppressed.
15097
15098 @kindex show complaints
15099 @item show complaints
15100 Displays how many symbol complaints @value{GDBN} is permitted to produce.
15101
15102 @end table
15103
15104 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15105 lot of stupid questions to confirm certain commands. For example, if
15106 you try to run a program which is already running:
15107
15108 @smallexample
15109 (@value{GDBP}) run
15110 The program being debugged has been started already.
15111 Start it from the beginning? (y or n)
15112 @end smallexample
15113
15114 If you are willing to unflinchingly face the consequences of your own
15115 commands, you can disable this ``feature'':
15116
15117 @table @code
15118
15119 @kindex set confirm
15120 @cindex flinching
15121 @cindex confirmation
15122 @cindex stupid questions
15123 @item set confirm off
15124 Disables confirmation requests.
15125
15126 @item set confirm on
15127 Enables confirmation requests (the default).
15128
15129 @kindex show confirm
15130 @item show confirm
15131 Displays state of confirmation requests.
15132
15133 @end table
15134
15135 @node Debugging Output
15136 @section Optional messages about internal happenings
15137 @cindex optional debugging messages
15138
15139 @value{GDBN} has commands that enable optional debugging messages from
15140 various @value{GDBN} subsystems; normally these commands are of
15141 interest to @value{GDBN} maintainers, or when reporting a bug. This
15142 section documents those commands.
15143
15144 @table @code
15145 @kindex set exec-done-display
15146 @item set exec-done-display
15147 Turns on or off the notification of asynchronous commands'
15148 completion. When on, @value{GDBN} will print a message when an
15149 asynchronous command finishes its execution. The default is off.
15150 @kindex show exec-done-display
15151 @item show exec-done-display
15152 Displays the current setting of asynchronous command completion
15153 notification.
15154 @kindex set debug
15155 @cindex gdbarch debugging info
15156 @cindex architecture debugging info
15157 @item set debug arch
15158 Turns on or off display of gdbarch debugging info. The default is off
15159 @kindex show debug
15160 @item show debug arch
15161 Displays the current state of displaying gdbarch debugging info.
15162 @item set debug aix-thread
15163 @cindex AIX threads
15164 Display debugging messages about inner workings of the AIX thread
15165 module.
15166 @item show debug aix-thread
15167 Show the current state of AIX thread debugging info display.
15168 @item set debug event
15169 @cindex event debugging info
15170 Turns on or off display of @value{GDBN} event debugging info. The
15171 default is off.
15172 @item show debug event
15173 Displays the current state of displaying @value{GDBN} event debugging
15174 info.
15175 @item set debug expression
15176 @cindex expression debugging info
15177 Turns on or off display of debugging info about @value{GDBN}
15178 expression parsing. The default is off.
15179 @item show debug expression
15180 Displays the current state of displaying debugging info about
15181 @value{GDBN} expression parsing.
15182 @item set debug frame
15183 @cindex frame debugging info
15184 Turns on or off display of @value{GDBN} frame debugging info. The
15185 default is off.
15186 @item show debug frame
15187 Displays the current state of displaying @value{GDBN} frame debugging
15188 info.
15189 @item set debug infrun
15190 @cindex inferior debugging info
15191 Turns on or off display of @value{GDBN} debugging info for running the inferior.
15192 The default is off. @file{infrun.c} contains GDB's runtime state machine used
15193 for implementing operations such as single-stepping the inferior.
15194 @item show debug infrun
15195 Displays the current state of @value{GDBN} inferior debugging.
15196 @item set debug lin-lwp
15197 @cindex @sc{gnu}/Linux LWP debug messages
15198 @cindex Linux lightweight processes
15199 Turns on or off debugging messages from the Linux LWP debug support.
15200 @item show debug lin-lwp
15201 Show the current state of Linux LWP debugging messages.
15202 @item set debug observer
15203 @cindex observer debugging info
15204 Turns on or off display of @value{GDBN} observer debugging. This
15205 includes info such as the notification of observable events.
15206 @item show debug observer
15207 Displays the current state of observer debugging.
15208 @item set debug overload
15209 @cindex C@t{++} overload debugging info
15210 Turns on or off display of @value{GDBN} C@t{++} overload debugging
15211 info. This includes info such as ranking of functions, etc. The default
15212 is off.
15213 @item show debug overload
15214 Displays the current state of displaying @value{GDBN} C@t{++} overload
15215 debugging info.
15216 @cindex packets, reporting on stdout
15217 @cindex serial connections, debugging
15218 @item set debug remote
15219 Turns on or off display of reports on all packets sent back and forth across
15220 the serial line to the remote machine. The info is printed on the
15221 @value{GDBN} standard output stream. The default is off.
15222 @item show debug remote
15223 Displays the state of display of remote packets.
15224 @item set debug serial
15225 Turns on or off display of @value{GDBN} serial debugging info. The
15226 default is off.
15227 @item show debug serial
15228 Displays the current state of displaying @value{GDBN} serial debugging
15229 info.
15230 @item set debug target
15231 @cindex target debugging info
15232 Turns on or off display of @value{GDBN} target debugging info. This info
15233 includes what is going on at the target level of GDB, as it happens. The
15234 default is 0. Set it to 1 to track events, and to 2 to also track the
15235 value of large memory transfers. Changes to this flag do not take effect
15236 until the next time you connect to a target or use the @code{run} command.
15237 @item show debug target
15238 Displays the current state of displaying @value{GDBN} target debugging
15239 info.
15240 @item set debug varobj
15241 @cindex variable object debugging info
15242 Turns on or off display of @value{GDBN} variable object debugging
15243 info. The default is off.
15244 @item show debug varobj
15245 Displays the current state of displaying @value{GDBN} variable object
15246 debugging info.
15247 @end table
15248
15249 @node Sequences
15250 @chapter Canned Sequences of Commands
15251
15252 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15253 command lists}), @value{GDBN} provides two ways to store sequences of
15254 commands for execution as a unit: user-defined commands and command
15255 files.
15256
15257 @menu
15258 * Define:: User-defined commands
15259 * Hooks:: User-defined command hooks
15260 * Command Files:: Command files
15261 * Output:: Commands for controlled output
15262 @end menu
15263
15264 @node Define
15265 @section User-defined commands
15266
15267 @cindex user-defined command
15268 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15269 which you assign a new name as a command. This is done with the
15270 @code{define} command. User commands may accept up to 10 arguments
15271 separated by whitespace. Arguments are accessed within the user command
15272 via @var{$arg0@dots{}$arg9}. A trivial example:
15273
15274 @smallexample
15275 define adder
15276 print $arg0 + $arg1 + $arg2
15277 @end smallexample
15278
15279 @noindent
15280 To execute the command use:
15281
15282 @smallexample
15283 adder 1 2 3
15284 @end smallexample
15285
15286 @noindent
15287 This defines the command @code{adder}, which prints the sum of
15288 its three arguments. Note the arguments are text substitutions, so they may
15289 reference variables, use complex expressions, or even perform inferior
15290 functions calls.
15291
15292 @table @code
15293
15294 @kindex define
15295 @item define @var{commandname}
15296 Define a command named @var{commandname}. If there is already a command
15297 by that name, you are asked to confirm that you want to redefine it.
15298
15299 The definition of the command is made up of other @value{GDBN} command lines,
15300 which are given following the @code{define} command. The end of these
15301 commands is marked by a line containing @code{end}.
15302
15303 @kindex if
15304 @kindex else
15305 @item if
15306 @itemx else
15307 Takes a single argument, which is an expression to evaluate.
15308 It is followed by a series of commands that are executed
15309 only if the expression is true (nonzero).
15310 There can then optionally be a line @code{else}, followed
15311 by a series of commands that are only executed if the expression
15312 was false. The end of the list is marked by a line containing @code{end}.
15313
15314 @kindex while
15315 @item while
15316 The syntax is similar to @code{if}: the command takes a single argument,
15317 which is an expression to evaluate, and must be followed by the commands to
15318 execute, one per line, terminated by an @code{end}.
15319 The commands are executed repeatedly as long as the expression
15320 evaluates to true.
15321
15322 @kindex document
15323 @item document @var{commandname}
15324 Document the user-defined command @var{commandname}, so that it can be
15325 accessed by @code{help}. The command @var{commandname} must already be
15326 defined. This command reads lines of documentation just as @code{define}
15327 reads the lines of the command definition, ending with @code{end}.
15328 After the @code{document} command is finished, @code{help} on command
15329 @var{commandname} displays the documentation you have written.
15330
15331 You may use the @code{document} command again to change the
15332 documentation of a command. Redefining the command with @code{define}
15333 does not change the documentation.
15334
15335 @kindex help user-defined
15336 @item help user-defined
15337 List all user-defined commands, with the first line of the documentation
15338 (if any) for each.
15339
15340 @kindex show user
15341 @item show user
15342 @itemx show user @var{commandname}
15343 Display the @value{GDBN} commands used to define @var{commandname} (but
15344 not its documentation). If no @var{commandname} is given, display the
15345 definitions for all user-defined commands.
15346
15347 @cindex infinite recusrion in user-defined commands
15348 @kindex show max-user-call-depth
15349 @kindex set max-user-call-depth
15350 @item show max-user-call-depth
15351 @itemx set max-user-call-depth
15352 The value of @code{max-user-call-depth} controls how many recursion
15353 levels are allowed in user-defined commands before GDB suspects an
15354 infinite recursion and aborts the command.
15355
15356 @end table
15357
15358 When user-defined commands are executed, the
15359 commands of the definition are not printed. An error in any command
15360 stops execution of the user-defined command.
15361
15362 If used interactively, commands that would ask for confirmation proceed
15363 without asking when used inside a user-defined command. Many @value{GDBN}
15364 commands that normally print messages to say what they are doing omit the
15365 messages when used in a user-defined command.
15366
15367 @node Hooks
15368 @section User-defined command hooks
15369 @cindex command hooks
15370 @cindex hooks, for commands
15371 @cindex hooks, pre-command
15372
15373 @kindex hook
15374 You may define @dfn{hooks}, which are a special kind of user-defined
15375 command. Whenever you run the command @samp{foo}, if the user-defined
15376 command @samp{hook-foo} exists, it is executed (with no arguments)
15377 before that command.
15378
15379 @cindex hooks, post-command
15380 @kindex hookpost
15381 A hook may also be defined which is run after the command you executed.
15382 Whenever you run the command @samp{foo}, if the user-defined command
15383 @samp{hookpost-foo} exists, it is executed (with no arguments) after
15384 that command. Post-execution hooks may exist simultaneously with
15385 pre-execution hooks, for the same command.
15386
15387 It is valid for a hook to call the command which it hooks. If this
15388 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
15389
15390 @c It would be nice if hookpost could be passed a parameter indicating
15391 @c if the command it hooks executed properly or not. FIXME!
15392
15393 @kindex stop@r{, a pseudo-command}
15394 In addition, a pseudo-command, @samp{stop} exists. Defining
15395 (@samp{hook-stop}) makes the associated commands execute every time
15396 execution stops in your program: before breakpoint commands are run,
15397 displays are printed, or the stack frame is printed.
15398
15399 For example, to ignore @code{SIGALRM} signals while
15400 single-stepping, but treat them normally during normal execution,
15401 you could define:
15402
15403 @smallexample
15404 define hook-stop
15405 handle SIGALRM nopass
15406 end
15407
15408 define hook-run
15409 handle SIGALRM pass
15410 end
15411
15412 define hook-continue
15413 handle SIGLARM pass
15414 end
15415 @end smallexample
15416
15417 As a further example, to hook at the begining and end of the @code{echo}
15418 command, and to add extra text to the beginning and end of the message,
15419 you could define:
15420
15421 @smallexample
15422 define hook-echo
15423 echo <<<---
15424 end
15425
15426 define hookpost-echo
15427 echo --->>>\n
15428 end
15429
15430 (@value{GDBP}) echo Hello World
15431 <<<---Hello World--->>>
15432 (@value{GDBP})
15433
15434 @end smallexample
15435
15436 You can define a hook for any single-word command in @value{GDBN}, but
15437 not for command aliases; you should define a hook for the basic command
15438 name, e.g. @code{backtrace} rather than @code{bt}.
15439 @c FIXME! So how does Joe User discover whether a command is an alias
15440 @c or not?
15441 If an error occurs during the execution of your hook, execution of
15442 @value{GDBN} commands stops and @value{GDBN} issues a prompt
15443 (before the command that you actually typed had a chance to run).
15444
15445 If you try to define a hook which does not match any known command, you
15446 get a warning from the @code{define} command.
15447
15448 @node Command Files
15449 @section Command files
15450
15451 @cindex command files
15452 A command file for @value{GDBN} is a file of lines that are @value{GDBN}
15453 commands. Comments (lines starting with @kbd{#}) may also be included.
15454 An empty line in a command file does nothing; it does not mean to repeat
15455 the last command, as it would from the terminal.
15456
15457 @cindex init file
15458 @cindex @file{.gdbinit}
15459 @cindex @file{gdb.ini}
15460 When you start @value{GDBN}, it automatically executes commands from its
15461 @dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
15462 port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
15463 limitations of file names imposed by DOS filesystems.}.
15464 During startup, @value{GDBN} does the following:
15465
15466 @enumerate
15467 @item
15468 Reads the init file (if any) in your home directory@footnote{On
15469 DOS/Windows systems, the home directory is the one pointed to by the
15470 @code{HOME} environment variable.}.
15471
15472 @item
15473 Processes command line options and operands.
15474
15475 @item
15476 Reads the init file (if any) in the current working directory.
15477
15478 @item
15479 Reads command files specified by the @samp{-x} option.
15480 @end enumerate
15481
15482 The init file in your home directory can set options (such as @samp{set
15483 complaints}) that affect subsequent processing of command line options
15484 and operands. Init files are not executed if you use the @samp{-nx}
15485 option (@pxref{Mode Options, ,Choosing modes}).
15486
15487 @cindex init file name
15488 On some configurations of @value{GDBN}, the init file is known by a
15489 different name (these are typically environments where a specialized
15490 form of @value{GDBN} may need to coexist with other forms, hence a
15491 different name for the specialized version's init file). These are the
15492 environments with special init file names:
15493
15494 @cindex @file{.vxgdbinit}
15495 @itemize @bullet
15496 @item
15497 VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
15498
15499 @cindex @file{.os68gdbinit}
15500 @item
15501 OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
15502
15503 @cindex @file{.esgdbinit}
15504 @item
15505 ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
15506 @end itemize
15507
15508 You can also request the execution of a command file with the
15509 @code{source} command:
15510
15511 @table @code
15512 @kindex source
15513 @item source @var{filename}
15514 Execute the command file @var{filename}.
15515 @end table
15516
15517 The lines in a command file are executed sequentially. They are not
15518 printed as they are executed. An error in any command terminates
15519 execution of the command file and control is returned to the console.
15520
15521 Commands that would ask for confirmation if used interactively proceed
15522 without asking when used in a command file. Many @value{GDBN} commands that
15523 normally print messages to say what they are doing omit the messages
15524 when called from command files.
15525
15526 @value{GDBN} also accepts command input from standard input. In this
15527 mode, normal output goes to standard output and error output goes to
15528 standard error. Errors in a command file supplied on standard input do
15529 not terminate execution of the command file --- execution continues with
15530 the next command.
15531
15532 @smallexample
15533 gdb < cmds > log 2>&1
15534 @end smallexample
15535
15536 (The syntax above will vary depending on the shell used.) This example
15537 will execute commands from the file @file{cmds}. All output and errors
15538 would be directed to @file{log}.
15539
15540 @node Output
15541 @section Commands for controlled output
15542
15543 During the execution of a command file or a user-defined command, normal
15544 @value{GDBN} output is suppressed; the only output that appears is what is
15545 explicitly printed by the commands in the definition. This section
15546 describes three commands useful for generating exactly the output you
15547 want.
15548
15549 @table @code
15550 @kindex echo
15551 @item echo @var{text}
15552 @c I do not consider backslash-space a standard C escape sequence
15553 @c because it is not in ANSI.
15554 Print @var{text}. Nonprinting characters can be included in
15555 @var{text} using C escape sequences, such as @samp{\n} to print a
15556 newline. @strong{No newline is printed unless you specify one.}
15557 In addition to the standard C escape sequences, a backslash followed
15558 by a space stands for a space. This is useful for displaying a
15559 string with spaces at the beginning or the end, since leading and
15560 trailing spaces are otherwise trimmed from all arguments.
15561 To print @samp{@w{ }and foo =@w{ }}, use the command
15562 @samp{echo \@w{ }and foo = \@w{ }}.
15563
15564 A backslash at the end of @var{text} can be used, as in C, to continue
15565 the command onto subsequent lines. For example,
15566
15567 @smallexample
15568 echo This is some text\n\
15569 which is continued\n\
15570 onto several lines.\n
15571 @end smallexample
15572
15573 produces the same output as
15574
15575 @smallexample
15576 echo This is some text\n
15577 echo which is continued\n
15578 echo onto several lines.\n
15579 @end smallexample
15580
15581 @kindex output
15582 @item output @var{expression}
15583 Print the value of @var{expression} and nothing but that value: no
15584 newlines, no @samp{$@var{nn} = }. The value is not entered in the
15585 value history either. @xref{Expressions, ,Expressions}, for more information
15586 on expressions.
15587
15588 @item output/@var{fmt} @var{expression}
15589 Print the value of @var{expression} in format @var{fmt}. You can use
15590 the same formats as for @code{print}. @xref{Output Formats,,Output
15591 formats}, for more information.
15592
15593 @kindex printf
15594 @item printf @var{string}, @var{expressions}@dots{}
15595 Print the values of the @var{expressions} under the control of
15596 @var{string}. The @var{expressions} are separated by commas and may be
15597 either numbers or pointers. Their values are printed as specified by
15598 @var{string}, exactly as if your program were to execute the C
15599 subroutine
15600 @c FIXME: the above implies that at least all ANSI C formats are
15601 @c supported, but it isn't true: %E and %G don't work (or so it seems).
15602 @c Either this is a bug, or the manual should document what formats are
15603 @c supported.
15604
15605 @smallexample
15606 printf (@var{string}, @var{expressions}@dots{});
15607 @end smallexample
15608
15609 For example, you can print two values in hex like this:
15610
15611 @smallexample
15612 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15613 @end smallexample
15614
15615 The only backslash-escape sequences that you can use in the format
15616 string are the simple ones that consist of backslash followed by a
15617 letter.
15618 @end table
15619
15620 @node Interpreters
15621 @chapter Command Interpreters
15622 @cindex command interpreters
15623
15624 @value{GDBN} supports multiple command interpreters, and some command
15625 infrastructure to allow users or user interface writers to switch
15626 between interpreters or run commands in other interpreters.
15627
15628 @value{GDBN} currently supports two command interpreters, the console
15629 interpreter (sometimes called the command-line interpreter or @sc{cli})
15630 and the machine interface interpreter (or @sc{gdb/mi}). This manual
15631 describes both of these interfaces in great detail.
15632
15633 By default, @value{GDBN} will start with the console interpreter.
15634 However, the user may choose to start @value{GDBN} with another
15635 interpreter by specifying the @option{-i} or @option{--interpreter}
15636 startup options. Defined interpreters include:
15637
15638 @table @code
15639 @item console
15640 @cindex console interpreter
15641 The traditional console or command-line interpreter. This is the most often
15642 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15643 @value{GDBN} will use this interpreter.
15644
15645 @item mi
15646 @cindex mi interpreter
15647 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15648 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15649 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15650 Interface}.
15651
15652 @item mi2
15653 @cindex mi2 interpreter
15654 The current @sc{gdb/mi} interface.
15655
15656 @item mi1
15657 @cindex mi1 interpreter
15658 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15659
15660 @end table
15661
15662 @cindex invoke another interpreter
15663 The interpreter being used by @value{GDBN} may not be dynamically
15664 switched at runtime. Although possible, this could lead to a very
15665 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15666 enters the command "interpreter-set console" in a console view,
15667 @value{GDBN} would switch to using the console interpreter, rendering
15668 the IDE inoperable!
15669
15670 @kindex interpreter-exec
15671 Although you may only choose a single interpreter at startup, you may execute
15672 commands in any interpreter from the current interpreter using the appropriate
15673 command. If you are running the console interpreter, simply use the
15674 @code{interpreter-exec} command:
15675
15676 @smallexample
15677 interpreter-exec mi "-data-list-register-names"
15678 @end smallexample
15679
15680 @sc{gdb/mi} has a similar command, although it is only available in versions of
15681 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15682
15683 @node TUI
15684 @chapter @value{GDBN} Text User Interface
15685 @cindex TUI
15686 @cindex Text User Interface
15687
15688 @menu
15689 * TUI Overview:: TUI overview
15690 * TUI Keys:: TUI key bindings
15691 * TUI Single Key Mode:: TUI single key mode
15692 * TUI Commands:: TUI specific commands
15693 * TUI Configuration:: TUI configuration variables
15694 @end menu
15695
15696 The @value{GDBN} Text User Interface, TUI in short, is a terminal
15697 interface which uses the @code{curses} library to show the source
15698 file, the assembly output, the program registers and @value{GDBN}
15699 commands in separate text windows.
15700
15701 The TUI is enabled by invoking @value{GDBN} using either
15702 @pindex gdbtui
15703 @samp{gdbtui} or @samp{gdb -tui}.
15704
15705 @node TUI Overview
15706 @section TUI overview
15707
15708 The TUI has two display modes that can be switched while
15709 @value{GDBN} runs:
15710
15711 @itemize @bullet
15712 @item
15713 A curses (or TUI) mode in which it displays several text
15714 windows on the terminal.
15715
15716 @item
15717 A standard mode which corresponds to the @value{GDBN} configured without
15718 the TUI.
15719 @end itemize
15720
15721 In the TUI mode, @value{GDBN} can display several text window
15722 on the terminal:
15723
15724 @table @emph
15725 @item command
15726 This window is the @value{GDBN} command window with the @value{GDBN}
15727 prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
15728 managed using readline but through the TUI. The @emph{command}
15729 window is always visible.
15730
15731 @item source
15732 The source window shows the source file of the program. The current
15733 line as well as active breakpoints are displayed in this window.
15734
15735 @item assembly
15736 The assembly window shows the disassembly output of the program.
15737
15738 @item register
15739 This window shows the processor registers. It detects when
15740 a register is changed and when this is the case, registers that have
15741 changed are highlighted.
15742
15743 @end table
15744
15745 The source and assembly windows show the current program position
15746 by highlighting the current line and marking them with the @samp{>} marker.
15747 Breakpoints are also indicated with two markers. A first one
15748 indicates the breakpoint type:
15749
15750 @table @code
15751 @item B
15752 Breakpoint which was hit at least once.
15753
15754 @item b
15755 Breakpoint which was never hit.
15756
15757 @item H
15758 Hardware breakpoint which was hit at least once.
15759
15760 @item h
15761 Hardware breakpoint which was never hit.
15762
15763 @end table
15764
15765 The second marker indicates whether the breakpoint is enabled or not:
15766
15767 @table @code
15768 @item +
15769 Breakpoint is enabled.
15770
15771 @item -
15772 Breakpoint is disabled.
15773
15774 @end table
15775
15776 The source, assembly and register windows are attached to the thread
15777 and the frame position. They are updated when the current thread
15778 changes, when the frame changes or when the program counter changes.
15779 These three windows are arranged by the TUI according to several
15780 layouts. The layout defines which of these three windows are visible.
15781 The following layouts are available:
15782
15783 @itemize @bullet
15784 @item
15785 source
15786
15787 @item
15788 assembly
15789
15790 @item
15791 source and assembly
15792
15793 @item
15794 source and registers
15795
15796 @item
15797 assembly and registers
15798
15799 @end itemize
15800
15801 On top of the command window a status line gives various information
15802 concerning the current process begin debugged. The status line is
15803 updated when the information it shows changes. The following fields
15804 are displayed:
15805
15806 @table @emph
15807 @item target
15808 Indicates the current gdb target
15809 (@pxref{Targets, ,Specifying a Debugging Target}).
15810
15811 @item process
15812 Gives information about the current process or thread number.
15813 When no process is being debugged, this field is set to @code{No process}.
15814
15815 @item function
15816 Gives the current function name for the selected frame.
15817 The name is demangled if demangling is turned on (@pxref{Print Settings}).
15818 When there is no symbol corresponding to the current program counter
15819 the string @code{??} is displayed.
15820
15821 @item line
15822 Indicates the current line number for the selected frame.
15823 When the current line number is not known the string @code{??} is displayed.
15824
15825 @item pc
15826 Indicates the current program counter address.
15827
15828 @end table
15829
15830 @node TUI Keys
15831 @section TUI Key Bindings
15832 @cindex TUI key bindings
15833
15834 The TUI installs several key bindings in the readline keymaps
15835 (@pxref{Command Line Editing}).
15836 They allow to leave or enter in the TUI mode or they operate
15837 directly on the TUI layout and windows. The TUI also provides
15838 a @emph{SingleKey} keymap which binds several keys directly to
15839 @value{GDBN} commands. The following key bindings
15840 are installed for both TUI mode and the @value{GDBN} standard mode.
15841
15842 @table @kbd
15843 @kindex C-x C-a
15844 @item C-x C-a
15845 @kindex C-x a
15846 @itemx C-x a
15847 @kindex C-x A
15848 @itemx C-x A
15849 Enter or leave the TUI mode. When the TUI mode is left,
15850 the curses window management is left and @value{GDBN} operates using
15851 its standard mode writing on the terminal directly. When the TUI
15852 mode is entered, the control is given back to the curses windows.
15853 The screen is then refreshed.
15854
15855 @kindex C-x 1
15856 @item C-x 1
15857 Use a TUI layout with only one window. The layout will
15858 either be @samp{source} or @samp{assembly}. When the TUI mode
15859 is not active, it will switch to the TUI mode.
15860
15861 Think of this key binding as the Emacs @kbd{C-x 1} binding.
15862
15863 @kindex C-x 2
15864 @item C-x 2
15865 Use a TUI layout with at least two windows. When the current
15866 layout shows already two windows, a next layout with two windows is used.
15867 When a new layout is chosen, one window will always be common to the
15868 previous layout and the new one.
15869
15870 Think of it as the Emacs @kbd{C-x 2} binding.
15871
15872 @kindex C-x o
15873 @item C-x o
15874 Change the active window. The TUI associates several key bindings
15875 (like scrolling and arrow keys) to the active window. This command
15876 gives the focus to the next TUI window.
15877
15878 Think of it as the Emacs @kbd{C-x o} binding.
15879
15880 @kindex C-x s
15881 @item C-x s
15882 Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
15883 (@pxref{TUI Single Key Mode}).
15884
15885 @end table
15886
15887 The following key bindings are handled only by the TUI mode:
15888
15889 @table @key
15890 @kindex PgUp
15891 @item PgUp
15892 Scroll the active window one page up.
15893
15894 @kindex PgDn
15895 @item PgDn
15896 Scroll the active window one page down.
15897
15898 @kindex Up
15899 @item Up
15900 Scroll the active window one line up.
15901
15902 @kindex Down
15903 @item Down
15904 Scroll the active window one line down.
15905
15906 @kindex Left
15907 @item Left
15908 Scroll the active window one column left.
15909
15910 @kindex Right
15911 @item Right
15912 Scroll the active window one column right.
15913
15914 @kindex C-L
15915 @item C-L
15916 Refresh the screen.
15917
15918 @end table
15919
15920 In the TUI mode, the arrow keys are used by the active window
15921 for scrolling. This means they are available for readline when the
15922 active window is the command window. When the command window
15923 does not have the focus, it is necessary to use other readline
15924 key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
15925
15926 @node TUI Single Key Mode
15927 @section TUI Single Key Mode
15928 @cindex TUI single key mode
15929
15930 The TUI provides a @emph{SingleKey} mode in which it installs a particular
15931 key binding in the readline keymaps to connect single keys to
15932 some gdb commands.
15933
15934 @table @kbd
15935 @kindex c @r{(SingleKey TUI key)}
15936 @item c
15937 continue
15938
15939 @kindex d @r{(SingleKey TUI key)}
15940 @item d
15941 down
15942
15943 @kindex f @r{(SingleKey TUI key)}
15944 @item f
15945 finish
15946
15947 @kindex n @r{(SingleKey TUI key)}
15948 @item n
15949 next
15950
15951 @kindex q @r{(SingleKey TUI key)}
15952 @item q
15953 exit the @emph{SingleKey} mode.
15954
15955 @kindex r @r{(SingleKey TUI key)}
15956 @item r
15957 run
15958
15959 @kindex s @r{(SingleKey TUI key)}
15960 @item s
15961 step
15962
15963 @kindex u @r{(SingleKey TUI key)}
15964 @item u
15965 up
15966
15967 @kindex v @r{(SingleKey TUI key)}
15968 @item v
15969 info locals
15970
15971 @kindex w @r{(SingleKey TUI key)}
15972 @item w
15973 where
15974
15975 @end table
15976
15977 Other keys temporarily switch to the @value{GDBN} command prompt.
15978 The key that was pressed is inserted in the editing buffer so that
15979 it is possible to type most @value{GDBN} commands without interaction
15980 with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
15981 @emph{SingleKey} mode is restored. The only way to permanently leave
15982 this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
15983
15984
15985 @node TUI Commands
15986 @section TUI specific commands
15987 @cindex TUI commands
15988
15989 The TUI has specific commands to control the text windows.
15990 These commands are always available, that is they do not depend on
15991 the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
15992 is in the standard mode, using these commands will automatically switch
15993 in the TUI mode.
15994
15995 @table @code
15996 @item info win
15997 @kindex info win
15998 List and give the size of all displayed windows.
15999
16000 @item layout next
16001 @kindex layout
16002 Display the next layout.
16003
16004 @item layout prev
16005 Display the previous layout.
16006
16007 @item layout src
16008 Display the source window only.
16009
16010 @item layout asm
16011 Display the assembly window only.
16012
16013 @item layout split
16014 Display the source and assembly window.
16015
16016 @item layout regs
16017 Display the register window together with the source or assembly window.
16018
16019 @item focus next | prev | src | asm | regs | split
16020 @kindex focus
16021 Set the focus to the named window.
16022 This command allows to change the active window so that scrolling keys
16023 can be affected to another window.
16024
16025 @item refresh
16026 @kindex refresh
16027 Refresh the screen. This is similar to using @key{C-L} key.
16028
16029 @item tui reg float
16030 @kindex tui reg
16031 Show the floating point registers in the register window.
16032
16033 @item tui reg general
16034 Show the general registers in the register window.
16035
16036 @item tui reg next
16037 Show the next register group. The list of register groups as well as
16038 their order is target specific. The predefined register groups are the
16039 following: @code{general}, @code{float}, @code{system}, @code{vector},
16040 @code{all}, @code{save}, @code{restore}.
16041
16042 @item tui reg system
16043 Show the system registers in the register window.
16044
16045 @item update
16046 @kindex update
16047 Update the source window and the current execution point.
16048
16049 @item winheight @var{name} +@var{count}
16050 @itemx winheight @var{name} -@var{count}
16051 @kindex winheight
16052 Change the height of the window @var{name} by @var{count}
16053 lines. Positive counts increase the height, while negative counts
16054 decrease it.
16055
16056 @end table
16057
16058 @node TUI Configuration
16059 @section TUI configuration variables
16060 @cindex TUI configuration variables
16061
16062 The TUI has several configuration variables that control the
16063 appearance of windows on the terminal.
16064
16065 @table @code
16066 @item set tui border-kind @var{kind}
16067 @kindex set tui border-kind
16068 Select the border appearance for the source, assembly and register windows.
16069 The possible values are the following:
16070 @table @code
16071 @item space
16072 Use a space character to draw the border.
16073
16074 @item ascii
16075 Use ascii characters + - and | to draw the border.
16076
16077 @item acs
16078 Use the Alternate Character Set to draw the border. The border is
16079 drawn using character line graphics if the terminal supports them.
16080
16081 @end table
16082
16083 @item set tui active-border-mode @var{mode}
16084 @kindex set tui active-border-mode
16085 Select the attributes to display the border of the active window.
16086 The possible values are @code{normal}, @code{standout}, @code{reverse},
16087 @code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
16088
16089 @item set tui border-mode @var{mode}
16090 @kindex set tui border-mode
16091 Select the attributes to display the border of other windows.
16092 The @var{mode} can be one of the following:
16093 @table @code
16094 @item normal
16095 Use normal attributes to display the border.
16096
16097 @item standout
16098 Use standout mode.
16099
16100 @item reverse
16101 Use reverse video mode.
16102
16103 @item half
16104 Use half bright mode.
16105
16106 @item half-standout
16107 Use half bright and standout mode.
16108
16109 @item bold
16110 Use extra bright or bold mode.
16111
16112 @item bold-standout
16113 Use extra bright or bold and standout mode.
16114
16115 @end table
16116
16117 @end table
16118
16119 @node Emacs
16120 @chapter Using @value{GDBN} under @sc{gnu} Emacs
16121
16122 @cindex Emacs
16123 @cindex @sc{gnu} Emacs
16124 A special interface allows you to use @sc{gnu} Emacs to view (and
16125 edit) the source files for the program you are debugging with
16126 @value{GDBN}.
16127
16128 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16129 executable file you want to debug as an argument. This command starts
16130 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
16131 created Emacs buffer.
16132 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
16133
16134 Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16135 things:
16136
16137 @itemize @bullet
16138 @item
16139 All ``terminal'' input and output goes through the Emacs buffer.
16140 @end itemize
16141
16142 This applies both to @value{GDBN} commands and their output, and to the input
16143 and output done by the program you are debugging.
16144
16145 This is useful because it means that you can copy the text of previous
16146 commands and input them again; you can even use parts of the output
16147 in this way.
16148
16149 All the facilities of Emacs' Shell mode are available for interacting
16150 with your program. In particular, you can send signals the usual
16151 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16152 stop.
16153
16154 @itemize @bullet
16155 @item
16156 @value{GDBN} displays source code through Emacs.
16157 @end itemize
16158
16159 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16160 source file for that frame and puts an arrow (@samp{=>}) at the
16161 left margin of the current line. Emacs uses a separate buffer for
16162 source display, and splits the screen to show both your @value{GDBN} session
16163 and the source.
16164
16165 Explicit @value{GDBN} @code{list} or search commands still produce output as
16166 usual, but you probably have no reason to use them from Emacs.
16167
16168 If you specify an absolute file name when prompted for the @kbd{M-x
16169 gdb} argument, then Emacs sets your current working directory to where
16170 your program resides. If you only specify the file name, then Emacs
16171 sets your current working directory to to the directory associated
16172 with the previous buffer. In this case, @value{GDBN} may find your
16173 program by searching your environment's @code{PATH} variable, but on
16174 some operating systems it might not find the source. So, although the
16175 @value{GDBN} input and output session proceeds normally, the auxiliary
16176 buffer does not display the current source and line of execution.
16177
16178 The initial working directory of @value{GDBN} is printed on the top
16179 line of the @value{GDBN} I/O buffer and this serves as a default for
16180 the commands that specify files for @value{GDBN} to operate
16181 on. @xref{Files, ,Commands to specify files}.
16182
16183 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16184 need to call @value{GDBN} by a different name (for example, if you
16185 keep several configurations around, with different names) you can
16186 customize the Emacs variable @code{gud-gdb-command-name} to run the
16187 one you want.
16188
16189 In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16190 addition to the standard Shell mode commands:
16191
16192 @table @kbd
16193 @item C-h m
16194 Describe the features of Emacs' @value{GDBN} Mode.
16195
16196 @item C-c C-s
16197 Execute to another source line, like the @value{GDBN} @code{step} command; also
16198 update the display window to show the current file and location.
16199
16200 @item C-c C-n
16201 Execute to next source line in this function, skipping all function
16202 calls, like the @value{GDBN} @code{next} command. Then update the display window
16203 to show the current file and location.
16204
16205 @item C-c C-i
16206 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16207 display window accordingly.
16208
16209 @item C-c C-f
16210 Execute until exit from the selected stack frame, like the @value{GDBN}
16211 @code{finish} command.
16212
16213 @item C-c C-r
16214 Continue execution of your program, like the @value{GDBN} @code{continue}
16215 command.
16216
16217 @item C-c <
16218 Go up the number of frames indicated by the numeric argument
16219 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16220 like the @value{GDBN} @code{up} command.
16221
16222 @item C-c >
16223 Go down the number of frames indicated by the numeric argument, like the
16224 @value{GDBN} @code{down} command.
16225 @end table
16226
16227 In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
16228 tells @value{GDBN} to set a breakpoint on the source line point is on.
16229
16230 If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16231 shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16232 point to any frame in the stack and type @key{RET} to make it become the
16233 current frame and display the associated source in the source buffer.
16234 Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16235 current one.
16236
16237 If you accidentally delete the source-display buffer, an easy way to get
16238 it back is to type the command @code{f} in the @value{GDBN} buffer, to
16239 request a frame display; when you run under Emacs, this recreates
16240 the source buffer if necessary to show you the context of the current
16241 frame.
16242
16243 The source files displayed in Emacs are in ordinary Emacs buffers
16244 which are visiting the source files in the usual way. You can edit
16245 the files with these buffers if you wish; but keep in mind that @value{GDBN}
16246 communicates with Emacs in terms of line numbers. If you add or
16247 delete lines from the text, the line numbers that @value{GDBN} knows cease
16248 to correspond properly with the code.
16249
16250 The description given here is for GNU Emacs version 21.3 and a more
16251 detailed description of its interaction with @value{GDBN} is given in
16252 the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
16253
16254 @c The following dropped because Epoch is nonstandard. Reactivate
16255 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16256 @ignore
16257 @kindex Emacs Epoch environment
16258 @kindex Epoch
16259 @kindex inspect
16260
16261 Version 18 of @sc{gnu} Emacs has a built-in window system
16262 called the @code{epoch}
16263 environment. Users of this environment can use a new command,
16264 @code{inspect} which performs identically to @code{print} except that
16265 each value is printed in its own window.
16266 @end ignore
16267
16268
16269 @node GDB/MI
16270 @chapter The @sc{gdb/mi} Interface
16271
16272 @unnumberedsec Function and Purpose
16273
16274 @cindex @sc{gdb/mi}, its purpose
16275 @sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
16276 specifically intended to support the development of systems which use
16277 the debugger as just one small component of a larger system.
16278
16279 This chapter is a specification of the @sc{gdb/mi} interface. It is written
16280 in the form of a reference manual.
16281
16282 Note that @sc{gdb/mi} is still under construction, so some of the
16283 features described below are incomplete and subject to change.
16284
16285 @unnumberedsec Notation and Terminology
16286
16287 @cindex notational conventions, for @sc{gdb/mi}
16288 This chapter uses the following notation:
16289
16290 @itemize @bullet
16291 @item
16292 @code{|} separates two alternatives.
16293
16294 @item
16295 @code{[ @var{something} ]} indicates that @var{something} is optional:
16296 it may or may not be given.
16297
16298 @item
16299 @code{( @var{group} )*} means that @var{group} inside the parentheses
16300 may repeat zero or more times.
16301
16302 @item
16303 @code{( @var{group} )+} means that @var{group} inside the parentheses
16304 may repeat one or more times.
16305
16306 @item
16307 @code{"@var{string}"} means a literal @var{string}.
16308 @end itemize
16309
16310 @ignore
16311 @heading Dependencies
16312 @end ignore
16313
16314 @heading Acknowledgments
16315
16316 In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16317 Elena Zannoni.
16318
16319 @menu
16320 * GDB/MI Command Syntax::
16321 * GDB/MI Compatibility with CLI::
16322 * GDB/MI Output Records::
16323 * GDB/MI Command Description Format::
16324 * GDB/MI Breakpoint Table Commands::
16325 * GDB/MI Data Manipulation::
16326 * GDB/MI Program Control::
16327 * GDB/MI Miscellaneous Commands::
16328 @ignore
16329 * GDB/MI Kod Commands::
16330 * GDB/MI Memory Overlay Commands::
16331 * GDB/MI Signal Handling Commands::
16332 @end ignore
16333 * GDB/MI Stack Manipulation::
16334 * GDB/MI Symbol Query::
16335 * GDB/MI Target Manipulation::
16336 * GDB/MI Thread Commands::
16337 * GDB/MI Tracepoint Commands::
16338 * GDB/MI Variable Objects::
16339 @end menu
16340
16341 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16342 @node GDB/MI Command Syntax
16343 @section @sc{gdb/mi} Command Syntax
16344
16345 @menu
16346 * GDB/MI Input Syntax::
16347 * GDB/MI Output Syntax::
16348 * GDB/MI Simple Examples::
16349 @end menu
16350
16351 @node GDB/MI Input Syntax
16352 @subsection @sc{gdb/mi} Input Syntax
16353
16354 @cindex input syntax for @sc{gdb/mi}
16355 @cindex @sc{gdb/mi}, input syntax
16356 @table @code
16357 @item @var{command} @expansion{}
16358 @code{@var{cli-command} | @var{mi-command}}
16359
16360 @item @var{cli-command} @expansion{}
16361 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16362 @var{cli-command} is any existing @value{GDBN} CLI command.
16363
16364 @item @var{mi-command} @expansion{}
16365 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16366 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16367
16368 @item @var{token} @expansion{}
16369 "any sequence of digits"
16370
16371 @item @var{option} @expansion{}
16372 @code{"-" @var{parameter} [ " " @var{parameter} ]}
16373
16374 @item @var{parameter} @expansion{}
16375 @code{@var{non-blank-sequence} | @var{c-string}}
16376
16377 @item @var{operation} @expansion{}
16378 @emph{any of the operations described in this chapter}
16379
16380 @item @var{non-blank-sequence} @expansion{}
16381 @emph{anything, provided it doesn't contain special characters such as
16382 "-", @var{nl}, """ and of course " "}
16383
16384 @item @var{c-string} @expansion{}
16385 @code{""" @var{seven-bit-iso-c-string-content} """}
16386
16387 @item @var{nl} @expansion{}
16388 @code{CR | CR-LF}
16389 @end table
16390
16391 @noindent
16392 Notes:
16393
16394 @itemize @bullet
16395 @item
16396 The CLI commands are still handled by the @sc{mi} interpreter; their
16397 output is described below.
16398
16399 @item
16400 The @code{@var{token}}, when present, is passed back when the command
16401 finishes.
16402
16403 @item
16404 Some @sc{mi} commands accept optional arguments as part of the parameter
16405 list. Each option is identified by a leading @samp{-} (dash) and may be
16406 followed by an optional argument parameter. Options occur first in the
16407 parameter list and can be delimited from normal parameters using
16408 @samp{--} (this is useful when some parameters begin with a dash).
16409 @end itemize
16410
16411 Pragmatics:
16412
16413 @itemize @bullet
16414 @item
16415 We want easy access to the existing CLI syntax (for debugging).
16416
16417 @item
16418 We want it to be easy to spot a @sc{mi} operation.
16419 @end itemize
16420
16421 @node GDB/MI Output Syntax
16422 @subsection @sc{gdb/mi} Output Syntax
16423
16424 @cindex output syntax of @sc{gdb/mi}
16425 @cindex @sc{gdb/mi}, output syntax
16426 The output from @sc{gdb/mi} consists of zero or more out-of-band records
16427 followed, optionally, by a single result record. This result record
16428 is for the most recent command. The sequence of output records is
16429 terminated by @samp{(@value{GDBP})}.
16430
16431 If an input command was prefixed with a @code{@var{token}} then the
16432 corresponding output for that command will also be prefixed by that same
16433 @var{token}.
16434
16435 @table @code
16436 @item @var{output} @expansion{}
16437 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
16438
16439 @item @var{result-record} @expansion{}
16440 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16441
16442 @item @var{out-of-band-record} @expansion{}
16443 @code{@var{async-record} | @var{stream-record}}
16444
16445 @item @var{async-record} @expansion{}
16446 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16447
16448 @item @var{exec-async-output} @expansion{}
16449 @code{[ @var{token} ] "*" @var{async-output}}
16450
16451 @item @var{status-async-output} @expansion{}
16452 @code{[ @var{token} ] "+" @var{async-output}}
16453
16454 @item @var{notify-async-output} @expansion{}
16455 @code{[ @var{token} ] "=" @var{async-output}}
16456
16457 @item @var{async-output} @expansion{}
16458 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
16459
16460 @item @var{result-class} @expansion{}
16461 @code{"done" | "running" | "connected" | "error" | "exit"}
16462
16463 @item @var{async-class} @expansion{}
16464 @code{"stopped" | @var{others}} (where @var{others} will be added
16465 depending on the needs---this is still in development).
16466
16467 @item @var{result} @expansion{}
16468 @code{ @var{variable} "=" @var{value}}
16469
16470 @item @var{variable} @expansion{}
16471 @code{ @var{string} }
16472
16473 @item @var{value} @expansion{}
16474 @code{ @var{const} | @var{tuple} | @var{list} }
16475
16476 @item @var{const} @expansion{}
16477 @code{@var{c-string}}
16478
16479 @item @var{tuple} @expansion{}
16480 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16481
16482 @item @var{list} @expansion{}
16483 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16484 @var{result} ( "," @var{result} )* "]" }
16485
16486 @item @var{stream-record} @expansion{}
16487 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16488
16489 @item @var{console-stream-output} @expansion{}
16490 @code{"~" @var{c-string}}
16491
16492 @item @var{target-stream-output} @expansion{}
16493 @code{"@@" @var{c-string}}
16494
16495 @item @var{log-stream-output} @expansion{}
16496 @code{"&" @var{c-string}}
16497
16498 @item @var{nl} @expansion{}
16499 @code{CR | CR-LF}
16500
16501 @item @var{token} @expansion{}
16502 @emph{any sequence of digits}.
16503 @end table
16504
16505 @noindent
16506 Notes:
16507
16508 @itemize @bullet
16509 @item
16510 All output sequences end in a single line containing a period.
16511
16512 @item
16513 The @code{@var{token}} is from the corresponding request. If an execution
16514 command is interrupted by the @samp{-exec-interrupt} command, the
16515 @var{token} associated with the @samp{*stopped} message is the one of the
16516 original execution command, not the one of the interrupt command.
16517
16518 @item
16519 @cindex status output in @sc{gdb/mi}
16520 @var{status-async-output} contains on-going status information about the
16521 progress of a slow operation. It can be discarded. All status output is
16522 prefixed by @samp{+}.
16523
16524 @item
16525 @cindex async output in @sc{gdb/mi}
16526 @var{exec-async-output} contains asynchronous state change on the target
16527 (stopped, started, disappeared). All async output is prefixed by
16528 @samp{*}.
16529
16530 @item
16531 @cindex notify output in @sc{gdb/mi}
16532 @var{notify-async-output} contains supplementary information that the
16533 client should handle (e.g., a new breakpoint information). All notify
16534 output is prefixed by @samp{=}.
16535
16536 @item
16537 @cindex console output in @sc{gdb/mi}
16538 @var{console-stream-output} is output that should be displayed as is in the
16539 console. It is the textual response to a CLI command. All the console
16540 output is prefixed by @samp{~}.
16541
16542 @item
16543 @cindex target output in @sc{gdb/mi}
16544 @var{target-stream-output} is the output produced by the target program.
16545 All the target output is prefixed by @samp{@@}.
16546
16547 @item
16548 @cindex log output in @sc{gdb/mi}
16549 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16550 instance messages that should be displayed as part of an error log. All
16551 the log output is prefixed by @samp{&}.
16552
16553 @item
16554 @cindex list output in @sc{gdb/mi}
16555 New @sc{gdb/mi} commands should only output @var{lists} containing
16556 @var{values}.
16557
16558
16559 @end itemize
16560
16561 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16562 details about the various output records.
16563
16564 @node GDB/MI Simple Examples
16565 @subsection Simple Examples of @sc{gdb/mi} Interaction
16566 @cindex @sc{gdb/mi}, simple examples
16567
16568 This subsection presents several simple examples of interaction using
16569 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16570 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16571 the output received from @sc{gdb/mi}.
16572
16573 @subsubheading Target Stop
16574 @c Ummm... There is no "-stop" command. This assumes async, no?
16575 Here's an example of stopping the inferior process:
16576
16577 @smallexample
16578 -> -stop
16579 <- (@value{GDBP})
16580 @end smallexample
16581
16582 @noindent
16583 and later:
16584
16585 @smallexample
16586 <- *stop,reason="stop",address="0x123",source="a.c:123"
16587 <- (@value{GDBP})
16588 @end smallexample
16589
16590 @subsubheading Simple CLI Command
16591
16592 Here's an example of a simple CLI command being passed through
16593 @sc{gdb/mi} and on to the CLI.
16594
16595 @smallexample
16596 -> print 1+2
16597 <- &"print 1+2\n"
16598 <- ~"$1 = 3\n"
16599 <- ^done
16600 <- (@value{GDBP})
16601 @end smallexample
16602
16603 @subsubheading Command With Side Effects
16604
16605 @smallexample
16606 -> -symbol-file xyz.exe
16607 <- *breakpoint,nr="3",address="0x123",source="a.c:123"
16608 <- (@value{GDBP})
16609 @end smallexample
16610
16611 @subsubheading A Bad Command
16612
16613 Here's what happens if you pass a non-existent command:
16614
16615 @smallexample
16616 -> -rubbish
16617 <- ^error,msg="Undefined MI command: rubbish"
16618 <- (@value{GDBP})
16619 @end smallexample
16620
16621 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16622 @node GDB/MI Compatibility with CLI
16623 @section @sc{gdb/mi} Compatibility with CLI
16624
16625 @cindex compatibility, @sc{gdb/mi} and CLI
16626 @cindex @sc{gdb/mi}, compatibility with CLI
16627 To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16628 accepts existing CLI commands. As specified by the syntax, such
16629 commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16630 respond.
16631
16632 This mechanism is provided as an aid to developers of @sc{gdb/mi}
16633 clients and not as a reliable interface into the CLI. Since the command
16634 is being interpreteted in an environment that assumes @sc{gdb/mi}
16635 behaviour, the exact output of such commands is likely to end up being
16636 an un-supported hybrid of @sc{gdb/mi} and CLI output.
16637
16638 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16639 @node GDB/MI Output Records
16640 @section @sc{gdb/mi} Output Records
16641
16642 @menu
16643 * GDB/MI Result Records::
16644 * GDB/MI Stream Records::
16645 * GDB/MI Out-of-band Records::
16646 @end menu
16647
16648 @node GDB/MI Result Records
16649 @subsection @sc{gdb/mi} Result Records
16650
16651 @cindex result records in @sc{gdb/mi}
16652 @cindex @sc{gdb/mi}, result records
16653 In addition to a number of out-of-band notifications, the response to a
16654 @sc{gdb/mi} command includes one of the following result indications:
16655
16656 @table @code
16657 @findex ^done
16658 @item "^done" [ "," @var{results} ]
16659 The synchronous operation was successful, @code{@var{results}} are the return
16660 values.
16661
16662 @item "^running"
16663 @findex ^running
16664 @c Is this one correct? Should it be an out-of-band notification?
16665 The asynchronous operation was successfully started. The target is
16666 running.
16667
16668 @item "^error" "," @var{c-string}
16669 @findex ^error
16670 The operation failed. The @code{@var{c-string}} contains the corresponding
16671 error message.
16672 @end table
16673
16674 @node GDB/MI Stream Records
16675 @subsection @sc{gdb/mi} Stream Records
16676
16677 @cindex @sc{gdb/mi}, stream records
16678 @cindex stream records in @sc{gdb/mi}
16679 @value{GDBN} internally maintains a number of output streams: the console, the
16680 target, and the log. The output intended for each of these streams is
16681 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16682
16683 Each stream record begins with a unique @dfn{prefix character} which
16684 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16685 Syntax}). In addition to the prefix, each stream record contains a
16686 @code{@var{string-output}}. This is either raw text (with an implicit new
16687 line) or a quoted C string (which does not contain an implicit newline).
16688
16689 @table @code
16690 @item "~" @var{string-output}
16691 The console output stream contains text that should be displayed in the
16692 CLI console window. It contains the textual responses to CLI commands.
16693
16694 @item "@@" @var{string-output}
16695 The target output stream contains any textual output from the running
16696 target.
16697
16698 @item "&" @var{string-output}
16699 The log stream contains debugging messages being produced by @value{GDBN}'s
16700 internals.
16701 @end table
16702
16703 @node GDB/MI Out-of-band Records
16704 @subsection @sc{gdb/mi} Out-of-band Records
16705
16706 @cindex out-of-band records in @sc{gdb/mi}
16707 @cindex @sc{gdb/mi}, out-of-band records
16708 @dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
16709 additional changes that have occurred. Those changes can either be a
16710 consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
16711 target activity (e.g., target stopped).
16712
16713 The following is a preliminary list of possible out-of-band records.
16714
16715 @table @code
16716 @item "*" "stop"
16717 @end table
16718
16719
16720 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16721 @node GDB/MI Command Description Format
16722 @section @sc{gdb/mi} Command Description Format
16723
16724 The remaining sections describe blocks of commands. Each block of
16725 commands is laid out in a fashion similar to this section.
16726
16727 Note the the line breaks shown in the examples are here only for
16728 readability. They don't appear in the real output.
16729 Also note that the commands with a non-available example (N.A.@:) are
16730 not yet implemented.
16731
16732 @subheading Motivation
16733
16734 The motivation for this collection of commands.
16735
16736 @subheading Introduction
16737
16738 A brief introduction to this collection of commands as a whole.
16739
16740 @subheading Commands
16741
16742 For each command in the block, the following is described:
16743
16744 @subsubheading Synopsis
16745
16746 @smallexample
16747 -command @var{args}@dots{}
16748 @end smallexample
16749
16750 @subsubheading @value{GDBN} Command
16751
16752 The corresponding @value{GDBN} CLI command.
16753
16754 @subsubheading Result
16755
16756 @subsubheading Out-of-band
16757
16758 @subsubheading Notes
16759
16760 @subsubheading Example
16761
16762
16763 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16764 @node GDB/MI Breakpoint Table Commands
16765 @section @sc{gdb/mi} Breakpoint table commands
16766
16767 @cindex breakpoint commands for @sc{gdb/mi}
16768 @cindex @sc{gdb/mi}, breakpoint commands
16769 This section documents @sc{gdb/mi} commands for manipulating
16770 breakpoints.
16771
16772 @subheading The @code{-break-after} Command
16773 @findex -break-after
16774
16775 @subsubheading Synopsis
16776
16777 @smallexample
16778 -break-after @var{number} @var{count}
16779 @end smallexample
16780
16781 The breakpoint number @var{number} is not in effect until it has been
16782 hit @var{count} times. To see how this is reflected in the output of
16783 the @samp{-break-list} command, see the description of the
16784 @samp{-break-list} command below.
16785
16786 @subsubheading @value{GDBN} Command
16787
16788 The corresponding @value{GDBN} command is @samp{ignore}.
16789
16790 @subsubheading Example
16791
16792 @smallexample
16793 (@value{GDBP})
16794 -break-insert main
16795 ^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
16796 (@value{GDBP})
16797 -break-after 1 3
16798 ~
16799 ^done
16800 (@value{GDBP})
16801 -break-list
16802 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16803 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16804 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16805 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16806 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16807 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16808 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
16809 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
16810 addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
16811 ignore="3"@}]@}
16812 (@value{GDBP})
16813 @end smallexample
16814
16815 @ignore
16816 @subheading The @code{-break-catch} Command
16817 @findex -break-catch
16818
16819 @subheading The @code{-break-commands} Command
16820 @findex -break-commands
16821 @end ignore
16822
16823
16824 @subheading The @code{-break-condition} Command
16825 @findex -break-condition
16826
16827 @subsubheading Synopsis
16828
16829 @smallexample
16830 -break-condition @var{number} @var{expr}
16831 @end smallexample
16832
16833 Breakpoint @var{number} will stop the program only if the condition in
16834 @var{expr} is true. The condition becomes part of the
16835 @samp{-break-list} output (see the description of the @samp{-break-list}
16836 command below).
16837
16838 @subsubheading @value{GDBN} Command
16839
16840 The corresponding @value{GDBN} command is @samp{condition}.
16841
16842 @subsubheading Example
16843
16844 @smallexample
16845 (@value{GDBP})
16846 -break-condition 1 1
16847 ^done
16848 (@value{GDBP})
16849 -break-list
16850 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16851 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16852 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16853 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16854 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16855 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16856 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
16857 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
16858 addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
16859 times="0",ignore="3"@}]@}
16860 (@value{GDBP})
16861 @end smallexample
16862
16863 @subheading The @code{-break-delete} Command
16864 @findex -break-delete
16865
16866 @subsubheading Synopsis
16867
16868 @smallexample
16869 -break-delete ( @var{breakpoint} )+
16870 @end smallexample
16871
16872 Delete the breakpoint(s) whose number(s) are specified in the argument
16873 list. This is obviously reflected in the breakpoint list.
16874
16875 @subsubheading @value{GDBN} command
16876
16877 The corresponding @value{GDBN} command is @samp{delete}.
16878
16879 @subsubheading Example
16880
16881 @smallexample
16882 (@value{GDBP})
16883 -break-delete 1
16884 ^done
16885 (@value{GDBP})
16886 -break-list
16887 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
16888 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16889 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16890 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16891 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16892 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16893 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
16894 body=[]@}
16895 (@value{GDBP})
16896 @end smallexample
16897
16898 @subheading The @code{-break-disable} Command
16899 @findex -break-disable
16900
16901 @subsubheading Synopsis
16902
16903 @smallexample
16904 -break-disable ( @var{breakpoint} )+
16905 @end smallexample
16906
16907 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
16908 break list is now set to @samp{n} for the named @var{breakpoint}(s).
16909
16910 @subsubheading @value{GDBN} Command
16911
16912 The corresponding @value{GDBN} command is @samp{disable}.
16913
16914 @subsubheading Example
16915
16916 @smallexample
16917 (@value{GDBP})
16918 -break-disable 2
16919 ^done
16920 (@value{GDBP})
16921 -break-list
16922 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16923 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16924 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16925 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16926 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16927 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16928 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
16929 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
16930 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
16931 (@value{GDBP})
16932 @end smallexample
16933
16934 @subheading The @code{-break-enable} Command
16935 @findex -break-enable
16936
16937 @subsubheading Synopsis
16938
16939 @smallexample
16940 -break-enable ( @var{breakpoint} )+
16941 @end smallexample
16942
16943 Enable (previously disabled) @var{breakpoint}(s).
16944
16945 @subsubheading @value{GDBN} Command
16946
16947 The corresponding @value{GDBN} command is @samp{enable}.
16948
16949 @subsubheading Example
16950
16951 @smallexample
16952 (@value{GDBP})
16953 -break-enable 2
16954 ^done
16955 (@value{GDBP})
16956 -break-list
16957 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16958 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16959 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16960 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16961 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16962 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16963 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
16964 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
16965 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
16966 (@value{GDBP})
16967 @end smallexample
16968
16969 @subheading The @code{-break-info} Command
16970 @findex -break-info
16971
16972 @subsubheading Synopsis
16973
16974 @smallexample
16975 -break-info @var{breakpoint}
16976 @end smallexample
16977
16978 @c REDUNDANT???
16979 Get information about a single breakpoint.
16980
16981 @subsubheading @value{GDBN} command
16982
16983 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
16984
16985 @subsubheading Example
16986 N.A.
16987
16988 @subheading The @code{-break-insert} Command
16989 @findex -break-insert
16990
16991 @subsubheading Synopsis
16992
16993 @smallexample
16994 -break-insert [ -t ] [ -h ] [ -r ]
16995 [ -c @var{condition} ] [ -i @var{ignore-count} ]
16996 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
16997 @end smallexample
16998
16999 @noindent
17000 If specified, @var{line}, can be one of:
17001
17002 @itemize @bullet
17003 @item function
17004 @c @item +offset
17005 @c @item -offset
17006 @c @item linenum
17007 @item filename:linenum
17008 @item filename:function
17009 @item *address
17010 @end itemize
17011
17012 The possible optional parameters of this command are:
17013
17014 @table @samp
17015 @item -t
17016 Insert a tempoary breakpoint.
17017 @item -h
17018 Insert a hardware breakpoint.
17019 @item -c @var{condition}
17020 Make the breakpoint conditional on @var{condition}.
17021 @item -i @var{ignore-count}
17022 Initialize the @var{ignore-count}.
17023 @item -r
17024 Insert a regular breakpoint in all the functions whose names match the
17025 given regular expression. Other flags are not applicable to regular
17026 expresson.
17027 @end table
17028
17029 @subsubheading Result
17030
17031 The result is in the form:
17032
17033 @smallexample
17034 ^done,bkptno="@var{number}",func="@var{funcname}",
17035 file="@var{filename}",line="@var{lineno}"
17036 @end smallexample
17037
17038 @noindent
17039 where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17040 is the name of the function where the breakpoint was inserted,
17041 @var{filename} is the name of the source file which contains this
17042 function, and @var{lineno} is the source line number within that file.
17043
17044 Note: this format is open to change.
17045 @c An out-of-band breakpoint instead of part of the result?
17046
17047 @subsubheading @value{GDBN} Command
17048
17049 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17050 @samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17051
17052 @subsubheading Example
17053
17054 @smallexample
17055 (@value{GDBP})
17056 -break-insert main
17057 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17058 (@value{GDBP})
17059 -break-insert -t foo
17060 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17061 (@value{GDBP})
17062 -break-list
17063 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17064 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17065 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17066 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17067 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17068 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17069 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17070 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17071 addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17072 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17073 addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17074 (@value{GDBP})
17075 -break-insert -r foo.*
17076 ~int foo(int, int);
17077 ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17078 (@value{GDBP})
17079 @end smallexample
17080
17081 @subheading The @code{-break-list} Command
17082 @findex -break-list
17083
17084 @subsubheading Synopsis
17085
17086 @smallexample
17087 -break-list
17088 @end smallexample
17089
17090 Displays the list of inserted breakpoints, showing the following fields:
17091
17092 @table @samp
17093 @item Number
17094 number of the breakpoint
17095 @item Type
17096 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17097 @item Disposition
17098 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17099 or @samp{nokeep}
17100 @item Enabled
17101 is the breakpoint enabled or no: @samp{y} or @samp{n}
17102 @item Address
17103 memory location at which the breakpoint is set
17104 @item What
17105 logical location of the breakpoint, expressed by function name, file
17106 name, line number
17107 @item Times
17108 number of times the breakpoint has been hit
17109 @end table
17110
17111 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17112 @code{body} field is an empty list.
17113
17114 @subsubheading @value{GDBN} Command
17115
17116 The corresponding @value{GDBN} command is @samp{info break}.
17117
17118 @subsubheading Example
17119
17120 @smallexample
17121 (@value{GDBP})
17122 -break-list
17123 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17124 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17125 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17126 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17127 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17128 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17129 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17130 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17131 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17132 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17133 addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17134 (@value{GDBP})
17135 @end smallexample
17136
17137 Here's an example of the result when there are no breakpoints:
17138
17139 @smallexample
17140 (@value{GDBP})
17141 -break-list
17142 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17143 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17144 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17145 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17146 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17147 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17148 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17149 body=[]@}
17150 (@value{GDBP})
17151 @end smallexample
17152
17153 @subheading The @code{-break-watch} Command
17154 @findex -break-watch
17155
17156 @subsubheading Synopsis
17157
17158 @smallexample
17159 -break-watch [ -a | -r ]
17160 @end smallexample
17161
17162 Create a watchpoint. With the @samp{-a} option it will create an
17163 @dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17164 read from or on a write to the memory location. With the @samp{-r}
17165 option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17166 trigger only when the memory location is accessed for reading. Without
17167 either of the options, the watchpoint created is a regular watchpoint,
17168 i.e. it will trigger when the memory location is accessed for writing.
17169 @xref{Set Watchpoints, , Setting watchpoints}.
17170
17171 Note that @samp{-break-list} will report a single list of watchpoints and
17172 breakpoints inserted.
17173
17174 @subsubheading @value{GDBN} Command
17175
17176 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17177 @samp{rwatch}.
17178
17179 @subsubheading Example
17180
17181 Setting a watchpoint on a variable in the @code{main} function:
17182
17183 @smallexample
17184 (@value{GDBP})
17185 -break-watch x
17186 ^done,wpt=@{number="2",exp="x"@}
17187 (@value{GDBP})
17188 -exec-continue
17189 ^running
17190 ^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17191 value=@{old="-268439212",new="55"@},
17192 frame=@{func="main",args=[],file="recursive2.c",line="5"@}
17193 (@value{GDBP})
17194 @end smallexample
17195
17196 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17197 the program execution twice: first for the variable changing value, then
17198 for the watchpoint going out of scope.
17199
17200 @smallexample
17201 (@value{GDBP})
17202 -break-watch C
17203 ^done,wpt=@{number="5",exp="C"@}
17204 (@value{GDBP})
17205 -exec-continue
17206 ^running
17207 ^done,reason="watchpoint-trigger",
17208 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17209 frame=@{func="callee4",args=[],
17210 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
17211 (@value{GDBP})
17212 -exec-continue
17213 ^running
17214 ^done,reason="watchpoint-scope",wpnum="5",
17215 frame=@{func="callee3",args=[@{name="strarg",
17216 value="0x11940 \"A string argument.\""@}],
17217 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17218 (@value{GDBP})
17219 @end smallexample
17220
17221 Listing breakpoints and watchpoints, at different points in the program
17222 execution. Note that once the watchpoint goes out of scope, it is
17223 deleted.
17224
17225 @smallexample
17226 (@value{GDBP})
17227 -break-watch C
17228 ^done,wpt=@{number="2",exp="C"@}
17229 (@value{GDBP})
17230 -break-list
17231 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17232 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17233 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17234 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17235 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17236 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17237 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17238 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17239 addr="0x00010734",func="callee4",
17240 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17241 bkpt=@{number="2",type="watchpoint",disp="keep",
17242 enabled="y",addr="",what="C",times="0"@}]@}
17243 (@value{GDBP})
17244 -exec-continue
17245 ^running
17246 ^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17247 value=@{old="-276895068",new="3"@},
17248 frame=@{func="callee4",args=[],
17249 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
17250 (@value{GDBP})
17251 -break-list
17252 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17253 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17254 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17255 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17256 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17257 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17258 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17259 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17260 addr="0x00010734",func="callee4",
17261 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17262 bkpt=@{number="2",type="watchpoint",disp="keep",
17263 enabled="y",addr="",what="C",times="-5"@}]@}
17264 (@value{GDBP})
17265 -exec-continue
17266 ^running
17267 ^done,reason="watchpoint-scope",wpnum="2",
17268 frame=@{func="callee3",args=[@{name="strarg",
17269 value="0x11940 \"A string argument.\""@}],
17270 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17271 (@value{GDBP})
17272 -break-list
17273 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17274 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17275 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17276 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17277 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17278 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17279 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
17280 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17281 addr="0x00010734",func="callee4",
17282 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17283 (@value{GDBP})
17284 @end smallexample
17285
17286 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17287 @node GDB/MI Data Manipulation
17288 @section @sc{gdb/mi} Data Manipulation
17289
17290 @cindex data manipulation, in @sc{gdb/mi}
17291 @cindex @sc{gdb/mi}, data manipulation
17292 This section describes the @sc{gdb/mi} commands that manipulate data:
17293 examine memory and registers, evaluate expressions, etc.
17294
17295 @c REMOVED FROM THE INTERFACE.
17296 @c @subheading -data-assign
17297 @c Change the value of a program variable. Plenty of side effects.
17298 @c @subsubheading GDB command
17299 @c set variable
17300 @c @subsubheading Example
17301 @c N.A.
17302
17303 @subheading The @code{-data-disassemble} Command
17304 @findex -data-disassemble
17305
17306 @subsubheading Synopsis
17307
17308 @smallexample
17309 -data-disassemble
17310 [ -s @var{start-addr} -e @var{end-addr} ]
17311 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17312 -- @var{mode}
17313 @end smallexample
17314
17315 @noindent
17316 Where:
17317
17318 @table @samp
17319 @item @var{start-addr}
17320 is the beginning address (or @code{$pc})
17321 @item @var{end-addr}
17322 is the end address
17323 @item @var{filename}
17324 is the name of the file to disassemble
17325 @item @var{linenum}
17326 is the line number to disassemble around
17327 @item @var{lines}
17328 is the the number of disassembly lines to be produced. If it is -1,
17329 the whole function will be disassembled, in case no @var{end-addr} is
17330 specified. If @var{end-addr} is specified as a non-zero value, and
17331 @var{lines} is lower than the number of disassembly lines between
17332 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
17333 displayed; if @var{lines} is higher than the number of lines between
17334 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17335 are displayed.
17336 @item @var{mode}
17337 is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17338 disassembly).
17339 @end table
17340
17341 @subsubheading Result
17342
17343 The output for each instruction is composed of four fields:
17344
17345 @itemize @bullet
17346 @item Address
17347 @item Func-name
17348 @item Offset
17349 @item Instruction
17350 @end itemize
17351
17352 Note that whatever included in the instruction field, is not manipulated
17353 directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17354
17355 @subsubheading @value{GDBN} Command
17356
17357 There's no direct mapping from this command to the CLI.
17358
17359 @subsubheading Example
17360
17361 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17362
17363 @smallexample
17364 (@value{GDBP})
17365 -data-disassemble -s $pc -e "$pc + 20" -- 0
17366 ^done,
17367 asm_insns=[
17368 @{address="0x000107c0",func-name="main",offset="4",
17369 inst="mov 2, %o0"@},
17370 @{address="0x000107c4",func-name="main",offset="8",
17371 inst="sethi %hi(0x11800), %o2"@},
17372 @{address="0x000107c8",func-name="main",offset="12",
17373 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17374 @{address="0x000107cc",func-name="main",offset="16",
17375 inst="sethi %hi(0x11800), %o2"@},
17376 @{address="0x000107d0",func-name="main",offset="20",
17377 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17378 (@value{GDBP})
17379 @end smallexample
17380
17381 Disassemble the whole @code{main} function. Line 32 is part of
17382 @code{main}.
17383
17384 @smallexample
17385 -data-disassemble -f basics.c -l 32 -- 0
17386 ^done,asm_insns=[
17387 @{address="0x000107bc",func-name="main",offset="0",
17388 inst="save %sp, -112, %sp"@},
17389 @{address="0x000107c0",func-name="main",offset="4",
17390 inst="mov 2, %o0"@},
17391 @{address="0x000107c4",func-name="main",offset="8",
17392 inst="sethi %hi(0x11800), %o2"@},
17393 [@dots{}]
17394 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17395 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17396 (@value{GDBP})
17397 @end smallexample
17398
17399 Disassemble 3 instructions from the start of @code{main}:
17400
17401 @smallexample
17402 (@value{GDBP})
17403 -data-disassemble -f basics.c -l 32 -n 3 -- 0
17404 ^done,asm_insns=[
17405 @{address="0x000107bc",func-name="main",offset="0",
17406 inst="save %sp, -112, %sp"@},
17407 @{address="0x000107c0",func-name="main",offset="4",
17408 inst="mov 2, %o0"@},
17409 @{address="0x000107c4",func-name="main",offset="8",
17410 inst="sethi %hi(0x11800), %o2"@}]
17411 (@value{GDBP})
17412 @end smallexample
17413
17414 Disassemble 3 instructions from the start of @code{main} in mixed mode:
17415
17416 @smallexample
17417 (@value{GDBP})
17418 -data-disassemble -f basics.c -l 32 -n 3 -- 1
17419 ^done,asm_insns=[
17420 src_and_asm_line=@{line="31",
17421 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17422 testsuite/gdb.mi/basics.c",line_asm_insn=[
17423 @{address="0x000107bc",func-name="main",offset="0",
17424 inst="save %sp, -112, %sp"@}]@},
17425 src_and_asm_line=@{line="32",
17426 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17427 testsuite/gdb.mi/basics.c",line_asm_insn=[
17428 @{address="0x000107c0",func-name="main",offset="4",
17429 inst="mov 2, %o0"@},
17430 @{address="0x000107c4",func-name="main",offset="8",
17431 inst="sethi %hi(0x11800), %o2"@}]@}]
17432 (@value{GDBP})
17433 @end smallexample
17434
17435
17436 @subheading The @code{-data-evaluate-expression} Command
17437 @findex -data-evaluate-expression
17438
17439 @subsubheading Synopsis
17440
17441 @smallexample
17442 -data-evaluate-expression @var{expr}
17443 @end smallexample
17444
17445 Evaluate @var{expr} as an expression. The expression could contain an
17446 inferior function call. The function call will execute synchronously.
17447 If the expression contains spaces, it must be enclosed in double quotes.
17448
17449 @subsubheading @value{GDBN} Command
17450
17451 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17452 @samp{call}. In @code{gdbtk} only, there's a corresponding
17453 @samp{gdb_eval} command.
17454
17455 @subsubheading Example
17456
17457 In the following example, the numbers that precede the commands are the
17458 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17459 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17460 output.
17461
17462 @smallexample
17463 211-data-evaluate-expression A
17464 211^done,value="1"
17465 (@value{GDBP})
17466 311-data-evaluate-expression &A
17467 311^done,value="0xefffeb7c"
17468 (@value{GDBP})
17469 411-data-evaluate-expression A+3
17470 411^done,value="4"
17471 (@value{GDBP})
17472 511-data-evaluate-expression "A + 3"
17473 511^done,value="4"
17474 (@value{GDBP})
17475 @end smallexample
17476
17477
17478 @subheading The @code{-data-list-changed-registers} Command
17479 @findex -data-list-changed-registers
17480
17481 @subsubheading Synopsis
17482
17483 @smallexample
17484 -data-list-changed-registers
17485 @end smallexample
17486
17487 Display a list of the registers that have changed.
17488
17489 @subsubheading @value{GDBN} Command
17490
17491 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17492 has the corresponding command @samp{gdb_changed_register_list}.
17493
17494 @subsubheading Example
17495
17496 On a PPC MBX board:
17497
17498 @smallexample
17499 (@value{GDBP})
17500 -exec-continue
17501 ^running
17502
17503 (@value{GDBP})
17504 *stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
17505 args=[],file="try.c",line="5"@}
17506 (@value{GDBP})
17507 -data-list-changed-registers
17508 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17509 "10","11","13","14","15","16","17","18","19","20","21","22","23",
17510 "24","25","26","27","28","30","31","64","65","66","67","69"]
17511 (@value{GDBP})
17512 @end smallexample
17513
17514
17515 @subheading The @code{-data-list-register-names} Command
17516 @findex -data-list-register-names
17517
17518 @subsubheading Synopsis
17519
17520 @smallexample
17521 -data-list-register-names [ ( @var{regno} )+ ]
17522 @end smallexample
17523
17524 Show a list of register names for the current target. If no arguments
17525 are given, it shows a list of the names of all the registers. If
17526 integer numbers are given as arguments, it will print a list of the
17527 names of the registers corresponding to the arguments. To ensure
17528 consistency between a register name and its number, the output list may
17529 include empty register names.
17530
17531 @subsubheading @value{GDBN} Command
17532
17533 @value{GDBN} does not have a command which corresponds to
17534 @samp{-data-list-register-names}. In @code{gdbtk} there is a
17535 corresponding command @samp{gdb_regnames}.
17536
17537 @subsubheading Example
17538
17539 For the PPC MBX board:
17540 @smallexample
17541 (@value{GDBP})
17542 -data-list-register-names
17543 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17544 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17545 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17546 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17547 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17548 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17549 "", "pc","ps","cr","lr","ctr","xer"]
17550 (@value{GDBP})
17551 -data-list-register-names 1 2 3
17552 ^done,register-names=["r1","r2","r3"]
17553 (@value{GDBP})
17554 @end smallexample
17555
17556 @subheading The @code{-data-list-register-values} Command
17557 @findex -data-list-register-values
17558
17559 @subsubheading Synopsis
17560
17561 @smallexample
17562 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17563 @end smallexample
17564
17565 Display the registers' contents. @var{fmt} is the format according to
17566 which the registers' contents are to be returned, followed by an optional
17567 list of numbers specifying the registers to display. A missing list of
17568 numbers indicates that the contents of all the registers must be returned.
17569
17570 Allowed formats for @var{fmt} are:
17571
17572 @table @code
17573 @item x
17574 Hexadecimal
17575 @item o
17576 Octal
17577 @item t
17578 Binary
17579 @item d
17580 Decimal
17581 @item r
17582 Raw
17583 @item N
17584 Natural
17585 @end table
17586
17587 @subsubheading @value{GDBN} Command
17588
17589 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17590 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17591
17592 @subsubheading Example
17593
17594 For a PPC MBX board (note: line breaks are for readability only, they
17595 don't appear in the actual output):
17596
17597 @smallexample
17598 (@value{GDBP})
17599 -data-list-register-values r 64 65
17600 ^done,register-values=[@{number="64",value="0xfe00a300"@},
17601 @{number="65",value="0x00029002"@}]
17602 (@value{GDBP})
17603 -data-list-register-values x
17604 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
17605 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17606 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
17607 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17608 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17609 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17610 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
17611 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17612 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17613 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17614 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17615 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17616 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17617 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17618 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17619 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17620 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
17621 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
17622 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
17623 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
17624 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
17625 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
17626 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
17627 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
17628 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
17629 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
17630 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
17631 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
17632 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
17633 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
17634 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
17635 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
17636 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17637 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17638 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17639 @{number="69",value="0x20002b03"@}]
17640 (@value{GDBP})
17641 @end smallexample
17642
17643
17644 @subheading The @code{-data-read-memory} Command
17645 @findex -data-read-memory
17646
17647 @subsubheading Synopsis
17648
17649 @smallexample
17650 -data-read-memory [ -o @var{byte-offset} ]
17651 @var{address} @var{word-format} @var{word-size}
17652 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17653 @end smallexample
17654
17655 @noindent
17656 where:
17657
17658 @table @samp
17659 @item @var{address}
17660 An expression specifying the address of the first memory word to be
17661 read. Complex expressions containing embedded white space should be
17662 quoted using the C convention.
17663
17664 @item @var{word-format}
17665 The format to be used to print the memory words. The notation is the
17666 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17667 ,Output formats}).
17668
17669 @item @var{word-size}
17670 The size of each memory word in bytes.
17671
17672 @item @var{nr-rows}
17673 The number of rows in the output table.
17674
17675 @item @var{nr-cols}
17676 The number of columns in the output table.
17677
17678 @item @var{aschar}
17679 If present, indicates that each row should include an @sc{ascii} dump. The
17680 value of @var{aschar} is used as a padding character when a byte is not a
17681 member of the printable @sc{ascii} character set (printable @sc{ascii}
17682 characters are those whose code is between 32 and 126, inclusively).
17683
17684 @item @var{byte-offset}
17685 An offset to add to the @var{address} before fetching memory.
17686 @end table
17687
17688 This command displays memory contents as a table of @var{nr-rows} by
17689 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
17690 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
17691 (returned as @samp{total-bytes}). Should less than the requested number
17692 of bytes be returned by the target, the missing words are identified
17693 using @samp{N/A}. The number of bytes read from the target is returned
17694 in @samp{nr-bytes} and the starting address used to read memory in
17695 @samp{addr}.
17696
17697 The address of the next/previous row or page is available in
17698 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
17699 @samp{prev-page}.
17700
17701 @subsubheading @value{GDBN} Command
17702
17703 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
17704 @samp{gdb_get_mem} memory read command.
17705
17706 @subsubheading Example
17707
17708 Read six bytes of memory starting at @code{bytes+6} but then offset by
17709 @code{-6} bytes. Format as three rows of two columns. One byte per
17710 word. Display each word in hex.
17711
17712 @smallexample
17713 (@value{GDBP})
17714 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
17715 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
17716 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
17717 prev-page="0x0000138a",memory=[
17718 @{addr="0x00001390",data=["0x00","0x01"]@},
17719 @{addr="0x00001392",data=["0x02","0x03"]@},
17720 @{addr="0x00001394",data=["0x04","0x05"]@}]
17721 (@value{GDBP})
17722 @end smallexample
17723
17724 Read two bytes of memory starting at address @code{shorts + 64} and
17725 display as a single word formatted in decimal.
17726
17727 @smallexample
17728 (@value{GDBP})
17729 5-data-read-memory shorts+64 d 2 1 1
17730 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
17731 next-row="0x00001512",prev-row="0x0000150e",
17732 next-page="0x00001512",prev-page="0x0000150e",memory=[
17733 @{addr="0x00001510",data=["128"]@}]
17734 (@value{GDBP})
17735 @end smallexample
17736
17737 Read thirty two bytes of memory starting at @code{bytes+16} and format
17738 as eight rows of four columns. Include a string encoding with @samp{x}
17739 used as the non-printable character.
17740
17741 @smallexample
17742 (@value{GDBP})
17743 4-data-read-memory bytes+16 x 1 8 4 x
17744 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
17745 next-row="0x000013c0",prev-row="0x0000139c",
17746 next-page="0x000013c0",prev-page="0x00001380",memory=[
17747 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
17748 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
17749 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
17750 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
17751 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
17752 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
17753 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
17754 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
17755 (@value{GDBP})
17756 @end smallexample
17757
17758 @subheading The @code{-display-delete} Command
17759 @findex -display-delete
17760
17761 @subsubheading Synopsis
17762
17763 @smallexample
17764 -display-delete @var{number}
17765 @end smallexample
17766
17767 Delete the display @var{number}.
17768
17769 @subsubheading @value{GDBN} Command
17770
17771 The corresponding @value{GDBN} command is @samp{delete display}.
17772
17773 @subsubheading Example
17774 N.A.
17775
17776
17777 @subheading The @code{-display-disable} Command
17778 @findex -display-disable
17779
17780 @subsubheading Synopsis
17781
17782 @smallexample
17783 -display-disable @var{number}
17784 @end smallexample
17785
17786 Disable display @var{number}.
17787
17788 @subsubheading @value{GDBN} Command
17789
17790 The corresponding @value{GDBN} command is @samp{disable display}.
17791
17792 @subsubheading Example
17793 N.A.
17794
17795
17796 @subheading The @code{-display-enable} Command
17797 @findex -display-enable
17798
17799 @subsubheading Synopsis
17800
17801 @smallexample
17802 -display-enable @var{number}
17803 @end smallexample
17804
17805 Enable display @var{number}.
17806
17807 @subsubheading @value{GDBN} Command
17808
17809 The corresponding @value{GDBN} command is @samp{enable display}.
17810
17811 @subsubheading Example
17812 N.A.
17813
17814
17815 @subheading The @code{-display-insert} Command
17816 @findex -display-insert
17817
17818 @subsubheading Synopsis
17819
17820 @smallexample
17821 -display-insert @var{expression}
17822 @end smallexample
17823
17824 Display @var{expression} every time the program stops.
17825
17826 @subsubheading @value{GDBN} Command
17827
17828 The corresponding @value{GDBN} command is @samp{display}.
17829
17830 @subsubheading Example
17831 N.A.
17832
17833
17834 @subheading The @code{-display-list} Command
17835 @findex -display-list
17836
17837 @subsubheading Synopsis
17838
17839 @smallexample
17840 -display-list
17841 @end smallexample
17842
17843 List the displays. Do not show the current values.
17844
17845 @subsubheading @value{GDBN} Command
17846
17847 The corresponding @value{GDBN} command is @samp{info display}.
17848
17849 @subsubheading Example
17850 N.A.
17851
17852
17853 @subheading The @code{-environment-cd} Command
17854 @findex -environment-cd
17855
17856 @subsubheading Synopsis
17857
17858 @smallexample
17859 -environment-cd @var{pathdir}
17860 @end smallexample
17861
17862 Set @value{GDBN}'s working directory.
17863
17864 @subsubheading @value{GDBN} Command
17865
17866 The corresponding @value{GDBN} command is @samp{cd}.
17867
17868 @subsubheading Example
17869
17870 @smallexample
17871 (@value{GDBP})
17872 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
17873 ^done
17874 (@value{GDBP})
17875 @end smallexample
17876
17877
17878 @subheading The @code{-environment-directory} Command
17879 @findex -environment-directory
17880
17881 @subsubheading Synopsis
17882
17883 @smallexample
17884 -environment-directory [ -r ] [ @var{pathdir} ]+
17885 @end smallexample
17886
17887 Add directories @var{pathdir} to beginning of search path for source files.
17888 If the @samp{-r} option is used, the search path is reset to the default
17889 search path. If directories @var{pathdir} are supplied in addition to the
17890 @samp{-r} option, the search path is first reset and then addition
17891 occurs as normal.
17892 Multiple directories may be specified, separated by blanks. Specifying
17893 multiple directories in a single command
17894 results in the directories added to the beginning of the
17895 search path in the same order they were presented in the command.
17896 If blanks are needed as
17897 part of a directory name, double-quotes should be used around
17898 the name. In the command output, the path will show up separated
17899 by the system directory-separator character. The directory-seperator
17900 character must not be used
17901 in any directory name.
17902 If no directories are specified, the current search path is displayed.
17903
17904 @subsubheading @value{GDBN} Command
17905
17906 The corresponding @value{GDBN} command is @samp{dir}.
17907
17908 @subsubheading Example
17909
17910 @smallexample
17911 (@value{GDBP})
17912 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
17913 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
17914 (@value{GDBP})
17915 -environment-directory ""
17916 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
17917 (@value{GDBP})
17918 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
17919 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
17920 (@value{GDBP})
17921 -environment-directory -r
17922 ^done,source-path="$cdir:$cwd"
17923 (@value{GDBP})
17924 @end smallexample
17925
17926
17927 @subheading The @code{-environment-path} Command
17928 @findex -environment-path
17929
17930 @subsubheading Synopsis
17931
17932 @smallexample
17933 -environment-path [ -r ] [ @var{pathdir} ]+
17934 @end smallexample
17935
17936 Add directories @var{pathdir} to beginning of search path for object files.
17937 If the @samp{-r} option is used, the search path is reset to the original
17938 search path that existed at gdb start-up. If directories @var{pathdir} are
17939 supplied in addition to the
17940 @samp{-r} option, the search path is first reset and then addition
17941 occurs as normal.
17942 Multiple directories may be specified, separated by blanks. Specifying
17943 multiple directories in a single command
17944 results in the directories added to the beginning of the
17945 search path in the same order they were presented in the command.
17946 If blanks are needed as
17947 part of a directory name, double-quotes should be used around
17948 the name. In the command output, the path will show up separated
17949 by the system directory-separator character. The directory-seperator
17950 character must not be used
17951 in any directory name.
17952 If no directories are specified, the current path is displayed.
17953
17954
17955 @subsubheading @value{GDBN} Command
17956
17957 The corresponding @value{GDBN} command is @samp{path}.
17958
17959 @subsubheading Example
17960
17961 @smallexample
17962 (@value{GDBP})
17963 -environment-path
17964 ^done,path="/usr/bin"
17965 (@value{GDBP})
17966 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
17967 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
17968 (@value{GDBP})
17969 -environment-path -r /usr/local/bin
17970 ^done,path="/usr/local/bin:/usr/bin"
17971 (@value{GDBP})
17972 @end smallexample
17973
17974
17975 @subheading The @code{-environment-pwd} Command
17976 @findex -environment-pwd
17977
17978 @subsubheading Synopsis
17979
17980 @smallexample
17981 -environment-pwd
17982 @end smallexample
17983
17984 Show the current working directory.
17985
17986 @subsubheading @value{GDBN} command
17987
17988 The corresponding @value{GDBN} command is @samp{pwd}.
17989
17990 @subsubheading Example
17991
17992 @smallexample
17993 (@value{GDBP})
17994 -environment-pwd
17995 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
17996 (@value{GDBP})
17997 @end smallexample
17998
17999 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18000 @node GDB/MI Program Control
18001 @section @sc{gdb/mi} Program control
18002
18003 @subsubheading Program termination
18004
18005 As a result of execution, the inferior program can run to completion, if
18006 it doesn't encounter any breakpoints. In this case the output will
18007 include an exit code, if the program has exited exceptionally.
18008
18009 @subsubheading Examples
18010
18011 @noindent
18012 Program exited normally:
18013
18014 @smallexample
18015 (@value{GDBP})
18016 -exec-run
18017 ^running
18018 (@value{GDBP})
18019 x = 55
18020 *stopped,reason="exited-normally"
18021 (@value{GDBP})
18022 @end smallexample
18023
18024 @noindent
18025 Program exited exceptionally:
18026
18027 @smallexample
18028 (@value{GDBP})
18029 -exec-run
18030 ^running
18031 (@value{GDBP})
18032 x = 55
18033 *stopped,reason="exited",exit-code="01"
18034 (@value{GDBP})
18035 @end smallexample
18036
18037 Another way the program can terminate is if it receives a signal such as
18038 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18039
18040 @smallexample
18041 (@value{GDBP})
18042 *stopped,reason="exited-signalled",signal-name="SIGINT",
18043 signal-meaning="Interrupt"
18044 @end smallexample
18045
18046
18047 @subheading The @code{-exec-abort} Command
18048 @findex -exec-abort
18049
18050 @subsubheading Synopsis
18051
18052 @smallexample
18053 -exec-abort
18054 @end smallexample
18055
18056 Kill the inferior running program.
18057
18058 @subsubheading @value{GDBN} Command
18059
18060 The corresponding @value{GDBN} command is @samp{kill}.
18061
18062 @subsubheading Example
18063 N.A.
18064
18065
18066 @subheading The @code{-exec-arguments} Command
18067 @findex -exec-arguments
18068
18069 @subsubheading Synopsis
18070
18071 @smallexample
18072 -exec-arguments @var{args}
18073 @end smallexample
18074
18075 Set the inferior program arguments, to be used in the next
18076 @samp{-exec-run}.
18077
18078 @subsubheading @value{GDBN} Command
18079
18080 The corresponding @value{GDBN} command is @samp{set args}.
18081
18082 @subsubheading Example
18083
18084 @c FIXME!
18085 Don't have one around.
18086
18087
18088 @subheading The @code{-exec-continue} Command
18089 @findex -exec-continue
18090
18091 @subsubheading Synopsis
18092
18093 @smallexample
18094 -exec-continue
18095 @end smallexample
18096
18097 Asynchronous command. Resumes the execution of the inferior program
18098 until a breakpoint is encountered, or until the inferior exits.
18099
18100 @subsubheading @value{GDBN} Command
18101
18102 The corresponding @value{GDBN} corresponding is @samp{continue}.
18103
18104 @subsubheading Example
18105
18106 @smallexample
18107 -exec-continue
18108 ^running
18109 (@value{GDBP})
18110 @@Hello world
18111 *stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
18112 file="hello.c",line="13"@}
18113 (@value{GDBP})
18114 @end smallexample
18115
18116
18117 @subheading The @code{-exec-finish} Command
18118 @findex -exec-finish
18119
18120 @subsubheading Synopsis
18121
18122 @smallexample
18123 -exec-finish
18124 @end smallexample
18125
18126 Asynchronous command. Resumes the execution of the inferior program
18127 until the current function is exited. Displays the results returned by
18128 the function.
18129
18130 @subsubheading @value{GDBN} Command
18131
18132 The corresponding @value{GDBN} command is @samp{finish}.
18133
18134 @subsubheading Example
18135
18136 Function returning @code{void}.
18137
18138 @smallexample
18139 -exec-finish
18140 ^running
18141 (@value{GDBP})
18142 @@hello from foo
18143 *stopped,reason="function-finished",frame=@{func="main",args=[],
18144 file="hello.c",line="7"@}
18145 (@value{GDBP})
18146 @end smallexample
18147
18148 Function returning other than @code{void}. The name of the internal
18149 @value{GDBN} variable storing the result is printed, together with the
18150 value itself.
18151
18152 @smallexample
18153 -exec-finish
18154 ^running
18155 (@value{GDBP})
18156 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18157 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
18158 file="recursive2.c",line="14"@},
18159 gdb-result-var="$1",return-value="0"
18160 (@value{GDBP})
18161 @end smallexample
18162
18163
18164 @subheading The @code{-exec-interrupt} Command
18165 @findex -exec-interrupt
18166
18167 @subsubheading Synopsis
18168
18169 @smallexample
18170 -exec-interrupt
18171 @end smallexample
18172
18173 Asynchronous command. Interrupts the background execution of the target.
18174 Note how the token associated with the stop message is the one for the
18175 execution command that has been interrupted. The token for the interrupt
18176 itself only appears in the @samp{^done} output. If the user is trying to
18177 interrupt a non-running program, an error message will be printed.
18178
18179 @subsubheading @value{GDBN} Command
18180
18181 The corresponding @value{GDBN} command is @samp{interrupt}.
18182
18183 @subsubheading Example
18184
18185 @smallexample
18186 (@value{GDBP})
18187 111-exec-continue
18188 111^running
18189
18190 (@value{GDBP})
18191 222-exec-interrupt
18192 222^done
18193 (@value{GDBP})
18194 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
18195 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
18196 (@value{GDBP})
18197
18198 (@value{GDBP})
18199 -exec-interrupt
18200 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18201 (@value{GDBP})
18202 @end smallexample
18203
18204
18205 @subheading The @code{-exec-next} Command
18206 @findex -exec-next
18207
18208 @subsubheading Synopsis
18209
18210 @smallexample
18211 -exec-next
18212 @end smallexample
18213
18214 Asynchronous command. Resumes execution of the inferior program, stopping
18215 when the beginning of the next source line is reached.
18216
18217 @subsubheading @value{GDBN} Command
18218
18219 The corresponding @value{GDBN} command is @samp{next}.
18220
18221 @subsubheading Example
18222
18223 @smallexample
18224 -exec-next
18225 ^running
18226 (@value{GDBP})
18227 *stopped,reason="end-stepping-range",line="8",file="hello.c"
18228 (@value{GDBP})
18229 @end smallexample
18230
18231
18232 @subheading The @code{-exec-next-instruction} Command
18233 @findex -exec-next-instruction
18234
18235 @subsubheading Synopsis
18236
18237 @smallexample
18238 -exec-next-instruction
18239 @end smallexample
18240
18241 Asynchronous command. Executes one machine instruction. If the
18242 instruction is a function call continues until the function returns. If
18243 the program stops at an instruction in the middle of a source line, the
18244 address will be printed as well.
18245
18246 @subsubheading @value{GDBN} Command
18247
18248 The corresponding @value{GDBN} command is @samp{nexti}.
18249
18250 @subsubheading Example
18251
18252 @smallexample
18253 (@value{GDBP})
18254 -exec-next-instruction
18255 ^running
18256
18257 (@value{GDBP})
18258 *stopped,reason="end-stepping-range",
18259 addr="0x000100d4",line="5",file="hello.c"
18260 (@value{GDBP})
18261 @end smallexample
18262
18263
18264 @subheading The @code{-exec-return} Command
18265 @findex -exec-return
18266
18267 @subsubheading Synopsis
18268
18269 @smallexample
18270 -exec-return
18271 @end smallexample
18272
18273 Makes current function return immediately. Doesn't execute the inferior.
18274 Displays the new current frame.
18275
18276 @subsubheading @value{GDBN} Command
18277
18278 The corresponding @value{GDBN} command is @samp{return}.
18279
18280 @subsubheading Example
18281
18282 @smallexample
18283 (@value{GDBP})
18284 200-break-insert callee4
18285 200^done,bkpt=@{number="1",addr="0x00010734",
18286 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18287 (@value{GDBP})
18288 000-exec-run
18289 000^running
18290 (@value{GDBP})
18291 000*stopped,reason="breakpoint-hit",bkptno="1",
18292 frame=@{func="callee4",args=[],
18293 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18294 (@value{GDBP})
18295 205-break-delete
18296 205^done
18297 (@value{GDBP})
18298 111-exec-return
18299 111^done,frame=@{level="0",func="callee3",
18300 args=[@{name="strarg",
18301 value="0x11940 \"A string argument.\""@}],
18302 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18303 (@value{GDBP})
18304 @end smallexample
18305
18306
18307 @subheading The @code{-exec-run} Command
18308 @findex -exec-run
18309
18310 @subsubheading Synopsis
18311
18312 @smallexample
18313 -exec-run
18314 @end smallexample
18315
18316 Asynchronous command. Starts execution of the inferior from the
18317 beginning. The inferior executes until either a breakpoint is
18318 encountered or the program exits.
18319
18320 @subsubheading @value{GDBN} Command
18321
18322 The corresponding @value{GDBN} command is @samp{run}.
18323
18324 @subsubheading Example
18325
18326 @smallexample
18327 (@value{GDBP})
18328 -break-insert main
18329 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18330 (@value{GDBP})
18331 -exec-run
18332 ^running
18333 (@value{GDBP})
18334 *stopped,reason="breakpoint-hit",bkptno="1",
18335 frame=@{func="main",args=[],file="recursive2.c",line="4"@}
18336 (@value{GDBP})
18337 @end smallexample
18338
18339
18340 @subheading The @code{-exec-show-arguments} Command
18341 @findex -exec-show-arguments
18342
18343 @subsubheading Synopsis
18344
18345 @smallexample
18346 -exec-show-arguments
18347 @end smallexample
18348
18349 Print the arguments of the program.
18350
18351 @subsubheading @value{GDBN} Command
18352
18353 The corresponding @value{GDBN} command is @samp{show args}.
18354
18355 @subsubheading Example
18356 N.A.
18357
18358 @c @subheading -exec-signal
18359
18360 @subheading The @code{-exec-step} Command
18361 @findex -exec-step
18362
18363 @subsubheading Synopsis
18364
18365 @smallexample
18366 -exec-step
18367 @end smallexample
18368
18369 Asynchronous command. Resumes execution of the inferior program, stopping
18370 when the beginning of the next source line is reached, if the next
18371 source line is not a function call. If it is, stop at the first
18372 instruction of the called function.
18373
18374 @subsubheading @value{GDBN} Command
18375
18376 The corresponding @value{GDBN} command is @samp{step}.
18377
18378 @subsubheading Example
18379
18380 Stepping into a function:
18381
18382 @smallexample
18383 -exec-step
18384 ^running
18385 (@value{GDBP})
18386 *stopped,reason="end-stepping-range",
18387 frame=@{func="foo",args=[@{name="a",value="10"@},
18388 @{name="b",value="0"@}],file="recursive2.c",line="11"@}
18389 (@value{GDBP})
18390 @end smallexample
18391
18392 Regular stepping:
18393
18394 @smallexample
18395 -exec-step
18396 ^running
18397 (@value{GDBP})
18398 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18399 (@value{GDBP})
18400 @end smallexample
18401
18402
18403 @subheading The @code{-exec-step-instruction} Command
18404 @findex -exec-step-instruction
18405
18406 @subsubheading Synopsis
18407
18408 @smallexample
18409 -exec-step-instruction
18410 @end smallexample
18411
18412 Asynchronous command. Resumes the inferior which executes one machine
18413 instruction. The output, once @value{GDBN} has stopped, will vary depending on
18414 whether we have stopped in the middle of a source line or not. In the
18415 former case, the address at which the program stopped will be printed as
18416 well.
18417
18418 @subsubheading @value{GDBN} Command
18419
18420 The corresponding @value{GDBN} command is @samp{stepi}.
18421
18422 @subsubheading Example
18423
18424 @smallexample
18425 (@value{GDBP})
18426 -exec-step-instruction
18427 ^running
18428
18429 (@value{GDBP})
18430 *stopped,reason="end-stepping-range",
18431 frame=@{func="foo",args=[],file="try.c",line="10"@}
18432 (@value{GDBP})
18433 -exec-step-instruction
18434 ^running
18435
18436 (@value{GDBP})
18437 *stopped,reason="end-stepping-range",
18438 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
18439 (@value{GDBP})
18440 @end smallexample
18441
18442
18443 @subheading The @code{-exec-until} Command
18444 @findex -exec-until
18445
18446 @subsubheading Synopsis
18447
18448 @smallexample
18449 -exec-until [ @var{location} ]
18450 @end smallexample
18451
18452 Asynchronous command. Executes the inferior until the @var{location}
18453 specified in the argument is reached. If there is no argument, the inferior
18454 executes until a source line greater than the current one is reached.
18455 The reason for stopping in this case will be @samp{location-reached}.
18456
18457 @subsubheading @value{GDBN} Command
18458
18459 The corresponding @value{GDBN} command is @samp{until}.
18460
18461 @subsubheading Example
18462
18463 @smallexample
18464 (@value{GDBP})
18465 -exec-until recursive2.c:6
18466 ^running
18467 (@value{GDBP})
18468 x = 55
18469 *stopped,reason="location-reached",frame=@{func="main",args=[],
18470 file="recursive2.c",line="6"@}
18471 (@value{GDBP})
18472 @end smallexample
18473
18474 @ignore
18475 @subheading -file-clear
18476 Is this going away????
18477 @end ignore
18478
18479
18480 @subheading The @code{-file-exec-and-symbols} Command
18481 @findex -file-exec-and-symbols
18482
18483 @subsubheading Synopsis
18484
18485 @smallexample
18486 -file-exec-and-symbols @var{file}
18487 @end smallexample
18488
18489 Specify the executable file to be debugged. This file is the one from
18490 which the symbol table is also read. If no file is specified, the
18491 command clears the executable and symbol information. If breakpoints
18492 are set when using this command with no arguments, @value{GDBN} will produce
18493 error messages. Otherwise, no output is produced, except a completion
18494 notification.
18495
18496 @subsubheading @value{GDBN} Command
18497
18498 The corresponding @value{GDBN} command is @samp{file}.
18499
18500 @subsubheading Example
18501
18502 @smallexample
18503 (@value{GDBP})
18504 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18505 ^done
18506 (@value{GDBP})
18507 @end smallexample
18508
18509
18510 @subheading The @code{-file-exec-file} Command
18511 @findex -file-exec-file
18512
18513 @subsubheading Synopsis
18514
18515 @smallexample
18516 -file-exec-file @var{file}
18517 @end smallexample
18518
18519 Specify the executable file to be debugged. Unlike
18520 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18521 from this file. If used without argument, @value{GDBN} clears the information
18522 about the executable file. No output is produced, except a completion
18523 notification.
18524
18525 @subsubheading @value{GDBN} Command
18526
18527 The corresponding @value{GDBN} command is @samp{exec-file}.
18528
18529 @subsubheading Example
18530
18531 @smallexample
18532 (@value{GDBP})
18533 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18534 ^done
18535 (@value{GDBP})
18536 @end smallexample
18537
18538
18539 @subheading The @code{-file-list-exec-sections} Command
18540 @findex -file-list-exec-sections
18541
18542 @subsubheading Synopsis
18543
18544 @smallexample
18545 -file-list-exec-sections
18546 @end smallexample
18547
18548 List the sections of the current executable file.
18549
18550 @subsubheading @value{GDBN} Command
18551
18552 The @value{GDBN} command @samp{info file} shows, among the rest, the same
18553 information as this command. @code{gdbtk} has a corresponding command
18554 @samp{gdb_load_info}.
18555
18556 @subsubheading Example
18557 N.A.
18558
18559
18560 @subheading The @code{-file-list-exec-source-file} Command
18561 @findex -file-list-exec-source-file
18562
18563 @subsubheading Synopsis
18564
18565 @smallexample
18566 -file-list-exec-source-file
18567 @end smallexample
18568
18569 List the line number, the current source file, and the absolute path
18570 to the current source file for the current executable.
18571
18572 @subsubheading @value{GDBN} Command
18573
18574 There's no @value{GDBN} command which directly corresponds to this one.
18575
18576 @subsubheading Example
18577
18578 @smallexample
18579 (@value{GDBP})
18580 123-file-list-exec-source-file
18581 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18582 (@value{GDBP})
18583 @end smallexample
18584
18585
18586 @subheading The @code{-file-list-exec-source-files} Command
18587 @findex -file-list-exec-source-files
18588
18589 @subsubheading Synopsis
18590
18591 @smallexample
18592 -file-list-exec-source-files
18593 @end smallexample
18594
18595 List the source files for the current executable.
18596
18597 It will always output the filename, but only when GDB can find the absolute
18598 file name of a source file, will it output the fullname.
18599
18600 @subsubheading @value{GDBN} Command
18601
18602 There's no @value{GDBN} command which directly corresponds to this one.
18603 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18604
18605 @subsubheading Example
18606 @smallexample
18607 (@value{GDBP})
18608 -file-list-exec-source-files
18609 ^done,files=[
18610 @{file=foo.c,fullname=/home/foo.c@},
18611 @{file=/home/bar.c,fullname=/home/bar.c@},
18612 @{file=gdb_could_not_find_fullpath.c@}]
18613 (@value{GDBP})
18614 @end smallexample
18615
18616 @subheading The @code{-file-list-shared-libraries} Command
18617 @findex -file-list-shared-libraries
18618
18619 @subsubheading Synopsis
18620
18621 @smallexample
18622 -file-list-shared-libraries
18623 @end smallexample
18624
18625 List the shared libraries in the program.
18626
18627 @subsubheading @value{GDBN} Command
18628
18629 The corresponding @value{GDBN} command is @samp{info shared}.
18630
18631 @subsubheading Example
18632 N.A.
18633
18634
18635 @subheading The @code{-file-list-symbol-files} Command
18636 @findex -file-list-symbol-files
18637
18638 @subsubheading Synopsis
18639
18640 @smallexample
18641 -file-list-symbol-files
18642 @end smallexample
18643
18644 List symbol files.
18645
18646 @subsubheading @value{GDBN} Command
18647
18648 The corresponding @value{GDBN} command is @samp{info file} (part of it).
18649
18650 @subsubheading Example
18651 N.A.
18652
18653
18654 @subheading The @code{-file-symbol-file} Command
18655 @findex -file-symbol-file
18656
18657 @subsubheading Synopsis
18658
18659 @smallexample
18660 -file-symbol-file @var{file}
18661 @end smallexample
18662
18663 Read symbol table info from the specified @var{file} argument. When
18664 used without arguments, clears @value{GDBN}'s symbol table info. No output is
18665 produced, except for a completion notification.
18666
18667 @subsubheading @value{GDBN} Command
18668
18669 The corresponding @value{GDBN} command is @samp{symbol-file}.
18670
18671 @subsubheading Example
18672
18673 @smallexample
18674 (@value{GDBP})
18675 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18676 ^done
18677 (@value{GDBP})
18678 @end smallexample
18679
18680 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18681 @node GDB/MI Miscellaneous Commands
18682 @section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
18683
18684 @c @subheading -gdb-complete
18685
18686 @subheading The @code{-gdb-exit} Command
18687 @findex -gdb-exit
18688
18689 @subsubheading Synopsis
18690
18691 @smallexample
18692 -gdb-exit
18693 @end smallexample
18694
18695 Exit @value{GDBN} immediately.
18696
18697 @subsubheading @value{GDBN} Command
18698
18699 Approximately corresponds to @samp{quit}.
18700
18701 @subsubheading Example
18702
18703 @smallexample
18704 (@value{GDBP})
18705 -gdb-exit
18706 @end smallexample
18707
18708 @subheading The @code{-gdb-set} Command
18709 @findex -gdb-set
18710
18711 @subsubheading Synopsis
18712
18713 @smallexample
18714 -gdb-set
18715 @end smallexample
18716
18717 Set an internal @value{GDBN} variable.
18718 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
18719
18720 @subsubheading @value{GDBN} Command
18721
18722 The corresponding @value{GDBN} command is @samp{set}.
18723
18724 @subsubheading Example
18725
18726 @smallexample
18727 (@value{GDBP})
18728 -gdb-set $foo=3
18729 ^done
18730 (@value{GDBP})
18731 @end smallexample
18732
18733
18734 @subheading The @code{-gdb-show} Command
18735 @findex -gdb-show
18736
18737 @subsubheading Synopsis
18738
18739 @smallexample
18740 -gdb-show
18741 @end smallexample
18742
18743 Show the current value of a @value{GDBN} variable.
18744
18745 @subsubheading @value{GDBN} command
18746
18747 The corresponding @value{GDBN} command is @samp{show}.
18748
18749 @subsubheading Example
18750
18751 @smallexample
18752 (@value{GDBP})
18753 -gdb-show annotate
18754 ^done,value="0"
18755 (@value{GDBP})
18756 @end smallexample
18757
18758 @c @subheading -gdb-source
18759
18760
18761 @subheading The @code{-gdb-version} Command
18762 @findex -gdb-version
18763
18764 @subsubheading Synopsis
18765
18766 @smallexample
18767 -gdb-version
18768 @end smallexample
18769
18770 Show version information for @value{GDBN}. Used mostly in testing.
18771
18772 @subsubheading @value{GDBN} Command
18773
18774 There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
18775 information when you start an interactive session.
18776
18777 @subsubheading Example
18778
18779 @c This example modifies the actual output from GDB to avoid overfull
18780 @c box in TeX.
18781 @smallexample
18782 (@value{GDBP})
18783 -gdb-version
18784 ~GNU gdb 5.2.1
18785 ~Copyright 2000 Free Software Foundation, Inc.
18786 ~GDB is free software, covered by the GNU General Public License, and
18787 ~you are welcome to change it and/or distribute copies of it under
18788 ~ certain conditions.
18789 ~Type "show copying" to see the conditions.
18790 ~There is absolutely no warranty for GDB. Type "show warranty" for
18791 ~ details.
18792 ~This GDB was configured as
18793 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
18794 ^done
18795 (@value{GDBP})
18796 @end smallexample
18797
18798 @subheading The @code{-interpreter-exec} Command
18799 @findex -interpreter-exec
18800
18801 @subheading Synopsis
18802
18803 @smallexample
18804 -interpreter-exec @var{interpreter} @var{command}
18805 @end smallexample
18806
18807 Execute the specified @var{command} in the given @var{interpreter}.
18808
18809 @subheading @value{GDBN} Command
18810
18811 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
18812
18813 @subheading Example
18814
18815 @smallexample
18816 (@value{GDBP})
18817 -interpreter-exec console "break main"
18818 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
18819 &"During symbol reading, bad structure-type format.\n"
18820 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
18821 ^done
18822 (@value{GDBP})
18823 @end smallexample
18824
18825 @ignore
18826 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18827 @node GDB/MI Kod Commands
18828 @section @sc{gdb/mi} Kod Commands
18829
18830 The Kod commands are not implemented.
18831
18832 @c @subheading -kod-info
18833
18834 @c @subheading -kod-list
18835
18836 @c @subheading -kod-list-object-types
18837
18838 @c @subheading -kod-show
18839
18840 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18841 @node GDB/MI Memory Overlay Commands
18842 @section @sc{gdb/mi} Memory Overlay Commands
18843
18844 The memory overlay commands are not implemented.
18845
18846 @c @subheading -overlay-auto
18847
18848 @c @subheading -overlay-list-mapping-state
18849
18850 @c @subheading -overlay-list-overlays
18851
18852 @c @subheading -overlay-map
18853
18854 @c @subheading -overlay-off
18855
18856 @c @subheading -overlay-on
18857
18858 @c @subheading -overlay-unmap
18859
18860 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18861 @node GDB/MI Signal Handling Commands
18862 @section @sc{gdb/mi} Signal Handling Commands
18863
18864 Signal handling commands are not implemented.
18865
18866 @c @subheading -signal-handle
18867
18868 @c @subheading -signal-list-handle-actions
18869
18870 @c @subheading -signal-list-signal-types
18871 @end ignore
18872
18873
18874 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18875 @node GDB/MI Stack Manipulation
18876 @section @sc{gdb/mi} Stack Manipulation Commands
18877
18878
18879 @subheading The @code{-stack-info-frame} Command
18880 @findex -stack-info-frame
18881
18882 @subsubheading Synopsis
18883
18884 @smallexample
18885 -stack-info-frame
18886 @end smallexample
18887
18888 Get info on the current frame.
18889
18890 @subsubheading @value{GDBN} Command
18891
18892 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
18893 (without arguments).
18894
18895 @subsubheading Example
18896 N.A.
18897
18898 @subheading The @code{-stack-info-depth} Command
18899 @findex -stack-info-depth
18900
18901 @subsubheading Synopsis
18902
18903 @smallexample
18904 -stack-info-depth [ @var{max-depth} ]
18905 @end smallexample
18906
18907 Return the depth of the stack. If the integer argument @var{max-depth}
18908 is specified, do not count beyond @var{max-depth} frames.
18909
18910 @subsubheading @value{GDBN} Command
18911
18912 There's no equivalent @value{GDBN} command.
18913
18914 @subsubheading Example
18915
18916 For a stack with frame levels 0 through 11:
18917
18918 @smallexample
18919 (@value{GDBP})
18920 -stack-info-depth
18921 ^done,depth="12"
18922 (@value{GDBP})
18923 -stack-info-depth 4
18924 ^done,depth="4"
18925 (@value{GDBP})
18926 -stack-info-depth 12
18927 ^done,depth="12"
18928 (@value{GDBP})
18929 -stack-info-depth 11
18930 ^done,depth="11"
18931 (@value{GDBP})
18932 -stack-info-depth 13
18933 ^done,depth="12"
18934 (@value{GDBP})
18935 @end smallexample
18936
18937 @subheading The @code{-stack-list-arguments} Command
18938 @findex -stack-list-arguments
18939
18940 @subsubheading Synopsis
18941
18942 @smallexample
18943 -stack-list-arguments @var{show-values}
18944 [ @var{low-frame} @var{high-frame} ]
18945 @end smallexample
18946
18947 Display a list of the arguments for the frames between @var{low-frame}
18948 and @var{high-frame} (inclusive). If @var{low-frame} and
18949 @var{high-frame} are not provided, list the arguments for the whole call
18950 stack.
18951
18952 The @var{show-values} argument must have a value of 0 or 1. A value of
18953 0 means that only the names of the arguments are listed, a value of 1
18954 means that both names and values of the arguments are printed.
18955
18956 @subsubheading @value{GDBN} Command
18957
18958 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
18959 @samp{gdb_get_args} command which partially overlaps with the
18960 functionality of @samp{-stack-list-arguments}.
18961
18962 @subsubheading Example
18963
18964 @smallexample
18965 (@value{GDBP})
18966 -stack-list-frames
18967 ^done,
18968 stack=[
18969 frame=@{level="0",addr="0x00010734",func="callee4",
18970 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
18971 frame=@{level="1",addr="0x0001076c",func="callee3",
18972 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
18973 frame=@{level="2",addr="0x0001078c",func="callee2",
18974 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
18975 frame=@{level="3",addr="0x000107b4",func="callee1",
18976 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
18977 frame=@{level="4",addr="0x000107e0",func="main",
18978 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
18979 (@value{GDBP})
18980 -stack-list-arguments 0
18981 ^done,
18982 stack-args=[
18983 frame=@{level="0",args=[]@},
18984 frame=@{level="1",args=[name="strarg"]@},
18985 frame=@{level="2",args=[name="intarg",name="strarg"]@},
18986 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
18987 frame=@{level="4",args=[]@}]
18988 (@value{GDBP})
18989 -stack-list-arguments 1
18990 ^done,
18991 stack-args=[
18992 frame=@{level="0",args=[]@},
18993 frame=@{level="1",
18994 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
18995 frame=@{level="2",args=[
18996 @{name="intarg",value="2"@},
18997 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
18998 @{frame=@{level="3",args=[
18999 @{name="intarg",value="2"@},
19000 @{name="strarg",value="0x11940 \"A string argument.\""@},
19001 @{name="fltarg",value="3.5"@}]@},
19002 frame=@{level="4",args=[]@}]
19003 (@value{GDBP})
19004 -stack-list-arguments 0 2 2
19005 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19006 (@value{GDBP})
19007 -stack-list-arguments 1 2 2
19008 ^done,stack-args=[frame=@{level="2",
19009 args=[@{name="intarg",value="2"@},
19010 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19011 (@value{GDBP})
19012 @end smallexample
19013
19014 @c @subheading -stack-list-exception-handlers
19015
19016
19017 @subheading The @code{-stack-list-frames} Command
19018 @findex -stack-list-frames
19019
19020 @subsubheading Synopsis
19021
19022 @smallexample
19023 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19024 @end smallexample
19025
19026 List the frames currently on the stack. For each frame it displays the
19027 following info:
19028
19029 @table @samp
19030 @item @var{level}
19031 The frame number, 0 being the topmost frame, i.e. the innermost function.
19032 @item @var{addr}
19033 The @code{$pc} value for that frame.
19034 @item @var{func}
19035 Function name.
19036 @item @var{file}
19037 File name of the source file where the function lives.
19038 @item @var{line}
19039 Line number corresponding to the @code{$pc}.
19040 @end table
19041
19042 If invoked without arguments, this command prints a backtrace for the
19043 whole stack. If given two integer arguments, it shows the frames whose
19044 levels are between the two arguments (inclusive). If the two arguments
19045 are equal, it shows the single frame at the corresponding level.
19046
19047 @subsubheading @value{GDBN} Command
19048
19049 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19050
19051 @subsubheading Example
19052
19053 Full stack backtrace:
19054
19055 @smallexample
19056 (@value{GDBP})
19057 -stack-list-frames
19058 ^done,stack=
19059 [frame=@{level="0",addr="0x0001076c",func="foo",
19060 file="recursive2.c",line="11"@},
19061 frame=@{level="1",addr="0x000107a4",func="foo",
19062 file="recursive2.c",line="14"@},
19063 frame=@{level="2",addr="0x000107a4",func="foo",
19064 file="recursive2.c",line="14"@},
19065 frame=@{level="3",addr="0x000107a4",func="foo",
19066 file="recursive2.c",line="14"@},
19067 frame=@{level="4",addr="0x000107a4",func="foo",
19068 file="recursive2.c",line="14"@},
19069 frame=@{level="5",addr="0x000107a4",func="foo",
19070 file="recursive2.c",line="14"@},
19071 frame=@{level="6",addr="0x000107a4",func="foo",
19072 file="recursive2.c",line="14"@},
19073 frame=@{level="7",addr="0x000107a4",func="foo",
19074 file="recursive2.c",line="14"@},
19075 frame=@{level="8",addr="0x000107a4",func="foo",
19076 file="recursive2.c",line="14"@},
19077 frame=@{level="9",addr="0x000107a4",func="foo",
19078 file="recursive2.c",line="14"@},
19079 frame=@{level="10",addr="0x000107a4",func="foo",
19080 file="recursive2.c",line="14"@},
19081 frame=@{level="11",addr="0x00010738",func="main",
19082 file="recursive2.c",line="4"@}]
19083 (@value{GDBP})
19084 @end smallexample
19085
19086 Show frames between @var{low_frame} and @var{high_frame}:
19087
19088 @smallexample
19089 (@value{GDBP})
19090 -stack-list-frames 3 5
19091 ^done,stack=
19092 [frame=@{level="3",addr="0x000107a4",func="foo",
19093 file="recursive2.c",line="14"@},
19094 frame=@{level="4",addr="0x000107a4",func="foo",
19095 file="recursive2.c",line="14"@},
19096 frame=@{level="5",addr="0x000107a4",func="foo",
19097 file="recursive2.c",line="14"@}]
19098 (@value{GDBP})
19099 @end smallexample
19100
19101 Show a single frame:
19102
19103 @smallexample
19104 (@value{GDBP})
19105 -stack-list-frames 3 3
19106 ^done,stack=
19107 [frame=@{level="3",addr="0x000107a4",func="foo",
19108 file="recursive2.c",line="14"@}]
19109 (@value{GDBP})
19110 @end smallexample
19111
19112
19113 @subheading The @code{-stack-list-locals} Command
19114 @findex -stack-list-locals
19115
19116 @subsubheading Synopsis
19117
19118 @smallexample
19119 -stack-list-locals @var{print-values}
19120 @end smallexample
19121
19122 Display the local variable names for the current frame. With an
19123 argument of 0 or @code{--no-values}, prints only the names of the variables.
19124 With argument of 1 or @code{--all-values}, prints also their values. With
19125 argument of 2 or @code{--simple-values}, prints the name, type and value for
19126 simple data types and the name and type for arrays, structures and
19127 unions. In this last case, the idea is that the user can see the
19128 value of simple data types immediately and he can create variable
19129 objects for other data types if he wishes to explore their values in
19130 more detail.
19131
19132 @subsubheading @value{GDBN} Command
19133
19134 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19135
19136 @subsubheading Example
19137
19138 @smallexample
19139 (@value{GDBP})
19140 -stack-list-locals 0
19141 ^done,locals=[name="A",name="B",name="C"]
19142 (@value{GDBP})
19143 -stack-list-locals --all-values
19144 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
19145 @{name="C",value="@{1, 2, 3@}"@}]
19146 -stack-list-locals --simple-values
19147 ^done,locals=[@{name="A",type="int",value="1"@},
19148 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
19149 (@value{GDBP})
19150 @end smallexample
19151
19152
19153 @subheading The @code{-stack-select-frame} Command
19154 @findex -stack-select-frame
19155
19156 @subsubheading Synopsis
19157
19158 @smallexample
19159 -stack-select-frame @var{framenum}
19160 @end smallexample
19161
19162 Change the current frame. Select a different frame @var{framenum} on
19163 the stack.
19164
19165 @subsubheading @value{GDBN} Command
19166
19167 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19168 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19169
19170 @subsubheading Example
19171
19172 @smallexample
19173 (@value{GDBP})
19174 -stack-select-frame 2
19175 ^done
19176 (@value{GDBP})
19177 @end smallexample
19178
19179 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19180 @node GDB/MI Symbol Query
19181 @section @sc{gdb/mi} Symbol Query Commands
19182
19183
19184 @subheading The @code{-symbol-info-address} Command
19185 @findex -symbol-info-address
19186
19187 @subsubheading Synopsis
19188
19189 @smallexample
19190 -symbol-info-address @var{symbol}
19191 @end smallexample
19192
19193 Describe where @var{symbol} is stored.
19194
19195 @subsubheading @value{GDBN} Command
19196
19197 The corresponding @value{GDBN} command is @samp{info address}.
19198
19199 @subsubheading Example
19200 N.A.
19201
19202
19203 @subheading The @code{-symbol-info-file} Command
19204 @findex -symbol-info-file
19205
19206 @subsubheading Synopsis
19207
19208 @smallexample
19209 -symbol-info-file
19210 @end smallexample
19211
19212 Show the file for the symbol.
19213
19214 @subsubheading @value{GDBN} Command
19215
19216 There's no equivalent @value{GDBN} command. @code{gdbtk} has
19217 @samp{gdb_find_file}.
19218
19219 @subsubheading Example
19220 N.A.
19221
19222
19223 @subheading The @code{-symbol-info-function} Command
19224 @findex -symbol-info-function
19225
19226 @subsubheading Synopsis
19227
19228 @smallexample
19229 -symbol-info-function
19230 @end smallexample
19231
19232 Show which function the symbol lives in.
19233
19234 @subsubheading @value{GDBN} Command
19235
19236 @samp{gdb_get_function} in @code{gdbtk}.
19237
19238 @subsubheading Example
19239 N.A.
19240
19241
19242 @subheading The @code{-symbol-info-line} Command
19243 @findex -symbol-info-line
19244
19245 @subsubheading Synopsis
19246
19247 @smallexample
19248 -symbol-info-line
19249 @end smallexample
19250
19251 Show the core addresses of the code for a source line.
19252
19253 @subsubheading @value{GDBN} Command
19254
19255 The corresponding @value{GDBN} command is @samp{info line}.
19256 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19257
19258 @subsubheading Example
19259 N.A.
19260
19261
19262 @subheading The @code{-symbol-info-symbol} Command
19263 @findex -symbol-info-symbol
19264
19265 @subsubheading Synopsis
19266
19267 @smallexample
19268 -symbol-info-symbol @var{addr}
19269 @end smallexample
19270
19271 Describe what symbol is at location @var{addr}.
19272
19273 @subsubheading @value{GDBN} Command
19274
19275 The corresponding @value{GDBN} command is @samp{info symbol}.
19276
19277 @subsubheading Example
19278 N.A.
19279
19280
19281 @subheading The @code{-symbol-list-functions} Command
19282 @findex -symbol-list-functions
19283
19284 @subsubheading Synopsis
19285
19286 @smallexample
19287 -symbol-list-functions
19288 @end smallexample
19289
19290 List the functions in the executable.
19291
19292 @subsubheading @value{GDBN} Command
19293
19294 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19295 @samp{gdb_search} in @code{gdbtk}.
19296
19297 @subsubheading Example
19298 N.A.
19299
19300
19301 @subheading The @code{-symbol-list-lines} Command
19302 @findex -symbol-list-lines
19303
19304 @subsubheading Synopsis
19305
19306 @smallexample
19307 -symbol-list-lines @var{filename}
19308 @end smallexample
19309
19310 Print the list of lines that contain code and their associated program
19311 addresses for the given source filename. The entries are sorted in
19312 ascending PC order.
19313
19314 @subsubheading @value{GDBN} Command
19315
19316 There is no corresponding @value{GDBN} command.
19317
19318 @subsubheading Example
19319 @smallexample
19320 (@value{GDBP})
19321 -symbol-list-lines basics.c
19322 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
19323 (@value{GDBP})
19324 @end smallexample
19325
19326
19327 @subheading The @code{-symbol-list-types} Command
19328 @findex -symbol-list-types
19329
19330 @subsubheading Synopsis
19331
19332 @smallexample
19333 -symbol-list-types
19334 @end smallexample
19335
19336 List all the type names.
19337
19338 @subsubheading @value{GDBN} Command
19339
19340 The corresponding commands are @samp{info types} in @value{GDBN},
19341 @samp{gdb_search} in @code{gdbtk}.
19342
19343 @subsubheading Example
19344 N.A.
19345
19346
19347 @subheading The @code{-symbol-list-variables} Command
19348 @findex -symbol-list-variables
19349
19350 @subsubheading Synopsis
19351
19352 @smallexample
19353 -symbol-list-variables
19354 @end smallexample
19355
19356 List all the global and static variable names.
19357
19358 @subsubheading @value{GDBN} Command
19359
19360 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19361
19362 @subsubheading Example
19363 N.A.
19364
19365
19366 @subheading The @code{-symbol-locate} Command
19367 @findex -symbol-locate
19368
19369 @subsubheading Synopsis
19370
19371 @smallexample
19372 -symbol-locate
19373 @end smallexample
19374
19375 @subsubheading @value{GDBN} Command
19376
19377 @samp{gdb_loc} in @code{gdbtk}.
19378
19379 @subsubheading Example
19380 N.A.
19381
19382
19383 @subheading The @code{-symbol-type} Command
19384 @findex -symbol-type
19385
19386 @subsubheading Synopsis
19387
19388 @smallexample
19389 -symbol-type @var{variable}
19390 @end smallexample
19391
19392 Show type of @var{variable}.
19393
19394 @subsubheading @value{GDBN} Command
19395
19396 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19397 @samp{gdb_obj_variable}.
19398
19399 @subsubheading Example
19400 N.A.
19401
19402
19403 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19404 @node GDB/MI Target Manipulation
19405 @section @sc{gdb/mi} Target Manipulation Commands
19406
19407
19408 @subheading The @code{-target-attach} Command
19409 @findex -target-attach
19410
19411 @subsubheading Synopsis
19412
19413 @smallexample
19414 -target-attach @var{pid} | @var{file}
19415 @end smallexample
19416
19417 Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19418
19419 @subsubheading @value{GDBN} command
19420
19421 The corresponding @value{GDBN} command is @samp{attach}.
19422
19423 @subsubheading Example
19424 N.A.
19425
19426
19427 @subheading The @code{-target-compare-sections} Command
19428 @findex -target-compare-sections
19429
19430 @subsubheading Synopsis
19431
19432 @smallexample
19433 -target-compare-sections [ @var{section} ]
19434 @end smallexample
19435
19436 Compare data of section @var{section} on target to the exec file.
19437 Without the argument, all sections are compared.
19438
19439 @subsubheading @value{GDBN} Command
19440
19441 The @value{GDBN} equivalent is @samp{compare-sections}.
19442
19443 @subsubheading Example
19444 N.A.
19445
19446
19447 @subheading The @code{-target-detach} Command
19448 @findex -target-detach
19449
19450 @subsubheading Synopsis
19451
19452 @smallexample
19453 -target-detach
19454 @end smallexample
19455
19456 Disconnect from the remote target. There's no output.
19457
19458 @subsubheading @value{GDBN} command
19459
19460 The corresponding @value{GDBN} command is @samp{detach}.
19461
19462 @subsubheading Example
19463
19464 @smallexample
19465 (@value{GDBP})
19466 -target-detach
19467 ^done
19468 (@value{GDBP})
19469 @end smallexample
19470
19471
19472 @subheading The @code{-target-disconnect} Command
19473 @findex -target-disconnect
19474
19475 @subsubheading Synopsis
19476
19477 @example
19478 -target-disconnect
19479 @end example
19480
19481 Disconnect from the remote target. There's no output.
19482
19483 @subsubheading @value{GDBN} command
19484
19485 The corresponding @value{GDBN} command is @samp{disconnect}.
19486
19487 @subsubheading Example
19488
19489 @smallexample
19490 (@value{GDBP})
19491 -target-disconnect
19492 ^done
19493 (@value{GDBP})
19494 @end smallexample
19495
19496
19497 @subheading The @code{-target-download} Command
19498 @findex -target-download
19499
19500 @subsubheading Synopsis
19501
19502 @smallexample
19503 -target-download
19504 @end smallexample
19505
19506 Loads the executable onto the remote target.
19507 It prints out an update message every half second, which includes the fields:
19508
19509 @table @samp
19510 @item section
19511 The name of the section.
19512 @item section-sent
19513 The size of what has been sent so far for that section.
19514 @item section-size
19515 The size of the section.
19516 @item total-sent
19517 The total size of what was sent so far (the current and the previous sections).
19518 @item total-size
19519 The size of the overall executable to download.
19520 @end table
19521
19522 @noindent
19523 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19524 @sc{gdb/mi} Output Syntax}).
19525
19526 In addition, it prints the name and size of the sections, as they are
19527 downloaded. These messages include the following fields:
19528
19529 @table @samp
19530 @item section
19531 The name of the section.
19532 @item section-size
19533 The size of the section.
19534 @item total-size
19535 The size of the overall executable to download.
19536 @end table
19537
19538 @noindent
19539 At the end, a summary is printed.
19540
19541 @subsubheading @value{GDBN} Command
19542
19543 The corresponding @value{GDBN} command is @samp{load}.
19544
19545 @subsubheading Example
19546
19547 Note: each status message appears on a single line. Here the messages
19548 have been broken down so that they can fit onto a page.
19549
19550 @smallexample
19551 (@value{GDBP})
19552 -target-download
19553 +download,@{section=".text",section-size="6668",total-size="9880"@}
19554 +download,@{section=".text",section-sent="512",section-size="6668",
19555 total-sent="512",total-size="9880"@}
19556 +download,@{section=".text",section-sent="1024",section-size="6668",
19557 total-sent="1024",total-size="9880"@}
19558 +download,@{section=".text",section-sent="1536",section-size="6668",
19559 total-sent="1536",total-size="9880"@}
19560 +download,@{section=".text",section-sent="2048",section-size="6668",
19561 total-sent="2048",total-size="9880"@}
19562 +download,@{section=".text",section-sent="2560",section-size="6668",
19563 total-sent="2560",total-size="9880"@}
19564 +download,@{section=".text",section-sent="3072",section-size="6668",
19565 total-sent="3072",total-size="9880"@}
19566 +download,@{section=".text",section-sent="3584",section-size="6668",
19567 total-sent="3584",total-size="9880"@}
19568 +download,@{section=".text",section-sent="4096",section-size="6668",
19569 total-sent="4096",total-size="9880"@}
19570 +download,@{section=".text",section-sent="4608",section-size="6668",
19571 total-sent="4608",total-size="9880"@}
19572 +download,@{section=".text",section-sent="5120",section-size="6668",
19573 total-sent="5120",total-size="9880"@}
19574 +download,@{section=".text",section-sent="5632",section-size="6668",
19575 total-sent="5632",total-size="9880"@}
19576 +download,@{section=".text",section-sent="6144",section-size="6668",
19577 total-sent="6144",total-size="9880"@}
19578 +download,@{section=".text",section-sent="6656",section-size="6668",
19579 total-sent="6656",total-size="9880"@}
19580 +download,@{section=".init",section-size="28",total-size="9880"@}
19581 +download,@{section=".fini",section-size="28",total-size="9880"@}
19582 +download,@{section=".data",section-size="3156",total-size="9880"@}
19583 +download,@{section=".data",section-sent="512",section-size="3156",
19584 total-sent="7236",total-size="9880"@}
19585 +download,@{section=".data",section-sent="1024",section-size="3156",
19586 total-sent="7748",total-size="9880"@}
19587 +download,@{section=".data",section-sent="1536",section-size="3156",
19588 total-sent="8260",total-size="9880"@}
19589 +download,@{section=".data",section-sent="2048",section-size="3156",
19590 total-sent="8772",total-size="9880"@}
19591 +download,@{section=".data",section-sent="2560",section-size="3156",
19592 total-sent="9284",total-size="9880"@}
19593 +download,@{section=".data",section-sent="3072",section-size="3156",
19594 total-sent="9796",total-size="9880"@}
19595 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
19596 write-rate="429"
19597 (@value{GDBP})
19598 @end smallexample
19599
19600
19601 @subheading The @code{-target-exec-status} Command
19602 @findex -target-exec-status
19603
19604 @subsubheading Synopsis
19605
19606 @smallexample
19607 -target-exec-status
19608 @end smallexample
19609
19610 Provide information on the state of the target (whether it is running or
19611 not, for instance).
19612
19613 @subsubheading @value{GDBN} Command
19614
19615 There's no equivalent @value{GDBN} command.
19616
19617 @subsubheading Example
19618 N.A.
19619
19620
19621 @subheading The @code{-target-list-available-targets} Command
19622 @findex -target-list-available-targets
19623
19624 @subsubheading Synopsis
19625
19626 @smallexample
19627 -target-list-available-targets
19628 @end smallexample
19629
19630 List the possible targets to connect to.
19631
19632 @subsubheading @value{GDBN} Command
19633
19634 The corresponding @value{GDBN} command is @samp{help target}.
19635
19636 @subsubheading Example
19637 N.A.
19638
19639
19640 @subheading The @code{-target-list-current-targets} Command
19641 @findex -target-list-current-targets
19642
19643 @subsubheading Synopsis
19644
19645 @smallexample
19646 -target-list-current-targets
19647 @end smallexample
19648
19649 Describe the current target.
19650
19651 @subsubheading @value{GDBN} Command
19652
19653 The corresponding information is printed by @samp{info file} (among
19654 other things).
19655
19656 @subsubheading Example
19657 N.A.
19658
19659
19660 @subheading The @code{-target-list-parameters} Command
19661 @findex -target-list-parameters
19662
19663 @subsubheading Synopsis
19664
19665 @smallexample
19666 -target-list-parameters
19667 @end smallexample
19668
19669 @c ????
19670
19671 @subsubheading @value{GDBN} Command
19672
19673 No equivalent.
19674
19675 @subsubheading Example
19676 N.A.
19677
19678
19679 @subheading The @code{-target-select} Command
19680 @findex -target-select
19681
19682 @subsubheading Synopsis
19683
19684 @smallexample
19685 -target-select @var{type} @var{parameters @dots{}}
19686 @end smallexample
19687
19688 Connect @value{GDBN} to the remote target. This command takes two args:
19689
19690 @table @samp
19691 @item @var{type}
19692 The type of target, for instance @samp{async}, @samp{remote}, etc.
19693 @item @var{parameters}
19694 Device names, host names and the like. @xref{Target Commands, ,
19695 Commands for managing targets}, for more details.
19696 @end table
19697
19698 The output is a connection notification, followed by the address at
19699 which the target program is, in the following form:
19700
19701 @smallexample
19702 ^connected,addr="@var{address}",func="@var{function name}",
19703 args=[@var{arg list}]
19704 @end smallexample
19705
19706 @subsubheading @value{GDBN} Command
19707
19708 The corresponding @value{GDBN} command is @samp{target}.
19709
19710 @subsubheading Example
19711
19712 @smallexample
19713 (@value{GDBP})
19714 -target-select async /dev/ttya
19715 ^connected,addr="0xfe00a300",func="??",args=[]
19716 (@value{GDBP})
19717 @end smallexample
19718
19719 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19720 @node GDB/MI Thread Commands
19721 @section @sc{gdb/mi} Thread Commands
19722
19723
19724 @subheading The @code{-thread-info} Command
19725 @findex -thread-info
19726
19727 @subsubheading Synopsis
19728
19729 @smallexample
19730 -thread-info
19731 @end smallexample
19732
19733 @subsubheading @value{GDBN} command
19734
19735 No equivalent.
19736
19737 @subsubheading Example
19738 N.A.
19739
19740
19741 @subheading The @code{-thread-list-all-threads} Command
19742 @findex -thread-list-all-threads
19743
19744 @subsubheading Synopsis
19745
19746 @smallexample
19747 -thread-list-all-threads
19748 @end smallexample
19749
19750 @subsubheading @value{GDBN} Command
19751
19752 The equivalent @value{GDBN} command is @samp{info threads}.
19753
19754 @subsubheading Example
19755 N.A.
19756
19757
19758 @subheading The @code{-thread-list-ids} Command
19759 @findex -thread-list-ids
19760
19761 @subsubheading Synopsis
19762
19763 @smallexample
19764 -thread-list-ids
19765 @end smallexample
19766
19767 Produces a list of the currently known @value{GDBN} thread ids. At the
19768 end of the list it also prints the total number of such threads.
19769
19770 @subsubheading @value{GDBN} Command
19771
19772 Part of @samp{info threads} supplies the same information.
19773
19774 @subsubheading Example
19775
19776 No threads present, besides the main process:
19777
19778 @smallexample
19779 (@value{GDBP})
19780 -thread-list-ids
19781 ^done,thread-ids=@{@},number-of-threads="0"
19782 (@value{GDBP})
19783 @end smallexample
19784
19785
19786 Several threads:
19787
19788 @smallexample
19789 (@value{GDBP})
19790 -thread-list-ids
19791 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
19792 number-of-threads="3"
19793 (@value{GDBP})
19794 @end smallexample
19795
19796
19797 @subheading The @code{-thread-select} Command
19798 @findex -thread-select
19799
19800 @subsubheading Synopsis
19801
19802 @smallexample
19803 -thread-select @var{threadnum}
19804 @end smallexample
19805
19806 Make @var{threadnum} the current thread. It prints the number of the new
19807 current thread, and the topmost frame for that thread.
19808
19809 @subsubheading @value{GDBN} Command
19810
19811 The corresponding @value{GDBN} command is @samp{thread}.
19812
19813 @subsubheading Example
19814
19815 @smallexample
19816 (@value{GDBP})
19817 -exec-next
19818 ^running
19819 (@value{GDBP})
19820 *stopped,reason="end-stepping-range",thread-id="2",line="187",
19821 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
19822 (@value{GDBP})
19823 -thread-list-ids
19824 ^done,
19825 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
19826 number-of-threads="3"
19827 (@value{GDBP})
19828 -thread-select 3
19829 ^done,new-thread-id="3",
19830 frame=@{level="0",func="vprintf",
19831 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
19832 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
19833 (@value{GDBP})
19834 @end smallexample
19835
19836 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19837 @node GDB/MI Tracepoint Commands
19838 @section @sc{gdb/mi} Tracepoint Commands
19839
19840 The tracepoint commands are not yet implemented.
19841
19842 @c @subheading -trace-actions
19843
19844 @c @subheading -trace-delete
19845
19846 @c @subheading -trace-disable
19847
19848 @c @subheading -trace-dump
19849
19850 @c @subheading -trace-enable
19851
19852 @c @subheading -trace-exists
19853
19854 @c @subheading -trace-find
19855
19856 @c @subheading -trace-frame-number
19857
19858 @c @subheading -trace-info
19859
19860 @c @subheading -trace-insert
19861
19862 @c @subheading -trace-list
19863
19864 @c @subheading -trace-pass-count
19865
19866 @c @subheading -trace-save
19867
19868 @c @subheading -trace-start
19869
19870 @c @subheading -trace-stop
19871
19872
19873 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19874 @node GDB/MI Variable Objects
19875 @section @sc{gdb/mi} Variable Objects
19876
19877
19878 @subheading Motivation for Variable Objects in @sc{gdb/mi}
19879
19880 For the implementation of a variable debugger window (locals, watched
19881 expressions, etc.), we are proposing the adaptation of the existing code
19882 used by @code{Insight}.
19883
19884 The two main reasons for that are:
19885
19886 @enumerate 1
19887 @item
19888 It has been proven in practice (it is already on its second generation).
19889
19890 @item
19891 It will shorten development time (needless to say how important it is
19892 now).
19893 @end enumerate
19894
19895 The original interface was designed to be used by Tcl code, so it was
19896 slightly changed so it could be used through @sc{gdb/mi}. This section
19897 describes the @sc{gdb/mi} operations that will be available and gives some
19898 hints about their use.
19899
19900 @emph{Note}: In addition to the set of operations described here, we
19901 expect the @sc{gui} implementation of a variable window to require, at
19902 least, the following operations:
19903
19904 @itemize @bullet
19905 @item @code{-gdb-show} @code{output-radix}
19906 @item @code{-stack-list-arguments}
19907 @item @code{-stack-list-locals}
19908 @item @code{-stack-select-frame}
19909 @end itemize
19910
19911 @subheading Introduction to Variable Objects in @sc{gdb/mi}
19912
19913 @cindex variable objects in @sc{gdb/mi}
19914 The basic idea behind variable objects is the creation of a named object
19915 to represent a variable, an expression, a memory location or even a CPU
19916 register. For each object created, a set of operations is available for
19917 examining or changing its properties.
19918
19919 Furthermore, complex data types, such as C structures, are represented
19920 in a tree format. For instance, the @code{struct} type variable is the
19921 root and the children will represent the struct members. If a child
19922 is itself of a complex type, it will also have children of its own.
19923 Appropriate language differences are handled for C, C@t{++} and Java.
19924
19925 When returning the actual values of the objects, this facility allows
19926 for the individual selection of the display format used in the result
19927 creation. It can be chosen among: binary, decimal, hexadecimal, octal
19928 and natural. Natural refers to a default format automatically
19929 chosen based on the variable type (like decimal for an @code{int}, hex
19930 for pointers, etc.).
19931
19932 The following is the complete set of @sc{gdb/mi} operations defined to
19933 access this functionality:
19934
19935 @multitable @columnfractions .4 .6
19936 @item @strong{Operation}
19937 @tab @strong{Description}
19938
19939 @item @code{-var-create}
19940 @tab create a variable object
19941 @item @code{-var-delete}
19942 @tab delete the variable object and its children
19943 @item @code{-var-set-format}
19944 @tab set the display format of this variable
19945 @item @code{-var-show-format}
19946 @tab show the display format of this variable
19947 @item @code{-var-info-num-children}
19948 @tab tells how many children this object has
19949 @item @code{-var-list-children}
19950 @tab return a list of the object's children
19951 @item @code{-var-info-type}
19952 @tab show the type of this variable object
19953 @item @code{-var-info-expression}
19954 @tab print what this variable object represents
19955 @item @code{-var-show-attributes}
19956 @tab is this variable editable? does it exist here?
19957 @item @code{-var-evaluate-expression}
19958 @tab get the value of this variable
19959 @item @code{-var-assign}
19960 @tab set the value of this variable
19961 @item @code{-var-update}
19962 @tab update the variable and its children
19963 @end multitable
19964
19965 In the next subsection we describe each operation in detail and suggest
19966 how it can be used.
19967
19968 @subheading Description And Use of Operations on Variable Objects
19969
19970 @subheading The @code{-var-create} Command
19971 @findex -var-create
19972
19973 @subsubheading Synopsis
19974
19975 @smallexample
19976 -var-create @{@var{name} | "-"@}
19977 @{@var{frame-addr} | "*"@} @var{expression}
19978 @end smallexample
19979
19980 This operation creates a variable object, which allows the monitoring of
19981 a variable, the result of an expression, a memory cell or a CPU
19982 register.
19983
19984 The @var{name} parameter is the string by which the object can be
19985 referenced. It must be unique. If @samp{-} is specified, the varobj
19986 system will generate a string ``varNNNNNN'' automatically. It will be
19987 unique provided that one does not specify @var{name} on that format.
19988 The command fails if a duplicate name is found.
19989
19990 The frame under which the expression should be evaluated can be
19991 specified by @var{frame-addr}. A @samp{*} indicates that the current
19992 frame should be used.
19993
19994 @var{expression} is any expression valid on the current language set (must not
19995 begin with a @samp{*}), or one of the following:
19996
19997 @itemize @bullet
19998 @item
19999 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20000
20001 @item
20002 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20003
20004 @item
20005 @samp{$@var{regname}} --- a CPU register name
20006 @end itemize
20007
20008 @subsubheading Result
20009
20010 This operation returns the name, number of children and the type of the
20011 object created. Type is returned as a string as the ones generated by
20012 the @value{GDBN} CLI:
20013
20014 @smallexample
20015 name="@var{name}",numchild="N",type="@var{type}"
20016 @end smallexample
20017
20018
20019 @subheading The @code{-var-delete} Command
20020 @findex -var-delete
20021
20022 @subsubheading Synopsis
20023
20024 @smallexample
20025 -var-delete @var{name}
20026 @end smallexample
20027
20028 Deletes a previously created variable object and all of its children.
20029
20030 Returns an error if the object @var{name} is not found.
20031
20032
20033 @subheading The @code{-var-set-format} Command
20034 @findex -var-set-format
20035
20036 @subsubheading Synopsis
20037
20038 @smallexample
20039 -var-set-format @var{name} @var{format-spec}
20040 @end smallexample
20041
20042 Sets the output format for the value of the object @var{name} to be
20043 @var{format-spec}.
20044
20045 The syntax for the @var{format-spec} is as follows:
20046
20047 @smallexample
20048 @var{format-spec} @expansion{}
20049 @{binary | decimal | hexadecimal | octal | natural@}
20050 @end smallexample
20051
20052
20053 @subheading The @code{-var-show-format} Command
20054 @findex -var-show-format
20055
20056 @subsubheading Synopsis
20057
20058 @smallexample
20059 -var-show-format @var{name}
20060 @end smallexample
20061
20062 Returns the format used to display the value of the object @var{name}.
20063
20064 @smallexample
20065 @var{format} @expansion{}
20066 @var{format-spec}
20067 @end smallexample
20068
20069
20070 @subheading The @code{-var-info-num-children} Command
20071 @findex -var-info-num-children
20072
20073 @subsubheading Synopsis
20074
20075 @smallexample
20076 -var-info-num-children @var{name}
20077 @end smallexample
20078
20079 Returns the number of children of a variable object @var{name}:
20080
20081 @smallexample
20082 numchild=@var{n}
20083 @end smallexample
20084
20085
20086 @subheading The @code{-var-list-children} Command
20087 @findex -var-list-children
20088
20089 @subsubheading Synopsis
20090
20091 @smallexample
20092 -var-list-children [@var{print-values}] @var{name}
20093 @end smallexample
20094
20095 Returns a list of the children of the specified variable object. With
20096 just the variable object name as an argument or with an optional
20097 preceding argument of 0 or @code{--no-values}, prints only the names of the
20098 variables. With an optional preceding argument of 1 or @code{--all-values},
20099 also prints their values.
20100
20101 @subsubheading Example
20102
20103 @smallexample
20104 (@value{GDBP})
20105 -var-list-children n
20106 numchild=@var{n},children=[@{name=@var{name},
20107 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
20108 (@value{GDBP})
20109 -var-list-children --all-values n
20110 numchild=@var{n},children=[@{name=@var{name},
20111 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
20112 @end smallexample
20113
20114
20115 @subheading The @code{-var-info-type} Command
20116 @findex -var-info-type
20117
20118 @subsubheading Synopsis
20119
20120 @smallexample
20121 -var-info-type @var{name}
20122 @end smallexample
20123
20124 Returns the type of the specified variable @var{name}. The type is
20125 returned as a string in the same format as it is output by the
20126 @value{GDBN} CLI:
20127
20128 @smallexample
20129 type=@var{typename}
20130 @end smallexample
20131
20132
20133 @subheading The @code{-var-info-expression} Command
20134 @findex -var-info-expression
20135
20136 @subsubheading Synopsis
20137
20138 @smallexample
20139 -var-info-expression @var{name}
20140 @end smallexample
20141
20142 Returns what is represented by the variable object @var{name}:
20143
20144 @smallexample
20145 lang=@var{lang-spec},exp=@var{expression}
20146 @end smallexample
20147
20148 @noindent
20149 where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20150
20151 @subheading The @code{-var-show-attributes} Command
20152 @findex -var-show-attributes
20153
20154 @subsubheading Synopsis
20155
20156 @smallexample
20157 -var-show-attributes @var{name}
20158 @end smallexample
20159
20160 List attributes of the specified variable object @var{name}:
20161
20162 @smallexample
20163 status=@var{attr} [ ( ,@var{attr} )* ]
20164 @end smallexample
20165
20166 @noindent
20167 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20168
20169 @subheading The @code{-var-evaluate-expression} Command
20170 @findex -var-evaluate-expression
20171
20172 @subsubheading Synopsis
20173
20174 @smallexample
20175 -var-evaluate-expression @var{name}
20176 @end smallexample
20177
20178 Evaluates the expression that is represented by the specified variable
20179 object and returns its value as a string in the current format specified
20180 for the object:
20181
20182 @smallexample
20183 value=@var{value}
20184 @end smallexample
20185
20186 Note that one must invoke @code{-var-list-children} for a variable
20187 before the value of a child variable can be evaluated.
20188
20189 @subheading The @code{-var-assign} Command
20190 @findex -var-assign
20191
20192 @subsubheading Synopsis
20193
20194 @smallexample
20195 -var-assign @var{name} @var{expression}
20196 @end smallexample
20197
20198 Assigns the value of @var{expression} to the variable object specified
20199 by @var{name}. The object must be @samp{editable}. If the variable's
20200 value is altered by the assign, the variable will show up in any
20201 subsequent @code{-var-update} list.
20202
20203 @subsubheading Example
20204
20205 @smallexample
20206 (@value{GDBP})
20207 -var-assign var1 3
20208 ^done,value="3"
20209 (@value{GDBP})
20210 -var-update *
20211 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20212 (@value{GDBP})
20213 @end smallexample
20214
20215 @subheading The @code{-var-update} Command
20216 @findex -var-update
20217
20218 @subsubheading Synopsis
20219
20220 @smallexample
20221 -var-update @{@var{name} | "*"@}
20222 @end smallexample
20223
20224 Update the value of the variable object @var{name} by evaluating its
20225 expression after fetching all the new values from memory or registers.
20226 A @samp{*} causes all existing variable objects to be updated.
20227
20228
20229 @node Annotations
20230 @chapter @value{GDBN} Annotations
20231
20232 This chapter describes annotations in @value{GDBN}. Annotations were
20233 designed to interface @value{GDBN} to graphical user interfaces or other
20234 similar programs which want to interact with @value{GDBN} at a
20235 relatively high level.
20236
20237 The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20238 (@pxref{GDB/MI}).
20239
20240 @ignore
20241 This is Edition @value{EDITION}, @value{DATE}.
20242 @end ignore
20243
20244 @menu
20245 * Annotations Overview:: What annotations are; the general syntax.
20246 * Server Prefix:: Issuing a command without affecting user state.
20247 * Prompting:: Annotations marking @value{GDBN}'s need for input.
20248 * Errors:: Annotations for error messages.
20249 * Invalidation:: Some annotations describe things now invalid.
20250 * Annotations for Running::
20251 Whether the program is running, how it stopped, etc.
20252 * Source Annotations:: Annotations describing source code.
20253 @end menu
20254
20255 @node Annotations Overview
20256 @section What is an Annotation?
20257 @cindex annotations
20258
20259 Annotations start with a newline character, two @samp{control-z}
20260 characters, and the name of the annotation. If there is no additional
20261 information associated with this annotation, the name of the annotation
20262 is followed immediately by a newline. If there is additional
20263 information, the name of the annotation is followed by a space, the
20264 additional information, and a newline. The additional information
20265 cannot contain newline characters.
20266
20267 Any output not beginning with a newline and two @samp{control-z}
20268 characters denotes literal output from @value{GDBN}. Currently there is
20269 no need for @value{GDBN} to output a newline followed by two
20270 @samp{control-z} characters, but if there was such a need, the
20271 annotations could be extended with an @samp{escape} annotation which
20272 means those three characters as output.
20273
20274 The annotation @var{level}, which is specified using the
20275 @option{--annotate} command line option (@pxref{Mode Options}), controls
20276 how much information @value{GDBN} prints together with its prompt,
20277 values of expressions, source lines, and other types of output. Level 0
20278 is for no anntations, level 1 is for use when @value{GDBN} is run as a
20279 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20280 for programs that control @value{GDBN}, and level 2 annotations have
20281 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
20282 Interface, annotate, GDB's Obsolete Annotations}).
20283
20284 @table @code
20285 @kindex set annotate
20286 @item set annotate @var{level}
20287 The @value{GDB} command @code{set annotate} sets the level of
20288 annotations to the specified @var{level}.
20289
20290 @item show annotate
20291 @kindex show annotate
20292 Show the current annotation level.
20293 @end table
20294
20295 This chapter describes level 3 annotations.
20296
20297 A simple example of starting up @value{GDBN} with annotations is:
20298
20299 @smallexample
20300 $ @kbd{gdb --annotate=3}
20301 GNU gdb 6.0
20302 Copyright 2003 Free Software Foundation, Inc.
20303 GDB is free software, covered by the GNU General Public License,
20304 and you are welcome to change it and/or distribute copies of it
20305 under certain conditions.
20306 Type "show copying" to see the conditions.
20307 There is absolutely no warranty for GDB. Type "show warranty"
20308 for details.
20309 This GDB was configured as "i386-pc-linux-gnu"
20310
20311 ^Z^Zpre-prompt
20312 (@value{GDBP})
20313 ^Z^Zprompt
20314 @kbd{quit}
20315
20316 ^Z^Zpost-prompt
20317 $
20318 @end smallexample
20319
20320 Here @samp{quit} is input to @value{GDBN}; the rest is output from
20321 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20322 denotes a @samp{control-z} character) are annotations; the rest is
20323 output from @value{GDBN}.
20324
20325 @node Server Prefix
20326 @section The Server Prefix
20327 @cindex server prefix for annotations
20328
20329 To issue a command to @value{GDBN} without affecting certain aspects of
20330 the state which is seen by users, prefix it with @samp{server }. This
20331 means that this command will not affect the command history, nor will it
20332 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20333 pressed on a line by itself.
20334
20335 The server prefix does not affect the recording of values into the value
20336 history; to print a value without recording it into the value history,
20337 use the @code{output} command instead of the @code{print} command.
20338
20339 @node Prompting
20340 @section Annotation for @value{GDBN} Input
20341
20342 @cindex annotations for prompts
20343 When @value{GDBN} prompts for input, it annotates this fact so it is possible
20344 to know when to send output, when the output from a given command is
20345 over, etc.
20346
20347 Different kinds of input each have a different @dfn{input type}. Each
20348 input type has three annotations: a @code{pre-} annotation, which
20349 denotes the beginning of any prompt which is being output, a plain
20350 annotation, which denotes the end of the prompt, and then a @code{post-}
20351 annotation which denotes the end of any echo which may (or may not) be
20352 associated with the input. For example, the @code{prompt} input type
20353 features the following annotations:
20354
20355 @smallexample
20356 ^Z^Zpre-prompt
20357 ^Z^Zprompt
20358 ^Z^Zpost-prompt
20359 @end smallexample
20360
20361 The input types are
20362
20363 @table @code
20364 @findex pre-prompt
20365 @findex prompt
20366 @findex post-prompt
20367 @item prompt
20368 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20369
20370 @findex pre-commands
20371 @findex commands
20372 @findex post-commands
20373 @item commands
20374 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20375 command. The annotations are repeated for each command which is input.
20376
20377 @findex pre-overload-choice
20378 @findex overload-choice
20379 @findex post-overload-choice
20380 @item overload-choice
20381 When @value{GDBN} wants the user to select between various overloaded functions.
20382
20383 @findex pre-query
20384 @findex query
20385 @findex post-query
20386 @item query
20387 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20388
20389 @findex pre-prompt-for-continue
20390 @findex prompt-for-continue
20391 @findex post-prompt-for-continue
20392 @item prompt-for-continue
20393 When @value{GDBN} is asking the user to press return to continue. Note: Don't
20394 expect this to work well; instead use @code{set height 0} to disable
20395 prompting. This is because the counting of lines is buggy in the
20396 presence of annotations.
20397 @end table
20398
20399 @node Errors
20400 @section Errors
20401 @cindex annotations for errors, warnings and interrupts
20402
20403 @findex quit
20404 @smallexample
20405 ^Z^Zquit
20406 @end smallexample
20407
20408 This annotation occurs right before @value{GDBN} responds to an interrupt.
20409
20410 @findex error
20411 @smallexample
20412 ^Z^Zerror
20413 @end smallexample
20414
20415 This annotation occurs right before @value{GDBN} responds to an error.
20416
20417 Quit and error annotations indicate that any annotations which @value{GDBN} was
20418 in the middle of may end abruptly. For example, if a
20419 @code{value-history-begin} annotation is followed by a @code{error}, one
20420 cannot expect to receive the matching @code{value-history-end}. One
20421 cannot expect not to receive it either, however; an error annotation
20422 does not necessarily mean that @value{GDBN} is immediately returning all the way
20423 to the top level.
20424
20425 @findex error-begin
20426 A quit or error annotation may be preceded by
20427
20428 @smallexample
20429 ^Z^Zerror-begin
20430 @end smallexample
20431
20432 Any output between that and the quit or error annotation is the error
20433 message.
20434
20435 Warning messages are not yet annotated.
20436 @c If we want to change that, need to fix warning(), type_error(),
20437 @c range_error(), and possibly other places.
20438
20439 @node Invalidation
20440 @section Invalidation Notices
20441
20442 @cindex annotations for invalidation messages
20443 The following annotations say that certain pieces of state may have
20444 changed.
20445
20446 @table @code
20447 @findex frames-invalid
20448 @item ^Z^Zframes-invalid
20449
20450 The frames (for example, output from the @code{backtrace} command) may
20451 have changed.
20452
20453 @findex breakpoints-invalid
20454 @item ^Z^Zbreakpoints-invalid
20455
20456 The breakpoints may have changed. For example, the user just added or
20457 deleted a breakpoint.
20458 @end table
20459
20460 @node Annotations for Running
20461 @section Running the Program
20462 @cindex annotations for running programs
20463
20464 @findex starting
20465 @findex stopping
20466 When the program starts executing due to a @value{GDBN} command such as
20467 @code{step} or @code{continue},
20468
20469 @smallexample
20470 ^Z^Zstarting
20471 @end smallexample
20472
20473 is output. When the program stops,
20474
20475 @smallexample
20476 ^Z^Zstopped
20477 @end smallexample
20478
20479 is output. Before the @code{stopped} annotation, a variety of
20480 annotations describe how the program stopped.
20481
20482 @table @code
20483 @findex exited
20484 @item ^Z^Zexited @var{exit-status}
20485 The program exited, and @var{exit-status} is the exit status (zero for
20486 successful exit, otherwise nonzero).
20487
20488 @findex signalled
20489 @findex signal-name
20490 @findex signal-name-end
20491 @findex signal-string
20492 @findex signal-string-end
20493 @item ^Z^Zsignalled
20494 The program exited with a signal. After the @code{^Z^Zsignalled}, the
20495 annotation continues:
20496
20497 @smallexample
20498 @var{intro-text}
20499 ^Z^Zsignal-name
20500 @var{name}
20501 ^Z^Zsignal-name-end
20502 @var{middle-text}
20503 ^Z^Zsignal-string
20504 @var{string}
20505 ^Z^Zsignal-string-end
20506 @var{end-text}
20507 @end smallexample
20508
20509 @noindent
20510 where @var{name} is the name of the signal, such as @code{SIGILL} or
20511 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20512 as @code{Illegal Instruction} or @code{Segmentation fault}.
20513 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20514 user's benefit and have no particular format.
20515
20516 @findex signal
20517 @item ^Z^Zsignal
20518 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20519 just saying that the program received the signal, not that it was
20520 terminated with it.
20521
20522 @findex breakpoint
20523 @item ^Z^Zbreakpoint @var{number}
20524 The program hit breakpoint number @var{number}.
20525
20526 @findex watchpoint
20527 @item ^Z^Zwatchpoint @var{number}
20528 The program hit watchpoint number @var{number}.
20529 @end table
20530
20531 @node Source Annotations
20532 @section Displaying Source
20533 @cindex annotations for source display
20534
20535 @findex source
20536 The following annotation is used instead of displaying source code:
20537
20538 @smallexample
20539 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20540 @end smallexample
20541
20542 where @var{filename} is an absolute file name indicating which source
20543 file, @var{line} is the line number within that file (where 1 is the
20544 first line in the file), @var{character} is the character position
20545 within the file (where 0 is the first character in the file) (for most
20546 debug formats this will necessarily point to the beginning of a line),
20547 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
20548 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20549 @var{addr} is the address in the target program associated with the
20550 source which is being displayed. @var{addr} is in the form @samp{0x}
20551 followed by one or more lowercase hex digits (note that this does not
20552 depend on the language).
20553
20554 @node GDB Bugs
20555 @chapter Reporting Bugs in @value{GDBN}
20556 @cindex bugs in @value{GDBN}
20557 @cindex reporting bugs in @value{GDBN}
20558
20559 Your bug reports play an essential role in making @value{GDBN} reliable.
20560
20561 Reporting a bug may help you by bringing a solution to your problem, or it
20562 may not. But in any case the principal function of a bug report is to help
20563 the entire community by making the next version of @value{GDBN} work better. Bug
20564 reports are your contribution to the maintenance of @value{GDBN}.
20565
20566 In order for a bug report to serve its purpose, you must include the
20567 information that enables us to fix the bug.
20568
20569 @menu
20570 * Bug Criteria:: Have you found a bug?
20571 * Bug Reporting:: How to report bugs
20572 @end menu
20573
20574 @node Bug Criteria
20575 @section Have you found a bug?
20576 @cindex bug criteria
20577
20578 If you are not sure whether you have found a bug, here are some guidelines:
20579
20580 @itemize @bullet
20581 @cindex fatal signal
20582 @cindex debugger crash
20583 @cindex crash of debugger
20584 @item
20585 If the debugger gets a fatal signal, for any input whatever, that is a
20586 @value{GDBN} bug. Reliable debuggers never crash.
20587
20588 @cindex error on valid input
20589 @item
20590 If @value{GDBN} produces an error message for valid input, that is a
20591 bug. (Note that if you're cross debugging, the problem may also be
20592 somewhere in the connection to the target.)
20593
20594 @cindex invalid input
20595 @item
20596 If @value{GDBN} does not produce an error message for invalid input,
20597 that is a bug. However, you should note that your idea of
20598 ``invalid input'' might be our idea of ``an extension'' or ``support
20599 for traditional practice''.
20600
20601 @item
20602 If you are an experienced user of debugging tools, your suggestions
20603 for improvement of @value{GDBN} are welcome in any case.
20604 @end itemize
20605
20606 @node Bug Reporting
20607 @section How to report bugs
20608 @cindex bug reports
20609 @cindex @value{GDBN} bugs, reporting
20610
20611 A number of companies and individuals offer support for @sc{gnu} products.
20612 If you obtained @value{GDBN} from a support organization, we recommend you
20613 contact that organization first.
20614
20615 You can find contact information for many support companies and
20616 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20617 distribution.
20618 @c should add a web page ref...
20619
20620 In any event, we also recommend that you submit bug reports for
20621 @value{GDBN}. The prefered method is to submit them directly using
20622 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20623 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20624 be used.
20625
20626 @strong{Do not send bug reports to @samp{info-gdb}, or to
20627 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20628 not want to receive bug reports. Those that do have arranged to receive
20629 @samp{bug-gdb}.
20630
20631 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20632 serves as a repeater. The mailing list and the newsgroup carry exactly
20633 the same messages. Often people think of posting bug reports to the
20634 newsgroup instead of mailing them. This appears to work, but it has one
20635 problem which can be crucial: a newsgroup posting often lacks a mail
20636 path back to the sender. Thus, if we need to ask for more information,
20637 we may be unable to reach you. For this reason, it is better to send
20638 bug reports to the mailing list.
20639
20640 The fundamental principle of reporting bugs usefully is this:
20641 @strong{report all the facts}. If you are not sure whether to state a
20642 fact or leave it out, state it!
20643
20644 Often people omit facts because they think they know what causes the
20645 problem and assume that some details do not matter. Thus, you might
20646 assume that the name of the variable you use in an example does not matter.
20647 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
20648 stray memory reference which happens to fetch from the location where that
20649 name is stored in memory; perhaps, if the name were different, the contents
20650 of that location would fool the debugger into doing the right thing despite
20651 the bug. Play it safe and give a specific, complete example. That is the
20652 easiest thing for you to do, and the most helpful.
20653
20654 Keep in mind that the purpose of a bug report is to enable us to fix the
20655 bug. It may be that the bug has been reported previously, but neither
20656 you nor we can know that unless your bug report is complete and
20657 self-contained.
20658
20659 Sometimes people give a few sketchy facts and ask, ``Does this ring a
20660 bell?'' Those bug reports are useless, and we urge everyone to
20661 @emph{refuse to respond to them} except to chide the sender to report
20662 bugs properly.
20663
20664 To enable us to fix the bug, you should include all these things:
20665
20666 @itemize @bullet
20667 @item
20668 The version of @value{GDBN}. @value{GDBN} announces it if you start
20669 with no arguments; you can also print it at any time using @code{show
20670 version}.
20671
20672 Without this, we will not know whether there is any point in looking for
20673 the bug in the current version of @value{GDBN}.
20674
20675 @item
20676 The type of machine you are using, and the operating system name and
20677 version number.
20678
20679 @item
20680 What compiler (and its version) was used to compile @value{GDBN}---e.g.
20681 ``@value{GCC}--2.8.1''.
20682
20683 @item
20684 What compiler (and its version) was used to compile the program you are
20685 debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
20686 C Compiler''. For GCC, you can say @code{gcc --version} to get this
20687 information; for other compilers, see the documentation for those
20688 compilers.
20689
20690 @item
20691 The command arguments you gave the compiler to compile your example and
20692 observe the bug. For example, did you use @samp{-O}? To guarantee
20693 you will not omit something important, list them all. A copy of the
20694 Makefile (or the output from make) is sufficient.
20695
20696 If we were to try to guess the arguments, we would probably guess wrong
20697 and then we might not encounter the bug.
20698
20699 @item
20700 A complete input script, and all necessary source files, that will
20701 reproduce the bug.
20702
20703 @item
20704 A description of what behavior you observe that you believe is
20705 incorrect. For example, ``It gets a fatal signal.''
20706
20707 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
20708 will certainly notice it. But if the bug is incorrect output, we might
20709 not notice unless it is glaringly wrong. You might as well not give us
20710 a chance to make a mistake.
20711
20712 Even if the problem you experience is a fatal signal, you should still
20713 say so explicitly. Suppose something strange is going on, such as, your
20714 copy of @value{GDBN} is out of synch, or you have encountered a bug in
20715 the C library on your system. (This has happened!) Your copy might
20716 crash and ours would not. If you told us to expect a crash, then when
20717 ours fails to crash, we would know that the bug was not happening for
20718 us. If you had not told us to expect a crash, then we would not be able
20719 to draw any conclusion from our observations.
20720
20721 @pindex script
20722 @cindex recording a session script
20723 To collect all this information, you can use a session recording program
20724 such as @command{script}, which is available on many Unix systems.
20725 Just run your @value{GDBN} session inside @command{script} and then
20726 include the @file{typescript} file with your bug report.
20727
20728 Another way to record a @value{GDBN} session is to run @value{GDBN}
20729 inside Emacs and then save the entire buffer to a file.
20730
20731 @item
20732 If you wish to suggest changes to the @value{GDBN} source, send us context
20733 diffs. If you even discuss something in the @value{GDBN} source, refer to
20734 it by context, not by line number.
20735
20736 The line numbers in our development sources will not match those in your
20737 sources. Your line numbers would convey no useful information to us.
20738
20739 @end itemize
20740
20741 Here are some things that are not necessary:
20742
20743 @itemize @bullet
20744 @item
20745 A description of the envelope of the bug.
20746
20747 Often people who encounter a bug spend a lot of time investigating
20748 which changes to the input file will make the bug go away and which
20749 changes will not affect it.
20750
20751 This is often time consuming and not very useful, because the way we
20752 will find the bug is by running a single example under the debugger
20753 with breakpoints, not by pure deduction from a series of examples.
20754 We recommend that you save your time for something else.
20755
20756 Of course, if you can find a simpler example to report @emph{instead}
20757 of the original one, that is a convenience for us. Errors in the
20758 output will be easier to spot, running under the debugger will take
20759 less time, and so on.
20760
20761 However, simplification is not vital; if you do not want to do this,
20762 report the bug anyway and send us the entire test case you used.
20763
20764 @item
20765 A patch for the bug.
20766
20767 A patch for the bug does help us if it is a good one. But do not omit
20768 the necessary information, such as the test case, on the assumption that
20769 a patch is all we need. We might see problems with your patch and decide
20770 to fix the problem another way, or we might not understand it at all.
20771
20772 Sometimes with a program as complicated as @value{GDBN} it is very hard to
20773 construct an example that will make the program follow a certain path
20774 through the code. If you do not send us the example, we will not be able
20775 to construct one, so we will not be able to verify that the bug is fixed.
20776
20777 And if we cannot understand what bug you are trying to fix, or why your
20778 patch should be an improvement, we will not install it. A test case will
20779 help us to understand.
20780
20781 @item
20782 A guess about what the bug is or what it depends on.
20783
20784 Such guesses are usually wrong. Even we cannot guess right about such
20785 things without first using the debugger to find the facts.
20786 @end itemize
20787
20788 @c The readline documentation is distributed with the readline code
20789 @c and consists of the two following files:
20790 @c rluser.texinfo
20791 @c inc-hist.texinfo
20792 @c Use -I with makeinfo to point to the appropriate directory,
20793 @c environment var TEXINPUTS with TeX.
20794 @include rluser.texinfo
20795 @include inc-hist.texinfo
20796
20797
20798 @node Formatting Documentation
20799 @appendix Formatting Documentation
20800
20801 @cindex @value{GDBN} reference card
20802 @cindex reference card
20803 The @value{GDBN} 4 release includes an already-formatted reference card, ready
20804 for printing with PostScript or Ghostscript, in the @file{gdb}
20805 subdirectory of the main source directory@footnote{In
20806 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
20807 release.}. If you can use PostScript or Ghostscript with your printer,
20808 you can print the reference card immediately with @file{refcard.ps}.
20809
20810 The release also includes the source for the reference card. You
20811 can format it, using @TeX{}, by typing:
20812
20813 @smallexample
20814 make refcard.dvi
20815 @end smallexample
20816
20817 The @value{GDBN} reference card is designed to print in @dfn{landscape}
20818 mode on US ``letter'' size paper;
20819 that is, on a sheet 11 inches wide by 8.5 inches
20820 high. You will need to specify this form of printing as an option to
20821 your @sc{dvi} output program.
20822
20823 @cindex documentation
20824
20825 All the documentation for @value{GDBN} comes as part of the machine-readable
20826 distribution. The documentation is written in Texinfo format, which is
20827 a documentation system that uses a single source file to produce both
20828 on-line information and a printed manual. You can use one of the Info
20829 formatting commands to create the on-line version of the documentation
20830 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
20831
20832 @value{GDBN} includes an already formatted copy of the on-line Info
20833 version of this manual in the @file{gdb} subdirectory. The main Info
20834 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
20835 subordinate files matching @samp{gdb.info*} in the same directory. If
20836 necessary, you can print out these files, or read them with any editor;
20837 but they are easier to read using the @code{info} subsystem in @sc{gnu}
20838 Emacs or the standalone @code{info} program, available as part of the
20839 @sc{gnu} Texinfo distribution.
20840
20841 If you want to format these Info files yourself, you need one of the
20842 Info formatting programs, such as @code{texinfo-format-buffer} or
20843 @code{makeinfo}.
20844
20845 If you have @code{makeinfo} installed, and are in the top level
20846 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
20847 version @value{GDBVN}), you can make the Info file by typing:
20848
20849 @smallexample
20850 cd gdb
20851 make gdb.info
20852 @end smallexample
20853
20854 If you want to typeset and print copies of this manual, you need @TeX{},
20855 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
20856 Texinfo definitions file.
20857
20858 @TeX{} is a typesetting program; it does not print files directly, but
20859 produces output files called @sc{dvi} files. To print a typeset
20860 document, you need a program to print @sc{dvi} files. If your system
20861 has @TeX{} installed, chances are it has such a program. The precise
20862 command to use depends on your system; @kbd{lpr -d} is common; another
20863 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
20864 require a file name without any extension or a @samp{.dvi} extension.
20865
20866 @TeX{} also requires a macro definitions file called
20867 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
20868 written in Texinfo format. On its own, @TeX{} cannot either read or
20869 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
20870 and is located in the @file{gdb-@var{version-number}/texinfo}
20871 directory.
20872
20873 If you have @TeX{} and a @sc{dvi} printer program installed, you can
20874 typeset and print this manual. First switch to the the @file{gdb}
20875 subdirectory of the main source directory (for example, to
20876 @file{gdb-@value{GDBVN}/gdb}) and type:
20877
20878 @smallexample
20879 make gdb.dvi
20880 @end smallexample
20881
20882 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
20883
20884 @node Installing GDB
20885 @appendix Installing @value{GDBN}
20886 @cindex configuring @value{GDBN}
20887 @cindex installation
20888 @cindex configuring @value{GDBN}, and source tree subdirectories
20889
20890 @value{GDBN} comes with a @code{configure} script that automates the process
20891 of preparing @value{GDBN} for installation; you can then use @code{make} to
20892 build the @code{gdb} program.
20893 @iftex
20894 @c irrelevant in info file; it's as current as the code it lives with.
20895 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
20896 look at the @file{README} file in the sources; we may have improved the
20897 installation procedures since publishing this manual.}
20898 @end iftex
20899
20900 The @value{GDBN} distribution includes all the source code you need for
20901 @value{GDBN} in a single directory, whose name is usually composed by
20902 appending the version number to @samp{gdb}.
20903
20904 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
20905 @file{gdb-@value{GDBVN}} directory. That directory contains:
20906
20907 @table @code
20908 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
20909 script for configuring @value{GDBN} and all its supporting libraries
20910
20911 @item gdb-@value{GDBVN}/gdb
20912 the source specific to @value{GDBN} itself
20913
20914 @item gdb-@value{GDBVN}/bfd
20915 source for the Binary File Descriptor library
20916
20917 @item gdb-@value{GDBVN}/include
20918 @sc{gnu} include files
20919
20920 @item gdb-@value{GDBVN}/libiberty
20921 source for the @samp{-liberty} free software library
20922
20923 @item gdb-@value{GDBVN}/opcodes
20924 source for the library of opcode tables and disassemblers
20925
20926 @item gdb-@value{GDBVN}/readline
20927 source for the @sc{gnu} command-line interface
20928
20929 @item gdb-@value{GDBVN}/glob
20930 source for the @sc{gnu} filename pattern-matching subroutine
20931
20932 @item gdb-@value{GDBVN}/mmalloc
20933 source for the @sc{gnu} memory-mapped malloc package
20934 @end table
20935
20936 The simplest way to configure and build @value{GDBN} is to run @code{configure}
20937 from the @file{gdb-@var{version-number}} source directory, which in
20938 this example is the @file{gdb-@value{GDBVN}} directory.
20939
20940 First switch to the @file{gdb-@var{version-number}} source directory
20941 if you are not already in it; then run @code{configure}. Pass the
20942 identifier for the platform on which @value{GDBN} will run as an
20943 argument.
20944
20945 For example:
20946
20947 @smallexample
20948 cd gdb-@value{GDBVN}
20949 ./configure @var{host}
20950 make
20951 @end smallexample
20952
20953 @noindent
20954 where @var{host} is an identifier such as @samp{sun4} or
20955 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
20956 (You can often leave off @var{host}; @code{configure} tries to guess the
20957 correct value by examining your system.)
20958
20959 Running @samp{configure @var{host}} and then running @code{make} builds the
20960 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
20961 libraries, then @code{gdb} itself. The configured source files, and the
20962 binaries, are left in the corresponding source directories.
20963
20964 @need 750
20965 @code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
20966 system does not recognize this automatically when you run a different
20967 shell, you may need to run @code{sh} on it explicitly:
20968
20969 @smallexample
20970 sh configure @var{host}
20971 @end smallexample
20972
20973 If you run @code{configure} from a directory that contains source
20974 directories for multiple libraries or programs, such as the
20975 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
20976 creates configuration files for every directory level underneath (unless
20977 you tell it not to, with the @samp{--norecursion} option).
20978
20979 You should run the @code{configure} script from the top directory in the
20980 source tree, the @file{gdb-@var{version-number}} directory. If you run
20981 @code{configure} from one of the subdirectories, you will configure only
20982 that subdirectory. That is usually not what you want. In particular,
20983 if you run the first @code{configure} from the @file{gdb} subdirectory
20984 of the @file{gdb-@var{version-number}} directory, you will omit the
20985 configuration of @file{bfd}, @file{readline}, and other sibling
20986 directories of the @file{gdb} subdirectory. This leads to build errors
20987 about missing include files such as @file{bfd/bfd.h}.
20988
20989 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
20990 However, you should make sure that the shell on your path (named by
20991 the @samp{SHELL} environment variable) is publicly readable. Remember
20992 that @value{GDBN} uses the shell to start your program---some systems refuse to
20993 let @value{GDBN} debug child processes whose programs are not readable.
20994
20995 @menu
20996 * Separate Objdir:: Compiling @value{GDBN} in another directory
20997 * Config Names:: Specifying names for hosts and targets
20998 * Configure Options:: Summary of options for configure
20999 @end menu
21000
21001 @node Separate Objdir
21002 @section Compiling @value{GDBN} in another directory
21003
21004 If you want to run @value{GDBN} versions for several host or target machines,
21005 you need a different @code{gdb} compiled for each combination of
21006 host and target. @code{configure} is designed to make this easy by
21007 allowing you to generate each configuration in a separate subdirectory,
21008 rather than in the source directory. If your @code{make} program
21009 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21010 @code{make} in each of these directories builds the @code{gdb}
21011 program specified there.
21012
21013 To build @code{gdb} in a separate directory, run @code{configure}
21014 with the @samp{--srcdir} option to specify where to find the source.
21015 (You also need to specify a path to find @code{configure}
21016 itself from your working directory. If the path to @code{configure}
21017 would be the same as the argument to @samp{--srcdir}, you can leave out
21018 the @samp{--srcdir} option; it is assumed.)
21019
21020 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21021 separate directory for a Sun 4 like this:
21022
21023 @smallexample
21024 @group
21025 cd gdb-@value{GDBVN}
21026 mkdir ../gdb-sun4
21027 cd ../gdb-sun4
21028 ../gdb-@value{GDBVN}/configure sun4
21029 make
21030 @end group
21031 @end smallexample
21032
21033 When @code{configure} builds a configuration using a remote source
21034 directory, it creates a tree for the binaries with the same structure
21035 (and using the same names) as the tree under the source directory. In
21036 the example, you'd find the Sun 4 library @file{libiberty.a} in the
21037 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21038 @file{gdb-sun4/gdb}.
21039
21040 Make sure that your path to the @file{configure} script has just one
21041 instance of @file{gdb} in it. If your path to @file{configure} looks
21042 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21043 one subdirectory of @value{GDBN}, not the whole package. This leads to
21044 build errors about missing include files such as @file{bfd/bfd.h}.
21045
21046 One popular reason to build several @value{GDBN} configurations in separate
21047 directories is to configure @value{GDBN} for cross-compiling (where
21048 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
21049 programs that run on another machine---the @dfn{target}).
21050 You specify a cross-debugging target by
21051 giving the @samp{--target=@var{target}} option to @code{configure}.
21052
21053 When you run @code{make} to build a program or library, you must run
21054 it in a configured directory---whatever directory you were in when you
21055 called @code{configure} (or one of its subdirectories).
21056
21057 The @code{Makefile} that @code{configure} generates in each source
21058 directory also runs recursively. If you type @code{make} in a source
21059 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21060 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21061 will build all the required libraries, and then build GDB.
21062
21063 When you have multiple hosts or targets configured in separate
21064 directories, you can run @code{make} on them in parallel (for example,
21065 if they are NFS-mounted on each of the hosts); they will not interfere
21066 with each other.
21067
21068 @node Config Names
21069 @section Specifying names for hosts and targets
21070
21071 The specifications used for hosts and targets in the @code{configure}
21072 script are based on a three-part naming scheme, but some short predefined
21073 aliases are also supported. The full naming scheme encodes three pieces
21074 of information in the following pattern:
21075
21076 @smallexample
21077 @var{architecture}-@var{vendor}-@var{os}
21078 @end smallexample
21079
21080 For example, you can use the alias @code{sun4} as a @var{host} argument,
21081 or as the value for @var{target} in a @code{--target=@var{target}}
21082 option. The equivalent full name is @samp{sparc-sun-sunos4}.
21083
21084 The @code{configure} script accompanying @value{GDBN} does not provide
21085 any query facility to list all supported host and target names or
21086 aliases. @code{configure} calls the Bourne shell script
21087 @code{config.sub} to map abbreviations to full names; you can read the
21088 script, if you wish, or you can use it to test your guesses on
21089 abbreviations---for example:
21090
21091 @smallexample
21092 % sh config.sub i386-linux
21093 i386-pc-linux-gnu
21094 % sh config.sub alpha-linux
21095 alpha-unknown-linux-gnu
21096 % sh config.sub hp9k700
21097 hppa1.1-hp-hpux
21098 % sh config.sub sun4
21099 sparc-sun-sunos4.1.1
21100 % sh config.sub sun3
21101 m68k-sun-sunos4.1.1
21102 % sh config.sub i986v
21103 Invalid configuration `i986v': machine `i986v' not recognized
21104 @end smallexample
21105
21106 @noindent
21107 @code{config.sub} is also distributed in the @value{GDBN} source
21108 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
21109
21110 @node Configure Options
21111 @section @code{configure} options
21112
21113 Here is a summary of the @code{configure} options and arguments that
21114 are most often useful for building @value{GDBN}. @code{configure} also has
21115 several other options not listed here. @inforef{What Configure
21116 Does,,configure.info}, for a full explanation of @code{configure}.
21117
21118 @smallexample
21119 configure @r{[}--help@r{]}
21120 @r{[}--prefix=@var{dir}@r{]}
21121 @r{[}--exec-prefix=@var{dir}@r{]}
21122 @r{[}--srcdir=@var{dirname}@r{]}
21123 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21124 @r{[}--target=@var{target}@r{]}
21125 @var{host}
21126 @end smallexample
21127
21128 @noindent
21129 You may introduce options with a single @samp{-} rather than
21130 @samp{--} if you prefer; but you may abbreviate option names if you use
21131 @samp{--}.
21132
21133 @table @code
21134 @item --help
21135 Display a quick summary of how to invoke @code{configure}.
21136
21137 @item --prefix=@var{dir}
21138 Configure the source to install programs and files under directory
21139 @file{@var{dir}}.
21140
21141 @item --exec-prefix=@var{dir}
21142 Configure the source to install programs under directory
21143 @file{@var{dir}}.
21144
21145 @c avoid splitting the warning from the explanation:
21146 @need 2000
21147 @item --srcdir=@var{dirname}
21148 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21149 @code{make} that implements the @code{VPATH} feature.}@*
21150 Use this option to make configurations in directories separate from the
21151 @value{GDBN} source directories. Among other things, you can use this to
21152 build (or maintain) several configurations simultaneously, in separate
21153 directories. @code{configure} writes configuration specific files in
21154 the current directory, but arranges for them to use the source in the
21155 directory @var{dirname}. @code{configure} creates directories under
21156 the working directory in parallel to the source directories below
21157 @var{dirname}.
21158
21159 @item --norecursion
21160 Configure only the directory level where @code{configure} is executed; do not
21161 propagate configuration to subdirectories.
21162
21163 @item --target=@var{target}
21164 Configure @value{GDBN} for cross-debugging programs running on the specified
21165 @var{target}. Without this option, @value{GDBN} is configured to debug
21166 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
21167
21168 There is no convenient way to generate a list of all available targets.
21169
21170 @item @var{host} @dots{}
21171 Configure @value{GDBN} to run on the specified @var{host}.
21172
21173 There is no convenient way to generate a list of all available hosts.
21174 @end table
21175
21176 There are many other options available as well, but they are generally
21177 needed for special purposes only.
21178
21179 @node Maintenance Commands
21180 @appendix Maintenance Commands
21181 @cindex maintenance commands
21182 @cindex internal commands
21183
21184 In addition to commands intended for @value{GDBN} users, @value{GDBN}
21185 includes a number of commands intended for @value{GDBN} developers,
21186 that are not documented elsewhere in this manual. These commands are
21187 provided here for reference. (For commands that turn on debugging
21188 messages, see @ref{Debugging Output}.)
21189
21190 @table @code
21191 @kindex maint agent
21192 @item maint agent @var{expression}
21193 Translate the given @var{expression} into remote agent bytecodes.
21194 This command is useful for debugging the Agent Expression mechanism
21195 (@pxref{Agent Expressions}).
21196
21197 @kindex maint info breakpoints
21198 @item @anchor{maint info breakpoints}maint info breakpoints
21199 Using the same format as @samp{info breakpoints}, display both the
21200 breakpoints you've set explicitly, and those @value{GDBN} is using for
21201 internal purposes. Internal breakpoints are shown with negative
21202 breakpoint numbers. The type column identifies what kind of breakpoint
21203 is shown:
21204
21205 @table @code
21206 @item breakpoint
21207 Normal, explicitly set breakpoint.
21208
21209 @item watchpoint
21210 Normal, explicitly set watchpoint.
21211
21212 @item longjmp
21213 Internal breakpoint, used to handle correctly stepping through
21214 @code{longjmp} calls.
21215
21216 @item longjmp resume
21217 Internal breakpoint at the target of a @code{longjmp}.
21218
21219 @item until
21220 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
21221
21222 @item finish
21223 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
21224
21225 @item shlib events
21226 Shared library events.
21227
21228 @end table
21229
21230 @kindex maint check-symtabs
21231 @item maint check-symtabs
21232 Check the consistency of psymtabs and symtabs.
21233
21234 @kindex maint cplus first_component
21235 @item maint cplus first_component @var{name}
21236 Print the first C@t{++} class/namespace component of @var{name}.
21237
21238 @kindex maint cplus namespace
21239 @item maint cplus namespace
21240 Print the list of possible C@t{++} namespaces.
21241
21242 @kindex maint demangle
21243 @item maint demangle @var{name}
21244 Demangle a C@t{++} or Objective-C manled @var{name}.
21245
21246 @kindex maint deprecate
21247 @kindex maint undeprecate
21248 @cindex deprecated commands
21249 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21250 @itemx maint undeprecate @var{command}
21251 Deprecate or undeprecate the named @var{command}. Deprecated commands
21252 cause @value{GDBN} to issue a warning when you use them. The optional
21253 argument @var{replacement} says which newer command should be used in
21254 favor of the deprecated one; if it is given, @value{GDBN} will mention
21255 the replacement as part of the warning.
21256
21257 @kindex maint dump-me
21258 @item maint dump-me
21259 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
21260 Cause a fatal signal in the debugger and force it to dump its core.
21261 This is supported only on systems which support aborting a program
21262 with the @code{SIGQUIT} signal.
21263
21264 @kindex maint internal-error
21265 @kindex maint internal-warning
21266 @item maint internal-error @r{[}@var{message-text}@r{]}
21267 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
21268 Cause @value{GDBN} to call the internal function @code{internal_error}
21269 or @code{internal_warning} and hence behave as though an internal error
21270 or internal warning has been detected. In addition to reporting the
21271 internal problem, these functions give the user the opportunity to
21272 either quit @value{GDBN} or create a core file of the current
21273 @value{GDBN} session.
21274
21275 These commands take an optional parameter @var{message-text} that is
21276 used as the text of the error or warning message.
21277
21278 Here's an example of using @code{indernal-error}:
21279
21280 @smallexample
21281 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
21282 @dots{}/maint.c:121: internal-error: testing, 1, 2
21283 A problem internal to GDB has been detected. Further
21284 debugging may prove unreliable.
21285 Quit this debugging session? (y or n) @kbd{n}
21286 Create a core file? (y or n) @kbd{n}
21287 (@value{GDBP})
21288 @end smallexample
21289
21290 @kindex maint packet
21291 @item maint packet @var{text}
21292 If @value{GDBN} is talking to an inferior via the serial protocol,
21293 then this command sends the string @var{text} to the inferior, and
21294 displays the response packet. @value{GDBN} supplies the initial
21295 @samp{$} character, the terminating @samp{#} character, and the
21296 checksum.
21297
21298 @kindex maint print architecture
21299 @item maint print architecture @r{[}@var{file}@r{]}
21300 Print the entire architecture configuration. The optional argument
21301 @var{file} names the file where the output goes.
21302
21303 @kindex maint print dummy-frames
21304 @item maint print dummy-frames
21305 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21306
21307 @smallexample
21308 (@value{GDBP}) @kbd{b add}
21309 @dots{}
21310 (@value{GDBP}) @kbd{print add(2,3)}
21311 Breakpoint 2, add (a=2, b=3) at @dots{}
21312 58 return (a + b);
21313 The program being debugged stopped while in a function called from GDB.
21314 @dots{}
21315 (@value{GDBP}) @kbd{maint print dummy-frames}
21316 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21317 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21318 call_lo=0x01014000 call_hi=0x01014001
21319 (@value{GDBP})
21320 @end smallexample
21321
21322 Takes an optional file parameter.
21323
21324 @kindex maint print registers
21325 @kindex maint print raw-registers
21326 @kindex maint print cooked-registers
21327 @kindex maint print register-groups
21328 @item maint print registers @r{[}@var{file}@r{]}
21329 @itemx maint print raw-registers @r{[}@var{file}@r{]}
21330 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
21331 @itemx maint print register-groups @r{[}@var{file}@r{]}
21332 Print @value{GDBN}'s internal register data structures.
21333
21334 The command @code{maint print raw-registers} includes the contents of
21335 the raw register cache; the command @code{maint print cooked-registers}
21336 includes the (cooked) value of all registers; and the command
21337 @code{maint print register-groups} includes the groups that each
21338 register is a member of. @xref{Registers,, Registers, gdbint,
21339 @value{GDBN} Internals}.
21340
21341 These commands take an optional parameter, a file name to which to
21342 write the information.
21343
21344 @kindex maint print reggroups
21345 @item maint print reggroups @r{[}@var{file}@r{]}
21346 Print @value{GDBN}'s internal register group data structures. The
21347 optional argument @var{file} tells to what file to write the
21348 information.
21349
21350 The register groups info looks like this:
21351
21352 @smallexample
21353 (@value{GDBP}) @kbd{maint print reggroups}
21354 Group Type
21355 general user
21356 float user
21357 all user
21358 vector user
21359 system user
21360 save internal
21361 restore internal
21362 @end smallexample
21363
21364 @kindex flushregs
21365 @item flushregs
21366 This command forces @value{GDBN} to flush its internal register cache.
21367
21368 @kindex maint print objfiles
21369 @cindex info for known object files
21370 @item maint print objfiles
21371 Print a dump of all known object files. For each object file, this
21372 command prints its name, address in memory, and all of its psymtabs
21373 and symtabs.
21374
21375 @kindex maint print statistics
21376 @cindex bcache statistics
21377 @item maint print statistics
21378 This command prints, for each object file in the program, various data
21379 about that object file followed by the byte cache (@dfn{bcache})
21380 statistics for the object file. The objfile data includes the number
21381 of minimal, partical, full, and stabs symbols, the number of types
21382 defined by the objfile, the number of as yet unexpanded psym tables,
21383 the number of line tables and string tables, and the amount of memory
21384 used by the various tables. The bcache statistics include the counts,
21385 sizes, and counts of duplicates of all and unique objects, max,
21386 average, and median entry size, total memory used and its overhead and
21387 savings, and various measures of the hash table size and chain
21388 lengths.
21389
21390 @kindex maint print type
21391 @cindex type chain of a data type
21392 @item maint print type @var{expr}
21393 Print the type chain for a type specified by @var{expr}. The argument
21394 can be either a type name or a symbol. If it is a symbol, the type of
21395 that symbol is described. The type chain produced by this command is
21396 a recursive definition of the data type as stored in @value{GDBN}'s
21397 data structures, including its flags and contained types.
21398
21399 @kindex maint set dwarf2 max-cache-age
21400 @kindex maint show dwarf2 max-cache-age
21401 @item maint set dwarf2 max-cache-age
21402 @itemx maint show dwarf2 max-cache-age
21403 Control the DWARF 2 compilation unit cache.
21404
21405 @cindex DWARF 2 compilation units cache
21406 In object files with inter-compilation-unit references, such as those
21407 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21408 reader needs to frequently refer to previously read compilation units.
21409 This setting controls how long a compilation unit will remain in the
21410 cache if it is not referenced. A higher limit means that cached
21411 compilation units will be stored in memory longer, and more total
21412 memory will be used. Setting it to zero disables caching, which will
21413 slow down @value{GDBN} startup, but reduce memory consumption.
21414
21415 @kindex maint set profile
21416 @kindex maint show profile
21417 @cindex profiling GDB
21418 @item maint set profile
21419 @itemx maint show profile
21420 Control profiling of @value{GDBN}.
21421
21422 Profiling will be disabled until you use the @samp{maint set profile}
21423 command to enable it. When you enable profiling, the system will begin
21424 collecting timing and execution count data; when you disable profiling or
21425 exit @value{GDBN}, the results will be written to a log file. Remember that
21426 if you use profiling, @value{GDBN} will overwrite the profiling log file
21427 (often called @file{gmon.out}). If you have a record of important profiling
21428 data in a @file{gmon.out} file, be sure to move it to a safe location.
21429
21430 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
21431 compiled with the @samp{-pg} compiler option.
21432
21433 @kindex maint show-debug-regs
21434 @cindex x86 hardware debug registers
21435 @item maint show-debug-regs
21436 Control whether to show variables that mirror the x86 hardware debug
21437 registers. Use @code{ON} to enable, @code{OFF} to disable. If
21438 enabled, the debug registers values are shown when GDB inserts or
21439 removes a hardware breakpoint or watchpoint, and when the inferior
21440 triggers a hardware-assisted breakpoint or watchpoint.
21441
21442 @kindex maint space
21443 @cindex memory used by commands
21444 @item maint space
21445 Control whether to display memory usage for each command. If set to a
21446 nonzero value, @value{GDBN} will display how much memory each command
21447 took, following the command's own output. This can also be requested
21448 by invoking @value{GDBN} with the @option{--statistics} command-line
21449 switch (@pxref{Mode Options}).
21450
21451 @kindex maint time
21452 @cindex time of command execution
21453 @item maint time
21454 Control whether to display the execution time for each command. If
21455 set to a nonzero value, @value{GDBN} will display how much time it
21456 took to execute each command, following the command's own output.
21457 This can also be requested by invoking @value{GDBN} with the
21458 @option{--statistics} command-line switch (@pxref{Mode Options}).
21459
21460 @kindex maint translate-address
21461 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21462 Find the symbol stored at the location specified by the address
21463 @var{addr} and an optional section name @var{section}. If found,
21464 @value{GDBN} prints the name of the closest symbol and an offset from
21465 the symbol's location to the specified address. This is similar to
21466 the @code{info address} command (@pxref{Symbols}), except that this
21467 command also allows to find symbols in other sections.
21468
21469 @end table
21470
21471 The following command is useful for non-interactive invocations of
21472 @value{GDBN}, such as in the test suite.
21473
21474 @table @code
21475 @item set watchdog @var{nsec}
21476 @kindex set watchdog
21477 @cindex watchdog timer
21478 @cindex timeout for commands
21479 Set the maximum number of seconds @value{GDBN} will wait for the
21480 target operation to finish. If this time expires, @value{GDBN}
21481 reports and error and the command is aborted.
21482
21483 @item show watchdog
21484 Show the current setting of the target wait timeout.
21485 @end table
21486
21487 @node Remote Protocol
21488 @appendix @value{GDBN} Remote Serial Protocol
21489
21490 @menu
21491 * Overview::
21492 * Packets::
21493 * Stop Reply Packets::
21494 * General Query Packets::
21495 * Register Packet Format::
21496 * Examples::
21497 * File-I/O remote protocol extension::
21498 @end menu
21499
21500 @node Overview
21501 @section Overview
21502
21503 There may be occasions when you need to know something about the
21504 protocol---for example, if there is only one serial port to your target
21505 machine, you might want your program to do something special if it
21506 recognizes a packet meant for @value{GDBN}.
21507
21508 In the examples below, @samp{->} and @samp{<-} are used to indicate
21509 transmitted and received data respectfully.
21510
21511 @cindex protocol, @value{GDBN} remote serial
21512 @cindex serial protocol, @value{GDBN} remote
21513 @cindex remote serial protocol
21514 All @value{GDBN} commands and responses (other than acknowledgments) are
21515 sent as a @var{packet}. A @var{packet} is introduced with the character
21516 @samp{$}, the actual @var{packet-data}, and the terminating character
21517 @samp{#} followed by a two-digit @var{checksum}:
21518
21519 @smallexample
21520 @code{$}@var{packet-data}@code{#}@var{checksum}
21521 @end smallexample
21522 @noindent
21523
21524 @cindex checksum, for @value{GDBN} remote
21525 @noindent
21526 The two-digit @var{checksum} is computed as the modulo 256 sum of all
21527 characters between the leading @samp{$} and the trailing @samp{#} (an
21528 eight bit unsigned checksum).
21529
21530 Implementors should note that prior to @value{GDBN} 5.0 the protocol
21531 specification also included an optional two-digit @var{sequence-id}:
21532
21533 @smallexample
21534 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
21535 @end smallexample
21536
21537 @cindex sequence-id, for @value{GDBN} remote
21538 @noindent
21539 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21540 has never output @var{sequence-id}s. Stubs that handle packets added
21541 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
21542
21543 @cindex acknowledgment, for @value{GDBN} remote
21544 When either the host or the target machine receives a packet, the first
21545 response expected is an acknowledgment: either @samp{+} (to indicate
21546 the package was received correctly) or @samp{-} (to request
21547 retransmission):
21548
21549 @smallexample
21550 -> @code{$}@var{packet-data}@code{#}@var{checksum}
21551 <- @code{+}
21552 @end smallexample
21553 @noindent
21554
21555 The host (@value{GDBN}) sends @var{command}s, and the target (the
21556 debugging stub incorporated in your program) sends a @var{response}. In
21557 the case of step and continue @var{command}s, the response is only sent
21558 when the operation has completed (the target has again stopped).
21559
21560 @var{packet-data} consists of a sequence of characters with the
21561 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21562 exceptions).
21563
21564 Fields within the packet should be separated using @samp{,} @samp{;} or
21565 @cindex remote protocol, field separator
21566 @samp{:}. Except where otherwise noted all numbers are represented in
21567 @sc{hex} with leading zeros suppressed.
21568
21569 Implementors should note that prior to @value{GDBN} 5.0, the character
21570 @samp{:} could not appear as the third character in a packet (as it
21571 would potentially conflict with the @var{sequence-id}).
21572
21573 Response @var{data} can be run-length encoded to save space. A @samp{*}
21574 means that the next character is an @sc{ascii} encoding giving a repeat count
21575 which stands for that many repetitions of the character preceding the
21576 @samp{*}. The encoding is @code{n+29}, yielding a printable character
21577 where @code{n >=3} (which is where rle starts to win). The printable
21578 characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21579 value greater than 126 should not be used.
21580
21581 So:
21582 @smallexample
21583 "@code{0* }"
21584 @end smallexample
21585 @noindent
21586 means the same as "0000".
21587
21588 The error response returned for some packets includes a two character
21589 error number. That number is not well defined.
21590
21591 For any @var{command} not supported by the stub, an empty response
21592 (@samp{$#00}) should be returned. That way it is possible to extend the
21593 protocol. A newer @value{GDBN} can tell if a packet is supported based
21594 on that response.
21595
21596 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21597 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
21598 optional.
21599
21600 @node Packets
21601 @section Packets
21602
21603 The following table provides a complete list of all currently defined
21604 @var{command}s and their corresponding response @var{data}.
21605 @xref{File-I/O remote protocol extension}, for details about the File
21606 I/O extension of the remote protocol.
21607
21608 @table @r
21609
21610 @item @code{!} --- extended mode
21611 @cindex @code{!} packet
21612
21613 Enable extended mode. In extended mode, the remote server is made
21614 persistent. The @samp{R} packet is used to restart the program being
21615 debugged.
21616
21617 Reply:
21618 @table @samp
21619 @item OK
21620 The remote target both supports and has enabled extended mode.
21621 @end table
21622
21623 @item @code{?} --- last signal
21624 @cindex @code{?} packet
21625
21626 Indicate the reason the target halted. The reply is the same as for
21627 step and continue.
21628
21629 Reply:
21630 @xref{Stop Reply Packets}, for the reply specifications.
21631
21632 @item @code{a} --- reserved
21633
21634 Reserved for future use.
21635
21636 @item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21637 @cindex @code{A} packet
21638
21639 Initialized @samp{argv[]} array passed into program. @var{arglen}
21640 specifies the number of bytes in the hex encoded byte stream @var{arg}.
21641 See @code{gdbserver} for more details.
21642
21643 Reply:
21644 @table @samp
21645 @item OK
21646 @item E@var{NN}
21647 @end table
21648
21649 @item @code{b}@var{baud} --- set baud @strong{(deprecated)}
21650 @cindex @code{b} packet
21651
21652 Change the serial line speed to @var{baud}.
21653
21654 JTC: @emph{When does the transport layer state change? When it's
21655 received, or after the ACK is transmitted. In either case, there are
21656 problems if the command or the acknowledgment packet is dropped.}
21657
21658 Stan: @emph{If people really wanted to add something like this, and get
21659 it working for the first time, they ought to modify ser-unix.c to send
21660 some kind of out-of-band message to a specially-setup stub and have the
21661 switch happen "in between" packets, so that from remote protocol's point
21662 of view, nothing actually happened.}
21663
21664 @item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
21665 @cindex @code{B} packet
21666
21667 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
21668 breakpoint at @var{addr}.
21669
21670 This packet has been replaced by the @samp{Z} and @samp{z} packets
21671 (@pxref{insert breakpoint or watchpoint packet}).
21672
21673 @item @code{c}@var{addr} --- continue
21674 @cindex @code{c} packet
21675
21676 @var{addr} is address to resume. If @var{addr} is omitted, resume at
21677 current address.
21678
21679 Reply:
21680 @xref{Stop Reply Packets}, for the reply specifications.
21681
21682 @item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
21683 @cindex @code{C} packet
21684
21685 Continue with signal @var{sig} (hex signal number). If
21686 @code{;}@var{addr} is omitted, resume at same address.
21687
21688 Reply:
21689 @xref{Stop Reply Packets}, for the reply specifications.
21690
21691 @item @code{d} --- toggle debug @strong{(deprecated)}
21692 @cindex @code{d} packet
21693
21694 Toggle debug flag.
21695
21696 @item @code{D} --- detach
21697 @cindex @code{D} packet
21698
21699 Detach @value{GDBN} from the remote system. Sent to the remote target
21700 before @value{GDBN} disconnects via the @code{detach} command.
21701
21702 Reply:
21703 @table @samp
21704 @item @emph{no response}
21705 @value{GDBN} does not check for any response after sending this packet.
21706 @end table
21707
21708 @item @code{e} --- reserved
21709
21710 Reserved for future use.
21711
21712 @item @code{E} --- reserved
21713
21714 Reserved for future use.
21715
21716 @item @code{f} --- reserved
21717
21718 Reserved for future use.
21719
21720 @item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
21721 @cindex @code{F} packet
21722
21723 This packet is send by @value{GDBN} as reply to a @code{F} request packet
21724 sent by the target. This is part of the File-I/O protocol extension.
21725 @xref{File-I/O remote protocol extension}, for the specification.
21726
21727 @item @code{g} --- read registers
21728 @anchor{read registers packet}
21729 @cindex @code{g} packet
21730
21731 Read general registers.
21732
21733 Reply:
21734 @table @samp
21735 @item @var{XX@dots{}}
21736 Each byte of register data is described by two hex digits. The bytes
21737 with the register are transmitted in target byte order. The size of
21738 each register and their position within the @samp{g} @var{packet} are
21739 determined by the @value{GDBN} internal macros
21740 @var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
21741 specification of several standard @code{g} packets is specified below.
21742 @item E@var{NN}
21743 for an error.
21744 @end table
21745
21746 @item @code{G}@var{XX@dots{}} --- write regs
21747 @cindex @code{G} packet
21748
21749 @xref{read registers packet}, for a description of the @var{XX@dots{}}
21750 data.
21751
21752 Reply:
21753 @table @samp
21754 @item OK
21755 for success
21756 @item E@var{NN}
21757 for an error
21758 @end table
21759
21760 @item @code{h} --- reserved
21761
21762 Reserved for future use.
21763
21764 @item @code{H}@var{c}@var{t@dots{}} --- set thread
21765 @cindex @code{H} packet
21766
21767 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
21768 @samp{G}, et.al.). @var{c} depends on the operation to be performed: it
21769 should be @samp{c} for step and continue operations, @samp{g} for other
21770 operations. The thread designator @var{t@dots{}} may be -1, meaning all
21771 the threads, a thread number, or zero which means pick any thread.
21772
21773 Reply:
21774 @table @samp
21775 @item OK
21776 for success
21777 @item E@var{NN}
21778 for an error
21779 @end table
21780
21781 @c FIXME: JTC:
21782 @c 'H': How restrictive (or permissive) is the thread model. If a
21783 @c thread is selected and stopped, are other threads allowed
21784 @c to continue to execute? As I mentioned above, I think the
21785 @c semantics of each command when a thread is selected must be
21786 @c described. For example:
21787 @c
21788 @c 'g': If the stub supports threads and a specific thread is
21789 @c selected, returns the register block from that thread;
21790 @c otherwise returns current registers.
21791 @c
21792 @c 'G' If the stub supports threads and a specific thread is
21793 @c selected, sets the registers of the register block of
21794 @c that thread; otherwise sets current registers.
21795
21796 @item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
21797 @anchor{cycle step packet}
21798 @cindex @code{i} packet
21799
21800 Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
21801 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
21802 step starting at that address.
21803
21804 @item @code{I} --- signal then cycle step @strong{(reserved)}
21805 @cindex @code{I} packet
21806
21807 @xref{step with signal packet}. @xref{cycle step packet}.
21808
21809 @item @code{j} --- reserved
21810
21811 Reserved for future use.
21812
21813 @item @code{J} --- reserved
21814
21815 Reserved for future use.
21816
21817 @item @code{k} --- kill request
21818 @cindex @code{k} packet
21819
21820 FIXME: @emph{There is no description of how to operate when a specific
21821 thread context has been selected (i.e.@: does 'k' kill only that
21822 thread?)}.
21823
21824 @item @code{K} --- reserved
21825
21826 Reserved for future use.
21827
21828 @item @code{l} --- reserved
21829
21830 Reserved for future use.
21831
21832 @item @code{L} --- reserved
21833
21834 Reserved for future use.
21835
21836 @item @code{m}@var{addr}@code{,}@var{length} --- read memory
21837 @cindex @code{m} packet
21838
21839 Read @var{length} bytes of memory starting at address @var{addr}.
21840 Neither @value{GDBN} nor the stub assume that sized memory transfers are
21841 assumed using word aligned accesses. FIXME: @emph{A word aligned memory
21842 transfer mechanism is needed.}
21843
21844 Reply:
21845 @table @samp
21846 @item @var{XX@dots{}}
21847 @var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
21848 to read only part of the data. Neither @value{GDBN} nor the stub assume
21849 that sized memory transfers are assumed using word aligned
21850 accesses. FIXME: @emph{A word aligned memory transfer mechanism is
21851 needed.}
21852 @item E@var{NN}
21853 @var{NN} is errno
21854 @end table
21855
21856 @item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
21857 @cindex @code{M} packet
21858
21859 Write @var{length} bytes of memory starting at address @var{addr}.
21860 @var{XX@dots{}} is the data.
21861
21862 Reply:
21863 @table @samp
21864 @item OK
21865 for success
21866 @item E@var{NN}
21867 for an error (this includes the case where only part of the data was
21868 written).
21869 @end table
21870
21871 @item @code{n} --- reserved
21872
21873 Reserved for future use.
21874
21875 @item @code{N} --- reserved
21876
21877 Reserved for future use.
21878
21879 @item @code{o} --- reserved
21880
21881 Reserved for future use.
21882
21883 @item @code{O} --- reserved
21884
21885 @item @code{p}@var{hex number of register} --- read register packet
21886 @cindex @code{p} packet
21887
21888 @xref{read registers packet}, for a description of how the returned
21889 register value is encoded.
21890
21891 Reply:
21892 @table @samp
21893 @item @var{XX@dots{}}
21894 the register's value
21895 @item E@var{NN}
21896 for an error
21897 @item
21898 Indicating an unrecognized @var{query}.
21899 @end table
21900
21901 @item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
21902 @anchor{write register packet}
21903 @cindex @code{P} packet
21904
21905 Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
21906 digits for each byte in the register (target byte order).
21907
21908 Reply:
21909 @table @samp
21910 @item OK
21911 for success
21912 @item E@var{NN}
21913 for an error
21914 @end table
21915
21916 @item @code{q}@var{query} --- general query
21917 @anchor{general query packet}
21918 @cindex @code{q} packet
21919
21920 Request info about @var{query}. In general @value{GDBN} queries have a
21921 leading upper case letter. Custom vendor queries should use a company
21922 prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
21923 be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
21924 that they match the full @var{query} name.
21925
21926 Reply:
21927 @table @samp
21928 @item @var{XX@dots{}}
21929 Hex encoded data from query. The reply can not be empty.
21930 @item E@var{NN}
21931 error reply
21932 @item
21933 Indicating an unrecognized @var{query}.
21934 @end table
21935
21936 @item @code{Q}@var{var}@code{=}@var{val} --- general set
21937 @cindex @code{Q} packet
21938
21939 Set value of @var{var} to @var{val}.
21940
21941 @xref{general query packet}, for a discussion of naming conventions.
21942
21943 @item @code{r} --- reset @strong{(deprecated)}
21944 @cindex @code{r} packet
21945
21946 Reset the entire system.
21947
21948 @item @code{R}@var{XX} --- remote restart
21949 @cindex @code{R} packet
21950
21951 Restart the program being debugged. @var{XX}, while needed, is ignored.
21952 This packet is only available in extended mode.
21953
21954 Reply:
21955 @table @samp
21956 @item @emph{no reply}
21957 The @samp{R} packet has no reply.
21958 @end table
21959
21960 @item @code{s}@var{addr} --- step
21961 @cindex @code{s} packet
21962
21963 @var{addr} is address to resume. If @var{addr} is omitted, resume at
21964 same address.
21965
21966 Reply:
21967 @xref{Stop Reply Packets}, for the reply specifications.
21968
21969 @item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
21970 @anchor{step with signal packet}
21971 @cindex @code{S} packet
21972
21973 Like @samp{C} but step not continue.
21974
21975 Reply:
21976 @xref{Stop Reply Packets}, for the reply specifications.
21977
21978 @item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
21979 @cindex @code{t} packet
21980
21981 Search backwards starting at address @var{addr} for a match with pattern
21982 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
21983 @var{addr} must be at least 3 digits.
21984
21985 @item @code{T}@var{XX} --- thread alive
21986 @cindex @code{T} packet
21987
21988 Find out if the thread XX is alive.
21989
21990 Reply:
21991 @table @samp
21992 @item OK
21993 thread is still alive
21994 @item E@var{NN}
21995 thread is dead
21996 @end table
21997
21998 @item @code{u} --- reserved
21999
22000 Reserved for future use.
22001
22002 @item @code{U} --- reserved
22003
22004 Reserved for future use.
22005
22006 @item @code{v} --- verbose packet prefix
22007
22008 Packets starting with @code{v} are identified by a multi-letter name,
22009 up to the first @code{;} or @code{?} (or the end of the packet).
22010
22011 @item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22012 @cindex @code{vCont} packet
22013
22014 Resume the inferior. Different actions may be specified for each thread.
22015 If an action is specified with no @var{tid}, then it is applied to any
22016 threads that don't have a specific action specified; if no default action is
22017 specified then other threads should remain stopped. Specifying multiple
22018 default actions is an error; specifying no actions is also an error.
22019 Thread IDs are specified in hexadecimal. Currently supported actions are:
22020
22021 @table @code
22022 @item c
22023 Continue.
22024 @item C@var{sig}
22025 Continue with signal @var{sig}. @var{sig} should be two hex digits.
22026 @item s
22027 Step.
22028 @item S@var{sig}
22029 Step with signal @var{sig}. @var{sig} should be two hex digits.
22030 @end table
22031
22032 The optional @var{addr} argument normally associated with these packets is
22033 not supported in @code{vCont}.
22034
22035 Reply:
22036 @xref{Stop Reply Packets}, for the reply specifications.
22037
22038 @item @code{vCont?} --- extended resume query
22039 @cindex @code{vCont?} packet
22040
22041 Query support for the @code{vCont} packet.
22042
22043 Reply:
22044 @table @samp
22045 @item @code{vCont}[;@var{action}]...
22046 The @code{vCont} packet is supported. Each @var{action} is a supported
22047 command in the @code{vCont} packet.
22048 @item
22049 The @code{vCont} packet is not supported.
22050 @end table
22051
22052 @item @code{V} --- reserved
22053
22054 Reserved for future use.
22055
22056 @item @code{w} --- reserved
22057
22058 Reserved for future use.
22059
22060 @item @code{W} --- reserved
22061
22062 Reserved for future use.
22063
22064 @item @code{x} --- reserved
22065
22066 Reserved for future use.
22067
22068 @item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22069 @cindex @code{X} packet
22070
22071 @var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22072 is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
22073 escaped using @code{0x7d}, and then XORed with @code{0x20}.
22074 For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
22075
22076 Reply:
22077 @table @samp
22078 @item OK
22079 for success
22080 @item E@var{NN}
22081 for an error
22082 @end table
22083
22084 @item @code{y} --- reserved
22085
22086 Reserved for future use.
22087
22088 @item @code{Y} reserved
22089
22090 Reserved for future use.
22091
22092 @item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22093 @itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22094 @anchor{insert breakpoint or watchpoint packet}
22095 @cindex @code{z} packet
22096 @cindex @code{Z} packets
22097
22098 Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22099 watchpoint starting at address @var{address} and covering the next
22100 @var{length} bytes.
22101
22102 Each breakpoint and watchpoint packet @var{type} is documented
22103 separately.
22104
22105 @emph{Implementation notes: A remote target shall return an empty string
22106 for an unrecognized breakpoint or watchpoint packet @var{type}. A
22107 remote target shall support either both or neither of a given
22108 @code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22109 avoid potential problems with duplicate packets, the operations should
22110 be implemented in an idempotent way.}
22111
22112 @item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22113 @item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22114 @cindex @code{z0} packet
22115 @cindex @code{Z0} packet
22116
22117 Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22118 @code{addr} of size @code{length}.
22119
22120 A memory breakpoint is implemented by replacing the instruction at
22121 @var{addr} with a software breakpoint or trap instruction. The
22122 @code{length} is used by targets that indicates the size of the
22123 breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22124 @sc{mips} can insert either a 2 or 4 byte breakpoint).
22125
22126 @emph{Implementation note: It is possible for a target to copy or move
22127 code that contains memory breakpoints (e.g., when implementing
22128 overlays). The behavior of this packet, in the presence of such a
22129 target, is not defined.}
22130
22131 Reply:
22132 @table @samp
22133 @item OK
22134 success
22135 @item
22136 not supported
22137 @item E@var{NN}
22138 for an error
22139 @end table
22140
22141 @item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22142 @item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22143 @cindex @code{z1} packet
22144 @cindex @code{Z1} packet
22145
22146 Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22147 address @code{addr} of size @code{length}.
22148
22149 A hardware breakpoint is implemented using a mechanism that is not
22150 dependant on being able to modify the target's memory.
22151
22152 @emph{Implementation note: A hardware breakpoint is not affected by code
22153 movement.}
22154
22155 Reply:
22156 @table @samp
22157 @item OK
22158 success
22159 @item
22160 not supported
22161 @item E@var{NN}
22162 for an error
22163 @end table
22164
22165 @item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22166 @item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22167 @cindex @code{z2} packet
22168 @cindex @code{Z2} packet
22169
22170 Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22171
22172 Reply:
22173 @table @samp
22174 @item OK
22175 success
22176 @item
22177 not supported
22178 @item E@var{NN}
22179 for an error
22180 @end table
22181
22182 @item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22183 @item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22184 @cindex @code{z3} packet
22185 @cindex @code{Z3} packet
22186
22187 Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
22188
22189 Reply:
22190 @table @samp
22191 @item OK
22192 success
22193 @item
22194 not supported
22195 @item E@var{NN}
22196 for an error
22197 @end table
22198
22199 @item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22200 @item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
22201 @cindex @code{z4} packet
22202 @cindex @code{Z4} packet
22203
22204 Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22205
22206 Reply:
22207 @table @samp
22208 @item OK
22209 success
22210 @item
22211 not supported
22212 @item E@var{NN}
22213 for an error
22214 @end table
22215
22216 @end table
22217
22218 @node Stop Reply Packets
22219 @section Stop Reply Packets
22220 @cindex stop reply packets
22221
22222 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22223 receive any of the below as a reply. In the case of the @samp{C},
22224 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22225 when the target halts. In the below the exact meaning of @samp{signal
22226 number} is poorly defined. In general one of the UNIX signal numbering
22227 conventions is used.
22228
22229 @table @samp
22230
22231 @item S@var{AA}
22232 @var{AA} is the signal number
22233
22234 @item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
22235 @cindex @code{T} packet reply
22236
22237 @var{AA} = two hex digit signal number; @var{n...} = register number
22238 (hex), @var{r...} = target byte ordered register contents, size defined
22239 by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22240 @var{r...} = thread process ID, this is a hex integer; @var{n...} =
22241 (@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22242 address, this is a hex integer; @var{n...} = other string not starting
22243 with valid hex digit. @value{GDBN} should ignore this @var{n...},
22244 @var{r...} pair and go on to the next. This way we can extend the
22245 protocol.
22246
22247 @item W@var{AA}
22248
22249 The process exited, and @var{AA} is the exit status. This is only
22250 applicable to certain targets.
22251
22252 @item X@var{AA}
22253
22254 The process terminated with signal @var{AA}.
22255
22256 @item O@var{XX@dots{}}
22257
22258 @var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22259 any time while the program is running and the debugger should continue
22260 to wait for @samp{W}, @samp{T}, etc.
22261
22262 @item F@var{call-id}@code{,}@var{parameter@dots{}}
22263
22264 @var{call-id} is the identifier which says which host system call should
22265 be called. This is just the name of the function. Translation into the
22266 correct system call is only applicable as it's defined in @value{GDBN}.
22267 @xref{File-I/O remote protocol extension}, for a list of implemented
22268 system calls.
22269
22270 @var{parameter@dots{}} is a list of parameters as defined for this very
22271 system call.
22272
22273 The target replies with this packet when it expects @value{GDBN} to call
22274 a host system call on behalf of the target. @value{GDBN} replies with
22275 an appropriate @code{F} packet and keeps up waiting for the next reply
22276 packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22277 @samp{s} action is expected to be continued.
22278 @xref{File-I/O remote protocol extension}, for more details.
22279
22280 @end table
22281
22282 @node General Query Packets
22283 @section General Query Packets
22284 @cindex remote query requests
22285
22286 The following set and query packets have already been defined.
22287
22288 @table @r
22289
22290 @item @code{q}@code{C} --- current thread
22291 @cindex current thread, remote request
22292 @cindex @code{qC} packet
22293 Return the current thread id.
22294
22295 Reply:
22296 @table @samp
22297 @item @code{QC}@var{pid}
22298 Where @var{pid} is an unsigned hexidecimal process id.
22299 @item *
22300 Any other reply implies the old pid.
22301 @end table
22302
22303 @item @code{q}@code{fThreadInfo} -- all thread ids
22304 @cindex list active threads, remote request
22305 @cindex @code{qfThreadInfo} packet
22306 @code{q}@code{sThreadInfo}
22307
22308 Obtain a list of active thread ids from the target (OS). Since there
22309 may be too many active threads to fit into one reply packet, this query
22310 works iteratively: it may require more than one query/reply sequence to
22311 obtain the entire list of threads. The first query of the sequence will
22312 be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22313 sequence will be the @code{qs}@code{ThreadInfo} query.
22314
22315 NOTE: replaces the @code{qL} query (see below).
22316
22317 Reply:
22318 @table @samp
22319 @item @code{m}@var{id}
22320 A single thread id
22321 @item @code{m}@var{id},@var{id}@dots{}
22322 a comma-separated list of thread ids
22323 @item @code{l}
22324 (lower case 'el') denotes end of list.
22325 @end table
22326
22327 In response to each query, the target will reply with a list of one or
22328 more thread ids, in big-endian unsigned hex, separated by commas.
22329 @value{GDBN} will respond to each reply with a request for more thread
22330 ids (using the @code{qs} form of the query), until the target responds
22331 with @code{l} (lower-case el, for @code{'last'}).
22332
22333 @item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
22334 @cindex thread attributes info, remote request
22335 @cindex @code{qThreadExtraInfo} packet
22336 Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22337 string description of a thread's attributes from the target OS. This
22338 string may contain anything that the target OS thinks is interesting for
22339 @value{GDBN} to tell the user about the thread. The string is displayed
22340 in @value{GDBN}'s @samp{info threads} display. Some examples of
22341 possible thread extra info strings are ``Runnable'', or ``Blocked on
22342 Mutex''.
22343
22344 Reply:
22345 @table @samp
22346 @item @var{XX@dots{}}
22347 Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22348 the printable string containing the extra information about the thread's
22349 attributes.
22350 @end table
22351
22352 @item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
22353
22354 Obtain thread information from RTOS. Where: @var{startflag} (one hex
22355 digit) is one to indicate the first query and zero to indicate a
22356 subsequent query; @var{threadcount} (two hex digits) is the maximum
22357 number of threads the response packet can contain; and @var{nextthread}
22358 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
22359 returned in the response as @var{argthread}.
22360
22361 NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22362 (see above).
22363
22364 Reply:
22365 @table @samp
22366 @item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
22367 Where: @var{count} (two hex digits) is the number of threads being
22368 returned; @var{done} (one hex digit) is zero to indicate more threads
22369 and one indicates no further threads; @var{argthreadid} (eight hex
22370 digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22371 is a sequence of thread IDs from the target. @var{threadid} (eight hex
22372 digits). See @code{remote.c:parse_threadlist_response()}.
22373 @end table
22374
22375 @item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
22376 @cindex CRC of memory block, remote request
22377 @cindex @code{qCRC} packet
22378 Reply:
22379 @table @samp
22380 @item @code{E}@var{NN}
22381 An error (such as memory fault)
22382 @item @code{C}@var{CRC32}
22383 A 32 bit cyclic redundancy check of the specified memory region.
22384 @end table
22385
22386 @item @code{q}@code{Offsets} --- query sect offs
22387 @cindex section offsets, remote request
22388 @cindex @code{qOffsets} packet
22389 Get section offsets that the target used when re-locating the downloaded
22390 image. @emph{Note: while a @code{Bss} offset is included in the
22391 response, @value{GDBN} ignores this and instead applies the @code{Data}
22392 offset to the @code{Bss} section.}
22393
22394 Reply:
22395 @table @samp
22396 @item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22397 @end table
22398
22399 @item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
22400 @cindex thread information, remote request
22401 @cindex @code{qP} packet
22402 Returns information on @var{threadid}. Where: @var{mode} is a hex
22403 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
22404
22405 Reply:
22406 @table @samp
22407 @item *
22408 @end table
22409
22410 See @code{remote.c:remote_unpack_thread_info_response()}.
22411
22412 @item @code{q}@code{Rcmd,}@var{command} --- remote command
22413 @cindex execute remote command, remote request
22414 @cindex @code{qRcmd} packet
22415 @var{command} (hex encoded) is passed to the local interpreter for
22416 execution. Invalid commands should be reported using the output string.
22417 Before the final result packet, the target may also respond with a
22418 number of intermediate @code{O}@var{output} console output packets.
22419 @emph{Implementors should note that providing access to a stubs's
22420 interpreter may have security implications}.
22421
22422 Reply:
22423 @table @samp
22424 @item OK
22425 A command response with no output.
22426 @item @var{OUTPUT}
22427 A command response with the hex encoded output string @var{OUTPUT}.
22428 @item @code{E}@var{NN}
22429 Indicate a badly formed request.
22430 @item @samp{}
22431 When @samp{q}@samp{Rcmd} is not recognized.
22432 @end table
22433 z
22434 @item @code{qSymbol::} --- symbol lookup
22435 @cindex symbol lookup, remote request
22436 @cindex @code{qSymbol} packet
22437 Notify the target that @value{GDBN} is prepared to serve symbol lookup
22438 requests. Accept requests from the target for the values of symbols.
22439
22440 Reply:
22441 @table @samp
22442 @item @code{OK}
22443 The target does not need to look up any (more) symbols.
22444 @item @code{qSymbol:}@var{sym_name}
22445 The target requests the value of symbol @var{sym_name} (hex encoded).
22446 @value{GDBN} may provide the value by using the
22447 @code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22448 @end table
22449
22450 @item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22451
22452 Set the value of @var{sym_name} to @var{sym_value}.
22453
22454 @var{sym_name} (hex encoded) is the name of a symbol whose value the
22455 target has previously requested.
22456
22457 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22458 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
22459 will be empty.
22460
22461 Reply:
22462 @table @samp
22463 @item @code{OK}
22464 The target does not need to look up any (more) symbols.
22465 @item @code{qSymbol:}@var{sym_name}
22466 The target requests the value of a new symbol @var{sym_name} (hex
22467 encoded). @value{GDBN} will continue to supply the values of symbols
22468 (if available), until the target ceases to request them.
22469 @end table
22470
22471 @item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
22472 @cindex read special object, remote request
22473 @cindex @code{qPart} packet
22474 Read uninterpreted bytes from the target's special data area
22475 identified by the keyword @code{object}.
22476 Request @var{length} bytes starting at @var{offset} bytes into the data.
22477 The content and encoding of @var{annex} is specific to the object;
22478 it can supply additional details about what data to access.
22479
22480 Here are the specific requests of this form defined so far.
22481 All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22482 requests use the same reply formats, listed below.
22483
22484 @table @asis
22485 @item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
22486 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22487 auxiliary vector}, and see @ref{Remote configuration,
22488 read-aux-vector-packet}. Note @var{annex} must be empty.
22489 @end table
22490
22491 Reply:
22492 @table @asis
22493 @item @code{OK}
22494 The @var{offset} in the request is at the end of the data.
22495 There is no more data to be read.
22496
22497 @item @var{XX@dots{}}
22498 Hex encoded data bytes read.
22499 This may be fewer bytes than the @var{length} in the request.
22500
22501 @item @code{E00}
22502 The request was malformed, or @var{annex} was invalid.
22503
22504 @item @code{E}@var{nn}
22505 The offset was invalid, or there was an error encountered reading the data.
22506 @var{nn} is a hex-encoded @code{errno} value.
22507
22508 @item @code{""} (empty)
22509 An empty reply indicates the @var{object} or @var{annex} string was not
22510 recognized by the stub.
22511 @end table
22512
22513 @item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
22514 @cindex write data into object, remote request
22515 Write uninterpreted bytes into the target's special data area
22516 identified by the keyword @code{object},
22517 starting at @var{offset} bytes into the data.
22518 @var{data@dots{}} is the hex-encoded data to be written.
22519 The content and encoding of @var{annex} is specific to the object;
22520 it can supply additional details about what data to access.
22521
22522 No requests of this form are presently in use. This specification
22523 serves as a placeholder to document the common format that new
22524 specific request specifications ought to use.
22525
22526 Reply:
22527 @table @asis
22528 @item @var{nn}
22529 @var{nn} (hex encoded) is the number of bytes written.
22530 This may be fewer bytes than supplied in the request.
22531
22532 @item @code{E00}
22533 The request was malformed, or @var{annex} was invalid.
22534
22535 @item @code{E}@var{nn}
22536 The offset was invalid, or there was an error encountered writing the data.
22537 @var{nn} is a hex-encoded @code{errno} value.
22538
22539 @item @code{""} (empty)
22540 An empty reply indicates the @var{object} or @var{annex} string was not
22541 recognized by the stub, or that the object does not support writing.
22542 @end table
22543
22544 @item @code{qPart}:@var{object}:@var{operation}:@dots{}
22545 Requests of this form may be added in the future. When a stub does
22546 not recognize the @var{object} keyword, or its support for
22547 @var{object} does not recognize the @var{operation} keyword,
22548 the stub must respond with an empty packet.
22549
22550 @item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
22551 @cindex get thread-local storage address, remote request
22552 @cindex @code{qGetTLSAddr} packet
22553 Fetch the address associated with thread local storage specified
22554 by @var{thread-id}, @var{offset}, and @var{lm}.
22555
22556 @var{thread-id} is the (big endian, hex encoded) thread id associated with the
22557 thread for which to fetch the TLS address.
22558
22559 @var{offset} is the (big endian, hex encoded) offset associated with the
22560 thread local variable. (This offset is obtained from the debug
22561 information associated with the variable.)
22562
22563 @var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22564 the load module associated with the thread local storage. For example,
22565 a @sc{gnu}/Linux system will pass the link map address of the shared
22566 object associated with the thread local storage under consideration.
22567 Other operating environments may choose to represent the load module
22568 differently, so the precise meaning of this parameter will vary.
22569
22570 Reply:
22571 @table @asis
22572 @item @var{XX@dots{}}
22573 Hex encoded (big endian) bytes representing the address of the thread
22574 local storage requested.
22575
22576 @item @code{E}@var{nn} (where @var{nn} are hex digits)
22577 An error occurred.
22578
22579 @item @code{""} (empty)
22580 An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22581 @end table
22582
22583 @end table
22584
22585 @node Register Packet Format
22586 @section Register Packet Format
22587
22588 The following @samp{g}/@samp{G} packets have previously been defined.
22589 In the below, some thirty-two bit registers are transferred as
22590 sixty-four bits. Those registers should be zero/sign extended (which?)
22591 to fill the space allocated. Register bytes are transfered in target
22592 byte order. The two nibbles within a register byte are transfered
22593 most-significant - least-significant.
22594
22595 @table @r
22596
22597 @item MIPS32
22598
22599 All registers are transfered as thirty-two bit quantities in the order:
22600 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22601 registers; fsr; fir; fp.
22602
22603 @item MIPS64
22604
22605 All registers are transfered as sixty-four bit quantities (including
22606 thirty-two bit registers such as @code{sr}). The ordering is the same
22607 as @code{MIPS32}.
22608
22609 @end table
22610
22611 @node Examples
22612 @section Examples
22613
22614 Example sequence of a target being re-started. Notice how the restart
22615 does not get any direct output:
22616
22617 @smallexample
22618 -> @code{R00}
22619 <- @code{+}
22620 @emph{target restarts}
22621 -> @code{?}
22622 <- @code{+}
22623 <- @code{T001:1234123412341234}
22624 -> @code{+}
22625 @end smallexample
22626
22627 Example sequence of a target being stepped by a single instruction:
22628
22629 @smallexample
22630 -> @code{G1445@dots{}}
22631 <- @code{+}
22632 -> @code{s}
22633 <- @code{+}
22634 @emph{time passes}
22635 <- @code{T001:1234123412341234}
22636 -> @code{+}
22637 -> @code{g}
22638 <- @code{+}
22639 <- @code{1455@dots{}}
22640 -> @code{+}
22641 @end smallexample
22642
22643 @node File-I/O remote protocol extension
22644 @section File-I/O remote protocol extension
22645 @cindex File-I/O remote protocol extension
22646
22647 @menu
22648 * File-I/O Overview::
22649 * Protocol basics::
22650 * The F request packet::
22651 * The F reply packet::
22652 * Memory transfer::
22653 * The Ctrl-C message::
22654 * Console I/O::
22655 * The isatty call::
22656 * The system call::
22657 * List of supported calls::
22658 * Protocol specific representation of datatypes::
22659 * Constants::
22660 * File-I/O Examples::
22661 @end menu
22662
22663 @node File-I/O Overview
22664 @subsection File-I/O Overview
22665 @cindex file-i/o overview
22666
22667 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
22668 target to use the host's file system and console I/O when calling various
22669 system calls. System calls on the target system are translated into a
22670 remote protocol packet to the host system which then performs the needed
22671 actions and returns with an adequate response packet to the target system.
22672 This simulates file system operations even on targets that lack file systems.
22673
22674 The protocol is defined host- and target-system independent. It uses
22675 its own independent representation of datatypes and values. Both,
22676 @value{GDBN} and the target's @value{GDBN} stub are responsible for
22677 translating the system dependent values into the unified protocol values
22678 when data is transmitted.
22679
22680 The communication is synchronous. A system call is possible only
22681 when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
22682 packets. While @value{GDBN} handles the request for a system call,
22683 the target is stopped to allow deterministic access to the target's
22684 memory. Therefore File-I/O is not interuptible by target signals. It
22685 is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
22686
22687 The target's request to perform a host system call does not finish
22688 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
22689 after finishing the system call, the target returns to continuing the
22690 previous activity (continue, step). No additional continue or step
22691 request from @value{GDBN} is required.
22692
22693 @smallexample
22694 (@value{GDBP}) continue
22695 <- target requests 'system call X'
22696 target is stopped, @value{GDBN} executes system call
22697 -> GDB returns result
22698 ... target continues, GDB returns to wait for the target
22699 <- target hits breakpoint and sends a Txx packet
22700 @end smallexample
22701
22702 The protocol is only used for files on the host file system and
22703 for I/O on the console. Character or block special devices, pipes,
22704 named pipes or sockets or any other communication method on the host
22705 system are not supported by this protocol.
22706
22707 @node Protocol basics
22708 @subsection Protocol basics
22709 @cindex protocol basics, file-i/o
22710
22711 The File-I/O protocol uses the @code{F} packet, as request as well
22712 as as reply packet. Since a File-I/O system call can only occur when
22713 @value{GDBN} is waiting for the continuing or stepping target, the
22714 File-I/O request is a reply that @value{GDBN} has to expect as a result
22715 of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
22716 This @code{F} packet contains all information needed to allow @value{GDBN}
22717 to call the appropriate host system call:
22718
22719 @itemize @bullet
22720 @item
22721 A unique identifier for the requested system call.
22722
22723 @item
22724 All parameters to the system call. Pointers are given as addresses
22725 in the target memory address space. Pointers to strings are given as
22726 pointer/length pair. Numerical values are given as they are.
22727 Numerical control values are given in a protocol specific representation.
22728
22729 @end itemize
22730
22731 At that point @value{GDBN} has to perform the following actions.
22732
22733 @itemize @bullet
22734 @item
22735 If parameter pointer values are given, which point to data needed as input
22736 to a system call, @value{GDBN} requests this data from the target with a
22737 standard @code{m} packet request. This additional communication has to be
22738 expected by the target implementation and is handled as any other @code{m}
22739 packet.
22740
22741 @item
22742 @value{GDBN} translates all value from protocol representation to host
22743 representation as needed. Datatypes are coerced into the host types.
22744
22745 @item
22746 @value{GDBN} calls the system call
22747
22748 @item
22749 It then coerces datatypes back to protocol representation.
22750
22751 @item
22752 If pointer parameters in the request packet point to buffer space in which
22753 a system call is expected to copy data to, the data is transmitted to the
22754 target using a @code{M} or @code{X} packet. This packet has to be expected
22755 by the target implementation and is handled as any other @code{M} or @code{X}
22756 packet.
22757
22758 @end itemize
22759
22760 Eventually @value{GDBN} replies with another @code{F} packet which contains all
22761 necessary information for the target to continue. This at least contains
22762
22763 @itemize @bullet
22764 @item
22765 Return value.
22766
22767 @item
22768 @code{errno}, if has been changed by the system call.
22769
22770 @item
22771 ``Ctrl-C'' flag.
22772
22773 @end itemize
22774
22775 After having done the needed type and value coercion, the target continues
22776 the latest continue or step action.
22777
22778 @node The F request packet
22779 @subsection The @code{F} request packet
22780 @cindex file-i/o request packet
22781 @cindex @code{F} request packet
22782
22783 The @code{F} request packet has the following format:
22784
22785 @table @samp
22786
22787 @smallexample
22788 @code{F}@var{call-id}@code{,}@var{parameter@dots{}}
22789 @end smallexample
22790
22791 @var{call-id} is the identifier to indicate the host system call to be called.
22792 This is just the name of the function.
22793
22794 @var{parameter@dots{}} are the parameters to the system call.
22795
22796 @end table
22797
22798 Parameters are hexadecimal integer values, either the real values in case
22799 of scalar datatypes, as pointers to target buffer space in case of compound
22800 datatypes and unspecified memory areas or as pointer/length pairs in case
22801 of string parameters. These are appended to the call-id, each separated
22802 from its predecessor by a comma. All values are transmitted in ASCII
22803 string representation, pointer/length pairs separated by a slash.
22804
22805 @node The F reply packet
22806 @subsection The @code{F} reply packet
22807 @cindex file-i/o reply packet
22808 @cindex @code{F} reply packet
22809
22810 The @code{F} reply packet has the following format:
22811
22812 @table @samp
22813
22814 @smallexample
22815 @code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
22816 @end smallexample
22817
22818 @var{retcode} is the return code of the system call as hexadecimal value.
22819
22820 @var{errno} is the errno set by the call, in protocol specific representation.
22821 This parameter can be omitted if the call was successful.
22822
22823 @var{Ctrl-C flag} is only send if the user requested a break. In this
22824 case, @var{errno} must be send as well, even if the call was successful.
22825 The @var{Ctrl-C flag} itself consists of the character 'C':
22826
22827 @smallexample
22828 F0,0,C
22829 @end smallexample
22830
22831 @noindent
22832 or, if the call was interupted before the host call has been performed:
22833
22834 @smallexample
22835 F-1,4,C
22836 @end smallexample
22837
22838 @noindent
22839 assuming 4 is the protocol specific representation of @code{EINTR}.
22840
22841 @end table
22842
22843 @node Memory transfer
22844 @subsection Memory transfer
22845 @cindex memory transfer, in file-i/o protocol
22846
22847 Structured data which is transferred using a memory read or write as e.g.@:
22848 a @code{struct stat} is expected to be in a protocol specific format with
22849 all scalar multibyte datatypes being big endian. This should be done by
22850 the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
22851 it transfers memory to the target. Transferred pointers to structured
22852 data should point to the already coerced data at any time.
22853
22854 @node The Ctrl-C message
22855 @subsection The Ctrl-C message
22856 @cindex ctrl-c message, in file-i/o protocol
22857
22858 A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
22859 reply packet. In this case the target should behave, as if it had
22860 gotten a break message. The meaning for the target is ``system call
22861 interupted by @code{SIGINT}''. Consequentially, the target should actually stop
22862 (as with a break message) and return to @value{GDBN} with a @code{T02}
22863 packet. In this case, it's important for the target to know, in which
22864 state the system call was interrupted. Since this action is by design
22865 not an atomic operation, we have to differ between two cases:
22866
22867 @itemize @bullet
22868 @item
22869 The system call hasn't been performed on the host yet.
22870
22871 @item
22872 The system call on the host has been finished.
22873
22874 @end itemize
22875
22876 These two states can be distinguished by the target by the value of the
22877 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
22878 call hasn't been performed. This is equivalent to the @code{EINTR} handling
22879 on POSIX systems. In any other case, the target may presume that the
22880 system call has been finished --- successful or not --- and should behave
22881 as if the break message arrived right after the system call.
22882
22883 @value{GDBN} must behave reliable. If the system call has not been called
22884 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
22885 @code{errno} in the packet. If the system call on the host has been finished
22886 before the user requests a break, the full action must be finshed by
22887 @value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
22888 The @code{F} packet may only be send when either nothing has happened
22889 or the full action has been completed.
22890
22891 @node Console I/O
22892 @subsection Console I/O
22893 @cindex console i/o as part of file-i/o
22894
22895 By default and if not explicitely closed by the target system, the file
22896 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
22897 on the @value{GDBN} console is handled as any other file output operation
22898 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
22899 by @value{GDBN} so that after the target read request from file descriptor
22900 0 all following typing is buffered until either one of the following
22901 conditions is met:
22902
22903 @itemize @bullet
22904 @item
22905 The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
22906 @code{read}
22907 system call is treated as finished.
22908
22909 @item
22910 The user presses @kbd{Enter}. This is treated as end of input with a trailing
22911 line feed.
22912
22913 @item
22914 The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
22915 character, especially no Ctrl-D is appended to the input.
22916
22917 @end itemize
22918
22919 If the user has typed more characters as fit in the buffer given to
22920 the read call, the trailing characters are buffered in @value{GDBN} until
22921 either another @code{read(0, @dots{})} is requested by the target or debugging
22922 is stopped on users request.
22923
22924 @node The isatty call
22925 @subsection The isatty(3) call
22926 @cindex isatty call, file-i/o protocol
22927
22928 A special case in this protocol is the library call @code{isatty} which
22929 is implemented as its own call inside of this protocol. It returns
22930 1 to the target if the file descriptor given as parameter is attached
22931 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
22932 would require implementing @code{ioctl} and would be more complex than
22933 needed.
22934
22935 @node The system call
22936 @subsection The system(3) call
22937 @cindex system call, file-i/o protocol
22938
22939 The other special case in this protocol is the @code{system} call which
22940 is implemented as its own call, too. @value{GDBN} is taking over the full
22941 task of calling the necessary host calls to perform the @code{system}
22942 call. The return value of @code{system} is simplified before it's returned
22943 to the target. Basically, the only signal transmitted back is @code{EINTR}
22944 in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
22945 entirely of the exit status of the called command.
22946
22947 Due to security concerns, the @code{system} call is by default refused
22948 by @value{GDBN}. The user has to allow this call explicitly with the
22949 @kbd{set remote system-call-allowed 1} command.
22950
22951 @table @code
22952 @item set remote system-call-allowed
22953 @kindex set remote system-call-allowed
22954 Control whether to allow the @code{system} calls in the File I/O
22955 protocol for the remote target. The default is zero (disabled).
22956
22957 @item show remote system-call-allowed
22958 @kindex show remote system-call-allowed
22959 Show the current setting of system calls for the remote File I/O
22960 protocol.
22961 @end table
22962
22963 @node List of supported calls
22964 @subsection List of supported calls
22965 @cindex list of supported file-i/o calls
22966
22967 @menu
22968 * open::
22969 * close::
22970 * read::
22971 * write::
22972 * lseek::
22973 * rename::
22974 * unlink::
22975 * stat/fstat::
22976 * gettimeofday::
22977 * isatty::
22978 * system::
22979 @end menu
22980
22981 @node open
22982 @unnumberedsubsubsec open
22983 @cindex open, file-i/o system call
22984
22985 @smallexample
22986 @exdent Synopsis:
22987 int open(const char *pathname, int flags);
22988 int open(const char *pathname, int flags, mode_t mode);
22989
22990 @exdent Request:
22991 Fopen,pathptr/len,flags,mode
22992 @end smallexample
22993
22994 @noindent
22995 @code{flags} is the bitwise or of the following values:
22996
22997 @table @code
22998 @item O_CREAT
22999 If the file does not exist it will be created. The host
23000 rules apply as far as file ownership and time stamps
23001 are concerned.
23002
23003 @item O_EXCL
23004 When used with O_CREAT, if the file already exists it is
23005 an error and open() fails.
23006
23007 @item O_TRUNC
23008 If the file already exists and the open mode allows
23009 writing (O_RDWR or O_WRONLY is given) it will be
23010 truncated to length 0.
23011
23012 @item O_APPEND
23013 The file is opened in append mode.
23014
23015 @item O_RDONLY
23016 The file is opened for reading only.
23017
23018 @item O_WRONLY
23019 The file is opened for writing only.
23020
23021 @item O_RDWR
23022 The file is opened for reading and writing.
23023
23024 @noindent
23025 Each other bit is silently ignored.
23026
23027 @end table
23028
23029 @noindent
23030 @code{mode} is the bitwise or of the following values:
23031
23032 @table @code
23033 @item S_IRUSR
23034 User has read permission.
23035
23036 @item S_IWUSR
23037 User has write permission.
23038
23039 @item S_IRGRP
23040 Group has read permission.
23041
23042 @item S_IWGRP
23043 Group has write permission.
23044
23045 @item S_IROTH
23046 Others have read permission.
23047
23048 @item S_IWOTH
23049 Others have write permission.
23050
23051 @noindent
23052 Each other bit is silently ignored.
23053
23054 @end table
23055
23056 @smallexample
23057 @exdent Return value:
23058 open returns the new file descriptor or -1 if an error
23059 occured.
23060
23061 @exdent Errors:
23062 @end smallexample
23063
23064 @table @code
23065 @item EEXIST
23066 pathname already exists and O_CREAT and O_EXCL were used.
23067
23068 @item EISDIR
23069 pathname refers to a directory.
23070
23071 @item EACCES
23072 The requested access is not allowed.
23073
23074 @item ENAMETOOLONG
23075 pathname was too long.
23076
23077 @item ENOENT
23078 A directory component in pathname does not exist.
23079
23080 @item ENODEV
23081 pathname refers to a device, pipe, named pipe or socket.
23082
23083 @item EROFS
23084 pathname refers to a file on a read-only filesystem and
23085 write access was requested.
23086
23087 @item EFAULT
23088 pathname is an invalid pointer value.
23089
23090 @item ENOSPC
23091 No space on device to create the file.
23092
23093 @item EMFILE
23094 The process already has the maximum number of files open.
23095
23096 @item ENFILE
23097 The limit on the total number of files open on the system
23098 has been reached.
23099
23100 @item EINTR
23101 The call was interrupted by the user.
23102 @end table
23103
23104 @node close
23105 @unnumberedsubsubsec close
23106 @cindex close, file-i/o system call
23107
23108 @smallexample
23109 @exdent Synopsis:
23110 int close(int fd);
23111
23112 @exdent Request:
23113 Fclose,fd
23114
23115 @exdent Return value:
23116 close returns zero on success, or -1 if an error occurred.
23117
23118 @exdent Errors:
23119 @end smallexample
23120
23121 @table @code
23122 @item EBADF
23123 fd isn't a valid open file descriptor.
23124
23125 @item EINTR
23126 The call was interrupted by the user.
23127 @end table
23128
23129 @node read
23130 @unnumberedsubsubsec read
23131 @cindex read, file-i/o system call
23132
23133 @smallexample
23134 @exdent Synopsis:
23135 int read(int fd, void *buf, unsigned int count);
23136
23137 @exdent Request:
23138 Fread,fd,bufptr,count
23139
23140 @exdent Return value:
23141 On success, the number of bytes read is returned.
23142 Zero indicates end of file. If count is zero, read
23143 returns zero as well. On error, -1 is returned.
23144
23145 @exdent Errors:
23146 @end smallexample
23147
23148 @table @code
23149 @item EBADF
23150 fd is not a valid file descriptor or is not open for
23151 reading.
23152
23153 @item EFAULT
23154 buf is an invalid pointer value.
23155
23156 @item EINTR
23157 The call was interrupted by the user.
23158 @end table
23159
23160 @node write
23161 @unnumberedsubsubsec write
23162 @cindex write, file-i/o system call
23163
23164 @smallexample
23165 @exdent Synopsis:
23166 int write(int fd, const void *buf, unsigned int count);
23167
23168 @exdent Request:
23169 Fwrite,fd,bufptr,count
23170
23171 @exdent Return value:
23172 On success, the number of bytes written are returned.
23173 Zero indicates nothing was written. On error, -1
23174 is returned.
23175
23176 @exdent Errors:
23177 @end smallexample
23178
23179 @table @code
23180 @item EBADF
23181 fd is not a valid file descriptor or is not open for
23182 writing.
23183
23184 @item EFAULT
23185 buf is an invalid pointer value.
23186
23187 @item EFBIG
23188 An attempt was made to write a file that exceeds the
23189 host specific maximum file size allowed.
23190
23191 @item ENOSPC
23192 No space on device to write the data.
23193
23194 @item EINTR
23195 The call was interrupted by the user.
23196 @end table
23197
23198 @node lseek
23199 @unnumberedsubsubsec lseek
23200 @cindex lseek, file-i/o system call
23201
23202 @smallexample
23203 @exdent Synopsis:
23204 long lseek (int fd, long offset, int flag);
23205
23206 @exdent Request:
23207 Flseek,fd,offset,flag
23208 @end smallexample
23209
23210 @code{flag} is one of:
23211
23212 @table @code
23213 @item SEEK_SET
23214 The offset is set to offset bytes.
23215
23216 @item SEEK_CUR
23217 The offset is set to its current location plus offset
23218 bytes.
23219
23220 @item SEEK_END
23221 The offset is set to the size of the file plus offset
23222 bytes.
23223 @end table
23224
23225 @smallexample
23226 @exdent Return value:
23227 On success, the resulting unsigned offset in bytes from
23228 the beginning of the file is returned. Otherwise, a
23229 value of -1 is returned.
23230
23231 @exdent Errors:
23232 @end smallexample
23233
23234 @table @code
23235 @item EBADF
23236 fd is not a valid open file descriptor.
23237
23238 @item ESPIPE
23239 fd is associated with the @value{GDBN} console.
23240
23241 @item EINVAL
23242 flag is not a proper value.
23243
23244 @item EINTR
23245 The call was interrupted by the user.
23246 @end table
23247
23248 @node rename
23249 @unnumberedsubsubsec rename
23250 @cindex rename, file-i/o system call
23251
23252 @smallexample
23253 @exdent Synopsis:
23254 int rename(const char *oldpath, const char *newpath);
23255
23256 @exdent Request:
23257 Frename,oldpathptr/len,newpathptr/len
23258
23259 @exdent Return value:
23260 On success, zero is returned. On error, -1 is returned.
23261
23262 @exdent Errors:
23263 @end smallexample
23264
23265 @table @code
23266 @item EISDIR
23267 newpath is an existing directory, but oldpath is not a
23268 directory.
23269
23270 @item EEXIST
23271 newpath is a non-empty directory.
23272
23273 @item EBUSY
23274 oldpath or newpath is a directory that is in use by some
23275 process.
23276
23277 @item EINVAL
23278 An attempt was made to make a directory a subdirectory
23279 of itself.
23280
23281 @item ENOTDIR
23282 A component used as a directory in oldpath or new
23283 path is not a directory. Or oldpath is a directory
23284 and newpath exists but is not a directory.
23285
23286 @item EFAULT
23287 oldpathptr or newpathptr are invalid pointer values.
23288
23289 @item EACCES
23290 No access to the file or the path of the file.
23291
23292 @item ENAMETOOLONG
23293
23294 oldpath or newpath was too long.
23295
23296 @item ENOENT
23297 A directory component in oldpath or newpath does not exist.
23298
23299 @item EROFS
23300 The file is on a read-only filesystem.
23301
23302 @item ENOSPC
23303 The device containing the file has no room for the new
23304 directory entry.
23305
23306 @item EINTR
23307 The call was interrupted by the user.
23308 @end table
23309
23310 @node unlink
23311 @unnumberedsubsubsec unlink
23312 @cindex unlink, file-i/o system call
23313
23314 @smallexample
23315 @exdent Synopsis:
23316 int unlink(const char *pathname);
23317
23318 @exdent Request:
23319 Funlink,pathnameptr/len
23320
23321 @exdent Return value:
23322 On success, zero is returned. On error, -1 is returned.
23323
23324 @exdent Errors:
23325 @end smallexample
23326
23327 @table @code
23328 @item EACCES
23329 No access to the file or the path of the file.
23330
23331 @item EPERM
23332 The system does not allow unlinking of directories.
23333
23334 @item EBUSY
23335 The file pathname cannot be unlinked because it's
23336 being used by another process.
23337
23338 @item EFAULT
23339 pathnameptr is an invalid pointer value.
23340
23341 @item ENAMETOOLONG
23342 pathname was too long.
23343
23344 @item ENOENT
23345 A directory component in pathname does not exist.
23346
23347 @item ENOTDIR
23348 A component of the path is not a directory.
23349
23350 @item EROFS
23351 The file is on a read-only filesystem.
23352
23353 @item EINTR
23354 The call was interrupted by the user.
23355 @end table
23356
23357 @node stat/fstat
23358 @unnumberedsubsubsec stat/fstat
23359 @cindex fstat, file-i/o system call
23360 @cindex stat, file-i/o system call
23361
23362 @smallexample
23363 @exdent Synopsis:
23364 int stat(const char *pathname, struct stat *buf);
23365 int fstat(int fd, struct stat *buf);
23366
23367 @exdent Request:
23368 Fstat,pathnameptr/len,bufptr
23369 Ffstat,fd,bufptr
23370
23371 @exdent Return value:
23372 On success, zero is returned. On error, -1 is returned.
23373
23374 @exdent Errors:
23375 @end smallexample
23376
23377 @table @code
23378 @item EBADF
23379 fd is not a valid open file.
23380
23381 @item ENOENT
23382 A directory component in pathname does not exist or the
23383 path is an empty string.
23384
23385 @item ENOTDIR
23386 A component of the path is not a directory.
23387
23388 @item EFAULT
23389 pathnameptr is an invalid pointer value.
23390
23391 @item EACCES
23392 No access to the file or the path of the file.
23393
23394 @item ENAMETOOLONG
23395 pathname was too long.
23396
23397 @item EINTR
23398 The call was interrupted by the user.
23399 @end table
23400
23401 @node gettimeofday
23402 @unnumberedsubsubsec gettimeofday
23403 @cindex gettimeofday, file-i/o system call
23404
23405 @smallexample
23406 @exdent Synopsis:
23407 int gettimeofday(struct timeval *tv, void *tz);
23408
23409 @exdent Request:
23410 Fgettimeofday,tvptr,tzptr
23411
23412 @exdent Return value:
23413 On success, 0 is returned, -1 otherwise.
23414
23415 @exdent Errors:
23416 @end smallexample
23417
23418 @table @code
23419 @item EINVAL
23420 tz is a non-NULL pointer.
23421
23422 @item EFAULT
23423 tvptr and/or tzptr is an invalid pointer value.
23424 @end table
23425
23426 @node isatty
23427 @unnumberedsubsubsec isatty
23428 @cindex isatty, file-i/o system call
23429
23430 @smallexample
23431 @exdent Synopsis:
23432 int isatty(int fd);
23433
23434 @exdent Request:
23435 Fisatty,fd
23436
23437 @exdent Return value:
23438 Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23439
23440 @exdent Errors:
23441 @end smallexample
23442
23443 @table @code
23444 @item EINTR
23445 The call was interrupted by the user.
23446 @end table
23447
23448 @node system
23449 @unnumberedsubsubsec system
23450 @cindex system, file-i/o system call
23451
23452 @smallexample
23453 @exdent Synopsis:
23454 int system(const char *command);
23455
23456 @exdent Request:
23457 Fsystem,commandptr/len
23458
23459 @exdent Return value:
23460 The value returned is -1 on error and the return status
23461 of the command otherwise. Only the exit status of the
23462 command is returned, which is extracted from the hosts
23463 system return value by calling WEXITSTATUS(retval).
23464 In case /bin/sh could not be executed, 127 is returned.
23465
23466 @exdent Errors:
23467 @end smallexample
23468
23469 @table @code
23470 @item EINTR
23471 The call was interrupted by the user.
23472 @end table
23473
23474 @node Protocol specific representation of datatypes
23475 @subsection Protocol specific representation of datatypes
23476 @cindex protocol specific representation of datatypes, in file-i/o protocol
23477
23478 @menu
23479 * Integral datatypes::
23480 * Pointer values::
23481 * struct stat::
23482 * struct timeval::
23483 @end menu
23484
23485 @node Integral datatypes
23486 @unnumberedsubsubsec Integral datatypes
23487 @cindex integral datatypes, in file-i/o protocol
23488
23489 The integral datatypes used in the system calls are
23490
23491 @smallexample
23492 int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23493 @end smallexample
23494
23495 @code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23496 implemented as 32 bit values in this protocol.
23497
23498 @code{Long} and @code{unsigned long} are implemented as 64 bit types.
23499
23500 @xref{Limits}, for corresponding MIN and MAX values (similar to those
23501 in @file{limits.h}) to allow range checking on host and target.
23502
23503 @code{time_t} datatypes are defined as seconds since the Epoch.
23504
23505 All integral datatypes transferred as part of a memory read or write of a
23506 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23507 byte order.
23508
23509 @node Pointer values
23510 @unnumberedsubsubsec Pointer values
23511 @cindex pointer values, in file-i/o protocol
23512
23513 Pointers to target data are transmitted as they are. An exception
23514 is made for pointers to buffers for which the length isn't
23515 transmitted as part of the function call, namely strings. Strings
23516 are transmitted as a pointer/length pair, both as hex values, e.g.@:
23517
23518 @smallexample
23519 @code{1aaf/12}
23520 @end smallexample
23521
23522 @noindent
23523 which is a pointer to data of length 18 bytes at position 0x1aaf.
23524 The length is defined as the full string length in bytes, including
23525 the trailing null byte. Example:
23526
23527 @smallexample
23528 ``hello, world'' at address 0x123456
23529 @end smallexample
23530
23531 @noindent
23532 is transmitted as
23533
23534 @smallexample
23535 @code{123456/d}
23536 @end smallexample
23537
23538 @node struct stat
23539 @unnumberedsubsubsec struct stat
23540 @cindex struct stat, in file-i/o protocol
23541
23542 The buffer of type struct stat used by the target and @value{GDBN} is defined
23543 as follows:
23544
23545 @smallexample
23546 struct stat @{
23547 unsigned int st_dev; /* device */
23548 unsigned int st_ino; /* inode */
23549 mode_t st_mode; /* protection */
23550 unsigned int st_nlink; /* number of hard links */
23551 unsigned int st_uid; /* user ID of owner */
23552 unsigned int st_gid; /* group ID of owner */
23553 unsigned int st_rdev; /* device type (if inode device) */
23554 unsigned long st_size; /* total size, in bytes */
23555 unsigned long st_blksize; /* blocksize for filesystem I/O */
23556 unsigned long st_blocks; /* number of blocks allocated */
23557 time_t st_atime; /* time of last access */
23558 time_t st_mtime; /* time of last modification */
23559 time_t st_ctime; /* time of last change */
23560 @};
23561 @end smallexample
23562
23563 The integral datatypes are conforming to the definitions given in the
23564 approriate section (see @ref{Integral datatypes}, for details) so this
23565 structure is of size 64 bytes.
23566
23567 The values of several fields have a restricted meaning and/or
23568 range of values.
23569
23570 @smallexample
23571 st_dev: 0 file
23572 1 console
23573
23574 st_ino: No valid meaning for the target. Transmitted unchanged.
23575
23576 st_mode: Valid mode bits are described in Appendix C. Any other
23577 bits have currently no meaning for the target.
23578
23579 st_uid: No valid meaning for the target. Transmitted unchanged.
23580
23581 st_gid: No valid meaning for the target. Transmitted unchanged.
23582
23583 st_rdev: No valid meaning for the target. Transmitted unchanged.
23584
23585 st_atime, st_mtime, st_ctime:
23586 These values have a host and file system dependent
23587 accuracy. Especially on Windows hosts the file systems
23588 don't support exact timing values.
23589 @end smallexample
23590
23591 The target gets a struct stat of the above representation and is
23592 responsible to coerce it to the target representation before
23593 continuing.
23594
23595 Note that due to size differences between the host and target
23596 representation of stat members, these members could eventually
23597 get truncated on the target.
23598
23599 @node struct timeval
23600 @unnumberedsubsubsec struct timeval
23601 @cindex struct timeval, in file-i/o protocol
23602
23603 The buffer of type struct timeval used by the target and @value{GDBN}
23604 is defined as follows:
23605
23606 @smallexample
23607 struct timeval @{
23608 time_t tv_sec; /* second */
23609 long tv_usec; /* microsecond */
23610 @};
23611 @end smallexample
23612
23613 The integral datatypes are conforming to the definitions given in the
23614 approriate section (see @ref{Integral datatypes}, for details) so this
23615 structure is of size 8 bytes.
23616
23617 @node Constants
23618 @subsection Constants
23619 @cindex constants, in file-i/o protocol
23620
23621 The following values are used for the constants inside of the
23622 protocol. @value{GDBN} and target are resposible to translate these
23623 values before and after the call as needed.
23624
23625 @menu
23626 * Open flags::
23627 * mode_t values::
23628 * Errno values::
23629 * Lseek flags::
23630 * Limits::
23631 @end menu
23632
23633 @node Open flags
23634 @unnumberedsubsubsec Open flags
23635 @cindex open flags, in file-i/o protocol
23636
23637 All values are given in hexadecimal representation.
23638
23639 @smallexample
23640 O_RDONLY 0x0
23641 O_WRONLY 0x1
23642 O_RDWR 0x2
23643 O_APPEND 0x8
23644 O_CREAT 0x200
23645 O_TRUNC 0x400
23646 O_EXCL 0x800
23647 @end smallexample
23648
23649 @node mode_t values
23650 @unnumberedsubsubsec mode_t values
23651 @cindex mode_t values, in file-i/o protocol
23652
23653 All values are given in octal representation.
23654
23655 @smallexample
23656 S_IFREG 0100000
23657 S_IFDIR 040000
23658 S_IRUSR 0400
23659 S_IWUSR 0200
23660 S_IXUSR 0100
23661 S_IRGRP 040
23662 S_IWGRP 020
23663 S_IXGRP 010
23664 S_IROTH 04
23665 S_IWOTH 02
23666 S_IXOTH 01
23667 @end smallexample
23668
23669 @node Errno values
23670 @unnumberedsubsubsec Errno values
23671 @cindex errno values, in file-i/o protocol
23672
23673 All values are given in decimal representation.
23674
23675 @smallexample
23676 EPERM 1
23677 ENOENT 2
23678 EINTR 4
23679 EBADF 9
23680 EACCES 13
23681 EFAULT 14
23682 EBUSY 16
23683 EEXIST 17
23684 ENODEV 19
23685 ENOTDIR 20
23686 EISDIR 21
23687 EINVAL 22
23688 ENFILE 23
23689 EMFILE 24
23690 EFBIG 27
23691 ENOSPC 28
23692 ESPIPE 29
23693 EROFS 30
23694 ENAMETOOLONG 91
23695 EUNKNOWN 9999
23696 @end smallexample
23697
23698 EUNKNOWN is used as a fallback error value if a host system returns
23699 any error value not in the list of supported error numbers.
23700
23701 @node Lseek flags
23702 @unnumberedsubsubsec Lseek flags
23703 @cindex lseek flags, in file-i/o protocol
23704
23705 @smallexample
23706 SEEK_SET 0
23707 SEEK_CUR 1
23708 SEEK_END 2
23709 @end smallexample
23710
23711 @node Limits
23712 @unnumberedsubsubsec Limits
23713 @cindex limits, in file-i/o protocol
23714
23715 All values are given in decimal representation.
23716
23717 @smallexample
23718 INT_MIN -2147483648
23719 INT_MAX 2147483647
23720 UINT_MAX 4294967295
23721 LONG_MIN -9223372036854775808
23722 LONG_MAX 9223372036854775807
23723 ULONG_MAX 18446744073709551615
23724 @end smallexample
23725
23726 @node File-I/O Examples
23727 @subsection File-I/O Examples
23728 @cindex file-i/o examples
23729
23730 Example sequence of a write call, file descriptor 3, buffer is at target
23731 address 0x1234, 6 bytes should be written:
23732
23733 @smallexample
23734 <- @code{Fwrite,3,1234,6}
23735 @emph{request memory read from target}
23736 -> @code{m1234,6}
23737 <- XXXXXX
23738 @emph{return "6 bytes written"}
23739 -> @code{F6}
23740 @end smallexample
23741
23742 Example sequence of a read call, file descriptor 3, buffer is at target
23743 address 0x1234, 6 bytes should be read:
23744
23745 @smallexample
23746 <- @code{Fread,3,1234,6}
23747 @emph{request memory write to target}
23748 -> @code{X1234,6:XXXXXX}
23749 @emph{return "6 bytes read"}
23750 -> @code{F6}
23751 @end smallexample
23752
23753 Example sequence of a read call, call fails on the host due to invalid
23754 file descriptor (EBADF):
23755
23756 @smallexample
23757 <- @code{Fread,3,1234,6}
23758 -> @code{F-1,9}
23759 @end smallexample
23760
23761 Example sequence of a read call, user presses Ctrl-C before syscall on
23762 host is called:
23763
23764 @smallexample
23765 <- @code{Fread,3,1234,6}
23766 -> @code{F-1,4,C}
23767 <- @code{T02}
23768 @end smallexample
23769
23770 Example sequence of a read call, user presses Ctrl-C after syscall on
23771 host is called:
23772
23773 @smallexample
23774 <- @code{Fread,3,1234,6}
23775 -> @code{X1234,6:XXXXXX}
23776 <- @code{T02}
23777 @end smallexample
23778
23779 @include agentexpr.texi
23780
23781 @include gpl.texi
23782
23783 @raisesections
23784 @include fdl.texi
23785 @lowersections
23786
23787 @node Index
23788 @unnumbered Index
23789
23790 @printindex cp
23791
23792 @tex
23793 % I think something like @colophon should be in texinfo. In the
23794 % meantime:
23795 \long\def\colophon{\hbox to0pt{}\vfill
23796 \centerline{The body of this manual is set in}
23797 \centerline{\fontname\tenrm,}
23798 \centerline{with headings in {\bf\fontname\tenbf}}
23799 \centerline{and examples in {\tt\fontname\tentt}.}
23800 \centerline{{\it\fontname\tenit\/},}
23801 \centerline{{\bf\fontname\tenbf}, and}
23802 \centerline{{\sl\fontname\tensl\/}}
23803 \centerline{are used for emphasis.}\vfill}
23804 \page\colophon
23805 % Blame: doc@cygnus.com, 1991.
23806 @end tex
23807
23808 @bye
This page took 0.513167 seconds and 5 git commands to generate.