]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
* elf32-arm.h (elf32_arm_final_link_relocate): Check that we created
[thirdparty/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
c552b3bb 3@c 1999, 2000, 2001, 2002, 2003, 2004
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
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
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
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
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
96a2c332
SS
41@dircategory Programming & development tools.
42@direntry
c906108c 43* Gdb: (gdb). The @sc{gnu} debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
c552b3bb 55 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
c906108c 56
e9c75b65
EZ
57Permission is granted to copy, distribute and/or modify this document
58under the terms of the GNU Free Documentation License, Version 1.1 or
59any later version published by the Free Software Foundation; with the
959acfd1
EZ
60Invariant Sections being ``Free Software'' and ``Free Software Needs
61Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
62and with the Back-Cover Texts as in (a) below.
c906108c 63
6826cf00
EZ
64(a) The Free Software Foundation's Back-Cover Text is: ``You have
65freedom to copy and modify this GNU Manual, like GNU software. Copies
66published by the Free Software Foundation raise funds for GNU
67development.''
c906108c
SS
68@end ifinfo
69
70@titlepage
71@title Debugging with @value{GDBN}
72@subtitle The @sc{gnu} Source-Level Debugger
c906108c 73@sp 1
c906108c 74@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 75@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 76@page
c906108c
SS
77@tex
78{\parskip=0pt
53a5351d 79\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
80\hfill {\it Debugging with @value{GDBN}}\par
81\hfill \TeX{}info \texinfoversion\par
82}
83@end tex
53a5351d 84
c906108c 85@vskip 0pt plus 1filll
8a037dd7 86Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1e698235 871996, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
c906108c 88@sp 2
c906108c
SS
89Published by the Free Software Foundation @*
9059 Temple Place - Suite 330, @*
91Boston, MA 02111-1307 USA @*
6d2ebf8b 92ISBN 1-882114-77-9 @*
e9c75b65
EZ
93
94Permission is granted to copy, distribute and/or modify this document
95under the terms of the GNU Free Documentation License, Version 1.1 or
96any later version published by the Free Software Foundation; with the
959acfd1
EZ
97Invariant Sections being ``Free Software'' and ``Free Software Needs
98Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
99and with the Back-Cover Texts as in (a) below.
e9c75b65 100
6826cf00
EZ
101(a) The Free Software Foundation's Back-Cover Text is: ``You have
102freedom to copy and modify this GNU Manual, like GNU software. Copies
103published by the Free Software Foundation raise funds for GNU
104development.''
c906108c
SS
105@end titlepage
106@page
107
6c0e9fb3 108@ifnottex
6d2ebf8b
SS
109@node Top, Summary, (dir), (dir)
110
c906108c
SS
111@top Debugging with @value{GDBN}
112
113This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
114
9fe8321b 115This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
116@value{GDBVN}.
117
c552b3bb 118Copyright (C) 1988-2004 Free Software Foundation, Inc.
6d2ebf8b
SS
119
120@menu
121* Summary:: Summary of @value{GDBN}
122* Sample Session:: A sample @value{GDBN} session
123
124* Invocation:: Getting in and out of @value{GDBN}
125* Commands:: @value{GDBN} commands
126* Running:: Running programs under @value{GDBN}
127* Stopping:: Stopping and continuing
128* Stack:: Examining the stack
129* Source:: Examining source files
130* Data:: Examining data
e2e0bcd1 131* Macros:: Preprocessor Macros
b37052ae 132* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 133* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
134
135* Languages:: Using @value{GDBN} with different languages
136
137* Symbols:: Examining the symbol table
138* Altering:: Altering execution
139* GDB Files:: @value{GDBN} files
140* Targets:: Specifying a debugging target
6b2f586d 141* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
142* Configurations:: Configuration-specific information
143* Controlling GDB:: Controlling @value{GDBN}
144* Sequences:: Canned sequences of commands
c4555f82 145* TUI:: @value{GDBN} Text User Interface
21c294e6 146* Interpreters:: Command Interpreters
6d2ebf8b
SS
147* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
148* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 149* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
150
151* GDB Bugs:: Reporting bugs in @value{GDBN}
152* Formatting Documentation:: How to format and print @value{GDBN} documentation
153
154* Command Line Editing:: Command Line Editing
155* Using History Interactively:: Using History Interactively
156* Installing GDB:: Installing GDB
eb12ee30 157* Maintenance Commands:: Maintenance Commands
e0ce93ac 158* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 159* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
160* Copying:: GNU General Public License says
161 how you can copy and share GDB
6826cf00 162* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
163* Index:: Index
164@end menu
165
6c0e9fb3 166@end ifnottex
c906108c 167
449f3b6c 168@contents
449f3b6c 169
6d2ebf8b 170@node Summary
c906108c
SS
171@unnumbered Summary of @value{GDBN}
172
173The purpose of a debugger such as @value{GDBN} is to allow you to see what is
174going on ``inside'' another program while it executes---or what another
175program was doing at the moment it crashed.
176
177@value{GDBN} can do four main kinds of things (plus other things in support of
178these) to help you catch bugs in the act:
179
180@itemize @bullet
181@item
182Start your program, specifying anything that might affect its behavior.
183
184@item
185Make your program stop on specified conditions.
186
187@item
188Examine what has happened, when your program has stopped.
189
190@item
191Change things in your program, so you can experiment with correcting the
192effects of one bug and go on to learn about another.
193@end itemize
194
cce74817 195You can use @value{GDBN} to debug programs written in C and C++.
c906108c 196For more information, see @ref{Support,,Supported languages}.
c906108c
SS
197For more information, see @ref{C,,C and C++}.
198
cce74817 199@cindex Modula-2
e632838e
AC
200Support for Modula-2 is partial. For information on Modula-2, see
201@ref{Modula-2,,Modula-2}.
c906108c 202
cce74817
JM
203@cindex Pascal
204Debugging Pascal programs which use sets, subranges, file variables, or
205nested functions does not currently work. @value{GDBN} does not support
206entering expressions, printing values, or similar features using Pascal
207syntax.
c906108c 208
c906108c
SS
209@cindex Fortran
210@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 211it may be necessary to refer to some variables with a trailing
cce74817 212underscore.
c906108c 213
b37303ee
AF
214@value{GDBN} can be used to debug programs written in Objective-C,
215using either the Apple/NeXT or the GNU Objective-C runtime.
216
c906108c
SS
217@menu
218* Free Software:: Freely redistributable software
219* Contributors:: Contributors to GDB
220@end menu
221
6d2ebf8b 222@node Free Software
c906108c
SS
223@unnumberedsec Free software
224
5d161b24 225@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
226General Public License
227(GPL). The GPL gives you the freedom to copy or adapt a licensed
228program---but every person getting a copy also gets with it the
229freedom to modify that copy (which means that they must get access to
230the source code), and the freedom to distribute further copies.
231Typical software companies use copyrights to limit your freedoms; the
232Free Software Foundation uses the GPL to preserve these freedoms.
233
234Fundamentally, the General Public License is a license which says that
235you have these freedoms and that you cannot take these freedoms away
236from anyone else.
237
2666264b 238@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
239
240The biggest deficiency in the free software community today is not in
241the software---it is the lack of good free documentation that we can
242include with the free software. Many of our most important
243programs do not come with free reference manuals and free introductory
244texts. Documentation is an essential part of any software package;
245when an important free software package does not come with a free
246manual and a free tutorial, that is a major gap. We have many such
247gaps today.
248
249Consider Perl, for instance. The tutorial manuals that people
250normally use are non-free. How did this come about? Because the
251authors of those manuals published them with restrictive terms---no
252copying, no modification, source files not available---which exclude
253them from the free software world.
254
255That wasn't the first time this sort of thing happened, and it was far
256from the last. Many times we have heard a GNU user eagerly describe a
257manual that he is writing, his intended contribution to the community,
258only to learn that he had ruined everything by signing a publication
259contract to make it non-free.
260
261Free documentation, like free software, is a matter of freedom, not
262price. The problem with the non-free manual is not that publishers
263charge a price for printed copies---that in itself is fine. (The Free
264Software Foundation sells printed copies of manuals, too.) The
265problem is the restrictions on the use of the manual. Free manuals
266are available in source code form, and give you permission to copy and
267modify. Non-free manuals do not allow this.
268
269The criteria of freedom for a free manual are roughly the same as for
270free software. Redistribution (including the normal kinds of
271commercial redistribution) must be permitted, so that the manual can
272accompany every copy of the program, both on-line and on paper.
273
274Permission for modification of the technical content is crucial too.
275When people modify the software, adding or changing features, if they
276are conscientious they will change the manual too---so they can
277provide accurate and clear documentation for the modified program. A
278manual that leaves you no choice but to write a new manual to document
279a changed version of the program is not really available to our
280community.
281
282Some kinds of limits on the way modification is handled are
283acceptable. For example, requirements to preserve the original
284author's copyright notice, the distribution terms, or the list of
285authors, are ok. It is also no problem to require modified versions
286to include notice that they were modified. Even entire sections that
287may not be deleted or changed are acceptable, as long as they deal
288with nontechnical topics (like this one). These kinds of restrictions
289are acceptable because they don't obstruct the community's normal use
290of the manual.
291
292However, it must be possible to modify all the @emph{technical}
293content of the manual, and then distribute the result in all the usual
294media, through all the usual channels. Otherwise, the restrictions
295obstruct the use of the manual, it is not free, and we need another
296manual to replace it.
297
298Please spread the word about this issue. Our community continues to
299lose manuals to proprietary publishing. If we spread the word that
300free software needs free reference manuals and free tutorials, perhaps
301the next person who wants to contribute by writing documentation will
302realize, before it is too late, that only free manuals contribute to
303the free software community.
304
305If you are writing documentation, please insist on publishing it under
306the GNU Free Documentation License or another free documentation
307license. Remember that this decision requires your approval---you
308don't have to let the publisher decide. Some commercial publishers
309will use a free license if you insist, but they will not propose the
310option; it is up to you to raise the issue and say firmly that this is
311what you want. If the publisher you are dealing with refuses, please
312try other publishers. If you're not sure whether a proposed license
42584a72 313is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
314
315You can encourage commercial publishers to sell more free, copylefted
316manuals and tutorials by buying them, and particularly by buying
317copies from the publishers that paid for their writing or for major
318improvements. Meanwhile, try to avoid buying non-free documentation
319at all. Check the distribution terms of a manual before you buy it,
320and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
321Check the history of the book, and try to reward the publishers that
322have paid or pay the authors to work on it.
959acfd1
EZ
323
324The Free Software Foundation maintains a list of free documentation
325published by other publishers, at
326@url{http://www.fsf.org/doc/other-free-books.html}.
327
6d2ebf8b 328@node Contributors
96a2c332
SS
329@unnumberedsec Contributors to @value{GDBN}
330
331Richard Stallman was the original author of @value{GDBN}, and of many
332other @sc{gnu} programs. Many others have contributed to its
333development. This section attempts to credit major contributors. One
334of the virtues of free software is that everyone is free to contribute
335to it; with regret, we cannot actually acknowledge everyone here. The
336file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
337blow-by-blow account.
338
339Changes much prior to version 2.0 are lost in the mists of time.
340
341@quotation
342@emph{Plea:} Additions to this section are particularly welcome. If you
343or your friends (or enemies, to be evenhanded) have been unfairly
344omitted from this list, we would like to add your names!
345@end quotation
346
347So that they may not regard their many labors as thankless, we
348particularly thank those who shepherded @value{GDBN} through major
349releases:
f2c06f52 350Andrew Cagney (releases 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
351Jim Blandy (release 4.18);
352Jason Molenda (release 4.17);
353Stan Shebs (release 4.14);
354Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
355Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
356John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
357Jim Kingdon (releases 3.5, 3.4, and 3.3);
358and Randy Smith (releases 3.2, 3.1, and 3.0).
359
360Richard Stallman, assisted at various times by Peter TerMaat, Chris
361Hanson, and Richard Mlynarik, handled releases through 2.8.
362
b37052ae
EZ
363Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
364in @value{GDBN}, with significant additional contributions from Per
365Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
366demangler. Early work on C@t{++} was by Peter TerMaat (who also did
367much general update work leading to release 3.0).
c906108c 368
b37052ae 369@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
370object-file formats; BFD was a joint project of David V.
371Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
372
373David Johnson wrote the original COFF support; Pace Willison did
374the original support for encapsulated COFF.
375
0179ffac 376Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
377
378Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
379Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
380support.
381Jean-Daniel Fekete contributed Sun 386i support.
382Chris Hanson improved the HP9000 support.
383Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
384David Johnson contributed Encore Umax support.
385Jyrki Kuoppala contributed Altos 3068 support.
386Jeff Law contributed HP PA and SOM support.
387Keith Packard contributed NS32K support.
388Doug Rabson contributed Acorn Risc Machine support.
389Bob Rusk contributed Harris Nighthawk CX-UX support.
390Chris Smith contributed Convex support (and Fortran debugging).
391Jonathan Stone contributed Pyramid support.
392Michael Tiemann contributed SPARC support.
393Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
394Pace Willison contributed Intel 386 support.
395Jay Vosburgh contributed Symmetry support.
a37295f9 396Marko Mlinar contributed OpenRISC 1000 support.
c906108c 397
1104b9e7 398Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
399
400Rich Schaefer and Peter Schauer helped with support of SunOS shared
401libraries.
402
403Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
404about several machine instruction sets.
405
406Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
407remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
408contributed remote debugging modules for the i960, VxWorks, A29K UDI,
409and RDI targets, respectively.
410
411Brian Fox is the author of the readline libraries providing
412command-line editing and command history.
413
7a292a7a
SS
414Andrew Beers of SUNY Buffalo wrote the language-switching code, the
415Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 416
5d161b24 417Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 418He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 419symbols.
c906108c 420
f24c5e49
KI
421Hitachi America (now Renesas America), Ltd. sponsored the support for
422H8/300, H8/500, and Super-H processors.
c906108c
SS
423
424NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
425
f24c5e49
KI
426Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
427processors.
c906108c
SS
428
429Toshiba sponsored the support for the TX39 Mips processor.
430
431Matsushita sponsored the support for the MN10200 and MN10300 processors.
432
96a2c332 433Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
434
435Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
436watchpoints.
437
438Michael Snyder added support for tracepoints.
439
440Stu Grossman wrote gdbserver.
441
442Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 443nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
444
445The following people at the Hewlett-Packard Company contributed
446support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 447(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
c906108c
SS
448compiler, and the terminal user interface: Ben Krepp, Richard Title,
449John Bishop, Susan Macchia, Kathy Mann, Satish Pai, India Paul, Steve
450Rehrauer, and Elena Zannoni. Kim Haase provided HP-specific
451information in this manual.
452
b37052ae
EZ
453DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
454Robert Hoehne made significant contributions to the DJGPP port.
455
96a2c332
SS
456Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
457development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
458fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
459Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
460Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
461Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
462Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
463addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
464JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
465Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
466Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
467Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
468Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
469Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
470Zuhn have made contributions both large and small.
c906108c 471
e2e0bcd1
JB
472Jim Blandy added support for preprocessor macros, while working for Red
473Hat.
c906108c 474
6d2ebf8b 475@node Sample Session
c906108c
SS
476@chapter A Sample @value{GDBN} Session
477
478You can use this manual at your leisure to read all about @value{GDBN}.
479However, a handful of commands are enough to get started using the
480debugger. This chapter illustrates those commands.
481
482@iftex
483In this sample session, we emphasize user input like this: @b{input},
484to make it easier to pick out from the surrounding output.
485@end iftex
486
487@c FIXME: this example may not be appropriate for some configs, where
488@c FIXME...primary interest is in remote use.
489
490One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
491processor) exhibits the following bug: sometimes, when we change its
492quote strings from the default, the commands used to capture one macro
493definition within another stop working. In the following short @code{m4}
494session, we define a macro @code{foo} which expands to @code{0000}; we
495then use the @code{m4} built-in @code{defn} to define @code{bar} as the
496same thing. However, when we change the open quote string to
497@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
498procedure fails to define a new synonym @code{baz}:
499
500@smallexample
501$ @b{cd gnu/m4}
502$ @b{./m4}
503@b{define(foo,0000)}
504
505@b{foo}
5060000
507@b{define(bar,defn(`foo'))}
508
509@b{bar}
5100000
511@b{changequote(<QUOTE>,<UNQUOTE>)}
512
513@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
514@b{baz}
515@b{C-d}
516m4: End of input: 0: fatal error: EOF in string
517@end smallexample
518
519@noindent
520Let us use @value{GDBN} to try to see what is going on.
521
c906108c
SS
522@smallexample
523$ @b{@value{GDBP} m4}
524@c FIXME: this falsifies the exact text played out, to permit smallbook
525@c FIXME... format to come out better.
526@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 527 of it under certain conditions; type "show copying" to see
c906108c 528 the conditions.
5d161b24 529There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
530 for details.
531
532@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
533(@value{GDBP})
534@end smallexample
c906108c
SS
535
536@noindent
537@value{GDBN} reads only enough symbol data to know where to find the
538rest when needed; as a result, the first prompt comes up very quickly.
539We now tell @value{GDBN} to use a narrower display width than usual, so
540that examples fit in this manual.
541
542@smallexample
543(@value{GDBP}) @b{set width 70}
544@end smallexample
545
546@noindent
547We need to see how the @code{m4} built-in @code{changequote} works.
548Having looked at the source, we know the relevant subroutine is
549@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
550@code{break} command.
551
552@smallexample
553(@value{GDBP}) @b{break m4_changequote}
554Breakpoint 1 at 0x62f4: file builtin.c, line 879.
555@end smallexample
556
557@noindent
558Using the @code{run} command, we start @code{m4} running under @value{GDBN}
559control; as long as control does not reach the @code{m4_changequote}
560subroutine, the program runs as usual:
561
562@smallexample
563(@value{GDBP}) @b{run}
564Starting program: /work/Editorial/gdb/gnu/m4/m4
565@b{define(foo,0000)}
566
567@b{foo}
5680000
569@end smallexample
570
571@noindent
572To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
573suspends execution of @code{m4}, displaying information about the
574context where it stops.
575
576@smallexample
577@b{changequote(<QUOTE>,<UNQUOTE>)}
578
5d161b24 579Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
580 at builtin.c:879
581879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
582@end smallexample
583
584@noindent
585Now we use the command @code{n} (@code{next}) to advance execution to
586the next line of the current function.
587
588@smallexample
589(@value{GDBP}) @b{n}
590882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
591 : nil,
592@end smallexample
593
594@noindent
595@code{set_quotes} looks like a promising subroutine. We can go into it
596by using the command @code{s} (@code{step}) instead of @code{next}.
597@code{step} goes to the next line to be executed in @emph{any}
598subroutine, so it steps into @code{set_quotes}.
599
600@smallexample
601(@value{GDBP}) @b{s}
602set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
603 at input.c:530
604530 if (lquote != def_lquote)
605@end smallexample
606
607@noindent
608The display that shows the subroutine where @code{m4} is now
609suspended (and its arguments) is called a stack frame display. It
610shows a summary of the stack. We can use the @code{backtrace}
611command (which can also be spelled @code{bt}), to see where we are
612in the stack as a whole: the @code{backtrace} command displays a
613stack frame for each active subroutine.
614
615@smallexample
616(@value{GDBP}) @b{bt}
617#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
618 at input.c:530
5d161b24 619#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
620 at builtin.c:882
621#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
622#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
623 at macro.c:71
624#4 0x79dc in expand_input () at macro.c:40
625#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
626@end smallexample
627
628@noindent
629We step through a few more lines to see what happens. The first two
630times, we can use @samp{s}; the next two times we use @code{n} to avoid
631falling into the @code{xstrdup} subroutine.
632
633@smallexample
634(@value{GDBP}) @b{s}
6350x3b5c 532 if (rquote != def_rquote)
636(@value{GDBP}) @b{s}
6370x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
638def_lquote : xstrdup(lq);
639(@value{GDBP}) @b{n}
640536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
641 : xstrdup(rq);
642(@value{GDBP}) @b{n}
643538 len_lquote = strlen(rquote);
644@end smallexample
645
646@noindent
647The last line displayed looks a little odd; we can examine the variables
648@code{lquote} and @code{rquote} to see if they are in fact the new left
649and right quotes we specified. We use the command @code{p}
650(@code{print}) to see their values.
651
652@smallexample
653(@value{GDBP}) @b{p lquote}
654$1 = 0x35d40 "<QUOTE>"
655(@value{GDBP}) @b{p rquote}
656$2 = 0x35d50 "<UNQUOTE>"
657@end smallexample
658
659@noindent
660@code{lquote} and @code{rquote} are indeed the new left and right quotes.
661To look at some context, we can display ten lines of source
662surrounding the current line with the @code{l} (@code{list}) command.
663
664@smallexample
665(@value{GDBP}) @b{l}
666533 xfree(rquote);
667534
668535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
669 : xstrdup (lq);
670536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
671 : xstrdup (rq);
672537
673538 len_lquote = strlen(rquote);
674539 len_rquote = strlen(lquote);
675540 @}
676541
677542 void
678@end smallexample
679
680@noindent
681Let us step past the two lines that set @code{len_lquote} and
682@code{len_rquote}, and then examine the values of those variables.
683
684@smallexample
685(@value{GDBP}) @b{n}
686539 len_rquote = strlen(lquote);
687(@value{GDBP}) @b{n}
688540 @}
689(@value{GDBP}) @b{p len_lquote}
690$3 = 9
691(@value{GDBP}) @b{p len_rquote}
692$4 = 7
693@end smallexample
694
695@noindent
696That certainly looks wrong, assuming @code{len_lquote} and
697@code{len_rquote} are meant to be the lengths of @code{lquote} and
698@code{rquote} respectively. We can set them to better values using
699the @code{p} command, since it can print the value of
700any expression---and that expression can include subroutine calls and
701assignments.
702
703@smallexample
704(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
705$5 = 7
706(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
707$6 = 9
708@end smallexample
709
710@noindent
711Is that enough to fix the problem of using the new quotes with the
712@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
713executing with the @code{c} (@code{continue}) command, and then try the
714example that caused trouble initially:
715
716@smallexample
717(@value{GDBP}) @b{c}
718Continuing.
719
720@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
721
722baz
7230000
724@end smallexample
725
726@noindent
727Success! The new quotes now work just as well as the default ones. The
728problem seems to have been just the two typos defining the wrong
729lengths. We allow @code{m4} exit by giving it an EOF as input:
730
731@smallexample
732@b{C-d}
733Program exited normally.
734@end smallexample
735
736@noindent
737The message @samp{Program exited normally.} is from @value{GDBN}; it
738indicates @code{m4} has finished executing. We can end our @value{GDBN}
739session with the @value{GDBN} @code{quit} command.
740
741@smallexample
742(@value{GDBP}) @b{quit}
743@end smallexample
c906108c 744
6d2ebf8b 745@node Invocation
c906108c
SS
746@chapter Getting In and Out of @value{GDBN}
747
748This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 749The essentials are:
c906108c 750@itemize @bullet
5d161b24 751@item
53a5351d 752type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 753@item
c906108c
SS
754type @kbd{quit} or @kbd{C-d} to exit.
755@end itemize
756
757@menu
758* Invoking GDB:: How to start @value{GDBN}
759* Quitting GDB:: How to quit @value{GDBN}
760* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 761* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
762@end menu
763
6d2ebf8b 764@node Invoking GDB
c906108c
SS
765@section Invoking @value{GDBN}
766
c906108c
SS
767Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
768@value{GDBN} reads commands from the terminal until you tell it to exit.
769
770You can also run @code{@value{GDBP}} with a variety of arguments and options,
771to specify more of your debugging environment at the outset.
772
c906108c
SS
773The command-line options described here are designed
774to cover a variety of situations; in some environments, some of these
5d161b24 775options may effectively be unavailable.
c906108c
SS
776
777The most usual way to start @value{GDBN} is with one argument,
778specifying an executable program:
779
474c8240 780@smallexample
c906108c 781@value{GDBP} @var{program}
474c8240 782@end smallexample
c906108c 783
c906108c
SS
784@noindent
785You can also start with both an executable program and a core file
786specified:
787
474c8240 788@smallexample
c906108c 789@value{GDBP} @var{program} @var{core}
474c8240 790@end smallexample
c906108c
SS
791
792You can, instead, specify a process ID as a second argument, if you want
793to debug a running process:
794
474c8240 795@smallexample
c906108c 796@value{GDBP} @var{program} 1234
474c8240 797@end smallexample
c906108c
SS
798
799@noindent
800would attach @value{GDBN} to process @code{1234} (unless you also have a file
801named @file{1234}; @value{GDBN} does check for a core file first).
802
c906108c 803Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
804complete operating system; when you use @value{GDBN} as a remote
805debugger attached to a bare board, there may not be any notion of
806``process'', and there is often no way to get a core dump. @value{GDBN}
807will warn you if it is unable to attach or to read core dumps.
c906108c 808
aa26fa3a
TT
809You can optionally have @code{@value{GDBP}} pass any arguments after the
810executable file to the inferior using @code{--args}. This option stops
811option processing.
474c8240 812@smallexample
aa26fa3a 813gdb --args gcc -O2 -c foo.c
474c8240 814@end smallexample
aa26fa3a
TT
815This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
816@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
817
96a2c332 818You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
819@value{GDBN}'s non-warranty, by specifying @code{-silent}:
820
821@smallexample
822@value{GDBP} -silent
823@end smallexample
824
825@noindent
826You can further control how @value{GDBN} starts up by using command-line
827options. @value{GDBN} itself can remind you of the options available.
828
829@noindent
830Type
831
474c8240 832@smallexample
c906108c 833@value{GDBP} -help
474c8240 834@end smallexample
c906108c
SS
835
836@noindent
837to display all available options and briefly describe their use
838(@samp{@value{GDBP} -h} is a shorter equivalent).
839
840All options and command line arguments you give are processed
841in sequential order. The order makes a difference when the
842@samp{-x} option is used.
843
844
845@menu
c906108c
SS
846* File Options:: Choosing files
847* Mode Options:: Choosing modes
848@end menu
849
6d2ebf8b 850@node File Options
c906108c
SS
851@subsection Choosing files
852
2df3850c 853When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
854specifying an executable file and core file (or process ID). This is
855the same as if the arguments were specified by the @samp{-se} and
19837790
MS
856@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
857first argument that does not have an associated option flag as
858equivalent to the @samp{-se} option followed by that argument; and the
859second argument that does not have an associated option flag, if any, as
860equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
861If the second argument begins with a decimal digit, @value{GDBN} will
862first attempt to attach to it as a process, and if that fails, attempt
863to open it as a corefile. If you have a corefile whose name begins with
864a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 865prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
866
867If @value{GDBN} has not been configured to included core file support,
868such as for most embedded targets, then it will complain about a second
869argument and ignore it.
c906108c
SS
870
871Many options have both long and short forms; both are shown in the
872following list. @value{GDBN} also recognizes the long forms if you truncate
873them, so long as enough of the option is present to be unambiguous.
874(If you prefer, you can flag option arguments with @samp{--} rather
875than @samp{-}, though we illustrate the more usual convention.)
876
d700128c
EZ
877@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
878@c way, both those who look for -foo and --foo in the index, will find
879@c it.
880
c906108c
SS
881@table @code
882@item -symbols @var{file}
883@itemx -s @var{file}
d700128c
EZ
884@cindex @code{--symbols}
885@cindex @code{-s}
c906108c
SS
886Read symbol table from file @var{file}.
887
888@item -exec @var{file}
889@itemx -e @var{file}
d700128c
EZ
890@cindex @code{--exec}
891@cindex @code{-e}
7a292a7a
SS
892Use file @var{file} as the executable file to execute when appropriate,
893and for examining pure data in conjunction with a core dump.
c906108c
SS
894
895@item -se @var{file}
d700128c 896@cindex @code{--se}
c906108c
SS
897Read symbol table from file @var{file} and use it as the executable
898file.
899
c906108c
SS
900@item -core @var{file}
901@itemx -c @var{file}
d700128c
EZ
902@cindex @code{--core}
903@cindex @code{-c}
19837790 904Use file @var{file} as a core dump to examine.
c906108c
SS
905
906@item -c @var{number}
19837790
MS
907@item -pid @var{number}
908@itemx -p @var{number}
909@cindex @code{--pid}
910@cindex @code{-p}
911Connect to process ID @var{number}, as with the @code{attach} command.
912If there is no such process, @value{GDBN} will attempt to open a core
913file named @var{number}.
c906108c
SS
914
915@item -command @var{file}
916@itemx -x @var{file}
d700128c
EZ
917@cindex @code{--command}
918@cindex @code{-x}
c906108c
SS
919Execute @value{GDBN} commands from file @var{file}. @xref{Command
920Files,, Command files}.
921
922@item -directory @var{directory}
923@itemx -d @var{directory}
d700128c
EZ
924@cindex @code{--directory}
925@cindex @code{-d}
c906108c
SS
926Add @var{directory} to the path to search for source files.
927
c906108c
SS
928@item -m
929@itemx -mapped
d700128c
EZ
930@cindex @code{--mapped}
931@cindex @code{-m}
c906108c
SS
932@emph{Warning: this option depends on operating system facilities that are not
933supported on all systems.}@*
934If memory-mapped files are available on your system through the @code{mmap}
5d161b24 935system call, you can use this option
c906108c
SS
936to have @value{GDBN} write the symbols from your
937program into a reusable file in the current directory. If the program you are debugging is
96a2c332 938called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
939Future @value{GDBN} debugging sessions notice the presence of this file,
940and can quickly map in symbol information from it, rather than reading
941the symbol table from the executable program.
942
943The @file{.syms} file is specific to the host machine where @value{GDBN}
944is run. It holds an exact image of the internal @value{GDBN} symbol
945table. It cannot be shared across multiple host platforms.
c906108c 946
c906108c
SS
947@item -r
948@itemx -readnow
d700128c
EZ
949@cindex @code{--readnow}
950@cindex @code{-r}
c906108c
SS
951Read each symbol file's entire symbol table immediately, rather than
952the default, which is to read it incrementally as it is needed.
953This makes startup slower, but makes future operations faster.
53a5351d 954
c906108c
SS
955@end table
956
2df3850c 957You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 958order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
959information. (@xref{Files,,Commands to specify files}, for information
960on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
961but build a @file{.syms} file for future use is:
c906108c 962
474c8240 963@smallexample
2df3850c 964gdb -batch -nx -mapped -readnow programname
474c8240 965@end smallexample
c906108c 966
6d2ebf8b 967@node Mode Options
c906108c
SS
968@subsection Choosing modes
969
970You can run @value{GDBN} in various alternative modes---for example, in
971batch mode or quiet mode.
972
973@table @code
974@item -nx
975@itemx -n
d700128c
EZ
976@cindex @code{--nx}
977@cindex @code{-n}
96565e91 978Do not execute commands found in any initialization files. Normally,
2df3850c
JM
979@value{GDBN} executes the commands in these files after all the command
980options and arguments have been processed. @xref{Command Files,,Command
981files}.
c906108c
SS
982
983@item -quiet
d700128c 984@itemx -silent
c906108c 985@itemx -q
d700128c
EZ
986@cindex @code{--quiet}
987@cindex @code{--silent}
988@cindex @code{-q}
c906108c
SS
989``Quiet''. Do not print the introductory and copyright messages. These
990messages are also suppressed in batch mode.
991
992@item -batch
d700128c 993@cindex @code{--batch}
c906108c
SS
994Run in batch mode. Exit with status @code{0} after processing all the
995command files specified with @samp{-x} (and all commands from
996initialization files, if not inhibited with @samp{-n}). Exit with
997nonzero status if an error occurs in executing the @value{GDBN} commands
998in the command files.
999
2df3850c
JM
1000Batch mode may be useful for running @value{GDBN} as a filter, for
1001example to download and run a program on another computer; in order to
1002make this more useful, the message
c906108c 1003
474c8240 1004@smallexample
c906108c 1005Program exited normally.
474c8240 1006@end smallexample
c906108c
SS
1007
1008@noindent
2df3850c
JM
1009(which is ordinarily issued whenever a program running under
1010@value{GDBN} control terminates) is not issued when running in batch
1011mode.
1012
1013@item -nowindows
1014@itemx -nw
d700128c
EZ
1015@cindex @code{--nowindows}
1016@cindex @code{-nw}
2df3850c 1017``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1018(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1019interface. If no GUI is available, this option has no effect.
1020
1021@item -windows
1022@itemx -w
d700128c
EZ
1023@cindex @code{--windows}
1024@cindex @code{-w}
2df3850c
JM
1025If @value{GDBN} includes a GUI, then this option requires it to be
1026used if possible.
c906108c
SS
1027
1028@item -cd @var{directory}
d700128c 1029@cindex @code{--cd}
c906108c
SS
1030Run @value{GDBN} using @var{directory} as its working directory,
1031instead of the current directory.
1032
c906108c
SS
1033@item -fullname
1034@itemx -f
d700128c
EZ
1035@cindex @code{--fullname}
1036@cindex @code{-f}
7a292a7a
SS
1037@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1038subprocess. It tells @value{GDBN} to output the full file name and line
1039number in a standard, recognizable fashion each time a stack frame is
1040displayed (which includes each time your program stops). This
1041recognizable format looks like two @samp{\032} characters, followed by
1042the file name, line number and character position separated by colons,
1043and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1044@samp{\032} characters as a signal to display the source code for the
1045frame.
c906108c 1046
d700128c
EZ
1047@item -epoch
1048@cindex @code{--epoch}
1049The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1050@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1051routines so as to allow Epoch to display values of expressions in a
1052separate window.
1053
1054@item -annotate @var{level}
1055@cindex @code{--annotate}
1056This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1057effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1058(@pxref{Annotations}). The annotation @var{level} controls how much
1059information @value{GDBN} prints together with its prompt, values of
1060expressions, source lines, and other types of output. Level 0 is the
1061normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1062@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1063that control @value{GDBN}, and level 2 has been deprecated.
1064
1065The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1066(@pxref{GDB/MI}).
d700128c
EZ
1067
1068@item -async
1069@cindex @code{--async}
1070Use the asynchronous event loop for the command-line interface.
1071@value{GDBN} processes all events, such as user keyboard input, via a
1072special event loop. This allows @value{GDBN} to accept and process user
1073commands in parallel with the debugged process being
1074run@footnote{@value{GDBN} built with @sc{djgpp} tools for
1075MS-DOS/MS-Windows supports this mode of operation, but the event loop is
1076suspended when the debuggee runs.}, so you don't need to wait for
1077control to return to @value{GDBN} before you type the next command.
b37052ae 1078(@emph{Note:} as of version 5.1, the target side of the asynchronous
d700128c
EZ
1079operation is not yet in place, so @samp{-async} does not work fully
1080yet.)
1081@c FIXME: when the target side of the event loop is done, the above NOTE
1082@c should be removed.
1083
1084When the standard input is connected to a terminal device, @value{GDBN}
1085uses the asynchronous event loop by default, unless disabled by the
1086@samp{-noasync} option.
1087
1088@item -noasync
1089@cindex @code{--noasync}
1090Disable the asynchronous event loop for the command-line interface.
1091
aa26fa3a
TT
1092@item --args
1093@cindex @code{--args}
1094Change interpretation of command line so that arguments following the
1095executable file are passed as command line arguments to the inferior.
1096This option stops option processing.
1097
2df3850c
JM
1098@item -baud @var{bps}
1099@itemx -b @var{bps}
d700128c
EZ
1100@cindex @code{--baud}
1101@cindex @code{-b}
c906108c
SS
1102Set the line speed (baud rate or bits per second) of any serial
1103interface used by @value{GDBN} for remote debugging.
c906108c
SS
1104
1105@item -tty @var{device}
d700128c
EZ
1106@itemx -t @var{device}
1107@cindex @code{--tty}
1108@cindex @code{-t}
c906108c
SS
1109Run using @var{device} for your program's standard input and output.
1110@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1111
53a5351d 1112@c resolve the situation of these eventually
c4555f82
SC
1113@item -tui
1114@cindex @code{--tui}
1115Activate the Terminal User Interface when starting.
1116The Terminal User Interface manages several text windows on the terminal,
1117showing source, assembly, registers and @value{GDBN} command outputs
1118(@pxref{TUI, ,@value{GDBN} Text User Interface}).
1119Do not use this option if you run @value{GDBN} from Emacs
1120(@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1121
1122@c @item -xdb
d700128c 1123@c @cindex @code{--xdb}
53a5351d
JM
1124@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1125@c For information, see the file @file{xdb_trans.html}, which is usually
1126@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1127@c systems.
1128
d700128c
EZ
1129@item -interpreter @var{interp}
1130@cindex @code{--interpreter}
1131Use the interpreter @var{interp} for interface with the controlling
1132program or device. This option is meant to be set by programs which
94bbb2c0 1133communicate with @value{GDBN} using it as a back end.
21c294e6 1134@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1135
da0f9dcd 1136@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0
AC
1137@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1138The @sc{gdb/mi} Interface}) included in @var{GDBN} version 6.0. The
1139previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3,
1140can be selected with @samp{--interpreter=mi1}. Earlier @sc{gdb/mi}
1141interfaces are not supported.
d700128c
EZ
1142
1143@item -write
1144@cindex @code{--write}
1145Open the executable and core files for both reading and writing. This
1146is equivalent to the @samp{set write on} command inside @value{GDBN}
1147(@pxref{Patching}).
1148
1149@item -statistics
1150@cindex @code{--statistics}
1151This option causes @value{GDBN} to print statistics about time and
1152memory usage after it completes each command and returns to the prompt.
1153
1154@item -version
1155@cindex @code{--version}
1156This option causes @value{GDBN} to print its version number and
1157no-warranty blurb, and exit.
1158
c906108c
SS
1159@end table
1160
6d2ebf8b 1161@node Quitting GDB
c906108c
SS
1162@section Quitting @value{GDBN}
1163@cindex exiting @value{GDBN}
1164@cindex leaving @value{GDBN}
1165
1166@table @code
1167@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1168@kindex q @r{(@code{quit})}
96a2c332
SS
1169@item quit @r{[}@var{expression}@r{]}
1170@itemx q
1171To exit @value{GDBN}, use the @code{quit} command (abbreviated
1172@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1173do not supply @var{expression}, @value{GDBN} will terminate normally;
1174otherwise it will terminate using the result of @var{expression} as the
1175error code.
c906108c
SS
1176@end table
1177
1178@cindex interrupt
1179An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1180terminates the action of any @value{GDBN} command that is in progress and
1181returns to @value{GDBN} command level. It is safe to type the interrupt
1182character at any time because @value{GDBN} does not allow it to take effect
1183until a time when it is safe.
1184
c906108c
SS
1185If you have been using @value{GDBN} to control an attached process or
1186device, you can release it with the @code{detach} command
1187(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1188
6d2ebf8b 1189@node Shell Commands
c906108c
SS
1190@section Shell commands
1191
1192If you need to execute occasional shell commands during your
1193debugging session, there is no need to leave or suspend @value{GDBN}; you can
1194just use the @code{shell} command.
1195
1196@table @code
1197@kindex shell
1198@cindex shell escape
1199@item shell @var{command string}
1200Invoke a standard shell to execute @var{command string}.
c906108c 1201If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1202shell to run. Otherwise @value{GDBN} uses the default shell
1203(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1204@end table
1205
1206The utility @code{make} is often needed in development environments.
1207You do not have to use the @code{shell} command for this purpose in
1208@value{GDBN}:
1209
1210@table @code
1211@kindex make
1212@cindex calling make
1213@item make @var{make-args}
1214Execute the @code{make} program with the specified
1215arguments. This is equivalent to @samp{shell make @var{make-args}}.
1216@end table
1217
0fac0b41
DJ
1218@node Logging output
1219@section Logging output
1220@cindex logging @value{GDBN} output
1221
1222You may want to save the output of @value{GDBN} commands to a file.
1223There are several commands to control @value{GDBN}'s logging.
1224
1225@table @code
1226@kindex set logging
1227@item set logging on
1228Enable logging.
1229@item set logging off
1230Disable logging.
1231@item set logging file @var{file}
1232Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1233@item set logging overwrite [on|off]
1234By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1235you want @code{set logging on} to overwrite the logfile instead.
1236@item set logging redirect [on|off]
1237By default, @value{GDBN} output will go to both the terminal and the logfile.
1238Set @code{redirect} if you want output to go only to the log file.
1239@kindex show logging
1240@item show logging
1241Show the current values of the logging settings.
1242@end table
1243
6d2ebf8b 1244@node Commands
c906108c
SS
1245@chapter @value{GDBN} Commands
1246
1247You can abbreviate a @value{GDBN} command to the first few letters of the command
1248name, if that abbreviation is unambiguous; and you can repeat certain
1249@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1250key to get @value{GDBN} to fill out the rest of a word in a command (or to
1251show you the alternatives available, if there is more than one possibility).
1252
1253@menu
1254* Command Syntax:: How to give commands to @value{GDBN}
1255* Completion:: Command completion
1256* Help:: How to ask @value{GDBN} for help
1257@end menu
1258
6d2ebf8b 1259@node Command Syntax
c906108c
SS
1260@section Command syntax
1261
1262A @value{GDBN} command is a single line of input. There is no limit on
1263how long it can be. It starts with a command name, which is followed by
1264arguments whose meaning depends on the command name. For example, the
1265command @code{step} accepts an argument which is the number of times to
1266step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1267with no arguments. Some commands do not allow any arguments.
c906108c
SS
1268
1269@cindex abbreviation
1270@value{GDBN} command names may always be truncated if that abbreviation is
1271unambiguous. Other possible command abbreviations are listed in the
1272documentation for individual commands. In some cases, even ambiguous
1273abbreviations are allowed; for example, @code{s} is specially defined as
1274equivalent to @code{step} even though there are other commands whose
1275names start with @code{s}. You can test abbreviations by using them as
1276arguments to the @code{help} command.
1277
1278@cindex repeating commands
41afff9a 1279@kindex RET @r{(repeat last command)}
c906108c 1280A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1281repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1282will not repeat this way; these are commands whose unintentional
1283repetition might cause trouble and which you are unlikely to want to
1284repeat.
1285
1286The @code{list} and @code{x} commands, when you repeat them with
1287@key{RET}, construct new arguments rather than repeating
1288exactly as typed. This permits easy scanning of source or memory.
1289
1290@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1291output, in a way similar to the common utility @code{more}
1292(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1293@key{RET} too many in this situation, @value{GDBN} disables command
1294repetition after any command that generates this sort of display.
1295
41afff9a 1296@kindex # @r{(a comment)}
c906108c
SS
1297@cindex comment
1298Any text from a @kbd{#} to the end of the line is a comment; it does
1299nothing. This is useful mainly in command files (@pxref{Command
1300Files,,Command files}).
1301
88118b3a
TT
1302@cindex repeating command sequences
1303@kindex C-o @r{(operate-and-get-next)}
1304The @kbd{C-o} binding is useful for repeating a complex sequence of
1305commands. This command accepts the current line, like @kbd{RET}, and
1306then fetches the next line relative to the current line from the history
1307for editing.
1308
6d2ebf8b 1309@node Completion
c906108c
SS
1310@section Command completion
1311
1312@cindex completion
1313@cindex word completion
1314@value{GDBN} can fill in the rest of a word in a command for you, if there is
1315only one possibility; it can also show you what the valid possibilities
1316are for the next word in a command, at any time. This works for @value{GDBN}
1317commands, @value{GDBN} subcommands, and the names of symbols in your program.
1318
1319Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1320of a word. If there is only one possibility, @value{GDBN} fills in the
1321word, and waits for you to finish the command (or press @key{RET} to
1322enter it). For example, if you type
1323
1324@c FIXME "@key" does not distinguish its argument sufficiently to permit
1325@c complete accuracy in these examples; space introduced for clarity.
1326@c If texinfo enhancements make it unnecessary, it would be nice to
1327@c replace " @key" by "@key" in the following...
474c8240 1328@smallexample
c906108c 1329(@value{GDBP}) info bre @key{TAB}
474c8240 1330@end smallexample
c906108c
SS
1331
1332@noindent
1333@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1334the only @code{info} subcommand beginning with @samp{bre}:
1335
474c8240 1336@smallexample
c906108c 1337(@value{GDBP}) info breakpoints
474c8240 1338@end smallexample
c906108c
SS
1339
1340@noindent
1341You can either press @key{RET} at this point, to run the @code{info
1342breakpoints} command, or backspace and enter something else, if
1343@samp{breakpoints} does not look like the command you expected. (If you
1344were sure you wanted @code{info breakpoints} in the first place, you
1345might as well just type @key{RET} immediately after @samp{info bre},
1346to exploit command abbreviations rather than command completion).
1347
1348If there is more than one possibility for the next word when you press
1349@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1350characters and try again, or just press @key{TAB} a second time;
1351@value{GDBN} displays all the possible completions for that word. For
1352example, you might want to set a breakpoint on a subroutine whose name
1353begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1354just sounds the bell. Typing @key{TAB} again displays all the
1355function names in your program that begin with those characters, for
1356example:
1357
474c8240 1358@smallexample
c906108c
SS
1359(@value{GDBP}) b make_ @key{TAB}
1360@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1361make_a_section_from_file make_environ
1362make_abs_section make_function_type
1363make_blockvector make_pointer_type
1364make_cleanup make_reference_type
c906108c
SS
1365make_command make_symbol_completion_list
1366(@value{GDBP}) b make_
474c8240 1367@end smallexample
c906108c
SS
1368
1369@noindent
1370After displaying the available possibilities, @value{GDBN} copies your
1371partial input (@samp{b make_} in the example) so you can finish the
1372command.
1373
1374If you just want to see the list of alternatives in the first place, you
b37052ae 1375can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1376means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1377key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1378one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1379
1380@cindex quotes in commands
1381@cindex completion of quoted strings
1382Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1383parentheses or other characters that @value{GDBN} normally excludes from
1384its notion of a word. To permit word completion to work in this
1385situation, you may enclose words in @code{'} (single quote marks) in
1386@value{GDBN} commands.
c906108c 1387
c906108c 1388The most likely situation where you might need this is in typing the
b37052ae
EZ
1389name of a C@t{++} function. This is because C@t{++} allows function
1390overloading (multiple definitions of the same function, distinguished
1391by argument type). For example, when you want to set a breakpoint you
1392may need to distinguish whether you mean the version of @code{name}
1393that takes an @code{int} parameter, @code{name(int)}, or the version
1394that takes a @code{float} parameter, @code{name(float)}. To use the
1395word-completion facilities in this situation, type a single quote
1396@code{'} at the beginning of the function name. This alerts
1397@value{GDBN} that it may need to consider more information than usual
1398when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1399
474c8240 1400@smallexample
96a2c332 1401(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1402bubble(double,double) bubble(int,int)
1403(@value{GDBP}) b 'bubble(
474c8240 1404@end smallexample
c906108c
SS
1405
1406In some cases, @value{GDBN} can tell that completing a name requires using
1407quotes. When this happens, @value{GDBN} inserts the quote for you (while
1408completing as much as it can) if you do not type the quote in the first
1409place:
1410
474c8240 1411@smallexample
c906108c
SS
1412(@value{GDBP}) b bub @key{TAB}
1413@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1414(@value{GDBP}) b 'bubble(
474c8240 1415@end smallexample
c906108c
SS
1416
1417@noindent
1418In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1419you have not yet started typing the argument list when you ask for
1420completion on an overloaded symbol.
1421
d4f3574e 1422For more information about overloaded functions, see @ref{C plus plus
b37052ae 1423expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1424overload-resolution off} to disable overload resolution;
b37052ae 1425see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1426
1427
6d2ebf8b 1428@node Help
c906108c
SS
1429@section Getting help
1430@cindex online documentation
1431@kindex help
1432
5d161b24 1433You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1434using the command @code{help}.
1435
1436@table @code
41afff9a 1437@kindex h @r{(@code{help})}
c906108c
SS
1438@item help
1439@itemx h
1440You can use @code{help} (abbreviated @code{h}) with no arguments to
1441display a short list of named classes of commands:
1442
1443@smallexample
1444(@value{GDBP}) help
1445List of classes of commands:
1446
2df3850c 1447aliases -- Aliases of other commands
c906108c 1448breakpoints -- Making program stop at certain points
2df3850c 1449data -- Examining data
c906108c 1450files -- Specifying and examining files
2df3850c
JM
1451internals -- Maintenance commands
1452obscure -- Obscure features
1453running -- Running the program
1454stack -- Examining the stack
c906108c
SS
1455status -- Status inquiries
1456support -- Support facilities
96a2c332
SS
1457tracepoints -- Tracing of program execution without@*
1458 stopping the program
c906108c 1459user-defined -- User-defined commands
c906108c 1460
5d161b24 1461Type "help" followed by a class name for a list of
c906108c 1462commands in that class.
5d161b24 1463Type "help" followed by command name for full
c906108c
SS
1464documentation.
1465Command name abbreviations are allowed if unambiguous.
1466(@value{GDBP})
1467@end smallexample
96a2c332 1468@c the above line break eliminates huge line overfull...
c906108c
SS
1469
1470@item help @var{class}
1471Using one of the general help classes as an argument, you can get a
1472list of the individual commands in that class. For example, here is the
1473help display for the class @code{status}:
1474
1475@smallexample
1476(@value{GDBP}) help status
1477Status inquiries.
1478
1479List of commands:
1480
1481@c Line break in "show" line falsifies real output, but needed
1482@c to fit in smallbook page size.
2df3850c
JM
1483info -- Generic command for showing things
1484 about the program being debugged
1485show -- Generic command for showing things
1486 about the debugger
c906108c 1487
5d161b24 1488Type "help" followed by command name for full
c906108c
SS
1489documentation.
1490Command name abbreviations are allowed if unambiguous.
1491(@value{GDBP})
1492@end smallexample
1493
1494@item help @var{command}
1495With a command name as @code{help} argument, @value{GDBN} displays a
1496short paragraph on how to use that command.
1497
6837a0a2
DB
1498@kindex apropos
1499@item apropos @var{args}
1500The @code{apropos @var{args}} command searches through all of the @value{GDBN}
1501commands, and their documentation, for the regular expression specified in
1502@var{args}. It prints out all matches found. For example:
1503
1504@smallexample
1505apropos reload
1506@end smallexample
1507
b37052ae
EZ
1508@noindent
1509results in:
6837a0a2
DB
1510
1511@smallexample
6d2ebf8b
SS
1512@c @group
1513set symbol-reloading -- Set dynamic symbol table reloading
1514 multiple times in one run
1515show symbol-reloading -- Show dynamic symbol table reloading
1516 multiple times in one run
1517@c @end group
6837a0a2
DB
1518@end smallexample
1519
c906108c
SS
1520@kindex complete
1521@item complete @var{args}
1522The @code{complete @var{args}} command lists all the possible completions
1523for the beginning of a command. Use @var{args} to specify the beginning of the
1524command you want completed. For example:
1525
1526@smallexample
1527complete i
1528@end smallexample
1529
1530@noindent results in:
1531
1532@smallexample
1533@group
2df3850c
JM
1534if
1535ignore
c906108c
SS
1536info
1537inspect
c906108c
SS
1538@end group
1539@end smallexample
1540
1541@noindent This is intended for use by @sc{gnu} Emacs.
1542@end table
1543
1544In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1545and @code{show} to inquire about the state of your program, or the state
1546of @value{GDBN} itself. Each command supports many topics of inquiry; this
1547manual introduces each of them in the appropriate context. The listings
1548under @code{info} and under @code{show} in the Index point to
1549all the sub-commands. @xref{Index}.
1550
1551@c @group
1552@table @code
1553@kindex info
41afff9a 1554@kindex i @r{(@code{info})}
c906108c
SS
1555@item info
1556This command (abbreviated @code{i}) is for describing the state of your
1557program. For example, you can list the arguments given to your program
1558with @code{info args}, list the registers currently in use with @code{info
1559registers}, or list the breakpoints you have set with @code{info breakpoints}.
1560You can get a complete list of the @code{info} sub-commands with
1561@w{@code{help info}}.
1562
1563@kindex set
1564@item set
5d161b24 1565You can assign the result of an expression to an environment variable with
c906108c
SS
1566@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1567@code{set prompt $}.
1568
1569@kindex show
1570@item show
5d161b24 1571In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1572@value{GDBN} itself.
1573You can change most of the things you can @code{show}, by using the
1574related command @code{set}; for example, you can control what number
1575system is used for displays with @code{set radix}, or simply inquire
1576which is currently in use with @code{show radix}.
1577
1578@kindex info set
1579To display all the settable parameters and their current
1580values, you can use @code{show} with no arguments; you may also use
1581@code{info set}. Both commands produce the same display.
1582@c FIXME: "info set" violates the rule that "info" is for state of
1583@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1584@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1585@end table
1586@c @end group
1587
1588Here are three miscellaneous @code{show} subcommands, all of which are
1589exceptional in lacking corresponding @code{set} commands:
1590
1591@table @code
1592@kindex show version
1593@cindex version number
1594@item show version
1595Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1596information in @value{GDBN} bug-reports. If multiple versions of
1597@value{GDBN} are in use at your site, you may need to determine which
1598version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1599commands are introduced, and old ones may wither away. Also, many
1600system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1601variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1602The version number is the same as the one announced when you start
1603@value{GDBN}.
c906108c
SS
1604
1605@kindex show copying
1606@item show copying
1607Display information about permission for copying @value{GDBN}.
1608
1609@kindex show warranty
1610@item show warranty
2df3850c 1611Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1612if your version of @value{GDBN} comes with one.
2df3850c 1613
c906108c
SS
1614@end table
1615
6d2ebf8b 1616@node Running
c906108c
SS
1617@chapter Running Programs Under @value{GDBN}
1618
1619When you run a program under @value{GDBN}, you must first generate
1620debugging information when you compile it.
7a292a7a
SS
1621
1622You may start @value{GDBN} with its arguments, if any, in an environment
1623of your choice. If you are doing native debugging, you may redirect
1624your program's input and output, debug an already running process, or
1625kill a child process.
c906108c
SS
1626
1627@menu
1628* Compilation:: Compiling for debugging
1629* Starting:: Starting your program
c906108c
SS
1630* Arguments:: Your program's arguments
1631* Environment:: Your program's environment
c906108c
SS
1632
1633* Working Directory:: Your program's working directory
1634* Input/Output:: Your program's input and output
1635* Attach:: Debugging an already-running process
1636* Kill Process:: Killing the child process
c906108c
SS
1637
1638* Threads:: Debugging programs with multiple threads
1639* Processes:: Debugging programs with multiple processes
1640@end menu
1641
6d2ebf8b 1642@node Compilation
c906108c
SS
1643@section Compiling for debugging
1644
1645In order to debug a program effectively, you need to generate
1646debugging information when you compile it. This debugging information
1647is stored in the object file; it describes the data type of each
1648variable or function and the correspondence between source line numbers
1649and addresses in the executable code.
1650
1651To request debugging information, specify the @samp{-g} option when you run
1652the compiler.
1653
e2e0bcd1
JB
1654Most compilers do not include information about preprocessor macros in
1655the debugging information if you specify the @option{-g} flag alone,
1656because this information is rather large. Version 3.1 of @value{NGCC},
1657the @sc{gnu} C compiler, provides macro information if you specify the
1658options @option{-gdwarf-2} and @option{-g3}; the former option requests
1659debugging information in the Dwarf 2 format, and the latter requests
1660``extra information''. In the future, we hope to find more compact ways
1661to represent macro information, so that it can be included with
1662@option{-g} alone.
1663
c906108c
SS
1664Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1665options together. Using those compilers, you cannot generate optimized
1666executables containing debugging information.
1667
53a5351d
JM
1668@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1669without @samp{-O}, making it possible to debug optimized code. We
1670recommend that you @emph{always} use @samp{-g} whenever you compile a
1671program. You may think your program is correct, but there is no sense
1672in pushing your luck.
c906108c
SS
1673
1674@cindex optimized code, debugging
1675@cindex debugging optimized code
1676When you debug a program compiled with @samp{-g -O}, remember that the
1677optimizer is rearranging your code; the debugger shows you what is
1678really there. Do not be too surprised when the execution path does not
1679exactly match your source file! An extreme example: if you define a
1680variable, but never use it, @value{GDBN} never sees that
1681variable---because the compiler optimizes it out of existence.
1682
1683Some things do not work as well with @samp{-g -O} as with just
1684@samp{-g}, particularly on machines with instruction scheduling. If in
1685doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1686please report it to us as a bug (including a test case!).
1687
1688Older versions of the @sc{gnu} C compiler permitted a variant option
1689@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1690format; if your @sc{gnu} C compiler has this option, do not use it.
1691
1692@need 2000
6d2ebf8b 1693@node Starting
c906108c
SS
1694@section Starting your program
1695@cindex starting
1696@cindex running
1697
1698@table @code
1699@kindex run
41afff9a 1700@kindex r @r{(@code{run})}
c906108c
SS
1701@item run
1702@itemx r
7a292a7a
SS
1703Use the @code{run} command to start your program under @value{GDBN}.
1704You must first specify the program name (except on VxWorks) with an
1705argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1706@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1707(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1708
1709@end table
1710
c906108c
SS
1711If you are running your program in an execution environment that
1712supports processes, @code{run} creates an inferior process and makes
1713that process run your program. (In environments without processes,
1714@code{run} jumps to the start of your program.)
1715
1716The execution of a program is affected by certain information it
1717receives from its superior. @value{GDBN} provides ways to specify this
1718information, which you must do @emph{before} starting your program. (You
1719can change it after starting your program, but such changes only affect
1720your program the next time you start it.) This information may be
1721divided into four categories:
1722
1723@table @asis
1724@item The @emph{arguments.}
1725Specify the arguments to give your program as the arguments of the
1726@code{run} command. If a shell is available on your target, the shell
1727is used to pass the arguments, so that you may use normal conventions
1728(such as wildcard expansion or variable substitution) in describing
1729the arguments.
1730In Unix systems, you can control which shell is used with the
1731@code{SHELL} environment variable.
1732@xref{Arguments, ,Your program's arguments}.
1733
1734@item The @emph{environment.}
1735Your program normally inherits its environment from @value{GDBN}, but you can
1736use the @value{GDBN} commands @code{set environment} and @code{unset
1737environment} to change parts of the environment that affect
1738your program. @xref{Environment, ,Your program's environment}.
1739
1740@item The @emph{working directory.}
1741Your program inherits its working directory from @value{GDBN}. You can set
1742the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1743@xref{Working Directory, ,Your program's working directory}.
1744
1745@item The @emph{standard input and output.}
1746Your program normally uses the same device for standard input and
1747standard output as @value{GDBN} is using. You can redirect input and output
1748in the @code{run} command line, or you can use the @code{tty} command to
1749set a different device for your program.
1750@xref{Input/Output, ,Your program's input and output}.
1751
1752@cindex pipes
1753@emph{Warning:} While input and output redirection work, you cannot use
1754pipes to pass the output of the program you are debugging to another
1755program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1756wrong program.
1757@end table
c906108c
SS
1758
1759When you issue the @code{run} command, your program begins to execute
1760immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1761of how to arrange for your program to stop. Once your program has
1762stopped, you may call functions in your program, using the @code{print}
1763or @code{call} commands. @xref{Data, ,Examining Data}.
1764
1765If the modification time of your symbol file has changed since the last
1766time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1767table, and reads it again. When it does this, @value{GDBN} tries to retain
1768your current breakpoints.
1769
6d2ebf8b 1770@node Arguments
c906108c
SS
1771@section Your program's arguments
1772
1773@cindex arguments (to your program)
1774The arguments to your program can be specified by the arguments of the
5d161b24 1775@code{run} command.
c906108c
SS
1776They are passed to a shell, which expands wildcard characters and
1777performs redirection of I/O, and thence to your program. Your
1778@code{SHELL} environment variable (if it exists) specifies what shell
1779@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1780the default shell (@file{/bin/sh} on Unix).
1781
1782On non-Unix systems, the program is usually invoked directly by
1783@value{GDBN}, which emulates I/O redirection via the appropriate system
1784calls, and the wildcard characters are expanded by the startup code of
1785the program, not by the shell.
c906108c
SS
1786
1787@code{run} with no arguments uses the same arguments used by the previous
1788@code{run}, or those set by the @code{set args} command.
1789
c906108c 1790@table @code
41afff9a 1791@kindex set args
c906108c
SS
1792@item set args
1793Specify the arguments to be used the next time your program is run. If
1794@code{set args} has no arguments, @code{run} executes your program
1795with no arguments. Once you have run your program with arguments,
1796using @code{set args} before the next @code{run} is the only way to run
1797it again without arguments.
1798
1799@kindex show args
1800@item show args
1801Show the arguments to give your program when it is started.
1802@end table
1803
6d2ebf8b 1804@node Environment
c906108c
SS
1805@section Your program's environment
1806
1807@cindex environment (of your program)
1808The @dfn{environment} consists of a set of environment variables and
1809their values. Environment variables conventionally record such things as
1810your user name, your home directory, your terminal type, and your search
1811path for programs to run. Usually you set up environment variables with
1812the shell and they are inherited by all the other programs you run. When
1813debugging, it can be useful to try running your program with a modified
1814environment without having to start @value{GDBN} over again.
1815
1816@table @code
1817@kindex path
1818@item path @var{directory}
1819Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1820(the search path for executables) that will be passed to your program.
1821The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1822You may specify several directory names, separated by whitespace or by a
1823system-dependent separator character (@samp{:} on Unix, @samp{;} on
1824MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1825is moved to the front, so it is searched sooner.
c906108c
SS
1826
1827You can use the string @samp{$cwd} to refer to whatever is the current
1828working directory at the time @value{GDBN} searches the path. If you
1829use @samp{.} instead, it refers to the directory where you executed the
1830@code{path} command. @value{GDBN} replaces @samp{.} in the
1831@var{directory} argument (with the current path) before adding
1832@var{directory} to the search path.
1833@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1834@c document that, since repeating it would be a no-op.
1835
1836@kindex show paths
1837@item show paths
1838Display the list of search paths for executables (the @code{PATH}
1839environment variable).
1840
1841@kindex show environment
1842@item show environment @r{[}@var{varname}@r{]}
1843Print the value of environment variable @var{varname} to be given to
1844your program when it starts. If you do not supply @var{varname},
1845print the names and values of all environment variables to be given to
1846your program. You can abbreviate @code{environment} as @code{env}.
1847
1848@kindex set environment
53a5351d 1849@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1850Set environment variable @var{varname} to @var{value}. The value
1851changes for your program only, not for @value{GDBN} itself. @var{value} may
1852be any string; the values of environment variables are just strings, and
1853any interpretation is supplied by your program itself. The @var{value}
1854parameter is optional; if it is eliminated, the variable is set to a
1855null value.
1856@c "any string" here does not include leading, trailing
1857@c blanks. Gnu asks: does anyone care?
1858
1859For example, this command:
1860
474c8240 1861@smallexample
c906108c 1862set env USER = foo
474c8240 1863@end smallexample
c906108c
SS
1864
1865@noindent
d4f3574e 1866tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1867@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1868are not actually required.)
1869
1870@kindex unset environment
1871@item unset environment @var{varname}
1872Remove variable @var{varname} from the environment to be passed to your
1873program. This is different from @samp{set env @var{varname} =};
1874@code{unset environment} removes the variable from the environment,
1875rather than assigning it an empty value.
1876@end table
1877
d4f3574e
SS
1878@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1879the shell indicated
c906108c
SS
1880by your @code{SHELL} environment variable if it exists (or
1881@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1882that runs an initialization file---such as @file{.cshrc} for C-shell, or
1883@file{.bashrc} for BASH---any variables you set in that file affect
1884your program. You may wish to move setting of environment variables to
1885files that are only run when you sign on, such as @file{.login} or
1886@file{.profile}.
1887
6d2ebf8b 1888@node Working Directory
c906108c
SS
1889@section Your program's working directory
1890
1891@cindex working directory (of your program)
1892Each time you start your program with @code{run}, it inherits its
1893working directory from the current working directory of @value{GDBN}.
1894The @value{GDBN} working directory is initially whatever it inherited
1895from its parent process (typically the shell), but you can specify a new
1896working directory in @value{GDBN} with the @code{cd} command.
1897
1898The @value{GDBN} working directory also serves as a default for the commands
1899that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1900specify files}.
1901
1902@table @code
1903@kindex cd
1904@item cd @var{directory}
1905Set the @value{GDBN} working directory to @var{directory}.
1906
1907@kindex pwd
1908@item pwd
1909Print the @value{GDBN} working directory.
1910@end table
1911
6d2ebf8b 1912@node Input/Output
c906108c
SS
1913@section Your program's input and output
1914
1915@cindex redirection
1916@cindex i/o
1917@cindex terminal
1918By default, the program you run under @value{GDBN} does input and output to
5d161b24 1919the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1920to its own terminal modes to interact with you, but it records the terminal
1921modes your program was using and switches back to them when you continue
1922running your program.
1923
1924@table @code
1925@kindex info terminal
1926@item info terminal
1927Displays information recorded by @value{GDBN} about the terminal modes your
1928program is using.
1929@end table
1930
1931You can redirect your program's input and/or output using shell
1932redirection with the @code{run} command. For example,
1933
474c8240 1934@smallexample
c906108c 1935run > outfile
474c8240 1936@end smallexample
c906108c
SS
1937
1938@noindent
1939starts your program, diverting its output to the file @file{outfile}.
1940
1941@kindex tty
1942@cindex controlling terminal
1943Another way to specify where your program should do input and output is
1944with the @code{tty} command. This command accepts a file name as
1945argument, and causes this file to be the default for future @code{run}
1946commands. It also resets the controlling terminal for the child
1947process, for future @code{run} commands. For example,
1948
474c8240 1949@smallexample
c906108c 1950tty /dev/ttyb
474c8240 1951@end smallexample
c906108c
SS
1952
1953@noindent
1954directs that processes started with subsequent @code{run} commands
1955default to do input and output on the terminal @file{/dev/ttyb} and have
1956that as their controlling terminal.
1957
1958An explicit redirection in @code{run} overrides the @code{tty} command's
1959effect on the input/output device, but not its effect on the controlling
1960terminal.
1961
1962When you use the @code{tty} command or redirect input in the @code{run}
1963command, only the input @emph{for your program} is affected. The input
1964for @value{GDBN} still comes from your terminal.
1965
6d2ebf8b 1966@node Attach
c906108c
SS
1967@section Debugging an already-running process
1968@kindex attach
1969@cindex attach
1970
1971@table @code
1972@item attach @var{process-id}
1973This command attaches to a running process---one that was started
1974outside @value{GDBN}. (@code{info files} shows your active
1975targets.) The command takes as argument a process ID. The usual way to
1976find out the process-id of a Unix process is with the @code{ps} utility,
1977or with the @samp{jobs -l} shell command.
1978
1979@code{attach} does not repeat if you press @key{RET} a second time after
1980executing the command.
1981@end table
1982
1983To use @code{attach}, your program must be running in an environment
1984which supports processes; for example, @code{attach} does not work for
1985programs on bare-board targets that lack an operating system. You must
1986also have permission to send the process a signal.
1987
1988When you use @code{attach}, the debugger finds the program running in
1989the process first by looking in the current working directory, then (if
1990the program is not found) by using the source file search path
1991(@pxref{Source Path, ,Specifying source directories}). You can also use
1992the @code{file} command to load the program. @xref{Files, ,Commands to
1993Specify Files}.
1994
1995The first thing @value{GDBN} does after arranging to debug the specified
1996process is to stop it. You can examine and modify an attached process
53a5351d
JM
1997with all the @value{GDBN} commands that are ordinarily available when
1998you start processes with @code{run}. You can insert breakpoints; you
1999can step and continue; you can modify storage. If you would rather the
2000process continue running, you may use the @code{continue} command after
c906108c
SS
2001attaching @value{GDBN} to the process.
2002
2003@table @code
2004@kindex detach
2005@item detach
2006When you have finished debugging the attached process, you can use the
2007@code{detach} command to release it from @value{GDBN} control. Detaching
2008the process continues its execution. After the @code{detach} command,
2009that process and @value{GDBN} become completely independent once more, and you
2010are ready to @code{attach} another process or start one with @code{run}.
2011@code{detach} does not repeat if you press @key{RET} again after
2012executing the command.
2013@end table
2014
2015If you exit @value{GDBN} or use the @code{run} command while you have an
2016attached process, you kill that process. By default, @value{GDBN} asks
2017for confirmation if you try to do either of these things; you can
2018control whether or not you need to confirm by using the @code{set
2019confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2020messages}).
2021
6d2ebf8b 2022@node Kill Process
c906108c 2023@section Killing the child process
c906108c
SS
2024
2025@table @code
2026@kindex kill
2027@item kill
2028Kill the child process in which your program is running under @value{GDBN}.
2029@end table
2030
2031This command is useful if you wish to debug a core dump instead of a
2032running process. @value{GDBN} ignores any core dump file while your program
2033is running.
2034
2035On some operating systems, a program cannot be executed outside @value{GDBN}
2036while you have breakpoints set on it inside @value{GDBN}. You can use the
2037@code{kill} command in this situation to permit running your program
2038outside the debugger.
2039
2040The @code{kill} command is also useful if you wish to recompile and
2041relink your program, since on many systems it is impossible to modify an
2042executable file while it is running in a process. In this case, when you
2043next type @code{run}, @value{GDBN} notices that the file has changed, and
2044reads the symbol table again (while trying to preserve your current
2045breakpoint settings).
2046
6d2ebf8b 2047@node Threads
c906108c 2048@section Debugging programs with multiple threads
c906108c
SS
2049
2050@cindex threads of execution
2051@cindex multiple threads
2052@cindex switching threads
2053In some operating systems, such as HP-UX and Solaris, a single program
2054may have more than one @dfn{thread} of execution. The precise semantics
2055of threads differ from one operating system to another, but in general
2056the threads of a single program are akin to multiple processes---except
2057that they share one address space (that is, they can all examine and
2058modify the same variables). On the other hand, each thread has its own
2059registers and execution stack, and perhaps private memory.
2060
2061@value{GDBN} provides these facilities for debugging multi-thread
2062programs:
2063
2064@itemize @bullet
2065@item automatic notification of new threads
2066@item @samp{thread @var{threadno}}, a command to switch among threads
2067@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2068@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2069a command to apply a command to a list of threads
2070@item thread-specific breakpoints
2071@end itemize
2072
c906108c
SS
2073@quotation
2074@emph{Warning:} These facilities are not yet available on every
2075@value{GDBN} configuration where the operating system supports threads.
2076If your @value{GDBN} does not support threads, these commands have no
2077effect. For example, a system without thread support shows no output
2078from @samp{info threads}, and always rejects the @code{thread} command,
2079like this:
2080
2081@smallexample
2082(@value{GDBP}) info threads
2083(@value{GDBP}) thread 1
2084Thread ID 1 not known. Use the "info threads" command to
2085see the IDs of currently known threads.
2086@end smallexample
2087@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2088@c doesn't support threads"?
2089@end quotation
c906108c
SS
2090
2091@cindex focus of debugging
2092@cindex current thread
2093The @value{GDBN} thread debugging facility allows you to observe all
2094threads while your program runs---but whenever @value{GDBN} takes
2095control, one thread in particular is always the focus of debugging.
2096This thread is called the @dfn{current thread}. Debugging commands show
2097program information from the perspective of the current thread.
2098
41afff9a 2099@cindex @code{New} @var{systag} message
c906108c
SS
2100@cindex thread identifier (system)
2101@c FIXME-implementors!! It would be more helpful if the [New...] message
2102@c included GDB's numeric thread handle, so you could just go to that
2103@c thread without first checking `info threads'.
2104Whenever @value{GDBN} detects a new thread in your program, it displays
2105the target system's identification for the thread with a message in the
2106form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2107whose form varies depending on the particular system. For example, on
2108LynxOS, you might see
2109
474c8240 2110@smallexample
c906108c 2111[New process 35 thread 27]
474c8240 2112@end smallexample
c906108c
SS
2113
2114@noindent
2115when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2116the @var{systag} is simply something like @samp{process 368}, with no
2117further qualifier.
2118
2119@c FIXME!! (1) Does the [New...] message appear even for the very first
2120@c thread of a program, or does it only appear for the
6ca652b0 2121@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2122@c program?
2123@c (2) *Is* there necessarily a first thread always? Or do some
2124@c multithread systems permit starting a program with multiple
5d161b24 2125@c threads ab initio?
c906108c
SS
2126
2127@cindex thread number
2128@cindex thread identifier (GDB)
2129For debugging purposes, @value{GDBN} associates its own thread
2130number---always a single integer---with each thread in your program.
2131
2132@table @code
2133@kindex info threads
2134@item info threads
2135Display a summary of all threads currently in your
2136program. @value{GDBN} displays for each thread (in this order):
2137
2138@enumerate
2139@item the thread number assigned by @value{GDBN}
2140
2141@item the target system's thread identifier (@var{systag})
2142
2143@item the current stack frame summary for that thread
2144@end enumerate
2145
2146@noindent
2147An asterisk @samp{*} to the left of the @value{GDBN} thread number
2148indicates the current thread.
2149
5d161b24 2150For example,
c906108c
SS
2151@end table
2152@c end table here to get a little more width for example
2153
2154@smallexample
2155(@value{GDBP}) info threads
2156 3 process 35 thread 27 0x34e5 in sigpause ()
2157 2 process 35 thread 23 0x34e5 in sigpause ()
2158* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2159 at threadtest.c:68
2160@end smallexample
53a5351d
JM
2161
2162On HP-UX systems:
c906108c
SS
2163
2164@cindex thread number
2165@cindex thread identifier (GDB)
2166For debugging purposes, @value{GDBN} associates its own thread
2167number---a small integer assigned in thread-creation order---with each
2168thread in your program.
2169
41afff9a
EZ
2170@cindex @code{New} @var{systag} message, on HP-UX
2171@cindex thread identifier (system), on HP-UX
c906108c
SS
2172@c FIXME-implementors!! It would be more helpful if the [New...] message
2173@c included GDB's numeric thread handle, so you could just go to that
2174@c thread without first checking `info threads'.
2175Whenever @value{GDBN} detects a new thread in your program, it displays
2176both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2177form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2178whose form varies depending on the particular system. For example, on
2179HP-UX, you see
2180
474c8240 2181@smallexample
c906108c 2182[New thread 2 (system thread 26594)]
474c8240 2183@end smallexample
c906108c
SS
2184
2185@noindent
5d161b24 2186when @value{GDBN} notices a new thread.
c906108c
SS
2187
2188@table @code
2189@kindex info threads
2190@item info threads
2191Display a summary of all threads currently in your
2192program. @value{GDBN} displays for each thread (in this order):
2193
2194@enumerate
2195@item the thread number assigned by @value{GDBN}
2196
2197@item the target system's thread identifier (@var{systag})
2198
2199@item the current stack frame summary for that thread
2200@end enumerate
2201
2202@noindent
2203An asterisk @samp{*} to the left of the @value{GDBN} thread number
2204indicates the current thread.
2205
5d161b24 2206For example,
c906108c
SS
2207@end table
2208@c end table here to get a little more width for example
2209
474c8240 2210@smallexample
c906108c 2211(@value{GDBP}) info threads
6d2ebf8b
SS
2212 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2213 at quicksort.c:137
2214 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2215 from /usr/lib/libc.2
2216 1 system thread 27905 0x7b003498 in _brk () \@*
2217 from /usr/lib/libc.2
474c8240 2218@end smallexample
c906108c
SS
2219
2220@table @code
2221@kindex thread @var{threadno}
2222@item thread @var{threadno}
2223Make thread number @var{threadno} the current thread. The command
2224argument @var{threadno} is the internal @value{GDBN} thread number, as
2225shown in the first field of the @samp{info threads} display.
2226@value{GDBN} responds by displaying the system identifier of the thread
2227you selected, and its current stack frame summary:
2228
2229@smallexample
2230@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2231(@value{GDBP}) thread 2
c906108c 2232[Switching to process 35 thread 23]
c906108c
SS
22330x34e5 in sigpause ()
2234@end smallexample
2235
2236@noindent
2237As with the @samp{[New @dots{}]} message, the form of the text after
2238@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2239threads.
c906108c
SS
2240
2241@kindex thread apply
2242@item thread apply [@var{threadno}] [@var{all}] @var{args}
2243The @code{thread apply} command allows you to apply a command to one or
2244more threads. Specify the numbers of the threads that you want affected
2245with the command argument @var{threadno}. @var{threadno} is the internal
2246@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2247threads} display. To apply a command to all threads, use
2248@code{thread apply all} @var{args}.
c906108c
SS
2249@end table
2250
2251@cindex automatic thread selection
2252@cindex switching threads automatically
2253@cindex threads, automatic switching
2254Whenever @value{GDBN} stops your program, due to a breakpoint or a
2255signal, it automatically selects the thread where that breakpoint or
2256signal happened. @value{GDBN} alerts you to the context switch with a
2257message of the form @samp{[Switching to @var{systag}]} to identify the
2258thread.
2259
2260@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2261more information about how @value{GDBN} behaves when you stop and start
2262programs with multiple threads.
2263
2264@xref{Set Watchpoints,,Setting watchpoints}, for information about
2265watchpoints in programs with multiple threads.
c906108c 2266
6d2ebf8b 2267@node Processes
c906108c
SS
2268@section Debugging programs with multiple processes
2269
2270@cindex fork, debugging programs which call
2271@cindex multiple processes
2272@cindex processes, multiple
53a5351d
JM
2273On most systems, @value{GDBN} has no special support for debugging
2274programs which create additional processes using the @code{fork}
2275function. When a program forks, @value{GDBN} will continue to debug the
2276parent process and the child process will run unimpeded. If you have
2277set a breakpoint in any code which the child then executes, the child
2278will get a @code{SIGTRAP} signal which (unless it catches the signal)
2279will cause it to terminate.
c906108c
SS
2280
2281However, if you want to debug the child process there is a workaround
2282which isn't too painful. Put a call to @code{sleep} in the code which
2283the child process executes after the fork. It may be useful to sleep
2284only if a certain environment variable is set, or a certain file exists,
2285so that the delay need not occur when you don't want to run @value{GDBN}
2286on the child. While the child is sleeping, use the @code{ps} program to
2287get its process ID. Then tell @value{GDBN} (a new invocation of
2288@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2289the child process (@pxref{Attach}). From that point on you can debug
c906108c 2290the child process just like any other process which you attached to.
c906108c 2291
53a5351d
JM
2292On HP-UX (11.x and later only?), @value{GDBN} provides support for
2293debugging programs that create additional processes using the
2294@code{fork} or @code{vfork} function.
c906108c
SS
2295
2296By default, when a program forks, @value{GDBN} will continue to debug
2297the parent process and the child process will run unimpeded.
2298
2299If you want to follow the child process instead of the parent process,
2300use the command @w{@code{set follow-fork-mode}}.
2301
2302@table @code
2303@kindex set follow-fork-mode
2304@item set follow-fork-mode @var{mode}
2305Set the debugger response to a program call of @code{fork} or
2306@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2307process. The @var{mode} can be:
2308
2309@table @code
2310@item parent
2311The original process is debugged after a fork. The child process runs
2df3850c 2312unimpeded. This is the default.
c906108c
SS
2313
2314@item child
2315The new process is debugged after a fork. The parent process runs
2316unimpeded.
2317
2318@item ask
2319The debugger will ask for one of the above choices.
2320@end table
2321
2322@item show follow-fork-mode
2df3850c 2323Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2324@end table
2325
2326If you ask to debug a child process and a @code{vfork} is followed by an
2327@code{exec}, @value{GDBN} executes the new target up to the first
2328breakpoint in the new target. If you have a breakpoint set on
2329@code{main} in your original program, the breakpoint will also be set on
2330the child process's @code{main}.
2331
2332When a child process is spawned by @code{vfork}, you cannot debug the
2333child or parent until an @code{exec} call completes.
2334
2335If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2336call executes, the new target restarts. To restart the parent process,
2337use the @code{file} command with the parent executable name as its
2338argument.
2339
2340You can use the @code{catch} command to make @value{GDBN} stop whenever
2341a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2342Catchpoints, ,Setting catchpoints}.
c906108c 2343
6d2ebf8b 2344@node Stopping
c906108c
SS
2345@chapter Stopping and Continuing
2346
2347The principal purposes of using a debugger are so that you can stop your
2348program before it terminates; or so that, if your program runs into
2349trouble, you can investigate and find out why.
2350
7a292a7a
SS
2351Inside @value{GDBN}, your program may stop for any of several reasons,
2352such as a signal, a breakpoint, or reaching a new line after a
2353@value{GDBN} command such as @code{step}. You may then examine and
2354change variables, set new breakpoints or remove old ones, and then
2355continue execution. Usually, the messages shown by @value{GDBN} provide
2356ample explanation of the status of your program---but you can also
2357explicitly request this information at any time.
c906108c
SS
2358
2359@table @code
2360@kindex info program
2361@item info program
2362Display information about the status of your program: whether it is
7a292a7a 2363running or not, what process it is, and why it stopped.
c906108c
SS
2364@end table
2365
2366@menu
2367* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2368* Continuing and Stepping:: Resuming execution
c906108c 2369* Signals:: Signals
c906108c 2370* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2371@end menu
2372
6d2ebf8b 2373@node Breakpoints
c906108c
SS
2374@section Breakpoints, watchpoints, and catchpoints
2375
2376@cindex breakpoints
2377A @dfn{breakpoint} makes your program stop whenever a certain point in
2378the program is reached. For each breakpoint, you can add conditions to
2379control in finer detail whether your program stops. You can set
2380breakpoints with the @code{break} command and its variants (@pxref{Set
2381Breaks, ,Setting breakpoints}), to specify the place where your program
2382should stop by line number, function name or exact address in the
2383program.
2384
2385In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set
2386breakpoints in shared libraries before the executable is run. There is
2387a minor limitation on HP-UX systems: you must wait until the executable
2388is run in order to set breakpoints in shared library routines that are
2389not called directly by the program (for example, routines that are
2390arguments in a @code{pthread_create} call).
2391
2392@cindex watchpoints
2393@cindex memory tracing
2394@cindex breakpoint on memory address
2395@cindex breakpoint on variable modification
2396A @dfn{watchpoint} is a special breakpoint that stops your program
2397when the value of an expression changes. You must use a different
2398command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2399watchpoints}), but aside from that, you can manage a watchpoint like
2400any other breakpoint: you enable, disable, and delete both breakpoints
2401and watchpoints using the same commands.
2402
2403You can arrange to have values from your program displayed automatically
2404whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2405Automatic display}.
2406
2407@cindex catchpoints
2408@cindex breakpoint on events
2409A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2410when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2411exception or the loading of a library. As with watchpoints, you use a
2412different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2413catchpoints}), but aside from that, you can manage a catchpoint like any
2414other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2415@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2416
2417@cindex breakpoint numbers
2418@cindex numbers for breakpoints
2419@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2420catchpoint when you create it; these numbers are successive integers
2421starting with one. In many of the commands for controlling various
2422features of breakpoints you use the breakpoint number to say which
2423breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2424@dfn{disabled}; if disabled, it has no effect on your program until you
2425enable it again.
2426
c5394b80
JM
2427@cindex breakpoint ranges
2428@cindex ranges of breakpoints
2429Some @value{GDBN} commands accept a range of breakpoints on which to
2430operate. A breakpoint range is either a single breakpoint number, like
2431@samp{5}, or two such numbers, in increasing order, separated by a
2432hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2433all breakpoint in that range are operated on.
2434
c906108c
SS
2435@menu
2436* Set Breaks:: Setting breakpoints
2437* Set Watchpoints:: Setting watchpoints
2438* Set Catchpoints:: Setting catchpoints
2439* Delete Breaks:: Deleting breakpoints
2440* Disabling:: Disabling breakpoints
2441* Conditions:: Break conditions
2442* Break Commands:: Breakpoint command lists
c906108c 2443* Breakpoint Menus:: Breakpoint menus
d4f3574e 2444* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2445* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2446@end menu
2447
6d2ebf8b 2448@node Set Breaks
c906108c
SS
2449@subsection Setting breakpoints
2450
5d161b24 2451@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2452@c consider in particular declaration with/without initialization.
2453@c
2454@c FIXME 2 is there stuff on this already? break at fun start, already init?
2455
2456@kindex break
41afff9a
EZ
2457@kindex b @r{(@code{break})}
2458@vindex $bpnum@r{, convenience variable}
c906108c
SS
2459@cindex latest breakpoint
2460Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2461@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2462number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2463Vars,, Convenience variables}, for a discussion of what you can do with
2464convenience variables.
2465
2466You have several ways to say where the breakpoint should go.
2467
2468@table @code
2469@item break @var{function}
5d161b24 2470Set a breakpoint at entry to function @var{function}.
c906108c 2471When using source languages that permit overloading of symbols, such as
b37052ae 2472C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2473@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2474
2475@item break +@var{offset}
2476@itemx break -@var{offset}
2477Set a breakpoint some number of lines forward or back from the position
d4f3574e 2478at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2479(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2480
2481@item break @var{linenum}
2482Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2483The current source file is the last file whose source text was printed.
2484The breakpoint will stop your program just before it executes any of the
c906108c
SS
2485code on that line.
2486
2487@item break @var{filename}:@var{linenum}
2488Set a breakpoint at line @var{linenum} in source file @var{filename}.
2489
2490@item break @var{filename}:@var{function}
2491Set a breakpoint at entry to function @var{function} found in file
2492@var{filename}. Specifying a file name as well as a function name is
2493superfluous except when multiple files contain similarly named
2494functions.
2495
2496@item break *@var{address}
2497Set a breakpoint at address @var{address}. You can use this to set
2498breakpoints in parts of your program which do not have debugging
2499information or source files.
2500
2501@item break
2502When called without any arguments, @code{break} sets a breakpoint at
2503the next instruction to be executed in the selected stack frame
2504(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2505innermost, this makes your program stop as soon as control
2506returns to that frame. This is similar to the effect of a
2507@code{finish} command in the frame inside the selected frame---except
2508that @code{finish} does not leave an active breakpoint. If you use
2509@code{break} without an argument in the innermost frame, @value{GDBN} stops
2510the next time it reaches the current location; this may be useful
2511inside loops.
2512
2513@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2514least one instruction has been executed. If it did not do this, you
2515would be unable to proceed past a breakpoint without first disabling the
2516breakpoint. This rule applies whether or not the breakpoint already
2517existed when your program stopped.
2518
2519@item break @dots{} if @var{cond}
2520Set a breakpoint with condition @var{cond}; evaluate the expression
2521@var{cond} each time the breakpoint is reached, and stop only if the
2522value is nonzero---that is, if @var{cond} evaluates as true.
2523@samp{@dots{}} stands for one of the possible arguments described
2524above (or no argument) specifying where to break. @xref{Conditions,
2525,Break conditions}, for more information on breakpoint conditions.
2526
2527@kindex tbreak
2528@item tbreak @var{args}
2529Set a breakpoint enabled only for one stop. @var{args} are the
2530same as for the @code{break} command, and the breakpoint is set in the same
2531way, but the breakpoint is automatically deleted after the first time your
2532program stops there. @xref{Disabling, ,Disabling breakpoints}.
2533
c906108c
SS
2534@kindex hbreak
2535@item hbreak @var{args}
d4f3574e
SS
2536Set a hardware-assisted breakpoint. @var{args} are the same as for the
2537@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2538breakpoint requires hardware support and some target hardware may not
2539have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2540debugging, so you can set a breakpoint at an instruction without
2541changing the instruction. This can be used with the new trap-generation
2542provided by SPARClite DSU and some x86-based targets. These targets
2543will generate traps when a program accesses some data or instruction
2544address that is assigned to the debug registers. However the hardware
2545breakpoint registers can take a limited number of breakpoints. For
2546example, on the DSU, only two data breakpoints can be set at a time, and
2547@value{GDBN} will reject this command if more than two are used. Delete
2548or disable unused hardware breakpoints before setting new ones
2549(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
501eef12
AC
2550@xref{set remote hardware-breakpoint-limit}.
2551
c906108c
SS
2552
2553@kindex thbreak
2554@item thbreak @var{args}
2555Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2556are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2557the same way. However, like the @code{tbreak} command,
c906108c
SS
2558the breakpoint is automatically deleted after the
2559first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2560command, the breakpoint requires hardware support and some target hardware
2561may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2562See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2563
2564@kindex rbreak
2565@cindex regular expression
2566@item rbreak @var{regex}
c906108c 2567Set breakpoints on all functions matching the regular expression
11cf8741
JM
2568@var{regex}. This command sets an unconditional breakpoint on all
2569matches, printing a list of all breakpoints it set. Once these
2570breakpoints are set, they are treated just like the breakpoints set with
2571the @code{break} command. You can delete them, disable them, or make
2572them conditional the same way as any other breakpoint.
2573
2574The syntax of the regular expression is the standard one used with tools
2575like @file{grep}. Note that this is different from the syntax used by
2576shells, so for instance @code{foo*} matches all functions that include
2577an @code{fo} followed by zero or more @code{o}s. There is an implicit
2578@code{.*} leading and trailing the regular expression you supply, so to
2579match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2580
b37052ae 2581When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2582breakpoints on overloaded functions that are not members of any special
2583classes.
c906108c
SS
2584
2585@kindex info breakpoints
2586@cindex @code{$_} and @code{info breakpoints}
2587@item info breakpoints @r{[}@var{n}@r{]}
2588@itemx info break @r{[}@var{n}@r{]}
2589@itemx info watchpoints @r{[}@var{n}@r{]}
2590Print a table of all breakpoints, watchpoints, and catchpoints set and
2591not deleted, with the following columns for each breakpoint:
2592
2593@table @emph
2594@item Breakpoint Numbers
2595@item Type
2596Breakpoint, watchpoint, or catchpoint.
2597@item Disposition
2598Whether the breakpoint is marked to be disabled or deleted when hit.
2599@item Enabled or Disabled
2600Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2601that are not enabled.
2602@item Address
2df3850c 2603Where the breakpoint is in your program, as a memory address.
c906108c
SS
2604@item What
2605Where the breakpoint is in the source for your program, as a file and
2606line number.
2607@end table
2608
2609@noindent
2610If a breakpoint is conditional, @code{info break} shows the condition on
2611the line following the affected breakpoint; breakpoint commands, if any,
2612are listed after that.
2613
2614@noindent
2615@code{info break} with a breakpoint
2616number @var{n} as argument lists only that breakpoint. The
2617convenience variable @code{$_} and the default examining-address for
2618the @code{x} command are set to the address of the last breakpoint
5d161b24 2619listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2620
2621@noindent
2622@code{info break} displays a count of the number of times the breakpoint
2623has been hit. This is especially useful in conjunction with the
2624@code{ignore} command. You can ignore a large number of breakpoint
2625hits, look at the breakpoint info to see how many times the breakpoint
2626was hit, and then run again, ignoring one less than that number. This
2627will get you quickly to the last hit of that breakpoint.
2628@end table
2629
2630@value{GDBN} allows you to set any number of breakpoints at the same place in
2631your program. There is nothing silly or meaningless about this. When
2632the breakpoints are conditional, this is even useful
2633(@pxref{Conditions, ,Break conditions}).
2634
2635@cindex negative breakpoint numbers
2636@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2637@value{GDBN} itself sometimes sets breakpoints in your program for
2638special purposes, such as proper handling of @code{longjmp} (in C
2639programs). These internal breakpoints are assigned negative numbers,
2640starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2641You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2642@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2643
2644
6d2ebf8b 2645@node Set Watchpoints
c906108c
SS
2646@subsection Setting watchpoints
2647
2648@cindex setting watchpoints
2649@cindex software watchpoints
2650@cindex hardware watchpoints
2651You can use a watchpoint to stop execution whenever the value of an
2652expression changes, without having to predict a particular place where
2653this may happen.
2654
2655Depending on your system, watchpoints may be implemented in software or
2df3850c 2656hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2657program and testing the variable's value each time, which is hundreds of
2658times slower than normal execution. (But this may still be worth it, to
2659catch errors where you have no clue what part of your program is the
2660culprit.)
2661
1104b9e7 2662On some systems, such as HP-UX, @sc{gnu}/Linux and some other x86-based targets,
2df3850c 2663@value{GDBN} includes support for
c906108c
SS
2664hardware watchpoints, which do not slow down the running of your
2665program.
2666
2667@table @code
2668@kindex watch
2669@item watch @var{expr}
2670Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2671is written into by the program and its value changes.
2672
2673@kindex rwatch
2674@item rwatch @var{expr}
2675Set a watchpoint that will break when watch @var{expr} is read by the program.
c906108c
SS
2676
2677@kindex awatch
2678@item awatch @var{expr}
2df3850c 2679Set a watchpoint that will break when @var{expr} is either read or written into
7be570e7 2680by the program.
c906108c
SS
2681
2682@kindex info watchpoints
2683@item info watchpoints
2684This command prints a list of watchpoints, breakpoints, and catchpoints;
2685it is the same as @code{info break}.
2686@end table
2687
2688@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2689watchpoints execute very quickly, and the debugger reports a change in
2690value at the exact instruction where the change occurs. If @value{GDBN}
2691cannot set a hardware watchpoint, it sets a software watchpoint, which
2692executes more slowly and reports the change in value at the next
2693statement, not the instruction, after the change occurs.
2694
2695When you issue the @code{watch} command, @value{GDBN} reports
2696
474c8240 2697@smallexample
c906108c 2698Hardware watchpoint @var{num}: @var{expr}
474c8240 2699@end smallexample
c906108c
SS
2700
2701@noindent
2702if it was able to set a hardware watchpoint.
2703
7be570e7
JM
2704Currently, the @code{awatch} and @code{rwatch} commands can only set
2705hardware watchpoints, because accesses to data that don't change the
2706value of the watched expression cannot be detected without examining
2707every instruction as it is being executed, and @value{GDBN} does not do
2708that currently. If @value{GDBN} finds that it is unable to set a
2709hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2710will print a message like this:
2711
2712@smallexample
2713Expression cannot be implemented with read/access watchpoint.
2714@end smallexample
2715
2716Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2717data type of the watched expression is wider than what a hardware
2718watchpoint on the target machine can handle. For example, some systems
2719can only watch regions that are up to 4 bytes wide; on such systems you
2720cannot set hardware watchpoints for an expression that yields a
2721double-precision floating-point number (which is typically 8 bytes
2722wide). As a work-around, it might be possible to break the large region
2723into a series of smaller ones and watch them with separate watchpoints.
2724
2725If you set too many hardware watchpoints, @value{GDBN} might be unable
2726to insert all of them when you resume the execution of your program.
2727Since the precise number of active watchpoints is unknown until such
2728time as the program is about to be resumed, @value{GDBN} might not be
2729able to warn you about this when you set the watchpoints, and the
2730warning will be printed only when the program is resumed:
2731
2732@smallexample
2733Hardware watchpoint @var{num}: Could not insert watchpoint
2734@end smallexample
2735
2736@noindent
2737If this happens, delete or disable some of the watchpoints.
2738
2739The SPARClite DSU will generate traps when a program accesses some data
2740or instruction address that is assigned to the debug registers. For the
2741data addresses, DSU facilitates the @code{watch} command. However the
2742hardware breakpoint registers can only take two data watchpoints, and
2743both watchpoints must be the same kind. For example, you can set two
2744watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2745@strong{or} two with @code{awatch} commands, but you cannot set one
2746watchpoint with one command and the other with a different command.
c906108c
SS
2747@value{GDBN} will reject the command if you try to mix watchpoints.
2748Delete or disable unused watchpoint commands before setting new ones.
2749
2750If you call a function interactively using @code{print} or @code{call},
2df3850c 2751any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2752kind of breakpoint or the call completes.
2753
7be570e7
JM
2754@value{GDBN} automatically deletes watchpoints that watch local
2755(automatic) variables, or expressions that involve such variables, when
2756they go out of scope, that is, when the execution leaves the block in
2757which these variables were defined. In particular, when the program
2758being debugged terminates, @emph{all} local variables go out of scope,
2759and so only watchpoints that watch global variables remain set. If you
2760rerun the program, you will need to set all such watchpoints again. One
2761way of doing that would be to set a code breakpoint at the entry to the
2762@code{main} function and when it breaks, set all the watchpoints.
2763
c906108c
SS
2764@quotation
2765@cindex watchpoints and threads
2766@cindex threads and watchpoints
c906108c
SS
2767@emph{Warning:} In multi-thread programs, watchpoints have only limited
2768usefulness. With the current watchpoint implementation, @value{GDBN}
2769can only watch the value of an expression @emph{in a single thread}. If
2770you are confident that the expression can only change due to the current
2771thread's activity (and if you are also confident that no other thread
2772can become current), then you can use watchpoints as usual. However,
2773@value{GDBN} may not notice when a non-current thread's activity changes
2774the expression.
53a5351d 2775
d4f3574e 2776@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2777@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2778have only limited usefulness. If @value{GDBN} creates a software
2779watchpoint, it can only watch the value of an expression @emph{in a
2780single thread}. If you are confident that the expression can only
2781change due to the current thread's activity (and if you are also
2782confident that no other thread can become current), then you can use
2783software watchpoints as usual. However, @value{GDBN} may not notice
2784when a non-current thread's activity changes the expression. (Hardware
2785watchpoints, in contrast, watch an expression in all threads.)
c906108c 2786@end quotation
c906108c 2787
501eef12
AC
2788@xref{set remote hardware-watchpoint-limit}.
2789
6d2ebf8b 2790@node Set Catchpoints
c906108c 2791@subsection Setting catchpoints
d4f3574e 2792@cindex catchpoints, setting
c906108c
SS
2793@cindex exception handlers
2794@cindex event handling
2795
2796You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2797kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2798shared library. Use the @code{catch} command to set a catchpoint.
2799
2800@table @code
2801@kindex catch
2802@item catch @var{event}
2803Stop when @var{event} occurs. @var{event} can be any of the following:
2804@table @code
2805@item throw
2806@kindex catch throw
b37052ae 2807The throwing of a C@t{++} exception.
c906108c
SS
2808
2809@item catch
2810@kindex catch catch
b37052ae 2811The catching of a C@t{++} exception.
c906108c
SS
2812
2813@item exec
2814@kindex catch exec
2815A call to @code{exec}. This is currently only available for HP-UX.
2816
2817@item fork
2818@kindex catch fork
2819A call to @code{fork}. This is currently only available for HP-UX.
2820
2821@item vfork
2822@kindex catch vfork
2823A call to @code{vfork}. This is currently only available for HP-UX.
2824
2825@item load
2826@itemx load @var{libname}
2827@kindex catch load
2828The dynamic loading of any shared library, or the loading of the library
2829@var{libname}. This is currently only available for HP-UX.
2830
2831@item unload
2832@itemx unload @var{libname}
2833@kindex catch unload
2834The unloading of any dynamically loaded shared library, or the unloading
2835of the library @var{libname}. This is currently only available for HP-UX.
2836@end table
2837
2838@item tcatch @var{event}
2839Set a catchpoint that is enabled only for one stop. The catchpoint is
2840automatically deleted after the first time the event is caught.
2841
2842@end table
2843
2844Use the @code{info break} command to list the current catchpoints.
2845
b37052ae 2846There are currently some limitations to C@t{++} exception handling
c906108c
SS
2847(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2848
2849@itemize @bullet
2850@item
2851If you call a function interactively, @value{GDBN} normally returns
2852control to you when the function has finished executing. If the call
2853raises an exception, however, the call may bypass the mechanism that
2854returns control to you and cause your program either to abort or to
2855simply continue running until it hits a breakpoint, catches a signal
2856that @value{GDBN} is listening for, or exits. This is the case even if
2857you set a catchpoint for the exception; catchpoints on exceptions are
2858disabled within interactive calls.
2859
2860@item
2861You cannot raise an exception interactively.
2862
2863@item
2864You cannot install an exception handler interactively.
2865@end itemize
2866
2867@cindex raise exceptions
2868Sometimes @code{catch} is not the best way to debug exception handling:
2869if you need to know exactly where an exception is raised, it is better to
2870stop @emph{before} the exception handler is called, since that way you
2871can see the stack before any unwinding takes place. If you set a
2872breakpoint in an exception handler instead, it may not be easy to find
2873out where the exception was raised.
2874
2875To stop just before an exception handler is called, you need some
b37052ae 2876knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
2877raised by calling a library function named @code{__raise_exception}
2878which has the following ANSI C interface:
2879
474c8240 2880@smallexample
c906108c 2881 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
2882 @var{id} is the exception identifier. */
2883 void __raise_exception (void **addr, void *id);
474c8240 2884@end smallexample
c906108c
SS
2885
2886@noindent
2887To make the debugger catch all exceptions before any stack
2888unwinding takes place, set a breakpoint on @code{__raise_exception}
2889(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
2890
2891With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
2892that depends on the value of @var{id}, you can stop your program when
2893a specific exception is raised. You can use multiple conditional
2894breakpoints to stop your program when any of a number of exceptions are
2895raised.
2896
2897
6d2ebf8b 2898@node Delete Breaks
c906108c
SS
2899@subsection Deleting breakpoints
2900
2901@cindex clearing breakpoints, watchpoints, catchpoints
2902@cindex deleting breakpoints, watchpoints, catchpoints
2903It is often necessary to eliminate a breakpoint, watchpoint, or
2904catchpoint once it has done its job and you no longer want your program
2905to stop there. This is called @dfn{deleting} the breakpoint. A
2906breakpoint that has been deleted no longer exists; it is forgotten.
2907
2908With the @code{clear} command you can delete breakpoints according to
2909where they are in your program. With the @code{delete} command you can
2910delete individual breakpoints, watchpoints, or catchpoints by specifying
2911their breakpoint numbers.
2912
2913It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
2914automatically ignores breakpoints on the first instruction to be executed
2915when you continue execution without changing the execution address.
2916
2917@table @code
2918@kindex clear
2919@item clear
2920Delete any breakpoints at the next instruction to be executed in the
2921selected stack frame (@pxref{Selection, ,Selecting a frame}). When
2922the innermost frame is selected, this is a good way to delete a
2923breakpoint where your program just stopped.
2924
2925@item clear @var{function}
2926@itemx clear @var{filename}:@var{function}
2927Delete any breakpoints set at entry to the function @var{function}.
2928
2929@item clear @var{linenum}
2930@itemx clear @var{filename}:@var{linenum}
2931Delete any breakpoints set at or within the code of the specified line.
2932
2933@cindex delete breakpoints
2934@kindex delete
41afff9a 2935@kindex d @r{(@code{delete})}
c5394b80
JM
2936@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
2937Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
2938ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
2939breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
2940confirm off}). You can abbreviate this command as @code{d}.
2941@end table
2942
6d2ebf8b 2943@node Disabling
c906108c
SS
2944@subsection Disabling breakpoints
2945
2946@kindex disable breakpoints
2947@kindex enable breakpoints
2948Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
2949prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
2950it had been deleted, but remembers the information on the breakpoint so
2951that you can @dfn{enable} it again later.
2952
2953You disable and enable breakpoints, watchpoints, and catchpoints with
2954the @code{enable} and @code{disable} commands, optionally specifying one
2955or more breakpoint numbers as arguments. Use @code{info break} or
2956@code{info watch} to print a list of breakpoints, watchpoints, and
2957catchpoints if you do not know which numbers to use.
2958
2959A breakpoint, watchpoint, or catchpoint can have any of four different
2960states of enablement:
2961
2962@itemize @bullet
2963@item
2964Enabled. The breakpoint stops your program. A breakpoint set
2965with the @code{break} command starts out in this state.
2966@item
2967Disabled. The breakpoint has no effect on your program.
2968@item
2969Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 2970disabled.
c906108c
SS
2971@item
2972Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
2973immediately after it does so it is deleted permanently. A breakpoint
2974set with the @code{tbreak} command starts out in this state.
c906108c
SS
2975@end itemize
2976
2977You can use the following commands to enable or disable breakpoints,
2978watchpoints, and catchpoints:
2979
2980@table @code
2981@kindex disable breakpoints
2982@kindex disable
41afff9a 2983@kindex dis @r{(@code{disable})}
c5394b80 2984@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2985Disable the specified breakpoints---or all breakpoints, if none are
2986listed. A disabled breakpoint has no effect but is not forgotten. All
2987options such as ignore-counts, conditions and commands are remembered in
2988case the breakpoint is enabled again later. You may abbreviate
2989@code{disable} as @code{dis}.
2990
2991@kindex enable breakpoints
2992@kindex enable
c5394b80 2993@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
2994Enable the specified breakpoints (or all defined breakpoints). They
2995become effective once again in stopping your program.
2996
c5394b80 2997@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
2998Enable the specified breakpoints temporarily. @value{GDBN} disables any
2999of these breakpoints immediately after stopping your program.
3000
c5394b80 3001@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3002Enable the specified breakpoints to work once, then die. @value{GDBN}
3003deletes any of these breakpoints as soon as your program stops there.
3004@end table
3005
d4f3574e
SS
3006@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3007@c confusing: tbreak is also initially enabled.
c906108c
SS
3008Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3009,Setting breakpoints}), breakpoints that you set are initially enabled;
3010subsequently, they become disabled or enabled only when you use one of
3011the commands above. (The command @code{until} can set and delete a
3012breakpoint of its own, but it does not change the state of your other
3013breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3014stepping}.)
3015
6d2ebf8b 3016@node Conditions
c906108c
SS
3017@subsection Break conditions
3018@cindex conditional breakpoints
3019@cindex breakpoint conditions
3020
3021@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3022@c in particular for a watchpoint?
c906108c
SS
3023The simplest sort of breakpoint breaks every time your program reaches a
3024specified place. You can also specify a @dfn{condition} for a
3025breakpoint. A condition is just a Boolean expression in your
3026programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3027a condition evaluates the expression each time your program reaches it,
3028and your program stops only if the condition is @emph{true}.
3029
3030This is the converse of using assertions for program validation; in that
3031situation, you want to stop when the assertion is violated---that is,
3032when the condition is false. In C, if you want to test an assertion expressed
3033by the condition @var{assert}, you should set the condition
3034@samp{! @var{assert}} on the appropriate breakpoint.
3035
3036Conditions are also accepted for watchpoints; you may not need them,
3037since a watchpoint is inspecting the value of an expression anyhow---but
3038it might be simpler, say, to just set a watchpoint on a variable name,
3039and specify a condition that tests whether the new value is an interesting
3040one.
3041
3042Break conditions can have side effects, and may even call functions in
3043your program. This can be useful, for example, to activate functions
3044that log program progress, or to use your own print functions to
3045format special data structures. The effects are completely predictable
3046unless there is another enabled breakpoint at the same address. (In
3047that case, @value{GDBN} might see the other breakpoint first and stop your
3048program without checking the condition of this one.) Note that
d4f3574e
SS
3049breakpoint commands are usually more convenient and flexible than break
3050conditions for the
c906108c
SS
3051purpose of performing side effects when a breakpoint is reached
3052(@pxref{Break Commands, ,Breakpoint command lists}).
3053
3054Break conditions can be specified when a breakpoint is set, by using
3055@samp{if} in the arguments to the @code{break} command. @xref{Set
3056Breaks, ,Setting breakpoints}. They can also be changed at any time
3057with the @code{condition} command.
53a5351d 3058
c906108c
SS
3059You can also use the @code{if} keyword with the @code{watch} command.
3060The @code{catch} command does not recognize the @code{if} keyword;
3061@code{condition} is the only way to impose a further condition on a
3062catchpoint.
c906108c
SS
3063
3064@table @code
3065@kindex condition
3066@item condition @var{bnum} @var{expression}
3067Specify @var{expression} as the break condition for breakpoint,
3068watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3069breakpoint @var{bnum} stops your program only if the value of
3070@var{expression} is true (nonzero, in C). When you use
3071@code{condition}, @value{GDBN} checks @var{expression} immediately for
3072syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3073referents in the context of your breakpoint. If @var{expression} uses
3074symbols not referenced in the context of the breakpoint, @value{GDBN}
3075prints an error message:
3076
474c8240 3077@smallexample
d4f3574e 3078No symbol "foo" in current context.
474c8240 3079@end smallexample
d4f3574e
SS
3080
3081@noindent
c906108c
SS
3082@value{GDBN} does
3083not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3084command (or a command that sets a breakpoint with a condition, like
3085@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3086
3087@item condition @var{bnum}
3088Remove the condition from breakpoint number @var{bnum}. It becomes
3089an ordinary unconditional breakpoint.
3090@end table
3091
3092@cindex ignore count (of breakpoint)
3093A special case of a breakpoint condition is to stop only when the
3094breakpoint has been reached a certain number of times. This is so
3095useful that there is a special way to do it, using the @dfn{ignore
3096count} of the breakpoint. Every breakpoint has an ignore count, which
3097is an integer. Most of the time, the ignore count is zero, and
3098therefore has no effect. But if your program reaches a breakpoint whose
3099ignore count is positive, then instead of stopping, it just decrements
3100the ignore count by one and continues. As a result, if the ignore count
3101value is @var{n}, the breakpoint does not stop the next @var{n} times
3102your program reaches it.
3103
3104@table @code
3105@kindex ignore
3106@item ignore @var{bnum} @var{count}
3107Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3108The next @var{count} times the breakpoint is reached, your program's
3109execution does not stop; other than to decrement the ignore count, @value{GDBN}
3110takes no action.
3111
3112To make the breakpoint stop the next time it is reached, specify
3113a count of zero.
3114
3115When you use @code{continue} to resume execution of your program from a
3116breakpoint, you can specify an ignore count directly as an argument to
3117@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3118Stepping,,Continuing and stepping}.
3119
3120If a breakpoint has a positive ignore count and a condition, the
3121condition is not checked. Once the ignore count reaches zero,
3122@value{GDBN} resumes checking the condition.
3123
3124You could achieve the effect of the ignore count with a condition such
3125as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3126is decremented each time. @xref{Convenience Vars, ,Convenience
3127variables}.
3128@end table
3129
3130Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3131
3132
6d2ebf8b 3133@node Break Commands
c906108c
SS
3134@subsection Breakpoint command lists
3135
3136@cindex breakpoint commands
3137You can give any breakpoint (or watchpoint or catchpoint) a series of
3138commands to execute when your program stops due to that breakpoint. For
3139example, you might want to print the values of certain expressions, or
3140enable other breakpoints.
3141
3142@table @code
3143@kindex commands
3144@kindex end
3145@item commands @r{[}@var{bnum}@r{]}
3146@itemx @dots{} @var{command-list} @dots{}
3147@itemx end
3148Specify a list of commands for breakpoint number @var{bnum}. The commands
3149themselves appear on the following lines. Type a line containing just
3150@code{end} to terminate the commands.
3151
3152To remove all commands from a breakpoint, type @code{commands} and
3153follow it immediately with @code{end}; that is, give no commands.
3154
3155With no @var{bnum} argument, @code{commands} refers to the last
3156breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3157recently encountered).
3158@end table
3159
3160Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3161disabled within a @var{command-list}.
3162
3163You can use breakpoint commands to start your program up again. Simply
3164use the @code{continue} command, or @code{step}, or any other command
3165that resumes execution.
3166
3167Any other commands in the command list, after a command that resumes
3168execution, are ignored. This is because any time you resume execution
3169(even with a simple @code{next} or @code{step}), you may encounter
3170another breakpoint---which could have its own command list, leading to
3171ambiguities about which list to execute.
3172
3173@kindex silent
3174If the first command you specify in a command list is @code{silent}, the
3175usual message about stopping at a breakpoint is not printed. This may
3176be desirable for breakpoints that are to print a specific message and
3177then continue. If none of the remaining commands print anything, you
3178see no sign that the breakpoint was reached. @code{silent} is
3179meaningful only at the beginning of a breakpoint command list.
3180
3181The commands @code{echo}, @code{output}, and @code{printf} allow you to
3182print precisely controlled output, and are often useful in silent
3183breakpoints. @xref{Output, ,Commands for controlled output}.
3184
3185For example, here is how you could use breakpoint commands to print the
3186value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3187
474c8240 3188@smallexample
c906108c
SS
3189break foo if x>0
3190commands
3191silent
3192printf "x is %d\n",x
3193cont
3194end
474c8240 3195@end smallexample
c906108c
SS
3196
3197One application for breakpoint commands is to compensate for one bug so
3198you can test for another. Put a breakpoint just after the erroneous line
3199of code, give it a condition to detect the case in which something
3200erroneous has been done, and give it commands to assign correct values
3201to any variables that need them. End with the @code{continue} command
3202so that your program does not stop, and start with the @code{silent}
3203command so that no output is produced. Here is an example:
3204
474c8240 3205@smallexample
c906108c
SS
3206break 403
3207commands
3208silent
3209set x = y + 4
3210cont
3211end
474c8240 3212@end smallexample
c906108c 3213
6d2ebf8b 3214@node Breakpoint Menus
c906108c
SS
3215@subsection Breakpoint menus
3216@cindex overloading
3217@cindex symbol overloading
3218
b37303ee
AF
3219Some programming languages (notably C@t{++} and Objective-C) permit a
3220single function name
c906108c
SS
3221to be defined several times, for application in different contexts.
3222This is called @dfn{overloading}. When a function name is overloaded,
3223@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3224a breakpoint. If you realize this is a problem, you can use
3225something like @samp{break @var{function}(@var{types})} to specify which
3226particular version of the function you want. Otherwise, @value{GDBN} offers
3227you a menu of numbered choices for different possible breakpoints, and
3228waits for your selection with the prompt @samp{>}. The first two
3229options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3230sets a breakpoint at each definition of @var{function}, and typing
3231@kbd{0} aborts the @code{break} command without setting any new
3232breakpoints.
3233
3234For example, the following session excerpt shows an attempt to set a
3235breakpoint at the overloaded symbol @code{String::after}.
3236We choose three particular definitions of that function name:
3237
3238@c FIXME! This is likely to change to show arg type lists, at least
3239@smallexample
3240@group
3241(@value{GDBP}) b String::after
3242[0] cancel
3243[1] all
3244[2] file:String.cc; line number:867
3245[3] file:String.cc; line number:860
3246[4] file:String.cc; line number:875
3247[5] file:String.cc; line number:853
3248[6] file:String.cc; line number:846
3249[7] file:String.cc; line number:735
3250> 2 4 6
3251Breakpoint 1 at 0xb26c: file String.cc, line 867.
3252Breakpoint 2 at 0xb344: file String.cc, line 875.
3253Breakpoint 3 at 0xafcc: file String.cc, line 846.
3254Multiple breakpoints were set.
3255Use the "delete" command to delete unwanted
3256 breakpoints.
3257(@value{GDBP})
3258@end group
3259@end smallexample
c906108c
SS
3260
3261@c @ifclear BARETARGET
6d2ebf8b 3262@node Error in Breakpoints
d4f3574e 3263@subsection ``Cannot insert breakpoints''
c906108c
SS
3264@c
3265@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3266@c
d4f3574e
SS
3267Under some operating systems, breakpoints cannot be used in a program if
3268any other process is running that program. In this situation,
5d161b24 3269attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3270@value{GDBN} to print an error message:
3271
474c8240 3272@smallexample
d4f3574e
SS
3273Cannot insert breakpoints.
3274The same program may be running in another process.
474c8240 3275@end smallexample
d4f3574e
SS
3276
3277When this happens, you have three ways to proceed:
3278
3279@enumerate
3280@item
3281Remove or disable the breakpoints, then continue.
3282
3283@item
5d161b24 3284Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3285name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3286that @value{GDBN} should run your program under that name.
d4f3574e
SS
3287Then start your program again.
3288
3289@item
3290Relink your program so that the text segment is nonsharable, using the
3291linker option @samp{-N}. The operating system limitation may not apply
3292to nonsharable executables.
3293@end enumerate
c906108c
SS
3294@c @end ifclear
3295
d4f3574e
SS
3296A similar message can be printed if you request too many active
3297hardware-assisted breakpoints and watchpoints:
3298
3299@c FIXME: the precise wording of this message may change; the relevant
3300@c source change is not committed yet (Sep 3, 1999).
3301@smallexample
3302Stopped; cannot insert breakpoints.
3303You may have requested too many hardware breakpoints and watchpoints.
3304@end smallexample
3305
3306@noindent
3307This message is printed when you attempt to resume the program, since
3308only then @value{GDBN} knows exactly how many hardware breakpoints and
3309watchpoints it needs to insert.
3310
3311When this message is printed, you need to disable or remove some of the
3312hardware-assisted breakpoints and watchpoints, and then continue.
3313
1485d690
KB
3314@node Breakpoint related warnings
3315@subsection ``Breakpoint address adjusted...''
3316@cindex breakpoint address adjusted
3317
3318Some processor architectures place constraints on the addresses at
3319which breakpoints may be placed. For architectures thus constrained,
3320@value{GDBN} will attempt to adjust the breakpoint's address to comply
3321with the constraints dictated by the architecture.
3322
3323One example of such an architecture is the Fujitsu FR-V. The FR-V is
3324a VLIW architecture in which a number of RISC-like instructions may be
3325bundled together for parallel execution. The FR-V architecture
3326constrains the location of a breakpoint instruction within such a
3327bundle to the instruction with the lowest address. @value{GDBN}
3328honors this constraint by adjusting a breakpoint's address to the
3329first in the bundle.
3330
3331It is not uncommon for optimized code to have bundles which contain
3332instructions from different source statements, thus it may happen that
3333a breakpoint's address will be adjusted from one source statement to
3334another. Since this adjustment may significantly alter @value{GDBN}'s
3335breakpoint related behavior from what the user expects, a warning is
3336printed when the breakpoint is first set and also when the breakpoint
3337is hit.
3338
3339A warning like the one below is printed when setting a breakpoint
3340that's been subject to address adjustment:
3341
3342@smallexample
3343warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3344@end smallexample
3345
3346Such warnings are printed both for user settable and @value{GDBN}'s
3347internal breakpoints. If you see one of these warnings, you should
3348verify that a breakpoint set at the adjusted address will have the
3349desired affect. If not, the breakpoint in question may be removed and
3350other breakpoints may be set which will have the desired behavior.
3351E.g., it may be sufficient to place the breakpoint at a later
3352instruction. A conditional breakpoint may also be useful in some
3353cases to prevent the breakpoint from triggering too often.
3354
3355@value{GDBN} will also issue a warning when stopping at one of these
3356adjusted breakpoints:
3357
3358@smallexample
3359warning: Breakpoint 1 address previously adjusted from 0x00010414
3360to 0x00010410.
3361@end smallexample
3362
3363When this warning is encountered, it may be too late to take remedial
3364action except in cases where the breakpoint is hit earlier or more
3365frequently than expected.
d4f3574e 3366
6d2ebf8b 3367@node Continuing and Stepping
c906108c
SS
3368@section Continuing and stepping
3369
3370@cindex stepping
3371@cindex continuing
3372@cindex resuming execution
3373@dfn{Continuing} means resuming program execution until your program
3374completes normally. In contrast, @dfn{stepping} means executing just
3375one more ``step'' of your program, where ``step'' may mean either one
3376line of source code, or one machine instruction (depending on what
7a292a7a
SS
3377particular command you use). Either when continuing or when stepping,
3378your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3379it stops due to a signal, you may want to use @code{handle}, or use
3380@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3381
3382@table @code
3383@kindex continue
41afff9a
EZ
3384@kindex c @r{(@code{continue})}
3385@kindex fg @r{(resume foreground execution)}
c906108c
SS
3386@item continue @r{[}@var{ignore-count}@r{]}
3387@itemx c @r{[}@var{ignore-count}@r{]}
3388@itemx fg @r{[}@var{ignore-count}@r{]}
3389Resume program execution, at the address where your program last stopped;
3390any breakpoints set at that address are bypassed. The optional argument
3391@var{ignore-count} allows you to specify a further number of times to
3392ignore a breakpoint at this location; its effect is like that of
3393@code{ignore} (@pxref{Conditions, ,Break conditions}).
3394
3395The argument @var{ignore-count} is meaningful only when your program
3396stopped due to a breakpoint. At other times, the argument to
3397@code{continue} is ignored.
3398
d4f3574e
SS
3399The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3400debugged program is deemed to be the foreground program) are provided
3401purely for convenience, and have exactly the same behavior as
3402@code{continue}.
c906108c
SS
3403@end table
3404
3405To resume execution at a different place, you can use @code{return}
3406(@pxref{Returning, ,Returning from a function}) to go back to the
3407calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3408different address}) to go to an arbitrary location in your program.
3409
3410A typical technique for using stepping is to set a breakpoint
3411(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3412beginning of the function or the section of your program where a problem
3413is believed to lie, run your program until it stops at that breakpoint,
3414and then step through the suspect area, examining the variables that are
3415interesting, until you see the problem happen.
3416
3417@table @code
3418@kindex step
41afff9a 3419@kindex s @r{(@code{step})}
c906108c
SS
3420@item step
3421Continue running your program until control reaches a different source
3422line, then stop it and return control to @value{GDBN}. This command is
3423abbreviated @code{s}.
3424
3425@quotation
3426@c "without debugging information" is imprecise; actually "without line
3427@c numbers in the debugging information". (gcc -g1 has debugging info but
3428@c not line numbers). But it seems complex to try to make that
3429@c distinction here.
3430@emph{Warning:} If you use the @code{step} command while control is
3431within a function that was compiled without debugging information,
3432execution proceeds until control reaches a function that does have
3433debugging information. Likewise, it will not step into a function which
3434is compiled without debugging information. To step through functions
3435without debugging information, use the @code{stepi} command, described
3436below.
3437@end quotation
3438
4a92d011
EZ
3439The @code{step} command only stops at the first instruction of a source
3440line. This prevents the multiple stops that could otherwise occur in
3441@code{switch} statements, @code{for} loops, etc. @code{step} continues
3442to stop if a function that has debugging information is called within
3443the line. In other words, @code{step} @emph{steps inside} any functions
3444called within the line.
c906108c 3445
d4f3574e
SS
3446Also, the @code{step} command only enters a function if there is line
3447number information for the function. Otherwise it acts like the
5d161b24 3448@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3449on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3450was any debugging information about the routine.
c906108c
SS
3451
3452@item step @var{count}
3453Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3454breakpoint is reached, or a signal not related to stepping occurs before
3455@var{count} steps, stepping stops right away.
c906108c
SS
3456
3457@kindex next
41afff9a 3458@kindex n @r{(@code{next})}
c906108c
SS
3459@item next @r{[}@var{count}@r{]}
3460Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3461This is similar to @code{step}, but function calls that appear within
3462the line of code are executed without stopping. Execution stops when
3463control reaches a different line of code at the original stack level
3464that was executing when you gave the @code{next} command. This command
3465is abbreviated @code{n}.
c906108c
SS
3466
3467An argument @var{count} is a repeat count, as for @code{step}.
3468
3469
3470@c FIX ME!! Do we delete this, or is there a way it fits in with
3471@c the following paragraph? --- Vctoria
3472@c
3473@c @code{next} within a function that lacks debugging information acts like
3474@c @code{step}, but any function calls appearing within the code of the
3475@c function are executed without stopping.
3476
d4f3574e
SS
3477The @code{next} command only stops at the first instruction of a
3478source line. This prevents multiple stops that could otherwise occur in
4a92d011 3479@code{switch} statements, @code{for} loops, etc.
c906108c 3480
b90a5f51
CF
3481@kindex set step-mode
3482@item set step-mode
3483@cindex functions without line info, and stepping
3484@cindex stepping into functions with no line info
3485@itemx set step-mode on
4a92d011 3486The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3487stop at the first instruction of a function which contains no debug line
3488information rather than stepping over it.
3489
4a92d011
EZ
3490This is useful in cases where you may be interested in inspecting the
3491machine instructions of a function which has no symbolic info and do not
3492want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3493
3494@item set step-mode off
4a92d011 3495Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3496debug information. This is the default.
3497
c906108c
SS
3498@kindex finish
3499@item finish
3500Continue running until just after function in the selected stack frame
3501returns. Print the returned value (if any).
3502
3503Contrast this with the @code{return} command (@pxref{Returning,
3504,Returning from a function}).
3505
3506@kindex until
41afff9a 3507@kindex u @r{(@code{until})}
c906108c
SS
3508@item until
3509@itemx u
3510Continue running until a source line past the current line, in the
3511current stack frame, is reached. This command is used to avoid single
3512stepping through a loop more than once. It is like the @code{next}
3513command, except that when @code{until} encounters a jump, it
3514automatically continues execution until the program counter is greater
3515than the address of the jump.
3516
3517This means that when you reach the end of a loop after single stepping
3518though it, @code{until} makes your program continue execution until it
3519exits the loop. In contrast, a @code{next} command at the end of a loop
3520simply steps back to the beginning of the loop, which forces you to step
3521through the next iteration.
3522
3523@code{until} always stops your program if it attempts to exit the current
3524stack frame.
3525
3526@code{until} may produce somewhat counterintuitive results if the order
3527of machine code does not match the order of the source lines. For
3528example, in the following excerpt from a debugging session, the @code{f}
3529(@code{frame}) command shows that execution is stopped at line
3530@code{206}; yet when we use @code{until}, we get to line @code{195}:
3531
474c8240 3532@smallexample
c906108c
SS
3533(@value{GDBP}) f
3534#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3535206 expand_input();
3536(@value{GDBP}) until
3537195 for ( ; argc > 0; NEXTARG) @{
474c8240 3538@end smallexample
c906108c
SS
3539
3540This happened because, for execution efficiency, the compiler had
3541generated code for the loop closure test at the end, rather than the
3542start, of the loop---even though the test in a C @code{for}-loop is
3543written before the body of the loop. The @code{until} command appeared
3544to step back to the beginning of the loop when it advanced to this
3545expression; however, it has not really gone to an earlier
3546statement---not in terms of the actual machine code.
3547
3548@code{until} with no argument works by means of single
3549instruction stepping, and hence is slower than @code{until} with an
3550argument.
3551
3552@item until @var{location}
3553@itemx u @var{location}
3554Continue running your program until either the specified location is
3555reached, or the current stack frame returns. @var{location} is any of
3556the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3557,Setting breakpoints}). This form of the command uses breakpoints, and
3558hence is quicker than @code{until} without an argument. The specified
3559location is actually reached only if it is in the current frame. This
3560implies that @code{until} can be used to skip over recursive function
3561invocations. For instance in the code below, if the current location is
3562line @code{96}, issuing @code{until 99} will execute the program up to
3563line @code{99} in the same invocation of factorial, i.e. after the inner
3564invocations have returned.
3565
3566@smallexample
356794 int factorial (int value)
356895 @{
356996 if (value > 1) @{
357097 value *= factorial (value - 1);
357198 @}
357299 return (value);
3573100 @}
3574@end smallexample
3575
3576
3577@kindex advance @var{location}
3578@itemx advance @var{location}
3579Continue running the program up to the given location. An argument is
3580required, anything of the same form as arguments for the @code{break}
3581command. Execution will also stop upon exit from the current stack
3582frame. This command is similar to @code{until}, but @code{advance} will
3583not skip over recursive function calls, and the target location doesn't
3584have to be in the same frame as the current one.
3585
c906108c
SS
3586
3587@kindex stepi
41afff9a 3588@kindex si @r{(@code{stepi})}
c906108c 3589@item stepi
96a2c332 3590@itemx stepi @var{arg}
c906108c
SS
3591@itemx si
3592Execute one machine instruction, then stop and return to the debugger.
3593
3594It is often useful to do @samp{display/i $pc} when stepping by machine
3595instructions. This makes @value{GDBN} automatically display the next
3596instruction to be executed, each time your program stops. @xref{Auto
3597Display,, Automatic display}.
3598
3599An argument is a repeat count, as in @code{step}.
3600
3601@need 750
3602@kindex nexti
41afff9a 3603@kindex ni @r{(@code{nexti})}
c906108c 3604@item nexti
96a2c332 3605@itemx nexti @var{arg}
c906108c
SS
3606@itemx ni
3607Execute one machine instruction, but if it is a function call,
3608proceed until the function returns.
3609
3610An argument is a repeat count, as in @code{next}.
3611@end table
3612
6d2ebf8b 3613@node Signals
c906108c
SS
3614@section Signals
3615@cindex signals
3616
3617A signal is an asynchronous event that can happen in a program. The
3618operating system defines the possible kinds of signals, and gives each
3619kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3620signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3621@code{SIGSEGV} is the signal a program gets from referencing a place in
3622memory far away from all the areas in use; @code{SIGALRM} occurs when
3623the alarm clock timer goes off (which happens only if your program has
3624requested an alarm).
3625
3626@cindex fatal signals
3627Some signals, including @code{SIGALRM}, are a normal part of the
3628functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3629errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3630program has not specified in advance some other way to handle the signal.
3631@code{SIGINT} does not indicate an error in your program, but it is normally
3632fatal so it can carry out the purpose of the interrupt: to kill the program.
3633
3634@value{GDBN} has the ability to detect any occurrence of a signal in your
3635program. You can tell @value{GDBN} in advance what to do for each kind of
3636signal.
3637
3638@cindex handling signals
24f93129
EZ
3639Normally, @value{GDBN} is set up to let the non-erroneous signals like
3640@code{SIGALRM} be silently passed to your program
3641(so as not to interfere with their role in the program's functioning)
c906108c
SS
3642but to stop your program immediately whenever an error signal happens.
3643You can change these settings with the @code{handle} command.
3644
3645@table @code
3646@kindex info signals
3647@item info signals
96a2c332 3648@itemx info handle
c906108c
SS
3649Print a table of all the kinds of signals and how @value{GDBN} has been told to
3650handle each one. You can use this to see the signal numbers of all
3651the defined types of signals.
3652
d4f3574e 3653@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3654
3655@kindex handle
3656@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3657Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3658can be the number of a signal or its name (with or without the
24f93129 3659@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3660@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3661known signals. The @var{keywords} say what change to make.
c906108c
SS
3662@end table
3663
3664@c @group
3665The keywords allowed by the @code{handle} command can be abbreviated.
3666Their full names are:
3667
3668@table @code
3669@item nostop
3670@value{GDBN} should not stop your program when this signal happens. It may
3671still print a message telling you that the signal has come in.
3672
3673@item stop
3674@value{GDBN} should stop your program when this signal happens. This implies
3675the @code{print} keyword as well.
3676
3677@item print
3678@value{GDBN} should print a message when this signal happens.
3679
3680@item noprint
3681@value{GDBN} should not mention the occurrence of the signal at all. This
3682implies the @code{nostop} keyword as well.
3683
3684@item pass
5ece1a18 3685@itemx noignore
c906108c
SS
3686@value{GDBN} should allow your program to see this signal; your program
3687can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3688and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3689
3690@item nopass
5ece1a18 3691@itemx ignore
c906108c 3692@value{GDBN} should not allow your program to see this signal.
5ece1a18 3693@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3694@end table
3695@c @end group
3696
d4f3574e
SS
3697When a signal stops your program, the signal is not visible to the
3698program until you
c906108c
SS
3699continue. Your program sees the signal then, if @code{pass} is in
3700effect for the signal in question @emph{at that time}. In other words,
3701after @value{GDBN} reports a signal, you can use the @code{handle}
3702command with @code{pass} or @code{nopass} to control whether your
3703program sees that signal when you continue.
3704
24f93129
EZ
3705The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3706non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3707@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3708erroneous signals.
3709
c906108c
SS
3710You can also use the @code{signal} command to prevent your program from
3711seeing a signal, or cause it to see a signal it normally would not see,
3712or to give it any signal at any time. For example, if your program stopped
3713due to some sort of memory reference error, you might store correct
3714values into the erroneous variables and continue, hoping to see more
3715execution; but your program would probably terminate immediately as
3716a result of the fatal signal once it saw the signal. To prevent this,
3717you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3718program a signal}.
c906108c 3719
6d2ebf8b 3720@node Thread Stops
c906108c
SS
3721@section Stopping and starting multi-thread programs
3722
3723When your program has multiple threads (@pxref{Threads,, Debugging
3724programs with multiple threads}), you can choose whether to set
3725breakpoints on all threads, or on a particular thread.
3726
3727@table @code
3728@cindex breakpoints and threads
3729@cindex thread breakpoints
3730@kindex break @dots{} thread @var{threadno}
3731@item break @var{linespec} thread @var{threadno}
3732@itemx break @var{linespec} thread @var{threadno} if @dots{}
3733@var{linespec} specifies source lines; there are several ways of
3734writing them, but the effect is always to specify some source line.
3735
3736Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3737to specify that you only want @value{GDBN} to stop the program when a
3738particular thread reaches this breakpoint. @var{threadno} is one of the
3739numeric thread identifiers assigned by @value{GDBN}, shown in the first
3740column of the @samp{info threads} display.
3741
3742If you do not specify @samp{thread @var{threadno}} when you set a
3743breakpoint, the breakpoint applies to @emph{all} threads of your
3744program.
3745
3746You can use the @code{thread} qualifier on conditional breakpoints as
3747well; in this case, place @samp{thread @var{threadno}} before the
3748breakpoint condition, like this:
3749
3750@smallexample
2df3850c 3751(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3752@end smallexample
3753
3754@end table
3755
3756@cindex stopped threads
3757@cindex threads, stopped
3758Whenever your program stops under @value{GDBN} for any reason,
3759@emph{all} threads of execution stop, not just the current thread. This
3760allows you to examine the overall state of the program, including
3761switching between threads, without worrying that things may change
3762underfoot.
3763
36d86913
MC
3764@cindex thread breakpoints and system calls
3765@cindex system calls and thread breakpoints
3766@cindex premature return from system calls
3767There is an unfortunate side effect. If one thread stops for a
3768breakpoint, or for some other reason, and another thread is blocked in a
3769system call, then the system call may return prematurely. This is a
3770consequence of the interaction between multiple threads and the signals
3771that @value{GDBN} uses to implement breakpoints and other events that
3772stop execution.
3773
3774To handle this problem, your program should check the return value of
3775each system call and react appropriately. This is good programming
3776style anyways.
3777
3778For example, do not write code like this:
3779
3780@smallexample
3781 sleep (10);
3782@end smallexample
3783
3784The call to @code{sleep} will return early if a different thread stops
3785at a breakpoint or for some other reason.
3786
3787Instead, write this:
3788
3789@smallexample
3790 int unslept = 10;
3791 while (unslept > 0)
3792 unslept = sleep (unslept);
3793@end smallexample
3794
3795A system call is allowed to return early, so the system is still
3796conforming to its specification. But @value{GDBN} does cause your
3797multi-threaded program to behave differently than it would without
3798@value{GDBN}.
3799
3800Also, @value{GDBN} uses internal breakpoints in the thread library to
3801monitor certain events such as thread creation and thread destruction.
3802When such an event happens, a system call in another thread may return
3803prematurely, even though your program does not appear to stop.
3804
c906108c
SS
3805@cindex continuing threads
3806@cindex threads, continuing
3807Conversely, whenever you restart the program, @emph{all} threads start
3808executing. @emph{This is true even when single-stepping} with commands
5d161b24 3809like @code{step} or @code{next}.
c906108c
SS
3810
3811In particular, @value{GDBN} cannot single-step all threads in lockstep.
3812Since thread scheduling is up to your debugging target's operating
3813system (not controlled by @value{GDBN}), other threads may
3814execute more than one statement while the current thread completes a
3815single step. Moreover, in general other threads stop in the middle of a
3816statement, rather than at a clean statement boundary, when the program
3817stops.
3818
3819You might even find your program stopped in another thread after
3820continuing or even single-stepping. This happens whenever some other
3821thread runs into a breakpoint, a signal, or an exception before the
3822first thread completes whatever you requested.
3823
3824On some OSes, you can lock the OS scheduler and thus allow only a single
3825thread to run.
3826
3827@table @code
3828@item set scheduler-locking @var{mode}
3829Set the scheduler locking mode. If it is @code{off}, then there is no
3830locking and any thread may run at any time. If @code{on}, then only the
3831current thread may run when the inferior is resumed. The @code{step}
3832mode optimizes for single-stepping. It stops other threads from
3833``seizing the prompt'' by preempting the current thread while you are
3834stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3835when you step. They are more likely to run when you @samp{next} over a
c906108c 3836function call, and they are completely free to run when you use commands
d4f3574e 3837like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3838thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3839@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3840
3841@item show scheduler-locking
3842Display the current scheduler locking mode.
3843@end table
3844
c906108c 3845
6d2ebf8b 3846@node Stack
c906108c
SS
3847@chapter Examining the Stack
3848
3849When your program has stopped, the first thing you need to know is where it
3850stopped and how it got there.
3851
3852@cindex call stack
5d161b24
DB
3853Each time your program performs a function call, information about the call
3854is generated.
3855That information includes the location of the call in your program,
3856the arguments of the call,
c906108c 3857and the local variables of the function being called.
5d161b24 3858The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3859The stack frames are allocated in a region of memory called the @dfn{call
3860stack}.
3861
3862When your program stops, the @value{GDBN} commands for examining the
3863stack allow you to see all of this information.
3864
3865@cindex selected frame
3866One of the stack frames is @dfn{selected} by @value{GDBN} and many
3867@value{GDBN} commands refer implicitly to the selected frame. In
3868particular, whenever you ask @value{GDBN} for the value of a variable in
3869your program, the value is found in the selected frame. There are
3870special @value{GDBN} commands to select whichever frame you are
3871interested in. @xref{Selection, ,Selecting a frame}.
3872
3873When your program stops, @value{GDBN} automatically selects the
5d161b24 3874currently executing frame and describes it briefly, similar to the
c906108c
SS
3875@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
3876
3877@menu
3878* Frames:: Stack frames
3879* Backtrace:: Backtraces
3880* Selection:: Selecting a frame
3881* Frame Info:: Information on a frame
c906108c
SS
3882
3883@end menu
3884
6d2ebf8b 3885@node Frames
c906108c
SS
3886@section Stack frames
3887
d4f3574e 3888@cindex frame, definition
c906108c
SS
3889@cindex stack frame
3890The call stack is divided up into contiguous pieces called @dfn{stack
3891frames}, or @dfn{frames} for short; each frame is the data associated
3892with one call to one function. The frame contains the arguments given
3893to the function, the function's local variables, and the address at
3894which the function is executing.
3895
3896@cindex initial frame
3897@cindex outermost frame
3898@cindex innermost frame
3899When your program is started, the stack has only one frame, that of the
3900function @code{main}. This is called the @dfn{initial} frame or the
3901@dfn{outermost} frame. Each time a function is called, a new frame is
3902made. Each time a function returns, the frame for that function invocation
3903is eliminated. If a function is recursive, there can be many frames for
3904the same function. The frame for the function in which execution is
3905actually occurring is called the @dfn{innermost} frame. This is the most
3906recently created of all the stack frames that still exist.
3907
3908@cindex frame pointer
3909Inside your program, stack frames are identified by their addresses. A
3910stack frame consists of many bytes, each of which has its own address; each
3911kind of computer has a convention for choosing one byte whose
3912address serves as the address of the frame. Usually this address is kept
3913in a register called the @dfn{frame pointer register} while execution is
3914going on in that frame.
3915
3916@cindex frame number
3917@value{GDBN} assigns numbers to all existing stack frames, starting with
3918zero for the innermost frame, one for the frame that called it,
3919and so on upward. These numbers do not really exist in your program;
3920they are assigned by @value{GDBN} to give you a way of designating stack
3921frames in @value{GDBN} commands.
3922
6d2ebf8b
SS
3923@c The -fomit-frame-pointer below perennially causes hbox overflow
3924@c underflow problems.
c906108c
SS
3925@cindex frameless execution
3926Some compilers provide a way to compile functions so that they operate
6d2ebf8b 3927without stack frames. (For example, the @value{GCC} option
474c8240 3928@smallexample
6d2ebf8b 3929@samp{-fomit-frame-pointer}
474c8240 3930@end smallexample
6d2ebf8b 3931generates functions without a frame.)
c906108c
SS
3932This is occasionally done with heavily used library functions to save
3933the frame setup time. @value{GDBN} has limited facilities for dealing
3934with these function invocations. If the innermost function invocation
3935has no stack frame, @value{GDBN} nevertheless regards it as though
3936it had a separate frame, which is numbered zero as usual, allowing
3937correct tracing of the function call chain. However, @value{GDBN} has
3938no provision for frameless functions elsewhere in the stack.
3939
3940@table @code
d4f3574e 3941@kindex frame@r{, command}
41afff9a 3942@cindex current stack frame
c906108c 3943@item frame @var{args}
5d161b24 3944The @code{frame} command allows you to move from one stack frame to another,
c906108c 3945and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
3946address of the frame or the stack frame number. Without an argument,
3947@code{frame} prints the current stack frame.
c906108c
SS
3948
3949@kindex select-frame
41afff9a 3950@cindex selecting frame silently
c906108c
SS
3951@item select-frame
3952The @code{select-frame} command allows you to move from one stack frame
3953to another without printing the frame. This is the silent version of
3954@code{frame}.
3955@end table
3956
6d2ebf8b 3957@node Backtrace
c906108c
SS
3958@section Backtraces
3959
3960@cindex backtraces
3961@cindex tracebacks
3962@cindex stack traces
3963A backtrace is a summary of how your program got where it is. It shows one
3964line per frame, for many frames, starting with the currently executing
3965frame (frame zero), followed by its caller (frame one), and on up the
3966stack.
3967
3968@table @code
3969@kindex backtrace
41afff9a 3970@kindex bt @r{(@code{backtrace})}
c906108c
SS
3971@item backtrace
3972@itemx bt
3973Print a backtrace of the entire stack: one line per frame for all
3974frames in the stack.
3975
3976You can stop the backtrace at any time by typing the system interrupt
3977character, normally @kbd{C-c}.
3978
3979@item backtrace @var{n}
3980@itemx bt @var{n}
3981Similar, but print only the innermost @var{n} frames.
3982
3983@item backtrace -@var{n}
3984@itemx bt -@var{n}
3985Similar, but print only the outermost @var{n} frames.
3986@end table
3987
3988@kindex where
3989@kindex info stack
41afff9a 3990@kindex info s @r{(@code{info stack})}
c906108c
SS
3991The names @code{where} and @code{info stack} (abbreviated @code{info s})
3992are additional aliases for @code{backtrace}.
3993
3994Each line in the backtrace shows the frame number and the function name.
3995The program counter value is also shown---unless you use @code{set
3996print address off}. The backtrace also shows the source file name and
3997line number, as well as the arguments to the function. The program
3998counter value is omitted if it is at the beginning of the code for that
3999line number.
4000
4001Here is an example of a backtrace. It was made with the command
4002@samp{bt 3}, so it shows the innermost three frames.
4003
4004@smallexample
4005@group
5d161b24 4006#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4007 at builtin.c:993
4008#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4009#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4010 at macro.c:71
4011(More stack frames follow...)
4012@end group
4013@end smallexample
4014
4015@noindent
4016The display for frame zero does not begin with a program counter
4017value, indicating that your program has stopped at the beginning of the
4018code for line @code{993} of @code{builtin.c}.
4019
25d29d70
AC
4020@kindex set backtrace past-main
4021@kindex show backtrace past-main
4022@kindex set backtrace limit
4023@kindex show backtrace limit
b4e9345d 4024
25d29d70
AC
4025Most programs have a standard user entry point---a place where system
4026libraries and startup code transition into user code. For C this is
4027@code{main}. When @value{GDBN} finds the entry function in a backtrace
4028it will terminate the backtrace, to avoid tracing into highly
4029system-specific (and generally uninteresting) code.
4030
4031If you need to examine the startup code, or limit the number of levels
4032in a backtrace, you can change this behavior:
95f90d25
DJ
4033
4034@table @code
25d29d70
AC
4035@item set backtrace past-main
4036@itemx set backtrace past-main on
4037Backtraces will continue past the user entry point.
4038
4039@item set backtrace past-main off
95f90d25
DJ
4040Backtraces will stop when they encounter the user entry point. This is the
4041default.
4042
25d29d70
AC
4043@item show backtrace past-main
4044Display the current user entry point backtrace policy.
4045
4046@item set backtrace limit @var{n}
4047@itemx set backtrace limit 0
4048@cindex backtrace limit
4049Limit the backtrace to @var{n} levels. A value of zero means
4050unlimited.
95f90d25 4051
25d29d70
AC
4052@item show backtrace limit
4053Display the current limit on backtrace levels.
95f90d25
DJ
4054@end table
4055
6d2ebf8b 4056@node Selection
c906108c
SS
4057@section Selecting a frame
4058
4059Most commands for examining the stack and other data in your program work on
4060whichever stack frame is selected at the moment. Here are the commands for
4061selecting a stack frame; all of them finish by printing a brief description
4062of the stack frame just selected.
4063
4064@table @code
d4f3574e 4065@kindex frame@r{, selecting}
41afff9a 4066@kindex f @r{(@code{frame})}
c906108c
SS
4067@item frame @var{n}
4068@itemx f @var{n}
4069Select frame number @var{n}. Recall that frame zero is the innermost
4070(currently executing) frame, frame one is the frame that called the
4071innermost one, and so on. The highest-numbered frame is the one for
4072@code{main}.
4073
4074@item frame @var{addr}
4075@itemx f @var{addr}
4076Select the frame at address @var{addr}. This is useful mainly if the
4077chaining of stack frames has been damaged by a bug, making it
4078impossible for @value{GDBN} to assign numbers properly to all frames. In
4079addition, this can be useful when your program has multiple stacks and
4080switches between them.
4081
c906108c
SS
4082On the SPARC architecture, @code{frame} needs two addresses to
4083select an arbitrary frame: a frame pointer and a stack pointer.
4084
4085On the MIPS and Alpha architecture, it needs two addresses: a stack
4086pointer and a program counter.
4087
4088On the 29k architecture, it needs three addresses: a register stack
4089pointer, a program counter, and a memory stack pointer.
4090@c note to future updaters: this is conditioned on a flag
4091@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4092@c as of 27 Jan 1994.
c906108c
SS
4093
4094@kindex up
4095@item up @var{n}
4096Move @var{n} frames up the stack. For positive numbers @var{n}, this
4097advances toward the outermost frame, to higher frame numbers, to frames
4098that have existed longer. @var{n} defaults to one.
4099
4100@kindex down
41afff9a 4101@kindex do @r{(@code{down})}
c906108c
SS
4102@item down @var{n}
4103Move @var{n} frames down the stack. For positive numbers @var{n}, this
4104advances toward the innermost frame, to lower frame numbers, to frames
4105that were created more recently. @var{n} defaults to one. You may
4106abbreviate @code{down} as @code{do}.
4107@end table
4108
4109All of these commands end by printing two lines of output describing the
4110frame. The first line shows the frame number, the function name, the
4111arguments, and the source file and line number of execution in that
5d161b24 4112frame. The second line shows the text of that source line.
c906108c
SS
4113
4114@need 1000
4115For example:
4116
4117@smallexample
4118@group
4119(@value{GDBP}) up
4120#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4121 at env.c:10
412210 read_input_file (argv[i]);
4123@end group
4124@end smallexample
4125
4126After such a printout, the @code{list} command with no arguments
4127prints ten lines centered on the point of execution in the frame.
87885426
FN
4128You can also edit the program at the point of execution with your favorite
4129editing program by typing @code{edit}.
4130@xref{List, ,Printing source lines},
4131for details.
c906108c
SS
4132
4133@table @code
4134@kindex down-silently
4135@kindex up-silently
4136@item up-silently @var{n}
4137@itemx down-silently @var{n}
4138These two commands are variants of @code{up} and @code{down},
4139respectively; they differ in that they do their work silently, without
4140causing display of the new frame. They are intended primarily for use
4141in @value{GDBN} command scripts, where the output might be unnecessary and
4142distracting.
4143@end table
4144
6d2ebf8b 4145@node Frame Info
c906108c
SS
4146@section Information about a frame
4147
4148There are several other commands to print information about the selected
4149stack frame.
4150
4151@table @code
4152@item frame
4153@itemx f
4154When used without any argument, this command does not change which
4155frame is selected, but prints a brief description of the currently
4156selected stack frame. It can be abbreviated @code{f}. With an
4157argument, this command is used to select a stack frame.
4158@xref{Selection, ,Selecting a frame}.
4159
4160@kindex info frame
41afff9a 4161@kindex info f @r{(@code{info frame})}
c906108c
SS
4162@item info frame
4163@itemx info f
4164This command prints a verbose description of the selected stack frame,
4165including:
4166
4167@itemize @bullet
5d161b24
DB
4168@item
4169the address of the frame
c906108c
SS
4170@item
4171the address of the next frame down (called by this frame)
4172@item
4173the address of the next frame up (caller of this frame)
4174@item
4175the language in which the source code corresponding to this frame is written
4176@item
4177the address of the frame's arguments
4178@item
d4f3574e
SS
4179the address of the frame's local variables
4180@item
c906108c
SS
4181the program counter saved in it (the address of execution in the caller frame)
4182@item
4183which registers were saved in the frame
4184@end itemize
4185
4186@noindent The verbose description is useful when
4187something has gone wrong that has made the stack format fail to fit
4188the usual conventions.
4189
4190@item info frame @var{addr}
4191@itemx info f @var{addr}
4192Print a verbose description of the frame at address @var{addr}, without
4193selecting that frame. The selected frame remains unchanged by this
4194command. This requires the same kind of address (more than one for some
4195architectures) that you specify in the @code{frame} command.
4196@xref{Selection, ,Selecting a frame}.
4197
4198@kindex info args
4199@item info args
4200Print the arguments of the selected frame, each on a separate line.
4201
4202@item info locals
4203@kindex info locals
4204Print the local variables of the selected frame, each on a separate
4205line. These are all variables (declared either static or automatic)
4206accessible at the point of execution of the selected frame.
4207
c906108c 4208@kindex info catch
d4f3574e
SS
4209@cindex catch exceptions, list active handlers
4210@cindex exception handlers, how to list
c906108c
SS
4211@item info catch
4212Print a list of all the exception handlers that are active in the
4213current stack frame at the current point of execution. To see other
4214exception handlers, visit the associated frame (using the @code{up},
4215@code{down}, or @code{frame} commands); then type @code{info catch}.
4216@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4217
c906108c
SS
4218@end table
4219
c906108c 4220
6d2ebf8b 4221@node Source
c906108c
SS
4222@chapter Examining Source Files
4223
4224@value{GDBN} can print parts of your program's source, since the debugging
4225information recorded in the program tells @value{GDBN} what source files were
4226used to build it. When your program stops, @value{GDBN} spontaneously prints
4227the line where it stopped. Likewise, when you select a stack frame
4228(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4229execution in that frame has stopped. You can print other portions of
4230source files by explicit command.
4231
7a292a7a 4232If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4233prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4234@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4235
4236@menu
4237* List:: Printing source lines
87885426 4238* Edit:: Editing source files
c906108c 4239* Search:: Searching source files
c906108c
SS
4240* Source Path:: Specifying source directories
4241* Machine Code:: Source and machine code
4242@end menu
4243
6d2ebf8b 4244@node List
c906108c
SS
4245@section Printing source lines
4246
4247@kindex list
41afff9a 4248@kindex l @r{(@code{list})}
c906108c 4249To print lines from a source file, use the @code{list} command
5d161b24 4250(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4251There are several ways to specify what part of the file you want to print.
4252
4253Here are the forms of the @code{list} command most commonly used:
4254
4255@table @code
4256@item list @var{linenum}
4257Print lines centered around line number @var{linenum} in the
4258current source file.
4259
4260@item list @var{function}
4261Print lines centered around the beginning of function
4262@var{function}.
4263
4264@item list
4265Print more lines. If the last lines printed were printed with a
4266@code{list} command, this prints lines following the last lines
4267printed; however, if the last line printed was a solitary line printed
4268as part of displaying a stack frame (@pxref{Stack, ,Examining the
4269Stack}), this prints lines centered around that line.
4270
4271@item list -
4272Print lines just before the lines last printed.
4273@end table
4274
4275By default, @value{GDBN} prints ten source lines with any of these forms of
4276the @code{list} command. You can change this using @code{set listsize}:
4277
4278@table @code
4279@kindex set listsize
4280@item set listsize @var{count}
4281Make the @code{list} command display @var{count} source lines (unless
4282the @code{list} argument explicitly specifies some other number).
4283
4284@kindex show listsize
4285@item show listsize
4286Display the number of lines that @code{list} prints.
4287@end table
4288
4289Repeating a @code{list} command with @key{RET} discards the argument,
4290so it is equivalent to typing just @code{list}. This is more useful
4291than listing the same lines again. An exception is made for an
4292argument of @samp{-}; that argument is preserved in repetition so that
4293each repetition moves up in the source file.
4294
4295@cindex linespec
4296In general, the @code{list} command expects you to supply zero, one or two
4297@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4298of writing them, but the effect is always to specify some source line.
c906108c
SS
4299Here is a complete description of the possible arguments for @code{list}:
4300
4301@table @code
4302@item list @var{linespec}
4303Print lines centered around the line specified by @var{linespec}.
4304
4305@item list @var{first},@var{last}
4306Print lines from @var{first} to @var{last}. Both arguments are
4307linespecs.
4308
4309@item list ,@var{last}
4310Print lines ending with @var{last}.
4311
4312@item list @var{first},
4313Print lines starting with @var{first}.
4314
4315@item list +
4316Print lines just after the lines last printed.
4317
4318@item list -
4319Print lines just before the lines last printed.
4320
4321@item list
4322As described in the preceding table.
4323@end table
4324
4325Here are the ways of specifying a single source line---all the
4326kinds of linespec.
4327
4328@table @code
4329@item @var{number}
4330Specifies line @var{number} of the current source file.
4331When a @code{list} command has two linespecs, this refers to
4332the same source file as the first linespec.
4333
4334@item +@var{offset}
4335Specifies the line @var{offset} lines after the last line printed.
4336When used as the second linespec in a @code{list} command that has
4337two, this specifies the line @var{offset} lines down from the
4338first linespec.
4339
4340@item -@var{offset}
4341Specifies the line @var{offset} lines before the last line printed.
4342
4343@item @var{filename}:@var{number}
4344Specifies line @var{number} in the source file @var{filename}.
4345
4346@item @var{function}
4347Specifies the line that begins the body of the function @var{function}.
4348For example: in C, this is the line with the open brace.
4349
4350@item @var{filename}:@var{function}
4351Specifies the line of the open-brace that begins the body of the
4352function @var{function} in the file @var{filename}. You only need the
4353file name with a function name to avoid ambiguity when there are
4354identically named functions in different source files.
4355
4356@item *@var{address}
4357Specifies the line containing the program address @var{address}.
4358@var{address} may be any expression.
4359@end table
4360
87885426
FN
4361@node Edit
4362@section Editing source files
4363@cindex editing source files
4364
4365@kindex edit
4366@kindex e @r{(@code{edit})}
4367To edit the lines in a source file, use the @code{edit} command.
4368The editing program of your choice
4369is invoked with the current line set to
4370the active line in the program.
4371Alternatively, there are several ways to specify what part of the file you
4372want to print if you want to see other parts of the program.
4373
4374Here are the forms of the @code{edit} command most commonly used:
4375
4376@table @code
4377@item edit
4378Edit the current source file at the active line number in the program.
4379
4380@item edit @var{number}
4381Edit the current source file with @var{number} as the active line number.
4382
4383@item edit @var{function}
4384Edit the file containing @var{function} at the beginning of its definition.
4385
4386@item edit @var{filename}:@var{number}
4387Specifies line @var{number} in the source file @var{filename}.
4388
4389@item edit @var{filename}:@var{function}
4390Specifies the line that begins the body of the
4391function @var{function} in the file @var{filename}. You only need the
4392file name with a function name to avoid ambiguity when there are
4393identically named functions in different source files.
4394
4395@item edit *@var{address}
4396Specifies the line containing the program address @var{address}.
4397@var{address} may be any expression.
4398@end table
4399
4400@subsection Choosing your editor
4401You can customize @value{GDBN} to use any editor you want
4402@footnote{
4403The only restriction is that your editor (say @code{ex}), recognizes the
4404following command-line syntax:
10998722 4405@smallexample
87885426 4406ex +@var{number} file
10998722
AC
4407@end smallexample
4408The optional numeric value +@var{number} designates the active line in
4409the file.}. By default, it is @value{EDITOR}, but you can change this
4410by setting the environment variable @code{EDITOR} before using
4411@value{GDBN}. For example, to configure @value{GDBN} to use the
4412@code{vi} editor, you could use these commands with the @code{sh} shell:
4413@smallexample
87885426
FN
4414EDITOR=/usr/bin/vi
4415export EDITOR
4416gdb ...
10998722 4417@end smallexample
87885426 4418or in the @code{csh} shell,
10998722 4419@smallexample
87885426
FN
4420setenv EDITOR /usr/bin/vi
4421gdb ...
10998722 4422@end smallexample
87885426 4423
6d2ebf8b 4424@node Search
c906108c
SS
4425@section Searching source files
4426@cindex searching
4427@kindex reverse-search
4428
4429There are two commands for searching through the current source file for a
4430regular expression.
4431
4432@table @code
4433@kindex search
4434@kindex forward-search
4435@item forward-search @var{regexp}
4436@itemx search @var{regexp}
4437The command @samp{forward-search @var{regexp}} checks each line,
4438starting with the one following the last line listed, for a match for
5d161b24 4439@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4440synonym @samp{search @var{regexp}} or abbreviate the command name as
4441@code{fo}.
4442
4443@item reverse-search @var{regexp}
4444The command @samp{reverse-search @var{regexp}} checks each line, starting
4445with the one before the last line listed and going backward, for a match
4446for @var{regexp}. It lists the line that is found. You can abbreviate
4447this command as @code{rev}.
4448@end table
c906108c 4449
6d2ebf8b 4450@node Source Path
c906108c
SS
4451@section Specifying source directories
4452
4453@cindex source path
4454@cindex directories for source files
4455Executable programs sometimes do not record the directories of the source
4456files from which they were compiled, just the names. Even when they do,
4457the directories could be moved between the compilation and your debugging
4458session. @value{GDBN} has a list of directories to search for source files;
4459this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4460it tries all the directories in the list, in the order they are present
4461in the list, until it finds a file with the desired name. Note that
4462the executable search path is @emph{not} used for this purpose. Neither is
4463the current working directory, unless it happens to be in the source
4464path.
4465
4466If @value{GDBN} cannot find a source file in the source path, and the
4467object program records a directory, @value{GDBN} tries that directory
4468too. If the source path is empty, and there is no record of the
4469compilation directory, @value{GDBN} looks in the current directory as a
4470last resort.
4471
4472Whenever you reset or rearrange the source path, @value{GDBN} clears out
4473any information it has cached about where source files are found and where
4474each line is in the file.
4475
4476@kindex directory
4477@kindex dir
d4f3574e
SS
4478When you start @value{GDBN}, its source path includes only @samp{cdir}
4479and @samp{cwd}, in that order.
c906108c
SS
4480To add other directories, use the @code{directory} command.
4481
4482@table @code
4483@item directory @var{dirname} @dots{}
4484@item dir @var{dirname} @dots{}
4485Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4486directory names may be given to this command, separated by @samp{:}
4487(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4488part of absolute file names) or
c906108c
SS
4489whitespace. You may specify a directory that is already in the source
4490path; this moves it forward, so @value{GDBN} searches it sooner.
4491
4492@kindex cdir
4493@kindex cwd
41afff9a
EZ
4494@vindex $cdir@r{, convenience variable}
4495@vindex $cwdr@r{, convenience variable}
c906108c
SS
4496@cindex compilation directory
4497@cindex current directory
4498@cindex working directory
4499@cindex directory, current
4500@cindex directory, compilation
4501You can use the string @samp{$cdir} to refer to the compilation
4502directory (if one is recorded), and @samp{$cwd} to refer to the current
4503working directory. @samp{$cwd} is not the same as @samp{.}---the former
4504tracks the current working directory as it changes during your @value{GDBN}
4505session, while the latter is immediately expanded to the current
4506directory at the time you add an entry to the source path.
4507
4508@item directory
4509Reset the source path to empty again. This requires confirmation.
4510
4511@c RET-repeat for @code{directory} is explicitly disabled, but since
4512@c repeating it would be a no-op we do not say that. (thanks to RMS)
4513
4514@item show directories
4515@kindex show directories
4516Print the source path: show which directories it contains.
4517@end table
4518
4519If your source path is cluttered with directories that are no longer of
4520interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4521versions of source. You can correct the situation as follows:
4522
4523@enumerate
4524@item
4525Use @code{directory} with no argument to reset the source path to empty.
4526
4527@item
4528Use @code{directory} with suitable arguments to reinstall the
4529directories you want in the source path. You can add all the
4530directories in one command.
4531@end enumerate
4532
6d2ebf8b 4533@node Machine Code
c906108c
SS
4534@section Source and machine code
4535
4536You can use the command @code{info line} to map source lines to program
4537addresses (and vice versa), and the command @code{disassemble} to display
4538a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4539mode, the @code{info line} command causes the arrow to point to the
5d161b24 4540line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4541well as hex.
4542
4543@table @code
4544@kindex info line
4545@item info line @var{linespec}
4546Print the starting and ending addresses of the compiled code for
4547source line @var{linespec}. You can specify source lines in any of
4548the ways understood by the @code{list} command (@pxref{List, ,Printing
4549source lines}).
4550@end table
4551
4552For example, we can use @code{info line} to discover the location of
4553the object code for the first line of function
4554@code{m4_changequote}:
4555
d4f3574e
SS
4556@c FIXME: I think this example should also show the addresses in
4557@c symbolic form, as they usually would be displayed.
c906108c 4558@smallexample
96a2c332 4559(@value{GDBP}) info line m4_changequote
c906108c
SS
4560Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4561@end smallexample
4562
4563@noindent
4564We can also inquire (using @code{*@var{addr}} as the form for
4565@var{linespec}) what source line covers a particular address:
4566@smallexample
4567(@value{GDBP}) info line *0x63ff
4568Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4569@end smallexample
4570
4571@cindex @code{$_} and @code{info line}
41afff9a 4572@kindex x@r{(examine), and} info line
c906108c
SS
4573After @code{info line}, the default address for the @code{x} command
4574is changed to the starting address of the line, so that @samp{x/i} is
4575sufficient to begin examining the machine code (@pxref{Memory,
4576,Examining memory}). Also, this address is saved as the value of the
4577convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4578variables}).
4579
4580@table @code
4581@kindex disassemble
4582@cindex assembly instructions
4583@cindex instructions, assembly
4584@cindex machine instructions
4585@cindex listing machine instructions
4586@item disassemble
4587This specialized command dumps a range of memory as machine
4588instructions. The default memory range is the function surrounding the
4589program counter of the selected frame. A single argument to this
4590command is a program counter value; @value{GDBN} dumps the function
4591surrounding this value. Two arguments specify a range of addresses
4592(first inclusive, second exclusive) to dump.
4593@end table
4594
c906108c
SS
4595The following example shows the disassembly of a range of addresses of
4596HP PA-RISC 2.0 code:
4597
4598@smallexample
4599(@value{GDBP}) disas 0x32c4 0x32e4
4600Dump of assembler code from 0x32c4 to 0x32e4:
46010x32c4 <main+204>: addil 0,dp
46020x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
46030x32cc <main+212>: ldil 0x3000,r31
46040x32d0 <main+216>: ble 0x3f8(sr4,r31)
46050x32d4 <main+220>: ldo 0(r31),rp
46060x32d8 <main+224>: addil -0x800,dp
46070x32dc <main+228>: ldo 0x588(r1),r26
46080x32e0 <main+232>: ldil 0x3000,r31
4609End of assembler dump.
4610@end smallexample
c906108c
SS
4611
4612Some architectures have more than one commonly-used set of instruction
4613mnemonics or other syntax.
4614
4615@table @code
d4f3574e 4616@kindex set disassembly-flavor
c906108c
SS
4617@cindex assembly instructions
4618@cindex instructions, assembly
4619@cindex machine instructions
4620@cindex listing machine instructions
d4f3574e
SS
4621@cindex Intel disassembly flavor
4622@cindex AT&T disassembly flavor
4623@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4624Select the instruction set to use when disassembling the
4625program via the @code{disassemble} or @code{x/i} commands.
4626
4627Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4628can set @var{instruction-set} to either @code{intel} or @code{att}.
4629The default is @code{att}, the AT&T flavor used by default by Unix
4630assemblers for x86-based targets.
c906108c
SS
4631@end table
4632
4633
6d2ebf8b 4634@node Data
c906108c
SS
4635@chapter Examining Data
4636
4637@cindex printing data
4638@cindex examining data
4639@kindex print
4640@kindex inspect
4641@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4642@c document because it is nonstandard... Under Epoch it displays in a
4643@c different window or something like that.
4644The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4645command (abbreviated @code{p}), or its synonym @code{inspect}. It
4646evaluates and prints the value of an expression of the language your
4647program is written in (@pxref{Languages, ,Using @value{GDBN} with
4648Different Languages}).
c906108c
SS
4649
4650@table @code
d4f3574e
SS
4651@item print @var{expr}
4652@itemx print /@var{f} @var{expr}
4653@var{expr} is an expression (in the source language). By default the
4654value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4655you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4656@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4657formats}.
4658
4659@item print
4660@itemx print /@var{f}
d4f3574e 4661If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4662@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4663conveniently inspect the same value in an alternative format.
4664@end table
4665
4666A more low-level way of examining data is with the @code{x} command.
4667It examines data in memory at a specified address and prints it in a
4668specified format. @xref{Memory, ,Examining memory}.
4669
7a292a7a 4670If you are interested in information about types, or about how the
d4f3574e
SS
4671fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4672command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4673Table}.
c906108c
SS
4674
4675@menu
4676* Expressions:: Expressions
4677* Variables:: Program variables
4678* Arrays:: Artificial arrays
4679* Output Formats:: Output formats
4680* Memory:: Examining memory
4681* Auto Display:: Automatic display
4682* Print Settings:: Print settings
4683* Value History:: Value history
4684* Convenience Vars:: Convenience variables
4685* Registers:: Registers
c906108c 4686* Floating Point Hardware:: Floating point hardware
53c69bd7 4687* Vector Unit:: Vector Unit
29e57380 4688* Memory Region Attributes:: Memory region attributes
16d9dec6 4689* Dump/Restore Files:: Copy between memory and a file
a0eb71c5
KB
4690* Character Sets:: Debugging programs that use a different
4691 character set than GDB does
c906108c
SS
4692@end menu
4693
6d2ebf8b 4694@node Expressions
c906108c
SS
4695@section Expressions
4696
4697@cindex expressions
4698@code{print} and many other @value{GDBN} commands accept an expression and
4699compute its value. Any kind of constant, variable or operator defined
4700by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4701@value{GDBN}. This includes conditional expressions, function calls,
4702casts, and string constants. It also includes preprocessor macros, if
4703you compiled your program to include this information; see
4704@ref{Compilation}.
c906108c 4705
d4f3574e
SS
4706@value{GDBN} supports array constants in expressions input by
4707the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4708you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4709memory that is @code{malloc}ed in the target program.
c906108c 4710
c906108c
SS
4711Because C is so widespread, most of the expressions shown in examples in
4712this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4713Languages}, for information on how to use expressions in other
4714languages.
4715
4716In this section, we discuss operators that you can use in @value{GDBN}
4717expressions regardless of your programming language.
4718
4719Casts are supported in all languages, not just in C, because it is so
4720useful to cast a number into a pointer in order to examine a structure
4721at that address in memory.
4722@c FIXME: casts supported---Mod2 true?
c906108c
SS
4723
4724@value{GDBN} supports these operators, in addition to those common
4725to programming languages:
4726
4727@table @code
4728@item @@
4729@samp{@@} is a binary operator for treating parts of memory as arrays.
4730@xref{Arrays, ,Artificial arrays}, for more information.
4731
4732@item ::
4733@samp{::} allows you to specify a variable in terms of the file or
4734function where it is defined. @xref{Variables, ,Program variables}.
4735
4736@cindex @{@var{type}@}
4737@cindex type casting memory
4738@cindex memory, viewing as typed object
4739@cindex casts, to view memory
4740@item @{@var{type}@} @var{addr}
4741Refers to an object of type @var{type} stored at address @var{addr} in
4742memory. @var{addr} may be any expression whose value is an integer or
4743pointer (but parentheses are required around binary operators, just as in
4744a cast). This construct is allowed regardless of what kind of data is
4745normally supposed to reside at @var{addr}.
4746@end table
4747
6d2ebf8b 4748@node Variables
c906108c
SS
4749@section Program variables
4750
4751The most common kind of expression to use is the name of a variable
4752in your program.
4753
4754Variables in expressions are understood in the selected stack frame
4755(@pxref{Selection, ,Selecting a frame}); they must be either:
4756
4757@itemize @bullet
4758@item
4759global (or file-static)
4760@end itemize
4761
5d161b24 4762@noindent or
c906108c
SS
4763
4764@itemize @bullet
4765@item
4766visible according to the scope rules of the
4767programming language from the point of execution in that frame
5d161b24 4768@end itemize
c906108c
SS
4769
4770@noindent This means that in the function
4771
474c8240 4772@smallexample
c906108c
SS
4773foo (a)
4774 int a;
4775@{
4776 bar (a);
4777 @{
4778 int b = test ();
4779 bar (b);
4780 @}
4781@}
474c8240 4782@end smallexample
c906108c
SS
4783
4784@noindent
4785you can examine and use the variable @code{a} whenever your program is
4786executing within the function @code{foo}, but you can only use or
4787examine the variable @code{b} while your program is executing inside
4788the block where @code{b} is declared.
4789
4790@cindex variable name conflict
4791There is an exception: you can refer to a variable or function whose
4792scope is a single source file even if the current execution point is not
4793in this file. But it is possible to have more than one such variable or
4794function with the same name (in different source files). If that
4795happens, referring to that name has unpredictable effects. If you wish,
4796you can specify a static variable in a particular function or file,
4797using the colon-colon notation:
4798
d4f3574e 4799@cindex colon-colon, context for variables/functions
c906108c
SS
4800@iftex
4801@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4802@cindex @code{::}, context for variables/functions
c906108c 4803@end iftex
474c8240 4804@smallexample
c906108c
SS
4805@var{file}::@var{variable}
4806@var{function}::@var{variable}
474c8240 4807@end smallexample
c906108c
SS
4808
4809@noindent
4810Here @var{file} or @var{function} is the name of the context for the
4811static @var{variable}. In the case of file names, you can use quotes to
4812make sure @value{GDBN} parses the file name as a single word---for example,
4813to print a global value of @code{x} defined in @file{f2.c}:
4814
474c8240 4815@smallexample
c906108c 4816(@value{GDBP}) p 'f2.c'::x
474c8240 4817@end smallexample
c906108c 4818
b37052ae 4819@cindex C@t{++} scope resolution
c906108c 4820This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4821use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4822scope resolution operator in @value{GDBN} expressions.
4823@c FIXME: Um, so what happens in one of those rare cases where it's in
4824@c conflict?? --mew
c906108c
SS
4825
4826@cindex wrong values
4827@cindex variable values, wrong
4828@quotation
4829@emph{Warning:} Occasionally, a local variable may appear to have the
4830wrong value at certain points in a function---just after entry to a new
4831scope, and just before exit.
4832@end quotation
4833You may see this problem when you are stepping by machine instructions.
4834This is because, on most machines, it takes more than one instruction to
4835set up a stack frame (including local variable definitions); if you are
4836stepping by machine instructions, variables may appear to have the wrong
4837values until the stack frame is completely built. On exit, it usually
4838also takes more than one machine instruction to destroy a stack frame;
4839after you begin stepping through that group of instructions, local
4840variable definitions may be gone.
4841
4842This may also happen when the compiler does significant optimizations.
4843To be sure of always seeing accurate values, turn off all optimization
4844when compiling.
4845
d4f3574e
SS
4846@cindex ``No symbol "foo" in current context''
4847Another possible effect of compiler optimizations is to optimize
4848unused variables out of existence, or assign variables to registers (as
4849opposed to memory addresses). Depending on the support for such cases
4850offered by the debug info format used by the compiler, @value{GDBN}
4851might not be able to display values for such local variables. If that
4852happens, @value{GDBN} will print a message like this:
4853
474c8240 4854@smallexample
d4f3574e 4855No symbol "foo" in current context.
474c8240 4856@end smallexample
d4f3574e
SS
4857
4858To solve such problems, either recompile without optimizations, or use a
4859different debug info format, if the compiler supports several such
0179ffac
DC
4860formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler
4861usually supports the @option{-gstabs+} option. @option{-gstabs+}
4862produces debug info in a format that is superior to formats such as
4863COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
4864an effective form for debug info. @xref{Debugging Options,,Options
4865for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
d4f3574e
SS
4866
4867
6d2ebf8b 4868@node Arrays
c906108c
SS
4869@section Artificial arrays
4870
4871@cindex artificial array
41afff9a 4872@kindex @@@r{, referencing memory as an array}
c906108c
SS
4873It is often useful to print out several successive objects of the
4874same type in memory; a section of an array, or an array of
4875dynamically determined size for which only a pointer exists in the
4876program.
4877
4878You can do this by referring to a contiguous span of memory as an
4879@dfn{artificial array}, using the binary operator @samp{@@}. The left
4880operand of @samp{@@} should be the first element of the desired array
4881and be an individual object. The right operand should be the desired length
4882of the array. The result is an array value whose elements are all of
4883the type of the left argument. The first element is actually the left
4884argument; the second element comes from bytes of memory immediately
4885following those that hold the first element, and so on. Here is an
4886example. If a program says
4887
474c8240 4888@smallexample
c906108c 4889int *array = (int *) malloc (len * sizeof (int));
474c8240 4890@end smallexample
c906108c
SS
4891
4892@noindent
4893you can print the contents of @code{array} with
4894
474c8240 4895@smallexample
c906108c 4896p *array@@len
474c8240 4897@end smallexample
c906108c
SS
4898
4899The left operand of @samp{@@} must reside in memory. Array values made
4900with @samp{@@} in this way behave just like other arrays in terms of
4901subscripting, and are coerced to pointers when used in expressions.
4902Artificial arrays most often appear in expressions via the value history
4903(@pxref{Value History, ,Value history}), after printing one out.
4904
4905Another way to create an artificial array is to use a cast.
4906This re-interprets a value as if it were an array.
4907The value need not be in memory:
474c8240 4908@smallexample
c906108c
SS
4909(@value{GDBP}) p/x (short[2])0x12345678
4910$1 = @{0x1234, 0x5678@}
474c8240 4911@end smallexample
c906108c
SS
4912
4913As a convenience, if you leave the array length out (as in
c3f6f71d 4914@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 4915the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 4916@smallexample
c906108c
SS
4917(@value{GDBP}) p/x (short[])0x12345678
4918$2 = @{0x1234, 0x5678@}
474c8240 4919@end smallexample
c906108c
SS
4920
4921Sometimes the artificial array mechanism is not quite enough; in
4922moderately complex data structures, the elements of interest may not
4923actually be adjacent---for example, if you are interested in the values
4924of pointers in an array. One useful work-around in this situation is
4925to use a convenience variable (@pxref{Convenience Vars, ,Convenience
4926variables}) as a counter in an expression that prints the first
4927interesting value, and then repeat that expression via @key{RET}. For
4928instance, suppose you have an array @code{dtab} of pointers to
4929structures, and you are interested in the values of a field @code{fv}
4930in each structure. Here is an example of what you might type:
4931
474c8240 4932@smallexample
c906108c
SS
4933set $i = 0
4934p dtab[$i++]->fv
4935@key{RET}
4936@key{RET}
4937@dots{}
474c8240 4938@end smallexample
c906108c 4939
6d2ebf8b 4940@node Output Formats
c906108c
SS
4941@section Output formats
4942
4943@cindex formatted output
4944@cindex output formats
4945By default, @value{GDBN} prints a value according to its data type. Sometimes
4946this is not what you want. For example, you might want to print a number
4947in hex, or a pointer in decimal. Or you might want to view data in memory
4948at a certain address as a character string or as an instruction. To do
4949these things, specify an @dfn{output format} when you print a value.
4950
4951The simplest use of output formats is to say how to print a value
4952already computed. This is done by starting the arguments of the
4953@code{print} command with a slash and a format letter. The format
4954letters supported are:
4955
4956@table @code
4957@item x
4958Regard the bits of the value as an integer, and print the integer in
4959hexadecimal.
4960
4961@item d
4962Print as integer in signed decimal.
4963
4964@item u
4965Print as integer in unsigned decimal.
4966
4967@item o
4968Print as integer in octal.
4969
4970@item t
4971Print as integer in binary. The letter @samp{t} stands for ``two''.
4972@footnote{@samp{b} cannot be used because these format letters are also
4973used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 4974see @ref{Memory,,Examining memory}.}
c906108c
SS
4975
4976@item a
4977@cindex unknown address, locating
3d67e040 4978@cindex locate address
c906108c
SS
4979Print as an address, both absolute in hexadecimal and as an offset from
4980the nearest preceding symbol. You can use this format used to discover
4981where (in what function) an unknown address is located:
4982
474c8240 4983@smallexample
c906108c
SS
4984(@value{GDBP}) p/a 0x54320
4985$3 = 0x54320 <_initialize_vx+396>
474c8240 4986@end smallexample
c906108c 4987
3d67e040
EZ
4988@noindent
4989The command @code{info symbol 0x54320} yields similar results.
4990@xref{Symbols, info symbol}.
4991
c906108c
SS
4992@item c
4993Regard as an integer and print it as a character constant.
4994
4995@item f
4996Regard the bits of the value as a floating point number and print
4997using typical floating point syntax.
4998@end table
4999
5000For example, to print the program counter in hex (@pxref{Registers}), type
5001
474c8240 5002@smallexample
c906108c 5003p/x $pc
474c8240 5004@end smallexample
c906108c
SS
5005
5006@noindent
5007Note that no space is required before the slash; this is because command
5008names in @value{GDBN} cannot contain a slash.
5009
5010To reprint the last value in the value history with a different format,
5011you can use the @code{print} command with just a format and no
5012expression. For example, @samp{p/x} reprints the last value in hex.
5013
6d2ebf8b 5014@node Memory
c906108c
SS
5015@section Examining memory
5016
5017You can use the command @code{x} (for ``examine'') to examine memory in
5018any of several formats, independently of your program's data types.
5019
5020@cindex examining memory
5021@table @code
41afff9a 5022@kindex x @r{(examine memory)}
c906108c
SS
5023@item x/@var{nfu} @var{addr}
5024@itemx x @var{addr}
5025@itemx x
5026Use the @code{x} command to examine memory.
5027@end table
5028
5029@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5030much memory to display and how to format it; @var{addr} is an
5031expression giving the address where you want to start displaying memory.
5032If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5033Several commands set convenient defaults for @var{addr}.
5034
5035@table @r
5036@item @var{n}, the repeat count
5037The repeat count is a decimal integer; the default is 1. It specifies
5038how much memory (counting by units @var{u}) to display.
5039@c This really is **decimal**; unaffected by 'set radix' as of GDB
5040@c 4.1.2.
5041
5042@item @var{f}, the display format
5043The display format is one of the formats used by @code{print},
5044@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5045The default is @samp{x} (hexadecimal) initially.
5046The default changes each time you use either @code{x} or @code{print}.
5047
5048@item @var{u}, the unit size
5049The unit size is any of
5050
5051@table @code
5052@item b
5053Bytes.
5054@item h
5055Halfwords (two bytes).
5056@item w
5057Words (four bytes). This is the initial default.
5058@item g
5059Giant words (eight bytes).
5060@end table
5061
5062Each time you specify a unit size with @code{x}, that size becomes the
5063default unit the next time you use @code{x}. (For the @samp{s} and
5064@samp{i} formats, the unit size is ignored and is normally not written.)
5065
5066@item @var{addr}, starting display address
5067@var{addr} is the address where you want @value{GDBN} to begin displaying
5068memory. The expression need not have a pointer value (though it may);
5069it is always interpreted as an integer address of a byte of memory.
5070@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5071@var{addr} is usually just after the last address examined---but several
5072other commands also set the default address: @code{info breakpoints} (to
5073the address of the last breakpoint listed), @code{info line} (to the
5074starting address of a line), and @code{print} (if you use it to display
5075a value from memory).
5076@end table
5077
5078For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5079(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5080starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5081words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5082@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5083
5084Since the letters indicating unit sizes are all distinct from the
5085letters specifying output formats, you do not have to remember whether
5086unit size or format comes first; either order works. The output
5087specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5088(However, the count @var{n} must come first; @samp{wx4} does not work.)
5089
5090Even though the unit size @var{u} is ignored for the formats @samp{s}
5091and @samp{i}, you might still want to use a count @var{n}; for example,
5092@samp{3i} specifies that you want to see three machine instructions,
5093including any operands. The command @code{disassemble} gives an
d4f3574e 5094alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5095Code,,Source and machine code}.
5096
5097All the defaults for the arguments to @code{x} are designed to make it
5098easy to continue scanning memory with minimal specifications each time
5099you use @code{x}. For example, after you have inspected three machine
5100instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5101with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5102the repeat count @var{n} is used again; the other arguments default as
5103for successive uses of @code{x}.
5104
5105@cindex @code{$_}, @code{$__}, and value history
5106The addresses and contents printed by the @code{x} command are not saved
5107in the value history because there is often too much of them and they
5108would get in the way. Instead, @value{GDBN} makes these values available for
5109subsequent use in expressions as values of the convenience variables
5110@code{$_} and @code{$__}. After an @code{x} command, the last address
5111examined is available for use in expressions in the convenience variable
5112@code{$_}. The contents of that address, as examined, are available in
5113the convenience variable @code{$__}.
5114
5115If the @code{x} command has a repeat count, the address and contents saved
5116are from the last memory unit printed; this is not the same as the last
5117address printed if several units were printed on the last line of output.
5118
6d2ebf8b 5119@node Auto Display
c906108c
SS
5120@section Automatic display
5121@cindex automatic display
5122@cindex display of expressions
5123
5124If you find that you want to print the value of an expression frequently
5125(to see how it changes), you might want to add it to the @dfn{automatic
5126display list} so that @value{GDBN} prints its value each time your program stops.
5127Each expression added to the list is given a number to identify it;
5128to remove an expression from the list, you specify that number.
5129The automatic display looks like this:
5130
474c8240 5131@smallexample
c906108c
SS
51322: foo = 38
51333: bar[5] = (struct hack *) 0x3804
474c8240 5134@end smallexample
c906108c
SS
5135
5136@noindent
5137This display shows item numbers, expressions and their current values. As with
5138displays you request manually using @code{x} or @code{print}, you can
5139specify the output format you prefer; in fact, @code{display} decides
5140whether to use @code{print} or @code{x} depending on how elaborate your
5141format specification is---it uses @code{x} if you specify a unit size,
5142or one of the two formats (@samp{i} and @samp{s}) that are only
5143supported by @code{x}; otherwise it uses @code{print}.
5144
5145@table @code
5146@kindex display
d4f3574e
SS
5147@item display @var{expr}
5148Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5149each time your program stops. @xref{Expressions, ,Expressions}.
5150
5151@code{display} does not repeat if you press @key{RET} again after using it.
5152
d4f3574e 5153@item display/@var{fmt} @var{expr}
c906108c 5154For @var{fmt} specifying only a display format and not a size or
d4f3574e 5155count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5156arrange to display it each time in the specified format @var{fmt}.
5157@xref{Output Formats,,Output formats}.
5158
5159@item display/@var{fmt} @var{addr}
5160For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5161number of units, add the expression @var{addr} as a memory address to
5162be examined each time your program stops. Examining means in effect
5163doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5164@end table
5165
5166For example, @samp{display/i $pc} can be helpful, to see the machine
5167instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5168is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5169
5170@table @code
5171@kindex delete display
5172@kindex undisplay
5173@item undisplay @var{dnums}@dots{}
5174@itemx delete display @var{dnums}@dots{}
5175Remove item numbers @var{dnums} from the list of expressions to display.
5176
5177@code{undisplay} does not repeat if you press @key{RET} after using it.
5178(Otherwise you would just get the error @samp{No display number @dots{}}.)
5179
5180@kindex disable display
5181@item disable display @var{dnums}@dots{}
5182Disable the display of item numbers @var{dnums}. A disabled display
5183item is not printed automatically, but is not forgotten. It may be
5184enabled again later.
5185
5186@kindex enable display
5187@item enable display @var{dnums}@dots{}
5188Enable display of item numbers @var{dnums}. It becomes effective once
5189again in auto display of its expression, until you specify otherwise.
5190
5191@item display
5192Display the current values of the expressions on the list, just as is
5193done when your program stops.
5194
5195@kindex info display
5196@item info display
5197Print the list of expressions previously set up to display
5198automatically, each one with its item number, but without showing the
5199values. This includes disabled expressions, which are marked as such.
5200It also includes expressions which would not be displayed right now
5201because they refer to automatic variables not currently available.
5202@end table
5203
5204If a display expression refers to local variables, then it does not make
5205sense outside the lexical context for which it was set up. Such an
5206expression is disabled when execution enters a context where one of its
5207variables is not defined. For example, if you give the command
5208@code{display last_char} while inside a function with an argument
5209@code{last_char}, @value{GDBN} displays this argument while your program
5210continues to stop inside that function. When it stops elsewhere---where
5211there is no variable @code{last_char}---the display is disabled
5212automatically. The next time your program stops where @code{last_char}
5213is meaningful, you can enable the display expression once again.
5214
6d2ebf8b 5215@node Print Settings
c906108c
SS
5216@section Print settings
5217
5218@cindex format options
5219@cindex print settings
5220@value{GDBN} provides the following ways to control how arrays, structures,
5221and symbols are printed.
5222
5223@noindent
5224These settings are useful for debugging programs in any language:
5225
5226@table @code
5227@kindex set print address
5228@item set print address
5229@itemx set print address on
5230@value{GDBN} prints memory addresses showing the location of stack
5231traces, structure values, pointer values, breakpoints, and so forth,
5232even when it also displays the contents of those addresses. The default
5233is @code{on}. For example, this is what a stack frame display looks like with
5234@code{set print address on}:
5235
5236@smallexample
5237@group
5238(@value{GDBP}) f
5239#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5240 at input.c:530
5241530 if (lquote != def_lquote)
5242@end group
5243@end smallexample
5244
5245@item set print address off
5246Do not print addresses when displaying their contents. For example,
5247this is the same stack frame displayed with @code{set print address off}:
5248
5249@smallexample
5250@group
5251(@value{GDBP}) set print addr off
5252(@value{GDBP}) f
5253#0 set_quotes (lq="<<", rq=">>") at input.c:530
5254530 if (lquote != def_lquote)
5255@end group
5256@end smallexample
5257
5258You can use @samp{set print address off} to eliminate all machine
5259dependent displays from the @value{GDBN} interface. For example, with
5260@code{print address off}, you should get the same text for backtraces on
5261all machines---whether or not they involve pointer arguments.
5262
5263@kindex show print address
5264@item show print address
5265Show whether or not addresses are to be printed.
5266@end table
5267
5268When @value{GDBN} prints a symbolic address, it normally prints the
5269closest earlier symbol plus an offset. If that symbol does not uniquely
5270identify the address (for example, it is a name whose scope is a single
5271source file), you may need to clarify. One way to do this is with
5272@code{info line}, for example @samp{info line *0x4537}. Alternately,
5273you can set @value{GDBN} to print the source file and line number when
5274it prints a symbolic address:
5275
5276@table @code
5277@kindex set print symbol-filename
5278@item set print symbol-filename on
5279Tell @value{GDBN} to print the source file name and line number of a
5280symbol in the symbolic form of an address.
5281
5282@item set print symbol-filename off
5283Do not print source file name and line number of a symbol. This is the
5284default.
5285
5286@kindex show print symbol-filename
5287@item show print symbol-filename
5288Show whether or not @value{GDBN} will print the source file name and
5289line number of a symbol in the symbolic form of an address.
5290@end table
5291
5292Another situation where it is helpful to show symbol filenames and line
5293numbers is when disassembling code; @value{GDBN} shows you the line
5294number and source file that corresponds to each instruction.
5295
5296Also, you may wish to see the symbolic form only if the address being
5297printed is reasonably close to the closest earlier symbol:
5298
5299@table @code
5300@kindex set print max-symbolic-offset
5301@item set print max-symbolic-offset @var{max-offset}
5302Tell @value{GDBN} to only display the symbolic form of an address if the
5303offset between the closest earlier symbol and the address is less than
5d161b24 5304@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5305to always print the symbolic form of an address if any symbol precedes it.
5306
5307@kindex show print max-symbolic-offset
5308@item show print max-symbolic-offset
5309Ask how large the maximum offset is that @value{GDBN} prints in a
5310symbolic address.
5311@end table
5312
5313@cindex wild pointer, interpreting
5314@cindex pointer, finding referent
5315If you have a pointer and you are not sure where it points, try
5316@samp{set print symbol-filename on}. Then you can determine the name
5317and source file location of the variable where it points, using
5318@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5319For example, here @value{GDBN} shows that a variable @code{ptt} points
5320at another variable @code{t}, defined in @file{hi2.c}:
5321
474c8240 5322@smallexample
c906108c
SS
5323(@value{GDBP}) set print symbol-filename on
5324(@value{GDBP}) p/a ptt
5325$4 = 0xe008 <t in hi2.c>
474c8240 5326@end smallexample
c906108c
SS
5327
5328@quotation
5329@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5330does not show the symbol name and filename of the referent, even with
5331the appropriate @code{set print} options turned on.
5332@end quotation
5333
5334Other settings control how different kinds of objects are printed:
5335
5336@table @code
5337@kindex set print array
5338@item set print array
5339@itemx set print array on
5340Pretty print arrays. This format is more convenient to read,
5341but uses more space. The default is off.
5342
5343@item set print array off
5344Return to compressed format for arrays.
5345
5346@kindex show print array
5347@item show print array
5348Show whether compressed or pretty format is selected for displaying
5349arrays.
5350
5351@kindex set print elements
5352@item set print elements @var{number-of-elements}
5353Set a limit on how many elements of an array @value{GDBN} will print.
5354If @value{GDBN} is printing a large array, it stops printing after it has
5355printed the number of elements set by the @code{set print elements} command.
5356This limit also applies to the display of strings.
d4f3574e 5357When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5358Setting @var{number-of-elements} to zero means that the printing is unlimited.
5359
5360@kindex show print elements
5361@item show print elements
5362Display the number of elements of a large array that @value{GDBN} will print.
5363If the number is 0, then the printing is unlimited.
5364
5365@kindex set print null-stop
5366@item set print null-stop
5367Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5368@sc{null} is encountered. This is useful when large arrays actually
c906108c 5369contain only short strings.
d4f3574e 5370The default is off.
c906108c
SS
5371
5372@kindex set print pretty
5373@item set print pretty on
5d161b24 5374Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5375per line, like this:
5376
5377@smallexample
5378@group
5379$1 = @{
5380 next = 0x0,
5381 flags = @{
5382 sweet = 1,
5383 sour = 1
5384 @},
5385 meat = 0x54 "Pork"
5386@}
5387@end group
5388@end smallexample
5389
5390@item set print pretty off
5391Cause @value{GDBN} to print structures in a compact format, like this:
5392
5393@smallexample
5394@group
5395$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5396meat = 0x54 "Pork"@}
5397@end group
5398@end smallexample
5399
5400@noindent
5401This is the default format.
5402
5403@kindex show print pretty
5404@item show print pretty
5405Show which format @value{GDBN} is using to print structures.
5406
5407@kindex set print sevenbit-strings
5408@item set print sevenbit-strings on
5409Print using only seven-bit characters; if this option is set,
5410@value{GDBN} displays any eight-bit characters (in strings or
5411character values) using the notation @code{\}@var{nnn}. This setting is
5412best if you are working in English (@sc{ascii}) and you use the
5413high-order bit of characters as a marker or ``meta'' bit.
5414
5415@item set print sevenbit-strings off
5416Print full eight-bit characters. This allows the use of more
5417international character sets, and is the default.
5418
5419@kindex show print sevenbit-strings
5420@item show print sevenbit-strings
5421Show whether or not @value{GDBN} is printing only seven-bit characters.
5422
5423@kindex set print union
5424@item set print union on
5d161b24 5425Tell @value{GDBN} to print unions which are contained in structures. This
c906108c
SS
5426is the default setting.
5427
5428@item set print union off
5429Tell @value{GDBN} not to print unions which are contained in structures.
5430
5431@kindex show print union
5432@item show print union
5433Ask @value{GDBN} whether or not it will print unions which are contained in
5434structures.
5435
5436For example, given the declarations
5437
5438@smallexample
5439typedef enum @{Tree, Bug@} Species;
5440typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5441typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5442 Bug_forms;
5443
5444struct thing @{
5445 Species it;
5446 union @{
5447 Tree_forms tree;
5448 Bug_forms bug;
5449 @} form;
5450@};
5451
5452struct thing foo = @{Tree, @{Acorn@}@};
5453@end smallexample
5454
5455@noindent
5456with @code{set print union on} in effect @samp{p foo} would print
5457
5458@smallexample
5459$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5460@end smallexample
5461
5462@noindent
5463and with @code{set print union off} in effect it would print
5464
5465@smallexample
5466$1 = @{it = Tree, form = @{...@}@}
5467@end smallexample
5468@end table
5469
c906108c
SS
5470@need 1000
5471@noindent
b37052ae 5472These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5473
5474@table @code
5475@cindex demangling
5476@kindex set print demangle
5477@item set print demangle
5478@itemx set print demangle on
b37052ae 5479Print C@t{++} names in their source form rather than in the encoded
c906108c 5480(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5481linkage. The default is on.
c906108c
SS
5482
5483@kindex show print demangle
5484@item show print demangle
b37052ae 5485Show whether C@t{++} names are printed in mangled or demangled form.
c906108c
SS
5486
5487@kindex set print asm-demangle
5488@item set print asm-demangle
5489@itemx set print asm-demangle on
b37052ae 5490Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5491in assembler code printouts such as instruction disassemblies.
5492The default is off.
5493
5494@kindex show print asm-demangle
5495@item show print asm-demangle
b37052ae 5496Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5497or demangled form.
5498
5499@kindex set demangle-style
b37052ae
EZ
5500@cindex C@t{++} symbol decoding style
5501@cindex symbol decoding style, C@t{++}
c906108c
SS
5502@item set demangle-style @var{style}
5503Choose among several encoding schemes used by different compilers to
b37052ae 5504represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5505
5506@table @code
5507@item auto
5508Allow @value{GDBN} to choose a decoding style by inspecting your program.
5509
5510@item gnu
b37052ae 5511Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5512This is the default.
c906108c
SS
5513
5514@item hp
b37052ae 5515Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5516
5517@item lucid
b37052ae 5518Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5519
5520@item arm
b37052ae 5521Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5522@strong{Warning:} this setting alone is not sufficient to allow
5523debugging @code{cfront}-generated executables. @value{GDBN} would
5524require further enhancement to permit that.
5525
5526@end table
5527If you omit @var{style}, you will see a list of possible formats.
5528
5529@kindex show demangle-style
5530@item show demangle-style
b37052ae 5531Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c
SS
5532
5533@kindex set print object
5534@item set print object
5535@itemx set print object on
5536When displaying a pointer to an object, identify the @emph{actual}
5537(derived) type of the object rather than the @emph{declared} type, using
5538the virtual function table.
5539
5540@item set print object off
5541Display only the declared type of objects, without reference to the
5542virtual function table. This is the default setting.
5543
5544@kindex show print object
5545@item show print object
5546Show whether actual, or declared, object types are displayed.
5547
5548@kindex set print static-members
5549@item set print static-members
5550@itemx set print static-members on
b37052ae 5551Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5552
5553@item set print static-members off
b37052ae 5554Do not print static members when displaying a C@t{++} object.
c906108c
SS
5555
5556@kindex show print static-members
5557@item show print static-members
b37052ae 5558Show whether C@t{++} static members are printed, or not.
c906108c
SS
5559
5560@c These don't work with HP ANSI C++ yet.
5561@kindex set print vtbl
5562@item set print vtbl
5563@itemx set print vtbl on
b37052ae 5564Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5565(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5566ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5567
5568@item set print vtbl off
b37052ae 5569Do not pretty print C@t{++} virtual function tables.
c906108c
SS
5570
5571@kindex show print vtbl
5572@item show print vtbl
b37052ae 5573Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5574@end table
c906108c 5575
6d2ebf8b 5576@node Value History
c906108c
SS
5577@section Value history
5578
5579@cindex value history
5d161b24
DB
5580Values printed by the @code{print} command are saved in the @value{GDBN}
5581@dfn{value history}. This allows you to refer to them in other expressions.
5582Values are kept until the symbol table is re-read or discarded
5583(for example with the @code{file} or @code{symbol-file} commands).
5584When the symbol table changes, the value history is discarded,
5585since the values may contain pointers back to the types defined in the
c906108c
SS
5586symbol table.
5587
5588@cindex @code{$}
5589@cindex @code{$$}
5590@cindex history number
5591The values printed are given @dfn{history numbers} by which you can
5592refer to them. These are successive integers starting with one.
5593@code{print} shows you the history number assigned to a value by
5594printing @samp{$@var{num} = } before the value; here @var{num} is the
5595history number.
5596
5597To refer to any previous value, use @samp{$} followed by the value's
5598history number. The way @code{print} labels its output is designed to
5599remind you of this. Just @code{$} refers to the most recent value in
5600the history, and @code{$$} refers to the value before that.
5601@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5602is the value just prior to @code{$$}, @code{$$1} is equivalent to
5603@code{$$}, and @code{$$0} is equivalent to @code{$}.
5604
5605For example, suppose you have just printed a pointer to a structure and
5606want to see the contents of the structure. It suffices to type
5607
474c8240 5608@smallexample
c906108c 5609p *$
474c8240 5610@end smallexample
c906108c
SS
5611
5612If you have a chain of structures where the component @code{next} points
5613to the next one, you can print the contents of the next one with this:
5614
474c8240 5615@smallexample
c906108c 5616p *$.next
474c8240 5617@end smallexample
c906108c
SS
5618
5619@noindent
5620You can print successive links in the chain by repeating this
5621command---which you can do by just typing @key{RET}.
5622
5623Note that the history records values, not expressions. If the value of
5624@code{x} is 4 and you type these commands:
5625
474c8240 5626@smallexample
c906108c
SS
5627print x
5628set x=5
474c8240 5629@end smallexample
c906108c
SS
5630
5631@noindent
5632then the value recorded in the value history by the @code{print} command
5633remains 4 even though the value of @code{x} has changed.
5634
5635@table @code
5636@kindex show values
5637@item show values
5638Print the last ten values in the value history, with their item numbers.
5639This is like @samp{p@ $$9} repeated ten times, except that @code{show
5640values} does not change the history.
5641
5642@item show values @var{n}
5643Print ten history values centered on history item number @var{n}.
5644
5645@item show values +
5646Print ten history values just after the values last printed. If no more
5647values are available, @code{show values +} produces no display.
5648@end table
5649
5650Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5651same effect as @samp{show values +}.
5652
6d2ebf8b 5653@node Convenience Vars
c906108c
SS
5654@section Convenience variables
5655
5656@cindex convenience variables
5657@value{GDBN} provides @dfn{convenience variables} that you can use within
5658@value{GDBN} to hold on to a value and refer to it later. These variables
5659exist entirely within @value{GDBN}; they are not part of your program, and
5660setting a convenience variable has no direct effect on further execution
5661of your program. That is why you can use them freely.
5662
5663Convenience variables are prefixed with @samp{$}. Any name preceded by
5664@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5665the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5666(Value history references, in contrast, are @emph{numbers} preceded
5667by @samp{$}. @xref{Value History, ,Value history}.)
5668
5669You can save a value in a convenience variable with an assignment
5670expression, just as you would set a variable in your program.
5671For example:
5672
474c8240 5673@smallexample
c906108c 5674set $foo = *object_ptr
474c8240 5675@end smallexample
c906108c
SS
5676
5677@noindent
5678would save in @code{$foo} the value contained in the object pointed to by
5679@code{object_ptr}.
5680
5681Using a convenience variable for the first time creates it, but its
5682value is @code{void} until you assign a new value. You can alter the
5683value with another assignment at any time.
5684
5685Convenience variables have no fixed types. You can assign a convenience
5686variable any type of value, including structures and arrays, even if
5687that variable already has a value of a different type. The convenience
5688variable, when used as an expression, has the type of its current value.
5689
5690@table @code
5691@kindex show convenience
5692@item show convenience
5693Print a list of convenience variables used so far, and their values.
d4f3574e 5694Abbreviated @code{show conv}.
c906108c
SS
5695@end table
5696
5697One of the ways to use a convenience variable is as a counter to be
5698incremented or a pointer to be advanced. For example, to print
5699a field from successive elements of an array of structures:
5700
474c8240 5701@smallexample
c906108c
SS
5702set $i = 0
5703print bar[$i++]->contents
474c8240 5704@end smallexample
c906108c 5705
d4f3574e
SS
5706@noindent
5707Repeat that command by typing @key{RET}.
c906108c
SS
5708
5709Some convenience variables are created automatically by @value{GDBN} and given
5710values likely to be useful.
5711
5712@table @code
41afff9a 5713@vindex $_@r{, convenience variable}
c906108c
SS
5714@item $_
5715The variable @code{$_} is automatically set by the @code{x} command to
5716the last address examined (@pxref{Memory, ,Examining memory}). Other
5717commands which provide a default address for @code{x} to examine also
5718set @code{$_} to that address; these commands include @code{info line}
5719and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5720except when set by the @code{x} command, in which case it is a pointer
5721to the type of @code{$__}.
5722
41afff9a 5723@vindex $__@r{, convenience variable}
c906108c
SS
5724@item $__
5725The variable @code{$__} is automatically set by the @code{x} command
5726to the value found in the last address examined. Its type is chosen
5727to match the format in which the data was printed.
5728
5729@item $_exitcode
41afff9a 5730@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5731The variable @code{$_exitcode} is automatically set to the exit code when
5732the program being debugged terminates.
5733@end table
5734
53a5351d
JM
5735On HP-UX systems, if you refer to a function or variable name that
5736begins with a dollar sign, @value{GDBN} searches for a user or system
5737name first, before it searches for a convenience variable.
c906108c 5738
6d2ebf8b 5739@node Registers
c906108c
SS
5740@section Registers
5741
5742@cindex registers
5743You can refer to machine register contents, in expressions, as variables
5744with names starting with @samp{$}. The names of registers are different
5745for each machine; use @code{info registers} to see the names used on
5746your machine.
5747
5748@table @code
5749@kindex info registers
5750@item info registers
5751Print the names and values of all registers except floating-point
c85508ee 5752and vector registers (in the selected stack frame).
c906108c
SS
5753
5754@kindex info all-registers
5755@cindex floating point registers
5756@item info all-registers
5757Print the names and values of all registers, including floating-point
c85508ee 5758and vector registers (in the selected stack frame).
c906108c
SS
5759
5760@item info registers @var{regname} @dots{}
5761Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5762As discussed in detail below, register values are normally relative to
5763the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5764the machine you are using, with or without the initial @samp{$}.
5765@end table
5766
5767@value{GDBN} has four ``standard'' register names that are available (in
5768expressions) on most machines---whenever they do not conflict with an
5769architecture's canonical mnemonics for registers. The register names
5770@code{$pc} and @code{$sp} are used for the program counter register and
5771the stack pointer. @code{$fp} is used for a register that contains a
5772pointer to the current stack frame, and @code{$ps} is used for a
5773register that contains the processor status. For example,
5774you could print the program counter in hex with
5775
474c8240 5776@smallexample
c906108c 5777p/x $pc
474c8240 5778@end smallexample
c906108c
SS
5779
5780@noindent
5781or print the instruction to be executed next with
5782
474c8240 5783@smallexample
c906108c 5784x/i $pc
474c8240 5785@end smallexample
c906108c
SS
5786
5787@noindent
5788or add four to the stack pointer@footnote{This is a way of removing
5789one word from the stack, on machines where stacks grow downward in
5790memory (most machines, nowadays). This assumes that the innermost
5791stack frame is selected; setting @code{$sp} is not allowed when other
5792stack frames are selected. To pop entire frames off the stack,
5793regardless of machine architecture, use @code{return};
d4f3574e 5794see @ref{Returning, ,Returning from a function}.} with
c906108c 5795
474c8240 5796@smallexample
c906108c 5797set $sp += 4
474c8240 5798@end smallexample
c906108c
SS
5799
5800Whenever possible, these four standard register names are available on
5801your machine even though the machine has different canonical mnemonics,
5802so long as there is no conflict. The @code{info registers} command
5803shows the canonical names. For example, on the SPARC, @code{info
5804registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
5805can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
5806is an alias for the @sc{eflags} register.
c906108c
SS
5807
5808@value{GDBN} always considers the contents of an ordinary register as an
5809integer when the register is examined in this way. Some machines have
5810special registers which can hold nothing but floating point; these
5811registers are considered to have floating point values. There is no way
5812to refer to the contents of an ordinary register as floating point value
5813(although you can @emph{print} it as a floating point value with
5814@samp{print/f $@var{regname}}).
5815
5816Some registers have distinct ``raw'' and ``virtual'' data formats. This
5817means that the data format in which the register contents are saved by
5818the operating system is not the same one that your program normally
5819sees. For example, the registers of the 68881 floating point
5820coprocessor are always saved in ``extended'' (raw) format, but all C
5821programs expect to work with ``double'' (virtual) format. In such
5d161b24 5822cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
5823that makes sense for your program), but the @code{info registers} command
5824prints the data in both formats.
5825
5826Normally, register values are relative to the selected stack frame
5827(@pxref{Selection, ,Selecting a frame}). This means that you get the
5828value that the register would contain if all stack frames farther in
5829were exited and their saved registers restored. In order to see the
5830true contents of hardware registers, you must select the innermost
5831frame (with @samp{frame 0}).
5832
5833However, @value{GDBN} must deduce where registers are saved, from the machine
5834code generated by your compiler. If some registers are not saved, or if
5835@value{GDBN} is unable to locate the saved registers, the selected stack
5836frame makes no difference.
5837
6d2ebf8b 5838@node Floating Point Hardware
c906108c
SS
5839@section Floating point hardware
5840@cindex floating point
5841
5842Depending on the configuration, @value{GDBN} may be able to give
5843you more information about the status of the floating point hardware.
5844
5845@table @code
5846@kindex info float
5847@item info float
5848Display hardware-dependent information about the floating
5849point unit. The exact contents and layout vary depending on the
5850floating point chip. Currently, @samp{info float} is supported on
5851the ARM and x86 machines.
5852@end table
c906108c 5853
e76f1f2e
AC
5854@node Vector Unit
5855@section Vector Unit
5856@cindex vector unit
5857
5858Depending on the configuration, @value{GDBN} may be able to give you
5859more information about the status of the vector unit.
5860
5861@table @code
5862@kindex info vector
5863@item info vector
5864Display information about the vector unit. The exact contents and
5865layout vary depending on the hardware.
5866@end table
5867
29e57380 5868@node Memory Region Attributes
16d9dec6 5869@section Memory region attributes
29e57380
C
5870@cindex memory region attributes
5871
5872@dfn{Memory region attributes} allow you to describe special handling
5873required by regions of your target's memory. @value{GDBN} uses attributes
5874to determine whether to allow certain types of memory accesses; whether to
5875use specific width accesses; and whether to cache target memory.
5876
5877Defined memory regions can be individually enabled and disabled. When a
5878memory region is disabled, @value{GDBN} uses the default attributes when
5879accessing memory in that region. Similarly, if no memory regions have
5880been defined, @value{GDBN} uses the default attributes when accessing
5881all memory.
5882
5883When a memory region is defined, it is given a number to identify it;
5884to enable, disable, or remove a memory region, you specify that number.
5885
5886@table @code
5887@kindex mem
bfac230e
DH
5888@item mem @var{lower} @var{upper} @var{attributes}@dots{}
5889Define memory region bounded by @var{lower} and @var{upper} with
5890attributes @var{attributes}@dots{}. Note that @var{upper} == 0 is a
5891special case: it is treated as the the target's maximum memory address.
5892(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
5893
5894@kindex delete mem
5895@item delete mem @var{nums}@dots{}
59649f2e 5896Remove memory regions @var{nums}@dots{}.
29e57380
C
5897
5898@kindex disable mem
5899@item disable mem @var{nums}@dots{}
59649f2e 5900Disable memory regions @var{nums}@dots{}.
29e57380
C
5901A disabled memory region is not forgotten.
5902It may be enabled again later.
5903
5904@kindex enable mem
5905@item enable mem @var{nums}@dots{}
59649f2e 5906Enable memory regions @var{nums}@dots{}.
29e57380
C
5907
5908@kindex info mem
5909@item info mem
5910Print a table of all defined memory regions, with the following columns
5911for each region.
5912
5913@table @emph
5914@item Memory Region Number
5915@item Enabled or Disabled.
5916Enabled memory regions are marked with @samp{y}.
5917Disabled memory regions are marked with @samp{n}.
5918
5919@item Lo Address
5920The address defining the inclusive lower bound of the memory region.
5921
5922@item Hi Address
5923The address defining the exclusive upper bound of the memory region.
5924
5925@item Attributes
5926The list of attributes set for this memory region.
5927@end table
5928@end table
5929
5930
5931@subsection Attributes
5932
5933@subsubsection Memory Access Mode
5934The access mode attributes set whether @value{GDBN} may make read or
5935write accesses to a memory region.
5936
5937While these attributes prevent @value{GDBN} from performing invalid
5938memory accesses, they do nothing to prevent the target system, I/O DMA,
5939etc. from accessing memory.
5940
5941@table @code
5942@item ro
5943Memory is read only.
5944@item wo
5945Memory is write only.
5946@item rw
6ca652b0 5947Memory is read/write. This is the default.
29e57380
C
5948@end table
5949
5950@subsubsection Memory Access Size
5951The acccess size attributes tells @value{GDBN} to use specific sized
5952accesses in the memory region. Often memory mapped device registers
5953require specific sized accesses. If no access size attribute is
5954specified, @value{GDBN} may use accesses of any size.
5955
5956@table @code
5957@item 8
5958Use 8 bit memory accesses.
5959@item 16
5960Use 16 bit memory accesses.
5961@item 32
5962Use 32 bit memory accesses.
5963@item 64
5964Use 64 bit memory accesses.
5965@end table
5966
5967@c @subsubsection Hardware/Software Breakpoints
5968@c The hardware/software breakpoint attributes set whether @value{GDBN}
5969@c will use hardware or software breakpoints for the internal breakpoints
5970@c used by the step, next, finish, until, etc. commands.
5971@c
5972@c @table @code
5973@c @item hwbreak
5974@c Always use hardware breakpoints
5975@c @item swbreak (default)
5976@c @end table
5977
5978@subsubsection Data Cache
5979The data cache attributes set whether @value{GDBN} will cache target
5980memory. While this generally improves performance by reducing debug
5981protocol overhead, it can lead to incorrect results because @value{GDBN}
5982does not know about volatile variables or memory mapped device
5983registers.
5984
5985@table @code
5986@item cache
5987Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
5988@item nocache
5989Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
5990@end table
5991
5992@c @subsubsection Memory Write Verification
5993@c The memory write verification attributes set whether @value{GDBN}
5994@c will re-reads data after each write to verify the write was successful.
5995@c
5996@c @table @code
5997@c @item verify
5998@c @item noverify (default)
5999@c @end table
6000
16d9dec6
MS
6001@node Dump/Restore Files
6002@section Copy between memory and a file
6003@cindex dump/restore files
6004@cindex append data to a file
6005@cindex dump data to a file
6006@cindex restore data from a file
16d9dec6 6007
df5215a6
JB
6008You can use the commands @code{dump}, @code{append}, and
6009@code{restore} to copy data between target memory and a file. The
6010@code{dump} and @code{append} commands write data to a file, and the
6011@code{restore} command reads data from a file back into the inferior's
6012memory. Files may be in binary, Motorola S-record, Intel hex, or
6013Tektronix Hex format; however, @value{GDBN} can only append to binary
6014files.
6015
6016@table @code
6017
6018@kindex dump
6019@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6020@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6021Dump the contents of memory from @var{start_addr} to @var{end_addr},
6022or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6023
df5215a6 6024The @var{format} parameter may be any one of:
16d9dec6 6025@table @code
df5215a6
JB
6026@item binary
6027Raw binary form.
6028@item ihex
6029Intel hex format.
6030@item srec
6031Motorola S-record format.
6032@item tekhex
6033Tektronix Hex format.
6034@end table
6035
6036@value{GDBN} uses the same definitions of these formats as the
6037@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6038@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6039form.
6040
6041@kindex append
6042@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6043@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6044Append the contents of memory from @var{start_addr} to @var{end_addr},
6045or the value of @var{expr}, to @var{filename}, in raw binary form.
6046(@value{GDBN} can only append data to files in raw binary form.)
6047
6048@kindex restore
6049@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6050Restore the contents of file @var{filename} into memory. The
6051@code{restore} command can automatically recognize any known @sc{bfd}
6052file format, except for raw binary. To restore a raw binary file you
6053must specify the optional keyword @code{binary} after the filename.
16d9dec6
MS
6054
6055If @var{bias} is non-zero, its value will be added to the addresses
6056contained in the file. Binary files always start at address zero, so
6057they will be restored at address @var{bias}. Other bfd files have
6058a built-in location; they will be restored at offset @var{bias}
6059from that location.
6060
6061If @var{start} and/or @var{end} are non-zero, then only data between
6062file offset @var{start} and file offset @var{end} will be restored.
6063These offsets are relative to the addresses in the file, before
6064the @var{bias} argument is applied.
6065
6066@end table
6067
a0eb71c5
KB
6068@node Character Sets
6069@section Character Sets
6070@cindex character sets
6071@cindex charset
6072@cindex translating between character sets
6073@cindex host character set
6074@cindex target character set
6075
6076If the program you are debugging uses a different character set to
6077represent characters and strings than the one @value{GDBN} uses itself,
6078@value{GDBN} can automatically translate between the character sets for
6079you. The character set @value{GDBN} uses we call the @dfn{host
6080character set}; the one the inferior program uses we call the
6081@dfn{target character set}.
6082
6083For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6084uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6085remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6086running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6087then the host character set is Latin-1, and the target character set is
6088@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6089target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6090@sc{ebcdic} and Latin 1 as you print character or string values, or use
6091character and string literals in expressions.
6092
6093@value{GDBN} has no way to automatically recognize which character set
6094the inferior program uses; you must tell it, using the @code{set
6095target-charset} command, described below.
6096
6097Here are the commands for controlling @value{GDBN}'s character set
6098support:
6099
6100@table @code
6101@item set target-charset @var{charset}
6102@kindex set target-charset
6103Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6104character set names @value{GDBN} recognizes below, but if you type
6105@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6106list the target character sets it supports.
a0eb71c5
KB
6107@end table
6108
6109@table @code
6110@item set host-charset @var{charset}
6111@kindex set host-charset
6112Set the current host character set to @var{charset}.
6113
6114By default, @value{GDBN} uses a host character set appropriate to the
6115system it is running on; you can override that default using the
6116@code{set host-charset} command.
6117
6118@value{GDBN} can only use certain character sets as its host character
6119set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6120indicate which can be host character sets, but if you type
6121@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6122list the host character sets it supports.
a0eb71c5
KB
6123
6124@item set charset @var{charset}
6125@kindex set charset
e33d66ec
EZ
6126Set the current host and target character sets to @var{charset}. As
6127above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6128@value{GDBN} will list the name of the character sets that can be used
6129for both host and target.
6130
a0eb71c5
KB
6131
6132@item show charset
a0eb71c5 6133@kindex show charset
e33d66ec
EZ
6134Show the names of the current host and target charsets.
6135
6136@itemx show host-charset
a0eb71c5 6137@kindex show host-charset
e33d66ec
EZ
6138Show the name of the current host charset.
6139
6140@itemx show target-charset
a0eb71c5 6141@kindex show target-charset
e33d66ec 6142Show the name of the current target charset.
a0eb71c5
KB
6143
6144@end table
6145
6146@value{GDBN} currently includes support for the following character
6147sets:
6148
6149@table @code
6150
6151@item ASCII
6152@cindex ASCII character set
6153Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6154character set.
6155
6156@item ISO-8859-1
6157@cindex ISO 8859-1 character set
6158@cindex ISO Latin 1 character set
e33d66ec 6159The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6160characters needed for French, German, and Spanish. @value{GDBN} can use
6161this as its host character set.
6162
6163@item EBCDIC-US
6164@itemx IBM1047
6165@cindex EBCDIC character set
6166@cindex IBM1047 character set
6167Variants of the @sc{ebcdic} character set, used on some of IBM's
6168mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6169@value{GDBN} cannot use these as its host character set.
6170
6171@end table
6172
6173Note that these are all single-byte character sets. More work inside
6174GDB is needed to support multi-byte or variable-width character
6175encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6176
6177Here is an example of @value{GDBN}'s character set support in action.
6178Assume that the following source code has been placed in the file
6179@file{charset-test.c}:
6180
6181@smallexample
6182#include <stdio.h>
6183
6184char ascii_hello[]
6185 = @{72, 101, 108, 108, 111, 44, 32, 119,
6186 111, 114, 108, 100, 33, 10, 0@};
6187char ibm1047_hello[]
6188 = @{200, 133, 147, 147, 150, 107, 64, 166,
6189 150, 153, 147, 132, 90, 37, 0@};
6190
6191main ()
6192@{
6193 printf ("Hello, world!\n");
6194@}
10998722 6195@end smallexample
a0eb71c5
KB
6196
6197In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6198containing the string @samp{Hello, world!} followed by a newline,
6199encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6200
6201We compile the program, and invoke the debugger on it:
6202
6203@smallexample
6204$ gcc -g charset-test.c -o charset-test
6205$ gdb -nw charset-test
6206GNU gdb 2001-12-19-cvs
6207Copyright 2001 Free Software Foundation, Inc.
6208@dots{}
6209(gdb)
10998722 6210@end smallexample
a0eb71c5
KB
6211
6212We can use the @code{show charset} command to see what character sets
6213@value{GDBN} is currently using to interpret and display characters and
6214strings:
6215
6216@smallexample
6217(gdb) show charset
e33d66ec 6218The current host and target character set is `ISO-8859-1'.
a0eb71c5 6219(gdb)
10998722 6220@end smallexample
a0eb71c5
KB
6221
6222For the sake of printing this manual, let's use @sc{ascii} as our
6223initial character set:
6224@smallexample
e33d66ec 6225(gdb) set charset ASCII
a0eb71c5 6226(gdb) show charset
e33d66ec 6227The current host and target character set is `ASCII'.
a0eb71c5 6228(gdb)
10998722 6229@end smallexample
a0eb71c5
KB
6230
6231Let's assume that @sc{ascii} is indeed the correct character set for our
6232host system --- in other words, let's assume that if @value{GDBN} prints
6233characters using the @sc{ascii} character set, our terminal will display
6234them properly. Since our current target character set is also
6235@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6236
6237@smallexample
6238(gdb) print ascii_hello
6239$1 = 0x401698 "Hello, world!\n"
6240(gdb) print ascii_hello[0]
6241$2 = 72 'H'
6242(gdb)
10998722 6243@end smallexample
a0eb71c5
KB
6244
6245@value{GDBN} uses the target character set for character and string
6246literals you use in expressions:
6247
6248@smallexample
6249(gdb) print '+'
6250$3 = 43 '+'
6251(gdb)
10998722 6252@end smallexample
a0eb71c5
KB
6253
6254The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6255character.
6256
6257@value{GDBN} relies on the user to tell it which character set the
6258target program uses. If we print @code{ibm1047_hello} while our target
6259character set is still @sc{ascii}, we get jibberish:
6260
6261@smallexample
6262(gdb) print ibm1047_hello
6263$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
6264(gdb) print ibm1047_hello[0]
6265$5 = 200 '\310'
6266(gdb)
10998722 6267@end smallexample
a0eb71c5 6268
e33d66ec 6269If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6270@value{GDBN} tells us the character sets it supports:
6271
6272@smallexample
6273(gdb) set target-charset
e33d66ec
EZ
6274ASCII EBCDIC-US IBM1047 ISO-8859-1
6275(gdb) set target-charset
10998722 6276@end smallexample
a0eb71c5
KB
6277
6278We can select @sc{ibm1047} as our target character set, and examine the
6279program's strings again. Now the @sc{ascii} string is wrong, but
6280@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6281target character set, @sc{ibm1047}, to the host character set,
6282@sc{ascii}, and they display correctly:
6283
6284@smallexample
e33d66ec 6285(gdb) set target-charset IBM1047
a0eb71c5 6286(gdb) show charset
e33d66ec
EZ
6287The current host character set is `ASCII'.
6288The current target character set is `IBM1047'.
a0eb71c5
KB
6289(gdb) print ascii_hello
6290$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
6291(gdb) print ascii_hello[0]
6292$7 = 72 '\110'
6293(gdb) print ibm1047_hello
6294$8 = 0x4016a8 "Hello, world!\n"
6295(gdb) print ibm1047_hello[0]
6296$9 = 200 'H'
6297(gdb)
10998722 6298@end smallexample
a0eb71c5
KB
6299
6300As above, @value{GDBN} uses the target character set for character and
6301string literals you use in expressions:
6302
6303@smallexample
6304(gdb) print '+'
6305$10 = 78 '+'
6306(gdb)
10998722 6307@end smallexample
a0eb71c5 6308
e33d66ec 6309The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6310character.
6311
6312
e2e0bcd1
JB
6313@node Macros
6314@chapter C Preprocessor Macros
6315
6316Some languages, such as C and C++, provide a way to define and invoke
6317``preprocessor macros'' which expand into strings of tokens.
6318@value{GDBN} can evaluate expressions containing macro invocations, show
6319the result of macro expansion, and show a macro's definition, including
6320where it was defined.
6321
6322You may need to compile your program specially to provide @value{GDBN}
6323with information about preprocessor macros. Most compilers do not
6324include macros in their debugging information, even when you compile
6325with the @option{-g} flag. @xref{Compilation}.
6326
6327A program may define a macro at one point, remove that definition later,
6328and then provide a different definition after that. Thus, at different
6329points in the program, a macro may have different definitions, or have
6330no definition at all. If there is a current stack frame, @value{GDBN}
6331uses the macros in scope at that frame's source code line. Otherwise,
6332@value{GDBN} uses the macros in scope at the current listing location;
6333see @ref{List}.
6334
6335At the moment, @value{GDBN} does not support the @code{##}
6336token-splicing operator, the @code{#} stringification operator, or
6337variable-arity macros.
6338
6339Whenever @value{GDBN} evaluates an expression, it always expands any
6340macro invocations present in the expression. @value{GDBN} also provides
6341the following commands for working with macros explicitly.
6342
6343@table @code
6344
6345@kindex macro expand
6346@cindex macro expansion, showing the results of preprocessor
6347@cindex preprocessor macro expansion, showing the results of
6348@cindex expanding preprocessor macros
6349@item macro expand @var{expression}
6350@itemx macro exp @var{expression}
6351Show the results of expanding all preprocessor macro invocations in
6352@var{expression}. Since @value{GDBN} simply expands macros, but does
6353not parse the result, @var{expression} need not be a valid expression;
6354it can be any string of tokens.
6355
6356@kindex macro expand-once
6357@item macro expand-once @var{expression}
6358@itemx macro exp1 @var{expression}
6359@i{(This command is not yet implemented.)} Show the results of
6360expanding those preprocessor macro invocations that appear explicitly in
6361@var{expression}. Macro invocations appearing in that expansion are
6362left unchanged. This command allows you to see the effect of a
6363particular macro more clearly, without being confused by further
6364expansions. Since @value{GDBN} simply expands macros, but does not
6365parse the result, @var{expression} need not be a valid expression; it
6366can be any string of tokens.
6367
475b0867 6368@kindex info macro
e2e0bcd1
JB
6369@cindex macro definition, showing
6370@cindex definition, showing a macro's
475b0867 6371@item info macro @var{macro}
e2e0bcd1
JB
6372Show the definition of the macro named @var{macro}, and describe the
6373source location where that definition was established.
6374
6375@kindex macro define
6376@cindex user-defined macros
6377@cindex defining macros interactively
6378@cindex macros, user-defined
6379@item macro define @var{macro} @var{replacement-list}
6380@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6381@i{(This command is not yet implemented.)} Introduce a definition for a
6382preprocessor macro named @var{macro}, invocations of which are replaced
6383by the tokens given in @var{replacement-list}. The first form of this
6384command defines an ``object-like'' macro, which takes no arguments; the
6385second form defines a ``function-like'' macro, which takes the arguments
6386given in @var{arglist}.
6387
6388A definition introduced by this command is in scope in every expression
6389evaluated in @value{GDBN}, until it is removed with the @command{macro
6390undef} command, described below. The definition overrides all
6391definitions for @var{macro} present in the program being debugged, as
6392well as any previous user-supplied definition.
6393
6394@kindex macro undef
6395@item macro undef @var{macro}
6396@i{(This command is not yet implemented.)} Remove any user-supplied
6397definition for the macro named @var{macro}. This command only affects
6398definitions provided with the @command{macro define} command, described
6399above; it cannot remove definitions present in the program being
6400debugged.
6401
6402@end table
6403
6404@cindex macros, example of debugging with
6405Here is a transcript showing the above commands in action. First, we
6406show our source files:
6407
6408@smallexample
6409$ cat sample.c
6410#include <stdio.h>
6411#include "sample.h"
6412
6413#define M 42
6414#define ADD(x) (M + x)
6415
6416main ()
6417@{
6418#define N 28
6419 printf ("Hello, world!\n");
6420#undef N
6421 printf ("We're so creative.\n");
6422#define N 1729
6423 printf ("Goodbye, world!\n");
6424@}
6425$ cat sample.h
6426#define Q <
6427$
6428@end smallexample
6429
6430Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6431We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6432compiler includes information about preprocessor macros in the debugging
6433information.
6434
6435@smallexample
6436$ gcc -gdwarf-2 -g3 sample.c -o sample
6437$
6438@end smallexample
6439
6440Now, we start @value{GDBN} on our sample program:
6441
6442@smallexample
6443$ gdb -nw sample
6444GNU gdb 2002-05-06-cvs
6445Copyright 2002 Free Software Foundation, Inc.
6446GDB is free software, @dots{}
6447(gdb)
6448@end smallexample
6449
6450We can expand macros and examine their definitions, even when the
6451program is not running. @value{GDBN} uses the current listing position
6452to decide which macro definitions are in scope:
6453
6454@smallexample
6455(gdb) list main
64563
64574 #define M 42
64585 #define ADD(x) (M + x)
64596
64607 main ()
64618 @{
64629 #define N 28
646310 printf ("Hello, world!\n");
646411 #undef N
646512 printf ("We're so creative.\n");
475b0867 6466(gdb) info macro ADD
e2e0bcd1
JB
6467Defined at /home/jimb/gdb/macros/play/sample.c:5
6468#define ADD(x) (M + x)
475b0867 6469(gdb) info macro Q
e2e0bcd1
JB
6470Defined at /home/jimb/gdb/macros/play/sample.h:1
6471 included at /home/jimb/gdb/macros/play/sample.c:2
6472#define Q <
6473(gdb) macro expand ADD(1)
6474expands to: (42 + 1)
6475(gdb) macro expand-once ADD(1)
6476expands to: once (M + 1)
6477(gdb)
6478@end smallexample
6479
6480In the example above, note that @command{macro expand-once} expands only
6481the macro invocation explicit in the original text --- the invocation of
6482@code{ADD} --- but does not expand the invocation of the macro @code{M},
6483which was introduced by @code{ADD}.
6484
6485Once the program is running, GDB uses the macro definitions in force at
6486the source line of the current stack frame:
6487
6488@smallexample
6489(gdb) break main
6490Breakpoint 1 at 0x8048370: file sample.c, line 10.
6491(gdb) run
6492Starting program: /home/jimb/gdb/macros/play/sample
6493
6494Breakpoint 1, main () at sample.c:10
649510 printf ("Hello, world!\n");
6496(gdb)
6497@end smallexample
6498
6499At line 10, the definition of the macro @code{N} at line 9 is in force:
6500
6501@smallexample
475b0867 6502(gdb) info macro N
e2e0bcd1
JB
6503Defined at /home/jimb/gdb/macros/play/sample.c:9
6504#define N 28
6505(gdb) macro expand N Q M
6506expands to: 28 < 42
6507(gdb) print N Q M
6508$1 = 1
6509(gdb)
6510@end smallexample
6511
6512As we step over directives that remove @code{N}'s definition, and then
6513give it a new definition, @value{GDBN} finds the definition (or lack
6514thereof) in force at each point:
6515
6516@smallexample
6517(gdb) next
6518Hello, world!
651912 printf ("We're so creative.\n");
475b0867 6520(gdb) info macro N
e2e0bcd1
JB
6521The symbol `N' has no definition as a C/C++ preprocessor macro
6522at /home/jimb/gdb/macros/play/sample.c:12
6523(gdb) next
6524We're so creative.
652514 printf ("Goodbye, world!\n");
475b0867 6526(gdb) info macro N
e2e0bcd1
JB
6527Defined at /home/jimb/gdb/macros/play/sample.c:13
6528#define N 1729
6529(gdb) macro expand N Q M
6530expands to: 1729 < 42
6531(gdb) print N Q M
6532$2 = 0
6533(gdb)
6534@end smallexample
6535
6536
b37052ae
EZ
6537@node Tracepoints
6538@chapter Tracepoints
6539@c This chapter is based on the documentation written by Michael
6540@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6541
6542@cindex tracepoints
6543In some applications, it is not feasible for the debugger to interrupt
6544the program's execution long enough for the developer to learn
6545anything helpful about its behavior. If the program's correctness
6546depends on its real-time behavior, delays introduced by a debugger
6547might cause the program to change its behavior drastically, or perhaps
6548fail, even when the code itself is correct. It is useful to be able
6549to observe the program's behavior without interrupting it.
6550
6551Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6552specify locations in the program, called @dfn{tracepoints}, and
6553arbitrary expressions to evaluate when those tracepoints are reached.
6554Later, using the @code{tfind} command, you can examine the values
6555those expressions had when the program hit the tracepoints. The
6556expressions may also denote objects in memory---structures or arrays,
6557for example---whose values @value{GDBN} should record; while visiting
6558a particular tracepoint, you may inspect those objects as if they were
6559in memory at that moment. However, because @value{GDBN} records these
6560values without interacting with you, it can do so quickly and
6561unobtrusively, hopefully not disturbing the program's behavior.
6562
6563The tracepoint facility is currently available only for remote
2c0069bb
EZ
6564targets. @xref{Targets}. In addition, your remote target must know how
6565to collect trace data. This functionality is implemented in the remote
6566stub; however, none of the stubs distributed with @value{GDBN} support
6567tracepoints as of this writing.
b37052ae
EZ
6568
6569This chapter describes the tracepoint commands and features.
6570
6571@menu
6572* Set Tracepoints::
6573* Analyze Collected Data::
6574* Tracepoint Variables::
6575@end menu
6576
6577@node Set Tracepoints
6578@section Commands to Set Tracepoints
6579
6580Before running such a @dfn{trace experiment}, an arbitrary number of
6581tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6582tracepoint has a number assigned to it by @value{GDBN}. Like with
6583breakpoints, tracepoint numbers are successive integers starting from
6584one. Many of the commands associated with tracepoints take the
6585tracepoint number as their argument, to identify which tracepoint to
6586work on.
6587
6588For each tracepoint, you can specify, in advance, some arbitrary set
6589of data that you want the target to collect in the trace buffer when
6590it hits that tracepoint. The collected data can include registers,
6591local variables, or global data. Later, you can use @value{GDBN}
6592commands to examine the values these data had at the time the
6593tracepoint was hit.
6594
6595This section describes commands to set tracepoints and associated
6596conditions and actions.
6597
6598@menu
6599* Create and Delete Tracepoints::
6600* Enable and Disable Tracepoints::
6601* Tracepoint Passcounts::
6602* Tracepoint Actions::
6603* Listing Tracepoints::
6604* Starting and Stopping Trace Experiment::
6605@end menu
6606
6607@node Create and Delete Tracepoints
6608@subsection Create and Delete Tracepoints
6609
6610@table @code
6611@cindex set tracepoint
6612@kindex trace
6613@item trace
6614The @code{trace} command is very similar to the @code{break} command.
6615Its argument can be a source line, a function name, or an address in
6616the target program. @xref{Set Breaks}. The @code{trace} command
6617defines a tracepoint, which is a point in the target program where the
6618debugger will briefly stop, collect some data, and then allow the
6619program to continue. Setting a tracepoint or changing its commands
6620doesn't take effect until the next @code{tstart} command; thus, you
6621cannot change the tracepoint attributes once a trace experiment is
6622running.
6623
6624Here are some examples of using the @code{trace} command:
6625
6626@smallexample
6627(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6628
6629(@value{GDBP}) @b{trace +2} // 2 lines forward
6630
6631(@value{GDBP}) @b{trace my_function} // first source line of function
6632
6633(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6634
6635(@value{GDBP}) @b{trace *0x2117c4} // an address
6636@end smallexample
6637
6638@noindent
6639You can abbreviate @code{trace} as @code{tr}.
6640
6641@vindex $tpnum
6642@cindex last tracepoint number
6643@cindex recent tracepoint number
6644@cindex tracepoint number
6645The convenience variable @code{$tpnum} records the tracepoint number
6646of the most recently set tracepoint.
6647
6648@kindex delete tracepoint
6649@cindex tracepoint deletion
6650@item delete tracepoint @r{[}@var{num}@r{]}
6651Permanently delete one or more tracepoints. With no argument, the
6652default is to delete all tracepoints.
6653
6654Examples:
6655
6656@smallexample
6657(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
6658
6659(@value{GDBP}) @b{delete trace} // remove all tracepoints
6660@end smallexample
6661
6662@noindent
6663You can abbreviate this command as @code{del tr}.
6664@end table
6665
6666@node Enable and Disable Tracepoints
6667@subsection Enable and Disable Tracepoints
6668
6669@table @code
6670@kindex disable tracepoint
6671@item disable tracepoint @r{[}@var{num}@r{]}
6672Disable tracepoint @var{num}, or all tracepoints if no argument
6673@var{num} is given. A disabled tracepoint will have no effect during
6674the next trace experiment, but it is not forgotten. You can re-enable
6675a disabled tracepoint using the @code{enable tracepoint} command.
6676
6677@kindex enable tracepoint
6678@item enable tracepoint @r{[}@var{num}@r{]}
6679Enable tracepoint @var{num}, or all tracepoints. The enabled
6680tracepoints will become effective the next time a trace experiment is
6681run.
6682@end table
6683
6684@node Tracepoint Passcounts
6685@subsection Tracepoint Passcounts
6686
6687@table @code
6688@kindex passcount
6689@cindex tracepoint pass count
6690@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
6691Set the @dfn{passcount} of a tracepoint. The passcount is a way to
6692automatically stop a trace experiment. If a tracepoint's passcount is
6693@var{n}, then the trace experiment will be automatically stopped on
6694the @var{n}'th time that tracepoint is hit. If the tracepoint number
6695@var{num} is not specified, the @code{passcount} command sets the
6696passcount of the most recently defined tracepoint. If no passcount is
6697given, the trace experiment will run until stopped explicitly by the
6698user.
6699
6700Examples:
6701
6702@smallexample
6826cf00
EZ
6703(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6704@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
6705
6706(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 6707@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
6708(@value{GDBP}) @b{trace foo}
6709(@value{GDBP}) @b{pass 3}
6710(@value{GDBP}) @b{trace bar}
6711(@value{GDBP}) @b{pass 2}
6712(@value{GDBP}) @b{trace baz}
6713(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
6714@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
6715@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
6716@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
6717@end smallexample
6718@end table
6719
6720@node Tracepoint Actions
6721@subsection Tracepoint Action Lists
6722
6723@table @code
6724@kindex actions
6725@cindex tracepoint actions
6726@item actions @r{[}@var{num}@r{]}
6727This command will prompt for a list of actions to be taken when the
6728tracepoint is hit. If the tracepoint number @var{num} is not
6729specified, this command sets the actions for the one that was most
6730recently defined (so that you can define a tracepoint and then say
6731@code{actions} without bothering about its number). You specify the
6732actions themselves on the following lines, one action at a time, and
6733terminate the actions list with a line containing just @code{end}. So
6734far, the only defined actions are @code{collect} and
6735@code{while-stepping}.
6736
6737@cindex remove actions from a tracepoint
6738To remove all actions from a tracepoint, type @samp{actions @var{num}}
6739and follow it immediately with @samp{end}.
6740
6741@smallexample
6742(@value{GDBP}) @b{collect @var{data}} // collect some data
6743
6826cf00 6744(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 6745
6826cf00 6746(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
6747@end smallexample
6748
6749In the following example, the action list begins with @code{collect}
6750commands indicating the things to be collected when the tracepoint is
6751hit. Then, in order to single-step and collect additional data
6752following the tracepoint, a @code{while-stepping} command is used,
6753followed by the list of things to be collected while stepping. The
6754@code{while-stepping} command is terminated by its own separate
6755@code{end} command. Lastly, the action list is terminated by an
6756@code{end} command.
6757
6758@smallexample
6759(@value{GDBP}) @b{trace foo}
6760(@value{GDBP}) @b{actions}
6761Enter actions for tracepoint 1, one per line:
6762> collect bar,baz
6763> collect $regs
6764> while-stepping 12
6765 > collect $fp, $sp
6766 > end
6767end
6768@end smallexample
6769
6770@kindex collect @r{(tracepoints)}
6771@item collect @var{expr1}, @var{expr2}, @dots{}
6772Collect values of the given expressions when the tracepoint is hit.
6773This command accepts a comma-separated list of any valid expressions.
6774In addition to global, static, or local variables, the following
6775special arguments are supported:
6776
6777@table @code
6778@item $regs
6779collect all registers
6780
6781@item $args
6782collect all function arguments
6783
6784@item $locals
6785collect all local variables.
6786@end table
6787
6788You can give several consecutive @code{collect} commands, each one
6789with a single argument, or one @code{collect} command with several
6790arguments separated by commas: the effect is the same.
6791
f5c37c66
EZ
6792The command @code{info scope} (@pxref{Symbols, info scope}) is
6793particularly useful for figuring out what data to collect.
6794
b37052ae
EZ
6795@kindex while-stepping @r{(tracepoints)}
6796@item while-stepping @var{n}
6797Perform @var{n} single-step traces after the tracepoint, collecting
6798new data at each step. The @code{while-stepping} command is
6799followed by the list of what to collect while stepping (followed by
6800its own @code{end} command):
6801
6802@smallexample
6803> while-stepping 12
6804 > collect $regs, myglobal
6805 > end
6806>
6807@end smallexample
6808
6809@noindent
6810You may abbreviate @code{while-stepping} as @code{ws} or
6811@code{stepping}.
6812@end table
6813
6814@node Listing Tracepoints
6815@subsection Listing Tracepoints
6816
6817@table @code
6818@kindex info tracepoints
6819@cindex information about tracepoints
6820@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 6821Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 6822a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
6823defined so far. For each tracepoint, the following information is
6824shown:
6825
6826@itemize @bullet
6827@item
6828its number
6829@item
6830whether it is enabled or disabled
6831@item
6832its address
6833@item
6834its passcount as given by the @code{passcount @var{n}} command
6835@item
6836its step count as given by the @code{while-stepping @var{n}} command
6837@item
6838where in the source files is the tracepoint set
6839@item
6840its action list as given by the @code{actions} command
6841@end itemize
6842
6843@smallexample
6844(@value{GDBP}) @b{info trace}
6845Num Enb Address PassC StepC What
68461 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
68472 y 0x0020dc64 0 0 in g_test at g_test.c:1375
68483 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
6849(@value{GDBP})
6850@end smallexample
6851
6852@noindent
6853This command can be abbreviated @code{info tp}.
6854@end table
6855
6856@node Starting and Stopping Trace Experiment
6857@subsection Starting and Stopping Trace Experiment
6858
6859@table @code
6860@kindex tstart
6861@cindex start a new trace experiment
6862@cindex collected data discarded
6863@item tstart
6864This command takes no arguments. It starts the trace experiment, and
6865begins collecting data. This has the side effect of discarding all
6866the data collected in the trace buffer during the previous trace
6867experiment.
6868
6869@kindex tstop
6870@cindex stop a running trace experiment
6871@item tstop
6872This command takes no arguments. It ends the trace experiment, and
6873stops collecting data.
6874
6875@strong{Note:} a trace experiment and data collection may stop
6876automatically if any tracepoint's passcount is reached
6877(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
6878
6879@kindex tstatus
6880@cindex status of trace data collection
6881@cindex trace experiment, status of
6882@item tstatus
6883This command displays the status of the current trace data
6884collection.
6885@end table
6886
6887Here is an example of the commands we described so far:
6888
6889@smallexample
6890(@value{GDBP}) @b{trace gdb_c_test}
6891(@value{GDBP}) @b{actions}
6892Enter actions for tracepoint #1, one per line.
6893> collect $regs,$locals,$args
6894> while-stepping 11
6895 > collect $regs
6896 > end
6897> end
6898(@value{GDBP}) @b{tstart}
6899 [time passes @dots{}]
6900(@value{GDBP}) @b{tstop}
6901@end smallexample
6902
6903
6904@node Analyze Collected Data
6905@section Using the collected data
6906
6907After the tracepoint experiment ends, you use @value{GDBN} commands
6908for examining the trace data. The basic idea is that each tracepoint
6909collects a trace @dfn{snapshot} every time it is hit and another
6910snapshot every time it single-steps. All these snapshots are
6911consecutively numbered from zero and go into a buffer, and you can
6912examine them later. The way you examine them is to @dfn{focus} on a
6913specific trace snapshot. When the remote stub is focused on a trace
6914snapshot, it will respond to all @value{GDBN} requests for memory and
6915registers by reading from the buffer which belongs to that snapshot,
6916rather than from @emph{real} memory or registers of the program being
6917debugged. This means that @strong{all} @value{GDBN} commands
6918(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
6919behave as if we were currently debugging the program state as it was
6920when the tracepoint occurred. Any requests for data that are not in
6921the buffer will fail.
6922
6923@menu
6924* tfind:: How to select a trace snapshot
6925* tdump:: How to display all data for a snapshot
6926* save-tracepoints:: How to save tracepoints for a future run
6927@end menu
6928
6929@node tfind
6930@subsection @code{tfind @var{n}}
6931
6932@kindex tfind
6933@cindex select trace snapshot
6934@cindex find trace snapshot
6935The basic command for selecting a trace snapshot from the buffer is
6936@code{tfind @var{n}}, which finds trace snapshot number @var{n},
6937counting from zero. If no argument @var{n} is given, the next
6938snapshot is selected.
6939
6940Here are the various forms of using the @code{tfind} command.
6941
6942@table @code
6943@item tfind start
6944Find the first snapshot in the buffer. This is a synonym for
6945@code{tfind 0} (since 0 is the number of the first snapshot).
6946
6947@item tfind none
6948Stop debugging trace snapshots, resume @emph{live} debugging.
6949
6950@item tfind end
6951Same as @samp{tfind none}.
6952
6953@item tfind
6954No argument means find the next trace snapshot.
6955
6956@item tfind -
6957Find the previous trace snapshot before the current one. This permits
6958retracing earlier steps.
6959
6960@item tfind tracepoint @var{num}
6961Find the next snapshot associated with tracepoint @var{num}. Search
6962proceeds forward from the last examined trace snapshot. If no
6963argument @var{num} is given, it means find the next snapshot collected
6964for the same tracepoint as the current snapshot.
6965
6966@item tfind pc @var{addr}
6967Find the next snapshot associated with the value @var{addr} of the
6968program counter. Search proceeds forward from the last examined trace
6969snapshot. If no argument @var{addr} is given, it means find the next
6970snapshot with the same value of PC as the current snapshot.
6971
6972@item tfind outside @var{addr1}, @var{addr2}
6973Find the next snapshot whose PC is outside the given range of
6974addresses.
6975
6976@item tfind range @var{addr1}, @var{addr2}
6977Find the next snapshot whose PC is between @var{addr1} and
6978@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
6979
6980@item tfind line @r{[}@var{file}:@r{]}@var{n}
6981Find the next snapshot associated with the source line @var{n}. If
6982the optional argument @var{file} is given, refer to line @var{n} in
6983that source file. Search proceeds forward from the last examined
6984trace snapshot. If no argument @var{n} is given, it means find the
6985next line other than the one currently being examined; thus saying
6986@code{tfind line} repeatedly can appear to have the same effect as
6987stepping from line to line in a @emph{live} debugging session.
6988@end table
6989
6990The default arguments for the @code{tfind} commands are specifically
6991designed to make it easy to scan through the trace buffer. For
6992instance, @code{tfind} with no argument selects the next trace
6993snapshot, and @code{tfind -} with no argument selects the previous
6994trace snapshot. So, by giving one @code{tfind} command, and then
6995simply hitting @key{RET} repeatedly you can examine all the trace
6996snapshots in order. Or, by saying @code{tfind -} and then hitting
6997@key{RET} repeatedly you can examine the snapshots in reverse order.
6998The @code{tfind line} command with no argument selects the snapshot
6999for the next source line executed. The @code{tfind pc} command with
7000no argument selects the next snapshot with the same program counter
7001(PC) as the current frame. The @code{tfind tracepoint} command with
7002no argument selects the next trace snapshot collected by the same
7003tracepoint as the current one.
7004
7005In addition to letting you scan through the trace buffer manually,
7006these commands make it easy to construct @value{GDBN} scripts that
7007scan through the trace buffer and print out whatever collected data
7008you are interested in. Thus, if we want to examine the PC, FP, and SP
7009registers from each trace frame in the buffer, we can say this:
7010
7011@smallexample
7012(@value{GDBP}) @b{tfind start}
7013(@value{GDBP}) @b{while ($trace_frame != -1)}
7014> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7015 $trace_frame, $pc, $sp, $fp
7016> tfind
7017> end
7018
7019Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7020Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7021Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7022Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7023Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7024Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7025Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7026Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7027Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7028Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7029Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7030@end smallexample
7031
7032Or, if we want to examine the variable @code{X} at each source line in
7033the buffer:
7034
7035@smallexample
7036(@value{GDBP}) @b{tfind start}
7037(@value{GDBP}) @b{while ($trace_frame != -1)}
7038> printf "Frame %d, X == %d\n", $trace_frame, X
7039> tfind line
7040> end
7041
7042Frame 0, X = 1
7043Frame 7, X = 2
7044Frame 13, X = 255
7045@end smallexample
7046
7047@node tdump
7048@subsection @code{tdump}
7049@kindex tdump
7050@cindex dump all data collected at tracepoint
7051@cindex tracepoint data, display
7052
7053This command takes no arguments. It prints all the data collected at
7054the current trace snapshot.
7055
7056@smallexample
7057(@value{GDBP}) @b{trace 444}
7058(@value{GDBP}) @b{actions}
7059Enter actions for tracepoint #2, one per line:
7060> collect $regs, $locals, $args, gdb_long_test
7061> end
7062
7063(@value{GDBP}) @b{tstart}
7064
7065(@value{GDBP}) @b{tfind line 444}
7066#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7067at gdb_test.c:444
7068444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7069
7070(@value{GDBP}) @b{tdump}
7071Data collected at tracepoint 2, trace frame 1:
7072d0 0xc4aa0085 -995491707
7073d1 0x18 24
7074d2 0x80 128
7075d3 0x33 51
7076d4 0x71aea3d 119204413
7077d5 0x22 34
7078d6 0xe0 224
7079d7 0x380035 3670069
7080a0 0x19e24a 1696330
7081a1 0x3000668 50333288
7082a2 0x100 256
7083a3 0x322000 3284992
7084a4 0x3000698 50333336
7085a5 0x1ad3cc 1758156
7086fp 0x30bf3c 0x30bf3c
7087sp 0x30bf34 0x30bf34
7088ps 0x0 0
7089pc 0x20b2c8 0x20b2c8
7090fpcontrol 0x0 0
7091fpstatus 0x0 0
7092fpiaddr 0x0 0
7093p = 0x20e5b4 "gdb-test"
7094p1 = (void *) 0x11
7095p2 = (void *) 0x22
7096p3 = (void *) 0x33
7097p4 = (void *) 0x44
7098p5 = (void *) 0x55
7099p6 = (void *) 0x66
7100gdb_long_test = 17 '\021'
7101
7102(@value{GDBP})
7103@end smallexample
7104
7105@node save-tracepoints
7106@subsection @code{save-tracepoints @var{filename}}
7107@kindex save-tracepoints
7108@cindex save tracepoints for future sessions
7109
7110This command saves all current tracepoint definitions together with
7111their actions and passcounts, into a file @file{@var{filename}}
7112suitable for use in a later debugging session. To read the saved
7113tracepoint definitions, use the @code{source} command (@pxref{Command
7114Files}).
7115
7116@node Tracepoint Variables
7117@section Convenience Variables for Tracepoints
7118@cindex tracepoint variables
7119@cindex convenience variables for tracepoints
7120
7121@table @code
7122@vindex $trace_frame
7123@item (int) $trace_frame
7124The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7125snapshot is selected.
7126
7127@vindex $tracepoint
7128@item (int) $tracepoint
7129The tracepoint for the current trace snapshot.
7130
7131@vindex $trace_line
7132@item (int) $trace_line
7133The line number for the current trace snapshot.
7134
7135@vindex $trace_file
7136@item (char []) $trace_file
7137The source file for the current trace snapshot.
7138
7139@vindex $trace_func
7140@item (char []) $trace_func
7141The name of the function containing @code{$tracepoint}.
7142@end table
7143
7144Note: @code{$trace_file} is not suitable for use in @code{printf},
7145use @code{output} instead.
7146
7147Here's a simple example of using these convenience variables for
7148stepping through all the trace snapshots and printing some of their
7149data.
7150
7151@smallexample
7152(@value{GDBP}) @b{tfind start}
7153
7154(@value{GDBP}) @b{while $trace_frame != -1}
7155> output $trace_file
7156> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7157> tfind
7158> end
7159@end smallexample
7160
df0cd8c5
JB
7161@node Overlays
7162@chapter Debugging Programs That Use Overlays
7163@cindex overlays
7164
7165If your program is too large to fit completely in your target system's
7166memory, you can sometimes use @dfn{overlays} to work around this
7167problem. @value{GDBN} provides some support for debugging programs that
7168use overlays.
7169
7170@menu
7171* How Overlays Work:: A general explanation of overlays.
7172* Overlay Commands:: Managing overlays in @value{GDBN}.
7173* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7174 mapped by asking the inferior.
7175* Overlay Sample Program:: A sample program using overlays.
7176@end menu
7177
7178@node How Overlays Work
7179@section How Overlays Work
7180@cindex mapped overlays
7181@cindex unmapped overlays
7182@cindex load address, overlay's
7183@cindex mapped address
7184@cindex overlay area
7185
7186Suppose you have a computer whose instruction address space is only 64
7187kilobytes long, but which has much more memory which can be accessed by
7188other means: special instructions, segment registers, or memory
7189management hardware, for example. Suppose further that you want to
7190adapt a program which is larger than 64 kilobytes to run on this system.
7191
7192One solution is to identify modules of your program which are relatively
7193independent, and need not call each other directly; call these modules
7194@dfn{overlays}. Separate the overlays from the main program, and place
7195their machine code in the larger memory. Place your main program in
7196instruction memory, but leave at least enough space there to hold the
7197largest overlay as well.
7198
7199Now, to call a function located in an overlay, you must first copy that
7200overlay's machine code from the large memory into the space set aside
7201for it in the instruction memory, and then jump to its entry point
7202there.
7203
c928edc0
AC
7204@c NB: In the below the mapped area's size is greater or equal to the
7205@c size of all overlays. This is intentional to remind the developer
7206@c that overlays don't necessarily need to be the same size.
7207
474c8240 7208@smallexample
df0cd8c5 7209@group
c928edc0
AC
7210 Data Instruction Larger
7211Address Space Address Space Address Space
7212+-----------+ +-----------+ +-----------+
7213| | | | | |
7214+-----------+ +-----------+ +-----------+<-- overlay 1
7215| program | | main | .----| overlay 1 | load address
7216| variables | | program | | +-----------+
7217| and heap | | | | | |
7218+-----------+ | | | +-----------+<-- overlay 2
7219| | +-----------+ | | | load address
7220+-----------+ | | | .-| overlay 2 |
7221 | | | | | |
7222 mapped --->+-----------+ | | +-----------+
7223 address | | | | | |
7224 | overlay | <-' | | |
7225 | area | <---' +-----------+<-- overlay 3
7226 | | <---. | | load address
7227 +-----------+ `--| overlay 3 |
7228 | | | |
7229 +-----------+ | |
7230 +-----------+
7231 | |
7232 +-----------+
7233
7234 @anchor{A code overlay}A code overlay
df0cd8c5 7235@end group
474c8240 7236@end smallexample
df0cd8c5 7237
c928edc0
AC
7238The diagram (@pxref{A code overlay}) shows a system with separate data
7239and instruction address spaces. To map an overlay, the program copies
7240its code from the larger address space to the instruction address space.
7241Since the overlays shown here all use the same mapped address, only one
7242may be mapped at a time. For a system with a single address space for
7243data and instructions, the diagram would be similar, except that the
7244program variables and heap would share an address space with the main
7245program and the overlay area.
df0cd8c5
JB
7246
7247An overlay loaded into instruction memory and ready for use is called a
7248@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7249instruction memory. An overlay not present (or only partially present)
7250in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7251is its address in the larger memory. The mapped address is also called
7252the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7253called the @dfn{load memory address}, or @dfn{LMA}.
7254
7255Unfortunately, overlays are not a completely transparent way to adapt a
7256program to limited instruction memory. They introduce a new set of
7257global constraints you must keep in mind as you design your program:
7258
7259@itemize @bullet
7260
7261@item
7262Before calling or returning to a function in an overlay, your program
7263must make sure that overlay is actually mapped. Otherwise, the call or
7264return will transfer control to the right address, but in the wrong
7265overlay, and your program will probably crash.
7266
7267@item
7268If the process of mapping an overlay is expensive on your system, you
7269will need to choose your overlays carefully to minimize their effect on
7270your program's performance.
7271
7272@item
7273The executable file you load onto your system must contain each
7274overlay's instructions, appearing at the overlay's load address, not its
7275mapped address. However, each overlay's instructions must be relocated
7276and its symbols defined as if the overlay were at its mapped address.
7277You can use GNU linker scripts to specify different load and relocation
7278addresses for pieces of your program; see @ref{Overlay Description,,,
7279ld.info, Using ld: the GNU linker}.
7280
7281@item
7282The procedure for loading executable files onto your system must be able
7283to load their contents into the larger address space as well as the
7284instruction and data spaces.
7285
7286@end itemize
7287
7288The overlay system described above is rather simple, and could be
7289improved in many ways:
7290
7291@itemize @bullet
7292
7293@item
7294If your system has suitable bank switch registers or memory management
7295hardware, you could use those facilities to make an overlay's load area
7296contents simply appear at their mapped address in instruction space.
7297This would probably be faster than copying the overlay to its mapped
7298area in the usual way.
7299
7300@item
7301If your overlays are small enough, you could set aside more than one
7302overlay area, and have more than one overlay mapped at a time.
7303
7304@item
7305You can use overlays to manage data, as well as instructions. In
7306general, data overlays are even less transparent to your design than
7307code overlays: whereas code overlays only require care when you call or
7308return to functions, data overlays require care every time you access
7309the data. Also, if you change the contents of a data overlay, you
7310must copy its contents back out to its load address before you can copy a
7311different data overlay into the same mapped area.
7312
7313@end itemize
7314
7315
7316@node Overlay Commands
7317@section Overlay Commands
7318
7319To use @value{GDBN}'s overlay support, each overlay in your program must
7320correspond to a separate section of the executable file. The section's
7321virtual memory address and load memory address must be the overlay's
7322mapped and load addresses. Identifying overlays with sections allows
7323@value{GDBN} to determine the appropriate address of a function or
7324variable, depending on whether the overlay is mapped or not.
7325
7326@value{GDBN}'s overlay commands all start with the word @code{overlay};
7327you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7328
7329@table @code
7330@item overlay off
7331@kindex overlay off
7332Disable @value{GDBN}'s overlay support. When overlay support is
7333disabled, @value{GDBN} assumes that all functions and variables are
7334always present at their mapped addresses. By default, @value{GDBN}'s
7335overlay support is disabled.
7336
7337@item overlay manual
7338@kindex overlay manual
7339@cindex manual overlay debugging
7340Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7341relies on you to tell it which overlays are mapped, and which are not,
7342using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7343commands described below.
7344
7345@item overlay map-overlay @var{overlay}
7346@itemx overlay map @var{overlay}
7347@kindex overlay map-overlay
7348@cindex map an overlay
7349Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7350be the name of the object file section containing the overlay. When an
7351overlay is mapped, @value{GDBN} assumes it can find the overlay's
7352functions and variables at their mapped addresses. @value{GDBN} assumes
7353that any other overlays whose mapped ranges overlap that of
7354@var{overlay} are now unmapped.
7355
7356@item overlay unmap-overlay @var{overlay}
7357@itemx overlay unmap @var{overlay}
7358@kindex overlay unmap-overlay
7359@cindex unmap an overlay
7360Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7361must be the name of the object file section containing the overlay.
7362When an overlay is unmapped, @value{GDBN} assumes it can find the
7363overlay's functions and variables at their load addresses.
7364
7365@item overlay auto
7366@kindex overlay auto
7367Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7368consults a data structure the overlay manager maintains in the inferior
7369to see which overlays are mapped. For details, see @ref{Automatic
7370Overlay Debugging}.
7371
7372@item overlay load-target
7373@itemx overlay load
7374@kindex overlay load-target
7375@cindex reloading the overlay table
7376Re-read the overlay table from the inferior. Normally, @value{GDBN}
7377re-reads the table @value{GDBN} automatically each time the inferior
7378stops, so this command should only be necessary if you have changed the
7379overlay mapping yourself using @value{GDBN}. This command is only
7380useful when using automatic overlay debugging.
7381
7382@item overlay list-overlays
7383@itemx overlay list
7384@cindex listing mapped overlays
7385Display a list of the overlays currently mapped, along with their mapped
7386addresses, load addresses, and sizes.
7387
7388@end table
7389
7390Normally, when @value{GDBN} prints a code address, it includes the name
7391of the function the address falls in:
7392
474c8240 7393@smallexample
df0cd8c5
JB
7394(gdb) print main
7395$3 = @{int ()@} 0x11a0 <main>
474c8240 7396@end smallexample
df0cd8c5
JB
7397@noindent
7398When overlay debugging is enabled, @value{GDBN} recognizes code in
7399unmapped overlays, and prints the names of unmapped functions with
7400asterisks around them. For example, if @code{foo} is a function in an
7401unmapped overlay, @value{GDBN} prints it this way:
7402
474c8240 7403@smallexample
df0cd8c5
JB
7404(gdb) overlay list
7405No sections are mapped.
7406(gdb) print foo
7407$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7408@end smallexample
df0cd8c5
JB
7409@noindent
7410When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7411name normally:
7412
474c8240 7413@smallexample
df0cd8c5
JB
7414(gdb) overlay list
7415Section .ov.foo.text, loaded at 0x100000 - 0x100034,
7416 mapped at 0x1016 - 0x104a
7417(gdb) print foo
7418$6 = @{int (int)@} 0x1016 <foo>
474c8240 7419@end smallexample
df0cd8c5
JB
7420
7421When overlay debugging is enabled, @value{GDBN} can find the correct
7422address for functions and variables in an overlay, whether or not the
7423overlay is mapped. This allows most @value{GDBN} commands, like
7424@code{break} and @code{disassemble}, to work normally, even on unmapped
7425code. However, @value{GDBN}'s breakpoint support has some limitations:
7426
7427@itemize @bullet
7428@item
7429@cindex breakpoints in overlays
7430@cindex overlays, setting breakpoints in
7431You can set breakpoints in functions in unmapped overlays, as long as
7432@value{GDBN} can write to the overlay at its load address.
7433@item
7434@value{GDBN} can not set hardware or simulator-based breakpoints in
7435unmapped overlays. However, if you set a breakpoint at the end of your
7436overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7437you are using manual overlay management), @value{GDBN} will re-set its
7438breakpoints properly.
7439@end itemize
7440
7441
7442@node Automatic Overlay Debugging
7443@section Automatic Overlay Debugging
7444@cindex automatic overlay debugging
7445
7446@value{GDBN} can automatically track which overlays are mapped and which
7447are not, given some simple co-operation from the overlay manager in the
7448inferior. If you enable automatic overlay debugging with the
7449@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7450looks in the inferior's memory for certain variables describing the
7451current state of the overlays.
7452
7453Here are the variables your overlay manager must define to support
7454@value{GDBN}'s automatic overlay debugging:
7455
7456@table @asis
7457
7458@item @code{_ovly_table}:
7459This variable must be an array of the following structures:
7460
474c8240 7461@smallexample
df0cd8c5
JB
7462struct
7463@{
7464 /* The overlay's mapped address. */
7465 unsigned long vma;
7466
7467 /* The size of the overlay, in bytes. */
7468 unsigned long size;
7469
7470 /* The overlay's load address. */
7471 unsigned long lma;
7472
7473 /* Non-zero if the overlay is currently mapped;
7474 zero otherwise. */
7475 unsigned long mapped;
7476@}
474c8240 7477@end smallexample
df0cd8c5
JB
7478
7479@item @code{_novlys}:
7480This variable must be a four-byte signed integer, holding the total
7481number of elements in @code{_ovly_table}.
7482
7483@end table
7484
7485To decide whether a particular overlay is mapped or not, @value{GDBN}
7486looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7487@code{lma} members equal the VMA and LMA of the overlay's section in the
7488executable file. When @value{GDBN} finds a matching entry, it consults
7489the entry's @code{mapped} member to determine whether the overlay is
7490currently mapped.
7491
81d46470 7492In addition, your overlay manager may define a function called
def71bfa 7493@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7494will silently set a breakpoint there. If the overlay manager then
7495calls this function whenever it has changed the overlay table, this
7496will enable @value{GDBN} to accurately keep track of which overlays
7497are in program memory, and update any breakpoints that may be set
7498in overlays. This will allow breakpoints to work even if the
7499overlays are kept in ROM or other non-writable memory while they
7500are not being executed.
df0cd8c5
JB
7501
7502@node Overlay Sample Program
7503@section Overlay Sample Program
7504@cindex overlay example program
7505
7506When linking a program which uses overlays, you must place the overlays
7507at their load addresses, while relocating them to run at their mapped
7508addresses. To do this, you must write a linker script (@pxref{Overlay
7509Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7510since linker scripts are specific to a particular host system, target
7511architecture, and target memory layout, this manual cannot provide
7512portable sample code demonstrating @value{GDBN}'s overlay support.
7513
7514However, the @value{GDBN} source distribution does contain an overlaid
7515program, with linker scripts for a few systems, as part of its test
7516suite. The program consists of the following files from
7517@file{gdb/testsuite/gdb.base}:
7518
7519@table @file
7520@item overlays.c
7521The main program file.
7522@item ovlymgr.c
7523A simple overlay manager, used by @file{overlays.c}.
7524@item foo.c
7525@itemx bar.c
7526@itemx baz.c
7527@itemx grbx.c
7528Overlay modules, loaded and used by @file{overlays.c}.
7529@item d10v.ld
7530@itemx m32r.ld
7531Linker scripts for linking the test program on the @code{d10v-elf}
7532and @code{m32r-elf} targets.
7533@end table
7534
7535You can build the test program using the @code{d10v-elf} GCC
7536cross-compiler like this:
7537
474c8240 7538@smallexample
df0cd8c5
JB
7539$ d10v-elf-gcc -g -c overlays.c
7540$ d10v-elf-gcc -g -c ovlymgr.c
7541$ d10v-elf-gcc -g -c foo.c
7542$ d10v-elf-gcc -g -c bar.c
7543$ d10v-elf-gcc -g -c baz.c
7544$ d10v-elf-gcc -g -c grbx.c
7545$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7546 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7547@end smallexample
df0cd8c5
JB
7548
7549The build process is identical for any other architecture, except that
7550you must substitute the appropriate compiler and linker script for the
7551target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7552
7553
6d2ebf8b 7554@node Languages
c906108c
SS
7555@chapter Using @value{GDBN} with Different Languages
7556@cindex languages
7557
c906108c
SS
7558Although programming languages generally have common aspects, they are
7559rarely expressed in the same manner. For instance, in ANSI C,
7560dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7561Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7562represented (and displayed) differently. Hex numbers in C appear as
c906108c 7563@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7564
7565@cindex working language
7566Language-specific information is built into @value{GDBN} for some languages,
7567allowing you to express operations like the above in your program's
7568native language, and allowing @value{GDBN} to output values in a manner
7569consistent with the syntax of your program's native language. The
7570language you use to build expressions is called the @dfn{working
7571language}.
7572
7573@menu
7574* Setting:: Switching between source languages
7575* Show:: Displaying the language
c906108c 7576* Checks:: Type and range checks
c906108c 7577* Support:: Supported languages
4e562065 7578* Unsupported languages:: Unsupported languages
c906108c
SS
7579@end menu
7580
6d2ebf8b 7581@node Setting
c906108c
SS
7582@section Switching between source languages
7583
7584There are two ways to control the working language---either have @value{GDBN}
7585set it automatically, or select it manually yourself. You can use the
7586@code{set language} command for either purpose. On startup, @value{GDBN}
7587defaults to setting the language automatically. The working language is
7588used to determine how expressions you type are interpreted, how values
7589are printed, etc.
7590
7591In addition to the working language, every source file that
7592@value{GDBN} knows about has its own working language. For some object
7593file formats, the compiler might indicate which language a particular
7594source file is in. However, most of the time @value{GDBN} infers the
7595language from the name of the file. The language of a source file
b37052ae 7596controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7597show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7598set the language of a source file from within @value{GDBN}, but you can
7599set the language associated with a filename extension. @xref{Show, ,
7600Displaying the language}.
c906108c
SS
7601
7602This is most commonly a problem when you use a program, such
5d161b24 7603as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7604another language. In that case, make the
7605program use @code{#line} directives in its C output; that way
7606@value{GDBN} will know the correct language of the source code of the original
7607program, and will display that source code, not the generated C code.
7608
7609@menu
7610* Filenames:: Filename extensions and languages.
7611* Manually:: Setting the working language manually
7612* Automatically:: Having @value{GDBN} infer the source language
7613@end menu
7614
6d2ebf8b 7615@node Filenames
c906108c
SS
7616@subsection List of filename extensions and languages
7617
7618If a source file name ends in one of the following extensions, then
7619@value{GDBN} infers that its language is the one indicated.
7620
7621@table @file
7622
7623@item .c
7624C source file
7625
7626@item .C
7627@itemx .cc
7628@itemx .cp
7629@itemx .cpp
7630@itemx .cxx
7631@itemx .c++
b37052ae 7632C@t{++} source file
c906108c 7633
b37303ee
AF
7634@item .m
7635Objective-C source file
7636
c906108c
SS
7637@item .f
7638@itemx .F
7639Fortran source file
7640
c906108c
SS
7641@item .mod
7642Modula-2 source file
c906108c
SS
7643
7644@item .s
7645@itemx .S
7646Assembler source file. This actually behaves almost like C, but
7647@value{GDBN} does not skip over function prologues when stepping.
7648@end table
7649
7650In addition, you may set the language associated with a filename
7651extension. @xref{Show, , Displaying the language}.
7652
6d2ebf8b 7653@node Manually
c906108c
SS
7654@subsection Setting the working language
7655
7656If you allow @value{GDBN} to set the language automatically,
7657expressions are interpreted the same way in your debugging session and
7658your program.
7659
7660@kindex set language
7661If you wish, you may set the language manually. To do this, issue the
7662command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 7663a language, such as
c906108c 7664@code{c} or @code{modula-2}.
c906108c
SS
7665For a list of the supported languages, type @samp{set language}.
7666
c906108c
SS
7667Setting the language manually prevents @value{GDBN} from updating the working
7668language automatically. This can lead to confusion if you try
7669to debug a program when the working language is not the same as the
7670source language, when an expression is acceptable to both
7671languages---but means different things. For instance, if the current
7672source file were written in C, and @value{GDBN} was parsing Modula-2, a
7673command such as:
7674
474c8240 7675@smallexample
c906108c 7676print a = b + c
474c8240 7677@end smallexample
c906108c
SS
7678
7679@noindent
7680might not have the effect you intended. In C, this means to add
7681@code{b} and @code{c} and place the result in @code{a}. The result
7682printed would be the value of @code{a}. In Modula-2, this means to compare
7683@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 7684
6d2ebf8b 7685@node Automatically
c906108c
SS
7686@subsection Having @value{GDBN} infer the source language
7687
7688To have @value{GDBN} set the working language automatically, use
7689@samp{set language local} or @samp{set language auto}. @value{GDBN}
7690then infers the working language. That is, when your program stops in a
7691frame (usually by encountering a breakpoint), @value{GDBN} sets the
7692working language to the language recorded for the function in that
7693frame. If the language for a frame is unknown (that is, if the function
7694or block corresponding to the frame was defined in a source file that
7695does not have a recognized extension), the current working language is
7696not changed, and @value{GDBN} issues a warning.
7697
7698This may not seem necessary for most programs, which are written
7699entirely in one source language. However, program modules and libraries
7700written in one source language can be used by a main program written in
7701a different source language. Using @samp{set language auto} in this
7702case frees you from having to set the working language manually.
7703
6d2ebf8b 7704@node Show
c906108c 7705@section Displaying the language
c906108c
SS
7706
7707The following commands help you find out which language is the
7708working language, and also what language source files were written in.
7709
7710@kindex show language
d4f3574e
SS
7711@kindex info frame@r{, show the source language}
7712@kindex info source@r{, show the source language}
c906108c
SS
7713@table @code
7714@item show language
7715Display the current working language. This is the
7716language you can use with commands such as @code{print} to
7717build and compute expressions that may involve variables in your program.
7718
7719@item info frame
5d161b24 7720Display the source language for this frame. This language becomes the
c906108c 7721working language if you use an identifier from this frame.
5d161b24 7722@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
7723information listed here.
7724
7725@item info source
7726Display the source language of this source file.
5d161b24 7727@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
7728information listed here.
7729@end table
7730
7731In unusual circumstances, you may have source files with extensions
7732not in the standard list. You can then set the extension associated
7733with a language explicitly:
7734
7735@kindex set extension-language
7736@kindex info extensions
7737@table @code
7738@item set extension-language @var{.ext} @var{language}
7739Set source files with extension @var{.ext} to be assumed to be in
7740the source language @var{language}.
7741
7742@item info extensions
7743List all the filename extensions and the associated languages.
7744@end table
7745
6d2ebf8b 7746@node Checks
c906108c
SS
7747@section Type and range checking
7748
7749@quotation
7750@emph{Warning:} In this release, the @value{GDBN} commands for type and range
7751checking are included, but they do not yet have any effect. This
7752section documents the intended facilities.
7753@end quotation
7754@c FIXME remove warning when type/range code added
7755
7756Some languages are designed to guard you against making seemingly common
7757errors through a series of compile- and run-time checks. These include
7758checking the type of arguments to functions and operators, and making
7759sure mathematical overflows are caught at run time. Checks such as
7760these help to ensure a program's correctness once it has been compiled
7761by eliminating type mismatches, and providing active checks for range
7762errors when your program is running.
7763
7764@value{GDBN} can check for conditions like the above if you wish.
7765Although @value{GDBN} does not check the statements in your program, it
7766can check expressions entered directly into @value{GDBN} for evaluation via
7767the @code{print} command, for example. As with the working language,
7768@value{GDBN} can also decide whether or not to check automatically based on
7769your program's source language. @xref{Support, ,Supported languages},
7770for the default settings of supported languages.
7771
7772@menu
7773* Type Checking:: An overview of type checking
7774* Range Checking:: An overview of range checking
7775@end menu
7776
7777@cindex type checking
7778@cindex checks, type
6d2ebf8b 7779@node Type Checking
c906108c
SS
7780@subsection An overview of type checking
7781
7782Some languages, such as Modula-2, are strongly typed, meaning that the
7783arguments to operators and functions have to be of the correct type,
7784otherwise an error occurs. These checks prevent type mismatch
7785errors from ever causing any run-time problems. For example,
7786
7787@smallexample
77881 + 2 @result{} 3
7789@exdent but
7790@error{} 1 + 2.3
7791@end smallexample
7792
7793The second example fails because the @code{CARDINAL} 1 is not
7794type-compatible with the @code{REAL} 2.3.
7795
5d161b24
DB
7796For the expressions you use in @value{GDBN} commands, you can tell the
7797@value{GDBN} type checker to skip checking;
7798to treat any mismatches as errors and abandon the expression;
7799or to only issue warnings when type mismatches occur,
c906108c
SS
7800but evaluate the expression anyway. When you choose the last of
7801these, @value{GDBN} evaluates expressions like the second example above, but
7802also issues a warning.
7803
5d161b24
DB
7804Even if you turn type checking off, there may be other reasons
7805related to type that prevent @value{GDBN} from evaluating an expression.
7806For instance, @value{GDBN} does not know how to add an @code{int} and
7807a @code{struct foo}. These particular type errors have nothing to do
7808with the language in use, and usually arise from expressions, such as
c906108c
SS
7809the one described above, which make little sense to evaluate anyway.
7810
7811Each language defines to what degree it is strict about type. For
7812instance, both Modula-2 and C require the arguments to arithmetical
7813operators to be numbers. In C, enumerated types and pointers can be
7814represented as numbers, so that they are valid arguments to mathematical
7815operators. @xref{Support, ,Supported languages}, for further
7816details on specific languages.
7817
7818@value{GDBN} provides some additional commands for controlling the type checker:
7819
d4f3574e 7820@kindex set check@r{, type}
c906108c
SS
7821@kindex set check type
7822@kindex show check type
7823@table @code
7824@item set check type auto
7825Set type checking on or off based on the current working language.
7826@xref{Support, ,Supported languages}, for the default settings for
7827each language.
7828
7829@item set check type on
7830@itemx set check type off
7831Set type checking on or off, overriding the default setting for the
7832current working language. Issue a warning if the setting does not
7833match the language default. If any type mismatches occur in
d4f3574e 7834evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
7835message and aborts evaluation of the expression.
7836
7837@item set check type warn
7838Cause the type checker to issue warnings, but to always attempt to
7839evaluate the expression. Evaluating the expression may still
7840be impossible for other reasons. For example, @value{GDBN} cannot add
7841numbers and structures.
7842
7843@item show type
5d161b24 7844Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
7845is setting it automatically.
7846@end table
7847
7848@cindex range checking
7849@cindex checks, range
6d2ebf8b 7850@node Range Checking
c906108c
SS
7851@subsection An overview of range checking
7852
7853In some languages (such as Modula-2), it is an error to exceed the
7854bounds of a type; this is enforced with run-time checks. Such range
7855checking is meant to ensure program correctness by making sure
7856computations do not overflow, or indices on an array element access do
7857not exceed the bounds of the array.
7858
7859For expressions you use in @value{GDBN} commands, you can tell
7860@value{GDBN} to treat range errors in one of three ways: ignore them,
7861always treat them as errors and abandon the expression, or issue
7862warnings but evaluate the expression anyway.
7863
7864A range error can result from numerical overflow, from exceeding an
7865array index bound, or when you type a constant that is not a member
7866of any type. Some languages, however, do not treat overflows as an
7867error. In many implementations of C, mathematical overflow causes the
7868result to ``wrap around'' to lower values---for example, if @var{m} is
7869the largest integer value, and @var{s} is the smallest, then
7870
474c8240 7871@smallexample
c906108c 7872@var{m} + 1 @result{} @var{s}
474c8240 7873@end smallexample
c906108c
SS
7874
7875This, too, is specific to individual languages, and in some cases
7876specific to individual compilers or machines. @xref{Support, ,
7877Supported languages}, for further details on specific languages.
7878
7879@value{GDBN} provides some additional commands for controlling the range checker:
7880
d4f3574e 7881@kindex set check@r{, range}
c906108c
SS
7882@kindex set check range
7883@kindex show check range
7884@table @code
7885@item set check range auto
7886Set range checking on or off based on the current working language.
7887@xref{Support, ,Supported languages}, for the default settings for
7888each language.
7889
7890@item set check range on
7891@itemx set check range off
7892Set range checking on or off, overriding the default setting for the
7893current working language. A warning is issued if the setting does not
c3f6f71d
JM
7894match the language default. If a range error occurs and range checking is on,
7895then a message is printed and evaluation of the expression is aborted.
c906108c
SS
7896
7897@item set check range warn
7898Output messages when the @value{GDBN} range checker detects a range error,
7899but attempt to evaluate the expression anyway. Evaluating the
7900expression may still be impossible for other reasons, such as accessing
7901memory that the process does not own (a typical example from many Unix
7902systems).
7903
7904@item show range
7905Show the current setting of the range checker, and whether or not it is
7906being set automatically by @value{GDBN}.
7907@end table
c906108c 7908
6d2ebf8b 7909@node Support
c906108c 7910@section Supported languages
c906108c 7911
b37303ee 7912@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, assembly, and Modula-2.
cce74817 7913@c This is false ...
c906108c
SS
7914Some @value{GDBN} features may be used in expressions regardless of the
7915language you use: the @value{GDBN} @code{@@} and @code{::} operators,
7916and the @samp{@{type@}addr} construct (@pxref{Expressions,
7917,Expressions}) can be used with the constructs of any supported
7918language.
7919
7920The following sections detail to what degree each source language is
7921supported by @value{GDBN}. These sections are not meant to be language
7922tutorials or references, but serve only as a reference guide to what the
7923@value{GDBN} expression parser accepts, and what input and output
7924formats should look like for different languages. There are many good
7925books written on each of these languages; please look to these for a
7926language reference or tutorial.
7927
c906108c 7928@menu
b37303ee
AF
7929* C:: C and C@t{++}
7930* Objective-C:: Objective-C
7931* Modula-2:: Modula-2
c906108c
SS
7932@end menu
7933
6d2ebf8b 7934@node C
b37052ae 7935@subsection C and C@t{++}
7a292a7a 7936
b37052ae
EZ
7937@cindex C and C@t{++}
7938@cindex expressions in C or C@t{++}
c906108c 7939
b37052ae 7940Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
7941to both languages. Whenever this is the case, we discuss those languages
7942together.
7943
41afff9a
EZ
7944@cindex C@t{++}
7945@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
7946@cindex @sc{gnu} C@t{++}
7947The C@t{++} debugging facilities are jointly implemented by the C@t{++}
7948compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
7949effectively, you must compile your C@t{++} programs with a supported
7950C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
7951compiler (@code{aCC}).
7952
0179ffac
DC
7953For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
7954format; if it doesn't work on your system, try the stabs+ debugging
7955format. You can select those formats explicitly with the @code{g++}
7956command-line options @option{-gdwarf-2} and @option{-gstabs+}.
7957@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
7958CC, gcc.info, Using @sc{gnu} CC}.
c906108c 7959
c906108c 7960@menu
b37052ae
EZ
7961* C Operators:: C and C@t{++} operators
7962* C Constants:: C and C@t{++} constants
7963* C plus plus expressions:: C@t{++} expressions
7964* C Defaults:: Default settings for C and C@t{++}
7965* C Checks:: C and C@t{++} type and range checks
c906108c 7966* Debugging C:: @value{GDBN} and C
b37052ae 7967* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 7968@end menu
c906108c 7969
6d2ebf8b 7970@node C Operators
b37052ae 7971@subsubsection C and C@t{++} operators
7a292a7a 7972
b37052ae 7973@cindex C and C@t{++} operators
c906108c
SS
7974
7975Operators must be defined on values of specific types. For instance,
7976@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 7977often defined on groups of types.
c906108c 7978
b37052ae 7979For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
7980
7981@itemize @bullet
53a5351d 7982
c906108c 7983@item
c906108c 7984@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 7985specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
7986
7987@item
d4f3574e
SS
7988@emph{Floating-point types} include @code{float}, @code{double}, and
7989@code{long double} (if supported by the target platform).
c906108c
SS
7990
7991@item
53a5351d 7992@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
7993
7994@item
7995@emph{Scalar types} include all of the above.
53a5351d 7996
c906108c
SS
7997@end itemize
7998
7999@noindent
8000The following operators are supported. They are listed here
8001in order of increasing precedence:
8002
8003@table @code
8004@item ,
8005The comma or sequencing operator. Expressions in a comma-separated list
8006are evaluated from left to right, with the result of the entire
8007expression being the last expression evaluated.
8008
8009@item =
8010Assignment. The value of an assignment expression is the value
8011assigned. Defined on scalar types.
8012
8013@item @var{op}=
8014Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8015and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8016@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8017@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8018@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8019
8020@item ?:
8021The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8022of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8023integral type.
8024
8025@item ||
8026Logical @sc{or}. Defined on integral types.
8027
8028@item &&
8029Logical @sc{and}. Defined on integral types.
8030
8031@item |
8032Bitwise @sc{or}. Defined on integral types.
8033
8034@item ^
8035Bitwise exclusive-@sc{or}. Defined on integral types.
8036
8037@item &
8038Bitwise @sc{and}. Defined on integral types.
8039
8040@item ==@r{, }!=
8041Equality and inequality. Defined on scalar types. The value of these
8042expressions is 0 for false and non-zero for true.
8043
8044@item <@r{, }>@r{, }<=@r{, }>=
8045Less than, greater than, less than or equal, greater than or equal.
8046Defined on scalar types. The value of these expressions is 0 for false
8047and non-zero for true.
8048
8049@item <<@r{, }>>
8050left shift, and right shift. Defined on integral types.
8051
8052@item @@
8053The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8054
8055@item +@r{, }-
8056Addition and subtraction. Defined on integral types, floating-point types and
8057pointer types.
8058
8059@item *@r{, }/@r{, }%
8060Multiplication, division, and modulus. Multiplication and division are
8061defined on integral and floating-point types. Modulus is defined on
8062integral types.
8063
8064@item ++@r{, }--
8065Increment and decrement. When appearing before a variable, the
8066operation is performed before the variable is used in an expression;
8067when appearing after it, the variable's value is used before the
8068operation takes place.
8069
8070@item *
8071Pointer dereferencing. Defined on pointer types. Same precedence as
8072@code{++}.
8073
8074@item &
8075Address operator. Defined on variables. Same precedence as @code{++}.
8076
b37052ae
EZ
8077For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8078allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8079(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8080where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8081stored.
c906108c
SS
8082
8083@item -
8084Negative. Defined on integral and floating-point types. Same
8085precedence as @code{++}.
8086
8087@item !
8088Logical negation. Defined on integral types. Same precedence as
8089@code{++}.
8090
8091@item ~
8092Bitwise complement operator. Defined on integral types. Same precedence as
8093@code{++}.
8094
8095
8096@item .@r{, }->
8097Structure member, and pointer-to-structure member. For convenience,
8098@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8099pointer based on the stored type information.
8100Defined on @code{struct} and @code{union} data.
8101
c906108c
SS
8102@item .*@r{, }->*
8103Dereferences of pointers to members.
c906108c
SS
8104
8105@item []
8106Array indexing. @code{@var{a}[@var{i}]} is defined as
8107@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8108
8109@item ()
8110Function parameter list. Same precedence as @code{->}.
8111
c906108c 8112@item ::
b37052ae 8113C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8114and @code{class} types.
c906108c
SS
8115
8116@item ::
7a292a7a
SS
8117Doubled colons also represent the @value{GDBN} scope operator
8118(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8119above.
c906108c
SS
8120@end table
8121
c906108c
SS
8122If an operator is redefined in the user code, @value{GDBN} usually
8123attempts to invoke the redefined version instead of using the operator's
8124predefined meaning.
c906108c 8125
c906108c 8126@menu
5d161b24 8127* C Constants::
c906108c
SS
8128@end menu
8129
6d2ebf8b 8130@node C Constants
b37052ae 8131@subsubsection C and C@t{++} constants
c906108c 8132
b37052ae 8133@cindex C and C@t{++} constants
c906108c 8134
b37052ae 8135@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8136following ways:
c906108c
SS
8137
8138@itemize @bullet
8139@item
8140Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8141specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8142by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8143@samp{l}, specifying that the constant should be treated as a
8144@code{long} value.
8145
8146@item
8147Floating point constants are a sequence of digits, followed by a decimal
8148point, followed by a sequence of digits, and optionally followed by an
8149exponent. An exponent is of the form:
8150@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8151sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8152A floating-point constant may also end with a letter @samp{f} or
8153@samp{F}, specifying that the constant should be treated as being of
8154the @code{float} (as opposed to the default @code{double}) type; or with
8155a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8156constant.
c906108c
SS
8157
8158@item
8159Enumerated constants consist of enumerated identifiers, or their
8160integral equivalents.
8161
8162@item
8163Character constants are a single character surrounded by single quotes
8164(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8165(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8166be represented by a letter or by @dfn{escape sequences}, which are of
8167the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8168of the character's ordinal value; or of the form @samp{\@var{x}}, where
8169@samp{@var{x}} is a predefined special character---for example,
8170@samp{\n} for newline.
8171
8172@item
96a2c332
SS
8173String constants are a sequence of character constants surrounded by
8174double quotes (@code{"}). Any valid character constant (as described
8175above) may appear. Double quotes within the string must be preceded by
8176a backslash, so for instance @samp{"a\"b'c"} is a string of five
8177characters.
c906108c
SS
8178
8179@item
8180Pointer constants are an integral value. You can also write pointers
8181to constants using the C operator @samp{&}.
8182
8183@item
8184Array constants are comma-separated lists surrounded by braces @samp{@{}
8185and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8186integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8187and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8188@end itemize
8189
c906108c 8190@menu
5d161b24
DB
8191* C plus plus expressions::
8192* C Defaults::
8193* C Checks::
c906108c 8194
5d161b24 8195* Debugging C::
c906108c
SS
8196@end menu
8197
6d2ebf8b 8198@node C plus plus expressions
b37052ae
EZ
8199@subsubsection C@t{++} expressions
8200
8201@cindex expressions in C@t{++}
8202@value{GDBN} expression handling can interpret most C@t{++} expressions.
8203
0179ffac
DC
8204@cindex debugging C@t{++} programs
8205@cindex C@t{++} compilers
8206@cindex debug formats and C@t{++}
8207@cindex @value{NGCC} and C@t{++}
c906108c 8208@quotation
b37052ae 8209@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8210proper compiler and the proper debug format. Currently, @value{GDBN}
8211works best when debugging C@t{++} code that is compiled with
8212@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8213@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8214stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8215stabs+ as their default debug format, so you usually don't need to
8216specify a debug format explicitly. Other compilers and/or debug formats
8217are likely to work badly or not at all when using @value{GDBN} to debug
8218C@t{++} code.
c906108c 8219@end quotation
c906108c
SS
8220
8221@enumerate
8222
8223@cindex member functions
8224@item
8225Member function calls are allowed; you can use expressions like
8226
474c8240 8227@smallexample
c906108c 8228count = aml->GetOriginal(x, y)
474c8240 8229@end smallexample
c906108c 8230
41afff9a 8231@vindex this@r{, inside C@t{++} member functions}
b37052ae 8232@cindex namespace in C@t{++}
c906108c
SS
8233@item
8234While a member function is active (in the selected stack frame), your
8235expressions have the same namespace available as the member function;
8236that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8237pointer @code{this} following the same rules as C@t{++}.
c906108c 8238
c906108c 8239@cindex call overloaded functions
d4f3574e 8240@cindex overloaded functions, calling
b37052ae 8241@cindex type conversions in C@t{++}
c906108c
SS
8242@item
8243You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8244call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8245perform overload resolution involving user-defined type conversions,
8246calls to constructors, or instantiations of templates that do not exist
8247in the program. It also cannot handle ellipsis argument lists or
8248default arguments.
8249
8250It does perform integral conversions and promotions, floating-point
8251promotions, arithmetic conversions, pointer conversions, conversions of
8252class objects to base classes, and standard conversions such as those of
8253functions or arrays to pointers; it requires an exact match on the
8254number of function arguments.
8255
8256Overload resolution is always performed, unless you have specified
8257@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8258,@value{GDBN} features for C@t{++}}.
c906108c 8259
d4f3574e 8260You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8261explicit function signature to call an overloaded function, as in
8262@smallexample
8263p 'foo(char,int)'('x', 13)
8264@end smallexample
d4f3574e 8265
c906108c 8266The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8267see @ref{Completion, ,Command completion}.
c906108c 8268
c906108c
SS
8269@cindex reference declarations
8270@item
b37052ae
EZ
8271@value{GDBN} understands variables declared as C@t{++} references; you can use
8272them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8273dereferenced.
8274
8275In the parameter list shown when @value{GDBN} displays a frame, the values of
8276reference variables are not displayed (unlike other variables); this
8277avoids clutter, since references are often used for large structures.
8278The @emph{address} of a reference variable is always shown, unless
8279you have specified @samp{set print address off}.
8280
8281@item
b37052ae 8282@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8283expressions can use it just as expressions in your program do. Since
8284one scope may be defined in another, you can use @code{::} repeatedly if
8285necessary, for example in an expression like
8286@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8287resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8288debugging (@pxref{Variables, ,Program variables}).
8289@end enumerate
8290
b37052ae 8291In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8292calling virtual functions correctly, printing out virtual bases of
8293objects, calling functions in a base subobject, casting objects, and
8294invoking user-defined operators.
c906108c 8295
6d2ebf8b 8296@node C Defaults
b37052ae 8297@subsubsection C and C@t{++} defaults
7a292a7a 8298
b37052ae 8299@cindex C and C@t{++} defaults
c906108c 8300
c906108c
SS
8301If you allow @value{GDBN} to set type and range checking automatically, they
8302both default to @code{off} whenever the working language changes to
b37052ae 8303C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8304selects the working language.
c906108c
SS
8305
8306If you allow @value{GDBN} to set the language automatically, it
8307recognizes source files whose names end with @file{.c}, @file{.C}, or
8308@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8309these files, it sets the working language to C or C@t{++}.
c906108c
SS
8310@xref{Automatically, ,Having @value{GDBN} infer the source language},
8311for further details.
8312
c906108c
SS
8313@c Type checking is (a) primarily motivated by Modula-2, and (b)
8314@c unimplemented. If (b) changes, it might make sense to let this node
8315@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8316
6d2ebf8b 8317@node C Checks
b37052ae 8318@subsubsection C and C@t{++} type and range checks
7a292a7a 8319
b37052ae 8320@cindex C and C@t{++} checks
c906108c 8321
b37052ae 8322By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8323is not used. However, if you turn type checking on, @value{GDBN}
8324considers two variables type equivalent if:
8325
8326@itemize @bullet
8327@item
8328The two variables are structured and have the same structure, union, or
8329enumerated tag.
8330
8331@item
8332The two variables have the same type name, or types that have been
8333declared equivalent through @code{typedef}.
8334
8335@ignore
8336@c leaving this out because neither J Gilmore nor R Pesch understand it.
8337@c FIXME--beers?
8338@item
8339The two @code{struct}, @code{union}, or @code{enum} variables are
8340declared in the same declaration. (Note: this may not be true for all C
8341compilers.)
8342@end ignore
8343@end itemize
8344
8345Range checking, if turned on, is done on mathematical operations. Array
8346indices are not checked, since they are often used to index a pointer
8347that is not itself an array.
c906108c 8348
6d2ebf8b 8349@node Debugging C
c906108c 8350@subsubsection @value{GDBN} and C
c906108c
SS
8351
8352The @code{set print union} and @code{show print union} commands apply to
8353the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8354inside a @code{struct} or @code{class} is also printed. Otherwise, it
8355appears as @samp{@{...@}}.
c906108c
SS
8356
8357The @code{@@} operator aids in the debugging of dynamic arrays, formed
8358with pointers and a memory allocation function. @xref{Expressions,
8359,Expressions}.
8360
c906108c 8361@menu
5d161b24 8362* Debugging C plus plus::
c906108c
SS
8363@end menu
8364
6d2ebf8b 8365@node Debugging C plus plus
b37052ae 8366@subsubsection @value{GDBN} features for C@t{++}
c906108c 8367
b37052ae 8368@cindex commands for C@t{++}
7a292a7a 8369
b37052ae
EZ
8370Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8371designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8372
8373@table @code
8374@cindex break in overloaded functions
8375@item @r{breakpoint menus}
8376When you want a breakpoint in a function whose name is overloaded,
8377@value{GDBN} breakpoint menus help you specify which function definition
8378you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8379
b37052ae 8380@cindex overloading in C@t{++}
c906108c
SS
8381@item rbreak @var{regex}
8382Setting breakpoints using regular expressions is helpful for setting
8383breakpoints on overloaded functions that are not members of any special
8384classes.
8385@xref{Set Breaks, ,Setting breakpoints}.
8386
b37052ae 8387@cindex C@t{++} exception handling
c906108c
SS
8388@item catch throw
8389@itemx catch catch
b37052ae 8390Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8391Catchpoints, , Setting catchpoints}.
8392
8393@cindex inheritance
8394@item ptype @var{typename}
8395Print inheritance relationships as well as other information for type
8396@var{typename}.
8397@xref{Symbols, ,Examining the Symbol Table}.
8398
b37052ae 8399@cindex C@t{++} symbol display
c906108c
SS
8400@item set print demangle
8401@itemx show print demangle
8402@itemx set print asm-demangle
8403@itemx show print asm-demangle
b37052ae
EZ
8404Control whether C@t{++} symbols display in their source form, both when
8405displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8406@xref{Print Settings, ,Print settings}.
8407
8408@item set print object
8409@itemx show print object
8410Choose whether to print derived (actual) or declared types of objects.
8411@xref{Print Settings, ,Print settings}.
8412
8413@item set print vtbl
8414@itemx show print vtbl
8415Control the format for printing virtual function tables.
8416@xref{Print Settings, ,Print settings}.
c906108c 8417(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8418ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8419
8420@kindex set overload-resolution
d4f3574e 8421@cindex overloaded functions, overload resolution
c906108c 8422@item set overload-resolution on
b37052ae 8423Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8424is on. For overloaded functions, @value{GDBN} evaluates the arguments
8425and searches for a function whose signature matches the argument types,
b37052ae 8426using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8427expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8428message.
8429
8430@item set overload-resolution off
b37052ae 8431Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8432overloaded functions that are not class member functions, @value{GDBN}
8433chooses the first function of the specified name that it finds in the
8434symbol table, whether or not its arguments are of the correct type. For
8435overloaded functions that are class member functions, @value{GDBN}
8436searches for a function whose signature @emph{exactly} matches the
8437argument types.
c906108c
SS
8438
8439@item @r{Overloaded symbol names}
8440You can specify a particular definition of an overloaded symbol, using
b37052ae 8441the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8442@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8443also use the @value{GDBN} command-line word completion facilities to list the
8444available choices, or to finish the type list for you.
8445@xref{Completion,, Command completion}, for details on how to do this.
8446@end table
c906108c 8447
b37303ee
AF
8448@node Objective-C
8449@subsection Objective-C
8450
8451@cindex Objective-C
8452This section provides information about some commands and command
8453options that are useful for debugging Objective-C code.
8454
8455@menu
8456* Method Names in Commands::
8457* The Print Command with Objective-C::
8458@end menu
8459
8460@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8461@subsubsection Method Names in Commands
8462
8463The following commands have been extended to accept Objective-C method
8464names as line specifications:
8465
8466@kindex clear@r{, and Objective-C}
8467@kindex break@r{, and Objective-C}
8468@kindex info line@r{, and Objective-C}
8469@kindex jump@r{, and Objective-C}
8470@kindex list@r{, and Objective-C}
8471@itemize
8472@item @code{clear}
8473@item @code{break}
8474@item @code{info line}
8475@item @code{jump}
8476@item @code{list}
8477@end itemize
8478
8479A fully qualified Objective-C method name is specified as
8480
8481@smallexample
8482-[@var{Class} @var{methodName}]
8483@end smallexample
8484
c552b3bb
JM
8485where the minus sign is used to indicate an instance method and a
8486plus sign (not shown) is used to indicate a class method. The class
8487name @var{Class} and method name @var{methodName} are enclosed in
8488brackets, similar to the way messages are specified in Objective-C
8489source code. For example, to set a breakpoint at the @code{create}
8490instance method of class @code{Fruit} in the program currently being
8491debugged, enter:
b37303ee
AF
8492
8493@smallexample
8494break -[Fruit create]
8495@end smallexample
8496
8497To list ten program lines around the @code{initialize} class method,
8498enter:
8499
8500@smallexample
8501list +[NSText initialize]
8502@end smallexample
8503
c552b3bb
JM
8504In the current version of @value{GDBN}, the plus or minus sign is
8505required. In future versions of @value{GDBN}, the plus or minus
8506sign will be optional, but you can use it to narrow the search. It
8507is also possible to specify just a method name:
b37303ee
AF
8508
8509@smallexample
8510break create
8511@end smallexample
8512
8513You must specify the complete method name, including any colons. If
8514your program's source files contain more than one @code{create} method,
8515you'll be presented with a numbered list of classes that implement that
8516method. Indicate your choice by number, or type @samp{0} to exit if
8517none apply.
8518
8519As another example, to clear a breakpoint established at the
8520@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8521
8522@smallexample
8523clear -[NSWindow makeKeyAndOrderFront:]
8524@end smallexample
8525
8526@node The Print Command with Objective-C
8527@subsubsection The Print Command With Objective-C
c552b3bb
JM
8528@kindex print-object
8529@kindex po @r{(@code{print-object})}
b37303ee 8530
c552b3bb 8531The print command has also been extended to accept methods. For example:
b37303ee
AF
8532
8533@smallexample
c552b3bb 8534print -[@var{object} hash]
b37303ee
AF
8535@end smallexample
8536
8537@cindex print an Objective-C object description
c552b3bb
JM
8538@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8539@noindent
8540will tell @value{GDBN} to send the @code{hash} message to @var{object}
8541and print the result. Also, an additional command has been added,
8542@code{print-object} or @code{po} for short, which is meant to print
8543the description of an object. However, this command may only work
8544with certain Objective-C libraries that have a particular hook
8545function, @code{_NSPrintForDebugger}, defined.
b37303ee
AF
8546
8547@node Modula-2, , Objective-C, Support
c906108c 8548@subsection Modula-2
7a292a7a 8549
d4f3574e 8550@cindex Modula-2, @value{GDBN} support
c906108c
SS
8551
8552The extensions made to @value{GDBN} to support Modula-2 only support
8553output from the @sc{gnu} Modula-2 compiler (which is currently being
8554developed). Other Modula-2 compilers are not currently supported, and
8555attempting to debug executables produced by them is most likely
8556to give an error as @value{GDBN} reads in the executable's symbol
8557table.
8558
8559@cindex expressions in Modula-2
8560@menu
8561* M2 Operators:: Built-in operators
8562* Built-In Func/Proc:: Built-in functions and procedures
8563* M2 Constants:: Modula-2 constants
8564* M2 Defaults:: Default settings for Modula-2
8565* Deviations:: Deviations from standard Modula-2
8566* M2 Checks:: Modula-2 type and range checks
8567* M2 Scope:: The scope operators @code{::} and @code{.}
8568* GDB/M2:: @value{GDBN} and Modula-2
8569@end menu
8570
6d2ebf8b 8571@node M2 Operators
c906108c
SS
8572@subsubsection Operators
8573@cindex Modula-2 operators
8574
8575Operators must be defined on values of specific types. For instance,
8576@code{+} is defined on numbers, but not on structures. Operators are
8577often defined on groups of types. For the purposes of Modula-2, the
8578following definitions hold:
8579
8580@itemize @bullet
8581
8582@item
8583@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8584their subranges.
8585
8586@item
8587@emph{Character types} consist of @code{CHAR} and its subranges.
8588
8589@item
8590@emph{Floating-point types} consist of @code{REAL}.
8591
8592@item
8593@emph{Pointer types} consist of anything declared as @code{POINTER TO
8594@var{type}}.
8595
8596@item
8597@emph{Scalar types} consist of all of the above.
8598
8599@item
8600@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8601
8602@item
8603@emph{Boolean types} consist of @code{BOOLEAN}.
8604@end itemize
8605
8606@noindent
8607The following operators are supported, and appear in order of
8608increasing precedence:
8609
8610@table @code
8611@item ,
8612Function argument or array index separator.
8613
8614@item :=
8615Assignment. The value of @var{var} @code{:=} @var{value} is
8616@var{value}.
8617
8618@item <@r{, }>
8619Less than, greater than on integral, floating-point, or enumerated
8620types.
8621
8622@item <=@r{, }>=
96a2c332 8623Less than or equal to, greater than or equal to
c906108c
SS
8624on integral, floating-point and enumerated types, or set inclusion on
8625set types. Same precedence as @code{<}.
8626
8627@item =@r{, }<>@r{, }#
8628Equality and two ways of expressing inequality, valid on scalar types.
8629Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
8630available for inequality, since @code{#} conflicts with the script
8631comment character.
8632
8633@item IN
8634Set membership. Defined on set types and the types of their members.
8635Same precedence as @code{<}.
8636
8637@item OR
8638Boolean disjunction. Defined on boolean types.
8639
8640@item AND@r{, }&
d4f3574e 8641Boolean conjunction. Defined on boolean types.
c906108c
SS
8642
8643@item @@
8644The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8645
8646@item +@r{, }-
8647Addition and subtraction on integral and floating-point types, or union
8648and difference on set types.
8649
8650@item *
8651Multiplication on integral and floating-point types, or set intersection
8652on set types.
8653
8654@item /
8655Division on floating-point types, or symmetric set difference on set
8656types. Same precedence as @code{*}.
8657
8658@item DIV@r{, }MOD
8659Integer division and remainder. Defined on integral types. Same
8660precedence as @code{*}.
8661
8662@item -
8663Negative. Defined on @code{INTEGER} and @code{REAL} data.
8664
8665@item ^
8666Pointer dereferencing. Defined on pointer types.
8667
8668@item NOT
8669Boolean negation. Defined on boolean types. Same precedence as
8670@code{^}.
8671
8672@item .
8673@code{RECORD} field selector. Defined on @code{RECORD} data. Same
8674precedence as @code{^}.
8675
8676@item []
8677Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
8678
8679@item ()
8680Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
8681as @code{^}.
8682
8683@item ::@r{, }.
8684@value{GDBN} and Modula-2 scope operators.
8685@end table
8686
8687@quotation
8688@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
8689treats the use of the operator @code{IN}, or the use of operators
8690@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
8691@code{<=}, and @code{>=} on sets as an error.
8692@end quotation
8693
cb51c4e0 8694
6d2ebf8b 8695@node Built-In Func/Proc
c906108c 8696@subsubsection Built-in functions and procedures
cb51c4e0 8697@cindex Modula-2 built-ins
c906108c
SS
8698
8699Modula-2 also makes available several built-in procedures and functions.
8700In describing these, the following metavariables are used:
8701
8702@table @var
8703
8704@item a
8705represents an @code{ARRAY} variable.
8706
8707@item c
8708represents a @code{CHAR} constant or variable.
8709
8710@item i
8711represents a variable or constant of integral type.
8712
8713@item m
8714represents an identifier that belongs to a set. Generally used in the
8715same function with the metavariable @var{s}. The type of @var{s} should
8716be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
8717
8718@item n
8719represents a variable or constant of integral or floating-point type.
8720
8721@item r
8722represents a variable or constant of floating-point type.
8723
8724@item t
8725represents a type.
8726
8727@item v
8728represents a variable.
8729
8730@item x
8731represents a variable or constant of one of many types. See the
8732explanation of the function for details.
8733@end table
8734
8735All Modula-2 built-in procedures also return a result, described below.
8736
8737@table @code
8738@item ABS(@var{n})
8739Returns the absolute value of @var{n}.
8740
8741@item CAP(@var{c})
8742If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 8743equivalent, otherwise it returns its argument.
c906108c
SS
8744
8745@item CHR(@var{i})
8746Returns the character whose ordinal value is @var{i}.
8747
8748@item DEC(@var{v})
c3f6f71d 8749Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8750
8751@item DEC(@var{v},@var{i})
8752Decrements the value in the variable @var{v} by @var{i}. Returns the
8753new value.
8754
8755@item EXCL(@var{m},@var{s})
8756Removes the element @var{m} from the set @var{s}. Returns the new
8757set.
8758
8759@item FLOAT(@var{i})
8760Returns the floating point equivalent of the integer @var{i}.
8761
8762@item HIGH(@var{a})
8763Returns the index of the last member of @var{a}.
8764
8765@item INC(@var{v})
c3f6f71d 8766Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
8767
8768@item INC(@var{v},@var{i})
8769Increments the value in the variable @var{v} by @var{i}. Returns the
8770new value.
8771
8772@item INCL(@var{m},@var{s})
8773Adds the element @var{m} to the set @var{s} if it is not already
8774there. Returns the new set.
8775
8776@item MAX(@var{t})
8777Returns the maximum value of the type @var{t}.
8778
8779@item MIN(@var{t})
8780Returns the minimum value of the type @var{t}.
8781
8782@item ODD(@var{i})
8783Returns boolean TRUE if @var{i} is an odd number.
8784
8785@item ORD(@var{x})
8786Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
8787value of a character is its @sc{ascii} value (on machines supporting the
8788@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
8789integral, character and enumerated types.
8790
8791@item SIZE(@var{x})
8792Returns the size of its argument. @var{x} can be a variable or a type.
8793
8794@item TRUNC(@var{r})
8795Returns the integral part of @var{r}.
8796
8797@item VAL(@var{t},@var{i})
8798Returns the member of the type @var{t} whose ordinal value is @var{i}.
8799@end table
8800
8801@quotation
8802@emph{Warning:} Sets and their operations are not yet supported, so
8803@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
8804an error.
8805@end quotation
8806
8807@cindex Modula-2 constants
6d2ebf8b 8808@node M2 Constants
c906108c
SS
8809@subsubsection Constants
8810
8811@value{GDBN} allows you to express the constants of Modula-2 in the following
8812ways:
8813
8814@itemize @bullet
8815
8816@item
8817Integer constants are simply a sequence of digits. When used in an
8818expression, a constant is interpreted to be type-compatible with the
8819rest of the expression. Hexadecimal integers are specified by a
8820trailing @samp{H}, and octal integers by a trailing @samp{B}.
8821
8822@item
8823Floating point constants appear as a sequence of digits, followed by a
8824decimal point and another sequence of digits. An optional exponent can
8825then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
8826@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
8827digits of the floating point constant must be valid decimal (base 10)
8828digits.
8829
8830@item
8831Character constants consist of a single character enclosed by a pair of
8832like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 8833also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
8834followed by a @samp{C}.
8835
8836@item
8837String constants consist of a sequence of characters enclosed by a
8838pair of like quotes, either single (@code{'}) or double (@code{"}).
8839Escape sequences in the style of C are also allowed. @xref{C
b37052ae 8840Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
8841sequences.
8842
8843@item
8844Enumerated constants consist of an enumerated identifier.
8845
8846@item
8847Boolean constants consist of the identifiers @code{TRUE} and
8848@code{FALSE}.
8849
8850@item
8851Pointer constants consist of integral values only.
8852
8853@item
8854Set constants are not yet supported.
8855@end itemize
8856
6d2ebf8b 8857@node M2 Defaults
c906108c
SS
8858@subsubsection Modula-2 defaults
8859@cindex Modula-2 defaults
8860
8861If type and range checking are set automatically by @value{GDBN}, they
8862both default to @code{on} whenever the working language changes to
d4f3574e 8863Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
8864selected the working language.
8865
8866If you allow @value{GDBN} to set the language automatically, then entering
8867code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 8868working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
8869the language automatically}, for further details.
8870
6d2ebf8b 8871@node Deviations
c906108c
SS
8872@subsubsection Deviations from standard Modula-2
8873@cindex Modula-2, deviations from
8874
8875A few changes have been made to make Modula-2 programs easier to debug.
8876This is done primarily via loosening its type strictness:
8877
8878@itemize @bullet
8879@item
8880Unlike in standard Modula-2, pointer constants can be formed by
8881integers. This allows you to modify pointer variables during
8882debugging. (In standard Modula-2, the actual address contained in a
8883pointer variable is hidden from you; it can only be modified
8884through direct assignment to another pointer variable or expression that
8885returned a pointer.)
8886
8887@item
8888C escape sequences can be used in strings and characters to represent
8889non-printable characters. @value{GDBN} prints out strings with these
8890escape sequences embedded. Single non-printable characters are
8891printed using the @samp{CHR(@var{nnn})} format.
8892
8893@item
8894The assignment operator (@code{:=}) returns the value of its right-hand
8895argument.
8896
8897@item
8898All built-in procedures both modify @emph{and} return their argument.
8899@end itemize
8900
6d2ebf8b 8901@node M2 Checks
c906108c
SS
8902@subsubsection Modula-2 type and range checks
8903@cindex Modula-2 checks
8904
8905@quotation
8906@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
8907range checking.
8908@end quotation
8909@c FIXME remove warning when type/range checks added
8910
8911@value{GDBN} considers two Modula-2 variables type equivalent if:
8912
8913@itemize @bullet
8914@item
8915They are of types that have been declared equivalent via a @code{TYPE
8916@var{t1} = @var{t2}} statement
8917
8918@item
8919They have been declared on the same line. (Note: This is true of the
8920@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
8921@end itemize
8922
8923As long as type checking is enabled, any attempt to combine variables
8924whose types are not equivalent is an error.
8925
8926Range checking is done on all mathematical operations, assignment, array
8927index bounds, and all built-in functions and procedures.
8928
6d2ebf8b 8929@node M2 Scope
c906108c
SS
8930@subsubsection The scope operators @code{::} and @code{.}
8931@cindex scope
41afff9a 8932@cindex @code{.}, Modula-2 scope operator
c906108c
SS
8933@cindex colon, doubled as scope operator
8934@ifinfo
41afff9a 8935@vindex colon-colon@r{, in Modula-2}
c906108c
SS
8936@c Info cannot handle :: but TeX can.
8937@end ifinfo
8938@iftex
41afff9a 8939@vindex ::@r{, in Modula-2}
c906108c
SS
8940@end iftex
8941
8942There are a few subtle differences between the Modula-2 scope operator
8943(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
8944similar syntax:
8945
474c8240 8946@smallexample
c906108c
SS
8947
8948@var{module} . @var{id}
8949@var{scope} :: @var{id}
474c8240 8950@end smallexample
c906108c
SS
8951
8952@noindent
8953where @var{scope} is the name of a module or a procedure,
8954@var{module} the name of a module, and @var{id} is any declared
8955identifier within your program, except another module.
8956
8957Using the @code{::} operator makes @value{GDBN} search the scope
8958specified by @var{scope} for the identifier @var{id}. If it is not
8959found in the specified scope, then @value{GDBN} searches all scopes
8960enclosing the one specified by @var{scope}.
8961
8962Using the @code{.} operator makes @value{GDBN} search the current scope for
8963the identifier specified by @var{id} that was imported from the
8964definition module specified by @var{module}. With this operator, it is
8965an error if the identifier @var{id} was not imported from definition
8966module @var{module}, or if @var{id} is not an identifier in
8967@var{module}.
8968
6d2ebf8b 8969@node GDB/M2
c906108c
SS
8970@subsubsection @value{GDBN} and Modula-2
8971
8972Some @value{GDBN} commands have little use when debugging Modula-2 programs.
8973Five subcommands of @code{set print} and @code{show print} apply
b37052ae 8974specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 8975@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 8976apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
8977analogue in Modula-2.
8978
8979The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 8980with any language, is not useful with Modula-2. Its
c906108c 8981intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 8982created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 8983address can be specified by an integral constant, the construct
d4f3574e 8984@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
8985
8986@cindex @code{#} in Modula-2
8987In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
8988interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 8989
4e562065
JB
8990@node Unsupported languages
8991@section Unsupported languages
8992
8993@cindex unsupported languages
8994@cindex minimal language
8995In addition to the other fully-supported programming languages,
8996@value{GDBN} also provides a pseudo-language, called @code{minimal}.
8997It does not represent a real programming language, but provides a set
8998of capabilities close to what the C or assembly languages provide.
8999This should allow most simple operations to be performed while debugging
9000an application that uses a language currently not supported by @value{GDBN}.
9001
9002If the language is set to @code{auto}, @value{GDBN} will automatically
9003select this language if the current frame corresponds to an unsupported
9004language.
9005
6d2ebf8b 9006@node Symbols
c906108c
SS
9007@chapter Examining the Symbol Table
9008
d4f3574e 9009The commands described in this chapter allow you to inquire about the
c906108c
SS
9010symbols (names of variables, functions and types) defined in your
9011program. This information is inherent in the text of your program and
9012does not change as your program executes. @value{GDBN} finds it in your
9013program's symbol table, in the file indicated when you started @value{GDBN}
9014(@pxref{File Options, ,Choosing files}), or by one of the
9015file-management commands (@pxref{Files, ,Commands to specify files}).
9016
9017@cindex symbol names
9018@cindex names of symbols
9019@cindex quoting names
9020Occasionally, you may need to refer to symbols that contain unusual
9021characters, which @value{GDBN} ordinarily treats as word delimiters. The
9022most frequent case is in referring to static variables in other
9023source files (@pxref{Variables,,Program variables}). File names
9024are recorded in object files as debugging symbols, but @value{GDBN} would
9025ordinarily parse a typical file name, like @file{foo.c}, as the three words
9026@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9027@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9028
474c8240 9029@smallexample
c906108c 9030p 'foo.c'::x
474c8240 9031@end smallexample
c906108c
SS
9032
9033@noindent
9034looks up the value of @code{x} in the scope of the file @file{foo.c}.
9035
9036@table @code
9037@kindex info address
b37052ae 9038@cindex address of a symbol
c906108c
SS
9039@item info address @var{symbol}
9040Describe where the data for @var{symbol} is stored. For a register
9041variable, this says which register it is kept in. For a non-register
9042local variable, this prints the stack-frame offset at which the variable
9043is always stored.
9044
9045Note the contrast with @samp{print &@var{symbol}}, which does not work
9046at all for a register variable, and for a stack local variable prints
9047the exact address of the current instantiation of the variable.
9048
3d67e040 9049@kindex info symbol
b37052ae 9050@cindex symbol from address
3d67e040
EZ
9051@item info symbol @var{addr}
9052Print the name of a symbol which is stored at the address @var{addr}.
9053If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9054nearest symbol and an offset from it:
9055
474c8240 9056@smallexample
3d67e040
EZ
9057(@value{GDBP}) info symbol 0x54320
9058_initialize_vx + 396 in section .text
474c8240 9059@end smallexample
3d67e040
EZ
9060
9061@noindent
9062This is the opposite of the @code{info address} command. You can use
9063it to find out the name of a variable or a function given its address.
9064
c906108c 9065@kindex whatis
d4f3574e
SS
9066@item whatis @var{expr}
9067Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9068actually evaluated, and any side-effecting operations (such as
9069assignments or function calls) inside it do not take place.
9070@xref{Expressions, ,Expressions}.
9071
9072@item whatis
9073Print the data type of @code{$}, the last value in the value history.
9074
9075@kindex ptype
9076@item ptype @var{typename}
9077Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9078the name of a type, or for C code it may have the form @samp{class
9079@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9080@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9081
d4f3574e 9082@item ptype @var{expr}
c906108c 9083@itemx ptype
d4f3574e 9084Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9085differs from @code{whatis} by printing a detailed description, instead
9086of just the name of the type.
9087
9088For example, for this variable declaration:
9089
474c8240 9090@smallexample
c906108c 9091struct complex @{double real; double imag;@} v;
474c8240 9092@end smallexample
c906108c
SS
9093
9094@noindent
9095the two commands give this output:
9096
474c8240 9097@smallexample
c906108c
SS
9098@group
9099(@value{GDBP}) whatis v
9100type = struct complex
9101(@value{GDBP}) ptype v
9102type = struct complex @{
9103 double real;
9104 double imag;
9105@}
9106@end group
474c8240 9107@end smallexample
c906108c
SS
9108
9109@noindent
9110As with @code{whatis}, using @code{ptype} without an argument refers to
9111the type of @code{$}, the last value in the value history.
9112
9113@kindex info types
9114@item info types @var{regexp}
9115@itemx info types
d4f3574e 9116Print a brief description of all types whose names match @var{regexp}
c906108c
SS
9117(or all types in your program, if you supply no argument). Each
9118complete typename is matched as though it were a complete line; thus,
9119@samp{i type value} gives information on all types in your program whose
d4f3574e 9120names include the string @code{value}, but @samp{i type ^value$} gives
c906108c
SS
9121information only on types whose complete name is @code{value}.
9122
9123This command differs from @code{ptype} in two ways: first, like
9124@code{whatis}, it does not print a detailed description; second, it
9125lists all source files where a type is defined.
9126
b37052ae
EZ
9127@kindex info scope
9128@cindex local variables
9129@item info scope @var{addr}
9130List all the variables local to a particular scope. This command
9131accepts a location---a function name, a source line, or an address
9132preceded by a @samp{*}, and prints all the variables local to the
9133scope defined by that location. For example:
9134
9135@smallexample
9136(@value{GDBP}) @b{info scope command_line_handler}
9137Scope for command_line_handler:
9138Symbol rl is an argument at stack/frame offset 8, length 4.
9139Symbol linebuffer is in static storage at address 0x150a18, length 4.
9140Symbol linelength is in static storage at address 0x150a1c, length 4.
9141Symbol p is a local variable in register $esi, length 4.
9142Symbol p1 is a local variable in register $ebx, length 4.
9143Symbol nline is a local variable in register $edx, length 4.
9144Symbol repeat is a local variable at frame offset -8, length 4.
9145@end smallexample
9146
f5c37c66
EZ
9147@noindent
9148This command is especially useful for determining what data to collect
9149during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9150collect}.
9151
c906108c
SS
9152@kindex info source
9153@item info source
919d772c
JB
9154Show information about the current source file---that is, the source file for
9155the function containing the current point of execution:
9156@itemize @bullet
9157@item
9158the name of the source file, and the directory containing it,
9159@item
9160the directory it was compiled in,
9161@item
9162its length, in lines,
9163@item
9164which programming language it is written in,
9165@item
9166whether the executable includes debugging information for that file, and
9167if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9168@item
9169whether the debugging information includes information about
9170preprocessor macros.
9171@end itemize
9172
c906108c
SS
9173
9174@kindex info sources
9175@item info sources
9176Print the names of all source files in your program for which there is
9177debugging information, organized into two lists: files whose symbols
9178have already been read, and files whose symbols will be read when needed.
9179
9180@kindex info functions
9181@item info functions
9182Print the names and data types of all defined functions.
9183
9184@item info functions @var{regexp}
9185Print the names and data types of all defined functions
9186whose names contain a match for regular expression @var{regexp}.
9187Thus, @samp{info fun step} finds all functions whose names
9188include @code{step}; @samp{info fun ^step} finds those whose names
1c5dfdad
MS
9189start with @code{step}. If a function name contains characters
9190that conflict with the regular expression language (eg.
9191@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9192
9193@kindex info variables
9194@item info variables
9195Print the names and data types of all variables that are declared
6ca652b0 9196outside of functions (i.e.@: excluding local variables).
c906108c
SS
9197
9198@item info variables @var{regexp}
9199Print the names and data types of all variables (except for local
9200variables) whose names contain a match for regular expression
9201@var{regexp}.
9202
b37303ee
AF
9203@kindex info classes
9204@item info classes
9205@itemx info classes @var{regexp}
9206Display all Objective-C classes in your program, or
9207(with the @var{regexp} argument) all those matching a particular regular
9208expression.
9209
9210@kindex info selectors
9211@item info selectors
9212@itemx info selectors @var{regexp}
9213Display all Objective-C selectors in your program, or
9214(with the @var{regexp} argument) all those matching a particular regular
9215expression.
9216
c906108c
SS
9217@ignore
9218This was never implemented.
9219@kindex info methods
9220@item info methods
9221@itemx info methods @var{regexp}
9222The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9223methods within C@t{++} program, or (with the @var{regexp} argument) a
9224specific set of methods found in the various C@t{++} classes. Many
9225C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9226from the @code{ptype} command can be overwhelming and hard to use. The
9227@code{info-methods} command filters the methods, printing only those
9228which match the regular-expression @var{regexp}.
9229@end ignore
9230
c906108c
SS
9231@cindex reloading symbols
9232Some systems allow individual object files that make up your program to
7a292a7a
SS
9233be replaced without stopping and restarting your program. For example,
9234in VxWorks you can simply recompile a defective object file and keep on
9235running. If you are running on one of these systems, you can allow
9236@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9237
9238@table @code
9239@kindex set symbol-reloading
9240@item set symbol-reloading on
9241Replace symbol definitions for the corresponding source file when an
9242object file with a particular name is seen again.
9243
9244@item set symbol-reloading off
6d2ebf8b
SS
9245Do not replace symbol definitions when encountering object files of the
9246same name more than once. This is the default state; if you are not
9247running on a system that permits automatic relinking of modules, you
9248should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
9249may discard symbols when linking large programs, that may contain
9250several modules (from different directories or libraries) with the same
9251name.
c906108c
SS
9252
9253@kindex show symbol-reloading
9254@item show symbol-reloading
9255Show the current @code{on} or @code{off} setting.
9256@end table
c906108c 9257
c906108c
SS
9258@kindex set opaque-type-resolution
9259@item set opaque-type-resolution on
9260Tell @value{GDBN} to resolve opaque types. An opaque type is a type
9261declared as a pointer to a @code{struct}, @code{class}, or
9262@code{union}---for example, @code{struct MyType *}---that is used in one
9263source file although the full declaration of @code{struct MyType} is in
9264another source file. The default is on.
9265
9266A change in the setting of this subcommand will not take effect until
9267the next time symbols for a file are loaded.
9268
9269@item set opaque-type-resolution off
9270Tell @value{GDBN} not to resolve opaque types. In this case, the type
9271is printed as follows:
9272@smallexample
9273@{<no data fields>@}
9274@end smallexample
9275
9276@kindex show opaque-type-resolution
9277@item show opaque-type-resolution
9278Show whether opaque types are resolved or not.
c906108c
SS
9279
9280@kindex maint print symbols
9281@cindex symbol dump
9282@kindex maint print psymbols
9283@cindex partial symbol dump
9284@item maint print symbols @var{filename}
9285@itemx maint print psymbols @var{filename}
9286@itemx maint print msymbols @var{filename}
9287Write a dump of debugging symbol data into the file @var{filename}.
9288These commands are used to debug the @value{GDBN} symbol-reading code. Only
9289symbols with debugging data are included. If you use @samp{maint print
9290symbols}, @value{GDBN} includes all the symbols for which it has already
9291collected full details: that is, @var{filename} reflects symbols for
9292only those files whose symbols @value{GDBN} has read. You can use the
9293command @code{info sources} to find out which files these are. If you
9294use @samp{maint print psymbols} instead, the dump shows information about
9295symbols that @value{GDBN} only knows partially---that is, symbols defined in
9296files that @value{GDBN} has skimmed, but not yet read completely. Finally,
9297@samp{maint print msymbols} dumps just the minimal symbol information
9298required for each object file from which @value{GDBN} has read some symbols.
9299@xref{Files, ,Commands to specify files}, for a discussion of how
9300@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 9301
5e7b2f39
JB
9302@kindex maint info symtabs
9303@kindex maint info psymtabs
44ea7b70
JB
9304@cindex listing @value{GDBN}'s internal symbol tables
9305@cindex symbol tables, listing @value{GDBN}'s internal
9306@cindex full symbol tables, listing @value{GDBN}'s internal
9307@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
9308@item maint info symtabs @r{[} @var{regexp} @r{]}
9309@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
9310
9311List the @code{struct symtab} or @code{struct partial_symtab}
9312structures whose names match @var{regexp}. If @var{regexp} is not
9313given, list them all. The output includes expressions which you can
9314copy into a @value{GDBN} debugging this one to examine a particular
9315structure in more detail. For example:
9316
9317@smallexample
5e7b2f39 9318(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
9319@{ objfile /home/gnu/build/gdb/gdb
9320 ((struct objfile *) 0x82e69d0)
9321 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
9322 ((struct partial_symtab *) 0x8474b10)
9323 readin no
9324 fullname (null)
9325 text addresses 0x814d3c8 -- 0x8158074
9326 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
9327 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
9328 dependencies (none)
9329 @}
9330@}
5e7b2f39 9331(@value{GDBP}) maint info symtabs
44ea7b70
JB
9332(@value{GDBP})
9333@end smallexample
9334@noindent
9335We see that there is one partial symbol table whose filename contains
9336the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
9337and we see that @value{GDBN} has not read in any symtabs yet at all.
9338If we set a breakpoint on a function, that will cause @value{GDBN} to
9339read the symtab for the compilation unit containing that function:
9340
9341@smallexample
9342(@value{GDBP}) break dwarf2_psymtab_to_symtab
9343Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
9344line 1574.
5e7b2f39 9345(@value{GDBP}) maint info symtabs
44ea7b70
JB
9346@{ objfile /home/gnu/build/gdb/gdb
9347 ((struct objfile *) 0x82e69d0)
9348 @{ symtab /home/gnu/src/gdb/dwarf2read.c
9349 ((struct symtab *) 0x86c1f38)
9350 dirname (null)
9351 fullname (null)
9352 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
9353 debugformat DWARF 2
9354 @}
9355@}
9356(@value{GDBP})
9357@end smallexample
c906108c
SS
9358@end table
9359
44ea7b70 9360
6d2ebf8b 9361@node Altering
c906108c
SS
9362@chapter Altering Execution
9363
9364Once you think you have found an error in your program, you might want to
9365find out for certain whether correcting the apparent error would lead to
9366correct results in the rest of the run. You can find the answer by
9367experiment, using the @value{GDBN} features for altering execution of the
9368program.
9369
9370For example, you can store new values into variables or memory
7a292a7a
SS
9371locations, give your program a signal, restart it at a different
9372address, or even return prematurely from a function.
c906108c
SS
9373
9374@menu
9375* Assignment:: Assignment to variables
9376* Jumping:: Continuing at a different address
c906108c 9377* Signaling:: Giving your program a signal
c906108c
SS
9378* Returning:: Returning from a function
9379* Calling:: Calling your program's functions
9380* Patching:: Patching your program
9381@end menu
9382
6d2ebf8b 9383@node Assignment
c906108c
SS
9384@section Assignment to variables
9385
9386@cindex assignment
9387@cindex setting variables
9388To alter the value of a variable, evaluate an assignment expression.
9389@xref{Expressions, ,Expressions}. For example,
9390
474c8240 9391@smallexample
c906108c 9392print x=4
474c8240 9393@end smallexample
c906108c
SS
9394
9395@noindent
9396stores the value 4 into the variable @code{x}, and then prints the
5d161b24 9397value of the assignment expression (which is 4).
c906108c
SS
9398@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
9399information on operators in supported languages.
c906108c
SS
9400
9401@kindex set variable
9402@cindex variables, setting
9403If you are not interested in seeing the value of the assignment, use the
9404@code{set} command instead of the @code{print} command. @code{set} is
9405really the same as @code{print} except that the expression's value is
9406not printed and is not put in the value history (@pxref{Value History,
9407,Value history}). The expression is evaluated only for its effects.
9408
c906108c
SS
9409If the beginning of the argument string of the @code{set} command
9410appears identical to a @code{set} subcommand, use the @code{set
9411variable} command instead of just @code{set}. This command is identical
9412to @code{set} except for its lack of subcommands. For example, if your
9413program has a variable @code{width}, you get an error if you try to set
9414a new value with just @samp{set width=13}, because @value{GDBN} has the
9415command @code{set width}:
9416
474c8240 9417@smallexample
c906108c
SS
9418(@value{GDBP}) whatis width
9419type = double
9420(@value{GDBP}) p width
9421$4 = 13
9422(@value{GDBP}) set width=47
9423Invalid syntax in expression.
474c8240 9424@end smallexample
c906108c
SS
9425
9426@noindent
9427The invalid expression, of course, is @samp{=47}. In
9428order to actually set the program's variable @code{width}, use
9429
474c8240 9430@smallexample
c906108c 9431(@value{GDBP}) set var width=47
474c8240 9432@end smallexample
53a5351d 9433
c906108c
SS
9434Because the @code{set} command has many subcommands that can conflict
9435with the names of program variables, it is a good idea to use the
9436@code{set variable} command instead of just @code{set}. For example, if
9437your program has a variable @code{g}, you run into problems if you try
9438to set a new value with just @samp{set g=4}, because @value{GDBN} has
9439the command @code{set gnutarget}, abbreviated @code{set g}:
9440
474c8240 9441@smallexample
c906108c
SS
9442@group
9443(@value{GDBP}) whatis g
9444type = double
9445(@value{GDBP}) p g
9446$1 = 1
9447(@value{GDBP}) set g=4
2df3850c 9448(@value{GDBP}) p g
c906108c
SS
9449$2 = 1
9450(@value{GDBP}) r
9451The program being debugged has been started already.
9452Start it from the beginning? (y or n) y
9453Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
9454"/home/smith/cc_progs/a.out": can't open to read symbols:
9455 Invalid bfd target.
c906108c
SS
9456(@value{GDBP}) show g
9457The current BFD target is "=4".
9458@end group
474c8240 9459@end smallexample
c906108c
SS
9460
9461@noindent
9462The program variable @code{g} did not change, and you silently set the
9463@code{gnutarget} to an invalid value. In order to set the variable
9464@code{g}, use
9465
474c8240 9466@smallexample
c906108c 9467(@value{GDBP}) set var g=4
474c8240 9468@end smallexample
c906108c
SS
9469
9470@value{GDBN} allows more implicit conversions in assignments than C; you can
9471freely store an integer value into a pointer variable or vice versa,
9472and you can convert any structure to any other structure that is the
9473same length or shorter.
9474@comment FIXME: how do structs align/pad in these conversions?
9475@comment /doc@cygnus.com 18dec1990
9476
9477To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
9478construct to generate a value of specified type at a specified address
9479(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
9480to memory location @code{0x83040} as an integer (which implies a certain size
9481and representation in memory), and
9482
474c8240 9483@smallexample
c906108c 9484set @{int@}0x83040 = 4
474c8240 9485@end smallexample
c906108c
SS
9486
9487@noindent
9488stores the value 4 into that memory location.
9489
6d2ebf8b 9490@node Jumping
c906108c
SS
9491@section Continuing at a different address
9492
9493Ordinarily, when you continue your program, you do so at the place where
9494it stopped, with the @code{continue} command. You can instead continue at
9495an address of your own choosing, with the following commands:
9496
9497@table @code
9498@kindex jump
9499@item jump @var{linespec}
9500Resume execution at line @var{linespec}. Execution stops again
9501immediately if there is a breakpoint there. @xref{List, ,Printing
9502source lines}, for a description of the different forms of
9503@var{linespec}. It is common practice to use the @code{tbreak} command
9504in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
9505breakpoints}.
9506
9507The @code{jump} command does not change the current stack frame, or
9508the stack pointer, or the contents of any memory location or any
9509register other than the program counter. If line @var{linespec} is in
9510a different function from the one currently executing, the results may
9511be bizarre if the two functions expect different patterns of arguments or
9512of local variables. For this reason, the @code{jump} command requests
9513confirmation if the specified line is not in the function currently
9514executing. However, even bizarre results are predictable if you are
9515well acquainted with the machine-language code of your program.
9516
9517@item jump *@var{address}
9518Resume execution at the instruction at address @var{address}.
9519@end table
9520
c906108c 9521@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
9522On many systems, you can get much the same effect as the @code{jump}
9523command by storing a new value into the register @code{$pc}. The
9524difference is that this does not start your program running; it only
9525changes the address of where it @emph{will} run when you continue. For
9526example,
c906108c 9527
474c8240 9528@smallexample
c906108c 9529set $pc = 0x485
474c8240 9530@end smallexample
c906108c
SS
9531
9532@noindent
9533makes the next @code{continue} command or stepping command execute at
9534address @code{0x485}, rather than at the address where your program stopped.
9535@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
9536
9537The most common occasion to use the @code{jump} command is to back
9538up---perhaps with more breakpoints set---over a portion of a program
9539that has already executed, in order to examine its execution in more
9540detail.
9541
c906108c 9542@c @group
6d2ebf8b 9543@node Signaling
c906108c
SS
9544@section Giving your program a signal
9545
9546@table @code
9547@kindex signal
9548@item signal @var{signal}
9549Resume execution where your program stopped, but immediately give it the
9550signal @var{signal}. @var{signal} can be the name or the number of a
9551signal. For example, on many systems @code{signal 2} and @code{signal
9552SIGINT} are both ways of sending an interrupt signal.
9553
9554Alternatively, if @var{signal} is zero, continue execution without
9555giving a signal. This is useful when your program stopped on account of
9556a signal and would ordinary see the signal when resumed with the
9557@code{continue} command; @samp{signal 0} causes it to resume without a
9558signal.
9559
9560@code{signal} does not repeat when you press @key{RET} a second time
9561after executing the command.
9562@end table
9563@c @end group
9564
9565Invoking the @code{signal} command is not the same as invoking the
9566@code{kill} utility from the shell. Sending a signal with @code{kill}
9567causes @value{GDBN} to decide what to do with the signal depending on
9568the signal handling tables (@pxref{Signals}). The @code{signal} command
9569passes the signal directly to your program.
9570
c906108c 9571
6d2ebf8b 9572@node Returning
c906108c
SS
9573@section Returning from a function
9574
9575@table @code
9576@cindex returning from a function
9577@kindex return
9578@item return
9579@itemx return @var{expression}
9580You can cancel execution of a function call with the @code{return}
9581command. If you give an
9582@var{expression} argument, its value is used as the function's return
9583value.
9584@end table
9585
9586When you use @code{return}, @value{GDBN} discards the selected stack frame
9587(and all frames within it). You can think of this as making the
9588discarded frame return prematurely. If you wish to specify a value to
9589be returned, give that value as the argument to @code{return}.
9590
9591This pops the selected stack frame (@pxref{Selection, ,Selecting a
9592frame}), and any other frames inside of it, leaving its caller as the
9593innermost remaining frame. That frame becomes selected. The
9594specified value is stored in the registers used for returning values
9595of functions.
9596
9597The @code{return} command does not resume execution; it leaves the
9598program stopped in the state that would exist if the function had just
9599returned. In contrast, the @code{finish} command (@pxref{Continuing
9600and Stepping, ,Continuing and stepping}) resumes execution until the
9601selected stack frame returns naturally.
9602
6d2ebf8b 9603@node Calling
c906108c
SS
9604@section Calling program functions
9605
9606@cindex calling functions
9607@kindex call
9608@table @code
9609@item call @var{expr}
9610Evaluate the expression @var{expr} without displaying @code{void}
9611returned values.
9612@end table
9613
9614You can use this variant of the @code{print} command if you want to
9615execute a function from your program, but without cluttering the output
5d161b24
DB
9616with @code{void} returned values. If the result is not void, it
9617is printed and saved in the value history.
c906108c 9618
6d2ebf8b 9619@node Patching
c906108c 9620@section Patching programs
7a292a7a 9621
c906108c
SS
9622@cindex patching binaries
9623@cindex writing into executables
c906108c 9624@cindex writing into corefiles
c906108c 9625
7a292a7a
SS
9626By default, @value{GDBN} opens the file containing your program's
9627executable code (or the corefile) read-only. This prevents accidental
9628alterations to machine code; but it also prevents you from intentionally
9629patching your program's binary.
c906108c
SS
9630
9631If you'd like to be able to patch the binary, you can specify that
9632explicitly with the @code{set write} command. For example, you might
9633want to turn on internal debugging flags, or even to make emergency
9634repairs.
9635
9636@table @code
9637@kindex set write
9638@item set write on
9639@itemx set write off
7a292a7a
SS
9640If you specify @samp{set write on}, @value{GDBN} opens executable and
9641core files for both reading and writing; if you specify @samp{set write
c906108c
SS
9642off} (the default), @value{GDBN} opens them read-only.
9643
9644If you have already loaded a file, you must load it again (using the
7a292a7a
SS
9645@code{exec-file} or @code{core-file} command) after changing @code{set
9646write}, for your new setting to take effect.
c906108c
SS
9647
9648@item show write
9649@kindex show write
7a292a7a
SS
9650Display whether executable files and core files are opened for writing
9651as well as reading.
c906108c
SS
9652@end table
9653
6d2ebf8b 9654@node GDB Files
c906108c
SS
9655@chapter @value{GDBN} Files
9656
7a292a7a
SS
9657@value{GDBN} needs to know the file name of the program to be debugged,
9658both in order to read its symbol table and in order to start your
9659program. To debug a core dump of a previous run, you must also tell
9660@value{GDBN} the name of the core dump file.
c906108c
SS
9661
9662@menu
9663* Files:: Commands to specify files
5b5d99cf 9664* Separate Debug Files:: Debugging information in separate files
c906108c
SS
9665* Symbol Errors:: Errors reading symbol files
9666@end menu
9667
6d2ebf8b 9668@node Files
c906108c 9669@section Commands to specify files
c906108c 9670
7a292a7a 9671@cindex symbol table
c906108c 9672@cindex core dump file
7a292a7a
SS
9673
9674You may want to specify executable and core dump file names. The usual
9675way to do this is at start-up time, using the arguments to
9676@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
9677Out of @value{GDBN}}).
c906108c
SS
9678
9679Occasionally it is necessary to change to a different file during a
9680@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
9681a file you want to use. In these situations the @value{GDBN} commands
9682to specify new files are useful.
9683
9684@table @code
9685@cindex executable file
9686@kindex file
9687@item file @var{filename}
9688Use @var{filename} as the program to be debugged. It is read for its
9689symbols and for the contents of pure memory. It is also the program
9690executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
9691directory and the file is not found in the @value{GDBN} working directory,
9692@value{GDBN} uses the environment variable @code{PATH} as a list of
9693directories to search, just as the shell does when looking for a program
9694to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
9695and your program, using the @code{path} command.
9696
6d2ebf8b 9697On systems with memory-mapped files, an auxiliary file named
c906108c
SS
9698@file{@var{filename}.syms} may hold symbol table information for
9699@var{filename}. If so, @value{GDBN} maps in the symbol table from
9700@file{@var{filename}.syms}, starting up more quickly. See the
9701descriptions of the file options @samp{-mapped} and @samp{-readnow}
9702(available on the command line, and with the commands @code{file},
5d161b24 9703@code{symbol-file}, or @code{add-symbol-file}, described below),
c906108c 9704for more information.
c906108c
SS
9705
9706@item file
9707@code{file} with no argument makes @value{GDBN} discard any information it
9708has on both executable file and the symbol table.
9709
9710@kindex exec-file
9711@item exec-file @r{[} @var{filename} @r{]}
9712Specify that the program to be run (but not the symbol table) is found
9713in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
9714if necessary to locate your program. Omitting @var{filename} means to
9715discard information on the executable file.
9716
9717@kindex symbol-file
9718@item symbol-file @r{[} @var{filename} @r{]}
9719Read symbol table information from file @var{filename}. @code{PATH} is
9720searched when necessary. Use the @code{file} command to get both symbol
9721table and program to run from the same file.
9722
9723@code{symbol-file} with no argument clears out @value{GDBN} information on your
9724program's symbol table.
9725
5d161b24 9726The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
9727of its convenience variables, the value history, and all breakpoints and
9728auto-display expressions. This is because they may contain pointers to
9729the internal data recording symbols and data types, which are part of
9730the old symbol table data being discarded inside @value{GDBN}.
9731
9732@code{symbol-file} does not repeat if you press @key{RET} again after
9733executing it once.
9734
9735When @value{GDBN} is configured for a particular environment, it
9736understands debugging information in whatever format is the standard
9737generated for that environment; you may use either a @sc{gnu} compiler, or
9738other compilers that adhere to the local conventions.
c906108c
SS
9739Best results are usually obtained from @sc{gnu} compilers; for example,
9740using @code{@value{GCC}} you can generate debugging information for
9741optimized code.
c906108c
SS
9742
9743For most kinds of object files, with the exception of old SVR3 systems
9744using COFF, the @code{symbol-file} command does not normally read the
9745symbol table in full right away. Instead, it scans the symbol table
9746quickly to find which source files and which symbols are present. The
9747details are read later, one source file at a time, as they are needed.
9748
9749The purpose of this two-stage reading strategy is to make @value{GDBN}
9750start up faster. For the most part, it is invisible except for
9751occasional pauses while the symbol table details for a particular source
9752file are being read. (The @code{set verbose} command can turn these
9753pauses into messages if desired. @xref{Messages/Warnings, ,Optional
9754warnings and messages}.)
9755
c906108c
SS
9756We have not implemented the two-stage strategy for COFF yet. When the
9757symbol table is stored in COFF format, @code{symbol-file} reads the
9758symbol table data in full right away. Note that ``stabs-in-COFF''
9759still does the two-stage strategy, since the debug info is actually
9760in stabs format.
9761
9762@kindex readnow
9763@cindex reading symbols immediately
9764@cindex symbols, reading immediately
9765@kindex mapped
9766@cindex memory-mapped symbol file
9767@cindex saving symbol table
9768@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9769@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
9770You can override the @value{GDBN} two-stage strategy for reading symbol
9771tables by using the @samp{-readnow} option with any of the commands that
9772load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 9773entire symbol table available.
c906108c 9774
c906108c
SS
9775If memory-mapped files are available on your system through the
9776@code{mmap} system call, you can use another option, @samp{-mapped}, to
9777cause @value{GDBN} to write the symbols for your program into a reusable
9778file. Future @value{GDBN} debugging sessions map in symbol information
9779from this auxiliary symbol file (if the program has not changed), rather
9780than spending time reading the symbol table from the executable
9781program. Using the @samp{-mapped} option has the same effect as
9782starting @value{GDBN} with the @samp{-mapped} command-line option.
9783
9784You can use both options together, to make sure the auxiliary symbol
9785file has all the symbol information for your program.
9786
9787The auxiliary symbol file for a program called @var{myprog} is called
9788@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
9789than the corresponding executable), @value{GDBN} always attempts to use
9790it when you debug @var{myprog}; no special options or commands are
9791needed.
9792
9793The @file{.syms} file is specific to the host machine where you run
9794@value{GDBN}. It holds an exact image of the internal @value{GDBN}
9795symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
9796
9797@c FIXME: for now no mention of directories, since this seems to be in
9798@c flux. 13mar1992 status is that in theory GDB would look either in
9799@c current dir or in same dir as myprog; but issues like competing
9800@c GDB's, or clutter in system dirs, mean that in practice right now
9801@c only current dir is used. FFish says maybe a special GDB hierarchy
9802@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
9803@c files.
9804
9805@kindex core
9806@kindex core-file
9807@item core-file @r{[} @var{filename} @r{]}
9808Specify the whereabouts of a core dump file to be used as the ``contents
9809of memory''. Traditionally, core files contain only some parts of the
9810address space of the process that generated them; @value{GDBN} can access the
9811executable file itself for other parts.
9812
9813@code{core-file} with no argument specifies that no core file is
9814to be used.
9815
9816Note that the core file is ignored when your program is actually running
7a292a7a
SS
9817under @value{GDBN}. So, if you have been running your program and you
9818wish to debug a core file instead, you must kill the subprocess in which
9819the program is running. To do this, use the @code{kill} command
c906108c 9820(@pxref{Kill Process, ,Killing the child process}).
c906108c 9821
c906108c
SS
9822@kindex add-symbol-file
9823@cindex dynamic linking
9824@item add-symbol-file @var{filename} @var{address}
9825@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 9826@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
9827The @code{add-symbol-file} command reads additional symbol table
9828information from the file @var{filename}. You would use this command
9829when @var{filename} has been dynamically loaded (by some other means)
9830into the program that is running. @var{address} should be the memory
9831address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
9832this out for itself. You can additionally specify an arbitrary number
9833of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
9834section name and base address for that section. You can specify any
9835@var{address} as an expression.
c906108c
SS
9836
9837The symbol table of the file @var{filename} is added to the symbol table
9838originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
9839@code{add-symbol-file} command any number of times; the new symbol data
9840thus read keeps adding to the old. To discard all old symbol data
9841instead, use the @code{symbol-file} command without any arguments.
c906108c 9842
17d9d558
JB
9843@cindex relocatable object files, reading symbols from
9844@cindex object files, relocatable, reading symbols from
9845@cindex reading symbols from relocatable object files
9846@cindex symbols, reading from relocatable object files
9847@cindex @file{.o} files, reading symbols from
9848Although @var{filename} is typically a shared library file, an
9849executable file, or some other object file which has been fully
9850relocated for loading into a process, you can also load symbolic
9851information from relocatable @file{.o} files, as long as:
9852
9853@itemize @bullet
9854@item
9855the file's symbolic information refers only to linker symbols defined in
9856that file, not to symbols defined by other object files,
9857@item
9858every section the file's symbolic information refers to has actually
9859been loaded into the inferior, as it appears in the file, and
9860@item
9861you can determine the address at which every section was loaded, and
9862provide these to the @code{add-symbol-file} command.
9863@end itemize
9864
9865@noindent
9866Some embedded operating systems, like Sun Chorus and VxWorks, can load
9867relocatable files into an already running program; such systems
9868typically make the requirements above easy to meet. However, it's
9869important to recognize that many native systems use complex link
9870procedures (@code{.linkonce} section factoring and C++ constructor table
9871assembly, for example) that make the requirements difficult to meet. In
9872general, one cannot assume that using @code{add-symbol-file} to read a
9873relocatable object file's symbolic information will have the same effect
9874as linking the relocatable object file into the program in the normal
9875way.
9876
c906108c
SS
9877@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
9878
9879You can use the @samp{-mapped} and @samp{-readnow} options just as with
9880the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
9881table information for @var{filename}.
9882
9883@kindex add-shared-symbol-file
9884@item add-shared-symbol-file
9885The @code{add-shared-symbol-file} command can be used only under Harris' CXUX
5d161b24
DB
9886operating system for the Motorola 88k. @value{GDBN} automatically looks for
9887shared libraries, however if @value{GDBN} does not find yours, you can run
c906108c 9888@code{add-shared-symbol-file}. It takes no arguments.
c906108c 9889
c906108c
SS
9890@kindex section
9891@item section
5d161b24
DB
9892The @code{section} command changes the base address of section SECTION of
9893the exec file to ADDR. This can be used if the exec file does not contain
9894section addresses, (such as in the a.out format), or when the addresses
9895specified in the file itself are wrong. Each section must be changed
d4f3574e
SS
9896separately. The @code{info files} command, described below, lists all
9897the sections and their addresses.
c906108c
SS
9898
9899@kindex info files
9900@kindex info target
9901@item info files
9902@itemx info target
7a292a7a
SS
9903@code{info files} and @code{info target} are synonymous; both print the
9904current target (@pxref{Targets, ,Specifying a Debugging Target}),
9905including the names of the executable and core dump files currently in
9906use by @value{GDBN}, and the files from which symbols were loaded. The
9907command @code{help target} lists all possible targets rather than
9908current ones.
9909
fe95c787
MS
9910@kindex maint info sections
9911@item maint info sections
9912Another command that can give you extra information about program sections
9913is @code{maint info sections}. In addition to the section information
9914displayed by @code{info files}, this command displays the flags and file
9915offset of each section in the executable and core dump files. In addition,
9916@code{maint info sections} provides the following command options (which
9917may be arbitrarily combined):
9918
9919@table @code
9920@item ALLOBJ
9921Display sections for all loaded object files, including shared libraries.
9922@item @var{sections}
6600abed 9923Display info only for named @var{sections}.
fe95c787
MS
9924@item @var{section-flags}
9925Display info only for sections for which @var{section-flags} are true.
9926The section flags that @value{GDBN} currently knows about are:
9927@table @code
9928@item ALLOC
9929Section will have space allocated in the process when loaded.
9930Set for all sections except those containing debug information.
9931@item LOAD
9932Section will be loaded from the file into the child process memory.
9933Set for pre-initialized code and data, clear for @code{.bss} sections.
9934@item RELOC
9935Section needs to be relocated before loading.
9936@item READONLY
9937Section cannot be modified by the child process.
9938@item CODE
9939Section contains executable code only.
6600abed 9940@item DATA
fe95c787
MS
9941Section contains data only (no executable code).
9942@item ROM
9943Section will reside in ROM.
9944@item CONSTRUCTOR
9945Section contains data for constructor/destructor lists.
9946@item HAS_CONTENTS
9947Section is not empty.
9948@item NEVER_LOAD
9949An instruction to the linker to not output the section.
9950@item COFF_SHARED_LIBRARY
9951A notification to the linker that the section contains
9952COFF shared library information.
9953@item IS_COMMON
9954Section contains common symbols.
9955@end table
9956@end table
6763aef9
MS
9957@kindex set trust-readonly-sections
9958@item set trust-readonly-sections on
9959Tell @value{GDBN} that readonly sections in your object file
6ca652b0 9960really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
9961In that case, @value{GDBN} can fetch values from these sections
9962out of the object file, rather than from the target program.
9963For some targets (notably embedded ones), this can be a significant
9964enhancement to debugging performance.
9965
9966The default is off.
9967
9968@item set trust-readonly-sections off
15110bc3 9969Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
9970the contents of the section might change while the program is running,
9971and must therefore be fetched from the target when needed.
c906108c
SS
9972@end table
9973
9974All file-specifying commands allow both absolute and relative file names
9975as arguments. @value{GDBN} always converts the file name to an absolute file
9976name and remembers it that way.
9977
c906108c 9978@cindex shared libraries
c906108c
SS
9979@value{GDBN} supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
9980libraries.
53a5351d 9981
c906108c
SS
9982@value{GDBN} automatically loads symbol definitions from shared libraries
9983when you use the @code{run} command, or when you examine a core file.
9984(Before you issue the @code{run} command, @value{GDBN} does not understand
9985references to a function in a shared library, however---unless you are
9986debugging a core file).
53a5351d
JM
9987
9988On HP-UX, if the program loads a library explicitly, @value{GDBN}
9989automatically loads the symbols at the time of the @code{shl_load} call.
9990
c906108c
SS
9991@c FIXME: some @value{GDBN} release may permit some refs to undef
9992@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
9993@c FIXME...lib; check this from time to time when updating manual
9994
b7209cb4
FF
9995There are times, however, when you may wish to not automatically load
9996symbol definitions from shared libraries, such as when they are
9997particularly large or there are many of them.
9998
9999To control the automatic loading of shared library symbols, use the
10000commands:
10001
10002@table @code
10003@kindex set auto-solib-add
10004@item set auto-solib-add @var{mode}
10005If @var{mode} is @code{on}, symbols from all shared object libraries
10006will be loaded automatically when the inferior begins execution, you
10007attach to an independently started inferior, or when the dynamic linker
10008informs @value{GDBN} that a new library has been loaded. If @var{mode}
10009is @code{off}, symbols must be loaded manually, using the
10010@code{sharedlibrary} command. The default value is @code{on}.
10011
10012@kindex show auto-solib-add
10013@item show auto-solib-add
10014Display the current autoloading mode.
10015@end table
10016
10017To explicitly load shared library symbols, use the @code{sharedlibrary}
10018command:
10019
c906108c
SS
10020@table @code
10021@kindex info sharedlibrary
10022@kindex info share
10023@item info share
10024@itemx info sharedlibrary
10025Print the names of the shared libraries which are currently loaded.
10026
10027@kindex sharedlibrary
10028@kindex share
10029@item sharedlibrary @var{regex}
10030@itemx share @var{regex}
c906108c
SS
10031Load shared object library symbols for files matching a
10032Unix regular expression.
10033As with files loaded automatically, it only loads shared libraries
10034required by your program for a core file or after typing @code{run}. If
10035@var{regex} is omitted all shared libraries required by your program are
10036loaded.
10037@end table
10038
b7209cb4
FF
10039On some systems, such as HP-UX systems, @value{GDBN} supports
10040autoloading shared library symbols until a limiting threshold size is
10041reached. This provides the benefit of allowing autoloading to remain on
10042by default, but avoids autoloading excessively large shared libraries,
10043up to a threshold that is initially set, but which you can modify if you
10044wish.
c906108c
SS
10045
10046Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10047loaded. To load these symbols, use the command @code{sharedlibrary
10048@var{filename}}. The base address of the shared library is determined
c906108c
SS
10049automatically by @value{GDBN} and need not be specified.
10050
10051To display or set the threshold, use the commands:
10052
10053@table @code
b7209cb4
FF
10054@kindex set auto-solib-limit
10055@item set auto-solib-limit @var{threshold}
10056Set the autoloading size threshold, in an integral number of megabytes.
10057If @var{threshold} is nonzero and shared library autoloading is enabled,
10058symbols from all shared object libraries will be loaded until the total
10059size of the loaded shared library symbols exceeds this threshold.
c906108c 10060Otherwise, symbols must be loaded manually, using the
6ca652b0 10061@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10062Mb).
c906108c 10063
b7209cb4
FF
10064@kindex show auto-solib-limit
10065@item show auto-solib-limit
c906108c
SS
10066Display the current autoloading size threshold, in megabytes.
10067@end table
c906108c 10068
f5ebfba0
DJ
10069Shared libraries are also supported in many cross or remote debugging
10070configurations. A copy of the target's libraries need to be present on the
10071host system; they need to be the same as the target libraries, although the
10072copies on the target can be stripped as long as the copies on the host are
10073not.
10074
10075You need to tell @value{GDBN} where the target libraries are, so that it can
10076load the correct copies---otherwise, it may try to load the host's libraries.
10077@value{GDBN} has two variables to specify the search directories for target
10078libraries.
10079
10080@table @code
10081@kindex set solib-absolute-prefix
10082@item set solib-absolute-prefix @var{path}
10083If this variable is set, @var{path} will be used as a prefix for any
10084absolute shared library paths; many runtime loaders store the absolute
10085paths to the shared library in the target program's memory. If you use
10086@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10087out in the same way that they are on the target, with e.g.@: a
10088@file{/usr/lib} hierarchy under @var{path}.
10089
10090You can set the default value of @samp{solib-absolute-prefix} by using the
10091configure-time @samp{--with-sysroot} option.
10092
10093@kindex show solib-absolute-prefix
10094@item show solib-absolute-prefix
10095Display the current shared library prefix.
10096
10097@kindex set solib-search-path
10098@item set solib-search-path @var{path}
10099If this variable is set, @var{path} is a colon-separated list of directories
10100to search for shared libraries. @samp{solib-search-path} is used after
10101@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10102the library is relative instead of absolute. If you want to use
10103@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10104set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10105@value{GDBN} from finding your host's libraries.
10106
10107@kindex show solib-search-path
10108@item show solib-search-path
10109Display the current shared library search path.
10110@end table
10111
5b5d99cf
JB
10112
10113@node Separate Debug Files
10114@section Debugging Information in Separate Files
10115@cindex separate debugging information files
10116@cindex debugging information in separate files
10117@cindex @file{.debug} subdirectories
10118@cindex debugging information directory, global
10119@cindex global debugging information directory
10120
10121@value{GDBN} allows you to put a program's debugging information in a
10122file separate from the executable itself, in a way that allows
10123@value{GDBN} to find and load the debugging information automatically.
10124Since debugging information can be very large --- sometimes larger
10125than the executable code itself --- some systems distribute debugging
10126information for their executables in separate files, which users can
10127install only when they need to debug a problem.
10128
10129If an executable's debugging information has been extracted to a
10130separate file, the executable should contain a @dfn{debug link} giving
10131the name of the debugging information file (with no directory
10132components), and a checksum of its contents. (The exact form of a
10133debug link is described below.) If the full name of the directory
10134containing the executable is @var{execdir}, and the executable has a
10135debug link that specifies the name @var{debugfile}, then @value{GDBN}
10136will automatically search for the debugging information file in three
10137places:
10138
10139@itemize @bullet
10140@item
10141the directory containing the executable file (that is, it will look
10142for a file named @file{@var{execdir}/@var{debugfile}},
10143@item
10144a subdirectory of that directory named @file{.debug} (that is, the
10145file @file{@var{execdir}/.debug/@var{debugfile}}, and
10146@item
10147a subdirectory of the global debug file directory that includes the
10148executable's full path, and the name from the link (that is, the file
10149@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10150@var{globaldebugdir} is the global debug file directory, and
10151@var{execdir} has been turned into a relative path).
10152@end itemize
10153@noindent
10154@value{GDBN} checks under each of these names for a debugging
10155information file whose checksum matches that given in the link, and
10156reads the debugging information from the first one it finds.
10157
10158So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10159which has a link containing the name @file{ls.debug}, and the global
10160debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10161for debug information in @file{/usr/bin/ls.debug},
10162@file{/usr/bin/.debug/ls.debug}, and
10163@file{/usr/lib/debug/usr/bin/ls.debug}.
10164
10165You can set the global debugging info directory's name, and view the
10166name @value{GDBN} is currently using.
10167
10168@table @code
10169
10170@kindex set debug-file-directory
10171@item set debug-file-directory @var{directory}
10172Set the directory which @value{GDBN} searches for separate debugging
10173information files to @var{directory}.
10174
10175@kindex show debug-file-directory
10176@item show debug-file-directory
10177Show the directory @value{GDBN} searches for separate debugging
10178information files.
10179
10180@end table
10181
10182@cindex @code{.gnu_debuglink} sections
10183@cindex debug links
10184A debug link is a special section of the executable file named
10185@code{.gnu_debuglink}. The section must contain:
10186
10187@itemize
10188@item
10189A filename, with any leading directory components removed, followed by
10190a zero byte,
10191@item
10192zero to three bytes of padding, as needed to reach the next four-byte
10193boundary within the section, and
10194@item
10195a four-byte CRC checksum, stored in the same endianness used for the
10196executable file itself. The checksum is computed on the debugging
10197information file's full contents by the function given below, passing
10198zero as the @var{crc} argument.
10199@end itemize
10200
10201Any executable file format can carry a debug link, as long as it can
10202contain a section named @code{.gnu_debuglink} with the contents
10203described above.
10204
10205The debugging information file itself should be an ordinary
10206executable, containing a full set of linker symbols, sections, and
10207debugging information. The sections of the debugging information file
10208should have the same names, addresses and sizes as the original file,
10209but they need not contain any data --- much like a @code{.bss} section
10210in an ordinary executable.
10211
10212As of December 2002, there is no standard GNU utility to produce
10213separated executable / debugging information file pairs. Ulrich
10214Drepper's @file{elfutils} package, starting with version 0.53,
10215contains a version of the @code{strip} command such that the command
10216@kbd{strip foo -f foo.debug} removes the debugging information from
10217the executable file @file{foo}, places it in the file
10218@file{foo.debug}, and leaves behind a debug link in @file{foo}.
10219
10220Since there are many different ways to compute CRC's (different
10221polynomials, reversals, byte ordering, etc.), the simplest way to
10222describe the CRC used in @code{.gnu_debuglink} sections is to give the
10223complete code for a function that computes it:
10224
10225@kindex @code{gnu_debuglink_crc32}
10226@smallexample
10227unsigned long
10228gnu_debuglink_crc32 (unsigned long crc,
10229 unsigned char *buf, size_t len)
10230@{
10231 static const unsigned long crc32_table[256] =
10232 @{
10233 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10234 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10235 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10236 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10237 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10238 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10239 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10240 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10241 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10242 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10243 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10244 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10245 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10246 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10247 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10248 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10249 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10250 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10251 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10252 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10253 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10254 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10255 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10256 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10257 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10258 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10259 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10260 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10261 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10262 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10263 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10264 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10265 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10266 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10267 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10268 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10269 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10270 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10271 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10272 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10273 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10274 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10275 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10276 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10277 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10278 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10279 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10280 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10281 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10282 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10283 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10284 0x2d02ef8d
10285 @};
10286 unsigned char *end;
10287
10288 crc = ~crc & 0xffffffff;
10289 for (end = buf + len; buf < end; ++buf)
10290 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 10291 return ~crc & 0xffffffff;
5b5d99cf
JB
10292@}
10293@end smallexample
10294
10295
6d2ebf8b 10296@node Symbol Errors
c906108c
SS
10297@section Errors reading symbol files
10298
10299While reading a symbol file, @value{GDBN} occasionally encounters problems,
10300such as symbol types it does not recognize, or known bugs in compiler
10301output. By default, @value{GDBN} does not notify you of such problems, since
10302they are relatively common and primarily of interest to people
10303debugging compilers. If you are interested in seeing information
10304about ill-constructed symbol tables, you can either ask @value{GDBN} to print
10305only one message about each such type of problem, no matter how many
10306times the problem occurs; or you can ask @value{GDBN} to print more messages,
10307to see how many times the problems occur, with the @code{set
10308complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
10309messages}).
10310
10311The messages currently printed, and their meanings, include:
10312
10313@table @code
10314@item inner block not inside outer block in @var{symbol}
10315
10316The symbol information shows where symbol scopes begin and end
10317(such as at the start of a function or a block of statements). This
10318error indicates that an inner scope block is not fully contained
10319in its outer scope blocks.
10320
10321@value{GDBN} circumvents the problem by treating the inner block as if it had
10322the same scope as the outer block. In the error message, @var{symbol}
10323may be shown as ``@code{(don't know)}'' if the outer block is not a
10324function.
10325
10326@item block at @var{address} out of order
10327
10328The symbol information for symbol scope blocks should occur in
10329order of increasing addresses. This error indicates that it does not
10330do so.
10331
10332@value{GDBN} does not circumvent this problem, and has trouble
10333locating symbols in the source file whose symbols it is reading. (You
10334can often determine what source file is affected by specifying
10335@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
10336messages}.)
10337
10338@item bad block start address patched
10339
10340The symbol information for a symbol scope block has a start address
10341smaller than the address of the preceding source line. This is known
10342to occur in the SunOS 4.1.1 (and earlier) C compiler.
10343
10344@value{GDBN} circumvents the problem by treating the symbol scope block as
10345starting on the previous source line.
10346
10347@item bad string table offset in symbol @var{n}
10348
10349@cindex foo
10350Symbol number @var{n} contains a pointer into the string table which is
10351larger than the size of the string table.
10352
10353@value{GDBN} circumvents the problem by considering the symbol to have the
10354name @code{foo}, which may cause other problems if many symbols end up
10355with this name.
10356
10357@item unknown symbol type @code{0x@var{nn}}
10358
7a292a7a
SS
10359The symbol information contains new data types that @value{GDBN} does
10360not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 10361uncomprehended information, in hexadecimal.
c906108c 10362
7a292a7a
SS
10363@value{GDBN} circumvents the error by ignoring this symbol information.
10364This usually allows you to debug your program, though certain symbols
c906108c 10365are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
10366debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
10367on @code{complain}, then go up to the function @code{read_dbx_symtab}
10368and examine @code{*bufp} to see the symbol.
c906108c
SS
10369
10370@item stub type has NULL name
c906108c 10371
7a292a7a 10372@value{GDBN} could not find the full definition for a struct or class.
c906108c 10373
7a292a7a 10374@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 10375The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
10376information that recent versions of the compiler should have output for
10377it.
c906108c
SS
10378
10379@item info mismatch between compiler and debugger
10380
10381@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 10382
c906108c
SS
10383@end table
10384
6d2ebf8b 10385@node Targets
c906108c 10386@chapter Specifying a Debugging Target
7a292a7a 10387
c906108c
SS
10388@cindex debugging target
10389@kindex target
10390
10391A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
10392
10393Often, @value{GDBN} runs in the same host environment as your program;
10394in that case, the debugging target is specified as a side effect when
10395you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
10396flexibility---for example, running @value{GDBN} on a physically separate
10397host, or controlling a standalone system over a serial port or a
53a5351d
JM
10398realtime system over a TCP/IP connection---you can use the @code{target}
10399command to specify one of the target types configured for @value{GDBN}
10400(@pxref{Target Commands, ,Commands for managing targets}).
c906108c
SS
10401
10402@menu
10403* Active Targets:: Active targets
10404* Target Commands:: Commands for managing targets
c906108c
SS
10405* Byte Order:: Choosing target byte order
10406* Remote:: Remote debugging
96baa820 10407* KOD:: Kernel Object Display
c906108c
SS
10408
10409@end menu
10410
6d2ebf8b 10411@node Active Targets
c906108c 10412@section Active targets
7a292a7a 10413
c906108c
SS
10414@cindex stacking targets
10415@cindex active targets
10416@cindex multiple targets
10417
c906108c 10418There are three classes of targets: processes, core files, and
7a292a7a
SS
10419executable files. @value{GDBN} can work concurrently on up to three
10420active targets, one in each class. This allows you to (for example)
10421start a process and inspect its activity without abandoning your work on
10422a core file.
c906108c
SS
10423
10424For example, if you execute @samp{gdb a.out}, then the executable file
10425@code{a.out} is the only active target. If you designate a core file as
10426well---presumably from a prior run that crashed and coredumped---then
10427@value{GDBN} has two active targets and uses them in tandem, looking
10428first in the corefile target, then in the executable file, to satisfy
10429requests for memory addresses. (Typically, these two classes of target
10430are complementary, since core files contain only a program's
10431read-write memory---variables and so on---plus machine status, while
10432executable files contain only the program text and initialized data.)
c906108c
SS
10433
10434When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
10435target as well. When a process target is active, all @value{GDBN}
10436commands requesting memory addresses refer to that target; addresses in
10437an active core file or executable file target are obscured while the
10438process target is active.
c906108c 10439
7a292a7a
SS
10440Use the @code{core-file} and @code{exec-file} commands to select a new
10441core file or executable target (@pxref{Files, ,Commands to specify
c906108c 10442files}). To specify as a target a process that is already running, use
7a292a7a
SS
10443the @code{attach} command (@pxref{Attach, ,Debugging an already-running
10444process}).
c906108c 10445
6d2ebf8b 10446@node Target Commands
c906108c
SS
10447@section Commands for managing targets
10448
10449@table @code
10450@item target @var{type} @var{parameters}
7a292a7a
SS
10451Connects the @value{GDBN} host environment to a target machine or
10452process. A target is typically a protocol for talking to debugging
10453facilities. You use the argument @var{type} to specify the type or
10454protocol of the target machine.
c906108c
SS
10455
10456Further @var{parameters} are interpreted by the target protocol, but
10457typically include things like device names or host names to connect
10458with, process numbers, and baud rates.
c906108c
SS
10459
10460The @code{target} command does not repeat if you press @key{RET} again
10461after executing the command.
10462
10463@kindex help target
10464@item help target
10465Displays the names of all targets available. To display targets
10466currently selected, use either @code{info target} or @code{info files}
10467(@pxref{Files, ,Commands to specify files}).
10468
10469@item help target @var{name}
10470Describe a particular target, including any parameters necessary to
10471select it.
10472
10473@kindex set gnutarget
10474@item set gnutarget @var{args}
5d161b24 10475@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 10476knows whether it is reading an @dfn{executable},
5d161b24
DB
10477a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
10478with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
10479with @code{gnutarget} the @code{target} refers to a program, not a machine.
10480
d4f3574e 10481@quotation
c906108c
SS
10482@emph{Warning:} To specify a file format with @code{set gnutarget},
10483you must know the actual BFD name.
d4f3574e 10484@end quotation
c906108c 10485
d4f3574e
SS
10486@noindent
10487@xref{Files, , Commands to specify files}.
c906108c 10488
5d161b24 10489@kindex show gnutarget
c906108c
SS
10490@item show gnutarget
10491Use the @code{show gnutarget} command to display what file format
10492@code{gnutarget} is set to read. If you have not set @code{gnutarget},
10493@value{GDBN} will determine the file format for each file automatically,
10494and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
10495@end table
10496
c906108c
SS
10497Here are some common targets (available, or not, depending on the GDB
10498configuration):
c906108c
SS
10499
10500@table @code
10501@kindex target exec
10502@item target exec @var{program}
10503An executable file. @samp{target exec @var{program}} is the same as
10504@samp{exec-file @var{program}}.
10505
c906108c
SS
10506@kindex target core
10507@item target core @var{filename}
10508A core dump file. @samp{target core @var{filename}} is the same as
10509@samp{core-file @var{filename}}.
c906108c
SS
10510
10511@kindex target remote
10512@item target remote @var{dev}
10513Remote serial target in GDB-specific protocol. The argument @var{dev}
10514specifies what serial device to use for the connection (e.g.
10515@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 10516supports the @code{load} command. This is only useful if you have
c906108c
SS
10517some other way of getting the stub to the target system, and you can put
10518it somewhere in memory where it won't get clobbered by the download.
10519
c906108c
SS
10520@kindex target sim
10521@item target sim
2df3850c 10522Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 10523In general,
474c8240 10524@smallexample
104c1213
JM
10525 target sim
10526 load
10527 run
474c8240 10528@end smallexample
d4f3574e 10529@noindent
104c1213 10530works; however, you cannot assume that a specific memory map, device
d4f3574e 10531drivers, or even basic I/O is available, although some simulators do
104c1213
JM
10532provide these. For info about any processor-specific simulator details,
10533see the appropriate section in @ref{Embedded Processors, ,Embedded
10534Processors}.
10535
c906108c
SS
10536@end table
10537
104c1213 10538Some configurations may include these targets as well:
c906108c
SS
10539
10540@table @code
10541
c906108c
SS
10542@kindex target nrom
10543@item target nrom @var{dev}
10544NetROM ROM emulator. This target only supports downloading.
10545
c906108c
SS
10546@end table
10547
5d161b24 10548Different targets are available on different configurations of @value{GDBN};
c906108c 10549your configuration may have more or fewer targets.
c906108c
SS
10550
10551Many remote targets require you to download the executable's code
10552once you've successfully established a connection.
10553
10554@table @code
10555
10556@kindex load @var{filename}
10557@item load @var{filename}
c906108c
SS
10558Depending on what remote debugging facilities are configured into
10559@value{GDBN}, the @code{load} command may be available. Where it exists, it
10560is meant to make @var{filename} (an executable) available for debugging
10561on the remote system---by downloading, or dynamic linking, for example.
10562@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
10563the @code{add-symbol-file} command.
10564
10565If your @value{GDBN} does not have a @code{load} command, attempting to
10566execute it gets the error message ``@code{You can't do that when your
10567target is @dots{}}''
c906108c
SS
10568
10569The file is loaded at whatever address is specified in the executable.
10570For some object file formats, you can specify the load address when you
10571link the program; for other formats, like a.out, the object file format
10572specifies a fixed address.
10573@c FIXME! This would be a good place for an xref to the GNU linker doc.
10574
c906108c
SS
10575@code{load} does not repeat if you press @key{RET} again after using it.
10576@end table
10577
6d2ebf8b 10578@node Byte Order
c906108c 10579@section Choosing target byte order
7a292a7a 10580
c906108c
SS
10581@cindex choosing target byte order
10582@cindex target byte order
c906108c 10583
172c2a43 10584Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
10585offer the ability to run either big-endian or little-endian byte
10586orders. Usually the executable or symbol will include a bit to
10587designate the endian-ness, and you will not need to worry about
10588which to use. However, you may still find it useful to adjust
d4f3574e 10589@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
10590
10591@table @code
10592@kindex set endian big
10593@item set endian big
10594Instruct @value{GDBN} to assume the target is big-endian.
10595
10596@kindex set endian little
10597@item set endian little
10598Instruct @value{GDBN} to assume the target is little-endian.
10599
10600@kindex set endian auto
10601@item set endian auto
10602Instruct @value{GDBN} to use the byte order associated with the
10603executable.
10604
10605@item show endian
10606Display @value{GDBN}'s current idea of the target byte order.
10607
10608@end table
10609
10610Note that these commands merely adjust interpretation of symbolic
10611data on the host, and that they have absolutely no effect on the
10612target system.
10613
6d2ebf8b 10614@node Remote
c906108c
SS
10615@section Remote debugging
10616@cindex remote debugging
10617
10618If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
10619@value{GDBN} in the usual way, it is often useful to use remote debugging.
10620For example, you might use remote debugging on an operating system kernel,
c906108c
SS
10621or on a small system which does not have a general purpose operating system
10622powerful enough to run a full-featured debugger.
10623
10624Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
10625to make this work with particular debugging targets. In addition,
5d161b24 10626@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
10627but not specific to any particular target system) which you can use if you
10628write the remote stubs---the code that runs on the remote system to
10629communicate with @value{GDBN}.
10630
10631Other remote targets may be available in your
10632configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 10633
6f05cf9f
AC
10634@node KOD
10635@section Kernel Object Display
10636
10637@cindex kernel object display
10638@cindex kernel object
10639@cindex KOD
10640
10641Some targets support kernel object display. Using this facility,
10642@value{GDBN} communicates specially with the underlying operating system
10643and can display information about operating system-level objects such as
10644mutexes and other synchronization objects. Exactly which objects can be
10645displayed is determined on a per-OS basis.
10646
10647Use the @code{set os} command to set the operating system. This tells
10648@value{GDBN} which kernel object display module to initialize:
10649
474c8240 10650@smallexample
6f05cf9f 10651(@value{GDBP}) set os cisco
474c8240 10652@end smallexample
6f05cf9f
AC
10653
10654If @code{set os} succeeds, @value{GDBN} will display some information
10655about the operating system, and will create a new @code{info} command
10656which can be used to query the target. The @code{info} command is named
10657after the operating system:
c906108c 10658
474c8240 10659@smallexample
6f05cf9f
AC
10660(@value{GDBP}) info cisco
10661List of Cisco Kernel Objects
10662Object Description
10663any Any and all objects
474c8240 10664@end smallexample
6f05cf9f
AC
10665
10666Further subcommands can be used to query about particular objects known
10667by the kernel.
10668
10669There is currently no way to determine whether a given operating system
10670is supported other than to try it.
10671
10672
10673@node Remote Debugging
10674@chapter Debugging remote programs
10675
6b2f586d 10676@menu
07f31aa6 10677* Connecting:: Connecting to a remote target
6b2f586d
AC
10678* Server:: Using the gdbserver program
10679* NetWare:: Using the gdbserve.nlm program
501eef12 10680* Remote configuration:: Remote configuration
6b2f586d 10681* remote stub:: Implementing a remote stub
6b2f586d
AC
10682@end menu
10683
07f31aa6
DJ
10684@node Connecting
10685@section Connecting to a remote target
10686
10687On the @value{GDBN} host machine, you will need an unstripped copy of
10688your program, since @value{GDBN} needs symobl and debugging information.
10689Start up @value{GDBN} as usual, using the name of the local copy of your
10690program as the first argument.
10691
10692@cindex serial line, @code{target remote}
10693If you're using a serial line, you may want to give @value{GDBN} the
10694@w{@samp{--baud}} option, or use the @code{set remotebaud} command
10695before the @code{target} command.
10696
10697After that, use @code{target remote} to establish communications with
10698the target machine. Its argument specifies how to communicate---either
10699via a devicename attached to a direct serial line, or a TCP or UDP port
10700(possibly to a terminal server which in turn has a serial line to the
10701target). For example, to use a serial line connected to the device
10702named @file{/dev/ttyb}:
10703
10704@smallexample
10705target remote /dev/ttyb
10706@end smallexample
10707
10708@cindex TCP port, @code{target remote}
10709To use a TCP connection, use an argument of the form
10710@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
10711For example, to connect to port 2828 on a
10712terminal server named @code{manyfarms}:
10713
10714@smallexample
10715target remote manyfarms:2828
10716@end smallexample
10717
10718If your remote target is actually running on the same machine as
10719your debugger session (e.g.@: a simulator of your target running on
10720the same host), you can omit the hostname. For example, to connect
10721to port 1234 on your local machine:
10722
10723@smallexample
10724target remote :1234
10725@end smallexample
10726@noindent
10727
10728Note that the colon is still required here.
10729
10730@cindex UDP port, @code{target remote}
10731To use a UDP connection, use an argument of the form
10732@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
10733on a terminal server named @code{manyfarms}:
10734
10735@smallexample
10736target remote udp:manyfarms:2828
10737@end smallexample
10738
10739When using a UDP connection for remote debugging, you should keep in mind
10740that the `U' stands for ``Unreliable''. UDP can silently drop packets on
10741busy or unreliable networks, which will cause havoc with your debugging
10742session.
10743
10744Now you can use all the usual commands to examine and change data and to
10745step and continue the remote program.
10746
10747@cindex interrupting remote programs
10748@cindex remote programs, interrupting
10749Whenever @value{GDBN} is waiting for the remote program, if you type the
10750interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
10751program. This may or may not succeed, depending in part on the hardware
10752and the serial drivers the remote system uses. If you type the
10753interrupt character once again, @value{GDBN} displays this prompt:
10754
10755@smallexample
10756Interrupted while waiting for the program.
10757Give up (and stop debugging it)? (y or n)
10758@end smallexample
10759
10760If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
10761(If you decide you want to try again later, you can use @samp{target
10762remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
10763goes back to waiting.
10764
10765@table @code
10766@kindex detach (remote)
10767@item detach
10768When you have finished debugging the remote program, you can use the
10769@code{detach} command to release it from @value{GDBN} control.
10770Detaching from the target normally resumes its execution, but the results
10771will depend on your particular remote stub. After the @code{detach}
10772command, @value{GDBN} is free to connect to another target.
10773
10774@kindex disconnect
10775@item disconnect
10776The @code{disconnect} command behaves like @code{detach}, except that
10777the target is generally not resumed. It will wait for @value{GDBN}
10778(this instance or another one) to connect and continue debugging. After
10779the @code{disconnect} command, @value{GDBN} is again free to connect to
10780another target.
10781@end table
10782
6f05cf9f
AC
10783@node Server
10784@section Using the @code{gdbserver} program
10785
10786@kindex gdbserver
10787@cindex remote connection without stubs
10788@code{gdbserver} is a control program for Unix-like systems, which
10789allows you to connect your program with a remote @value{GDBN} via
10790@code{target remote}---but without linking in the usual debugging stub.
10791
10792@code{gdbserver} is not a complete replacement for the debugging stubs,
10793because it requires essentially the same operating-system facilities
10794that @value{GDBN} itself does. In fact, a system that can run
10795@code{gdbserver} to connect to a remote @value{GDBN} could also run
10796@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
10797because it is a much smaller program than @value{GDBN} itself. It is
10798also easier to port than all of @value{GDBN}, so you may be able to get
10799started more quickly on a new system by using @code{gdbserver}.
10800Finally, if you develop code for real-time systems, you may find that
10801the tradeoffs involved in real-time operation make it more convenient to
10802do as much development work as possible on another system, for example
10803by cross-compiling. You can use @code{gdbserver} to make a similar
10804choice for debugging.
10805
10806@value{GDBN} and @code{gdbserver} communicate via either a serial line
10807or a TCP connection, using the standard @value{GDBN} remote serial
10808protocol.
10809
10810@table @emph
10811@item On the target machine,
10812you need to have a copy of the program you want to debug.
10813@code{gdbserver} does not need your program's symbol table, so you can
10814strip the program if necessary to save space. @value{GDBN} on the host
10815system does all the symbol handling.
10816
10817To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 10818the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
10819syntax is:
10820
10821@smallexample
10822target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
10823@end smallexample
10824
10825@var{comm} is either a device name (to use a serial line) or a TCP
10826hostname and portnumber. For example, to debug Emacs with the argument
10827@samp{foo.txt} and communicate with @value{GDBN} over the serial port
10828@file{/dev/com1}:
10829
10830@smallexample
10831target> gdbserver /dev/com1 emacs foo.txt
10832@end smallexample
10833
10834@code{gdbserver} waits passively for the host @value{GDBN} to communicate
10835with it.
10836
10837To use a TCP connection instead of a serial line:
10838
10839@smallexample
10840target> gdbserver host:2345 emacs foo.txt
10841@end smallexample
10842
10843The only difference from the previous example is the first argument,
10844specifying that you are communicating with the host @value{GDBN} via
10845TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
10846expect a TCP connection from machine @samp{host} to local TCP port 2345.
10847(Currently, the @samp{host} part is ignored.) You can choose any number
10848you want for the port number as long as it does not conflict with any
10849TCP ports already in use on the target system (for example, @code{23} is
10850reserved for @code{telnet}).@footnote{If you choose a port number that
10851conflicts with another service, @code{gdbserver} prints an error message
10852and exits.} You must use the same port number with the host @value{GDBN}
10853@code{target remote} command.
10854
56460a61
DJ
10855On some targets, @code{gdbserver} can also attach to running programs.
10856This is accomplished via the @code{--attach} argument. The syntax is:
10857
10858@smallexample
10859target> gdbserver @var{comm} --attach @var{pid}
10860@end smallexample
10861
10862@var{pid} is the process ID of a currently running process. It isn't necessary
10863to point @code{gdbserver} at a binary for the running process.
10864
b1fe9455
DJ
10865@pindex pidof
10866@cindex attach to a program by name
10867You can debug processes by name instead of process ID if your target has the
10868@code{pidof} utility:
10869
10870@smallexample
10871target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
10872@end smallexample
10873
10874In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
10875has multiple threads, most versions of @code{pidof} support the
10876@code{-s} option to only return the first process ID.
10877
07f31aa6
DJ
10878@item On the host machine,
10879connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
10880For TCP connections, you must start up @code{gdbserver} prior to using
10881the @code{target remote} command. Otherwise you may get an error whose
10882text depends on the host system, but which usually looks something like
07f31aa6
DJ
10883@samp{Connection refused}. You don't need to use the @code{load}
10884command in @value{GDBN} when using gdbserver, since the program is
10885already on the target.
10886
6f05cf9f
AC
10887@end table
10888
10889@node NetWare
10890@section Using the @code{gdbserve.nlm} program
10891
10892@kindex gdbserve.nlm
10893@code{gdbserve.nlm} is a control program for NetWare systems, which
10894allows you to connect your program with a remote @value{GDBN} via
10895@code{target remote}.
10896
10897@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
10898using the standard @value{GDBN} remote serial protocol.
10899
10900@table @emph
10901@item On the target machine,
10902you need to have a copy of the program you want to debug.
10903@code{gdbserve.nlm} does not need your program's symbol table, so you
10904can strip the program if necessary to save space. @value{GDBN} on the
10905host system does all the symbol handling.
10906
10907To use the server, you must tell it how to communicate with
10908@value{GDBN}; the name of your program; and the arguments for your
10909program. The syntax is:
10910
10911@smallexample
10912load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
10913 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
10914@end smallexample
10915
10916@var{board} and @var{port} specify the serial line; @var{baud} specifies
10917the baud rate used by the connection. @var{port} and @var{node} default
10918to 0, @var{baud} defaults to 9600@dmn{bps}.
10919
10920For example, to debug Emacs with the argument @samp{foo.txt}and
10921communicate with @value{GDBN} over serial port number 2 or board 1
10922using a 19200@dmn{bps} connection:
10923
10924@smallexample
10925load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
10926@end smallexample
10927
07f31aa6
DJ
10928@item
10929On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
10930Connecting to a remote target}).
6f05cf9f 10931
6f05cf9f
AC
10932@end table
10933
501eef12
AC
10934@node Remote configuration
10935@section Remote configuration
10936
10937The following configuration options are available when debugging remote
10938programs:
10939
10940@table @code
10941@kindex set remote hardware-watchpoint-limit
10942@kindex set remote hardware-breakpoint-limit
10943@anchor{set remote hardware-watchpoint-limit}
10944@anchor{set remote hardware-breakpoint-limit}
10945@item set remote hardware-watchpoint-limit @var{limit}
10946@itemx set remote hardware-breakpoint-limit @var{limit}
10947Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
10948watchpoints. A limit of -1, the default, is treated as unlimited.
10949@end table
10950
6f05cf9f
AC
10951@node remote stub
10952@section Implementing a remote stub
7a292a7a 10953
8e04817f
AC
10954@cindex debugging stub, example
10955@cindex remote stub, example
10956@cindex stub example, remote debugging
10957The stub files provided with @value{GDBN} implement the target side of the
10958communication protocol, and the @value{GDBN} side is implemented in the
10959@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
10960these subroutines to communicate, and ignore the details. (If you're
10961implementing your own stub file, you can still ignore the details: start
10962with one of the existing stub files. @file{sparc-stub.c} is the best
10963organized, and therefore the easiest to read.)
10964
104c1213
JM
10965@cindex remote serial debugging, overview
10966To debug a program running on another machine (the debugging
10967@dfn{target} machine), you must first arrange for all the usual
10968prerequisites for the program to run by itself. For example, for a C
10969program, you need:
c906108c 10970
104c1213
JM
10971@enumerate
10972@item
10973A startup routine to set up the C runtime environment; these usually
10974have a name like @file{crt0}. The startup routine may be supplied by
10975your hardware supplier, or you may have to write your own.
96baa820 10976
5d161b24 10977@item
d4f3574e 10978A C subroutine library to support your program's
104c1213 10979subroutine calls, notably managing input and output.
96baa820 10980
104c1213
JM
10981@item
10982A way of getting your program to the other machine---for example, a
10983download program. These are often supplied by the hardware
10984manufacturer, but you may have to write your own from hardware
10985documentation.
10986@end enumerate
96baa820 10987
104c1213
JM
10988The next step is to arrange for your program to use a serial port to
10989communicate with the machine where @value{GDBN} is running (the @dfn{host}
10990machine). In general terms, the scheme looks like this:
96baa820 10991
104c1213
JM
10992@table @emph
10993@item On the host,
10994@value{GDBN} already understands how to use this protocol; when everything
10995else is set up, you can simply use the @samp{target remote} command
10996(@pxref{Targets,,Specifying a Debugging Target}).
10997
10998@item On the target,
10999you must link with your program a few special-purpose subroutines that
11000implement the @value{GDBN} remote serial protocol. The file containing these
11001subroutines is called a @dfn{debugging stub}.
11002
11003On certain remote targets, you can use an auxiliary program
11004@code{gdbserver} instead of linking a stub into your program.
11005@xref{Server,,Using the @code{gdbserver} program}, for details.
11006@end table
96baa820 11007
104c1213
JM
11008The debugging stub is specific to the architecture of the remote
11009machine; for example, use @file{sparc-stub.c} to debug programs on
11010@sc{sparc} boards.
96baa820 11011
104c1213
JM
11012@cindex remote serial stub list
11013These working remote stubs are distributed with @value{GDBN}:
96baa820 11014
104c1213
JM
11015@table @code
11016
11017@item i386-stub.c
41afff9a 11018@cindex @file{i386-stub.c}
104c1213
JM
11019@cindex Intel
11020@cindex i386
11021For Intel 386 and compatible architectures.
11022
11023@item m68k-stub.c
41afff9a 11024@cindex @file{m68k-stub.c}
104c1213
JM
11025@cindex Motorola 680x0
11026@cindex m680x0
11027For Motorola 680x0 architectures.
11028
11029@item sh-stub.c
41afff9a 11030@cindex @file{sh-stub.c}
172c2a43 11031@cindex Renesas
104c1213 11032@cindex SH
172c2a43 11033For Renesas SH architectures.
104c1213
JM
11034
11035@item sparc-stub.c
41afff9a 11036@cindex @file{sparc-stub.c}
104c1213
JM
11037@cindex Sparc
11038For @sc{sparc} architectures.
11039
11040@item sparcl-stub.c
41afff9a 11041@cindex @file{sparcl-stub.c}
104c1213
JM
11042@cindex Fujitsu
11043@cindex SparcLite
11044For Fujitsu @sc{sparclite} architectures.
11045
11046@end table
11047
11048The @file{README} file in the @value{GDBN} distribution may list other
11049recently added stubs.
11050
11051@menu
11052* Stub Contents:: What the stub can do for you
11053* Bootstrapping:: What you must do for the stub
11054* Debug Session:: Putting it all together
104c1213
JM
11055@end menu
11056
6d2ebf8b 11057@node Stub Contents
6f05cf9f 11058@subsection What the stub can do for you
104c1213
JM
11059
11060@cindex remote serial stub
11061The debugging stub for your architecture supplies these three
11062subroutines:
11063
11064@table @code
11065@item set_debug_traps
11066@kindex set_debug_traps
11067@cindex remote serial stub, initialization
11068This routine arranges for @code{handle_exception} to run when your
11069program stops. You must call this subroutine explicitly near the
11070beginning of your program.
11071
11072@item handle_exception
11073@kindex handle_exception
11074@cindex remote serial stub, main routine
11075This is the central workhorse, but your program never calls it
11076explicitly---the setup code arranges for @code{handle_exception} to
11077run when a trap is triggered.
11078
11079@code{handle_exception} takes control when your program stops during
11080execution (for example, on a breakpoint), and mediates communications
11081with @value{GDBN} on the host machine. This is where the communications
11082protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 11083representative on the target machine. It begins by sending summary
104c1213
JM
11084information on the state of your program, then continues to execute,
11085retrieving and transmitting any information @value{GDBN} needs, until you
11086execute a @value{GDBN} command that makes your program resume; at that point,
11087@code{handle_exception} returns control to your own code on the target
5d161b24 11088machine.
104c1213
JM
11089
11090@item breakpoint
11091@cindex @code{breakpoint} subroutine, remote
11092Use this auxiliary subroutine to make your program contain a
11093breakpoint. Depending on the particular situation, this may be the only
11094way for @value{GDBN} to get control. For instance, if your target
11095machine has some sort of interrupt button, you won't need to call this;
11096pressing the interrupt button transfers control to
11097@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
11098simply receiving characters on the serial port may also trigger a trap;
11099again, in that situation, you don't need to call @code{breakpoint} from
11100your own program---simply running @samp{target remote} from the host
5d161b24 11101@value{GDBN} session gets control.
104c1213
JM
11102
11103Call @code{breakpoint} if none of these is true, or if you simply want
11104to make certain your program stops at a predetermined point for the
11105start of your debugging session.
11106@end table
11107
6d2ebf8b 11108@node Bootstrapping
6f05cf9f 11109@subsection What you must do for the stub
104c1213
JM
11110
11111@cindex remote stub, support routines
11112The debugging stubs that come with @value{GDBN} are set up for a particular
11113chip architecture, but they have no information about the rest of your
11114debugging target machine.
11115
11116First of all you need to tell the stub how to communicate with the
11117serial port.
11118
11119@table @code
11120@item int getDebugChar()
11121@kindex getDebugChar
11122Write this subroutine to read a single character from the serial port.
11123It may be identical to @code{getchar} for your target system; a
11124different name is used to allow you to distinguish the two if you wish.
11125
11126@item void putDebugChar(int)
11127@kindex putDebugChar
11128Write this subroutine to write a single character to the serial port.
5d161b24 11129It may be identical to @code{putchar} for your target system; a
104c1213
JM
11130different name is used to allow you to distinguish the two if you wish.
11131@end table
11132
11133@cindex control C, and remote debugging
11134@cindex interrupting remote targets
11135If you want @value{GDBN} to be able to stop your program while it is
11136running, you need to use an interrupt-driven serial driver, and arrange
11137for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
11138character). That is the character which @value{GDBN} uses to tell the
11139remote system to stop.
11140
11141Getting the debugging target to return the proper status to @value{GDBN}
11142probably requires changes to the standard stub; one quick and dirty way
11143is to just execute a breakpoint instruction (the ``dirty'' part is that
11144@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
11145
11146Other routines you need to supply are:
11147
11148@table @code
11149@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
11150@kindex exceptionHandler
11151Write this function to install @var{exception_address} in the exception
11152handling tables. You need to do this because the stub does not have any
11153way of knowing what the exception handling tables on your target system
11154are like (for example, the processor's table might be in @sc{rom},
11155containing entries which point to a table in @sc{ram}).
11156@var{exception_number} is the exception number which should be changed;
11157its meaning is architecture-dependent (for example, different numbers
11158might represent divide by zero, misaligned access, etc). When this
11159exception occurs, control should be transferred directly to
11160@var{exception_address}, and the processor state (stack, registers,
11161and so on) should be just as it is when a processor exception occurs. So if
11162you want to use a jump instruction to reach @var{exception_address}, it
11163should be a simple jump, not a jump to subroutine.
11164
11165For the 386, @var{exception_address} should be installed as an interrupt
11166gate so that interrupts are masked while the handler runs. The gate
11167should be at privilege level 0 (the most privileged level). The
11168@sc{sparc} and 68k stubs are able to mask interrupts themselves without
11169help from @code{exceptionHandler}.
11170
11171@item void flush_i_cache()
11172@kindex flush_i_cache
d4f3574e 11173On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
11174instruction cache, if any, on your target machine. If there is no
11175instruction cache, this subroutine may be a no-op.
11176
11177On target machines that have instruction caches, @value{GDBN} requires this
11178function to make certain that the state of your program is stable.
11179@end table
11180
11181@noindent
11182You must also make sure this library routine is available:
11183
11184@table @code
11185@item void *memset(void *, int, int)
11186@kindex memset
11187This is the standard library function @code{memset} that sets an area of
11188memory to a known value. If you have one of the free versions of
11189@code{libc.a}, @code{memset} can be found there; otherwise, you must
11190either obtain it from your hardware manufacturer, or write your own.
11191@end table
11192
11193If you do not use the GNU C compiler, you may need other standard
11194library subroutines as well; this varies from one stub to another,
11195but in general the stubs are likely to use any of the common library
d4f3574e 11196subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
11197
11198
6d2ebf8b 11199@node Debug Session
6f05cf9f 11200@subsection Putting it all together
104c1213
JM
11201
11202@cindex remote serial debugging summary
11203In summary, when your program is ready to debug, you must follow these
11204steps.
11205
11206@enumerate
11207@item
6d2ebf8b 11208Make sure you have defined the supporting low-level routines
104c1213
JM
11209(@pxref{Bootstrapping,,What you must do for the stub}):
11210@display
11211@code{getDebugChar}, @code{putDebugChar},
11212@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
11213@end display
11214
11215@item
11216Insert these lines near the top of your program:
11217
474c8240 11218@smallexample
104c1213
JM
11219set_debug_traps();
11220breakpoint();
474c8240 11221@end smallexample
104c1213
JM
11222
11223@item
11224For the 680x0 stub only, you need to provide a variable called
11225@code{exceptionHook}. Normally you just use:
11226
474c8240 11227@smallexample
104c1213 11228void (*exceptionHook)() = 0;
474c8240 11229@end smallexample
104c1213 11230
d4f3574e 11231@noindent
104c1213 11232but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 11233function in your program, that function is called when
104c1213
JM
11234@code{@value{GDBN}} continues after stopping on a trap (for example, bus
11235error). The function indicated by @code{exceptionHook} is called with
11236one parameter: an @code{int} which is the exception number.
11237
11238@item
11239Compile and link together: your program, the @value{GDBN} debugging stub for
11240your target architecture, and the supporting subroutines.
11241
11242@item
11243Make sure you have a serial connection between your target machine and
11244the @value{GDBN} host, and identify the serial port on the host.
11245
11246@item
11247@c The "remote" target now provides a `load' command, so we should
11248@c document that. FIXME.
11249Download your program to your target machine (or get it there by
11250whatever means the manufacturer provides), and start it.
11251
11252@item
07f31aa6
DJ
11253Start @value{GDBN} on the host, and connect to the target
11254(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 11255
104c1213
JM
11256@end enumerate
11257
8e04817f
AC
11258@node Configurations
11259@chapter Configuration-Specific Information
104c1213 11260
8e04817f
AC
11261While nearly all @value{GDBN} commands are available for all native and
11262cross versions of the debugger, there are some exceptions. This chapter
11263describes things that are only available in certain configurations.
104c1213 11264
8e04817f
AC
11265There are three major categories of configurations: native
11266configurations, where the host and target are the same, embedded
11267operating system configurations, which are usually the same for several
11268different processor architectures, and bare embedded processors, which
11269are quite different from each other.
104c1213 11270
8e04817f
AC
11271@menu
11272* Native::
11273* Embedded OS::
11274* Embedded Processors::
11275* Architectures::
11276@end menu
104c1213 11277
8e04817f
AC
11278@node Native
11279@section Native
104c1213 11280
8e04817f
AC
11281This section describes details specific to particular native
11282configurations.
6cf7e474 11283
8e04817f
AC
11284@menu
11285* HP-UX:: HP-UX
11286* SVR4 Process Information:: SVR4 process information
11287* DJGPP Native:: Features specific to the DJGPP port
78c47bea 11288* Cygwin Native:: Features specific to the Cygwin port
8e04817f 11289@end menu
6cf7e474 11290
8e04817f
AC
11291@node HP-UX
11292@subsection HP-UX
104c1213 11293
8e04817f
AC
11294On HP-UX systems, if you refer to a function or variable name that
11295begins with a dollar sign, @value{GDBN} searches for a user or system
11296name first, before it searches for a convenience variable.
104c1213 11297
8e04817f
AC
11298@node SVR4 Process Information
11299@subsection SVR4 process information
104c1213 11300
8e04817f
AC
11301@kindex /proc
11302@cindex process image
104c1213 11303
8e04817f
AC
11304Many versions of SVR4 provide a facility called @samp{/proc} that can be
11305used to examine the image of a running process using file-system
11306subroutines. If @value{GDBN} is configured for an operating system with
11307this facility, the command @code{info proc} is available to report on
11308several kinds of information about the process running your program.
11309@code{info proc} works only on SVR4 systems that include the
11310@code{procfs} code. This includes OSF/1 (Digital Unix), Solaris, Irix,
1104b9e7 11311and Unixware, but not HP-UX or @sc{gnu}/Linux, for example.
104c1213 11312
8e04817f
AC
11313@table @code
11314@kindex info proc
11315@item info proc
11316Summarize available information about the process.
6cf7e474 11317
8e04817f
AC
11318@kindex info proc mappings
11319@item info proc mappings
11320Report on the address ranges accessible in the program, with information
11321on whether your program may read, write, or execute each range.
11322@ignore
11323@comment These sub-options of 'info proc' were not included when
11324@comment procfs.c was re-written. Keep their descriptions around
11325@comment against the day when someone finds the time to put them back in.
11326@kindex info proc times
11327@item info proc times
11328Starting time, user CPU time, and system CPU time for your program and
11329its children.
6cf7e474 11330
8e04817f
AC
11331@kindex info proc id
11332@item info proc id
11333Report on the process IDs related to your program: its own process ID,
11334the ID of its parent, the process group ID, and the session ID.
104c1213 11335
8e04817f
AC
11336@kindex info proc status
11337@item info proc status
11338General information on the state of the process. If the process is
11339stopped, this report includes the reason for stopping, and any signal
11340received.
d4f3574e 11341
8e04817f
AC
11342@item info proc all
11343Show all the above information about the process.
11344@end ignore
11345@end table
104c1213 11346
8e04817f
AC
11347@node DJGPP Native
11348@subsection Features for Debugging @sc{djgpp} Programs
11349@cindex @sc{djgpp} debugging
11350@cindex native @sc{djgpp} debugging
11351@cindex MS-DOS-specific commands
104c1213 11352
8e04817f
AC
11353@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
11354MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
11355that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
11356top of real-mode DOS systems and their emulations.
104c1213 11357
8e04817f
AC
11358@value{GDBN} supports native debugging of @sc{djgpp} programs, and
11359defines a few commands specific to the @sc{djgpp} port. This
11360subsection describes those commands.
104c1213 11361
8e04817f
AC
11362@table @code
11363@kindex info dos
11364@item info dos
11365This is a prefix of @sc{djgpp}-specific commands which print
11366information about the target system and important OS structures.
f1251bdd 11367
8e04817f
AC
11368@kindex sysinfo
11369@cindex MS-DOS system info
11370@cindex free memory information (MS-DOS)
11371@item info dos sysinfo
11372This command displays assorted information about the underlying
11373platform: the CPU type and features, the OS version and flavor, the
11374DPMI version, and the available conventional and DPMI memory.
104c1213 11375
8e04817f
AC
11376@cindex GDT
11377@cindex LDT
11378@cindex IDT
11379@cindex segment descriptor tables
11380@cindex descriptor tables display
11381@item info dos gdt
11382@itemx info dos ldt
11383@itemx info dos idt
11384These 3 commands display entries from, respectively, Global, Local,
11385and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
11386tables are data structures which store a descriptor for each segment
11387that is currently in use. The segment's selector is an index into a
11388descriptor table; the table entry for that index holds the
11389descriptor's base address and limit, and its attributes and access
11390rights.
104c1213 11391
8e04817f
AC
11392A typical @sc{djgpp} program uses 3 segments: a code segment, a data
11393segment (used for both data and the stack), and a DOS segment (which
11394allows access to DOS/BIOS data structures and absolute addresses in
11395conventional memory). However, the DPMI host will usually define
11396additional segments in order to support the DPMI environment.
d4f3574e 11397
8e04817f
AC
11398@cindex garbled pointers
11399These commands allow to display entries from the descriptor tables.
11400Without an argument, all entries from the specified table are
11401displayed. An argument, which should be an integer expression, means
11402display a single entry whose index is given by the argument. For
11403example, here's a convenient way to display information about the
11404debugged program's data segment:
104c1213 11405
8e04817f
AC
11406@smallexample
11407@exdent @code{(@value{GDBP}) info dos ldt $ds}
11408@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
11409@end smallexample
104c1213 11410
8e04817f
AC
11411@noindent
11412This comes in handy when you want to see whether a pointer is outside
11413the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 11414
8e04817f
AC
11415@cindex page tables display (MS-DOS)
11416@item info dos pde
11417@itemx info dos pte
11418These two commands display entries from, respectively, the Page
11419Directory and the Page Tables. Page Directories and Page Tables are
11420data structures which control how virtual memory addresses are mapped
11421into physical addresses. A Page Table includes an entry for every
11422page of memory that is mapped into the program's address space; there
11423may be several Page Tables, each one holding up to 4096 entries. A
11424Page Directory has up to 4096 entries, one each for every Page Table
11425that is currently in use.
104c1213 11426
8e04817f
AC
11427Without an argument, @kbd{info dos pde} displays the entire Page
11428Directory, and @kbd{info dos pte} displays all the entries in all of
11429the Page Tables. An argument, an integer expression, given to the
11430@kbd{info dos pde} command means display only that entry from the Page
11431Directory table. An argument given to the @kbd{info dos pte} command
11432means display entries from a single Page Table, the one pointed to by
11433the specified entry in the Page Directory.
104c1213 11434
8e04817f
AC
11435@cindex direct memory access (DMA) on MS-DOS
11436These commands are useful when your program uses @dfn{DMA} (Direct
11437Memory Access), which needs physical addresses to program the DMA
11438controller.
104c1213 11439
8e04817f 11440These commands are supported only with some DPMI servers.
104c1213 11441
8e04817f
AC
11442@cindex physical address from linear address
11443@item info dos address-pte @var{addr}
11444This command displays the Page Table entry for a specified linear
11445address. The argument linear address @var{addr} should already have the
11446appropriate segment's base address added to it, because this command
11447accepts addresses which may belong to @emph{any} segment. For
11448example, here's how to display the Page Table entry for the page where
11449the variable @code{i} is stored:
104c1213 11450
8e04817f
AC
11451@smallexample
11452@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
11453@exdent @code{Page Table entry for address 0x11a00d30:}
11454@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
11455@end smallexample
104c1213 11456
8e04817f
AC
11457@noindent
11458This says that @code{i} is stored at offset @code{0xd30} from the page
11459whose physical base address is @code{0x02698000}, and prints all the
11460attributes of that page.
104c1213 11461
8e04817f
AC
11462Note that you must cast the addresses of variables to a @code{char *},
11463since otherwise the value of @code{__djgpp_base_address}, the base
11464address of all variables and functions in a @sc{djgpp} program, will
11465be added using the rules of C pointer arithmetics: if @code{i} is
11466declared an @code{int}, @value{GDBN} will add 4 times the value of
11467@code{__djgpp_base_address} to the address of @code{i}.
104c1213 11468
8e04817f
AC
11469Here's another example, it displays the Page Table entry for the
11470transfer buffer:
104c1213 11471
8e04817f
AC
11472@smallexample
11473@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
11474@exdent @code{Page Table entry for address 0x29110:}
11475@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
11476@end smallexample
104c1213 11477
8e04817f
AC
11478@noindent
11479(The @code{+ 3} offset is because the transfer buffer's address is the
114803rd member of the @code{_go32_info_block} structure.) The output of
11481this command clearly shows that addresses in conventional memory are
11482mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 11483
8e04817f
AC
11484This command is supported only with some DPMI servers.
11485@end table
104c1213 11486
78c47bea
PM
11487@node Cygwin Native
11488@subsection Features for Debugging MS Windows PE executables
11489@cindex MS Windows debugging
11490@cindex native Cygwin debugging
11491@cindex Cygwin-specific commands
11492
be448670
CF
11493@value{GDBN} supports native debugging of MS Windows programs, including
11494DLLs with and without symbolic debugging information. There are various
11495additional Cygwin-specific commands, described in this subsection. The
11496subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
11497that have no debugging symbols.
11498
78c47bea
PM
11499
11500@table @code
11501@kindex info w32
11502@item info w32
11503This is a prefix of MS Windows specific commands which print
11504information about the target system and important OS structures.
11505
11506@item info w32 selector
11507This command displays information returned by
11508the Win32 API @code{GetThreadSelectorEntry} function.
11509It takes an optional argument that is evaluated to
11510a long value to give the information about this given selector.
11511Without argument, this command displays information
11512about the the six segment registers.
11513
11514@kindex info dll
11515@item info dll
11516This is a Cygwin specific alias of info shared.
11517
11518@kindex dll-symbols
11519@item dll-symbols
11520This command loads symbols from a dll similarly to
11521add-sym command but without the need to specify a base address.
11522
11523@kindex set new-console
11524@item set new-console @var{mode}
11525If @var{mode} is @code{on} the debuggee will
11526be started in a new console on next start.
11527If @var{mode} is @code{off}i, the debuggee will
11528be started in the same console as the debugger.
11529
11530@kindex show new-console
11531@item show new-console
11532Displays whether a new console is used
11533when the debuggee is started.
11534
11535@kindex set new-group
11536@item set new-group @var{mode}
11537This boolean value controls whether the debuggee should
11538start a new group or stay in the same group as the debugger.
11539This affects the way the Windows OS handles
11540Ctrl-C.
11541
11542@kindex show new-group
11543@item show new-group
11544Displays current value of new-group boolean.
11545
11546@kindex set debugevents
11547@item set debugevents
11548This boolean value adds debug output concerning events seen by the debugger.
11549
11550@kindex set debugexec
11551@item set debugexec
11552This boolean value adds debug output concerning execute events
11553seen by the debugger.
11554
11555@kindex set debugexceptions
11556@item set debugexceptions
11557This boolean value adds debug ouptut concerning exception events
11558seen by the debugger.
11559
11560@kindex set debugmemory
11561@item set debugmemory
11562This boolean value adds debug ouptut concerning memory events
11563seen by the debugger.
11564
11565@kindex set shell
11566@item set shell
11567This boolean values specifies whether the debuggee is called
11568via a shell or directly (default value is on).
11569
11570@kindex show shell
11571@item show shell
11572Displays if the debuggee will be started with a shell.
11573
11574@end table
11575
be448670
CF
11576@menu
11577* Non-debug DLL symbols:: Support for DLLs without debugging symbols
11578@end menu
11579
11580@node Non-debug DLL symbols
11581@subsubsection Support for DLLs without debugging symbols
11582@cindex DLLs with no debugging symbols
11583@cindex Minimal symbols and DLLs
11584
11585Very often on windows, some of the DLLs that your program relies on do
11586not include symbolic debugging information (for example,
11587@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
11588symbols in a DLL, it relies on the minimal amount of symbolic
11589information contained in the DLL's export table. This subsubsection
11590describes working with such symbols, known internally to @value{GDBN} as
11591``minimal symbols''.
11592
11593Note that before the debugged program has started execution, no DLLs
11594will have been loaded. The easiest way around this problem is simply to
11595start the program --- either by setting a breakpoint or letting the
11596program run once to completion. It is also possible to force
11597@value{GDBN} to load a particular DLL before starting the executable ---
11598see the shared library information in @pxref{Files} or the
11599@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
11600explicitly loading symbols from a DLL with no debugging information will
11601cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
11602which may adversely affect symbol lookup performance.
11603
11604@subsubsection DLL name prefixes
11605
11606In keeping with the naming conventions used by the Microsoft debugging
11607tools, DLL export symbols are made available with a prefix based on the
11608DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
11609also entered into the symbol table, so @code{CreateFileA} is often
11610sufficient. In some cases there will be name clashes within a program
11611(particularly if the executable itself includes full debugging symbols)
11612necessitating the use of the fully qualified name when referring to the
11613contents of the DLL. Use single-quotes around the name to avoid the
11614exclamation mark (``!'') being interpreted as a language operator.
11615
11616Note that the internal name of the DLL may be all upper-case, even
11617though the file name of the DLL is lower-case, or vice-versa. Since
11618symbols within @value{GDBN} are @emph{case-sensitive} this may cause
11619some confusion. If in doubt, try the @code{info functions} and
11620@code{info variables} commands or even @code{maint print msymbols} (see
11621@pxref{Symbols}). Here's an example:
11622
11623@smallexample
11624(gdb) info function CreateFileA
11625All functions matching regular expression "CreateFileA":
11626
11627Non-debugging symbols:
116280x77e885f4 CreateFileA
116290x77e885f4 KERNEL32!CreateFileA
11630@end smallexample
11631
11632@smallexample
11633(gdb) info function !
11634All functions matching regular expression "!":
11635
11636Non-debugging symbols:
116370x6100114c cygwin1!__assert
116380x61004034 cygwin1!_dll_crt0@@0
116390x61004240 cygwin1!dll_crt0(per_process *)
11640[etc...]
11641@end smallexample
11642
11643@subsubsection Working with minimal symbols
11644
11645Symbols extracted from a DLL's export table do not contain very much
11646type information. All that @value{GDBN} can do is guess whether a symbol
11647refers to a function or variable depending on the linker section that
11648contains the symbol. Also note that the actual contents of the memory
11649contained in a DLL are not available unless the program is running. This
11650means that you cannot examine the contents of a variable or disassemble
11651a function within a DLL without a running program.
11652
11653Variables are generally treated as pointers and dereferenced
11654automatically. For this reason, it is often necessary to prefix a
11655variable name with the address-of operator (``&'') and provide explicit
11656type information in the command. Here's an example of the type of
11657problem:
11658
11659@smallexample
11660(gdb) print 'cygwin1!__argv'
11661$1 = 268572168
11662@end smallexample
11663
11664@smallexample
11665(gdb) x 'cygwin1!__argv'
116660x10021610: "\230y\""
11667@end smallexample
11668
11669And two possible solutions:
11670
11671@smallexample
11672(gdb) print ((char **)'cygwin1!__argv')[0]
11673$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
11674@end smallexample
11675
11676@smallexample
11677(gdb) x/2x &'cygwin1!__argv'
116780x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
11679(gdb) x/x 0x10021608
116800x10021608: 0x0022fd98
11681(gdb) x/s 0x0022fd98
116820x22fd98: "/cygdrive/c/mydirectory/myprogram"
11683@end smallexample
11684
11685Setting a break point within a DLL is possible even before the program
11686starts execution. However, under these circumstances, @value{GDBN} can't
11687examine the initial instructions of the function in order to skip the
11688function's frame set-up code. You can work around this by using ``*&''
11689to set the breakpoint at a raw memory address:
11690
11691@smallexample
11692(gdb) break *&'python22!PyOS_Readline'
11693Breakpoint 1 at 0x1e04eff0
11694@end smallexample
11695
11696The author of these extensions is not entirely convinced that setting a
11697break point within a shared DLL like @file{kernel32.dll} is completely
11698safe.
11699
8e04817f
AC
11700@node Embedded OS
11701@section Embedded Operating Systems
104c1213 11702
8e04817f
AC
11703This section describes configurations involving the debugging of
11704embedded operating systems that are available for several different
11705architectures.
d4f3574e 11706
8e04817f
AC
11707@menu
11708* VxWorks:: Using @value{GDBN} with VxWorks
11709@end menu
104c1213 11710
8e04817f
AC
11711@value{GDBN} includes the ability to debug programs running on
11712various real-time operating systems.
104c1213 11713
8e04817f
AC
11714@node VxWorks
11715@subsection Using @value{GDBN} with VxWorks
104c1213 11716
8e04817f 11717@cindex VxWorks
104c1213 11718
8e04817f 11719@table @code
104c1213 11720
8e04817f
AC
11721@kindex target vxworks
11722@item target vxworks @var{machinename}
11723A VxWorks system, attached via TCP/IP. The argument @var{machinename}
11724is the target system's machine name or IP address.
104c1213 11725
8e04817f 11726@end table
104c1213 11727
8e04817f
AC
11728On VxWorks, @code{load} links @var{filename} dynamically on the
11729current target system as well as adding its symbols in @value{GDBN}.
104c1213 11730
8e04817f
AC
11731@value{GDBN} enables developers to spawn and debug tasks running on networked
11732VxWorks targets from a Unix host. Already-running tasks spawned from
11733the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
11734both the Unix host and on the VxWorks target. The program
11735@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
11736installed with the name @code{vxgdb}, to distinguish it from a
11737@value{GDBN} for debugging programs on the host itself.)
104c1213 11738
8e04817f
AC
11739@table @code
11740@item VxWorks-timeout @var{args}
11741@kindex vxworks-timeout
11742All VxWorks-based targets now support the option @code{vxworks-timeout}.
11743This option is set by the user, and @var{args} represents the number of
11744seconds @value{GDBN} waits for responses to rpc's. You might use this if
11745your VxWorks target is a slow software simulator or is on the far side
11746of a thin network line.
11747@end table
104c1213 11748
8e04817f
AC
11749The following information on connecting to VxWorks was current when
11750this manual was produced; newer releases of VxWorks may use revised
11751procedures.
104c1213 11752
8e04817f
AC
11753@kindex INCLUDE_RDB
11754To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
11755to include the remote debugging interface routines in the VxWorks
11756library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
11757VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
11758kernel. The resulting kernel contains @file{rdb.a}, and spawns the
11759source debugging task @code{tRdbTask} when VxWorks is booted. For more
11760information on configuring and remaking VxWorks, see the manufacturer's
11761manual.
11762@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 11763
8e04817f
AC
11764Once you have included @file{rdb.a} in your VxWorks system image and set
11765your Unix execution search path to find @value{GDBN}, you are ready to
11766run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
11767@code{vxgdb}, depending on your installation).
104c1213 11768
8e04817f 11769@value{GDBN} comes up showing the prompt:
104c1213 11770
474c8240 11771@smallexample
8e04817f 11772(vxgdb)
474c8240 11773@end smallexample
104c1213 11774
8e04817f
AC
11775@menu
11776* VxWorks Connection:: Connecting to VxWorks
11777* VxWorks Download:: VxWorks download
11778* VxWorks Attach:: Running tasks
11779@end menu
104c1213 11780
8e04817f
AC
11781@node VxWorks Connection
11782@subsubsection Connecting to VxWorks
104c1213 11783
8e04817f
AC
11784The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
11785network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 11786
474c8240 11787@smallexample
8e04817f 11788(vxgdb) target vxworks tt
474c8240 11789@end smallexample
104c1213 11790
8e04817f
AC
11791@need 750
11792@value{GDBN} displays messages like these:
104c1213 11793
8e04817f
AC
11794@smallexample
11795Attaching remote machine across net...
11796Connected to tt.
11797@end smallexample
104c1213 11798
8e04817f
AC
11799@need 1000
11800@value{GDBN} then attempts to read the symbol tables of any object modules
11801loaded into the VxWorks target since it was last booted. @value{GDBN} locates
11802these files by searching the directories listed in the command search
11803path (@pxref{Environment, ,Your program's environment}); if it fails
11804to find an object file, it displays a message such as:
5d161b24 11805
474c8240 11806@smallexample
8e04817f 11807prog.o: No such file or directory.
474c8240 11808@end smallexample
104c1213 11809
8e04817f
AC
11810When this happens, add the appropriate directory to the search path with
11811the @value{GDBN} command @code{path}, and execute the @code{target}
11812command again.
104c1213 11813
8e04817f
AC
11814@node VxWorks Download
11815@subsubsection VxWorks download
104c1213 11816
8e04817f
AC
11817@cindex download to VxWorks
11818If you have connected to the VxWorks target and you want to debug an
11819object that has not yet been loaded, you can use the @value{GDBN}
11820@code{load} command to download a file from Unix to VxWorks
11821incrementally. The object file given as an argument to the @code{load}
11822command is actually opened twice: first by the VxWorks target in order
11823to download the code, then by @value{GDBN} in order to read the symbol
11824table. This can lead to problems if the current working directories on
11825the two systems differ. If both systems have NFS mounted the same
11826filesystems, you can avoid these problems by using absolute paths.
11827Otherwise, it is simplest to set the working directory on both systems
11828to the directory in which the object file resides, and then to reference
11829the file by its name, without any path. For instance, a program
11830@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
11831and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
11832program, type this on VxWorks:
104c1213 11833
474c8240 11834@smallexample
8e04817f 11835-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 11836@end smallexample
104c1213 11837
8e04817f
AC
11838@noindent
11839Then, in @value{GDBN}, type:
104c1213 11840
474c8240 11841@smallexample
8e04817f
AC
11842(vxgdb) cd @var{hostpath}/vw/demo/rdb
11843(vxgdb) load prog.o
474c8240 11844@end smallexample
104c1213 11845
8e04817f 11846@value{GDBN} displays a response similar to this:
104c1213 11847
8e04817f
AC
11848@smallexample
11849Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
11850@end smallexample
104c1213 11851
8e04817f
AC
11852You can also use the @code{load} command to reload an object module
11853after editing and recompiling the corresponding source file. Note that
11854this makes @value{GDBN} delete all currently-defined breakpoints,
11855auto-displays, and convenience variables, and to clear the value
11856history. (This is necessary in order to preserve the integrity of
11857debugger's data structures that reference the target system's symbol
11858table.)
104c1213 11859
8e04817f
AC
11860@node VxWorks Attach
11861@subsubsection Running tasks
104c1213
JM
11862
11863@cindex running VxWorks tasks
11864You can also attach to an existing task using the @code{attach} command as
11865follows:
11866
474c8240 11867@smallexample
104c1213 11868(vxgdb) attach @var{task}
474c8240 11869@end smallexample
104c1213
JM
11870
11871@noindent
11872where @var{task} is the VxWorks hexadecimal task ID. The task can be running
11873or suspended when you attach to it. Running tasks are suspended at
11874the time of attachment.
11875
6d2ebf8b 11876@node Embedded Processors
104c1213
JM
11877@section Embedded Processors
11878
11879This section goes into details specific to particular embedded
11880configurations.
11881
7d86b5d5 11882
104c1213 11883@menu
104c1213 11884* ARM:: ARM
172c2a43
KI
11885* H8/300:: Renesas H8/300
11886* H8/500:: Renesas H8/500
11887* M32R/D:: Renesas M32R/D
104c1213 11888* M68K:: Motorola M68K
104c1213 11889* MIPS Embedded:: MIPS Embedded
a37295f9 11890* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
11891* PA:: HP PA Embedded
11892* PowerPC: PowerPC
172c2a43 11893* SH:: Renesas SH
104c1213
JM
11894* Sparclet:: Tsqware Sparclet
11895* Sparclite:: Fujitsu Sparclite
11896* ST2000:: Tandem ST2000
11897* Z8000:: Zilog Z8000
11898@end menu
11899
6d2ebf8b 11900@node ARM
104c1213
JM
11901@subsection ARM
11902
11903@table @code
11904
8e04817f
AC
11905@kindex target rdi
11906@item target rdi @var{dev}
11907ARM Angel monitor, via RDI library interface to ADP protocol. You may
11908use this target to communicate with both boards running the Angel
11909monitor, or with the EmbeddedICE JTAG debug device.
11910
11911@kindex target rdp
11912@item target rdp @var{dev}
11913ARM Demon monitor.
11914
11915@end table
11916
11917@node H8/300
172c2a43 11918@subsection Renesas H8/300
8e04817f
AC
11919
11920@table @code
11921
11922@kindex target hms@r{, with H8/300}
11923@item target hms @var{dev}
172c2a43 11924A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
11925Use special commands @code{device} and @code{speed} to control the serial
11926line and the communications speed used.
11927
11928@kindex target e7000@r{, with H8/300}
11929@item target e7000 @var{dev}
172c2a43 11930E7000 emulator for Renesas H8 and SH.
8e04817f
AC
11931
11932@kindex target sh3@r{, with H8/300}
11933@kindex target sh3e@r{, with H8/300}
11934@item target sh3 @var{dev}
11935@itemx target sh3e @var{dev}
172c2a43 11936Renesas SH-3 and SH-3E target systems.
8e04817f
AC
11937
11938@end table
11939
11940@cindex download to H8/300 or H8/500
11941@cindex H8/300 or H8/500 download
172c2a43
KI
11942@cindex download to Renesas SH
11943@cindex Renesas SH download
11944When you select remote debugging to a Renesas SH, H8/300, or H8/500
11945board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
11946board and also opens it as the current executable target for
11947@value{GDBN} on your host (like the @code{file} command).
11948
11949@value{GDBN} needs to know these things to talk to your
172c2a43 11950Renesas SH, H8/300, or H8/500:
8e04817f
AC
11951
11952@enumerate
11953@item
11954that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
11955for Renesas microprocessors, or @samp{target e7000}, the in-circuit
11956emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
11957the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
11958H8/300, or H8/500.)
11959
11960@item
172c2a43 11961what serial device connects your host to your Renesas board (the first
8e04817f
AC
11962serial device available on your host is the default).
11963
11964@item
11965what speed to use over the serial device.
11966@end enumerate
11967
11968@menu
172c2a43
KI
11969* Renesas Boards:: Connecting to Renesas boards.
11970* Renesas ICE:: Using the E7000 In-Circuit Emulator.
11971* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
11972@end menu
11973
172c2a43
KI
11974@node Renesas Boards
11975@subsubsection Connecting to Renesas boards
8e04817f
AC
11976
11977@c only for Unix hosts
11978@kindex device
172c2a43 11979@cindex serial device, Renesas micros
8e04817f
AC
11980Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
11981need to explicitly set the serial device. The default @var{port} is the
11982first available port on your host. This is only necessary on Unix
11983hosts, where it is typically something like @file{/dev/ttya}.
11984
11985@kindex speed
172c2a43 11986@cindex serial line speed, Renesas micros
8e04817f
AC
11987@code{@value{GDBN}} has another special command to set the communications
11988speed: @samp{speed @var{bps}}. This command also is only used from Unix
11989hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
11990the DOS @code{mode} command (for instance,
11991@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
11992
11993The @samp{device} and @samp{speed} commands are available only when you
172c2a43 11994use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
11995use a DOS host,
11996@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
11997called @code{asynctsr} to communicate with the development board
11998through a PC serial port. You must also use the DOS @code{mode} command
11999to set up the serial port on the DOS side.
12000
12001The following sample session illustrates the steps needed to start a
12002program under @value{GDBN} control on an H8/300. The example uses a
12003sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 12004the Renesas SH and the H8/500.
8e04817f
AC
12005
12006First hook up your development board. In this example, we use a
12007board attached to serial port @code{COM2}; if you use a different serial
12008port, substitute its name in the argument of the @code{mode} command.
12009When you call @code{asynctsr}, the auxiliary comms program used by the
12010debugger, you give it just the numeric part of the serial port's name;
12011for example, @samp{asyncstr 2} below runs @code{asyncstr} on
12012@code{COM2}.
12013
474c8240 12014@smallexample
8e04817f
AC
12015C:\H8300\TEST> asynctsr 2
12016C:\H8300\TEST> mode com2:9600,n,8,1,p
12017
12018Resident portion of MODE loaded
12019
12020COM2: 9600, n, 8, 1, p
12021
474c8240 12022@end smallexample
8e04817f
AC
12023
12024@quotation
12025@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
12026@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
12027disable it, or even boot without it, to use @code{asynctsr} to control
12028your development board.
12029@end quotation
12030
12031@kindex target hms@r{, and serial protocol}
12032Now that serial communications are set up, and the development board is
12033connected, you can start up @value{GDBN}. Call @code{@value{GDBP}} with
12034the name of your program as the argument. @code{@value{GDBN}} prompts
12035you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
12036commands to begin your debugging session: @samp{target hms} to specify
172c2a43 12037cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
12038download your program to the board. @code{load} displays the names of
12039the program's sections, and a @samp{*} for each 2K of data downloaded.
12040(If you want to refresh @value{GDBN} data on symbols or on the
12041executable file without downloading, use the @value{GDBN} commands
12042@code{file} or @code{symbol-file}. These commands, and @code{load}
12043itself, are described in @ref{Files,,Commands to specify files}.)
12044
12045@smallexample
12046(eg-C:\H8300\TEST) @value{GDBP} t.x
12047@value{GDBN} is free software and you are welcome to distribute copies
12048 of it under certain conditions; type "show copying" to see
12049 the conditions.
12050There is absolutely no warranty for @value{GDBN}; type "show warranty"
12051for details.
12052@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
12053(@value{GDBP}) target hms
12054Connected to remote H8/300 HMS system.
12055(@value{GDBP}) load t.x
12056.text : 0x8000 .. 0xabde ***********
12057.data : 0xabde .. 0xad30 *
12058.stack : 0xf000 .. 0xf014 *
12059@end smallexample
12060
12061At this point, you're ready to run or debug your program. From here on,
12062you can use all the usual @value{GDBN} commands. The @code{break} command
12063sets breakpoints; the @code{run} command starts your program;
12064@code{print} or @code{x} display data; the @code{continue} command
12065resumes execution after stopping at a breakpoint. You can use the
12066@code{help} command at any time to find out more about @value{GDBN} commands.
12067
12068Remember, however, that @emph{operating system} facilities aren't
12069available on your development board; for example, if your program hangs,
12070you can't send an interrupt---but you can press the @sc{reset} switch!
12071
12072Use the @sc{reset} button on the development board
12073@itemize @bullet
12074@item
12075to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
12076no way to pass an interrupt signal to the development board); and
12077
12078@item
12079to return to the @value{GDBN} command prompt after your program finishes
12080normally. The communications protocol provides no other way for @value{GDBN}
12081to detect program completion.
12082@end itemize
12083
12084In either case, @value{GDBN} sees the effect of a @sc{reset} on the
12085development board as a ``normal exit'' of your program.
12086
172c2a43 12087@node Renesas ICE
8e04817f
AC
12088@subsubsection Using the E7000 in-circuit emulator
12089
172c2a43 12090@kindex target e7000@r{, with Renesas ICE}
8e04817f 12091You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 12092Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
12093e7000} command to connect @value{GDBN} to your E7000:
12094
12095@table @code
12096@item target e7000 @var{port} @var{speed}
12097Use this form if your E7000 is connected to a serial port. The
12098@var{port} argument identifies what serial port to use (for example,
12099@samp{com2}). The third argument is the line speed in bits per second
12100(for example, @samp{9600}).
12101
12102@item target e7000 @var{hostname}
12103If your E7000 is installed as a host on a TCP/IP network, you can just
12104specify its hostname; @value{GDBN} uses @code{telnet} to connect.
12105@end table
12106
172c2a43
KI
12107@node Renesas Special
12108@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
12109
12110Some @value{GDBN} commands are available only for the H8/300:
12111
12112@table @code
12113
12114@kindex set machine
12115@kindex show machine
12116@item set machine h8300
12117@itemx set machine h8300h
12118Condition @value{GDBN} for one of the two variants of the H8/300
12119architecture with @samp{set machine}. You can use @samp{show machine}
12120to check which variant is currently in effect.
104c1213
JM
12121
12122@end table
12123
8e04817f
AC
12124@node H8/500
12125@subsection H8/500
104c1213
JM
12126
12127@table @code
12128
8e04817f
AC
12129@kindex set memory @var{mod}
12130@cindex memory models, H8/500
12131@item set memory @var{mod}
12132@itemx show memory
12133Specify which H8/500 memory model (@var{mod}) you are using with
12134@samp{set memory}; check which memory model is in effect with @samp{show
12135memory}. The accepted values for @var{mod} are @code{small},
12136@code{big}, @code{medium}, and @code{compact}.
104c1213 12137
8e04817f 12138@end table
104c1213 12139
8e04817f 12140@node M32R/D
172c2a43 12141@subsection Renesas M32R/D
8e04817f
AC
12142
12143@table @code
12144
12145@kindex target m32r
12146@item target m32r @var{dev}
172c2a43 12147Renesas M32R/D ROM monitor.
8e04817f 12148
fb3e19c0
KI
12149@kindex target m32rsdi
12150@item target m32rsdi @var{dev}
12151Renesas M32R SDI server, connected via parallel port to the board.
12152
8e04817f
AC
12153@end table
12154
12155@node M68K
12156@subsection M68k
12157
12158The Motorola m68k configuration includes ColdFire support, and
12159target command for the following ROM monitors.
12160
12161@table @code
12162
12163@kindex target abug
12164@item target abug @var{dev}
12165ABug ROM monitor for M68K.
12166
12167@kindex target cpu32bug
12168@item target cpu32bug @var{dev}
12169CPU32BUG monitor, running on a CPU32 (M68K) board.
12170
12171@kindex target dbug
12172@item target dbug @var{dev}
12173dBUG ROM monitor for Motorola ColdFire.
12174
12175@kindex target est
12176@item target est @var{dev}
12177EST-300 ICE monitor, running on a CPU32 (M68K) board.
12178
12179@kindex target rom68k
12180@item target rom68k @var{dev}
12181ROM 68K monitor, running on an M68K IDP board.
12182
12183@end table
12184
8e04817f
AC
12185@table @code
12186
12187@kindex target rombug
12188@item target rombug @var{dev}
12189ROMBUG ROM monitor for OS/9000.
12190
12191@end table
12192
8e04817f
AC
12193@node MIPS Embedded
12194@subsection MIPS Embedded
12195
12196@cindex MIPS boards
12197@value{GDBN} can use the MIPS remote debugging protocol to talk to a
12198MIPS board attached to a serial line. This is available when
12199you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 12200
8e04817f
AC
12201@need 1000
12202Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 12203
8e04817f
AC
12204@table @code
12205@item target mips @var{port}
12206@kindex target mips @var{port}
12207To run a program on the board, start up @code{@value{GDBP}} with the
12208name of your program as the argument. To connect to the board, use the
12209command @samp{target mips @var{port}}, where @var{port} is the name of
12210the serial port connected to the board. If the program has not already
12211been downloaded to the board, you may use the @code{load} command to
12212download it. You can then use all the usual @value{GDBN} commands.
104c1213 12213
8e04817f
AC
12214For example, this sequence connects to the target board through a serial
12215port, and loads and runs a program called @var{prog} through the
12216debugger:
104c1213 12217
474c8240 12218@smallexample
8e04817f
AC
12219host$ @value{GDBP} @var{prog}
12220@value{GDBN} is free software and @dots{}
12221(@value{GDBP}) target mips /dev/ttyb
12222(@value{GDBP}) load @var{prog}
12223(@value{GDBP}) run
474c8240 12224@end smallexample
104c1213 12225
8e04817f
AC
12226@item target mips @var{hostname}:@var{portnumber}
12227On some @value{GDBN} host configurations, you can specify a TCP
12228connection (for instance, to a serial line managed by a terminal
12229concentrator) instead of a serial port, using the syntax
12230@samp{@var{hostname}:@var{portnumber}}.
104c1213 12231
8e04817f
AC
12232@item target pmon @var{port}
12233@kindex target pmon @var{port}
12234PMON ROM monitor.
104c1213 12235
8e04817f
AC
12236@item target ddb @var{port}
12237@kindex target ddb @var{port}
12238NEC's DDB variant of PMON for Vr4300.
104c1213 12239
8e04817f
AC
12240@item target lsi @var{port}
12241@kindex target lsi @var{port}
12242LSI variant of PMON.
104c1213 12243
8e04817f
AC
12244@kindex target r3900
12245@item target r3900 @var{dev}
12246Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 12247
8e04817f
AC
12248@kindex target array
12249@item target array @var{dev}
12250Array Tech LSI33K RAID controller board.
104c1213 12251
8e04817f 12252@end table
104c1213 12253
104c1213 12254
8e04817f
AC
12255@noindent
12256@value{GDBN} also supports these special commands for MIPS targets:
104c1213 12257
8e04817f
AC
12258@table @code
12259@item set processor @var{args}
12260@itemx show processor
12261@kindex set processor @var{args}
12262@kindex show processor
12263Use the @code{set processor} command to set the type of MIPS
12264processor when you want to access processor-type-specific registers.
12265For example, @code{set processor @var{r3041}} tells @value{GDBN}
12266to use the CPU registers appropriate for the 3041 chip.
12267Use the @code{show processor} command to see what MIPS processor @value{GDBN}
12268is using. Use the @code{info reg} command to see what registers
12269@value{GDBN} is using.
104c1213 12270
8e04817f
AC
12271@item set mipsfpu double
12272@itemx set mipsfpu single
12273@itemx set mipsfpu none
12274@itemx show mipsfpu
12275@kindex set mipsfpu
12276@kindex show mipsfpu
12277@cindex MIPS remote floating point
12278@cindex floating point, MIPS remote
12279If your target board does not support the MIPS floating point
12280coprocessor, you should use the command @samp{set mipsfpu none} (if you
12281need this, you may wish to put the command in your @value{GDBN} init
12282file). This tells @value{GDBN} how to find the return value of
12283functions which return floating point values. It also allows
12284@value{GDBN} to avoid saving the floating point registers when calling
12285functions on the board. If you are using a floating point coprocessor
12286with only single precision floating point support, as on the @sc{r4650}
12287processor, use the command @samp{set mipsfpu single}. The default
12288double precision floating point coprocessor may be selected using
12289@samp{set mipsfpu double}.
104c1213 12290
8e04817f
AC
12291In previous versions the only choices were double precision or no
12292floating point, so @samp{set mipsfpu on} will select double precision
12293and @samp{set mipsfpu off} will select no floating point.
104c1213 12294
8e04817f
AC
12295As usual, you can inquire about the @code{mipsfpu} variable with
12296@samp{show mipsfpu}.
104c1213 12297
8e04817f
AC
12298@item set remotedebug @var{n}
12299@itemx show remotedebug
12300@kindex set remotedebug@r{, MIPS protocol}
12301@kindex show remotedebug@r{, MIPS protocol}
12302@cindex @code{remotedebug}, MIPS protocol
12303@cindex MIPS @code{remotedebug} protocol
12304@c FIXME! For this to be useful, you must know something about the MIPS
12305@c FIXME...protocol. Where is it described?
12306You can see some debugging information about communications with the board
12307by setting the @code{remotedebug} variable. If you set it to @code{1} using
12308@samp{set remotedebug 1}, every packet is displayed. If you set it
12309to @code{2}, every character is displayed. You can check the current value
12310at any time with the command @samp{show remotedebug}.
104c1213 12311
8e04817f
AC
12312@item set timeout @var{seconds}
12313@itemx set retransmit-timeout @var{seconds}
12314@itemx show timeout
12315@itemx show retransmit-timeout
12316@cindex @code{timeout}, MIPS protocol
12317@cindex @code{retransmit-timeout}, MIPS protocol
12318@kindex set timeout
12319@kindex show timeout
12320@kindex set retransmit-timeout
12321@kindex show retransmit-timeout
12322You can control the timeout used while waiting for a packet, in the MIPS
12323remote protocol, with the @code{set timeout @var{seconds}} command. The
12324default is 5 seconds. Similarly, you can control the timeout used while
12325waiting for an acknowledgement of a packet with the @code{set
12326retransmit-timeout @var{seconds}} command. The default is 3 seconds.
12327You can inspect both values with @code{show timeout} and @code{show
12328retransmit-timeout}. (These commands are @emph{only} available when
12329@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 12330
8e04817f
AC
12331The timeout set by @code{set timeout} does not apply when @value{GDBN}
12332is waiting for your program to stop. In that case, @value{GDBN} waits
12333forever because it has no way of knowing how long the program is going
12334to run before stopping.
12335@end table
104c1213 12336
a37295f9
MM
12337@node OpenRISC 1000
12338@subsection OpenRISC 1000
12339@cindex OpenRISC 1000
12340
12341@cindex or1k boards
12342See OR1k Architecture document (@uref{www.opencores.org}) for more information
12343about platform and commands.
12344
12345@table @code
12346
12347@kindex target jtag
12348@item target jtag jtag://@var{host}:@var{port}
12349
12350Connects to remote JTAG server.
12351JTAG remote server can be either an or1ksim or JTAG server,
12352connected via parallel port to the board.
12353
12354Example: @code{target jtag jtag://localhost:9999}
12355
12356@kindex or1ksim
12357@item or1ksim @var{command}
12358If connected to @code{or1ksim} OpenRISC 1000 Architectural
12359Simulator, proprietary commands can be executed.
12360
12361@kindex info or1k spr
12362@item info or1k spr
12363Displays spr groups.
12364
12365@item info or1k spr @var{group}
12366@itemx info or1k spr @var{groupno}
12367Displays register names in selected group.
12368
12369@item info or1k spr @var{group} @var{register}
12370@itemx info or1k spr @var{register}
12371@itemx info or1k spr @var{groupno} @var{registerno}
12372@itemx info or1k spr @var{registerno}
12373Shows information about specified spr register.
12374
12375@kindex spr
12376@item spr @var{group} @var{register} @var{value}
12377@itemx spr @var{register @var{value}}
12378@itemx spr @var{groupno} @var{registerno @var{value}}
12379@itemx spr @var{registerno @var{value}}
12380Writes @var{value} to specified spr register.
12381@end table
12382
12383Some implementations of OpenRISC 1000 Architecture also have hardware trace.
12384It is very similar to @value{GDBN} trace, except it does not interfere with normal
12385program execution and is thus much faster. Hardware breakpoints/watchpoint
12386triggers can be set using:
12387@table @code
12388@item $LEA/$LDATA
12389Load effective address/data
12390@item $SEA/$SDATA
12391Store effective address/data
12392@item $AEA/$ADATA
12393Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
12394@item $FETCH
12395Fetch data
12396@end table
12397
12398When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
12399@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
12400
12401@code{htrace} commands:
12402@cindex OpenRISC 1000 htrace
12403@table @code
12404@kindex hwatch
12405@item hwatch @var{conditional}
12406Set hardware watchpoint on combination of Load/Store Effecive Address(es)
12407or Data. For example:
12408
12409@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12410
12411@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
12412
12413@kindex htrace info
12414@item htrace info
12415Display information about current HW trace configuration.
12416
12417@kindex htrace trigger
12418@item htrace trigger @var{conditional}
12419Set starting criteria for HW trace.
12420
12421@kindex htrace qualifier
12422@item htrace qualifier @var{conditional}
12423Set acquisition qualifier for HW trace.
12424
12425@kindex htrace stop
12426@item htrace stop @var{conditional}
12427Set HW trace stopping criteria.
12428
12429@kindex htrace record
f153cc92 12430@item htrace record [@var{data}]*
a37295f9
MM
12431Selects the data to be recorded, when qualifier is met and HW trace was
12432triggered.
12433
12434@kindex htrace enable
12435@item htrace enable
12436@kindex htrace disable
12437@itemx htrace disable
12438Enables/disables the HW trace.
12439
12440@kindex htrace rewind
f153cc92 12441@item htrace rewind [@var{filename}]
a37295f9
MM
12442Clears currently recorded trace data.
12443
12444If filename is specified, new trace file is made and any newly collected data
12445will be written there.
12446
12447@kindex htrace print
f153cc92 12448@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
12449Prints trace buffer, using current record configuration.
12450
12451@kindex htrace mode continuous
12452@item htrace mode continuous
12453Set continuous trace mode.
12454
12455@kindex htrace mode suspend
12456@item htrace mode suspend
12457Set suspend trace mode.
12458
12459@end table
12460
8e04817f
AC
12461@node PowerPC
12462@subsection PowerPC
104c1213
JM
12463
12464@table @code
104c1213 12465
8e04817f
AC
12466@kindex target dink32
12467@item target dink32 @var{dev}
12468DINK32 ROM monitor.
104c1213 12469
8e04817f
AC
12470@kindex target ppcbug
12471@item target ppcbug @var{dev}
12472@kindex target ppcbug1
12473@item target ppcbug1 @var{dev}
12474PPCBUG ROM monitor for PowerPC.
104c1213 12475
8e04817f
AC
12476@kindex target sds
12477@item target sds @var{dev}
12478SDS monitor, running on a PowerPC board (such as Motorola's ADS).
12479
12480@end table
12481
12482@node PA
12483@subsection HP PA Embedded
104c1213
JM
12484
12485@table @code
12486
8e04817f
AC
12487@kindex target op50n
12488@item target op50n @var{dev}
12489OP50N monitor, running on an OKI HPPA board.
12490
12491@kindex target w89k
12492@item target w89k @var{dev}
12493W89K monitor, running on a Winbond HPPA board.
104c1213
JM
12494
12495@end table
12496
8e04817f 12497@node SH
172c2a43 12498@subsection Renesas SH
104c1213
JM
12499
12500@table @code
12501
172c2a43 12502@kindex target hms@r{, with Renesas SH}
8e04817f 12503@item target hms @var{dev}
172c2a43 12504A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
12505commands @code{device} and @code{speed} to control the serial line and
12506the communications speed used.
104c1213 12507
172c2a43 12508@kindex target e7000@r{, with Renesas SH}
8e04817f 12509@item target e7000 @var{dev}
172c2a43 12510E7000 emulator for Renesas SH.
104c1213 12511
8e04817f
AC
12512@kindex target sh3@r{, with SH}
12513@kindex target sh3e@r{, with SH}
12514@item target sh3 @var{dev}
12515@item target sh3e @var{dev}
172c2a43 12516Renesas SH-3 and SH-3E target systems.
104c1213 12517
8e04817f 12518@end table
104c1213 12519
8e04817f
AC
12520@node Sparclet
12521@subsection Tsqware Sparclet
104c1213 12522
8e04817f
AC
12523@cindex Sparclet
12524
12525@value{GDBN} enables developers to debug tasks running on
12526Sparclet targets from a Unix host.
12527@value{GDBN} uses code that runs on
12528both the Unix host and on the Sparclet target. The program
12529@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 12530
8e04817f
AC
12531@table @code
12532@item remotetimeout @var{args}
12533@kindex remotetimeout
12534@value{GDBN} supports the option @code{remotetimeout}.
12535This option is set by the user, and @var{args} represents the number of
12536seconds @value{GDBN} waits for responses.
104c1213
JM
12537@end table
12538
8e04817f
AC
12539@cindex compiling, on Sparclet
12540When compiling for debugging, include the options @samp{-g} to get debug
12541information and @samp{-Ttext} to relocate the program to where you wish to
12542load it on the target. You may also want to add the options @samp{-n} or
12543@samp{-N} in order to reduce the size of the sections. Example:
104c1213 12544
474c8240 12545@smallexample
8e04817f 12546sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 12547@end smallexample
104c1213 12548
8e04817f 12549You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 12550
474c8240 12551@smallexample
8e04817f 12552sparclet-aout-objdump --headers --syms prog
474c8240 12553@end smallexample
104c1213 12554
8e04817f
AC
12555@cindex running, on Sparclet
12556Once you have set
12557your Unix execution search path to find @value{GDBN}, you are ready to
12558run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
12559(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 12560
8e04817f
AC
12561@value{GDBN} comes up showing the prompt:
12562
474c8240 12563@smallexample
8e04817f 12564(gdbslet)
474c8240 12565@end smallexample
104c1213
JM
12566
12567@menu
8e04817f
AC
12568* Sparclet File:: Setting the file to debug
12569* Sparclet Connection:: Connecting to Sparclet
12570* Sparclet Download:: Sparclet download
12571* Sparclet Execution:: Running and debugging
104c1213
JM
12572@end menu
12573
8e04817f
AC
12574@node Sparclet File
12575@subsubsection Setting file to debug
104c1213 12576
8e04817f 12577The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 12578
474c8240 12579@smallexample
8e04817f 12580(gdbslet) file prog
474c8240 12581@end smallexample
104c1213 12582
8e04817f
AC
12583@need 1000
12584@value{GDBN} then attempts to read the symbol table of @file{prog}.
12585@value{GDBN} locates
12586the file by searching the directories listed in the command search
12587path.
12588If the file was compiled with debug information (option "-g"), source
12589files will be searched as well.
12590@value{GDBN} locates
12591the source files by searching the directories listed in the directory search
12592path (@pxref{Environment, ,Your program's environment}).
12593If it fails
12594to find a file, it displays a message such as:
104c1213 12595
474c8240 12596@smallexample
8e04817f 12597prog: No such file or directory.
474c8240 12598@end smallexample
104c1213 12599
8e04817f
AC
12600When this happens, add the appropriate directories to the search paths with
12601the @value{GDBN} commands @code{path} and @code{dir}, and execute the
12602@code{target} command again.
104c1213 12603
8e04817f
AC
12604@node Sparclet Connection
12605@subsubsection Connecting to Sparclet
104c1213 12606
8e04817f
AC
12607The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
12608To connect to a target on serial port ``@code{ttya}'', type:
104c1213 12609
474c8240 12610@smallexample
8e04817f
AC
12611(gdbslet) target sparclet /dev/ttya
12612Remote target sparclet connected to /dev/ttya
12613main () at ../prog.c:3
474c8240 12614@end smallexample
104c1213 12615
8e04817f
AC
12616@need 750
12617@value{GDBN} displays messages like these:
104c1213 12618
474c8240 12619@smallexample
8e04817f 12620Connected to ttya.
474c8240 12621@end smallexample
104c1213 12622
8e04817f
AC
12623@node Sparclet Download
12624@subsubsection Sparclet download
104c1213 12625
8e04817f
AC
12626@cindex download to Sparclet
12627Once connected to the Sparclet target,
12628you can use the @value{GDBN}
12629@code{load} command to download the file from the host to the target.
12630The file name and load offset should be given as arguments to the @code{load}
12631command.
12632Since the file format is aout, the program must be loaded to the starting
12633address. You can use @code{objdump} to find out what this value is. The load
12634offset is an offset which is added to the VMA (virtual memory address)
12635of each of the file's sections.
12636For instance, if the program
12637@file{prog} was linked to text address 0x1201000, with data at 0x12010160
12638and bss at 0x12010170, in @value{GDBN}, type:
104c1213 12639
474c8240 12640@smallexample
8e04817f
AC
12641(gdbslet) load prog 0x12010000
12642Loading section .text, size 0xdb0 vma 0x12010000
474c8240 12643@end smallexample
104c1213 12644
8e04817f
AC
12645If the code is loaded at a different address then what the program was linked
12646to, you may need to use the @code{section} and @code{add-symbol-file} commands
12647to tell @value{GDBN} where to map the symbol table.
12648
12649@node Sparclet Execution
12650@subsubsection Running and debugging
12651
12652@cindex running and debugging Sparclet programs
12653You can now begin debugging the task using @value{GDBN}'s execution control
12654commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
12655manual for the list of commands.
12656
474c8240 12657@smallexample
8e04817f
AC
12658(gdbslet) b main
12659Breakpoint 1 at 0x12010000: file prog.c, line 3.
12660(gdbslet) run
12661Starting program: prog
12662Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
126633 char *symarg = 0;
12664(gdbslet) step
126654 char *execarg = "hello!";
12666(gdbslet)
474c8240 12667@end smallexample
8e04817f
AC
12668
12669@node Sparclite
12670@subsection Fujitsu Sparclite
104c1213
JM
12671
12672@table @code
12673
8e04817f
AC
12674@kindex target sparclite
12675@item target sparclite @var{dev}
12676Fujitsu sparclite boards, used only for the purpose of loading.
12677You must use an additional command to debug the program.
12678For example: target remote @var{dev} using @value{GDBN} standard
12679remote protocol.
104c1213
JM
12680
12681@end table
12682
8e04817f
AC
12683@node ST2000
12684@subsection Tandem ST2000
104c1213 12685
8e04817f
AC
12686@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
12687STDBUG protocol.
104c1213 12688
8e04817f
AC
12689To connect your ST2000 to the host system, see the manufacturer's
12690manual. Once the ST2000 is physically attached, you can run:
104c1213 12691
474c8240 12692@smallexample
8e04817f 12693target st2000 @var{dev} @var{speed}
474c8240 12694@end smallexample
104c1213 12695
8e04817f
AC
12696@noindent
12697to establish it as your debugging environment. @var{dev} is normally
12698the name of a serial device, such as @file{/dev/ttya}, connected to the
12699ST2000 via a serial line. You can instead specify @var{dev} as a TCP
12700connection (for example, to a serial line attached via a terminal
12701concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 12702
8e04817f
AC
12703The @code{load} and @code{attach} commands are @emph{not} defined for
12704this target; you must load your program into the ST2000 as you normally
12705would for standalone operation. @value{GDBN} reads debugging information
12706(such as symbols) from a separate, debugging version of the program
12707available on your host computer.
12708@c FIXME!! This is terribly vague; what little content is here is
12709@c basically hearsay.
104c1213 12710
8e04817f
AC
12711@cindex ST2000 auxiliary commands
12712These auxiliary @value{GDBN} commands are available to help you with the ST2000
12713environment:
104c1213 12714
8e04817f
AC
12715@table @code
12716@item st2000 @var{command}
12717@kindex st2000 @var{cmd}
12718@cindex STDBUG commands (ST2000)
12719@cindex commands to STDBUG (ST2000)
12720Send a @var{command} to the STDBUG monitor. See the manufacturer's
12721manual for available commands.
104c1213 12722
8e04817f
AC
12723@item connect
12724@cindex connect (to STDBUG)
12725Connect the controlling terminal to the STDBUG command monitor. When
12726you are done interacting with STDBUG, typing either of two character
12727sequences gets you back to the @value{GDBN} command prompt:
12728@kbd{@key{RET}~.} (Return, followed by tilde and period) or
12729@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
12730@end table
12731
8e04817f
AC
12732@node Z8000
12733@subsection Zilog Z8000
104c1213 12734
8e04817f
AC
12735@cindex Z8000
12736@cindex simulator, Z8000
12737@cindex Zilog Z8000 simulator
104c1213 12738
8e04817f
AC
12739When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
12740a Z8000 simulator.
12741
12742For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
12743unsegmented variant of the Z8000 architecture) or the Z8001 (the
12744segmented variant). The simulator recognizes which architecture is
12745appropriate by inspecting the object code.
104c1213 12746
8e04817f
AC
12747@table @code
12748@item target sim @var{args}
12749@kindex sim
12750@kindex target sim@r{, with Z8000}
12751Debug programs on a simulated CPU. If the simulator supports setup
12752options, specify them via @var{args}.
104c1213
JM
12753@end table
12754
8e04817f
AC
12755@noindent
12756After specifying this target, you can debug programs for the simulated
12757CPU in the same style as programs for your host computer; use the
12758@code{file} command to load a new program image, the @code{run} command
12759to run your program, and so on.
12760
12761As well as making available all the usual machine registers
12762(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
12763additional items of information as specially named registers:
104c1213
JM
12764
12765@table @code
12766
8e04817f
AC
12767@item cycles
12768Counts clock-ticks in the simulator.
104c1213 12769
8e04817f
AC
12770@item insts
12771Counts instructions run in the simulator.
104c1213 12772
8e04817f
AC
12773@item time
12774Execution time in 60ths of a second.
104c1213 12775
8e04817f 12776@end table
104c1213 12777
8e04817f
AC
12778You can refer to these values in @value{GDBN} expressions with the usual
12779conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
12780conditional breakpoint that suspends only after at least 5000
12781simulated clock ticks.
104c1213 12782
8e04817f
AC
12783@node Architectures
12784@section Architectures
104c1213 12785
8e04817f
AC
12786This section describes characteristics of architectures that affect
12787all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 12788
8e04817f
AC
12789@menu
12790* A29K::
12791* Alpha::
12792* MIPS::
12793@end menu
104c1213 12794
8e04817f
AC
12795@node A29K
12796@subsection A29K
104c1213
JM
12797
12798@table @code
104c1213 12799
8e04817f
AC
12800@kindex set rstack_high_address
12801@cindex AMD 29K register stack
12802@cindex register stack, AMD29K
12803@item set rstack_high_address @var{address}
12804On AMD 29000 family processors, registers are saved in a separate
12805@dfn{register stack}. There is no way for @value{GDBN} to determine the
12806extent of this stack. Normally, @value{GDBN} just assumes that the
12807stack is ``large enough''. This may result in @value{GDBN} referencing
12808memory locations that do not exist. If necessary, you can get around
12809this problem by specifying the ending address of the register stack with
12810the @code{set rstack_high_address} command. The argument should be an
12811address, which you probably want to precede with @samp{0x} to specify in
12812hexadecimal.
104c1213 12813
8e04817f
AC
12814@kindex show rstack_high_address
12815@item show rstack_high_address
12816Display the current limit of the register stack, on AMD 29000 family
12817processors.
104c1213 12818
8e04817f 12819@end table
104c1213 12820
8e04817f
AC
12821@node Alpha
12822@subsection Alpha
104c1213 12823
8e04817f 12824See the following section.
104c1213 12825
8e04817f
AC
12826@node MIPS
12827@subsection MIPS
104c1213 12828
8e04817f
AC
12829@cindex stack on Alpha
12830@cindex stack on MIPS
12831@cindex Alpha stack
12832@cindex MIPS stack
12833Alpha- and MIPS-based computers use an unusual stack frame, which
12834sometimes requires @value{GDBN} to search backward in the object code to
12835find the beginning of a function.
104c1213 12836
8e04817f
AC
12837@cindex response time, MIPS debugging
12838To improve response time (especially for embedded applications, where
12839@value{GDBN} may be restricted to a slow serial line for this search)
12840you may want to limit the size of this search, using one of these
12841commands:
104c1213 12842
8e04817f
AC
12843@table @code
12844@cindex @code{heuristic-fence-post} (Alpha, MIPS)
12845@item set heuristic-fence-post @var{limit}
12846Restrict @value{GDBN} to examining at most @var{limit} bytes in its
12847search for the beginning of a function. A value of @var{0} (the
12848default) means there is no limit. However, except for @var{0}, the
12849larger the limit the more bytes @code{heuristic-fence-post} must search
12850and therefore the longer it takes to run.
104c1213 12851
8e04817f
AC
12852@item show heuristic-fence-post
12853Display the current limit.
12854@end table
104c1213
JM
12855
12856@noindent
8e04817f
AC
12857These commands are available @emph{only} when @value{GDBN} is configured
12858for debugging programs on Alpha or MIPS processors.
104c1213 12859
104c1213 12860
8e04817f
AC
12861@node Controlling GDB
12862@chapter Controlling @value{GDBN}
12863
12864You can alter the way @value{GDBN} interacts with you by using the
12865@code{set} command. For commands controlling how @value{GDBN} displays
12866data, see @ref{Print Settings, ,Print settings}. Other settings are
12867described here.
12868
12869@menu
12870* Prompt:: Prompt
12871* Editing:: Command editing
12872* History:: Command history
12873* Screen Size:: Screen size
12874* Numbers:: Numbers
1e698235 12875* ABI:: Configuring the current ABI
8e04817f
AC
12876* Messages/Warnings:: Optional warnings and messages
12877* Debugging Output:: Optional messages about internal happenings
12878@end menu
12879
12880@node Prompt
12881@section Prompt
104c1213 12882
8e04817f 12883@cindex prompt
104c1213 12884
8e04817f
AC
12885@value{GDBN} indicates its readiness to read a command by printing a string
12886called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
12887can change the prompt string with the @code{set prompt} command. For
12888instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
12889the prompt in one of the @value{GDBN} sessions so that you can always tell
12890which one you are talking to.
104c1213 12891
8e04817f
AC
12892@emph{Note:} @code{set prompt} does not add a space for you after the
12893prompt you set. This allows you to set a prompt which ends in a space
12894or a prompt that does not.
104c1213 12895
8e04817f
AC
12896@table @code
12897@kindex set prompt
12898@item set prompt @var{newprompt}
12899Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 12900
8e04817f
AC
12901@kindex show prompt
12902@item show prompt
12903Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
12904@end table
12905
8e04817f
AC
12906@node Editing
12907@section Command editing
12908@cindex readline
12909@cindex command line editing
104c1213 12910
8e04817f
AC
12911@value{GDBN} reads its input commands via the @dfn{readline} interface. This
12912@sc{gnu} library provides consistent behavior for programs which provide a
12913command line interface to the user. Advantages are @sc{gnu} Emacs-style
12914or @dfn{vi}-style inline editing of commands, @code{csh}-like history
12915substitution, and a storage and recall of command history across
12916debugging sessions.
104c1213 12917
8e04817f
AC
12918You may control the behavior of command line editing in @value{GDBN} with the
12919command @code{set}.
104c1213 12920
8e04817f
AC
12921@table @code
12922@kindex set editing
12923@cindex editing
12924@item set editing
12925@itemx set editing on
12926Enable command line editing (enabled by default).
104c1213 12927
8e04817f
AC
12928@item set editing off
12929Disable command line editing.
104c1213 12930
8e04817f
AC
12931@kindex show editing
12932@item show editing
12933Show whether command line editing is enabled.
104c1213
JM
12934@end table
12935
8e04817f
AC
12936@node History
12937@section Command history
12938
12939@value{GDBN} can keep track of the commands you type during your
12940debugging sessions, so that you can be certain of precisely what
12941happened. Use these commands to manage the @value{GDBN} command
12942history facility.
104c1213
JM
12943
12944@table @code
8e04817f
AC
12945@cindex history substitution
12946@cindex history file
12947@kindex set history filename
12948@kindex GDBHISTFILE
12949@item set history filename @var{fname}
12950Set the name of the @value{GDBN} command history file to @var{fname}.
12951This is the file where @value{GDBN} reads an initial command history
12952list, and where it writes the command history from this session when it
12953exits. You can access this list through history expansion or through
12954the history command editing characters listed below. This file defaults
12955to the value of the environment variable @code{GDBHISTFILE}, or to
12956@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
12957is not set.
104c1213 12958
8e04817f
AC
12959@cindex history save
12960@kindex set history save
12961@item set history save
12962@itemx set history save on
12963Record command history in a file, whose name may be specified with the
12964@code{set history filename} command. By default, this option is disabled.
104c1213 12965
8e04817f
AC
12966@item set history save off
12967Stop recording command history in a file.
104c1213 12968
8e04817f
AC
12969@cindex history size
12970@kindex set history size
12971@item set history size @var{size}
12972Set the number of commands which @value{GDBN} keeps in its history list.
12973This defaults to the value of the environment variable
12974@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
12975@end table
12976
8e04817f
AC
12977@cindex history expansion
12978History expansion assigns special meaning to the character @kbd{!}.
12979@ifset have-readline-appendices
12980@xref{Event Designators}.
12981@end ifset
12982
12983Since @kbd{!} is also the logical not operator in C, history expansion
12984is off by default. If you decide to enable history expansion with the
12985@code{set history expansion on} command, you may sometimes need to
12986follow @kbd{!} (when it is used as logical not, in an expression) with
12987a space or a tab to prevent it from being expanded. The readline
12988history facilities do not attempt substitution on the strings
12989@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
12990
12991The commands to control history expansion are:
104c1213
JM
12992
12993@table @code
8e04817f
AC
12994@kindex set history expansion
12995@item set history expansion on
12996@itemx set history expansion
12997Enable history expansion. History expansion is off by default.
104c1213 12998
8e04817f
AC
12999@item set history expansion off
13000Disable history expansion.
104c1213 13001
8e04817f
AC
13002The readline code comes with more complete documentation of
13003editing and history expansion features. Users unfamiliar with @sc{gnu} Emacs
13004or @code{vi} may wish to read it.
13005@ifset have-readline-appendices
13006@xref{Command Line Editing}.
13007@end ifset
104c1213 13008
8e04817f
AC
13009@c @group
13010@kindex show history
13011@item show history
13012@itemx show history filename
13013@itemx show history save
13014@itemx show history size
13015@itemx show history expansion
13016These commands display the state of the @value{GDBN} history parameters.
13017@code{show history} by itself displays all four states.
13018@c @end group
13019@end table
13020
13021@table @code
13022@kindex shows
13023@item show commands
13024Display the last ten commands in the command history.
104c1213 13025
8e04817f
AC
13026@item show commands @var{n}
13027Print ten commands centered on command number @var{n}.
13028
13029@item show commands +
13030Print ten commands just after the commands last printed.
104c1213
JM
13031@end table
13032
8e04817f
AC
13033@node Screen Size
13034@section Screen size
13035@cindex size of screen
13036@cindex pauses in output
104c1213 13037
8e04817f
AC
13038Certain commands to @value{GDBN} may produce large amounts of
13039information output to the screen. To help you read all of it,
13040@value{GDBN} pauses and asks you for input at the end of each page of
13041output. Type @key{RET} when you want to continue the output, or @kbd{q}
13042to discard the remaining output. Also, the screen width setting
13043determines when to wrap lines of output. Depending on what is being
13044printed, @value{GDBN} tries to break the line at a readable place,
13045rather than simply letting it overflow onto the following line.
13046
13047Normally @value{GDBN} knows the size of the screen from the terminal
13048driver software. For example, on Unix @value{GDBN} uses the termcap data base
13049together with the value of the @code{TERM} environment variable and the
13050@code{stty rows} and @code{stty cols} settings. If this is not correct,
13051you can override it with the @code{set height} and @code{set
13052width} commands:
13053
13054@table @code
13055@kindex set height
13056@kindex set width
13057@kindex show width
13058@kindex show height
13059@item set height @var{lpp}
13060@itemx show height
13061@itemx set width @var{cpl}
13062@itemx show width
13063These @code{set} commands specify a screen height of @var{lpp} lines and
13064a screen width of @var{cpl} characters. The associated @code{show}
13065commands display the current settings.
104c1213 13066
8e04817f
AC
13067If you specify a height of zero lines, @value{GDBN} does not pause during
13068output no matter how long the output is. This is useful if output is to a
13069file or to an editor buffer.
104c1213 13070
8e04817f
AC
13071Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
13072from wrapping its output.
104c1213
JM
13073@end table
13074
8e04817f
AC
13075@node Numbers
13076@section Numbers
13077@cindex number representation
13078@cindex entering numbers
104c1213 13079
8e04817f
AC
13080You can always enter numbers in octal, decimal, or hexadecimal in
13081@value{GDBN} by the usual conventions: octal numbers begin with
13082@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
13083begin with @samp{0x}. Numbers that begin with none of these are, by
13084default, entered in base 10; likewise, the default display for
13085numbers---when no particular format is specified---is base 10. You can
13086change the default base for both input and output with the @code{set
13087radix} command.
104c1213 13088
8e04817f
AC
13089@table @code
13090@kindex set input-radix
13091@item set input-radix @var{base}
13092Set the default base for numeric input. Supported choices
13093for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13094specified either unambiguously or using the current default radix; for
13095example, any of
104c1213 13096
8e04817f
AC
13097@smallexample
13098set radix 012
13099set radix 10.
13100set radix 0xa
13101@end smallexample
104c1213 13102
8e04817f
AC
13103@noindent
13104sets the base to decimal. On the other hand, @samp{set radix 10}
13105leaves the radix unchanged no matter what it was.
104c1213 13106
8e04817f
AC
13107@kindex set output-radix
13108@item set output-radix @var{base}
13109Set the default base for numeric display. Supported choices
13110for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
13111specified either unambiguously or using the current default radix.
104c1213 13112
8e04817f
AC
13113@kindex show input-radix
13114@item show input-radix
13115Display the current default base for numeric input.
104c1213 13116
8e04817f
AC
13117@kindex show output-radix
13118@item show output-radix
13119Display the current default base for numeric display.
13120@end table
104c1213 13121
1e698235
DJ
13122@node ABI
13123@section Configuring the current ABI
13124
13125@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
13126application automatically. However, sometimes you need to override its
13127conclusions. Use these commands to manage @value{GDBN}'s view of the
13128current ABI.
13129
98b45e30
DJ
13130@cindex OS ABI
13131@kindex set osabi
b4e9345d 13132@kindex show osabi
98b45e30
DJ
13133
13134One @value{GDBN} configuration can debug binaries for multiple operating
13135system targets, either via remote debugging or native emulation.
13136@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
13137but you can override its conclusion using the @code{set osabi} command.
13138One example where this is useful is in debugging of binaries which use
13139an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
13140not have the same identifying marks that the standard C library for your
13141platform provides.
13142
13143@table @code
13144@item show osabi
13145Show the OS ABI currently in use.
13146
13147@item set osabi
13148With no argument, show the list of registered available OS ABI's.
13149
13150@item set osabi @var{abi}
13151Set the current OS ABI to @var{abi}.
13152@end table
13153
1e698235
DJ
13154@cindex float promotion
13155@kindex set coerce-float-to-double
13156
13157Generally, the way that an argument of type @code{float} is passed to a
13158function depends on whether the function is prototyped. For a prototyped
13159(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
13160according to the architecture's convention for @code{float}. For unprototyped
13161(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
13162@code{double} and then passed.
13163
13164Unfortunately, some forms of debug information do not reliably indicate whether
13165a function is prototyped. If @value{GDBN} calls a function that is not marked
13166as prototyped, it consults @kbd{set coerce-float-to-double}.
13167
13168@table @code
13169@item set coerce-float-to-double
13170@itemx set coerce-float-to-double on
13171Arguments of type @code{float} will be promoted to @code{double} when passed
13172to an unprototyped function. This is the default setting.
13173
13174@item set coerce-float-to-double off
13175Arguments of type @code{float} will be passed directly to unprototyped
13176functions.
13177@end table
13178
f1212245
DJ
13179@kindex set cp-abi
13180@kindex show cp-abi
13181@value{GDBN} needs to know the ABI used for your program's C@t{++}
13182objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
13183used to build your application. @value{GDBN} only fully supports
13184programs with a single C@t{++} ABI; if your program contains code using
13185multiple C@t{++} ABI's or if @value{GDBN} can not identify your
13186program's ABI correctly, you can tell @value{GDBN} which ABI to use.
13187Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
13188before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
13189``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
13190use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
13191``auto''.
13192
13193@table @code
13194@item show cp-abi
13195Show the C@t{++} ABI currently in use.
13196
13197@item set cp-abi
13198With no argument, show the list of supported C@t{++} ABI's.
13199
13200@item set cp-abi @var{abi}
13201@itemx set cp-abi auto
13202Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
13203@end table
13204
8e04817f
AC
13205@node Messages/Warnings
13206@section Optional warnings and messages
104c1213 13207
8e04817f
AC
13208By default, @value{GDBN} is silent about its inner workings. If you are
13209running on a slow machine, you may want to use the @code{set verbose}
13210command. This makes @value{GDBN} tell you when it does a lengthy
13211internal operation, so you will not think it has crashed.
104c1213 13212
8e04817f
AC
13213Currently, the messages controlled by @code{set verbose} are those
13214which announce that the symbol table for a source file is being read;
13215see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 13216
8e04817f
AC
13217@table @code
13218@kindex set verbose
13219@item set verbose on
13220Enables @value{GDBN} output of certain informational messages.
104c1213 13221
8e04817f
AC
13222@item set verbose off
13223Disables @value{GDBN} output of certain informational messages.
104c1213 13224
8e04817f
AC
13225@kindex show verbose
13226@item show verbose
13227Displays whether @code{set verbose} is on or off.
13228@end table
104c1213 13229
8e04817f
AC
13230By default, if @value{GDBN} encounters bugs in the symbol table of an
13231object file, it is silent; but if you are debugging a compiler, you may
13232find this information useful (@pxref{Symbol Errors, ,Errors reading
13233symbol files}).
104c1213 13234
8e04817f 13235@table @code
104c1213 13236
8e04817f
AC
13237@kindex set complaints
13238@item set complaints @var{limit}
13239Permits @value{GDBN} to output @var{limit} complaints about each type of
13240unusual symbols before becoming silent about the problem. Set
13241@var{limit} to zero to suppress all complaints; set it to a large number
13242to prevent complaints from being suppressed.
104c1213 13243
8e04817f
AC
13244@kindex show complaints
13245@item show complaints
13246Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 13247
8e04817f 13248@end table
104c1213 13249
8e04817f
AC
13250By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
13251lot of stupid questions to confirm certain commands. For example, if
13252you try to run a program which is already running:
104c1213 13253
474c8240 13254@smallexample
8e04817f
AC
13255(@value{GDBP}) run
13256The program being debugged has been started already.
13257Start it from the beginning? (y or n)
474c8240 13258@end smallexample
104c1213 13259
8e04817f
AC
13260If you are willing to unflinchingly face the consequences of your own
13261commands, you can disable this ``feature'':
104c1213 13262
8e04817f 13263@table @code
104c1213 13264
8e04817f
AC
13265@kindex set confirm
13266@cindex flinching
13267@cindex confirmation
13268@cindex stupid questions
13269@item set confirm off
13270Disables confirmation requests.
104c1213 13271
8e04817f
AC
13272@item set confirm on
13273Enables confirmation requests (the default).
104c1213 13274
8e04817f
AC
13275@kindex show confirm
13276@item show confirm
13277Displays state of confirmation requests.
13278
13279@end table
104c1213 13280
8e04817f
AC
13281@node Debugging Output
13282@section Optional messages about internal happenings
104c1213 13283@table @code
8e04817f
AC
13284@kindex set debug arch
13285@item set debug arch
13286Turns on or off display of gdbarch debugging info. The default is off
13287@kindex show debug arch
13288@item show debug arch
13289Displays the current state of displaying gdbarch debugging info.
13290@kindex set debug event
13291@item set debug event
13292Turns on or off display of @value{GDBN} event debugging info. The
13293default is off.
13294@kindex show debug event
13295@item show debug event
13296Displays the current state of displaying @value{GDBN} event debugging
13297info.
13298@kindex set debug expression
13299@item set debug expression
13300Turns on or off display of @value{GDBN} expression debugging info. The
13301default is off.
13302@kindex show debug expression
13303@item show debug expression
13304Displays the current state of displaying @value{GDBN} expression
13305debugging info.
7453dc06
AC
13306@kindex set debug frame
13307@item set debug frame
13308Turns on or off display of @value{GDBN} frame debugging info. The
13309default is off.
13310@kindex show debug frame
13311@item show debug frame
13312Displays the current state of displaying @value{GDBN} frame debugging
13313info.
8e04817f
AC
13314@kindex set debug overload
13315@item set debug overload
13316Turns on or off display of @value{GDBN} C@t{++} overload debugging
13317info. This includes info such as ranking of functions, etc. The default
13318is off.
13319@kindex show debug overload
13320@item show debug overload
13321Displays the current state of displaying @value{GDBN} C@t{++} overload
13322debugging info.
13323@kindex set debug remote
13324@cindex packets, reporting on stdout
13325@cindex serial connections, debugging
13326@item set debug remote
13327Turns on or off display of reports on all packets sent back and forth across
13328the serial line to the remote machine. The info is printed on the
13329@value{GDBN} standard output stream. The default is off.
13330@kindex show debug remote
13331@item show debug remote
13332Displays the state of display of remote packets.
13333@kindex set debug serial
13334@item set debug serial
13335Turns on or off display of @value{GDBN} serial debugging info. The
13336default is off.
13337@kindex show debug serial
13338@item show debug serial
13339Displays the current state of displaying @value{GDBN} serial debugging
13340info.
13341@kindex set debug target
13342@item set debug target
13343Turns on or off display of @value{GDBN} target debugging info. This info
13344includes what is going on at the target level of GDB, as it happens. The
13345default is off.
13346@kindex show debug target
13347@item show debug target
13348Displays the current state of displaying @value{GDBN} target debugging
13349info.
13350@kindex set debug varobj
13351@item set debug varobj
13352Turns on or off display of @value{GDBN} variable object debugging
13353info. The default is off.
13354@kindex show debug varobj
13355@item show debug varobj
13356Displays the current state of displaying @value{GDBN} variable object
13357debugging info.
13358@end table
104c1213 13359
8e04817f
AC
13360@node Sequences
13361@chapter Canned Sequences of Commands
104c1213 13362
8e04817f
AC
13363Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
13364command lists}), @value{GDBN} provides two ways to store sequences of
13365commands for execution as a unit: user-defined commands and command
13366files.
104c1213 13367
8e04817f
AC
13368@menu
13369* Define:: User-defined commands
13370* Hooks:: User-defined command hooks
13371* Command Files:: Command files
13372* Output:: Commands for controlled output
13373@end menu
104c1213 13374
8e04817f
AC
13375@node Define
13376@section User-defined commands
104c1213 13377
8e04817f
AC
13378@cindex user-defined command
13379A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
13380which you assign a new name as a command. This is done with the
13381@code{define} command. User commands may accept up to 10 arguments
13382separated by whitespace. Arguments are accessed within the user command
13383via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 13384
8e04817f
AC
13385@smallexample
13386define adder
13387 print $arg0 + $arg1 + $arg2
13388@end smallexample
104c1213
JM
13389
13390@noindent
8e04817f 13391To execute the command use:
104c1213 13392
8e04817f
AC
13393@smallexample
13394adder 1 2 3
13395@end smallexample
104c1213 13396
8e04817f
AC
13397@noindent
13398This defines the command @code{adder}, which prints the sum of
13399its three arguments. Note the arguments are text substitutions, so they may
13400reference variables, use complex expressions, or even perform inferior
13401functions calls.
104c1213
JM
13402
13403@table @code
104c1213 13404
8e04817f
AC
13405@kindex define
13406@item define @var{commandname}
13407Define a command named @var{commandname}. If there is already a command
13408by that name, you are asked to confirm that you want to redefine it.
104c1213 13409
8e04817f
AC
13410The definition of the command is made up of other @value{GDBN} command lines,
13411which are given following the @code{define} command. The end of these
13412commands is marked by a line containing @code{end}.
104c1213 13413
8e04817f
AC
13414@kindex if
13415@kindex else
13416@item if
13417Takes a single argument, which is an expression to evaluate.
13418It is followed by a series of commands that are executed
13419only if the expression is true (nonzero).
13420There can then optionally be a line @code{else}, followed
13421by a series of commands that are only executed if the expression
13422was false. The end of the list is marked by a line containing @code{end}.
104c1213 13423
8e04817f
AC
13424@kindex while
13425@item while
13426The syntax is similar to @code{if}: the command takes a single argument,
13427which is an expression to evaluate, and must be followed by the commands to
13428execute, one per line, terminated by an @code{end}.
13429The commands are executed repeatedly as long as the expression
13430evaluates to true.
104c1213 13431
8e04817f
AC
13432@kindex document
13433@item document @var{commandname}
13434Document the user-defined command @var{commandname}, so that it can be
13435accessed by @code{help}. The command @var{commandname} must already be
13436defined. This command reads lines of documentation just as @code{define}
13437reads the lines of the command definition, ending with @code{end}.
13438After the @code{document} command is finished, @code{help} on command
13439@var{commandname} displays the documentation you have written.
104c1213 13440
8e04817f
AC
13441You may use the @code{document} command again to change the
13442documentation of a command. Redefining the command with @code{define}
13443does not change the documentation.
104c1213 13444
8e04817f
AC
13445@kindex help user-defined
13446@item help user-defined
13447List all user-defined commands, with the first line of the documentation
13448(if any) for each.
104c1213 13449
8e04817f
AC
13450@kindex show user
13451@item show user
13452@itemx show user @var{commandname}
13453Display the @value{GDBN} commands used to define @var{commandname} (but
13454not its documentation). If no @var{commandname} is given, display the
13455definitions for all user-defined commands.
104c1213 13456
20f01a46
DH
13457@kindex show max-user-call-depth
13458@kindex set max-user-call-depth
13459@item show max-user-call-depth
5ca0cb28
DH
13460@itemx set max-user-call-depth
13461The value of @code{max-user-call-depth} controls how many recursion
13462levels are allowed in user-defined commands before GDB suspects an
13463infinite recursion and aborts the command.
20f01a46 13464
104c1213
JM
13465@end table
13466
8e04817f
AC
13467When user-defined commands are executed, the
13468commands of the definition are not printed. An error in any command
13469stops execution of the user-defined command.
104c1213 13470
8e04817f
AC
13471If used interactively, commands that would ask for confirmation proceed
13472without asking when used inside a user-defined command. Many @value{GDBN}
13473commands that normally print messages to say what they are doing omit the
13474messages when used in a user-defined command.
104c1213 13475
8e04817f
AC
13476@node Hooks
13477@section User-defined command hooks
13478@cindex command hooks
13479@cindex hooks, for commands
13480@cindex hooks, pre-command
104c1213 13481
8e04817f
AC
13482@kindex hook
13483@kindex hook-
13484You may define @dfn{hooks}, which are a special kind of user-defined
13485command. Whenever you run the command @samp{foo}, if the user-defined
13486command @samp{hook-foo} exists, it is executed (with no arguments)
13487before that command.
104c1213 13488
8e04817f
AC
13489@cindex hooks, post-command
13490@kindex hookpost
13491@kindex hookpost-
13492A hook may also be defined which is run after the command you executed.
13493Whenever you run the command @samp{foo}, if the user-defined command
13494@samp{hookpost-foo} exists, it is executed (with no arguments) after
13495that command. Post-execution hooks may exist simultaneously with
13496pre-execution hooks, for the same command.
104c1213 13497
8e04817f
AC
13498It is valid for a hook to call the command which it hooks. If this
13499occurs, the hook is not re-executed, thereby avoiding infinte recursion.
104c1213 13500
8e04817f
AC
13501@c It would be nice if hookpost could be passed a parameter indicating
13502@c if the command it hooks executed properly or not. FIXME!
104c1213 13503
8e04817f
AC
13504@kindex stop@r{, a pseudo-command}
13505In addition, a pseudo-command, @samp{stop} exists. Defining
13506(@samp{hook-stop}) makes the associated commands execute every time
13507execution stops in your program: before breakpoint commands are run,
13508displays are printed, or the stack frame is printed.
104c1213 13509
8e04817f
AC
13510For example, to ignore @code{SIGALRM} signals while
13511single-stepping, but treat them normally during normal execution,
13512you could define:
104c1213 13513
474c8240 13514@smallexample
8e04817f
AC
13515define hook-stop
13516handle SIGALRM nopass
13517end
104c1213 13518
8e04817f
AC
13519define hook-run
13520handle SIGALRM pass
13521end
104c1213 13522
8e04817f
AC
13523define hook-continue
13524handle SIGLARM pass
13525end
474c8240 13526@end smallexample
104c1213 13527
8e04817f
AC
13528As a further example, to hook at the begining and end of the @code{echo}
13529command, and to add extra text to the beginning and end of the message,
13530you could define:
104c1213 13531
474c8240 13532@smallexample
8e04817f
AC
13533define hook-echo
13534echo <<<---
13535end
104c1213 13536
8e04817f
AC
13537define hookpost-echo
13538echo --->>>\n
13539end
104c1213 13540
8e04817f
AC
13541(@value{GDBP}) echo Hello World
13542<<<---Hello World--->>>
13543(@value{GDBP})
104c1213 13544
474c8240 13545@end smallexample
104c1213 13546
8e04817f
AC
13547You can define a hook for any single-word command in @value{GDBN}, but
13548not for command aliases; you should define a hook for the basic command
13549name, e.g. @code{backtrace} rather than @code{bt}.
13550@c FIXME! So how does Joe User discover whether a command is an alias
13551@c or not?
13552If an error occurs during the execution of your hook, execution of
13553@value{GDBN} commands stops and @value{GDBN} issues a prompt
13554(before the command that you actually typed had a chance to run).
104c1213 13555
8e04817f
AC
13556If you try to define a hook which does not match any known command, you
13557get a warning from the @code{define} command.
c906108c 13558
8e04817f
AC
13559@node Command Files
13560@section Command files
c906108c 13561
8e04817f
AC
13562@cindex command files
13563A command file for @value{GDBN} is a file of lines that are @value{GDBN}
13564commands. Comments (lines starting with @kbd{#}) may also be included.
13565An empty line in a command file does nothing; it does not mean to repeat
13566the last command, as it would from the terminal.
c906108c 13567
8e04817f
AC
13568@cindex init file
13569@cindex @file{.gdbinit}
13570@cindex @file{gdb.ini}
13571When you start @value{GDBN}, it automatically executes commands from its
13572@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
13573port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
13574limitations of file names imposed by DOS filesystems.}.
13575During startup, @value{GDBN} does the following:
c906108c 13576
8e04817f
AC
13577@enumerate
13578@item
13579Reads the init file (if any) in your home directory@footnote{On
13580DOS/Windows systems, the home directory is the one pointed to by the
13581@code{HOME} environment variable.}.
c906108c 13582
8e04817f
AC
13583@item
13584Processes command line options and operands.
c906108c 13585
8e04817f
AC
13586@item
13587Reads the init file (if any) in the current working directory.
c906108c 13588
8e04817f
AC
13589@item
13590Reads command files specified by the @samp{-x} option.
13591@end enumerate
c906108c 13592
8e04817f
AC
13593The init file in your home directory can set options (such as @samp{set
13594complaints}) that affect subsequent processing of command line options
13595and operands. Init files are not executed if you use the @samp{-nx}
13596option (@pxref{Mode Options, ,Choosing modes}).
c906108c 13597
8e04817f
AC
13598@cindex init file name
13599On some configurations of @value{GDBN}, the init file is known by a
13600different name (these are typically environments where a specialized
13601form of @value{GDBN} may need to coexist with other forms, hence a
13602different name for the specialized version's init file). These are the
13603environments with special init file names:
c906108c 13604
8e04817f
AC
13605@cindex @file{.vxgdbinit}
13606@itemize @bullet
13607@item
13608VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 13609
8e04817f
AC
13610@cindex @file{.os68gdbinit}
13611@item
13612OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 13613
8e04817f
AC
13614@cindex @file{.esgdbinit}
13615@item
13616ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
13617@end itemize
c906108c 13618
8e04817f
AC
13619You can also request the execution of a command file with the
13620@code{source} command:
c906108c 13621
8e04817f
AC
13622@table @code
13623@kindex source
13624@item source @var{filename}
13625Execute the command file @var{filename}.
c906108c
SS
13626@end table
13627
8e04817f 13628The lines in a command file are executed sequentially. They are not
a71ec265
DH
13629printed as they are executed. An error in any command terminates
13630execution of the command file and control is returned to the console.
c906108c 13631
8e04817f
AC
13632Commands that would ask for confirmation if used interactively proceed
13633without asking when used in a command file. Many @value{GDBN} commands that
13634normally print messages to say what they are doing omit the messages
13635when called from command files.
c906108c 13636
8e04817f
AC
13637@value{GDBN} also accepts command input from standard input. In this
13638mode, normal output goes to standard output and error output goes to
13639standard error. Errors in a command file supplied on standard input do
13640not terminate execution of the command file --- execution continues with
13641the next command.
c906108c 13642
474c8240 13643@smallexample
8e04817f 13644gdb < cmds > log 2>&1
474c8240 13645@end smallexample
c906108c 13646
8e04817f
AC
13647(The syntax above will vary depending on the shell used.) This example
13648will execute commands from the file @file{cmds}. All output and errors
13649would be directed to @file{log}.
c906108c 13650
8e04817f
AC
13651@node Output
13652@section Commands for controlled output
c906108c 13653
8e04817f
AC
13654During the execution of a command file or a user-defined command, normal
13655@value{GDBN} output is suppressed; the only output that appears is what is
13656explicitly printed by the commands in the definition. This section
13657describes three commands useful for generating exactly the output you
13658want.
c906108c
SS
13659
13660@table @code
8e04817f
AC
13661@kindex echo
13662@item echo @var{text}
13663@c I do not consider backslash-space a standard C escape sequence
13664@c because it is not in ANSI.
13665Print @var{text}. Nonprinting characters can be included in
13666@var{text} using C escape sequences, such as @samp{\n} to print a
13667newline. @strong{No newline is printed unless you specify one.}
13668In addition to the standard C escape sequences, a backslash followed
13669by a space stands for a space. This is useful for displaying a
13670string with spaces at the beginning or the end, since leading and
13671trailing spaces are otherwise trimmed from all arguments.
13672To print @samp{@w{ }and foo =@w{ }}, use the command
13673@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 13674
8e04817f
AC
13675A backslash at the end of @var{text} can be used, as in C, to continue
13676the command onto subsequent lines. For example,
c906108c 13677
474c8240 13678@smallexample
8e04817f
AC
13679echo This is some text\n\
13680which is continued\n\
13681onto several lines.\n
474c8240 13682@end smallexample
c906108c 13683
8e04817f 13684produces the same output as
c906108c 13685
474c8240 13686@smallexample
8e04817f
AC
13687echo This is some text\n
13688echo which is continued\n
13689echo onto several lines.\n
474c8240 13690@end smallexample
c906108c 13691
8e04817f
AC
13692@kindex output
13693@item output @var{expression}
13694Print the value of @var{expression} and nothing but that value: no
13695newlines, no @samp{$@var{nn} = }. The value is not entered in the
13696value history either. @xref{Expressions, ,Expressions}, for more information
13697on expressions.
c906108c 13698
8e04817f
AC
13699@item output/@var{fmt} @var{expression}
13700Print the value of @var{expression} in format @var{fmt}. You can use
13701the same formats as for @code{print}. @xref{Output Formats,,Output
13702formats}, for more information.
c906108c 13703
8e04817f
AC
13704@kindex printf
13705@item printf @var{string}, @var{expressions}@dots{}
13706Print the values of the @var{expressions} under the control of
13707@var{string}. The @var{expressions} are separated by commas and may be
13708either numbers or pointers. Their values are printed as specified by
13709@var{string}, exactly as if your program were to execute the C
13710subroutine
13711@c FIXME: the above implies that at least all ANSI C formats are
13712@c supported, but it isn't true: %E and %G don't work (or so it seems).
13713@c Either this is a bug, or the manual should document what formats are
13714@c supported.
c906108c 13715
474c8240 13716@smallexample
8e04817f 13717printf (@var{string}, @var{expressions}@dots{});
474c8240 13718@end smallexample
c906108c 13719
8e04817f 13720For example, you can print two values in hex like this:
c906108c 13721
8e04817f
AC
13722@smallexample
13723printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
13724@end smallexample
c906108c 13725
8e04817f
AC
13726The only backslash-escape sequences that you can use in the format
13727string are the simple ones that consist of backslash followed by a
13728letter.
c906108c
SS
13729@end table
13730
21c294e6
AC
13731@node Interpreters
13732@chapter Command Interpreters
13733@cindex command interpreters
13734
13735@value{GDBN} supports multiple command interpreters, and some command
13736infrastructure to allow users or user interface writers to switch
13737between interpreters or run commands in other interpreters.
13738
13739@value{GDBN} currently supports two command interpreters, the console
13740interpreter (sometimes called the command-line interpreter or @sc{cli})
13741and the machine interface interpreter (or @sc{gdb/mi}). This manual
13742describes both of these interfaces in great detail.
13743
13744By default, @value{GDBN} will start with the console interpreter.
13745However, the user may choose to start @value{GDBN} with another
13746interpreter by specifying the @option{-i} or @option{--interpreter}
13747startup options. Defined interpreters include:
13748
13749@table @code
13750@item console
13751@cindex console interpreter
13752The traditional console or command-line interpreter. This is the most often
13753used interpreter with @value{GDBN}. With no interpreter specified at runtime,
13754@value{GDBN} will use this interpreter.
13755
13756@item mi
13757@cindex mi interpreter
13758The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
13759by programs wishing to use @value{GDBN} as a backend for a debugger GUI
13760or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
13761Interface}.
13762
13763@item mi2
13764@cindex mi2 interpreter
13765The current @sc{gdb/mi} interface.
13766
13767@item mi1
13768@cindex mi1 interpreter
13769The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
13770
13771@end table
13772
13773@cindex invoke another interpreter
13774The interpreter being used by @value{GDBN} may not be dynamically
13775switched at runtime. Although possible, this could lead to a very
13776precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
13777enters the command "interpreter-set console" in a console view,
13778@value{GDBN} would switch to using the console interpreter, rendering
13779the IDE inoperable!
13780
13781@kindex interpreter-exec
13782Although you may only choose a single interpreter at startup, you may execute
13783commands in any interpreter from the current interpreter using the appropriate
13784command. If you are running the console interpreter, simply use the
13785@code{interpreter-exec} command:
13786
13787@smallexample
13788interpreter-exec mi "-data-list-register-names"
13789@end smallexample
13790
13791@sc{gdb/mi} has a similar command, although it is only available in versions of
13792@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
13793
8e04817f
AC
13794@node TUI
13795@chapter @value{GDBN} Text User Interface
13796@cindex TUI
c906108c 13797
8e04817f
AC
13798@menu
13799* TUI Overview:: TUI overview
13800* TUI Keys:: TUI key bindings
7cf36c78 13801* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
13802* TUI Commands:: TUI specific commands
13803* TUI Configuration:: TUI configuration variables
13804@end menu
c906108c 13805
8e04817f
AC
13806The @value{GDBN} Text User Interface, TUI in short,
13807is a terminal interface which uses the @code{curses} library
13808to show the source file, the assembly output, the program registers
13809and @value{GDBN} commands in separate text windows.
13810The TUI is available only when @value{GDBN} is configured
13811with the @code{--enable-tui} configure option (@pxref{Configure Options}).
c906108c 13812
8e04817f
AC
13813@node TUI Overview
13814@section TUI overview
c906108c 13815
8e04817f
AC
13816The TUI has two display modes that can be switched while
13817@value{GDBN} runs:
c906108c 13818
8e04817f
AC
13819@itemize @bullet
13820@item
13821A curses (or TUI) mode in which it displays several text
13822windows on the terminal.
c906108c 13823
8e04817f
AC
13824@item
13825A standard mode which corresponds to the @value{GDBN} configured without
13826the TUI.
13827@end itemize
c906108c 13828
8e04817f
AC
13829In the TUI mode, @value{GDBN} can display several text window
13830on the terminal:
c906108c 13831
8e04817f
AC
13832@table @emph
13833@item command
13834This window is the @value{GDBN} command window with the @value{GDBN}
13835prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
13836managed using readline but through the TUI. The @emph{command}
13837window is always visible.
c906108c 13838
8e04817f
AC
13839@item source
13840The source window shows the source file of the program. The current
13841line as well as active breakpoints are displayed in this window.
c906108c 13842
8e04817f
AC
13843@item assembly
13844The assembly window shows the disassembly output of the program.
c906108c 13845
8e04817f
AC
13846@item register
13847This window shows the processor registers. It detects when
13848a register is changed and when this is the case, registers that have
13849changed are highlighted.
c906108c 13850
c906108c
SS
13851@end table
13852
269c21fe
SC
13853The source and assembly windows show the current program position
13854by highlighting the current line and marking them with the @samp{>} marker.
13855Breakpoints are also indicated with two markers. A first one
13856indicates the breakpoint type:
13857
13858@table @code
13859@item B
13860Breakpoint which was hit at least once.
13861
13862@item b
13863Breakpoint which was never hit.
13864
13865@item H
13866Hardware breakpoint which was hit at least once.
13867
13868@item h
13869Hardware breakpoint which was never hit.
13870
13871@end table
13872
13873The second marker indicates whether the breakpoint is enabled or not:
13874
13875@table @code
13876@item +
13877Breakpoint is enabled.
13878
13879@item -
13880Breakpoint is disabled.
13881
13882@end table
13883
8e04817f
AC
13884The source, assembly and register windows are attached to the thread
13885and the frame position. They are updated when the current thread
13886changes, when the frame changes or when the program counter changes.
13887These three windows are arranged by the TUI according to several
13888layouts. The layout defines which of these three windows are visible.
13889The following layouts are available:
c906108c 13890
8e04817f
AC
13891@itemize @bullet
13892@item
13893source
2df3850c 13894
8e04817f
AC
13895@item
13896assembly
13897
13898@item
13899source and assembly
13900
13901@item
13902source and registers
c906108c 13903
8e04817f
AC
13904@item
13905assembly and registers
2df3850c 13906
8e04817f 13907@end itemize
c906108c 13908
b7bb15bc
SC
13909On top of the command window a status line gives various information
13910concerning the current process begin debugged. The status line is
13911updated when the information it shows changes. The following fields
13912are displayed:
13913
13914@table @emph
13915@item target
13916Indicates the current gdb target
13917(@pxref{Targets, ,Specifying a Debugging Target}).
13918
13919@item process
13920Gives information about the current process or thread number.
13921When no process is being debugged, this field is set to @code{No process}.
13922
13923@item function
13924Gives the current function name for the selected frame.
13925The name is demangled if demangling is turned on (@pxref{Print Settings}).
13926When there is no symbol corresponding to the current program counter
13927the string @code{??} is displayed.
13928
13929@item line
13930Indicates the current line number for the selected frame.
13931When the current line number is not known the string @code{??} is displayed.
13932
13933@item pc
13934Indicates the current program counter address.
13935
13936@end table
13937
8e04817f
AC
13938@node TUI Keys
13939@section TUI Key Bindings
13940@cindex TUI key bindings
c906108c 13941
8e04817f
AC
13942The TUI installs several key bindings in the readline keymaps
13943(@pxref{Command Line Editing}).
13944They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
13945directly on the TUI layout and windows. The TUI also provides
13946a @emph{SingleKey} keymap which binds several keys directly to
13947@value{GDBN} commands. The following key bindings
8e04817f 13948are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 13949
8e04817f
AC
13950@table @kbd
13951@kindex C-x C-a
13952@item C-x C-a
13953@kindex C-x a
13954@itemx C-x a
13955@kindex C-x A
13956@itemx C-x A
13957Enter or leave the TUI mode. When the TUI mode is left,
13958the curses window management is left and @value{GDBN} operates using
13959its standard mode writing on the terminal directly. When the TUI
13960mode is entered, the control is given back to the curses windows.
13961The screen is then refreshed.
c906108c 13962
8e04817f
AC
13963@kindex C-x 1
13964@item C-x 1
13965Use a TUI layout with only one window. The layout will
13966either be @samp{source} or @samp{assembly}. When the TUI mode
13967is not active, it will switch to the TUI mode.
2df3850c 13968
8e04817f 13969Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 13970
8e04817f
AC
13971@kindex C-x 2
13972@item C-x 2
13973Use a TUI layout with at least two windows. When the current
13974layout shows already two windows, a next layout with two windows is used.
13975When a new layout is chosen, one window will always be common to the
13976previous layout and the new one.
c906108c 13977
8e04817f 13978Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 13979
72ffddc9
SC
13980@kindex C-x o
13981@item C-x o
13982Change the active window. The TUI associates several key bindings
13983(like scrolling and arrow keys) to the active window. This command
13984gives the focus to the next TUI window.
13985
13986Think of it as the Emacs @kbd{C-x o} binding.
13987
7cf36c78
SC
13988@kindex C-x s
13989@item C-x s
13990Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
13991(@pxref{TUI Single Key Mode}).
13992
c906108c
SS
13993@end table
13994
8e04817f 13995The following key bindings are handled only by the TUI mode:
5d161b24 13996
8e04817f
AC
13997@table @key
13998@kindex PgUp
13999@item PgUp
14000Scroll the active window one page up.
c906108c 14001
8e04817f
AC
14002@kindex PgDn
14003@item PgDn
14004Scroll the active window one page down.
c906108c 14005
8e04817f
AC
14006@kindex Up
14007@item Up
14008Scroll the active window one line up.
c906108c 14009
8e04817f
AC
14010@kindex Down
14011@item Down
14012Scroll the active window one line down.
c906108c 14013
8e04817f
AC
14014@kindex Left
14015@item Left
14016Scroll the active window one column left.
c906108c 14017
8e04817f
AC
14018@kindex Right
14019@item Right
14020Scroll the active window one column right.
c906108c 14021
8e04817f
AC
14022@kindex C-L
14023@item C-L
14024Refresh the screen.
c906108c 14025
8e04817f 14026@end table
c906108c 14027
8e04817f 14028In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
14029for scrolling. This means they are available for readline when the
14030active window is the command window. When the command window
14031does not have the focus, it is necessary to use other readline
14032key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 14033
7cf36c78
SC
14034@node TUI Single Key Mode
14035@section TUI Single Key Mode
14036@cindex TUI single key mode
14037
14038The TUI provides a @emph{SingleKey} mode in which it installs a particular
14039key binding in the readline keymaps to connect single keys to
14040some gdb commands.
14041
14042@table @kbd
14043@kindex c @r{(SingleKey TUI key)}
14044@item c
14045continue
14046
14047@kindex d @r{(SingleKey TUI key)}
14048@item d
14049down
14050
14051@kindex f @r{(SingleKey TUI key)}
14052@item f
14053finish
14054
14055@kindex n @r{(SingleKey TUI key)}
14056@item n
14057next
14058
14059@kindex q @r{(SingleKey TUI key)}
14060@item q
14061exit the @emph{SingleKey} mode.
14062
14063@kindex r @r{(SingleKey TUI key)}
14064@item r
14065run
14066
14067@kindex s @r{(SingleKey TUI key)}
14068@item s
14069step
14070
14071@kindex u @r{(SingleKey TUI key)}
14072@item u
14073up
14074
14075@kindex v @r{(SingleKey TUI key)}
14076@item v
14077info locals
14078
14079@kindex w @r{(SingleKey TUI key)}
14080@item w
14081where
14082
14083@end table
14084
14085Other keys temporarily switch to the @value{GDBN} command prompt.
14086The key that was pressed is inserted in the editing buffer so that
14087it is possible to type most @value{GDBN} commands without interaction
14088with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
14089@emph{SingleKey} mode is restored. The only way to permanently leave
14090this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
14091
14092
8e04817f
AC
14093@node TUI Commands
14094@section TUI specific commands
14095@cindex TUI commands
14096
14097The TUI has specific commands to control the text windows.
14098These commands are always available, that is they do not depend on
14099the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
14100is in the standard mode, using these commands will automatically switch
14101in the TUI mode.
c906108c
SS
14102
14103@table @code
3d757584
SC
14104@item info win
14105@kindex info win
14106List and give the size of all displayed windows.
14107
8e04817f
AC
14108@item layout next
14109@kindex layout next
14110Display the next layout.
2df3850c 14111
8e04817f
AC
14112@item layout prev
14113@kindex layout prev
14114Display the previous layout.
c906108c 14115
8e04817f
AC
14116@item layout src
14117@kindex layout src
14118Display the source window only.
c906108c 14119
8e04817f
AC
14120@item layout asm
14121@kindex layout asm
14122Display the assembly window only.
c906108c 14123
8e04817f
AC
14124@item layout split
14125@kindex layout split
14126Display the source and assembly window.
c906108c 14127
8e04817f
AC
14128@item layout regs
14129@kindex layout regs
14130Display the register window together with the source or assembly window.
14131
14132@item focus next | prev | src | asm | regs | split
14133@kindex focus
14134Set the focus to the named window.
14135This command allows to change the active window so that scrolling keys
14136can be affected to another window.
c906108c 14137
8e04817f
AC
14138@item refresh
14139@kindex refresh
14140Refresh the screen. This is similar to using @key{C-L} key.
c906108c 14141
8e04817f
AC
14142@item update
14143@kindex update
14144Update the source window and the current execution point.
c906108c 14145
8e04817f
AC
14146@item winheight @var{name} +@var{count}
14147@itemx winheight @var{name} -@var{count}
14148@kindex winheight
14149Change the height of the window @var{name} by @var{count}
14150lines. Positive counts increase the height, while negative counts
14151decrease it.
2df3850c 14152
c906108c
SS
14153@end table
14154
8e04817f
AC
14155@node TUI Configuration
14156@section TUI configuration variables
14157@cindex TUI configuration variables
c906108c 14158
8e04817f
AC
14159The TUI has several configuration variables that control the
14160appearance of windows on the terminal.
c906108c 14161
8e04817f
AC
14162@table @code
14163@item set tui border-kind @var{kind}
14164@kindex set tui border-kind
14165Select the border appearance for the source, assembly and register windows.
14166The possible values are the following:
14167@table @code
14168@item space
14169Use a space character to draw the border.
c906108c 14170
8e04817f
AC
14171@item ascii
14172Use ascii characters + - and | to draw the border.
c906108c 14173
8e04817f
AC
14174@item acs
14175Use the Alternate Character Set to draw the border. The border is
14176drawn using character line graphics if the terminal supports them.
c78b4128 14177
8e04817f 14178@end table
c78b4128 14179
8e04817f
AC
14180@item set tui active-border-mode @var{mode}
14181@kindex set tui active-border-mode
14182Select the attributes to display the border of the active window.
14183The possible values are @code{normal}, @code{standout}, @code{reverse},
14184@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 14185
8e04817f
AC
14186@item set tui border-mode @var{mode}
14187@kindex set tui border-mode
14188Select the attributes to display the border of other windows.
14189The @var{mode} can be one of the following:
14190@table @code
14191@item normal
14192Use normal attributes to display the border.
c906108c 14193
8e04817f
AC
14194@item standout
14195Use standout mode.
c906108c 14196
8e04817f
AC
14197@item reverse
14198Use reverse video mode.
c906108c 14199
8e04817f
AC
14200@item half
14201Use half bright mode.
c906108c 14202
8e04817f
AC
14203@item half-standout
14204Use half bright and standout mode.
c906108c 14205
8e04817f
AC
14206@item bold
14207Use extra bright or bold mode.
c78b4128 14208
8e04817f
AC
14209@item bold-standout
14210Use extra bright or bold and standout mode.
c78b4128 14211
8e04817f 14212@end table
c78b4128 14213
8e04817f 14214@end table
c78b4128 14215
8e04817f
AC
14216@node Emacs
14217@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 14218
8e04817f
AC
14219@cindex Emacs
14220@cindex @sc{gnu} Emacs
14221A special interface allows you to use @sc{gnu} Emacs to view (and
14222edit) the source files for the program you are debugging with
14223@value{GDBN}.
c906108c 14224
8e04817f
AC
14225To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
14226executable file you want to debug as an argument. This command starts
14227@value{GDBN} as a subprocess of Emacs, with input and output through a newly
14228created Emacs buffer.
14229@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 14230
8e04817f
AC
14231Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
14232things:
c906108c 14233
8e04817f
AC
14234@itemize @bullet
14235@item
14236All ``terminal'' input and output goes through the Emacs buffer.
14237@end itemize
c906108c 14238
8e04817f
AC
14239This applies both to @value{GDBN} commands and their output, and to the input
14240and output done by the program you are debugging.
bf0184be 14241
8e04817f
AC
14242This is useful because it means that you can copy the text of previous
14243commands and input them again; you can even use parts of the output
14244in this way.
bf0184be 14245
8e04817f
AC
14246All the facilities of Emacs' Shell mode are available for interacting
14247with your program. In particular, you can send signals the usual
14248way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
14249stop.
bf0184be 14250
8e04817f 14251@itemize @bullet
bf0184be 14252@item
8e04817f
AC
14253@value{GDBN} displays source code through Emacs.
14254@end itemize
bf0184be 14255
8e04817f
AC
14256Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
14257source file for that frame and puts an arrow (@samp{=>}) at the
14258left margin of the current line. Emacs uses a separate buffer for
14259source display, and splits the screen to show both your @value{GDBN} session
14260and the source.
bf0184be 14261
8e04817f
AC
14262Explicit @value{GDBN} @code{list} or search commands still produce output as
14263usual, but you probably have no reason to use them from Emacs.
c906108c 14264
64fabec2
AC
14265If you specify an absolute file name when prompted for the @kbd{M-x
14266gdb} argument, then Emacs sets your current working directory to where
14267your program resides. If you only specify the file name, then Emacs
14268sets your current working directory to to the directory associated
14269with the previous buffer. In this case, @value{GDBN} may find your
14270program by searching your environment's @code{PATH} variable, but on
14271some operating systems it might not find the source. So, although the
14272@value{GDBN} input and output session proceeds normally, the auxiliary
14273buffer does not display the current source and line of execution.
14274
14275The initial working directory of @value{GDBN} is printed on the top
14276line of the @value{GDBN} I/O buffer and this serves as a default for
14277the commands that specify files for @value{GDBN} to operate
14278on. @xref{Files, ,Commands to specify files}.
14279
14280By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
14281need to call @value{GDBN} by a different name (for example, if you
14282keep several configurations around, with different names) you can
14283customize the Emacs variable @code{gud-gdb-command-name} to run the
14284one you want.
8e04817f
AC
14285
14286In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
14287addition to the standard Shell mode commands:
c906108c 14288
8e04817f
AC
14289@table @kbd
14290@item C-h m
14291Describe the features of Emacs' @value{GDBN} Mode.
c906108c 14292
64fabec2 14293@item C-c C-s
8e04817f
AC
14294Execute to another source line, like the @value{GDBN} @code{step} command; also
14295update the display window to show the current file and location.
c906108c 14296
64fabec2 14297@item C-c C-n
8e04817f
AC
14298Execute to next source line in this function, skipping all function
14299calls, like the @value{GDBN} @code{next} command. Then update the display window
14300to show the current file and location.
c906108c 14301
64fabec2 14302@item C-c C-i
8e04817f
AC
14303Execute one instruction, like the @value{GDBN} @code{stepi} command; update
14304display window accordingly.
c906108c 14305
8e04817f
AC
14306@item C-c C-f
14307Execute until exit from the selected stack frame, like the @value{GDBN}
14308@code{finish} command.
c906108c 14309
64fabec2 14310@item C-c C-r
8e04817f
AC
14311Continue execution of your program, like the @value{GDBN} @code{continue}
14312command.
b433d00b 14313
64fabec2 14314@item C-c <
8e04817f
AC
14315Go up the number of frames indicated by the numeric argument
14316(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
14317like the @value{GDBN} @code{up} command.
b433d00b 14318
64fabec2 14319@item C-c >
8e04817f
AC
14320Go down the number of frames indicated by the numeric argument, like the
14321@value{GDBN} @code{down} command.
8e04817f 14322@end table
c906108c 14323
64fabec2 14324In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 14325tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 14326
64fabec2
AC
14327If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
14328shows a backtrace when the @value{GDBN} I/O buffer is current. Move
14329point to any frame in the stack and type @key{RET} to make it become the
14330current frame and display the associated source in the source buffer.
14331Alternatively, click @kbd{Mouse-2} to make the selected frame become the
14332current one.
14333
8e04817f
AC
14334If you accidentally delete the source-display buffer, an easy way to get
14335it back is to type the command @code{f} in the @value{GDBN} buffer, to
14336request a frame display; when you run under Emacs, this recreates
14337the source buffer if necessary to show you the context of the current
14338frame.
c906108c 14339
8e04817f
AC
14340The source files displayed in Emacs are in ordinary Emacs buffers
14341which are visiting the source files in the usual way. You can edit
14342the files with these buffers if you wish; but keep in mind that @value{GDBN}
14343communicates with Emacs in terms of line numbers. If you add or
14344delete lines from the text, the line numbers that @value{GDBN} knows cease
14345to correspond properly with the code.
64fabec2
AC
14346
14347The description given here is for GNU Emacs version 21.3 and a more
14348detailed description of its interaction with @value{GDBN} is given in
14349the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 14350
8e04817f
AC
14351@c The following dropped because Epoch is nonstandard. Reactivate
14352@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
14353@ignore
14354@kindex Emacs Epoch environment
14355@kindex Epoch
14356@kindex inspect
c906108c 14357
8e04817f
AC
14358Version 18 of @sc{gnu} Emacs has a built-in window system
14359called the @code{epoch}
14360environment. Users of this environment can use a new command,
14361@code{inspect} which performs identically to @code{print} except that
14362each value is printed in its own window.
14363@end ignore
c906108c 14364
922fbb7b
AC
14365
14366@node GDB/MI
14367@chapter The @sc{gdb/mi} Interface
14368
14369@unnumberedsec Function and Purpose
14370
14371@cindex @sc{gdb/mi}, its purpose
14372@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
14373specifically intended to support the development of systems which use
14374the debugger as just one small component of a larger system.
14375
14376This chapter is a specification of the @sc{gdb/mi} interface. It is written
14377in the form of a reference manual.
14378
14379Note that @sc{gdb/mi} is still under construction, so some of the
14380features described below are incomplete and subject to change.
14381
14382@unnumberedsec Notation and Terminology
14383
14384@cindex notational conventions, for @sc{gdb/mi}
14385This chapter uses the following notation:
14386
14387@itemize @bullet
14388@item
14389@code{|} separates two alternatives.
14390
14391@item
14392@code{[ @var{something} ]} indicates that @var{something} is optional:
14393it may or may not be given.
14394
14395@item
14396@code{( @var{group} )*} means that @var{group} inside the parentheses
14397may repeat zero or more times.
14398
14399@item
14400@code{( @var{group} )+} means that @var{group} inside the parentheses
14401may repeat one or more times.
14402
14403@item
14404@code{"@var{string}"} means a literal @var{string}.
14405@end itemize
14406
14407@ignore
14408@heading Dependencies
14409@end ignore
14410
14411@heading Acknowledgments
14412
14413In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
14414Elena Zannoni.
14415
14416@menu
14417* GDB/MI Command Syntax::
14418* GDB/MI Compatibility with CLI::
14419* GDB/MI Output Records::
14420* GDB/MI Command Description Format::
14421* GDB/MI Breakpoint Table Commands::
14422* GDB/MI Data Manipulation::
14423* GDB/MI Program Control::
14424* GDB/MI Miscellaneous Commands::
14425@ignore
14426* GDB/MI Kod Commands::
14427* GDB/MI Memory Overlay Commands::
14428* GDB/MI Signal Handling Commands::
14429@end ignore
14430* GDB/MI Stack Manipulation::
14431* GDB/MI Symbol Query::
14432* GDB/MI Target Manipulation::
14433* GDB/MI Thread Commands::
14434* GDB/MI Tracepoint Commands::
14435* GDB/MI Variable Objects::
14436@end menu
14437
14438@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14439@node GDB/MI Command Syntax
14440@section @sc{gdb/mi} Command Syntax
14441
14442@menu
14443* GDB/MI Input Syntax::
14444* GDB/MI Output Syntax::
14445* GDB/MI Simple Examples::
14446@end menu
14447
14448@node GDB/MI Input Syntax
14449@subsection @sc{gdb/mi} Input Syntax
14450
14451@cindex input syntax for @sc{gdb/mi}
14452@cindex @sc{gdb/mi}, input syntax
14453@table @code
14454@item @var{command} @expansion{}
14455@code{@var{cli-command} | @var{mi-command}}
14456
14457@item @var{cli-command} @expansion{}
14458@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
14459@var{cli-command} is any existing @value{GDBN} CLI command.
14460
14461@item @var{mi-command} @expansion{}
14462@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
14463@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
14464
14465@item @var{token} @expansion{}
14466"any sequence of digits"
14467
14468@item @var{option} @expansion{}
14469@code{"-" @var{parameter} [ " " @var{parameter} ]}
14470
14471@item @var{parameter} @expansion{}
14472@code{@var{non-blank-sequence} | @var{c-string}}
14473
14474@item @var{operation} @expansion{}
14475@emph{any of the operations described in this chapter}
14476
14477@item @var{non-blank-sequence} @expansion{}
14478@emph{anything, provided it doesn't contain special characters such as
14479"-", @var{nl}, """ and of course " "}
14480
14481@item @var{c-string} @expansion{}
14482@code{""" @var{seven-bit-iso-c-string-content} """}
14483
14484@item @var{nl} @expansion{}
14485@code{CR | CR-LF}
14486@end table
14487
14488@noindent
14489Notes:
14490
14491@itemize @bullet
14492@item
14493The CLI commands are still handled by the @sc{mi} interpreter; their
14494output is described below.
14495
14496@item
14497The @code{@var{token}}, when present, is passed back when the command
14498finishes.
14499
14500@item
14501Some @sc{mi} commands accept optional arguments as part of the parameter
14502list. Each option is identified by a leading @samp{-} (dash) and may be
14503followed by an optional argument parameter. Options occur first in the
14504parameter list and can be delimited from normal parameters using
14505@samp{--} (this is useful when some parameters begin with a dash).
14506@end itemize
14507
14508Pragmatics:
14509
14510@itemize @bullet
14511@item
14512We want easy access to the existing CLI syntax (for debugging).
14513
14514@item
14515We want it to be easy to spot a @sc{mi} operation.
14516@end itemize
14517
14518@node GDB/MI Output Syntax
14519@subsection @sc{gdb/mi} Output Syntax
14520
14521@cindex output syntax of @sc{gdb/mi}
14522@cindex @sc{gdb/mi}, output syntax
14523The output from @sc{gdb/mi} consists of zero or more out-of-band records
14524followed, optionally, by a single result record. This result record
14525is for the most recent command. The sequence of output records is
14526terminated by @samp{(@value{GDBP})}.
14527
14528If an input command was prefixed with a @code{@var{token}} then the
14529corresponding output for that command will also be prefixed by that same
14530@var{token}.
14531
14532@table @code
14533@item @var{output} @expansion{}
14534@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
14535
14536@item @var{result-record} @expansion{}
14537@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
14538
14539@item @var{out-of-band-record} @expansion{}
14540@code{@var{async-record} | @var{stream-record}}
14541
14542@item @var{async-record} @expansion{}
14543@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
14544
14545@item @var{exec-async-output} @expansion{}
14546@code{[ @var{token} ] "*" @var{async-output}}
14547
14548@item @var{status-async-output} @expansion{}
14549@code{[ @var{token} ] "+" @var{async-output}}
14550
14551@item @var{notify-async-output} @expansion{}
14552@code{[ @var{token} ] "=" @var{async-output}}
14553
14554@item @var{async-output} @expansion{}
14555@code{@var{async-class} ( "," @var{result} )* @var{nl}}
14556
14557@item @var{result-class} @expansion{}
14558@code{"done" | "running" | "connected" | "error" | "exit"}
14559
14560@item @var{async-class} @expansion{}
14561@code{"stopped" | @var{others}} (where @var{others} will be added
14562depending on the needs---this is still in development).
14563
14564@item @var{result} @expansion{}
14565@code{ @var{variable} "=" @var{value}}
14566
14567@item @var{variable} @expansion{}
14568@code{ @var{string} }
14569
14570@item @var{value} @expansion{}
14571@code{ @var{const} | @var{tuple} | @var{list} }
14572
14573@item @var{const} @expansion{}
14574@code{@var{c-string}}
14575
14576@item @var{tuple} @expansion{}
14577@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
14578
14579@item @var{list} @expansion{}
14580@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
14581@var{result} ( "," @var{result} )* "]" }
14582
14583@item @var{stream-record} @expansion{}
14584@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
14585
14586@item @var{console-stream-output} @expansion{}
14587@code{"~" @var{c-string}}
14588
14589@item @var{target-stream-output} @expansion{}
14590@code{"@@" @var{c-string}}
14591
14592@item @var{log-stream-output} @expansion{}
14593@code{"&" @var{c-string}}
14594
14595@item @var{nl} @expansion{}
14596@code{CR | CR-LF}
14597
14598@item @var{token} @expansion{}
14599@emph{any sequence of digits}.
14600@end table
14601
14602@noindent
14603Notes:
14604
14605@itemize @bullet
14606@item
14607All output sequences end in a single line containing a period.
14608
14609@item
14610The @code{@var{token}} is from the corresponding request. If an execution
14611command is interrupted by the @samp{-exec-interrupt} command, the
14612@var{token} associated with the @samp{*stopped} message is the one of the
14613original execution command, not the one of the interrupt command.
14614
14615@item
14616@cindex status output in @sc{gdb/mi}
14617@var{status-async-output} contains on-going status information about the
14618progress of a slow operation. It can be discarded. All status output is
14619prefixed by @samp{+}.
14620
14621@item
14622@cindex async output in @sc{gdb/mi}
14623@var{exec-async-output} contains asynchronous state change on the target
14624(stopped, started, disappeared). All async output is prefixed by
14625@samp{*}.
14626
14627@item
14628@cindex notify output in @sc{gdb/mi}
14629@var{notify-async-output} contains supplementary information that the
14630client should handle (e.g., a new breakpoint information). All notify
14631output is prefixed by @samp{=}.
14632
14633@item
14634@cindex console output in @sc{gdb/mi}
14635@var{console-stream-output} is output that should be displayed as is in the
14636console. It is the textual response to a CLI command. All the console
14637output is prefixed by @samp{~}.
14638
14639@item
14640@cindex target output in @sc{gdb/mi}
14641@var{target-stream-output} is the output produced by the target program.
14642All the target output is prefixed by @samp{@@}.
14643
14644@item
14645@cindex log output in @sc{gdb/mi}
14646@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
14647instance messages that should be displayed as part of an error log. All
14648the log output is prefixed by @samp{&}.
14649
14650@item
14651@cindex list output in @sc{gdb/mi}
14652New @sc{gdb/mi} commands should only output @var{lists} containing
14653@var{values}.
14654
14655
14656@end itemize
14657
14658@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
14659details about the various output records.
14660
14661@node GDB/MI Simple Examples
14662@subsection Simple Examples of @sc{gdb/mi} Interaction
14663@cindex @sc{gdb/mi}, simple examples
14664
14665This subsection presents several simple examples of interaction using
14666the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
14667following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
14668the output received from @sc{gdb/mi}.
14669
14670@subsubheading Target Stop
14671@c Ummm... There is no "-stop" command. This assumes async, no?
14672Here's an example of stopping the inferior process:
14673
14674@smallexample
14675-> -stop
14676<- (@value{GDBP})
14677@end smallexample
14678
14679@noindent
14680and later:
14681
14682@smallexample
14683<- *stop,reason="stop",address="0x123",source="a.c:123"
14684<- (@value{GDBP})
14685@end smallexample
14686
14687@subsubheading Simple CLI Command
14688
14689Here's an example of a simple CLI command being passed through
14690@sc{gdb/mi} and on to the CLI.
14691
14692@smallexample
14693-> print 1+2
14694<- &"print 1+2\n"
14695<- ~"$1 = 3\n"
14696<- ^done
14697<- (@value{GDBP})
14698@end smallexample
14699
14700@subsubheading Command With Side Effects
14701
14702@smallexample
14703-> -symbol-file xyz.exe
14704<- *breakpoint,nr="3",address="0x123",source="a.c:123"
14705<- (@value{GDBP})
14706@end smallexample
14707
14708@subsubheading A Bad Command
14709
14710Here's what happens if you pass a non-existent command:
14711
14712@smallexample
14713-> -rubbish
14714<- ^error,msg="Undefined MI command: rubbish"
14715<- (@value{GDBP})
14716@end smallexample
14717
14718@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14719@node GDB/MI Compatibility with CLI
14720@section @sc{gdb/mi} Compatibility with CLI
14721
14722@cindex compatibility, @sc{gdb/mi} and CLI
14723@cindex @sc{gdb/mi}, compatibility with CLI
14724To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
14725accepts existing CLI commands. As specified by the syntax, such
14726commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
14727respond.
14728
14729This mechanism is provided as an aid to developers of @sc{gdb/mi}
14730clients and not as a reliable interface into the CLI. Since the command
14731is being interpreteted in an environment that assumes @sc{gdb/mi}
14732behaviour, the exact output of such commands is likely to end up being
14733an un-supported hybrid of @sc{gdb/mi} and CLI output.
14734
14735@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14736@node GDB/MI Output Records
14737@section @sc{gdb/mi} Output Records
14738
14739@menu
14740* GDB/MI Result Records::
14741* GDB/MI Stream Records::
14742* GDB/MI Out-of-band Records::
14743@end menu
14744
14745@node GDB/MI Result Records
14746@subsection @sc{gdb/mi} Result Records
14747
14748@cindex result records in @sc{gdb/mi}
14749@cindex @sc{gdb/mi}, result records
14750In addition to a number of out-of-band notifications, the response to a
14751@sc{gdb/mi} command includes one of the following result indications:
14752
14753@table @code
14754@findex ^done
14755@item "^done" [ "," @var{results} ]
14756The synchronous operation was successful, @code{@var{results}} are the return
14757values.
14758
14759@item "^running"
14760@findex ^running
14761@c Is this one correct? Should it be an out-of-band notification?
14762The asynchronous operation was successfully started. The target is
14763running.
14764
14765@item "^error" "," @var{c-string}
14766@findex ^error
14767The operation failed. The @code{@var{c-string}} contains the corresponding
14768error message.
14769@end table
14770
14771@node GDB/MI Stream Records
14772@subsection @sc{gdb/mi} Stream Records
14773
14774@cindex @sc{gdb/mi}, stream records
14775@cindex stream records in @sc{gdb/mi}
14776@value{GDBN} internally maintains a number of output streams: the console, the
14777target, and the log. The output intended for each of these streams is
14778funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
14779
14780Each stream record begins with a unique @dfn{prefix character} which
14781identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
14782Syntax}). In addition to the prefix, each stream record contains a
14783@code{@var{string-output}}. This is either raw text (with an implicit new
14784line) or a quoted C string (which does not contain an implicit newline).
14785
14786@table @code
14787@item "~" @var{string-output}
14788The console output stream contains text that should be displayed in the
14789CLI console window. It contains the textual responses to CLI commands.
14790
14791@item "@@" @var{string-output}
14792The target output stream contains any textual output from the running
14793target.
14794
14795@item "&" @var{string-output}
14796The log stream contains debugging messages being produced by @value{GDBN}'s
14797internals.
14798@end table
14799
14800@node GDB/MI Out-of-band Records
14801@subsection @sc{gdb/mi} Out-of-band Records
14802
14803@cindex out-of-band records in @sc{gdb/mi}
14804@cindex @sc{gdb/mi}, out-of-band records
14805@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
14806additional changes that have occurred. Those changes can either be a
14807consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
14808target activity (e.g., target stopped).
14809
14810The following is a preliminary list of possible out-of-band records.
14811
14812@table @code
14813@item "*" "stop"
14814@end table
14815
14816
14817@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14818@node GDB/MI Command Description Format
14819@section @sc{gdb/mi} Command Description Format
14820
14821The remaining sections describe blocks of commands. Each block of
14822commands is laid out in a fashion similar to this section.
14823
14824Note the the line breaks shown in the examples are here only for
14825readability. They don't appear in the real output.
14826Also note that the commands with a non-available example (N.A.@:) are
14827not yet implemented.
14828
14829@subheading Motivation
14830
14831The motivation for this collection of commands.
14832
14833@subheading Introduction
14834
14835A brief introduction to this collection of commands as a whole.
14836
14837@subheading Commands
14838
14839For each command in the block, the following is described:
14840
14841@subsubheading Synopsis
14842
14843@smallexample
14844 -command @var{args}@dots{}
14845@end smallexample
14846
14847@subsubheading @value{GDBN} Command
14848
14849The corresponding @value{GDBN} CLI command.
14850
14851@subsubheading Result
14852
14853@subsubheading Out-of-band
14854
14855@subsubheading Notes
14856
14857@subsubheading Example
14858
14859
14860@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14861@node GDB/MI Breakpoint Table Commands
14862@section @sc{gdb/mi} Breakpoint table commands
14863
14864@cindex breakpoint commands for @sc{gdb/mi}
14865@cindex @sc{gdb/mi}, breakpoint commands
14866This section documents @sc{gdb/mi} commands for manipulating
14867breakpoints.
14868
14869@subheading The @code{-break-after} Command
14870@findex -break-after
14871
14872@subsubheading Synopsis
14873
14874@smallexample
14875 -break-after @var{number} @var{count}
14876@end smallexample
14877
14878The breakpoint number @var{number} is not in effect until it has been
14879hit @var{count} times. To see how this is reflected in the output of
14880the @samp{-break-list} command, see the description of the
14881@samp{-break-list} command below.
14882
14883@subsubheading @value{GDBN} Command
14884
14885The corresponding @value{GDBN} command is @samp{ignore}.
14886
14887@subsubheading Example
14888
14889@smallexample
14890(@value{GDBP})
14891-break-insert main
14892^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
14893(@value{GDBP})
14894-break-after 1 3
14895~
14896^done
14897(@value{GDBP})
14898-break-list
14899^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14900hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14901@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14902@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14903@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14904@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14905@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14906body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
14907addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
14908ignore="3"@}]@}
14909(@value{GDBP})
14910@end smallexample
14911
14912@ignore
14913@subheading The @code{-break-catch} Command
14914@findex -break-catch
14915
14916@subheading The @code{-break-commands} Command
14917@findex -break-commands
14918@end ignore
14919
14920
14921@subheading The @code{-break-condition} Command
14922@findex -break-condition
14923
14924@subsubheading Synopsis
14925
14926@smallexample
14927 -break-condition @var{number} @var{expr}
14928@end smallexample
14929
14930Breakpoint @var{number} will stop the program only if the condition in
14931@var{expr} is true. The condition becomes part of the
14932@samp{-break-list} output (see the description of the @samp{-break-list}
14933command below).
14934
14935@subsubheading @value{GDBN} Command
14936
14937The corresponding @value{GDBN} command is @samp{condition}.
14938
14939@subsubheading Example
14940
14941@smallexample
14942(@value{GDBP})
14943-break-condition 1 1
14944^done
14945(@value{GDBP})
14946-break-list
14947^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
14948hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14949@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14950@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14951@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14952@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14953@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14954body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
14955addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
14956times="0",ignore="3"@}]@}
14957(@value{GDBP})
14958@end smallexample
14959
14960@subheading The @code{-break-delete} Command
14961@findex -break-delete
14962
14963@subsubheading Synopsis
14964
14965@smallexample
14966 -break-delete ( @var{breakpoint} )+
14967@end smallexample
14968
14969Delete the breakpoint(s) whose number(s) are specified in the argument
14970list. This is obviously reflected in the breakpoint list.
14971
14972@subsubheading @value{GDBN} command
14973
14974The corresponding @value{GDBN} command is @samp{delete}.
14975
14976@subsubheading Example
14977
14978@smallexample
14979(@value{GDBP})
14980-break-delete 1
14981^done
14982(@value{GDBP})
14983-break-list
14984^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
14985hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
14986@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
14987@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
14988@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
14989@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
14990@{width="40",alignment="2",col_name="what",colhdr="What"@}],
14991body=[]@}
14992(@value{GDBP})
14993@end smallexample
14994
14995@subheading The @code{-break-disable} Command
14996@findex -break-disable
14997
14998@subsubheading Synopsis
14999
15000@smallexample
15001 -break-disable ( @var{breakpoint} )+
15002@end smallexample
15003
15004Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
15005break list is now set to @samp{n} for the named @var{breakpoint}(s).
15006
15007@subsubheading @value{GDBN} Command
15008
15009The corresponding @value{GDBN} command is @samp{disable}.
15010
15011@subsubheading Example
15012
15013@smallexample
15014(@value{GDBP})
15015-break-disable 2
15016^done
15017(@value{GDBP})
15018-break-list
15019^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15020hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15021@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15022@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15023@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15024@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15025@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15026body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
15027addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15028(@value{GDBP})
15029@end smallexample
15030
15031@subheading The @code{-break-enable} Command
15032@findex -break-enable
15033
15034@subsubheading Synopsis
15035
15036@smallexample
15037 -break-enable ( @var{breakpoint} )+
15038@end smallexample
15039
15040Enable (previously disabled) @var{breakpoint}(s).
15041
15042@subsubheading @value{GDBN} Command
15043
15044The corresponding @value{GDBN} command is @samp{enable}.
15045
15046@subsubheading Example
15047
15048@smallexample
15049(@value{GDBP})
15050-break-enable 2
15051^done
15052(@value{GDBP})
15053-break-list
15054^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15055hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15056@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15057@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15058@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15059@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15060@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15061body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15062addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
15063(@value{GDBP})
15064@end smallexample
15065
15066@subheading The @code{-break-info} Command
15067@findex -break-info
15068
15069@subsubheading Synopsis
15070
15071@smallexample
15072 -break-info @var{breakpoint}
15073@end smallexample
15074
15075@c REDUNDANT???
15076Get information about a single breakpoint.
15077
15078@subsubheading @value{GDBN} command
15079
15080The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
15081
15082@subsubheading Example
15083N.A.
15084
15085@subheading The @code{-break-insert} Command
15086@findex -break-insert
15087
15088@subsubheading Synopsis
15089
15090@smallexample
15091 -break-insert [ -t ] [ -h ] [ -r ]
15092 [ -c @var{condition} ] [ -i @var{ignore-count} ]
15093 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
15094@end smallexample
15095
15096@noindent
15097If specified, @var{line}, can be one of:
15098
15099@itemize @bullet
15100@item function
15101@c @item +offset
15102@c @item -offset
15103@c @item linenum
15104@item filename:linenum
15105@item filename:function
15106@item *address
15107@end itemize
15108
15109The possible optional parameters of this command are:
15110
15111@table @samp
15112@item -t
15113Insert a tempoary breakpoint.
15114@item -h
15115Insert a hardware breakpoint.
15116@item -c @var{condition}
15117Make the breakpoint conditional on @var{condition}.
15118@item -i @var{ignore-count}
15119Initialize the @var{ignore-count}.
15120@item -r
15121Insert a regular breakpoint in all the functions whose names match the
15122given regular expression. Other flags are not applicable to regular
15123expresson.
15124@end table
15125
15126@subsubheading Result
15127
15128The result is in the form:
15129
15130@smallexample
15131 ^done,bkptno="@var{number}",func="@var{funcname}",
15132 file="@var{filename}",line="@var{lineno}"
15133@end smallexample
15134
15135@noindent
15136where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
15137is the name of the function where the breakpoint was inserted,
15138@var{filename} is the name of the source file which contains this
15139function, and @var{lineno} is the source line number within that file.
15140
15141Note: this format is open to change.
15142@c An out-of-band breakpoint instead of part of the result?
15143
15144@subsubheading @value{GDBN} Command
15145
15146The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
15147@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
15148
15149@subsubheading Example
15150
15151@smallexample
15152(@value{GDBP})
15153-break-insert main
15154^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
15155(@value{GDBP})
15156-break-insert -t foo
15157^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
15158(@value{GDBP})
15159-break-list
15160^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15161hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15162@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15163@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15164@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15165@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15166@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15167body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15168addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
15169bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
15170addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
15171(@value{GDBP})
15172-break-insert -r foo.*
15173~int foo(int, int);
15174^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
15175(@value{GDBP})
15176@end smallexample
15177
15178@subheading The @code{-break-list} Command
15179@findex -break-list
15180
15181@subsubheading Synopsis
15182
15183@smallexample
15184 -break-list
15185@end smallexample
15186
15187Displays the list of inserted breakpoints, showing the following fields:
15188
15189@table @samp
15190@item Number
15191number of the breakpoint
15192@item Type
15193type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
15194@item Disposition
15195should the breakpoint be deleted or disabled when it is hit: @samp{keep}
15196or @samp{nokeep}
15197@item Enabled
15198is the breakpoint enabled or no: @samp{y} or @samp{n}
15199@item Address
15200memory location at which the breakpoint is set
15201@item What
15202logical location of the breakpoint, expressed by function name, file
15203name, line number
15204@item Times
15205number of times the breakpoint has been hit
15206@end table
15207
15208If there are no breakpoints or watchpoints, the @code{BreakpointTable}
15209@code{body} field is an empty list.
15210
15211@subsubheading @value{GDBN} Command
15212
15213The corresponding @value{GDBN} command is @samp{info break}.
15214
15215@subsubheading Example
15216
15217@smallexample
15218(@value{GDBP})
15219-break-list
15220^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15221hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15222@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15223@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15224@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15225@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15226@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15227body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15228addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
15229bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
15230addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
15231(@value{GDBP})
15232@end smallexample
15233
15234Here's an example of the result when there are no breakpoints:
15235
15236@smallexample
15237(@value{GDBP})
15238-break-list
15239^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
15240hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15241@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15242@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15243@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15244@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15245@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15246body=[]@}
15247(@value{GDBP})
15248@end smallexample
15249
15250@subheading The @code{-break-watch} Command
15251@findex -break-watch
15252
15253@subsubheading Synopsis
15254
15255@smallexample
15256 -break-watch [ -a | -r ]
15257@end smallexample
15258
15259Create a watchpoint. With the @samp{-a} option it will create an
15260@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
15261read from or on a write to the memory location. With the @samp{-r}
15262option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
15263trigger only when the memory location is accessed for reading. Without
15264either of the options, the watchpoint created is a regular watchpoint,
15265i.e. it will trigger when the memory location is accessed for writing.
15266@xref{Set Watchpoints, , Setting watchpoints}.
15267
15268Note that @samp{-break-list} will report a single list of watchpoints and
15269breakpoints inserted.
15270
15271@subsubheading @value{GDBN} Command
15272
15273The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
15274@samp{rwatch}.
15275
15276@subsubheading Example
15277
15278Setting a watchpoint on a variable in the @code{main} function:
15279
15280@smallexample
15281(@value{GDBP})
15282-break-watch x
15283^done,wpt=@{number="2",exp="x"@}
15284(@value{GDBP})
15285-exec-continue
15286^running
15287^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
15288value=@{old="-268439212",new="55"@},
15289frame=@{func="main",args=[],file="recursive2.c",line="5"@}
15290(@value{GDBP})
15291@end smallexample
15292
15293Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
15294the program execution twice: first for the variable changing value, then
15295for the watchpoint going out of scope.
15296
15297@smallexample
15298(@value{GDBP})
15299-break-watch C
15300^done,wpt=@{number="5",exp="C"@}
15301(@value{GDBP})
15302-exec-continue
15303^running
15304^done,reason="watchpoint-trigger",
15305wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
15306frame=@{func="callee4",args=[],
15307file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15308(@value{GDBP})
15309-exec-continue
15310^running
15311^done,reason="watchpoint-scope",wpnum="5",
15312frame=@{func="callee3",args=[@{name="strarg",
15313value="0x11940 \"A string argument.\""@}],
15314file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15315(@value{GDBP})
15316@end smallexample
15317
15318Listing breakpoints and watchpoints, at different points in the program
15319execution. Note that once the watchpoint goes out of scope, it is
15320deleted.
15321
15322@smallexample
15323(@value{GDBP})
15324-break-watch C
15325^done,wpt=@{number="2",exp="C"@}
15326(@value{GDBP})
15327-break-list
15328^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15329hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15330@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15331@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15332@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15333@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15334@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15335body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15336addr="0x00010734",func="callee4",
15337file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15338bkpt=@{number="2",type="watchpoint",disp="keep",
15339enabled="y",addr="",what="C",times="0"@}]@}
15340(@value{GDBP})
15341-exec-continue
15342^running
15343^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
15344value=@{old="-276895068",new="3"@},
15345frame=@{func="callee4",args=[],
15346file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
15347(@value{GDBP})
15348-break-list
15349^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
15350hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15351@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15352@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15353@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15354@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15355@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15356body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15357addr="0x00010734",func="callee4",
15358file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
15359bkpt=@{number="2",type="watchpoint",disp="keep",
15360enabled="y",addr="",what="C",times="-5"@}]@}
15361(@value{GDBP})
15362-exec-continue
15363^running
15364^done,reason="watchpoint-scope",wpnum="2",
15365frame=@{func="callee3",args=[@{name="strarg",
15366value="0x11940 \"A string argument.\""@}],
15367file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
15368(@value{GDBP})
15369-break-list
15370^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
15371hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
15372@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
15373@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
15374@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
15375@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
15376@{width="40",alignment="2",col_name="what",colhdr="What"@}],
15377body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
15378addr="0x00010734",func="callee4",
15379file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
15380(@value{GDBP})
15381@end smallexample
15382
15383@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15384@node GDB/MI Data Manipulation
15385@section @sc{gdb/mi} Data Manipulation
15386
15387@cindex data manipulation, in @sc{gdb/mi}
15388@cindex @sc{gdb/mi}, data manipulation
15389This section describes the @sc{gdb/mi} commands that manipulate data:
15390examine memory and registers, evaluate expressions, etc.
15391
15392@c REMOVED FROM THE INTERFACE.
15393@c @subheading -data-assign
15394@c Change the value of a program variable. Plenty of side effects.
15395@c @subsubheading GDB command
15396@c set variable
15397@c @subsubheading Example
15398@c N.A.
15399
15400@subheading The @code{-data-disassemble} Command
15401@findex -data-disassemble
15402
15403@subsubheading Synopsis
15404
15405@smallexample
15406 -data-disassemble
15407 [ -s @var{start-addr} -e @var{end-addr} ]
15408 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
15409 -- @var{mode}
15410@end smallexample
15411
15412@noindent
15413Where:
15414
15415@table @samp
15416@item @var{start-addr}
15417is the beginning address (or @code{$pc})
15418@item @var{end-addr}
15419is the end address
15420@item @var{filename}
15421is the name of the file to disassemble
15422@item @var{linenum}
15423is the line number to disassemble around
15424@item @var{lines}
15425is the the number of disassembly lines to be produced. If it is -1,
15426the whole function will be disassembled, in case no @var{end-addr} is
15427specified. If @var{end-addr} is specified as a non-zero value, and
15428@var{lines} is lower than the number of disassembly lines between
15429@var{start-addr} and @var{end-addr}, only @var{lines} lines are
15430displayed; if @var{lines} is higher than the number of lines between
15431@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
15432are displayed.
15433@item @var{mode}
15434is either 0 (meaning only disassembly) or 1 (meaning mixed source and
15435disassembly).
15436@end table
15437
15438@subsubheading Result
15439
15440The output for each instruction is composed of four fields:
15441
15442@itemize @bullet
15443@item Address
15444@item Func-name
15445@item Offset
15446@item Instruction
15447@end itemize
15448
15449Note that whatever included in the instruction field, is not manipulated
15450directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
15451
15452@subsubheading @value{GDBN} Command
15453
15454There's no direct mapping from this command to the CLI.
15455
15456@subsubheading Example
15457
15458Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
15459
15460@smallexample
15461(@value{GDBP})
15462-data-disassemble -s $pc -e "$pc + 20" -- 0
15463^done,
15464asm_insns=[
15465@{address="0x000107c0",func-name="main",offset="4",
15466inst="mov 2, %o0"@},
15467@{address="0x000107c4",func-name="main",offset="8",
15468inst="sethi %hi(0x11800), %o2"@},
15469@{address="0x000107c8",func-name="main",offset="12",
15470inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
15471@{address="0x000107cc",func-name="main",offset="16",
15472inst="sethi %hi(0x11800), %o2"@},
15473@{address="0x000107d0",func-name="main",offset="20",
15474inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
15475(@value{GDBP})
15476@end smallexample
15477
15478Disassemble the whole @code{main} function. Line 32 is part of
15479@code{main}.
15480
15481@smallexample
15482-data-disassemble -f basics.c -l 32 -- 0
15483^done,asm_insns=[
15484@{address="0x000107bc",func-name="main",offset="0",
15485inst="save %sp, -112, %sp"@},
15486@{address="0x000107c0",func-name="main",offset="4",
15487inst="mov 2, %o0"@},
15488@{address="0x000107c4",func-name="main",offset="8",
15489inst="sethi %hi(0x11800), %o2"@},
15490[@dots{}]
15491@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
15492@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
15493(@value{GDBP})
15494@end smallexample
15495
15496Disassemble 3 instructions from the start of @code{main}:
15497
15498@smallexample
15499(@value{GDBP})
15500-data-disassemble -f basics.c -l 32 -n 3 -- 0
15501^done,asm_insns=[
15502@{address="0x000107bc",func-name="main",offset="0",
15503inst="save %sp, -112, %sp"@},
15504@{address="0x000107c0",func-name="main",offset="4",
15505inst="mov 2, %o0"@},
15506@{address="0x000107c4",func-name="main",offset="8",
15507inst="sethi %hi(0x11800), %o2"@}]
15508(@value{GDBP})
15509@end smallexample
15510
15511Disassemble 3 instructions from the start of @code{main} in mixed mode:
15512
15513@smallexample
15514(@value{GDBP})
15515-data-disassemble -f basics.c -l 32 -n 3 -- 1
15516^done,asm_insns=[
15517src_and_asm_line=@{line="31",
15518file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15519 testsuite/gdb.mi/basics.c",line_asm_insn=[
15520@{address="0x000107bc",func-name="main",offset="0",
15521inst="save %sp, -112, %sp"@}]@},
15522src_and_asm_line=@{line="32",
15523file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
15524 testsuite/gdb.mi/basics.c",line_asm_insn=[
15525@{address="0x000107c0",func-name="main",offset="4",
15526inst="mov 2, %o0"@},
15527@{address="0x000107c4",func-name="main",offset="8",
15528inst="sethi %hi(0x11800), %o2"@}]@}]
15529(@value{GDBP})
15530@end smallexample
15531
15532
15533@subheading The @code{-data-evaluate-expression} Command
15534@findex -data-evaluate-expression
15535
15536@subsubheading Synopsis
15537
15538@smallexample
15539 -data-evaluate-expression @var{expr}
15540@end smallexample
15541
15542Evaluate @var{expr} as an expression. The expression could contain an
15543inferior function call. The function call will execute synchronously.
15544If the expression contains spaces, it must be enclosed in double quotes.
15545
15546@subsubheading @value{GDBN} Command
15547
15548The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
15549@samp{call}. In @code{gdbtk} only, there's a corresponding
15550@samp{gdb_eval} command.
15551
15552@subsubheading Example
15553
15554In the following example, the numbers that precede the commands are the
15555@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
15556Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
15557output.
15558
15559@smallexample
15560211-data-evaluate-expression A
15561211^done,value="1"
15562(@value{GDBP})
15563311-data-evaluate-expression &A
15564311^done,value="0xefffeb7c"
15565(@value{GDBP})
15566411-data-evaluate-expression A+3
15567411^done,value="4"
15568(@value{GDBP})
15569511-data-evaluate-expression "A + 3"
15570511^done,value="4"
15571(@value{GDBP})
15572@end smallexample
15573
15574
15575@subheading The @code{-data-list-changed-registers} Command
15576@findex -data-list-changed-registers
15577
15578@subsubheading Synopsis
15579
15580@smallexample
15581 -data-list-changed-registers
15582@end smallexample
15583
15584Display a list of the registers that have changed.
15585
15586@subsubheading @value{GDBN} Command
15587
15588@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
15589has the corresponding command @samp{gdb_changed_register_list}.
15590
15591@subsubheading Example
15592
15593On a PPC MBX board:
15594
15595@smallexample
15596(@value{GDBP})
15597-exec-continue
15598^running
15599
15600(@value{GDBP})
15601*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
15602args=[],file="try.c",line="5"@}
15603(@value{GDBP})
15604-data-list-changed-registers
15605^done,changed-registers=["0","1","2","4","5","6","7","8","9",
15606"10","11","13","14","15","16","17","18","19","20","21","22","23",
15607"24","25","26","27","28","30","31","64","65","66","67","69"]
15608(@value{GDBP})
15609@end smallexample
15610
15611
15612@subheading The @code{-data-list-register-names} Command
15613@findex -data-list-register-names
15614
15615@subsubheading Synopsis
15616
15617@smallexample
15618 -data-list-register-names [ ( @var{regno} )+ ]
15619@end smallexample
15620
15621Show a list of register names for the current target. If no arguments
15622are given, it shows a list of the names of all the registers. If
15623integer numbers are given as arguments, it will print a list of the
15624names of the registers corresponding to the arguments. To ensure
15625consistency between a register name and its number, the output list may
15626include empty register names.
15627
15628@subsubheading @value{GDBN} Command
15629
15630@value{GDBN} does not have a command which corresponds to
15631@samp{-data-list-register-names}. In @code{gdbtk} there is a
15632corresponding command @samp{gdb_regnames}.
15633
15634@subsubheading Example
15635
15636For the PPC MBX board:
15637@smallexample
15638(@value{GDBP})
15639-data-list-register-names
15640^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
15641"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
15642"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
15643"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
15644"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
15645"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
15646"", "pc","ps","cr","lr","ctr","xer"]
15647(@value{GDBP})
15648-data-list-register-names 1 2 3
15649^done,register-names=["r1","r2","r3"]
15650(@value{GDBP})
15651@end smallexample
15652
15653@subheading The @code{-data-list-register-values} Command
15654@findex -data-list-register-values
15655
15656@subsubheading Synopsis
15657
15658@smallexample
15659 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
15660@end smallexample
15661
15662Display the registers' contents. @var{fmt} is the format according to
15663which the registers' contents are to be returned, followed by an optional
15664list of numbers specifying the registers to display. A missing list of
15665numbers indicates that the contents of all the registers must be returned.
15666
15667Allowed formats for @var{fmt} are:
15668
15669@table @code
15670@item x
15671Hexadecimal
15672@item o
15673Octal
15674@item t
15675Binary
15676@item d
15677Decimal
15678@item r
15679Raw
15680@item N
15681Natural
15682@end table
15683
15684@subsubheading @value{GDBN} Command
15685
15686The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
15687all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
15688
15689@subsubheading Example
15690
15691For a PPC MBX board (note: line breaks are for readability only, they
15692don't appear in the actual output):
15693
15694@smallexample
15695(@value{GDBP})
15696-data-list-register-values r 64 65
15697^done,register-values=[@{number="64",value="0xfe00a300"@},
15698@{number="65",value="0x00029002"@}]
15699(@value{GDBP})
15700-data-list-register-values x
15701^done,register-values=[@{number="0",value="0xfe0043c8"@},
15702@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
15703@{number="3",value="0x0"@},@{number="4",value="0xa"@},
15704@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
15705@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
15706@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
15707@{number="11",value="0x1"@},@{number="12",value="0x0"@},
15708@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
15709@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
15710@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
15711@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
15712@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
15713@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
15714@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
15715@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
15716@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
15717@{number="31",value="0x0"@},@{number="32",value="0x0"@},
15718@{number="33",value="0x0"@},@{number="34",value="0x0"@},
15719@{number="35",value="0x0"@},@{number="36",value="0x0"@},
15720@{number="37",value="0x0"@},@{number="38",value="0x0"@},
15721@{number="39",value="0x0"@},@{number="40",value="0x0"@},
15722@{number="41",value="0x0"@},@{number="42",value="0x0"@},
15723@{number="43",value="0x0"@},@{number="44",value="0x0"@},
15724@{number="45",value="0x0"@},@{number="46",value="0x0"@},
15725@{number="47",value="0x0"@},@{number="48",value="0x0"@},
15726@{number="49",value="0x0"@},@{number="50",value="0x0"@},
15727@{number="51",value="0x0"@},@{number="52",value="0x0"@},
15728@{number="53",value="0x0"@},@{number="54",value="0x0"@},
15729@{number="55",value="0x0"@},@{number="56",value="0x0"@},
15730@{number="57",value="0x0"@},@{number="58",value="0x0"@},
15731@{number="59",value="0x0"@},@{number="60",value="0x0"@},
15732@{number="61",value="0x0"@},@{number="62",value="0x0"@},
15733@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
15734@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
15735@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
15736@{number="69",value="0x20002b03"@}]
15737(@value{GDBP})
15738@end smallexample
15739
15740
15741@subheading The @code{-data-read-memory} Command
15742@findex -data-read-memory
15743
15744@subsubheading Synopsis
15745
15746@smallexample
15747 -data-read-memory [ -o @var{byte-offset} ]
15748 @var{address} @var{word-format} @var{word-size}
15749 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
15750@end smallexample
15751
15752@noindent
15753where:
15754
15755@table @samp
15756@item @var{address}
15757An expression specifying the address of the first memory word to be
15758read. Complex expressions containing embedded white space should be
15759quoted using the C convention.
15760
15761@item @var{word-format}
15762The format to be used to print the memory words. The notation is the
15763same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
15764,Output formats}).
15765
15766@item @var{word-size}
15767The size of each memory word in bytes.
15768
15769@item @var{nr-rows}
15770The number of rows in the output table.
15771
15772@item @var{nr-cols}
15773The number of columns in the output table.
15774
15775@item @var{aschar}
15776If present, indicates that each row should include an @sc{ascii} dump. The
15777value of @var{aschar} is used as a padding character when a byte is not a
15778member of the printable @sc{ascii} character set (printable @sc{ascii}
15779characters are those whose code is between 32 and 126, inclusively).
15780
15781@item @var{byte-offset}
15782An offset to add to the @var{address} before fetching memory.
15783@end table
15784
15785This command displays memory contents as a table of @var{nr-rows} by
15786@var{nr-cols} words, each word being @var{word-size} bytes. In total,
15787@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
15788(returned as @samp{total-bytes}). Should less than the requested number
15789of bytes be returned by the target, the missing words are identified
15790using @samp{N/A}. The number of bytes read from the target is returned
15791in @samp{nr-bytes} and the starting address used to read memory in
15792@samp{addr}.
15793
15794The address of the next/previous row or page is available in
15795@samp{next-row} and @samp{prev-row}, @samp{next-page} and
15796@samp{prev-page}.
15797
15798@subsubheading @value{GDBN} Command
15799
15800The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
15801@samp{gdb_get_mem} memory read command.
15802
15803@subsubheading Example
15804
15805Read six bytes of memory starting at @code{bytes+6} but then offset by
15806@code{-6} bytes. Format as three rows of two columns. One byte per
15807word. Display each word in hex.
15808
15809@smallexample
15810(@value{GDBP})
158119-data-read-memory -o -6 -- bytes+6 x 1 3 2
158129^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
15813next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
15814prev-page="0x0000138a",memory=[
15815@{addr="0x00001390",data=["0x00","0x01"]@},
15816@{addr="0x00001392",data=["0x02","0x03"]@},
15817@{addr="0x00001394",data=["0x04","0x05"]@}]
15818(@value{GDBP})
15819@end smallexample
15820
15821Read two bytes of memory starting at address @code{shorts + 64} and
15822display as a single word formatted in decimal.
15823
15824@smallexample
15825(@value{GDBP})
158265-data-read-memory shorts+64 d 2 1 1
158275^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
15828next-row="0x00001512",prev-row="0x0000150e",
15829next-page="0x00001512",prev-page="0x0000150e",memory=[
15830@{addr="0x00001510",data=["128"]@}]
15831(@value{GDBP})
15832@end smallexample
15833
15834Read thirty two bytes of memory starting at @code{bytes+16} and format
15835as eight rows of four columns. Include a string encoding with @samp{x}
15836used as the non-printable character.
15837
15838@smallexample
15839(@value{GDBP})
158404-data-read-memory bytes+16 x 1 8 4 x
158414^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
15842next-row="0x000013c0",prev-row="0x0000139c",
15843next-page="0x000013c0",prev-page="0x00001380",memory=[
15844@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
15845@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
15846@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
15847@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
15848@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
15849@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
15850@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
15851@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
15852(@value{GDBP})
15853@end smallexample
15854
15855@subheading The @code{-display-delete} Command
15856@findex -display-delete
15857
15858@subsubheading Synopsis
15859
15860@smallexample
15861 -display-delete @var{number}
15862@end smallexample
15863
15864Delete the display @var{number}.
15865
15866@subsubheading @value{GDBN} Command
15867
15868The corresponding @value{GDBN} command is @samp{delete display}.
15869
15870@subsubheading Example
15871N.A.
15872
15873
15874@subheading The @code{-display-disable} Command
15875@findex -display-disable
15876
15877@subsubheading Synopsis
15878
15879@smallexample
15880 -display-disable @var{number}
15881@end smallexample
15882
15883Disable display @var{number}.
15884
15885@subsubheading @value{GDBN} Command
15886
15887The corresponding @value{GDBN} command is @samp{disable display}.
15888
15889@subsubheading Example
15890N.A.
15891
15892
15893@subheading The @code{-display-enable} Command
15894@findex -display-enable
15895
15896@subsubheading Synopsis
15897
15898@smallexample
15899 -display-enable @var{number}
15900@end smallexample
15901
15902Enable display @var{number}.
15903
15904@subsubheading @value{GDBN} Command
15905
15906The corresponding @value{GDBN} command is @samp{enable display}.
15907
15908@subsubheading Example
15909N.A.
15910
15911
15912@subheading The @code{-display-insert} Command
15913@findex -display-insert
15914
15915@subsubheading Synopsis
15916
15917@smallexample
15918 -display-insert @var{expression}
15919@end smallexample
15920
15921Display @var{expression} every time the program stops.
15922
15923@subsubheading @value{GDBN} Command
15924
15925The corresponding @value{GDBN} command is @samp{display}.
15926
15927@subsubheading Example
15928N.A.
15929
15930
15931@subheading The @code{-display-list} Command
15932@findex -display-list
15933
15934@subsubheading Synopsis
15935
15936@smallexample
15937 -display-list
15938@end smallexample
15939
15940List the displays. Do not show the current values.
15941
15942@subsubheading @value{GDBN} Command
15943
15944The corresponding @value{GDBN} command is @samp{info display}.
15945
15946@subsubheading Example
15947N.A.
15948
15949
15950@subheading The @code{-environment-cd} Command
15951@findex -environment-cd
15952
15953@subsubheading Synopsis
15954
15955@smallexample
15956 -environment-cd @var{pathdir}
15957@end smallexample
15958
15959Set @value{GDBN}'s working directory.
15960
15961@subsubheading @value{GDBN} Command
15962
15963The corresponding @value{GDBN} command is @samp{cd}.
15964
15965@subsubheading Example
15966
15967@smallexample
15968(@value{GDBP})
15969-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
15970^done
15971(@value{GDBP})
15972@end smallexample
15973
15974
15975@subheading The @code{-environment-directory} Command
15976@findex -environment-directory
15977
15978@subsubheading Synopsis
15979
15980@smallexample
15981 -environment-directory [ -r ] [ @var{pathdir} ]+
15982@end smallexample
15983
15984Add directories @var{pathdir} to beginning of search path for source files.
15985If the @samp{-r} option is used, the search path is reset to the default
15986search path. If directories @var{pathdir} are supplied in addition to the
15987@samp{-r} option, the search path is first reset and then addition
15988occurs as normal.
15989Multiple directories may be specified, separated by blanks. Specifying
15990multiple directories in a single command
15991results in the directories added to the beginning of the
15992search path in the same order they were presented in the command.
15993If blanks are needed as
15994part of a directory name, double-quotes should be used around
15995the name. In the command output, the path will show up separated
15996by the system directory-separator character. The directory-seperator
15997character must not be used
15998in any directory name.
15999If no directories are specified, the current search path is displayed.
16000
16001@subsubheading @value{GDBN} Command
16002
16003The corresponding @value{GDBN} command is @samp{dir}.
16004
16005@subsubheading Example
16006
16007@smallexample
16008(@value{GDBP})
16009-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
16010^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16011(@value{GDBP})
16012-environment-directory ""
16013^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
16014(@value{GDBP})
16015-environment-directory -r /home/jjohnstn/src/gdb /usr/src
16016^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
16017(@value{GDBP})
16018-environment-directory -r
16019^done,source-path="$cdir:$cwd"
16020(@value{GDBP})
16021@end smallexample
16022
16023
16024@subheading The @code{-environment-path} Command
16025@findex -environment-path
16026
16027@subsubheading Synopsis
16028
16029@smallexample
16030 -environment-path [ -r ] [ @var{pathdir} ]+
16031@end smallexample
16032
16033Add directories @var{pathdir} to beginning of search path for object files.
16034If the @samp{-r} option is used, the search path is reset to the original
16035search path that existed at gdb start-up. If directories @var{pathdir} are
16036supplied in addition to the
16037@samp{-r} option, the search path is first reset and then addition
16038occurs as normal.
16039Multiple directories may be specified, separated by blanks. Specifying
16040multiple directories in a single command
16041results in the directories added to the beginning of the
16042search path in the same order they were presented in the command.
16043If blanks are needed as
16044part of a directory name, double-quotes should be used around
16045the name. In the command output, the path will show up separated
16046by the system directory-separator character. The directory-seperator
16047character must not be used
16048in any directory name.
16049If no directories are specified, the current path is displayed.
16050
16051
16052@subsubheading @value{GDBN} Command
16053
16054The corresponding @value{GDBN} command is @samp{path}.
16055
16056@subsubheading Example
16057
16058@smallexample
16059(@value{GDBP})
16060-environment-path
16061^done,path="/usr/bin"
16062(@value{GDBP})
16063-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
16064^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
16065(@value{GDBP})
16066-environment-path -r /usr/local/bin
16067^done,path="/usr/local/bin:/usr/bin"
16068(@value{GDBP})
16069@end smallexample
16070
16071
16072@subheading The @code{-environment-pwd} Command
16073@findex -environment-pwd
16074
16075@subsubheading Synopsis
16076
16077@smallexample
16078 -environment-pwd
16079@end smallexample
16080
16081Show the current working directory.
16082
16083@subsubheading @value{GDBN} command
16084
16085The corresponding @value{GDBN} command is @samp{pwd}.
16086
16087@subsubheading Example
16088
16089@smallexample
16090(@value{GDBP})
16091-environment-pwd
16092^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
16093(@value{GDBP})
16094@end smallexample
16095
16096@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16097@node GDB/MI Program Control
16098@section @sc{gdb/mi} Program control
16099
16100@subsubheading Program termination
16101
16102As a result of execution, the inferior program can run to completion, if
16103it doesn't encounter any breakpoints. In this case the output will
16104include an exit code, if the program has exited exceptionally.
16105
16106@subsubheading Examples
16107
16108@noindent
16109Program exited normally:
16110
16111@smallexample
16112(@value{GDBP})
16113-exec-run
16114^running
16115(@value{GDBP})
16116x = 55
16117*stopped,reason="exited-normally"
16118(@value{GDBP})
16119@end smallexample
16120
16121@noindent
16122Program exited exceptionally:
16123
16124@smallexample
16125(@value{GDBP})
16126-exec-run
16127^running
16128(@value{GDBP})
16129x = 55
16130*stopped,reason="exited",exit-code="01"
16131(@value{GDBP})
16132@end smallexample
16133
16134Another way the program can terminate is if it receives a signal such as
16135@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
16136
16137@smallexample
16138(@value{GDBP})
16139*stopped,reason="exited-signalled",signal-name="SIGINT",
16140signal-meaning="Interrupt"
16141@end smallexample
16142
16143
16144@subheading The @code{-exec-abort} Command
16145@findex -exec-abort
16146
16147@subsubheading Synopsis
16148
16149@smallexample
16150 -exec-abort
16151@end smallexample
16152
16153Kill the inferior running program.
16154
16155@subsubheading @value{GDBN} Command
16156
16157The corresponding @value{GDBN} command is @samp{kill}.
16158
16159@subsubheading Example
16160N.A.
16161
16162
16163@subheading The @code{-exec-arguments} Command
16164@findex -exec-arguments
16165
16166@subsubheading Synopsis
16167
16168@smallexample
16169 -exec-arguments @var{args}
16170@end smallexample
16171
16172Set the inferior program arguments, to be used in the next
16173@samp{-exec-run}.
16174
16175@subsubheading @value{GDBN} Command
16176
16177The corresponding @value{GDBN} command is @samp{set args}.
16178
16179@subsubheading Example
16180
16181@c FIXME!
16182Don't have one around.
16183
16184
16185@subheading The @code{-exec-continue} Command
16186@findex -exec-continue
16187
16188@subsubheading Synopsis
16189
16190@smallexample
16191 -exec-continue
16192@end smallexample
16193
16194Asynchronous command. Resumes the execution of the inferior program
16195until a breakpoint is encountered, or until the inferior exits.
16196
16197@subsubheading @value{GDBN} Command
16198
16199The corresponding @value{GDBN} corresponding is @samp{continue}.
16200
16201@subsubheading Example
16202
16203@smallexample
16204-exec-continue
16205^running
16206(@value{GDBP})
16207@@Hello world
16208*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
16209file="hello.c",line="13"@}
16210(@value{GDBP})
16211@end smallexample
16212
16213
16214@subheading The @code{-exec-finish} Command
16215@findex -exec-finish
16216
16217@subsubheading Synopsis
16218
16219@smallexample
16220 -exec-finish
16221@end smallexample
16222
16223Asynchronous command. Resumes the execution of the inferior program
16224until the current function is exited. Displays the results returned by
16225the function.
16226
16227@subsubheading @value{GDBN} Command
16228
16229The corresponding @value{GDBN} command is @samp{finish}.
16230
16231@subsubheading Example
16232
16233Function returning @code{void}.
16234
16235@smallexample
16236-exec-finish
16237^running
16238(@value{GDBP})
16239@@hello from foo
16240*stopped,reason="function-finished",frame=@{func="main",args=[],
16241file="hello.c",line="7"@}
16242(@value{GDBP})
16243@end smallexample
16244
16245Function returning other than @code{void}. The name of the internal
16246@value{GDBN} variable storing the result is printed, together with the
16247value itself.
16248
16249@smallexample
16250-exec-finish
16251^running
16252(@value{GDBP})
16253*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
16254args=[@{name="a",value="1"],@{name="b",value="9"@}@},
16255file="recursive2.c",line="14"@},
16256gdb-result-var="$1",return-value="0"
16257(@value{GDBP})
16258@end smallexample
16259
16260
16261@subheading The @code{-exec-interrupt} Command
16262@findex -exec-interrupt
16263
16264@subsubheading Synopsis
16265
16266@smallexample
16267 -exec-interrupt
16268@end smallexample
16269
16270Asynchronous command. Interrupts the background execution of the target.
16271Note how the token associated with the stop message is the one for the
16272execution command that has been interrupted. The token for the interrupt
16273itself only appears in the @samp{^done} output. If the user is trying to
16274interrupt a non-running program, an error message will be printed.
16275
16276@subsubheading @value{GDBN} Command
16277
16278The corresponding @value{GDBN} command is @samp{interrupt}.
16279
16280@subsubheading Example
16281
16282@smallexample
16283(@value{GDBP})
16284111-exec-continue
16285111^running
16286
16287(@value{GDBP})
16288222-exec-interrupt
16289222^done
16290(@value{GDBP})
16291111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
16292frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
16293(@value{GDBP})
16294
16295(@value{GDBP})
16296-exec-interrupt
16297^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
16298(@value{GDBP})
16299@end smallexample
16300
16301
16302@subheading The @code{-exec-next} Command
16303@findex -exec-next
16304
16305@subsubheading Synopsis
16306
16307@smallexample
16308 -exec-next
16309@end smallexample
16310
16311Asynchronous command. Resumes execution of the inferior program, stopping
16312when the beginning of the next source line is reached.
16313
16314@subsubheading @value{GDBN} Command
16315
16316The corresponding @value{GDBN} command is @samp{next}.
16317
16318@subsubheading Example
16319
16320@smallexample
16321-exec-next
16322^running
16323(@value{GDBP})
16324*stopped,reason="end-stepping-range",line="8",file="hello.c"
16325(@value{GDBP})
16326@end smallexample
16327
16328
16329@subheading The @code{-exec-next-instruction} Command
16330@findex -exec-next-instruction
16331
16332@subsubheading Synopsis
16333
16334@smallexample
16335 -exec-next-instruction
16336@end smallexample
16337
16338Asynchronous command. Executes one machine instruction. If the
16339instruction is a function call continues until the function returns. If
16340the program stops at an instruction in the middle of a source line, the
16341address will be printed as well.
16342
16343@subsubheading @value{GDBN} Command
16344
16345The corresponding @value{GDBN} command is @samp{nexti}.
16346
16347@subsubheading Example
16348
16349@smallexample
16350(@value{GDBP})
16351-exec-next-instruction
16352^running
16353
16354(@value{GDBP})
16355*stopped,reason="end-stepping-range",
16356addr="0x000100d4",line="5",file="hello.c"
16357(@value{GDBP})
16358@end smallexample
16359
16360
16361@subheading The @code{-exec-return} Command
16362@findex -exec-return
16363
16364@subsubheading Synopsis
16365
16366@smallexample
16367 -exec-return
16368@end smallexample
16369
16370Makes current function return immediately. Doesn't execute the inferior.
16371Displays the new current frame.
16372
16373@subsubheading @value{GDBN} Command
16374
16375The corresponding @value{GDBN} command is @samp{return}.
16376
16377@subsubheading Example
16378
16379@smallexample
16380(@value{GDBP})
16381200-break-insert callee4
16382200^done,bkpt=@{number="1",addr="0x00010734",
16383file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16384(@value{GDBP})
16385000-exec-run
16386000^running
16387(@value{GDBP})
16388000*stopped,reason="breakpoint-hit",bkptno="1",
16389frame=@{func="callee4",args=[],
16390file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
16391(@value{GDBP})
16392205-break-delete
16393205^done
16394(@value{GDBP})
16395111-exec-return
16396111^done,frame=@{level="0",func="callee3",
16397args=[@{name="strarg",
16398value="0x11940 \"A string argument.\""@}],
16399file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
16400(@value{GDBP})
16401@end smallexample
16402
16403
16404@subheading The @code{-exec-run} Command
16405@findex -exec-run
16406
16407@subsubheading Synopsis
16408
16409@smallexample
16410 -exec-run
16411@end smallexample
16412
16413Asynchronous command. Starts execution of the inferior from the
16414beginning. The inferior executes until either a breakpoint is
16415encountered or the program exits.
16416
16417@subsubheading @value{GDBN} Command
16418
16419The corresponding @value{GDBN} command is @samp{run}.
16420
16421@subsubheading Example
16422
16423@smallexample
16424(@value{GDBP})
16425-break-insert main
16426^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
16427(@value{GDBP})
16428-exec-run
16429^running
16430(@value{GDBP})
16431*stopped,reason="breakpoint-hit",bkptno="1",
16432frame=@{func="main",args=[],file="recursive2.c",line="4"@}
16433(@value{GDBP})
16434@end smallexample
16435
16436
16437@subheading The @code{-exec-show-arguments} Command
16438@findex -exec-show-arguments
16439
16440@subsubheading Synopsis
16441
16442@smallexample
16443 -exec-show-arguments
16444@end smallexample
16445
16446Print the arguments of the program.
16447
16448@subsubheading @value{GDBN} Command
16449
16450The corresponding @value{GDBN} command is @samp{show args}.
16451
16452@subsubheading Example
16453N.A.
16454
16455@c @subheading -exec-signal
16456
16457@subheading The @code{-exec-step} Command
16458@findex -exec-step
16459
16460@subsubheading Synopsis
16461
16462@smallexample
16463 -exec-step
16464@end smallexample
16465
16466Asynchronous command. Resumes execution of the inferior program, stopping
16467when the beginning of the next source line is reached, if the next
16468source line is not a function call. If it is, stop at the first
16469instruction of the called function.
16470
16471@subsubheading @value{GDBN} Command
16472
16473The corresponding @value{GDBN} command is @samp{step}.
16474
16475@subsubheading Example
16476
16477Stepping into a function:
16478
16479@smallexample
16480-exec-step
16481^running
16482(@value{GDBP})
16483*stopped,reason="end-stepping-range",
16484frame=@{func="foo",args=[@{name="a",value="10"@},
16485@{name="b",value="0"@}],file="recursive2.c",line="11"@}
16486(@value{GDBP})
16487@end smallexample
16488
16489Regular stepping:
16490
16491@smallexample
16492-exec-step
16493^running
16494(@value{GDBP})
16495*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
16496(@value{GDBP})
16497@end smallexample
16498
16499
16500@subheading The @code{-exec-step-instruction} Command
16501@findex -exec-step-instruction
16502
16503@subsubheading Synopsis
16504
16505@smallexample
16506 -exec-step-instruction
16507@end smallexample
16508
16509Asynchronous command. Resumes the inferior which executes one machine
16510instruction. The output, once @value{GDBN} has stopped, will vary depending on
16511whether we have stopped in the middle of a source line or not. In the
16512former case, the address at which the program stopped will be printed as
16513well.
16514
16515@subsubheading @value{GDBN} Command
16516
16517The corresponding @value{GDBN} command is @samp{stepi}.
16518
16519@subsubheading Example
16520
16521@smallexample
16522(@value{GDBP})
16523-exec-step-instruction
16524^running
16525
16526(@value{GDBP})
16527*stopped,reason="end-stepping-range",
16528frame=@{func="foo",args=[],file="try.c",line="10"@}
16529(@value{GDBP})
16530-exec-step-instruction
16531^running
16532
16533(@value{GDBP})
16534*stopped,reason="end-stepping-range",
16535frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
16536(@value{GDBP})
16537@end smallexample
16538
16539
16540@subheading The @code{-exec-until} Command
16541@findex -exec-until
16542
16543@subsubheading Synopsis
16544
16545@smallexample
16546 -exec-until [ @var{location} ]
16547@end smallexample
16548
16549Asynchronous command. Executes the inferior until the @var{location}
16550specified in the argument is reached. If there is no argument, the inferior
16551executes until a source line greater than the current one is reached.
16552The reason for stopping in this case will be @samp{location-reached}.
16553
16554@subsubheading @value{GDBN} Command
16555
16556The corresponding @value{GDBN} command is @samp{until}.
16557
16558@subsubheading Example
16559
16560@smallexample
16561(@value{GDBP})
16562-exec-until recursive2.c:6
16563^running
16564(@value{GDBP})
16565x = 55
16566*stopped,reason="location-reached",frame=@{func="main",args=[],
16567file="recursive2.c",line="6"@}
16568(@value{GDBP})
16569@end smallexample
16570
16571@ignore
16572@subheading -file-clear
16573Is this going away????
16574@end ignore
16575
16576
16577@subheading The @code{-file-exec-and-symbols} Command
16578@findex -file-exec-and-symbols
16579
16580@subsubheading Synopsis
16581
16582@smallexample
16583 -file-exec-and-symbols @var{file}
16584@end smallexample
16585
16586Specify the executable file to be debugged. This file is the one from
16587which the symbol table is also read. If no file is specified, the
16588command clears the executable and symbol information. If breakpoints
16589are set when using this command with no arguments, @value{GDBN} will produce
16590error messages. Otherwise, no output is produced, except a completion
16591notification.
16592
16593@subsubheading @value{GDBN} Command
16594
16595The corresponding @value{GDBN} command is @samp{file}.
16596
16597@subsubheading Example
16598
16599@smallexample
16600(@value{GDBP})
16601-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16602^done
16603(@value{GDBP})
16604@end smallexample
16605
16606
16607@subheading The @code{-file-exec-file} Command
16608@findex -file-exec-file
16609
16610@subsubheading Synopsis
16611
16612@smallexample
16613 -file-exec-file @var{file}
16614@end smallexample
16615
16616Specify the executable file to be debugged. Unlike
16617@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
16618from this file. If used without argument, @value{GDBN} clears the information
16619about the executable file. No output is produced, except a completion
16620notification.
16621
16622@subsubheading @value{GDBN} Command
16623
16624The corresponding @value{GDBN} command is @samp{exec-file}.
16625
16626@subsubheading Example
16627
16628@smallexample
16629(@value{GDBP})
16630-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16631^done
16632(@value{GDBP})
16633@end smallexample
16634
16635
16636@subheading The @code{-file-list-exec-sections} Command
16637@findex -file-list-exec-sections
16638
16639@subsubheading Synopsis
16640
16641@smallexample
16642 -file-list-exec-sections
16643@end smallexample
16644
16645List the sections of the current executable file.
16646
16647@subsubheading @value{GDBN} Command
16648
16649The @value{GDBN} command @samp{info file} shows, among the rest, the same
16650information as this command. @code{gdbtk} has a corresponding command
16651@samp{gdb_load_info}.
16652
16653@subsubheading Example
16654N.A.
16655
16656
1abaf70c
BR
16657@subheading The @code{-file-list-exec-source-file} Command
16658@findex -file-list-exec-source-file
16659
16660@subsubheading Synopsis
16661
16662@smallexample
16663 -file-list-exec-source-file
16664@end smallexample
16665
16666List the line number, the current source file, and the absolute path
16667to the current source file for the current executable.
16668
16669@subsubheading @value{GDBN} Command
16670
16671There's no @value{GDBN} command which directly corresponds to this one.
16672
16673@subsubheading Example
16674
16675@smallexample
16676(@value{GDBP})
16677123-file-list-exec-source-file
16678123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
16679(@value{GDBP})
16680@end smallexample
16681
16682
922fbb7b
AC
16683@subheading The @code{-file-list-exec-source-files} Command
16684@findex -file-list-exec-source-files
16685
16686@subsubheading Synopsis
16687
16688@smallexample
16689 -file-list-exec-source-files
16690@end smallexample
16691
16692List the source files for the current executable.
16693
16694@subsubheading @value{GDBN} Command
16695
16696There's no @value{GDBN} command which directly corresponds to this one.
16697@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
16698
16699@subsubheading Example
16700N.A.
16701
16702
16703@subheading The @code{-file-list-shared-libraries} Command
16704@findex -file-list-shared-libraries
16705
16706@subsubheading Synopsis
16707
16708@smallexample
16709 -file-list-shared-libraries
16710@end smallexample
16711
16712List the shared libraries in the program.
16713
16714@subsubheading @value{GDBN} Command
16715
16716The corresponding @value{GDBN} command is @samp{info shared}.
16717
16718@subsubheading Example
16719N.A.
16720
16721
16722@subheading The @code{-file-list-symbol-files} Command
16723@findex -file-list-symbol-files
16724
16725@subsubheading Synopsis
16726
16727@smallexample
16728 -file-list-symbol-files
16729@end smallexample
16730
16731List symbol files.
16732
16733@subsubheading @value{GDBN} Command
16734
16735The corresponding @value{GDBN} command is @samp{info file} (part of it).
16736
16737@subsubheading Example
16738N.A.
16739
16740
16741@subheading The @code{-file-symbol-file} Command
16742@findex -file-symbol-file
16743
16744@subsubheading Synopsis
16745
16746@smallexample
16747 -file-symbol-file @var{file}
16748@end smallexample
16749
16750Read symbol table info from the specified @var{file} argument. When
16751used without arguments, clears @value{GDBN}'s symbol table info. No output is
16752produced, except for a completion notification.
16753
16754@subsubheading @value{GDBN} Command
16755
16756The corresponding @value{GDBN} command is @samp{symbol-file}.
16757
16758@subsubheading Example
16759
16760@smallexample
16761(@value{GDBP})
16762-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
16763^done
16764(@value{GDBP})
16765@end smallexample
16766
16767@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16768@node GDB/MI Miscellaneous Commands
16769@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
16770
16771@c @subheading -gdb-complete
16772
16773@subheading The @code{-gdb-exit} Command
16774@findex -gdb-exit
16775
16776@subsubheading Synopsis
16777
16778@smallexample
16779 -gdb-exit
16780@end smallexample
16781
16782Exit @value{GDBN} immediately.
16783
16784@subsubheading @value{GDBN} Command
16785
16786Approximately corresponds to @samp{quit}.
16787
16788@subsubheading Example
16789
16790@smallexample
16791(@value{GDBP})
16792-gdb-exit
16793@end smallexample
16794
16795@subheading The @code{-gdb-set} Command
16796@findex -gdb-set
16797
16798@subsubheading Synopsis
16799
16800@smallexample
16801 -gdb-set
16802@end smallexample
16803
16804Set an internal @value{GDBN} variable.
16805@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
16806
16807@subsubheading @value{GDBN} Command
16808
16809The corresponding @value{GDBN} command is @samp{set}.
16810
16811@subsubheading Example
16812
16813@smallexample
16814(@value{GDBP})
16815-gdb-set $foo=3
16816^done
16817(@value{GDBP})
16818@end smallexample
16819
16820
16821@subheading The @code{-gdb-show} Command
16822@findex -gdb-show
16823
16824@subsubheading Synopsis
16825
16826@smallexample
16827 -gdb-show
16828@end smallexample
16829
16830Show the current value of a @value{GDBN} variable.
16831
16832@subsubheading @value{GDBN} command
16833
16834The corresponding @value{GDBN} command is @samp{show}.
16835
16836@subsubheading Example
16837
16838@smallexample
16839(@value{GDBP})
16840-gdb-show annotate
16841^done,value="0"
16842(@value{GDBP})
16843@end smallexample
16844
16845@c @subheading -gdb-source
16846
16847
16848@subheading The @code{-gdb-version} Command
16849@findex -gdb-version
16850
16851@subsubheading Synopsis
16852
16853@smallexample
16854 -gdb-version
16855@end smallexample
16856
16857Show version information for @value{GDBN}. Used mostly in testing.
16858
16859@subsubheading @value{GDBN} Command
16860
16861There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
16862information when you start an interactive session.
16863
16864@subsubheading Example
16865
16866@c This example modifies the actual output from GDB to avoid overfull
16867@c box in TeX.
16868@smallexample
16869(@value{GDBP})
16870-gdb-version
16871~GNU gdb 5.2.1
16872~Copyright 2000 Free Software Foundation, Inc.
16873~GDB is free software, covered by the GNU General Public License, and
16874~you are welcome to change it and/or distribute copies of it under
16875~ certain conditions.
16876~Type "show copying" to see the conditions.
16877~There is absolutely no warranty for GDB. Type "show warranty" for
16878~ details.
16879~This GDB was configured as
16880 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
16881^done
16882(@value{GDBP})
16883@end smallexample
16884
16885@subheading The @code{-interpreter-exec} Command
16886@findex -interpreter-exec
16887
16888@subheading Synopsis
16889
16890@smallexample
16891-interpreter-exec @var{interpreter} @var{command}
16892@end smallexample
16893
16894Execute the specified @var{command} in the given @var{interpreter}.
16895
16896@subheading @value{GDBN} Command
16897
16898The corresponding @value{GDBN} command is @samp{interpreter-exec}.
16899
16900@subheading Example
16901
16902@smallexample
16903(@value{GDBP})
16904-interpreter-exec console "break main"
16905&"During symbol reading, couldn't parse type; debugger out of date?.\n"
16906&"During symbol reading, bad structure-type format.\n"
16907~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
16908^done
16909(@value{GDBP})
16910@end smallexample
16911
16912@ignore
16913@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16914@node GDB/MI Kod Commands
16915@section @sc{gdb/mi} Kod Commands
16916
16917The Kod commands are not implemented.
16918
16919@c @subheading -kod-info
16920
16921@c @subheading -kod-list
16922
16923@c @subheading -kod-list-object-types
16924
16925@c @subheading -kod-show
16926
16927@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16928@node GDB/MI Memory Overlay Commands
16929@section @sc{gdb/mi} Memory Overlay Commands
16930
16931The memory overlay commands are not implemented.
16932
16933@c @subheading -overlay-auto
16934
16935@c @subheading -overlay-list-mapping-state
16936
16937@c @subheading -overlay-list-overlays
16938
16939@c @subheading -overlay-map
16940
16941@c @subheading -overlay-off
16942
16943@c @subheading -overlay-on
16944
16945@c @subheading -overlay-unmap
16946
16947@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16948@node GDB/MI Signal Handling Commands
16949@section @sc{gdb/mi} Signal Handling Commands
16950
16951Signal handling commands are not implemented.
16952
16953@c @subheading -signal-handle
16954
16955@c @subheading -signal-list-handle-actions
16956
16957@c @subheading -signal-list-signal-types
16958@end ignore
16959
16960
16961@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16962@node GDB/MI Stack Manipulation
16963@section @sc{gdb/mi} Stack Manipulation Commands
16964
16965
16966@subheading The @code{-stack-info-frame} Command
16967@findex -stack-info-frame
16968
16969@subsubheading Synopsis
16970
16971@smallexample
16972 -stack-info-frame
16973@end smallexample
16974
16975Get info on the current frame.
16976
16977@subsubheading @value{GDBN} Command
16978
16979The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
16980(without arguments).
16981
16982@subsubheading Example
16983N.A.
16984
16985@subheading The @code{-stack-info-depth} Command
16986@findex -stack-info-depth
16987
16988@subsubheading Synopsis
16989
16990@smallexample
16991 -stack-info-depth [ @var{max-depth} ]
16992@end smallexample
16993
16994Return the depth of the stack. If the integer argument @var{max-depth}
16995is specified, do not count beyond @var{max-depth} frames.
16996
16997@subsubheading @value{GDBN} Command
16998
16999There's no equivalent @value{GDBN} command.
17000
17001@subsubheading Example
17002
17003For a stack with frame levels 0 through 11:
17004
17005@smallexample
17006(@value{GDBP})
17007-stack-info-depth
17008^done,depth="12"
17009(@value{GDBP})
17010-stack-info-depth 4
17011^done,depth="4"
17012(@value{GDBP})
17013-stack-info-depth 12
17014^done,depth="12"
17015(@value{GDBP})
17016-stack-info-depth 11
17017^done,depth="11"
17018(@value{GDBP})
17019-stack-info-depth 13
17020^done,depth="12"
17021(@value{GDBP})
17022@end smallexample
17023
17024@subheading The @code{-stack-list-arguments} Command
17025@findex -stack-list-arguments
17026
17027@subsubheading Synopsis
17028
17029@smallexample
17030 -stack-list-arguments @var{show-values}
17031 [ @var{low-frame} @var{high-frame} ]
17032@end smallexample
17033
17034Display a list of the arguments for the frames between @var{low-frame}
17035and @var{high-frame} (inclusive). If @var{low-frame} and
17036@var{high-frame} are not provided, list the arguments for the whole call
17037stack.
17038
17039The @var{show-values} argument must have a value of 0 or 1. A value of
170400 means that only the names of the arguments are listed, a value of 1
17041means that both names and values of the arguments are printed.
17042
17043@subsubheading @value{GDBN} Command
17044
17045@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
17046@samp{gdb_get_args} command which partially overlaps with the
17047functionality of @samp{-stack-list-arguments}.
17048
17049@subsubheading Example
17050
17051@smallexample
17052(@value{GDBP})
17053-stack-list-frames
17054^done,
17055stack=[
17056frame=@{level="0",addr="0x00010734",func="callee4",
17057file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
17058frame=@{level="1",addr="0x0001076c",func="callee3",
17059file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
17060frame=@{level="2",addr="0x0001078c",func="callee2",
17061file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
17062frame=@{level="3",addr="0x000107b4",func="callee1",
17063file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
17064frame=@{level="4",addr="0x000107e0",func="main",
17065file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
17066(@value{GDBP})
17067-stack-list-arguments 0
17068^done,
17069stack-args=[
17070frame=@{level="0",args=[]@},
17071frame=@{level="1",args=[name="strarg"]@},
17072frame=@{level="2",args=[name="intarg",name="strarg"]@},
17073frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
17074frame=@{level="4",args=[]@}]
17075(@value{GDBP})
17076-stack-list-arguments 1
17077^done,
17078stack-args=[
17079frame=@{level="0",args=[]@},
17080frame=@{level="1",
17081 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17082frame=@{level="2",args=[
17083@{name="intarg",value="2"@},
17084@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
17085@{frame=@{level="3",args=[
17086@{name="intarg",value="2"@},
17087@{name="strarg",value="0x11940 \"A string argument.\""@},
17088@{name="fltarg",value="3.5"@}]@},
17089frame=@{level="4",args=[]@}]
17090(@value{GDBP})
17091-stack-list-arguments 0 2 2
17092^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
17093(@value{GDBP})
17094-stack-list-arguments 1 2 2
17095^done,stack-args=[frame=@{level="2",
17096args=[@{name="intarg",value="2"@},
17097@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
17098(@value{GDBP})
17099@end smallexample
17100
17101@c @subheading -stack-list-exception-handlers
17102
17103
17104@subheading The @code{-stack-list-frames} Command
17105@findex -stack-list-frames
17106
17107@subsubheading Synopsis
17108
17109@smallexample
17110 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
17111@end smallexample
17112
17113List the frames currently on the stack. For each frame it displays the
17114following info:
17115
17116@table @samp
17117@item @var{level}
17118The frame number, 0 being the topmost frame, i.e. the innermost function.
17119@item @var{addr}
17120The @code{$pc} value for that frame.
17121@item @var{func}
17122Function name.
17123@item @var{file}
17124File name of the source file where the function lives.
17125@item @var{line}
17126Line number corresponding to the @code{$pc}.
17127@end table
17128
17129If invoked without arguments, this command prints a backtrace for the
17130whole stack. If given two integer arguments, it shows the frames whose
17131levels are between the two arguments (inclusive). If the two arguments
17132are equal, it shows the single frame at the corresponding level.
17133
17134@subsubheading @value{GDBN} Command
17135
17136The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
17137
17138@subsubheading Example
17139
17140Full stack backtrace:
17141
17142@smallexample
17143(@value{GDBP})
17144-stack-list-frames
17145^done,stack=
17146[frame=@{level="0",addr="0x0001076c",func="foo",
17147 file="recursive2.c",line="11"@},
17148frame=@{level="1",addr="0x000107a4",func="foo",
17149 file="recursive2.c",line="14"@},
17150frame=@{level="2",addr="0x000107a4",func="foo",
17151 file="recursive2.c",line="14"@},
17152frame=@{level="3",addr="0x000107a4",func="foo",
17153 file="recursive2.c",line="14"@},
17154frame=@{level="4",addr="0x000107a4",func="foo",
17155 file="recursive2.c",line="14"@},
17156frame=@{level="5",addr="0x000107a4",func="foo",
17157 file="recursive2.c",line="14"@},
17158frame=@{level="6",addr="0x000107a4",func="foo",
17159 file="recursive2.c",line="14"@},
17160frame=@{level="7",addr="0x000107a4",func="foo",
17161 file="recursive2.c",line="14"@},
17162frame=@{level="8",addr="0x000107a4",func="foo",
17163 file="recursive2.c",line="14"@},
17164frame=@{level="9",addr="0x000107a4",func="foo",
17165 file="recursive2.c",line="14"@},
17166frame=@{level="10",addr="0x000107a4",func="foo",
17167 file="recursive2.c",line="14"@},
17168frame=@{level="11",addr="0x00010738",func="main",
17169 file="recursive2.c",line="4"@}]
17170(@value{GDBP})
17171@end smallexample
17172
17173Show frames between @var{low_frame} and @var{high_frame}:
17174
17175@smallexample
17176(@value{GDBP})
17177-stack-list-frames 3 5
17178^done,stack=
17179[frame=@{level="3",addr="0x000107a4",func="foo",
17180 file="recursive2.c",line="14"@},
17181frame=@{level="4",addr="0x000107a4",func="foo",
17182 file="recursive2.c",line="14"@},
17183frame=@{level="5",addr="0x000107a4",func="foo",
17184 file="recursive2.c",line="14"@}]
17185(@value{GDBP})
17186@end smallexample
17187
17188Show a single frame:
17189
17190@smallexample
17191(@value{GDBP})
17192-stack-list-frames 3 3
17193^done,stack=
17194[frame=@{level="3",addr="0x000107a4",func="foo",
17195 file="recursive2.c",line="14"@}]
17196(@value{GDBP})
17197@end smallexample
17198
17199
17200@subheading The @code{-stack-list-locals} Command
17201@findex -stack-list-locals
17202
17203@subsubheading Synopsis
17204
17205@smallexample
17206 -stack-list-locals @var{print-values}
17207@end smallexample
17208
17209Display the local variable names for the current frame. With an
17210argument of 0 prints only the names of the variables, with argument of 1
17211prints also their values.
17212
17213@subsubheading @value{GDBN} Command
17214
17215@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
17216
17217@subsubheading Example
17218
17219@smallexample
17220(@value{GDBP})
17221-stack-list-locals 0
17222^done,locals=[name="A",name="B",name="C"]
17223(@value{GDBP})
17224-stack-list-locals 1
17225^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
17226 @{name="C",value="3"@}]
17227(@value{GDBP})
17228@end smallexample
17229
17230
17231@subheading The @code{-stack-select-frame} Command
17232@findex -stack-select-frame
17233
17234@subsubheading Synopsis
17235
17236@smallexample
17237 -stack-select-frame @var{framenum}
17238@end smallexample
17239
17240Change the current frame. Select a different frame @var{framenum} on
17241the stack.
17242
17243@subsubheading @value{GDBN} Command
17244
17245The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
17246@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
17247
17248@subsubheading Example
17249
17250@smallexample
17251(@value{GDBP})
17252-stack-select-frame 2
17253^done
17254(@value{GDBP})
17255@end smallexample
17256
17257@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17258@node GDB/MI Symbol Query
17259@section @sc{gdb/mi} Symbol Query Commands
17260
17261
17262@subheading The @code{-symbol-info-address} Command
17263@findex -symbol-info-address
17264
17265@subsubheading Synopsis
17266
17267@smallexample
17268 -symbol-info-address @var{symbol}
17269@end smallexample
17270
17271Describe where @var{symbol} is stored.
17272
17273@subsubheading @value{GDBN} Command
17274
17275The corresponding @value{GDBN} command is @samp{info address}.
17276
17277@subsubheading Example
17278N.A.
17279
17280
17281@subheading The @code{-symbol-info-file} Command
17282@findex -symbol-info-file
17283
17284@subsubheading Synopsis
17285
17286@smallexample
17287 -symbol-info-file
17288@end smallexample
17289
17290Show the file for the symbol.
17291
17292@subsubheading @value{GDBN} Command
17293
17294There's no equivalent @value{GDBN} command. @code{gdbtk} has
17295@samp{gdb_find_file}.
17296
17297@subsubheading Example
17298N.A.
17299
17300
17301@subheading The @code{-symbol-info-function} Command
17302@findex -symbol-info-function
17303
17304@subsubheading Synopsis
17305
17306@smallexample
17307 -symbol-info-function
17308@end smallexample
17309
17310Show which function the symbol lives in.
17311
17312@subsubheading @value{GDBN} Command
17313
17314@samp{gdb_get_function} in @code{gdbtk}.
17315
17316@subsubheading Example
17317N.A.
17318
17319
17320@subheading The @code{-symbol-info-line} Command
17321@findex -symbol-info-line
17322
17323@subsubheading Synopsis
17324
17325@smallexample
17326 -symbol-info-line
17327@end smallexample
17328
17329Show the core addresses of the code for a source line.
17330
17331@subsubheading @value{GDBN} Command
17332
71952f4c 17333The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
17334@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
17335
17336@subsubheading Example
17337N.A.
17338
17339
17340@subheading The @code{-symbol-info-symbol} Command
17341@findex -symbol-info-symbol
17342
17343@subsubheading Synopsis
17344
17345@smallexample
17346 -symbol-info-symbol @var{addr}
17347@end smallexample
17348
17349Describe what symbol is at location @var{addr}.
17350
17351@subsubheading @value{GDBN} Command
17352
17353The corresponding @value{GDBN} command is @samp{info symbol}.
17354
17355@subsubheading Example
17356N.A.
17357
17358
17359@subheading The @code{-symbol-list-functions} Command
17360@findex -symbol-list-functions
17361
17362@subsubheading Synopsis
17363
17364@smallexample
17365 -symbol-list-functions
17366@end smallexample
17367
17368List the functions in the executable.
17369
17370@subsubheading @value{GDBN} Command
17371
17372@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
17373@samp{gdb_search} in @code{gdbtk}.
17374
17375@subsubheading Example
17376N.A.
17377
17378
32e7087d
JB
17379@subheading The @code{-symbol-list-lines} Command
17380@findex -symbol-list-lines
17381
17382@subsubheading Synopsis
17383
17384@smallexample
17385 -symbol-list-lines @var{filename}
17386@end smallexample
17387
17388Print the list of lines that contain code and their associated program
17389addresses for the given source filename. The entries are sorted in
17390ascending PC order.
17391
17392@subsubheading @value{GDBN} Command
17393
17394There is no corresponding @value{GDBN} command.
17395
17396@subsubheading Example
17397@smallexample
17398(@value{GDBP})
17399-symbol-list-lines basics.c
54ff5908 17400^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
17401(@value{GDBP})
17402@end smallexample
17403
17404
922fbb7b
AC
17405@subheading The @code{-symbol-list-types} Command
17406@findex -symbol-list-types
17407
17408@subsubheading Synopsis
17409
17410@smallexample
17411 -symbol-list-types
17412@end smallexample
17413
17414List all the type names.
17415
17416@subsubheading @value{GDBN} Command
17417
17418The corresponding commands are @samp{info types} in @value{GDBN},
17419@samp{gdb_search} in @code{gdbtk}.
17420
17421@subsubheading Example
17422N.A.
17423
17424
17425@subheading The @code{-symbol-list-variables} Command
17426@findex -symbol-list-variables
17427
17428@subsubheading Synopsis
17429
17430@smallexample
17431 -symbol-list-variables
17432@end smallexample
17433
17434List all the global and static variable names.
17435
17436@subsubheading @value{GDBN} Command
17437
17438@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
17439
17440@subsubheading Example
17441N.A.
17442
17443
17444@subheading The @code{-symbol-locate} Command
17445@findex -symbol-locate
17446
17447@subsubheading Synopsis
17448
17449@smallexample
17450 -symbol-locate
17451@end smallexample
17452
17453@subsubheading @value{GDBN} Command
17454
17455@samp{gdb_loc} in @code{gdbtk}.
17456
17457@subsubheading Example
17458N.A.
17459
17460
17461@subheading The @code{-symbol-type} Command
17462@findex -symbol-type
17463
17464@subsubheading Synopsis
17465
17466@smallexample
17467 -symbol-type @var{variable}
17468@end smallexample
17469
17470Show type of @var{variable}.
17471
17472@subsubheading @value{GDBN} Command
17473
17474The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
17475@samp{gdb_obj_variable}.
17476
17477@subsubheading Example
17478N.A.
17479
17480
17481@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17482@node GDB/MI Target Manipulation
17483@section @sc{gdb/mi} Target Manipulation Commands
17484
17485
17486@subheading The @code{-target-attach} Command
17487@findex -target-attach
17488
17489@subsubheading Synopsis
17490
17491@smallexample
17492 -target-attach @var{pid} | @var{file}
17493@end smallexample
17494
17495Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
17496
17497@subsubheading @value{GDBN} command
17498
17499The corresponding @value{GDBN} command is @samp{attach}.
17500
17501@subsubheading Example
17502N.A.
17503
17504
17505@subheading The @code{-target-compare-sections} Command
17506@findex -target-compare-sections
17507
17508@subsubheading Synopsis
17509
17510@smallexample
17511 -target-compare-sections [ @var{section} ]
17512@end smallexample
17513
17514Compare data of section @var{section} on target to the exec file.
17515Without the argument, all sections are compared.
17516
17517@subsubheading @value{GDBN} Command
17518
17519The @value{GDBN} equivalent is @samp{compare-sections}.
17520
17521@subsubheading Example
17522N.A.
17523
17524
17525@subheading The @code{-target-detach} Command
17526@findex -target-detach
17527
17528@subsubheading Synopsis
17529
17530@smallexample
17531 -target-detach
17532@end smallexample
17533
17534Disconnect from the remote target. There's no output.
17535
17536@subsubheading @value{GDBN} command
17537
17538The corresponding @value{GDBN} command is @samp{detach}.
17539
17540@subsubheading Example
17541
17542@smallexample
17543(@value{GDBP})
17544-target-detach
17545^done
17546(@value{GDBP})
17547@end smallexample
17548
17549
07f31aa6
DJ
17550@subheading The @code{-target-disconnect} Command
17551@findex -target-disconnect
17552
17553@subsubheading Synopsis
17554
17555@example
17556 -target-disconnect
17557@end example
17558
17559Disconnect from the remote target. There's no output.
17560
17561@subsubheading @value{GDBN} command
17562
17563The corresponding @value{GDBN} command is @samp{disconnect}.
17564
17565@subsubheading Example
17566
17567@smallexample
17568(@value{GDBP})
17569-target-disconnect
17570^done
17571(@value{GDBP})
17572@end smallexample
17573
17574
922fbb7b
AC
17575@subheading The @code{-target-download} Command
17576@findex -target-download
17577
17578@subsubheading Synopsis
17579
17580@smallexample
17581 -target-download
17582@end smallexample
17583
17584Loads the executable onto the remote target.
17585It prints out an update message every half second, which includes the fields:
17586
17587@table @samp
17588@item section
17589The name of the section.
17590@item section-sent
17591The size of what has been sent so far for that section.
17592@item section-size
17593The size of the section.
17594@item total-sent
17595The total size of what was sent so far (the current and the previous sections).
17596@item total-size
17597The size of the overall executable to download.
17598@end table
17599
17600@noindent
17601Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
17602@sc{gdb/mi} Output Syntax}).
17603
17604In addition, it prints the name and size of the sections, as they are
17605downloaded. These messages include the following fields:
17606
17607@table @samp
17608@item section
17609The name of the section.
17610@item section-size
17611The size of the section.
17612@item total-size
17613The size of the overall executable to download.
17614@end table
17615
17616@noindent
17617At the end, a summary is printed.
17618
17619@subsubheading @value{GDBN} Command
17620
17621The corresponding @value{GDBN} command is @samp{load}.
17622
17623@subsubheading Example
17624
17625Note: each status message appears on a single line. Here the messages
17626have been broken down so that they can fit onto a page.
17627
17628@smallexample
17629(@value{GDBP})
17630-target-download
17631+download,@{section=".text",section-size="6668",total-size="9880"@}
17632+download,@{section=".text",section-sent="512",section-size="6668",
17633total-sent="512",total-size="9880"@}
17634+download,@{section=".text",section-sent="1024",section-size="6668",
17635total-sent="1024",total-size="9880"@}
17636+download,@{section=".text",section-sent="1536",section-size="6668",
17637total-sent="1536",total-size="9880"@}
17638+download,@{section=".text",section-sent="2048",section-size="6668",
17639total-sent="2048",total-size="9880"@}
17640+download,@{section=".text",section-sent="2560",section-size="6668",
17641total-sent="2560",total-size="9880"@}
17642+download,@{section=".text",section-sent="3072",section-size="6668",
17643total-sent="3072",total-size="9880"@}
17644+download,@{section=".text",section-sent="3584",section-size="6668",
17645total-sent="3584",total-size="9880"@}
17646+download,@{section=".text",section-sent="4096",section-size="6668",
17647total-sent="4096",total-size="9880"@}
17648+download,@{section=".text",section-sent="4608",section-size="6668",
17649total-sent="4608",total-size="9880"@}
17650+download,@{section=".text",section-sent="5120",section-size="6668",
17651total-sent="5120",total-size="9880"@}
17652+download,@{section=".text",section-sent="5632",section-size="6668",
17653total-sent="5632",total-size="9880"@}
17654+download,@{section=".text",section-sent="6144",section-size="6668",
17655total-sent="6144",total-size="9880"@}
17656+download,@{section=".text",section-sent="6656",section-size="6668",
17657total-sent="6656",total-size="9880"@}
17658+download,@{section=".init",section-size="28",total-size="9880"@}
17659+download,@{section=".fini",section-size="28",total-size="9880"@}
17660+download,@{section=".data",section-size="3156",total-size="9880"@}
17661+download,@{section=".data",section-sent="512",section-size="3156",
17662total-sent="7236",total-size="9880"@}
17663+download,@{section=".data",section-sent="1024",section-size="3156",
17664total-sent="7748",total-size="9880"@}
17665+download,@{section=".data",section-sent="1536",section-size="3156",
17666total-sent="8260",total-size="9880"@}
17667+download,@{section=".data",section-sent="2048",section-size="3156",
17668total-sent="8772",total-size="9880"@}
17669+download,@{section=".data",section-sent="2560",section-size="3156",
17670total-sent="9284",total-size="9880"@}
17671+download,@{section=".data",section-sent="3072",section-size="3156",
17672total-sent="9796",total-size="9880"@}
17673^done,address="0x10004",load-size="9880",transfer-rate="6586",
17674write-rate="429"
17675(@value{GDBP})
17676@end smallexample
17677
17678
17679@subheading The @code{-target-exec-status} Command
17680@findex -target-exec-status
17681
17682@subsubheading Synopsis
17683
17684@smallexample
17685 -target-exec-status
17686@end smallexample
17687
17688Provide information on the state of the target (whether it is running or
17689not, for instance).
17690
17691@subsubheading @value{GDBN} Command
17692
17693There's no equivalent @value{GDBN} command.
17694
17695@subsubheading Example
17696N.A.
17697
17698
17699@subheading The @code{-target-list-available-targets} Command
17700@findex -target-list-available-targets
17701
17702@subsubheading Synopsis
17703
17704@smallexample
17705 -target-list-available-targets
17706@end smallexample
17707
17708List the possible targets to connect to.
17709
17710@subsubheading @value{GDBN} Command
17711
17712The corresponding @value{GDBN} command is @samp{help target}.
17713
17714@subsubheading Example
17715N.A.
17716
17717
17718@subheading The @code{-target-list-current-targets} Command
17719@findex -target-list-current-targets
17720
17721@subsubheading Synopsis
17722
17723@smallexample
17724 -target-list-current-targets
17725@end smallexample
17726
17727Describe the current target.
17728
17729@subsubheading @value{GDBN} Command
17730
17731The corresponding information is printed by @samp{info file} (among
17732other things).
17733
17734@subsubheading Example
17735N.A.
17736
17737
17738@subheading The @code{-target-list-parameters} Command
17739@findex -target-list-parameters
17740
17741@subsubheading Synopsis
17742
17743@smallexample
17744 -target-list-parameters
17745@end smallexample
17746
17747@c ????
17748
17749@subsubheading @value{GDBN} Command
17750
17751No equivalent.
17752
17753@subsubheading Example
17754N.A.
17755
17756
17757@subheading The @code{-target-select} Command
17758@findex -target-select
17759
17760@subsubheading Synopsis
17761
17762@smallexample
17763 -target-select @var{type} @var{parameters @dots{}}
17764@end smallexample
17765
17766Connect @value{GDBN} to the remote target. This command takes two args:
17767
17768@table @samp
17769@item @var{type}
17770The type of target, for instance @samp{async}, @samp{remote}, etc.
17771@item @var{parameters}
17772Device names, host names and the like. @xref{Target Commands, ,
17773Commands for managing targets}, for more details.
17774@end table
17775
17776The output is a connection notification, followed by the address at
17777which the target program is, in the following form:
17778
17779@smallexample
17780^connected,addr="@var{address}",func="@var{function name}",
17781 args=[@var{arg list}]
17782@end smallexample
17783
17784@subsubheading @value{GDBN} Command
17785
17786The corresponding @value{GDBN} command is @samp{target}.
17787
17788@subsubheading Example
17789
17790@smallexample
17791(@value{GDBP})
17792-target-select async /dev/ttya
17793^connected,addr="0xfe00a300",func="??",args=[]
17794(@value{GDBP})
17795@end smallexample
17796
17797@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17798@node GDB/MI Thread Commands
17799@section @sc{gdb/mi} Thread Commands
17800
17801
17802@subheading The @code{-thread-info} Command
17803@findex -thread-info
17804
17805@subsubheading Synopsis
17806
17807@smallexample
17808 -thread-info
17809@end smallexample
17810
17811@subsubheading @value{GDBN} command
17812
17813No equivalent.
17814
17815@subsubheading Example
17816N.A.
17817
17818
17819@subheading The @code{-thread-list-all-threads} Command
17820@findex -thread-list-all-threads
17821
17822@subsubheading Synopsis
17823
17824@smallexample
17825 -thread-list-all-threads
17826@end smallexample
17827
17828@subsubheading @value{GDBN} Command
17829
17830The equivalent @value{GDBN} command is @samp{info threads}.
17831
17832@subsubheading Example
17833N.A.
17834
17835
17836@subheading The @code{-thread-list-ids} Command
17837@findex -thread-list-ids
17838
17839@subsubheading Synopsis
17840
17841@smallexample
17842 -thread-list-ids
17843@end smallexample
17844
17845Produces a list of the currently known @value{GDBN} thread ids. At the
17846end of the list it also prints the total number of such threads.
17847
17848@subsubheading @value{GDBN} Command
17849
17850Part of @samp{info threads} supplies the same information.
17851
17852@subsubheading Example
17853
17854No threads present, besides the main process:
17855
17856@smallexample
17857(@value{GDBP})
17858-thread-list-ids
17859^done,thread-ids=@{@},number-of-threads="0"
17860(@value{GDBP})
17861@end smallexample
17862
17863
17864Several threads:
17865
17866@smallexample
17867(@value{GDBP})
17868-thread-list-ids
17869^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17870number-of-threads="3"
17871(@value{GDBP})
17872@end smallexample
17873
17874
17875@subheading The @code{-thread-select} Command
17876@findex -thread-select
17877
17878@subsubheading Synopsis
17879
17880@smallexample
17881 -thread-select @var{threadnum}
17882@end smallexample
17883
17884Make @var{threadnum} the current thread. It prints the number of the new
17885current thread, and the topmost frame for that thread.
17886
17887@subsubheading @value{GDBN} Command
17888
17889The corresponding @value{GDBN} command is @samp{thread}.
17890
17891@subsubheading Example
17892
17893@smallexample
17894(@value{GDBP})
17895-exec-next
17896^running
17897(@value{GDBP})
17898*stopped,reason="end-stepping-range",thread-id="2",line="187",
17899file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
17900(@value{GDBP})
17901-thread-list-ids
17902^done,
17903thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
17904number-of-threads="3"
17905(@value{GDBP})
17906-thread-select 3
17907^done,new-thread-id="3",
17908frame=@{level="0",func="vprintf",
17909args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
17910@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
17911(@value{GDBP})
17912@end smallexample
17913
17914@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17915@node GDB/MI Tracepoint Commands
17916@section @sc{gdb/mi} Tracepoint Commands
17917
17918The tracepoint commands are not yet implemented.
17919
17920@c @subheading -trace-actions
17921
17922@c @subheading -trace-delete
17923
17924@c @subheading -trace-disable
17925
17926@c @subheading -trace-dump
17927
17928@c @subheading -trace-enable
17929
17930@c @subheading -trace-exists
17931
17932@c @subheading -trace-find
17933
17934@c @subheading -trace-frame-number
17935
17936@c @subheading -trace-info
17937
17938@c @subheading -trace-insert
17939
17940@c @subheading -trace-list
17941
17942@c @subheading -trace-pass-count
17943
17944@c @subheading -trace-save
17945
17946@c @subheading -trace-start
17947
17948@c @subheading -trace-stop
17949
17950
17951@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17952@node GDB/MI Variable Objects
17953@section @sc{gdb/mi} Variable Objects
17954
17955
17956@subheading Motivation for Variable Objects in @sc{gdb/mi}
17957
17958For the implementation of a variable debugger window (locals, watched
17959expressions, etc.), we are proposing the adaptation of the existing code
17960used by @code{Insight}.
17961
17962The two main reasons for that are:
17963
17964@enumerate 1
17965@item
17966It has been proven in practice (it is already on its second generation).
17967
17968@item
17969It will shorten development time (needless to say how important it is
17970now).
17971@end enumerate
17972
17973The original interface was designed to be used by Tcl code, so it was
17974slightly changed so it could be used through @sc{gdb/mi}. This section
17975describes the @sc{gdb/mi} operations that will be available and gives some
17976hints about their use.
17977
17978@emph{Note}: In addition to the set of operations described here, we
17979expect the @sc{gui} implementation of a variable window to require, at
17980least, the following operations:
17981
17982@itemize @bullet
17983@item @code{-gdb-show} @code{output-radix}
17984@item @code{-stack-list-arguments}
17985@item @code{-stack-list-locals}
17986@item @code{-stack-select-frame}
17987@end itemize
17988
17989@subheading Introduction to Variable Objects in @sc{gdb/mi}
17990
17991@cindex variable objects in @sc{gdb/mi}
17992The basic idea behind variable objects is the creation of a named object
17993to represent a variable, an expression, a memory location or even a CPU
17994register. For each object created, a set of operations is available for
17995examining or changing its properties.
17996
17997Furthermore, complex data types, such as C structures, are represented
17998in a tree format. For instance, the @code{struct} type variable is the
17999root and the children will represent the struct members. If a child
18000is itself of a complex type, it will also have children of its own.
18001Appropriate language differences are handled for C, C@t{++} and Java.
18002
18003When returning the actual values of the objects, this facility allows
18004for the individual selection of the display format used in the result
18005creation. It can be chosen among: binary, decimal, hexadecimal, octal
18006and natural. Natural refers to a default format automatically
18007chosen based on the variable type (like decimal for an @code{int}, hex
18008for pointers, etc.).
18009
18010The following is the complete set of @sc{gdb/mi} operations defined to
18011access this functionality:
18012
18013@multitable @columnfractions .4 .6
18014@item @strong{Operation}
18015@tab @strong{Description}
18016
18017@item @code{-var-create}
18018@tab create a variable object
18019@item @code{-var-delete}
18020@tab delete the variable object and its children
18021@item @code{-var-set-format}
18022@tab set the display format of this variable
18023@item @code{-var-show-format}
18024@tab show the display format of this variable
18025@item @code{-var-info-num-children}
18026@tab tells how many children this object has
18027@item @code{-var-list-children}
18028@tab return a list of the object's children
18029@item @code{-var-info-type}
18030@tab show the type of this variable object
18031@item @code{-var-info-expression}
18032@tab print what this variable object represents
18033@item @code{-var-show-attributes}
18034@tab is this variable editable? does it exist here?
18035@item @code{-var-evaluate-expression}
18036@tab get the value of this variable
18037@item @code{-var-assign}
18038@tab set the value of this variable
18039@item @code{-var-update}
18040@tab update the variable and its children
18041@end multitable
18042
18043In the next subsection we describe each operation in detail and suggest
18044how it can be used.
18045
18046@subheading Description And Use of Operations on Variable Objects
18047
18048@subheading The @code{-var-create} Command
18049@findex -var-create
18050
18051@subsubheading Synopsis
18052
18053@smallexample
18054 -var-create @{@var{name} | "-"@}
18055 @{@var{frame-addr} | "*"@} @var{expression}
18056@end smallexample
18057
18058This operation creates a variable object, which allows the monitoring of
18059a variable, the result of an expression, a memory cell or a CPU
18060register.
18061
18062The @var{name} parameter is the string by which the object can be
18063referenced. It must be unique. If @samp{-} is specified, the varobj
18064system will generate a string ``varNNNNNN'' automatically. It will be
18065unique provided that one does not specify @var{name} on that format.
18066The command fails if a duplicate name is found.
18067
18068The frame under which the expression should be evaluated can be
18069specified by @var{frame-addr}. A @samp{*} indicates that the current
18070frame should be used.
18071
18072@var{expression} is any expression valid on the current language set (must not
18073begin with a @samp{*}), or one of the following:
18074
18075@itemize @bullet
18076@item
18077@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
18078
18079@item
18080@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
18081
18082@item
18083@samp{$@var{regname}} --- a CPU register name
18084@end itemize
18085
18086@subsubheading Result
18087
18088This operation returns the name, number of children and the type of the
18089object created. Type is returned as a string as the ones generated by
18090the @value{GDBN} CLI:
18091
18092@smallexample
18093 name="@var{name}",numchild="N",type="@var{type}"
18094@end smallexample
18095
18096
18097@subheading The @code{-var-delete} Command
18098@findex -var-delete
18099
18100@subsubheading Synopsis
18101
18102@smallexample
18103 -var-delete @var{name}
18104@end smallexample
18105
18106Deletes a previously created variable object and all of its children.
18107
18108Returns an error if the object @var{name} is not found.
18109
18110
18111@subheading The @code{-var-set-format} Command
18112@findex -var-set-format
18113
18114@subsubheading Synopsis
18115
18116@smallexample
18117 -var-set-format @var{name} @var{format-spec}
18118@end smallexample
18119
18120Sets the output format for the value of the object @var{name} to be
18121@var{format-spec}.
18122
18123The syntax for the @var{format-spec} is as follows:
18124
18125@smallexample
18126 @var{format-spec} @expansion{}
18127 @{binary | decimal | hexadecimal | octal | natural@}
18128@end smallexample
18129
18130
18131@subheading The @code{-var-show-format} Command
18132@findex -var-show-format
18133
18134@subsubheading Synopsis
18135
18136@smallexample
18137 -var-show-format @var{name}
18138@end smallexample
18139
18140Returns the format used to display the value of the object @var{name}.
18141
18142@smallexample
18143 @var{format} @expansion{}
18144 @var{format-spec}
18145@end smallexample
18146
18147
18148@subheading The @code{-var-info-num-children} Command
18149@findex -var-info-num-children
18150
18151@subsubheading Synopsis
18152
18153@smallexample
18154 -var-info-num-children @var{name}
18155@end smallexample
18156
18157Returns the number of children of a variable object @var{name}:
18158
18159@smallexample
18160 numchild=@var{n}
18161@end smallexample
18162
18163
18164@subheading The @code{-var-list-children} Command
18165@findex -var-list-children
18166
18167@subsubheading Synopsis
18168
18169@smallexample
18170 -var-list-children @var{name}
18171@end smallexample
18172
18173Returns a list of the children of the specified variable object:
18174
18175@smallexample
18176 numchild=@var{n},children=[@{name=@var{name},
18177 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
18178@end smallexample
18179
18180
18181@subheading The @code{-var-info-type} Command
18182@findex -var-info-type
18183
18184@subsubheading Synopsis
18185
18186@smallexample
18187 -var-info-type @var{name}
18188@end smallexample
18189
18190Returns the type of the specified variable @var{name}. The type is
18191returned as a string in the same format as it is output by the
18192@value{GDBN} CLI:
18193
18194@smallexample
18195 type=@var{typename}
18196@end smallexample
18197
18198
18199@subheading The @code{-var-info-expression} Command
18200@findex -var-info-expression
18201
18202@subsubheading Synopsis
18203
18204@smallexample
18205 -var-info-expression @var{name}
18206@end smallexample
18207
18208Returns what is represented by the variable object @var{name}:
18209
18210@smallexample
18211 lang=@var{lang-spec},exp=@var{expression}
18212@end smallexample
18213
18214@noindent
18215where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
18216
18217@subheading The @code{-var-show-attributes} Command
18218@findex -var-show-attributes
18219
18220@subsubheading Synopsis
18221
18222@smallexample
18223 -var-show-attributes @var{name}
18224@end smallexample
18225
18226List attributes of the specified variable object @var{name}:
18227
18228@smallexample
18229 status=@var{attr} [ ( ,@var{attr} )* ]
18230@end smallexample
18231
18232@noindent
18233where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
18234
18235@subheading The @code{-var-evaluate-expression} Command
18236@findex -var-evaluate-expression
18237
18238@subsubheading Synopsis
18239
18240@smallexample
18241 -var-evaluate-expression @var{name}
18242@end smallexample
18243
18244Evaluates the expression that is represented by the specified variable
18245object and returns its value as a string in the current format specified
18246for the object:
18247
18248@smallexample
18249 value=@var{value}
18250@end smallexample
18251
18252Note that one must invoke @code{-var-list-children} for a variable
18253before the value of a child variable can be evaluated.
18254
18255@subheading The @code{-var-assign} Command
18256@findex -var-assign
18257
18258@subsubheading Synopsis
18259
18260@smallexample
18261 -var-assign @var{name} @var{expression}
18262@end smallexample
18263
18264Assigns the value of @var{expression} to the variable object specified
18265by @var{name}. The object must be @samp{editable}. If the variable's
18266value is altered by the assign, the variable will show up in any
18267subsequent @code{-var-update} list.
18268
18269@subsubheading Example
18270
18271@smallexample
18272(@value{GDBP})
18273-var-assign var1 3
18274^done,value="3"
18275(@value{GDBP})
18276-var-update *
18277^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
18278(@value{GDBP})
18279@end smallexample
18280
18281@subheading The @code{-var-update} Command
18282@findex -var-update
18283
18284@subsubheading Synopsis
18285
18286@smallexample
18287 -var-update @{@var{name} | "*"@}
18288@end smallexample
18289
18290Update the value of the variable object @var{name} by evaluating its
18291expression after fetching all the new values from memory or registers.
18292A @samp{*} causes all existing variable objects to be updated.
18293
18294
18295@node Annotations
18296@chapter @value{GDBN} Annotations
18297
086432e2
AC
18298This chapter describes annotations in @value{GDBN}. Annotations were
18299designed to interface @value{GDBN} to graphical user interfaces or other
18300similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
18301relatively high level.
18302
086432e2
AC
18303The annotation mechanism has largely been superseeded by @sc{gdb/mi}
18304(@pxref{GDB/MI}).
18305
922fbb7b
AC
18306@ignore
18307This is Edition @value{EDITION}, @value{DATE}.
18308@end ignore
18309
18310@menu
18311* Annotations Overview:: What annotations are; the general syntax.
18312* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
18313* Prompting:: Annotations marking @value{GDBN}'s need for input.
18314* Errors:: Annotations for error messages.
922fbb7b
AC
18315* Invalidation:: Some annotations describe things now invalid.
18316* Annotations for Running::
18317 Whether the program is running, how it stopped, etc.
18318* Source Annotations:: Annotations describing source code.
922fbb7b
AC
18319@end menu
18320
18321@node Annotations Overview
18322@section What is an Annotation?
18323@cindex annotations
18324
922fbb7b
AC
18325Annotations start with a newline character, two @samp{control-z}
18326characters, and the name of the annotation. If there is no additional
18327information associated with this annotation, the name of the annotation
18328is followed immediately by a newline. If there is additional
18329information, the name of the annotation is followed by a space, the
18330additional information, and a newline. The additional information
18331cannot contain newline characters.
18332
18333Any output not beginning with a newline and two @samp{control-z}
18334characters denotes literal output from @value{GDBN}. Currently there is
18335no need for @value{GDBN} to output a newline followed by two
18336@samp{control-z} characters, but if there was such a need, the
18337annotations could be extended with an @samp{escape} annotation which
18338means those three characters as output.
18339
086432e2
AC
18340The annotation @var{level}, which is specified using the
18341@option{--annotate} command line option (@pxref{Mode Options}), controls
18342how much information @value{GDBN} prints together with its prompt,
18343values of expressions, source lines, and other types of output. Level 0
18344is for no anntations, level 1 is for use when @value{GDBN} is run as a
18345subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
18346for programs that control @value{GDBN}, and level 2 annotations have
18347been made obsolete (@pxref{Limitations, , Limitations of the Annotation
18348Interface, annotate, GDB's Obsolete Annotations}). This chapter
18349describes level 3 annotations.
18350
922fbb7b
AC
18351A simple example of starting up @value{GDBN} with annotations is:
18352
18353@smallexample
086432e2
AC
18354$ @kbd{gdb --annotate=3}
18355GNU gdb 6.0
18356Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
18357GDB is free software, covered by the GNU General Public License,
18358and you are welcome to change it and/or distribute copies of it
18359under certain conditions.
18360Type "show copying" to see the conditions.
18361There is absolutely no warranty for GDB. Type "show warranty"
18362for details.
086432e2 18363This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
18364
18365^Z^Zpre-prompt
18366(gdb)
18367^Z^Zprompt
086432e2 18368@kbd{quit}
922fbb7b
AC
18369
18370^Z^Zpost-prompt
18371$
18372@end smallexample
18373
18374Here @samp{quit} is input to @value{GDBN}; the rest is output from
18375@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
18376denotes a @samp{control-z} character) are annotations; the rest is
18377output from @value{GDBN}.
18378
18379@node Server Prefix
18380@section The Server Prefix
18381@cindex server prefix for annotations
18382
18383To issue a command to @value{GDBN} without affecting certain aspects of
18384the state which is seen by users, prefix it with @samp{server }. This
18385means that this command will not affect the command history, nor will it
18386affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18387pressed on a line by itself.
18388
18389The server prefix does not affect the recording of values into the value
18390history; to print a value without recording it into the value history,
18391use the @code{output} command instead of the @code{print} command.
18392
922fbb7b
AC
18393@node Prompting
18394@section Annotation for @value{GDBN} Input
18395
18396@cindex annotations for prompts
18397When @value{GDBN} prompts for input, it annotates this fact so it is possible
18398to know when to send output, when the output from a given command is
18399over, etc.
18400
18401Different kinds of input each have a different @dfn{input type}. Each
18402input type has three annotations: a @code{pre-} annotation, which
18403denotes the beginning of any prompt which is being output, a plain
18404annotation, which denotes the end of the prompt, and then a @code{post-}
18405annotation which denotes the end of any echo which may (or may not) be
18406associated with the input. For example, the @code{prompt} input type
18407features the following annotations:
18408
18409@smallexample
18410^Z^Zpre-prompt
18411^Z^Zprompt
18412^Z^Zpost-prompt
18413@end smallexample
18414
18415The input types are
18416
18417@table @code
18418@findex pre-prompt
18419@findex prompt
18420@findex post-prompt
18421@item prompt
18422When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
18423
18424@findex pre-commands
18425@findex commands
18426@findex post-commands
18427@item commands
18428When @value{GDBN} prompts for a set of commands, like in the @code{commands}
18429command. The annotations are repeated for each command which is input.
18430
18431@findex pre-overload-choice
18432@findex overload-choice
18433@findex post-overload-choice
18434@item overload-choice
18435When @value{GDBN} wants the user to select between various overloaded functions.
18436
18437@findex pre-query
18438@findex query
18439@findex post-query
18440@item query
18441When @value{GDBN} wants the user to confirm a potentially dangerous operation.
18442
18443@findex pre-prompt-for-continue
18444@findex prompt-for-continue
18445@findex post-prompt-for-continue
18446@item prompt-for-continue
18447When @value{GDBN} is asking the user to press return to continue. Note: Don't
18448expect this to work well; instead use @code{set height 0} to disable
18449prompting. This is because the counting of lines is buggy in the
18450presence of annotations.
18451@end table
18452
18453@node Errors
18454@section Errors
18455@cindex annotations for errors, warnings and interrupts
18456
18457@findex quit
18458@smallexample
18459^Z^Zquit
18460@end smallexample
18461
18462This annotation occurs right before @value{GDBN} responds to an interrupt.
18463
18464@findex error
18465@smallexample
18466^Z^Zerror
18467@end smallexample
18468
18469This annotation occurs right before @value{GDBN} responds to an error.
18470
18471Quit and error annotations indicate that any annotations which @value{GDBN} was
18472in the middle of may end abruptly. For example, if a
18473@code{value-history-begin} annotation is followed by a @code{error}, one
18474cannot expect to receive the matching @code{value-history-end}. One
18475cannot expect not to receive it either, however; an error annotation
18476does not necessarily mean that @value{GDBN} is immediately returning all the way
18477to the top level.
18478
18479@findex error-begin
18480A quit or error annotation may be preceded by
18481
18482@smallexample
18483^Z^Zerror-begin
18484@end smallexample
18485
18486Any output between that and the quit or error annotation is the error
18487message.
18488
18489Warning messages are not yet annotated.
18490@c If we want to change that, need to fix warning(), type_error(),
18491@c range_error(), and possibly other places.
18492
922fbb7b
AC
18493@node Invalidation
18494@section Invalidation Notices
18495
18496@cindex annotations for invalidation messages
18497The following annotations say that certain pieces of state may have
18498changed.
18499
18500@table @code
18501@findex frames-invalid
18502@item ^Z^Zframes-invalid
18503
18504The frames (for example, output from the @code{backtrace} command) may
18505have changed.
18506
18507@findex breakpoints-invalid
18508@item ^Z^Zbreakpoints-invalid
18509
18510The breakpoints may have changed. For example, the user just added or
18511deleted a breakpoint.
18512@end table
18513
18514@node Annotations for Running
18515@section Running the Program
18516@cindex annotations for running programs
18517
18518@findex starting
18519@findex stopping
18520When the program starts executing due to a @value{GDBN} command such as
18521@code{step} or @code{continue},
18522
18523@smallexample
18524^Z^Zstarting
18525@end smallexample
18526
18527is output. When the program stops,
18528
18529@smallexample
18530^Z^Zstopped
18531@end smallexample
18532
18533is output. Before the @code{stopped} annotation, a variety of
18534annotations describe how the program stopped.
18535
18536@table @code
18537@findex exited
18538@item ^Z^Zexited @var{exit-status}
18539The program exited, and @var{exit-status} is the exit status (zero for
18540successful exit, otherwise nonzero).
18541
18542@findex signalled
18543@findex signal-name
18544@findex signal-name-end
18545@findex signal-string
18546@findex signal-string-end
18547@item ^Z^Zsignalled
18548The program exited with a signal. After the @code{^Z^Zsignalled}, the
18549annotation continues:
18550
18551@smallexample
18552@var{intro-text}
18553^Z^Zsignal-name
18554@var{name}
18555^Z^Zsignal-name-end
18556@var{middle-text}
18557^Z^Zsignal-string
18558@var{string}
18559^Z^Zsignal-string-end
18560@var{end-text}
18561@end smallexample
18562
18563@noindent
18564where @var{name} is the name of the signal, such as @code{SIGILL} or
18565@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
18566as @code{Illegal Instruction} or @code{Segmentation fault}.
18567@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
18568user's benefit and have no particular format.
18569
18570@findex signal
18571@item ^Z^Zsignal
18572The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
18573just saying that the program received the signal, not that it was
18574terminated with it.
18575
18576@findex breakpoint
18577@item ^Z^Zbreakpoint @var{number}
18578The program hit breakpoint number @var{number}.
18579
18580@findex watchpoint
18581@item ^Z^Zwatchpoint @var{number}
18582The program hit watchpoint number @var{number}.
18583@end table
18584
18585@node Source Annotations
18586@section Displaying Source
18587@cindex annotations for source display
18588
18589@findex source
18590The following annotation is used instead of displaying source code:
18591
18592@smallexample
18593^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
18594@end smallexample
18595
18596where @var{filename} is an absolute file name indicating which source
18597file, @var{line} is the line number within that file (where 1 is the
18598first line in the file), @var{character} is the character position
18599within the file (where 0 is the first character in the file) (for most
18600debug formats this will necessarily point to the beginning of a line),
18601@var{middle} is @samp{middle} if @var{addr} is in the middle of the
18602line, or @samp{beg} if @var{addr} is at the beginning of the line, and
18603@var{addr} is the address in the target program associated with the
18604source which is being displayed. @var{addr} is in the form @samp{0x}
18605followed by one or more lowercase hex digits (note that this does not
18606depend on the language).
18607
8e04817f
AC
18608@node GDB Bugs
18609@chapter Reporting Bugs in @value{GDBN}
18610@cindex bugs in @value{GDBN}
18611@cindex reporting bugs in @value{GDBN}
c906108c 18612
8e04817f 18613Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 18614
8e04817f
AC
18615Reporting a bug may help you by bringing a solution to your problem, or it
18616may not. But in any case the principal function of a bug report is to help
18617the entire community by making the next version of @value{GDBN} work better. Bug
18618reports are your contribution to the maintenance of @value{GDBN}.
c906108c 18619
8e04817f
AC
18620In order for a bug report to serve its purpose, you must include the
18621information that enables us to fix the bug.
c4555f82
SC
18622
18623@menu
8e04817f
AC
18624* Bug Criteria:: Have you found a bug?
18625* Bug Reporting:: How to report bugs
c4555f82
SC
18626@end menu
18627
8e04817f
AC
18628@node Bug Criteria
18629@section Have you found a bug?
18630@cindex bug criteria
c4555f82 18631
8e04817f 18632If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
18633
18634@itemize @bullet
8e04817f
AC
18635@cindex fatal signal
18636@cindex debugger crash
18637@cindex crash of debugger
c4555f82 18638@item
8e04817f
AC
18639If the debugger gets a fatal signal, for any input whatever, that is a
18640@value{GDBN} bug. Reliable debuggers never crash.
18641
18642@cindex error on valid input
18643@item
18644If @value{GDBN} produces an error message for valid input, that is a
18645bug. (Note that if you're cross debugging, the problem may also be
18646somewhere in the connection to the target.)
c4555f82 18647
8e04817f 18648@cindex invalid input
c4555f82 18649@item
8e04817f
AC
18650If @value{GDBN} does not produce an error message for invalid input,
18651that is a bug. However, you should note that your idea of
18652``invalid input'' might be our idea of ``an extension'' or ``support
18653for traditional practice''.
18654
18655@item
18656If you are an experienced user of debugging tools, your suggestions
18657for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
18658@end itemize
18659
8e04817f
AC
18660@node Bug Reporting
18661@section How to report bugs
18662@cindex bug reports
18663@cindex @value{GDBN} bugs, reporting
18664
18665A number of companies and individuals offer support for @sc{gnu} products.
18666If you obtained @value{GDBN} from a support organization, we recommend you
18667contact that organization first.
18668
18669You can find contact information for many support companies and
18670individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
18671distribution.
18672@c should add a web page ref...
18673
129188f6
AC
18674In any event, we also recommend that you submit bug reports for
18675@value{GDBN}. The prefered method is to submit them directly using
18676@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
18677page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
18678be used.
8e04817f
AC
18679
18680@strong{Do not send bug reports to @samp{info-gdb}, or to
18681@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
18682not want to receive bug reports. Those that do have arranged to receive
18683@samp{bug-gdb}.
18684
18685The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
18686serves as a repeater. The mailing list and the newsgroup carry exactly
18687the same messages. Often people think of posting bug reports to the
18688newsgroup instead of mailing them. This appears to work, but it has one
18689problem which can be crucial: a newsgroup posting often lacks a mail
18690path back to the sender. Thus, if we need to ask for more information,
18691we may be unable to reach you. For this reason, it is better to send
18692bug reports to the mailing list.
c4555f82 18693
8e04817f
AC
18694The fundamental principle of reporting bugs usefully is this:
18695@strong{report all the facts}. If you are not sure whether to state a
18696fact or leave it out, state it!
c4555f82 18697
8e04817f
AC
18698Often people omit facts because they think they know what causes the
18699problem and assume that some details do not matter. Thus, you might
18700assume that the name of the variable you use in an example does not matter.
18701Well, probably it does not, but one cannot be sure. Perhaps the bug is a
18702stray memory reference which happens to fetch from the location where that
18703name is stored in memory; perhaps, if the name were different, the contents
18704of that location would fool the debugger into doing the right thing despite
18705the bug. Play it safe and give a specific, complete example. That is the
18706easiest thing for you to do, and the most helpful.
c4555f82 18707
8e04817f
AC
18708Keep in mind that the purpose of a bug report is to enable us to fix the
18709bug. It may be that the bug has been reported previously, but neither
18710you nor we can know that unless your bug report is complete and
18711self-contained.
c4555f82 18712
8e04817f
AC
18713Sometimes people give a few sketchy facts and ask, ``Does this ring a
18714bell?'' Those bug reports are useless, and we urge everyone to
18715@emph{refuse to respond to them} except to chide the sender to report
18716bugs properly.
18717
18718To enable us to fix the bug, you should include all these things:
c4555f82
SC
18719
18720@itemize @bullet
18721@item
8e04817f
AC
18722The version of @value{GDBN}. @value{GDBN} announces it if you start
18723with no arguments; you can also print it at any time using @code{show
18724version}.
c4555f82 18725
8e04817f
AC
18726Without this, we will not know whether there is any point in looking for
18727the bug in the current version of @value{GDBN}.
c4555f82
SC
18728
18729@item
8e04817f
AC
18730The type of machine you are using, and the operating system name and
18731version number.
c4555f82
SC
18732
18733@item
8e04817f
AC
18734What compiler (and its version) was used to compile @value{GDBN}---e.g.
18735``@value{GCC}--2.8.1''.
c4555f82
SC
18736
18737@item
8e04817f
AC
18738What compiler (and its version) was used to compile the program you are
18739debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
18740C Compiler''. For GCC, you can say @code{gcc --version} to get this
18741information; for other compilers, see the documentation for those
18742compilers.
c4555f82 18743
8e04817f
AC
18744@item
18745The command arguments you gave the compiler to compile your example and
18746observe the bug. For example, did you use @samp{-O}? To guarantee
18747you will not omit something important, list them all. A copy of the
18748Makefile (or the output from make) is sufficient.
c4555f82 18749
8e04817f
AC
18750If we were to try to guess the arguments, we would probably guess wrong
18751and then we might not encounter the bug.
c4555f82 18752
8e04817f
AC
18753@item
18754A complete input script, and all necessary source files, that will
18755reproduce the bug.
c4555f82 18756
8e04817f
AC
18757@item
18758A description of what behavior you observe that you believe is
18759incorrect. For example, ``It gets a fatal signal.''
c4555f82 18760
8e04817f
AC
18761Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
18762will certainly notice it. But if the bug is incorrect output, we might
18763not notice unless it is glaringly wrong. You might as well not give us
18764a chance to make a mistake.
c4555f82 18765
8e04817f
AC
18766Even if the problem you experience is a fatal signal, you should still
18767say so explicitly. Suppose something strange is going on, such as, your
18768copy of @value{GDBN} is out of synch, or you have encountered a bug in
18769the C library on your system. (This has happened!) Your copy might
18770crash and ours would not. If you told us to expect a crash, then when
18771ours fails to crash, we would know that the bug was not happening for
18772us. If you had not told us to expect a crash, then we would not be able
18773to draw any conclusion from our observations.
c4555f82 18774
8e04817f
AC
18775@item
18776If you wish to suggest changes to the @value{GDBN} source, send us context
18777diffs. If you even discuss something in the @value{GDBN} source, refer to
18778it by context, not by line number.
c4555f82 18779
8e04817f
AC
18780The line numbers in our development sources will not match those in your
18781sources. Your line numbers would convey no useful information to us.
c4555f82 18782
8e04817f 18783@end itemize
c4555f82 18784
8e04817f 18785Here are some things that are not necessary:
c4555f82 18786
8e04817f
AC
18787@itemize @bullet
18788@item
18789A description of the envelope of the bug.
c4555f82 18790
8e04817f
AC
18791Often people who encounter a bug spend a lot of time investigating
18792which changes to the input file will make the bug go away and which
18793changes will not affect it.
c4555f82 18794
8e04817f
AC
18795This is often time consuming and not very useful, because the way we
18796will find the bug is by running a single example under the debugger
18797with breakpoints, not by pure deduction from a series of examples.
18798We recommend that you save your time for something else.
c4555f82 18799
8e04817f
AC
18800Of course, if you can find a simpler example to report @emph{instead}
18801of the original one, that is a convenience for us. Errors in the
18802output will be easier to spot, running under the debugger will take
18803less time, and so on.
c4555f82 18804
8e04817f
AC
18805However, simplification is not vital; if you do not want to do this,
18806report the bug anyway and send us the entire test case you used.
c4555f82 18807
8e04817f
AC
18808@item
18809A patch for the bug.
c4555f82 18810
8e04817f
AC
18811A patch for the bug does help us if it is a good one. But do not omit
18812the necessary information, such as the test case, on the assumption that
18813a patch is all we need. We might see problems with your patch and decide
18814to fix the problem another way, or we might not understand it at all.
c4555f82 18815
8e04817f
AC
18816Sometimes with a program as complicated as @value{GDBN} it is very hard to
18817construct an example that will make the program follow a certain path
18818through the code. If you do not send us the example, we will not be able
18819to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 18820
8e04817f
AC
18821And if we cannot understand what bug you are trying to fix, or why your
18822patch should be an improvement, we will not install it. A test case will
18823help us to understand.
c4555f82 18824
8e04817f
AC
18825@item
18826A guess about what the bug is or what it depends on.
c4555f82 18827
8e04817f
AC
18828Such guesses are usually wrong. Even we cannot guess right about such
18829things without first using the debugger to find the facts.
18830@end itemize
c4555f82 18831
8e04817f
AC
18832@c The readline documentation is distributed with the readline code
18833@c and consists of the two following files:
18834@c rluser.texinfo
18835@c inc-hist.texinfo
18836@c Use -I with makeinfo to point to the appropriate directory,
18837@c environment var TEXINPUTS with TeX.
18838@include rluser.texinfo
18839@include inc-hist.texinfo
c4555f82 18840
c4555f82 18841
8e04817f
AC
18842@node Formatting Documentation
18843@appendix Formatting Documentation
c4555f82 18844
8e04817f
AC
18845@cindex @value{GDBN} reference card
18846@cindex reference card
18847The @value{GDBN} 4 release includes an already-formatted reference card, ready
18848for printing with PostScript or Ghostscript, in the @file{gdb}
18849subdirectory of the main source directory@footnote{In
18850@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
18851release.}. If you can use PostScript or Ghostscript with your printer,
18852you can print the reference card immediately with @file{refcard.ps}.
c4555f82 18853
8e04817f
AC
18854The release also includes the source for the reference card. You
18855can format it, using @TeX{}, by typing:
c4555f82 18856
474c8240 18857@smallexample
8e04817f 18858make refcard.dvi
474c8240 18859@end smallexample
c4555f82 18860
8e04817f
AC
18861The @value{GDBN} reference card is designed to print in @dfn{landscape}
18862mode on US ``letter'' size paper;
18863that is, on a sheet 11 inches wide by 8.5 inches
18864high. You will need to specify this form of printing as an option to
18865your @sc{dvi} output program.
c4555f82 18866
8e04817f 18867@cindex documentation
c4555f82 18868
8e04817f
AC
18869All the documentation for @value{GDBN} comes as part of the machine-readable
18870distribution. The documentation is written in Texinfo format, which is
18871a documentation system that uses a single source file to produce both
18872on-line information and a printed manual. You can use one of the Info
18873formatting commands to create the on-line version of the documentation
18874and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 18875
8e04817f
AC
18876@value{GDBN} includes an already formatted copy of the on-line Info
18877version of this manual in the @file{gdb} subdirectory. The main Info
18878file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
18879subordinate files matching @samp{gdb.info*} in the same directory. If
18880necessary, you can print out these files, or read them with any editor;
18881but they are easier to read using the @code{info} subsystem in @sc{gnu}
18882Emacs or the standalone @code{info} program, available as part of the
18883@sc{gnu} Texinfo distribution.
c4555f82 18884
8e04817f
AC
18885If you want to format these Info files yourself, you need one of the
18886Info formatting programs, such as @code{texinfo-format-buffer} or
18887@code{makeinfo}.
c4555f82 18888
8e04817f
AC
18889If you have @code{makeinfo} installed, and are in the top level
18890@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
18891version @value{GDBVN}), you can make the Info file by typing:
c4555f82 18892
474c8240 18893@smallexample
8e04817f
AC
18894cd gdb
18895make gdb.info
474c8240 18896@end smallexample
c4555f82 18897
8e04817f
AC
18898If you want to typeset and print copies of this manual, you need @TeX{},
18899a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
18900Texinfo definitions file.
c4555f82 18901
8e04817f
AC
18902@TeX{} is a typesetting program; it does not print files directly, but
18903produces output files called @sc{dvi} files. To print a typeset
18904document, you need a program to print @sc{dvi} files. If your system
18905has @TeX{} installed, chances are it has such a program. The precise
18906command to use depends on your system; @kbd{lpr -d} is common; another
18907(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
18908require a file name without any extension or a @samp{.dvi} extension.
c4555f82 18909
8e04817f
AC
18910@TeX{} also requires a macro definitions file called
18911@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
18912written in Texinfo format. On its own, @TeX{} cannot either read or
18913typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
18914and is located in the @file{gdb-@var{version-number}/texinfo}
18915directory.
c4555f82 18916
8e04817f
AC
18917If you have @TeX{} and a @sc{dvi} printer program installed, you can
18918typeset and print this manual. First switch to the the @file{gdb}
18919subdirectory of the main source directory (for example, to
18920@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 18921
474c8240 18922@smallexample
8e04817f 18923make gdb.dvi
474c8240 18924@end smallexample
c4555f82 18925
8e04817f 18926Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 18927
8e04817f
AC
18928@node Installing GDB
18929@appendix Installing @value{GDBN}
18930@cindex configuring @value{GDBN}
18931@cindex installation
94e91d6d 18932@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 18933
8e04817f
AC
18934@value{GDBN} comes with a @code{configure} script that automates the process
18935of preparing @value{GDBN} for installation; you can then use @code{make} to
18936build the @code{gdb} program.
18937@iftex
18938@c irrelevant in info file; it's as current as the code it lives with.
18939@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
18940look at the @file{README} file in the sources; we may have improved the
18941installation procedures since publishing this manual.}
18942@end iftex
c4555f82 18943
8e04817f
AC
18944The @value{GDBN} distribution includes all the source code you need for
18945@value{GDBN} in a single directory, whose name is usually composed by
18946appending the version number to @samp{gdb}.
c4555f82 18947
8e04817f
AC
18948For example, the @value{GDBN} version @value{GDBVN} distribution is in the
18949@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 18950
8e04817f
AC
18951@table @code
18952@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
18953script for configuring @value{GDBN} and all its supporting libraries
c4555f82 18954
8e04817f
AC
18955@item gdb-@value{GDBVN}/gdb
18956the source specific to @value{GDBN} itself
c4555f82 18957
8e04817f
AC
18958@item gdb-@value{GDBVN}/bfd
18959source for the Binary File Descriptor library
c906108c 18960
8e04817f
AC
18961@item gdb-@value{GDBVN}/include
18962@sc{gnu} include files
c906108c 18963
8e04817f
AC
18964@item gdb-@value{GDBVN}/libiberty
18965source for the @samp{-liberty} free software library
c906108c 18966
8e04817f
AC
18967@item gdb-@value{GDBVN}/opcodes
18968source for the library of opcode tables and disassemblers
c906108c 18969
8e04817f
AC
18970@item gdb-@value{GDBVN}/readline
18971source for the @sc{gnu} command-line interface
c906108c 18972
8e04817f
AC
18973@item gdb-@value{GDBVN}/glob
18974source for the @sc{gnu} filename pattern-matching subroutine
c906108c 18975
8e04817f
AC
18976@item gdb-@value{GDBVN}/mmalloc
18977source for the @sc{gnu} memory-mapped malloc package
18978@end table
c906108c 18979
8e04817f
AC
18980The simplest way to configure and build @value{GDBN} is to run @code{configure}
18981from the @file{gdb-@var{version-number}} source directory, which in
18982this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 18983
8e04817f
AC
18984First switch to the @file{gdb-@var{version-number}} source directory
18985if you are not already in it; then run @code{configure}. Pass the
18986identifier for the platform on which @value{GDBN} will run as an
18987argument.
c906108c 18988
8e04817f 18989For example:
c906108c 18990
474c8240 18991@smallexample
8e04817f
AC
18992cd gdb-@value{GDBVN}
18993./configure @var{host}
18994make
474c8240 18995@end smallexample
c906108c 18996
8e04817f
AC
18997@noindent
18998where @var{host} is an identifier such as @samp{sun4} or
18999@samp{decstation}, that identifies the platform where @value{GDBN} will run.
19000(You can often leave off @var{host}; @code{configure} tries to guess the
19001correct value by examining your system.)
c906108c 19002
8e04817f
AC
19003Running @samp{configure @var{host}} and then running @code{make} builds the
19004@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
19005libraries, then @code{gdb} itself. The configured source files, and the
19006binaries, are left in the corresponding source directories.
c906108c 19007
8e04817f
AC
19008@need 750
19009@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
19010system does not recognize this automatically when you run a different
19011shell, you may need to run @code{sh} on it explicitly:
c906108c 19012
474c8240 19013@smallexample
8e04817f 19014sh configure @var{host}
474c8240 19015@end smallexample
c906108c 19016
8e04817f
AC
19017If you run @code{configure} from a directory that contains source
19018directories for multiple libraries or programs, such as the
19019@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
19020creates configuration files for every directory level underneath (unless
19021you tell it not to, with the @samp{--norecursion} option).
19022
94e91d6d
MC
19023You should run the @code{configure} script from the top directory in the
19024source tree, the @file{gdb-@var{version-number}} directory. If you run
19025@code{configure} from one of the subdirectories, you will configure only
19026that subdirectory. That is usually not what you want. In particular,
19027if you run the first @code{configure} from the @file{gdb} subdirectory
19028of the @file{gdb-@var{version-number}} directory, you will omit the
19029configuration of @file{bfd}, @file{readline}, and other sibling
19030directories of the @file{gdb} subdirectory. This leads to build errors
19031about missing include files such as @file{bfd/bfd.h}.
c906108c 19032
8e04817f
AC
19033You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
19034However, you should make sure that the shell on your path (named by
19035the @samp{SHELL} environment variable) is publicly readable. Remember
19036that @value{GDBN} uses the shell to start your program---some systems refuse to
19037let @value{GDBN} debug child processes whose programs are not readable.
c906108c 19038
8e04817f
AC
19039@menu
19040* Separate Objdir:: Compiling @value{GDBN} in another directory
19041* Config Names:: Specifying names for hosts and targets
19042* Configure Options:: Summary of options for configure
19043@end menu
c906108c 19044
8e04817f
AC
19045@node Separate Objdir
19046@section Compiling @value{GDBN} in another directory
c906108c 19047
8e04817f
AC
19048If you want to run @value{GDBN} versions for several host or target machines,
19049you need a different @code{gdb} compiled for each combination of
19050host and target. @code{configure} is designed to make this easy by
19051allowing you to generate each configuration in a separate subdirectory,
19052rather than in the source directory. If your @code{make} program
19053handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
19054@code{make} in each of these directories builds the @code{gdb}
19055program specified there.
c906108c 19056
8e04817f
AC
19057To build @code{gdb} in a separate directory, run @code{configure}
19058with the @samp{--srcdir} option to specify where to find the source.
19059(You also need to specify a path to find @code{configure}
19060itself from your working directory. If the path to @code{configure}
19061would be the same as the argument to @samp{--srcdir}, you can leave out
19062the @samp{--srcdir} option; it is assumed.)
c906108c 19063
8e04817f
AC
19064For example, with version @value{GDBVN}, you can build @value{GDBN} in a
19065separate directory for a Sun 4 like this:
c906108c 19066
474c8240 19067@smallexample
8e04817f
AC
19068@group
19069cd gdb-@value{GDBVN}
19070mkdir ../gdb-sun4
19071cd ../gdb-sun4
19072../gdb-@value{GDBVN}/configure sun4
19073make
19074@end group
474c8240 19075@end smallexample
c906108c 19076
8e04817f
AC
19077When @code{configure} builds a configuration using a remote source
19078directory, it creates a tree for the binaries with the same structure
19079(and using the same names) as the tree under the source directory. In
19080the example, you'd find the Sun 4 library @file{libiberty.a} in the
19081directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
19082@file{gdb-sun4/gdb}.
c906108c 19083
94e91d6d
MC
19084Make sure that your path to the @file{configure} script has just one
19085instance of @file{gdb} in it. If your path to @file{configure} looks
19086like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
19087one subdirectory of @value{GDBN}, not the whole package. This leads to
19088build errors about missing include files such as @file{bfd/bfd.h}.
19089
8e04817f
AC
19090One popular reason to build several @value{GDBN} configurations in separate
19091directories is to configure @value{GDBN} for cross-compiling (where
19092@value{GDBN} runs on one machine---the @dfn{host}---while debugging
19093programs that run on another machine---the @dfn{target}).
19094You specify a cross-debugging target by
19095giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 19096
8e04817f
AC
19097When you run @code{make} to build a program or library, you must run
19098it in a configured directory---whatever directory you were in when you
19099called @code{configure} (or one of its subdirectories).
c906108c 19100
8e04817f
AC
19101The @code{Makefile} that @code{configure} generates in each source
19102directory also runs recursively. If you type @code{make} in a source
19103directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
19104directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
19105will build all the required libraries, and then build GDB.
c906108c 19106
8e04817f
AC
19107When you have multiple hosts or targets configured in separate
19108directories, you can run @code{make} on them in parallel (for example,
19109if they are NFS-mounted on each of the hosts); they will not interfere
19110with each other.
c906108c 19111
8e04817f
AC
19112@node Config Names
19113@section Specifying names for hosts and targets
c906108c 19114
8e04817f
AC
19115The specifications used for hosts and targets in the @code{configure}
19116script are based on a three-part naming scheme, but some short predefined
19117aliases are also supported. The full naming scheme encodes three pieces
19118of information in the following pattern:
c906108c 19119
474c8240 19120@smallexample
8e04817f 19121@var{architecture}-@var{vendor}-@var{os}
474c8240 19122@end smallexample
c906108c 19123
8e04817f
AC
19124For example, you can use the alias @code{sun4} as a @var{host} argument,
19125or as the value for @var{target} in a @code{--target=@var{target}}
19126option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 19127
8e04817f
AC
19128The @code{configure} script accompanying @value{GDBN} does not provide
19129any query facility to list all supported host and target names or
19130aliases. @code{configure} calls the Bourne shell script
19131@code{config.sub} to map abbreviations to full names; you can read the
19132script, if you wish, or you can use it to test your guesses on
19133abbreviations---for example:
c906108c 19134
8e04817f
AC
19135@smallexample
19136% sh config.sub i386-linux
19137i386-pc-linux-gnu
19138% sh config.sub alpha-linux
19139alpha-unknown-linux-gnu
19140% sh config.sub hp9k700
19141hppa1.1-hp-hpux
19142% sh config.sub sun4
19143sparc-sun-sunos4.1.1
19144% sh config.sub sun3
19145m68k-sun-sunos4.1.1
19146% sh config.sub i986v
19147Invalid configuration `i986v': machine `i986v' not recognized
19148@end smallexample
c906108c 19149
8e04817f
AC
19150@noindent
19151@code{config.sub} is also distributed in the @value{GDBN} source
19152directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 19153
8e04817f
AC
19154@node Configure Options
19155@section @code{configure} options
c906108c 19156
8e04817f
AC
19157Here is a summary of the @code{configure} options and arguments that
19158are most often useful for building @value{GDBN}. @code{configure} also has
19159several other options not listed here. @inforef{What Configure
19160Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 19161
474c8240 19162@smallexample
8e04817f
AC
19163configure @r{[}--help@r{]}
19164 @r{[}--prefix=@var{dir}@r{]}
19165 @r{[}--exec-prefix=@var{dir}@r{]}
19166 @r{[}--srcdir=@var{dirname}@r{]}
19167 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
19168 @r{[}--target=@var{target}@r{]}
19169 @var{host}
474c8240 19170@end smallexample
c906108c 19171
8e04817f
AC
19172@noindent
19173You may introduce options with a single @samp{-} rather than
19174@samp{--} if you prefer; but you may abbreviate option names if you use
19175@samp{--}.
c906108c 19176
8e04817f
AC
19177@table @code
19178@item --help
19179Display a quick summary of how to invoke @code{configure}.
c906108c 19180
8e04817f
AC
19181@item --prefix=@var{dir}
19182Configure the source to install programs and files under directory
19183@file{@var{dir}}.
c906108c 19184
8e04817f
AC
19185@item --exec-prefix=@var{dir}
19186Configure the source to install programs under directory
19187@file{@var{dir}}.
c906108c 19188
8e04817f
AC
19189@c avoid splitting the warning from the explanation:
19190@need 2000
19191@item --srcdir=@var{dirname}
19192@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
19193@code{make} that implements the @code{VPATH} feature.}@*
19194Use this option to make configurations in directories separate from the
19195@value{GDBN} source directories. Among other things, you can use this to
19196build (or maintain) several configurations simultaneously, in separate
19197directories. @code{configure} writes configuration specific files in
19198the current directory, but arranges for them to use the source in the
19199directory @var{dirname}. @code{configure} creates directories under
19200the working directory in parallel to the source directories below
19201@var{dirname}.
c906108c 19202
8e04817f
AC
19203@item --norecursion
19204Configure only the directory level where @code{configure} is executed; do not
19205propagate configuration to subdirectories.
c906108c 19206
8e04817f
AC
19207@item --target=@var{target}
19208Configure @value{GDBN} for cross-debugging programs running on the specified
19209@var{target}. Without this option, @value{GDBN} is configured to debug
19210programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 19211
8e04817f 19212There is no convenient way to generate a list of all available targets.
c906108c 19213
8e04817f
AC
19214@item @var{host} @dots{}
19215Configure @value{GDBN} to run on the specified @var{host}.
c906108c 19216
8e04817f
AC
19217There is no convenient way to generate a list of all available hosts.
19218@end table
c906108c 19219
8e04817f
AC
19220There are many other options available as well, but they are generally
19221needed for special purposes only.
c906108c 19222
8e04817f
AC
19223@node Maintenance Commands
19224@appendix Maintenance Commands
19225@cindex maintenance commands
19226@cindex internal commands
c906108c 19227
8e04817f
AC
19228In addition to commands intended for @value{GDBN} users, @value{GDBN}
19229includes a number of commands intended for @value{GDBN} developers.
19230These commands are provided here for reference.
c906108c 19231
8e04817f
AC
19232@table @code
19233@kindex maint info breakpoints
19234@item @anchor{maint info breakpoints}maint info breakpoints
19235Using the same format as @samp{info breakpoints}, display both the
19236breakpoints you've set explicitly, and those @value{GDBN} is using for
19237internal purposes. Internal breakpoints are shown with negative
19238breakpoint numbers. The type column identifies what kind of breakpoint
19239is shown:
c906108c 19240
8e04817f
AC
19241@table @code
19242@item breakpoint
19243Normal, explicitly set breakpoint.
c906108c 19244
8e04817f
AC
19245@item watchpoint
19246Normal, explicitly set watchpoint.
c906108c 19247
8e04817f
AC
19248@item longjmp
19249Internal breakpoint, used to handle correctly stepping through
19250@code{longjmp} calls.
c906108c 19251
8e04817f
AC
19252@item longjmp resume
19253Internal breakpoint at the target of a @code{longjmp}.
c906108c 19254
8e04817f
AC
19255@item until
19256Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 19257
8e04817f
AC
19258@item finish
19259Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 19260
8e04817f
AC
19261@item shlib events
19262Shared library events.
c906108c 19263
8e04817f 19264@end table
c906108c 19265
8d30a00d
AC
19266@kindex maint internal-error
19267@kindex maint internal-warning
19268@item maint internal-error
19269@itemx maint internal-warning
19270Cause @value{GDBN} to call the internal function @code{internal_error}
19271or @code{internal_warning} and hence behave as though an internal error
19272or internal warning has been detected. In addition to reporting the
19273internal problem, these functions give the user the opportunity to
19274either quit @value{GDBN} or create a core file of the current
19275@value{GDBN} session.
19276
19277@smallexample
19278(gdb) @kbd{maint internal-error testing, 1, 2}
19279@dots{}/maint.c:121: internal-error: testing, 1, 2
19280A problem internal to GDB has been detected. Further
19281debugging may prove unreliable.
19282Quit this debugging session? (y or n) @kbd{n}
19283Create a core file? (y or n) @kbd{n}
19284(gdb)
19285@end smallexample
19286
19287Takes an optional parameter that is used as the text of the error or
19288warning message.
19289
00905d52
AC
19290@kindex maint print dummy-frames
19291@item maint print dummy-frames
19292
19293Prints the contents of @value{GDBN}'s internal dummy-frame stack.
19294
19295@smallexample
19296(gdb) @kbd{b add}
19297@dots{}
19298(gdb) @kbd{print add(2,3)}
19299Breakpoint 2, add (a=2, b=3) at @dots{}
1930058 return (a + b);
19301The program being debugged stopped while in a function called from GDB.
19302@dots{}
19303(gdb) @kbd{maint print dummy-frames}
193040x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
19305 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
19306 call_lo=0x01014000 call_hi=0x01014001
19307(gdb)
19308@end smallexample
19309
19310Takes an optional file parameter.
19311
0680b120
AC
19312@kindex maint print registers
19313@kindex maint print raw-registers
19314@kindex maint print cooked-registers
617073a9 19315@kindex maint print register-groups
0680b120
AC
19316@item maint print registers
19317@itemx maint print raw-registers
19318@itemx maint print cooked-registers
617073a9 19319@itemx maint print register-groups
0680b120
AC
19320Print @value{GDBN}'s internal register data structures.
19321
617073a9
AC
19322The command @code{maint print raw-registers} includes the contents of
19323the raw register cache; the command @code{maint print cooked-registers}
19324includes the (cooked) value of all registers; and the command
19325@code{maint print register-groups} includes the groups that each
19326register is a member of. @xref{Registers,, Registers, gdbint,
19327@value{GDBN} Internals}.
0680b120
AC
19328
19329Takes an optional file parameter.
19330
617073a9
AC
19331@kindex maint print reggroups
19332@item maint print reggroups
19333Print @value{GDBN}'s internal register group data structures.
19334
19335Takes an optional file parameter.
19336
19337@smallexample
19338(gdb) @kbd{maint print reggroups}
19339 Group Type
19340 general user
19341 float user
19342 all user
19343 vector user
19344 system user
19345 save internal
19346 restore internal
19347@end smallexample
19348
e7ba9c65
DJ
19349@kindex maint set profile
19350@kindex maint show profile
19351@cindex profiling GDB
19352@item maint set profile
19353@itemx maint show profile
19354Control profiling of @value{GDBN}.
19355
19356Profiling will be disabled until you use the @samp{maint set profile}
19357command to enable it. When you enable profiling, the system will begin
19358collecting timing and execution count data; when you disable profiling or
19359exit @value{GDBN}, the results will be written to a log file. Remember that
19360if you use profiling, @value{GDBN} will overwrite the profiling log file
19361(often called @file{gmon.out}). If you have a record of important profiling
19362data in a @file{gmon.out} file, be sure to move it to a safe location.
19363
19364Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
19365compiled with the @samp{-pg} compiler option.
19366
8e04817f 19367@end table
c906108c 19368
c906108c 19369
e0ce93ac 19370@node Remote Protocol
8e04817f 19371@appendix @value{GDBN} Remote Serial Protocol
c906108c 19372
ee2d5c50
AC
19373@menu
19374* Overview::
19375* Packets::
19376* Stop Reply Packets::
19377* General Query Packets::
19378* Register Packet Format::
19379* Examples::
0ce1b118 19380* File-I/O remote protocol extension::
ee2d5c50
AC
19381@end menu
19382
19383@node Overview
19384@section Overview
19385
8e04817f
AC
19386There may be occasions when you need to know something about the
19387protocol---for example, if there is only one serial port to your target
19388machine, you might want your program to do something special if it
19389recognizes a packet meant for @value{GDBN}.
c906108c 19390
d2c6833e 19391In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 19392transmitted and received data respectfully.
c906108c 19393
8e04817f
AC
19394@cindex protocol, @value{GDBN} remote serial
19395@cindex serial protocol, @value{GDBN} remote
19396@cindex remote serial protocol
19397All @value{GDBN} commands and responses (other than acknowledgments) are
19398sent as a @var{packet}. A @var{packet} is introduced with the character
19399@samp{$}, the actual @var{packet-data}, and the terminating character
19400@samp{#} followed by a two-digit @var{checksum}:
c906108c 19401
474c8240 19402@smallexample
8e04817f 19403@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 19404@end smallexample
8e04817f 19405@noindent
c906108c 19406
8e04817f
AC
19407@cindex checksum, for @value{GDBN} remote
19408@noindent
19409The two-digit @var{checksum} is computed as the modulo 256 sum of all
19410characters between the leading @samp{$} and the trailing @samp{#} (an
19411eight bit unsigned checksum).
c906108c 19412
8e04817f
AC
19413Implementors should note that prior to @value{GDBN} 5.0 the protocol
19414specification also included an optional two-digit @var{sequence-id}:
c906108c 19415
474c8240 19416@smallexample
8e04817f 19417@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 19418@end smallexample
c906108c 19419
8e04817f
AC
19420@cindex sequence-id, for @value{GDBN} remote
19421@noindent
19422That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
19423has never output @var{sequence-id}s. Stubs that handle packets added
19424since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 19425
8e04817f
AC
19426@cindex acknowledgment, for @value{GDBN} remote
19427When either the host or the target machine receives a packet, the first
19428response expected is an acknowledgment: either @samp{+} (to indicate
19429the package was received correctly) or @samp{-} (to request
19430retransmission):
c906108c 19431
474c8240 19432@smallexample
d2c6833e
AC
19433-> @code{$}@var{packet-data}@code{#}@var{checksum}
19434<- @code{+}
474c8240 19435@end smallexample
8e04817f 19436@noindent
53a5351d 19437
8e04817f
AC
19438The host (@value{GDBN}) sends @var{command}s, and the target (the
19439debugging stub incorporated in your program) sends a @var{response}. In
19440the case of step and continue @var{command}s, the response is only sent
19441when the operation has completed (the target has again stopped).
c906108c 19442
8e04817f
AC
19443@var{packet-data} consists of a sequence of characters with the
19444exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
19445exceptions).
c906108c 19446
8e04817f 19447Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 19448@cindex remote protocol, field separator
8e04817f 19449@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 19450@sc{hex} with leading zeros suppressed.
c906108c 19451
8e04817f
AC
19452Implementors should note that prior to @value{GDBN} 5.0, the character
19453@samp{:} could not appear as the third character in a packet (as it
19454would potentially conflict with the @var{sequence-id}).
c906108c 19455
8e04817f
AC
19456Response @var{data} can be run-length encoded to save space. A @samp{*}
19457means that the next character is an @sc{ascii} encoding giving a repeat count
19458which stands for that many repetitions of the character preceding the
19459@samp{*}. The encoding is @code{n+29}, yielding a printable character
19460where @code{n >=3} (which is where rle starts to win). The printable
19461characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
19462value greater than 126 should not be used.
c906108c 19463
8e04817f
AC
19464Some remote systems have used a different run-length encoding mechanism
19465loosely refered to as the cisco encoding. Following the @samp{*}
19466character are two hex digits that indicate the size of the packet.
c906108c 19467
8e04817f 19468So:
474c8240 19469@smallexample
8e04817f 19470"@code{0* }"
474c8240 19471@end smallexample
8e04817f
AC
19472@noindent
19473means the same as "0000".
c906108c 19474
8e04817f
AC
19475The error response returned for some packets includes a two character
19476error number. That number is not well defined.
c906108c 19477
8e04817f
AC
19478For any @var{command} not supported by the stub, an empty response
19479(@samp{$#00}) should be returned. That way it is possible to extend the
19480protocol. A newer @value{GDBN} can tell if a packet is supported based
19481on that response.
c906108c 19482
8e04817f
AC
19483A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
19484@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
19485optional.
c906108c 19486
ee2d5c50
AC
19487@node Packets
19488@section Packets
19489
19490The following table provides a complete list of all currently defined
19491@var{command}s and their corresponding response @var{data}.
19492
19493@table @r
19494
19495@item @code{!} --- extended mode
19496@cindex @code{!} packet
19497
8e04817f
AC
19498Enable extended mode. In extended mode, the remote server is made
19499persistent. The @samp{R} packet is used to restart the program being
19500debugged.
ee2d5c50
AC
19501
19502Reply:
19503@table @samp
19504@item OK
8e04817f 19505The remote target both supports and has enabled extended mode.
ee2d5c50 19506@end table
c906108c 19507
ee2d5c50
AC
19508@item @code{?} --- last signal
19509@cindex @code{?} packet
c906108c 19510
ee2d5c50
AC
19511Indicate the reason the target halted. The reply is the same as for
19512step and continue.
c906108c 19513
ee2d5c50
AC
19514Reply:
19515@xref{Stop Reply Packets}, for the reply specifications.
19516
19517@item @code{a} --- reserved
19518
19519Reserved for future use.
19520
19521@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
19522@cindex @code{A} packet
c906108c 19523
8e04817f
AC
19524Initialized @samp{argv[]} array passed into program. @var{arglen}
19525specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
19526See @code{gdbserver} for more details.
19527
19528Reply:
19529@table @samp
19530@item OK
19531@item E@var{NN}
19532@end table
19533
19534@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
19535@cindex @code{b} packet
19536
19537Change the serial line speed to @var{baud}.
19538
19539JTC: @emph{When does the transport layer state change? When it's
19540received, or after the ACK is transmitted. In either case, there are
19541problems if the command or the acknowledgment packet is dropped.}
19542
19543Stan: @emph{If people really wanted to add something like this, and get
19544it working for the first time, they ought to modify ser-unix.c to send
19545some kind of out-of-band message to a specially-setup stub and have the
19546switch happen "in between" packets, so that from remote protocol's point
19547of view, nothing actually happened.}
19548
19549@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
19550@cindex @code{B} packet
19551
8e04817f 19552Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
19553breakpoint at @var{addr}.
19554
19555This packet has been replaced by the @samp{Z} and @samp{z} packets
19556(@pxref{insert breakpoint or watchpoint packet}).
c906108c 19557
ee2d5c50
AC
19558@item @code{c}@var{addr} --- continue
19559@cindex @code{c} packet
19560
19561@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 19562current address.
c906108c 19563
ee2d5c50
AC
19564Reply:
19565@xref{Stop Reply Packets}, for the reply specifications.
19566
19567@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
19568@cindex @code{C} packet
19569
8e04817f
AC
19570Continue with signal @var{sig} (hex signal number). If
19571@code{;}@var{addr} is omitted, resume at same address.
c906108c 19572
ee2d5c50
AC
19573Reply:
19574@xref{Stop Reply Packets}, for the reply specifications.
c906108c 19575
ee2d5c50
AC
19576@item @code{d} --- toggle debug @strong{(deprecated)}
19577@cindex @code{d} packet
19578
19579Toggle debug flag.
19580
19581@item @code{D} --- detach
19582@cindex @code{D} packet
19583
19584Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 19585before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
19586
19587Reply:
19588@table @samp
19589@item @emph{no response}
8e04817f 19590@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 19591@end table
c906108c 19592
ee2d5c50 19593@item @code{e} --- reserved
c906108c 19594
ee2d5c50 19595Reserved for future use.
c906108c 19596
ee2d5c50 19597@item @code{E} --- reserved
c906108c 19598
ee2d5c50 19599Reserved for future use.
c906108c 19600
ee2d5c50
AC
19601@item @code{f} --- reserved
19602
19603Reserved for future use.
19604
0ce1b118
CV
19605@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
19606@cindex @code{F} packet
ee2d5c50 19607
0ce1b118
CV
19608This packet is send by @value{GDBN} as reply to a @code{F} request packet
19609sent by the target. This is part of the File-I/O protocol extension.
19610@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
19611
19612@item @code{g} --- read registers
19613@anchor{read registers packet}
19614@cindex @code{g} packet
19615
19616Read general registers.
19617
19618Reply:
19619@table @samp
19620@item @var{XX@dots{}}
8e04817f
AC
19621Each byte of register data is described by two hex digits. The bytes
19622with the register are transmitted in target byte order. The size of
19623each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
19624determined by the @value{GDBN} internal macros
19625@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
19626specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
19627@item E@var{NN}
19628for an error.
19629@end table
c906108c 19630
ee2d5c50
AC
19631@item @code{G}@var{XX@dots{}} --- write regs
19632@cindex @code{G} packet
c906108c 19633
ee2d5c50
AC
19634@xref{read registers packet}, for a description of the @var{XX@dots{}}
19635data.
19636
19637Reply:
19638@table @samp
19639@item OK
19640for success
19641@item E@var{NN}
19642for an error
19643@end table
19644
19645@item @code{h} --- reserved
19646
19647Reserved for future use.
19648
19649@item @code{H}@var{c}@var{t@dots{}} --- set thread
19650@cindex @code{H} packet
c906108c 19651
8e04817f 19652Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
19653@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
19654should be @samp{c} for step and continue operations, @samp{g} for other
19655operations. The thread designator @var{t@dots{}} may be -1, meaning all
19656the threads, a thread number, or zero which means pick any thread.
19657
19658Reply:
19659@table @samp
19660@item OK
19661for success
19662@item E@var{NN}
19663for an error
19664@end table
c906108c 19665
8e04817f
AC
19666@c FIXME: JTC:
19667@c 'H': How restrictive (or permissive) is the thread model. If a
19668@c thread is selected and stopped, are other threads allowed
19669@c to continue to execute? As I mentioned above, I think the
19670@c semantics of each command when a thread is selected must be
19671@c described. For example:
19672@c
19673@c 'g': If the stub supports threads and a specific thread is
19674@c selected, returns the register block from that thread;
19675@c otherwise returns current registers.
19676@c
19677@c 'G' If the stub supports threads and a specific thread is
19678@c selected, sets the registers of the register block of
19679@c that thread; otherwise sets current registers.
c906108c 19680
ee2d5c50
AC
19681@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
19682@anchor{cycle step packet}
19683@cindex @code{i} packet
19684
8e04817f
AC
19685Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
19686present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
19687step starting at that address.
c906108c 19688
ee2d5c50
AC
19689@item @code{I} --- signal then cycle step @strong{(reserved)}
19690@cindex @code{I} packet
19691
19692@xref{step with signal packet}. @xref{cycle step packet}.
19693
19694@item @code{j} --- reserved
19695
19696Reserved for future use.
19697
19698@item @code{J} --- reserved
c906108c 19699
ee2d5c50 19700Reserved for future use.
c906108c 19701
ee2d5c50
AC
19702@item @code{k} --- kill request
19703@cindex @code{k} packet
c906108c 19704
ac282366 19705FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
19706thread context has been selected (i.e.@: does 'k' kill only that
19707thread?)}.
c906108c 19708
ee2d5c50 19709@item @code{K} --- reserved
c906108c 19710
ee2d5c50
AC
19711Reserved for future use.
19712
19713@item @code{l} --- reserved
19714
19715Reserved for future use.
19716
19717@item @code{L} --- reserved
19718
19719Reserved for future use.
19720
19721@item @code{m}@var{addr}@code{,}@var{length} --- read memory
19722@cindex @code{m} packet
c906108c 19723
8e04817f 19724Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 19725Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 19726assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 19727transfer mechanism is needed.}
c906108c 19728
ee2d5c50
AC
19729Reply:
19730@table @samp
19731@item @var{XX@dots{}}
19732@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
19733to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 19734that sized memory transfers are assumed using word aligned
ee2d5c50
AC
19735accesses. FIXME: @emph{A word aligned memory transfer mechanism is
19736needed.}
19737@item E@var{NN}
19738@var{NN} is errno
19739@end table
19740
19741@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
19742@cindex @code{M} packet
19743
8e04817f 19744Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
19745@var{XX@dots{}} is the data.
19746
19747Reply:
19748@table @samp
19749@item OK
19750for success
19751@item E@var{NN}
8e04817f
AC
19752for an error (this includes the case where only part of the data was
19753written).
ee2d5c50 19754@end table
c906108c 19755
ee2d5c50 19756@item @code{n} --- reserved
c906108c 19757
ee2d5c50 19758Reserved for future use.
c906108c 19759
ee2d5c50 19760@item @code{N} --- reserved
c906108c 19761
ee2d5c50 19762Reserved for future use.
c906108c 19763
ee2d5c50
AC
19764@item @code{o} --- reserved
19765
19766Reserved for future use.
19767
19768@item @code{O} --- reserved
19769
19770Reserved for future use.
c906108c 19771
ee2d5c50
AC
19772@item @code{p}@var{n@dots{}} --- read reg @strong{(reserved)}
19773@cindex @code{p} packet
19774
19775@xref{write register packet}.
19776
19777Reply:
19778@table @samp
19779@item @var{r@dots{}.}
19780The hex encoded value of the register in target byte order.
19781@end table
19782
19783@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
19784@anchor{write register packet}
19785@cindex @code{P} packet
19786
19787Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 19788digits for each byte in the register (target byte order).
c906108c 19789
ee2d5c50
AC
19790Reply:
19791@table @samp
19792@item OK
19793for success
19794@item E@var{NN}
19795for an error
19796@end table
19797
19798@item @code{q}@var{query} --- general query
19799@anchor{general query packet}
19800@cindex @code{q} packet
19801
19802Request info about @var{query}. In general @value{GDBN} queries have a
19803leading upper case letter. Custom vendor queries should use a company
19804prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
19805be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
19806that they match the full @var{query} name.
19807
19808Reply:
19809@table @samp
19810@item @var{XX@dots{}}
19811Hex encoded data from query. The reply can not be empty.
19812@item E@var{NN}
19813error reply
8e04817f 19814@item
ee2d5c50
AC
19815Indicating an unrecognized @var{query}.
19816@end table
19817
19818@item @code{Q}@var{var}@code{=}@var{val} --- general set
19819@cindex @code{Q} packet
19820
19821Set value of @var{var} to @var{val}.
19822
19823@xref{general query packet}, for a discussion of naming conventions.
c906108c 19824
ee2d5c50
AC
19825@item @code{r} --- reset @strong{(deprecated)}
19826@cindex @code{r} packet
c906108c 19827
8e04817f 19828Reset the entire system.
c906108c 19829
ee2d5c50
AC
19830@item @code{R}@var{XX} --- remote restart
19831@cindex @code{R} packet
19832
8e04817f
AC
19833Restart the program being debugged. @var{XX}, while needed, is ignored.
19834This packet is only available in extended mode.
ee2d5c50
AC
19835
19836Reply:
19837@table @samp
19838@item @emph{no reply}
8e04817f 19839The @samp{R} packet has no reply.
ee2d5c50
AC
19840@end table
19841
19842@item @code{s}@var{addr} --- step
19843@cindex @code{s} packet
c906108c 19844
8e04817f
AC
19845@var{addr} is address to resume. If @var{addr} is omitted, resume at
19846same address.
c906108c 19847
ee2d5c50
AC
19848Reply:
19849@xref{Stop Reply Packets}, for the reply specifications.
19850
19851@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
19852@anchor{step with signal packet}
19853@cindex @code{S} packet
19854
8e04817f 19855Like @samp{C} but step not continue.
c906108c 19856
ee2d5c50
AC
19857Reply:
19858@xref{Stop Reply Packets}, for the reply specifications.
19859
19860@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
19861@cindex @code{t} packet
19862
8e04817f 19863Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
19864@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
19865@var{addr} must be at least 3 digits.
c906108c 19866
ee2d5c50
AC
19867@item @code{T}@var{XX} --- thread alive
19868@cindex @code{T} packet
c906108c 19869
ee2d5c50 19870Find out if the thread XX is alive.
c906108c 19871
ee2d5c50
AC
19872Reply:
19873@table @samp
19874@item OK
19875thread is still alive
19876@item E@var{NN}
19877thread is dead
19878@end table
19879
19880@item @code{u} --- reserved
19881
19882Reserved for future use.
19883
19884@item @code{U} --- reserved
19885
19886Reserved for future use.
19887
86d30acc 19888@item @code{v} --- verbose packet prefix
ee2d5c50 19889
86d30acc
DJ
19890Packets starting with @code{v} are identified by a multi-letter name,
19891up to the first @code{;} or @code{?} (or the end of the packet).
19892
19893@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
19894@cindex @code{vCont} packet
19895
19896Resume the inferior. Different actions may be specified for each thread.
19897If an action is specified with no @var{tid}, then it is applied to any
19898threads that don't have a specific action specified; if no default action is
19899specified then other threads should remain stopped. Specifying multiple
19900default actions is an error; specifying no actions is also an error.
19901Thread IDs are specified in hexadecimal. Currently supported actions are:
19902
19903@table @code
19904@item c
19905Continue.
19906@item C@var{sig}
19907Continue with signal @var{sig}. @var{sig} should be two hex digits.
19908@item s
19909Step.
19910@item S@var{sig}
19911Step with signal @var{sig}. @var{sig} should be two hex digits.
19912@end table
19913
19914The optional @var{addr} argument normally associated with these packets is
19915not supported in @code{vCont}.
19916
19917Reply:
19918@xref{Stop Reply Packets}, for the reply specifications.
19919
19920@item @code{vCont?} --- extended resume query
19921@cindex @code{vCont?} packet
19922
19923Query support for the @code{vCont} packet.
19924
19925Reply:
19926@table @samp
19927@item @code{vCont}[;@var{action}]...
19928The @code{vCont} packet is supported. Each @var{action} is a supported
19929command in the @code{vCont} packet.
19930@item
19931The @code{vCont} packet is not supported.
19932@end table
ee2d5c50
AC
19933
19934@item @code{V} --- reserved
c906108c 19935
ee2d5c50 19936Reserved for future use.
c906108c 19937
ee2d5c50 19938@item @code{w} --- reserved
c906108c 19939
ee2d5c50 19940Reserved for future use.
c906108c 19941
ee2d5c50 19942@item @code{W} --- reserved
c906108c 19943
ee2d5c50 19944Reserved for future use.
c906108c 19945
ee2d5c50
AC
19946@item @code{x} --- reserved
19947
19948Reserved for future use.
19949
19950@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
19951@cindex @code{X} packet
19952
19953@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
19954is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
8e04817f 19955escaped using @code{0x7d}.
c906108c 19956
ee2d5c50
AC
19957Reply:
19958@table @samp
19959@item OK
19960for success
19961@item E@var{NN}
19962for an error
19963@end table
19964
19965@item @code{y} --- reserved
c906108c 19966
ee2d5c50 19967Reserved for future use.
c906108c 19968
ee2d5c50
AC
19969@item @code{Y} reserved
19970
19971Reserved for future use.
19972
2f870471
AC
19973@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
19974@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
19975@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 19976@cindex @code{z} packet
2f870471 19977@cindex @code{Z} packets
ee2d5c50 19978
2f870471
AC
19979Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
19980watchpoint starting at address @var{address} and covering the next
19981@var{length} bytes.
ee2d5c50 19982
2f870471
AC
19983Each breakpoint and watchpoint packet @var{type} is documented
19984separately.
19985
512217c7
AC
19986@emph{Implementation notes: A remote target shall return an empty string
19987for an unrecognized breakpoint or watchpoint packet @var{type}. A
19988remote target shall support either both or neither of a given
2f870471
AC
19989@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
19990avoid potential problems with duplicate packets, the operations should
19991be implemented in an idempotent way.}
19992
19993@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
19994@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
19995@cindex @code{z0} packet
19996@cindex @code{Z0} packet
19997
19998Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
19999@code{addr} of size @code{length}.
20000
20001A memory breakpoint is implemented by replacing the instruction at
20002@var{addr} with a software breakpoint or trap instruction. The
20003@code{length} is used by targets that indicates the size of the
20004breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
20005@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 20006
2f870471
AC
20007@emph{Implementation note: It is possible for a target to copy or move
20008code that contains memory breakpoints (e.g., when implementing
20009overlays). The behavior of this packet, in the presence of such a
20010target, is not defined.}
c906108c 20011
ee2d5c50
AC
20012Reply:
20013@table @samp
2f870471
AC
20014@item OK
20015success
20016@item
20017not supported
ee2d5c50
AC
20018@item E@var{NN}
20019for an error
2f870471
AC
20020@end table
20021
20022@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
20023@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
20024@cindex @code{z1} packet
20025@cindex @code{Z1} packet
20026
20027Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
20028address @code{addr} of size @code{length}.
20029
20030A hardware breakpoint is implemented using a mechanism that is not
20031dependant on being able to modify the target's memory.
20032
20033@emph{Implementation note: A hardware breakpoint is not affected by code
20034movement.}
20035
20036Reply:
20037@table @samp
ee2d5c50 20038@item OK
2f870471
AC
20039success
20040@item
20041not supported
20042@item E@var{NN}
20043for an error
20044@end table
20045
20046@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
20047@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
20048@cindex @code{z2} packet
20049@cindex @code{Z2} packet
20050
20051Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
20052
20053Reply:
20054@table @samp
20055@item OK
20056success
20057@item
20058not supported
20059@item E@var{NN}
20060for an error
20061@end table
20062
20063@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
20064@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
20065@cindex @code{z3} packet
20066@cindex @code{Z3} packet
20067
2e834e49 20068Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
20069
20070Reply:
20071@table @samp
20072@item OK
20073success
20074@item
20075not supported
20076@item E@var{NN}
20077for an error
20078@end table
20079
2e834e49
HPN
20080@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
20081@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
20082@cindex @code{z4} packet
20083@cindex @code{Z4} packet
20084
20085Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
20086
20087Reply:
20088@table @samp
20089@item OK
20090success
20091@item
20092not supported
20093@item E@var{NN}
20094for an error
ee2d5c50
AC
20095@end table
20096
20097@end table
c906108c 20098
ee2d5c50
AC
20099@node Stop Reply Packets
20100@section Stop Reply Packets
20101@cindex stop reply packets
c906108c 20102
8e04817f
AC
20103The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
20104receive any of the below as a reply. In the case of the @samp{C},
20105@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
20106when the target halts. In the below the exact meaning of @samp{signal
20107number} is poorly defined. In general one of the UNIX signal numbering
20108conventions is used.
c906108c 20109
ee2d5c50 20110@table @samp
c906108c 20111
ee2d5c50
AC
20112@item S@var{AA}
20113@var{AA} is the signal number
c906108c 20114
8e04817f 20115@item @code{T}@var{AA}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}@var{n...}@code{:}@var{r...}@code{;}
ee2d5c50
AC
20116@cindex @code{T} packet reply
20117
8e04817f
AC
20118@var{AA} = two hex digit signal number; @var{n...} = register number
20119(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
20120by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
20121@var{r...} = thread process ID, this is a hex integer; @var{n...} =
20122(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
20123address, this is a hex integer; @var{n...} = other string not starting
20124with valid hex digit. @value{GDBN} should ignore this @var{n...},
20125@var{r...} pair and go on to the next. This way we can extend the
20126protocol.
c906108c 20127
ee2d5c50
AC
20128@item W@var{AA}
20129
8e04817f 20130The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
20131applicable to certain targets.
20132
20133@item X@var{AA}
c906108c 20134
8e04817f 20135The process terminated with signal @var{AA}.
c906108c 20136
ee2d5c50
AC
20137@item N@var{AA};@var{t@dots{}};@var{d@dots{}};@var{b@dots{}} @strong{(obsolete)}
20138
20139@var{AA} = signal number; @var{t@dots{}} = address of symbol
20140@code{_start}; @var{d@dots{}} = base of data section; @var{b@dots{}} =
20141base of bss section. @emph{Note: only used by Cisco Systems targets.
20142The difference between this reply and the @samp{qOffsets} query is that
20143the @samp{N} packet may arrive spontaneously whereas the @samp{qOffsets}
20144is a query initiated by the host debugger.}
c906108c 20145
ee2d5c50 20146@item O@var{XX@dots{}}
c906108c 20147
ee2d5c50
AC
20148@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
20149any time while the program is running and the debugger should continue
20150to wait for @samp{W}, @samp{T}, etc.
20151
0ce1b118
CV
20152@item F@var{call-id}@code{,}@var{parameter@dots{}}
20153
20154@var{call-id} is the identifier which says which host system call should
20155be called. This is just the name of the function. Translation into the
20156correct system call is only applicable as it's defined in @value{GDBN}.
20157@xref{File-I/O remote protocol extension}, for a list of implemented
20158system calls.
20159
20160@var{parameter@dots{}} is a list of parameters as defined for this very
20161system call.
20162
20163The target replies with this packet when it expects @value{GDBN} to call
20164a host system call on behalf of the target. @value{GDBN} replies with
20165an appropriate @code{F} packet and keeps up waiting for the next reply
20166packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
20167@samp{s} action is expected to be continued.
20168@xref{File-I/O remote protocol extension}, for more details.
20169
ee2d5c50
AC
20170@end table
20171
20172@node General Query Packets
20173@section General Query Packets
c906108c 20174
8e04817f 20175The following set and query packets have already been defined.
c906108c 20176
ee2d5c50 20177@table @r
c906108c 20178
ee2d5c50
AC
20179@item @code{q}@code{C} --- current thread
20180
20181Return the current thread id.
20182
20183Reply:
20184@table @samp
20185@item @code{QC}@var{pid}
8e04817f 20186Where @var{pid} is a HEX encoded 16 bit process id.
ee2d5c50
AC
20187@item *
20188Any other reply implies the old pid.
20189@end table
20190
20191@item @code{q}@code{fThreadInfo} -- all thread ids
20192
20193@code{q}@code{sThreadInfo}
c906108c 20194
8e04817f
AC
20195Obtain a list of active thread ids from the target (OS). Since there
20196may be too many active threads to fit into one reply packet, this query
20197works iteratively: it may require more than one query/reply sequence to
20198obtain the entire list of threads. The first query of the sequence will
20199be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
20200sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
20201
20202NOTE: replaces the @code{qL} query (see below).
20203
20204Reply:
20205@table @samp
20206@item @code{m}@var{id}
20207A single thread id
20208@item @code{m}@var{id},@var{id}@dots{}
20209a comma-separated list of thread ids
20210@item @code{l}
20211(lower case 'el') denotes end of list.
20212@end table
20213
20214In response to each query, the target will reply with a list of one or
20215more thread ids, in big-endian hex, separated by commas. @value{GDBN}
20216will respond to each reply with a request for more thread ids (using the
8e04817f
AC
20217@code{qs} form of the query), until the target responds with @code{l}
20218(lower-case el, for @code{'last'}).
c906108c 20219
ee2d5c50
AC
20220@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
20221
20222Where @var{id} is a thread-id in big-endian hex. Obtain a printable
20223string description of a thread's attributes from the target OS. This
20224string may contain anything that the target OS thinks is interesting for
20225@value{GDBN} to tell the user about the thread. The string is displayed
20226in @value{GDBN}'s @samp{info threads} display. Some examples of
20227possible thread extra info strings are ``Runnable'', or ``Blocked on
20228Mutex''.
20229
20230Reply:
20231@table @samp
20232@item @var{XX@dots{}}
20233Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
20234the printable string containing the extra information about the thread's
8e04817f 20235attributes.
ee2d5c50
AC
20236@end table
20237
20238@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 20239
8e04817f
AC
20240Obtain thread information from RTOS. Where: @var{startflag} (one hex
20241digit) is one to indicate the first query and zero to indicate a
20242subsequent query; @var{threadcount} (two hex digits) is the maximum
20243number of threads the response packet can contain; and @var{nextthread}
20244(eight hex digits), for subsequent queries (@var{startflag} is zero), is
20245returned in the response as @var{argthread}.
ee2d5c50
AC
20246
20247NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
20248(see above).
20249
20250Reply:
20251@table @samp
20252@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
20253Where: @var{count} (two hex digits) is the number of threads being
20254returned; @var{done} (one hex digit) is zero to indicate more threads
20255and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
20256digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
20257is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 20258digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 20259@end table
c906108c 20260
ee2d5c50
AC
20261@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
20262
20263Reply:
20264@table @samp
20265@item @code{E}@var{NN}
20266An error (such as memory fault)
20267@item @code{C}@var{CRC32}
20268A 32 bit cyclic redundancy check of the specified memory region.
20269@end table
20270
20271@item @code{q}@code{Offsets} --- query sect offs
c906108c 20272
8e04817f
AC
20273Get section offsets that the target used when re-locating the downloaded
20274image. @emph{Note: while a @code{Bss} offset is included in the
20275response, @value{GDBN} ignores this and instead applies the @code{Data}
20276offset to the @code{Bss} section.}
c906108c 20277
ee2d5c50
AC
20278Reply:
20279@table @samp
20280@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
20281@end table
20282
20283@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
20284
8e04817f
AC
20285Returns information on @var{threadid}. Where: @var{mode} is a hex
20286encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
20287
20288Reply:
20289@table @samp
20290@item *
20291@end table
20292
8e04817f 20293See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 20294
ee2d5c50
AC
20295@item @code{q}@code{Rcmd,}@var{command} --- remote command
20296
20297@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
20298execution. Invalid commands should be reported using the output string.
20299Before the final result packet, the target may also respond with a
ee2d5c50
AC
20300number of intermediate @code{O}@var{output} console output packets.
20301@emph{Implementors should note that providing access to a stubs's
20302interpreter may have security implications}.
20303
20304Reply:
20305@table @samp
20306@item OK
8e04817f 20307A command response with no output.
ee2d5c50 20308@item @var{OUTPUT}
8e04817f 20309A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 20310@item @code{E}@var{NN}
8e04817f 20311Indicate a badly formed request.
ee2d5c50 20312@item @samp{}
8e04817f 20313When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50
AC
20314@end table
20315
20316@item @code{qSymbol::} --- symbol lookup
c906108c 20317
8e04817f
AC
20318Notify the target that @value{GDBN} is prepared to serve symbol lookup
20319requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
20320
20321Reply:
20322@table @samp
20323@item @code{OK}
8e04817f 20324The target does not need to look up any (more) symbols.
ee2d5c50
AC
20325@item @code{qSymbol:}@var{sym_name}
20326The target requests the value of symbol @var{sym_name} (hex encoded).
20327@value{GDBN} may provide the value by using the
20328@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
20329@end table
20330
20331@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
20332
20333Set the value of @var{sym_name} to @var{sym_value}.
20334
20335@var{sym_name} (hex encoded) is the name of a symbol whose value the
20336target has previously requested.
20337
20338@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
20339@value{GDBN} cannot supply a value for @var{sym_name}, then this field
20340will be empty.
20341
20342Reply:
20343@table @samp
20344@item @code{OK}
8e04817f 20345The target does not need to look up any (more) symbols.
ee2d5c50
AC
20346@item @code{qSymbol:}@var{sym_name}
20347The target requests the value of a new symbol @var{sym_name} (hex
20348encoded). @value{GDBN} will continue to supply the values of symbols
20349(if available), until the target ceases to request them.
20350@end table
eb12ee30 20351
ee2d5c50
AC
20352@end table
20353
20354@node Register Packet Format
20355@section Register Packet Format
eb12ee30 20356
8e04817f 20357The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
20358In the below, some thirty-two bit registers are transferred as
20359sixty-four bits. Those registers should be zero/sign extended (which?)
20360to fill the space allocated. Register bytes are transfered in target
20361byte order. The two nibbles within a register byte are transfered
20362most-significant - least-significant.
eb12ee30 20363
ee2d5c50 20364@table @r
eb12ee30 20365
8e04817f 20366@item MIPS32
ee2d5c50 20367
8e04817f
AC
20368All registers are transfered as thirty-two bit quantities in the order:
2036932 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
20370registers; fsr; fir; fp.
eb12ee30 20371
8e04817f 20372@item MIPS64
ee2d5c50 20373
8e04817f
AC
20374All registers are transfered as sixty-four bit quantities (including
20375thirty-two bit registers such as @code{sr}). The ordering is the same
20376as @code{MIPS32}.
eb12ee30 20377
ee2d5c50
AC
20378@end table
20379
20380@node Examples
20381@section Examples
eb12ee30 20382
8e04817f
AC
20383Example sequence of a target being re-started. Notice how the restart
20384does not get any direct output:
eb12ee30 20385
474c8240 20386@smallexample
d2c6833e
AC
20387-> @code{R00}
20388<- @code{+}
8e04817f 20389@emph{target restarts}
d2c6833e 20390-> @code{?}
8e04817f 20391<- @code{+}
d2c6833e
AC
20392<- @code{T001:1234123412341234}
20393-> @code{+}
474c8240 20394@end smallexample
eb12ee30 20395
8e04817f 20396Example sequence of a target being stepped by a single instruction:
eb12ee30 20397
474c8240 20398@smallexample
d2c6833e 20399-> @code{G1445@dots{}}
8e04817f 20400<- @code{+}
d2c6833e
AC
20401-> @code{s}
20402<- @code{+}
20403@emph{time passes}
20404<- @code{T001:1234123412341234}
8e04817f 20405-> @code{+}
d2c6833e 20406-> @code{g}
8e04817f 20407<- @code{+}
d2c6833e
AC
20408<- @code{1455@dots{}}
20409-> @code{+}
474c8240 20410@end smallexample
eb12ee30 20411
0ce1b118
CV
20412@node File-I/O remote protocol extension
20413@section File-I/O remote protocol extension
20414@cindex File-I/O remote protocol extension
20415
20416@menu
20417* File-I/O Overview::
20418* Protocol basics::
1d8b2f28
JB
20419* The F request packet::
20420* The F reply packet::
0ce1b118
CV
20421* Memory transfer::
20422* The Ctrl-C message::
20423* Console I/O::
20424* The isatty call::
20425* The system call::
20426* List of supported calls::
20427* Protocol specific representation of datatypes::
20428* Constants::
20429* File-I/O Examples::
20430@end menu
20431
20432@node File-I/O Overview
20433@subsection File-I/O Overview
20434@cindex file-i/o overview
20435
20436The File I/O remote protocol extension (short: File-I/O) allows the
20437target to use the hosts file system and console I/O when calling various
20438system calls. System calls on the target system are translated into a
20439remote protocol packet to the host system which then performs the needed
20440actions and returns with an adequate response packet to the target system.
20441This simulates file system operations even on targets that lack file systems.
20442
20443The protocol is defined host- and target-system independent. It uses
20444it's own independent representation of datatypes and values. Both,
20445@value{GDBN} and the target's @value{GDBN} stub are responsible for
20446translating the system dependent values into the unified protocol values
20447when data is transmitted.
20448
20449The communication is synchronous. A system call is possible only
20450when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
20451packets. While @value{GDBN} handles the request for a system call,
20452the target is stopped to allow deterministic access to the target's
20453memory. Therefore File-I/O is not interuptible by target signals. It
20454is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
20455
20456The target's request to perform a host system call does not finish
20457the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
20458after finishing the system call, the target returns to continuing the
20459previous activity (continue, step). No additional continue or step
20460request from @value{GDBN} is required.
20461
20462@smallexample
20463(gdb) continue
20464 <- target requests 'system call X'
20465 target is stopped, @value{GDBN} executes system call
20466 -> GDB returns result
20467 ... target continues, GDB returns to wait for the target
20468 <- target hits breakpoint and sends a Txx packet
20469@end smallexample
20470
20471The protocol is only used for files on the host file system and
20472for I/O on the console. Character or block special devices, pipes,
20473named pipes or sockets or any other communication method on the host
20474system are not supported by this protocol.
20475
20476@node Protocol basics
20477@subsection Protocol basics
20478@cindex protocol basics, file-i/o
20479
20480The File-I/O protocol uses the @code{F} packet, as request as well
20481as as reply packet. Since a File-I/O system call can only occur when
20482@value{GDBN} is waiting for the continuing or stepping target, the
20483File-I/O request is a reply that @value{GDBN} has to expect as a result
20484of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
20485This @code{F} packet contains all information needed to allow @value{GDBN}
20486to call the appropriate host system call:
20487
20488@itemize @bullet
20489@item
20490A unique identifier for the requested system call.
20491
20492@item
20493All parameters to the system call. Pointers are given as addresses
20494in the target memory address space. Pointers to strings are given as
20495pointer/length pair. Numerical values are given as they are.
20496Numerical control values are given in a protocol specific representation.
20497
20498@end itemize
20499
20500At that point @value{GDBN} has to perform the following actions.
20501
20502@itemize @bullet
20503@item
20504If parameter pointer values are given, which point to data needed as input
20505to a system call, @value{GDBN} requests this data from the target with a
20506standard @code{m} packet request. This additional communication has to be
20507expected by the target implementation and is handled as any other @code{m}
20508packet.
20509
20510@item
20511@value{GDBN} translates all value from protocol representation to host
20512representation as needed. Datatypes are coerced into the host types.
20513
20514@item
20515@value{GDBN} calls the system call
20516
20517@item
20518It then coerces datatypes back to protocol representation.
20519
20520@item
20521If pointer parameters in the request packet point to buffer space in which
20522a system call is expected to copy data to, the data is transmitted to the
20523target using a @code{M} or @code{X} packet. This packet has to be expected
20524by the target implementation and is handled as any other @code{M} or @code{X}
20525packet.
20526
20527@end itemize
20528
20529Eventually @value{GDBN} replies with another @code{F} packet which contains all
20530necessary information for the target to continue. This at least contains
20531
20532@itemize @bullet
20533@item
20534Return value.
20535
20536@item
20537@code{errno}, if has been changed by the system call.
20538
20539@item
20540``Ctrl-C'' flag.
20541
20542@end itemize
20543
20544After having done the needed type and value coercion, the target continues
20545the latest continue or step action.
20546
1d8b2f28 20547@node The F request packet
0ce1b118
CV
20548@subsection The @code{F} request packet
20549@cindex file-i/o request packet
20550@cindex @code{F} request packet
20551
20552The @code{F} request packet has the following format:
20553
20554@table @samp
20555
20556@smallexample
20557@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
20558@end smallexample
20559
20560@var{call-id} is the identifier to indicate the host system call to be called.
20561This is just the name of the function.
20562
20563@var{parameter@dots{}} are the parameters to the system call.
20564
20565@end table
20566
20567Parameters are hexadecimal integer values, either the real values in case
20568of scalar datatypes, as pointers to target buffer space in case of compound
20569datatypes and unspecified memory areas or as pointer/length pairs in case
20570of string parameters. These are appended to the call-id, each separated
20571from its predecessor by a comma. All values are transmitted in ASCII
20572string representation, pointer/length pairs separated by a slash.
20573
1d8b2f28 20574@node The F reply packet
0ce1b118
CV
20575@subsection The @code{F} reply packet
20576@cindex file-i/o reply packet
20577@cindex @code{F} reply packet
20578
20579The @code{F} reply packet has the following format:
20580
20581@table @samp
20582
20583@smallexample
20584@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
20585@end smallexample
20586
20587@var{retcode} is the return code of the system call as hexadecimal value.
20588
20589@var{errno} is the errno set by the call, in protocol specific representation.
20590This parameter can be omitted if the call was successful.
20591
20592@var{Ctrl-C flag} is only send if the user requested a break. In this
20593case, @var{errno} must be send as well, even if the call was successful.
20594The @var{Ctrl-C flag} itself consists of the character 'C':
20595
20596@smallexample
20597F0,0,C
20598@end smallexample
20599
20600@noindent
20601or, if the call was interupted before the host call has been performed:
20602
20603@smallexample
20604F-1,4,C
20605@end smallexample
20606
20607@noindent
20608assuming 4 is the protocol specific representation of @code{EINTR}.
20609
20610@end table
20611
20612@node Memory transfer
20613@subsection Memory transfer
20614@cindex memory transfer, in file-i/o protocol
20615
20616Structured data which is transferred using a memory read or write as e.g.@:
20617a @code{struct stat} is expected to be in a protocol specific format with
20618all scalar multibyte datatypes being big endian. This should be done by
20619the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
20620it transfers memory to the target. Transferred pointers to structured
20621data should point to the already coerced data at any time.
20622
20623@node The Ctrl-C message
20624@subsection The Ctrl-C message
20625@cindex ctrl-c message, in file-i/o protocol
20626
20627A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
20628reply packet. In this case the target should behave, as if it had
20629gotten a break message. The meaning for the target is ``system call
20630interupted by @code{SIGINT}''. Consequentially, the target should actually stop
20631(as with a break message) and return to @value{GDBN} with a @code{T02}
20632packet. In this case, it's important for the target to know, in which
20633state the system call was interrupted. Since this action is by design
20634not an atomic operation, we have to differ between two cases:
20635
20636@itemize @bullet
20637@item
20638The system call hasn't been performed on the host yet.
20639
20640@item
20641The system call on the host has been finished.
20642
20643@end itemize
20644
20645These two states can be distinguished by the target by the value of the
20646returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
20647call hasn't been performed. This is equivalent to the @code{EINTR} handling
20648on POSIX systems. In any other case, the target may presume that the
20649system call has been finished --- successful or not --- and should behave
20650as if the break message arrived right after the system call.
20651
20652@value{GDBN} must behave reliable. If the system call has not been called
20653yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
20654@code{errno} in the packet. If the system call on the host has been finished
20655before the user requests a break, the full action must be finshed by
20656@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
20657The @code{F} packet may only be send when either nothing has happened
20658or the full action has been completed.
20659
20660@node Console I/O
20661@subsection Console I/O
20662@cindex console i/o as part of file-i/o
20663
20664By default and if not explicitely closed by the target system, the file
20665descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
20666on the @value{GDBN} console is handled as any other file output operation
20667(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
20668by @value{GDBN} so that after the target read request from file descriptor
206690 all following typing is buffered until either one of the following
20670conditions is met:
20671
20672@itemize @bullet
20673@item
20674The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
20675@code{read}
20676system call is treated as finished.
20677
20678@item
20679The user presses @kbd{Enter}. This is treated as end of input with a trailing
20680line feed.
20681
20682@item
20683The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
20684character, especially no Ctrl-D is appended to the input.
20685
20686@end itemize
20687
20688If the user has typed more characters as fit in the buffer given to
20689the read call, the trailing characters are buffered in @value{GDBN} until
20690either another @code{read(0, @dots{})} is requested by the target or debugging
20691is stopped on users request.
20692
20693@node The isatty call
20694@subsection The isatty(3) call
20695@cindex isatty call, file-i/o protocol
20696
20697A special case in this protocol is the library call @code{isatty} which
20698is implemented as it's own call inside of this protocol. It returns
206991 to the target if the file descriptor given as parameter is attached
20700to the @value{GDBN} console, 0 otherwise. Implementing through system calls
20701would require implementing @code{ioctl} and would be more complex than
20702needed.
20703
20704@node The system call
20705@subsection The system(3) call
20706@cindex system call, file-i/o protocol
20707
20708The other special case in this protocol is the @code{system} call which
20709is implemented as it's own call, too. @value{GDBN} is taking over the full
20710task of calling the necessary host calls to perform the @code{system}
20711call. The return value of @code{system} is simplified before it's returned
20712to the target. Basically, the only signal transmitted back is @code{EINTR}
20713in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
20714entirely of the exit status of the called command.
20715
20716Due to security concerns, the @code{system} call is refused to be called
20717by @value{GDBN} by default. The user has to allow this call explicitly by
20718entering
20719
20720@table @samp
20721@kindex set remote system-call-allowed 1
20722@item @code{set remote system-call-allowed 1}
20723@end table
20724
20725Disabling the @code{system} call is done by
20726
20727@table @samp
20728@kindex set remote system-call-allowed 0
20729@item @code{set remote system-call-allowed 0}
20730@end table
20731
20732The current setting is shown by typing
20733
20734@table @samp
20735@kindex show remote system-call-allowed
20736@item @code{show remote system-call-allowed}
20737@end table
20738
20739@node List of supported calls
20740@subsection List of supported calls
20741@cindex list of supported file-i/o calls
20742
20743@menu
20744* open::
20745* close::
20746* read::
20747* write::
20748* lseek::
20749* rename::
20750* unlink::
20751* stat/fstat::
20752* gettimeofday::
20753* isatty::
20754* system::
20755@end menu
20756
20757@node open
20758@unnumberedsubsubsec open
20759@cindex open, file-i/o system call
20760
20761@smallexample
20762@exdent Synopsis:
20763int open(const char *pathname, int flags);
20764int open(const char *pathname, int flags, mode_t mode);
20765
20766@exdent Request:
20767Fopen,pathptr/len,flags,mode
20768@end smallexample
20769
20770@noindent
20771@code{flags} is the bitwise or of the following values:
20772
20773@table @code
20774@item O_CREAT
20775If the file does not exist it will be created. The host
20776rules apply as far as file ownership and time stamps
20777are concerned.
20778
20779@item O_EXCL
20780When used with O_CREAT, if the file already exists it is
20781an error and open() fails.
20782
20783@item O_TRUNC
20784If the file already exists and the open mode allows
20785writing (O_RDWR or O_WRONLY is given) it will be
20786truncated to length 0.
20787
20788@item O_APPEND
20789The file is opened in append mode.
20790
20791@item O_RDONLY
20792The file is opened for reading only.
20793
20794@item O_WRONLY
20795The file is opened for writing only.
20796
20797@item O_RDWR
20798The file is opened for reading and writing.
20799
20800@noindent
20801Each other bit is silently ignored.
20802
20803@end table
20804
20805@noindent
20806@code{mode} is the bitwise or of the following values:
20807
20808@table @code
20809@item S_IRUSR
20810User has read permission.
20811
20812@item S_IWUSR
20813User has write permission.
20814
20815@item S_IRGRP
20816Group has read permission.
20817
20818@item S_IWGRP
20819Group has write permission.
20820
20821@item S_IROTH
20822Others have read permission.
20823
20824@item S_IWOTH
20825Others have write permission.
20826
20827@noindent
20828Each other bit is silently ignored.
20829
20830@end table
20831
20832@smallexample
20833@exdent Return value:
20834open returns the new file descriptor or -1 if an error
20835occured.
20836
20837@exdent Errors:
20838@end smallexample
20839
20840@table @code
20841@item EEXIST
20842pathname already exists and O_CREAT and O_EXCL were used.
20843
20844@item EISDIR
20845pathname refers to a directory.
20846
20847@item EACCES
20848The requested access is not allowed.
20849
20850@item ENAMETOOLONG
20851pathname was too long.
20852
20853@item ENOENT
20854A directory component in pathname does not exist.
20855
20856@item ENODEV
20857pathname refers to a device, pipe, named pipe or socket.
20858
20859@item EROFS
20860pathname refers to a file on a read-only filesystem and
20861write access was requested.
20862
20863@item EFAULT
20864pathname is an invalid pointer value.
20865
20866@item ENOSPC
20867No space on device to create the file.
20868
20869@item EMFILE
20870The process already has the maximum number of files open.
20871
20872@item ENFILE
20873The limit on the total number of files open on the system
20874has been reached.
20875
20876@item EINTR
20877The call was interrupted by the user.
20878@end table
20879
20880@node close
20881@unnumberedsubsubsec close
20882@cindex close, file-i/o system call
20883
20884@smallexample
20885@exdent Synopsis:
20886int close(int fd);
20887
20888@exdent Request:
20889Fclose,fd
20890
20891@exdent Return value:
20892close returns zero on success, or -1 if an error occurred.
20893
20894@exdent Errors:
20895@end smallexample
20896
20897@table @code
20898@item EBADF
20899fd isn't a valid open file descriptor.
20900
20901@item EINTR
20902The call was interrupted by the user.
20903@end table
20904
20905@node read
20906@unnumberedsubsubsec read
20907@cindex read, file-i/o system call
20908
20909@smallexample
20910@exdent Synopsis:
20911int read(int fd, void *buf, unsigned int count);
20912
20913@exdent Request:
20914Fread,fd,bufptr,count
20915
20916@exdent Return value:
20917On success, the number of bytes read is returned.
20918Zero indicates end of file. If count is zero, read
20919returns zero as well. On error, -1 is returned.
20920
20921@exdent Errors:
20922@end smallexample
20923
20924@table @code
20925@item EBADF
20926fd is not a valid file descriptor or is not open for
20927reading.
20928
20929@item EFAULT
20930buf is an invalid pointer value.
20931
20932@item EINTR
20933The call was interrupted by the user.
20934@end table
20935
20936@node write
20937@unnumberedsubsubsec write
20938@cindex write, file-i/o system call
20939
20940@smallexample
20941@exdent Synopsis:
20942int write(int fd, const void *buf, unsigned int count);
20943
20944@exdent Request:
20945Fwrite,fd,bufptr,count
20946
20947@exdent Return value:
20948On success, the number of bytes written are returned.
20949Zero indicates nothing was written. On error, -1
20950is returned.
20951
20952@exdent Errors:
20953@end smallexample
20954
20955@table @code
20956@item EBADF
20957fd is not a valid file descriptor or is not open for
20958writing.
20959
20960@item EFAULT
20961buf is an invalid pointer value.
20962
20963@item EFBIG
20964An attempt was made to write a file that exceeds the
20965host specific maximum file size allowed.
20966
20967@item ENOSPC
20968No space on device to write the data.
20969
20970@item EINTR
20971The call was interrupted by the user.
20972@end table
20973
20974@node lseek
20975@unnumberedsubsubsec lseek
20976@cindex lseek, file-i/o system call
20977
20978@smallexample
20979@exdent Synopsis:
20980long lseek (int fd, long offset, int flag);
20981
20982@exdent Request:
20983Flseek,fd,offset,flag
20984@end smallexample
20985
20986@code{flag} is one of:
20987
20988@table @code
20989@item SEEK_SET
20990The offset is set to offset bytes.
20991
20992@item SEEK_CUR
20993The offset is set to its current location plus offset
20994bytes.
20995
20996@item SEEK_END
20997The offset is set to the size of the file plus offset
20998bytes.
20999@end table
21000
21001@smallexample
21002@exdent Return value:
21003On success, the resulting unsigned offset in bytes from
21004the beginning of the file is returned. Otherwise, a
21005value of -1 is returned.
21006
21007@exdent Errors:
21008@end smallexample
21009
21010@table @code
21011@item EBADF
21012fd is not a valid open file descriptor.
21013
21014@item ESPIPE
21015fd is associated with the @value{GDBN} console.
21016
21017@item EINVAL
21018flag is not a proper value.
21019
21020@item EINTR
21021The call was interrupted by the user.
21022@end table
21023
21024@node rename
21025@unnumberedsubsubsec rename
21026@cindex rename, file-i/o system call
21027
21028@smallexample
21029@exdent Synopsis:
21030int rename(const char *oldpath, const char *newpath);
21031
21032@exdent Request:
21033Frename,oldpathptr/len,newpathptr/len
21034
21035@exdent Return value:
21036On success, zero is returned. On error, -1 is returned.
21037
21038@exdent Errors:
21039@end smallexample
21040
21041@table @code
21042@item EISDIR
21043newpath is an existing directory, but oldpath is not a
21044directory.
21045
21046@item EEXIST
21047newpath is a non-empty directory.
21048
21049@item EBUSY
21050oldpath or newpath is a directory that is in use by some
21051process.
21052
21053@item EINVAL
21054An attempt was made to make a directory a subdirectory
21055of itself.
21056
21057@item ENOTDIR
21058A component used as a directory in oldpath or new
21059path is not a directory. Or oldpath is a directory
21060and newpath exists but is not a directory.
21061
21062@item EFAULT
21063oldpathptr or newpathptr are invalid pointer values.
21064
21065@item EACCES
21066No access to the file or the path of the file.
21067
21068@item ENAMETOOLONG
21069
21070oldpath or newpath was too long.
21071
21072@item ENOENT
21073A directory component in oldpath or newpath does not exist.
21074
21075@item EROFS
21076The file is on a read-only filesystem.
21077
21078@item ENOSPC
21079The device containing the file has no room for the new
21080directory entry.
21081
21082@item EINTR
21083The call was interrupted by the user.
21084@end table
21085
21086@node unlink
21087@unnumberedsubsubsec unlink
21088@cindex unlink, file-i/o system call
21089
21090@smallexample
21091@exdent Synopsis:
21092int unlink(const char *pathname);
21093
21094@exdent Request:
21095Funlink,pathnameptr/len
21096
21097@exdent Return value:
21098On success, zero is returned. On error, -1 is returned.
21099
21100@exdent Errors:
21101@end smallexample
21102
21103@table @code
21104@item EACCES
21105No access to the file or the path of the file.
21106
21107@item EPERM
21108The system does not allow unlinking of directories.
21109
21110@item EBUSY
21111The file pathname cannot be unlinked because it's
21112being used by another process.
21113
21114@item EFAULT
21115pathnameptr is an invalid pointer value.
21116
21117@item ENAMETOOLONG
21118pathname was too long.
21119
21120@item ENOENT
21121A directory component in pathname does not exist.
21122
21123@item ENOTDIR
21124A component of the path is not a directory.
21125
21126@item EROFS
21127The file is on a read-only filesystem.
21128
21129@item EINTR
21130The call was interrupted by the user.
21131@end table
21132
21133@node stat/fstat
21134@unnumberedsubsubsec stat/fstat
21135@cindex fstat, file-i/o system call
21136@cindex stat, file-i/o system call
21137
21138@smallexample
21139@exdent Synopsis:
21140int stat(const char *pathname, struct stat *buf);
21141int fstat(int fd, struct stat *buf);
21142
21143@exdent Request:
21144Fstat,pathnameptr/len,bufptr
21145Ffstat,fd,bufptr
21146
21147@exdent Return value:
21148On success, zero is returned. On error, -1 is returned.
21149
21150@exdent Errors:
21151@end smallexample
21152
21153@table @code
21154@item EBADF
21155fd is not a valid open file.
21156
21157@item ENOENT
21158A directory component in pathname does not exist or the
21159path is an empty string.
21160
21161@item ENOTDIR
21162A component of the path is not a directory.
21163
21164@item EFAULT
21165pathnameptr is an invalid pointer value.
21166
21167@item EACCES
21168No access to the file or the path of the file.
21169
21170@item ENAMETOOLONG
21171pathname was too long.
21172
21173@item EINTR
21174The call was interrupted by the user.
21175@end table
21176
21177@node gettimeofday
21178@unnumberedsubsubsec gettimeofday
21179@cindex gettimeofday, file-i/o system call
21180
21181@smallexample
21182@exdent Synopsis:
21183int gettimeofday(struct timeval *tv, void *tz);
21184
21185@exdent Request:
21186Fgettimeofday,tvptr,tzptr
21187
21188@exdent Return value:
21189On success, 0 is returned, -1 otherwise.
21190
21191@exdent Errors:
21192@end smallexample
21193
21194@table @code
21195@item EINVAL
21196tz is a non-NULL pointer.
21197
21198@item EFAULT
21199tvptr and/or tzptr is an invalid pointer value.
21200@end table
21201
21202@node isatty
21203@unnumberedsubsubsec isatty
21204@cindex isatty, file-i/o system call
21205
21206@smallexample
21207@exdent Synopsis:
21208int isatty(int fd);
21209
21210@exdent Request:
21211Fisatty,fd
21212
21213@exdent Return value:
21214Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
21215
21216@exdent Errors:
21217@end smallexample
21218
21219@table @code
21220@item EINTR
21221The call was interrupted by the user.
21222@end table
21223
21224@node system
21225@unnumberedsubsubsec system
21226@cindex system, file-i/o system call
21227
21228@smallexample
21229@exdent Synopsis:
21230int system(const char *command);
21231
21232@exdent Request:
21233Fsystem,commandptr/len
21234
21235@exdent Return value:
21236The value returned is -1 on error and the return status
21237of the command otherwise. Only the exit status of the
21238command is returned, which is extracted from the hosts
21239system return value by calling WEXITSTATUS(retval).
21240In case /bin/sh could not be executed, 127 is returned.
21241
21242@exdent Errors:
21243@end smallexample
21244
21245@table @code
21246@item EINTR
21247The call was interrupted by the user.
21248@end table
21249
21250@node Protocol specific representation of datatypes
21251@subsection Protocol specific representation of datatypes
21252@cindex protocol specific representation of datatypes, in file-i/o protocol
21253
21254@menu
21255* Integral datatypes::
21256* Pointer values::
21257* struct stat::
21258* struct timeval::
21259@end menu
21260
21261@node Integral datatypes
21262@unnumberedsubsubsec Integral datatypes
21263@cindex integral datatypes, in file-i/o protocol
21264
21265The integral datatypes used in the system calls are
21266
21267@smallexample
21268int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
21269@end smallexample
21270
21271@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
21272implemented as 32 bit values in this protocol.
21273
21274@code{Long} and @code{unsigned long} are implemented as 64 bit types.
21275
21276@xref{Limits}, for corresponding MIN and MAX values (similar to those
21277in @file{limits.h}) to allow range checking on host and target.
21278
21279@code{time_t} datatypes are defined as seconds since the Epoch.
21280
21281All integral datatypes transferred as part of a memory read or write of a
21282structured datatype e.g.@: a @code{struct stat} have to be given in big endian
21283byte order.
21284
21285@node Pointer values
21286@unnumberedsubsubsec Pointer values
21287@cindex pointer values, in file-i/o protocol
21288
21289Pointers to target data are transmitted as they are. An exception
21290is made for pointers to buffers for which the length isn't
21291transmitted as part of the function call, namely strings. Strings
21292are transmitted as a pointer/length pair, both as hex values, e.g.@:
21293
21294@smallexample
21295@code{1aaf/12}
21296@end smallexample
21297
21298@noindent
21299which is a pointer to data of length 18 bytes at position 0x1aaf.
21300The length is defined as the full string length in bytes, including
21301the trailing null byte. Example:
21302
21303@smallexample
21304``hello, world'' at address 0x123456
21305@end smallexample
21306
21307@noindent
21308is transmitted as
21309
21310@smallexample
21311@code{123456/d}
21312@end smallexample
21313
21314@node struct stat
21315@unnumberedsubsubsec struct stat
21316@cindex struct stat, in file-i/o protocol
21317
21318The buffer of type struct stat used by the target and @value{GDBN} is defined
21319as follows:
21320
21321@smallexample
21322struct stat @{
21323 unsigned int st_dev; /* device */
21324 unsigned int st_ino; /* inode */
21325 mode_t st_mode; /* protection */
21326 unsigned int st_nlink; /* number of hard links */
21327 unsigned int st_uid; /* user ID of owner */
21328 unsigned int st_gid; /* group ID of owner */
21329 unsigned int st_rdev; /* device type (if inode device) */
21330 unsigned long st_size; /* total size, in bytes */
21331 unsigned long st_blksize; /* blocksize for filesystem I/O */
21332 unsigned long st_blocks; /* number of blocks allocated */
21333 time_t st_atime; /* time of last access */
21334 time_t st_mtime; /* time of last modification */
21335 time_t st_ctime; /* time of last change */
21336@};
21337@end smallexample
21338
21339The integral datatypes are conforming to the definitions given in the
21340approriate section (see @ref{Integral datatypes}, for details) so this
21341structure is of size 64 bytes.
21342
21343The values of several fields have a restricted meaning and/or
21344range of values.
21345
21346@smallexample
21347st_dev: 0 file
21348 1 console
21349
21350st_ino: No valid meaning for the target. Transmitted unchanged.
21351
21352st_mode: Valid mode bits are described in Appendix C. Any other
21353 bits have currently no meaning for the target.
21354
21355st_uid: No valid meaning for the target. Transmitted unchanged.
21356
21357st_gid: No valid meaning for the target. Transmitted unchanged.
21358
21359st_rdev: No valid meaning for the target. Transmitted unchanged.
21360
21361st_atime, st_mtime, st_ctime:
21362 These values have a host and file system dependent
21363 accuracy. Especially on Windows hosts the file systems
21364 don't support exact timing values.
21365@end smallexample
21366
21367The target gets a struct stat of the above representation and is
21368responsible to coerce it to the target representation before
21369continuing.
21370
21371Note that due to size differences between the host and target
21372representation of stat members, these members could eventually
21373get truncated on the target.
21374
21375@node struct timeval
21376@unnumberedsubsubsec struct timeval
21377@cindex struct timeval, in file-i/o protocol
21378
21379The buffer of type struct timeval used by the target and @value{GDBN}
21380is defined as follows:
21381
21382@smallexample
21383struct timeval @{
21384 time_t tv_sec; /* second */
21385 long tv_usec; /* microsecond */
21386@};
21387@end smallexample
21388
21389The integral datatypes are conforming to the definitions given in the
21390approriate section (see @ref{Integral datatypes}, for details) so this
21391structure is of size 8 bytes.
21392
21393@node Constants
21394@subsection Constants
21395@cindex constants, in file-i/o protocol
21396
21397The following values are used for the constants inside of the
21398protocol. @value{GDBN} and target are resposible to translate these
21399values before and after the call as needed.
21400
21401@menu
21402* Open flags::
21403* mode_t values::
21404* Errno values::
21405* Lseek flags::
21406* Limits::
21407@end menu
21408
21409@node Open flags
21410@unnumberedsubsubsec Open flags
21411@cindex open flags, in file-i/o protocol
21412
21413All values are given in hexadecimal representation.
21414
21415@smallexample
21416 O_RDONLY 0x0
21417 O_WRONLY 0x1
21418 O_RDWR 0x2
21419 O_APPEND 0x8
21420 O_CREAT 0x200
21421 O_TRUNC 0x400
21422 O_EXCL 0x800
21423@end smallexample
21424
21425@node mode_t values
21426@unnumberedsubsubsec mode_t values
21427@cindex mode_t values, in file-i/o protocol
21428
21429All values are given in octal representation.
21430
21431@smallexample
21432 S_IFREG 0100000
21433 S_IFDIR 040000
21434 S_IRUSR 0400
21435 S_IWUSR 0200
21436 S_IXUSR 0100
21437 S_IRGRP 040
21438 S_IWGRP 020
21439 S_IXGRP 010
21440 S_IROTH 04
21441 S_IWOTH 02
21442 S_IXOTH 01
21443@end smallexample
21444
21445@node Errno values
21446@unnumberedsubsubsec Errno values
21447@cindex errno values, in file-i/o protocol
21448
21449All values are given in decimal representation.
21450
21451@smallexample
21452 EPERM 1
21453 ENOENT 2
21454 EINTR 4
21455 EBADF 9
21456 EACCES 13
21457 EFAULT 14
21458 EBUSY 16
21459 EEXIST 17
21460 ENODEV 19
21461 ENOTDIR 20
21462 EISDIR 21
21463 EINVAL 22
21464 ENFILE 23
21465 EMFILE 24
21466 EFBIG 27
21467 ENOSPC 28
21468 ESPIPE 29
21469 EROFS 30
21470 ENAMETOOLONG 91
21471 EUNKNOWN 9999
21472@end smallexample
21473
21474 EUNKNOWN is used as a fallback error value if a host system returns
21475 any error value not in the list of supported error numbers.
21476
21477@node Lseek flags
21478@unnumberedsubsubsec Lseek flags
21479@cindex lseek flags, in file-i/o protocol
21480
21481@smallexample
21482 SEEK_SET 0
21483 SEEK_CUR 1
21484 SEEK_END 2
21485@end smallexample
21486
21487@node Limits
21488@unnumberedsubsubsec Limits
21489@cindex limits, in file-i/o protocol
21490
21491All values are given in decimal representation.
21492
21493@smallexample
21494 INT_MIN -2147483648
21495 INT_MAX 2147483647
21496 UINT_MAX 4294967295
21497 LONG_MIN -9223372036854775808
21498 LONG_MAX 9223372036854775807
21499 ULONG_MAX 18446744073709551615
21500@end smallexample
21501
21502@node File-I/O Examples
21503@subsection File-I/O Examples
21504@cindex file-i/o examples
21505
21506Example sequence of a write call, file descriptor 3, buffer is at target
21507address 0x1234, 6 bytes should be written:
21508
21509@smallexample
21510<- @code{Fwrite,3,1234,6}
21511@emph{request memory read from target}
21512-> @code{m1234,6}
21513<- XXXXXX
21514@emph{return "6 bytes written"}
21515-> @code{F6}
21516@end smallexample
21517
21518Example sequence of a read call, file descriptor 3, buffer is at target
21519address 0x1234, 6 bytes should be read:
21520
21521@smallexample
21522<- @code{Fread,3,1234,6}
21523@emph{request memory write to target}
21524-> @code{X1234,6:XXXXXX}
21525@emph{return "6 bytes read"}
21526-> @code{F6}
21527@end smallexample
21528
21529Example sequence of a read call, call fails on the host due to invalid
21530file descriptor (EBADF):
21531
21532@smallexample
21533<- @code{Fread,3,1234,6}
21534-> @code{F-1,9}
21535@end smallexample
21536
21537Example sequence of a read call, user presses Ctrl-C before syscall on
21538host is called:
21539
21540@smallexample
21541<- @code{Fread,3,1234,6}
21542-> @code{F-1,4,C}
21543<- @code{T02}
21544@end smallexample
21545
21546Example sequence of a read call, user presses Ctrl-C after syscall on
21547host is called:
21548
21549@smallexample
21550<- @code{Fread,3,1234,6}
21551-> @code{X1234,6:XXXXXX}
21552<- @code{T02}
21553@end smallexample
21554
f418dd93
DJ
21555@include agentexpr.texi
21556
aab4e0ec 21557@include gpl.texi
eb12ee30 21558
6826cf00
EZ
21559@include fdl.texi
21560
6d2ebf8b 21561@node Index
c906108c
SS
21562@unnumbered Index
21563
21564@printindex cp
21565
21566@tex
21567% I think something like @colophon should be in texinfo. In the
21568% meantime:
21569\long\def\colophon{\hbox to0pt{}\vfill
21570\centerline{The body of this manual is set in}
21571\centerline{\fontname\tenrm,}
21572\centerline{with headings in {\bf\fontname\tenbf}}
21573\centerline{and examples in {\tt\fontname\tentt}.}
21574\centerline{{\it\fontname\tenit\/},}
21575\centerline{{\bf\fontname\tenbf}, and}
21576\centerline{{\sl\fontname\tensl\/}}
21577\centerline{are used for emphasis.}\vfill}
21578\page\colophon
21579% Blame: doc@cygnus.com, 1991.
21580@end tex
21581
c906108c 21582@bye