(M32R/D): Document "sdireset", "sdistatus", "debug_chaos",
[deliverable/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,
7d51c7de 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005
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.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The 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,@*
7d51c7de
BR
55 1999, 2000, 2001, 2002, 2003, 2004, 2005@*
56 Free Software Foundation, Inc.
c906108c 57
e9c75b65
EZ
58Permission is granted to copy, distribute and/or modify this document
59under the terms of the GNU Free Documentation License, Version 1.1 or
60any later version published by the Free Software Foundation; with the
959acfd1
EZ
61Invariant Sections being ``Free Software'' and ``Free Software Needs
62Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63and with the Back-Cover Texts as in (a) below.
c906108c 64
6826cf00
EZ
65(a) The Free Software Foundation's Back-Cover Text is: ``You have
66freedom to copy and modify this GNU Manual, like GNU software. Copies
67published by the Free Software Foundation raise funds for GNU
68development.''
c906108c
SS
69@end ifinfo
70
71@titlepage
72@title Debugging with @value{GDBN}
73@subtitle The @sc{gnu} Source-Level Debugger
c906108c 74@sp 1
c906108c 75@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 76@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 77@page
c906108c
SS
78@tex
79{\parskip=0pt
53a5351d 80\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
81\hfill {\it Debugging with @value{GDBN}}\par
82\hfill \TeX{}info \texinfoversion\par
83}
84@end tex
53a5351d 85
c906108c 86@vskip 0pt plus 1filll
8a037dd7 87Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
7d51c7de
BR
881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b 94ISBN 1-882114-77-9 @*
e9c75b65
EZ
95
96Permission is granted to copy, distribute and/or modify this document
97under the terms of the GNU Free Documentation License, Version 1.1 or
98any later version published by the Free Software Foundation; with the
959acfd1
EZ
99Invariant Sections being ``Free Software'' and ``Free Software Needs
100Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101and with the Back-Cover Texts as in (a) below.
e9c75b65 102
6826cf00
EZ
103(a) The Free Software Foundation's Back-Cover Text is: ``You have
104freedom to copy and modify this GNU Manual, like GNU software. Copies
105published by the Free Software Foundation raise funds for GNU
106development.''
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
9fe8321b 117This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
7d51c7de 120Copyright (C) 1988-2005 Free Software Foundation, Inc.
6d2ebf8b
SS
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
e2e0bcd1 133* Macros:: Preprocessor Macros
b37052ae 134* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 135* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
6b2f586d 143* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
144* Configurations:: Configuration-specific information
145* Controlling GDB:: Controlling @value{GDBN}
146* Sequences:: Canned sequences of commands
c4555f82 147* TUI:: @value{GDBN} Text User Interface
21c294e6 148* Interpreters:: Command Interpreters
6d2ebf8b
SS
149* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 151* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
152
153* GDB Bugs:: Reporting bugs in @value{GDBN}
154* Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156* Command Line Editing:: Command Line Editing
157* Using History Interactively:: Using History Interactively
158* Installing GDB:: Installing GDB
eb12ee30 159* Maintenance Commands:: Maintenance Commands
e0ce93ac 160* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 161* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
162* Copying:: GNU General Public License says
163 how you can copy and share GDB
6826cf00 164* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
165* Index:: Index
166@end menu
167
6c0e9fb3 168@end ifnottex
c906108c 169
449f3b6c 170@contents
449f3b6c 171
6d2ebf8b 172@node Summary
c906108c
SS
173@unnumbered Summary of @value{GDBN}
174
175The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176going on ``inside'' another program while it executes---or what another
177program was doing at the moment it crashed.
178
179@value{GDBN} can do four main kinds of things (plus other things in support of
180these) to help you catch bugs in the act:
181
182@itemize @bullet
183@item
184Start your program, specifying anything that might affect its behavior.
185
186@item
187Make your program stop on specified conditions.
188
189@item
190Examine what has happened, when your program has stopped.
191
192@item
193Change things in your program, so you can experiment with correcting the
194effects of one bug and go on to learn about another.
195@end itemize
196
49efadf5 197You can use @value{GDBN} to debug programs written in C and C@t{++}.
9c16f35a 198For more information, see @ref{Supported languages,,Supported languages}.
c906108c
SS
199For more information, see @ref{C,,C and C++}.
200
cce74817 201@cindex Modula-2
e632838e
AC
202Support for Modula-2 is partial. For information on Modula-2, see
203@ref{Modula-2,,Modula-2}.
c906108c 204
cce74817
JM
205@cindex Pascal
206Debugging Pascal programs which use sets, subranges, file variables, or
207nested functions does not currently work. @value{GDBN} does not support
208entering expressions, printing values, or similar features using Pascal
209syntax.
c906108c 210
c906108c
SS
211@cindex Fortran
212@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 213it may be necessary to refer to some variables with a trailing
cce74817 214underscore.
c906108c 215
b37303ee
AF
216@value{GDBN} can be used to debug programs written in Objective-C,
217using either the Apple/NeXT or the GNU Objective-C runtime.
218
c906108c
SS
219@menu
220* Free Software:: Freely redistributable software
221* Contributors:: Contributors to GDB
222@end menu
223
6d2ebf8b 224@node Free Software
c906108c
SS
225@unnumberedsec Free software
226
5d161b24 227@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
228General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
237you have these freedoms and that you cannot take these freedoms away
238from anyone else.
239
2666264b 240@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
241
242The biggest deficiency in the free software community today is not in
243the software---it is the lack of good free documentation that we can
244include with the free software. Many of our most important
245programs do not come with free reference manuals and free introductory
246texts. Documentation is an essential part of any software package;
247when an important free software package does not come with a free
248manual and a free tutorial, that is a major gap. We have many such
249gaps today.
250
251Consider Perl, for instance. The tutorial manuals that people
252normally use are non-free. How did this come about? Because the
253authors of those manuals published them with restrictive terms---no
254copying, no modification, source files not available---which exclude
255them from the free software world.
256
257That wasn't the first time this sort of thing happened, and it was far
258from the last. Many times we have heard a GNU user eagerly describe a
259manual that he is writing, his intended contribution to the community,
260only to learn that he had ruined everything by signing a publication
261contract to make it non-free.
262
263Free documentation, like free software, is a matter of freedom, not
264price. The problem with the non-free manual is not that publishers
265charge a price for printed copies---that in itself is fine. (The Free
266Software Foundation sells printed copies of manuals, too.) The
267problem is the restrictions on the use of the manual. Free manuals
268are available in source code form, and give you permission to copy and
269modify. Non-free manuals do not allow this.
270
271The criteria of freedom for a free manual are roughly the same as for
272free software. Redistribution (including the normal kinds of
273commercial redistribution) must be permitted, so that the manual can
274accompany every copy of the program, both on-line and on paper.
275
276Permission for modification of the technical content is crucial too.
277When people modify the software, adding or changing features, if they
278are conscientious they will change the manual too---so they can
279provide accurate and clear documentation for the modified program. A
280manual that leaves you no choice but to write a new manual to document
281a changed version of the program is not really available to our
282community.
283
284Some kinds of limits on the way modification is handled are
285acceptable. For example, requirements to preserve the original
286author's copyright notice, the distribution terms, or the list of
287authors, are ok. It is also no problem to require modified versions
288to include notice that they were modified. Even entire sections that
289may not be deleted or changed are acceptable, as long as they deal
290with nontechnical topics (like this one). These kinds of restrictions
291are acceptable because they don't obstruct the community's normal use
292of the manual.
293
294However, it must be possible to modify all the @emph{technical}
295content of the manual, and then distribute the result in all the usual
296media, through all the usual channels. Otherwise, the restrictions
297obstruct the use of the manual, it is not free, and we need another
298manual to replace it.
299
300Please spread the word about this issue. Our community continues to
301lose manuals to proprietary publishing. If we spread the word that
302free software needs free reference manuals and free tutorials, perhaps
303the next person who wants to contribute by writing documentation will
304realize, before it is too late, that only free manuals contribute to
305the free software community.
306
307If you are writing documentation, please insist on publishing it under
308the GNU Free Documentation License or another free documentation
309license. Remember that this decision requires your approval---you
310don't have to let the publisher decide. Some commercial publishers
311will use a free license if you insist, but they will not propose the
312option; it is up to you to raise the issue and say firmly that this is
313what you want. If the publisher you are dealing with refuses, please
314try other publishers. If you're not sure whether a proposed license
42584a72 315is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
316
317You can encourage commercial publishers to sell more free, copylefted
318manuals and tutorials by buying them, and particularly by buying
319copies from the publishers that paid for their writing or for major
320improvements. Meanwhile, try to avoid buying non-free documentation
321at all. Check the distribution terms of a manual before you buy it,
322and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
323Check the history of the book, and try to reward the publishers that
324have paid or pay the authors to work on it.
959acfd1
EZ
325
326The Free Software Foundation maintains a list of free documentation
327published by other publishers, at
328@url{http://www.fsf.org/doc/other-free-books.html}.
329
6d2ebf8b 330@node Contributors
96a2c332
SS
331@unnumberedsec Contributors to @value{GDBN}
332
333Richard Stallman was the original author of @value{GDBN}, and of many
334other @sc{gnu} programs. Many others have contributed to its
335development. This section attempts to credit major contributors. One
336of the virtues of free software is that everyone is free to contribute
337to it; with regret, we cannot actually acknowledge everyone here. The
338file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
339blow-by-blow account.
340
341Changes much prior to version 2.0 are lost in the mists of time.
342
343@quotation
344@emph{Plea:} Additions to this section are particularly welcome. If you
345or your friends (or enemies, to be evenhanded) have been unfairly
346omitted from this list, we would like to add your names!
347@end quotation
348
349So that they may not regard their many labors as thankless, we
350particularly thank those who shepherded @value{GDBN} through major
351releases:
faae5abe 352Andrew Cagney (releases 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
353Jim Blandy (release 4.18);
354Jason Molenda (release 4.17);
355Stan Shebs (release 4.14);
356Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
357Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
358John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
359Jim Kingdon (releases 3.5, 3.4, and 3.3);
360and Randy Smith (releases 3.2, 3.1, and 3.0).
361
362Richard Stallman, assisted at various times by Peter TerMaat, Chris
363Hanson, and Richard Mlynarik, handled releases through 2.8.
364
b37052ae
EZ
365Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
366in @value{GDBN}, with significant additional contributions from Per
367Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
368demangler. Early work on C@t{++} was by Peter TerMaat (who also did
369much general update work leading to release 3.0).
c906108c 370
b37052ae 371@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
372object-file formats; BFD was a joint project of David V.
373Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
374
375David Johnson wrote the original COFF support; Pace Willison did
376the original support for encapsulated COFF.
377
0179ffac 378Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
379
380Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
381Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
382support.
383Jean-Daniel Fekete contributed Sun 386i support.
384Chris Hanson improved the HP9000 support.
385Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
386David Johnson contributed Encore Umax support.
387Jyrki Kuoppala contributed Altos 3068 support.
388Jeff Law contributed HP PA and SOM support.
389Keith Packard contributed NS32K support.
390Doug Rabson contributed Acorn Risc Machine support.
391Bob Rusk contributed Harris Nighthawk CX-UX support.
392Chris Smith contributed Convex support (and Fortran debugging).
393Jonathan Stone contributed Pyramid support.
394Michael Tiemann contributed SPARC support.
395Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
396Pace Willison contributed Intel 386 support.
397Jay Vosburgh contributed Symmetry support.
a37295f9 398Marko Mlinar contributed OpenRISC 1000 support.
c906108c 399
1104b9e7 400Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
401
402Rich Schaefer and Peter Schauer helped with support of SunOS shared
403libraries.
404
405Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
406about several machine instruction sets.
407
408Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
409remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
410contributed remote debugging modules for the i960, VxWorks, A29K UDI,
411and RDI targets, respectively.
412
413Brian Fox is the author of the readline libraries providing
414command-line editing and command history.
415
7a292a7a
SS
416Andrew Beers of SUNY Buffalo wrote the language-switching code, the
417Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 418
5d161b24 419Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 420He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 421symbols.
c906108c 422
f24c5e49
KI
423Hitachi America (now Renesas America), Ltd. sponsored the support for
424H8/300, H8/500, and Super-H processors.
c906108c
SS
425
426NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
427
f24c5e49
KI
428Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
429processors.
c906108c
SS
430
431Toshiba sponsored the support for the TX39 Mips processor.
432
433Matsushita sponsored the support for the MN10200 and MN10300 processors.
434
96a2c332 435Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
436
437Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
438watchpoints.
439
440Michael Snyder added support for tracepoints.
441
442Stu Grossman wrote gdbserver.
443
444Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 445nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
446
447The following people at the Hewlett-Packard Company contributed
448support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 449(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
450compiler, and the Text User Interface (nee Terminal User Interface):
451Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
452Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
453provided HP-specific information in this manual.
c906108c 454
b37052ae
EZ
455DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
456Robert Hoehne made significant contributions to the DJGPP port.
457
96a2c332
SS
458Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
459development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
460fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
461Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
462Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
463Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
464Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
465addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
466JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
467Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
468Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
469Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
470Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
471Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
472Zuhn have made contributions both large and small.
c906108c 473
e2e0bcd1
JB
474Jim Blandy added support for preprocessor macros, while working for Red
475Hat.
c906108c 476
6d2ebf8b 477@node Sample Session
c906108c
SS
478@chapter A Sample @value{GDBN} Session
479
480You can use this manual at your leisure to read all about @value{GDBN}.
481However, a handful of commands are enough to get started using the
482debugger. This chapter illustrates those commands.
483
484@iftex
485In this sample session, we emphasize user input like this: @b{input},
486to make it easier to pick out from the surrounding output.
487@end iftex
488
489@c FIXME: this example may not be appropriate for some configs, where
490@c FIXME...primary interest is in remote use.
491
492One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
493processor) exhibits the following bug: sometimes, when we change its
494quote strings from the default, the commands used to capture one macro
495definition within another stop working. In the following short @code{m4}
496session, we define a macro @code{foo} which expands to @code{0000}; we
497then use the @code{m4} built-in @code{defn} to define @code{bar} as the
498same thing. However, when we change the open quote string to
499@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
500procedure fails to define a new synonym @code{baz}:
501
502@smallexample
503$ @b{cd gnu/m4}
504$ @b{./m4}
505@b{define(foo,0000)}
506
507@b{foo}
5080000
509@b{define(bar,defn(`foo'))}
510
511@b{bar}
5120000
513@b{changequote(<QUOTE>,<UNQUOTE>)}
514
515@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
516@b{baz}
517@b{C-d}
518m4: End of input: 0: fatal error: EOF in string
519@end smallexample
520
521@noindent
522Let us use @value{GDBN} to try to see what is going on.
523
c906108c
SS
524@smallexample
525$ @b{@value{GDBP} m4}
526@c FIXME: this falsifies the exact text played out, to permit smallbook
527@c FIXME... format to come out better.
528@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 529 of it under certain conditions; type "show copying" to see
c906108c 530 the conditions.
5d161b24 531There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
532 for details.
533
534@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
535(@value{GDBP})
536@end smallexample
c906108c
SS
537
538@noindent
539@value{GDBN} reads only enough symbol data to know where to find the
540rest when needed; as a result, the first prompt comes up very quickly.
541We now tell @value{GDBN} to use a narrower display width than usual, so
542that examples fit in this manual.
543
544@smallexample
545(@value{GDBP}) @b{set width 70}
546@end smallexample
547
548@noindent
549We need to see how the @code{m4} built-in @code{changequote} works.
550Having looked at the source, we know the relevant subroutine is
551@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
552@code{break} command.
553
554@smallexample
555(@value{GDBP}) @b{break m4_changequote}
556Breakpoint 1 at 0x62f4: file builtin.c, line 879.
557@end smallexample
558
559@noindent
560Using the @code{run} command, we start @code{m4} running under @value{GDBN}
561control; as long as control does not reach the @code{m4_changequote}
562subroutine, the program runs as usual:
563
564@smallexample
565(@value{GDBP}) @b{run}
566Starting program: /work/Editorial/gdb/gnu/m4/m4
567@b{define(foo,0000)}
568
569@b{foo}
5700000
571@end smallexample
572
573@noindent
574To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
575suspends execution of @code{m4}, displaying information about the
576context where it stops.
577
578@smallexample
579@b{changequote(<QUOTE>,<UNQUOTE>)}
580
5d161b24 581Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
582 at builtin.c:879
583879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
584@end smallexample
585
586@noindent
587Now we use the command @code{n} (@code{next}) to advance execution to
588the next line of the current function.
589
590@smallexample
591(@value{GDBP}) @b{n}
592882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
593 : nil,
594@end smallexample
595
596@noindent
597@code{set_quotes} looks like a promising subroutine. We can go into it
598by using the command @code{s} (@code{step}) instead of @code{next}.
599@code{step} goes to the next line to be executed in @emph{any}
600subroutine, so it steps into @code{set_quotes}.
601
602@smallexample
603(@value{GDBP}) @b{s}
604set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
605 at input.c:530
606530 if (lquote != def_lquote)
607@end smallexample
608
609@noindent
610The display that shows the subroutine where @code{m4} is now
611suspended (and its arguments) is called a stack frame display. It
612shows a summary of the stack. We can use the @code{backtrace}
613command (which can also be spelled @code{bt}), to see where we are
614in the stack as a whole: the @code{backtrace} command displays a
615stack frame for each active subroutine.
616
617@smallexample
618(@value{GDBP}) @b{bt}
619#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
620 at input.c:530
5d161b24 621#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
622 at builtin.c:882
623#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
624#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
625 at macro.c:71
626#4 0x79dc in expand_input () at macro.c:40
627#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
628@end smallexample
629
630@noindent
631We step through a few more lines to see what happens. The first two
632times, we can use @samp{s}; the next two times we use @code{n} to avoid
633falling into the @code{xstrdup} subroutine.
634
635@smallexample
636(@value{GDBP}) @b{s}
6370x3b5c 532 if (rquote != def_rquote)
638(@value{GDBP}) @b{s}
6390x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
640def_lquote : xstrdup(lq);
641(@value{GDBP}) @b{n}
642536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
643 : xstrdup(rq);
644(@value{GDBP}) @b{n}
645538 len_lquote = strlen(rquote);
646@end smallexample
647
648@noindent
649The last line displayed looks a little odd; we can examine the variables
650@code{lquote} and @code{rquote} to see if they are in fact the new left
651and right quotes we specified. We use the command @code{p}
652(@code{print}) to see their values.
653
654@smallexample
655(@value{GDBP}) @b{p lquote}
656$1 = 0x35d40 "<QUOTE>"
657(@value{GDBP}) @b{p rquote}
658$2 = 0x35d50 "<UNQUOTE>"
659@end smallexample
660
661@noindent
662@code{lquote} and @code{rquote} are indeed the new left and right quotes.
663To look at some context, we can display ten lines of source
664surrounding the current line with the @code{l} (@code{list}) command.
665
666@smallexample
667(@value{GDBP}) @b{l}
668533 xfree(rquote);
669534
670535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
671 : xstrdup (lq);
672536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
673 : xstrdup (rq);
674537
675538 len_lquote = strlen(rquote);
676539 len_rquote = strlen(lquote);
677540 @}
678541
679542 void
680@end smallexample
681
682@noindent
683Let us step past the two lines that set @code{len_lquote} and
684@code{len_rquote}, and then examine the values of those variables.
685
686@smallexample
687(@value{GDBP}) @b{n}
688539 len_rquote = strlen(lquote);
689(@value{GDBP}) @b{n}
690540 @}
691(@value{GDBP}) @b{p len_lquote}
692$3 = 9
693(@value{GDBP}) @b{p len_rquote}
694$4 = 7
695@end smallexample
696
697@noindent
698That certainly looks wrong, assuming @code{len_lquote} and
699@code{len_rquote} are meant to be the lengths of @code{lquote} and
700@code{rquote} respectively. We can set them to better values using
701the @code{p} command, since it can print the value of
702any expression---and that expression can include subroutine calls and
703assignments.
704
705@smallexample
706(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
707$5 = 7
708(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
709$6 = 9
710@end smallexample
711
712@noindent
713Is that enough to fix the problem of using the new quotes with the
714@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
715executing with the @code{c} (@code{continue}) command, and then try the
716example that caused trouble initially:
717
718@smallexample
719(@value{GDBP}) @b{c}
720Continuing.
721
722@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
723
724baz
7250000
726@end smallexample
727
728@noindent
729Success! The new quotes now work just as well as the default ones. The
730problem seems to have been just the two typos defining the wrong
731lengths. We allow @code{m4} exit by giving it an EOF as input:
732
733@smallexample
734@b{C-d}
735Program exited normally.
736@end smallexample
737
738@noindent
739The message @samp{Program exited normally.} is from @value{GDBN}; it
740indicates @code{m4} has finished executing. We can end our @value{GDBN}
741session with the @value{GDBN} @code{quit} command.
742
743@smallexample
744(@value{GDBP}) @b{quit}
745@end smallexample
c906108c 746
6d2ebf8b 747@node Invocation
c906108c
SS
748@chapter Getting In and Out of @value{GDBN}
749
750This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 751The essentials are:
c906108c 752@itemize @bullet
5d161b24 753@item
53a5351d 754type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 755@item
c906108c
SS
756type @kbd{quit} or @kbd{C-d} to exit.
757@end itemize
758
759@menu
760* Invoking GDB:: How to start @value{GDBN}
761* Quitting GDB:: How to quit @value{GDBN}
762* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 763* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
764@end menu
765
6d2ebf8b 766@node Invoking GDB
c906108c
SS
767@section Invoking @value{GDBN}
768
c906108c
SS
769Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
770@value{GDBN} reads commands from the terminal until you tell it to exit.
771
772You can also run @code{@value{GDBP}} with a variety of arguments and options,
773to specify more of your debugging environment at the outset.
774
c906108c
SS
775The command-line options described here are designed
776to cover a variety of situations; in some environments, some of these
5d161b24 777options may effectively be unavailable.
c906108c
SS
778
779The most usual way to start @value{GDBN} is with one argument,
780specifying an executable program:
781
474c8240 782@smallexample
c906108c 783@value{GDBP} @var{program}
474c8240 784@end smallexample
c906108c 785
c906108c
SS
786@noindent
787You can also start with both an executable program and a core file
788specified:
789
474c8240 790@smallexample
c906108c 791@value{GDBP} @var{program} @var{core}
474c8240 792@end smallexample
c906108c
SS
793
794You can, instead, specify a process ID as a second argument, if you want
795to debug a running process:
796
474c8240 797@smallexample
c906108c 798@value{GDBP} @var{program} 1234
474c8240 799@end smallexample
c906108c
SS
800
801@noindent
802would attach @value{GDBN} to process @code{1234} (unless you also have a file
803named @file{1234}; @value{GDBN} does check for a core file first).
804
c906108c 805Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
806complete operating system; when you use @value{GDBN} as a remote
807debugger attached to a bare board, there may not be any notion of
808``process'', and there is often no way to get a core dump. @value{GDBN}
809will warn you if it is unable to attach or to read core dumps.
c906108c 810
aa26fa3a
TT
811You can optionally have @code{@value{GDBP}} pass any arguments after the
812executable file to the inferior using @code{--args}. This option stops
813option processing.
474c8240 814@smallexample
aa26fa3a 815gdb --args gcc -O2 -c foo.c
474c8240 816@end smallexample
aa26fa3a
TT
817This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
818@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
819
96a2c332 820You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
821@value{GDBN}'s non-warranty, by specifying @code{-silent}:
822
823@smallexample
824@value{GDBP} -silent
825@end smallexample
826
827@noindent
828You can further control how @value{GDBN} starts up by using command-line
829options. @value{GDBN} itself can remind you of the options available.
830
831@noindent
832Type
833
474c8240 834@smallexample
c906108c 835@value{GDBP} -help
474c8240 836@end smallexample
c906108c
SS
837
838@noindent
839to display all available options and briefly describe their use
840(@samp{@value{GDBP} -h} is a shorter equivalent).
841
842All options and command line arguments you give are processed
843in sequential order. The order makes a difference when the
844@samp{-x} option is used.
845
846
847@menu
c906108c
SS
848* File Options:: Choosing files
849* Mode Options:: Choosing modes
850@end menu
851
6d2ebf8b 852@node File Options
c906108c
SS
853@subsection Choosing files
854
2df3850c 855When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
856specifying an executable file and core file (or process ID). This is
857the same as if the arguments were specified by the @samp{-se} and
19837790
MS
858@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
859first argument that does not have an associated option flag as
860equivalent to the @samp{-se} option followed by that argument; and the
861second argument that does not have an associated option flag, if any, as
862equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
863If the second argument begins with a decimal digit, @value{GDBN} will
864first attempt to attach to it as a process, and if that fails, attempt
865to open it as a corefile. If you have a corefile whose name begins with
b383017d 866a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 867prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
868
869If @value{GDBN} has not been configured to included core file support,
870such as for most embedded targets, then it will complain about a second
871argument and ignore it.
c906108c
SS
872
873Many options have both long and short forms; both are shown in the
874following list. @value{GDBN} also recognizes the long forms if you truncate
875them, so long as enough of the option is present to be unambiguous.
876(If you prefer, you can flag option arguments with @samp{--} rather
877than @samp{-}, though we illustrate the more usual convention.)
878
d700128c
EZ
879@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
880@c way, both those who look for -foo and --foo in the index, will find
881@c it.
882
c906108c
SS
883@table @code
884@item -symbols @var{file}
885@itemx -s @var{file}
d700128c
EZ
886@cindex @code{--symbols}
887@cindex @code{-s}
c906108c
SS
888Read symbol table from file @var{file}.
889
890@item -exec @var{file}
891@itemx -e @var{file}
d700128c
EZ
892@cindex @code{--exec}
893@cindex @code{-e}
7a292a7a
SS
894Use file @var{file} as the executable file to execute when appropriate,
895and for examining pure data in conjunction with a core dump.
c906108c
SS
896
897@item -se @var{file}
d700128c 898@cindex @code{--se}
c906108c
SS
899Read symbol table from file @var{file} and use it as the executable
900file.
901
c906108c
SS
902@item -core @var{file}
903@itemx -c @var{file}
d700128c
EZ
904@cindex @code{--core}
905@cindex @code{-c}
b383017d 906Use file @var{file} as a core dump to examine.
c906108c
SS
907
908@item -c @var{number}
19837790
MS
909@item -pid @var{number}
910@itemx -p @var{number}
911@cindex @code{--pid}
912@cindex @code{-p}
913Connect to process ID @var{number}, as with the @code{attach} command.
914If there is no such process, @value{GDBN} will attempt to open a core
915file named @var{number}.
c906108c
SS
916
917@item -command @var{file}
918@itemx -x @var{file}
d700128c
EZ
919@cindex @code{--command}
920@cindex @code{-x}
c906108c
SS
921Execute @value{GDBN} commands from file @var{file}. @xref{Command
922Files,, Command files}.
923
924@item -directory @var{directory}
925@itemx -d @var{directory}
d700128c
EZ
926@cindex @code{--directory}
927@cindex @code{-d}
c906108c
SS
928Add @var{directory} to the path to search for source files.
929
c906108c
SS
930@item -m
931@itemx -mapped
d700128c
EZ
932@cindex @code{--mapped}
933@cindex @code{-m}
c906108c
SS
934@emph{Warning: this option depends on operating system facilities that are not
935supported on all systems.}@*
936If memory-mapped files are available on your system through the @code{mmap}
5d161b24 937system call, you can use this option
c906108c
SS
938to have @value{GDBN} write the symbols from your
939program into a reusable file in the current directory. If the program you are debugging is
96a2c332 940called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
941Future @value{GDBN} debugging sessions notice the presence of this file,
942and can quickly map in symbol information from it, rather than reading
943the symbol table from the executable program.
944
945The @file{.syms} file is specific to the host machine where @value{GDBN}
946is run. It holds an exact image of the internal @value{GDBN} symbol
947table. It cannot be shared across multiple host platforms.
c906108c 948
c906108c
SS
949@item -r
950@itemx -readnow
d700128c
EZ
951@cindex @code{--readnow}
952@cindex @code{-r}
c906108c
SS
953Read each symbol file's entire symbol table immediately, rather than
954the default, which is to read it incrementally as it is needed.
955This makes startup slower, but makes future operations faster.
53a5351d 956
c906108c
SS
957@end table
958
2df3850c 959You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 960order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
961information. (@xref{Files,,Commands to specify files}, for information
962on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
963but build a @file{.syms} file for future use is:
c906108c 964
474c8240 965@smallexample
2df3850c 966gdb -batch -nx -mapped -readnow programname
474c8240 967@end smallexample
c906108c 968
6d2ebf8b 969@node Mode Options
c906108c
SS
970@subsection Choosing modes
971
972You can run @value{GDBN} in various alternative modes---for example, in
973batch mode or quiet mode.
974
975@table @code
976@item -nx
977@itemx -n
d700128c
EZ
978@cindex @code{--nx}
979@cindex @code{-n}
96565e91 980Do not execute commands found in any initialization files. Normally,
2df3850c
JM
981@value{GDBN} executes the commands in these files after all the command
982options and arguments have been processed. @xref{Command Files,,Command
983files}.
c906108c
SS
984
985@item -quiet
d700128c 986@itemx -silent
c906108c 987@itemx -q
d700128c
EZ
988@cindex @code{--quiet}
989@cindex @code{--silent}
990@cindex @code{-q}
c906108c
SS
991``Quiet''. Do not print the introductory and copyright messages. These
992messages are also suppressed in batch mode.
993
994@item -batch
d700128c 995@cindex @code{--batch}
c906108c
SS
996Run in batch mode. Exit with status @code{0} after processing all the
997command files specified with @samp{-x} (and all commands from
998initialization files, if not inhibited with @samp{-n}). Exit with
999nonzero status if an error occurs in executing the @value{GDBN} commands
1000in the command files.
1001
2df3850c
JM
1002Batch mode may be useful for running @value{GDBN} as a filter, for
1003example to download and run a program on another computer; in order to
1004make this more useful, the message
c906108c 1005
474c8240 1006@smallexample
c906108c 1007Program exited normally.
474c8240 1008@end smallexample
c906108c
SS
1009
1010@noindent
2df3850c
JM
1011(which is ordinarily issued whenever a program running under
1012@value{GDBN} control terminates) is not issued when running in batch
1013mode.
1014
1015@item -nowindows
1016@itemx -nw
d700128c
EZ
1017@cindex @code{--nowindows}
1018@cindex @code{-nw}
2df3850c 1019``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1020(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1021interface. If no GUI is available, this option has no effect.
1022
1023@item -windows
1024@itemx -w
d700128c
EZ
1025@cindex @code{--windows}
1026@cindex @code{-w}
2df3850c
JM
1027If @value{GDBN} includes a GUI, then this option requires it to be
1028used if possible.
c906108c
SS
1029
1030@item -cd @var{directory}
d700128c 1031@cindex @code{--cd}
c906108c
SS
1032Run @value{GDBN} using @var{directory} as its working directory,
1033instead of the current directory.
1034
c906108c
SS
1035@item -fullname
1036@itemx -f
d700128c
EZ
1037@cindex @code{--fullname}
1038@cindex @code{-f}
7a292a7a
SS
1039@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1040subprocess. It tells @value{GDBN} to output the full file name and line
1041number in a standard, recognizable fashion each time a stack frame is
1042displayed (which includes each time your program stops). This
1043recognizable format looks like two @samp{\032} characters, followed by
1044the file name, line number and character position separated by colons,
1045and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1046@samp{\032} characters as a signal to display the source code for the
1047frame.
c906108c 1048
d700128c
EZ
1049@item -epoch
1050@cindex @code{--epoch}
1051The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1052@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1053routines so as to allow Epoch to display values of expressions in a
1054separate window.
1055
1056@item -annotate @var{level}
1057@cindex @code{--annotate}
1058This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1059effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1060(@pxref{Annotations}). The annotation @var{level} controls how much
1061information @value{GDBN} prints together with its prompt, values of
1062expressions, source lines, and other types of output. Level 0 is the
1063normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1064@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1065that control @value{GDBN}, and level 2 has been deprecated.
1066
1067The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1068(@pxref{GDB/MI}).
d700128c 1069
aa26fa3a
TT
1070@item --args
1071@cindex @code{--args}
1072Change interpretation of command line so that arguments following the
1073executable file are passed as command line arguments to the inferior.
1074This option stops option processing.
1075
2df3850c
JM
1076@item -baud @var{bps}
1077@itemx -b @var{bps}
d700128c
EZ
1078@cindex @code{--baud}
1079@cindex @code{-b}
c906108c
SS
1080Set the line speed (baud rate or bits per second) of any serial
1081interface used by @value{GDBN} for remote debugging.
c906108c 1082
f47b1503
AS
1083@item -l @var{timeout}
1084@cindex @code{-l}
1085Set the timeout (in seconds) of any communication used by @value{GDBN}
1086for remote debugging.
1087
c906108c 1088@item -tty @var{device}
d700128c
EZ
1089@itemx -t @var{device}
1090@cindex @code{--tty}
1091@cindex @code{-t}
c906108c
SS
1092Run using @var{device} for your program's standard input and output.
1093@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1094
53a5351d 1095@c resolve the situation of these eventually
c4555f82
SC
1096@item -tui
1097@cindex @code{--tui}
d0d5df6f
AC
1098Activate the @dfn{Text User Interface} when starting. The Text User
1099Interface manages several text windows on the terminal, showing
1100source, assembly, registers and @value{GDBN} command outputs
1101(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1102Text User Interface can be enabled by invoking the program
1103@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1104Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1105
1106@c @item -xdb
d700128c 1107@c @cindex @code{--xdb}
53a5351d
JM
1108@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1109@c For information, see the file @file{xdb_trans.html}, which is usually
1110@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1111@c systems.
1112
d700128c
EZ
1113@item -interpreter @var{interp}
1114@cindex @code{--interpreter}
1115Use the interpreter @var{interp} for interface with the controlling
1116program or device. This option is meant to be set by programs which
94bbb2c0 1117communicate with @value{GDBN} using it as a back end.
21c294e6 1118@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1119
da0f9dcd 1120@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1121@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6c74ac8b
AC
1122The @sc{gdb/mi} Interface}) included since @var{GDBN} version 6.0. The
1123previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1124selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1125@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1126
1127@item -write
1128@cindex @code{--write}
1129Open the executable and core files for both reading and writing. This
1130is equivalent to the @samp{set write on} command inside @value{GDBN}
1131(@pxref{Patching}).
1132
1133@item -statistics
1134@cindex @code{--statistics}
1135This option causes @value{GDBN} to print statistics about time and
1136memory usage after it completes each command and returns to the prompt.
1137
1138@item -version
1139@cindex @code{--version}
1140This option causes @value{GDBN} to print its version number and
1141no-warranty blurb, and exit.
1142
c906108c
SS
1143@end table
1144
6d2ebf8b 1145@node Quitting GDB
c906108c
SS
1146@section Quitting @value{GDBN}
1147@cindex exiting @value{GDBN}
1148@cindex leaving @value{GDBN}
1149
1150@table @code
1151@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1152@kindex q @r{(@code{quit})}
96a2c332
SS
1153@item quit @r{[}@var{expression}@r{]}
1154@itemx q
1155To exit @value{GDBN}, use the @code{quit} command (abbreviated
1156@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1157do not supply @var{expression}, @value{GDBN} will terminate normally;
1158otherwise it will terminate using the result of @var{expression} as the
1159error code.
c906108c
SS
1160@end table
1161
1162@cindex interrupt
1163An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1164terminates the action of any @value{GDBN} command that is in progress and
1165returns to @value{GDBN} command level. It is safe to type the interrupt
1166character at any time because @value{GDBN} does not allow it to take effect
1167until a time when it is safe.
1168
c906108c
SS
1169If you have been using @value{GDBN} to control an attached process or
1170device, you can release it with the @code{detach} command
1171(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1172
6d2ebf8b 1173@node Shell Commands
c906108c
SS
1174@section Shell commands
1175
1176If you need to execute occasional shell commands during your
1177debugging session, there is no need to leave or suspend @value{GDBN}; you can
1178just use the @code{shell} command.
1179
1180@table @code
1181@kindex shell
1182@cindex shell escape
1183@item shell @var{command string}
1184Invoke a standard shell to execute @var{command string}.
c906108c 1185If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1186shell to run. Otherwise @value{GDBN} uses the default shell
1187(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1188@end table
1189
1190The utility @code{make} is often needed in development environments.
1191You do not have to use the @code{shell} command for this purpose in
1192@value{GDBN}:
1193
1194@table @code
1195@kindex make
1196@cindex calling make
1197@item make @var{make-args}
1198Execute the @code{make} program with the specified
1199arguments. This is equivalent to @samp{shell make @var{make-args}}.
1200@end table
1201
0fac0b41
DJ
1202@node Logging output
1203@section Logging output
1204@cindex logging @value{GDBN} output
9c16f35a 1205@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1206
1207You may want to save the output of @value{GDBN} commands to a file.
1208There are several commands to control @value{GDBN}'s logging.
1209
1210@table @code
1211@kindex set logging
1212@item set logging on
1213Enable logging.
1214@item set logging off
1215Disable logging.
9c16f35a 1216@cindex logging file name
0fac0b41
DJ
1217@item set logging file @var{file}
1218Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1219@item set logging overwrite [on|off]
1220By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1221you want @code{set logging on} to overwrite the logfile instead.
1222@item set logging redirect [on|off]
1223By default, @value{GDBN} output will go to both the terminal and the logfile.
1224Set @code{redirect} if you want output to go only to the log file.
1225@kindex show logging
1226@item show logging
1227Show the current values of the logging settings.
1228@end table
1229
6d2ebf8b 1230@node Commands
c906108c
SS
1231@chapter @value{GDBN} Commands
1232
1233You can abbreviate a @value{GDBN} command to the first few letters of the command
1234name, if that abbreviation is unambiguous; and you can repeat certain
1235@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1236key to get @value{GDBN} to fill out the rest of a word in a command (or to
1237show you the alternatives available, if there is more than one possibility).
1238
1239@menu
1240* Command Syntax:: How to give commands to @value{GDBN}
1241* Completion:: Command completion
1242* Help:: How to ask @value{GDBN} for help
1243@end menu
1244
6d2ebf8b 1245@node Command Syntax
c906108c
SS
1246@section Command syntax
1247
1248A @value{GDBN} command is a single line of input. There is no limit on
1249how long it can be. It starts with a command name, which is followed by
1250arguments whose meaning depends on the command name. For example, the
1251command @code{step} accepts an argument which is the number of times to
1252step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1253with no arguments. Some commands do not allow any arguments.
c906108c
SS
1254
1255@cindex abbreviation
1256@value{GDBN} command names may always be truncated if that abbreviation is
1257unambiguous. Other possible command abbreviations are listed in the
1258documentation for individual commands. In some cases, even ambiguous
1259abbreviations are allowed; for example, @code{s} is specially defined as
1260equivalent to @code{step} even though there are other commands whose
1261names start with @code{s}. You can test abbreviations by using them as
1262arguments to the @code{help} command.
1263
1264@cindex repeating commands
41afff9a 1265@kindex RET @r{(repeat last command)}
c906108c 1266A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1267repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1268will not repeat this way; these are commands whose unintentional
1269repetition might cause trouble and which you are unlikely to want to
1270repeat.
1271
1272The @code{list} and @code{x} commands, when you repeat them with
1273@key{RET}, construct new arguments rather than repeating
1274exactly as typed. This permits easy scanning of source or memory.
1275
1276@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1277output, in a way similar to the common utility @code{more}
1278(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1279@key{RET} too many in this situation, @value{GDBN} disables command
1280repetition after any command that generates this sort of display.
1281
41afff9a 1282@kindex # @r{(a comment)}
c906108c
SS
1283@cindex comment
1284Any text from a @kbd{#} to the end of the line is a comment; it does
1285nothing. This is useful mainly in command files (@pxref{Command
1286Files,,Command files}).
1287
88118b3a
TT
1288@cindex repeating command sequences
1289@kindex C-o @r{(operate-and-get-next)}
1290The @kbd{C-o} binding is useful for repeating a complex sequence of
1291commands. This command accepts the current line, like @kbd{RET}, and
1292then fetches the next line relative to the current line from the history
1293for editing.
1294
6d2ebf8b 1295@node Completion
c906108c
SS
1296@section Command completion
1297
1298@cindex completion
1299@cindex word completion
1300@value{GDBN} can fill in the rest of a word in a command for you, if there is
1301only one possibility; it can also show you what the valid possibilities
1302are for the next word in a command, at any time. This works for @value{GDBN}
1303commands, @value{GDBN} subcommands, and the names of symbols in your program.
1304
1305Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1306of a word. If there is only one possibility, @value{GDBN} fills in the
1307word, and waits for you to finish the command (or press @key{RET} to
1308enter it). For example, if you type
1309
1310@c FIXME "@key" does not distinguish its argument sufficiently to permit
1311@c complete accuracy in these examples; space introduced for clarity.
1312@c If texinfo enhancements make it unnecessary, it would be nice to
1313@c replace " @key" by "@key" in the following...
474c8240 1314@smallexample
c906108c 1315(@value{GDBP}) info bre @key{TAB}
474c8240 1316@end smallexample
c906108c
SS
1317
1318@noindent
1319@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1320the only @code{info} subcommand beginning with @samp{bre}:
1321
474c8240 1322@smallexample
c906108c 1323(@value{GDBP}) info breakpoints
474c8240 1324@end smallexample
c906108c
SS
1325
1326@noindent
1327You can either press @key{RET} at this point, to run the @code{info
1328breakpoints} command, or backspace and enter something else, if
1329@samp{breakpoints} does not look like the command you expected. (If you
1330were sure you wanted @code{info breakpoints} in the first place, you
1331might as well just type @key{RET} immediately after @samp{info bre},
1332to exploit command abbreviations rather than command completion).
1333
1334If there is more than one possibility for the next word when you press
1335@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1336characters and try again, or just press @key{TAB} a second time;
1337@value{GDBN} displays all the possible completions for that word. For
1338example, you might want to set a breakpoint on a subroutine whose name
1339begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1340just sounds the bell. Typing @key{TAB} again displays all the
1341function names in your program that begin with those characters, for
1342example:
1343
474c8240 1344@smallexample
c906108c
SS
1345(@value{GDBP}) b make_ @key{TAB}
1346@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1347make_a_section_from_file make_environ
1348make_abs_section make_function_type
1349make_blockvector make_pointer_type
1350make_cleanup make_reference_type
c906108c
SS
1351make_command make_symbol_completion_list
1352(@value{GDBP}) b make_
474c8240 1353@end smallexample
c906108c
SS
1354
1355@noindent
1356After displaying the available possibilities, @value{GDBN} copies your
1357partial input (@samp{b make_} in the example) so you can finish the
1358command.
1359
1360If you just want to see the list of alternatives in the first place, you
b37052ae 1361can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1362means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1363key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1364one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1365
1366@cindex quotes in commands
1367@cindex completion of quoted strings
1368Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1369parentheses or other characters that @value{GDBN} normally excludes from
1370its notion of a word. To permit word completion to work in this
1371situation, you may enclose words in @code{'} (single quote marks) in
1372@value{GDBN} commands.
c906108c 1373
c906108c 1374The most likely situation where you might need this is in typing the
b37052ae
EZ
1375name of a C@t{++} function. This is because C@t{++} allows function
1376overloading (multiple definitions of the same function, distinguished
1377by argument type). For example, when you want to set a breakpoint you
1378may need to distinguish whether you mean the version of @code{name}
1379that takes an @code{int} parameter, @code{name(int)}, or the version
1380that takes a @code{float} parameter, @code{name(float)}. To use the
1381word-completion facilities in this situation, type a single quote
1382@code{'} at the beginning of the function name. This alerts
1383@value{GDBN} that it may need to consider more information than usual
1384when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1385
474c8240 1386@smallexample
96a2c332 1387(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1388bubble(double,double) bubble(int,int)
1389(@value{GDBP}) b 'bubble(
474c8240 1390@end smallexample
c906108c
SS
1391
1392In some cases, @value{GDBN} can tell that completing a name requires using
1393quotes. When this happens, @value{GDBN} inserts the quote for you (while
1394completing as much as it can) if you do not type the quote in the first
1395place:
1396
474c8240 1397@smallexample
c906108c
SS
1398(@value{GDBP}) b bub @key{TAB}
1399@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1400(@value{GDBP}) b 'bubble(
474c8240 1401@end smallexample
c906108c
SS
1402
1403@noindent
1404In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1405you have not yet started typing the argument list when you ask for
1406completion on an overloaded symbol.
1407
d4f3574e 1408For more information about overloaded functions, see @ref{C plus plus
b37052ae 1409expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1410overload-resolution off} to disable overload resolution;
b37052ae 1411see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1412
1413
6d2ebf8b 1414@node Help
c906108c
SS
1415@section Getting help
1416@cindex online documentation
1417@kindex help
1418
5d161b24 1419You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1420using the command @code{help}.
1421
1422@table @code
41afff9a 1423@kindex h @r{(@code{help})}
c906108c
SS
1424@item help
1425@itemx h
1426You can use @code{help} (abbreviated @code{h}) with no arguments to
1427display a short list of named classes of commands:
1428
1429@smallexample
1430(@value{GDBP}) help
1431List of classes of commands:
1432
2df3850c 1433aliases -- Aliases of other commands
c906108c 1434breakpoints -- Making program stop at certain points
2df3850c 1435data -- Examining data
c906108c 1436files -- Specifying and examining files
2df3850c
JM
1437internals -- Maintenance commands
1438obscure -- Obscure features
1439running -- Running the program
1440stack -- Examining the stack
c906108c
SS
1441status -- Status inquiries
1442support -- Support facilities
96a2c332
SS
1443tracepoints -- Tracing of program execution without@*
1444 stopping the program
c906108c 1445user-defined -- User-defined commands
c906108c 1446
5d161b24 1447Type "help" followed by a class name for a list of
c906108c 1448commands in that class.
5d161b24 1449Type "help" followed by command name for full
c906108c
SS
1450documentation.
1451Command name abbreviations are allowed if unambiguous.
1452(@value{GDBP})
1453@end smallexample
96a2c332 1454@c the above line break eliminates huge line overfull...
c906108c
SS
1455
1456@item help @var{class}
1457Using one of the general help classes as an argument, you can get a
1458list of the individual commands in that class. For example, here is the
1459help display for the class @code{status}:
1460
1461@smallexample
1462(@value{GDBP}) help status
1463Status inquiries.
1464
1465List of commands:
1466
1467@c Line break in "show" line falsifies real output, but needed
1468@c to fit in smallbook page size.
2df3850c
JM
1469info -- Generic command for showing things
1470 about the program being debugged
1471show -- Generic command for showing things
1472 about the debugger
c906108c 1473
5d161b24 1474Type "help" followed by command name for full
c906108c
SS
1475documentation.
1476Command name abbreviations are allowed if unambiguous.
1477(@value{GDBP})
1478@end smallexample
1479
1480@item help @var{command}
1481With a command name as @code{help} argument, @value{GDBN} displays a
1482short paragraph on how to use that command.
1483
6837a0a2
DB
1484@kindex apropos
1485@item apropos @var{args}
09d4efe1 1486The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1487commands, and their documentation, for the regular expression specified in
1488@var{args}. It prints out all matches found. For example:
1489
1490@smallexample
1491apropos reload
1492@end smallexample
1493
b37052ae
EZ
1494@noindent
1495results in:
6837a0a2
DB
1496
1497@smallexample
6d2ebf8b
SS
1498@c @group
1499set symbol-reloading -- Set dynamic symbol table reloading
1500 multiple times in one run
1501show symbol-reloading -- Show dynamic symbol table reloading
1502 multiple times in one run
1503@c @end group
6837a0a2
DB
1504@end smallexample
1505
c906108c
SS
1506@kindex complete
1507@item complete @var{args}
1508The @code{complete @var{args}} command lists all the possible completions
1509for the beginning of a command. Use @var{args} to specify the beginning of the
1510command you want completed. For example:
1511
1512@smallexample
1513complete i
1514@end smallexample
1515
1516@noindent results in:
1517
1518@smallexample
1519@group
2df3850c
JM
1520if
1521ignore
c906108c
SS
1522info
1523inspect
c906108c
SS
1524@end group
1525@end smallexample
1526
1527@noindent This is intended for use by @sc{gnu} Emacs.
1528@end table
1529
1530In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1531and @code{show} to inquire about the state of your program, or the state
1532of @value{GDBN} itself. Each command supports many topics of inquiry; this
1533manual introduces each of them in the appropriate context. The listings
1534under @code{info} and under @code{show} in the Index point to
1535all the sub-commands. @xref{Index}.
1536
1537@c @group
1538@table @code
1539@kindex info
41afff9a 1540@kindex i @r{(@code{info})}
c906108c
SS
1541@item info
1542This command (abbreviated @code{i}) is for describing the state of your
1543program. For example, you can list the arguments given to your program
1544with @code{info args}, list the registers currently in use with @code{info
1545registers}, or list the breakpoints you have set with @code{info breakpoints}.
1546You can get a complete list of the @code{info} sub-commands with
1547@w{@code{help info}}.
1548
1549@kindex set
1550@item set
5d161b24 1551You can assign the result of an expression to an environment variable with
c906108c
SS
1552@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1553@code{set prompt $}.
1554
1555@kindex show
1556@item show
5d161b24 1557In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1558@value{GDBN} itself.
1559You can change most of the things you can @code{show}, by using the
1560related command @code{set}; for example, you can control what number
1561system is used for displays with @code{set radix}, or simply inquire
1562which is currently in use with @code{show radix}.
1563
1564@kindex info set
1565To display all the settable parameters and their current
1566values, you can use @code{show} with no arguments; you may also use
1567@code{info set}. Both commands produce the same display.
1568@c FIXME: "info set" violates the rule that "info" is for state of
1569@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1570@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1571@end table
1572@c @end group
1573
1574Here are three miscellaneous @code{show} subcommands, all of which are
1575exceptional in lacking corresponding @code{set} commands:
1576
1577@table @code
1578@kindex show version
9c16f35a 1579@cindex @value{GDBN} version number
c906108c
SS
1580@item show version
1581Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1582information in @value{GDBN} bug-reports. If multiple versions of
1583@value{GDBN} are in use at your site, you may need to determine which
1584version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1585commands are introduced, and old ones may wither away. Also, many
1586system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1587variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1588The version number is the same as the one announced when you start
1589@value{GDBN}.
c906108c
SS
1590
1591@kindex show copying
09d4efe1 1592@kindex info copying
9c16f35a 1593@cindex display @value{GDBN} copyright
c906108c 1594@item show copying
09d4efe1 1595@itemx info copying
c906108c
SS
1596Display information about permission for copying @value{GDBN}.
1597
1598@kindex show warranty
09d4efe1 1599@kindex info warranty
c906108c 1600@item show warranty
09d4efe1 1601@itemx info warranty
2df3850c 1602Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1603if your version of @value{GDBN} comes with one.
2df3850c 1604
c906108c
SS
1605@end table
1606
6d2ebf8b 1607@node Running
c906108c
SS
1608@chapter Running Programs Under @value{GDBN}
1609
1610When you run a program under @value{GDBN}, you must first generate
1611debugging information when you compile it.
7a292a7a
SS
1612
1613You may start @value{GDBN} with its arguments, if any, in an environment
1614of your choice. If you are doing native debugging, you may redirect
1615your program's input and output, debug an already running process, or
1616kill a child process.
c906108c
SS
1617
1618@menu
1619* Compilation:: Compiling for debugging
1620* Starting:: Starting your program
c906108c
SS
1621* Arguments:: Your program's arguments
1622* Environment:: Your program's environment
c906108c
SS
1623
1624* Working Directory:: Your program's working directory
1625* Input/Output:: Your program's input and output
1626* Attach:: Debugging an already-running process
1627* Kill Process:: Killing the child process
c906108c
SS
1628
1629* Threads:: Debugging programs with multiple threads
1630* Processes:: Debugging programs with multiple processes
1631@end menu
1632
6d2ebf8b 1633@node Compilation
c906108c
SS
1634@section Compiling for debugging
1635
1636In order to debug a program effectively, you need to generate
1637debugging information when you compile it. This debugging information
1638is stored in the object file; it describes the data type of each
1639variable or function and the correspondence between source line numbers
1640and addresses in the executable code.
1641
1642To request debugging information, specify the @samp{-g} option when you run
1643the compiler.
1644
e2e0bcd1
JB
1645Most compilers do not include information about preprocessor macros in
1646the debugging information if you specify the @option{-g} flag alone,
1647because this information is rather large. Version 3.1 of @value{NGCC},
1648the @sc{gnu} C compiler, provides macro information if you specify the
1649options @option{-gdwarf-2} and @option{-g3}; the former option requests
1650debugging information in the Dwarf 2 format, and the latter requests
1651``extra information''. In the future, we hope to find more compact ways
1652to represent macro information, so that it can be included with
1653@option{-g} alone.
1654
c906108c
SS
1655Many C compilers are unable to handle the @samp{-g} and @samp{-O}
1656options together. Using those compilers, you cannot generate optimized
1657executables containing debugging information.
1658
53a5351d
JM
1659@value{NGCC}, the @sc{gnu} C compiler, supports @samp{-g} with or
1660without @samp{-O}, making it possible to debug optimized code. We
1661recommend that you @emph{always} use @samp{-g} whenever you compile a
1662program. You may think your program is correct, but there is no sense
1663in pushing your luck.
c906108c
SS
1664
1665@cindex optimized code, debugging
1666@cindex debugging optimized code
1667When you debug a program compiled with @samp{-g -O}, remember that the
1668optimizer is rearranging your code; the debugger shows you what is
1669really there. Do not be too surprised when the execution path does not
1670exactly match your source file! An extreme example: if you define a
1671variable, but never use it, @value{GDBN} never sees that
1672variable---because the compiler optimizes it out of existence.
1673
1674Some things do not work as well with @samp{-g -O} as with just
1675@samp{-g}, particularly on machines with instruction scheduling. If in
1676doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1677please report it to us as a bug (including a test case!).
15387254 1678@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1679
1680Older versions of the @sc{gnu} C compiler permitted a variant option
1681@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1682format; if your @sc{gnu} C compiler has this option, do not use it.
1683
1684@need 2000
6d2ebf8b 1685@node Starting
c906108c
SS
1686@section Starting your program
1687@cindex starting
1688@cindex running
1689
1690@table @code
1691@kindex run
41afff9a 1692@kindex r @r{(@code{run})}
c906108c
SS
1693@item run
1694@itemx r
7a292a7a
SS
1695Use the @code{run} command to start your program under @value{GDBN}.
1696You must first specify the program name (except on VxWorks) with an
1697argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1698@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1699(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1700
1701@end table
1702
c906108c
SS
1703If you are running your program in an execution environment that
1704supports processes, @code{run} creates an inferior process and makes
1705that process run your program. (In environments without processes,
1706@code{run} jumps to the start of your program.)
1707
1708The execution of a program is affected by certain information it
1709receives from its superior. @value{GDBN} provides ways to specify this
1710information, which you must do @emph{before} starting your program. (You
1711can change it after starting your program, but such changes only affect
1712your program the next time you start it.) This information may be
1713divided into four categories:
1714
1715@table @asis
1716@item The @emph{arguments.}
1717Specify the arguments to give your program as the arguments of the
1718@code{run} command. If a shell is available on your target, the shell
1719is used to pass the arguments, so that you may use normal conventions
1720(such as wildcard expansion or variable substitution) in describing
1721the arguments.
1722In Unix systems, you can control which shell is used with the
1723@code{SHELL} environment variable.
1724@xref{Arguments, ,Your program's arguments}.
1725
1726@item The @emph{environment.}
1727Your program normally inherits its environment from @value{GDBN}, but you can
1728use the @value{GDBN} commands @code{set environment} and @code{unset
1729environment} to change parts of the environment that affect
1730your program. @xref{Environment, ,Your program's environment}.
1731
1732@item The @emph{working directory.}
1733Your program inherits its working directory from @value{GDBN}. You can set
1734the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1735@xref{Working Directory, ,Your program's working directory}.
1736
1737@item The @emph{standard input and output.}
1738Your program normally uses the same device for standard input and
1739standard output as @value{GDBN} is using. You can redirect input and output
1740in the @code{run} command line, or you can use the @code{tty} command to
1741set a different device for your program.
1742@xref{Input/Output, ,Your program's input and output}.
1743
1744@cindex pipes
1745@emph{Warning:} While input and output redirection work, you cannot use
1746pipes to pass the output of the program you are debugging to another
1747program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1748wrong program.
1749@end table
c906108c
SS
1750
1751When you issue the @code{run} command, your program begins to execute
1752immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1753of how to arrange for your program to stop. Once your program has
1754stopped, you may call functions in your program, using the @code{print}
1755or @code{call} commands. @xref{Data, ,Examining Data}.
1756
1757If the modification time of your symbol file has changed since the last
1758time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1759table, and reads it again. When it does this, @value{GDBN} tries to retain
1760your current breakpoints.
1761
4e8b0763
JB
1762@table @code
1763@kindex start
1764@item start
1765@cindex run to main procedure
1766The name of the main procedure can vary from language to language.
1767With C or C@t{++}, the main procedure name is always @code{main}, but
1768other languages such as Ada do not require a specific name for their
1769main procedure. The debugger provides a convenient way to start the
1770execution of the program and to stop at the beginning of the main
1771procedure, depending on the language used.
1772
1773The @samp{start} command does the equivalent of setting a temporary
1774breakpoint at the beginning of the main procedure and then invoking
1775the @samp{run} command.
1776
f018e82f
EZ
1777@cindex elaboration phase
1778Some programs contain an @dfn{elaboration} phase where some startup code is
1779executed before the main procedure is called. This depends on the
1780languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1781constructors for static and global objects are executed before
1782@code{main} is called. It is therefore possible that the debugger stops
1783before reaching the main procedure. However, the temporary breakpoint
1784will remain to halt execution.
1785
1786Specify the arguments to give to your program as arguments to the
1787@samp{start} command. These arguments will be given verbatim to the
1788underlying @samp{run} command. Note that the same arguments will be
1789reused if no argument is provided during subsequent calls to
1790@samp{start} or @samp{run}.
1791
1792It is sometimes necessary to debug the program during elaboration. In
1793these cases, using the @code{start} command would stop the execution of
1794your program too late, as the program would have already completed the
1795elaboration phase. Under these circumstances, insert breakpoints in your
1796elaboration code before running your program.
1797@end table
1798
6d2ebf8b 1799@node Arguments
c906108c
SS
1800@section Your program's arguments
1801
1802@cindex arguments (to your program)
1803The arguments to your program can be specified by the arguments of the
5d161b24 1804@code{run} command.
c906108c
SS
1805They are passed to a shell, which expands wildcard characters and
1806performs redirection of I/O, and thence to your program. Your
1807@code{SHELL} environment variable (if it exists) specifies what shell
1808@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1809the default shell (@file{/bin/sh} on Unix).
1810
1811On non-Unix systems, the program is usually invoked directly by
1812@value{GDBN}, which emulates I/O redirection via the appropriate system
1813calls, and the wildcard characters are expanded by the startup code of
1814the program, not by the shell.
c906108c
SS
1815
1816@code{run} with no arguments uses the same arguments used by the previous
1817@code{run}, or those set by the @code{set args} command.
1818
c906108c 1819@table @code
41afff9a 1820@kindex set args
c906108c
SS
1821@item set args
1822Specify the arguments to be used the next time your program is run. If
1823@code{set args} has no arguments, @code{run} executes your program
1824with no arguments. Once you have run your program with arguments,
1825using @code{set args} before the next @code{run} is the only way to run
1826it again without arguments.
1827
1828@kindex show args
1829@item show args
1830Show the arguments to give your program when it is started.
1831@end table
1832
6d2ebf8b 1833@node Environment
c906108c
SS
1834@section Your program's environment
1835
1836@cindex environment (of your program)
1837The @dfn{environment} consists of a set of environment variables and
1838their values. Environment variables conventionally record such things as
1839your user name, your home directory, your terminal type, and your search
1840path for programs to run. Usually you set up environment variables with
1841the shell and they are inherited by all the other programs you run. When
1842debugging, it can be useful to try running your program with a modified
1843environment without having to start @value{GDBN} over again.
1844
1845@table @code
1846@kindex path
1847@item path @var{directory}
1848Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1849(the search path for executables) that will be passed to your program.
1850The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1851You may specify several directory names, separated by whitespace or by a
1852system-dependent separator character (@samp{:} on Unix, @samp{;} on
1853MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1854is moved to the front, so it is searched sooner.
c906108c
SS
1855
1856You can use the string @samp{$cwd} to refer to whatever is the current
1857working directory at the time @value{GDBN} searches the path. If you
1858use @samp{.} instead, it refers to the directory where you executed the
1859@code{path} command. @value{GDBN} replaces @samp{.} in the
1860@var{directory} argument (with the current path) before adding
1861@var{directory} to the search path.
1862@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1863@c document that, since repeating it would be a no-op.
1864
1865@kindex show paths
1866@item show paths
1867Display the list of search paths for executables (the @code{PATH}
1868environment variable).
1869
1870@kindex show environment
1871@item show environment @r{[}@var{varname}@r{]}
1872Print the value of environment variable @var{varname} to be given to
1873your program when it starts. If you do not supply @var{varname},
1874print the names and values of all environment variables to be given to
1875your program. You can abbreviate @code{environment} as @code{env}.
1876
1877@kindex set environment
53a5351d 1878@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1879Set environment variable @var{varname} to @var{value}. The value
1880changes for your program only, not for @value{GDBN} itself. @var{value} may
1881be any string; the values of environment variables are just strings, and
1882any interpretation is supplied by your program itself. The @var{value}
1883parameter is optional; if it is eliminated, the variable is set to a
1884null value.
1885@c "any string" here does not include leading, trailing
1886@c blanks. Gnu asks: does anyone care?
1887
1888For example, this command:
1889
474c8240 1890@smallexample
c906108c 1891set env USER = foo
474c8240 1892@end smallexample
c906108c
SS
1893
1894@noindent
d4f3574e 1895tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1896@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1897are not actually required.)
1898
1899@kindex unset environment
1900@item unset environment @var{varname}
1901Remove variable @var{varname} from the environment to be passed to your
1902program. This is different from @samp{set env @var{varname} =};
1903@code{unset environment} removes the variable from the environment,
1904rather than assigning it an empty value.
1905@end table
1906
d4f3574e
SS
1907@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1908the shell indicated
c906108c
SS
1909by your @code{SHELL} environment variable if it exists (or
1910@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1911that runs an initialization file---such as @file{.cshrc} for C-shell, or
1912@file{.bashrc} for BASH---any variables you set in that file affect
1913your program. You may wish to move setting of environment variables to
1914files that are only run when you sign on, such as @file{.login} or
1915@file{.profile}.
1916
6d2ebf8b 1917@node Working Directory
c906108c
SS
1918@section Your program's working directory
1919
1920@cindex working directory (of your program)
1921Each time you start your program with @code{run}, it inherits its
1922working directory from the current working directory of @value{GDBN}.
1923The @value{GDBN} working directory is initially whatever it inherited
1924from its parent process (typically the shell), but you can specify a new
1925working directory in @value{GDBN} with the @code{cd} command.
1926
1927The @value{GDBN} working directory also serves as a default for the commands
1928that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1929specify files}.
1930
1931@table @code
1932@kindex cd
721c2651 1933@cindex change working directory
c906108c
SS
1934@item cd @var{directory}
1935Set the @value{GDBN} working directory to @var{directory}.
1936
1937@kindex pwd
1938@item pwd
1939Print the @value{GDBN} working directory.
1940@end table
1941
60bf7e09
EZ
1942It is generally impossible to find the current working directory of
1943the process being debugged (since a program can change its directory
1944during its run). If you work on a system where @value{GDBN} is
1945configured with the @file{/proc} support, you can use the @code{info
1946proc} command (@pxref{SVR4 Process Information}) to find out the
1947current working directory of the debuggee.
1948
6d2ebf8b 1949@node Input/Output
c906108c
SS
1950@section Your program's input and output
1951
1952@cindex redirection
1953@cindex i/o
1954@cindex terminal
1955By default, the program you run under @value{GDBN} does input and output to
5d161b24 1956the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
1957to its own terminal modes to interact with you, but it records the terminal
1958modes your program was using and switches back to them when you continue
1959running your program.
1960
1961@table @code
1962@kindex info terminal
1963@item info terminal
1964Displays information recorded by @value{GDBN} about the terminal modes your
1965program is using.
1966@end table
1967
1968You can redirect your program's input and/or output using shell
1969redirection with the @code{run} command. For example,
1970
474c8240 1971@smallexample
c906108c 1972run > outfile
474c8240 1973@end smallexample
c906108c
SS
1974
1975@noindent
1976starts your program, diverting its output to the file @file{outfile}.
1977
1978@kindex tty
1979@cindex controlling terminal
1980Another way to specify where your program should do input and output is
1981with the @code{tty} command. This command accepts a file name as
1982argument, and causes this file to be the default for future @code{run}
1983commands. It also resets the controlling terminal for the child
1984process, for future @code{run} commands. For example,
1985
474c8240 1986@smallexample
c906108c 1987tty /dev/ttyb
474c8240 1988@end smallexample
c906108c
SS
1989
1990@noindent
1991directs that processes started with subsequent @code{run} commands
1992default to do input and output on the terminal @file{/dev/ttyb} and have
1993that as their controlling terminal.
1994
1995An explicit redirection in @code{run} overrides the @code{tty} command's
1996effect on the input/output device, but not its effect on the controlling
1997terminal.
1998
1999When you use the @code{tty} command or redirect input in the @code{run}
2000command, only the input @emph{for your program} is affected. The input
2001for @value{GDBN} still comes from your terminal.
2002
6d2ebf8b 2003@node Attach
c906108c
SS
2004@section Debugging an already-running process
2005@kindex attach
2006@cindex attach
2007
2008@table @code
2009@item attach @var{process-id}
2010This command attaches to a running process---one that was started
2011outside @value{GDBN}. (@code{info files} shows your active
2012targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2013find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2014or with the @samp{jobs -l} shell command.
2015
2016@code{attach} does not repeat if you press @key{RET} a second time after
2017executing the command.
2018@end table
2019
2020To use @code{attach}, your program must be running in an environment
2021which supports processes; for example, @code{attach} does not work for
2022programs on bare-board targets that lack an operating system. You must
2023also have permission to send the process a signal.
2024
2025When you use @code{attach}, the debugger finds the program running in
2026the process first by looking in the current working directory, then (if
2027the program is not found) by using the source file search path
2028(@pxref{Source Path, ,Specifying source directories}). You can also use
2029the @code{file} command to load the program. @xref{Files, ,Commands to
2030Specify Files}.
2031
2032The first thing @value{GDBN} does after arranging to debug the specified
2033process is to stop it. You can examine and modify an attached process
53a5351d
JM
2034with all the @value{GDBN} commands that are ordinarily available when
2035you start processes with @code{run}. You can insert breakpoints; you
2036can step and continue; you can modify storage. If you would rather the
2037process continue running, you may use the @code{continue} command after
c906108c
SS
2038attaching @value{GDBN} to the process.
2039
2040@table @code
2041@kindex detach
2042@item detach
2043When you have finished debugging the attached process, you can use the
2044@code{detach} command to release it from @value{GDBN} control. Detaching
2045the process continues its execution. After the @code{detach} command,
2046that process and @value{GDBN} become completely independent once more, and you
2047are ready to @code{attach} another process or start one with @code{run}.
2048@code{detach} does not repeat if you press @key{RET} again after
2049executing the command.
2050@end table
2051
2052If you exit @value{GDBN} or use the @code{run} command while you have an
2053attached process, you kill that process. By default, @value{GDBN} asks
2054for confirmation if you try to do either of these things; you can
2055control whether or not you need to confirm by using the @code{set
2056confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2057messages}).
2058
6d2ebf8b 2059@node Kill Process
c906108c 2060@section Killing the child process
c906108c
SS
2061
2062@table @code
2063@kindex kill
2064@item kill
2065Kill the child process in which your program is running under @value{GDBN}.
2066@end table
2067
2068This command is useful if you wish to debug a core dump instead of a
2069running process. @value{GDBN} ignores any core dump file while your program
2070is running.
2071
2072On some operating systems, a program cannot be executed outside @value{GDBN}
2073while you have breakpoints set on it inside @value{GDBN}. You can use the
2074@code{kill} command in this situation to permit running your program
2075outside the debugger.
2076
2077The @code{kill} command is also useful if you wish to recompile and
2078relink your program, since on many systems it is impossible to modify an
2079executable file while it is running in a process. In this case, when you
2080next type @code{run}, @value{GDBN} notices that the file has changed, and
2081reads the symbol table again (while trying to preserve your current
2082breakpoint settings).
2083
6d2ebf8b 2084@node Threads
c906108c 2085@section Debugging programs with multiple threads
c906108c
SS
2086
2087@cindex threads of execution
2088@cindex multiple threads
2089@cindex switching threads
2090In some operating systems, such as HP-UX and Solaris, a single program
2091may have more than one @dfn{thread} of execution. The precise semantics
2092of threads differ from one operating system to another, but in general
2093the threads of a single program are akin to multiple processes---except
2094that they share one address space (that is, they can all examine and
2095modify the same variables). On the other hand, each thread has its own
2096registers and execution stack, and perhaps private memory.
2097
2098@value{GDBN} provides these facilities for debugging multi-thread
2099programs:
2100
2101@itemize @bullet
2102@item automatic notification of new threads
2103@item @samp{thread @var{threadno}}, a command to switch among threads
2104@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2105@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2106a command to apply a command to a list of threads
2107@item thread-specific breakpoints
2108@end itemize
2109
c906108c
SS
2110@quotation
2111@emph{Warning:} These facilities are not yet available on every
2112@value{GDBN} configuration where the operating system supports threads.
2113If your @value{GDBN} does not support threads, these commands have no
2114effect. For example, a system without thread support shows no output
2115from @samp{info threads}, and always rejects the @code{thread} command,
2116like this:
2117
2118@smallexample
2119(@value{GDBP}) info threads
2120(@value{GDBP}) thread 1
2121Thread ID 1 not known. Use the "info threads" command to
2122see the IDs of currently known threads.
2123@end smallexample
2124@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2125@c doesn't support threads"?
2126@end quotation
c906108c
SS
2127
2128@cindex focus of debugging
2129@cindex current thread
2130The @value{GDBN} thread debugging facility allows you to observe all
2131threads while your program runs---but whenever @value{GDBN} takes
2132control, one thread in particular is always the focus of debugging.
2133This thread is called the @dfn{current thread}. Debugging commands show
2134program information from the perspective of the current thread.
2135
41afff9a 2136@cindex @code{New} @var{systag} message
c906108c
SS
2137@cindex thread identifier (system)
2138@c FIXME-implementors!! It would be more helpful if the [New...] message
2139@c included GDB's numeric thread handle, so you could just go to that
2140@c thread without first checking `info threads'.
2141Whenever @value{GDBN} detects a new thread in your program, it displays
2142the target system's identification for the thread with a message in the
2143form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2144whose form varies depending on the particular system. For example, on
2145LynxOS, you might see
2146
474c8240 2147@smallexample
c906108c 2148[New process 35 thread 27]
474c8240 2149@end smallexample
c906108c
SS
2150
2151@noindent
2152when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2153the @var{systag} is simply something like @samp{process 368}, with no
2154further qualifier.
2155
2156@c FIXME!! (1) Does the [New...] message appear even for the very first
2157@c thread of a program, or does it only appear for the
6ca652b0 2158@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2159@c program?
2160@c (2) *Is* there necessarily a first thread always? Or do some
2161@c multithread systems permit starting a program with multiple
5d161b24 2162@c threads ab initio?
c906108c
SS
2163
2164@cindex thread number
2165@cindex thread identifier (GDB)
2166For debugging purposes, @value{GDBN} associates its own thread
2167number---always a single integer---with each thread in your program.
2168
2169@table @code
2170@kindex info threads
2171@item info threads
2172Display a summary of all threads currently in your
2173program. @value{GDBN} displays for each thread (in this order):
2174
2175@enumerate
09d4efe1
EZ
2176@item
2177the thread number assigned by @value{GDBN}
c906108c 2178
09d4efe1
EZ
2179@item
2180the target system's thread identifier (@var{systag})
c906108c 2181
09d4efe1
EZ
2182@item
2183the current stack frame summary for that thread
c906108c
SS
2184@end enumerate
2185
2186@noindent
2187An asterisk @samp{*} to the left of the @value{GDBN} thread number
2188indicates the current thread.
2189
5d161b24 2190For example,
c906108c
SS
2191@end table
2192@c end table here to get a little more width for example
2193
2194@smallexample
2195(@value{GDBP}) info threads
2196 3 process 35 thread 27 0x34e5 in sigpause ()
2197 2 process 35 thread 23 0x34e5 in sigpause ()
2198* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2199 at threadtest.c:68
2200@end smallexample
53a5351d
JM
2201
2202On HP-UX systems:
c906108c 2203
4644b6e3
EZ
2204@cindex debugging multithreaded programs (on HP-UX)
2205@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2206For debugging purposes, @value{GDBN} associates its own thread
2207number---a small integer assigned in thread-creation order---with each
2208thread in your program.
2209
41afff9a
EZ
2210@cindex @code{New} @var{systag} message, on HP-UX
2211@cindex thread identifier (system), on HP-UX
c906108c
SS
2212@c FIXME-implementors!! It would be more helpful if the [New...] message
2213@c included GDB's numeric thread handle, so you could just go to that
2214@c thread without first checking `info threads'.
2215Whenever @value{GDBN} detects a new thread in your program, it displays
2216both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2217form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2218whose form varies depending on the particular system. For example, on
2219HP-UX, you see
2220
474c8240 2221@smallexample
c906108c 2222[New thread 2 (system thread 26594)]
474c8240 2223@end smallexample
c906108c
SS
2224
2225@noindent
5d161b24 2226when @value{GDBN} notices a new thread.
c906108c
SS
2227
2228@table @code
4644b6e3 2229@kindex info threads (HP-UX)
c906108c
SS
2230@item info threads
2231Display a summary of all threads currently in your
2232program. @value{GDBN} displays for each thread (in this order):
2233
2234@enumerate
2235@item the thread number assigned by @value{GDBN}
2236
2237@item the target system's thread identifier (@var{systag})
2238
2239@item the current stack frame summary for that thread
2240@end enumerate
2241
2242@noindent
2243An asterisk @samp{*} to the left of the @value{GDBN} thread number
2244indicates the current thread.
2245
5d161b24 2246For example,
c906108c
SS
2247@end table
2248@c end table here to get a little more width for example
2249
474c8240 2250@smallexample
c906108c 2251(@value{GDBP}) info threads
6d2ebf8b
SS
2252 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2253 at quicksort.c:137
2254 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2255 from /usr/lib/libc.2
2256 1 system thread 27905 0x7b003498 in _brk () \@*
2257 from /usr/lib/libc.2
474c8240 2258@end smallexample
c906108c
SS
2259
2260@table @code
2261@kindex thread @var{threadno}
2262@item thread @var{threadno}
2263Make thread number @var{threadno} the current thread. The command
2264argument @var{threadno} is the internal @value{GDBN} thread number, as
2265shown in the first field of the @samp{info threads} display.
2266@value{GDBN} responds by displaying the system identifier of the thread
2267you selected, and its current stack frame summary:
2268
2269@smallexample
2270@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2271(@value{GDBP}) thread 2
c906108c 2272[Switching to process 35 thread 23]
c906108c
SS
22730x34e5 in sigpause ()
2274@end smallexample
2275
2276@noindent
2277As with the @samp{[New @dots{}]} message, the form of the text after
2278@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2279threads.
c906108c 2280
9c16f35a 2281@kindex thread apply
c906108c
SS
2282@item thread apply [@var{threadno}] [@var{all}] @var{args}
2283The @code{thread apply} command allows you to apply a command to one or
2284more threads. Specify the numbers of the threads that you want affected
2285with the command argument @var{threadno}. @var{threadno} is the internal
2286@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2287threads} display. To apply a command to all threads, use
2288@code{thread apply all} @var{args}.
c906108c
SS
2289@end table
2290
2291@cindex automatic thread selection
2292@cindex switching threads automatically
2293@cindex threads, automatic switching
2294Whenever @value{GDBN} stops your program, due to a breakpoint or a
2295signal, it automatically selects the thread where that breakpoint or
2296signal happened. @value{GDBN} alerts you to the context switch with a
2297message of the form @samp{[Switching to @var{systag}]} to identify the
2298thread.
2299
2300@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2301more information about how @value{GDBN} behaves when you stop and start
2302programs with multiple threads.
2303
2304@xref{Set Watchpoints,,Setting watchpoints}, for information about
2305watchpoints in programs with multiple threads.
c906108c 2306
6d2ebf8b 2307@node Processes
c906108c
SS
2308@section Debugging programs with multiple processes
2309
2310@cindex fork, debugging programs which call
2311@cindex multiple processes
2312@cindex processes, multiple
53a5351d
JM
2313On most systems, @value{GDBN} has no special support for debugging
2314programs which create additional processes using the @code{fork}
2315function. When a program forks, @value{GDBN} will continue to debug the
2316parent process and the child process will run unimpeded. If you have
2317set a breakpoint in any code which the child then executes, the child
2318will get a @code{SIGTRAP} signal which (unless it catches the signal)
2319will cause it to terminate.
c906108c
SS
2320
2321However, if you want to debug the child process there is a workaround
2322which isn't too painful. Put a call to @code{sleep} in the code which
2323the child process executes after the fork. It may be useful to sleep
2324only if a certain environment variable is set, or a certain file exists,
2325so that the delay need not occur when you don't want to run @value{GDBN}
2326on the child. While the child is sleeping, use the @code{ps} program to
2327get its process ID. Then tell @value{GDBN} (a new invocation of
2328@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2329the child process (@pxref{Attach}). From that point on you can debug
c906108c 2330the child process just like any other process which you attached to.
c906108c 2331
b51970ac
DJ
2332On some systems, @value{GDBN} provides support for debugging programs that
2333create additional processes using the @code{fork} or @code{vfork} functions.
2334Currently, the only platforms with this feature are HP-UX (11.x and later
2335only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2336
2337By default, when a program forks, @value{GDBN} will continue to debug
2338the parent process and the child process will run unimpeded.
2339
2340If you want to follow the child process instead of the parent process,
2341use the command @w{@code{set follow-fork-mode}}.
2342
2343@table @code
2344@kindex set follow-fork-mode
2345@item set follow-fork-mode @var{mode}
2346Set the debugger response to a program call of @code{fork} or
2347@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2348process. The @var{mode} argument can be:
c906108c
SS
2349
2350@table @code
2351@item parent
2352The original process is debugged after a fork. The child process runs
2df3850c 2353unimpeded. This is the default.
c906108c
SS
2354
2355@item child
2356The new process is debugged after a fork. The parent process runs
2357unimpeded.
2358
c906108c
SS
2359@end table
2360
9c16f35a 2361@kindex show follow-fork-mode
c906108c 2362@item show follow-fork-mode
2df3850c 2363Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2364@end table
2365
2366If you ask to debug a child process and a @code{vfork} is followed by an
2367@code{exec}, @value{GDBN} executes the new target up to the first
2368breakpoint in the new target. If you have a breakpoint set on
2369@code{main} in your original program, the breakpoint will also be set on
2370the child process's @code{main}.
2371
2372When a child process is spawned by @code{vfork}, you cannot debug the
2373child or parent until an @code{exec} call completes.
2374
2375If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2376call executes, the new target restarts. To restart the parent process,
2377use the @code{file} command with the parent executable name as its
2378argument.
2379
2380You can use the @code{catch} command to make @value{GDBN} stop whenever
2381a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2382Catchpoints, ,Setting catchpoints}.
c906108c 2383
6d2ebf8b 2384@node Stopping
c906108c
SS
2385@chapter Stopping and Continuing
2386
2387The principal purposes of using a debugger are so that you can stop your
2388program before it terminates; or so that, if your program runs into
2389trouble, you can investigate and find out why.
2390
7a292a7a
SS
2391Inside @value{GDBN}, your program may stop for any of several reasons,
2392such as a signal, a breakpoint, or reaching a new line after a
2393@value{GDBN} command such as @code{step}. You may then examine and
2394change variables, set new breakpoints or remove old ones, and then
2395continue execution. Usually, the messages shown by @value{GDBN} provide
2396ample explanation of the status of your program---but you can also
2397explicitly request this information at any time.
c906108c
SS
2398
2399@table @code
2400@kindex info program
2401@item info program
2402Display information about the status of your program: whether it is
7a292a7a 2403running or not, what process it is, and why it stopped.
c906108c
SS
2404@end table
2405
2406@menu
2407* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2408* Continuing and Stepping:: Resuming execution
c906108c 2409* Signals:: Signals
c906108c 2410* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2411@end menu
2412
6d2ebf8b 2413@node Breakpoints
c906108c
SS
2414@section Breakpoints, watchpoints, and catchpoints
2415
2416@cindex breakpoints
2417A @dfn{breakpoint} makes your program stop whenever a certain point in
2418the program is reached. For each breakpoint, you can add conditions to
2419control in finer detail whether your program stops. You can set
2420breakpoints with the @code{break} command and its variants (@pxref{Set
2421Breaks, ,Setting breakpoints}), to specify the place where your program
2422should stop by line number, function name or exact address in the
2423program.
2424
09d4efe1
EZ
2425On some systems, you can set breakpoints in shared libraries before
2426the executable is run. There is a minor limitation on HP-UX systems:
2427you must wait until the executable is run in order to set breakpoints
2428in shared library routines that are not called directly by the program
2429(for example, routines that are arguments in a @code{pthread_create}
2430call).
c906108c
SS
2431
2432@cindex watchpoints
2433@cindex memory tracing
2434@cindex breakpoint on memory address
2435@cindex breakpoint on variable modification
2436A @dfn{watchpoint} is a special breakpoint that stops your program
2437when the value of an expression changes. You must use a different
2438command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2439watchpoints}), but aside from that, you can manage a watchpoint like
2440any other breakpoint: you enable, disable, and delete both breakpoints
2441and watchpoints using the same commands.
2442
2443You can arrange to have values from your program displayed automatically
2444whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2445Automatic display}.
2446
2447@cindex catchpoints
2448@cindex breakpoint on events
2449A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2450when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2451exception or the loading of a library. As with watchpoints, you use a
2452different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2453catchpoints}), but aside from that, you can manage a catchpoint like any
2454other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2455@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2456
2457@cindex breakpoint numbers
2458@cindex numbers for breakpoints
2459@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2460catchpoint when you create it; these numbers are successive integers
2461starting with one. In many of the commands for controlling various
2462features of breakpoints you use the breakpoint number to say which
2463breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2464@dfn{disabled}; if disabled, it has no effect on your program until you
2465enable it again.
2466
c5394b80
JM
2467@cindex breakpoint ranges
2468@cindex ranges of breakpoints
2469Some @value{GDBN} commands accept a range of breakpoints on which to
2470operate. A breakpoint range is either a single breakpoint number, like
2471@samp{5}, or two such numbers, in increasing order, separated by a
2472hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2473all breakpoint in that range are operated on.
2474
c906108c
SS
2475@menu
2476* Set Breaks:: Setting breakpoints
2477* Set Watchpoints:: Setting watchpoints
2478* Set Catchpoints:: Setting catchpoints
2479* Delete Breaks:: Deleting breakpoints
2480* Disabling:: Disabling breakpoints
2481* Conditions:: Break conditions
2482* Break Commands:: Breakpoint command lists
c906108c 2483* Breakpoint Menus:: Breakpoint menus
d4f3574e 2484* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2485* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2486@end menu
2487
6d2ebf8b 2488@node Set Breaks
c906108c
SS
2489@subsection Setting breakpoints
2490
5d161b24 2491@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2492@c consider in particular declaration with/without initialization.
2493@c
2494@c FIXME 2 is there stuff on this already? break at fun start, already init?
2495
2496@kindex break
41afff9a
EZ
2497@kindex b @r{(@code{break})}
2498@vindex $bpnum@r{, convenience variable}
c906108c
SS
2499@cindex latest breakpoint
2500Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2501@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2502number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2503Vars,, Convenience variables}, for a discussion of what you can do with
2504convenience variables.
2505
2506You have several ways to say where the breakpoint should go.
2507
2508@table @code
2509@item break @var{function}
5d161b24 2510Set a breakpoint at entry to function @var{function}.
c906108c 2511When using source languages that permit overloading of symbols, such as
b37052ae 2512C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2513@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2514
2515@item break +@var{offset}
2516@itemx break -@var{offset}
2517Set a breakpoint some number of lines forward or back from the position
d4f3574e 2518at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2519(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2520
2521@item break @var{linenum}
2522Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2523The current source file is the last file whose source text was printed.
2524The breakpoint will stop your program just before it executes any of the
c906108c
SS
2525code on that line.
2526
2527@item break @var{filename}:@var{linenum}
2528Set a breakpoint at line @var{linenum} in source file @var{filename}.
2529
2530@item break @var{filename}:@var{function}
2531Set a breakpoint at entry to function @var{function} found in file
2532@var{filename}. Specifying a file name as well as a function name is
2533superfluous except when multiple files contain similarly named
2534functions.
2535
2536@item break *@var{address}
2537Set a breakpoint at address @var{address}. You can use this to set
2538breakpoints in parts of your program which do not have debugging
2539information or source files.
2540
2541@item break
2542When called without any arguments, @code{break} sets a breakpoint at
2543the next instruction to be executed in the selected stack frame
2544(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2545innermost, this makes your program stop as soon as control
2546returns to that frame. This is similar to the effect of a
2547@code{finish} command in the frame inside the selected frame---except
2548that @code{finish} does not leave an active breakpoint. If you use
2549@code{break} without an argument in the innermost frame, @value{GDBN} stops
2550the next time it reaches the current location; this may be useful
2551inside loops.
2552
2553@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2554least one instruction has been executed. If it did not do this, you
2555would be unable to proceed past a breakpoint without first disabling the
2556breakpoint. This rule applies whether or not the breakpoint already
2557existed when your program stopped.
2558
2559@item break @dots{} if @var{cond}
2560Set a breakpoint with condition @var{cond}; evaluate the expression
2561@var{cond} each time the breakpoint is reached, and stop only if the
2562value is nonzero---that is, if @var{cond} evaluates as true.
2563@samp{@dots{}} stands for one of the possible arguments described
2564above (or no argument) specifying where to break. @xref{Conditions,
2565,Break conditions}, for more information on breakpoint conditions.
2566
2567@kindex tbreak
2568@item tbreak @var{args}
2569Set a breakpoint enabled only for one stop. @var{args} are the
2570same as for the @code{break} command, and the breakpoint is set in the same
2571way, but the breakpoint is automatically deleted after the first time your
2572program stops there. @xref{Disabling, ,Disabling breakpoints}.
2573
c906108c 2574@kindex hbreak
ba04e063 2575@cindex hardware breakpoints
c906108c 2576@item hbreak @var{args}
d4f3574e
SS
2577Set a hardware-assisted breakpoint. @var{args} are the same as for the
2578@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2579breakpoint requires hardware support and some target hardware may not
2580have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2581debugging, so you can set a breakpoint at an instruction without
2582changing the instruction. This can be used with the new trap-generation
09d4efe1 2583provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2584will generate traps when a program accesses some data or instruction
2585address that is assigned to the debug registers. However the hardware
2586breakpoint registers can take a limited number of breakpoints. For
2587example, on the DSU, only two data breakpoints can be set at a time, and
2588@value{GDBN} will reject this command if more than two are used. Delete
2589or disable unused hardware breakpoints before setting new ones
2590(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2591For remote targets, you can restrict the number of hardware
2592breakpoints @value{GDBN} will use, see @ref{set remote
2593hardware-breakpoint-limit}.
501eef12 2594
c906108c
SS
2595
2596@kindex thbreak
2597@item thbreak @var{args}
2598Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2599are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2600the same way. However, like the @code{tbreak} command,
c906108c
SS
2601the breakpoint is automatically deleted after the
2602first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2603command, the breakpoint requires hardware support and some target hardware
2604may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2605See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2606
2607@kindex rbreak
2608@cindex regular expression
2609@item rbreak @var{regex}
c906108c 2610Set breakpoints on all functions matching the regular expression
11cf8741
JM
2611@var{regex}. This command sets an unconditional breakpoint on all
2612matches, printing a list of all breakpoints it set. Once these
2613breakpoints are set, they are treated just like the breakpoints set with
2614the @code{break} command. You can delete them, disable them, or make
2615them conditional the same way as any other breakpoint.
2616
2617The syntax of the regular expression is the standard one used with tools
2618like @file{grep}. Note that this is different from the syntax used by
2619shells, so for instance @code{foo*} matches all functions that include
2620an @code{fo} followed by zero or more @code{o}s. There is an implicit
2621@code{.*} leading and trailing the regular expression you supply, so to
2622match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2623
f7dc1244 2624@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2625When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2626breakpoints on overloaded functions that are not members of any special
2627classes.
c906108c 2628
f7dc1244
EZ
2629@cindex set breakpoints on all functions
2630The @code{rbreak} command can be used to set breakpoints in
2631@strong{all} the functions in a program, like this:
2632
2633@smallexample
2634(@value{GDBP}) rbreak .
2635@end smallexample
2636
c906108c
SS
2637@kindex info breakpoints
2638@cindex @code{$_} and @code{info breakpoints}
2639@item info breakpoints @r{[}@var{n}@r{]}
2640@itemx info break @r{[}@var{n}@r{]}
2641@itemx info watchpoints @r{[}@var{n}@r{]}
2642Print a table of all breakpoints, watchpoints, and catchpoints set and
2643not deleted, with the following columns for each breakpoint:
2644
2645@table @emph
2646@item Breakpoint Numbers
2647@item Type
2648Breakpoint, watchpoint, or catchpoint.
2649@item Disposition
2650Whether the breakpoint is marked to be disabled or deleted when hit.
2651@item Enabled or Disabled
2652Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2653that are not enabled.
2654@item Address
2650777c
JJ
2655Where the breakpoint is in your program, as a memory address. If the
2656breakpoint is pending (see below for details) on a future load of a shared library, the address
2657will be listed as @samp{<PENDING>}.
c906108c
SS
2658@item What
2659Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2660line number. For a pending breakpoint, the original string passed to
2661the breakpoint command will be listed as it cannot be resolved until
2662the appropriate shared library is loaded in the future.
c906108c
SS
2663@end table
2664
2665@noindent
2666If a breakpoint is conditional, @code{info break} shows the condition on
2667the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2668are listed after that. A pending breakpoint is allowed to have a condition
2669specified for it. The condition is not parsed for validity until a shared
2670library is loaded that allows the pending breakpoint to resolve to a
2671valid location.
c906108c
SS
2672
2673@noindent
2674@code{info break} with a breakpoint
2675number @var{n} as argument lists only that breakpoint. The
2676convenience variable @code{$_} and the default examining-address for
2677the @code{x} command are set to the address of the last breakpoint
5d161b24 2678listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2679
2680@noindent
2681@code{info break} displays a count of the number of times the breakpoint
2682has been hit. This is especially useful in conjunction with the
2683@code{ignore} command. You can ignore a large number of breakpoint
2684hits, look at the breakpoint info to see how many times the breakpoint
2685was hit, and then run again, ignoring one less than that number. This
2686will get you quickly to the last hit of that breakpoint.
2687@end table
2688
2689@value{GDBN} allows you to set any number of breakpoints at the same place in
2690your program. There is nothing silly or meaningless about this. When
2691the breakpoints are conditional, this is even useful
2692(@pxref{Conditions, ,Break conditions}).
2693
2650777c 2694@cindex pending breakpoints
dd79a6cf
JJ
2695If a specified breakpoint location cannot be found, it may be due to the fact
2696that the location is in a shared library that is yet to be loaded. In such
2697a case, you may want @value{GDBN} to create a special breakpoint (known as
2698a @dfn{pending breakpoint}) that
2699attempts to resolve itself in the future when an appropriate shared library
2700gets loaded.
2701
2702Pending breakpoints are useful to set at the start of your
2650777c
JJ
2703@value{GDBN} session for locations that you know will be dynamically loaded
2704later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2705a check is made to see if the load resolves any pending breakpoint locations.
2706If a pending breakpoint location gets resolved,
2707a regular breakpoint is created and the original pending breakpoint is removed.
2708
2709@value{GDBN} provides some additional commands for controlling pending
2710breakpoint support:
2711
2712@kindex set breakpoint pending
2713@kindex show breakpoint pending
2714@table @code
2715@item set breakpoint pending auto
2716This is the default behavior. When @value{GDBN} cannot find the breakpoint
2717location, it queries you whether a pending breakpoint should be created.
2718
2719@item set breakpoint pending on
2720This indicates that an unrecognized breakpoint location should automatically
2721result in a pending breakpoint being created.
2722
2723@item set breakpoint pending off
2724This indicates that pending breakpoints are not to be created. Any
2725unrecognized breakpoint location results in an error. This setting does
2726not affect any pending breakpoints previously created.
2727
2728@item show breakpoint pending
2729Show the current behavior setting for creating pending breakpoints.
2730@end table
2650777c 2731
649e03f6
RM
2732@cindex operations allowed on pending breakpoints
2733Normal breakpoint operations apply to pending breakpoints as well. You may
2734specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2735breakpoint is reached. You can also enable or disable
2736the pending breakpoint. When you specify a condition for a pending breakpoint,
2737the parsing of the condition will be deferred until the point where the
2738pending breakpoint location is resolved. Disabling a pending breakpoint
2739tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2740shared library load. When a pending breakpoint is re-enabled,
649e03f6 2741@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2742This is done because any number of shared library loads could have
2743occurred since the time the breakpoint was disabled and one or more
2744of these loads could resolve the location.
2745
c906108c
SS
2746@cindex negative breakpoint numbers
2747@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2748@value{GDBN} itself sometimes sets breakpoints in your program for
2749special purposes, such as proper handling of @code{longjmp} (in C
2750programs). These internal breakpoints are assigned negative numbers,
2751starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2752You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2753@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2754
2755
6d2ebf8b 2756@node Set Watchpoints
c906108c
SS
2757@subsection Setting watchpoints
2758
2759@cindex setting watchpoints
c906108c
SS
2760You can use a watchpoint to stop execution whenever the value of an
2761expression changes, without having to predict a particular place where
2762this may happen.
2763
82f2d802
EZ
2764@cindex software watchpoints
2765@cindex hardware watchpoints
c906108c 2766Depending on your system, watchpoints may be implemented in software or
2df3850c 2767hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2768program and testing the variable's value each time, which is hundreds of
2769times slower than normal execution. (But this may still be worth it, to
2770catch errors where you have no clue what part of your program is the
2771culprit.)
2772
82f2d802
EZ
2773On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2774x86-based targets, @value{GDBN} includes support for hardware
2775watchpoints, which do not slow down the running of your program.
c906108c
SS
2776
2777@table @code
2778@kindex watch
2779@item watch @var{expr}
2780Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2781is written into by the program and its value changes.
2782
2783@kindex rwatch
2784@item rwatch @var{expr}
09d4efe1
EZ
2785Set a watchpoint that will break when the value of @var{expr} is read
2786by the program.
c906108c
SS
2787
2788@kindex awatch
2789@item awatch @var{expr}
09d4efe1
EZ
2790Set a watchpoint that will break when @var{expr} is either read from
2791or written into by the program.
c906108c
SS
2792
2793@kindex info watchpoints
2794@item info watchpoints
2795This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2796it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2797@end table
2798
2799@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2800watchpoints execute very quickly, and the debugger reports a change in
2801value at the exact instruction where the change occurs. If @value{GDBN}
2802cannot set a hardware watchpoint, it sets a software watchpoint, which
2803executes more slowly and reports the change in value at the next
82f2d802
EZ
2804@emph{statement}, not the instruction, after the change occurs.
2805
2806@vindex can-use-hw-watchpoints
2807@cindex use only software watchpoints
2808You can force @value{GDBN} to use only software watchpoints with the
2809@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2810zero, @value{GDBN} will never try to use hardware watchpoints, even if
2811the underlying system supports them. (Note that hardware-assisted
2812watchpoints that were set @emph{before} setting
2813@code{can-use-hw-watchpoints} to zero will still use the hardware
2814mechanism of watching expressiion values.)
c906108c 2815
9c16f35a
EZ
2816@table @code
2817@item set can-use-hw-watchpoints
2818@kindex set can-use-hw-watchpoints
2819Set whether or not to use hardware watchpoints.
2820
2821@item show can-use-hw-watchpoints
2822@kindex show can-use-hw-watchpoints
2823Show the current mode of using hardware watchpoints.
2824@end table
2825
2826For remote targets, you can restrict the number of hardware
2827watchpoints @value{GDBN} will use, see @ref{set remote
2828hardware-breakpoint-limit}.
2829
c906108c
SS
2830When you issue the @code{watch} command, @value{GDBN} reports
2831
474c8240 2832@smallexample
c906108c 2833Hardware watchpoint @var{num}: @var{expr}
474c8240 2834@end smallexample
c906108c
SS
2835
2836@noindent
2837if it was able to set a hardware watchpoint.
2838
7be570e7
JM
2839Currently, the @code{awatch} and @code{rwatch} commands can only set
2840hardware watchpoints, because accesses to data that don't change the
2841value of the watched expression cannot be detected without examining
2842every instruction as it is being executed, and @value{GDBN} does not do
2843that currently. If @value{GDBN} finds that it is unable to set a
2844hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2845will print a message like this:
2846
2847@smallexample
2848Expression cannot be implemented with read/access watchpoint.
2849@end smallexample
2850
2851Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2852data type of the watched expression is wider than what a hardware
2853watchpoint on the target machine can handle. For example, some systems
2854can only watch regions that are up to 4 bytes wide; on such systems you
2855cannot set hardware watchpoints for an expression that yields a
2856double-precision floating-point number (which is typically 8 bytes
2857wide). As a work-around, it might be possible to break the large region
2858into a series of smaller ones and watch them with separate watchpoints.
2859
2860If you set too many hardware watchpoints, @value{GDBN} might be unable
2861to insert all of them when you resume the execution of your program.
2862Since the precise number of active watchpoints is unknown until such
2863time as the program is about to be resumed, @value{GDBN} might not be
2864able to warn you about this when you set the watchpoints, and the
2865warning will be printed only when the program is resumed:
2866
2867@smallexample
2868Hardware watchpoint @var{num}: Could not insert watchpoint
2869@end smallexample
2870
2871@noindent
2872If this happens, delete or disable some of the watchpoints.
2873
2874The SPARClite DSU will generate traps when a program accesses some data
2875or instruction address that is assigned to the debug registers. For the
2876data addresses, DSU facilitates the @code{watch} command. However the
2877hardware breakpoint registers can only take two data watchpoints, and
2878both watchpoints must be the same kind. For example, you can set two
2879watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2880@strong{or} two with @code{awatch} commands, but you cannot set one
2881watchpoint with one command and the other with a different command.
c906108c
SS
2882@value{GDBN} will reject the command if you try to mix watchpoints.
2883Delete or disable unused watchpoint commands before setting new ones.
2884
2885If you call a function interactively using @code{print} or @code{call},
2df3850c 2886any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2887kind of breakpoint or the call completes.
2888
7be570e7
JM
2889@value{GDBN} automatically deletes watchpoints that watch local
2890(automatic) variables, or expressions that involve such variables, when
2891they go out of scope, that is, when the execution leaves the block in
2892which these variables were defined. In particular, when the program
2893being debugged terminates, @emph{all} local variables go out of scope,
2894and so only watchpoints that watch global variables remain set. If you
2895rerun the program, you will need to set all such watchpoints again. One
2896way of doing that would be to set a code breakpoint at the entry to the
2897@code{main} function and when it breaks, set all the watchpoints.
2898
c906108c
SS
2899@quotation
2900@cindex watchpoints and threads
2901@cindex threads and watchpoints
c906108c
SS
2902@emph{Warning:} In multi-thread programs, watchpoints have only limited
2903usefulness. With the current watchpoint implementation, @value{GDBN}
2904can only watch the value of an expression @emph{in a single thread}. If
2905you are confident that the expression can only change due to the current
2906thread's activity (and if you are also confident that no other thread
2907can become current), then you can use watchpoints as usual. However,
2908@value{GDBN} may not notice when a non-current thread's activity changes
2909the expression.
53a5351d 2910
d4f3574e 2911@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
2912@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
2913have only limited usefulness. If @value{GDBN} creates a software
2914watchpoint, it can only watch the value of an expression @emph{in a
2915single thread}. If you are confident that the expression can only
2916change due to the current thread's activity (and if you are also
2917confident that no other thread can become current), then you can use
2918software watchpoints as usual. However, @value{GDBN} may not notice
2919when a non-current thread's activity changes the expression. (Hardware
2920watchpoints, in contrast, watch an expression in all threads.)
c906108c 2921@end quotation
c906108c 2922
501eef12
AC
2923@xref{set remote hardware-watchpoint-limit}.
2924
6d2ebf8b 2925@node Set Catchpoints
c906108c 2926@subsection Setting catchpoints
d4f3574e 2927@cindex catchpoints, setting
c906108c
SS
2928@cindex exception handlers
2929@cindex event handling
2930
2931You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 2932kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
2933shared library. Use the @code{catch} command to set a catchpoint.
2934
2935@table @code
2936@kindex catch
2937@item catch @var{event}
2938Stop when @var{event} occurs. @var{event} can be any of the following:
2939@table @code
2940@item throw
4644b6e3 2941@cindex stop on C@t{++} exceptions
b37052ae 2942The throwing of a C@t{++} exception.
c906108c
SS
2943
2944@item catch
b37052ae 2945The catching of a C@t{++} exception.
c906108c
SS
2946
2947@item exec
4644b6e3 2948@cindex break on fork/exec
c906108c
SS
2949A call to @code{exec}. This is currently only available for HP-UX.
2950
2951@item fork
c906108c
SS
2952A call to @code{fork}. This is currently only available for HP-UX.
2953
2954@item vfork
c906108c
SS
2955A call to @code{vfork}. This is currently only available for HP-UX.
2956
2957@item load
2958@itemx load @var{libname}
4644b6e3 2959@cindex break on load/unload of shared library
c906108c
SS
2960The dynamic loading of any shared library, or the loading of the library
2961@var{libname}. This is currently only available for HP-UX.
2962
2963@item unload
2964@itemx unload @var{libname}
c906108c
SS
2965The unloading of any dynamically loaded shared library, or the unloading
2966of the library @var{libname}. This is currently only available for HP-UX.
2967@end table
2968
2969@item tcatch @var{event}
2970Set a catchpoint that is enabled only for one stop. The catchpoint is
2971automatically deleted after the first time the event is caught.
2972
2973@end table
2974
2975Use the @code{info break} command to list the current catchpoints.
2976
b37052ae 2977There are currently some limitations to C@t{++} exception handling
c906108c
SS
2978(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
2979
2980@itemize @bullet
2981@item
2982If you call a function interactively, @value{GDBN} normally returns
2983control to you when the function has finished executing. If the call
2984raises an exception, however, the call may bypass the mechanism that
2985returns control to you and cause your program either to abort or to
2986simply continue running until it hits a breakpoint, catches a signal
2987that @value{GDBN} is listening for, or exits. This is the case even if
2988you set a catchpoint for the exception; catchpoints on exceptions are
2989disabled within interactive calls.
2990
2991@item
2992You cannot raise an exception interactively.
2993
2994@item
2995You cannot install an exception handler interactively.
2996@end itemize
2997
2998@cindex raise exceptions
2999Sometimes @code{catch} is not the best way to debug exception handling:
3000if you need to know exactly where an exception is raised, it is better to
3001stop @emph{before} the exception handler is called, since that way you
3002can see the stack before any unwinding takes place. If you set a
3003breakpoint in an exception handler instead, it may not be easy to find
3004out where the exception was raised.
3005
3006To stop just before an exception handler is called, you need some
b37052ae 3007knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3008raised by calling a library function named @code{__raise_exception}
3009which has the following ANSI C interface:
3010
474c8240 3011@smallexample
c906108c 3012 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3013 @var{id} is the exception identifier. */
3014 void __raise_exception (void **addr, void *id);
474c8240 3015@end smallexample
c906108c
SS
3016
3017@noindent
3018To make the debugger catch all exceptions before any stack
3019unwinding takes place, set a breakpoint on @code{__raise_exception}
3020(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3021
3022With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3023that depends on the value of @var{id}, you can stop your program when
3024a specific exception is raised. You can use multiple conditional
3025breakpoints to stop your program when any of a number of exceptions are
3026raised.
3027
3028
6d2ebf8b 3029@node Delete Breaks
c906108c
SS
3030@subsection Deleting breakpoints
3031
3032@cindex clearing breakpoints, watchpoints, catchpoints
3033@cindex deleting breakpoints, watchpoints, catchpoints
3034It is often necessary to eliminate a breakpoint, watchpoint, or
3035catchpoint once it has done its job and you no longer want your program
3036to stop there. This is called @dfn{deleting} the breakpoint. A
3037breakpoint that has been deleted no longer exists; it is forgotten.
3038
3039With the @code{clear} command you can delete breakpoints according to
3040where they are in your program. With the @code{delete} command you can
3041delete individual breakpoints, watchpoints, or catchpoints by specifying
3042their breakpoint numbers.
3043
3044It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3045automatically ignores breakpoints on the first instruction to be executed
3046when you continue execution without changing the execution address.
3047
3048@table @code
3049@kindex clear
3050@item clear
3051Delete any breakpoints at the next instruction to be executed in the
3052selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3053the innermost frame is selected, this is a good way to delete a
3054breakpoint where your program just stopped.
3055
3056@item clear @var{function}
3057@itemx clear @var{filename}:@var{function}
09d4efe1 3058Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3059
3060@item clear @var{linenum}
3061@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3062Delete any breakpoints set at or within the code of the specified
3063@var{linenum} of the specified @var{filename}.
c906108c
SS
3064
3065@cindex delete breakpoints
3066@kindex delete
41afff9a 3067@kindex d @r{(@code{delete})}
c5394b80
JM
3068@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3069Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3070ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3071breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3072confirm off}). You can abbreviate this command as @code{d}.
3073@end table
3074
6d2ebf8b 3075@node Disabling
c906108c
SS
3076@subsection Disabling breakpoints
3077
4644b6e3 3078@cindex enable/disable a breakpoint
c906108c
SS
3079Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3080prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3081it had been deleted, but remembers the information on the breakpoint so
3082that you can @dfn{enable} it again later.
3083
3084You disable and enable breakpoints, watchpoints, and catchpoints with
3085the @code{enable} and @code{disable} commands, optionally specifying one
3086or more breakpoint numbers as arguments. Use @code{info break} or
3087@code{info watch} to print a list of breakpoints, watchpoints, and
3088catchpoints if you do not know which numbers to use.
3089
3090A breakpoint, watchpoint, or catchpoint can have any of four different
3091states of enablement:
3092
3093@itemize @bullet
3094@item
3095Enabled. The breakpoint stops your program. A breakpoint set
3096with the @code{break} command starts out in this state.
3097@item
3098Disabled. The breakpoint has no effect on your program.
3099@item
3100Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3101disabled.
c906108c
SS
3102@item
3103Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3104immediately after it does so it is deleted permanently. A breakpoint
3105set with the @code{tbreak} command starts out in this state.
c906108c
SS
3106@end itemize
3107
3108You can use the following commands to enable or disable breakpoints,
3109watchpoints, and catchpoints:
3110
3111@table @code
c906108c 3112@kindex disable
41afff9a 3113@kindex dis @r{(@code{disable})}
c5394b80 3114@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3115Disable the specified breakpoints---or all breakpoints, if none are
3116listed. A disabled breakpoint has no effect but is not forgotten. All
3117options such as ignore-counts, conditions and commands are remembered in
3118case the breakpoint is enabled again later. You may abbreviate
3119@code{disable} as @code{dis}.
3120
c906108c 3121@kindex enable
c5394b80 3122@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3123Enable the specified breakpoints (or all defined breakpoints). They
3124become effective once again in stopping your program.
3125
c5394b80 3126@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3127Enable the specified breakpoints temporarily. @value{GDBN} disables any
3128of these breakpoints immediately after stopping your program.
3129
c5394b80 3130@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3131Enable the specified breakpoints to work once, then die. @value{GDBN}
3132deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3133Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3134@end table
3135
d4f3574e
SS
3136@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3137@c confusing: tbreak is also initially enabled.
c906108c
SS
3138Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3139,Setting breakpoints}), breakpoints that you set are initially enabled;
3140subsequently, they become disabled or enabled only when you use one of
3141the commands above. (The command @code{until} can set and delete a
3142breakpoint of its own, but it does not change the state of your other
3143breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3144stepping}.)
3145
6d2ebf8b 3146@node Conditions
c906108c
SS
3147@subsection Break conditions
3148@cindex conditional breakpoints
3149@cindex breakpoint conditions
3150
3151@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3152@c in particular for a watchpoint?
c906108c
SS
3153The simplest sort of breakpoint breaks every time your program reaches a
3154specified place. You can also specify a @dfn{condition} for a
3155breakpoint. A condition is just a Boolean expression in your
3156programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3157a condition evaluates the expression each time your program reaches it,
3158and your program stops only if the condition is @emph{true}.
3159
3160This is the converse of using assertions for program validation; in that
3161situation, you want to stop when the assertion is violated---that is,
3162when the condition is false. In C, if you want to test an assertion expressed
3163by the condition @var{assert}, you should set the condition
3164@samp{! @var{assert}} on the appropriate breakpoint.
3165
3166Conditions are also accepted for watchpoints; you may not need them,
3167since a watchpoint is inspecting the value of an expression anyhow---but
3168it might be simpler, say, to just set a watchpoint on a variable name,
3169and specify a condition that tests whether the new value is an interesting
3170one.
3171
3172Break conditions can have side effects, and may even call functions in
3173your program. This can be useful, for example, to activate functions
3174that log program progress, or to use your own print functions to
3175format special data structures. The effects are completely predictable
3176unless there is another enabled breakpoint at the same address. (In
3177that case, @value{GDBN} might see the other breakpoint first and stop your
3178program without checking the condition of this one.) Note that
d4f3574e
SS
3179breakpoint commands are usually more convenient and flexible than break
3180conditions for the
c906108c
SS
3181purpose of performing side effects when a breakpoint is reached
3182(@pxref{Break Commands, ,Breakpoint command lists}).
3183
3184Break conditions can be specified when a breakpoint is set, by using
3185@samp{if} in the arguments to the @code{break} command. @xref{Set
3186Breaks, ,Setting breakpoints}. They can also be changed at any time
3187with the @code{condition} command.
53a5351d 3188
c906108c
SS
3189You can also use the @code{if} keyword with the @code{watch} command.
3190The @code{catch} command does not recognize the @code{if} keyword;
3191@code{condition} is the only way to impose a further condition on a
3192catchpoint.
c906108c
SS
3193
3194@table @code
3195@kindex condition
3196@item condition @var{bnum} @var{expression}
3197Specify @var{expression} as the break condition for breakpoint,
3198watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3199breakpoint @var{bnum} stops your program only if the value of
3200@var{expression} is true (nonzero, in C). When you use
3201@code{condition}, @value{GDBN} checks @var{expression} immediately for
3202syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3203referents in the context of your breakpoint. If @var{expression} uses
3204symbols not referenced in the context of the breakpoint, @value{GDBN}
3205prints an error message:
3206
474c8240 3207@smallexample
d4f3574e 3208No symbol "foo" in current context.
474c8240 3209@end smallexample
d4f3574e
SS
3210
3211@noindent
c906108c
SS
3212@value{GDBN} does
3213not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3214command (or a command that sets a breakpoint with a condition, like
3215@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3216
3217@item condition @var{bnum}
3218Remove the condition from breakpoint number @var{bnum}. It becomes
3219an ordinary unconditional breakpoint.
3220@end table
3221
3222@cindex ignore count (of breakpoint)
3223A special case of a breakpoint condition is to stop only when the
3224breakpoint has been reached a certain number of times. This is so
3225useful that there is a special way to do it, using the @dfn{ignore
3226count} of the breakpoint. Every breakpoint has an ignore count, which
3227is an integer. Most of the time, the ignore count is zero, and
3228therefore has no effect. But if your program reaches a breakpoint whose
3229ignore count is positive, then instead of stopping, it just decrements
3230the ignore count by one and continues. As a result, if the ignore count
3231value is @var{n}, the breakpoint does not stop the next @var{n} times
3232your program reaches it.
3233
3234@table @code
3235@kindex ignore
3236@item ignore @var{bnum} @var{count}
3237Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3238The next @var{count} times the breakpoint is reached, your program's
3239execution does not stop; other than to decrement the ignore count, @value{GDBN}
3240takes no action.
3241
3242To make the breakpoint stop the next time it is reached, specify
3243a count of zero.
3244
3245When you use @code{continue} to resume execution of your program from a
3246breakpoint, you can specify an ignore count directly as an argument to
3247@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3248Stepping,,Continuing and stepping}.
3249
3250If a breakpoint has a positive ignore count and a condition, the
3251condition is not checked. Once the ignore count reaches zero,
3252@value{GDBN} resumes checking the condition.
3253
3254You could achieve the effect of the ignore count with a condition such
3255as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3256is decremented each time. @xref{Convenience Vars, ,Convenience
3257variables}.
3258@end table
3259
3260Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3261
3262
6d2ebf8b 3263@node Break Commands
c906108c
SS
3264@subsection Breakpoint command lists
3265
3266@cindex breakpoint commands
3267You can give any breakpoint (or watchpoint or catchpoint) a series of
3268commands to execute when your program stops due to that breakpoint. For
3269example, you might want to print the values of certain expressions, or
3270enable other breakpoints.
3271
3272@table @code
3273@kindex commands
3274@kindex end
3275@item commands @r{[}@var{bnum}@r{]}
3276@itemx @dots{} @var{command-list} @dots{}
3277@itemx end
3278Specify a list of commands for breakpoint number @var{bnum}. The commands
3279themselves appear on the following lines. Type a line containing just
3280@code{end} to terminate the commands.
3281
3282To remove all commands from a breakpoint, type @code{commands} and
3283follow it immediately with @code{end}; that is, give no commands.
3284
3285With no @var{bnum} argument, @code{commands} refers to the last
3286breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3287recently encountered).
3288@end table
3289
3290Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3291disabled within a @var{command-list}.
3292
3293You can use breakpoint commands to start your program up again. Simply
3294use the @code{continue} command, or @code{step}, or any other command
3295that resumes execution.
3296
3297Any other commands in the command list, after a command that resumes
3298execution, are ignored. This is because any time you resume execution
3299(even with a simple @code{next} or @code{step}), you may encounter
3300another breakpoint---which could have its own command list, leading to
3301ambiguities about which list to execute.
3302
3303@kindex silent
3304If the first command you specify in a command list is @code{silent}, the
3305usual message about stopping at a breakpoint is not printed. This may
3306be desirable for breakpoints that are to print a specific message and
3307then continue. If none of the remaining commands print anything, you
3308see no sign that the breakpoint was reached. @code{silent} is
3309meaningful only at the beginning of a breakpoint command list.
3310
3311The commands @code{echo}, @code{output}, and @code{printf} allow you to
3312print precisely controlled output, and are often useful in silent
3313breakpoints. @xref{Output, ,Commands for controlled output}.
3314
3315For example, here is how you could use breakpoint commands to print the
3316value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3317
474c8240 3318@smallexample
c906108c
SS
3319break foo if x>0
3320commands
3321silent
3322printf "x is %d\n",x
3323cont
3324end
474c8240 3325@end smallexample
c906108c
SS
3326
3327One application for breakpoint commands is to compensate for one bug so
3328you can test for another. Put a breakpoint just after the erroneous line
3329of code, give it a condition to detect the case in which something
3330erroneous has been done, and give it commands to assign correct values
3331to any variables that need them. End with the @code{continue} command
3332so that your program does not stop, and start with the @code{silent}
3333command so that no output is produced. Here is an example:
3334
474c8240 3335@smallexample
c906108c
SS
3336break 403
3337commands
3338silent
3339set x = y + 4
3340cont
3341end
474c8240 3342@end smallexample
c906108c 3343
6d2ebf8b 3344@node Breakpoint Menus
c906108c
SS
3345@subsection Breakpoint menus
3346@cindex overloading
3347@cindex symbol overloading
3348
b383017d 3349Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3350single function name
c906108c
SS
3351to be defined several times, for application in different contexts.
3352This is called @dfn{overloading}. When a function name is overloaded,
3353@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3354a breakpoint. If you realize this is a problem, you can use
3355something like @samp{break @var{function}(@var{types})} to specify which
3356particular version of the function you want. Otherwise, @value{GDBN} offers
3357you a menu of numbered choices for different possible breakpoints, and
3358waits for your selection with the prompt @samp{>}. The first two
3359options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3360sets a breakpoint at each definition of @var{function}, and typing
3361@kbd{0} aborts the @code{break} command without setting any new
3362breakpoints.
3363
3364For example, the following session excerpt shows an attempt to set a
3365breakpoint at the overloaded symbol @code{String::after}.
3366We choose three particular definitions of that function name:
3367
3368@c FIXME! This is likely to change to show arg type lists, at least
3369@smallexample
3370@group
3371(@value{GDBP}) b String::after
3372[0] cancel
3373[1] all
3374[2] file:String.cc; line number:867
3375[3] file:String.cc; line number:860
3376[4] file:String.cc; line number:875
3377[5] file:String.cc; line number:853
3378[6] file:String.cc; line number:846
3379[7] file:String.cc; line number:735
3380> 2 4 6
3381Breakpoint 1 at 0xb26c: file String.cc, line 867.
3382Breakpoint 2 at 0xb344: file String.cc, line 875.
3383Breakpoint 3 at 0xafcc: file String.cc, line 846.
3384Multiple breakpoints were set.
3385Use the "delete" command to delete unwanted
3386 breakpoints.
3387(@value{GDBP})
3388@end group
3389@end smallexample
c906108c
SS
3390
3391@c @ifclear BARETARGET
6d2ebf8b 3392@node Error in Breakpoints
d4f3574e 3393@subsection ``Cannot insert breakpoints''
c906108c
SS
3394@c
3395@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3396@c
d4f3574e
SS
3397Under some operating systems, breakpoints cannot be used in a program if
3398any other process is running that program. In this situation,
5d161b24 3399attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3400@value{GDBN} to print an error message:
3401
474c8240 3402@smallexample
d4f3574e
SS
3403Cannot insert breakpoints.
3404The same program may be running in another process.
474c8240 3405@end smallexample
d4f3574e
SS
3406
3407When this happens, you have three ways to proceed:
3408
3409@enumerate
3410@item
3411Remove or disable the breakpoints, then continue.
3412
3413@item
5d161b24 3414Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3415name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3416that @value{GDBN} should run your program under that name.
d4f3574e
SS
3417Then start your program again.
3418
3419@item
3420Relink your program so that the text segment is nonsharable, using the
3421linker option @samp{-N}. The operating system limitation may not apply
3422to nonsharable executables.
3423@end enumerate
c906108c
SS
3424@c @end ifclear
3425
d4f3574e
SS
3426A similar message can be printed if you request too many active
3427hardware-assisted breakpoints and watchpoints:
3428
3429@c FIXME: the precise wording of this message may change; the relevant
3430@c source change is not committed yet (Sep 3, 1999).
3431@smallexample
3432Stopped; cannot insert breakpoints.
3433You may have requested too many hardware breakpoints and watchpoints.
3434@end smallexample
3435
3436@noindent
3437This message is printed when you attempt to resume the program, since
3438only then @value{GDBN} knows exactly how many hardware breakpoints and
3439watchpoints it needs to insert.
3440
3441When this message is printed, you need to disable or remove some of the
3442hardware-assisted breakpoints and watchpoints, and then continue.
3443
1485d690
KB
3444@node Breakpoint related warnings
3445@subsection ``Breakpoint address adjusted...''
3446@cindex breakpoint address adjusted
3447
3448Some processor architectures place constraints on the addresses at
3449which breakpoints may be placed. For architectures thus constrained,
3450@value{GDBN} will attempt to adjust the breakpoint's address to comply
3451with the constraints dictated by the architecture.
3452
3453One example of such an architecture is the Fujitsu FR-V. The FR-V is
3454a VLIW architecture in which a number of RISC-like instructions may be
3455bundled together for parallel execution. The FR-V architecture
3456constrains the location of a breakpoint instruction within such a
3457bundle to the instruction with the lowest address. @value{GDBN}
3458honors this constraint by adjusting a breakpoint's address to the
3459first in the bundle.
3460
3461It is not uncommon for optimized code to have bundles which contain
3462instructions from different source statements, thus it may happen that
3463a breakpoint's address will be adjusted from one source statement to
3464another. Since this adjustment may significantly alter @value{GDBN}'s
3465breakpoint related behavior from what the user expects, a warning is
3466printed when the breakpoint is first set and also when the breakpoint
3467is hit.
3468
3469A warning like the one below is printed when setting a breakpoint
3470that's been subject to address adjustment:
3471
3472@smallexample
3473warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3474@end smallexample
3475
3476Such warnings are printed both for user settable and @value{GDBN}'s
3477internal breakpoints. If you see one of these warnings, you should
3478verify that a breakpoint set at the adjusted address will have the
3479desired affect. If not, the breakpoint in question may be removed and
b383017d 3480other breakpoints may be set which will have the desired behavior.
1485d690
KB
3481E.g., it may be sufficient to place the breakpoint at a later
3482instruction. A conditional breakpoint may also be useful in some
3483cases to prevent the breakpoint from triggering too often.
3484
3485@value{GDBN} will also issue a warning when stopping at one of these
3486adjusted breakpoints:
3487
3488@smallexample
3489warning: Breakpoint 1 address previously adjusted from 0x00010414
3490to 0x00010410.
3491@end smallexample
3492
3493When this warning is encountered, it may be too late to take remedial
3494action except in cases where the breakpoint is hit earlier or more
3495frequently than expected.
d4f3574e 3496
6d2ebf8b 3497@node Continuing and Stepping
c906108c
SS
3498@section Continuing and stepping
3499
3500@cindex stepping
3501@cindex continuing
3502@cindex resuming execution
3503@dfn{Continuing} means resuming program execution until your program
3504completes normally. In contrast, @dfn{stepping} means executing just
3505one more ``step'' of your program, where ``step'' may mean either one
3506line of source code, or one machine instruction (depending on what
7a292a7a
SS
3507particular command you use). Either when continuing or when stepping,
3508your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3509it stops due to a signal, you may want to use @code{handle}, or use
3510@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3511
3512@table @code
3513@kindex continue
41afff9a
EZ
3514@kindex c @r{(@code{continue})}
3515@kindex fg @r{(resume foreground execution)}
c906108c
SS
3516@item continue @r{[}@var{ignore-count}@r{]}
3517@itemx c @r{[}@var{ignore-count}@r{]}
3518@itemx fg @r{[}@var{ignore-count}@r{]}
3519Resume program execution, at the address where your program last stopped;
3520any breakpoints set at that address are bypassed. The optional argument
3521@var{ignore-count} allows you to specify a further number of times to
3522ignore a breakpoint at this location; its effect is like that of
3523@code{ignore} (@pxref{Conditions, ,Break conditions}).
3524
3525The argument @var{ignore-count} is meaningful only when your program
3526stopped due to a breakpoint. At other times, the argument to
3527@code{continue} is ignored.
3528
d4f3574e
SS
3529The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3530debugged program is deemed to be the foreground program) are provided
3531purely for convenience, and have exactly the same behavior as
3532@code{continue}.
c906108c
SS
3533@end table
3534
3535To resume execution at a different place, you can use @code{return}
3536(@pxref{Returning, ,Returning from a function}) to go back to the
3537calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3538different address}) to go to an arbitrary location in your program.
3539
3540A typical technique for using stepping is to set a breakpoint
3541(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3542beginning of the function or the section of your program where a problem
3543is believed to lie, run your program until it stops at that breakpoint,
3544and then step through the suspect area, examining the variables that are
3545interesting, until you see the problem happen.
3546
3547@table @code
3548@kindex step
41afff9a 3549@kindex s @r{(@code{step})}
c906108c
SS
3550@item step
3551Continue running your program until control reaches a different source
3552line, then stop it and return control to @value{GDBN}. This command is
3553abbreviated @code{s}.
3554
3555@quotation
3556@c "without debugging information" is imprecise; actually "without line
3557@c numbers in the debugging information". (gcc -g1 has debugging info but
3558@c not line numbers). But it seems complex to try to make that
3559@c distinction here.
3560@emph{Warning:} If you use the @code{step} command while control is
3561within a function that was compiled without debugging information,
3562execution proceeds until control reaches a function that does have
3563debugging information. Likewise, it will not step into a function which
3564is compiled without debugging information. To step through functions
3565without debugging information, use the @code{stepi} command, described
3566below.
3567@end quotation
3568
4a92d011
EZ
3569The @code{step} command only stops at the first instruction of a source
3570line. This prevents the multiple stops that could otherwise occur in
3571@code{switch} statements, @code{for} loops, etc. @code{step} continues
3572to stop if a function that has debugging information is called within
3573the line. In other words, @code{step} @emph{steps inside} any functions
3574called within the line.
c906108c 3575
d4f3574e
SS
3576Also, the @code{step} command only enters a function if there is line
3577number information for the function. Otherwise it acts like the
5d161b24 3578@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3579on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3580was any debugging information about the routine.
c906108c
SS
3581
3582@item step @var{count}
3583Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3584breakpoint is reached, or a signal not related to stepping occurs before
3585@var{count} steps, stepping stops right away.
c906108c
SS
3586
3587@kindex next
41afff9a 3588@kindex n @r{(@code{next})}
c906108c
SS
3589@item next @r{[}@var{count}@r{]}
3590Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3591This is similar to @code{step}, but function calls that appear within
3592the line of code are executed without stopping. Execution stops when
3593control reaches a different line of code at the original stack level
3594that was executing when you gave the @code{next} command. This command
3595is abbreviated @code{n}.
c906108c
SS
3596
3597An argument @var{count} is a repeat count, as for @code{step}.
3598
3599
3600@c FIX ME!! Do we delete this, or is there a way it fits in with
3601@c the following paragraph? --- Vctoria
3602@c
3603@c @code{next} within a function that lacks debugging information acts like
3604@c @code{step}, but any function calls appearing within the code of the
3605@c function are executed without stopping.
3606
d4f3574e
SS
3607The @code{next} command only stops at the first instruction of a
3608source line. This prevents multiple stops that could otherwise occur in
4a92d011 3609@code{switch} statements, @code{for} loops, etc.
c906108c 3610
b90a5f51
CF
3611@kindex set step-mode
3612@item set step-mode
3613@cindex functions without line info, and stepping
3614@cindex stepping into functions with no line info
3615@itemx set step-mode on
4a92d011 3616The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3617stop at the first instruction of a function which contains no debug line
3618information rather than stepping over it.
3619
4a92d011
EZ
3620This is useful in cases where you may be interested in inspecting the
3621machine instructions of a function which has no symbolic info and do not
3622want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3623
3624@item set step-mode off
4a92d011 3625Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3626debug information. This is the default.
3627
9c16f35a
EZ
3628@item show step-mode
3629Show whether @value{GDBN} will stop in or step over functions without
3630source line debug information.
3631
c906108c
SS
3632@kindex finish
3633@item finish
3634Continue running until just after function in the selected stack frame
3635returns. Print the returned value (if any).
3636
3637Contrast this with the @code{return} command (@pxref{Returning,
3638,Returning from a function}).
3639
3640@kindex until
41afff9a 3641@kindex u @r{(@code{until})}
09d4efe1 3642@cindex run until specified location
c906108c
SS
3643@item until
3644@itemx u
3645Continue running until a source line past the current line, in the
3646current stack frame, is reached. This command is used to avoid single
3647stepping through a loop more than once. It is like the @code{next}
3648command, except that when @code{until} encounters a jump, it
3649automatically continues execution until the program counter is greater
3650than the address of the jump.
3651
3652This means that when you reach the end of a loop after single stepping
3653though it, @code{until} makes your program continue execution until it
3654exits the loop. In contrast, a @code{next} command at the end of a loop
3655simply steps back to the beginning of the loop, which forces you to step
3656through the next iteration.
3657
3658@code{until} always stops your program if it attempts to exit the current
3659stack frame.
3660
3661@code{until} may produce somewhat counterintuitive results if the order
3662of machine code does not match the order of the source lines. For
3663example, in the following excerpt from a debugging session, the @code{f}
3664(@code{frame}) command shows that execution is stopped at line
3665@code{206}; yet when we use @code{until}, we get to line @code{195}:
3666
474c8240 3667@smallexample
c906108c
SS
3668(@value{GDBP}) f
3669#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3670206 expand_input();
3671(@value{GDBP}) until
3672195 for ( ; argc > 0; NEXTARG) @{
474c8240 3673@end smallexample
c906108c
SS
3674
3675This happened because, for execution efficiency, the compiler had
3676generated code for the loop closure test at the end, rather than the
3677start, of the loop---even though the test in a C @code{for}-loop is
3678written before the body of the loop. The @code{until} command appeared
3679to step back to the beginning of the loop when it advanced to this
3680expression; however, it has not really gone to an earlier
3681statement---not in terms of the actual machine code.
3682
3683@code{until} with no argument works by means of single
3684instruction stepping, and hence is slower than @code{until} with an
3685argument.
3686
3687@item until @var{location}
3688@itemx u @var{location}
3689Continue running your program until either the specified location is
3690reached, or the current stack frame returns. @var{location} is any of
3691the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3692,Setting breakpoints}). This form of the command uses breakpoints, and
3693hence is quicker than @code{until} without an argument. The specified
3694location is actually reached only if it is in the current frame. This
3695implies that @code{until} can be used to skip over recursive function
3696invocations. For instance in the code below, if the current location is
3697line @code{96}, issuing @code{until 99} will execute the program up to
3698line @code{99} in the same invocation of factorial, i.e. after the inner
3699invocations have returned.
3700
3701@smallexample
370294 int factorial (int value)
370395 @{
370496 if (value > 1) @{
370597 value *= factorial (value - 1);
370698 @}
370799 return (value);
3708100 @}
3709@end smallexample
3710
3711
3712@kindex advance @var{location}
3713@itemx advance @var{location}
09d4efe1
EZ
3714Continue running the program up to the given @var{location}. An argument is
3715required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3716command. Execution will also stop upon exit from the current stack
3717frame. This command is similar to @code{until}, but @code{advance} will
3718not skip over recursive function calls, and the target location doesn't
3719have to be in the same frame as the current one.
3720
c906108c
SS
3721
3722@kindex stepi
41afff9a 3723@kindex si @r{(@code{stepi})}
c906108c 3724@item stepi
96a2c332 3725@itemx stepi @var{arg}
c906108c
SS
3726@itemx si
3727Execute one machine instruction, then stop and return to the debugger.
3728
3729It is often useful to do @samp{display/i $pc} when stepping by machine
3730instructions. This makes @value{GDBN} automatically display the next
3731instruction to be executed, each time your program stops. @xref{Auto
3732Display,, Automatic display}.
3733
3734An argument is a repeat count, as in @code{step}.
3735
3736@need 750
3737@kindex nexti
41afff9a 3738@kindex ni @r{(@code{nexti})}
c906108c 3739@item nexti
96a2c332 3740@itemx nexti @var{arg}
c906108c
SS
3741@itemx ni
3742Execute one machine instruction, but if it is a function call,
3743proceed until the function returns.
3744
3745An argument is a repeat count, as in @code{next}.
3746@end table
3747
6d2ebf8b 3748@node Signals
c906108c
SS
3749@section Signals
3750@cindex signals
3751
3752A signal is an asynchronous event that can happen in a program. The
3753operating system defines the possible kinds of signals, and gives each
3754kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3755signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3756@code{SIGSEGV} is the signal a program gets from referencing a place in
3757memory far away from all the areas in use; @code{SIGALRM} occurs when
3758the alarm clock timer goes off (which happens only if your program has
3759requested an alarm).
3760
3761@cindex fatal signals
3762Some signals, including @code{SIGALRM}, are a normal part of the
3763functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3764errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3765program has not specified in advance some other way to handle the signal.
3766@code{SIGINT} does not indicate an error in your program, but it is normally
3767fatal so it can carry out the purpose of the interrupt: to kill the program.
3768
3769@value{GDBN} has the ability to detect any occurrence of a signal in your
3770program. You can tell @value{GDBN} in advance what to do for each kind of
3771signal.
3772
3773@cindex handling signals
24f93129
EZ
3774Normally, @value{GDBN} is set up to let the non-erroneous signals like
3775@code{SIGALRM} be silently passed to your program
3776(so as not to interfere with their role in the program's functioning)
c906108c
SS
3777but to stop your program immediately whenever an error signal happens.
3778You can change these settings with the @code{handle} command.
3779
3780@table @code
3781@kindex info signals
09d4efe1 3782@kindex info handle
c906108c 3783@item info signals
96a2c332 3784@itemx info handle
c906108c
SS
3785Print a table of all the kinds of signals and how @value{GDBN} has been told to
3786handle each one. You can use this to see the signal numbers of all
3787the defined types of signals.
3788
d4f3574e 3789@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3790
3791@kindex handle
3792@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3793Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3794can be the number of a signal or its name (with or without the
24f93129 3795@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3796@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3797known signals. The @var{keywords} say what change to make.
c906108c
SS
3798@end table
3799
3800@c @group
3801The keywords allowed by the @code{handle} command can be abbreviated.
3802Their full names are:
3803
3804@table @code
3805@item nostop
3806@value{GDBN} should not stop your program when this signal happens. It may
3807still print a message telling you that the signal has come in.
3808
3809@item stop
3810@value{GDBN} should stop your program when this signal happens. This implies
3811the @code{print} keyword as well.
3812
3813@item print
3814@value{GDBN} should print a message when this signal happens.
3815
3816@item noprint
3817@value{GDBN} should not mention the occurrence of the signal at all. This
3818implies the @code{nostop} keyword as well.
3819
3820@item pass
5ece1a18 3821@itemx noignore
c906108c
SS
3822@value{GDBN} should allow your program to see this signal; your program
3823can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3824and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3825
3826@item nopass
5ece1a18 3827@itemx ignore
c906108c 3828@value{GDBN} should not allow your program to see this signal.
5ece1a18 3829@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3830@end table
3831@c @end group
3832
d4f3574e
SS
3833When a signal stops your program, the signal is not visible to the
3834program until you
c906108c
SS
3835continue. Your program sees the signal then, if @code{pass} is in
3836effect for the signal in question @emph{at that time}. In other words,
3837after @value{GDBN} reports a signal, you can use the @code{handle}
3838command with @code{pass} or @code{nopass} to control whether your
3839program sees that signal when you continue.
3840
24f93129
EZ
3841The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3842non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3843@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3844erroneous signals.
3845
c906108c
SS
3846You can also use the @code{signal} command to prevent your program from
3847seeing a signal, or cause it to see a signal it normally would not see,
3848or to give it any signal at any time. For example, if your program stopped
3849due to some sort of memory reference error, you might store correct
3850values into the erroneous variables and continue, hoping to see more
3851execution; but your program would probably terminate immediately as
3852a result of the fatal signal once it saw the signal. To prevent this,
3853you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3854program a signal}.
c906108c 3855
6d2ebf8b 3856@node Thread Stops
c906108c
SS
3857@section Stopping and starting multi-thread programs
3858
3859When your program has multiple threads (@pxref{Threads,, Debugging
3860programs with multiple threads}), you can choose whether to set
3861breakpoints on all threads, or on a particular thread.
3862
3863@table @code
3864@cindex breakpoints and threads
3865@cindex thread breakpoints
3866@kindex break @dots{} thread @var{threadno}
3867@item break @var{linespec} thread @var{threadno}
3868@itemx break @var{linespec} thread @var{threadno} if @dots{}
3869@var{linespec} specifies source lines; there are several ways of
3870writing them, but the effect is always to specify some source line.
3871
3872Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3873to specify that you only want @value{GDBN} to stop the program when a
3874particular thread reaches this breakpoint. @var{threadno} is one of the
3875numeric thread identifiers assigned by @value{GDBN}, shown in the first
3876column of the @samp{info threads} display.
3877
3878If you do not specify @samp{thread @var{threadno}} when you set a
3879breakpoint, the breakpoint applies to @emph{all} threads of your
3880program.
3881
3882You can use the @code{thread} qualifier on conditional breakpoints as
3883well; in this case, place @samp{thread @var{threadno}} before the
3884breakpoint condition, like this:
3885
3886@smallexample
2df3850c 3887(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3888@end smallexample
3889
3890@end table
3891
3892@cindex stopped threads
3893@cindex threads, stopped
3894Whenever your program stops under @value{GDBN} for any reason,
3895@emph{all} threads of execution stop, not just the current thread. This
3896allows you to examine the overall state of the program, including
3897switching between threads, without worrying that things may change
3898underfoot.
3899
36d86913
MC
3900@cindex thread breakpoints and system calls
3901@cindex system calls and thread breakpoints
3902@cindex premature return from system calls
3903There is an unfortunate side effect. If one thread stops for a
3904breakpoint, or for some other reason, and another thread is blocked in a
3905system call, then the system call may return prematurely. This is a
3906consequence of the interaction between multiple threads and the signals
3907that @value{GDBN} uses to implement breakpoints and other events that
3908stop execution.
3909
3910To handle this problem, your program should check the return value of
3911each system call and react appropriately. This is good programming
3912style anyways.
3913
3914For example, do not write code like this:
3915
3916@smallexample
3917 sleep (10);
3918@end smallexample
3919
3920The call to @code{sleep} will return early if a different thread stops
3921at a breakpoint or for some other reason.
3922
3923Instead, write this:
3924
3925@smallexample
3926 int unslept = 10;
3927 while (unslept > 0)
3928 unslept = sleep (unslept);
3929@end smallexample
3930
3931A system call is allowed to return early, so the system is still
3932conforming to its specification. But @value{GDBN} does cause your
3933multi-threaded program to behave differently than it would without
3934@value{GDBN}.
3935
3936Also, @value{GDBN} uses internal breakpoints in the thread library to
3937monitor certain events such as thread creation and thread destruction.
3938When such an event happens, a system call in another thread may return
3939prematurely, even though your program does not appear to stop.
3940
c906108c
SS
3941@cindex continuing threads
3942@cindex threads, continuing
3943Conversely, whenever you restart the program, @emph{all} threads start
3944executing. @emph{This is true even when single-stepping} with commands
5d161b24 3945like @code{step} or @code{next}.
c906108c
SS
3946
3947In particular, @value{GDBN} cannot single-step all threads in lockstep.
3948Since thread scheduling is up to your debugging target's operating
3949system (not controlled by @value{GDBN}), other threads may
3950execute more than one statement while the current thread completes a
3951single step. Moreover, in general other threads stop in the middle of a
3952statement, rather than at a clean statement boundary, when the program
3953stops.
3954
3955You might even find your program stopped in another thread after
3956continuing or even single-stepping. This happens whenever some other
3957thread runs into a breakpoint, a signal, or an exception before the
3958first thread completes whatever you requested.
3959
3960On some OSes, you can lock the OS scheduler and thus allow only a single
3961thread to run.
3962
3963@table @code
3964@item set scheduler-locking @var{mode}
9c16f35a
EZ
3965@cindex scheduler locking mode
3966@cindex lock scheduler
c906108c
SS
3967Set the scheduler locking mode. If it is @code{off}, then there is no
3968locking and any thread may run at any time. If @code{on}, then only the
3969current thread may run when the inferior is resumed. The @code{step}
3970mode optimizes for single-stepping. It stops other threads from
3971``seizing the prompt'' by preempting the current thread while you are
3972stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 3973when you step. They are more likely to run when you @samp{next} over a
c906108c 3974function call, and they are completely free to run when you use commands
d4f3574e 3975like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 3976thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 3977@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
3978
3979@item show scheduler-locking
3980Display the current scheduler locking mode.
3981@end table
3982
c906108c 3983
6d2ebf8b 3984@node Stack
c906108c
SS
3985@chapter Examining the Stack
3986
3987When your program has stopped, the first thing you need to know is where it
3988stopped and how it got there.
3989
3990@cindex call stack
5d161b24
DB
3991Each time your program performs a function call, information about the call
3992is generated.
3993That information includes the location of the call in your program,
3994the arguments of the call,
c906108c 3995and the local variables of the function being called.
5d161b24 3996The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
3997The stack frames are allocated in a region of memory called the @dfn{call
3998stack}.
3999
4000When your program stops, the @value{GDBN} commands for examining the
4001stack allow you to see all of this information.
4002
4003@cindex selected frame
4004One of the stack frames is @dfn{selected} by @value{GDBN} and many
4005@value{GDBN} commands refer implicitly to the selected frame. In
4006particular, whenever you ask @value{GDBN} for the value of a variable in
4007your program, the value is found in the selected frame. There are
4008special @value{GDBN} commands to select whichever frame you are
4009interested in. @xref{Selection, ,Selecting a frame}.
4010
4011When your program stops, @value{GDBN} automatically selects the
5d161b24 4012currently executing frame and describes it briefly, similar to the
c906108c
SS
4013@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4014
4015@menu
4016* Frames:: Stack frames
4017* Backtrace:: Backtraces
4018* Selection:: Selecting a frame
4019* Frame Info:: Information on a frame
c906108c
SS
4020
4021@end menu
4022
6d2ebf8b 4023@node Frames
c906108c
SS
4024@section Stack frames
4025
d4f3574e 4026@cindex frame, definition
c906108c
SS
4027@cindex stack frame
4028The call stack is divided up into contiguous pieces called @dfn{stack
4029frames}, or @dfn{frames} for short; each frame is the data associated
4030with one call to one function. The frame contains the arguments given
4031to the function, the function's local variables, and the address at
4032which the function is executing.
4033
4034@cindex initial frame
4035@cindex outermost frame
4036@cindex innermost frame
4037When your program is started, the stack has only one frame, that of the
4038function @code{main}. This is called the @dfn{initial} frame or the
4039@dfn{outermost} frame. Each time a function is called, a new frame is
4040made. Each time a function returns, the frame for that function invocation
4041is eliminated. If a function is recursive, there can be many frames for
4042the same function. The frame for the function in which execution is
4043actually occurring is called the @dfn{innermost} frame. This is the most
4044recently created of all the stack frames that still exist.
4045
4046@cindex frame pointer
4047Inside your program, stack frames are identified by their addresses. A
4048stack frame consists of many bytes, each of which has its own address; each
4049kind of computer has a convention for choosing one byte whose
4050address serves as the address of the frame. Usually this address is kept
4051in a register called the @dfn{frame pointer register} while execution is
4052going on in that frame.
4053
4054@cindex frame number
4055@value{GDBN} assigns numbers to all existing stack frames, starting with
4056zero for the innermost frame, one for the frame that called it,
4057and so on upward. These numbers do not really exist in your program;
4058they are assigned by @value{GDBN} to give you a way of designating stack
4059frames in @value{GDBN} commands.
4060
6d2ebf8b
SS
4061@c The -fomit-frame-pointer below perennially causes hbox overflow
4062@c underflow problems.
c906108c
SS
4063@cindex frameless execution
4064Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4065without stack frames. (For example, the @value{GCC} option
474c8240 4066@smallexample
6d2ebf8b 4067@samp{-fomit-frame-pointer}
474c8240 4068@end smallexample
6d2ebf8b 4069generates functions without a frame.)
c906108c
SS
4070This is occasionally done with heavily used library functions to save
4071the frame setup time. @value{GDBN} has limited facilities for dealing
4072with these function invocations. If the innermost function invocation
4073has no stack frame, @value{GDBN} nevertheless regards it as though
4074it had a separate frame, which is numbered zero as usual, allowing
4075correct tracing of the function call chain. However, @value{GDBN} has
4076no provision for frameless functions elsewhere in the stack.
4077
4078@table @code
d4f3574e 4079@kindex frame@r{, command}
41afff9a 4080@cindex current stack frame
c906108c 4081@item frame @var{args}
5d161b24 4082The @code{frame} command allows you to move from one stack frame to another,
c906108c 4083and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4084address of the frame or the stack frame number. Without an argument,
4085@code{frame} prints the current stack frame.
c906108c
SS
4086
4087@kindex select-frame
41afff9a 4088@cindex selecting frame silently
c906108c
SS
4089@item select-frame
4090The @code{select-frame} command allows you to move from one stack frame
4091to another without printing the frame. This is the silent version of
4092@code{frame}.
4093@end table
4094
6d2ebf8b 4095@node Backtrace
c906108c
SS
4096@section Backtraces
4097
09d4efe1
EZ
4098@cindex traceback
4099@cindex call stack traces
c906108c
SS
4100A backtrace is a summary of how your program got where it is. It shows one
4101line per frame, for many frames, starting with the currently executing
4102frame (frame zero), followed by its caller (frame one), and on up the
4103stack.
4104
4105@table @code
4106@kindex backtrace
41afff9a 4107@kindex bt @r{(@code{backtrace})}
c906108c
SS
4108@item backtrace
4109@itemx bt
4110Print a backtrace of the entire stack: one line per frame for all
4111frames in the stack.
4112
4113You can stop the backtrace at any time by typing the system interrupt
4114character, normally @kbd{C-c}.
4115
4116@item backtrace @var{n}
4117@itemx bt @var{n}
4118Similar, but print only the innermost @var{n} frames.
4119
4120@item backtrace -@var{n}
4121@itemx bt -@var{n}
4122Similar, but print only the outermost @var{n} frames.
4123@end table
4124
4125@kindex where
4126@kindex info stack
c906108c
SS
4127The names @code{where} and @code{info stack} (abbreviated @code{info s})
4128are additional aliases for @code{backtrace}.
4129
4130Each line in the backtrace shows the frame number and the function name.
4131The program counter value is also shown---unless you use @code{set
4132print address off}. The backtrace also shows the source file name and
4133line number, as well as the arguments to the function. The program
4134counter value is omitted if it is at the beginning of the code for that
4135line number.
4136
4137Here is an example of a backtrace. It was made with the command
4138@samp{bt 3}, so it shows the innermost three frames.
4139
4140@smallexample
4141@group
5d161b24 4142#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4143 at builtin.c:993
4144#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4145#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4146 at macro.c:71
4147(More stack frames follow...)
4148@end group
4149@end smallexample
4150
4151@noindent
4152The display for frame zero does not begin with a program counter
4153value, indicating that your program has stopped at the beginning of the
4154code for line @code{993} of @code{builtin.c}.
4155
a8f24a35
EZ
4156@cindex backtrace beyond @code{main} function
4157@cindex program entry point
4158@cindex startup code, and backtrace
25d29d70
AC
4159Most programs have a standard user entry point---a place where system
4160libraries and startup code transition into user code. For C this is
4161@code{main}. When @value{GDBN} finds the entry function in a backtrace
4162it will terminate the backtrace, to avoid tracing into highly
4163system-specific (and generally uninteresting) code.
4164
4165If you need to examine the startup code, or limit the number of levels
4166in a backtrace, you can change this behavior:
95f90d25
DJ
4167
4168@table @code
25d29d70
AC
4169@item set backtrace past-main
4170@itemx set backtrace past-main on
4644b6e3 4171@kindex set backtrace
25d29d70
AC
4172Backtraces will continue past the user entry point.
4173
4174@item set backtrace past-main off
95f90d25
DJ
4175Backtraces will stop when they encounter the user entry point. This is the
4176default.
4177
25d29d70 4178@item show backtrace past-main
4644b6e3 4179@kindex show backtrace
25d29d70
AC
4180Display the current user entry point backtrace policy.
4181
2315ffec
RC
4182@item set backtrace past-entry
4183@itemx set backtrace past-entry on
a8f24a35 4184Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4185This entry point is encoded by the linker when the application is built,
4186and is likely before the user entry point @code{main} (or equivalent) is called.
4187
4188@item set backtrace past-entry off
4189Backtraces will stop when they encouter the internal entry point of an
4190application. This is the default.
4191
4192@item show backtrace past-entry
4193Display the current internal entry point backtrace policy.
4194
25d29d70
AC
4195@item set backtrace limit @var{n}
4196@itemx set backtrace limit 0
4197@cindex backtrace limit
4198Limit the backtrace to @var{n} levels. A value of zero means
4199unlimited.
95f90d25 4200
25d29d70
AC
4201@item show backtrace limit
4202Display the current limit on backtrace levels.
95f90d25
DJ
4203@end table
4204
6d2ebf8b 4205@node Selection
c906108c
SS
4206@section Selecting a frame
4207
4208Most commands for examining the stack and other data in your program work on
4209whichever stack frame is selected at the moment. Here are the commands for
4210selecting a stack frame; all of them finish by printing a brief description
4211of the stack frame just selected.
4212
4213@table @code
d4f3574e 4214@kindex frame@r{, selecting}
41afff9a 4215@kindex f @r{(@code{frame})}
c906108c
SS
4216@item frame @var{n}
4217@itemx f @var{n}
4218Select frame number @var{n}. Recall that frame zero is the innermost
4219(currently executing) frame, frame one is the frame that called the
4220innermost one, and so on. The highest-numbered frame is the one for
4221@code{main}.
4222
4223@item frame @var{addr}
4224@itemx f @var{addr}
4225Select the frame at address @var{addr}. This is useful mainly if the
4226chaining of stack frames has been damaged by a bug, making it
4227impossible for @value{GDBN} to assign numbers properly to all frames. In
4228addition, this can be useful when your program has multiple stacks and
4229switches between them.
4230
c906108c
SS
4231On the SPARC architecture, @code{frame} needs two addresses to
4232select an arbitrary frame: a frame pointer and a stack pointer.
4233
4234On the MIPS and Alpha architecture, it needs two addresses: a stack
4235pointer and a program counter.
4236
4237On the 29k architecture, it needs three addresses: a register stack
4238pointer, a program counter, and a memory stack pointer.
4239@c note to future updaters: this is conditioned on a flag
4240@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4241@c as of 27 Jan 1994.
c906108c
SS
4242
4243@kindex up
4244@item up @var{n}
4245Move @var{n} frames up the stack. For positive numbers @var{n}, this
4246advances toward the outermost frame, to higher frame numbers, to frames
4247that have existed longer. @var{n} defaults to one.
4248
4249@kindex down
41afff9a 4250@kindex do @r{(@code{down})}
c906108c
SS
4251@item down @var{n}
4252Move @var{n} frames down the stack. For positive numbers @var{n}, this
4253advances toward the innermost frame, to lower frame numbers, to frames
4254that were created more recently. @var{n} defaults to one. You may
4255abbreviate @code{down} as @code{do}.
4256@end table
4257
4258All of these commands end by printing two lines of output describing the
4259frame. The first line shows the frame number, the function name, the
4260arguments, and the source file and line number of execution in that
5d161b24 4261frame. The second line shows the text of that source line.
c906108c
SS
4262
4263@need 1000
4264For example:
4265
4266@smallexample
4267@group
4268(@value{GDBP}) up
4269#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4270 at env.c:10
427110 read_input_file (argv[i]);
4272@end group
4273@end smallexample
4274
4275After such a printout, the @code{list} command with no arguments
4276prints ten lines centered on the point of execution in the frame.
87885426
FN
4277You can also edit the program at the point of execution with your favorite
4278editing program by typing @code{edit}.
4279@xref{List, ,Printing source lines},
4280for details.
c906108c
SS
4281
4282@table @code
4283@kindex down-silently
4284@kindex up-silently
4285@item up-silently @var{n}
4286@itemx down-silently @var{n}
4287These two commands are variants of @code{up} and @code{down},
4288respectively; they differ in that they do their work silently, without
4289causing display of the new frame. They are intended primarily for use
4290in @value{GDBN} command scripts, where the output might be unnecessary and
4291distracting.
4292@end table
4293
6d2ebf8b 4294@node Frame Info
c906108c
SS
4295@section Information about a frame
4296
4297There are several other commands to print information about the selected
4298stack frame.
4299
4300@table @code
4301@item frame
4302@itemx f
4303When used without any argument, this command does not change which
4304frame is selected, but prints a brief description of the currently
4305selected stack frame. It can be abbreviated @code{f}. With an
4306argument, this command is used to select a stack frame.
4307@xref{Selection, ,Selecting a frame}.
4308
4309@kindex info frame
41afff9a 4310@kindex info f @r{(@code{info frame})}
c906108c
SS
4311@item info frame
4312@itemx info f
4313This command prints a verbose description of the selected stack frame,
4314including:
4315
4316@itemize @bullet
5d161b24
DB
4317@item
4318the address of the frame
c906108c
SS
4319@item
4320the address of the next frame down (called by this frame)
4321@item
4322the address of the next frame up (caller of this frame)
4323@item
4324the language in which the source code corresponding to this frame is written
4325@item
4326the address of the frame's arguments
4327@item
d4f3574e
SS
4328the address of the frame's local variables
4329@item
c906108c
SS
4330the program counter saved in it (the address of execution in the caller frame)
4331@item
4332which registers were saved in the frame
4333@end itemize
4334
4335@noindent The verbose description is useful when
4336something has gone wrong that has made the stack format fail to fit
4337the usual conventions.
4338
4339@item info frame @var{addr}
4340@itemx info f @var{addr}
4341Print a verbose description of the frame at address @var{addr}, without
4342selecting that frame. The selected frame remains unchanged by this
4343command. This requires the same kind of address (more than one for some
4344architectures) that you specify in the @code{frame} command.
4345@xref{Selection, ,Selecting a frame}.
4346
4347@kindex info args
4348@item info args
4349Print the arguments of the selected frame, each on a separate line.
4350
4351@item info locals
4352@kindex info locals
4353Print the local variables of the selected frame, each on a separate
4354line. These are all variables (declared either static or automatic)
4355accessible at the point of execution of the selected frame.
4356
c906108c 4357@kindex info catch
d4f3574e
SS
4358@cindex catch exceptions, list active handlers
4359@cindex exception handlers, how to list
c906108c
SS
4360@item info catch
4361Print a list of all the exception handlers that are active in the
4362current stack frame at the current point of execution. To see other
4363exception handlers, visit the associated frame (using the @code{up},
4364@code{down}, or @code{frame} commands); then type @code{info catch}.
4365@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4366
c906108c
SS
4367@end table
4368
c906108c 4369
6d2ebf8b 4370@node Source
c906108c
SS
4371@chapter Examining Source Files
4372
4373@value{GDBN} can print parts of your program's source, since the debugging
4374information recorded in the program tells @value{GDBN} what source files were
4375used to build it. When your program stops, @value{GDBN} spontaneously prints
4376the line where it stopped. Likewise, when you select a stack frame
4377(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4378execution in that frame has stopped. You can print other portions of
4379source files by explicit command.
4380
7a292a7a 4381If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4382prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4383@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4384
4385@menu
4386* List:: Printing source lines
87885426 4387* Edit:: Editing source files
c906108c 4388* Search:: Searching source files
c906108c
SS
4389* Source Path:: Specifying source directories
4390* Machine Code:: Source and machine code
4391@end menu
4392
6d2ebf8b 4393@node List
c906108c
SS
4394@section Printing source lines
4395
4396@kindex list
41afff9a 4397@kindex l @r{(@code{list})}
c906108c 4398To print lines from a source file, use the @code{list} command
5d161b24 4399(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4400There are several ways to specify what part of the file you want to print.
4401
4402Here are the forms of the @code{list} command most commonly used:
4403
4404@table @code
4405@item list @var{linenum}
4406Print lines centered around line number @var{linenum} in the
4407current source file.
4408
4409@item list @var{function}
4410Print lines centered around the beginning of function
4411@var{function}.
4412
4413@item list
4414Print more lines. If the last lines printed were printed with a
4415@code{list} command, this prints lines following the last lines
4416printed; however, if the last line printed was a solitary line printed
4417as part of displaying a stack frame (@pxref{Stack, ,Examining the
4418Stack}), this prints lines centered around that line.
4419
4420@item list -
4421Print lines just before the lines last printed.
4422@end table
4423
9c16f35a 4424@cindex @code{list}, how many lines to display
c906108c
SS
4425By default, @value{GDBN} prints ten source lines with any of these forms of
4426the @code{list} command. You can change this using @code{set listsize}:
4427
4428@table @code
4429@kindex set listsize
4430@item set listsize @var{count}
4431Make the @code{list} command display @var{count} source lines (unless
4432the @code{list} argument explicitly specifies some other number).
4433
4434@kindex show listsize
4435@item show listsize
4436Display the number of lines that @code{list} prints.
4437@end table
4438
4439Repeating a @code{list} command with @key{RET} discards the argument,
4440so it is equivalent to typing just @code{list}. This is more useful
4441than listing the same lines again. An exception is made for an
4442argument of @samp{-}; that argument is preserved in repetition so that
4443each repetition moves up in the source file.
4444
4445@cindex linespec
4446In general, the @code{list} command expects you to supply zero, one or two
4447@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4448of writing them, but the effect is always to specify some source line.
c906108c
SS
4449Here is a complete description of the possible arguments for @code{list}:
4450
4451@table @code
4452@item list @var{linespec}
4453Print lines centered around the line specified by @var{linespec}.
4454
4455@item list @var{first},@var{last}
4456Print lines from @var{first} to @var{last}. Both arguments are
4457linespecs.
4458
4459@item list ,@var{last}
4460Print lines ending with @var{last}.
4461
4462@item list @var{first},
4463Print lines starting with @var{first}.
4464
4465@item list +
4466Print lines just after the lines last printed.
4467
4468@item list -
4469Print lines just before the lines last printed.
4470
4471@item list
4472As described in the preceding table.
4473@end table
4474
4475Here are the ways of specifying a single source line---all the
4476kinds of linespec.
4477
4478@table @code
4479@item @var{number}
4480Specifies line @var{number} of the current source file.
4481When a @code{list} command has two linespecs, this refers to
4482the same source file as the first linespec.
4483
4484@item +@var{offset}
4485Specifies the line @var{offset} lines after the last line printed.
4486When used as the second linespec in a @code{list} command that has
4487two, this specifies the line @var{offset} lines down from the
4488first linespec.
4489
4490@item -@var{offset}
4491Specifies the line @var{offset} lines before the last line printed.
4492
4493@item @var{filename}:@var{number}
4494Specifies line @var{number} in the source file @var{filename}.
4495
4496@item @var{function}
4497Specifies the line that begins the body of the function @var{function}.
4498For example: in C, this is the line with the open brace.
4499
4500@item @var{filename}:@var{function}
4501Specifies the line of the open-brace that begins the body of the
4502function @var{function} in the file @var{filename}. You only need the
4503file name with a function name to avoid ambiguity when there are
4504identically named functions in different source files.
4505
4506@item *@var{address}
4507Specifies the line containing the program address @var{address}.
4508@var{address} may be any expression.
4509@end table
4510
87885426
FN
4511@node Edit
4512@section Editing source files
4513@cindex editing source files
4514
4515@kindex edit
4516@kindex e @r{(@code{edit})}
4517To edit the lines in a source file, use the @code{edit} command.
4518The editing program of your choice
4519is invoked with the current line set to
4520the active line in the program.
4521Alternatively, there are several ways to specify what part of the file you
4522want to print if you want to see other parts of the program.
4523
4524Here are the forms of the @code{edit} command most commonly used:
4525
4526@table @code
4527@item edit
4528Edit the current source file at the active line number in the program.
4529
4530@item edit @var{number}
4531Edit the current source file with @var{number} as the active line number.
4532
4533@item edit @var{function}
4534Edit the file containing @var{function} at the beginning of its definition.
4535
4536@item edit @var{filename}:@var{number}
4537Specifies line @var{number} in the source file @var{filename}.
4538
4539@item edit @var{filename}:@var{function}
4540Specifies the line that begins the body of the
4541function @var{function} in the file @var{filename}. You only need the
4542file name with a function name to avoid ambiguity when there are
4543identically named functions in different source files.
4544
4545@item edit *@var{address}
4546Specifies the line containing the program address @var{address}.
4547@var{address} may be any expression.
4548@end table
4549
4550@subsection Choosing your editor
4551You can customize @value{GDBN} to use any editor you want
4552@footnote{
4553The only restriction is that your editor (say @code{ex}), recognizes the
4554following command-line syntax:
10998722 4555@smallexample
87885426 4556ex +@var{number} file
10998722 4557@end smallexample
15387254
EZ
4558The optional numeric value +@var{number} specifies the number of the line in
4559the file where to start editing.}.
4560By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4561by setting the environment variable @code{EDITOR} before using
4562@value{GDBN}. For example, to configure @value{GDBN} to use the
4563@code{vi} editor, you could use these commands with the @code{sh} shell:
4564@smallexample
87885426
FN
4565EDITOR=/usr/bin/vi
4566export EDITOR
15387254 4567gdb @dots{}
10998722 4568@end smallexample
87885426 4569or in the @code{csh} shell,
10998722 4570@smallexample
87885426 4571setenv EDITOR /usr/bin/vi
15387254 4572gdb @dots{}
10998722 4573@end smallexample
87885426 4574
6d2ebf8b 4575@node Search
c906108c 4576@section Searching source files
15387254 4577@cindex searching source files
c906108c
SS
4578
4579There are two commands for searching through the current source file for a
4580regular expression.
4581
4582@table @code
4583@kindex search
4584@kindex forward-search
4585@item forward-search @var{regexp}
4586@itemx search @var{regexp}
4587The command @samp{forward-search @var{regexp}} checks each line,
4588starting with the one following the last line listed, for a match for
5d161b24 4589@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4590synonym @samp{search @var{regexp}} or abbreviate the command name as
4591@code{fo}.
4592
09d4efe1 4593@kindex reverse-search
c906108c
SS
4594@item reverse-search @var{regexp}
4595The command @samp{reverse-search @var{regexp}} checks each line, starting
4596with the one before the last line listed and going backward, for a match
4597for @var{regexp}. It lists the line that is found. You can abbreviate
4598this command as @code{rev}.
4599@end table
c906108c 4600
6d2ebf8b 4601@node Source Path
c906108c
SS
4602@section Specifying source directories
4603
4604@cindex source path
4605@cindex directories for source files
4606Executable programs sometimes do not record the directories of the source
4607files from which they were compiled, just the names. Even when they do,
4608the directories could be moved between the compilation and your debugging
4609session. @value{GDBN} has a list of directories to search for source files;
4610this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4611it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4612in the list, until it finds a file with the desired name.
4613
4614For example, suppose an executable references the file
4615@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4616@file{/mnt/cross}. The file is first looked up literally; if this
4617fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4618fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4619message is printed. @value{GDBN} does not look up the parts of the
4620source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4621Likewise, the subdirectories of the source path are not searched: if
4622the source path is @file{/mnt/cross}, and the binary refers to
4623@file{foo.c}, @value{GDBN} would not find it under
4624@file{/mnt/cross/usr/src/foo-1.0/lib}.
4625
4626Plain file names, relative file names with leading directories, file
4627names containing dots, etc.@: are all treated as described above; for
4628instance, if the source path is @file{/mnt/cross}, and the source file
4629is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4630@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4631that---@file{/mnt/cross/foo.c}.
4632
4633Note that the executable search path is @emph{not} used to locate the
4634source files. Neither is the current working directory, unless it
4635happens to be in the source path.
c906108c
SS
4636
4637Whenever you reset or rearrange the source path, @value{GDBN} clears out
4638any information it has cached about where source files are found and where
4639each line is in the file.
4640
4641@kindex directory
4642@kindex dir
d4f3574e
SS
4643When you start @value{GDBN}, its source path includes only @samp{cdir}
4644and @samp{cwd}, in that order.
c906108c
SS
4645To add other directories, use the @code{directory} command.
4646
4647@table @code
4648@item directory @var{dirname} @dots{}
4649@item dir @var{dirname} @dots{}
4650Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4651directory names may be given to this command, separated by @samp{:}
4652(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4653part of absolute file names) or
c906108c
SS
4654whitespace. You may specify a directory that is already in the source
4655path; this moves it forward, so @value{GDBN} searches it sooner.
4656
4657@kindex cdir
4658@kindex cwd
41afff9a
EZ
4659@vindex $cdir@r{, convenience variable}
4660@vindex $cwdr@r{, convenience variable}
c906108c
SS
4661@cindex compilation directory
4662@cindex current directory
4663@cindex working directory
4664@cindex directory, current
4665@cindex directory, compilation
4666You can use the string @samp{$cdir} to refer to the compilation
4667directory (if one is recorded), and @samp{$cwd} to refer to the current
4668working directory. @samp{$cwd} is not the same as @samp{.}---the former
4669tracks the current working directory as it changes during your @value{GDBN}
4670session, while the latter is immediately expanded to the current
4671directory at the time you add an entry to the source path.
4672
4673@item directory
4674Reset the source path to empty again. This requires confirmation.
4675
4676@c RET-repeat for @code{directory} is explicitly disabled, but since
4677@c repeating it would be a no-op we do not say that. (thanks to RMS)
4678
4679@item show directories
4680@kindex show directories
4681Print the source path: show which directories it contains.
4682@end table
4683
4684If your source path is cluttered with directories that are no longer of
4685interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4686versions of source. You can correct the situation as follows:
4687
4688@enumerate
4689@item
4690Use @code{directory} with no argument to reset the source path to empty.
4691
4692@item
4693Use @code{directory} with suitable arguments to reinstall the
4694directories you want in the source path. You can add all the
4695directories in one command.
4696@end enumerate
4697
6d2ebf8b 4698@node Machine Code
c906108c 4699@section Source and machine code
15387254 4700@cindex source line and its code address
c906108c
SS
4701
4702You can use the command @code{info line} to map source lines to program
4703addresses (and vice versa), and the command @code{disassemble} to display
4704a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4705mode, the @code{info line} command causes the arrow to point to the
5d161b24 4706line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4707well as hex.
4708
4709@table @code
4710@kindex info line
4711@item info line @var{linespec}
4712Print the starting and ending addresses of the compiled code for
4713source line @var{linespec}. You can specify source lines in any of
4714the ways understood by the @code{list} command (@pxref{List, ,Printing
4715source lines}).
4716@end table
4717
4718For example, we can use @code{info line} to discover the location of
4719the object code for the first line of function
4720@code{m4_changequote}:
4721
d4f3574e
SS
4722@c FIXME: I think this example should also show the addresses in
4723@c symbolic form, as they usually would be displayed.
c906108c 4724@smallexample
96a2c332 4725(@value{GDBP}) info line m4_changequote
c906108c
SS
4726Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4727@end smallexample
4728
4729@noindent
15387254 4730@cindex code address and its source line
c906108c
SS
4731We can also inquire (using @code{*@var{addr}} as the form for
4732@var{linespec}) what source line covers a particular address:
4733@smallexample
4734(@value{GDBP}) info line *0x63ff
4735Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4736@end smallexample
4737
4738@cindex @code{$_} and @code{info line}
15387254 4739@cindex @code{x} command, default address
41afff9a 4740@kindex x@r{(examine), and} info line
c906108c
SS
4741After @code{info line}, the default address for the @code{x} command
4742is changed to the starting address of the line, so that @samp{x/i} is
4743sufficient to begin examining the machine code (@pxref{Memory,
4744,Examining memory}). Also, this address is saved as the value of the
4745convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4746variables}).
4747
4748@table @code
4749@kindex disassemble
4750@cindex assembly instructions
4751@cindex instructions, assembly
4752@cindex machine instructions
4753@cindex listing machine instructions
4754@item disassemble
4755This specialized command dumps a range of memory as machine
4756instructions. The default memory range is the function surrounding the
4757program counter of the selected frame. A single argument to this
4758command is a program counter value; @value{GDBN} dumps the function
4759surrounding this value. Two arguments specify a range of addresses
4760(first inclusive, second exclusive) to dump.
4761@end table
4762
c906108c
SS
4763The following example shows the disassembly of a range of addresses of
4764HP PA-RISC 2.0 code:
4765
4766@smallexample
4767(@value{GDBP}) disas 0x32c4 0x32e4
4768Dump of assembler code from 0x32c4 to 0x32e4:
47690x32c4 <main+204>: addil 0,dp
47700x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
47710x32cc <main+212>: ldil 0x3000,r31
47720x32d0 <main+216>: ble 0x3f8(sr4,r31)
47730x32d4 <main+220>: ldo 0(r31),rp
47740x32d8 <main+224>: addil -0x800,dp
47750x32dc <main+228>: ldo 0x588(r1),r26
47760x32e0 <main+232>: ldil 0x3000,r31
4777End of assembler dump.
4778@end smallexample
c906108c
SS
4779
4780Some architectures have more than one commonly-used set of instruction
4781mnemonics or other syntax.
4782
4783@table @code
d4f3574e 4784@kindex set disassembly-flavor
d4f3574e
SS
4785@cindex Intel disassembly flavor
4786@cindex AT&T disassembly flavor
4787@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4788Select the instruction set to use when disassembling the
4789program via the @code{disassemble} or @code{x/i} commands.
4790
4791Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4792can set @var{instruction-set} to either @code{intel} or @code{att}.
4793The default is @code{att}, the AT&T flavor used by default by Unix
4794assemblers for x86-based targets.
9c16f35a
EZ
4795
4796@kindex show disassembly-flavor
4797@item show disassembly-flavor
4798Show the current setting of the disassembly flavor.
c906108c
SS
4799@end table
4800
4801
6d2ebf8b 4802@node Data
c906108c
SS
4803@chapter Examining Data
4804
4805@cindex printing data
4806@cindex examining data
4807@kindex print
4808@kindex inspect
4809@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4810@c document because it is nonstandard... Under Epoch it displays in a
4811@c different window or something like that.
4812The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4813command (abbreviated @code{p}), or its synonym @code{inspect}. It
4814evaluates and prints the value of an expression of the language your
4815program is written in (@pxref{Languages, ,Using @value{GDBN} with
4816Different Languages}).
c906108c
SS
4817
4818@table @code
d4f3574e
SS
4819@item print @var{expr}
4820@itemx print /@var{f} @var{expr}
4821@var{expr} is an expression (in the source language). By default the
4822value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4823you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4824@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4825formats}.
4826
4827@item print
4828@itemx print /@var{f}
15387254 4829@cindex reprint the last value
d4f3574e 4830If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4831@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4832conveniently inspect the same value in an alternative format.
4833@end table
4834
4835A more low-level way of examining data is with the @code{x} command.
4836It examines data in memory at a specified address and prints it in a
4837specified format. @xref{Memory, ,Examining memory}.
4838
7a292a7a 4839If you are interested in information about types, or about how the
d4f3574e
SS
4840fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4841command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4842Table}.
c906108c
SS
4843
4844@menu
4845* Expressions:: Expressions
4846* Variables:: Program variables
4847* Arrays:: Artificial arrays
4848* Output Formats:: Output formats
4849* Memory:: Examining memory
4850* Auto Display:: Automatic display
4851* Print Settings:: Print settings
4852* Value History:: Value history
4853* Convenience Vars:: Convenience variables
4854* Registers:: Registers
c906108c 4855* Floating Point Hardware:: Floating point hardware
53c69bd7 4856* Vector Unit:: Vector Unit
721c2651 4857* OS Information:: Auxiliary data provided by operating system
29e57380 4858* Memory Region Attributes:: Memory region attributes
16d9dec6 4859* Dump/Restore Files:: Copy between memory and a file
384ee23f 4860* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4861* Character Sets:: Debugging programs that use a different
4862 character set than GDB does
09d4efe1 4863* Caching Remote Data:: Data caching for remote targets
c906108c
SS
4864@end menu
4865
6d2ebf8b 4866@node Expressions
c906108c
SS
4867@section Expressions
4868
4869@cindex expressions
4870@code{print} and many other @value{GDBN} commands accept an expression and
4871compute its value. Any kind of constant, variable or operator defined
4872by the programming language you are using is valid in an expression in
e2e0bcd1
JB
4873@value{GDBN}. This includes conditional expressions, function calls,
4874casts, and string constants. It also includes preprocessor macros, if
4875you compiled your program to include this information; see
4876@ref{Compilation}.
c906108c 4877
15387254 4878@cindex arrays in expressions
d4f3574e
SS
4879@value{GDBN} supports array constants in expressions input by
4880the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 4881you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 4882memory that is @code{malloc}ed in the target program.
c906108c 4883
c906108c
SS
4884Because C is so widespread, most of the expressions shown in examples in
4885this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
4886Languages}, for information on how to use expressions in other
4887languages.
4888
4889In this section, we discuss operators that you can use in @value{GDBN}
4890expressions regardless of your programming language.
4891
15387254 4892@cindex casts, in expressions
c906108c
SS
4893Casts are supported in all languages, not just in C, because it is so
4894useful to cast a number into a pointer in order to examine a structure
4895at that address in memory.
4896@c FIXME: casts supported---Mod2 true?
c906108c
SS
4897
4898@value{GDBN} supports these operators, in addition to those common
4899to programming languages:
4900
4901@table @code
4902@item @@
4903@samp{@@} is a binary operator for treating parts of memory as arrays.
4904@xref{Arrays, ,Artificial arrays}, for more information.
4905
4906@item ::
4907@samp{::} allows you to specify a variable in terms of the file or
4908function where it is defined. @xref{Variables, ,Program variables}.
4909
4910@cindex @{@var{type}@}
4911@cindex type casting memory
4912@cindex memory, viewing as typed object
4913@cindex casts, to view memory
4914@item @{@var{type}@} @var{addr}
4915Refers to an object of type @var{type} stored at address @var{addr} in
4916memory. @var{addr} may be any expression whose value is an integer or
4917pointer (but parentheses are required around binary operators, just as in
4918a cast). This construct is allowed regardless of what kind of data is
4919normally supposed to reside at @var{addr}.
4920@end table
4921
6d2ebf8b 4922@node Variables
c906108c
SS
4923@section Program variables
4924
4925The most common kind of expression to use is the name of a variable
4926in your program.
4927
4928Variables in expressions are understood in the selected stack frame
4929(@pxref{Selection, ,Selecting a frame}); they must be either:
4930
4931@itemize @bullet
4932@item
4933global (or file-static)
4934@end itemize
4935
5d161b24 4936@noindent or
c906108c
SS
4937
4938@itemize @bullet
4939@item
4940visible according to the scope rules of the
4941programming language from the point of execution in that frame
5d161b24 4942@end itemize
c906108c
SS
4943
4944@noindent This means that in the function
4945
474c8240 4946@smallexample
c906108c
SS
4947foo (a)
4948 int a;
4949@{
4950 bar (a);
4951 @{
4952 int b = test ();
4953 bar (b);
4954 @}
4955@}
474c8240 4956@end smallexample
c906108c
SS
4957
4958@noindent
4959you can examine and use the variable @code{a} whenever your program is
4960executing within the function @code{foo}, but you can only use or
4961examine the variable @code{b} while your program is executing inside
4962the block where @code{b} is declared.
4963
4964@cindex variable name conflict
4965There is an exception: you can refer to a variable or function whose
4966scope is a single source file even if the current execution point is not
4967in this file. But it is possible to have more than one such variable or
4968function with the same name (in different source files). If that
4969happens, referring to that name has unpredictable effects. If you wish,
4970you can specify a static variable in a particular function or file,
15387254 4971using the colon-colon (@code{::}) notation:
c906108c 4972
d4f3574e 4973@cindex colon-colon, context for variables/functions
c906108c
SS
4974@iftex
4975@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 4976@cindex @code{::}, context for variables/functions
c906108c 4977@end iftex
474c8240 4978@smallexample
c906108c
SS
4979@var{file}::@var{variable}
4980@var{function}::@var{variable}
474c8240 4981@end smallexample
c906108c
SS
4982
4983@noindent
4984Here @var{file} or @var{function} is the name of the context for the
4985static @var{variable}. In the case of file names, you can use quotes to
4986make sure @value{GDBN} parses the file name as a single word---for example,
4987to print a global value of @code{x} defined in @file{f2.c}:
4988
474c8240 4989@smallexample
c906108c 4990(@value{GDBP}) p 'f2.c'::x
474c8240 4991@end smallexample
c906108c 4992
b37052ae 4993@cindex C@t{++} scope resolution
c906108c 4994This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 4995use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
4996scope resolution operator in @value{GDBN} expressions.
4997@c FIXME: Um, so what happens in one of those rare cases where it's in
4998@c conflict?? --mew
c906108c
SS
4999
5000@cindex wrong values
5001@cindex variable values, wrong
15387254
EZ
5002@cindex function entry/exit, wrong values of variables
5003@cindex optimized code, wrong values of variables
c906108c
SS
5004@quotation
5005@emph{Warning:} Occasionally, a local variable may appear to have the
5006wrong value at certain points in a function---just after entry to a new
5007scope, and just before exit.
5008@end quotation
5009You may see this problem when you are stepping by machine instructions.
5010This is because, on most machines, it takes more than one instruction to
5011set up a stack frame (including local variable definitions); if you are
5012stepping by machine instructions, variables may appear to have the wrong
5013values until the stack frame is completely built. On exit, it usually
5014also takes more than one machine instruction to destroy a stack frame;
5015after you begin stepping through that group of instructions, local
5016variable definitions may be gone.
5017
5018This may also happen when the compiler does significant optimizations.
5019To be sure of always seeing accurate values, turn off all optimization
5020when compiling.
5021
d4f3574e
SS
5022@cindex ``No symbol "foo" in current context''
5023Another possible effect of compiler optimizations is to optimize
5024unused variables out of existence, or assign variables to registers (as
5025opposed to memory addresses). Depending on the support for such cases
5026offered by the debug info format used by the compiler, @value{GDBN}
5027might not be able to display values for such local variables. If that
5028happens, @value{GDBN} will print a message like this:
5029
474c8240 5030@smallexample
d4f3574e 5031No symbol "foo" in current context.
474c8240 5032@end smallexample
d4f3574e
SS
5033
5034To solve such problems, either recompile without optimizations, or use a
5035different debug info format, if the compiler supports several such
15387254 5036formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5037usually supports the @option{-gstabs+} option. @option{-gstabs+}
5038produces debug info in a format that is superior to formats such as
5039COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5040an effective form for debug info. @xref{Debugging Options,,Options
5041for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5042@xref{C, , Debugging C++}, for more info about debug info formats
5043that are best suited to C@t{++} programs.
d4f3574e 5044
6d2ebf8b 5045@node Arrays
c906108c
SS
5046@section Artificial arrays
5047
5048@cindex artificial array
15387254 5049@cindex arrays
41afff9a 5050@kindex @@@r{, referencing memory as an array}
c906108c
SS
5051It is often useful to print out several successive objects of the
5052same type in memory; a section of an array, or an array of
5053dynamically determined size for which only a pointer exists in the
5054program.
5055
5056You can do this by referring to a contiguous span of memory as an
5057@dfn{artificial array}, using the binary operator @samp{@@}. The left
5058operand of @samp{@@} should be the first element of the desired array
5059and be an individual object. The right operand should be the desired length
5060of the array. The result is an array value whose elements are all of
5061the type of the left argument. The first element is actually the left
5062argument; the second element comes from bytes of memory immediately
5063following those that hold the first element, and so on. Here is an
5064example. If a program says
5065
474c8240 5066@smallexample
c906108c 5067int *array = (int *) malloc (len * sizeof (int));
474c8240 5068@end smallexample
c906108c
SS
5069
5070@noindent
5071you can print the contents of @code{array} with
5072
474c8240 5073@smallexample
c906108c 5074p *array@@len
474c8240 5075@end smallexample
c906108c
SS
5076
5077The left operand of @samp{@@} must reside in memory. Array values made
5078with @samp{@@} in this way behave just like other arrays in terms of
5079subscripting, and are coerced to pointers when used in expressions.
5080Artificial arrays most often appear in expressions via the value history
5081(@pxref{Value History, ,Value history}), after printing one out.
5082
5083Another way to create an artificial array is to use a cast.
5084This re-interprets a value as if it were an array.
5085The value need not be in memory:
474c8240 5086@smallexample
c906108c
SS
5087(@value{GDBP}) p/x (short[2])0x12345678
5088$1 = @{0x1234, 0x5678@}
474c8240 5089@end smallexample
c906108c
SS
5090
5091As a convenience, if you leave the array length out (as in
c3f6f71d 5092@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5093the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5094@smallexample
c906108c
SS
5095(@value{GDBP}) p/x (short[])0x12345678
5096$2 = @{0x1234, 0x5678@}
474c8240 5097@end smallexample
c906108c
SS
5098
5099Sometimes the artificial array mechanism is not quite enough; in
5100moderately complex data structures, the elements of interest may not
5101actually be adjacent---for example, if you are interested in the values
5102of pointers in an array. One useful work-around in this situation is
5103to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5104variables}) as a counter in an expression that prints the first
5105interesting value, and then repeat that expression via @key{RET}. For
5106instance, suppose you have an array @code{dtab} of pointers to
5107structures, and you are interested in the values of a field @code{fv}
5108in each structure. Here is an example of what you might type:
5109
474c8240 5110@smallexample
c906108c
SS
5111set $i = 0
5112p dtab[$i++]->fv
5113@key{RET}
5114@key{RET}
5115@dots{}
474c8240 5116@end smallexample
c906108c 5117
6d2ebf8b 5118@node Output Formats
c906108c
SS
5119@section Output formats
5120
5121@cindex formatted output
5122@cindex output formats
5123By default, @value{GDBN} prints a value according to its data type. Sometimes
5124this is not what you want. For example, you might want to print a number
5125in hex, or a pointer in decimal. Or you might want to view data in memory
5126at a certain address as a character string or as an instruction. To do
5127these things, specify an @dfn{output format} when you print a value.
5128
5129The simplest use of output formats is to say how to print a value
5130already computed. This is done by starting the arguments of the
5131@code{print} command with a slash and a format letter. The format
5132letters supported are:
5133
5134@table @code
5135@item x
5136Regard the bits of the value as an integer, and print the integer in
5137hexadecimal.
5138
5139@item d
5140Print as integer in signed decimal.
5141
5142@item u
5143Print as integer in unsigned decimal.
5144
5145@item o
5146Print as integer in octal.
5147
5148@item t
5149Print as integer in binary. The letter @samp{t} stands for ``two''.
5150@footnote{@samp{b} cannot be used because these format letters are also
5151used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5152see @ref{Memory,,Examining memory}.}
c906108c
SS
5153
5154@item a
5155@cindex unknown address, locating
3d67e040 5156@cindex locate address
c906108c
SS
5157Print as an address, both absolute in hexadecimal and as an offset from
5158the nearest preceding symbol. You can use this format used to discover
5159where (in what function) an unknown address is located:
5160
474c8240 5161@smallexample
c906108c
SS
5162(@value{GDBP}) p/a 0x54320
5163$3 = 0x54320 <_initialize_vx+396>
474c8240 5164@end smallexample
c906108c 5165
3d67e040
EZ
5166@noindent
5167The command @code{info symbol 0x54320} yields similar results.
5168@xref{Symbols, info symbol}.
5169
c906108c
SS
5170@item c
5171Regard as an integer and print it as a character constant.
5172
5173@item f
5174Regard the bits of the value as a floating point number and print
5175using typical floating point syntax.
5176@end table
5177
5178For example, to print the program counter in hex (@pxref{Registers}), type
5179
474c8240 5180@smallexample
c906108c 5181p/x $pc
474c8240 5182@end smallexample
c906108c
SS
5183
5184@noindent
5185Note that no space is required before the slash; this is because command
5186names in @value{GDBN} cannot contain a slash.
5187
5188To reprint the last value in the value history with a different format,
5189you can use the @code{print} command with just a format and no
5190expression. For example, @samp{p/x} reprints the last value in hex.
5191
6d2ebf8b 5192@node Memory
c906108c
SS
5193@section Examining memory
5194
5195You can use the command @code{x} (for ``examine'') to examine memory in
5196any of several formats, independently of your program's data types.
5197
5198@cindex examining memory
5199@table @code
41afff9a 5200@kindex x @r{(examine memory)}
c906108c
SS
5201@item x/@var{nfu} @var{addr}
5202@itemx x @var{addr}
5203@itemx x
5204Use the @code{x} command to examine memory.
5205@end table
5206
5207@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5208much memory to display and how to format it; @var{addr} is an
5209expression giving the address where you want to start displaying memory.
5210If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5211Several commands set convenient defaults for @var{addr}.
5212
5213@table @r
5214@item @var{n}, the repeat count
5215The repeat count is a decimal integer; the default is 1. It specifies
5216how much memory (counting by units @var{u}) to display.
5217@c This really is **decimal**; unaffected by 'set radix' as of GDB
5218@c 4.1.2.
5219
5220@item @var{f}, the display format
5221The display format is one of the formats used by @code{print},
5222@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5223The default is @samp{x} (hexadecimal) initially.
5224The default changes each time you use either @code{x} or @code{print}.
5225
5226@item @var{u}, the unit size
5227The unit size is any of
5228
5229@table @code
5230@item b
5231Bytes.
5232@item h
5233Halfwords (two bytes).
5234@item w
5235Words (four bytes). This is the initial default.
5236@item g
5237Giant words (eight bytes).
5238@end table
5239
5240Each time you specify a unit size with @code{x}, that size becomes the
5241default unit the next time you use @code{x}. (For the @samp{s} and
5242@samp{i} formats, the unit size is ignored and is normally not written.)
5243
5244@item @var{addr}, starting display address
5245@var{addr} is the address where you want @value{GDBN} to begin displaying
5246memory. The expression need not have a pointer value (though it may);
5247it is always interpreted as an integer address of a byte of memory.
5248@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5249@var{addr} is usually just after the last address examined---but several
5250other commands also set the default address: @code{info breakpoints} (to
5251the address of the last breakpoint listed), @code{info line} (to the
5252starting address of a line), and @code{print} (if you use it to display
5253a value from memory).
5254@end table
5255
5256For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5257(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5258starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5259words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5260@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5261
5262Since the letters indicating unit sizes are all distinct from the
5263letters specifying output formats, you do not have to remember whether
5264unit size or format comes first; either order works. The output
5265specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5266(However, the count @var{n} must come first; @samp{wx4} does not work.)
5267
5268Even though the unit size @var{u} is ignored for the formats @samp{s}
5269and @samp{i}, you might still want to use a count @var{n}; for example,
5270@samp{3i} specifies that you want to see three machine instructions,
5271including any operands. The command @code{disassemble} gives an
d4f3574e 5272alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5273Code,,Source and machine code}.
5274
5275All the defaults for the arguments to @code{x} are designed to make it
5276easy to continue scanning memory with minimal specifications each time
5277you use @code{x}. For example, after you have inspected three machine
5278instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5279with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5280the repeat count @var{n} is used again; the other arguments default as
5281for successive uses of @code{x}.
5282
5283@cindex @code{$_}, @code{$__}, and value history
5284The addresses and contents printed by the @code{x} command are not saved
5285in the value history because there is often too much of them and they
5286would get in the way. Instead, @value{GDBN} makes these values available for
5287subsequent use in expressions as values of the convenience variables
5288@code{$_} and @code{$__}. After an @code{x} command, the last address
5289examined is available for use in expressions in the convenience variable
5290@code{$_}. The contents of that address, as examined, are available in
5291the convenience variable @code{$__}.
5292
5293If the @code{x} command has a repeat count, the address and contents saved
5294are from the last memory unit printed; this is not the same as the last
5295address printed if several units were printed on the last line of output.
5296
09d4efe1
EZ
5297@cindex remote memory comparison
5298@cindex verify remote memory image
5299When you are debugging a program running on a remote target machine
5300(@pxref{Remote}), you may wish to verify the program's image in the
5301remote machine's memory against the executable file you downloaded to
5302the target. The @code{compare-sections} command is provided for such
5303situations.
5304
5305@table @code
5306@kindex compare-sections
5307@item compare-sections @r{[}@var{section-name}@r{]}
5308Compare the data of a loadable section @var{section-name} in the
5309executable file of the program being debugged with the same section in
5310the remote machine's memory, and report any mismatches. With no
5311arguments, compares all loadable sections. This command's
5312availability depends on the target's support for the @code{"qCRC"}
5313remote request.
5314@end table
5315
6d2ebf8b 5316@node Auto Display
c906108c
SS
5317@section Automatic display
5318@cindex automatic display
5319@cindex display of expressions
5320
5321If you find that you want to print the value of an expression frequently
5322(to see how it changes), you might want to add it to the @dfn{automatic
5323display list} so that @value{GDBN} prints its value each time your program stops.
5324Each expression added to the list is given a number to identify it;
5325to remove an expression from the list, you specify that number.
5326The automatic display looks like this:
5327
474c8240 5328@smallexample
c906108c
SS
53292: foo = 38
53303: bar[5] = (struct hack *) 0x3804
474c8240 5331@end smallexample
c906108c
SS
5332
5333@noindent
5334This display shows item numbers, expressions and their current values. As with
5335displays you request manually using @code{x} or @code{print}, you can
5336specify the output format you prefer; in fact, @code{display} decides
5337whether to use @code{print} or @code{x} depending on how elaborate your
5338format specification is---it uses @code{x} if you specify a unit size,
5339or one of the two formats (@samp{i} and @samp{s}) that are only
5340supported by @code{x}; otherwise it uses @code{print}.
5341
5342@table @code
5343@kindex display
d4f3574e
SS
5344@item display @var{expr}
5345Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5346each time your program stops. @xref{Expressions, ,Expressions}.
5347
5348@code{display} does not repeat if you press @key{RET} again after using it.
5349
d4f3574e 5350@item display/@var{fmt} @var{expr}
c906108c 5351For @var{fmt} specifying only a display format and not a size or
d4f3574e 5352count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5353arrange to display it each time in the specified format @var{fmt}.
5354@xref{Output Formats,,Output formats}.
5355
5356@item display/@var{fmt} @var{addr}
5357For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5358number of units, add the expression @var{addr} as a memory address to
5359be examined each time your program stops. Examining means in effect
5360doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5361@end table
5362
5363For example, @samp{display/i $pc} can be helpful, to see the machine
5364instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5365is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5366
5367@table @code
5368@kindex delete display
5369@kindex undisplay
5370@item undisplay @var{dnums}@dots{}
5371@itemx delete display @var{dnums}@dots{}
5372Remove item numbers @var{dnums} from the list of expressions to display.
5373
5374@code{undisplay} does not repeat if you press @key{RET} after using it.
5375(Otherwise you would just get the error @samp{No display number @dots{}}.)
5376
5377@kindex disable display
5378@item disable display @var{dnums}@dots{}
5379Disable the display of item numbers @var{dnums}. A disabled display
5380item is not printed automatically, but is not forgotten. It may be
5381enabled again later.
5382
5383@kindex enable display
5384@item enable display @var{dnums}@dots{}
5385Enable display of item numbers @var{dnums}. It becomes effective once
5386again in auto display of its expression, until you specify otherwise.
5387
5388@item display
5389Display the current values of the expressions on the list, just as is
5390done when your program stops.
5391
5392@kindex info display
5393@item info display
5394Print the list of expressions previously set up to display
5395automatically, each one with its item number, but without showing the
5396values. This includes disabled expressions, which are marked as such.
5397It also includes expressions which would not be displayed right now
5398because they refer to automatic variables not currently available.
5399@end table
5400
15387254 5401@cindex display disabled out of scope
c906108c
SS
5402If a display expression refers to local variables, then it does not make
5403sense outside the lexical context for which it was set up. Such an
5404expression is disabled when execution enters a context where one of its
5405variables is not defined. For example, if you give the command
5406@code{display last_char} while inside a function with an argument
5407@code{last_char}, @value{GDBN} displays this argument while your program
5408continues to stop inside that function. When it stops elsewhere---where
5409there is no variable @code{last_char}---the display is disabled
5410automatically. The next time your program stops where @code{last_char}
5411is meaningful, you can enable the display expression once again.
5412
6d2ebf8b 5413@node Print Settings
c906108c
SS
5414@section Print settings
5415
5416@cindex format options
5417@cindex print settings
5418@value{GDBN} provides the following ways to control how arrays, structures,
5419and symbols are printed.
5420
5421@noindent
5422These settings are useful for debugging programs in any language:
5423
5424@table @code
4644b6e3 5425@kindex set print
c906108c
SS
5426@item set print address
5427@itemx set print address on
4644b6e3 5428@cindex print/don't print memory addresses
c906108c
SS
5429@value{GDBN} prints memory addresses showing the location of stack
5430traces, structure values, pointer values, breakpoints, and so forth,
5431even when it also displays the contents of those addresses. The default
5432is @code{on}. For example, this is what a stack frame display looks like with
5433@code{set print address on}:
5434
5435@smallexample
5436@group
5437(@value{GDBP}) f
5438#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5439 at input.c:530
5440530 if (lquote != def_lquote)
5441@end group
5442@end smallexample
5443
5444@item set print address off
5445Do not print addresses when displaying their contents. For example,
5446this is the same stack frame displayed with @code{set print address off}:
5447
5448@smallexample
5449@group
5450(@value{GDBP}) set print addr off
5451(@value{GDBP}) f
5452#0 set_quotes (lq="<<", rq=">>") at input.c:530
5453530 if (lquote != def_lquote)
5454@end group
5455@end smallexample
5456
5457You can use @samp{set print address off} to eliminate all machine
5458dependent displays from the @value{GDBN} interface. For example, with
5459@code{print address off}, you should get the same text for backtraces on
5460all machines---whether or not they involve pointer arguments.
5461
4644b6e3 5462@kindex show print
c906108c
SS
5463@item show print address
5464Show whether or not addresses are to be printed.
5465@end table
5466
5467When @value{GDBN} prints a symbolic address, it normally prints the
5468closest earlier symbol plus an offset. If that symbol does not uniquely
5469identify the address (for example, it is a name whose scope is a single
5470source file), you may need to clarify. One way to do this is with
5471@code{info line}, for example @samp{info line *0x4537}. Alternately,
5472you can set @value{GDBN} to print the source file and line number when
5473it prints a symbolic address:
5474
5475@table @code
c906108c 5476@item set print symbol-filename on
9c16f35a
EZ
5477@cindex source file and line of a symbol
5478@cindex symbol, source file and line
c906108c
SS
5479Tell @value{GDBN} to print the source file name and line number of a
5480symbol in the symbolic form of an address.
5481
5482@item set print symbol-filename off
5483Do not print source file name and line number of a symbol. This is the
5484default.
5485
c906108c
SS
5486@item show print symbol-filename
5487Show whether or not @value{GDBN} will print the source file name and
5488line number of a symbol in the symbolic form of an address.
5489@end table
5490
5491Another situation where it is helpful to show symbol filenames and line
5492numbers is when disassembling code; @value{GDBN} shows you the line
5493number and source file that corresponds to each instruction.
5494
5495Also, you may wish to see the symbolic form only if the address being
5496printed is reasonably close to the closest earlier symbol:
5497
5498@table @code
c906108c 5499@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5500@cindex maximum value for offset of closest symbol
c906108c
SS
5501Tell @value{GDBN} to only display the symbolic form of an address if the
5502offset between the closest earlier symbol and the address is less than
5d161b24 5503@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5504to always print the symbolic form of an address if any symbol precedes it.
5505
c906108c
SS
5506@item show print max-symbolic-offset
5507Ask how large the maximum offset is that @value{GDBN} prints in a
5508symbolic address.
5509@end table
5510
5511@cindex wild pointer, interpreting
5512@cindex pointer, finding referent
5513If you have a pointer and you are not sure where it points, try
5514@samp{set print symbol-filename on}. Then you can determine the name
5515and source file location of the variable where it points, using
5516@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5517For example, here @value{GDBN} shows that a variable @code{ptt} points
5518at another variable @code{t}, defined in @file{hi2.c}:
5519
474c8240 5520@smallexample
c906108c
SS
5521(@value{GDBP}) set print symbol-filename on
5522(@value{GDBP}) p/a ptt
5523$4 = 0xe008 <t in hi2.c>
474c8240 5524@end smallexample
c906108c
SS
5525
5526@quotation
5527@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5528does not show the symbol name and filename of the referent, even with
5529the appropriate @code{set print} options turned on.
5530@end quotation
5531
5532Other settings control how different kinds of objects are printed:
5533
5534@table @code
c906108c
SS
5535@item set print array
5536@itemx set print array on
4644b6e3 5537@cindex pretty print arrays
c906108c
SS
5538Pretty print arrays. This format is more convenient to read,
5539but uses more space. The default is off.
5540
5541@item set print array off
5542Return to compressed format for arrays.
5543
c906108c
SS
5544@item show print array
5545Show whether compressed or pretty format is selected for displaying
5546arrays.
5547
c906108c 5548@item set print elements @var{number-of-elements}
4644b6e3 5549@cindex number of array elements to print
9c16f35a 5550@cindex limit on number of printed array elements
c906108c
SS
5551Set a limit on how many elements of an array @value{GDBN} will print.
5552If @value{GDBN} is printing a large array, it stops printing after it has
5553printed the number of elements set by the @code{set print elements} command.
5554This limit also applies to the display of strings.
d4f3574e 5555When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5556Setting @var{number-of-elements} to zero means that the printing is unlimited.
5557
c906108c
SS
5558@item show print elements
5559Display the number of elements of a large array that @value{GDBN} will print.
5560If the number is 0, then the printing is unlimited.
5561
9c16f35a
EZ
5562@item set print repeats
5563@cindex repeated array elements
5564Set the threshold for suppressing display of repeated array
5565elelments. When the number of consecutive identical elements of an
5566array exceeds the threshold, @value{GDBN} prints the string
5567@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5568identical repetitions, instead of displaying the identical elements
5569themselves. Setting the threshold to zero will cause all elements to
5570be individually printed. The default threshold is 10.
5571
5572@item show print repeats
5573Display the current threshold for printing repeated identical
5574elements.
5575
c906108c 5576@item set print null-stop
4644b6e3 5577@cindex @sc{null} elements in arrays
c906108c 5578Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5579@sc{null} is encountered. This is useful when large arrays actually
c906108c 5580contain only short strings.
d4f3574e 5581The default is off.
c906108c 5582
9c16f35a
EZ
5583@item show print null-stop
5584Show whether @value{GDBN} stops printing an array on the first
5585@sc{null} character.
5586
c906108c 5587@item set print pretty on
9c16f35a
EZ
5588@cindex print structures in indented form
5589@cindex indentation in structure display
5d161b24 5590Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5591per line, like this:
5592
5593@smallexample
5594@group
5595$1 = @{
5596 next = 0x0,
5597 flags = @{
5598 sweet = 1,
5599 sour = 1
5600 @},
5601 meat = 0x54 "Pork"
5602@}
5603@end group
5604@end smallexample
5605
5606@item set print pretty off
5607Cause @value{GDBN} to print structures in a compact format, like this:
5608
5609@smallexample
5610@group
5611$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5612meat = 0x54 "Pork"@}
5613@end group
5614@end smallexample
5615
5616@noindent
5617This is the default format.
5618
c906108c
SS
5619@item show print pretty
5620Show which format @value{GDBN} is using to print structures.
5621
c906108c 5622@item set print sevenbit-strings on
4644b6e3
EZ
5623@cindex eight-bit characters in strings
5624@cindex octal escapes in strings
c906108c
SS
5625Print using only seven-bit characters; if this option is set,
5626@value{GDBN} displays any eight-bit characters (in strings or
5627character values) using the notation @code{\}@var{nnn}. This setting is
5628best if you are working in English (@sc{ascii}) and you use the
5629high-order bit of characters as a marker or ``meta'' bit.
5630
5631@item set print sevenbit-strings off
5632Print full eight-bit characters. This allows the use of more
5633international character sets, and is the default.
5634
c906108c
SS
5635@item show print sevenbit-strings
5636Show whether or not @value{GDBN} is printing only seven-bit characters.
5637
c906108c 5638@item set print union on
4644b6e3 5639@cindex unions in structures, printing
9c16f35a
EZ
5640Tell @value{GDBN} to print unions which are contained in structures
5641and other unions. This is the default setting.
c906108c
SS
5642
5643@item set print union off
9c16f35a
EZ
5644Tell @value{GDBN} not to print unions which are contained in
5645structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5646instead.
c906108c 5647
c906108c
SS
5648@item show print union
5649Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5650structures and other unions.
c906108c
SS
5651
5652For example, given the declarations
5653
5654@smallexample
5655typedef enum @{Tree, Bug@} Species;
5656typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5657typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5658 Bug_forms;
5659
5660struct thing @{
5661 Species it;
5662 union @{
5663 Tree_forms tree;
5664 Bug_forms bug;
5665 @} form;
5666@};
5667
5668struct thing foo = @{Tree, @{Acorn@}@};
5669@end smallexample
5670
5671@noindent
5672with @code{set print union on} in effect @samp{p foo} would print
5673
5674@smallexample
5675$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5676@end smallexample
5677
5678@noindent
5679and with @code{set print union off} in effect it would print
5680
5681@smallexample
5682$1 = @{it = Tree, form = @{...@}@}
5683@end smallexample
9c16f35a
EZ
5684
5685@noindent
5686@code{set print union} affects programs written in C-like languages
5687and in Pascal.
c906108c
SS
5688@end table
5689
c906108c
SS
5690@need 1000
5691@noindent
b37052ae 5692These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5693
5694@table @code
4644b6e3 5695@cindex demangling C@t{++} names
c906108c
SS
5696@item set print demangle
5697@itemx set print demangle on
b37052ae 5698Print C@t{++} names in their source form rather than in the encoded
c906108c 5699(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5700linkage. The default is on.
c906108c 5701
c906108c 5702@item show print demangle
b37052ae 5703Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5704
c906108c
SS
5705@item set print asm-demangle
5706@itemx set print asm-demangle on
b37052ae 5707Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5708in assembler code printouts such as instruction disassemblies.
5709The default is off.
5710
c906108c 5711@item show print asm-demangle
b37052ae 5712Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5713or demangled form.
5714
b37052ae
EZ
5715@cindex C@t{++} symbol decoding style
5716@cindex symbol decoding style, C@t{++}
a8f24a35 5717@kindex set demangle-style
c906108c
SS
5718@item set demangle-style @var{style}
5719Choose among several encoding schemes used by different compilers to
b37052ae 5720represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5721
5722@table @code
5723@item auto
5724Allow @value{GDBN} to choose a decoding style by inspecting your program.
5725
5726@item gnu
b37052ae 5727Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5728This is the default.
c906108c
SS
5729
5730@item hp
b37052ae 5731Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5732
5733@item lucid
b37052ae 5734Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5735
5736@item arm
b37052ae 5737Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5738@strong{Warning:} this setting alone is not sufficient to allow
5739debugging @code{cfront}-generated executables. @value{GDBN} would
5740require further enhancement to permit that.
5741
5742@end table
5743If you omit @var{style}, you will see a list of possible formats.
5744
c906108c 5745@item show demangle-style
b37052ae 5746Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5747
c906108c
SS
5748@item set print object
5749@itemx set print object on
4644b6e3 5750@cindex derived type of an object, printing
9c16f35a 5751@cindex display derived types
c906108c
SS
5752When displaying a pointer to an object, identify the @emph{actual}
5753(derived) type of the object rather than the @emph{declared} type, using
5754the virtual function table.
5755
5756@item set print object off
5757Display only the declared type of objects, without reference to the
5758virtual function table. This is the default setting.
5759
c906108c
SS
5760@item show print object
5761Show whether actual, or declared, object types are displayed.
5762
c906108c
SS
5763@item set print static-members
5764@itemx set print static-members on
4644b6e3 5765@cindex static members of C@t{++} objects
b37052ae 5766Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5767
5768@item set print static-members off
b37052ae 5769Do not print static members when displaying a C@t{++} object.
c906108c 5770
c906108c 5771@item show print static-members
9c16f35a
EZ
5772Show whether C@t{++} static members are printed or not.
5773
5774@item set print pascal_static-members
5775@itemx set print pascal_static-members on
5776@cindex static members of Pacal objects
5777@cindex Pacal objects, static members display
5778Print static members when displaying a Pascal object. The default is on.
5779
5780@item set print pascal_static-members off
5781Do not print static members when displaying a Pascal object.
5782
5783@item show print pascal_static-members
5784Show whether Pascal static members are printed or not.
c906108c
SS
5785
5786@c These don't work with HP ANSI C++ yet.
c906108c
SS
5787@item set print vtbl
5788@itemx set print vtbl on
4644b6e3 5789@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5790@cindex virtual functions (C@t{++}) display
5791@cindex VTBL display
b37052ae 5792Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5793(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5794ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5795
5796@item set print vtbl off
b37052ae 5797Do not pretty print C@t{++} virtual function tables.
c906108c 5798
c906108c 5799@item show print vtbl
b37052ae 5800Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5801@end table
c906108c 5802
6d2ebf8b 5803@node Value History
c906108c
SS
5804@section Value history
5805
5806@cindex value history
9c16f35a 5807@cindex history of values printed by @value{GDBN}
5d161b24
DB
5808Values printed by the @code{print} command are saved in the @value{GDBN}
5809@dfn{value history}. This allows you to refer to them in other expressions.
5810Values are kept until the symbol table is re-read or discarded
5811(for example with the @code{file} or @code{symbol-file} commands).
5812When the symbol table changes, the value history is discarded,
5813since the values may contain pointers back to the types defined in the
c906108c
SS
5814symbol table.
5815
5816@cindex @code{$}
5817@cindex @code{$$}
5818@cindex history number
5819The values printed are given @dfn{history numbers} by which you can
5820refer to them. These are successive integers starting with one.
5821@code{print} shows you the history number assigned to a value by
5822printing @samp{$@var{num} = } before the value; here @var{num} is the
5823history number.
5824
5825To refer to any previous value, use @samp{$} followed by the value's
5826history number. The way @code{print} labels its output is designed to
5827remind you of this. Just @code{$} refers to the most recent value in
5828the history, and @code{$$} refers to the value before that.
5829@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5830is the value just prior to @code{$$}, @code{$$1} is equivalent to
5831@code{$$}, and @code{$$0} is equivalent to @code{$}.
5832
5833For example, suppose you have just printed a pointer to a structure and
5834want to see the contents of the structure. It suffices to type
5835
474c8240 5836@smallexample
c906108c 5837p *$
474c8240 5838@end smallexample
c906108c
SS
5839
5840If you have a chain of structures where the component @code{next} points
5841to the next one, you can print the contents of the next one with this:
5842
474c8240 5843@smallexample
c906108c 5844p *$.next
474c8240 5845@end smallexample
c906108c
SS
5846
5847@noindent
5848You can print successive links in the chain by repeating this
5849command---which you can do by just typing @key{RET}.
5850
5851Note that the history records values, not expressions. If the value of
5852@code{x} is 4 and you type these commands:
5853
474c8240 5854@smallexample
c906108c
SS
5855print x
5856set x=5
474c8240 5857@end smallexample
c906108c
SS
5858
5859@noindent
5860then the value recorded in the value history by the @code{print} command
5861remains 4 even though the value of @code{x} has changed.
5862
5863@table @code
5864@kindex show values
5865@item show values
5866Print the last ten values in the value history, with their item numbers.
5867This is like @samp{p@ $$9} repeated ten times, except that @code{show
5868values} does not change the history.
5869
5870@item show values @var{n}
5871Print ten history values centered on history item number @var{n}.
5872
5873@item show values +
5874Print ten history values just after the values last printed. If no more
5875values are available, @code{show values +} produces no display.
5876@end table
5877
5878Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
5879same effect as @samp{show values +}.
5880
6d2ebf8b 5881@node Convenience Vars
c906108c
SS
5882@section Convenience variables
5883
5884@cindex convenience variables
9c16f35a 5885@cindex user-defined variables
c906108c
SS
5886@value{GDBN} provides @dfn{convenience variables} that you can use within
5887@value{GDBN} to hold on to a value and refer to it later. These variables
5888exist entirely within @value{GDBN}; they are not part of your program, and
5889setting a convenience variable has no direct effect on further execution
5890of your program. That is why you can use them freely.
5891
5892Convenience variables are prefixed with @samp{$}. Any name preceded by
5893@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 5894the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
5895(Value history references, in contrast, are @emph{numbers} preceded
5896by @samp{$}. @xref{Value History, ,Value history}.)
5897
5898You can save a value in a convenience variable with an assignment
5899expression, just as you would set a variable in your program.
5900For example:
5901
474c8240 5902@smallexample
c906108c 5903set $foo = *object_ptr
474c8240 5904@end smallexample
c906108c
SS
5905
5906@noindent
5907would save in @code{$foo} the value contained in the object pointed to by
5908@code{object_ptr}.
5909
5910Using a convenience variable for the first time creates it, but its
5911value is @code{void} until you assign a new value. You can alter the
5912value with another assignment at any time.
5913
5914Convenience variables have no fixed types. You can assign a convenience
5915variable any type of value, including structures and arrays, even if
5916that variable already has a value of a different type. The convenience
5917variable, when used as an expression, has the type of its current value.
5918
5919@table @code
5920@kindex show convenience
9c16f35a 5921@cindex show all user variables
c906108c
SS
5922@item show convenience
5923Print a list of convenience variables used so far, and their values.
d4f3574e 5924Abbreviated @code{show conv}.
c906108c
SS
5925@end table
5926
5927One of the ways to use a convenience variable is as a counter to be
5928incremented or a pointer to be advanced. For example, to print
5929a field from successive elements of an array of structures:
5930
474c8240 5931@smallexample
c906108c
SS
5932set $i = 0
5933print bar[$i++]->contents
474c8240 5934@end smallexample
c906108c 5935
d4f3574e
SS
5936@noindent
5937Repeat that command by typing @key{RET}.
c906108c
SS
5938
5939Some convenience variables are created automatically by @value{GDBN} and given
5940values likely to be useful.
5941
5942@table @code
41afff9a 5943@vindex $_@r{, convenience variable}
c906108c
SS
5944@item $_
5945The variable @code{$_} is automatically set by the @code{x} command to
5946the last address examined (@pxref{Memory, ,Examining memory}). Other
5947commands which provide a default address for @code{x} to examine also
5948set @code{$_} to that address; these commands include @code{info line}
5949and @code{info breakpoint}. The type of @code{$_} is @code{void *}
5950except when set by the @code{x} command, in which case it is a pointer
5951to the type of @code{$__}.
5952
41afff9a 5953@vindex $__@r{, convenience variable}
c906108c
SS
5954@item $__
5955The variable @code{$__} is automatically set by the @code{x} command
5956to the value found in the last address examined. Its type is chosen
5957to match the format in which the data was printed.
5958
5959@item $_exitcode
41afff9a 5960@vindex $_exitcode@r{, convenience variable}
c906108c
SS
5961The variable @code{$_exitcode} is automatically set to the exit code when
5962the program being debugged terminates.
5963@end table
5964
53a5351d
JM
5965On HP-UX systems, if you refer to a function or variable name that
5966begins with a dollar sign, @value{GDBN} searches for a user or system
5967name first, before it searches for a convenience variable.
c906108c 5968
6d2ebf8b 5969@node Registers
c906108c
SS
5970@section Registers
5971
5972@cindex registers
5973You can refer to machine register contents, in expressions, as variables
5974with names starting with @samp{$}. The names of registers are different
5975for each machine; use @code{info registers} to see the names used on
5976your machine.
5977
5978@table @code
5979@kindex info registers
5980@item info registers
5981Print the names and values of all registers except floating-point
c85508ee 5982and vector registers (in the selected stack frame).
c906108c
SS
5983
5984@kindex info all-registers
5985@cindex floating point registers
5986@item info all-registers
5987Print the names and values of all registers, including floating-point
c85508ee 5988and vector registers (in the selected stack frame).
c906108c
SS
5989
5990@item info registers @var{regname} @dots{}
5991Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
5992As discussed in detail below, register values are normally relative to
5993the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
5994the machine you are using, with or without the initial @samp{$}.
5995@end table
5996
5997@value{GDBN} has four ``standard'' register names that are available (in
5998expressions) on most machines---whenever they do not conflict with an
5999architecture's canonical mnemonics for registers. The register names
6000@code{$pc} and @code{$sp} are used for the program counter register and
6001the stack pointer. @code{$fp} is used for a register that contains a
6002pointer to the current stack frame, and @code{$ps} is used for a
6003register that contains the processor status. For example,
6004you could print the program counter in hex with
6005
474c8240 6006@smallexample
c906108c 6007p/x $pc
474c8240 6008@end smallexample
c906108c
SS
6009
6010@noindent
6011or print the instruction to be executed next with
6012
474c8240 6013@smallexample
c906108c 6014x/i $pc
474c8240 6015@end smallexample
c906108c
SS
6016
6017@noindent
6018or add four to the stack pointer@footnote{This is a way of removing
6019one word from the stack, on machines where stacks grow downward in
6020memory (most machines, nowadays). This assumes that the innermost
6021stack frame is selected; setting @code{$sp} is not allowed when other
6022stack frames are selected. To pop entire frames off the stack,
6023regardless of machine architecture, use @code{return};
d4f3574e 6024see @ref{Returning, ,Returning from a function}.} with
c906108c 6025
474c8240 6026@smallexample
c906108c 6027set $sp += 4
474c8240 6028@end smallexample
c906108c
SS
6029
6030Whenever possible, these four standard register names are available on
6031your machine even though the machine has different canonical mnemonics,
6032so long as there is no conflict. The @code{info registers} command
6033shows the canonical names. For example, on the SPARC, @code{info
6034registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6035can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6036is an alias for the @sc{eflags} register.
c906108c
SS
6037
6038@value{GDBN} always considers the contents of an ordinary register as an
6039integer when the register is examined in this way. Some machines have
6040special registers which can hold nothing but floating point; these
6041registers are considered to have floating point values. There is no way
6042to refer to the contents of an ordinary register as floating point value
6043(although you can @emph{print} it as a floating point value with
6044@samp{print/f $@var{regname}}).
6045
6046Some registers have distinct ``raw'' and ``virtual'' data formats. This
6047means that the data format in which the register contents are saved by
6048the operating system is not the same one that your program normally
6049sees. For example, the registers of the 68881 floating point
6050coprocessor are always saved in ``extended'' (raw) format, but all C
6051programs expect to work with ``double'' (virtual) format. In such
5d161b24 6052cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6053that makes sense for your program), but the @code{info registers} command
6054prints the data in both formats.
6055
6056Normally, register values are relative to the selected stack frame
6057(@pxref{Selection, ,Selecting a frame}). This means that you get the
6058value that the register would contain if all stack frames farther in
6059were exited and their saved registers restored. In order to see the
6060true contents of hardware registers, you must select the innermost
6061frame (with @samp{frame 0}).
6062
6063However, @value{GDBN} must deduce where registers are saved, from the machine
6064code generated by your compiler. If some registers are not saved, or if
6065@value{GDBN} is unable to locate the saved registers, the selected stack
6066frame makes no difference.
6067
6d2ebf8b 6068@node Floating Point Hardware
c906108c
SS
6069@section Floating point hardware
6070@cindex floating point
6071
6072Depending on the configuration, @value{GDBN} may be able to give
6073you more information about the status of the floating point hardware.
6074
6075@table @code
6076@kindex info float
6077@item info float
6078Display hardware-dependent information about the floating
6079point unit. The exact contents and layout vary depending on the
6080floating point chip. Currently, @samp{info float} is supported on
6081the ARM and x86 machines.
6082@end table
c906108c 6083
e76f1f2e
AC
6084@node Vector Unit
6085@section Vector Unit
6086@cindex vector unit
6087
6088Depending on the configuration, @value{GDBN} may be able to give you
6089more information about the status of the vector unit.
6090
6091@table @code
6092@kindex info vector
6093@item info vector
6094Display information about the vector unit. The exact contents and
6095layout vary depending on the hardware.
6096@end table
6097
721c2651
EZ
6098@node OS Information
6099@section Operating system auxiliary information
6100@cindex OS information
6101
6102@value{GDBN} provides interfaces to useful OS facilities that can help
6103you debug your program.
6104
6105@cindex @code{ptrace} system call
6106@cindex @code{struct user} contents
6107When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6108machines), it interfaces with the inferior via the @code{ptrace}
6109system call. The operating system creates a special sata structure,
6110called @code{struct user}, for this interface. You can use the
6111command @code{info udot} to display the contents of this data
6112structure.
6113
6114@table @code
6115@item info udot
6116@kindex info udot
6117Display the contents of the @code{struct user} maintained by the OS
6118kernel for the program being debugged. @value{GDBN} displays the
6119contents of @code{struct user} as a list of hex numbers, similar to
6120the @code{examine} command.
6121@end table
6122
b383017d
RM
6123@cindex auxiliary vector
6124@cindex vector, auxiliary
b383017d
RM
6125Some operating systems supply an @dfn{auxiliary vector} to programs at
6126startup. This is akin to the arguments and environment that you
6127specify for a program, but contains a system-dependent variety of
6128binary values that tell system libraries important details about the
6129hardware, operating system, and process. Each value's purpose is
6130identified by an integer tag; the meanings are well-known but system-specific.
6131Depending on the configuration and operating system facilities,
9c16f35a
EZ
6132@value{GDBN} may be able to show you this information. For remote
6133targets, this functionality may further depend on the remote stub's
6134support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6135configuration, auxiliary vector}.
b383017d
RM
6136
6137@table @code
6138@kindex info auxv
6139@item info auxv
6140Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6141live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6142numerically, and also shows names and text descriptions for recognized
6143tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6144pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6145most appropriate form for a recognized tag, and in hexadecimal for
6146an unrecognized tag.
6147@end table
6148
721c2651 6149
29e57380 6150@node Memory Region Attributes
b383017d 6151@section Memory region attributes
29e57380
C
6152@cindex memory region attributes
6153
b383017d
RM
6154@dfn{Memory region attributes} allow you to describe special handling
6155required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6156to determine whether to allow certain types of memory accesses; whether to
6157use specific width accesses; and whether to cache target memory.
6158
6159Defined memory regions can be individually enabled and disabled. When a
6160memory region is disabled, @value{GDBN} uses the default attributes when
6161accessing memory in that region. Similarly, if no memory regions have
6162been defined, @value{GDBN} uses the default attributes when accessing
6163all memory.
6164
b383017d 6165When a memory region is defined, it is given a number to identify it;
29e57380
C
6166to enable, disable, or remove a memory region, you specify that number.
6167
6168@table @code
6169@kindex mem
bfac230e 6170@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6171Define a memory region bounded by @var{lower} and @var{upper} with
6172attributes @var{attributes}@dots{}, and add it to the list of regions
6173monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6174case: it is treated as the the target's maximum memory address.
bfac230e 6175(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6176
6177@kindex delete mem
6178@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6179Remove memory regions @var{nums}@dots{} from the list of regions
6180monitored by @value{GDBN}.
29e57380
C
6181
6182@kindex disable mem
6183@item disable mem @var{nums}@dots{}
09d4efe1 6184Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6185A disabled memory region is not forgotten.
29e57380
C
6186It may be enabled again later.
6187
6188@kindex enable mem
6189@item enable mem @var{nums}@dots{}
09d4efe1 6190Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6191
6192@kindex info mem
6193@item info mem
6194Print a table of all defined memory regions, with the following columns
09d4efe1 6195for each region:
29e57380
C
6196
6197@table @emph
6198@item Memory Region Number
6199@item Enabled or Disabled.
b383017d 6200Enabled memory regions are marked with @samp{y}.
29e57380
C
6201Disabled memory regions are marked with @samp{n}.
6202
6203@item Lo Address
6204The address defining the inclusive lower bound of the memory region.
6205
6206@item Hi Address
6207The address defining the exclusive upper bound of the memory region.
6208
6209@item Attributes
6210The list of attributes set for this memory region.
6211@end table
6212@end table
6213
6214
6215@subsection Attributes
6216
b383017d 6217@subsubsection Memory Access Mode
29e57380
C
6218The access mode attributes set whether @value{GDBN} may make read or
6219write accesses to a memory region.
6220
6221While these attributes prevent @value{GDBN} from performing invalid
6222memory accesses, they do nothing to prevent the target system, I/O DMA,
6223etc. from accessing memory.
6224
6225@table @code
6226@item ro
6227Memory is read only.
6228@item wo
6229Memory is write only.
6230@item rw
6ca652b0 6231Memory is read/write. This is the default.
29e57380
C
6232@end table
6233
6234@subsubsection Memory Access Size
6235The acccess size attributes tells @value{GDBN} to use specific sized
6236accesses in the memory region. Often memory mapped device registers
6237require specific sized accesses. If no access size attribute is
6238specified, @value{GDBN} may use accesses of any size.
6239
6240@table @code
6241@item 8
6242Use 8 bit memory accesses.
6243@item 16
6244Use 16 bit memory accesses.
6245@item 32
6246Use 32 bit memory accesses.
6247@item 64
6248Use 64 bit memory accesses.
6249@end table
6250
6251@c @subsubsection Hardware/Software Breakpoints
6252@c The hardware/software breakpoint attributes set whether @value{GDBN}
6253@c will use hardware or software breakpoints for the internal breakpoints
6254@c used by the step, next, finish, until, etc. commands.
6255@c
6256@c @table @code
6257@c @item hwbreak
b383017d 6258@c Always use hardware breakpoints
29e57380
C
6259@c @item swbreak (default)
6260@c @end table
6261
6262@subsubsection Data Cache
6263The data cache attributes set whether @value{GDBN} will cache target
6264memory. While this generally improves performance by reducing debug
6265protocol overhead, it can lead to incorrect results because @value{GDBN}
6266does not know about volatile variables or memory mapped device
6267registers.
6268
6269@table @code
6270@item cache
b383017d 6271Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6272@item nocache
6273Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6274@end table
6275
6276@c @subsubsection Memory Write Verification
b383017d 6277@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6278@c will re-reads data after each write to verify the write was successful.
6279@c
6280@c @table @code
6281@c @item verify
6282@c @item noverify (default)
6283@c @end table
6284
16d9dec6
MS
6285@node Dump/Restore Files
6286@section Copy between memory and a file
6287@cindex dump/restore files
6288@cindex append data to a file
6289@cindex dump data to a file
6290@cindex restore data from a file
16d9dec6 6291
df5215a6
JB
6292You can use the commands @code{dump}, @code{append}, and
6293@code{restore} to copy data between target memory and a file. The
6294@code{dump} and @code{append} commands write data to a file, and the
6295@code{restore} command reads data from a file back into the inferior's
6296memory. Files may be in binary, Motorola S-record, Intel hex, or
6297Tektronix Hex format; however, @value{GDBN} can only append to binary
6298files.
6299
6300@table @code
6301
6302@kindex dump
6303@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6304@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6305Dump the contents of memory from @var{start_addr} to @var{end_addr},
6306or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6307
df5215a6 6308The @var{format} parameter may be any one of:
16d9dec6 6309@table @code
df5215a6
JB
6310@item binary
6311Raw binary form.
6312@item ihex
6313Intel hex format.
6314@item srec
6315Motorola S-record format.
6316@item tekhex
6317Tektronix Hex format.
6318@end table
6319
6320@value{GDBN} uses the same definitions of these formats as the
6321@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6322@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6323form.
6324
6325@kindex append
6326@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6327@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6328Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6329or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6330(@value{GDBN} can only append data to files in raw binary form.)
6331
6332@kindex restore
6333@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6334Restore the contents of file @var{filename} into memory. The
6335@code{restore} command can automatically recognize any known @sc{bfd}
6336file format, except for raw binary. To restore a raw binary file you
6337must specify the optional keyword @code{binary} after the filename.
16d9dec6 6338
b383017d 6339If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6340contained in the file. Binary files always start at address zero, so
6341they will be restored at address @var{bias}. Other bfd files have
6342a built-in location; they will be restored at offset @var{bias}
6343from that location.
6344
6345If @var{start} and/or @var{end} are non-zero, then only data between
6346file offset @var{start} and file offset @var{end} will be restored.
b383017d 6347These offsets are relative to the addresses in the file, before
16d9dec6
MS
6348the @var{bias} argument is applied.
6349
6350@end table
6351
384ee23f
EZ
6352@node Core File Generation
6353@section How to Produce a Core File from Your Program
6354@cindex dump core from inferior
6355
6356A @dfn{core file} or @dfn{core dump} is a file that records the memory
6357image of a running process and its process status (register values
6358etc.). Its primary use is post-mortem debugging of a program that
6359crashed while it ran outside a debugger. A program that crashes
6360automatically produces a core file, unless this feature is disabled by
6361the user. @xref{Files}, for information on invoking @value{GDBN} in
6362the post-mortem debugging mode.
6363
6364Occasionally, you may wish to produce a core file of the program you
6365are debugging in order to preserve a snapshot of its state.
6366@value{GDBN} has a special command for that.
6367
6368@table @code
6369@kindex gcore
6370@kindex generate-core-file
6371@item generate-core-file [@var{file}]
6372@itemx gcore [@var{file}]
6373Produce a core dump of the inferior process. The optional argument
6374@var{file} specifies the file name where to put the core dump. If not
6375specified, the file name defaults to @file{core.@var{pid}}, where
6376@var{pid} is the inferior process ID.
6377
6378Note that this command is implemented only for some systems (as of
6379this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6380@end table
6381
a0eb71c5
KB
6382@node Character Sets
6383@section Character Sets
6384@cindex character sets
6385@cindex charset
6386@cindex translating between character sets
6387@cindex host character set
6388@cindex target character set
6389
6390If the program you are debugging uses a different character set to
6391represent characters and strings than the one @value{GDBN} uses itself,
6392@value{GDBN} can automatically translate between the character sets for
6393you. The character set @value{GDBN} uses we call the @dfn{host
6394character set}; the one the inferior program uses we call the
6395@dfn{target character set}.
6396
6397For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6398uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6399remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6400running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6401then the host character set is Latin-1, and the target character set is
6402@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6403target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6404@sc{ebcdic} and Latin 1 as you print character or string values, or use
6405character and string literals in expressions.
6406
6407@value{GDBN} has no way to automatically recognize which character set
6408the inferior program uses; you must tell it, using the @code{set
6409target-charset} command, described below.
6410
6411Here are the commands for controlling @value{GDBN}'s character set
6412support:
6413
6414@table @code
6415@item set target-charset @var{charset}
6416@kindex set target-charset
6417Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6418character set names @value{GDBN} recognizes below, but if you type
6419@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6420list the target character sets it supports.
a0eb71c5
KB
6421@end table
6422
6423@table @code
6424@item set host-charset @var{charset}
6425@kindex set host-charset
6426Set the current host character set to @var{charset}.
6427
6428By default, @value{GDBN} uses a host character set appropriate to the
6429system it is running on; you can override that default using the
6430@code{set host-charset} command.
6431
6432@value{GDBN} can only use certain character sets as its host character
6433set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6434indicate which can be host character sets, but if you type
6435@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6436list the host character sets it supports.
a0eb71c5
KB
6437
6438@item set charset @var{charset}
6439@kindex set charset
e33d66ec
EZ
6440Set the current host and target character sets to @var{charset}. As
6441above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6442@value{GDBN} will list the name of the character sets that can be used
6443for both host and target.
6444
a0eb71c5
KB
6445
6446@item show charset
a0eb71c5 6447@kindex show charset
b383017d 6448Show the names of the current host and target charsets.
e33d66ec
EZ
6449
6450@itemx show host-charset
a0eb71c5 6451@kindex show host-charset
b383017d 6452Show the name of the current host charset.
e33d66ec
EZ
6453
6454@itemx show target-charset
a0eb71c5 6455@kindex show target-charset
b383017d 6456Show the name of the current target charset.
a0eb71c5
KB
6457
6458@end table
6459
6460@value{GDBN} currently includes support for the following character
6461sets:
6462
6463@table @code
6464
6465@item ASCII
6466@cindex ASCII character set
6467Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6468character set.
6469
6470@item ISO-8859-1
6471@cindex ISO 8859-1 character set
6472@cindex ISO Latin 1 character set
e33d66ec 6473The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6474characters needed for French, German, and Spanish. @value{GDBN} can use
6475this as its host character set.
6476
6477@item EBCDIC-US
6478@itemx IBM1047
6479@cindex EBCDIC character set
6480@cindex IBM1047 character set
6481Variants of the @sc{ebcdic} character set, used on some of IBM's
6482mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6483@value{GDBN} cannot use these as its host character set.
6484
6485@end table
6486
6487Note that these are all single-byte character sets. More work inside
6488GDB is needed to support multi-byte or variable-width character
6489encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6490
6491Here is an example of @value{GDBN}'s character set support in action.
6492Assume that the following source code has been placed in the file
6493@file{charset-test.c}:
6494
6495@smallexample
6496#include <stdio.h>
6497
6498char ascii_hello[]
6499 = @{72, 101, 108, 108, 111, 44, 32, 119,
6500 111, 114, 108, 100, 33, 10, 0@};
6501char ibm1047_hello[]
6502 = @{200, 133, 147, 147, 150, 107, 64, 166,
6503 150, 153, 147, 132, 90, 37, 0@};
6504
6505main ()
6506@{
6507 printf ("Hello, world!\n");
6508@}
10998722 6509@end smallexample
a0eb71c5
KB
6510
6511In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6512containing the string @samp{Hello, world!} followed by a newline,
6513encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6514
6515We compile the program, and invoke the debugger on it:
6516
6517@smallexample
6518$ gcc -g charset-test.c -o charset-test
6519$ gdb -nw charset-test
6520GNU gdb 2001-12-19-cvs
6521Copyright 2001 Free Software Foundation, Inc.
6522@dots{}
f7dc1244 6523(@value{GDBP})
10998722 6524@end smallexample
a0eb71c5
KB
6525
6526We can use the @code{show charset} command to see what character sets
6527@value{GDBN} is currently using to interpret and display characters and
6528strings:
6529
6530@smallexample
f7dc1244 6531(@value{GDBP}) show charset
e33d66ec 6532The current host and target character set is `ISO-8859-1'.
f7dc1244 6533(@value{GDBP})
10998722 6534@end smallexample
a0eb71c5
KB
6535
6536For the sake of printing this manual, let's use @sc{ascii} as our
6537initial character set:
6538@smallexample
f7dc1244
EZ
6539(@value{GDBP}) set charset ASCII
6540(@value{GDBP}) show charset
e33d66ec 6541The current host and target character set is `ASCII'.
f7dc1244 6542(@value{GDBP})
10998722 6543@end smallexample
a0eb71c5
KB
6544
6545Let's assume that @sc{ascii} is indeed the correct character set for our
6546host system --- in other words, let's assume that if @value{GDBN} prints
6547characters using the @sc{ascii} character set, our terminal will display
6548them properly. Since our current target character set is also
6549@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6550
6551@smallexample
f7dc1244 6552(@value{GDBP}) print ascii_hello
a0eb71c5 6553$1 = 0x401698 "Hello, world!\n"
f7dc1244 6554(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6555$2 = 72 'H'
f7dc1244 6556(@value{GDBP})
10998722 6557@end smallexample
a0eb71c5
KB
6558
6559@value{GDBN} uses the target character set for character and string
6560literals you use in expressions:
6561
6562@smallexample
f7dc1244 6563(@value{GDBP}) print '+'
a0eb71c5 6564$3 = 43 '+'
f7dc1244 6565(@value{GDBP})
10998722 6566@end smallexample
a0eb71c5
KB
6567
6568The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6569character.
6570
6571@value{GDBN} relies on the user to tell it which character set the
6572target program uses. If we print @code{ibm1047_hello} while our target
6573character set is still @sc{ascii}, we get jibberish:
6574
6575@smallexample
f7dc1244 6576(@value{GDBP}) print ibm1047_hello
a0eb71c5 6577$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6578(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6579$5 = 200 '\310'
f7dc1244 6580(@value{GDBP})
10998722 6581@end smallexample
a0eb71c5 6582
e33d66ec 6583If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6584@value{GDBN} tells us the character sets it supports:
6585
6586@smallexample
f7dc1244 6587(@value{GDBP}) set target-charset
b383017d 6588ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6589(@value{GDBP}) set target-charset
10998722 6590@end smallexample
a0eb71c5
KB
6591
6592We can select @sc{ibm1047} as our target character set, and examine the
6593program's strings again. Now the @sc{ascii} string is wrong, but
6594@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6595target character set, @sc{ibm1047}, to the host character set,
6596@sc{ascii}, and they display correctly:
6597
6598@smallexample
f7dc1244
EZ
6599(@value{GDBP}) set target-charset IBM1047
6600(@value{GDBP}) show charset
e33d66ec
EZ
6601The current host character set is `ASCII'.
6602The current target character set is `IBM1047'.
f7dc1244 6603(@value{GDBP}) print ascii_hello
a0eb71c5 6604$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6605(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6606$7 = 72 '\110'
f7dc1244 6607(@value{GDBP}) print ibm1047_hello
a0eb71c5 6608$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6609(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6610$9 = 200 'H'
f7dc1244 6611(@value{GDBP})
10998722 6612@end smallexample
a0eb71c5
KB
6613
6614As above, @value{GDBN} uses the target character set for character and
6615string literals you use in expressions:
6616
6617@smallexample
f7dc1244 6618(@value{GDBP}) print '+'
a0eb71c5 6619$10 = 78 '+'
f7dc1244 6620(@value{GDBP})
10998722 6621@end smallexample
a0eb71c5 6622
e33d66ec 6623The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6624character.
6625
09d4efe1
EZ
6626@node Caching Remote Data
6627@section Caching Data of Remote Targets
6628@cindex caching data of remote targets
6629
6630@value{GDBN} can cache data exchanged between the debugger and a
6631remote target (@pxref{Remote}). Such caching generally improves
6632performance, because it reduces the overhead of the remote protocol by
6633bundling memory reads and writes into large chunks. Unfortunately,
6634@value{GDBN} does not currently know anything about volatile
6635registers, and thus data caching will produce incorrect results when
6636volatile registers are in use.
6637
6638@table @code
6639@kindex set remotecache
6640@item set remotecache on
6641@itemx set remotecache off
6642Set caching state for remote targets. When @code{ON}, use data
6643caching. By default, this option is @code{OFF}.
6644
6645@kindex show remotecache
6646@item show remotecache
6647Show the current state of data caching for remote targets.
6648
6649@kindex info dcache
6650@item info dcache
6651Print the information about the data cache performance. The
6652information displayed includes: the dcache width and depth; and for
6653each cache line, how many times it was referenced, and its data and
6654state (dirty, bad, ok, etc.). This command is useful for debugging
6655the data cache operation.
6656@end table
6657
a0eb71c5 6658
e2e0bcd1
JB
6659@node Macros
6660@chapter C Preprocessor Macros
6661
49efadf5 6662Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6663``preprocessor macros'' which expand into strings of tokens.
6664@value{GDBN} can evaluate expressions containing macro invocations, show
6665the result of macro expansion, and show a macro's definition, including
6666where it was defined.
6667
6668You may need to compile your program specially to provide @value{GDBN}
6669with information about preprocessor macros. Most compilers do not
6670include macros in their debugging information, even when you compile
6671with the @option{-g} flag. @xref{Compilation}.
6672
6673A program may define a macro at one point, remove that definition later,
6674and then provide a different definition after that. Thus, at different
6675points in the program, a macro may have different definitions, or have
6676no definition at all. If there is a current stack frame, @value{GDBN}
6677uses the macros in scope at that frame's source code line. Otherwise,
6678@value{GDBN} uses the macros in scope at the current listing location;
6679see @ref{List}.
6680
6681At the moment, @value{GDBN} does not support the @code{##}
6682token-splicing operator, the @code{#} stringification operator, or
6683variable-arity macros.
6684
6685Whenever @value{GDBN} evaluates an expression, it always expands any
6686macro invocations present in the expression. @value{GDBN} also provides
6687the following commands for working with macros explicitly.
6688
6689@table @code
6690
6691@kindex macro expand
6692@cindex macro expansion, showing the results of preprocessor
6693@cindex preprocessor macro expansion, showing the results of
6694@cindex expanding preprocessor macros
6695@item macro expand @var{expression}
6696@itemx macro exp @var{expression}
6697Show the results of expanding all preprocessor macro invocations in
6698@var{expression}. Since @value{GDBN} simply expands macros, but does
6699not parse the result, @var{expression} need not be a valid expression;
6700it can be any string of tokens.
6701
09d4efe1 6702@kindex macro exp1
e2e0bcd1
JB
6703@item macro expand-once @var{expression}
6704@itemx macro exp1 @var{expression}
4644b6e3 6705@cindex expand macro once
e2e0bcd1
JB
6706@i{(This command is not yet implemented.)} Show the results of
6707expanding those preprocessor macro invocations that appear explicitly in
6708@var{expression}. Macro invocations appearing in that expansion are
6709left unchanged. This command allows you to see the effect of a
6710particular macro more clearly, without being confused by further
6711expansions. Since @value{GDBN} simply expands macros, but does not
6712parse the result, @var{expression} need not be a valid expression; it
6713can be any string of tokens.
6714
475b0867 6715@kindex info macro
e2e0bcd1
JB
6716@cindex macro definition, showing
6717@cindex definition, showing a macro's
475b0867 6718@item info macro @var{macro}
e2e0bcd1
JB
6719Show the definition of the macro named @var{macro}, and describe the
6720source location where that definition was established.
6721
6722@kindex macro define
6723@cindex user-defined macros
6724@cindex defining macros interactively
6725@cindex macros, user-defined
6726@item macro define @var{macro} @var{replacement-list}
6727@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6728@i{(This command is not yet implemented.)} Introduce a definition for a
6729preprocessor macro named @var{macro}, invocations of which are replaced
6730by the tokens given in @var{replacement-list}. The first form of this
6731command defines an ``object-like'' macro, which takes no arguments; the
6732second form defines a ``function-like'' macro, which takes the arguments
6733given in @var{arglist}.
6734
6735A definition introduced by this command is in scope in every expression
6736evaluated in @value{GDBN}, until it is removed with the @command{macro
6737undef} command, described below. The definition overrides all
6738definitions for @var{macro} present in the program being debugged, as
6739well as any previous user-supplied definition.
6740
6741@kindex macro undef
6742@item macro undef @var{macro}
6743@i{(This command is not yet implemented.)} Remove any user-supplied
6744definition for the macro named @var{macro}. This command only affects
6745definitions provided with the @command{macro define} command, described
6746above; it cannot remove definitions present in the program being
6747debugged.
6748
09d4efe1
EZ
6749@kindex macro list
6750@item macro list
6751@i{(This command is not yet implemented.)} List all the macros
6752defined using the @code{macro define} command.
e2e0bcd1
JB
6753@end table
6754
6755@cindex macros, example of debugging with
6756Here is a transcript showing the above commands in action. First, we
6757show our source files:
6758
6759@smallexample
6760$ cat sample.c
6761#include <stdio.h>
6762#include "sample.h"
6763
6764#define M 42
6765#define ADD(x) (M + x)
6766
6767main ()
6768@{
6769#define N 28
6770 printf ("Hello, world!\n");
6771#undef N
6772 printf ("We're so creative.\n");
6773#define N 1729
6774 printf ("Goodbye, world!\n");
6775@}
6776$ cat sample.h
6777#define Q <
6778$
6779@end smallexample
6780
6781Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6782We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6783compiler includes information about preprocessor macros in the debugging
6784information.
6785
6786@smallexample
6787$ gcc -gdwarf-2 -g3 sample.c -o sample
6788$
6789@end smallexample
6790
6791Now, we start @value{GDBN} on our sample program:
6792
6793@smallexample
6794$ gdb -nw sample
6795GNU gdb 2002-05-06-cvs
6796Copyright 2002 Free Software Foundation, Inc.
6797GDB is free software, @dots{}
f7dc1244 6798(@value{GDBP})
e2e0bcd1
JB
6799@end smallexample
6800
6801We can expand macros and examine their definitions, even when the
6802program is not running. @value{GDBN} uses the current listing position
6803to decide which macro definitions are in scope:
6804
6805@smallexample
f7dc1244 6806(@value{GDBP}) list main
e2e0bcd1
JB
68073
68084 #define M 42
68095 #define ADD(x) (M + x)
68106
68117 main ()
68128 @{
68139 #define N 28
681410 printf ("Hello, world!\n");
681511 #undef N
681612 printf ("We're so creative.\n");
f7dc1244 6817(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6818Defined at /home/jimb/gdb/macros/play/sample.c:5
6819#define ADD(x) (M + x)
f7dc1244 6820(@value{GDBP}) info macro Q
e2e0bcd1
JB
6821Defined at /home/jimb/gdb/macros/play/sample.h:1
6822 included at /home/jimb/gdb/macros/play/sample.c:2
6823#define Q <
f7dc1244 6824(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6825expands to: (42 + 1)
f7dc1244 6826(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6827expands to: once (M + 1)
f7dc1244 6828(@value{GDBP})
e2e0bcd1
JB
6829@end smallexample
6830
6831In the example above, note that @command{macro expand-once} expands only
6832the macro invocation explicit in the original text --- the invocation of
6833@code{ADD} --- but does not expand the invocation of the macro @code{M},
6834which was introduced by @code{ADD}.
6835
6836Once the program is running, GDB uses the macro definitions in force at
6837the source line of the current stack frame:
6838
6839@smallexample
f7dc1244 6840(@value{GDBP}) break main
e2e0bcd1 6841Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6842(@value{GDBP}) run
b383017d 6843Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6844
6845Breakpoint 1, main () at sample.c:10
684610 printf ("Hello, world!\n");
f7dc1244 6847(@value{GDBP})
e2e0bcd1
JB
6848@end smallexample
6849
6850At line 10, the definition of the macro @code{N} at line 9 is in force:
6851
6852@smallexample
f7dc1244 6853(@value{GDBP}) info macro N
e2e0bcd1
JB
6854Defined at /home/jimb/gdb/macros/play/sample.c:9
6855#define N 28
f7dc1244 6856(@value{GDBP}) macro expand N Q M
e2e0bcd1 6857expands to: 28 < 42
f7dc1244 6858(@value{GDBP}) print N Q M
e2e0bcd1 6859$1 = 1
f7dc1244 6860(@value{GDBP})
e2e0bcd1
JB
6861@end smallexample
6862
6863As we step over directives that remove @code{N}'s definition, and then
6864give it a new definition, @value{GDBN} finds the definition (or lack
6865thereof) in force at each point:
6866
6867@smallexample
f7dc1244 6868(@value{GDBP}) next
e2e0bcd1
JB
6869Hello, world!
687012 printf ("We're so creative.\n");
f7dc1244 6871(@value{GDBP}) info macro N
e2e0bcd1
JB
6872The symbol `N' has no definition as a C/C++ preprocessor macro
6873at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 6874(@value{GDBP}) next
e2e0bcd1
JB
6875We're so creative.
687614 printf ("Goodbye, world!\n");
f7dc1244 6877(@value{GDBP}) info macro N
e2e0bcd1
JB
6878Defined at /home/jimb/gdb/macros/play/sample.c:13
6879#define N 1729
f7dc1244 6880(@value{GDBP}) macro expand N Q M
e2e0bcd1 6881expands to: 1729 < 42
f7dc1244 6882(@value{GDBP}) print N Q M
e2e0bcd1 6883$2 = 0
f7dc1244 6884(@value{GDBP})
e2e0bcd1
JB
6885@end smallexample
6886
6887
b37052ae
EZ
6888@node Tracepoints
6889@chapter Tracepoints
6890@c This chapter is based on the documentation written by Michael
6891@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
6892
6893@cindex tracepoints
6894In some applications, it is not feasible for the debugger to interrupt
6895the program's execution long enough for the developer to learn
6896anything helpful about its behavior. If the program's correctness
6897depends on its real-time behavior, delays introduced by a debugger
6898might cause the program to change its behavior drastically, or perhaps
6899fail, even when the code itself is correct. It is useful to be able
6900to observe the program's behavior without interrupting it.
6901
6902Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
6903specify locations in the program, called @dfn{tracepoints}, and
6904arbitrary expressions to evaluate when those tracepoints are reached.
6905Later, using the @code{tfind} command, you can examine the values
6906those expressions had when the program hit the tracepoints. The
6907expressions may also denote objects in memory---structures or arrays,
6908for example---whose values @value{GDBN} should record; while visiting
6909a particular tracepoint, you may inspect those objects as if they were
6910in memory at that moment. However, because @value{GDBN} records these
6911values without interacting with you, it can do so quickly and
6912unobtrusively, hopefully not disturbing the program's behavior.
6913
6914The tracepoint facility is currently available only for remote
2c0069bb
EZ
6915targets. @xref{Targets}. In addition, your remote target must know how
6916to collect trace data. This functionality is implemented in the remote
6917stub; however, none of the stubs distributed with @value{GDBN} support
6918tracepoints as of this writing.
b37052ae
EZ
6919
6920This chapter describes the tracepoint commands and features.
6921
6922@menu
b383017d
RM
6923* Set Tracepoints::
6924* Analyze Collected Data::
6925* Tracepoint Variables::
b37052ae
EZ
6926@end menu
6927
6928@node Set Tracepoints
6929@section Commands to Set Tracepoints
6930
6931Before running such a @dfn{trace experiment}, an arbitrary number of
6932tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
6933tracepoint has a number assigned to it by @value{GDBN}. Like with
6934breakpoints, tracepoint numbers are successive integers starting from
6935one. Many of the commands associated with tracepoints take the
6936tracepoint number as their argument, to identify which tracepoint to
6937work on.
6938
6939For each tracepoint, you can specify, in advance, some arbitrary set
6940of data that you want the target to collect in the trace buffer when
6941it hits that tracepoint. The collected data can include registers,
6942local variables, or global data. Later, you can use @value{GDBN}
6943commands to examine the values these data had at the time the
6944tracepoint was hit.
6945
6946This section describes commands to set tracepoints and associated
6947conditions and actions.
6948
6949@menu
b383017d
RM
6950* Create and Delete Tracepoints::
6951* Enable and Disable Tracepoints::
6952* Tracepoint Passcounts::
6953* Tracepoint Actions::
6954* Listing Tracepoints::
6955* Starting and Stopping Trace Experiment::
b37052ae
EZ
6956@end menu
6957
6958@node Create and Delete Tracepoints
6959@subsection Create and Delete Tracepoints
6960
6961@table @code
6962@cindex set tracepoint
6963@kindex trace
6964@item trace
6965The @code{trace} command is very similar to the @code{break} command.
6966Its argument can be a source line, a function name, or an address in
6967the target program. @xref{Set Breaks}. The @code{trace} command
6968defines a tracepoint, which is a point in the target program where the
6969debugger will briefly stop, collect some data, and then allow the
6970program to continue. Setting a tracepoint or changing its commands
6971doesn't take effect until the next @code{tstart} command; thus, you
6972cannot change the tracepoint attributes once a trace experiment is
6973running.
6974
6975Here are some examples of using the @code{trace} command:
6976
6977@smallexample
6978(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
6979
6980(@value{GDBP}) @b{trace +2} // 2 lines forward
6981
6982(@value{GDBP}) @b{trace my_function} // first source line of function
6983
6984(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
6985
6986(@value{GDBP}) @b{trace *0x2117c4} // an address
6987@end smallexample
6988
6989@noindent
6990You can abbreviate @code{trace} as @code{tr}.
6991
6992@vindex $tpnum
6993@cindex last tracepoint number
6994@cindex recent tracepoint number
6995@cindex tracepoint number
6996The convenience variable @code{$tpnum} records the tracepoint number
6997of the most recently set tracepoint.
6998
6999@kindex delete tracepoint
7000@cindex tracepoint deletion
7001@item delete tracepoint @r{[}@var{num}@r{]}
7002Permanently delete one or more tracepoints. With no argument, the
7003default is to delete all tracepoints.
7004
7005Examples:
7006
7007@smallexample
7008(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7009
7010(@value{GDBP}) @b{delete trace} // remove all tracepoints
7011@end smallexample
7012
7013@noindent
7014You can abbreviate this command as @code{del tr}.
7015@end table
7016
7017@node Enable and Disable Tracepoints
7018@subsection Enable and Disable Tracepoints
7019
7020@table @code
7021@kindex disable tracepoint
7022@item disable tracepoint @r{[}@var{num}@r{]}
7023Disable tracepoint @var{num}, or all tracepoints if no argument
7024@var{num} is given. A disabled tracepoint will have no effect during
7025the next trace experiment, but it is not forgotten. You can re-enable
7026a disabled tracepoint using the @code{enable tracepoint} command.
7027
7028@kindex enable tracepoint
7029@item enable tracepoint @r{[}@var{num}@r{]}
7030Enable tracepoint @var{num}, or all tracepoints. The enabled
7031tracepoints will become effective the next time a trace experiment is
7032run.
7033@end table
7034
7035@node Tracepoint Passcounts
7036@subsection Tracepoint Passcounts
7037
7038@table @code
7039@kindex passcount
7040@cindex tracepoint pass count
7041@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7042Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7043automatically stop a trace experiment. If a tracepoint's passcount is
7044@var{n}, then the trace experiment will be automatically stopped on
7045the @var{n}'th time that tracepoint is hit. If the tracepoint number
7046@var{num} is not specified, the @code{passcount} command sets the
7047passcount of the most recently defined tracepoint. If no passcount is
7048given, the trace experiment will run until stopped explicitly by the
7049user.
7050
7051Examples:
7052
7053@smallexample
b383017d 7054(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7055@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7056
7057(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7058@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7059(@value{GDBP}) @b{trace foo}
7060(@value{GDBP}) @b{pass 3}
7061(@value{GDBP}) @b{trace bar}
7062(@value{GDBP}) @b{pass 2}
7063(@value{GDBP}) @b{trace baz}
7064(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7065@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7066@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7067@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7068@end smallexample
7069@end table
7070
7071@node Tracepoint Actions
7072@subsection Tracepoint Action Lists
7073
7074@table @code
7075@kindex actions
7076@cindex tracepoint actions
7077@item actions @r{[}@var{num}@r{]}
7078This command will prompt for a list of actions to be taken when the
7079tracepoint is hit. If the tracepoint number @var{num} is not
7080specified, this command sets the actions for the one that was most
7081recently defined (so that you can define a tracepoint and then say
7082@code{actions} without bothering about its number). You specify the
7083actions themselves on the following lines, one action at a time, and
7084terminate the actions list with a line containing just @code{end}. So
7085far, the only defined actions are @code{collect} and
7086@code{while-stepping}.
7087
7088@cindex remove actions from a tracepoint
7089To remove all actions from a tracepoint, type @samp{actions @var{num}}
7090and follow it immediately with @samp{end}.
7091
7092@smallexample
7093(@value{GDBP}) @b{collect @var{data}} // collect some data
7094
6826cf00 7095(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7096
6826cf00 7097(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7098@end smallexample
7099
7100In the following example, the action list begins with @code{collect}
7101commands indicating the things to be collected when the tracepoint is
7102hit. Then, in order to single-step and collect additional data
7103following the tracepoint, a @code{while-stepping} command is used,
7104followed by the list of things to be collected while stepping. The
7105@code{while-stepping} command is terminated by its own separate
7106@code{end} command. Lastly, the action list is terminated by an
7107@code{end} command.
7108
7109@smallexample
7110(@value{GDBP}) @b{trace foo}
7111(@value{GDBP}) @b{actions}
7112Enter actions for tracepoint 1, one per line:
7113> collect bar,baz
7114> collect $regs
7115> while-stepping 12
7116 > collect $fp, $sp
7117 > end
7118end
7119@end smallexample
7120
7121@kindex collect @r{(tracepoints)}
7122@item collect @var{expr1}, @var{expr2}, @dots{}
7123Collect values of the given expressions when the tracepoint is hit.
7124This command accepts a comma-separated list of any valid expressions.
7125In addition to global, static, or local variables, the following
7126special arguments are supported:
7127
7128@table @code
7129@item $regs
7130collect all registers
7131
7132@item $args
7133collect all function arguments
7134
7135@item $locals
7136collect all local variables.
7137@end table
7138
7139You can give several consecutive @code{collect} commands, each one
7140with a single argument, or one @code{collect} command with several
7141arguments separated by commas: the effect is the same.
7142
f5c37c66
EZ
7143The command @code{info scope} (@pxref{Symbols, info scope}) is
7144particularly useful for figuring out what data to collect.
7145
b37052ae
EZ
7146@kindex while-stepping @r{(tracepoints)}
7147@item while-stepping @var{n}
7148Perform @var{n} single-step traces after the tracepoint, collecting
7149new data at each step. The @code{while-stepping} command is
7150followed by the list of what to collect while stepping (followed by
7151its own @code{end} command):
7152
7153@smallexample
7154> while-stepping 12
7155 > collect $regs, myglobal
7156 > end
7157>
7158@end smallexample
7159
7160@noindent
7161You may abbreviate @code{while-stepping} as @code{ws} or
7162@code{stepping}.
7163@end table
7164
7165@node Listing Tracepoints
7166@subsection Listing Tracepoints
7167
7168@table @code
7169@kindex info tracepoints
09d4efe1 7170@kindex info tp
b37052ae
EZ
7171@cindex information about tracepoints
7172@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7173Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7174a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7175defined so far. For each tracepoint, the following information is
7176shown:
7177
7178@itemize @bullet
7179@item
7180its number
7181@item
7182whether it is enabled or disabled
7183@item
7184its address
7185@item
7186its passcount as given by the @code{passcount @var{n}} command
7187@item
7188its step count as given by the @code{while-stepping @var{n}} command
7189@item
7190where in the source files is the tracepoint set
7191@item
7192its action list as given by the @code{actions} command
7193@end itemize
7194
7195@smallexample
7196(@value{GDBP}) @b{info trace}
7197Num Enb Address PassC StepC What
71981 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
71992 y 0x0020dc64 0 0 in g_test at g_test.c:1375
72003 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7201(@value{GDBP})
7202@end smallexample
7203
7204@noindent
7205This command can be abbreviated @code{info tp}.
7206@end table
7207
7208@node Starting and Stopping Trace Experiment
7209@subsection Starting and Stopping Trace Experiment
7210
7211@table @code
7212@kindex tstart
7213@cindex start a new trace experiment
7214@cindex collected data discarded
7215@item tstart
7216This command takes no arguments. It starts the trace experiment, and
7217begins collecting data. This has the side effect of discarding all
7218the data collected in the trace buffer during the previous trace
7219experiment.
7220
7221@kindex tstop
7222@cindex stop a running trace experiment
7223@item tstop
7224This command takes no arguments. It ends the trace experiment, and
7225stops collecting data.
7226
68c71a2e 7227@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7228automatically if any tracepoint's passcount is reached
7229(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7230
7231@kindex tstatus
7232@cindex status of trace data collection
7233@cindex trace experiment, status of
7234@item tstatus
7235This command displays the status of the current trace data
7236collection.
7237@end table
7238
7239Here is an example of the commands we described so far:
7240
7241@smallexample
7242(@value{GDBP}) @b{trace gdb_c_test}
7243(@value{GDBP}) @b{actions}
7244Enter actions for tracepoint #1, one per line.
7245> collect $regs,$locals,$args
7246> while-stepping 11
7247 > collect $regs
7248 > end
7249> end
7250(@value{GDBP}) @b{tstart}
7251 [time passes @dots{}]
7252(@value{GDBP}) @b{tstop}
7253@end smallexample
7254
7255
7256@node Analyze Collected Data
7257@section Using the collected data
7258
7259After the tracepoint experiment ends, you use @value{GDBN} commands
7260for examining the trace data. The basic idea is that each tracepoint
7261collects a trace @dfn{snapshot} every time it is hit and another
7262snapshot every time it single-steps. All these snapshots are
7263consecutively numbered from zero and go into a buffer, and you can
7264examine them later. The way you examine them is to @dfn{focus} on a
7265specific trace snapshot. When the remote stub is focused on a trace
7266snapshot, it will respond to all @value{GDBN} requests for memory and
7267registers by reading from the buffer which belongs to that snapshot,
7268rather than from @emph{real} memory or registers of the program being
7269debugged. This means that @strong{all} @value{GDBN} commands
7270(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7271behave as if we were currently debugging the program state as it was
7272when the tracepoint occurred. Any requests for data that are not in
7273the buffer will fail.
7274
7275@menu
7276* tfind:: How to select a trace snapshot
7277* tdump:: How to display all data for a snapshot
7278* save-tracepoints:: How to save tracepoints for a future run
7279@end menu
7280
7281@node tfind
7282@subsection @code{tfind @var{n}}
7283
7284@kindex tfind
7285@cindex select trace snapshot
7286@cindex find trace snapshot
7287The basic command for selecting a trace snapshot from the buffer is
7288@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7289counting from zero. If no argument @var{n} is given, the next
7290snapshot is selected.
7291
7292Here are the various forms of using the @code{tfind} command.
7293
7294@table @code
7295@item tfind start
7296Find the first snapshot in the buffer. This is a synonym for
7297@code{tfind 0} (since 0 is the number of the first snapshot).
7298
7299@item tfind none
7300Stop debugging trace snapshots, resume @emph{live} debugging.
7301
7302@item tfind end
7303Same as @samp{tfind none}.
7304
7305@item tfind
7306No argument means find the next trace snapshot.
7307
7308@item tfind -
7309Find the previous trace snapshot before the current one. This permits
7310retracing earlier steps.
7311
7312@item tfind tracepoint @var{num}
7313Find the next snapshot associated with tracepoint @var{num}. Search
7314proceeds forward from the last examined trace snapshot. If no
7315argument @var{num} is given, it means find the next snapshot collected
7316for the same tracepoint as the current snapshot.
7317
7318@item tfind pc @var{addr}
7319Find the next snapshot associated with the value @var{addr} of the
7320program counter. Search proceeds forward from the last examined trace
7321snapshot. If no argument @var{addr} is given, it means find the next
7322snapshot with the same value of PC as the current snapshot.
7323
7324@item tfind outside @var{addr1}, @var{addr2}
7325Find the next snapshot whose PC is outside the given range of
7326addresses.
7327
7328@item tfind range @var{addr1}, @var{addr2}
7329Find the next snapshot whose PC is between @var{addr1} and
7330@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7331
7332@item tfind line @r{[}@var{file}:@r{]}@var{n}
7333Find the next snapshot associated with the source line @var{n}. If
7334the optional argument @var{file} is given, refer to line @var{n} in
7335that source file. Search proceeds forward from the last examined
7336trace snapshot. If no argument @var{n} is given, it means find the
7337next line other than the one currently being examined; thus saying
7338@code{tfind line} repeatedly can appear to have the same effect as
7339stepping from line to line in a @emph{live} debugging session.
7340@end table
7341
7342The default arguments for the @code{tfind} commands are specifically
7343designed to make it easy to scan through the trace buffer. For
7344instance, @code{tfind} with no argument selects the next trace
7345snapshot, and @code{tfind -} with no argument selects the previous
7346trace snapshot. So, by giving one @code{tfind} command, and then
7347simply hitting @key{RET} repeatedly you can examine all the trace
7348snapshots in order. Or, by saying @code{tfind -} and then hitting
7349@key{RET} repeatedly you can examine the snapshots in reverse order.
7350The @code{tfind line} command with no argument selects the snapshot
7351for the next source line executed. The @code{tfind pc} command with
7352no argument selects the next snapshot with the same program counter
7353(PC) as the current frame. The @code{tfind tracepoint} command with
7354no argument selects the next trace snapshot collected by the same
7355tracepoint as the current one.
7356
7357In addition to letting you scan through the trace buffer manually,
7358these commands make it easy to construct @value{GDBN} scripts that
7359scan through the trace buffer and print out whatever collected data
7360you are interested in. Thus, if we want to examine the PC, FP, and SP
7361registers from each trace frame in the buffer, we can say this:
7362
7363@smallexample
7364(@value{GDBP}) @b{tfind start}
7365(@value{GDBP}) @b{while ($trace_frame != -1)}
7366> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7367 $trace_frame, $pc, $sp, $fp
7368> tfind
7369> end
7370
7371Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7372Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7373Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7374Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7375Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7376Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7377Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7378Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7379Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7380Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7381Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7382@end smallexample
7383
7384Or, if we want to examine the variable @code{X} at each source line in
7385the buffer:
7386
7387@smallexample
7388(@value{GDBP}) @b{tfind start}
7389(@value{GDBP}) @b{while ($trace_frame != -1)}
7390> printf "Frame %d, X == %d\n", $trace_frame, X
7391> tfind line
7392> end
7393
7394Frame 0, X = 1
7395Frame 7, X = 2
7396Frame 13, X = 255
7397@end smallexample
7398
7399@node tdump
7400@subsection @code{tdump}
7401@kindex tdump
7402@cindex dump all data collected at tracepoint
7403@cindex tracepoint data, display
7404
7405This command takes no arguments. It prints all the data collected at
7406the current trace snapshot.
7407
7408@smallexample
7409(@value{GDBP}) @b{trace 444}
7410(@value{GDBP}) @b{actions}
7411Enter actions for tracepoint #2, one per line:
7412> collect $regs, $locals, $args, gdb_long_test
7413> end
7414
7415(@value{GDBP}) @b{tstart}
7416
7417(@value{GDBP}) @b{tfind line 444}
7418#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7419at gdb_test.c:444
7420444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7421
7422(@value{GDBP}) @b{tdump}
7423Data collected at tracepoint 2, trace frame 1:
7424d0 0xc4aa0085 -995491707
7425d1 0x18 24
7426d2 0x80 128
7427d3 0x33 51
7428d4 0x71aea3d 119204413
7429d5 0x22 34
7430d6 0xe0 224
7431d7 0x380035 3670069
7432a0 0x19e24a 1696330
7433a1 0x3000668 50333288
7434a2 0x100 256
7435a3 0x322000 3284992
7436a4 0x3000698 50333336
7437a5 0x1ad3cc 1758156
7438fp 0x30bf3c 0x30bf3c
7439sp 0x30bf34 0x30bf34
7440ps 0x0 0
7441pc 0x20b2c8 0x20b2c8
7442fpcontrol 0x0 0
7443fpstatus 0x0 0
7444fpiaddr 0x0 0
7445p = 0x20e5b4 "gdb-test"
7446p1 = (void *) 0x11
7447p2 = (void *) 0x22
7448p3 = (void *) 0x33
7449p4 = (void *) 0x44
7450p5 = (void *) 0x55
7451p6 = (void *) 0x66
7452gdb_long_test = 17 '\021'
7453
7454(@value{GDBP})
7455@end smallexample
7456
7457@node save-tracepoints
7458@subsection @code{save-tracepoints @var{filename}}
7459@kindex save-tracepoints
7460@cindex save tracepoints for future sessions
7461
7462This command saves all current tracepoint definitions together with
7463their actions and passcounts, into a file @file{@var{filename}}
7464suitable for use in a later debugging session. To read the saved
7465tracepoint definitions, use the @code{source} command (@pxref{Command
7466Files}).
7467
7468@node Tracepoint Variables
7469@section Convenience Variables for Tracepoints
7470@cindex tracepoint variables
7471@cindex convenience variables for tracepoints
7472
7473@table @code
7474@vindex $trace_frame
7475@item (int) $trace_frame
7476The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7477snapshot is selected.
7478
7479@vindex $tracepoint
7480@item (int) $tracepoint
7481The tracepoint for the current trace snapshot.
7482
7483@vindex $trace_line
7484@item (int) $trace_line
7485The line number for the current trace snapshot.
7486
7487@vindex $trace_file
7488@item (char []) $trace_file
7489The source file for the current trace snapshot.
7490
7491@vindex $trace_func
7492@item (char []) $trace_func
7493The name of the function containing @code{$tracepoint}.
7494@end table
7495
7496Note: @code{$trace_file} is not suitable for use in @code{printf},
7497use @code{output} instead.
7498
7499Here's a simple example of using these convenience variables for
7500stepping through all the trace snapshots and printing some of their
7501data.
7502
7503@smallexample
7504(@value{GDBP}) @b{tfind start}
7505
7506(@value{GDBP}) @b{while $trace_frame != -1}
7507> output $trace_file
7508> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7509> tfind
7510> end
7511@end smallexample
7512
df0cd8c5
JB
7513@node Overlays
7514@chapter Debugging Programs That Use Overlays
7515@cindex overlays
7516
7517If your program is too large to fit completely in your target system's
7518memory, you can sometimes use @dfn{overlays} to work around this
7519problem. @value{GDBN} provides some support for debugging programs that
7520use overlays.
7521
7522@menu
7523* How Overlays Work:: A general explanation of overlays.
7524* Overlay Commands:: Managing overlays in @value{GDBN}.
7525* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7526 mapped by asking the inferior.
7527* Overlay Sample Program:: A sample program using overlays.
7528@end menu
7529
7530@node How Overlays Work
7531@section How Overlays Work
7532@cindex mapped overlays
7533@cindex unmapped overlays
7534@cindex load address, overlay's
7535@cindex mapped address
7536@cindex overlay area
7537
7538Suppose you have a computer whose instruction address space is only 64
7539kilobytes long, but which has much more memory which can be accessed by
7540other means: special instructions, segment registers, or memory
7541management hardware, for example. Suppose further that you want to
7542adapt a program which is larger than 64 kilobytes to run on this system.
7543
7544One solution is to identify modules of your program which are relatively
7545independent, and need not call each other directly; call these modules
7546@dfn{overlays}. Separate the overlays from the main program, and place
7547their machine code in the larger memory. Place your main program in
7548instruction memory, but leave at least enough space there to hold the
7549largest overlay as well.
7550
7551Now, to call a function located in an overlay, you must first copy that
7552overlay's machine code from the large memory into the space set aside
7553for it in the instruction memory, and then jump to its entry point
7554there.
7555
c928edc0
AC
7556@c NB: In the below the mapped area's size is greater or equal to the
7557@c size of all overlays. This is intentional to remind the developer
7558@c that overlays don't necessarily need to be the same size.
7559
474c8240 7560@smallexample
df0cd8c5 7561@group
c928edc0
AC
7562 Data Instruction Larger
7563Address Space Address Space Address Space
7564+-----------+ +-----------+ +-----------+
7565| | | | | |
7566+-----------+ +-----------+ +-----------+<-- overlay 1
7567| program | | main | .----| overlay 1 | load address
7568| variables | | program | | +-----------+
7569| and heap | | | | | |
7570+-----------+ | | | +-----------+<-- overlay 2
7571| | +-----------+ | | | load address
7572+-----------+ | | | .-| overlay 2 |
7573 | | | | | |
7574 mapped --->+-----------+ | | +-----------+
7575 address | | | | | |
7576 | overlay | <-' | | |
7577 | area | <---' +-----------+<-- overlay 3
7578 | | <---. | | load address
7579 +-----------+ `--| overlay 3 |
7580 | | | |
7581 +-----------+ | |
7582 +-----------+
7583 | |
7584 +-----------+
7585
7586 @anchor{A code overlay}A code overlay
df0cd8c5 7587@end group
474c8240 7588@end smallexample
df0cd8c5 7589
c928edc0
AC
7590The diagram (@pxref{A code overlay}) shows a system with separate data
7591and instruction address spaces. To map an overlay, the program copies
7592its code from the larger address space to the instruction address space.
7593Since the overlays shown here all use the same mapped address, only one
7594may be mapped at a time. For a system with a single address space for
7595data and instructions, the diagram would be similar, except that the
7596program variables and heap would share an address space with the main
7597program and the overlay area.
df0cd8c5
JB
7598
7599An overlay loaded into instruction memory and ready for use is called a
7600@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7601instruction memory. An overlay not present (or only partially present)
7602in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7603is its address in the larger memory. The mapped address is also called
7604the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7605called the @dfn{load memory address}, or @dfn{LMA}.
7606
7607Unfortunately, overlays are not a completely transparent way to adapt a
7608program to limited instruction memory. They introduce a new set of
7609global constraints you must keep in mind as you design your program:
7610
7611@itemize @bullet
7612
7613@item
7614Before calling or returning to a function in an overlay, your program
7615must make sure that overlay is actually mapped. Otherwise, the call or
7616return will transfer control to the right address, but in the wrong
7617overlay, and your program will probably crash.
7618
7619@item
7620If the process of mapping an overlay is expensive on your system, you
7621will need to choose your overlays carefully to minimize their effect on
7622your program's performance.
7623
7624@item
7625The executable file you load onto your system must contain each
7626overlay's instructions, appearing at the overlay's load address, not its
7627mapped address. However, each overlay's instructions must be relocated
7628and its symbols defined as if the overlay were at its mapped address.
7629You can use GNU linker scripts to specify different load and relocation
7630addresses for pieces of your program; see @ref{Overlay Description,,,
7631ld.info, Using ld: the GNU linker}.
7632
7633@item
7634The procedure for loading executable files onto your system must be able
7635to load their contents into the larger address space as well as the
7636instruction and data spaces.
7637
7638@end itemize
7639
7640The overlay system described above is rather simple, and could be
7641improved in many ways:
7642
7643@itemize @bullet
7644
7645@item
7646If your system has suitable bank switch registers or memory management
7647hardware, you could use those facilities to make an overlay's load area
7648contents simply appear at their mapped address in instruction space.
7649This would probably be faster than copying the overlay to its mapped
7650area in the usual way.
7651
7652@item
7653If your overlays are small enough, you could set aside more than one
7654overlay area, and have more than one overlay mapped at a time.
7655
7656@item
7657You can use overlays to manage data, as well as instructions. In
7658general, data overlays are even less transparent to your design than
7659code overlays: whereas code overlays only require care when you call or
7660return to functions, data overlays require care every time you access
7661the data. Also, if you change the contents of a data overlay, you
7662must copy its contents back out to its load address before you can copy a
7663different data overlay into the same mapped area.
7664
7665@end itemize
7666
7667
7668@node Overlay Commands
7669@section Overlay Commands
7670
7671To use @value{GDBN}'s overlay support, each overlay in your program must
7672correspond to a separate section of the executable file. The section's
7673virtual memory address and load memory address must be the overlay's
7674mapped and load addresses. Identifying overlays with sections allows
7675@value{GDBN} to determine the appropriate address of a function or
7676variable, depending on whether the overlay is mapped or not.
7677
7678@value{GDBN}'s overlay commands all start with the word @code{overlay};
7679you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7680
7681@table @code
7682@item overlay off
4644b6e3 7683@kindex overlay
df0cd8c5
JB
7684Disable @value{GDBN}'s overlay support. When overlay support is
7685disabled, @value{GDBN} assumes that all functions and variables are
7686always present at their mapped addresses. By default, @value{GDBN}'s
7687overlay support is disabled.
7688
7689@item overlay manual
df0cd8c5
JB
7690@cindex manual overlay debugging
7691Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7692relies on you to tell it which overlays are mapped, and which are not,
7693using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7694commands described below.
7695
7696@item overlay map-overlay @var{overlay}
7697@itemx overlay map @var{overlay}
df0cd8c5
JB
7698@cindex map an overlay
7699Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7700be the name of the object file section containing the overlay. When an
7701overlay is mapped, @value{GDBN} assumes it can find the overlay's
7702functions and variables at their mapped addresses. @value{GDBN} assumes
7703that any other overlays whose mapped ranges overlap that of
7704@var{overlay} are now unmapped.
7705
7706@item overlay unmap-overlay @var{overlay}
7707@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7708@cindex unmap an overlay
7709Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7710must be the name of the object file section containing the overlay.
7711When an overlay is unmapped, @value{GDBN} assumes it can find the
7712overlay's functions and variables at their load addresses.
7713
7714@item overlay auto
df0cd8c5
JB
7715Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7716consults a data structure the overlay manager maintains in the inferior
7717to see which overlays are mapped. For details, see @ref{Automatic
7718Overlay Debugging}.
7719
7720@item overlay load-target
7721@itemx overlay load
df0cd8c5
JB
7722@cindex reloading the overlay table
7723Re-read the overlay table from the inferior. Normally, @value{GDBN}
7724re-reads the table @value{GDBN} automatically each time the inferior
7725stops, so this command should only be necessary if you have changed the
7726overlay mapping yourself using @value{GDBN}. This command is only
7727useful when using automatic overlay debugging.
7728
7729@item overlay list-overlays
7730@itemx overlay list
7731@cindex listing mapped overlays
7732Display a list of the overlays currently mapped, along with their mapped
7733addresses, load addresses, and sizes.
7734
7735@end table
7736
7737Normally, when @value{GDBN} prints a code address, it includes the name
7738of the function the address falls in:
7739
474c8240 7740@smallexample
f7dc1244 7741(@value{GDBP}) print main
df0cd8c5 7742$3 = @{int ()@} 0x11a0 <main>
474c8240 7743@end smallexample
df0cd8c5
JB
7744@noindent
7745When overlay debugging is enabled, @value{GDBN} recognizes code in
7746unmapped overlays, and prints the names of unmapped functions with
7747asterisks around them. For example, if @code{foo} is a function in an
7748unmapped overlay, @value{GDBN} prints it this way:
7749
474c8240 7750@smallexample
f7dc1244 7751(@value{GDBP}) overlay list
df0cd8c5 7752No sections are mapped.
f7dc1244 7753(@value{GDBP}) print foo
df0cd8c5 7754$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7755@end smallexample
df0cd8c5
JB
7756@noindent
7757When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7758name normally:
7759
474c8240 7760@smallexample
f7dc1244 7761(@value{GDBP}) overlay list
b383017d 7762Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7763 mapped at 0x1016 - 0x104a
f7dc1244 7764(@value{GDBP}) print foo
df0cd8c5 7765$6 = @{int (int)@} 0x1016 <foo>
474c8240 7766@end smallexample
df0cd8c5
JB
7767
7768When overlay debugging is enabled, @value{GDBN} can find the correct
7769address for functions and variables in an overlay, whether or not the
7770overlay is mapped. This allows most @value{GDBN} commands, like
7771@code{break} and @code{disassemble}, to work normally, even on unmapped
7772code. However, @value{GDBN}'s breakpoint support has some limitations:
7773
7774@itemize @bullet
7775@item
7776@cindex breakpoints in overlays
7777@cindex overlays, setting breakpoints in
7778You can set breakpoints in functions in unmapped overlays, as long as
7779@value{GDBN} can write to the overlay at its load address.
7780@item
7781@value{GDBN} can not set hardware or simulator-based breakpoints in
7782unmapped overlays. However, if you set a breakpoint at the end of your
7783overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7784you are using manual overlay management), @value{GDBN} will re-set its
7785breakpoints properly.
7786@end itemize
7787
7788
7789@node Automatic Overlay Debugging
7790@section Automatic Overlay Debugging
7791@cindex automatic overlay debugging
7792
7793@value{GDBN} can automatically track which overlays are mapped and which
7794are not, given some simple co-operation from the overlay manager in the
7795inferior. If you enable automatic overlay debugging with the
7796@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7797looks in the inferior's memory for certain variables describing the
7798current state of the overlays.
7799
7800Here are the variables your overlay manager must define to support
7801@value{GDBN}'s automatic overlay debugging:
7802
7803@table @asis
7804
7805@item @code{_ovly_table}:
7806This variable must be an array of the following structures:
7807
474c8240 7808@smallexample
df0cd8c5
JB
7809struct
7810@{
7811 /* The overlay's mapped address. */
7812 unsigned long vma;
7813
7814 /* The size of the overlay, in bytes. */
7815 unsigned long size;
7816
7817 /* The overlay's load address. */
7818 unsigned long lma;
7819
7820 /* Non-zero if the overlay is currently mapped;
7821 zero otherwise. */
7822 unsigned long mapped;
7823@}
474c8240 7824@end smallexample
df0cd8c5
JB
7825
7826@item @code{_novlys}:
7827This variable must be a four-byte signed integer, holding the total
7828number of elements in @code{_ovly_table}.
7829
7830@end table
7831
7832To decide whether a particular overlay is mapped or not, @value{GDBN}
7833looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7834@code{lma} members equal the VMA and LMA of the overlay's section in the
7835executable file. When @value{GDBN} finds a matching entry, it consults
7836the entry's @code{mapped} member to determine whether the overlay is
7837currently mapped.
7838
81d46470 7839In addition, your overlay manager may define a function called
def71bfa 7840@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7841will silently set a breakpoint there. If the overlay manager then
7842calls this function whenever it has changed the overlay table, this
7843will enable @value{GDBN} to accurately keep track of which overlays
7844are in program memory, and update any breakpoints that may be set
b383017d 7845in overlays. This will allow breakpoints to work even if the
81d46470
MS
7846overlays are kept in ROM or other non-writable memory while they
7847are not being executed.
df0cd8c5
JB
7848
7849@node Overlay Sample Program
7850@section Overlay Sample Program
7851@cindex overlay example program
7852
7853When linking a program which uses overlays, you must place the overlays
7854at their load addresses, while relocating them to run at their mapped
7855addresses. To do this, you must write a linker script (@pxref{Overlay
7856Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7857since linker scripts are specific to a particular host system, target
7858architecture, and target memory layout, this manual cannot provide
7859portable sample code demonstrating @value{GDBN}'s overlay support.
7860
7861However, the @value{GDBN} source distribution does contain an overlaid
7862program, with linker scripts for a few systems, as part of its test
7863suite. The program consists of the following files from
7864@file{gdb/testsuite/gdb.base}:
7865
7866@table @file
7867@item overlays.c
7868The main program file.
7869@item ovlymgr.c
7870A simple overlay manager, used by @file{overlays.c}.
7871@item foo.c
7872@itemx bar.c
7873@itemx baz.c
7874@itemx grbx.c
7875Overlay modules, loaded and used by @file{overlays.c}.
7876@item d10v.ld
7877@itemx m32r.ld
7878Linker scripts for linking the test program on the @code{d10v-elf}
7879and @code{m32r-elf} targets.
7880@end table
7881
7882You can build the test program using the @code{d10v-elf} GCC
7883cross-compiler like this:
7884
474c8240 7885@smallexample
df0cd8c5
JB
7886$ d10v-elf-gcc -g -c overlays.c
7887$ d10v-elf-gcc -g -c ovlymgr.c
7888$ d10v-elf-gcc -g -c foo.c
7889$ d10v-elf-gcc -g -c bar.c
7890$ d10v-elf-gcc -g -c baz.c
7891$ d10v-elf-gcc -g -c grbx.c
7892$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
7893 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 7894@end smallexample
df0cd8c5
JB
7895
7896The build process is identical for any other architecture, except that
7897you must substitute the appropriate compiler and linker script for the
7898target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
7899
7900
6d2ebf8b 7901@node Languages
c906108c
SS
7902@chapter Using @value{GDBN} with Different Languages
7903@cindex languages
7904
c906108c
SS
7905Although programming languages generally have common aspects, they are
7906rarely expressed in the same manner. For instance, in ANSI C,
7907dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
7908Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 7909represented (and displayed) differently. Hex numbers in C appear as
c906108c 7910@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
7911
7912@cindex working language
7913Language-specific information is built into @value{GDBN} for some languages,
7914allowing you to express operations like the above in your program's
7915native language, and allowing @value{GDBN} to output values in a manner
7916consistent with the syntax of your program's native language. The
7917language you use to build expressions is called the @dfn{working
7918language}.
7919
7920@menu
7921* Setting:: Switching between source languages
7922* Show:: Displaying the language
c906108c 7923* Checks:: Type and range checks
9c16f35a 7924* Supported languages:: Supported languages
4e562065 7925* Unsupported languages:: Unsupported languages
c906108c
SS
7926@end menu
7927
6d2ebf8b 7928@node Setting
c906108c
SS
7929@section Switching between source languages
7930
7931There are two ways to control the working language---either have @value{GDBN}
7932set it automatically, or select it manually yourself. You can use the
7933@code{set language} command for either purpose. On startup, @value{GDBN}
7934defaults to setting the language automatically. The working language is
7935used to determine how expressions you type are interpreted, how values
7936are printed, etc.
7937
7938In addition to the working language, every source file that
7939@value{GDBN} knows about has its own working language. For some object
7940file formats, the compiler might indicate which language a particular
7941source file is in. However, most of the time @value{GDBN} infers the
7942language from the name of the file. The language of a source file
b37052ae 7943controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 7944show each frame appropriately for its own language. There is no way to
d4f3574e
SS
7945set the language of a source file from within @value{GDBN}, but you can
7946set the language associated with a filename extension. @xref{Show, ,
7947Displaying the language}.
c906108c
SS
7948
7949This is most commonly a problem when you use a program, such
5d161b24 7950as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
7951another language. In that case, make the
7952program use @code{#line} directives in its C output; that way
7953@value{GDBN} will know the correct language of the source code of the original
7954program, and will display that source code, not the generated C code.
7955
7956@menu
7957* Filenames:: Filename extensions and languages.
7958* Manually:: Setting the working language manually
7959* Automatically:: Having @value{GDBN} infer the source language
7960@end menu
7961
6d2ebf8b 7962@node Filenames
c906108c
SS
7963@subsection List of filename extensions and languages
7964
7965If a source file name ends in one of the following extensions, then
7966@value{GDBN} infers that its language is the one indicated.
7967
7968@table @file
e07c999f
PH
7969@item .ada
7970@itemx .ads
7971@itemx .adb
7972@itemx .a
7973Ada source file.
c906108c
SS
7974
7975@item .c
7976C source file
7977
7978@item .C
7979@itemx .cc
7980@itemx .cp
7981@itemx .cpp
7982@itemx .cxx
7983@itemx .c++
b37052ae 7984C@t{++} source file
c906108c 7985
b37303ee
AF
7986@item .m
7987Objective-C source file
7988
c906108c
SS
7989@item .f
7990@itemx .F
7991Fortran source file
7992
c906108c
SS
7993@item .mod
7994Modula-2 source file
c906108c
SS
7995
7996@item .s
7997@itemx .S
7998Assembler source file. This actually behaves almost like C, but
7999@value{GDBN} does not skip over function prologues when stepping.
8000@end table
8001
8002In addition, you may set the language associated with a filename
8003extension. @xref{Show, , Displaying the language}.
8004
6d2ebf8b 8005@node Manually
c906108c
SS
8006@subsection Setting the working language
8007
8008If you allow @value{GDBN} to set the language automatically,
8009expressions are interpreted the same way in your debugging session and
8010your program.
8011
8012@kindex set language
8013If you wish, you may set the language manually. To do this, issue the
8014command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8015a language, such as
c906108c 8016@code{c} or @code{modula-2}.
c906108c
SS
8017For a list of the supported languages, type @samp{set language}.
8018
c906108c
SS
8019Setting the language manually prevents @value{GDBN} from updating the working
8020language automatically. This can lead to confusion if you try
8021to debug a program when the working language is not the same as the
8022source language, when an expression is acceptable to both
8023languages---but means different things. For instance, if the current
8024source file were written in C, and @value{GDBN} was parsing Modula-2, a
8025command such as:
8026
474c8240 8027@smallexample
c906108c 8028print a = b + c
474c8240 8029@end smallexample
c906108c
SS
8030
8031@noindent
8032might not have the effect you intended. In C, this means to add
8033@code{b} and @code{c} and place the result in @code{a}. The result
8034printed would be the value of @code{a}. In Modula-2, this means to compare
8035@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8036
6d2ebf8b 8037@node Automatically
c906108c
SS
8038@subsection Having @value{GDBN} infer the source language
8039
8040To have @value{GDBN} set the working language automatically, use
8041@samp{set language local} or @samp{set language auto}. @value{GDBN}
8042then infers the working language. That is, when your program stops in a
8043frame (usually by encountering a breakpoint), @value{GDBN} sets the
8044working language to the language recorded for the function in that
8045frame. If the language for a frame is unknown (that is, if the function
8046or block corresponding to the frame was defined in a source file that
8047does not have a recognized extension), the current working language is
8048not changed, and @value{GDBN} issues a warning.
8049
8050This may not seem necessary for most programs, which are written
8051entirely in one source language. However, program modules and libraries
8052written in one source language can be used by a main program written in
8053a different source language. Using @samp{set language auto} in this
8054case frees you from having to set the working language manually.
8055
6d2ebf8b 8056@node Show
c906108c 8057@section Displaying the language
c906108c
SS
8058
8059The following commands help you find out which language is the
8060working language, and also what language source files were written in.
8061
c906108c
SS
8062@table @code
8063@item show language
9c16f35a 8064@kindex show language
c906108c
SS
8065Display the current working language. This is the
8066language you can use with commands such as @code{print} to
8067build and compute expressions that may involve variables in your program.
8068
8069@item info frame
4644b6e3 8070@kindex info frame@r{, show the source language}
5d161b24 8071Display the source language for this frame. This language becomes the
c906108c 8072working language if you use an identifier from this frame.
5d161b24 8073@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8074information listed here.
8075
8076@item info source
4644b6e3 8077@kindex info source@r{, show the source language}
c906108c 8078Display the source language of this source file.
5d161b24 8079@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8080information listed here.
8081@end table
8082
8083In unusual circumstances, you may have source files with extensions
8084not in the standard list. You can then set the extension associated
8085with a language explicitly:
8086
c906108c 8087@table @code
09d4efe1 8088@item set extension-language @var{ext} @var{language}
9c16f35a 8089@kindex set extension-language
09d4efe1
EZ
8090Tell @value{GDBN} that source files with extension @var{ext} are to be
8091assumed as written in the source language @var{language}.
c906108c
SS
8092
8093@item info extensions
9c16f35a 8094@kindex info extensions
c906108c
SS
8095List all the filename extensions and the associated languages.
8096@end table
8097
6d2ebf8b 8098@node Checks
c906108c
SS
8099@section Type and range checking
8100
8101@quotation
8102@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8103checking are included, but they do not yet have any effect. This
8104section documents the intended facilities.
8105@end quotation
8106@c FIXME remove warning when type/range code added
8107
8108Some languages are designed to guard you against making seemingly common
8109errors through a series of compile- and run-time checks. These include
8110checking the type of arguments to functions and operators, and making
8111sure mathematical overflows are caught at run time. Checks such as
8112these help to ensure a program's correctness once it has been compiled
8113by eliminating type mismatches, and providing active checks for range
8114errors when your program is running.
8115
8116@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8117Although @value{GDBN} does not check the statements in your program,
8118it can check expressions entered directly into @value{GDBN} for
8119evaluation via the @code{print} command, for example. As with the
8120working language, @value{GDBN} can also decide whether or not to check
8121automatically based on your program's source language.
8122@xref{Supported languages, ,Supported languages}, for the default
8123settings of supported languages.
c906108c
SS
8124
8125@menu
8126* Type Checking:: An overview of type checking
8127* Range Checking:: An overview of range checking
8128@end menu
8129
8130@cindex type checking
8131@cindex checks, type
6d2ebf8b 8132@node Type Checking
c906108c
SS
8133@subsection An overview of type checking
8134
8135Some languages, such as Modula-2, are strongly typed, meaning that the
8136arguments to operators and functions have to be of the correct type,
8137otherwise an error occurs. These checks prevent type mismatch
8138errors from ever causing any run-time problems. For example,
8139
8140@smallexample
81411 + 2 @result{} 3
8142@exdent but
8143@error{} 1 + 2.3
8144@end smallexample
8145
8146The second example fails because the @code{CARDINAL} 1 is not
8147type-compatible with the @code{REAL} 2.3.
8148
5d161b24
DB
8149For the expressions you use in @value{GDBN} commands, you can tell the
8150@value{GDBN} type checker to skip checking;
8151to treat any mismatches as errors and abandon the expression;
8152or to only issue warnings when type mismatches occur,
c906108c
SS
8153but evaluate the expression anyway. When you choose the last of
8154these, @value{GDBN} evaluates expressions like the second example above, but
8155also issues a warning.
8156
5d161b24
DB
8157Even if you turn type checking off, there may be other reasons
8158related to type that prevent @value{GDBN} from evaluating an expression.
8159For instance, @value{GDBN} does not know how to add an @code{int} and
8160a @code{struct foo}. These particular type errors have nothing to do
8161with the language in use, and usually arise from expressions, such as
c906108c
SS
8162the one described above, which make little sense to evaluate anyway.
8163
8164Each language defines to what degree it is strict about type. For
8165instance, both Modula-2 and C require the arguments to arithmetical
8166operators to be numbers. In C, enumerated types and pointers can be
8167represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8168operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8169details on specific languages.
8170
8171@value{GDBN} provides some additional commands for controlling the type checker:
8172
c906108c
SS
8173@kindex set check type
8174@kindex show check type
8175@table @code
8176@item set check type auto
8177Set type checking on or off based on the current working language.
9c16f35a 8178@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8179each language.
8180
8181@item set check type on
8182@itemx set check type off
8183Set type checking on or off, overriding the default setting for the
8184current working language. Issue a warning if the setting does not
8185match the language default. If any type mismatches occur in
d4f3574e 8186evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8187message and aborts evaluation of the expression.
8188
8189@item set check type warn
8190Cause the type checker to issue warnings, but to always attempt to
8191evaluate the expression. Evaluating the expression may still
8192be impossible for other reasons. For example, @value{GDBN} cannot add
8193numbers and structures.
8194
8195@item show type
5d161b24 8196Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8197is setting it automatically.
8198@end table
8199
8200@cindex range checking
8201@cindex checks, range
6d2ebf8b 8202@node Range Checking
c906108c
SS
8203@subsection An overview of range checking
8204
8205In some languages (such as Modula-2), it is an error to exceed the
8206bounds of a type; this is enforced with run-time checks. Such range
8207checking is meant to ensure program correctness by making sure
8208computations do not overflow, or indices on an array element access do
8209not exceed the bounds of the array.
8210
8211For expressions you use in @value{GDBN} commands, you can tell
8212@value{GDBN} to treat range errors in one of three ways: ignore them,
8213always treat them as errors and abandon the expression, or issue
8214warnings but evaluate the expression anyway.
8215
8216A range error can result from numerical overflow, from exceeding an
8217array index bound, or when you type a constant that is not a member
8218of any type. Some languages, however, do not treat overflows as an
8219error. In many implementations of C, mathematical overflow causes the
8220result to ``wrap around'' to lower values---for example, if @var{m} is
8221the largest integer value, and @var{s} is the smallest, then
8222
474c8240 8223@smallexample
c906108c 8224@var{m} + 1 @result{} @var{s}
474c8240 8225@end smallexample
c906108c
SS
8226
8227This, too, is specific to individual languages, and in some cases
9c16f35a 8228specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8229Supported languages}, for further details on specific languages.
8230
8231@value{GDBN} provides some additional commands for controlling the range checker:
8232
c906108c
SS
8233@kindex set check range
8234@kindex show check range
8235@table @code
8236@item set check range auto
8237Set range checking on or off based on the current working language.
9c16f35a 8238@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8239each language.
8240
8241@item set check range on
8242@itemx set check range off
8243Set range checking on or off, overriding the default setting for the
8244current working language. A warning is issued if the setting does not
c3f6f71d
JM
8245match the language default. If a range error occurs and range checking is on,
8246then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8247
8248@item set check range warn
8249Output messages when the @value{GDBN} range checker detects a range error,
8250but attempt to evaluate the expression anyway. Evaluating the
8251expression may still be impossible for other reasons, such as accessing
8252memory that the process does not own (a typical example from many Unix
8253systems).
8254
8255@item show range
8256Show the current setting of the range checker, and whether or not it is
8257being set automatically by @value{GDBN}.
8258@end table
c906108c 8259
9c16f35a 8260@node Supported languages
c906108c 8261@section Supported languages
c906108c 8262
9c16f35a
EZ
8263@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8264assembly, Modula-2, and Ada.
cce74817 8265@c This is false ...
c906108c
SS
8266Some @value{GDBN} features may be used in expressions regardless of the
8267language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8268and the @samp{@{type@}addr} construct (@pxref{Expressions,
8269,Expressions}) can be used with the constructs of any supported
8270language.
8271
8272The following sections detail to what degree each source language is
8273supported by @value{GDBN}. These sections are not meant to be language
8274tutorials or references, but serve only as a reference guide to what the
8275@value{GDBN} expression parser accepts, and what input and output
8276formats should look like for different languages. There are many good
8277books written on each of these languages; please look to these for a
8278language reference or tutorial.
8279
c906108c 8280@menu
b37303ee 8281* C:: C and C@t{++}
b383017d 8282* Objective-C:: Objective-C
09d4efe1 8283* Fortran:: Fortran
9c16f35a 8284* Pascal:: Pascal
b37303ee 8285* Modula-2:: Modula-2
e07c999f 8286* Ada:: Ada
c906108c
SS
8287@end menu
8288
6d2ebf8b 8289@node C
b37052ae 8290@subsection C and C@t{++}
7a292a7a 8291
b37052ae
EZ
8292@cindex C and C@t{++}
8293@cindex expressions in C or C@t{++}
c906108c 8294
b37052ae 8295Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8296to both languages. Whenever this is the case, we discuss those languages
8297together.
8298
41afff9a
EZ
8299@cindex C@t{++}
8300@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8301@cindex @sc{gnu} C@t{++}
8302The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8303compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8304effectively, you must compile your C@t{++} programs with a supported
8305C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8306compiler (@code{aCC}).
8307
0179ffac
DC
8308For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8309format; if it doesn't work on your system, try the stabs+ debugging
8310format. You can select those formats explicitly with the @code{g++}
8311command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8312@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8313CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8314
c906108c 8315@menu
b37052ae
EZ
8316* C Operators:: C and C@t{++} operators
8317* C Constants:: C and C@t{++} constants
8318* C plus plus expressions:: C@t{++} expressions
8319* C Defaults:: Default settings for C and C@t{++}
8320* C Checks:: C and C@t{++} type and range checks
c906108c 8321* Debugging C:: @value{GDBN} and C
b37052ae 8322* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8323@end menu
c906108c 8324
6d2ebf8b 8325@node C Operators
b37052ae 8326@subsubsection C and C@t{++} operators
7a292a7a 8327
b37052ae 8328@cindex C and C@t{++} operators
c906108c
SS
8329
8330Operators must be defined on values of specific types. For instance,
8331@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8332often defined on groups of types.
c906108c 8333
b37052ae 8334For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8335
8336@itemize @bullet
53a5351d 8337
c906108c 8338@item
c906108c 8339@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8340specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8341
8342@item
d4f3574e
SS
8343@emph{Floating-point types} include @code{float}, @code{double}, and
8344@code{long double} (if supported by the target platform).
c906108c
SS
8345
8346@item
53a5351d 8347@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8348
8349@item
8350@emph{Scalar types} include all of the above.
53a5351d 8351
c906108c
SS
8352@end itemize
8353
8354@noindent
8355The following operators are supported. They are listed here
8356in order of increasing precedence:
8357
8358@table @code
8359@item ,
8360The comma or sequencing operator. Expressions in a comma-separated list
8361are evaluated from left to right, with the result of the entire
8362expression being the last expression evaluated.
8363
8364@item =
8365Assignment. The value of an assignment expression is the value
8366assigned. Defined on scalar types.
8367
8368@item @var{op}=
8369Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8370and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8371@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8372@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8373@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8374
8375@item ?:
8376The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8377of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8378integral type.
8379
8380@item ||
8381Logical @sc{or}. Defined on integral types.
8382
8383@item &&
8384Logical @sc{and}. Defined on integral types.
8385
8386@item |
8387Bitwise @sc{or}. Defined on integral types.
8388
8389@item ^
8390Bitwise exclusive-@sc{or}. Defined on integral types.
8391
8392@item &
8393Bitwise @sc{and}. Defined on integral types.
8394
8395@item ==@r{, }!=
8396Equality and inequality. Defined on scalar types. The value of these
8397expressions is 0 for false and non-zero for true.
8398
8399@item <@r{, }>@r{, }<=@r{, }>=
8400Less than, greater than, less than or equal, greater than or equal.
8401Defined on scalar types. The value of these expressions is 0 for false
8402and non-zero for true.
8403
8404@item <<@r{, }>>
8405left shift, and right shift. Defined on integral types.
8406
8407@item @@
8408The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8409
8410@item +@r{, }-
8411Addition and subtraction. Defined on integral types, floating-point types and
8412pointer types.
8413
8414@item *@r{, }/@r{, }%
8415Multiplication, division, and modulus. Multiplication and division are
8416defined on integral and floating-point types. Modulus is defined on
8417integral types.
8418
8419@item ++@r{, }--
8420Increment and decrement. When appearing before a variable, the
8421operation is performed before the variable is used in an expression;
8422when appearing after it, the variable's value is used before the
8423operation takes place.
8424
8425@item *
8426Pointer dereferencing. Defined on pointer types. Same precedence as
8427@code{++}.
8428
8429@item &
8430Address operator. Defined on variables. Same precedence as @code{++}.
8431
b37052ae
EZ
8432For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8433allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8434(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8435where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8436stored.
c906108c
SS
8437
8438@item -
8439Negative. Defined on integral and floating-point types. Same
8440precedence as @code{++}.
8441
8442@item !
8443Logical negation. Defined on integral types. Same precedence as
8444@code{++}.
8445
8446@item ~
8447Bitwise complement operator. Defined on integral types. Same precedence as
8448@code{++}.
8449
8450
8451@item .@r{, }->
8452Structure member, and pointer-to-structure member. For convenience,
8453@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8454pointer based on the stored type information.
8455Defined on @code{struct} and @code{union} data.
8456
c906108c
SS
8457@item .*@r{, }->*
8458Dereferences of pointers to members.
c906108c
SS
8459
8460@item []
8461Array indexing. @code{@var{a}[@var{i}]} is defined as
8462@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8463
8464@item ()
8465Function parameter list. Same precedence as @code{->}.
8466
c906108c 8467@item ::
b37052ae 8468C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8469and @code{class} types.
c906108c
SS
8470
8471@item ::
7a292a7a
SS
8472Doubled colons also represent the @value{GDBN} scope operator
8473(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8474above.
c906108c
SS
8475@end table
8476
c906108c
SS
8477If an operator is redefined in the user code, @value{GDBN} usually
8478attempts to invoke the redefined version instead of using the operator's
8479predefined meaning.
c906108c 8480
c906108c 8481@menu
5d161b24 8482* C Constants::
c906108c
SS
8483@end menu
8484
6d2ebf8b 8485@node C Constants
b37052ae 8486@subsubsection C and C@t{++} constants
c906108c 8487
b37052ae 8488@cindex C and C@t{++} constants
c906108c 8489
b37052ae 8490@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8491following ways:
c906108c
SS
8492
8493@itemize @bullet
8494@item
8495Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8496specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8497by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8498@samp{l}, specifying that the constant should be treated as a
8499@code{long} value.
8500
8501@item
8502Floating point constants are a sequence of digits, followed by a decimal
8503point, followed by a sequence of digits, and optionally followed by an
8504exponent. An exponent is of the form:
8505@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8506sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8507A floating-point constant may also end with a letter @samp{f} or
8508@samp{F}, specifying that the constant should be treated as being of
8509the @code{float} (as opposed to the default @code{double}) type; or with
8510a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8511constant.
c906108c
SS
8512
8513@item
8514Enumerated constants consist of enumerated identifiers, or their
8515integral equivalents.
8516
8517@item
8518Character constants are a single character surrounded by single quotes
8519(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8520(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8521be represented by a letter or by @dfn{escape sequences}, which are of
8522the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8523of the character's ordinal value; or of the form @samp{\@var{x}}, where
8524@samp{@var{x}} is a predefined special character---for example,
8525@samp{\n} for newline.
8526
8527@item
96a2c332
SS
8528String constants are a sequence of character constants surrounded by
8529double quotes (@code{"}). Any valid character constant (as described
8530above) may appear. Double quotes within the string must be preceded by
8531a backslash, so for instance @samp{"a\"b'c"} is a string of five
8532characters.
c906108c
SS
8533
8534@item
8535Pointer constants are an integral value. You can also write pointers
8536to constants using the C operator @samp{&}.
8537
8538@item
8539Array constants are comma-separated lists surrounded by braces @samp{@{}
8540and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8541integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8542and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8543@end itemize
8544
c906108c 8545@menu
5d161b24
DB
8546* C plus plus expressions::
8547* C Defaults::
8548* C Checks::
c906108c 8549
5d161b24 8550* Debugging C::
c906108c
SS
8551@end menu
8552
6d2ebf8b 8553@node C plus plus expressions
b37052ae
EZ
8554@subsubsection C@t{++} expressions
8555
8556@cindex expressions in C@t{++}
8557@value{GDBN} expression handling can interpret most C@t{++} expressions.
8558
0179ffac
DC
8559@cindex debugging C@t{++} programs
8560@cindex C@t{++} compilers
8561@cindex debug formats and C@t{++}
8562@cindex @value{NGCC} and C@t{++}
c906108c 8563@quotation
b37052ae 8564@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8565proper compiler and the proper debug format. Currently, @value{GDBN}
8566works best when debugging C@t{++} code that is compiled with
8567@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8568@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8569stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8570stabs+ as their default debug format, so you usually don't need to
8571specify a debug format explicitly. Other compilers and/or debug formats
8572are likely to work badly or not at all when using @value{GDBN} to debug
8573C@t{++} code.
c906108c 8574@end quotation
c906108c
SS
8575
8576@enumerate
8577
8578@cindex member functions
8579@item
8580Member function calls are allowed; you can use expressions like
8581
474c8240 8582@smallexample
c906108c 8583count = aml->GetOriginal(x, y)
474c8240 8584@end smallexample
c906108c 8585
41afff9a 8586@vindex this@r{, inside C@t{++} member functions}
b37052ae 8587@cindex namespace in C@t{++}
c906108c
SS
8588@item
8589While a member function is active (in the selected stack frame), your
8590expressions have the same namespace available as the member function;
8591that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8592pointer @code{this} following the same rules as C@t{++}.
c906108c 8593
c906108c 8594@cindex call overloaded functions
d4f3574e 8595@cindex overloaded functions, calling
b37052ae 8596@cindex type conversions in C@t{++}
c906108c
SS
8597@item
8598You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8599call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8600perform overload resolution involving user-defined type conversions,
8601calls to constructors, or instantiations of templates that do not exist
8602in the program. It also cannot handle ellipsis argument lists or
8603default arguments.
8604
8605It does perform integral conversions and promotions, floating-point
8606promotions, arithmetic conversions, pointer conversions, conversions of
8607class objects to base classes, and standard conversions such as those of
8608functions or arrays to pointers; it requires an exact match on the
8609number of function arguments.
8610
8611Overload resolution is always performed, unless you have specified
8612@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8613,@value{GDBN} features for C@t{++}}.
c906108c 8614
d4f3574e 8615You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8616explicit function signature to call an overloaded function, as in
8617@smallexample
8618p 'foo(char,int)'('x', 13)
8619@end smallexample
d4f3574e 8620
c906108c 8621The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8622see @ref{Completion, ,Command completion}.
c906108c 8623
c906108c
SS
8624@cindex reference declarations
8625@item
b37052ae
EZ
8626@value{GDBN} understands variables declared as C@t{++} references; you can use
8627them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8628dereferenced.
8629
8630In the parameter list shown when @value{GDBN} displays a frame, the values of
8631reference variables are not displayed (unlike other variables); this
8632avoids clutter, since references are often used for large structures.
8633The @emph{address} of a reference variable is always shown, unless
8634you have specified @samp{set print address off}.
8635
8636@item
b37052ae 8637@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8638expressions can use it just as expressions in your program do. Since
8639one scope may be defined in another, you can use @code{::} repeatedly if
8640necessary, for example in an expression like
8641@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8642resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8643debugging (@pxref{Variables, ,Program variables}).
8644@end enumerate
8645
b37052ae 8646In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8647calling virtual functions correctly, printing out virtual bases of
8648objects, calling functions in a base subobject, casting objects, and
8649invoking user-defined operators.
c906108c 8650
6d2ebf8b 8651@node C Defaults
b37052ae 8652@subsubsection C and C@t{++} defaults
7a292a7a 8653
b37052ae 8654@cindex C and C@t{++} defaults
c906108c 8655
c906108c
SS
8656If you allow @value{GDBN} to set type and range checking automatically, they
8657both default to @code{off} whenever the working language changes to
b37052ae 8658C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8659selects the working language.
c906108c
SS
8660
8661If you allow @value{GDBN} to set the language automatically, it
8662recognizes source files whose names end with @file{.c}, @file{.C}, or
8663@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8664these files, it sets the working language to C or C@t{++}.
c906108c
SS
8665@xref{Automatically, ,Having @value{GDBN} infer the source language},
8666for further details.
8667
c906108c
SS
8668@c Type checking is (a) primarily motivated by Modula-2, and (b)
8669@c unimplemented. If (b) changes, it might make sense to let this node
8670@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8671
6d2ebf8b 8672@node C Checks
b37052ae 8673@subsubsection C and C@t{++} type and range checks
7a292a7a 8674
b37052ae 8675@cindex C and C@t{++} checks
c906108c 8676
b37052ae 8677By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8678is not used. However, if you turn type checking on, @value{GDBN}
8679considers two variables type equivalent if:
8680
8681@itemize @bullet
8682@item
8683The two variables are structured and have the same structure, union, or
8684enumerated tag.
8685
8686@item
8687The two variables have the same type name, or types that have been
8688declared equivalent through @code{typedef}.
8689
8690@ignore
8691@c leaving this out because neither J Gilmore nor R Pesch understand it.
8692@c FIXME--beers?
8693@item
8694The two @code{struct}, @code{union}, or @code{enum} variables are
8695declared in the same declaration. (Note: this may not be true for all C
8696compilers.)
8697@end ignore
8698@end itemize
8699
8700Range checking, if turned on, is done on mathematical operations. Array
8701indices are not checked, since they are often used to index a pointer
8702that is not itself an array.
c906108c 8703
6d2ebf8b 8704@node Debugging C
c906108c 8705@subsubsection @value{GDBN} and C
c906108c
SS
8706
8707The @code{set print union} and @code{show print union} commands apply to
8708the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8709inside a @code{struct} or @code{class} is also printed. Otherwise, it
8710appears as @samp{@{...@}}.
c906108c
SS
8711
8712The @code{@@} operator aids in the debugging of dynamic arrays, formed
8713with pointers and a memory allocation function. @xref{Expressions,
8714,Expressions}.
8715
c906108c 8716@menu
5d161b24 8717* Debugging C plus plus::
c906108c
SS
8718@end menu
8719
6d2ebf8b 8720@node Debugging C plus plus
b37052ae 8721@subsubsection @value{GDBN} features for C@t{++}
c906108c 8722
b37052ae 8723@cindex commands for C@t{++}
7a292a7a 8724
b37052ae
EZ
8725Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8726designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8727
8728@table @code
8729@cindex break in overloaded functions
8730@item @r{breakpoint menus}
8731When you want a breakpoint in a function whose name is overloaded,
8732@value{GDBN} breakpoint menus help you specify which function definition
8733you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8734
b37052ae 8735@cindex overloading in C@t{++}
c906108c
SS
8736@item rbreak @var{regex}
8737Setting breakpoints using regular expressions is helpful for setting
8738breakpoints on overloaded functions that are not members of any special
8739classes.
8740@xref{Set Breaks, ,Setting breakpoints}.
8741
b37052ae 8742@cindex C@t{++} exception handling
c906108c
SS
8743@item catch throw
8744@itemx catch catch
b37052ae 8745Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8746Catchpoints, , Setting catchpoints}.
8747
8748@cindex inheritance
8749@item ptype @var{typename}
8750Print inheritance relationships as well as other information for type
8751@var{typename}.
8752@xref{Symbols, ,Examining the Symbol Table}.
8753
b37052ae 8754@cindex C@t{++} symbol display
c906108c
SS
8755@item set print demangle
8756@itemx show print demangle
8757@itemx set print asm-demangle
8758@itemx show print asm-demangle
b37052ae
EZ
8759Control whether C@t{++} symbols display in their source form, both when
8760displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8761@xref{Print Settings, ,Print settings}.
8762
8763@item set print object
8764@itemx show print object
8765Choose whether to print derived (actual) or declared types of objects.
8766@xref{Print Settings, ,Print settings}.
8767
8768@item set print vtbl
8769@itemx show print vtbl
8770Control the format for printing virtual function tables.
8771@xref{Print Settings, ,Print settings}.
c906108c 8772(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8773ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8774
8775@kindex set overload-resolution
d4f3574e 8776@cindex overloaded functions, overload resolution
c906108c 8777@item set overload-resolution on
b37052ae 8778Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8779is on. For overloaded functions, @value{GDBN} evaluates the arguments
8780and searches for a function whose signature matches the argument types,
b37052ae 8781using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8782expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8783message.
8784
8785@item set overload-resolution off
b37052ae 8786Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8787overloaded functions that are not class member functions, @value{GDBN}
8788chooses the first function of the specified name that it finds in the
8789symbol table, whether or not its arguments are of the correct type. For
8790overloaded functions that are class member functions, @value{GDBN}
8791searches for a function whose signature @emph{exactly} matches the
8792argument types.
c906108c 8793
9c16f35a
EZ
8794@kindex show overload-resolution
8795@item show overload-resolution
8796Show the current setting of overload resolution.
8797
c906108c
SS
8798@item @r{Overloaded symbol names}
8799You can specify a particular definition of an overloaded symbol, using
b37052ae 8800the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8801@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8802also use the @value{GDBN} command-line word completion facilities to list the
8803available choices, or to finish the type list for you.
8804@xref{Completion,, Command completion}, for details on how to do this.
8805@end table
c906108c 8806
b37303ee
AF
8807@node Objective-C
8808@subsection Objective-C
8809
8810@cindex Objective-C
8811This section provides information about some commands and command
721c2651
EZ
8812options that are useful for debugging Objective-C code. See also
8813@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8814few more commands specific to Objective-C support.
b37303ee
AF
8815
8816@menu
b383017d
RM
8817* Method Names in Commands::
8818* The Print Command with Objective-C::
b37303ee
AF
8819@end menu
8820
8821@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8822@subsubsection Method Names in Commands
8823
8824The following commands have been extended to accept Objective-C method
8825names as line specifications:
8826
8827@kindex clear@r{, and Objective-C}
8828@kindex break@r{, and Objective-C}
8829@kindex info line@r{, and Objective-C}
8830@kindex jump@r{, and Objective-C}
8831@kindex list@r{, and Objective-C}
8832@itemize
8833@item @code{clear}
8834@item @code{break}
8835@item @code{info line}
8836@item @code{jump}
8837@item @code{list}
8838@end itemize
8839
8840A fully qualified Objective-C method name is specified as
8841
8842@smallexample
8843-[@var{Class} @var{methodName}]
8844@end smallexample
8845
c552b3bb
JM
8846where the minus sign is used to indicate an instance method and a
8847plus sign (not shown) is used to indicate a class method. The class
8848name @var{Class} and method name @var{methodName} are enclosed in
8849brackets, similar to the way messages are specified in Objective-C
8850source code. For example, to set a breakpoint at the @code{create}
8851instance method of class @code{Fruit} in the program currently being
8852debugged, enter:
b37303ee
AF
8853
8854@smallexample
8855break -[Fruit create]
8856@end smallexample
8857
8858To list ten program lines around the @code{initialize} class method,
8859enter:
8860
8861@smallexample
8862list +[NSText initialize]
8863@end smallexample
8864
c552b3bb
JM
8865In the current version of @value{GDBN}, the plus or minus sign is
8866required. In future versions of @value{GDBN}, the plus or minus
8867sign will be optional, but you can use it to narrow the search. It
8868is also possible to specify just a method name:
b37303ee
AF
8869
8870@smallexample
8871break create
8872@end smallexample
8873
8874You must specify the complete method name, including any colons. If
8875your program's source files contain more than one @code{create} method,
8876you'll be presented with a numbered list of classes that implement that
8877method. Indicate your choice by number, or type @samp{0} to exit if
8878none apply.
8879
8880As another example, to clear a breakpoint established at the
8881@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
8882
8883@smallexample
8884clear -[NSWindow makeKeyAndOrderFront:]
8885@end smallexample
8886
8887@node The Print Command with Objective-C
8888@subsubsection The Print Command With Objective-C
721c2651 8889@cindex Objective-C, print objects
c552b3bb
JM
8890@kindex print-object
8891@kindex po @r{(@code{print-object})}
b37303ee 8892
c552b3bb 8893The print command has also been extended to accept methods. For example:
b37303ee
AF
8894
8895@smallexample
c552b3bb 8896print -[@var{object} hash]
b37303ee
AF
8897@end smallexample
8898
8899@cindex print an Objective-C object description
c552b3bb
JM
8900@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
8901@noindent
8902will tell @value{GDBN} to send the @code{hash} message to @var{object}
8903and print the result. Also, an additional command has been added,
8904@code{print-object} or @code{po} for short, which is meant to print
8905the description of an object. However, this command may only work
8906with certain Objective-C libraries that have a particular hook
8907function, @code{_NSPrintForDebugger}, defined.
b37303ee 8908
09d4efe1
EZ
8909@node Fortran
8910@subsection Fortran
8911@cindex Fortran-specific support in @value{GDBN}
8912
8913@table @code
8914@cindex @code{COMMON} blocks, Fortran
8915@kindex info common
8916@item info common @r{[}@var{common-name}@r{]}
8917This command prints the values contained in the Fortran @code{COMMON}
8918block whose name is @var{common-name}. With no argument, the names of
8919all @code{COMMON} blocks visible at current program location are
8920printed.
8921@end table
8922
a8f24a35
EZ
8923Fortran symbols are usually case-insensitive, so @value{GDBN} by
8924default uses case-insensitive matches for Fortran symbols. You can
8925change that with the @samp{set case-insensitive} command, see
8926@ref{Symbols}, for the details.
8927
9c16f35a
EZ
8928@node Pascal
8929@subsection Pascal
8930
8931@cindex Pascal support in @value{GDBN}, limitations
8932Debugging Pascal programs which use sets, subranges, file variables, or
8933nested functions does not currently work. @value{GDBN} does not support
8934entering expressions, printing values, or similar features using Pascal
8935syntax.
8936
8937The Pascal-specific command @code{set print pascal_static-members}
8938controls whether static members of Pascal objects are displayed.
8939@xref{Print Settings, pascal_static-members}.
8940
09d4efe1 8941@node Modula-2
c906108c 8942@subsection Modula-2
7a292a7a 8943
d4f3574e 8944@cindex Modula-2, @value{GDBN} support
c906108c
SS
8945
8946The extensions made to @value{GDBN} to support Modula-2 only support
8947output from the @sc{gnu} Modula-2 compiler (which is currently being
8948developed). Other Modula-2 compilers are not currently supported, and
8949attempting to debug executables produced by them is most likely
8950to give an error as @value{GDBN} reads in the executable's symbol
8951table.
8952
8953@cindex expressions in Modula-2
8954@menu
8955* M2 Operators:: Built-in operators
8956* Built-In Func/Proc:: Built-in functions and procedures
8957* M2 Constants:: Modula-2 constants
8958* M2 Defaults:: Default settings for Modula-2
8959* Deviations:: Deviations from standard Modula-2
8960* M2 Checks:: Modula-2 type and range checks
8961* M2 Scope:: The scope operators @code{::} and @code{.}
8962* GDB/M2:: @value{GDBN} and Modula-2
8963@end menu
8964
6d2ebf8b 8965@node M2 Operators
c906108c
SS
8966@subsubsection Operators
8967@cindex Modula-2 operators
8968
8969Operators must be defined on values of specific types. For instance,
8970@code{+} is defined on numbers, but not on structures. Operators are
8971often defined on groups of types. For the purposes of Modula-2, the
8972following definitions hold:
8973
8974@itemize @bullet
8975
8976@item
8977@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
8978their subranges.
8979
8980@item
8981@emph{Character types} consist of @code{CHAR} and its subranges.
8982
8983@item
8984@emph{Floating-point types} consist of @code{REAL}.
8985
8986@item
8987@emph{Pointer types} consist of anything declared as @code{POINTER TO
8988@var{type}}.
8989
8990@item
8991@emph{Scalar types} consist of all of the above.
8992
8993@item
8994@emph{Set types} consist of @code{SET} and @code{BITSET} types.
8995
8996@item
8997@emph{Boolean types} consist of @code{BOOLEAN}.
8998@end itemize
8999
9000@noindent
9001The following operators are supported, and appear in order of
9002increasing precedence:
9003
9004@table @code
9005@item ,
9006Function argument or array index separator.
9007
9008@item :=
9009Assignment. The value of @var{var} @code{:=} @var{value} is
9010@var{value}.
9011
9012@item <@r{, }>
9013Less than, greater than on integral, floating-point, or enumerated
9014types.
9015
9016@item <=@r{, }>=
96a2c332 9017Less than or equal to, greater than or equal to
c906108c
SS
9018on integral, floating-point and enumerated types, or set inclusion on
9019set types. Same precedence as @code{<}.
9020
9021@item =@r{, }<>@r{, }#
9022Equality and two ways of expressing inequality, valid on scalar types.
9023Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9024available for inequality, since @code{#} conflicts with the script
9025comment character.
9026
9027@item IN
9028Set membership. Defined on set types and the types of their members.
9029Same precedence as @code{<}.
9030
9031@item OR
9032Boolean disjunction. Defined on boolean types.
9033
9034@item AND@r{, }&
d4f3574e 9035Boolean conjunction. Defined on boolean types.
c906108c
SS
9036
9037@item @@
9038The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9039
9040@item +@r{, }-
9041Addition and subtraction on integral and floating-point types, or union
9042and difference on set types.
9043
9044@item *
9045Multiplication on integral and floating-point types, or set intersection
9046on set types.
9047
9048@item /
9049Division on floating-point types, or symmetric set difference on set
9050types. Same precedence as @code{*}.
9051
9052@item DIV@r{, }MOD
9053Integer division and remainder. Defined on integral types. Same
9054precedence as @code{*}.
9055
9056@item -
9057Negative. Defined on @code{INTEGER} and @code{REAL} data.
9058
9059@item ^
9060Pointer dereferencing. Defined on pointer types.
9061
9062@item NOT
9063Boolean negation. Defined on boolean types. Same precedence as
9064@code{^}.
9065
9066@item .
9067@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9068precedence as @code{^}.
9069
9070@item []
9071Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9072
9073@item ()
9074Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9075as @code{^}.
9076
9077@item ::@r{, }.
9078@value{GDBN} and Modula-2 scope operators.
9079@end table
9080
9081@quotation
9082@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9083treats the use of the operator @code{IN}, or the use of operators
9084@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9085@code{<=}, and @code{>=} on sets as an error.
9086@end quotation
9087
cb51c4e0 9088
6d2ebf8b 9089@node Built-In Func/Proc
c906108c 9090@subsubsection Built-in functions and procedures
cb51c4e0 9091@cindex Modula-2 built-ins
c906108c
SS
9092
9093Modula-2 also makes available several built-in procedures and functions.
9094In describing these, the following metavariables are used:
9095
9096@table @var
9097
9098@item a
9099represents an @code{ARRAY} variable.
9100
9101@item c
9102represents a @code{CHAR} constant or variable.
9103
9104@item i
9105represents a variable or constant of integral type.
9106
9107@item m
9108represents an identifier that belongs to a set. Generally used in the
9109same function with the metavariable @var{s}. The type of @var{s} should
9110be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9111
9112@item n
9113represents a variable or constant of integral or floating-point type.
9114
9115@item r
9116represents a variable or constant of floating-point type.
9117
9118@item t
9119represents a type.
9120
9121@item v
9122represents a variable.
9123
9124@item x
9125represents a variable or constant of one of many types. See the
9126explanation of the function for details.
9127@end table
9128
9129All Modula-2 built-in procedures also return a result, described below.
9130
9131@table @code
9132@item ABS(@var{n})
9133Returns the absolute value of @var{n}.
9134
9135@item CAP(@var{c})
9136If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9137equivalent, otherwise it returns its argument.
c906108c
SS
9138
9139@item CHR(@var{i})
9140Returns the character whose ordinal value is @var{i}.
9141
9142@item DEC(@var{v})
c3f6f71d 9143Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9144
9145@item DEC(@var{v},@var{i})
9146Decrements the value in the variable @var{v} by @var{i}. Returns the
9147new value.
9148
9149@item EXCL(@var{m},@var{s})
9150Removes the element @var{m} from the set @var{s}. Returns the new
9151set.
9152
9153@item FLOAT(@var{i})
9154Returns the floating point equivalent of the integer @var{i}.
9155
9156@item HIGH(@var{a})
9157Returns the index of the last member of @var{a}.
9158
9159@item INC(@var{v})
c3f6f71d 9160Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9161
9162@item INC(@var{v},@var{i})
9163Increments the value in the variable @var{v} by @var{i}. Returns the
9164new value.
9165
9166@item INCL(@var{m},@var{s})
9167Adds the element @var{m} to the set @var{s} if it is not already
9168there. Returns the new set.
9169
9170@item MAX(@var{t})
9171Returns the maximum value of the type @var{t}.
9172
9173@item MIN(@var{t})
9174Returns the minimum value of the type @var{t}.
9175
9176@item ODD(@var{i})
9177Returns boolean TRUE if @var{i} is an odd number.
9178
9179@item ORD(@var{x})
9180Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9181value of a character is its @sc{ascii} value (on machines supporting the
9182@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9183integral, character and enumerated types.
9184
9185@item SIZE(@var{x})
9186Returns the size of its argument. @var{x} can be a variable or a type.
9187
9188@item TRUNC(@var{r})
9189Returns the integral part of @var{r}.
9190
9191@item VAL(@var{t},@var{i})
9192Returns the member of the type @var{t} whose ordinal value is @var{i}.
9193@end table
9194
9195@quotation
9196@emph{Warning:} Sets and their operations are not yet supported, so
9197@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9198an error.
9199@end quotation
9200
9201@cindex Modula-2 constants
6d2ebf8b 9202@node M2 Constants
c906108c
SS
9203@subsubsection Constants
9204
9205@value{GDBN} allows you to express the constants of Modula-2 in the following
9206ways:
9207
9208@itemize @bullet
9209
9210@item
9211Integer constants are simply a sequence of digits. When used in an
9212expression, a constant is interpreted to be type-compatible with the
9213rest of the expression. Hexadecimal integers are specified by a
9214trailing @samp{H}, and octal integers by a trailing @samp{B}.
9215
9216@item
9217Floating point constants appear as a sequence of digits, followed by a
9218decimal point and another sequence of digits. An optional exponent can
9219then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9220@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9221digits of the floating point constant must be valid decimal (base 10)
9222digits.
9223
9224@item
9225Character constants consist of a single character enclosed by a pair of
9226like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9227also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9228followed by a @samp{C}.
9229
9230@item
9231String constants consist of a sequence of characters enclosed by a
9232pair of like quotes, either single (@code{'}) or double (@code{"}).
9233Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9234Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9235sequences.
9236
9237@item
9238Enumerated constants consist of an enumerated identifier.
9239
9240@item
9241Boolean constants consist of the identifiers @code{TRUE} and
9242@code{FALSE}.
9243
9244@item
9245Pointer constants consist of integral values only.
9246
9247@item
9248Set constants are not yet supported.
9249@end itemize
9250
6d2ebf8b 9251@node M2 Defaults
c906108c
SS
9252@subsubsection Modula-2 defaults
9253@cindex Modula-2 defaults
9254
9255If type and range checking are set automatically by @value{GDBN}, they
9256both default to @code{on} whenever the working language changes to
d4f3574e 9257Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9258selected the working language.
9259
9260If you allow @value{GDBN} to set the language automatically, then entering
9261code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9262working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9263the language automatically}, for further details.
9264
6d2ebf8b 9265@node Deviations
c906108c
SS
9266@subsubsection Deviations from standard Modula-2
9267@cindex Modula-2, deviations from
9268
9269A few changes have been made to make Modula-2 programs easier to debug.
9270This is done primarily via loosening its type strictness:
9271
9272@itemize @bullet
9273@item
9274Unlike in standard Modula-2, pointer constants can be formed by
9275integers. This allows you to modify pointer variables during
9276debugging. (In standard Modula-2, the actual address contained in a
9277pointer variable is hidden from you; it can only be modified
9278through direct assignment to another pointer variable or expression that
9279returned a pointer.)
9280
9281@item
9282C escape sequences can be used in strings and characters to represent
9283non-printable characters. @value{GDBN} prints out strings with these
9284escape sequences embedded. Single non-printable characters are
9285printed using the @samp{CHR(@var{nnn})} format.
9286
9287@item
9288The assignment operator (@code{:=}) returns the value of its right-hand
9289argument.
9290
9291@item
9292All built-in procedures both modify @emph{and} return their argument.
9293@end itemize
9294
6d2ebf8b 9295@node M2 Checks
c906108c
SS
9296@subsubsection Modula-2 type and range checks
9297@cindex Modula-2 checks
9298
9299@quotation
9300@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9301range checking.
9302@end quotation
9303@c FIXME remove warning when type/range checks added
9304
9305@value{GDBN} considers two Modula-2 variables type equivalent if:
9306
9307@itemize @bullet
9308@item
9309They are of types that have been declared equivalent via a @code{TYPE
9310@var{t1} = @var{t2}} statement
9311
9312@item
9313They have been declared on the same line. (Note: This is true of the
9314@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9315@end itemize
9316
9317As long as type checking is enabled, any attempt to combine variables
9318whose types are not equivalent is an error.
9319
9320Range checking is done on all mathematical operations, assignment, array
9321index bounds, and all built-in functions and procedures.
9322
6d2ebf8b 9323@node M2 Scope
c906108c
SS
9324@subsubsection The scope operators @code{::} and @code{.}
9325@cindex scope
41afff9a 9326@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9327@cindex colon, doubled as scope operator
9328@ifinfo
41afff9a 9329@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9330@c Info cannot handle :: but TeX can.
9331@end ifinfo
9332@iftex
41afff9a 9333@vindex ::@r{, in Modula-2}
c906108c
SS
9334@end iftex
9335
9336There are a few subtle differences between the Modula-2 scope operator
9337(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9338similar syntax:
9339
474c8240 9340@smallexample
c906108c
SS
9341
9342@var{module} . @var{id}
9343@var{scope} :: @var{id}
474c8240 9344@end smallexample
c906108c
SS
9345
9346@noindent
9347where @var{scope} is the name of a module or a procedure,
9348@var{module} the name of a module, and @var{id} is any declared
9349identifier within your program, except another module.
9350
9351Using the @code{::} operator makes @value{GDBN} search the scope
9352specified by @var{scope} for the identifier @var{id}. If it is not
9353found in the specified scope, then @value{GDBN} searches all scopes
9354enclosing the one specified by @var{scope}.
9355
9356Using the @code{.} operator makes @value{GDBN} search the current scope for
9357the identifier specified by @var{id} that was imported from the
9358definition module specified by @var{module}. With this operator, it is
9359an error if the identifier @var{id} was not imported from definition
9360module @var{module}, or if @var{id} is not an identifier in
9361@var{module}.
9362
6d2ebf8b 9363@node GDB/M2
c906108c
SS
9364@subsubsection @value{GDBN} and Modula-2
9365
9366Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9367Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9368specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9369@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9370apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9371analogue in Modula-2.
9372
9373The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9374with any language, is not useful with Modula-2. Its
c906108c 9375intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9376created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9377address can be specified by an integral constant, the construct
d4f3574e 9378@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9379
9380@cindex @code{#} in Modula-2
9381In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9382interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9383
e07c999f
PH
9384@node Ada
9385@subsection Ada
9386@cindex Ada
9387
9388The extensions made to @value{GDBN} for Ada only support
9389output from the @sc{gnu} Ada (GNAT) compiler.
9390Other Ada compilers are not currently supported, and
9391attempting to debug executables produced by them is most likely
9392to be difficult.
9393
9394
9395@cindex expressions in Ada
9396@menu
9397* Ada Mode Intro:: General remarks on the Ada syntax
9398 and semantics supported by Ada mode
9399 in @value{GDBN}.
9400* Omissions from Ada:: Restrictions on the Ada expression syntax.
9401* Additions to Ada:: Extensions of the Ada expression syntax.
9402* Stopping Before Main Program:: Debugging the program during elaboration.
9403* Ada Glitches:: Known peculiarities of Ada mode.
9404@end menu
9405
9406@node Ada Mode Intro
9407@subsubsection Introduction
9408@cindex Ada mode, general
9409
9410The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9411syntax, with some extensions.
9412The philosophy behind the design of this subset is
9413
9414@itemize @bullet
9415@item
9416That @value{GDBN} should provide basic literals and access to operations for
9417arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9418leaving more sophisticated computations to subprograms written into the
9419program (which therefore may be called from @value{GDBN}).
9420
9421@item
9422That type safety and strict adherence to Ada language restrictions
9423are not particularly important to the @value{GDBN} user.
9424
9425@item
9426That brevity is important to the @value{GDBN} user.
9427@end itemize
9428
9429Thus, for brevity, the debugger acts as if there were
9430implicit @code{with} and @code{use} clauses in effect for all user-written
9431packages, making it unnecessary to fully qualify most names with
9432their packages, regardless of context. Where this causes ambiguity,
9433@value{GDBN} asks the user's intent.
9434
9435The debugger will start in Ada mode if it detects an Ada main program.
9436As for other languages, it will enter Ada mode when stopped in a program that
9437was translated from an Ada source file.
9438
9439While in Ada mode, you may use `@t{--}' for comments. This is useful
9440mostly for documenting command files. The standard @value{GDBN} comment
9441(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9442middle (to allow based literals).
9443
9444The debugger supports limited overloading. Given a subprogram call in which
9445the function symbol has multiple definitions, it will use the number of
9446actual parameters and some information about their types to attempt to narrow
9447the set of definitions. It also makes very limited use of context, preferring
9448procedures to functions in the context of the @code{call} command, and
9449functions to procedures elsewhere.
9450
9451@node Omissions from Ada
9452@subsubsection Omissions from Ada
9453@cindex Ada, omissions from
9454
9455Here are the notable omissions from the subset:
9456
9457@itemize @bullet
9458@item
9459Only a subset of the attributes are supported:
9460
9461@itemize @minus
9462@item
9463@t{'First}, @t{'Last}, and @t{'Length}
9464 on array objects (not on types and subtypes).
9465
9466@item
9467@t{'Min} and @t{'Max}.
9468
9469@item
9470@t{'Pos} and @t{'Val}.
9471
9472@item
9473@t{'Tag}.
9474
9475@item
9476@t{'Range} on array objects (not subtypes), but only as the right
9477operand of the membership (@code{in}) operator.
9478
9479@item
9480@t{'Access}, @t{'Unchecked_Access}, and
9481@t{'Unrestricted_Access} (a GNAT extension).
9482
9483@item
9484@t{'Address}.
9485@end itemize
9486
9487@item
9488The names in
9489@code{Characters.Latin_1} are not available and
9490concatenation is not implemented. Thus, escape characters in strings are
9491not currently available.
9492
9493@item
9494Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9495equality of representations. They will generally work correctly
9496for strings and arrays whose elements have integer or enumeration types.
9497They may not work correctly for arrays whose element
9498types have user-defined equality, for arrays of real values
9499(in particular, IEEE-conformant floating point, because of negative
9500zeroes and NaNs), and for arrays whose elements contain unused bits with
9501indeterminate values.
9502
9503@item
9504The other component-by-component array operations (@code{and}, @code{or},
9505@code{xor}, @code{not}, and relational tests other than equality)
9506are not implemented.
9507
9508@item
9509There are no record or array aggregates.
9510
9511@item
9512Calls to dispatching subprograms are not implemented.
9513
9514@item
9515The overloading algorithm is much more limited (i.e., less selective)
9516than that of real Ada. It makes only limited use of the context in which a subexpression
9517appears to resolve its meaning, and it is much looser in its rules for allowing
9518type matches. As a result, some function calls will be ambiguous, and the user
9519will be asked to choose the proper resolution.
9520
9521@item
9522The @code{new} operator is not implemented.
9523
9524@item
9525Entry calls are not implemented.
9526
9527@item
9528Aside from printing, arithmetic operations on the native VAX floating-point
9529formats are not supported.
9530
9531@item
9532It is not possible to slice a packed array.
9533@end itemize
9534
9535@node Additions to Ada
9536@subsubsection Additions to Ada
9537@cindex Ada, deviations from
9538
9539As it does for other languages, @value{GDBN} makes certain generic
9540extensions to Ada (@pxref{Expressions}):
9541
9542@itemize @bullet
9543@item
9544If the expression @var{E} is a variable residing in memory
9545(typically a local variable or array element) and @var{N} is
9546a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9547@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9548In Ada, this operator is generally not necessary, since its prime use
9549is in displaying parts of an array, and slicing will usually do this in Ada.
9550However, there are occasional uses when debugging programs
9551in which certain debugging information has been optimized away.
9552
9553@item
9554@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9555in function or file @var{B}.'' When @var{B} is a file name, you must typically
9556surround it in single quotes.
9557
9558@item
9559The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9560@var{type} that appears at address @var{addr}.''
9561
9562@item
9563A name starting with @samp{$} is a convenience variable
9564(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9565@end itemize
9566
9567In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9568to Ada:
9569
9570@itemize @bullet
9571@item
9572The assignment statement is allowed as an expression, returning
9573its right-hand operand as its value. Thus, you may enter
9574
9575@smallexample
9576set x := y + 3
9577print A(tmp := y + 1)
9578@end smallexample
9579
9580@item
9581The semicolon is allowed as an ``operator,'' returning as its value
9582the value of its right-hand operand.
9583This allows, for example,
9584complex conditional breaks:
9585
9586@smallexample
9587break f
9588condition 1 (report(i); k += 1; A(k) > 100)
9589@end smallexample
9590
9591@item
9592Rather than use catenation and symbolic character names to introduce special
9593characters into strings, one may instead use a special bracket notation,
9594which is also used to print strings. A sequence of characters of the form
9595@samp{["@var{XX}"]} within a string or character literal denotes the
9596(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9597sequence of characters @samp{["""]} also denotes a single quotation mark
9598in strings. For example,
9599@smallexample
9600 "One line.["0a"]Next line.["0a"]"
9601@end smallexample
9602@noindent
9603contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9604period.
9605
9606@item
9607The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9608@t{'Max} is optional (and is ignored in any case). For example, it is valid
9609to write
9610
9611@smallexample
9612print 'max(x, y)
9613@end smallexample
9614
9615@item
9616When printing arrays, @value{GDBN} uses positional notation when the
9617array has a lower bound of 1, and uses a modified named notation otherwise.
9618For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9619
9620@smallexample
9621(3 => 10, 17, 1)
9622@end smallexample
9623
9624@noindent
9625That is, in contrast to valid Ada, only the first component has a @code{=>}
9626clause.
9627
9628@item
9629You may abbreviate attributes in expressions with any unique,
9630multi-character subsequence of
9631their names (an exact match gets preference).
9632For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9633in place of @t{a'length}.
9634
9635@item
9636@cindex quoting Ada internal identifiers
9637Since Ada is case-insensitive, the debugger normally maps identifiers you type
9638to lower case. The GNAT compiler uses upper-case characters for
9639some of its internal identifiers, which are normally of no interest to users.
9640For the rare occasions when you actually have to look at them,
9641enclose them in angle brackets to avoid the lower-case mapping.
9642For example,
9643@smallexample
9644@value{GDBP} print <JMPBUF_SAVE>[0]
9645@end smallexample
9646
9647@item
9648Printing an object of class-wide type or dereferencing an
9649access-to-class-wide value will display all the components of the object's
9650specific type (as indicated by its run-time tag). Likewise, component
9651selection on such a value will operate on the specific type of the
9652object.
9653
9654@end itemize
9655
9656@node Stopping Before Main Program
9657@subsubsection Stopping at the Very Beginning
9658
9659@cindex breakpointing Ada elaboration code
9660It is sometimes necessary to debug the program during elaboration, and
9661before reaching the main procedure.
9662As defined in the Ada Reference
9663Manual, the elaboration code is invoked from a procedure called
9664@code{adainit}. To run your program up to the beginning of
9665elaboration, simply use the following two commands:
9666@code{tbreak adainit} and @code{run}.
9667
9668@node Ada Glitches
9669@subsubsection Known Peculiarities of Ada Mode
9670@cindex Ada, problems
9671
9672Besides the omissions listed previously (@pxref{Omissions from Ada}),
9673we know of several problems with and limitations of Ada mode in
9674@value{GDBN},
9675some of which will be fixed with planned future releases of the debugger
9676and the GNU Ada compiler.
9677
9678@itemize @bullet
9679@item
9680Currently, the debugger
9681has insufficient information to determine whether certain pointers represent
9682pointers to objects or the objects themselves.
9683Thus, the user may have to tack an extra @code{.all} after an expression
9684to get it printed properly.
9685
9686@item
9687Static constants that the compiler chooses not to materialize as objects in
9688storage are invisible to the debugger.
9689
9690@item
9691Named parameter associations in function argument lists are ignored (the
9692argument lists are treated as positional).
9693
9694@item
9695Many useful library packages are currently invisible to the debugger.
9696
9697@item
9698Fixed-point arithmetic, conversions, input, and output is carried out using
9699floating-point arithmetic, and may give results that only approximate those on
9700the host machine.
9701
9702@item
9703The type of the @t{'Address} attribute may not be @code{System.Address}.
9704
9705@item
9706The GNAT compiler never generates the prefix @code{Standard} for any of
9707the standard symbols defined by the Ada language. @value{GDBN} knows about
9708this: it will strip the prefix from names when you use it, and will never
9709look for a name you have so qualified among local symbols, nor match against
9710symbols in other packages or subprograms. If you have
9711defined entities anywhere in your program other than parameters and
9712local variables whose simple names match names in @code{Standard},
9713GNAT's lack of qualification here can cause confusion. When this happens,
9714you can usually resolve the confusion
9715by qualifying the problematic names with package
9716@code{Standard} explicitly.
9717@end itemize
9718
4e562065
JB
9719@node Unsupported languages
9720@section Unsupported languages
9721
9722@cindex unsupported languages
9723@cindex minimal language
9724In addition to the other fully-supported programming languages,
9725@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9726It does not represent a real programming language, but provides a set
9727of capabilities close to what the C or assembly languages provide.
9728This should allow most simple operations to be performed while debugging
9729an application that uses a language currently not supported by @value{GDBN}.
9730
9731If the language is set to @code{auto}, @value{GDBN} will automatically
9732select this language if the current frame corresponds to an unsupported
9733language.
9734
6d2ebf8b 9735@node Symbols
c906108c
SS
9736@chapter Examining the Symbol Table
9737
d4f3574e 9738The commands described in this chapter allow you to inquire about the
c906108c
SS
9739symbols (names of variables, functions and types) defined in your
9740program. This information is inherent in the text of your program and
9741does not change as your program executes. @value{GDBN} finds it in your
9742program's symbol table, in the file indicated when you started @value{GDBN}
9743(@pxref{File Options, ,Choosing files}), or by one of the
9744file-management commands (@pxref{Files, ,Commands to specify files}).
9745
9746@cindex symbol names
9747@cindex names of symbols
9748@cindex quoting names
9749Occasionally, you may need to refer to symbols that contain unusual
9750characters, which @value{GDBN} ordinarily treats as word delimiters. The
9751most frequent case is in referring to static variables in other
9752source files (@pxref{Variables,,Program variables}). File names
9753are recorded in object files as debugging symbols, but @value{GDBN} would
9754ordinarily parse a typical file name, like @file{foo.c}, as the three words
9755@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9756@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9757
474c8240 9758@smallexample
c906108c 9759p 'foo.c'::x
474c8240 9760@end smallexample
c906108c
SS
9761
9762@noindent
9763looks up the value of @code{x} in the scope of the file @file{foo.c}.
9764
9765@table @code
a8f24a35
EZ
9766@cindex case-insensitive symbol names
9767@cindex case sensitivity in symbol names
9768@kindex set case-sensitive
9769@item set case-sensitive on
9770@itemx set case-sensitive off
9771@itemx set case-sensitive auto
9772Normally, when @value{GDBN} looks up symbols, it matches their names
9773with case sensitivity determined by the current source language.
9774Occasionally, you may wish to control that. The command @code{set
9775case-sensitive} lets you do that by specifying @code{on} for
9776case-sensitive matches or @code{off} for case-insensitive ones. If
9777you specify @code{auto}, case sensitivity is reset to the default
9778suitable for the source language. The default is case-sensitive
9779matches for all languages except for Fortran, for which the default is
9780case-insensitive matches.
9781
9c16f35a
EZ
9782@kindex show case-sensitive
9783@item show case-sensitive
a8f24a35
EZ
9784This command shows the current setting of case sensitivity for symbols
9785lookups.
9786
c906108c 9787@kindex info address
b37052ae 9788@cindex address of a symbol
c906108c
SS
9789@item info address @var{symbol}
9790Describe where the data for @var{symbol} is stored. For a register
9791variable, this says which register it is kept in. For a non-register
9792local variable, this prints the stack-frame offset at which the variable
9793is always stored.
9794
9795Note the contrast with @samp{print &@var{symbol}}, which does not work
9796at all for a register variable, and for a stack local variable prints
9797the exact address of the current instantiation of the variable.
9798
3d67e040 9799@kindex info symbol
b37052ae 9800@cindex symbol from address
9c16f35a 9801@cindex closest symbol and offset for an address
3d67e040
EZ
9802@item info symbol @var{addr}
9803Print the name of a symbol which is stored at the address @var{addr}.
9804If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9805nearest symbol and an offset from it:
9806
474c8240 9807@smallexample
3d67e040
EZ
9808(@value{GDBP}) info symbol 0x54320
9809_initialize_vx + 396 in section .text
474c8240 9810@end smallexample
3d67e040
EZ
9811
9812@noindent
9813This is the opposite of the @code{info address} command. You can use
9814it to find out the name of a variable or a function given its address.
9815
c906108c 9816@kindex whatis
d4f3574e
SS
9817@item whatis @var{expr}
9818Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9819actually evaluated, and any side-effecting operations (such as
9820assignments or function calls) inside it do not take place.
9821@xref{Expressions, ,Expressions}.
9822
9823@item whatis
9824Print the data type of @code{$}, the last value in the value history.
9825
9826@kindex ptype
9827@item ptype @var{typename}
9828Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9829the name of a type, or for C code it may have the form @samp{class
9830@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9831@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9832
d4f3574e 9833@item ptype @var{expr}
c906108c 9834@itemx ptype
d4f3574e 9835Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9836differs from @code{whatis} by printing a detailed description, instead
9837of just the name of the type.
9838
9839For example, for this variable declaration:
9840
474c8240 9841@smallexample
c906108c 9842struct complex @{double real; double imag;@} v;
474c8240 9843@end smallexample
c906108c
SS
9844
9845@noindent
9846the two commands give this output:
9847
474c8240 9848@smallexample
c906108c
SS
9849@group
9850(@value{GDBP}) whatis v
9851type = struct complex
9852(@value{GDBP}) ptype v
9853type = struct complex @{
9854 double real;
9855 double imag;
9856@}
9857@end group
474c8240 9858@end smallexample
c906108c
SS
9859
9860@noindent
9861As with @code{whatis}, using @code{ptype} without an argument refers to
9862the type of @code{$}, the last value in the value history.
9863
9864@kindex info types
9865@item info types @var{regexp}
9866@itemx info types
09d4efe1
EZ
9867Print a brief description of all types whose names match the regular
9868expression @var{regexp} (or all types in your program, if you supply
9869no argument). Each complete typename is matched as though it were a
9870complete line; thus, @samp{i type value} gives information on all
9871types in your program whose names include the string @code{value}, but
9872@samp{i type ^value$} gives information only on types whose complete
9873name is @code{value}.
c906108c
SS
9874
9875This command differs from @code{ptype} in two ways: first, like
9876@code{whatis}, it does not print a detailed description; second, it
9877lists all source files where a type is defined.
9878
b37052ae
EZ
9879@kindex info scope
9880@cindex local variables
09d4efe1 9881@item info scope @var{location}
b37052ae 9882List all the variables local to a particular scope. This command
09d4efe1
EZ
9883accepts a @var{location} argument---a function name, a source line, or
9884an address preceded by a @samp{*}, and prints all the variables local
9885to the scope defined by that location. For example:
b37052ae
EZ
9886
9887@smallexample
9888(@value{GDBP}) @b{info scope command_line_handler}
9889Scope for command_line_handler:
9890Symbol rl is an argument at stack/frame offset 8, length 4.
9891Symbol linebuffer is in static storage at address 0x150a18, length 4.
9892Symbol linelength is in static storage at address 0x150a1c, length 4.
9893Symbol p is a local variable in register $esi, length 4.
9894Symbol p1 is a local variable in register $ebx, length 4.
9895Symbol nline is a local variable in register $edx, length 4.
9896Symbol repeat is a local variable at frame offset -8, length 4.
9897@end smallexample
9898
f5c37c66
EZ
9899@noindent
9900This command is especially useful for determining what data to collect
9901during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
9902collect}.
9903
c906108c
SS
9904@kindex info source
9905@item info source
919d772c
JB
9906Show information about the current source file---that is, the source file for
9907the function containing the current point of execution:
9908@itemize @bullet
9909@item
9910the name of the source file, and the directory containing it,
9911@item
9912the directory it was compiled in,
9913@item
9914its length, in lines,
9915@item
9916which programming language it is written in,
9917@item
9918whether the executable includes debugging information for that file, and
9919if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
9920@item
9921whether the debugging information includes information about
9922preprocessor macros.
9923@end itemize
9924
c906108c
SS
9925
9926@kindex info sources
9927@item info sources
9928Print the names of all source files in your program for which there is
9929debugging information, organized into two lists: files whose symbols
9930have already been read, and files whose symbols will be read when needed.
9931
9932@kindex info functions
9933@item info functions
9934Print the names and data types of all defined functions.
9935
9936@item info functions @var{regexp}
9937Print the names and data types of all defined functions
9938whose names contain a match for regular expression @var{regexp}.
9939Thus, @samp{info fun step} finds all functions whose names
9940include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
9941start with @code{step}. If a function name contains characters
9942that conflict with the regular expression language (eg.
1c5dfdad 9943@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
9944
9945@kindex info variables
9946@item info variables
9947Print the names and data types of all variables that are declared
6ca652b0 9948outside of functions (i.e.@: excluding local variables).
c906108c
SS
9949
9950@item info variables @var{regexp}
9951Print the names and data types of all variables (except for local
9952variables) whose names contain a match for regular expression
9953@var{regexp}.
9954
b37303ee 9955@kindex info classes
721c2651 9956@cindex Objective-C, classes and selectors
b37303ee
AF
9957@item info classes
9958@itemx info classes @var{regexp}
9959Display all Objective-C classes in your program, or
9960(with the @var{regexp} argument) all those matching a particular regular
9961expression.
9962
9963@kindex info selectors
9964@item info selectors
9965@itemx info selectors @var{regexp}
9966Display all Objective-C selectors in your program, or
9967(with the @var{regexp} argument) all those matching a particular regular
9968expression.
9969
c906108c
SS
9970@ignore
9971This was never implemented.
9972@kindex info methods
9973@item info methods
9974@itemx info methods @var{regexp}
9975The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
9976methods within C@t{++} program, or (with the @var{regexp} argument) a
9977specific set of methods found in the various C@t{++} classes. Many
9978C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
9979from the @code{ptype} command can be overwhelming and hard to use. The
9980@code{info-methods} command filters the methods, printing only those
9981which match the regular-expression @var{regexp}.
9982@end ignore
9983
c906108c
SS
9984@cindex reloading symbols
9985Some systems allow individual object files that make up your program to
7a292a7a
SS
9986be replaced without stopping and restarting your program. For example,
9987in VxWorks you can simply recompile a defective object file and keep on
9988running. If you are running on one of these systems, you can allow
9989@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
9990
9991@table @code
9992@kindex set symbol-reloading
9993@item set symbol-reloading on
9994Replace symbol definitions for the corresponding source file when an
9995object file with a particular name is seen again.
9996
9997@item set symbol-reloading off
6d2ebf8b
SS
9998Do not replace symbol definitions when encountering object files of the
9999same name more than once. This is the default state; if you are not
10000running on a system that permits automatic relinking of modules, you
10001should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10002may discard symbols when linking large programs, that may contain
10003several modules (from different directories or libraries) with the same
10004name.
c906108c
SS
10005
10006@kindex show symbol-reloading
10007@item show symbol-reloading
10008Show the current @code{on} or @code{off} setting.
10009@end table
c906108c 10010
9c16f35a 10011@cindex opaque data types
c906108c
SS
10012@kindex set opaque-type-resolution
10013@item set opaque-type-resolution on
10014Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10015declared as a pointer to a @code{struct}, @code{class}, or
10016@code{union}---for example, @code{struct MyType *}---that is used in one
10017source file although the full declaration of @code{struct MyType} is in
10018another source file. The default is on.
10019
10020A change in the setting of this subcommand will not take effect until
10021the next time symbols for a file are loaded.
10022
10023@item set opaque-type-resolution off
10024Tell @value{GDBN} not to resolve opaque types. In this case, the type
10025is printed as follows:
10026@smallexample
10027@{<no data fields>@}
10028@end smallexample
10029
10030@kindex show opaque-type-resolution
10031@item show opaque-type-resolution
10032Show whether opaque types are resolved or not.
c906108c
SS
10033
10034@kindex maint print symbols
10035@cindex symbol dump
10036@kindex maint print psymbols
10037@cindex partial symbol dump
10038@item maint print symbols @var{filename}
10039@itemx maint print psymbols @var{filename}
10040@itemx maint print msymbols @var{filename}
10041Write a dump of debugging symbol data into the file @var{filename}.
10042These commands are used to debug the @value{GDBN} symbol-reading code. Only
10043symbols with debugging data are included. If you use @samp{maint print
10044symbols}, @value{GDBN} includes all the symbols for which it has already
10045collected full details: that is, @var{filename} reflects symbols for
10046only those files whose symbols @value{GDBN} has read. You can use the
10047command @code{info sources} to find out which files these are. If you
10048use @samp{maint print psymbols} instead, the dump shows information about
10049symbols that @value{GDBN} only knows partially---that is, symbols defined in
10050files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10051@samp{maint print msymbols} dumps just the minimal symbol information
10052required for each object file from which @value{GDBN} has read some symbols.
10053@xref{Files, ,Commands to specify files}, for a discussion of how
10054@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10055
5e7b2f39
JB
10056@kindex maint info symtabs
10057@kindex maint info psymtabs
44ea7b70
JB
10058@cindex listing @value{GDBN}'s internal symbol tables
10059@cindex symbol tables, listing @value{GDBN}'s internal
10060@cindex full symbol tables, listing @value{GDBN}'s internal
10061@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10062@item maint info symtabs @r{[} @var{regexp} @r{]}
10063@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10064
10065List the @code{struct symtab} or @code{struct partial_symtab}
10066structures whose names match @var{regexp}. If @var{regexp} is not
10067given, list them all. The output includes expressions which you can
10068copy into a @value{GDBN} debugging this one to examine a particular
10069structure in more detail. For example:
10070
10071@smallexample
5e7b2f39 10072(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10073@{ objfile /home/gnu/build/gdb/gdb
10074 ((struct objfile *) 0x82e69d0)
b383017d 10075 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10076 ((struct partial_symtab *) 0x8474b10)
10077 readin no
10078 fullname (null)
10079 text addresses 0x814d3c8 -- 0x8158074
10080 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10081 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10082 dependencies (none)
10083 @}
10084@}
5e7b2f39 10085(@value{GDBP}) maint info symtabs
44ea7b70
JB
10086(@value{GDBP})
10087@end smallexample
10088@noindent
10089We see that there is one partial symbol table whose filename contains
10090the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10091and we see that @value{GDBN} has not read in any symtabs yet at all.
10092If we set a breakpoint on a function, that will cause @value{GDBN} to
10093read the symtab for the compilation unit containing that function:
10094
10095@smallexample
10096(@value{GDBP}) break dwarf2_psymtab_to_symtab
10097Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10098line 1574.
5e7b2f39 10099(@value{GDBP}) maint info symtabs
b383017d 10100@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10101 ((struct objfile *) 0x82e69d0)
b383017d 10102 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10103 ((struct symtab *) 0x86c1f38)
10104 dirname (null)
10105 fullname (null)
10106 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10107 debugformat DWARF 2
10108 @}
10109@}
b383017d 10110(@value{GDBP})
44ea7b70 10111@end smallexample
c906108c
SS
10112@end table
10113
44ea7b70 10114
6d2ebf8b 10115@node Altering
c906108c
SS
10116@chapter Altering Execution
10117
10118Once you think you have found an error in your program, you might want to
10119find out for certain whether correcting the apparent error would lead to
10120correct results in the rest of the run. You can find the answer by
10121experiment, using the @value{GDBN} features for altering execution of the
10122program.
10123
10124For example, you can store new values into variables or memory
7a292a7a
SS
10125locations, give your program a signal, restart it at a different
10126address, or even return prematurely from a function.
c906108c
SS
10127
10128@menu
10129* Assignment:: Assignment to variables
10130* Jumping:: Continuing at a different address
c906108c 10131* Signaling:: Giving your program a signal
c906108c
SS
10132* Returning:: Returning from a function
10133* Calling:: Calling your program's functions
10134* Patching:: Patching your program
10135@end menu
10136
6d2ebf8b 10137@node Assignment
c906108c
SS
10138@section Assignment to variables
10139
10140@cindex assignment
10141@cindex setting variables
10142To alter the value of a variable, evaluate an assignment expression.
10143@xref{Expressions, ,Expressions}. For example,
10144
474c8240 10145@smallexample
c906108c 10146print x=4
474c8240 10147@end smallexample
c906108c
SS
10148
10149@noindent
10150stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10151value of the assignment expression (which is 4).
c906108c
SS
10152@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10153information on operators in supported languages.
c906108c
SS
10154
10155@kindex set variable
10156@cindex variables, setting
10157If you are not interested in seeing the value of the assignment, use the
10158@code{set} command instead of the @code{print} command. @code{set} is
10159really the same as @code{print} except that the expression's value is
10160not printed and is not put in the value history (@pxref{Value History,
10161,Value history}). The expression is evaluated only for its effects.
10162
c906108c
SS
10163If the beginning of the argument string of the @code{set} command
10164appears identical to a @code{set} subcommand, use the @code{set
10165variable} command instead of just @code{set}. This command is identical
10166to @code{set} except for its lack of subcommands. For example, if your
10167program has a variable @code{width}, you get an error if you try to set
10168a new value with just @samp{set width=13}, because @value{GDBN} has the
10169command @code{set width}:
10170
474c8240 10171@smallexample
c906108c
SS
10172(@value{GDBP}) whatis width
10173type = double
10174(@value{GDBP}) p width
10175$4 = 13
10176(@value{GDBP}) set width=47
10177Invalid syntax in expression.
474c8240 10178@end smallexample
c906108c
SS
10179
10180@noindent
10181The invalid expression, of course, is @samp{=47}. In
10182order to actually set the program's variable @code{width}, use
10183
474c8240 10184@smallexample
c906108c 10185(@value{GDBP}) set var width=47
474c8240 10186@end smallexample
53a5351d 10187
c906108c
SS
10188Because the @code{set} command has many subcommands that can conflict
10189with the names of program variables, it is a good idea to use the
10190@code{set variable} command instead of just @code{set}. For example, if
10191your program has a variable @code{g}, you run into problems if you try
10192to set a new value with just @samp{set g=4}, because @value{GDBN} has
10193the command @code{set gnutarget}, abbreviated @code{set g}:
10194
474c8240 10195@smallexample
c906108c
SS
10196@group
10197(@value{GDBP}) whatis g
10198type = double
10199(@value{GDBP}) p g
10200$1 = 1
10201(@value{GDBP}) set g=4
2df3850c 10202(@value{GDBP}) p g
c906108c
SS
10203$2 = 1
10204(@value{GDBP}) r
10205The program being debugged has been started already.
10206Start it from the beginning? (y or n) y
10207Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10208"/home/smith/cc_progs/a.out": can't open to read symbols:
10209 Invalid bfd target.
c906108c
SS
10210(@value{GDBP}) show g
10211The current BFD target is "=4".
10212@end group
474c8240 10213@end smallexample
c906108c
SS
10214
10215@noindent
10216The program variable @code{g} did not change, and you silently set the
10217@code{gnutarget} to an invalid value. In order to set the variable
10218@code{g}, use
10219
474c8240 10220@smallexample
c906108c 10221(@value{GDBP}) set var g=4
474c8240 10222@end smallexample
c906108c
SS
10223
10224@value{GDBN} allows more implicit conversions in assignments than C; you can
10225freely store an integer value into a pointer variable or vice versa,
10226and you can convert any structure to any other structure that is the
10227same length or shorter.
10228@comment FIXME: how do structs align/pad in these conversions?
10229@comment /doc@cygnus.com 18dec1990
10230
10231To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10232construct to generate a value of specified type at a specified address
10233(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10234to memory location @code{0x83040} as an integer (which implies a certain size
10235and representation in memory), and
10236
474c8240 10237@smallexample
c906108c 10238set @{int@}0x83040 = 4
474c8240 10239@end smallexample
c906108c
SS
10240
10241@noindent
10242stores the value 4 into that memory location.
10243
6d2ebf8b 10244@node Jumping
c906108c
SS
10245@section Continuing at a different address
10246
10247Ordinarily, when you continue your program, you do so at the place where
10248it stopped, with the @code{continue} command. You can instead continue at
10249an address of your own choosing, with the following commands:
10250
10251@table @code
10252@kindex jump
10253@item jump @var{linespec}
10254Resume execution at line @var{linespec}. Execution stops again
10255immediately if there is a breakpoint there. @xref{List, ,Printing
10256source lines}, for a description of the different forms of
10257@var{linespec}. It is common practice to use the @code{tbreak} command
10258in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10259breakpoints}.
10260
10261The @code{jump} command does not change the current stack frame, or
10262the stack pointer, or the contents of any memory location or any
10263register other than the program counter. If line @var{linespec} is in
10264a different function from the one currently executing, the results may
10265be bizarre if the two functions expect different patterns of arguments or
10266of local variables. For this reason, the @code{jump} command requests
10267confirmation if the specified line is not in the function currently
10268executing. However, even bizarre results are predictable if you are
10269well acquainted with the machine-language code of your program.
10270
10271@item jump *@var{address}
10272Resume execution at the instruction at address @var{address}.
10273@end table
10274
c906108c 10275@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10276On many systems, you can get much the same effect as the @code{jump}
10277command by storing a new value into the register @code{$pc}. The
10278difference is that this does not start your program running; it only
10279changes the address of where it @emph{will} run when you continue. For
10280example,
c906108c 10281
474c8240 10282@smallexample
c906108c 10283set $pc = 0x485
474c8240 10284@end smallexample
c906108c
SS
10285
10286@noindent
10287makes the next @code{continue} command or stepping command execute at
10288address @code{0x485}, rather than at the address where your program stopped.
10289@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10290
10291The most common occasion to use the @code{jump} command is to back
10292up---perhaps with more breakpoints set---over a portion of a program
10293that has already executed, in order to examine its execution in more
10294detail.
10295
c906108c 10296@c @group
6d2ebf8b 10297@node Signaling
c906108c 10298@section Giving your program a signal
9c16f35a 10299@cindex deliver a signal to a program
c906108c
SS
10300
10301@table @code
10302@kindex signal
10303@item signal @var{signal}
10304Resume execution where your program stopped, but immediately give it the
10305signal @var{signal}. @var{signal} can be the name or the number of a
10306signal. For example, on many systems @code{signal 2} and @code{signal
10307SIGINT} are both ways of sending an interrupt signal.
10308
10309Alternatively, if @var{signal} is zero, continue execution without
10310giving a signal. This is useful when your program stopped on account of
10311a signal and would ordinary see the signal when resumed with the
10312@code{continue} command; @samp{signal 0} causes it to resume without a
10313signal.
10314
10315@code{signal} does not repeat when you press @key{RET} a second time
10316after executing the command.
10317@end table
10318@c @end group
10319
10320Invoking the @code{signal} command is not the same as invoking the
10321@code{kill} utility from the shell. Sending a signal with @code{kill}
10322causes @value{GDBN} to decide what to do with the signal depending on
10323the signal handling tables (@pxref{Signals}). The @code{signal} command
10324passes the signal directly to your program.
10325
c906108c 10326
6d2ebf8b 10327@node Returning
c906108c
SS
10328@section Returning from a function
10329
10330@table @code
10331@cindex returning from a function
10332@kindex return
10333@item return
10334@itemx return @var{expression}
10335You can cancel execution of a function call with the @code{return}
10336command. If you give an
10337@var{expression} argument, its value is used as the function's return
10338value.
10339@end table
10340
10341When you use @code{return}, @value{GDBN} discards the selected stack frame
10342(and all frames within it). You can think of this as making the
10343discarded frame return prematurely. If you wish to specify a value to
10344be returned, give that value as the argument to @code{return}.
10345
10346This pops the selected stack frame (@pxref{Selection, ,Selecting a
10347frame}), and any other frames inside of it, leaving its caller as the
10348innermost remaining frame. That frame becomes selected. The
10349specified value is stored in the registers used for returning values
10350of functions.
10351
10352The @code{return} command does not resume execution; it leaves the
10353program stopped in the state that would exist if the function had just
10354returned. In contrast, the @code{finish} command (@pxref{Continuing
10355and Stepping, ,Continuing and stepping}) resumes execution until the
10356selected stack frame returns naturally.
10357
6d2ebf8b 10358@node Calling
c906108c
SS
10359@section Calling program functions
10360
f8568604 10361@table @code
c906108c 10362@cindex calling functions
f8568604
EZ
10363@cindex inferior functions, calling
10364@item print @var{expr}
9c16f35a 10365Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10366@var{expr} may include calls to functions in the program being
10367debugged.
10368
c906108c 10369@kindex call
c906108c
SS
10370@item call @var{expr}
10371Evaluate the expression @var{expr} without displaying @code{void}
10372returned values.
c906108c
SS
10373
10374You can use this variant of the @code{print} command if you want to
f8568604
EZ
10375execute a function from your program that does not return anything
10376(a.k.a.@: @dfn{a void function}), but without cluttering the output
10377with @code{void} returned values that @value{GDBN} will otherwise
10378print. If the result is not void, it is printed and saved in the
10379value history.
10380@end table
10381
9c16f35a
EZ
10382It is possible for the function you call via the @code{print} or
10383@code{call} command to generate a signal (e.g., if there's a bug in
10384the function, or if you passed it incorrect arguments). What happens
10385in that case is controlled by the @code{set unwindonsignal} command.
10386
10387@table @code
10388@item set unwindonsignal
10389@kindex set unwindonsignal
10390@cindex unwind stack in called functions
10391@cindex call dummy stack unwinding
10392Set unwinding of the stack if a signal is received while in a function
10393that @value{GDBN} called in the program being debugged. If set to on,
10394@value{GDBN} unwinds the stack it created for the call and restores
10395the context to what it was before the call. If set to off (the
10396default), @value{GDBN} stops in the frame where the signal was
10397received.
10398
10399@item show unwindonsignal
10400@kindex show unwindonsignal
10401Show the current setting of stack unwinding in the functions called by
10402@value{GDBN}.
10403@end table
10404
f8568604
EZ
10405@cindex weak alias functions
10406Sometimes, a function you wish to call is actually a @dfn{weak alias}
10407for another function. In such case, @value{GDBN} might not pick up
10408the type information, including the types of the function arguments,
10409which causes @value{GDBN} to call the inferior function incorrectly.
10410As a result, the called function will function erroneously and may
10411even crash. A solution to that is to use the name of the aliased
10412function instead.
c906108c 10413
6d2ebf8b 10414@node Patching
c906108c 10415@section Patching programs
7a292a7a 10416
c906108c
SS
10417@cindex patching binaries
10418@cindex writing into executables
c906108c 10419@cindex writing into corefiles
c906108c 10420
7a292a7a
SS
10421By default, @value{GDBN} opens the file containing your program's
10422executable code (or the corefile) read-only. This prevents accidental
10423alterations to machine code; but it also prevents you from intentionally
10424patching your program's binary.
c906108c
SS
10425
10426If you'd like to be able to patch the binary, you can specify that
10427explicitly with the @code{set write} command. For example, you might
10428want to turn on internal debugging flags, or even to make emergency
10429repairs.
10430
10431@table @code
10432@kindex set write
10433@item set write on
10434@itemx set write off
7a292a7a
SS
10435If you specify @samp{set write on}, @value{GDBN} opens executable and
10436core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10437off} (the default), @value{GDBN} opens them read-only.
10438
10439If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10440@code{exec-file} or @code{core-file} command) after changing @code{set
10441write}, for your new setting to take effect.
c906108c
SS
10442
10443@item show write
10444@kindex show write
7a292a7a
SS
10445Display whether executable files and core files are opened for writing
10446as well as reading.
c906108c
SS
10447@end table
10448
6d2ebf8b 10449@node GDB Files
c906108c
SS
10450@chapter @value{GDBN} Files
10451
7a292a7a
SS
10452@value{GDBN} needs to know the file name of the program to be debugged,
10453both in order to read its symbol table and in order to start your
10454program. To debug a core dump of a previous run, you must also tell
10455@value{GDBN} the name of the core dump file.
c906108c
SS
10456
10457@menu
10458* Files:: Commands to specify files
5b5d99cf 10459* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10460* Symbol Errors:: Errors reading symbol files
10461@end menu
10462
6d2ebf8b 10463@node Files
c906108c 10464@section Commands to specify files
c906108c 10465
7a292a7a 10466@cindex symbol table
c906108c 10467@cindex core dump file
7a292a7a
SS
10468
10469You may want to specify executable and core dump file names. The usual
10470way to do this is at start-up time, using the arguments to
10471@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10472Out of @value{GDBN}}).
c906108c
SS
10473
10474Occasionally it is necessary to change to a different file during a
10475@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10476a file you want to use. In these situations the @value{GDBN} commands
10477to specify new files are useful.
10478
10479@table @code
10480@cindex executable file
10481@kindex file
10482@item file @var{filename}
10483Use @var{filename} as the program to be debugged. It is read for its
10484symbols and for the contents of pure memory. It is also the program
10485executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10486directory and the file is not found in the @value{GDBN} working directory,
10487@value{GDBN} uses the environment variable @code{PATH} as a list of
10488directories to search, just as the shell does when looking for a program
10489to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10490and your program, using the @code{path} command.
10491
6d2ebf8b 10492On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10493@file{@var{filename}.syms} may hold symbol table information for
10494@var{filename}. If so, @value{GDBN} maps in the symbol table from
10495@file{@var{filename}.syms}, starting up more quickly. See the
10496descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10497(available on the command line, see @ref{File Options, , -readnow},
10498and with the commands @code{file}, @code{symbol-file}, or
10499@code{add-symbol-file}, described below), for more information.
c906108c
SS
10500
10501@item file
10502@code{file} with no argument makes @value{GDBN} discard any information it
10503has on both executable file and the symbol table.
10504
10505@kindex exec-file
10506@item exec-file @r{[} @var{filename} @r{]}
10507Specify that the program to be run (but not the symbol table) is found
10508in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10509if necessary to locate your program. Omitting @var{filename} means to
10510discard information on the executable file.
10511
10512@kindex symbol-file
10513@item symbol-file @r{[} @var{filename} @r{]}
10514Read symbol table information from file @var{filename}. @code{PATH} is
10515searched when necessary. Use the @code{file} command to get both symbol
10516table and program to run from the same file.
10517
10518@code{symbol-file} with no argument clears out @value{GDBN} information on your
10519program's symbol table.
10520
5d161b24 10521The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10522of its convenience variables, the value history, and all breakpoints and
10523auto-display expressions. This is because they may contain pointers to
10524the internal data recording symbols and data types, which are part of
10525the old symbol table data being discarded inside @value{GDBN}.
10526
10527@code{symbol-file} does not repeat if you press @key{RET} again after
10528executing it once.
10529
10530When @value{GDBN} is configured for a particular environment, it
10531understands debugging information in whatever format is the standard
10532generated for that environment; you may use either a @sc{gnu} compiler, or
10533other compilers that adhere to the local conventions.
c906108c
SS
10534Best results are usually obtained from @sc{gnu} compilers; for example,
10535using @code{@value{GCC}} you can generate debugging information for
10536optimized code.
c906108c
SS
10537
10538For most kinds of object files, with the exception of old SVR3 systems
10539using COFF, the @code{symbol-file} command does not normally read the
10540symbol table in full right away. Instead, it scans the symbol table
10541quickly to find which source files and which symbols are present. The
10542details are read later, one source file at a time, as they are needed.
10543
10544The purpose of this two-stage reading strategy is to make @value{GDBN}
10545start up faster. For the most part, it is invisible except for
10546occasional pauses while the symbol table details for a particular source
10547file are being read. (The @code{set verbose} command can turn these
10548pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10549warnings and messages}.)
10550
c906108c
SS
10551We have not implemented the two-stage strategy for COFF yet. When the
10552symbol table is stored in COFF format, @code{symbol-file} reads the
10553symbol table data in full right away. Note that ``stabs-in-COFF''
10554still does the two-stage strategy, since the debug info is actually
10555in stabs format.
10556
10557@kindex readnow
10558@cindex reading symbols immediately
10559@cindex symbols, reading immediately
10560@kindex mapped
10561@cindex memory-mapped symbol file
10562@cindex saving symbol table
10563@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10564@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10565You can override the @value{GDBN} two-stage strategy for reading symbol
10566tables by using the @samp{-readnow} option with any of the commands that
10567load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10568entire symbol table available.
c906108c 10569
c906108c
SS
10570If memory-mapped files are available on your system through the
10571@code{mmap} system call, you can use another option, @samp{-mapped}, to
10572cause @value{GDBN} to write the symbols for your program into a reusable
10573file. Future @value{GDBN} debugging sessions map in symbol information
10574from this auxiliary symbol file (if the program has not changed), rather
10575than spending time reading the symbol table from the executable
10576program. Using the @samp{-mapped} option has the same effect as
10577starting @value{GDBN} with the @samp{-mapped} command-line option.
10578
10579You can use both options together, to make sure the auxiliary symbol
10580file has all the symbol information for your program.
10581
10582The auxiliary symbol file for a program called @var{myprog} is called
10583@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10584than the corresponding executable), @value{GDBN} always attempts to use
10585it when you debug @var{myprog}; no special options or commands are
10586needed.
10587
10588The @file{.syms} file is specific to the host machine where you run
10589@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10590symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10591
10592@c FIXME: for now no mention of directories, since this seems to be in
10593@c flux. 13mar1992 status is that in theory GDB would look either in
10594@c current dir or in same dir as myprog; but issues like competing
10595@c GDB's, or clutter in system dirs, mean that in practice right now
10596@c only current dir is used. FFish says maybe a special GDB hierarchy
10597@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10598@c files.
10599
c906108c 10600@kindex core-file
09d4efe1 10601@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10602@itemx core
c906108c
SS
10603Specify the whereabouts of a core dump file to be used as the ``contents
10604of memory''. Traditionally, core files contain only some parts of the
10605address space of the process that generated them; @value{GDBN} can access the
10606executable file itself for other parts.
10607
10608@code{core-file} with no argument specifies that no core file is
10609to be used.
10610
10611Note that the core file is ignored when your program is actually running
7a292a7a
SS
10612under @value{GDBN}. So, if you have been running your program and you
10613wish to debug a core file instead, you must kill the subprocess in which
10614the program is running. To do this, use the @code{kill} command
c906108c 10615(@pxref{Kill Process, ,Killing the child process}).
c906108c 10616
c906108c
SS
10617@kindex add-symbol-file
10618@cindex dynamic linking
10619@item add-symbol-file @var{filename} @var{address}
10620@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10621@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10622The @code{add-symbol-file} command reads additional symbol table
10623information from the file @var{filename}. You would use this command
10624when @var{filename} has been dynamically loaded (by some other means)
10625into the program that is running. @var{address} should be the memory
10626address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10627this out for itself. You can additionally specify an arbitrary number
10628of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10629section name and base address for that section. You can specify any
10630@var{address} as an expression.
c906108c
SS
10631
10632The symbol table of the file @var{filename} is added to the symbol table
10633originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10634@code{add-symbol-file} command any number of times; the new symbol data
10635thus read keeps adding to the old. To discard all old symbol data
10636instead, use the @code{symbol-file} command without any arguments.
c906108c 10637
17d9d558
JB
10638@cindex relocatable object files, reading symbols from
10639@cindex object files, relocatable, reading symbols from
10640@cindex reading symbols from relocatable object files
10641@cindex symbols, reading from relocatable object files
10642@cindex @file{.o} files, reading symbols from
10643Although @var{filename} is typically a shared library file, an
10644executable file, or some other object file which has been fully
10645relocated for loading into a process, you can also load symbolic
10646information from relocatable @file{.o} files, as long as:
10647
10648@itemize @bullet
10649@item
10650the file's symbolic information refers only to linker symbols defined in
10651that file, not to symbols defined by other object files,
10652@item
10653every section the file's symbolic information refers to has actually
10654been loaded into the inferior, as it appears in the file, and
10655@item
10656you can determine the address at which every section was loaded, and
10657provide these to the @code{add-symbol-file} command.
10658@end itemize
10659
10660@noindent
10661Some embedded operating systems, like Sun Chorus and VxWorks, can load
10662relocatable files into an already running program; such systems
10663typically make the requirements above easy to meet. However, it's
10664important to recognize that many native systems use complex link
49efadf5 10665procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10666assembly, for example) that make the requirements difficult to meet. In
10667general, one cannot assume that using @code{add-symbol-file} to read a
10668relocatable object file's symbolic information will have the same effect
10669as linking the relocatable object file into the program in the normal
10670way.
10671
c906108c
SS
10672@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10673
10674You can use the @samp{-mapped} and @samp{-readnow} options just as with
10675the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10676table information for @var{filename}.
10677
09d4efe1
EZ
10678@kindex add-shared-symbol-files
10679@kindex assf
10680@item add-shared-symbol-files @var{library-file}
10681@itemx assf @var{library-file}
10682The @code{add-shared-symbol-files} command can currently be used only
10683in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10684alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10685@value{GDBN} automatically looks for shared libraries, however if
10686@value{GDBN} does not find yours, you can invoke
10687@code{add-shared-symbol-files}. It takes one argument: the shared
10688library's file name. @code{assf} is a shorthand alias for
10689@code{add-shared-symbol-files}.
c906108c 10690
c906108c 10691@kindex section
09d4efe1
EZ
10692@item section @var{section} @var{addr}
10693The @code{section} command changes the base address of the named
10694@var{section} of the exec file to @var{addr}. This can be used if the
10695exec file does not contain section addresses, (such as in the
10696@code{a.out} format), or when the addresses specified in the file
10697itself are wrong. Each section must be changed separately. The
10698@code{info files} command, described below, lists all the sections and
10699their addresses.
c906108c
SS
10700
10701@kindex info files
10702@kindex info target
10703@item info files
10704@itemx info target
7a292a7a
SS
10705@code{info files} and @code{info target} are synonymous; both print the
10706current target (@pxref{Targets, ,Specifying a Debugging Target}),
10707including the names of the executable and core dump files currently in
10708use by @value{GDBN}, and the files from which symbols were loaded. The
10709command @code{help target} lists all possible targets rather than
10710current ones.
10711
fe95c787
MS
10712@kindex maint info sections
10713@item maint info sections
10714Another command that can give you extra information about program sections
10715is @code{maint info sections}. In addition to the section information
10716displayed by @code{info files}, this command displays the flags and file
10717offset of each section in the executable and core dump files. In addition,
10718@code{maint info sections} provides the following command options (which
10719may be arbitrarily combined):
10720
10721@table @code
10722@item ALLOBJ
10723Display sections for all loaded object files, including shared libraries.
10724@item @var{sections}
6600abed 10725Display info only for named @var{sections}.
fe95c787
MS
10726@item @var{section-flags}
10727Display info only for sections for which @var{section-flags} are true.
10728The section flags that @value{GDBN} currently knows about are:
10729@table @code
10730@item ALLOC
10731Section will have space allocated in the process when loaded.
10732Set for all sections except those containing debug information.
10733@item LOAD
10734Section will be loaded from the file into the child process memory.
10735Set for pre-initialized code and data, clear for @code{.bss} sections.
10736@item RELOC
10737Section needs to be relocated before loading.
10738@item READONLY
10739Section cannot be modified by the child process.
10740@item CODE
10741Section contains executable code only.
6600abed 10742@item DATA
fe95c787
MS
10743Section contains data only (no executable code).
10744@item ROM
10745Section will reside in ROM.
10746@item CONSTRUCTOR
10747Section contains data for constructor/destructor lists.
10748@item HAS_CONTENTS
10749Section is not empty.
10750@item NEVER_LOAD
10751An instruction to the linker to not output the section.
10752@item COFF_SHARED_LIBRARY
10753A notification to the linker that the section contains
10754COFF shared library information.
10755@item IS_COMMON
10756Section contains common symbols.
10757@end table
10758@end table
6763aef9 10759@kindex set trust-readonly-sections
9c16f35a 10760@cindex read-only sections
6763aef9
MS
10761@item set trust-readonly-sections on
10762Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10763really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10764In that case, @value{GDBN} can fetch values from these sections
10765out of the object file, rather than from the target program.
10766For some targets (notably embedded ones), this can be a significant
10767enhancement to debugging performance.
10768
10769The default is off.
10770
10771@item set trust-readonly-sections off
15110bc3 10772Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10773the contents of the section might change while the program is running,
10774and must therefore be fetched from the target when needed.
9c16f35a
EZ
10775
10776@item show trust-readonly-sections
10777Show the current setting of trusting readonly sections.
c906108c
SS
10778@end table
10779
10780All file-specifying commands allow both absolute and relative file names
10781as arguments. @value{GDBN} always converts the file name to an absolute file
10782name and remembers it that way.
10783
c906108c 10784@cindex shared libraries
9c16f35a
EZ
10785@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10786and IBM RS/6000 AIX shared libraries.
53a5351d 10787
c906108c
SS
10788@value{GDBN} automatically loads symbol definitions from shared libraries
10789when you use the @code{run} command, or when you examine a core file.
10790(Before you issue the @code{run} command, @value{GDBN} does not understand
10791references to a function in a shared library, however---unless you are
10792debugging a core file).
53a5351d
JM
10793
10794On HP-UX, if the program loads a library explicitly, @value{GDBN}
10795automatically loads the symbols at the time of the @code{shl_load} call.
10796
c906108c
SS
10797@c FIXME: some @value{GDBN} release may permit some refs to undef
10798@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10799@c FIXME...lib; check this from time to time when updating manual
10800
b7209cb4
FF
10801There are times, however, when you may wish to not automatically load
10802symbol definitions from shared libraries, such as when they are
10803particularly large or there are many of them.
10804
10805To control the automatic loading of shared library symbols, use the
10806commands:
10807
10808@table @code
10809@kindex set auto-solib-add
10810@item set auto-solib-add @var{mode}
10811If @var{mode} is @code{on}, symbols from all shared object libraries
10812will be loaded automatically when the inferior begins execution, you
10813attach to an independently started inferior, or when the dynamic linker
10814informs @value{GDBN} that a new library has been loaded. If @var{mode}
10815is @code{off}, symbols must be loaded manually, using the
10816@code{sharedlibrary} command. The default value is @code{on}.
10817
dcaf7c2c
EZ
10818@cindex memory used for symbol tables
10819If your program uses lots of shared libraries with debug info that
10820takes large amounts of memory, you can decrease the @value{GDBN}
10821memory footprint by preventing it from automatically loading the
10822symbols from shared libraries. To that end, type @kbd{set
10823auto-solib-add off} before running the inferior, then load each
10824library whose debug symbols you do need with @kbd{sharedlibrary
10825@var{regexp}}, where @var{regexp} is a regular expresion that matches
10826the libraries whose symbols you want to be loaded.
10827
b7209cb4
FF
10828@kindex show auto-solib-add
10829@item show auto-solib-add
10830Display the current autoloading mode.
10831@end table
10832
10833To explicitly load shared library symbols, use the @code{sharedlibrary}
10834command:
10835
c906108c
SS
10836@table @code
10837@kindex info sharedlibrary
10838@kindex info share
10839@item info share
10840@itemx info sharedlibrary
10841Print the names of the shared libraries which are currently loaded.
10842
10843@kindex sharedlibrary
10844@kindex share
10845@item sharedlibrary @var{regex}
10846@itemx share @var{regex}
c906108c
SS
10847Load shared object library symbols for files matching a
10848Unix regular expression.
10849As with files loaded automatically, it only loads shared libraries
10850required by your program for a core file or after typing @code{run}. If
10851@var{regex} is omitted all shared libraries required by your program are
10852loaded.
10853@end table
10854
b7209cb4
FF
10855On some systems, such as HP-UX systems, @value{GDBN} supports
10856autoloading shared library symbols until a limiting threshold size is
10857reached. This provides the benefit of allowing autoloading to remain on
10858by default, but avoids autoloading excessively large shared libraries,
10859up to a threshold that is initially set, but which you can modify if you
10860wish.
c906108c
SS
10861
10862Beyond that threshold, symbols from shared libraries must be explicitly
d4f3574e
SS
10863loaded. To load these symbols, use the command @code{sharedlibrary
10864@var{filename}}. The base address of the shared library is determined
c906108c
SS
10865automatically by @value{GDBN} and need not be specified.
10866
10867To display or set the threshold, use the commands:
10868
10869@table @code
b7209cb4
FF
10870@kindex set auto-solib-limit
10871@item set auto-solib-limit @var{threshold}
10872Set the autoloading size threshold, in an integral number of megabytes.
10873If @var{threshold} is nonzero and shared library autoloading is enabled,
10874symbols from all shared object libraries will be loaded until the total
10875size of the loaded shared library symbols exceeds this threshold.
c906108c 10876Otherwise, symbols must be loaded manually, using the
6ca652b0 10877@code{sharedlibrary} command. The default threshold is 100 (i.e.@: 100
b7209cb4 10878Mb).
c906108c 10879
b7209cb4
FF
10880@kindex show auto-solib-limit
10881@item show auto-solib-limit
c906108c
SS
10882Display the current autoloading size threshold, in megabytes.
10883@end table
c906108c 10884
721c2651
EZ
10885Sometimes you may wish that @value{GDBN} stops and gives you control
10886when any of shared library events happen. Use the @code{set
10887stop-on-solib-events} command for this:
10888
10889@table @code
10890@item set stop-on-solib-events
10891@kindex set stop-on-solib-events
10892This command controls whether @value{GDBN} should give you control
10893when the dynamic linker notifies it about some shared library event.
10894The most common event of interest is loading or unloading of a new
10895shared library.
10896
10897@item show stop-on-solib-events
10898@kindex show stop-on-solib-events
10899Show whether @value{GDBN} stops and gives you control when shared
10900library events happen.
10901@end table
10902
f5ebfba0
DJ
10903Shared libraries are also supported in many cross or remote debugging
10904configurations. A copy of the target's libraries need to be present on the
10905host system; they need to be the same as the target libraries, although the
10906copies on the target can be stripped as long as the copies on the host are
10907not.
10908
10909You need to tell @value{GDBN} where the target libraries are, so that it can
10910load the correct copies---otherwise, it may try to load the host's libraries.
10911@value{GDBN} has two variables to specify the search directories for target
10912libraries.
10913
10914@table @code
10915@kindex set solib-absolute-prefix
10916@item set solib-absolute-prefix @var{path}
10917If this variable is set, @var{path} will be used as a prefix for any
10918absolute shared library paths; many runtime loaders store the absolute
10919paths to the shared library in the target program's memory. If you use
10920@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
10921out in the same way that they are on the target, with e.g.@: a
10922@file{/usr/lib} hierarchy under @var{path}.
10923
10924You can set the default value of @samp{solib-absolute-prefix} by using the
10925configure-time @samp{--with-sysroot} option.
10926
10927@kindex show solib-absolute-prefix
10928@item show solib-absolute-prefix
10929Display the current shared library prefix.
10930
10931@kindex set solib-search-path
10932@item set solib-search-path @var{path}
10933If this variable is set, @var{path} is a colon-separated list of directories
10934to search for shared libraries. @samp{solib-search-path} is used after
10935@samp{solib-absolute-prefix} fails to locate the library, or if the path to
10936the library is relative instead of absolute. If you want to use
10937@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
10938set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
10939@value{GDBN} from finding your host's libraries.
10940
10941@kindex show solib-search-path
10942@item show solib-search-path
10943Display the current shared library search path.
10944@end table
10945
5b5d99cf
JB
10946
10947@node Separate Debug Files
10948@section Debugging Information in Separate Files
10949@cindex separate debugging information files
10950@cindex debugging information in separate files
10951@cindex @file{.debug} subdirectories
10952@cindex debugging information directory, global
10953@cindex global debugging information directory
10954
10955@value{GDBN} allows you to put a program's debugging information in a
10956file separate from the executable itself, in a way that allows
10957@value{GDBN} to find and load the debugging information automatically.
10958Since debugging information can be very large --- sometimes larger
10959than the executable code itself --- some systems distribute debugging
10960information for their executables in separate files, which users can
10961install only when they need to debug a problem.
10962
10963If an executable's debugging information has been extracted to a
10964separate file, the executable should contain a @dfn{debug link} giving
10965the name of the debugging information file (with no directory
10966components), and a checksum of its contents. (The exact form of a
10967debug link is described below.) If the full name of the directory
10968containing the executable is @var{execdir}, and the executable has a
10969debug link that specifies the name @var{debugfile}, then @value{GDBN}
10970will automatically search for the debugging information file in three
10971places:
10972
10973@itemize @bullet
10974@item
10975the directory containing the executable file (that is, it will look
10976for a file named @file{@var{execdir}/@var{debugfile}},
10977@item
10978a subdirectory of that directory named @file{.debug} (that is, the
10979file @file{@var{execdir}/.debug/@var{debugfile}}, and
10980@item
10981a subdirectory of the global debug file directory that includes the
10982executable's full path, and the name from the link (that is, the file
10983@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
10984@var{globaldebugdir} is the global debug file directory, and
10985@var{execdir} has been turned into a relative path).
10986@end itemize
10987@noindent
10988@value{GDBN} checks under each of these names for a debugging
10989information file whose checksum matches that given in the link, and
10990reads the debugging information from the first one it finds.
10991
10992So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
10993which has a link containing the name @file{ls.debug}, and the global
10994debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
10995for debug information in @file{/usr/bin/ls.debug},
10996@file{/usr/bin/.debug/ls.debug}, and
10997@file{/usr/lib/debug/usr/bin/ls.debug}.
10998
10999You can set the global debugging info directory's name, and view the
11000name @value{GDBN} is currently using.
11001
11002@table @code
11003
11004@kindex set debug-file-directory
11005@item set debug-file-directory @var{directory}
11006Set the directory which @value{GDBN} searches for separate debugging
11007information files to @var{directory}.
11008
11009@kindex show debug-file-directory
11010@item show debug-file-directory
11011Show the directory @value{GDBN} searches for separate debugging
11012information files.
11013
11014@end table
11015
11016@cindex @code{.gnu_debuglink} sections
11017@cindex debug links
11018A debug link is a special section of the executable file named
11019@code{.gnu_debuglink}. The section must contain:
11020
11021@itemize
11022@item
11023A filename, with any leading directory components removed, followed by
11024a zero byte,
11025@item
11026zero to three bytes of padding, as needed to reach the next four-byte
11027boundary within the section, and
11028@item
11029a four-byte CRC checksum, stored in the same endianness used for the
11030executable file itself. The checksum is computed on the debugging
11031information file's full contents by the function given below, passing
11032zero as the @var{crc} argument.
11033@end itemize
11034
11035Any executable file format can carry a debug link, as long as it can
11036contain a section named @code{.gnu_debuglink} with the contents
11037described above.
11038
11039The debugging information file itself should be an ordinary
11040executable, containing a full set of linker symbols, sections, and
11041debugging information. The sections of the debugging information file
11042should have the same names, addresses and sizes as the original file,
11043but they need not contain any data --- much like a @code{.bss} section
11044in an ordinary executable.
11045
11046As of December 2002, there is no standard GNU utility to produce
11047separated executable / debugging information file pairs. Ulrich
11048Drepper's @file{elfutils} package, starting with version 0.53,
11049contains a version of the @code{strip} command such that the command
11050@kbd{strip foo -f foo.debug} removes the debugging information from
11051the executable file @file{foo}, places it in the file
11052@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11053
11054Since there are many different ways to compute CRC's (different
11055polynomials, reversals, byte ordering, etc.), the simplest way to
11056describe the CRC used in @code{.gnu_debuglink} sections is to give the
11057complete code for a function that computes it:
11058
4644b6e3 11059@kindex gnu_debuglink_crc32
5b5d99cf
JB
11060@smallexample
11061unsigned long
11062gnu_debuglink_crc32 (unsigned long crc,
11063 unsigned char *buf, size_t len)
11064@{
11065 static const unsigned long crc32_table[256] =
11066 @{
11067 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11068 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11069 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11070 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11071 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11072 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11073 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11074 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11075 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11076 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11077 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11078 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11079 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11080 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11081 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11082 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11083 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11084 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11085 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11086 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11087 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11088 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11089 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11090 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11091 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11092 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11093 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11094 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11095 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11096 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11097 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11098 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11099 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11100 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11101 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11102 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11103 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11104 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11105 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11106 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11107 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11108 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11109 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11110 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11111 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11112 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11113 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11114 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11115 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11116 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11117 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11118 0x2d02ef8d
11119 @};
11120 unsigned char *end;
11121
11122 crc = ~crc & 0xffffffff;
11123 for (end = buf + len; buf < end; ++buf)
11124 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11125 return ~crc & 0xffffffff;
5b5d99cf
JB
11126@}
11127@end smallexample
11128
11129
6d2ebf8b 11130@node Symbol Errors
c906108c
SS
11131@section Errors reading symbol files
11132
11133While reading a symbol file, @value{GDBN} occasionally encounters problems,
11134such as symbol types it does not recognize, or known bugs in compiler
11135output. By default, @value{GDBN} does not notify you of such problems, since
11136they are relatively common and primarily of interest to people
11137debugging compilers. If you are interested in seeing information
11138about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11139only one message about each such type of problem, no matter how many
11140times the problem occurs; or you can ask @value{GDBN} to print more messages,
11141to see how many times the problems occur, with the @code{set
11142complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11143messages}).
11144
11145The messages currently printed, and their meanings, include:
11146
11147@table @code
11148@item inner block not inside outer block in @var{symbol}
11149
11150The symbol information shows where symbol scopes begin and end
11151(such as at the start of a function or a block of statements). This
11152error indicates that an inner scope block is not fully contained
11153in its outer scope blocks.
11154
11155@value{GDBN} circumvents the problem by treating the inner block as if it had
11156the same scope as the outer block. In the error message, @var{symbol}
11157may be shown as ``@code{(don't know)}'' if the outer block is not a
11158function.
11159
11160@item block at @var{address} out of order
11161
11162The symbol information for symbol scope blocks should occur in
11163order of increasing addresses. This error indicates that it does not
11164do so.
11165
11166@value{GDBN} does not circumvent this problem, and has trouble
11167locating symbols in the source file whose symbols it is reading. (You
11168can often determine what source file is affected by specifying
11169@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11170messages}.)
11171
11172@item bad block start address patched
11173
11174The symbol information for a symbol scope block has a start address
11175smaller than the address of the preceding source line. This is known
11176to occur in the SunOS 4.1.1 (and earlier) C compiler.
11177
11178@value{GDBN} circumvents the problem by treating the symbol scope block as
11179starting on the previous source line.
11180
11181@item bad string table offset in symbol @var{n}
11182
11183@cindex foo
11184Symbol number @var{n} contains a pointer into the string table which is
11185larger than the size of the string table.
11186
11187@value{GDBN} circumvents the problem by considering the symbol to have the
11188name @code{foo}, which may cause other problems if many symbols end up
11189with this name.
11190
11191@item unknown symbol type @code{0x@var{nn}}
11192
7a292a7a
SS
11193The symbol information contains new data types that @value{GDBN} does
11194not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11195uncomprehended information, in hexadecimal.
c906108c 11196
7a292a7a
SS
11197@value{GDBN} circumvents the error by ignoring this symbol information.
11198This usually allows you to debug your program, though certain symbols
c906108c 11199are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11200debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11201on @code{complain}, then go up to the function @code{read_dbx_symtab}
11202and examine @code{*bufp} to see the symbol.
c906108c
SS
11203
11204@item stub type has NULL name
c906108c 11205
7a292a7a 11206@value{GDBN} could not find the full definition for a struct or class.
c906108c 11207
7a292a7a 11208@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11209The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11210information that recent versions of the compiler should have output for
11211it.
c906108c
SS
11212
11213@item info mismatch between compiler and debugger
11214
11215@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11216
c906108c
SS
11217@end table
11218
6d2ebf8b 11219@node Targets
c906108c 11220@chapter Specifying a Debugging Target
7a292a7a 11221
c906108c 11222@cindex debugging target
c906108c 11223A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11224
11225Often, @value{GDBN} runs in the same host environment as your program;
11226in that case, the debugging target is specified as a side effect when
11227you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11228flexibility---for example, running @value{GDBN} on a physically separate
11229host, or controlling a standalone system over a serial port or a
53a5351d
JM
11230realtime system over a TCP/IP connection---you can use the @code{target}
11231command to specify one of the target types configured for @value{GDBN}
11232(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11233
a8f24a35
EZ
11234@cindex target architecture
11235It is possible to build @value{GDBN} for several different @dfn{target
11236architectures}. When @value{GDBN} is built like that, you can choose
11237one of the available architectures with the @kbd{set architecture}
11238command.
11239
11240@table @code
11241@kindex set architecture
11242@kindex show architecture
11243@item set architecture @var{arch}
11244This command sets the current target architecture to @var{arch}. The
11245value of @var{arch} can be @code{"auto"}, in addition to one of the
11246supported architectures.
11247
11248@item show architecture
11249Show the current target architecture.
9c16f35a
EZ
11250
11251@item set processor
11252@itemx processor
11253@kindex set processor
11254@kindex show processor
11255These are alias commands for, respectively, @code{set architecture}
11256and @code{show architecture}.
a8f24a35
EZ
11257@end table
11258
c906108c
SS
11259@menu
11260* Active Targets:: Active targets
11261* Target Commands:: Commands for managing targets
c906108c
SS
11262* Byte Order:: Choosing target byte order
11263* Remote:: Remote debugging
96baa820 11264* KOD:: Kernel Object Display
c906108c
SS
11265
11266@end menu
11267
6d2ebf8b 11268@node Active Targets
c906108c 11269@section Active targets
7a292a7a 11270
c906108c
SS
11271@cindex stacking targets
11272@cindex active targets
11273@cindex multiple targets
11274
c906108c 11275There are three classes of targets: processes, core files, and
7a292a7a
SS
11276executable files. @value{GDBN} can work concurrently on up to three
11277active targets, one in each class. This allows you to (for example)
11278start a process and inspect its activity without abandoning your work on
11279a core file.
c906108c
SS
11280
11281For example, if you execute @samp{gdb a.out}, then the executable file
11282@code{a.out} is the only active target. If you designate a core file as
11283well---presumably from a prior run that crashed and coredumped---then
11284@value{GDBN} has two active targets and uses them in tandem, looking
11285first in the corefile target, then in the executable file, to satisfy
11286requests for memory addresses. (Typically, these two classes of target
11287are complementary, since core files contain only a program's
11288read-write memory---variables and so on---plus machine status, while
11289executable files contain only the program text and initialized data.)
c906108c
SS
11290
11291When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11292target as well. When a process target is active, all @value{GDBN}
11293commands requesting memory addresses refer to that target; addresses in
11294an active core file or executable file target are obscured while the
11295process target is active.
c906108c 11296
7a292a7a
SS
11297Use the @code{core-file} and @code{exec-file} commands to select a new
11298core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11299files}). To specify as a target a process that is already running, use
7a292a7a
SS
11300the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11301process}).
c906108c 11302
6d2ebf8b 11303@node Target Commands
c906108c
SS
11304@section Commands for managing targets
11305
11306@table @code
11307@item target @var{type} @var{parameters}
7a292a7a
SS
11308Connects the @value{GDBN} host environment to a target machine or
11309process. A target is typically a protocol for talking to debugging
11310facilities. You use the argument @var{type} to specify the type or
11311protocol of the target machine.
c906108c
SS
11312
11313Further @var{parameters} are interpreted by the target protocol, but
11314typically include things like device names or host names to connect
11315with, process numbers, and baud rates.
c906108c
SS
11316
11317The @code{target} command does not repeat if you press @key{RET} again
11318after executing the command.
11319
11320@kindex help target
11321@item help target
11322Displays the names of all targets available. To display targets
11323currently selected, use either @code{info target} or @code{info files}
11324(@pxref{Files, ,Commands to specify files}).
11325
11326@item help target @var{name}
11327Describe a particular target, including any parameters necessary to
11328select it.
11329
11330@kindex set gnutarget
11331@item set gnutarget @var{args}
5d161b24 11332@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11333knows whether it is reading an @dfn{executable},
5d161b24
DB
11334a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11335with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11336with @code{gnutarget} the @code{target} refers to a program, not a machine.
11337
d4f3574e 11338@quotation
c906108c
SS
11339@emph{Warning:} To specify a file format with @code{set gnutarget},
11340you must know the actual BFD name.
d4f3574e 11341@end quotation
c906108c 11342
d4f3574e
SS
11343@noindent
11344@xref{Files, , Commands to specify files}.
c906108c 11345
5d161b24 11346@kindex show gnutarget
c906108c
SS
11347@item show gnutarget
11348Use the @code{show gnutarget} command to display what file format
11349@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11350@value{GDBN} will determine the file format for each file automatically,
11351and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11352@end table
11353
4644b6e3 11354@cindex common targets
c906108c
SS
11355Here are some common targets (available, or not, depending on the GDB
11356configuration):
c906108c
SS
11357
11358@table @code
4644b6e3 11359@kindex target
c906108c 11360@item target exec @var{program}
4644b6e3 11361@cindex executable file target
c906108c
SS
11362An executable file. @samp{target exec @var{program}} is the same as
11363@samp{exec-file @var{program}}.
11364
c906108c 11365@item target core @var{filename}
4644b6e3 11366@cindex core dump file target
c906108c
SS
11367A core dump file. @samp{target core @var{filename}} is the same as
11368@samp{core-file @var{filename}}.
c906108c 11369
c906108c 11370@item target remote @var{dev}
4644b6e3 11371@cindex remote target
c906108c
SS
11372Remote serial target in GDB-specific protocol. The argument @var{dev}
11373specifies what serial device to use for the connection (e.g.
11374@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11375supports the @code{load} command. This is only useful if you have
c906108c
SS
11376some other way of getting the stub to the target system, and you can put
11377it somewhere in memory where it won't get clobbered by the download.
11378
c906108c 11379@item target sim
4644b6e3 11380@cindex built-in simulator target
2df3850c 11381Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11382In general,
474c8240 11383@smallexample
104c1213
JM
11384 target sim
11385 load
11386 run
474c8240 11387@end smallexample
d4f3574e 11388@noindent
104c1213 11389works; however, you cannot assume that a specific memory map, device
d4f3574e 11390drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11391provide these. For info about any processor-specific simulator details,
11392see the appropriate section in @ref{Embedded Processors, ,Embedded
11393Processors}.
11394
c906108c
SS
11395@end table
11396
104c1213 11397Some configurations may include these targets as well:
c906108c
SS
11398
11399@table @code
11400
c906108c 11401@item target nrom @var{dev}
4644b6e3 11402@cindex NetROM ROM emulator target
c906108c
SS
11403NetROM ROM emulator. This target only supports downloading.
11404
c906108c
SS
11405@end table
11406
5d161b24 11407Different targets are available on different configurations of @value{GDBN};
c906108c 11408your configuration may have more or fewer targets.
c906108c 11409
721c2651
EZ
11410Many remote targets require you to download the executable's code once
11411you've successfully established a connection. You may wish to control
11412various aspects of this process, such as the size of the data chunks
11413used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11414
11415@table @code
11416@kindex set download-write-size
11417@item set download-write-size @var{size}
11418Set the write size used when downloading a program. Only used when
11419downloading a program onto a remote target. Specify zero or a
11420negative value to disable blocked writes. The actual size of each
11421transfer is also limited by the size of the target packet and the
11422memory cache.
11423
11424@kindex show download-write-size
11425@item show download-write-size
721c2651 11426@kindex show download-write-size
a8f24a35 11427Show the current value of the write size.
721c2651
EZ
11428
11429@item set hash
11430@kindex set hash@r{, for remote monitors}
11431@cindex hash mark while downloading
11432This command controls whether a hash mark @samp{#} is displayed while
11433downloading a file to the remote monitor. If on, a hash mark is
11434displayed after each S-record is successfully downloaded to the
11435monitor.
11436
11437@item show hash
11438@kindex show hash@r{, for remote monitors}
11439Show the current status of displaying the hash mark.
11440
11441@item set debug monitor
11442@kindex set debug monitor
11443@cindex display remote monitor communications
11444Enable or disable display of communications messages between
11445@value{GDBN} and the remote monitor.
11446
11447@item show debug monitor
11448@kindex show debug monitor
11449Show the current status of displaying communications between
11450@value{GDBN} and the remote monitor.
a8f24a35 11451@end table
c906108c
SS
11452
11453@table @code
11454
11455@kindex load @var{filename}
11456@item load @var{filename}
c906108c
SS
11457Depending on what remote debugging facilities are configured into
11458@value{GDBN}, the @code{load} command may be available. Where it exists, it
11459is meant to make @var{filename} (an executable) available for debugging
11460on the remote system---by downloading, or dynamic linking, for example.
11461@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11462the @code{add-symbol-file} command.
11463
11464If your @value{GDBN} does not have a @code{load} command, attempting to
11465execute it gets the error message ``@code{You can't do that when your
11466target is @dots{}}''
c906108c
SS
11467
11468The file is loaded at whatever address is specified in the executable.
11469For some object file formats, you can specify the load address when you
11470link the program; for other formats, like a.out, the object file format
11471specifies a fixed address.
11472@c FIXME! This would be a good place for an xref to the GNU linker doc.
11473
c906108c
SS
11474@code{load} does not repeat if you press @key{RET} again after using it.
11475@end table
11476
6d2ebf8b 11477@node Byte Order
c906108c 11478@section Choosing target byte order
7a292a7a 11479
c906108c
SS
11480@cindex choosing target byte order
11481@cindex target byte order
c906108c 11482
172c2a43 11483Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11484offer the ability to run either big-endian or little-endian byte
11485orders. Usually the executable or symbol will include a bit to
11486designate the endian-ness, and you will not need to worry about
11487which to use. However, you may still find it useful to adjust
d4f3574e 11488@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11489
11490@table @code
4644b6e3 11491@kindex set endian
c906108c
SS
11492@item set endian big
11493Instruct @value{GDBN} to assume the target is big-endian.
11494
c906108c
SS
11495@item set endian little
11496Instruct @value{GDBN} to assume the target is little-endian.
11497
c906108c
SS
11498@item set endian auto
11499Instruct @value{GDBN} to use the byte order associated with the
11500executable.
11501
11502@item show endian
11503Display @value{GDBN}'s current idea of the target byte order.
11504
11505@end table
11506
11507Note that these commands merely adjust interpretation of symbolic
11508data on the host, and that they have absolutely no effect on the
11509target system.
11510
6d2ebf8b 11511@node Remote
c906108c
SS
11512@section Remote debugging
11513@cindex remote debugging
11514
11515If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11516@value{GDBN} in the usual way, it is often useful to use remote debugging.
11517For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11518or on a small system which does not have a general purpose operating system
11519powerful enough to run a full-featured debugger.
11520
11521Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11522to make this work with particular debugging targets. In addition,
5d161b24 11523@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11524but not specific to any particular target system) which you can use if you
11525write the remote stubs---the code that runs on the remote system to
11526communicate with @value{GDBN}.
11527
11528Other remote targets may be available in your
11529configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11530
6f05cf9f
AC
11531@node KOD
11532@section Kernel Object Display
6f05cf9f 11533@cindex kernel object display
6f05cf9f
AC
11534@cindex KOD
11535
11536Some targets support kernel object display. Using this facility,
11537@value{GDBN} communicates specially with the underlying operating system
11538and can display information about operating system-level objects such as
11539mutexes and other synchronization objects. Exactly which objects can be
11540displayed is determined on a per-OS basis.
11541
3bbe9696 11542@kindex set os
6f05cf9f
AC
11543Use the @code{set os} command to set the operating system. This tells
11544@value{GDBN} which kernel object display module to initialize:
11545
474c8240 11546@smallexample
6f05cf9f 11547(@value{GDBP}) set os cisco
474c8240 11548@end smallexample
6f05cf9f 11549
3bbe9696
EZ
11550@kindex show os
11551The associated command @code{show os} displays the operating system
11552set with the @code{set os} command; if no operating system has been
11553set, @code{show os} will display an empty string @samp{""}.
11554
6f05cf9f
AC
11555If @code{set os} succeeds, @value{GDBN} will display some information
11556about the operating system, and will create a new @code{info} command
11557which can be used to query the target. The @code{info} command is named
11558after the operating system:
c906108c 11559
3bbe9696 11560@kindex info cisco
474c8240 11561@smallexample
6f05cf9f
AC
11562(@value{GDBP}) info cisco
11563List of Cisco Kernel Objects
11564Object Description
11565any Any and all objects
474c8240 11566@end smallexample
6f05cf9f
AC
11567
11568Further subcommands can be used to query about particular objects known
11569by the kernel.
11570
3bbe9696
EZ
11571There is currently no way to determine whether a given operating
11572system is supported other than to try setting it with @kbd{set os
11573@var{name}}, where @var{name} is the name of the operating system you
11574want to try.
6f05cf9f
AC
11575
11576
11577@node Remote Debugging
11578@chapter Debugging remote programs
11579
6b2f586d 11580@menu
07f31aa6 11581* Connecting:: Connecting to a remote target
6b2f586d
AC
11582* Server:: Using the gdbserver program
11583* NetWare:: Using the gdbserve.nlm program
501eef12 11584* Remote configuration:: Remote configuration
6b2f586d 11585* remote stub:: Implementing a remote stub
6b2f586d
AC
11586@end menu
11587
07f31aa6
DJ
11588@node Connecting
11589@section Connecting to a remote target
11590
11591On the @value{GDBN} host machine, you will need an unstripped copy of
11592your program, since @value{GDBN} needs symobl and debugging information.
11593Start up @value{GDBN} as usual, using the name of the local copy of your
11594program as the first argument.
11595
11596@cindex serial line, @code{target remote}
11597If you're using a serial line, you may want to give @value{GDBN} the
11598@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11599(@pxref{Remote configuration, set remotebaud}) before the
11600@code{target} command.
07f31aa6
DJ
11601
11602After that, use @code{target remote} to establish communications with
11603the target machine. Its argument specifies how to communicate---either
11604via a devicename attached to a direct serial line, or a TCP or UDP port
11605(possibly to a terminal server which in turn has a serial line to the
11606target). For example, to use a serial line connected to the device
11607named @file{/dev/ttyb}:
11608
11609@smallexample
11610target remote /dev/ttyb
11611@end smallexample
11612
11613@cindex TCP port, @code{target remote}
11614To use a TCP connection, use an argument of the form
11615@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11616For example, to connect to port 2828 on a
11617terminal server named @code{manyfarms}:
11618
11619@smallexample
11620target remote manyfarms:2828
11621@end smallexample
11622
11623If your remote target is actually running on the same machine as
11624your debugger session (e.g.@: a simulator of your target running on
11625the same host), you can omit the hostname. For example, to connect
11626to port 1234 on your local machine:
11627
11628@smallexample
11629target remote :1234
11630@end smallexample
11631@noindent
11632
11633Note that the colon is still required here.
11634
11635@cindex UDP port, @code{target remote}
11636To use a UDP connection, use an argument of the form
11637@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11638on a terminal server named @code{manyfarms}:
11639
11640@smallexample
11641target remote udp:manyfarms:2828
11642@end smallexample
11643
11644When using a UDP connection for remote debugging, you should keep in mind
11645that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11646busy or unreliable networks, which will cause havoc with your debugging
11647session.
11648
11649Now you can use all the usual commands to examine and change data and to
11650step and continue the remote program.
11651
11652@cindex interrupting remote programs
11653@cindex remote programs, interrupting
11654Whenever @value{GDBN} is waiting for the remote program, if you type the
11655interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11656program. This may or may not succeed, depending in part on the hardware
11657and the serial drivers the remote system uses. If you type the
11658interrupt character once again, @value{GDBN} displays this prompt:
11659
11660@smallexample
11661Interrupted while waiting for the program.
11662Give up (and stop debugging it)? (y or n)
11663@end smallexample
11664
11665If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11666(If you decide you want to try again later, you can use @samp{target
11667remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11668goes back to waiting.
11669
11670@table @code
11671@kindex detach (remote)
11672@item detach
11673When you have finished debugging the remote program, you can use the
11674@code{detach} command to release it from @value{GDBN} control.
11675Detaching from the target normally resumes its execution, but the results
11676will depend on your particular remote stub. After the @code{detach}
11677command, @value{GDBN} is free to connect to another target.
11678
11679@kindex disconnect
11680@item disconnect
11681The @code{disconnect} command behaves like @code{detach}, except that
11682the target is generally not resumed. It will wait for @value{GDBN}
11683(this instance or another one) to connect and continue debugging. After
11684the @code{disconnect} command, @value{GDBN} is again free to connect to
11685another target.
09d4efe1
EZ
11686
11687@cindex send command to remote monitor
11688@kindex monitor
11689@item monitor @var{cmd}
11690This command allows you to send commands directly to the remote
11691monitor.
07f31aa6
DJ
11692@end table
11693
6f05cf9f
AC
11694@node Server
11695@section Using the @code{gdbserver} program
11696
11697@kindex gdbserver
11698@cindex remote connection without stubs
11699@code{gdbserver} is a control program for Unix-like systems, which
11700allows you to connect your program with a remote @value{GDBN} via
11701@code{target remote}---but without linking in the usual debugging stub.
11702
11703@code{gdbserver} is not a complete replacement for the debugging stubs,
11704because it requires essentially the same operating-system facilities
11705that @value{GDBN} itself does. In fact, a system that can run
11706@code{gdbserver} to connect to a remote @value{GDBN} could also run
11707@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11708because it is a much smaller program than @value{GDBN} itself. It is
11709also easier to port than all of @value{GDBN}, so you may be able to get
11710started more quickly on a new system by using @code{gdbserver}.
11711Finally, if you develop code for real-time systems, you may find that
11712the tradeoffs involved in real-time operation make it more convenient to
11713do as much development work as possible on another system, for example
11714by cross-compiling. You can use @code{gdbserver} to make a similar
11715choice for debugging.
11716
11717@value{GDBN} and @code{gdbserver} communicate via either a serial line
11718or a TCP connection, using the standard @value{GDBN} remote serial
11719protocol.
11720
11721@table @emph
11722@item On the target machine,
11723you need to have a copy of the program you want to debug.
11724@code{gdbserver} does not need your program's symbol table, so you can
11725strip the program if necessary to save space. @value{GDBN} on the host
11726system does all the symbol handling.
11727
11728To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11729the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11730syntax is:
11731
11732@smallexample
11733target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11734@end smallexample
11735
11736@var{comm} is either a device name (to use a serial line) or a TCP
11737hostname and portnumber. For example, to debug Emacs with the argument
11738@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11739@file{/dev/com1}:
11740
11741@smallexample
11742target> gdbserver /dev/com1 emacs foo.txt
11743@end smallexample
11744
11745@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11746with it.
11747
11748To use a TCP connection instead of a serial line:
11749
11750@smallexample
11751target> gdbserver host:2345 emacs foo.txt
11752@end smallexample
11753
11754The only difference from the previous example is the first argument,
11755specifying that you are communicating with the host @value{GDBN} via
11756TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11757expect a TCP connection from machine @samp{host} to local TCP port 2345.
11758(Currently, the @samp{host} part is ignored.) You can choose any number
11759you want for the port number as long as it does not conflict with any
11760TCP ports already in use on the target system (for example, @code{23} is
11761reserved for @code{telnet}).@footnote{If you choose a port number that
11762conflicts with another service, @code{gdbserver} prints an error message
11763and exits.} You must use the same port number with the host @value{GDBN}
11764@code{target remote} command.
11765
56460a61
DJ
11766On some targets, @code{gdbserver} can also attach to running programs.
11767This is accomplished via the @code{--attach} argument. The syntax is:
11768
11769@smallexample
11770target> gdbserver @var{comm} --attach @var{pid}
11771@end smallexample
11772
11773@var{pid} is the process ID of a currently running process. It isn't necessary
11774to point @code{gdbserver} at a binary for the running process.
11775
b1fe9455
DJ
11776@pindex pidof
11777@cindex attach to a program by name
11778You can debug processes by name instead of process ID if your target has the
11779@code{pidof} utility:
11780
11781@smallexample
11782target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11783@end smallexample
11784
11785In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11786has multiple threads, most versions of @code{pidof} support the
11787@code{-s} option to only return the first process ID.
11788
07f31aa6
DJ
11789@item On the host machine,
11790connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11791For TCP connections, you must start up @code{gdbserver} prior to using
11792the @code{target remote} command. Otherwise you may get an error whose
11793text depends on the host system, but which usually looks something like
07f31aa6
DJ
11794@samp{Connection refused}. You don't need to use the @code{load}
11795command in @value{GDBN} when using gdbserver, since the program is
11796already on the target.
11797
6f05cf9f
AC
11798@end table
11799
11800@node NetWare
11801@section Using the @code{gdbserve.nlm} program
11802
11803@kindex gdbserve.nlm
11804@code{gdbserve.nlm} is a control program for NetWare systems, which
11805allows you to connect your program with a remote @value{GDBN} via
11806@code{target remote}.
11807
11808@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11809using the standard @value{GDBN} remote serial protocol.
11810
11811@table @emph
11812@item On the target machine,
11813you need to have a copy of the program you want to debug.
11814@code{gdbserve.nlm} does not need your program's symbol table, so you
11815can strip the program if necessary to save space. @value{GDBN} on the
11816host system does all the symbol handling.
11817
11818To use the server, you must tell it how to communicate with
11819@value{GDBN}; the name of your program; and the arguments for your
11820program. The syntax is:
11821
11822@smallexample
11823load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11824 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11825@end smallexample
11826
11827@var{board} and @var{port} specify the serial line; @var{baud} specifies
11828the baud rate used by the connection. @var{port} and @var{node} default
11829to 0, @var{baud} defaults to 9600@dmn{bps}.
11830
11831For example, to debug Emacs with the argument @samp{foo.txt}and
11832communicate with @value{GDBN} over serial port number 2 or board 1
11833using a 19200@dmn{bps} connection:
11834
11835@smallexample
11836load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11837@end smallexample
11838
07f31aa6
DJ
11839@item
11840On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11841Connecting to a remote target}).
6f05cf9f 11842
6f05cf9f
AC
11843@end table
11844
501eef12
AC
11845@node Remote configuration
11846@section Remote configuration
11847
9c16f35a
EZ
11848@kindex set remote
11849@kindex show remote
11850This section documents the configuration options available when
11851debugging remote programs. For the options related to the File I/O
11852extensions of the remote protocol, see @ref{The system call,
11853system-call-allowed}.
501eef12
AC
11854
11855@table @code
9c16f35a
EZ
11856@item set remoteaddresssize @var{bits}
11857@cindex adress size for remote targets
11858@cindex bits in remote address
11859Set the maximum size of address in a memory packet to the specified
11860number of bits. @value{GDBN} will mask off the address bits above
11861that number, when it passes addresses to the remote target. The
11862default value is the number of bits in the target's address.
11863
11864@item show remoteaddresssize
11865Show the current value of remote address size in bits.
11866
11867@item set remotebaud @var{n}
11868@cindex baud rate for remote targets
11869Set the baud rate for the remote serial I/O to @var{n} baud. The
11870value is used to set the speed of the serial port used for debugging
11871remote targets.
11872
11873@item show remotebaud
11874Show the current speed of the remote connection.
11875
11876@item set remotebreak
11877@cindex interrupt remote programs
11878@cindex BREAK signal instead of Ctrl-C
11879If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
11880when you press the @key{Ctrl-C} key to interrupt the program running
11881on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
11882character instead. The default is off, since most remote systems
11883expect to see @samp{Ctrl-C} as the interrupt signal.
11884
11885@item show remotebreak
11886Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
11887interrupt the remote program.
11888
11889@item set remotedebug
11890@cindex debug remote protocol
11891@cindex remote protocol debugging
11892@cindex display remote packets
11893Control the debugging of the remote protocol. When enabled, each
11894packet sent to or received from the remote target is displayed. The
11895defaults is off.
11896
11897@item show remotedebug
11898Show the current setting of the remote protocol debugging.
11899
11900@item set remotedevice @var{device}
11901@cindex serial port name
11902Set the name of the serial port through which to communicate to the
11903remote target to @var{device}. This is the device used by
11904@value{GDBN} to open the serial communications line to the remote
11905target. There's no default, so you must set a valid port name for the
11906remote serial communications to work. (Some varieties of the
11907@code{target} command accept the port name as part of their
11908arguments.)
11909
11910@item show remotedevice
11911Show the current name of the serial port.
11912
11913@item set remotelogbase @var{base}
11914Set the base (a.k.a.@: radix) of logging serial protocol
11915communications to @var{base}. Supported values of @var{base} are:
11916@code{ascii}, @code{octal}, and @code{hex}. The default is
11917@code{ascii}.
11918
11919@item show remotelogbase
11920Show the current setting of the radix for logging remote serial
11921protocol.
11922
11923@item set remotelogfile @var{file}
11924@cindex record serial communications on file
11925Record remote serial communications on the named @var{file}. The
11926default is not to record at all.
11927
11928@item show remotelogfile.
11929Show the current setting of the file name on which to record the
11930serial communications.
11931
11932@item set remotetimeout @var{num}
11933@cindex timeout for serial communications
11934@cindex remote timeout
11935Set the timeout limit to wait for the remote target to respond to
11936@var{num} seconds. The default is 2 seconds.
11937
11938@item show remotetimeout
11939Show the current number of seconds to wait for the remote target
11940responses.
11941
11942@cindex limit hardware breakpoints and watchpoints
11943@cindex remote target, limit break- and watchpoints
501eef12
AC
11944@anchor{set remote hardware-watchpoint-limit}
11945@anchor{set remote hardware-breakpoint-limit}
11946@item set remote hardware-watchpoint-limit @var{limit}
11947@itemx set remote hardware-breakpoint-limit @var{limit}
11948Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
11949watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
11950
11951@item set remote fetch-register-packet
11952@itemx set remote set-register-packet
11953@itemx set remote P-packet
11954@itemx set remote p-packet
11955@cindex P-packet
11956@cindex fetch registers from remote targets
11957@cindex set registers in remote targets
11958Determine whether @value{GDBN} can set and fetch registers from the
11959remote target using the @samp{P} packets. The default depends on the
11960remote stub's support of the @samp{P} packets (@value{GDBN} queries
11961the stub when this packet is first required).
11962
11963@item show remote fetch-register-packet
11964@itemx show remote set-register-packet
11965@itemx show remote P-packet
11966@itemx show remote p-packet
11967Show the current setting of using the @samp{P} packets for setting and
11968fetching registers from the remote target.
11969
11970@cindex binary downloads
11971@cindex X-packet
11972@item set remote binary-download-packet
11973@itemx set remote X-packet
11974Determine whether @value{GDBN} sends downloads in binary mode using
11975the @samp{X} packets. The default is on.
11976
11977@item show remote binary-download-packet
11978@itemx show remote X-packet
11979Show the current setting of using the @samp{X} packets for binary
11980downloads.
11981
11982@item set remote read-aux-vector-packet
11983@cindex auxiliary vector of remote target
11984@cindex @code{auxv}, and remote targets
11985Set the use of the remote protocol's @samp{qPart:auxv:read} (target
11986auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
11987remote target's @dfn{auxiliary vector}, see @ref{OS Information,
11988Auxiliary Vector}. The default setting depends on the remote stub's
11989support of this request (@value{GDBN} queries the stub when this
11990request is first required). @xref{General Query Packets, qPart}, for
11991more information about this request.
9c16f35a
EZ
11992
11993@item show remote read-aux-vector-packet
11994Show the current setting of use of the @samp{qPart:auxv:read} request.
11995
11996@item set remote symbol-lookup-packet
11997@cindex remote symbol lookup request
11998Set the use of the remote protocol's @samp{qSymbol} (target symbol
11999lookup) request. This request is used to communicate symbol
12000information to the remote target, e.g., whenever a new shared library
12001is loaded by the remote (@pxref{Files, shared libraries}). The
12002default setting depends on the remote stub's support of this request
12003(@value{GDBN} queries the stub when this request is first required).
12004@xref{General Query Packets, qSymbol}, for more information about this
12005request.
12006
12007@item show remote symbol-lookup-packet
12008Show the current setting of use of the @samp{qSymbol} request.
12009
12010@item set remote verbose-resume-packet
12011@cindex resume remote target
12012@cindex signal thread, and remote targets
12013@cindex single-step thread, and remote targets
12014@cindex thread-specific operations on remote targets
12015Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12016request. This request is used to resume specific threads in the
12017remote target, and to single-step or signal them. The default setting
12018depends on the remote stub's support of this request (@value{GDBN}
12019queries the stub when this request is first required). This setting
12020affects debugging of multithreaded programs: if @samp{vCont} cannot be
12021used, @value{GDBN} might be unable to single-step a specific thread,
12022especially under @code{set scheduler-locking off}; it is also
12023impossible to pause a specific thread. @xref{Packets, vCont}, for
12024more details.
12025
12026@item show remote verbose-resume-packet
12027Show the current setting of use of the @samp{vCont} request
12028
12029@item set remote software-breakpoint-packet
12030@itemx set remote hardware-breakpoint-packet
12031@itemx set remote write-watchpoint-packet
12032@itemx set remote read-watchpoint-packet
12033@itemx set remote access-watchpoint-packet
12034@itemx set remote Z-packet
12035@cindex Z-packet
12036@cindex remote hardware breakpoints and watchpoints
12037These commands enable or disable the use of @samp{Z} packets for
12038setting breakpoints and watchpoints in the remote target. The default
12039depends on the remote stub's support of the @samp{Z} packets
12040(@value{GDBN} queries the stub when each packet is first required).
12041The command @code{set remote Z-packet}, kept for back-compatibility,
12042turns on or off all the features that require the use of @samp{Z}
12043packets.
12044
12045@item show remote software-breakpoint-packet
12046@itemx show remote hardware-breakpoint-packet
12047@itemx show remote write-watchpoint-packet
12048@itemx show remote read-watchpoint-packet
12049@itemx show remote access-watchpoint-packet
12050@itemx show remote Z-packet
12051Show the current setting of @samp{Z} packets usage.
501eef12
AC
12052@end table
12053
6f05cf9f
AC
12054@node remote stub
12055@section Implementing a remote stub
7a292a7a 12056
8e04817f
AC
12057@cindex debugging stub, example
12058@cindex remote stub, example
12059@cindex stub example, remote debugging
12060The stub files provided with @value{GDBN} implement the target side of the
12061communication protocol, and the @value{GDBN} side is implemented in the
12062@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12063these subroutines to communicate, and ignore the details. (If you're
12064implementing your own stub file, you can still ignore the details: start
12065with one of the existing stub files. @file{sparc-stub.c} is the best
12066organized, and therefore the easiest to read.)
12067
104c1213
JM
12068@cindex remote serial debugging, overview
12069To debug a program running on another machine (the debugging
12070@dfn{target} machine), you must first arrange for all the usual
12071prerequisites for the program to run by itself. For example, for a C
12072program, you need:
c906108c 12073
104c1213
JM
12074@enumerate
12075@item
12076A startup routine to set up the C runtime environment; these usually
12077have a name like @file{crt0}. The startup routine may be supplied by
12078your hardware supplier, or you may have to write your own.
96baa820 12079
5d161b24 12080@item
d4f3574e 12081A C subroutine library to support your program's
104c1213 12082subroutine calls, notably managing input and output.
96baa820 12083
104c1213
JM
12084@item
12085A way of getting your program to the other machine---for example, a
12086download program. These are often supplied by the hardware
12087manufacturer, but you may have to write your own from hardware
12088documentation.
12089@end enumerate
96baa820 12090
104c1213
JM
12091The next step is to arrange for your program to use a serial port to
12092communicate with the machine where @value{GDBN} is running (the @dfn{host}
12093machine). In general terms, the scheme looks like this:
96baa820 12094
104c1213
JM
12095@table @emph
12096@item On the host,
12097@value{GDBN} already understands how to use this protocol; when everything
12098else is set up, you can simply use the @samp{target remote} command
12099(@pxref{Targets,,Specifying a Debugging Target}).
12100
12101@item On the target,
12102you must link with your program a few special-purpose subroutines that
12103implement the @value{GDBN} remote serial protocol. The file containing these
12104subroutines is called a @dfn{debugging stub}.
12105
12106On certain remote targets, you can use an auxiliary program
12107@code{gdbserver} instead of linking a stub into your program.
12108@xref{Server,,Using the @code{gdbserver} program}, for details.
12109@end table
96baa820 12110
104c1213
JM
12111The debugging stub is specific to the architecture of the remote
12112machine; for example, use @file{sparc-stub.c} to debug programs on
12113@sc{sparc} boards.
96baa820 12114
104c1213
JM
12115@cindex remote serial stub list
12116These working remote stubs are distributed with @value{GDBN}:
96baa820 12117
104c1213
JM
12118@table @code
12119
12120@item i386-stub.c
41afff9a 12121@cindex @file{i386-stub.c}
104c1213
JM
12122@cindex Intel
12123@cindex i386
12124For Intel 386 and compatible architectures.
12125
12126@item m68k-stub.c
41afff9a 12127@cindex @file{m68k-stub.c}
104c1213
JM
12128@cindex Motorola 680x0
12129@cindex m680x0
12130For Motorola 680x0 architectures.
12131
12132@item sh-stub.c
41afff9a 12133@cindex @file{sh-stub.c}
172c2a43 12134@cindex Renesas
104c1213 12135@cindex SH
172c2a43 12136For Renesas SH architectures.
104c1213
JM
12137
12138@item sparc-stub.c
41afff9a 12139@cindex @file{sparc-stub.c}
104c1213
JM
12140@cindex Sparc
12141For @sc{sparc} architectures.
12142
12143@item sparcl-stub.c
41afff9a 12144@cindex @file{sparcl-stub.c}
104c1213
JM
12145@cindex Fujitsu
12146@cindex SparcLite
12147For Fujitsu @sc{sparclite} architectures.
12148
12149@end table
12150
12151The @file{README} file in the @value{GDBN} distribution may list other
12152recently added stubs.
12153
12154@menu
12155* Stub Contents:: What the stub can do for you
12156* Bootstrapping:: What you must do for the stub
12157* Debug Session:: Putting it all together
104c1213
JM
12158@end menu
12159
6d2ebf8b 12160@node Stub Contents
6f05cf9f 12161@subsection What the stub can do for you
104c1213
JM
12162
12163@cindex remote serial stub
12164The debugging stub for your architecture supplies these three
12165subroutines:
12166
12167@table @code
12168@item set_debug_traps
4644b6e3 12169@findex set_debug_traps
104c1213
JM
12170@cindex remote serial stub, initialization
12171This routine arranges for @code{handle_exception} to run when your
12172program stops. You must call this subroutine explicitly near the
12173beginning of your program.
12174
12175@item handle_exception
4644b6e3 12176@findex handle_exception
104c1213
JM
12177@cindex remote serial stub, main routine
12178This is the central workhorse, but your program never calls it
12179explicitly---the setup code arranges for @code{handle_exception} to
12180run when a trap is triggered.
12181
12182@code{handle_exception} takes control when your program stops during
12183execution (for example, on a breakpoint), and mediates communications
12184with @value{GDBN} on the host machine. This is where the communications
12185protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12186representative on the target machine. It begins by sending summary
104c1213
JM
12187information on the state of your program, then continues to execute,
12188retrieving and transmitting any information @value{GDBN} needs, until you
12189execute a @value{GDBN} command that makes your program resume; at that point,
12190@code{handle_exception} returns control to your own code on the target
5d161b24 12191machine.
104c1213
JM
12192
12193@item breakpoint
12194@cindex @code{breakpoint} subroutine, remote
12195Use this auxiliary subroutine to make your program contain a
12196breakpoint. Depending on the particular situation, this may be the only
12197way for @value{GDBN} to get control. For instance, if your target
12198machine has some sort of interrupt button, you won't need to call this;
12199pressing the interrupt button transfers control to
12200@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12201simply receiving characters on the serial port may also trigger a trap;
12202again, in that situation, you don't need to call @code{breakpoint} from
12203your own program---simply running @samp{target remote} from the host
5d161b24 12204@value{GDBN} session gets control.
104c1213
JM
12205
12206Call @code{breakpoint} if none of these is true, or if you simply want
12207to make certain your program stops at a predetermined point for the
12208start of your debugging session.
12209@end table
12210
6d2ebf8b 12211@node Bootstrapping
6f05cf9f 12212@subsection What you must do for the stub
104c1213
JM
12213
12214@cindex remote stub, support routines
12215The debugging stubs that come with @value{GDBN} are set up for a particular
12216chip architecture, but they have no information about the rest of your
12217debugging target machine.
12218
12219First of all you need to tell the stub how to communicate with the
12220serial port.
12221
12222@table @code
12223@item int getDebugChar()
4644b6e3 12224@findex getDebugChar
104c1213
JM
12225Write this subroutine to read a single character from the serial port.
12226It may be identical to @code{getchar} for your target system; a
12227different name is used to allow you to distinguish the two if you wish.
12228
12229@item void putDebugChar(int)
4644b6e3 12230@findex putDebugChar
104c1213 12231Write this subroutine to write a single character to the serial port.
5d161b24 12232It may be identical to @code{putchar} for your target system; a
104c1213
JM
12233different name is used to allow you to distinguish the two if you wish.
12234@end table
12235
12236@cindex control C, and remote debugging
12237@cindex interrupting remote targets
12238If you want @value{GDBN} to be able to stop your program while it is
12239running, you need to use an interrupt-driven serial driver, and arrange
12240for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12241character). That is the character which @value{GDBN} uses to tell the
12242remote system to stop.
12243
12244Getting the debugging target to return the proper status to @value{GDBN}
12245probably requires changes to the standard stub; one quick and dirty way
12246is to just execute a breakpoint instruction (the ``dirty'' part is that
12247@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12248
12249Other routines you need to supply are:
12250
12251@table @code
12252@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12253@findex exceptionHandler
104c1213
JM
12254Write this function to install @var{exception_address} in the exception
12255handling tables. You need to do this because the stub does not have any
12256way of knowing what the exception handling tables on your target system
12257are like (for example, the processor's table might be in @sc{rom},
12258containing entries which point to a table in @sc{ram}).
12259@var{exception_number} is the exception number which should be changed;
12260its meaning is architecture-dependent (for example, different numbers
12261might represent divide by zero, misaligned access, etc). When this
12262exception occurs, control should be transferred directly to
12263@var{exception_address}, and the processor state (stack, registers,
12264and so on) should be just as it is when a processor exception occurs. So if
12265you want to use a jump instruction to reach @var{exception_address}, it
12266should be a simple jump, not a jump to subroutine.
12267
12268For the 386, @var{exception_address} should be installed as an interrupt
12269gate so that interrupts are masked while the handler runs. The gate
12270should be at privilege level 0 (the most privileged level). The
12271@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12272help from @code{exceptionHandler}.
12273
12274@item void flush_i_cache()
4644b6e3 12275@findex flush_i_cache
d4f3574e 12276On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12277instruction cache, if any, on your target machine. If there is no
12278instruction cache, this subroutine may be a no-op.
12279
12280On target machines that have instruction caches, @value{GDBN} requires this
12281function to make certain that the state of your program is stable.
12282@end table
12283
12284@noindent
12285You must also make sure this library routine is available:
12286
12287@table @code
12288@item void *memset(void *, int, int)
4644b6e3 12289@findex memset
104c1213
JM
12290This is the standard library function @code{memset} that sets an area of
12291memory to a known value. If you have one of the free versions of
12292@code{libc.a}, @code{memset} can be found there; otherwise, you must
12293either obtain it from your hardware manufacturer, or write your own.
12294@end table
12295
12296If you do not use the GNU C compiler, you may need other standard
12297library subroutines as well; this varies from one stub to another,
12298but in general the stubs are likely to use any of the common library
d4f3574e 12299subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12300
12301
6d2ebf8b 12302@node Debug Session
6f05cf9f 12303@subsection Putting it all together
104c1213
JM
12304
12305@cindex remote serial debugging summary
12306In summary, when your program is ready to debug, you must follow these
12307steps.
12308
12309@enumerate
12310@item
6d2ebf8b 12311Make sure you have defined the supporting low-level routines
104c1213
JM
12312(@pxref{Bootstrapping,,What you must do for the stub}):
12313@display
12314@code{getDebugChar}, @code{putDebugChar},
12315@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12316@end display
12317
12318@item
12319Insert these lines near the top of your program:
12320
474c8240 12321@smallexample
104c1213
JM
12322set_debug_traps();
12323breakpoint();
474c8240 12324@end smallexample
104c1213
JM
12325
12326@item
12327For the 680x0 stub only, you need to provide a variable called
12328@code{exceptionHook}. Normally you just use:
12329
474c8240 12330@smallexample
104c1213 12331void (*exceptionHook)() = 0;
474c8240 12332@end smallexample
104c1213 12333
d4f3574e 12334@noindent
104c1213 12335but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12336function in your program, that function is called when
104c1213
JM
12337@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12338error). The function indicated by @code{exceptionHook} is called with
12339one parameter: an @code{int} which is the exception number.
12340
12341@item
12342Compile and link together: your program, the @value{GDBN} debugging stub for
12343your target architecture, and the supporting subroutines.
12344
12345@item
12346Make sure you have a serial connection between your target machine and
12347the @value{GDBN} host, and identify the serial port on the host.
12348
12349@item
12350@c The "remote" target now provides a `load' command, so we should
12351@c document that. FIXME.
12352Download your program to your target machine (or get it there by
12353whatever means the manufacturer provides), and start it.
12354
12355@item
07f31aa6
DJ
12356Start @value{GDBN} on the host, and connect to the target
12357(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12358
104c1213
JM
12359@end enumerate
12360
8e04817f
AC
12361@node Configurations
12362@chapter Configuration-Specific Information
104c1213 12363
8e04817f
AC
12364While nearly all @value{GDBN} commands are available for all native and
12365cross versions of the debugger, there are some exceptions. This chapter
12366describes things that are only available in certain configurations.
104c1213 12367
8e04817f
AC
12368There are three major categories of configurations: native
12369configurations, where the host and target are the same, embedded
12370operating system configurations, which are usually the same for several
12371different processor architectures, and bare embedded processors, which
12372are quite different from each other.
104c1213 12373
8e04817f
AC
12374@menu
12375* Native::
12376* Embedded OS::
12377* Embedded Processors::
12378* Architectures::
12379@end menu
104c1213 12380
8e04817f
AC
12381@node Native
12382@section Native
104c1213 12383
8e04817f
AC
12384This section describes details specific to particular native
12385configurations.
6cf7e474 12386
8e04817f
AC
12387@menu
12388* HP-UX:: HP-UX
7561d450 12389* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12390* SVR4 Process Information:: SVR4 process information
12391* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12392* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12393* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12394* Neutrino:: Features specific to QNX Neutrino
8e04817f 12395@end menu
6cf7e474 12396
8e04817f
AC
12397@node HP-UX
12398@subsection HP-UX
104c1213 12399
8e04817f
AC
12400On HP-UX systems, if you refer to a function or variable name that
12401begins with a dollar sign, @value{GDBN} searches for a user or system
12402name first, before it searches for a convenience variable.
104c1213 12403
9c16f35a 12404
7561d450
MK
12405@node BSD libkvm Interface
12406@subsection BSD libkvm Interface
12407
12408@cindex libkvm
12409@cindex kernel memory image
12410@cindex kernel crash dump
12411
12412BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12413interface that provides a uniform interface for accessing kernel virtual
12414memory images, including live systems and crash dumps. @value{GDBN}
12415uses this interface to allow you to debug live kernels and kernel crash
12416dumps on many native BSD configurations. This is implemented as a
12417special @code{kvm} debugging target. For debugging a live system, load
12418the currently running kernel into @value{GDBN} and connect to the
12419@code{kvm} target:
12420
12421@smallexample
12422(@value{GDBP}) @b{target kvm}
12423@end smallexample
12424
12425For debugging crash dumps, provide the file name of the crash dump as an
12426argument:
12427
12428@smallexample
12429(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12430@end smallexample
12431
12432Once connected to the @code{kvm} target, the following commands are
12433available:
12434
12435@table @code
12436@kindex kvm
12437@item kvm pcb
721c2651 12438Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12439
12440@item kvm proc
12441Set current context from proc address. This command isn't available on
12442modern FreeBSD systems.
12443@end table
12444
8e04817f
AC
12445@node SVR4 Process Information
12446@subsection SVR4 process information
60bf7e09
EZ
12447@cindex /proc
12448@cindex examine process image
12449@cindex process info via @file{/proc}
104c1213 12450
60bf7e09
EZ
12451Many versions of SVR4 and compatible systems provide a facility called
12452@samp{/proc} that can be used to examine the image of a running
12453process using file-system subroutines. If @value{GDBN} is configured
12454for an operating system with this facility, the command @code{info
12455proc} is available to report information about the process running
12456your program, or about any process running on your system. @code{info
12457proc} works only on SVR4 systems that include the @code{procfs} code.
12458This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12459Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12460
8e04817f
AC
12461@table @code
12462@kindex info proc
60bf7e09 12463@cindex process ID
8e04817f 12464@item info proc
60bf7e09
EZ
12465@itemx info proc @var{process-id}
12466Summarize available information about any running process. If a
12467process ID is specified by @var{process-id}, display information about
12468that process; otherwise display information about the program being
12469debugged. The summary includes the debugged process ID, the command
12470line used to invoke it, its current working directory, and its
12471executable file's absolute file name.
12472
12473On some systems, @var{process-id} can be of the form
12474@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12475within a process. If the optional @var{pid} part is missing, it means
12476a thread from the process being debugged (the leading @samp{/} still
12477needs to be present, or else @value{GDBN} will interpret the number as
12478a process ID rather than a thread ID).
6cf7e474 12479
8e04817f 12480@item info proc mappings
60bf7e09
EZ
12481@cindex memory address space mappings
12482Report the memory address space ranges accessible in the program, with
12483information on whether the process has read, write, or execute access
12484rights to each range. On @sc{gnu}/Linux systems, each memory range
12485includes the object file which is mapped to that range, instead of the
12486memory access rights to that range.
12487
12488@item info proc stat
12489@itemx info proc status
12490@cindex process detailed status information
12491These subcommands are specific to @sc{gnu}/Linux systems. They show
12492the process-related information, including the user ID and group ID;
12493how many threads are there in the process; its virtual memory usage;
12494the signals that are pending, blocked, and ignored; its TTY; its
12495consumption of system and user time; its stack size; its @samp{nice}
12496value; etc. For more information, see the @samp{proc(5)} man page
12497(type @kbd{man 5 proc} from your shell prompt).
12498
12499@item info proc all
12500Show all the information about the process described under all of the
12501above @code{info proc} subcommands.
12502
8e04817f
AC
12503@ignore
12504@comment These sub-options of 'info proc' were not included when
12505@comment procfs.c was re-written. Keep their descriptions around
12506@comment against the day when someone finds the time to put them back in.
12507@kindex info proc times
12508@item info proc times
12509Starting time, user CPU time, and system CPU time for your program and
12510its children.
6cf7e474 12511
8e04817f
AC
12512@kindex info proc id
12513@item info proc id
12514Report on the process IDs related to your program: its own process ID,
12515the ID of its parent, the process group ID, and the session ID.
8e04817f 12516@end ignore
721c2651
EZ
12517
12518@item set procfs-trace
12519@kindex set procfs-trace
12520@cindex @code{procfs} API calls
12521This command enables and disables tracing of @code{procfs} API calls.
12522
12523@item show procfs-trace
12524@kindex show procfs-trace
12525Show the current state of @code{procfs} API call tracing.
12526
12527@item set procfs-file @var{file}
12528@kindex set procfs-file
12529Tell @value{GDBN} to write @code{procfs} API trace to the named
12530@var{file}. @value{GDBN} appends the trace info to the previous
12531contents of the file. The default is to display the trace on the
12532standard output.
12533
12534@item show procfs-file
12535@kindex show procfs-file
12536Show the file to which @code{procfs} API trace is written.
12537
12538@item proc-trace-entry
12539@itemx proc-trace-exit
12540@itemx proc-untrace-entry
12541@itemx proc-untrace-exit
12542@kindex proc-trace-entry
12543@kindex proc-trace-exit
12544@kindex proc-untrace-entry
12545@kindex proc-untrace-exit
12546These commands enable and disable tracing of entries into and exits
12547from the @code{syscall} interface.
12548
12549@item info pidlist
12550@kindex info pidlist
12551@cindex process list, QNX Neutrino
12552For QNX Neutrino only, this command displays the list of all the
12553processes and all the threads within each process.
12554
12555@item info meminfo
12556@kindex info meminfo
12557@cindex mapinfo list, QNX Neutrino
12558For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12559@end table
104c1213 12560
8e04817f
AC
12561@node DJGPP Native
12562@subsection Features for Debugging @sc{djgpp} Programs
12563@cindex @sc{djgpp} debugging
12564@cindex native @sc{djgpp} debugging
12565@cindex MS-DOS-specific commands
104c1213 12566
8e04817f
AC
12567@sc{djgpp} is the port of @sc{gnu} development tools to MS-DOS and
12568MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12569that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12570top of real-mode DOS systems and their emulations.
104c1213 12571
8e04817f
AC
12572@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12573defines a few commands specific to the @sc{djgpp} port. This
12574subsection describes those commands.
104c1213 12575
8e04817f
AC
12576@table @code
12577@kindex info dos
12578@item info dos
12579This is a prefix of @sc{djgpp}-specific commands which print
12580information about the target system and important OS structures.
f1251bdd 12581
8e04817f
AC
12582@kindex sysinfo
12583@cindex MS-DOS system info
12584@cindex free memory information (MS-DOS)
12585@item info dos sysinfo
12586This command displays assorted information about the underlying
12587platform: the CPU type and features, the OS version and flavor, the
12588DPMI version, and the available conventional and DPMI memory.
104c1213 12589
8e04817f
AC
12590@cindex GDT
12591@cindex LDT
12592@cindex IDT
12593@cindex segment descriptor tables
12594@cindex descriptor tables display
12595@item info dos gdt
12596@itemx info dos ldt
12597@itemx info dos idt
12598These 3 commands display entries from, respectively, Global, Local,
12599and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12600tables are data structures which store a descriptor for each segment
12601that is currently in use. The segment's selector is an index into a
12602descriptor table; the table entry for that index holds the
12603descriptor's base address and limit, and its attributes and access
12604rights.
104c1213 12605
8e04817f
AC
12606A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12607segment (used for both data and the stack), and a DOS segment (which
12608allows access to DOS/BIOS data structures and absolute addresses in
12609conventional memory). However, the DPMI host will usually define
12610additional segments in order to support the DPMI environment.
d4f3574e 12611
8e04817f
AC
12612@cindex garbled pointers
12613These commands allow to display entries from the descriptor tables.
12614Without an argument, all entries from the specified table are
12615displayed. An argument, which should be an integer expression, means
12616display a single entry whose index is given by the argument. For
12617example, here's a convenient way to display information about the
12618debugged program's data segment:
104c1213 12619
8e04817f
AC
12620@smallexample
12621@exdent @code{(@value{GDBP}) info dos ldt $ds}
12622@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12623@end smallexample
104c1213 12624
8e04817f
AC
12625@noindent
12626This comes in handy when you want to see whether a pointer is outside
12627the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12628
8e04817f
AC
12629@cindex page tables display (MS-DOS)
12630@item info dos pde
12631@itemx info dos pte
12632These two commands display entries from, respectively, the Page
12633Directory and the Page Tables. Page Directories and Page Tables are
12634data structures which control how virtual memory addresses are mapped
12635into physical addresses. A Page Table includes an entry for every
12636page of memory that is mapped into the program's address space; there
12637may be several Page Tables, each one holding up to 4096 entries. A
12638Page Directory has up to 4096 entries, one each for every Page Table
12639that is currently in use.
104c1213 12640
8e04817f
AC
12641Without an argument, @kbd{info dos pde} displays the entire Page
12642Directory, and @kbd{info dos pte} displays all the entries in all of
12643the Page Tables. An argument, an integer expression, given to the
12644@kbd{info dos pde} command means display only that entry from the Page
12645Directory table. An argument given to the @kbd{info dos pte} command
12646means display entries from a single Page Table, the one pointed to by
12647the specified entry in the Page Directory.
104c1213 12648
8e04817f
AC
12649@cindex direct memory access (DMA) on MS-DOS
12650These commands are useful when your program uses @dfn{DMA} (Direct
12651Memory Access), which needs physical addresses to program the DMA
12652controller.
104c1213 12653
8e04817f 12654These commands are supported only with some DPMI servers.
104c1213 12655
8e04817f
AC
12656@cindex physical address from linear address
12657@item info dos address-pte @var{addr}
12658This command displays the Page Table entry for a specified linear
12659address. The argument linear address @var{addr} should already have the
12660appropriate segment's base address added to it, because this command
12661accepts addresses which may belong to @emph{any} segment. For
12662example, here's how to display the Page Table entry for the page where
12663the variable @code{i} is stored:
104c1213 12664
b383017d 12665@smallexample
8e04817f
AC
12666@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12667@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12668@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12669@end smallexample
104c1213 12670
8e04817f
AC
12671@noindent
12672This says that @code{i} is stored at offset @code{0xd30} from the page
12673whose physical base address is @code{0x02698000}, and prints all the
12674attributes of that page.
104c1213 12675
8e04817f
AC
12676Note that you must cast the addresses of variables to a @code{char *},
12677since otherwise the value of @code{__djgpp_base_address}, the base
12678address of all variables and functions in a @sc{djgpp} program, will
12679be added using the rules of C pointer arithmetics: if @code{i} is
12680declared an @code{int}, @value{GDBN} will add 4 times the value of
12681@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12682
8e04817f
AC
12683Here's another example, it displays the Page Table entry for the
12684transfer buffer:
104c1213 12685
8e04817f
AC
12686@smallexample
12687@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12688@exdent @code{Page Table entry for address 0x29110:}
12689@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12690@end smallexample
104c1213 12691
8e04817f
AC
12692@noindent
12693(The @code{+ 3} offset is because the transfer buffer's address is the
126943rd member of the @code{_go32_info_block} structure.) The output of
12695this command clearly shows that addresses in conventional memory are
12696mapped 1:1, i.e.@: the physical and linear addresses are identical.
104c1213 12697
8e04817f
AC
12698This command is supported only with some DPMI servers.
12699@end table
104c1213 12700
a8f24a35
EZ
12701In addition to native debugging, the DJGPP port supports remote
12702debugging via a serial data link. The following commands are specific
12703to remote serial debugging in the DJGPP port of @value{GDBN}.
12704
12705@table @code
12706@kindex set com1base
12707@kindex set com1irq
12708@kindex set com2base
12709@kindex set com2irq
12710@kindex set com3base
12711@kindex set com3irq
12712@kindex set com4base
12713@kindex set com4irq
12714@item set com1base @var{addr}
12715This command sets the base I/O port address of the @file{COM1} serial
12716port.
12717
12718@item set com1irq @var{irq}
12719This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12720for the @file{COM1} serial port.
12721
12722There are similar commands @samp{set com2base}, @samp{set com3irq},
12723etc.@: for setting the port address and the @code{IRQ} lines for the
12724other 3 COM ports.
12725
12726@kindex show com1base
12727@kindex show com1irq
12728@kindex show com2base
12729@kindex show com2irq
12730@kindex show com3base
12731@kindex show com3irq
12732@kindex show com4base
12733@kindex show com4irq
12734The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12735display the current settings of the base address and the @code{IRQ}
12736lines used by the COM ports.
12737@end table
12738
12739
78c47bea
PM
12740@node Cygwin Native
12741@subsection Features for Debugging MS Windows PE executables
12742@cindex MS Windows debugging
12743@cindex native Cygwin debugging
12744@cindex Cygwin-specific commands
12745
be448670
CF
12746@value{GDBN} supports native debugging of MS Windows programs, including
12747DLLs with and without symbolic debugging information. There are various
12748additional Cygwin-specific commands, described in this subsection. The
12749subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12750that have no debugging symbols.
12751
78c47bea
PM
12752
12753@table @code
12754@kindex info w32
12755@item info w32
12756This is a prefix of MS Windows specific commands which print
12757information about the target system and important OS structures.
12758
12759@item info w32 selector
12760This command displays information returned by
12761the Win32 API @code{GetThreadSelectorEntry} function.
12762It takes an optional argument that is evaluated to
12763a long value to give the information about this given selector.
12764Without argument, this command displays information
12765about the the six segment registers.
12766
12767@kindex info dll
12768@item info dll
12769This is a Cygwin specific alias of info shared.
12770
12771@kindex dll-symbols
12772@item dll-symbols
12773This command loads symbols from a dll similarly to
12774add-sym command but without the need to specify a base address.
12775
b383017d 12776@kindex set new-console
78c47bea 12777@item set new-console @var{mode}
b383017d 12778If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12779be started in a new console on next start.
12780If @var{mode} is @code{off}i, the debuggee will
12781be started in the same console as the debugger.
12782
12783@kindex show new-console
12784@item show new-console
12785Displays whether a new console is used
12786when the debuggee is started.
12787
12788@kindex set new-group
12789@item set new-group @var{mode}
12790This boolean value controls whether the debuggee should
12791start a new group or stay in the same group as the debugger.
12792This affects the way the Windows OS handles
12793Ctrl-C.
12794
12795@kindex show new-group
12796@item show new-group
12797Displays current value of new-group boolean.
12798
12799@kindex set debugevents
12800@item set debugevents
12801This boolean value adds debug output concerning events seen by the debugger.
12802
12803@kindex set debugexec
12804@item set debugexec
b383017d 12805This boolean value adds debug output concerning execute events
78c47bea
PM
12806seen by the debugger.
12807
12808@kindex set debugexceptions
12809@item set debugexceptions
b383017d 12810This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12811seen by the debugger.
12812
12813@kindex set debugmemory
12814@item set debugmemory
b383017d 12815This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12816seen by the debugger.
12817
12818@kindex set shell
12819@item set shell
12820This boolean values specifies whether the debuggee is called
12821via a shell or directly (default value is on).
12822
12823@kindex show shell
12824@item show shell
12825Displays if the debuggee will be started with a shell.
12826
12827@end table
12828
be448670
CF
12829@menu
12830* Non-debug DLL symbols:: Support for DLLs without debugging symbols
12831@end menu
12832
12833@node Non-debug DLL symbols
12834@subsubsection Support for DLLs without debugging symbols
12835@cindex DLLs with no debugging symbols
12836@cindex Minimal symbols and DLLs
12837
12838Very often on windows, some of the DLLs that your program relies on do
12839not include symbolic debugging information (for example,
12840@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
12841symbols in a DLL, it relies on the minimal amount of symbolic
12842information contained in the DLL's export table. This subsubsection
12843describes working with such symbols, known internally to @value{GDBN} as
12844``minimal symbols''.
12845
12846Note that before the debugged program has started execution, no DLLs
12847will have been loaded. The easiest way around this problem is simply to
12848start the program --- either by setting a breakpoint or letting the
12849program run once to completion. It is also possible to force
12850@value{GDBN} to load a particular DLL before starting the executable ---
12851see the shared library information in @pxref{Files} or the
12852@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
12853explicitly loading symbols from a DLL with no debugging information will
12854cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
12855which may adversely affect symbol lookup performance.
12856
12857@subsubsection DLL name prefixes
12858
12859In keeping with the naming conventions used by the Microsoft debugging
12860tools, DLL export symbols are made available with a prefix based on the
12861DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
12862also entered into the symbol table, so @code{CreateFileA} is often
12863sufficient. In some cases there will be name clashes within a program
12864(particularly if the executable itself includes full debugging symbols)
12865necessitating the use of the fully qualified name when referring to the
12866contents of the DLL. Use single-quotes around the name to avoid the
12867exclamation mark (``!'') being interpreted as a language operator.
12868
12869Note that the internal name of the DLL may be all upper-case, even
12870though the file name of the DLL is lower-case, or vice-versa. Since
12871symbols within @value{GDBN} are @emph{case-sensitive} this may cause
12872some confusion. If in doubt, try the @code{info functions} and
12873@code{info variables} commands or even @code{maint print msymbols} (see
12874@pxref{Symbols}). Here's an example:
12875
12876@smallexample
f7dc1244 12877(@value{GDBP}) info function CreateFileA
be448670
CF
12878All functions matching regular expression "CreateFileA":
12879
12880Non-debugging symbols:
128810x77e885f4 CreateFileA
128820x77e885f4 KERNEL32!CreateFileA
12883@end smallexample
12884
12885@smallexample
f7dc1244 12886(@value{GDBP}) info function !
be448670
CF
12887All functions matching regular expression "!":
12888
12889Non-debugging symbols:
128900x6100114c cygwin1!__assert
128910x61004034 cygwin1!_dll_crt0@@0
128920x61004240 cygwin1!dll_crt0(per_process *)
12893[etc...]
12894@end smallexample
12895
12896@subsubsection Working with minimal symbols
12897
12898Symbols extracted from a DLL's export table do not contain very much
12899type information. All that @value{GDBN} can do is guess whether a symbol
12900refers to a function or variable depending on the linker section that
12901contains the symbol. Also note that the actual contents of the memory
12902contained in a DLL are not available unless the program is running. This
12903means that you cannot examine the contents of a variable or disassemble
12904a function within a DLL without a running program.
12905
12906Variables are generally treated as pointers and dereferenced
12907automatically. For this reason, it is often necessary to prefix a
12908variable name with the address-of operator (``&'') and provide explicit
12909type information in the command. Here's an example of the type of
12910problem:
12911
12912@smallexample
f7dc1244 12913(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
12914$1 = 268572168
12915@end smallexample
12916
12917@smallexample
f7dc1244 12918(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
129190x10021610: "\230y\""
12920@end smallexample
12921
12922And two possible solutions:
12923
12924@smallexample
f7dc1244 12925(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
12926$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
12927@end smallexample
12928
12929@smallexample
f7dc1244 12930(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 129310x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 12932(@value{GDBP}) x/x 0x10021608
be448670 129330x10021608: 0x0022fd98
f7dc1244 12934(@value{GDBP}) x/s 0x0022fd98
be448670
CF
129350x22fd98: "/cygdrive/c/mydirectory/myprogram"
12936@end smallexample
12937
12938Setting a break point within a DLL is possible even before the program
12939starts execution. However, under these circumstances, @value{GDBN} can't
12940examine the initial instructions of the function in order to skip the
12941function's frame set-up code. You can work around this by using ``*&''
12942to set the breakpoint at a raw memory address:
12943
12944@smallexample
f7dc1244 12945(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
12946Breakpoint 1 at 0x1e04eff0
12947@end smallexample
12948
12949The author of these extensions is not entirely convinced that setting a
12950break point within a shared DLL like @file{kernel32.dll} is completely
12951safe.
12952
14d6dd68
EZ
12953@node Hurd Native
12954@subsection Commands specific to @sc{gnu} Hurd systems
12955@cindex @sc{gnu} Hurd debugging
12956
12957This subsection describes @value{GDBN} commands specific to the
12958@sc{gnu} Hurd native debugging.
12959
12960@table @code
12961@item set signals
12962@itemx set sigs
12963@kindex set signals@r{, Hurd command}
12964@kindex set sigs@r{, Hurd command}
12965This command toggles the state of inferior signal interception by
12966@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
12967affected by this command. @code{sigs} is a shorthand alias for
12968@code{signals}.
12969
12970@item show signals
12971@itemx show sigs
12972@kindex show signals@r{, Hurd command}
12973@kindex show sigs@r{, Hurd command}
12974Show the current state of intercepting inferior's signals.
12975
12976@item set signal-thread
12977@itemx set sigthread
12978@kindex set signal-thread
12979@kindex set sigthread
12980This command tells @value{GDBN} which thread is the @code{libc} signal
12981thread. That thread is run when a signal is delivered to a running
12982process. @code{set sigthread} is the shorthand alias of @code{set
12983signal-thread}.
12984
12985@item show signal-thread
12986@itemx show sigthread
12987@kindex show signal-thread
12988@kindex show sigthread
12989These two commands show which thread will run when the inferior is
12990delivered a signal.
12991
12992@item set stopped
12993@kindex set stopped@r{, Hurd command}
12994This commands tells @value{GDBN} that the inferior process is stopped,
12995as with the @code{SIGSTOP} signal. The stopped process can be
12996continued by delivering a signal to it.
12997
12998@item show stopped
12999@kindex show stopped@r{, Hurd command}
13000This command shows whether @value{GDBN} thinks the debuggee is
13001stopped.
13002
13003@item set exceptions
13004@kindex set exceptions@r{, Hurd command}
13005Use this command to turn off trapping of exceptions in the inferior.
13006When exception trapping is off, neither breakpoints nor
13007single-stepping will work. To restore the default, set exception
13008trapping on.
13009
13010@item show exceptions
13011@kindex show exceptions@r{, Hurd command}
13012Show the current state of trapping exceptions in the inferior.
13013
13014@item set task pause
13015@kindex set task@r{, Hurd commands}
13016@cindex task attributes (@sc{gnu} Hurd)
13017@cindex pause current task (@sc{gnu} Hurd)
13018This command toggles task suspension when @value{GDBN} has control.
13019Setting it to on takes effect immediately, and the task is suspended
13020whenever @value{GDBN} gets control. Setting it to off will take
13021effect the next time the inferior is continued. If this option is set
13022to off, you can use @code{set thread default pause on} or @code{set
13023thread pause on} (see below) to pause individual threads.
13024
13025@item show task pause
13026@kindex show task@r{, Hurd commands}
13027Show the current state of task suspension.
13028
13029@item set task detach-suspend-count
13030@cindex task suspend count
13031@cindex detach from task, @sc{gnu} Hurd
13032This command sets the suspend count the task will be left with when
13033@value{GDBN} detaches from it.
13034
13035@item show task detach-suspend-count
13036Show the suspend count the task will be left with when detaching.
13037
13038@item set task exception-port
13039@itemx set task excp
13040@cindex task exception port, @sc{gnu} Hurd
13041This command sets the task exception port to which @value{GDBN} will
13042forward exceptions. The argument should be the value of the @dfn{send
13043rights} of the task. @code{set task excp} is a shorthand alias.
13044
13045@item set noninvasive
13046@cindex noninvasive task options
13047This command switches @value{GDBN} to a mode that is the least
13048invasive as far as interfering with the inferior is concerned. This
13049is the same as using @code{set task pause}, @code{set exceptions}, and
13050@code{set signals} to values opposite to the defaults.
13051
13052@item info send-rights
13053@itemx info receive-rights
13054@itemx info port-rights
13055@itemx info port-sets
13056@itemx info dead-names
13057@itemx info ports
13058@itemx info psets
13059@cindex send rights, @sc{gnu} Hurd
13060@cindex receive rights, @sc{gnu} Hurd
13061@cindex port rights, @sc{gnu} Hurd
13062@cindex port sets, @sc{gnu} Hurd
13063@cindex dead names, @sc{gnu} Hurd
13064These commands display information about, respectively, send rights,
13065receive rights, port rights, port sets, and dead names of a task.
13066There are also shorthand aliases: @code{info ports} for @code{info
13067port-rights} and @code{info psets} for @code{info port-sets}.
13068
13069@item set thread pause
13070@kindex set thread@r{, Hurd command}
13071@cindex thread properties, @sc{gnu} Hurd
13072@cindex pause current thread (@sc{gnu} Hurd)
13073This command toggles current thread suspension when @value{GDBN} has
13074control. Setting it to on takes effect immediately, and the current
13075thread is suspended whenever @value{GDBN} gets control. Setting it to
13076off will take effect the next time the inferior is continued.
13077Normally, this command has no effect, since when @value{GDBN} has
13078control, the whole task is suspended. However, if you used @code{set
13079task pause off} (see above), this command comes in handy to suspend
13080only the current thread.
13081
13082@item show thread pause
13083@kindex show thread@r{, Hurd command}
13084This command shows the state of current thread suspension.
13085
13086@item set thread run
13087This comamnd sets whether the current thread is allowed to run.
13088
13089@item show thread run
13090Show whether the current thread is allowed to run.
13091
13092@item set thread detach-suspend-count
13093@cindex thread suspend count, @sc{gnu} Hurd
13094@cindex detach from thread, @sc{gnu} Hurd
13095This command sets the suspend count @value{GDBN} will leave on a
13096thread when detaching. This number is relative to the suspend count
13097found by @value{GDBN} when it notices the thread; use @code{set thread
13098takeover-suspend-count} to force it to an absolute value.
13099
13100@item show thread detach-suspend-count
13101Show the suspend count @value{GDBN} will leave on the thread when
13102detaching.
13103
13104@item set thread exception-port
13105@itemx set thread excp
13106Set the thread exception port to which to forward exceptions. This
13107overrides the port set by @code{set task exception-port} (see above).
13108@code{set thread excp} is the shorthand alias.
13109
13110@item set thread takeover-suspend-count
13111Normally, @value{GDBN}'s thread suspend counts are relative to the
13112value @value{GDBN} finds when it notices each thread. This command
13113changes the suspend counts to be absolute instead.
13114
13115@item set thread default
13116@itemx show thread default
13117@cindex thread default settings, @sc{gnu} Hurd
13118Each of the above @code{set thread} commands has a @code{set thread
13119default} counterpart (e.g., @code{set thread default pause}, @code{set
13120thread default exception-port}, etc.). The @code{thread default}
13121variety of commands sets the default thread properties for all
13122threads; you can then change the properties of individual threads with
13123the non-default commands.
13124@end table
13125
13126
a64548ea
EZ
13127@node Neutrino
13128@subsection QNX Neutrino
13129@cindex QNX Neutrino
13130
13131@value{GDBN} provides the following commands specific to the QNX
13132Neutrino target:
13133
13134@table @code
13135@item set debug nto-debug
13136@kindex set debug nto-debug
13137When set to on, enables debugging messages specific to the QNX
13138Neutrino support.
13139
13140@item show debug nto-debug
13141@kindex show debug nto-debug
13142Show the current state of QNX Neutrino messages.
13143@end table
13144
13145
8e04817f
AC
13146@node Embedded OS
13147@section Embedded Operating Systems
104c1213 13148
8e04817f
AC
13149This section describes configurations involving the debugging of
13150embedded operating systems that are available for several different
13151architectures.
d4f3574e 13152
8e04817f
AC
13153@menu
13154* VxWorks:: Using @value{GDBN} with VxWorks
13155@end menu
104c1213 13156
8e04817f
AC
13157@value{GDBN} includes the ability to debug programs running on
13158various real-time operating systems.
104c1213 13159
8e04817f
AC
13160@node VxWorks
13161@subsection Using @value{GDBN} with VxWorks
104c1213 13162
8e04817f 13163@cindex VxWorks
104c1213 13164
8e04817f 13165@table @code
104c1213 13166
8e04817f
AC
13167@kindex target vxworks
13168@item target vxworks @var{machinename}
13169A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13170is the target system's machine name or IP address.
104c1213 13171
8e04817f 13172@end table
104c1213 13173
8e04817f
AC
13174On VxWorks, @code{load} links @var{filename} dynamically on the
13175current target system as well as adding its symbols in @value{GDBN}.
104c1213 13176
8e04817f
AC
13177@value{GDBN} enables developers to spawn and debug tasks running on networked
13178VxWorks targets from a Unix host. Already-running tasks spawned from
13179the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13180both the Unix host and on the VxWorks target. The program
13181@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13182installed with the name @code{vxgdb}, to distinguish it from a
13183@value{GDBN} for debugging programs on the host itself.)
104c1213 13184
8e04817f
AC
13185@table @code
13186@item VxWorks-timeout @var{args}
13187@kindex vxworks-timeout
13188All VxWorks-based targets now support the option @code{vxworks-timeout}.
13189This option is set by the user, and @var{args} represents the number of
13190seconds @value{GDBN} waits for responses to rpc's. You might use this if
13191your VxWorks target is a slow software simulator or is on the far side
13192of a thin network line.
13193@end table
104c1213 13194
8e04817f
AC
13195The following information on connecting to VxWorks was current when
13196this manual was produced; newer releases of VxWorks may use revised
13197procedures.
104c1213 13198
4644b6e3 13199@findex INCLUDE_RDB
8e04817f
AC
13200To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13201to include the remote debugging interface routines in the VxWorks
13202library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13203VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13204kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13205source debugging task @code{tRdbTask} when VxWorks is booted. For more
13206information on configuring and remaking VxWorks, see the manufacturer's
13207manual.
13208@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13209
8e04817f
AC
13210Once you have included @file{rdb.a} in your VxWorks system image and set
13211your Unix execution search path to find @value{GDBN}, you are ready to
13212run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13213@code{vxgdb}, depending on your installation).
104c1213 13214
8e04817f 13215@value{GDBN} comes up showing the prompt:
104c1213 13216
474c8240 13217@smallexample
8e04817f 13218(vxgdb)
474c8240 13219@end smallexample
104c1213 13220
8e04817f
AC
13221@menu
13222* VxWorks Connection:: Connecting to VxWorks
13223* VxWorks Download:: VxWorks download
13224* VxWorks Attach:: Running tasks
13225@end menu
104c1213 13226
8e04817f
AC
13227@node VxWorks Connection
13228@subsubsection Connecting to VxWorks
104c1213 13229
8e04817f
AC
13230The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13231network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13232
474c8240 13233@smallexample
8e04817f 13234(vxgdb) target vxworks tt
474c8240 13235@end smallexample
104c1213 13236
8e04817f
AC
13237@need 750
13238@value{GDBN} displays messages like these:
104c1213 13239
8e04817f
AC
13240@smallexample
13241Attaching remote machine across net...
13242Connected to tt.
13243@end smallexample
104c1213 13244
8e04817f
AC
13245@need 1000
13246@value{GDBN} then attempts to read the symbol tables of any object modules
13247loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13248these files by searching the directories listed in the command search
13249path (@pxref{Environment, ,Your program's environment}); if it fails
13250to find an object file, it displays a message such as:
5d161b24 13251
474c8240 13252@smallexample
8e04817f 13253prog.o: No such file or directory.
474c8240 13254@end smallexample
104c1213 13255
8e04817f
AC
13256When this happens, add the appropriate directory to the search path with
13257the @value{GDBN} command @code{path}, and execute the @code{target}
13258command again.
104c1213 13259
8e04817f
AC
13260@node VxWorks Download
13261@subsubsection VxWorks download
104c1213 13262
8e04817f
AC
13263@cindex download to VxWorks
13264If you have connected to the VxWorks target and you want to debug an
13265object that has not yet been loaded, you can use the @value{GDBN}
13266@code{load} command to download a file from Unix to VxWorks
13267incrementally. The object file given as an argument to the @code{load}
13268command is actually opened twice: first by the VxWorks target in order
13269to download the code, then by @value{GDBN} in order to read the symbol
13270table. This can lead to problems if the current working directories on
13271the two systems differ. If both systems have NFS mounted the same
13272filesystems, you can avoid these problems by using absolute paths.
13273Otherwise, it is simplest to set the working directory on both systems
13274to the directory in which the object file resides, and then to reference
13275the file by its name, without any path. For instance, a program
13276@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13277and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13278program, type this on VxWorks:
104c1213 13279
474c8240 13280@smallexample
8e04817f 13281-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13282@end smallexample
104c1213 13283
8e04817f
AC
13284@noindent
13285Then, in @value{GDBN}, type:
104c1213 13286
474c8240 13287@smallexample
8e04817f
AC
13288(vxgdb) cd @var{hostpath}/vw/demo/rdb
13289(vxgdb) load prog.o
474c8240 13290@end smallexample
104c1213 13291
8e04817f 13292@value{GDBN} displays a response similar to this:
104c1213 13293
8e04817f
AC
13294@smallexample
13295Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13296@end smallexample
104c1213 13297
8e04817f
AC
13298You can also use the @code{load} command to reload an object module
13299after editing and recompiling the corresponding source file. Note that
13300this makes @value{GDBN} delete all currently-defined breakpoints,
13301auto-displays, and convenience variables, and to clear the value
13302history. (This is necessary in order to preserve the integrity of
13303debugger's data structures that reference the target system's symbol
13304table.)
104c1213 13305
8e04817f
AC
13306@node VxWorks Attach
13307@subsubsection Running tasks
104c1213
JM
13308
13309@cindex running VxWorks tasks
13310You can also attach to an existing task using the @code{attach} command as
13311follows:
13312
474c8240 13313@smallexample
104c1213 13314(vxgdb) attach @var{task}
474c8240 13315@end smallexample
104c1213
JM
13316
13317@noindent
13318where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13319or suspended when you attach to it. Running tasks are suspended at
13320the time of attachment.
13321
6d2ebf8b 13322@node Embedded Processors
104c1213
JM
13323@section Embedded Processors
13324
13325This section goes into details specific to particular embedded
13326configurations.
13327
7d86b5d5 13328
104c1213 13329@menu
104c1213 13330* ARM:: ARM
172c2a43
KI
13331* H8/300:: Renesas H8/300
13332* H8/500:: Renesas H8/500
13333* M32R/D:: Renesas M32R/D
104c1213 13334* M68K:: Motorola M68K
104c1213 13335* MIPS Embedded:: MIPS Embedded
a37295f9 13336* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13337* PA:: HP PA Embedded
13338* PowerPC: PowerPC
172c2a43 13339* SH:: Renesas SH
104c1213
JM
13340* Sparclet:: Tsqware Sparclet
13341* Sparclite:: Fujitsu Sparclite
13342* ST2000:: Tandem ST2000
13343* Z8000:: Zilog Z8000
a64548ea
EZ
13344* AVR:: Atmel AVR
13345* CRIS:: CRIS
13346* Super-H:: Renesas Super-H
104c1213
JM
13347@end menu
13348
6d2ebf8b 13349@node ARM
104c1213
JM
13350@subsection ARM
13351
13352@table @code
13353
8e04817f
AC
13354@kindex target rdi
13355@item target rdi @var{dev}
13356ARM Angel monitor, via RDI library interface to ADP protocol. You may
13357use this target to communicate with both boards running the Angel
13358monitor, or with the EmbeddedICE JTAG debug device.
13359
13360@kindex target rdp
13361@item target rdp @var{dev}
13362ARM Demon monitor.
13363
13364@end table
13365
e2f4edfd
EZ
13366@value{GDBN} provides the following ARM-specific commands:
13367
13368@table @code
13369@item set arm disassembler
13370@kindex set arm
13371This commands selects from a list of disassembly styles. The
13372@code{"std"} style is the standard style.
13373
13374@item show arm disassembler
13375@kindex show arm
13376Show the current disassembly style.
13377
13378@item set arm apcs32
13379@cindex ARM 32-bit mode
13380This command toggles ARM operation mode between 32-bit and 26-bit.
13381
13382@item show arm apcs32
13383Display the current usage of the ARM 32-bit mode.
13384
13385@item set arm fpu @var{fputype}
13386This command sets the ARM floating-point unit (FPU) type. The
13387argument @var{fputype} can be one of these:
13388
13389@table @code
13390@item auto
13391Determine the FPU type by querying the OS ABI.
13392@item softfpa
13393Software FPU, with mixed-endian doubles on little-endian ARM
13394processors.
13395@item fpa
13396GCC-compiled FPA co-processor.
13397@item softvfp
13398Software FPU with pure-endian doubles.
13399@item vfp
13400VFP co-processor.
13401@end table
13402
13403@item show arm fpu
13404Show the current type of the FPU.
13405
13406@item set arm abi
13407This command forces @value{GDBN} to use the specified ABI.
13408
13409@item show arm abi
13410Show the currently used ABI.
13411
13412@item set debug arm
13413Toggle whether to display ARM-specific debugging messages from the ARM
13414target support subsystem.
13415
13416@item show debug arm
13417Show whether ARM-specific debugging messages are enabled.
13418@end table
13419
13420
8e04817f 13421@node H8/300
172c2a43 13422@subsection Renesas H8/300
8e04817f
AC
13423
13424@table @code
13425
13426@kindex target hms@r{, with H8/300}
13427@item target hms @var{dev}
172c2a43 13428A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13429Use special commands @code{device} and @code{speed} to control the serial
13430line and the communications speed used.
13431
13432@kindex target e7000@r{, with H8/300}
13433@item target e7000 @var{dev}
172c2a43 13434E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13435
13436@kindex target sh3@r{, with H8/300}
13437@kindex target sh3e@r{, with H8/300}
13438@item target sh3 @var{dev}
13439@itemx target sh3e @var{dev}
172c2a43 13440Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13441
13442@end table
13443
13444@cindex download to H8/300 or H8/500
13445@cindex H8/300 or H8/500 download
172c2a43
KI
13446@cindex download to Renesas SH
13447@cindex Renesas SH download
13448When you select remote debugging to a Renesas SH, H8/300, or H8/500
13449board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13450board and also opens it as the current executable target for
13451@value{GDBN} on your host (like the @code{file} command).
13452
13453@value{GDBN} needs to know these things to talk to your
172c2a43 13454Renesas SH, H8/300, or H8/500:
8e04817f
AC
13455
13456@enumerate
13457@item
13458that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13459for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13460emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13461the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13462H8/300, or H8/500.)
13463
13464@item
172c2a43 13465what serial device connects your host to your Renesas board (the first
8e04817f
AC
13466serial device available on your host is the default).
13467
13468@item
13469what speed to use over the serial device.
13470@end enumerate
13471
13472@menu
172c2a43
KI
13473* Renesas Boards:: Connecting to Renesas boards.
13474* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13475* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13476@end menu
13477
172c2a43
KI
13478@node Renesas Boards
13479@subsubsection Connecting to Renesas boards
8e04817f
AC
13480
13481@c only for Unix hosts
13482@kindex device
172c2a43 13483@cindex serial device, Renesas micros
8e04817f
AC
13484Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13485need to explicitly set the serial device. The default @var{port} is the
13486first available port on your host. This is only necessary on Unix
13487hosts, where it is typically something like @file{/dev/ttya}.
13488
13489@kindex speed
172c2a43 13490@cindex serial line speed, Renesas micros
8e04817f
AC
13491@code{@value{GDBN}} has another special command to set the communications
13492speed: @samp{speed @var{bps}}. This command also is only used from Unix
13493hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13494the DOS @code{mode} command (for instance,
13495@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13496
13497The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13498use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13499use a DOS host,
13500@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13501called @code{asynctsr} to communicate with the development board
13502through a PC serial port. You must also use the DOS @code{mode} command
13503to set up the serial port on the DOS side.
13504
13505The following sample session illustrates the steps needed to start a
13506program under @value{GDBN} control on an H8/300. The example uses a
13507sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13508the Renesas SH and the H8/500.
8e04817f
AC
13509
13510First hook up your development board. In this example, we use a
13511board attached to serial port @code{COM2}; if you use a different serial
13512port, substitute its name in the argument of the @code{mode} command.
13513When you call @code{asynctsr}, the auxiliary comms program used by the
13514debugger, you give it just the numeric part of the serial port's name;
13515for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13516@code{COM2}.
13517
474c8240 13518@smallexample
8e04817f
AC
13519C:\H8300\TEST> asynctsr 2
13520C:\H8300\TEST> mode com2:9600,n,8,1,p
13521
13522Resident portion of MODE loaded
13523
13524COM2: 9600, n, 8, 1, p
13525
474c8240 13526@end smallexample
8e04817f
AC
13527
13528@quotation
13529@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13530@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13531disable it, or even boot without it, to use @code{asynctsr} to control
13532your development board.
13533@end quotation
13534
13535@kindex target hms@r{, and serial protocol}
13536Now that serial communications are set up, and the development board is
9c16f35a 13537connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13538the name of your program as the argument. @code{@value{GDBN}} prompts
13539you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13540commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13541cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13542download your program to the board. @code{load} displays the names of
13543the program's sections, and a @samp{*} for each 2K of data downloaded.
13544(If you want to refresh @value{GDBN} data on symbols or on the
13545executable file without downloading, use the @value{GDBN} commands
13546@code{file} or @code{symbol-file}. These commands, and @code{load}
13547itself, are described in @ref{Files,,Commands to specify files}.)
13548
13549@smallexample
13550(eg-C:\H8300\TEST) @value{GDBP} t.x
13551@value{GDBN} is free software and you are welcome to distribute copies
13552 of it under certain conditions; type "show copying" to see
13553 the conditions.
13554There is absolutely no warranty for @value{GDBN}; type "show warranty"
13555for details.
13556@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13557(@value{GDBP}) target hms
13558Connected to remote H8/300 HMS system.
13559(@value{GDBP}) load t.x
13560.text : 0x8000 .. 0xabde ***********
13561.data : 0xabde .. 0xad30 *
13562.stack : 0xf000 .. 0xf014 *
13563@end smallexample
13564
13565At this point, you're ready to run or debug your program. From here on,
13566you can use all the usual @value{GDBN} commands. The @code{break} command
13567sets breakpoints; the @code{run} command starts your program;
13568@code{print} or @code{x} display data; the @code{continue} command
13569resumes execution after stopping at a breakpoint. You can use the
13570@code{help} command at any time to find out more about @value{GDBN} commands.
13571
13572Remember, however, that @emph{operating system} facilities aren't
13573available on your development board; for example, if your program hangs,
13574you can't send an interrupt---but you can press the @sc{reset} switch!
13575
13576Use the @sc{reset} button on the development board
13577@itemize @bullet
13578@item
13579to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13580no way to pass an interrupt signal to the development board); and
13581
13582@item
13583to return to the @value{GDBN} command prompt after your program finishes
13584normally. The communications protocol provides no other way for @value{GDBN}
13585to detect program completion.
13586@end itemize
13587
13588In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13589development board as a ``normal exit'' of your program.
13590
172c2a43 13591@node Renesas ICE
8e04817f
AC
13592@subsubsection Using the E7000 in-circuit emulator
13593
172c2a43 13594@kindex target e7000@r{, with Renesas ICE}
8e04817f 13595You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13596Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13597e7000} command to connect @value{GDBN} to your E7000:
13598
13599@table @code
13600@item target e7000 @var{port} @var{speed}
13601Use this form if your E7000 is connected to a serial port. The
13602@var{port} argument identifies what serial port to use (for example,
13603@samp{com2}). The third argument is the line speed in bits per second
13604(for example, @samp{9600}).
13605
13606@item target e7000 @var{hostname}
13607If your E7000 is installed as a host on a TCP/IP network, you can just
13608specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13609@end table
13610
ba04e063
EZ
13611The following special commands are available when debugging with the
13612Renesas E7000 ICE:
13613
13614@table @code
13615@item e7000 @var{command}
13616@kindex e7000
13617@cindex send command to E7000 monitor
13618This sends the specified @var{command} to the E7000 monitor.
13619
13620@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13621@kindex ftplogin@r{, E7000}
13622This command records information for subsequent interface with the
13623E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13624named @var{machine} using specified @var{username} and @var{password},
13625and then chdir to the named directory @var{dir}.
13626
13627@item ftpload @var{file}
13628@kindex ftpload@r{, E7000}
13629This command uses credentials recorded by @code{ftplogin} to fetch and
13630load the named @var{file} from the E7000 monitor.
13631
13632@item drain
13633@kindex drain@r{, E7000}
13634This command drains any pending text buffers stored on the E7000.
13635
13636@item set usehardbreakpoints
13637@itemx show usehardbreakpoints
13638@kindex set usehardbreakpoints@r{, E7000}
13639@kindex show usehardbreakpoints@r{, E7000}
13640@cindex hardware breakpoints, and E7000
13641These commands set and show the use of hardware breakpoints for all
13642breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13643more information about using hardware breakpoints selectively.
13644@end table
13645
172c2a43
KI
13646@node Renesas Special
13647@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13648
13649Some @value{GDBN} commands are available only for the H8/300:
13650
13651@table @code
13652
13653@kindex set machine
13654@kindex show machine
13655@item set machine h8300
13656@itemx set machine h8300h
13657Condition @value{GDBN} for one of the two variants of the H8/300
13658architecture with @samp{set machine}. You can use @samp{show machine}
13659to check which variant is currently in effect.
104c1213
JM
13660
13661@end table
13662
8e04817f
AC
13663@node H8/500
13664@subsection H8/500
104c1213
JM
13665
13666@table @code
13667
8e04817f
AC
13668@kindex set memory @var{mod}
13669@cindex memory models, H8/500
13670@item set memory @var{mod}
13671@itemx show memory
13672Specify which H8/500 memory model (@var{mod}) you are using with
13673@samp{set memory}; check which memory model is in effect with @samp{show
13674memory}. The accepted values for @var{mod} are @code{small},
13675@code{big}, @code{medium}, and @code{compact}.
104c1213 13676
8e04817f 13677@end table
104c1213 13678
8e04817f 13679@node M32R/D
ba04e063 13680@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13681
13682@table @code
8e04817f
AC
13683@kindex target m32r
13684@item target m32r @var{dev}
172c2a43 13685Renesas M32R/D ROM monitor.
8e04817f 13686
fb3e19c0
KI
13687@kindex target m32rsdi
13688@item target m32rsdi @var{dev}
13689Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13690@end table
13691
13692The following @value{GDBN} commands are specific to the M32R monitor:
13693
13694@table @code
13695@item set download-path @var{path}
13696@kindex set download-path
13697@cindex find downloadable @sc{srec} files (M32R)
13698Set the default path for finding donwloadable @sc{srec} files.
13699
13700@item show download-path
13701@kindex show download-path
13702Show the default path for downloadable @sc{srec} files.
fb3e19c0 13703
721c2651
EZ
13704@item set board-address @var{addr}
13705@kindex set board-address
13706@cindex M32-EVA target board address
13707Set the IP address for the M32R-EVA target board.
13708
13709@item show board-address
13710@kindex show board-address
13711Show the current IP address of the target board.
13712
13713@item set server-address @var{addr}
13714@kindex set server-address
13715@cindex download server address (M32R)
13716Set the IP address for the download server, which is the @value{GDBN}'s
13717host machine.
13718
13719@item show server-address
13720@kindex show server-address
13721Display the IP address of the download server.
13722
13723@item upload @r{[}@var{file}@r{]}
13724@kindex upload@r{, M32R}
13725Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13726upload capability. If no @var{file} argument is given, the current
13727executable file is uploaded.
13728
13729@item tload @r{[}@var{file}@r{]}
13730@kindex tload@r{, M32R}
13731Test the @code{upload} command.
8e04817f
AC
13732@end table
13733
ba04e063
EZ
13734The following commands are available for M32R/SDI:
13735
13736@table @code
13737@item sdireset
13738@kindex sdireset
13739@cindex reset SDI connection, M32R
13740This command resets the SDI connection.
13741
13742@item sdistatus
13743@kindex sdistatus
13744This command shows the SDI connection status.
13745
13746@item debug_chaos
13747@kindex debug_chaos
13748@cindex M32R/Chaos debugging
13749Instructs the remote that M32R/Chaos debugging is to be used.
13750
13751@item use_debug_dma
13752@kindex use_debug_dma
13753Instructs the remote to use the DEBUG_DMA method of accessing memory.
13754
13755@item use_mon_code
13756@kindex use_mon_code
13757Instructs the remote to use the MON_CODE method of accessing memory.
13758
13759@item use_ib_break
13760@kindex use_ib_break
13761Instructs the remote to set breakpoints by IB break.
13762
13763@item use_dbt_break
13764@kindex use_dbt_break
13765Instructs the remote to set breakpoints by DBT.
13766@end table
13767
8e04817f
AC
13768@node M68K
13769@subsection M68k
13770
13771The Motorola m68k configuration includes ColdFire support, and
13772target command for the following ROM monitors.
13773
13774@table @code
13775
13776@kindex target abug
13777@item target abug @var{dev}
13778ABug ROM monitor for M68K.
13779
13780@kindex target cpu32bug
13781@item target cpu32bug @var{dev}
13782CPU32BUG monitor, running on a CPU32 (M68K) board.
13783
13784@kindex target dbug
13785@item target dbug @var{dev}
13786dBUG ROM monitor for Motorola ColdFire.
13787
13788@kindex target est
13789@item target est @var{dev}
13790EST-300 ICE monitor, running on a CPU32 (M68K) board.
13791
13792@kindex target rom68k
13793@item target rom68k @var{dev}
13794ROM 68K monitor, running on an M68K IDP board.
13795
13796@end table
13797
8e04817f
AC
13798@table @code
13799
13800@kindex target rombug
13801@item target rombug @var{dev}
13802ROMBUG ROM monitor for OS/9000.
13803
13804@end table
13805
8e04817f
AC
13806@node MIPS Embedded
13807@subsection MIPS Embedded
13808
13809@cindex MIPS boards
13810@value{GDBN} can use the MIPS remote debugging protocol to talk to a
13811MIPS board attached to a serial line. This is available when
13812you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 13813
8e04817f
AC
13814@need 1000
13815Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 13816
8e04817f
AC
13817@table @code
13818@item target mips @var{port}
13819@kindex target mips @var{port}
13820To run a program on the board, start up @code{@value{GDBP}} with the
13821name of your program as the argument. To connect to the board, use the
13822command @samp{target mips @var{port}}, where @var{port} is the name of
13823the serial port connected to the board. If the program has not already
13824been downloaded to the board, you may use the @code{load} command to
13825download it. You can then use all the usual @value{GDBN} commands.
104c1213 13826
8e04817f
AC
13827For example, this sequence connects to the target board through a serial
13828port, and loads and runs a program called @var{prog} through the
13829debugger:
104c1213 13830
474c8240 13831@smallexample
8e04817f
AC
13832host$ @value{GDBP} @var{prog}
13833@value{GDBN} is free software and @dots{}
13834(@value{GDBP}) target mips /dev/ttyb
13835(@value{GDBP}) load @var{prog}
13836(@value{GDBP}) run
474c8240 13837@end smallexample
104c1213 13838
8e04817f
AC
13839@item target mips @var{hostname}:@var{portnumber}
13840On some @value{GDBN} host configurations, you can specify a TCP
13841connection (for instance, to a serial line managed by a terminal
13842concentrator) instead of a serial port, using the syntax
13843@samp{@var{hostname}:@var{portnumber}}.
104c1213 13844
8e04817f
AC
13845@item target pmon @var{port}
13846@kindex target pmon @var{port}
13847PMON ROM monitor.
104c1213 13848
8e04817f
AC
13849@item target ddb @var{port}
13850@kindex target ddb @var{port}
13851NEC's DDB variant of PMON for Vr4300.
104c1213 13852
8e04817f
AC
13853@item target lsi @var{port}
13854@kindex target lsi @var{port}
13855LSI variant of PMON.
104c1213 13856
8e04817f
AC
13857@kindex target r3900
13858@item target r3900 @var{dev}
13859Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 13860
8e04817f
AC
13861@kindex target array
13862@item target array @var{dev}
13863Array Tech LSI33K RAID controller board.
104c1213 13864
8e04817f 13865@end table
104c1213 13866
104c1213 13867
8e04817f
AC
13868@noindent
13869@value{GDBN} also supports these special commands for MIPS targets:
104c1213 13870
8e04817f 13871@table @code
8e04817f
AC
13872@item set mipsfpu double
13873@itemx set mipsfpu single
13874@itemx set mipsfpu none
a64548ea 13875@itemx set mipsfpu auto
8e04817f
AC
13876@itemx show mipsfpu
13877@kindex set mipsfpu
13878@kindex show mipsfpu
13879@cindex MIPS remote floating point
13880@cindex floating point, MIPS remote
13881If your target board does not support the MIPS floating point
13882coprocessor, you should use the command @samp{set mipsfpu none} (if you
13883need this, you may wish to put the command in your @value{GDBN} init
13884file). This tells @value{GDBN} how to find the return value of
13885functions which return floating point values. It also allows
13886@value{GDBN} to avoid saving the floating point registers when calling
13887functions on the board. If you are using a floating point coprocessor
13888with only single precision floating point support, as on the @sc{r4650}
13889processor, use the command @samp{set mipsfpu single}. The default
13890double precision floating point coprocessor may be selected using
13891@samp{set mipsfpu double}.
104c1213 13892
8e04817f
AC
13893In previous versions the only choices were double precision or no
13894floating point, so @samp{set mipsfpu on} will select double precision
13895and @samp{set mipsfpu off} will select no floating point.
104c1213 13896
8e04817f
AC
13897As usual, you can inquire about the @code{mipsfpu} variable with
13898@samp{show mipsfpu}.
104c1213 13899
8e04817f
AC
13900@item set timeout @var{seconds}
13901@itemx set retransmit-timeout @var{seconds}
13902@itemx show timeout
13903@itemx show retransmit-timeout
13904@cindex @code{timeout}, MIPS protocol
13905@cindex @code{retransmit-timeout}, MIPS protocol
13906@kindex set timeout
13907@kindex show timeout
13908@kindex set retransmit-timeout
13909@kindex show retransmit-timeout
13910You can control the timeout used while waiting for a packet, in the MIPS
13911remote protocol, with the @code{set timeout @var{seconds}} command. The
13912default is 5 seconds. Similarly, you can control the timeout used while
13913waiting for an acknowledgement of a packet with the @code{set
13914retransmit-timeout @var{seconds}} command. The default is 3 seconds.
13915You can inspect both values with @code{show timeout} and @code{show
13916retransmit-timeout}. (These commands are @emph{only} available when
13917@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 13918
8e04817f
AC
13919The timeout set by @code{set timeout} does not apply when @value{GDBN}
13920is waiting for your program to stop. In that case, @value{GDBN} waits
13921forever because it has no way of knowing how long the program is going
13922to run before stopping.
ba04e063
EZ
13923
13924@item set syn-garbage-limit @var{num}
13925@kindex set syn-garbage-limit@r{, MIPS remote}
13926@cindex synchronize with remote MIPS target
13927Limit the maximum number of characters @value{GDBN} should ignore when
13928it tries to synchronize with the remote target. The default is 10
13929characters. Setting the limit to -1 means there's no limit.
13930
13931@item show syn-garbage-limit
13932@kindex show syn-garbage-limit@r{, MIPS remote}
13933Show the current limit on the number of characters to ignore when
13934trying to synchronize with the remote system.
13935
13936@item set monitor-prompt @var{prompt}
13937@kindex set monitor-prompt@r{, MIPS remote}
13938@cindex remote monitor prompt
13939Tell @value{GDBN} to expect the specified @var{prompt} string from the
13940remote monitor. The default depends on the target:
13941@table @asis
13942@item pmon target
13943@samp{PMON}
13944@item ddb target
13945@samp{NEC010}
13946@item lsi target
13947@samp{PMON>}
13948@end table
13949
13950@item show monitor-prompt
13951@kindex show monitor-prompt@r{, MIPS remote}
13952Show the current strings @value{GDBN} expects as the prompt from the
13953remote monitor.
13954
13955@item set monitor-warnings
13956@kindex set monitor-warnings@r{, MIPS remote}
13957Enable or disable monitor warnings about hardware breakpoints. This
13958has effect only for the @code{lsi} target. When on, @value{GDBN} will
13959display warning messages whose codes are returned by the @code{lsi}
13960PMON monitor for breakpoint commands.
13961
13962@item show monitor-warnings
13963@kindex show monitor-warnings@r{, MIPS remote}
13964Show the current setting of printing monitor warnings.
13965
13966@item pmon @var{command}
13967@kindex pmon@r{, MIPS remote}
13968@cindex send PMON command
13969This command allows sending an arbitrary @var{command} string to the
13970monitor. The monitor must be in debug mode for this to work.
8e04817f 13971@end table
104c1213 13972
a37295f9
MM
13973@node OpenRISC 1000
13974@subsection OpenRISC 1000
13975@cindex OpenRISC 1000
13976
13977@cindex or1k boards
13978See OR1k Architecture document (@uref{www.opencores.org}) for more information
13979about platform and commands.
13980
13981@table @code
13982
13983@kindex target jtag
13984@item target jtag jtag://@var{host}:@var{port}
13985
13986Connects to remote JTAG server.
13987JTAG remote server can be either an or1ksim or JTAG server,
13988connected via parallel port to the board.
13989
13990Example: @code{target jtag jtag://localhost:9999}
13991
13992@kindex or1ksim
13993@item or1ksim @var{command}
13994If connected to @code{or1ksim} OpenRISC 1000 Architectural
13995Simulator, proprietary commands can be executed.
13996
13997@kindex info or1k spr
13998@item info or1k spr
13999Displays spr groups.
14000
14001@item info or1k spr @var{group}
14002@itemx info or1k spr @var{groupno}
14003Displays register names in selected group.
14004
14005@item info or1k spr @var{group} @var{register}
14006@itemx info or1k spr @var{register}
14007@itemx info or1k spr @var{groupno} @var{registerno}
14008@itemx info or1k spr @var{registerno}
14009Shows information about specified spr register.
14010
14011@kindex spr
14012@item spr @var{group} @var{register} @var{value}
14013@itemx spr @var{register @var{value}}
14014@itemx spr @var{groupno} @var{registerno @var{value}}
14015@itemx spr @var{registerno @var{value}}
14016Writes @var{value} to specified spr register.
14017@end table
14018
14019Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14020It is very similar to @value{GDBN} trace, except it does not interfere with normal
14021program execution and is thus much faster. Hardware breakpoints/watchpoint
14022triggers can be set using:
14023@table @code
14024@item $LEA/$LDATA
14025Load effective address/data
14026@item $SEA/$SDATA
14027Store effective address/data
14028@item $AEA/$ADATA
14029Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14030@item $FETCH
14031Fetch data
14032@end table
14033
14034When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14035@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14036
14037@code{htrace} commands:
14038@cindex OpenRISC 1000 htrace
14039@table @code
14040@kindex hwatch
14041@item hwatch @var{conditional}
14042Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14043or Data. For example:
14044
14045@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14046
14047@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14048
4644b6e3 14049@kindex htrace
a37295f9
MM
14050@item htrace info
14051Display information about current HW trace configuration.
14052
a37295f9
MM
14053@item htrace trigger @var{conditional}
14054Set starting criteria for HW trace.
14055
a37295f9
MM
14056@item htrace qualifier @var{conditional}
14057Set acquisition qualifier for HW trace.
14058
a37295f9
MM
14059@item htrace stop @var{conditional}
14060Set HW trace stopping criteria.
14061
f153cc92 14062@item htrace record [@var{data}]*
a37295f9
MM
14063Selects the data to be recorded, when qualifier is met and HW trace was
14064triggered.
14065
a37295f9 14066@item htrace enable
a37295f9
MM
14067@itemx htrace disable
14068Enables/disables the HW trace.
14069
f153cc92 14070@item htrace rewind [@var{filename}]
a37295f9
MM
14071Clears currently recorded trace data.
14072
14073If filename is specified, new trace file is made and any newly collected data
14074will be written there.
14075
f153cc92 14076@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14077Prints trace buffer, using current record configuration.
14078
a37295f9
MM
14079@item htrace mode continuous
14080Set continuous trace mode.
14081
a37295f9
MM
14082@item htrace mode suspend
14083Set suspend trace mode.
14084
14085@end table
14086
8e04817f
AC
14087@node PowerPC
14088@subsection PowerPC
104c1213
JM
14089
14090@table @code
104c1213 14091
8e04817f
AC
14092@kindex target dink32
14093@item target dink32 @var{dev}
14094DINK32 ROM monitor.
104c1213 14095
8e04817f
AC
14096@kindex target ppcbug
14097@item target ppcbug @var{dev}
14098@kindex target ppcbug1
14099@item target ppcbug1 @var{dev}
14100PPCBUG ROM monitor for PowerPC.
104c1213 14101
8e04817f
AC
14102@kindex target sds
14103@item target sds @var{dev}
14104SDS monitor, running on a PowerPC board (such as Motorola's ADS).
14105
14106@end table
14107
14108@node PA
14109@subsection HP PA Embedded
104c1213
JM
14110
14111@table @code
14112
8e04817f
AC
14113@kindex target op50n
14114@item target op50n @var{dev}
14115OP50N monitor, running on an OKI HPPA board.
14116
14117@kindex target w89k
14118@item target w89k @var{dev}
14119W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14120
14121@end table
14122
8e04817f 14123@node SH
172c2a43 14124@subsection Renesas SH
104c1213
JM
14125
14126@table @code
14127
172c2a43 14128@kindex target hms@r{, with Renesas SH}
8e04817f 14129@item target hms @var{dev}
172c2a43 14130A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14131commands @code{device} and @code{speed} to control the serial line and
14132the communications speed used.
104c1213 14133
172c2a43 14134@kindex target e7000@r{, with Renesas SH}
8e04817f 14135@item target e7000 @var{dev}
172c2a43 14136E7000 emulator for Renesas SH.
104c1213 14137
8e04817f
AC
14138@kindex target sh3@r{, with SH}
14139@kindex target sh3e@r{, with SH}
14140@item target sh3 @var{dev}
14141@item target sh3e @var{dev}
172c2a43 14142Renesas SH-3 and SH-3E target systems.
104c1213 14143
8e04817f 14144@end table
104c1213 14145
8e04817f
AC
14146@node Sparclet
14147@subsection Tsqware Sparclet
104c1213 14148
8e04817f
AC
14149@cindex Sparclet
14150
14151@value{GDBN} enables developers to debug tasks running on
14152Sparclet targets from a Unix host.
14153@value{GDBN} uses code that runs on
14154both the Unix host and on the Sparclet target. The program
14155@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14156
8e04817f
AC
14157@table @code
14158@item remotetimeout @var{args}
14159@kindex remotetimeout
14160@value{GDBN} supports the option @code{remotetimeout}.
14161This option is set by the user, and @var{args} represents the number of
14162seconds @value{GDBN} waits for responses.
104c1213
JM
14163@end table
14164
8e04817f
AC
14165@cindex compiling, on Sparclet
14166When compiling for debugging, include the options @samp{-g} to get debug
14167information and @samp{-Ttext} to relocate the program to where you wish to
14168load it on the target. You may also want to add the options @samp{-n} or
14169@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14170
474c8240 14171@smallexample
8e04817f 14172sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14173@end smallexample
104c1213 14174
8e04817f 14175You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14176
474c8240 14177@smallexample
8e04817f 14178sparclet-aout-objdump --headers --syms prog
474c8240 14179@end smallexample
104c1213 14180
8e04817f
AC
14181@cindex running, on Sparclet
14182Once you have set
14183your Unix execution search path to find @value{GDBN}, you are ready to
14184run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14185(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14186
8e04817f
AC
14187@value{GDBN} comes up showing the prompt:
14188
474c8240 14189@smallexample
8e04817f 14190(gdbslet)
474c8240 14191@end smallexample
104c1213
JM
14192
14193@menu
8e04817f
AC
14194* Sparclet File:: Setting the file to debug
14195* Sparclet Connection:: Connecting to Sparclet
14196* Sparclet Download:: Sparclet download
14197* Sparclet Execution:: Running and debugging
104c1213
JM
14198@end menu
14199
8e04817f
AC
14200@node Sparclet File
14201@subsubsection Setting file to debug
104c1213 14202
8e04817f 14203The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14204
474c8240 14205@smallexample
8e04817f 14206(gdbslet) file prog
474c8240 14207@end smallexample
104c1213 14208
8e04817f
AC
14209@need 1000
14210@value{GDBN} then attempts to read the symbol table of @file{prog}.
14211@value{GDBN} locates
14212the file by searching the directories listed in the command search
14213path.
14214If the file was compiled with debug information (option "-g"), source
14215files will be searched as well.
14216@value{GDBN} locates
14217the source files by searching the directories listed in the directory search
14218path (@pxref{Environment, ,Your program's environment}).
14219If it fails
14220to find a file, it displays a message such as:
104c1213 14221
474c8240 14222@smallexample
8e04817f 14223prog: No such file or directory.
474c8240 14224@end smallexample
104c1213 14225
8e04817f
AC
14226When this happens, add the appropriate directories to the search paths with
14227the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14228@code{target} command again.
104c1213 14229
8e04817f
AC
14230@node Sparclet Connection
14231@subsubsection Connecting to Sparclet
104c1213 14232
8e04817f
AC
14233The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14234To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14235
474c8240 14236@smallexample
8e04817f
AC
14237(gdbslet) target sparclet /dev/ttya
14238Remote target sparclet connected to /dev/ttya
14239main () at ../prog.c:3
474c8240 14240@end smallexample
104c1213 14241
8e04817f
AC
14242@need 750
14243@value{GDBN} displays messages like these:
104c1213 14244
474c8240 14245@smallexample
8e04817f 14246Connected to ttya.
474c8240 14247@end smallexample
104c1213 14248
8e04817f
AC
14249@node Sparclet Download
14250@subsubsection Sparclet download
104c1213 14251
8e04817f
AC
14252@cindex download to Sparclet
14253Once connected to the Sparclet target,
14254you can use the @value{GDBN}
14255@code{load} command to download the file from the host to the target.
14256The file name and load offset should be given as arguments to the @code{load}
14257command.
14258Since the file format is aout, the program must be loaded to the starting
14259address. You can use @code{objdump} to find out what this value is. The load
14260offset is an offset which is added to the VMA (virtual memory address)
14261of each of the file's sections.
14262For instance, if the program
14263@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14264and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14265
474c8240 14266@smallexample
8e04817f
AC
14267(gdbslet) load prog 0x12010000
14268Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14269@end smallexample
104c1213 14270
8e04817f
AC
14271If the code is loaded at a different address then what the program was linked
14272to, you may need to use the @code{section} and @code{add-symbol-file} commands
14273to tell @value{GDBN} where to map the symbol table.
14274
14275@node Sparclet Execution
14276@subsubsection Running and debugging
14277
14278@cindex running and debugging Sparclet programs
14279You can now begin debugging the task using @value{GDBN}'s execution control
14280commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14281manual for the list of commands.
14282
474c8240 14283@smallexample
8e04817f
AC
14284(gdbslet) b main
14285Breakpoint 1 at 0x12010000: file prog.c, line 3.
14286(gdbslet) run
14287Starting program: prog
14288Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
142893 char *symarg = 0;
14290(gdbslet) step
142914 char *execarg = "hello!";
14292(gdbslet)
474c8240 14293@end smallexample
8e04817f
AC
14294
14295@node Sparclite
14296@subsection Fujitsu Sparclite
104c1213
JM
14297
14298@table @code
14299
8e04817f
AC
14300@kindex target sparclite
14301@item target sparclite @var{dev}
14302Fujitsu sparclite boards, used only for the purpose of loading.
14303You must use an additional command to debug the program.
14304For example: target remote @var{dev} using @value{GDBN} standard
14305remote protocol.
104c1213
JM
14306
14307@end table
14308
8e04817f
AC
14309@node ST2000
14310@subsection Tandem ST2000
104c1213 14311
8e04817f
AC
14312@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14313STDBUG protocol.
104c1213 14314
8e04817f
AC
14315To connect your ST2000 to the host system, see the manufacturer's
14316manual. Once the ST2000 is physically attached, you can run:
104c1213 14317
474c8240 14318@smallexample
8e04817f 14319target st2000 @var{dev} @var{speed}
474c8240 14320@end smallexample
104c1213 14321
8e04817f
AC
14322@noindent
14323to establish it as your debugging environment. @var{dev} is normally
14324the name of a serial device, such as @file{/dev/ttya}, connected to the
14325ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14326connection (for example, to a serial line attached via a terminal
14327concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14328
8e04817f
AC
14329The @code{load} and @code{attach} commands are @emph{not} defined for
14330this target; you must load your program into the ST2000 as you normally
14331would for standalone operation. @value{GDBN} reads debugging information
14332(such as symbols) from a separate, debugging version of the program
14333available on your host computer.
14334@c FIXME!! This is terribly vague; what little content is here is
14335@c basically hearsay.
104c1213 14336
8e04817f
AC
14337@cindex ST2000 auxiliary commands
14338These auxiliary @value{GDBN} commands are available to help you with the ST2000
14339environment:
104c1213 14340
8e04817f
AC
14341@table @code
14342@item st2000 @var{command}
14343@kindex st2000 @var{cmd}
14344@cindex STDBUG commands (ST2000)
14345@cindex commands to STDBUG (ST2000)
14346Send a @var{command} to the STDBUG monitor. See the manufacturer's
14347manual for available commands.
104c1213 14348
8e04817f
AC
14349@item connect
14350@cindex connect (to STDBUG)
14351Connect the controlling terminal to the STDBUG command monitor. When
14352you are done interacting with STDBUG, typing either of two character
14353sequences gets you back to the @value{GDBN} command prompt:
14354@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14355@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14356@end table
14357
8e04817f
AC
14358@node Z8000
14359@subsection Zilog Z8000
104c1213 14360
8e04817f
AC
14361@cindex Z8000
14362@cindex simulator, Z8000
14363@cindex Zilog Z8000 simulator
104c1213 14364
8e04817f
AC
14365When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14366a Z8000 simulator.
14367
14368For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14369unsegmented variant of the Z8000 architecture) or the Z8001 (the
14370segmented variant). The simulator recognizes which architecture is
14371appropriate by inspecting the object code.
104c1213 14372
8e04817f
AC
14373@table @code
14374@item target sim @var{args}
14375@kindex sim
14376@kindex target sim@r{, with Z8000}
14377Debug programs on a simulated CPU. If the simulator supports setup
14378options, specify them via @var{args}.
104c1213
JM
14379@end table
14380
8e04817f
AC
14381@noindent
14382After specifying this target, you can debug programs for the simulated
14383CPU in the same style as programs for your host computer; use the
14384@code{file} command to load a new program image, the @code{run} command
14385to run your program, and so on.
14386
14387As well as making available all the usual machine registers
14388(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14389additional items of information as specially named registers:
104c1213
JM
14390
14391@table @code
14392
8e04817f
AC
14393@item cycles
14394Counts clock-ticks in the simulator.
104c1213 14395
8e04817f
AC
14396@item insts
14397Counts instructions run in the simulator.
104c1213 14398
8e04817f
AC
14399@item time
14400Execution time in 60ths of a second.
104c1213 14401
8e04817f 14402@end table
104c1213 14403
8e04817f
AC
14404You can refer to these values in @value{GDBN} expressions with the usual
14405conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14406conditional breakpoint that suspends only after at least 5000
14407simulated clock ticks.
104c1213 14408
a64548ea
EZ
14409@node AVR
14410@subsection Atmel AVR
14411@cindex AVR
14412
14413When configured for debugging the Atmel AVR, @value{GDBN} supports the
14414following AVR-specific commands:
14415
14416@table @code
14417@item info io_registers
14418@kindex info io_registers@r{, AVR}
14419@cindex I/O registers (Atmel AVR)
14420This command displays information about the AVR I/O registers. For
14421each register, @value{GDBN} prints its number and value.
14422@end table
14423
14424@node CRIS
14425@subsection CRIS
14426@cindex CRIS
14427
14428When configured for debugging CRIS, @value{GDBN} provides the
14429following CRIS-specific commands:
14430
14431@table @code
14432@item set cris-version @var{ver}
14433@cindex CRIS version
14434Set the current CRIS version to @var{ver}. The CRIS version affects
14435register names and sizes. This command is useful in case
14436autodetection of the CRIS version fails.
14437
14438@item show cris-version
14439Show the current CRIS version.
14440
14441@item set cris-dwarf2-cfi
14442@cindex DWARF-2 CFI and CRIS
14443Set the usage of DWARF-2 CFI for CRIS debugging. The default is off
14444if using @code{gcc-cris} whose version is below @code{R59}, otherwise
14445on.
14446
14447@item show cris-dwarf2-cfi
14448Show the current state of using DWARF-2 CFI.
14449@end table
14450
14451@node Super-H
14452@subsection Renesas Super-H
14453@cindex Super-H
14454
14455For the Renesas Super-H processor, @value{GDBN} provides these
14456commands:
14457
14458@table @code
14459@item regs
14460@kindex regs@r{, Super-H}
14461Show the values of all Super-H registers.
14462@end table
14463
14464
8e04817f
AC
14465@node Architectures
14466@section Architectures
104c1213 14467
8e04817f
AC
14468This section describes characteristics of architectures that affect
14469all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14470
8e04817f 14471@menu
9c16f35a 14472* i386::
8e04817f
AC
14473* A29K::
14474* Alpha::
14475* MIPS::
a64548ea 14476* HPPA:: HP PA architecture
8e04817f 14477@end menu
104c1213 14478
9c16f35a
EZ
14479@node i386
14480@subsection x86 Architecture-specific issues.
14481
14482@table @code
14483@item set struct-convention @var{mode}
14484@kindex set struct-convention
14485@cindex struct return convention
14486@cindex struct/union returned in registers
14487Set the convention used by the inferior to return @code{struct}s and
14488@code{union}s from functions to @var{mode}. Possible values of
14489@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14490default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14491are returned on the stack, while @code{"reg"} means that a
14492@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14493be returned in a register.
14494
14495@item show struct-convention
14496@kindex show struct-convention
14497Show the current setting of the convention to return @code{struct}s
14498from functions.
14499@end table
14500
8e04817f
AC
14501@node A29K
14502@subsection A29K
104c1213
JM
14503
14504@table @code
104c1213 14505
8e04817f
AC
14506@kindex set rstack_high_address
14507@cindex AMD 29K register stack
14508@cindex register stack, AMD29K
14509@item set rstack_high_address @var{address}
14510On AMD 29000 family processors, registers are saved in a separate
14511@dfn{register stack}. There is no way for @value{GDBN} to determine the
14512extent of this stack. Normally, @value{GDBN} just assumes that the
14513stack is ``large enough''. This may result in @value{GDBN} referencing
14514memory locations that do not exist. If necessary, you can get around
14515this problem by specifying the ending address of the register stack with
14516the @code{set rstack_high_address} command. The argument should be an
14517address, which you probably want to precede with @samp{0x} to specify in
14518hexadecimal.
104c1213 14519
8e04817f
AC
14520@kindex show rstack_high_address
14521@item show rstack_high_address
14522Display the current limit of the register stack, on AMD 29000 family
14523processors.
104c1213 14524
8e04817f 14525@end table
104c1213 14526
8e04817f
AC
14527@node Alpha
14528@subsection Alpha
104c1213 14529
8e04817f 14530See the following section.
104c1213 14531
8e04817f
AC
14532@node MIPS
14533@subsection MIPS
104c1213 14534
8e04817f
AC
14535@cindex stack on Alpha
14536@cindex stack on MIPS
14537@cindex Alpha stack
14538@cindex MIPS stack
14539Alpha- and MIPS-based computers use an unusual stack frame, which
14540sometimes requires @value{GDBN} to search backward in the object code to
14541find the beginning of a function.
104c1213 14542
8e04817f
AC
14543@cindex response time, MIPS debugging
14544To improve response time (especially for embedded applications, where
14545@value{GDBN} may be restricted to a slow serial line for this search)
14546you may want to limit the size of this search, using one of these
14547commands:
104c1213 14548
8e04817f
AC
14549@table @code
14550@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14551@item set heuristic-fence-post @var{limit}
14552Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14553search for the beginning of a function. A value of @var{0} (the
14554default) means there is no limit. However, except for @var{0}, the
14555larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14556and therefore the longer it takes to run. You should only need to use
14557this command when debugging a stripped executable.
104c1213 14558
8e04817f
AC
14559@item show heuristic-fence-post
14560Display the current limit.
14561@end table
104c1213
JM
14562
14563@noindent
8e04817f
AC
14564These commands are available @emph{only} when @value{GDBN} is configured
14565for debugging programs on Alpha or MIPS processors.
104c1213 14566
a64548ea
EZ
14567Several MIPS-specific commands are available when debugging MIPS
14568programs:
14569
14570@table @code
14571@item set mips saved-gpreg-size @var{size}
14572@kindex set mips saved-gpreg-size
14573@cindex MIPS GP register size on stack
14574Set the size of MIPS general-purpose registers saved on the stack.
14575The argument @var{size} can be one of the following:
14576
14577@table @samp
14578@item 32
1457932-bit GP registers
14580@item 64
1458164-bit GP registers
14582@item auto
14583Use the target's default setting or autodetect the saved size from the
14584information contained in the executable. This is the default
14585@end table
14586
14587@item show mips saved-gpreg-size
14588@kindex show mips saved-gpreg-size
14589Show the current size of MIPS GP registers on the stack.
14590
14591@item set mips stack-arg-size @var{size}
14592@kindex set mips stack-arg-size
14593@cindex MIPS stack space for arguments
14594Set the amount of stack space reserved for arguments to functions.
14595The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14596(the default).
14597
14598@item set mips abi @var{arg}
14599@kindex set mips abi
14600@cindex set ABI for MIPS
14601Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14602values of @var{arg} are:
14603
14604@table @samp
14605@item auto
14606The default ABI associated with the current binary (this is the
14607default).
14608@item o32
14609@item o64
14610@item n32
14611@item n64
14612@item eabi32
14613@item eabi64
14614@item auto
14615@end table
14616
14617@item show mips abi
14618@kindex show mips abi
14619Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14620
14621@item set mipsfpu
14622@itemx show mipsfpu
14623@xref{MIPS Embedded, set mipsfpu}.
14624
14625@item set mips mask-address @var{arg}
14626@kindex set mips mask-address
14627@cindex MIPS addresses, masking
14628This command determines whether the most-significant 32 bits of 64-bit
14629MIPS addresses are masked off. The argument @var{arg} can be
14630@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14631setting, which lets @value{GDBN} determine the correct value.
14632
14633@item show mips mask-address
14634@kindex show mips mask-address
14635Show whether the upper 32 bits of MIPS addresses are masked off or
14636not.
14637
14638@item set remote-mips64-transfers-32bit-regs
14639@kindex set remote-mips64-transfers-32bit-regs
14640This command controls compatibility with 64-bit MIPS targets that
14641transfer data in 32-bit quantities. If you have an old MIPS 64 target
14642that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14643and 64 bits for other registers, set this option to @samp{on}.
14644
14645@item show remote-mips64-transfers-32bit-regs
14646@kindex show remote-mips64-transfers-32bit-regs
14647Show the current setting of compatibility with older MIPS 64 targets.
14648
14649@item set debug mips
14650@kindex set debug mips
14651This command turns on and off debugging messages for the MIPS-specific
14652target code in @value{GDBN}.
14653
14654@item show debug mips
14655@kindex show debug mips
14656Show the current setting of MIPS debugging messages.
14657@end table
14658
14659
14660@node HPPA
14661@subsection HPPA
14662@cindex HPPA support
14663
14664When @value{GDBN} is debugging te HP PA architecture, it provides the
14665following special commands:
14666
14667@table @code
14668@item set debug hppa
14669@kindex set debug hppa
14670THis command determines whether HPPA architecture specific debugging
14671messages are to be displayed.
14672
14673@item show debug hppa
14674Show whether HPPA debugging messages are displayed.
14675
14676@item maint print unwind @var{address}
14677@kindex maint print unwind@r{, HPPA}
14678This command displays the contents of the unwind table entry at the
14679given @var{address}.
14680
14681@end table
14682
104c1213 14683
8e04817f
AC
14684@node Controlling GDB
14685@chapter Controlling @value{GDBN}
14686
14687You can alter the way @value{GDBN} interacts with you by using the
14688@code{set} command. For commands controlling how @value{GDBN} displays
14689data, see @ref{Print Settings, ,Print settings}. Other settings are
14690described here.
14691
14692@menu
14693* Prompt:: Prompt
14694* Editing:: Command editing
14695* History:: Command history
14696* Screen Size:: Screen size
14697* Numbers:: Numbers
1e698235 14698* ABI:: Configuring the current ABI
8e04817f
AC
14699* Messages/Warnings:: Optional warnings and messages
14700* Debugging Output:: Optional messages about internal happenings
14701@end menu
14702
14703@node Prompt
14704@section Prompt
104c1213 14705
8e04817f 14706@cindex prompt
104c1213 14707
8e04817f
AC
14708@value{GDBN} indicates its readiness to read a command by printing a string
14709called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
14710can change the prompt string with the @code{set prompt} command. For
14711instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
14712the prompt in one of the @value{GDBN} sessions so that you can always tell
14713which one you are talking to.
104c1213 14714
8e04817f
AC
14715@emph{Note:} @code{set prompt} does not add a space for you after the
14716prompt you set. This allows you to set a prompt which ends in a space
14717or a prompt that does not.
104c1213 14718
8e04817f
AC
14719@table @code
14720@kindex set prompt
14721@item set prompt @var{newprompt}
14722Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 14723
8e04817f
AC
14724@kindex show prompt
14725@item show prompt
14726Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
14727@end table
14728
8e04817f
AC
14729@node Editing
14730@section Command editing
14731@cindex readline
14732@cindex command line editing
104c1213 14733
703663ab 14734@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
14735@sc{gnu} library provides consistent behavior for programs which provide a
14736command line interface to the user. Advantages are @sc{gnu} Emacs-style
14737or @dfn{vi}-style inline editing of commands, @code{csh}-like history
14738substitution, and a storage and recall of command history across
14739debugging sessions.
104c1213 14740
8e04817f
AC
14741You may control the behavior of command line editing in @value{GDBN} with the
14742command @code{set}.
104c1213 14743
8e04817f
AC
14744@table @code
14745@kindex set editing
14746@cindex editing
14747@item set editing
14748@itemx set editing on
14749Enable command line editing (enabled by default).
104c1213 14750
8e04817f
AC
14751@item set editing off
14752Disable command line editing.
104c1213 14753
8e04817f
AC
14754@kindex show editing
14755@item show editing
14756Show whether command line editing is enabled.
104c1213
JM
14757@end table
14758
703663ab
EZ
14759@xref{Command Line Editing}, for more details about the Readline
14760interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
14761encouraged to read that chapter.
14762
8e04817f
AC
14763@node History
14764@section Command history
703663ab 14765@cindex command history
8e04817f
AC
14766
14767@value{GDBN} can keep track of the commands you type during your
14768debugging sessions, so that you can be certain of precisely what
14769happened. Use these commands to manage the @value{GDBN} command
14770history facility.
104c1213 14771
703663ab
EZ
14772@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
14773package, to provide the history facility. @xref{Using History
14774Interactively}, for the detailed description of the History library.
14775
14776Here is the description of @value{GDBN} commands related to command
14777history.
14778
104c1213 14779@table @code
8e04817f
AC
14780@cindex history substitution
14781@cindex history file
14782@kindex set history filename
4644b6e3 14783@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
14784@item set history filename @var{fname}
14785Set the name of the @value{GDBN} command history file to @var{fname}.
14786This is the file where @value{GDBN} reads an initial command history
14787list, and where it writes the command history from this session when it
14788exits. You can access this list through history expansion or through
14789the history command editing characters listed below. This file defaults
14790to the value of the environment variable @code{GDBHISTFILE}, or to
14791@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
14792is not set.
104c1213 14793
9c16f35a
EZ
14794@cindex save command history
14795@kindex set history save
8e04817f
AC
14796@item set history save
14797@itemx set history save on
14798Record command history in a file, whose name may be specified with the
14799@code{set history filename} command. By default, this option is disabled.
104c1213 14800
8e04817f
AC
14801@item set history save off
14802Stop recording command history in a file.
104c1213 14803
8e04817f 14804@cindex history size
9c16f35a 14805@kindex set history size
8e04817f
AC
14806@item set history size @var{size}
14807Set the number of commands which @value{GDBN} keeps in its history list.
14808This defaults to the value of the environment variable
14809@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
14810@end table
14811
8e04817f 14812History expansion assigns special meaning to the character @kbd{!}.
703663ab 14813@xref{Event Designators}, for more details.
8e04817f 14814
703663ab 14815@cindex history expansion, turn on/off
8e04817f
AC
14816Since @kbd{!} is also the logical not operator in C, history expansion
14817is off by default. If you decide to enable history expansion with the
14818@code{set history expansion on} command, you may sometimes need to
14819follow @kbd{!} (when it is used as logical not, in an expression) with
14820a space or a tab to prevent it from being expanded. The readline
14821history facilities do not attempt substitution on the strings
14822@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
14823
14824The commands to control history expansion are:
104c1213
JM
14825
14826@table @code
8e04817f
AC
14827@item set history expansion on
14828@itemx set history expansion
703663ab 14829@kindex set history expansion
8e04817f 14830Enable history expansion. History expansion is off by default.
104c1213 14831
8e04817f
AC
14832@item set history expansion off
14833Disable history expansion.
104c1213 14834
8e04817f
AC
14835@c @group
14836@kindex show history
14837@item show history
14838@itemx show history filename
14839@itemx show history save
14840@itemx show history size
14841@itemx show history expansion
14842These commands display the state of the @value{GDBN} history parameters.
14843@code{show history} by itself displays all four states.
14844@c @end group
14845@end table
14846
14847@table @code
9c16f35a
EZ
14848@kindex show commands
14849@cindex show last commands
14850@cindex display command history
8e04817f
AC
14851@item show commands
14852Display the last ten commands in the command history.
104c1213 14853
8e04817f
AC
14854@item show commands @var{n}
14855Print ten commands centered on command number @var{n}.
14856
14857@item show commands +
14858Print ten commands just after the commands last printed.
104c1213
JM
14859@end table
14860
8e04817f
AC
14861@node Screen Size
14862@section Screen size
14863@cindex size of screen
14864@cindex pauses in output
104c1213 14865
8e04817f
AC
14866Certain commands to @value{GDBN} may produce large amounts of
14867information output to the screen. To help you read all of it,
14868@value{GDBN} pauses and asks you for input at the end of each page of
14869output. Type @key{RET} when you want to continue the output, or @kbd{q}
14870to discard the remaining output. Also, the screen width setting
14871determines when to wrap lines of output. Depending on what is being
14872printed, @value{GDBN} tries to break the line at a readable place,
14873rather than simply letting it overflow onto the following line.
14874
14875Normally @value{GDBN} knows the size of the screen from the terminal
14876driver software. For example, on Unix @value{GDBN} uses the termcap data base
14877together with the value of the @code{TERM} environment variable and the
14878@code{stty rows} and @code{stty cols} settings. If this is not correct,
14879you can override it with the @code{set height} and @code{set
14880width} commands:
14881
14882@table @code
14883@kindex set height
14884@kindex set width
14885@kindex show width
14886@kindex show height
14887@item set height @var{lpp}
14888@itemx show height
14889@itemx set width @var{cpl}
14890@itemx show width
14891These @code{set} commands specify a screen height of @var{lpp} lines and
14892a screen width of @var{cpl} characters. The associated @code{show}
14893commands display the current settings.
104c1213 14894
8e04817f
AC
14895If you specify a height of zero lines, @value{GDBN} does not pause during
14896output no matter how long the output is. This is useful if output is to a
14897file or to an editor buffer.
104c1213 14898
8e04817f
AC
14899Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
14900from wrapping its output.
9c16f35a
EZ
14901
14902@item set pagination on
14903@itemx set pagination off
14904@kindex set pagination
14905Turn the output pagination on or off; the default is on. Turning
14906pagination off is the alternative to @code{set height 0}.
14907
14908@item show pagination
14909@kindex show pagination
14910Show the current pagination mode.
104c1213
JM
14911@end table
14912
8e04817f
AC
14913@node Numbers
14914@section Numbers
14915@cindex number representation
14916@cindex entering numbers
104c1213 14917
8e04817f
AC
14918You can always enter numbers in octal, decimal, or hexadecimal in
14919@value{GDBN} by the usual conventions: octal numbers begin with
14920@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
14921begin with @samp{0x}. Numbers that begin with none of these are, by
14922default, entered in base 10; likewise, the default display for
14923numbers---when no particular format is specified---is base 10. You can
14924change the default base for both input and output with the @code{set
14925radix} command.
104c1213 14926
8e04817f
AC
14927@table @code
14928@kindex set input-radix
14929@item set input-radix @var{base}
14930Set the default base for numeric input. Supported choices
14931for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
14932specified either unambiguously or using the current default radix; for
14933example, any of
104c1213 14934
8e04817f 14935@smallexample
9c16f35a
EZ
14936set input-radix 012
14937set input-radix 10.
14938set input-radix 0xa
8e04817f 14939@end smallexample
104c1213 14940
8e04817f 14941@noindent
9c16f35a
EZ
14942sets the input base to decimal. On the other hand, @samp{set input-radix 10}
14943leaves the input radix unchanged, no matter what it was.
104c1213 14944
8e04817f
AC
14945@kindex set output-radix
14946@item set output-radix @var{base}
14947Set the default base for numeric display. Supported choices
14948for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
14949specified either unambiguously or using the current default radix.
104c1213 14950
8e04817f
AC
14951@kindex show input-radix
14952@item show input-radix
14953Display the current default base for numeric input.
104c1213 14954
8e04817f
AC
14955@kindex show output-radix
14956@item show output-radix
14957Display the current default base for numeric display.
9c16f35a
EZ
14958
14959@item set radix @r{[}@var{base}@r{]}
14960@itemx show radix
14961@kindex set radix
14962@kindex show radix
14963These commands set and show the default base for both input and output
14964of numbers. @code{set radix} sets the radix of input and output to
14965the same base; without an argument, it resets the radix back to its
14966default value of 10.
14967
8e04817f 14968@end table
104c1213 14969
1e698235
DJ
14970@node ABI
14971@section Configuring the current ABI
14972
14973@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
14974application automatically. However, sometimes you need to override its
14975conclusions. Use these commands to manage @value{GDBN}'s view of the
14976current ABI.
14977
98b45e30
DJ
14978@cindex OS ABI
14979@kindex set osabi
b4e9345d 14980@kindex show osabi
98b45e30
DJ
14981
14982One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 14983system targets, either via remote debugging or native emulation.
98b45e30
DJ
14984@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
14985but you can override its conclusion using the @code{set osabi} command.
14986One example where this is useful is in debugging of binaries which use
14987an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
14988not have the same identifying marks that the standard C library for your
14989platform provides.
14990
14991@table @code
14992@item show osabi
14993Show the OS ABI currently in use.
14994
14995@item set osabi
14996With no argument, show the list of registered available OS ABI's.
14997
14998@item set osabi @var{abi}
14999Set the current OS ABI to @var{abi}.
15000@end table
15001
1e698235 15002@cindex float promotion
1e698235
DJ
15003
15004Generally, the way that an argument of type @code{float} is passed to a
15005function depends on whether the function is prototyped. For a prototyped
15006(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15007according to the architecture's convention for @code{float}. For unprototyped
15008(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15009@code{double} and then passed.
15010
15011Unfortunately, some forms of debug information do not reliably indicate whether
15012a function is prototyped. If @value{GDBN} calls a function that is not marked
15013as prototyped, it consults @kbd{set coerce-float-to-double}.
15014
15015@table @code
a8f24a35 15016@kindex set coerce-float-to-double
1e698235
DJ
15017@item set coerce-float-to-double
15018@itemx set coerce-float-to-double on
15019Arguments of type @code{float} will be promoted to @code{double} when passed
15020to an unprototyped function. This is the default setting.
15021
15022@item set coerce-float-to-double off
15023Arguments of type @code{float} will be passed directly to unprototyped
15024functions.
9c16f35a
EZ
15025
15026@kindex show coerce-float-to-double
15027@item show coerce-float-to-double
15028Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15029@end table
15030
f1212245
DJ
15031@kindex set cp-abi
15032@kindex show cp-abi
15033@value{GDBN} needs to know the ABI used for your program's C@t{++}
15034objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15035used to build your application. @value{GDBN} only fully supports
15036programs with a single C@t{++} ABI; if your program contains code using
15037multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15038program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15039Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15040before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15041``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15042use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15043``auto''.
15044
15045@table @code
15046@item show cp-abi
15047Show the C@t{++} ABI currently in use.
15048
15049@item set cp-abi
15050With no argument, show the list of supported C@t{++} ABI's.
15051
15052@item set cp-abi @var{abi}
15053@itemx set cp-abi auto
15054Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15055@end table
15056
8e04817f
AC
15057@node Messages/Warnings
15058@section Optional warnings and messages
104c1213 15059
9c16f35a
EZ
15060@cindex verbose operation
15061@cindex optional warnings
8e04817f
AC
15062By default, @value{GDBN} is silent about its inner workings. If you are
15063running on a slow machine, you may want to use the @code{set verbose}
15064command. This makes @value{GDBN} tell you when it does a lengthy
15065internal operation, so you will not think it has crashed.
104c1213 15066
8e04817f
AC
15067Currently, the messages controlled by @code{set verbose} are those
15068which announce that the symbol table for a source file is being read;
15069see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15070
8e04817f
AC
15071@table @code
15072@kindex set verbose
15073@item set verbose on
15074Enables @value{GDBN} output of certain informational messages.
104c1213 15075
8e04817f
AC
15076@item set verbose off
15077Disables @value{GDBN} output of certain informational messages.
104c1213 15078
8e04817f
AC
15079@kindex show verbose
15080@item show verbose
15081Displays whether @code{set verbose} is on or off.
15082@end table
104c1213 15083
8e04817f
AC
15084By default, if @value{GDBN} encounters bugs in the symbol table of an
15085object file, it is silent; but if you are debugging a compiler, you may
15086find this information useful (@pxref{Symbol Errors, ,Errors reading
15087symbol files}).
104c1213 15088
8e04817f 15089@table @code
104c1213 15090
8e04817f
AC
15091@kindex set complaints
15092@item set complaints @var{limit}
15093Permits @value{GDBN} to output @var{limit} complaints about each type of
15094unusual symbols before becoming silent about the problem. Set
15095@var{limit} to zero to suppress all complaints; set it to a large number
15096to prevent complaints from being suppressed.
104c1213 15097
8e04817f
AC
15098@kindex show complaints
15099@item show complaints
15100Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15101
8e04817f 15102@end table
104c1213 15103
8e04817f
AC
15104By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15105lot of stupid questions to confirm certain commands. For example, if
15106you try to run a program which is already running:
104c1213 15107
474c8240 15108@smallexample
8e04817f
AC
15109(@value{GDBP}) run
15110The program being debugged has been started already.
15111Start it from the beginning? (y or n)
474c8240 15112@end smallexample
104c1213 15113
8e04817f
AC
15114If you are willing to unflinchingly face the consequences of your own
15115commands, you can disable this ``feature'':
104c1213 15116
8e04817f 15117@table @code
104c1213 15118
8e04817f
AC
15119@kindex set confirm
15120@cindex flinching
15121@cindex confirmation
15122@cindex stupid questions
15123@item set confirm off
15124Disables confirmation requests.
104c1213 15125
8e04817f
AC
15126@item set confirm on
15127Enables confirmation requests (the default).
104c1213 15128
8e04817f
AC
15129@kindex show confirm
15130@item show confirm
15131Displays state of confirmation requests.
15132
15133@end table
104c1213 15134
8e04817f
AC
15135@node Debugging Output
15136@section Optional messages about internal happenings
4644b6e3
EZ
15137@cindex optional debugging messages
15138
da316a69
EZ
15139@value{GDBN} has commands that enable optional debugging messages from
15140various @value{GDBN} subsystems; normally these commands are of
15141interest to @value{GDBN} maintainers, or when reporting a bug. This
15142section documents those commands.
15143
104c1213 15144@table @code
a8f24a35
EZ
15145@kindex set exec-done-display
15146@item set exec-done-display
15147Turns on or off the notification of asynchronous commands'
15148completion. When on, @value{GDBN} will print a message when an
15149asynchronous command finishes its execution. The default is off.
15150@kindex show exec-done-display
15151@item show exec-done-display
15152Displays the current setting of asynchronous command completion
15153notification.
4644b6e3
EZ
15154@kindex set debug
15155@cindex gdbarch debugging info
a8f24a35 15156@cindex architecture debugging info
8e04817f 15157@item set debug arch
a8f24a35 15158Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15159@kindex show debug
8e04817f
AC
15160@item show debug arch
15161Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15162@item set debug aix-thread
15163@cindex AIX threads
15164Display debugging messages about inner workings of the AIX thread
15165module.
15166@item show debug aix-thread
15167Show the current state of AIX thread debugging info display.
8e04817f 15168@item set debug event
4644b6e3 15169@cindex event debugging info
a8f24a35 15170Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15171default is off.
8e04817f
AC
15172@item show debug event
15173Displays the current state of displaying @value{GDBN} event debugging
15174info.
8e04817f 15175@item set debug expression
4644b6e3 15176@cindex expression debugging info
721c2651
EZ
15177Turns on or off display of debugging info about @value{GDBN}
15178expression parsing. The default is off.
8e04817f 15179@item show debug expression
721c2651
EZ
15180Displays the current state of displaying debugging info about
15181@value{GDBN} expression parsing.
7453dc06 15182@item set debug frame
4644b6e3 15183@cindex frame debugging info
7453dc06
AC
15184Turns on or off display of @value{GDBN} frame debugging info. The
15185default is off.
7453dc06
AC
15186@item show debug frame
15187Displays the current state of displaying @value{GDBN} frame debugging
15188info.
30e91e0b
RC
15189@item set debug infrun
15190@cindex inferior debugging info
15191Turns on or off display of @value{GDBN} debugging info for running the inferior.
15192The default is off. @file{infrun.c} contains GDB's runtime state machine used
15193for implementing operations such as single-stepping the inferior.
15194@item show debug infrun
15195Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15196@item set debug lin-lwp
15197@cindex @sc{gnu}/Linux LWP debug messages
15198@cindex Linux lightweight processes
721c2651 15199Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15200@item show debug lin-lwp
15201Show the current state of Linux LWP debugging messages.
2b4855ab 15202@item set debug observer
4644b6e3 15203@cindex observer debugging info
2b4855ab
AC
15204Turns on or off display of @value{GDBN} observer debugging. This
15205includes info such as the notification of observable events.
2b4855ab
AC
15206@item show debug observer
15207Displays the current state of observer debugging.
8e04817f 15208@item set debug overload
4644b6e3 15209@cindex C@t{++} overload debugging info
8e04817f
AC
15210Turns on or off display of @value{GDBN} C@t{++} overload debugging
15211info. This includes info such as ranking of functions, etc. The default
15212is off.
8e04817f
AC
15213@item show debug overload
15214Displays the current state of displaying @value{GDBN} C@t{++} overload
15215debugging info.
8e04817f
AC
15216@cindex packets, reporting on stdout
15217@cindex serial connections, debugging
15218@item set debug remote
15219Turns on or off display of reports on all packets sent back and forth across
15220the serial line to the remote machine. The info is printed on the
15221@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15222@item show debug remote
15223Displays the state of display of remote packets.
8e04817f
AC
15224@item set debug serial
15225Turns on or off display of @value{GDBN} serial debugging info. The
15226default is off.
8e04817f
AC
15227@item show debug serial
15228Displays the current state of displaying @value{GDBN} serial debugging
15229info.
8e04817f 15230@item set debug target
4644b6e3 15231@cindex target debugging info
8e04817f
AC
15232Turns on or off display of @value{GDBN} target debugging info. This info
15233includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15234default is 0. Set it to 1 to track events, and to 2 to also track the
15235value of large memory transfers. Changes to this flag do not take effect
15236until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15237@item show debug target
15238Displays the current state of displaying @value{GDBN} target debugging
15239info.
8e04817f 15240@item set debug varobj
4644b6e3 15241@cindex variable object debugging info
8e04817f
AC
15242Turns on or off display of @value{GDBN} variable object debugging
15243info. The default is off.
8e04817f
AC
15244@item show debug varobj
15245Displays the current state of displaying @value{GDBN} variable object
15246debugging info.
15247@end table
104c1213 15248
8e04817f
AC
15249@node Sequences
15250@chapter Canned Sequences of Commands
104c1213 15251
8e04817f
AC
15252Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15253command lists}), @value{GDBN} provides two ways to store sequences of
15254commands for execution as a unit: user-defined commands and command
15255files.
104c1213 15256
8e04817f
AC
15257@menu
15258* Define:: User-defined commands
15259* Hooks:: User-defined command hooks
15260* Command Files:: Command files
15261* Output:: Commands for controlled output
15262@end menu
104c1213 15263
8e04817f
AC
15264@node Define
15265@section User-defined commands
104c1213 15266
8e04817f
AC
15267@cindex user-defined command
15268A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15269which you assign a new name as a command. This is done with the
15270@code{define} command. User commands may accept up to 10 arguments
15271separated by whitespace. Arguments are accessed within the user command
15272via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15273
8e04817f
AC
15274@smallexample
15275define adder
15276 print $arg0 + $arg1 + $arg2
15277@end smallexample
104c1213
JM
15278
15279@noindent
8e04817f 15280To execute the command use:
104c1213 15281
8e04817f
AC
15282@smallexample
15283adder 1 2 3
15284@end smallexample
104c1213 15285
8e04817f
AC
15286@noindent
15287This defines the command @code{adder}, which prints the sum of
15288its three arguments. Note the arguments are text substitutions, so they may
15289reference variables, use complex expressions, or even perform inferior
15290functions calls.
104c1213
JM
15291
15292@table @code
104c1213 15293
8e04817f
AC
15294@kindex define
15295@item define @var{commandname}
15296Define a command named @var{commandname}. If there is already a command
15297by that name, you are asked to confirm that you want to redefine it.
104c1213 15298
8e04817f
AC
15299The definition of the command is made up of other @value{GDBN} command lines,
15300which are given following the @code{define} command. The end of these
15301commands is marked by a line containing @code{end}.
104c1213 15302
8e04817f
AC
15303@kindex if
15304@kindex else
15305@item if
09d4efe1 15306@itemx else
8e04817f
AC
15307Takes a single argument, which is an expression to evaluate.
15308It is followed by a series of commands that are executed
15309only if the expression is true (nonzero).
15310There can then optionally be a line @code{else}, followed
15311by a series of commands that are only executed if the expression
15312was false. The end of the list is marked by a line containing @code{end}.
104c1213 15313
8e04817f
AC
15314@kindex while
15315@item while
15316The syntax is similar to @code{if}: the command takes a single argument,
15317which is an expression to evaluate, and must be followed by the commands to
15318execute, one per line, terminated by an @code{end}.
15319The commands are executed repeatedly as long as the expression
15320evaluates to true.
104c1213 15321
8e04817f
AC
15322@kindex document
15323@item document @var{commandname}
15324Document the user-defined command @var{commandname}, so that it can be
15325accessed by @code{help}. The command @var{commandname} must already be
15326defined. This command reads lines of documentation just as @code{define}
15327reads the lines of the command definition, ending with @code{end}.
15328After the @code{document} command is finished, @code{help} on command
15329@var{commandname} displays the documentation you have written.
104c1213 15330
8e04817f
AC
15331You may use the @code{document} command again to change the
15332documentation of a command. Redefining the command with @code{define}
15333does not change the documentation.
104c1213 15334
8e04817f
AC
15335@kindex help user-defined
15336@item help user-defined
15337List all user-defined commands, with the first line of the documentation
15338(if any) for each.
104c1213 15339
8e04817f
AC
15340@kindex show user
15341@item show user
15342@itemx show user @var{commandname}
15343Display the @value{GDBN} commands used to define @var{commandname} (but
15344not its documentation). If no @var{commandname} is given, display the
15345definitions for all user-defined commands.
104c1213 15346
9c16f35a 15347@cindex infinite recusrion in user-defined commands
20f01a46
DH
15348@kindex show max-user-call-depth
15349@kindex set max-user-call-depth
15350@item show max-user-call-depth
5ca0cb28
DH
15351@itemx set max-user-call-depth
15352The value of @code{max-user-call-depth} controls how many recursion
15353levels are allowed in user-defined commands before GDB suspects an
15354infinite recursion and aborts the command.
20f01a46 15355
104c1213
JM
15356@end table
15357
8e04817f
AC
15358When user-defined commands are executed, the
15359commands of the definition are not printed. An error in any command
15360stops execution of the user-defined command.
104c1213 15361
8e04817f
AC
15362If used interactively, commands that would ask for confirmation proceed
15363without asking when used inside a user-defined command. Many @value{GDBN}
15364commands that normally print messages to say what they are doing omit the
15365messages when used in a user-defined command.
104c1213 15366
8e04817f
AC
15367@node Hooks
15368@section User-defined command hooks
15369@cindex command hooks
15370@cindex hooks, for commands
15371@cindex hooks, pre-command
104c1213 15372
8e04817f 15373@kindex hook
8e04817f
AC
15374You may define @dfn{hooks}, which are a special kind of user-defined
15375command. Whenever you run the command @samp{foo}, if the user-defined
15376command @samp{hook-foo} exists, it is executed (with no arguments)
15377before that command.
104c1213 15378
8e04817f
AC
15379@cindex hooks, post-command
15380@kindex hookpost
8e04817f
AC
15381A hook may also be defined which is run after the command you executed.
15382Whenever you run the command @samp{foo}, if the user-defined command
15383@samp{hookpost-foo} exists, it is executed (with no arguments) after
15384that command. Post-execution hooks may exist simultaneously with
15385pre-execution hooks, for the same command.
104c1213 15386
8e04817f 15387It is valid for a hook to call the command which it hooks. If this
9f1c6395 15388occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15389
8e04817f
AC
15390@c It would be nice if hookpost could be passed a parameter indicating
15391@c if the command it hooks executed properly or not. FIXME!
104c1213 15392
8e04817f
AC
15393@kindex stop@r{, a pseudo-command}
15394In addition, a pseudo-command, @samp{stop} exists. Defining
15395(@samp{hook-stop}) makes the associated commands execute every time
15396execution stops in your program: before breakpoint commands are run,
15397displays are printed, or the stack frame is printed.
104c1213 15398
8e04817f
AC
15399For example, to ignore @code{SIGALRM} signals while
15400single-stepping, but treat them normally during normal execution,
15401you could define:
104c1213 15402
474c8240 15403@smallexample
8e04817f
AC
15404define hook-stop
15405handle SIGALRM nopass
15406end
104c1213 15407
8e04817f
AC
15408define hook-run
15409handle SIGALRM pass
15410end
104c1213 15411
8e04817f
AC
15412define hook-continue
15413handle SIGLARM pass
15414end
474c8240 15415@end smallexample
104c1213 15416
8e04817f 15417As a further example, to hook at the begining and end of the @code{echo}
b383017d 15418command, and to add extra text to the beginning and end of the message,
8e04817f 15419you could define:
104c1213 15420
474c8240 15421@smallexample
8e04817f
AC
15422define hook-echo
15423echo <<<---
15424end
104c1213 15425
8e04817f
AC
15426define hookpost-echo
15427echo --->>>\n
15428end
104c1213 15429
8e04817f
AC
15430(@value{GDBP}) echo Hello World
15431<<<---Hello World--->>>
15432(@value{GDBP})
104c1213 15433
474c8240 15434@end smallexample
104c1213 15435
8e04817f
AC
15436You can define a hook for any single-word command in @value{GDBN}, but
15437not for command aliases; you should define a hook for the basic command
15438name, e.g. @code{backtrace} rather than @code{bt}.
15439@c FIXME! So how does Joe User discover whether a command is an alias
15440@c or not?
15441If an error occurs during the execution of your hook, execution of
15442@value{GDBN} commands stops and @value{GDBN} issues a prompt
15443(before the command that you actually typed had a chance to run).
104c1213 15444
8e04817f
AC
15445If you try to define a hook which does not match any known command, you
15446get a warning from the @code{define} command.
c906108c 15447
8e04817f
AC
15448@node Command Files
15449@section Command files
c906108c 15450
8e04817f
AC
15451@cindex command files
15452A command file for @value{GDBN} is a file of lines that are @value{GDBN}
15453commands. Comments (lines starting with @kbd{#}) may also be included.
15454An empty line in a command file does nothing; it does not mean to repeat
15455the last command, as it would from the terminal.
c906108c 15456
8e04817f
AC
15457@cindex init file
15458@cindex @file{.gdbinit}
15459@cindex @file{gdb.ini}
15460When you start @value{GDBN}, it automatically executes commands from its
15461@dfn{init files}, normally called @file{.gdbinit}@footnote{The DJGPP
15462port of @value{GDBN} uses the name @file{gdb.ini} instead, due to the
15463limitations of file names imposed by DOS filesystems.}.
15464During startup, @value{GDBN} does the following:
c906108c 15465
8e04817f
AC
15466@enumerate
15467@item
15468Reads the init file (if any) in your home directory@footnote{On
15469DOS/Windows systems, the home directory is the one pointed to by the
15470@code{HOME} environment variable.}.
c906108c 15471
8e04817f
AC
15472@item
15473Processes command line options and operands.
c906108c 15474
8e04817f
AC
15475@item
15476Reads the init file (if any) in the current working directory.
c906108c 15477
8e04817f
AC
15478@item
15479Reads command files specified by the @samp{-x} option.
15480@end enumerate
c906108c 15481
8e04817f
AC
15482The init file in your home directory can set options (such as @samp{set
15483complaints}) that affect subsequent processing of command line options
15484and operands. Init files are not executed if you use the @samp{-nx}
15485option (@pxref{Mode Options, ,Choosing modes}).
c906108c 15486
8e04817f
AC
15487@cindex init file name
15488On some configurations of @value{GDBN}, the init file is known by a
15489different name (these are typically environments where a specialized
15490form of @value{GDBN} may need to coexist with other forms, hence a
15491different name for the specialized version's init file). These are the
15492environments with special init file names:
c906108c 15493
8e04817f
AC
15494@cindex @file{.vxgdbinit}
15495@itemize @bullet
15496@item
15497VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
c906108c 15498
8e04817f
AC
15499@cindex @file{.os68gdbinit}
15500@item
15501OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
c906108c 15502
8e04817f
AC
15503@cindex @file{.esgdbinit}
15504@item
15505ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
15506@end itemize
c906108c 15507
8e04817f
AC
15508You can also request the execution of a command file with the
15509@code{source} command:
c906108c 15510
8e04817f
AC
15511@table @code
15512@kindex source
15513@item source @var{filename}
15514Execute the command file @var{filename}.
c906108c
SS
15515@end table
15516
8e04817f 15517The lines in a command file are executed sequentially. They are not
a71ec265
DH
15518printed as they are executed. An error in any command terminates
15519execution of the command file and control is returned to the console.
c906108c 15520
8e04817f
AC
15521Commands that would ask for confirmation if used interactively proceed
15522without asking when used in a command file. Many @value{GDBN} commands that
15523normally print messages to say what they are doing omit the messages
15524when called from command files.
c906108c 15525
8e04817f
AC
15526@value{GDBN} also accepts command input from standard input. In this
15527mode, normal output goes to standard output and error output goes to
15528standard error. Errors in a command file supplied on standard input do
15529not terminate execution of the command file --- execution continues with
15530the next command.
c906108c 15531
474c8240 15532@smallexample
8e04817f 15533gdb < cmds > log 2>&1
474c8240 15534@end smallexample
c906108c 15535
8e04817f
AC
15536(The syntax above will vary depending on the shell used.) This example
15537will execute commands from the file @file{cmds}. All output and errors
15538would be directed to @file{log}.
c906108c 15539
8e04817f
AC
15540@node Output
15541@section Commands for controlled output
c906108c 15542
8e04817f
AC
15543During the execution of a command file or a user-defined command, normal
15544@value{GDBN} output is suppressed; the only output that appears is what is
15545explicitly printed by the commands in the definition. This section
15546describes three commands useful for generating exactly the output you
15547want.
c906108c
SS
15548
15549@table @code
8e04817f
AC
15550@kindex echo
15551@item echo @var{text}
15552@c I do not consider backslash-space a standard C escape sequence
15553@c because it is not in ANSI.
15554Print @var{text}. Nonprinting characters can be included in
15555@var{text} using C escape sequences, such as @samp{\n} to print a
15556newline. @strong{No newline is printed unless you specify one.}
15557In addition to the standard C escape sequences, a backslash followed
15558by a space stands for a space. This is useful for displaying a
15559string with spaces at the beginning or the end, since leading and
15560trailing spaces are otherwise trimmed from all arguments.
15561To print @samp{@w{ }and foo =@w{ }}, use the command
15562@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15563
8e04817f
AC
15564A backslash at the end of @var{text} can be used, as in C, to continue
15565the command onto subsequent lines. For example,
c906108c 15566
474c8240 15567@smallexample
8e04817f
AC
15568echo This is some text\n\
15569which is continued\n\
15570onto several lines.\n
474c8240 15571@end smallexample
c906108c 15572
8e04817f 15573produces the same output as
c906108c 15574
474c8240 15575@smallexample
8e04817f
AC
15576echo This is some text\n
15577echo which is continued\n
15578echo onto several lines.\n
474c8240 15579@end smallexample
c906108c 15580
8e04817f
AC
15581@kindex output
15582@item output @var{expression}
15583Print the value of @var{expression} and nothing but that value: no
15584newlines, no @samp{$@var{nn} = }. The value is not entered in the
15585value history either. @xref{Expressions, ,Expressions}, for more information
15586on expressions.
c906108c 15587
8e04817f
AC
15588@item output/@var{fmt} @var{expression}
15589Print the value of @var{expression} in format @var{fmt}. You can use
15590the same formats as for @code{print}. @xref{Output Formats,,Output
15591formats}, for more information.
c906108c 15592
8e04817f
AC
15593@kindex printf
15594@item printf @var{string}, @var{expressions}@dots{}
15595Print the values of the @var{expressions} under the control of
15596@var{string}. The @var{expressions} are separated by commas and may be
15597either numbers or pointers. Their values are printed as specified by
15598@var{string}, exactly as if your program were to execute the C
15599subroutine
15600@c FIXME: the above implies that at least all ANSI C formats are
15601@c supported, but it isn't true: %E and %G don't work (or so it seems).
15602@c Either this is a bug, or the manual should document what formats are
15603@c supported.
c906108c 15604
474c8240 15605@smallexample
8e04817f 15606printf (@var{string}, @var{expressions}@dots{});
474c8240 15607@end smallexample
c906108c 15608
8e04817f 15609For example, you can print two values in hex like this:
c906108c 15610
8e04817f
AC
15611@smallexample
15612printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15613@end smallexample
c906108c 15614
8e04817f
AC
15615The only backslash-escape sequences that you can use in the format
15616string are the simple ones that consist of backslash followed by a
15617letter.
c906108c
SS
15618@end table
15619
21c294e6
AC
15620@node Interpreters
15621@chapter Command Interpreters
15622@cindex command interpreters
15623
15624@value{GDBN} supports multiple command interpreters, and some command
15625infrastructure to allow users or user interface writers to switch
15626between interpreters or run commands in other interpreters.
15627
15628@value{GDBN} currently supports two command interpreters, the console
15629interpreter (sometimes called the command-line interpreter or @sc{cli})
15630and the machine interface interpreter (or @sc{gdb/mi}). This manual
15631describes both of these interfaces in great detail.
15632
15633By default, @value{GDBN} will start with the console interpreter.
15634However, the user may choose to start @value{GDBN} with another
15635interpreter by specifying the @option{-i} or @option{--interpreter}
15636startup options. Defined interpreters include:
15637
15638@table @code
15639@item console
15640@cindex console interpreter
15641The traditional console or command-line interpreter. This is the most often
15642used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15643@value{GDBN} will use this interpreter.
15644
15645@item mi
15646@cindex mi interpreter
15647The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15648by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15649or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15650Interface}.
15651
15652@item mi2
15653@cindex mi2 interpreter
15654The current @sc{gdb/mi} interface.
15655
15656@item mi1
15657@cindex mi1 interpreter
15658The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15659
15660@end table
15661
15662@cindex invoke another interpreter
15663The interpreter being used by @value{GDBN} may not be dynamically
15664switched at runtime. Although possible, this could lead to a very
15665precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15666enters the command "interpreter-set console" in a console view,
15667@value{GDBN} would switch to using the console interpreter, rendering
15668the IDE inoperable!
15669
15670@kindex interpreter-exec
15671Although you may only choose a single interpreter at startup, you may execute
15672commands in any interpreter from the current interpreter using the appropriate
15673command. If you are running the console interpreter, simply use the
15674@code{interpreter-exec} command:
15675
15676@smallexample
15677interpreter-exec mi "-data-list-register-names"
15678@end smallexample
15679
15680@sc{gdb/mi} has a similar command, although it is only available in versions of
15681@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15682
8e04817f
AC
15683@node TUI
15684@chapter @value{GDBN} Text User Interface
15685@cindex TUI
d0d5df6f 15686@cindex Text User Interface
c906108c 15687
8e04817f
AC
15688@menu
15689* TUI Overview:: TUI overview
15690* TUI Keys:: TUI key bindings
7cf36c78 15691* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15692* TUI Commands:: TUI specific commands
15693* TUI Configuration:: TUI configuration variables
15694@end menu
c906108c 15695
d0d5df6f
AC
15696The @value{GDBN} Text User Interface, TUI in short, is a terminal
15697interface which uses the @code{curses} library to show the source
15698file, the assembly output, the program registers and @value{GDBN}
15699commands in separate text windows.
15700
15701The TUI is enabled by invoking @value{GDBN} using either
15702@pindex gdbtui
15703@samp{gdbtui} or @samp{gdb -tui}.
c906108c 15704
8e04817f
AC
15705@node TUI Overview
15706@section TUI overview
c906108c 15707
8e04817f
AC
15708The TUI has two display modes that can be switched while
15709@value{GDBN} runs:
c906108c 15710
8e04817f
AC
15711@itemize @bullet
15712@item
15713A curses (or TUI) mode in which it displays several text
15714windows on the terminal.
c906108c 15715
8e04817f
AC
15716@item
15717A standard mode which corresponds to the @value{GDBN} configured without
15718the TUI.
15719@end itemize
c906108c 15720
8e04817f
AC
15721In the TUI mode, @value{GDBN} can display several text window
15722on the terminal:
c906108c 15723
8e04817f
AC
15724@table @emph
15725@item command
15726This window is the @value{GDBN} command window with the @value{GDBN}
15727prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
15728managed using readline but through the TUI. The @emph{command}
15729window is always visible.
c906108c 15730
8e04817f
AC
15731@item source
15732The source window shows the source file of the program. The current
15733line as well as active breakpoints are displayed in this window.
c906108c 15734
8e04817f
AC
15735@item assembly
15736The assembly window shows the disassembly output of the program.
c906108c 15737
8e04817f
AC
15738@item register
15739This window shows the processor registers. It detects when
15740a register is changed and when this is the case, registers that have
6a1b180d 15741changed are highlighted.
c906108c 15742
c906108c
SS
15743@end table
15744
269c21fe
SC
15745The source and assembly windows show the current program position
15746by highlighting the current line and marking them with the @samp{>} marker.
15747Breakpoints are also indicated with two markers. A first one
15748indicates the breakpoint type:
15749
15750@table @code
15751@item B
15752Breakpoint which was hit at least once.
15753
15754@item b
15755Breakpoint which was never hit.
15756
15757@item H
15758Hardware breakpoint which was hit at least once.
15759
15760@item h
15761Hardware breakpoint which was never hit.
15762
15763@end table
15764
15765The second marker indicates whether the breakpoint is enabled or not:
15766
15767@table @code
15768@item +
15769Breakpoint is enabled.
15770
15771@item -
15772Breakpoint is disabled.
15773
15774@end table
15775
8e04817f
AC
15776The source, assembly and register windows are attached to the thread
15777and the frame position. They are updated when the current thread
15778changes, when the frame changes or when the program counter changes.
15779These three windows are arranged by the TUI according to several
15780layouts. The layout defines which of these three windows are visible.
15781The following layouts are available:
c906108c 15782
8e04817f
AC
15783@itemize @bullet
15784@item
15785source
2df3850c 15786
8e04817f
AC
15787@item
15788assembly
15789
15790@item
15791source and assembly
15792
15793@item
15794source and registers
c906108c 15795
8e04817f
AC
15796@item
15797assembly and registers
2df3850c 15798
8e04817f 15799@end itemize
c906108c 15800
b7bb15bc
SC
15801On top of the command window a status line gives various information
15802concerning the current process begin debugged. The status line is
15803updated when the information it shows changes. The following fields
15804are displayed:
15805
15806@table @emph
15807@item target
15808Indicates the current gdb target
15809(@pxref{Targets, ,Specifying a Debugging Target}).
15810
15811@item process
15812Gives information about the current process or thread number.
15813When no process is being debugged, this field is set to @code{No process}.
15814
15815@item function
15816Gives the current function name for the selected frame.
15817The name is demangled if demangling is turned on (@pxref{Print Settings}).
15818When there is no symbol corresponding to the current program counter
15819the string @code{??} is displayed.
15820
15821@item line
15822Indicates the current line number for the selected frame.
15823When the current line number is not known the string @code{??} is displayed.
15824
15825@item pc
15826Indicates the current program counter address.
15827
15828@end table
15829
8e04817f
AC
15830@node TUI Keys
15831@section TUI Key Bindings
15832@cindex TUI key bindings
c906108c 15833
8e04817f
AC
15834The TUI installs several key bindings in the readline keymaps
15835(@pxref{Command Line Editing}).
15836They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
15837directly on the TUI layout and windows. The TUI also provides
15838a @emph{SingleKey} keymap which binds several keys directly to
15839@value{GDBN} commands. The following key bindings
8e04817f 15840are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 15841
8e04817f
AC
15842@table @kbd
15843@kindex C-x C-a
15844@item C-x C-a
15845@kindex C-x a
15846@itemx C-x a
15847@kindex C-x A
15848@itemx C-x A
15849Enter or leave the TUI mode. When the TUI mode is left,
15850the curses window management is left and @value{GDBN} operates using
15851its standard mode writing on the terminal directly. When the TUI
15852mode is entered, the control is given back to the curses windows.
15853The screen is then refreshed.
c906108c 15854
8e04817f
AC
15855@kindex C-x 1
15856@item C-x 1
15857Use a TUI layout with only one window. The layout will
15858either be @samp{source} or @samp{assembly}. When the TUI mode
15859is not active, it will switch to the TUI mode.
2df3850c 15860
8e04817f 15861Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 15862
8e04817f
AC
15863@kindex C-x 2
15864@item C-x 2
15865Use a TUI layout with at least two windows. When the current
15866layout shows already two windows, a next layout with two windows is used.
15867When a new layout is chosen, one window will always be common to the
15868previous layout and the new one.
c906108c 15869
8e04817f 15870Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 15871
72ffddc9
SC
15872@kindex C-x o
15873@item C-x o
15874Change the active window. The TUI associates several key bindings
15875(like scrolling and arrow keys) to the active window. This command
15876gives the focus to the next TUI window.
15877
15878Think of it as the Emacs @kbd{C-x o} binding.
15879
7cf36c78
SC
15880@kindex C-x s
15881@item C-x s
15882Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
15883(@pxref{TUI Single Key Mode}).
15884
c906108c
SS
15885@end table
15886
8e04817f 15887The following key bindings are handled only by the TUI mode:
5d161b24 15888
8e04817f
AC
15889@table @key
15890@kindex PgUp
15891@item PgUp
15892Scroll the active window one page up.
c906108c 15893
8e04817f
AC
15894@kindex PgDn
15895@item PgDn
15896Scroll the active window one page down.
c906108c 15897
8e04817f
AC
15898@kindex Up
15899@item Up
15900Scroll the active window one line up.
c906108c 15901
8e04817f
AC
15902@kindex Down
15903@item Down
15904Scroll the active window one line down.
c906108c 15905
8e04817f
AC
15906@kindex Left
15907@item Left
15908Scroll the active window one column left.
c906108c 15909
8e04817f
AC
15910@kindex Right
15911@item Right
15912Scroll the active window one column right.
c906108c 15913
8e04817f
AC
15914@kindex C-L
15915@item C-L
15916Refresh the screen.
c906108c 15917
8e04817f 15918@end table
c906108c 15919
8e04817f 15920In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
15921for scrolling. This means they are available for readline when the
15922active window is the command window. When the command window
15923does not have the focus, it is necessary to use other readline
15924key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 15925
7cf36c78
SC
15926@node TUI Single Key Mode
15927@section TUI Single Key Mode
15928@cindex TUI single key mode
15929
15930The TUI provides a @emph{SingleKey} mode in which it installs a particular
15931key binding in the readline keymaps to connect single keys to
b383017d 15932some gdb commands.
7cf36c78
SC
15933
15934@table @kbd
15935@kindex c @r{(SingleKey TUI key)}
15936@item c
15937continue
15938
15939@kindex d @r{(SingleKey TUI key)}
15940@item d
15941down
15942
15943@kindex f @r{(SingleKey TUI key)}
15944@item f
15945finish
15946
15947@kindex n @r{(SingleKey TUI key)}
15948@item n
15949next
15950
15951@kindex q @r{(SingleKey TUI key)}
15952@item q
15953exit the @emph{SingleKey} mode.
15954
15955@kindex r @r{(SingleKey TUI key)}
15956@item r
15957run
15958
15959@kindex s @r{(SingleKey TUI key)}
15960@item s
15961step
15962
15963@kindex u @r{(SingleKey TUI key)}
15964@item u
15965up
15966
15967@kindex v @r{(SingleKey TUI key)}
15968@item v
15969info locals
15970
15971@kindex w @r{(SingleKey TUI key)}
15972@item w
15973where
15974
15975@end table
15976
15977Other keys temporarily switch to the @value{GDBN} command prompt.
15978The key that was pressed is inserted in the editing buffer so that
15979it is possible to type most @value{GDBN} commands without interaction
15980with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
15981@emph{SingleKey} mode is restored. The only way to permanently leave
15982this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
15983
15984
8e04817f
AC
15985@node TUI Commands
15986@section TUI specific commands
15987@cindex TUI commands
15988
15989The TUI has specific commands to control the text windows.
15990These commands are always available, that is they do not depend on
15991the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
15992is in the standard mode, using these commands will automatically switch
15993in the TUI mode.
c906108c
SS
15994
15995@table @code
3d757584
SC
15996@item info win
15997@kindex info win
15998List and give the size of all displayed windows.
15999
8e04817f 16000@item layout next
4644b6e3 16001@kindex layout
8e04817f 16002Display the next layout.
2df3850c 16003
8e04817f 16004@item layout prev
8e04817f 16005Display the previous layout.
c906108c 16006
8e04817f 16007@item layout src
8e04817f 16008Display the source window only.
c906108c 16009
8e04817f 16010@item layout asm
8e04817f 16011Display the assembly window only.
c906108c 16012
8e04817f 16013@item layout split
8e04817f 16014Display the source and assembly window.
c906108c 16015
8e04817f 16016@item layout regs
8e04817f
AC
16017Display the register window together with the source or assembly window.
16018
16019@item focus next | prev | src | asm | regs | split
16020@kindex focus
16021Set the focus to the named window.
16022This command allows to change the active window so that scrolling keys
16023can be affected to another window.
c906108c 16024
8e04817f
AC
16025@item refresh
16026@kindex refresh
16027Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16028
6a1b180d
SC
16029@item tui reg float
16030@kindex tui reg
16031Show the floating point registers in the register window.
16032
16033@item tui reg general
16034Show the general registers in the register window.
16035
16036@item tui reg next
16037Show the next register group. The list of register groups as well as
16038their order is target specific. The predefined register groups are the
16039following: @code{general}, @code{float}, @code{system}, @code{vector},
16040@code{all}, @code{save}, @code{restore}.
16041
16042@item tui reg system
16043Show the system registers in the register window.
16044
8e04817f
AC
16045@item update
16046@kindex update
16047Update the source window and the current execution point.
c906108c 16048
8e04817f
AC
16049@item winheight @var{name} +@var{count}
16050@itemx winheight @var{name} -@var{count}
16051@kindex winheight
16052Change the height of the window @var{name} by @var{count}
16053lines. Positive counts increase the height, while negative counts
16054decrease it.
2df3850c 16055
c906108c
SS
16056@end table
16057
8e04817f
AC
16058@node TUI Configuration
16059@section TUI configuration variables
16060@cindex TUI configuration variables
c906108c 16061
8e04817f
AC
16062The TUI has several configuration variables that control the
16063appearance of windows on the terminal.
c906108c 16064
8e04817f
AC
16065@table @code
16066@item set tui border-kind @var{kind}
16067@kindex set tui border-kind
16068Select the border appearance for the source, assembly and register windows.
16069The possible values are the following:
16070@table @code
16071@item space
16072Use a space character to draw the border.
c906108c 16073
8e04817f
AC
16074@item ascii
16075Use ascii characters + - and | to draw the border.
c906108c 16076
8e04817f
AC
16077@item acs
16078Use the Alternate Character Set to draw the border. The border is
16079drawn using character line graphics if the terminal supports them.
c78b4128 16080
8e04817f 16081@end table
c78b4128 16082
8e04817f
AC
16083@item set tui active-border-mode @var{mode}
16084@kindex set tui active-border-mode
16085Select the attributes to display the border of the active window.
16086The possible values are @code{normal}, @code{standout}, @code{reverse},
16087@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16088
8e04817f
AC
16089@item set tui border-mode @var{mode}
16090@kindex set tui border-mode
16091Select the attributes to display the border of other windows.
16092The @var{mode} can be one of the following:
16093@table @code
16094@item normal
16095Use normal attributes to display the border.
c906108c 16096
8e04817f
AC
16097@item standout
16098Use standout mode.
c906108c 16099
8e04817f
AC
16100@item reverse
16101Use reverse video mode.
c906108c 16102
8e04817f
AC
16103@item half
16104Use half bright mode.
c906108c 16105
8e04817f
AC
16106@item half-standout
16107Use half bright and standout mode.
c906108c 16108
8e04817f
AC
16109@item bold
16110Use extra bright or bold mode.
c78b4128 16111
8e04817f
AC
16112@item bold-standout
16113Use extra bright or bold and standout mode.
c78b4128 16114
8e04817f 16115@end table
c78b4128 16116
8e04817f 16117@end table
c78b4128 16118
8e04817f
AC
16119@node Emacs
16120@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16121
8e04817f
AC
16122@cindex Emacs
16123@cindex @sc{gnu} Emacs
16124A special interface allows you to use @sc{gnu} Emacs to view (and
16125edit) the source files for the program you are debugging with
16126@value{GDBN}.
c906108c 16127
8e04817f
AC
16128To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16129executable file you want to debug as an argument. This command starts
16130@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16131created Emacs buffer.
16132@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16133
8e04817f
AC
16134Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16135things:
c906108c 16136
8e04817f
AC
16137@itemize @bullet
16138@item
16139All ``terminal'' input and output goes through the Emacs buffer.
16140@end itemize
c906108c 16141
8e04817f
AC
16142This applies both to @value{GDBN} commands and their output, and to the input
16143and output done by the program you are debugging.
bf0184be 16144
8e04817f
AC
16145This is useful because it means that you can copy the text of previous
16146commands and input them again; you can even use parts of the output
16147in this way.
bf0184be 16148
8e04817f
AC
16149All the facilities of Emacs' Shell mode are available for interacting
16150with your program. In particular, you can send signals the usual
16151way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16152stop.
bf0184be 16153
8e04817f 16154@itemize @bullet
bf0184be 16155@item
8e04817f
AC
16156@value{GDBN} displays source code through Emacs.
16157@end itemize
bf0184be 16158
8e04817f
AC
16159Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16160source file for that frame and puts an arrow (@samp{=>}) at the
16161left margin of the current line. Emacs uses a separate buffer for
16162source display, and splits the screen to show both your @value{GDBN} session
16163and the source.
bf0184be 16164
8e04817f
AC
16165Explicit @value{GDBN} @code{list} or search commands still produce output as
16166usual, but you probably have no reason to use them from Emacs.
c906108c 16167
64fabec2
AC
16168If you specify an absolute file name when prompted for the @kbd{M-x
16169gdb} argument, then Emacs sets your current working directory to where
16170your program resides. If you only specify the file name, then Emacs
16171sets your current working directory to to the directory associated
16172with the previous buffer. In this case, @value{GDBN} may find your
16173program by searching your environment's @code{PATH} variable, but on
16174some operating systems it might not find the source. So, although the
16175@value{GDBN} input and output session proceeds normally, the auxiliary
16176buffer does not display the current source and line of execution.
16177
16178The initial working directory of @value{GDBN} is printed on the top
16179line of the @value{GDBN} I/O buffer and this serves as a default for
16180the commands that specify files for @value{GDBN} to operate
16181on. @xref{Files, ,Commands to specify files}.
16182
16183By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16184need to call @value{GDBN} by a different name (for example, if you
16185keep several configurations around, with different names) you can
16186customize the Emacs variable @code{gud-gdb-command-name} to run the
16187one you want.
8e04817f
AC
16188
16189In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16190addition to the standard Shell mode commands:
c906108c 16191
8e04817f
AC
16192@table @kbd
16193@item C-h m
16194Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16195
64fabec2 16196@item C-c C-s
8e04817f
AC
16197Execute to another source line, like the @value{GDBN} @code{step} command; also
16198update the display window to show the current file and location.
c906108c 16199
64fabec2 16200@item C-c C-n
8e04817f
AC
16201Execute to next source line in this function, skipping all function
16202calls, like the @value{GDBN} @code{next} command. Then update the display window
16203to show the current file and location.
c906108c 16204
64fabec2 16205@item C-c C-i
8e04817f
AC
16206Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16207display window accordingly.
c906108c 16208
8e04817f
AC
16209@item C-c C-f
16210Execute until exit from the selected stack frame, like the @value{GDBN}
16211@code{finish} command.
c906108c 16212
64fabec2 16213@item C-c C-r
8e04817f
AC
16214Continue execution of your program, like the @value{GDBN} @code{continue}
16215command.
b433d00b 16216
64fabec2 16217@item C-c <
8e04817f
AC
16218Go up the number of frames indicated by the numeric argument
16219(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16220like the @value{GDBN} @code{up} command.
b433d00b 16221
64fabec2 16222@item C-c >
8e04817f
AC
16223Go down the number of frames indicated by the numeric argument, like the
16224@value{GDBN} @code{down} command.
8e04817f 16225@end table
c906108c 16226
64fabec2 16227In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16228tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16229
64fabec2
AC
16230If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16231shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16232point to any frame in the stack and type @key{RET} to make it become the
16233current frame and display the associated source in the source buffer.
16234Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16235current one.
16236
8e04817f
AC
16237If you accidentally delete the source-display buffer, an easy way to get
16238it back is to type the command @code{f} in the @value{GDBN} buffer, to
16239request a frame display; when you run under Emacs, this recreates
16240the source buffer if necessary to show you the context of the current
16241frame.
c906108c 16242
8e04817f
AC
16243The source files displayed in Emacs are in ordinary Emacs buffers
16244which are visiting the source files in the usual way. You can edit
16245the files with these buffers if you wish; but keep in mind that @value{GDBN}
16246communicates with Emacs in terms of line numbers. If you add or
16247delete lines from the text, the line numbers that @value{GDBN} knows cease
16248to correspond properly with the code.
b383017d 16249
64fabec2
AC
16250The description given here is for GNU Emacs version 21.3 and a more
16251detailed description of its interaction with @value{GDBN} is given in
16252the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16253
8e04817f
AC
16254@c The following dropped because Epoch is nonstandard. Reactivate
16255@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16256@ignore
16257@kindex Emacs Epoch environment
16258@kindex Epoch
16259@kindex inspect
c906108c 16260
8e04817f
AC
16261Version 18 of @sc{gnu} Emacs has a built-in window system
16262called the @code{epoch}
16263environment. Users of this environment can use a new command,
16264@code{inspect} which performs identically to @code{print} except that
16265each value is printed in its own window.
16266@end ignore
c906108c 16267
922fbb7b
AC
16268
16269@node GDB/MI
16270@chapter The @sc{gdb/mi} Interface
16271
16272@unnumberedsec Function and Purpose
16273
16274@cindex @sc{gdb/mi}, its purpose
16275@sc{gdb/mi} is a line based machine oriented text interface to @value{GDBN}. It is
16276specifically intended to support the development of systems which use
16277the debugger as just one small component of a larger system.
16278
16279This chapter is a specification of the @sc{gdb/mi} interface. It is written
16280in the form of a reference manual.
16281
16282Note that @sc{gdb/mi} is still under construction, so some of the
16283features described below are incomplete and subject to change.
16284
16285@unnumberedsec Notation and Terminology
16286
16287@cindex notational conventions, for @sc{gdb/mi}
16288This chapter uses the following notation:
16289
16290@itemize @bullet
16291@item
16292@code{|} separates two alternatives.
16293
16294@item
16295@code{[ @var{something} ]} indicates that @var{something} is optional:
16296it may or may not be given.
16297
16298@item
16299@code{( @var{group} )*} means that @var{group} inside the parentheses
16300may repeat zero or more times.
16301
16302@item
16303@code{( @var{group} )+} means that @var{group} inside the parentheses
16304may repeat one or more times.
16305
16306@item
16307@code{"@var{string}"} means a literal @var{string}.
16308@end itemize
16309
16310@ignore
16311@heading Dependencies
16312@end ignore
16313
16314@heading Acknowledgments
16315
16316In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16317Elena Zannoni.
16318
16319@menu
16320* GDB/MI Command Syntax::
16321* GDB/MI Compatibility with CLI::
16322* GDB/MI Output Records::
16323* GDB/MI Command Description Format::
16324* GDB/MI Breakpoint Table Commands::
16325* GDB/MI Data Manipulation::
16326* GDB/MI Program Control::
16327* GDB/MI Miscellaneous Commands::
16328@ignore
16329* GDB/MI Kod Commands::
16330* GDB/MI Memory Overlay Commands::
16331* GDB/MI Signal Handling Commands::
16332@end ignore
16333* GDB/MI Stack Manipulation::
16334* GDB/MI Symbol Query::
16335* GDB/MI Target Manipulation::
16336* GDB/MI Thread Commands::
16337* GDB/MI Tracepoint Commands::
16338* GDB/MI Variable Objects::
16339@end menu
16340
16341@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16342@node GDB/MI Command Syntax
16343@section @sc{gdb/mi} Command Syntax
16344
16345@menu
16346* GDB/MI Input Syntax::
16347* GDB/MI Output Syntax::
16348* GDB/MI Simple Examples::
16349@end menu
16350
16351@node GDB/MI Input Syntax
16352@subsection @sc{gdb/mi} Input Syntax
16353
16354@cindex input syntax for @sc{gdb/mi}
16355@cindex @sc{gdb/mi}, input syntax
16356@table @code
16357@item @var{command} @expansion{}
16358@code{@var{cli-command} | @var{mi-command}}
16359
16360@item @var{cli-command} @expansion{}
16361@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16362@var{cli-command} is any existing @value{GDBN} CLI command.
16363
16364@item @var{mi-command} @expansion{}
16365@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16366@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16367
16368@item @var{token} @expansion{}
16369"any sequence of digits"
16370
16371@item @var{option} @expansion{}
16372@code{"-" @var{parameter} [ " " @var{parameter} ]}
16373
16374@item @var{parameter} @expansion{}
16375@code{@var{non-blank-sequence} | @var{c-string}}
16376
16377@item @var{operation} @expansion{}
16378@emph{any of the operations described in this chapter}
16379
16380@item @var{non-blank-sequence} @expansion{}
16381@emph{anything, provided it doesn't contain special characters such as
16382"-", @var{nl}, """ and of course " "}
16383
16384@item @var{c-string} @expansion{}
16385@code{""" @var{seven-bit-iso-c-string-content} """}
16386
16387@item @var{nl} @expansion{}
16388@code{CR | CR-LF}
16389@end table
16390
16391@noindent
16392Notes:
16393
16394@itemize @bullet
16395@item
16396The CLI commands are still handled by the @sc{mi} interpreter; their
16397output is described below.
16398
16399@item
16400The @code{@var{token}}, when present, is passed back when the command
16401finishes.
16402
16403@item
16404Some @sc{mi} commands accept optional arguments as part of the parameter
16405list. Each option is identified by a leading @samp{-} (dash) and may be
16406followed by an optional argument parameter. Options occur first in the
16407parameter list and can be delimited from normal parameters using
16408@samp{--} (this is useful when some parameters begin with a dash).
16409@end itemize
16410
16411Pragmatics:
16412
16413@itemize @bullet
16414@item
16415We want easy access to the existing CLI syntax (for debugging).
16416
16417@item
16418We want it to be easy to spot a @sc{mi} operation.
16419@end itemize
16420
16421@node GDB/MI Output Syntax
16422@subsection @sc{gdb/mi} Output Syntax
16423
16424@cindex output syntax of @sc{gdb/mi}
16425@cindex @sc{gdb/mi}, output syntax
16426The output from @sc{gdb/mi} consists of zero or more out-of-band records
16427followed, optionally, by a single result record. This result record
16428is for the most recent command. The sequence of output records is
16429terminated by @samp{(@value{GDBP})}.
16430
16431If an input command was prefixed with a @code{@var{token}} then the
16432corresponding output for that command will also be prefixed by that same
16433@var{token}.
16434
16435@table @code
16436@item @var{output} @expansion{}
f7dc1244 16437@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16438
16439@item @var{result-record} @expansion{}
16440@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16441
16442@item @var{out-of-band-record} @expansion{}
16443@code{@var{async-record} | @var{stream-record}}
16444
16445@item @var{async-record} @expansion{}
16446@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16447
16448@item @var{exec-async-output} @expansion{}
16449@code{[ @var{token} ] "*" @var{async-output}}
16450
16451@item @var{status-async-output} @expansion{}
16452@code{[ @var{token} ] "+" @var{async-output}}
16453
16454@item @var{notify-async-output} @expansion{}
16455@code{[ @var{token} ] "=" @var{async-output}}
16456
16457@item @var{async-output} @expansion{}
16458@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16459
16460@item @var{result-class} @expansion{}
16461@code{"done" | "running" | "connected" | "error" | "exit"}
16462
16463@item @var{async-class} @expansion{}
16464@code{"stopped" | @var{others}} (where @var{others} will be added
16465depending on the needs---this is still in development).
16466
16467@item @var{result} @expansion{}
16468@code{ @var{variable} "=" @var{value}}
16469
16470@item @var{variable} @expansion{}
16471@code{ @var{string} }
16472
16473@item @var{value} @expansion{}
16474@code{ @var{const} | @var{tuple} | @var{list} }
16475
16476@item @var{const} @expansion{}
16477@code{@var{c-string}}
16478
16479@item @var{tuple} @expansion{}
16480@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16481
16482@item @var{list} @expansion{}
16483@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16484@var{result} ( "," @var{result} )* "]" }
16485
16486@item @var{stream-record} @expansion{}
16487@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16488
16489@item @var{console-stream-output} @expansion{}
16490@code{"~" @var{c-string}}
16491
16492@item @var{target-stream-output} @expansion{}
16493@code{"@@" @var{c-string}}
16494
16495@item @var{log-stream-output} @expansion{}
16496@code{"&" @var{c-string}}
16497
16498@item @var{nl} @expansion{}
16499@code{CR | CR-LF}
16500
16501@item @var{token} @expansion{}
16502@emph{any sequence of digits}.
16503@end table
16504
16505@noindent
16506Notes:
16507
16508@itemize @bullet
16509@item
16510All output sequences end in a single line containing a period.
16511
16512@item
16513The @code{@var{token}} is from the corresponding request. If an execution
16514command is interrupted by the @samp{-exec-interrupt} command, the
16515@var{token} associated with the @samp{*stopped} message is the one of the
16516original execution command, not the one of the interrupt command.
16517
16518@item
16519@cindex status output in @sc{gdb/mi}
16520@var{status-async-output} contains on-going status information about the
16521progress of a slow operation. It can be discarded. All status output is
16522prefixed by @samp{+}.
16523
16524@item
16525@cindex async output in @sc{gdb/mi}
16526@var{exec-async-output} contains asynchronous state change on the target
16527(stopped, started, disappeared). All async output is prefixed by
16528@samp{*}.
16529
16530@item
16531@cindex notify output in @sc{gdb/mi}
16532@var{notify-async-output} contains supplementary information that the
16533client should handle (e.g., a new breakpoint information). All notify
16534output is prefixed by @samp{=}.
16535
16536@item
16537@cindex console output in @sc{gdb/mi}
16538@var{console-stream-output} is output that should be displayed as is in the
16539console. It is the textual response to a CLI command. All the console
16540output is prefixed by @samp{~}.
16541
16542@item
16543@cindex target output in @sc{gdb/mi}
16544@var{target-stream-output} is the output produced by the target program.
16545All the target output is prefixed by @samp{@@}.
16546
16547@item
16548@cindex log output in @sc{gdb/mi}
16549@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16550instance messages that should be displayed as part of an error log. All
16551the log output is prefixed by @samp{&}.
16552
16553@item
16554@cindex list output in @sc{gdb/mi}
16555New @sc{gdb/mi} commands should only output @var{lists} containing
16556@var{values}.
16557
16558
16559@end itemize
16560
16561@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16562details about the various output records.
16563
16564@node GDB/MI Simple Examples
16565@subsection Simple Examples of @sc{gdb/mi} Interaction
16566@cindex @sc{gdb/mi}, simple examples
16567
16568This subsection presents several simple examples of interaction using
16569the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16570following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16571the output received from @sc{gdb/mi}.
16572
16573@subsubheading Target Stop
16574@c Ummm... There is no "-stop" command. This assumes async, no?
16575Here's an example of stopping the inferior process:
16576
16577@smallexample
16578-> -stop
16579<- (@value{GDBP})
16580@end smallexample
16581
16582@noindent
16583and later:
16584
16585@smallexample
16586<- *stop,reason="stop",address="0x123",source="a.c:123"
16587<- (@value{GDBP})
16588@end smallexample
16589
16590@subsubheading Simple CLI Command
16591
16592Here's an example of a simple CLI command being passed through
16593@sc{gdb/mi} and on to the CLI.
16594
16595@smallexample
16596-> print 1+2
16597<- &"print 1+2\n"
16598<- ~"$1 = 3\n"
16599<- ^done
16600<- (@value{GDBP})
16601@end smallexample
16602
16603@subsubheading Command With Side Effects
16604
16605@smallexample
16606-> -symbol-file xyz.exe
16607<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16608<- (@value{GDBP})
16609@end smallexample
16610
16611@subsubheading A Bad Command
16612
16613Here's what happens if you pass a non-existent command:
16614
16615@smallexample
16616-> -rubbish
16617<- ^error,msg="Undefined MI command: rubbish"
16618<- (@value{GDBP})
16619@end smallexample
16620
16621@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16622@node GDB/MI Compatibility with CLI
16623@section @sc{gdb/mi} Compatibility with CLI
16624
16625@cindex compatibility, @sc{gdb/mi} and CLI
16626@cindex @sc{gdb/mi}, compatibility with CLI
16627To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16628accepts existing CLI commands. As specified by the syntax, such
16629commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16630respond.
16631
16632This mechanism is provided as an aid to developers of @sc{gdb/mi}
16633clients and not as a reliable interface into the CLI. Since the command
16634is being interpreteted in an environment that assumes @sc{gdb/mi}
16635behaviour, the exact output of such commands is likely to end up being
16636an un-supported hybrid of @sc{gdb/mi} and CLI output.
16637
16638@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16639@node GDB/MI Output Records
16640@section @sc{gdb/mi} Output Records
16641
16642@menu
16643* GDB/MI Result Records::
16644* GDB/MI Stream Records::
16645* GDB/MI Out-of-band Records::
16646@end menu
16647
16648@node GDB/MI Result Records
16649@subsection @sc{gdb/mi} Result Records
16650
16651@cindex result records in @sc{gdb/mi}
16652@cindex @sc{gdb/mi}, result records
16653In addition to a number of out-of-band notifications, the response to a
16654@sc{gdb/mi} command includes one of the following result indications:
16655
16656@table @code
16657@findex ^done
16658@item "^done" [ "," @var{results} ]
16659The synchronous operation was successful, @code{@var{results}} are the return
16660values.
16661
16662@item "^running"
16663@findex ^running
16664@c Is this one correct? Should it be an out-of-band notification?
16665The asynchronous operation was successfully started. The target is
16666running.
16667
16668@item "^error" "," @var{c-string}
16669@findex ^error
16670The operation failed. The @code{@var{c-string}} contains the corresponding
16671error message.
16672@end table
16673
16674@node GDB/MI Stream Records
16675@subsection @sc{gdb/mi} Stream Records
16676
16677@cindex @sc{gdb/mi}, stream records
16678@cindex stream records in @sc{gdb/mi}
16679@value{GDBN} internally maintains a number of output streams: the console, the
16680target, and the log. The output intended for each of these streams is
16681funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16682
16683Each stream record begins with a unique @dfn{prefix character} which
16684identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16685Syntax}). In addition to the prefix, each stream record contains a
16686@code{@var{string-output}}. This is either raw text (with an implicit new
16687line) or a quoted C string (which does not contain an implicit newline).
16688
16689@table @code
16690@item "~" @var{string-output}
16691The console output stream contains text that should be displayed in the
16692CLI console window. It contains the textual responses to CLI commands.
16693
16694@item "@@" @var{string-output}
16695The target output stream contains any textual output from the running
16696target.
16697
16698@item "&" @var{string-output}
16699The log stream contains debugging messages being produced by @value{GDBN}'s
16700internals.
16701@end table
16702
16703@node GDB/MI Out-of-band Records
16704@subsection @sc{gdb/mi} Out-of-band Records
16705
16706@cindex out-of-band records in @sc{gdb/mi}
16707@cindex @sc{gdb/mi}, out-of-band records
16708@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
16709additional changes that have occurred. Those changes can either be a
16710consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
16711target activity (e.g., target stopped).
16712
16713The following is a preliminary list of possible out-of-band records.
16714
16715@table @code
16716@item "*" "stop"
16717@end table
16718
16719
16720@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16721@node GDB/MI Command Description Format
16722@section @sc{gdb/mi} Command Description Format
16723
16724The remaining sections describe blocks of commands. Each block of
16725commands is laid out in a fashion similar to this section.
16726
16727Note the the line breaks shown in the examples are here only for
16728readability. They don't appear in the real output.
16729Also note that the commands with a non-available example (N.A.@:) are
16730not yet implemented.
16731
16732@subheading Motivation
16733
16734The motivation for this collection of commands.
16735
16736@subheading Introduction
16737
16738A brief introduction to this collection of commands as a whole.
16739
16740@subheading Commands
16741
16742For each command in the block, the following is described:
16743
16744@subsubheading Synopsis
16745
16746@smallexample
16747 -command @var{args}@dots{}
16748@end smallexample
16749
16750@subsubheading @value{GDBN} Command
16751
16752The corresponding @value{GDBN} CLI command.
16753
16754@subsubheading Result
16755
16756@subsubheading Out-of-band
16757
16758@subsubheading Notes
16759
16760@subsubheading Example
16761
16762
16763@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16764@node GDB/MI Breakpoint Table Commands
16765@section @sc{gdb/mi} Breakpoint table commands
16766
16767@cindex breakpoint commands for @sc{gdb/mi}
16768@cindex @sc{gdb/mi}, breakpoint commands
16769This section documents @sc{gdb/mi} commands for manipulating
16770breakpoints.
16771
16772@subheading The @code{-break-after} Command
16773@findex -break-after
16774
16775@subsubheading Synopsis
16776
16777@smallexample
16778 -break-after @var{number} @var{count}
16779@end smallexample
16780
16781The breakpoint number @var{number} is not in effect until it has been
16782hit @var{count} times. To see how this is reflected in the output of
16783the @samp{-break-list} command, see the description of the
16784@samp{-break-list} command below.
16785
16786@subsubheading @value{GDBN} Command
16787
16788The corresponding @value{GDBN} command is @samp{ignore}.
16789
16790@subsubheading Example
16791
16792@smallexample
16793(@value{GDBP})
16794-break-insert main
16795^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
16796(@value{GDBP})
16797-break-after 1 3
16798~
16799^done
16800(@value{GDBP})
16801-break-list
16802^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16803hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16804@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16805@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16806@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16807@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16808@{width="40",alignment="2",col_name="what",colhdr="What"@}],
16809body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
16810addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
16811ignore="3"@}]@}
16812(@value{GDBP})
16813@end smallexample
16814
16815@ignore
16816@subheading The @code{-break-catch} Command
16817@findex -break-catch
16818
16819@subheading The @code{-break-commands} Command
16820@findex -break-commands
16821@end ignore
16822
16823
16824@subheading The @code{-break-condition} Command
16825@findex -break-condition
16826
16827@subsubheading Synopsis
16828
16829@smallexample
16830 -break-condition @var{number} @var{expr}
16831@end smallexample
16832
16833Breakpoint @var{number} will stop the program only if the condition in
16834@var{expr} is true. The condition becomes part of the
16835@samp{-break-list} output (see the description of the @samp{-break-list}
16836command below).
16837
16838@subsubheading @value{GDBN} Command
16839
16840The corresponding @value{GDBN} command is @samp{condition}.
16841
16842@subsubheading Example
16843
16844@smallexample
16845(@value{GDBP})
16846-break-condition 1 1
16847^done
16848(@value{GDBP})
16849-break-list
16850^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16851hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16852@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16853@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16854@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16855@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16856@{width="40",alignment="2",col_name="what",colhdr="What"@}],
16857body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
16858addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
16859times="0",ignore="3"@}]@}
16860(@value{GDBP})
16861@end smallexample
16862
16863@subheading The @code{-break-delete} Command
16864@findex -break-delete
16865
16866@subsubheading Synopsis
16867
16868@smallexample
16869 -break-delete ( @var{breakpoint} )+
16870@end smallexample
16871
16872Delete the breakpoint(s) whose number(s) are specified in the argument
16873list. This is obviously reflected in the breakpoint list.
16874
16875@subsubheading @value{GDBN} command
16876
16877The corresponding @value{GDBN} command is @samp{delete}.
16878
16879@subsubheading Example
16880
16881@smallexample
16882(@value{GDBP})
16883-break-delete 1
16884^done
16885(@value{GDBP})
16886-break-list
16887^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
16888hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16889@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16890@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16891@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16892@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16893@{width="40",alignment="2",col_name="what",colhdr="What"@}],
16894body=[]@}
16895(@value{GDBP})
16896@end smallexample
16897
16898@subheading The @code{-break-disable} Command
16899@findex -break-disable
16900
16901@subsubheading Synopsis
16902
16903@smallexample
16904 -break-disable ( @var{breakpoint} )+
16905@end smallexample
16906
16907Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
16908break list is now set to @samp{n} for the named @var{breakpoint}(s).
16909
16910@subsubheading @value{GDBN} Command
16911
16912The corresponding @value{GDBN} command is @samp{disable}.
16913
16914@subsubheading Example
16915
16916@smallexample
16917(@value{GDBP})
16918-break-disable 2
16919^done
16920(@value{GDBP})
16921-break-list
16922^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16923hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16924@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16925@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16926@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16927@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16928@{width="40",alignment="2",col_name="what",colhdr="What"@}],
16929body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
16930addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
16931(@value{GDBP})
16932@end smallexample
16933
16934@subheading The @code{-break-enable} Command
16935@findex -break-enable
16936
16937@subsubheading Synopsis
16938
16939@smallexample
16940 -break-enable ( @var{breakpoint} )+
16941@end smallexample
16942
16943Enable (previously disabled) @var{breakpoint}(s).
16944
16945@subsubheading @value{GDBN} Command
16946
16947The corresponding @value{GDBN} command is @samp{enable}.
16948
16949@subsubheading Example
16950
16951@smallexample
16952(@value{GDBP})
16953-break-enable 2
16954^done
16955(@value{GDBP})
16956-break-list
16957^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
16958hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
16959@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
16960@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
16961@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
16962@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
16963@{width="40",alignment="2",col_name="what",colhdr="What"@}],
16964body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
16965addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
16966(@value{GDBP})
16967@end smallexample
16968
16969@subheading The @code{-break-info} Command
16970@findex -break-info
16971
16972@subsubheading Synopsis
16973
16974@smallexample
16975 -break-info @var{breakpoint}
16976@end smallexample
16977
16978@c REDUNDANT???
16979Get information about a single breakpoint.
16980
16981@subsubheading @value{GDBN} command
16982
16983The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
16984
16985@subsubheading Example
16986N.A.
16987
16988@subheading The @code{-break-insert} Command
16989@findex -break-insert
16990
16991@subsubheading Synopsis
16992
16993@smallexample
16994 -break-insert [ -t ] [ -h ] [ -r ]
16995 [ -c @var{condition} ] [ -i @var{ignore-count} ]
16996 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
16997@end smallexample
16998
16999@noindent
17000If specified, @var{line}, can be one of:
17001
17002@itemize @bullet
17003@item function
17004@c @item +offset
17005@c @item -offset
17006@c @item linenum
17007@item filename:linenum
17008@item filename:function
17009@item *address
17010@end itemize
17011
17012The possible optional parameters of this command are:
17013
17014@table @samp
17015@item -t
17016Insert a tempoary breakpoint.
17017@item -h
17018Insert a hardware breakpoint.
17019@item -c @var{condition}
17020Make the breakpoint conditional on @var{condition}.
17021@item -i @var{ignore-count}
17022Initialize the @var{ignore-count}.
17023@item -r
17024Insert a regular breakpoint in all the functions whose names match the
17025given regular expression. Other flags are not applicable to regular
17026expresson.
17027@end table
17028
17029@subsubheading Result
17030
17031The result is in the form:
17032
17033@smallexample
17034 ^done,bkptno="@var{number}",func="@var{funcname}",
17035 file="@var{filename}",line="@var{lineno}"
17036@end smallexample
17037
17038@noindent
17039where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17040is the name of the function where the breakpoint was inserted,
17041@var{filename} is the name of the source file which contains this
17042function, and @var{lineno} is the source line number within that file.
17043
17044Note: this format is open to change.
17045@c An out-of-band breakpoint instead of part of the result?
17046
17047@subsubheading @value{GDBN} Command
17048
17049The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17050@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17051
17052@subsubheading Example
17053
17054@smallexample
17055(@value{GDBP})
17056-break-insert main
17057^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17058(@value{GDBP})
17059-break-insert -t foo
17060^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17061(@value{GDBP})
17062-break-list
17063^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17064hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17065@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17066@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17067@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17068@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17069@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17070body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17071addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17072bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17073addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17074(@value{GDBP})
17075-break-insert -r foo.*
17076~int foo(int, int);
17077^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17078(@value{GDBP})
17079@end smallexample
17080
17081@subheading The @code{-break-list} Command
17082@findex -break-list
17083
17084@subsubheading Synopsis
17085
17086@smallexample
17087 -break-list
17088@end smallexample
17089
17090Displays the list of inserted breakpoints, showing the following fields:
17091
17092@table @samp
17093@item Number
17094number of the breakpoint
17095@item Type
17096type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17097@item Disposition
17098should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17099or @samp{nokeep}
17100@item Enabled
17101is the breakpoint enabled or no: @samp{y} or @samp{n}
17102@item Address
17103memory location at which the breakpoint is set
17104@item What
17105logical location of the breakpoint, expressed by function name, file
17106name, line number
17107@item Times
17108number of times the breakpoint has been hit
17109@end table
17110
17111If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17112@code{body} field is an empty list.
17113
17114@subsubheading @value{GDBN} Command
17115
17116The corresponding @value{GDBN} command is @samp{info break}.
17117
17118@subsubheading Example
17119
17120@smallexample
17121(@value{GDBP})
17122-break-list
17123^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17124hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17125@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17126@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17127@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17128@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17129@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17130body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17131addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17132bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17133addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17134(@value{GDBP})
17135@end smallexample
17136
17137Here's an example of the result when there are no breakpoints:
17138
17139@smallexample
17140(@value{GDBP})
17141-break-list
17142^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17143hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17144@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17145@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17146@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17147@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17148@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17149body=[]@}
17150(@value{GDBP})
17151@end smallexample
17152
17153@subheading The @code{-break-watch} Command
17154@findex -break-watch
17155
17156@subsubheading Synopsis
17157
17158@smallexample
17159 -break-watch [ -a | -r ]
17160@end smallexample
17161
17162Create a watchpoint. With the @samp{-a} option it will create an
17163@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17164read from or on a write to the memory location. With the @samp{-r}
17165option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17166trigger only when the memory location is accessed for reading. Without
17167either of the options, the watchpoint created is a regular watchpoint,
17168i.e. it will trigger when the memory location is accessed for writing.
17169@xref{Set Watchpoints, , Setting watchpoints}.
17170
17171Note that @samp{-break-list} will report a single list of watchpoints and
17172breakpoints inserted.
17173
17174@subsubheading @value{GDBN} Command
17175
17176The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17177@samp{rwatch}.
17178
17179@subsubheading Example
17180
17181Setting a watchpoint on a variable in the @code{main} function:
17182
17183@smallexample
17184(@value{GDBP})
17185-break-watch x
17186^done,wpt=@{number="2",exp="x"@}
17187(@value{GDBP})
17188-exec-continue
17189^running
17190^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17191value=@{old="-268439212",new="55"@},
17192frame=@{func="main",args=[],file="recursive2.c",line="5"@}
17193(@value{GDBP})
17194@end smallexample
17195
17196Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17197the program execution twice: first for the variable changing value, then
17198for the watchpoint going out of scope.
17199
17200@smallexample
17201(@value{GDBP})
17202-break-watch C
17203^done,wpt=@{number="5",exp="C"@}
17204(@value{GDBP})
17205-exec-continue
17206^running
17207^done,reason="watchpoint-trigger",
17208wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17209frame=@{func="callee4",args=[],
17210file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
17211(@value{GDBP})
17212-exec-continue
17213^running
17214^done,reason="watchpoint-scope",wpnum="5",
17215frame=@{func="callee3",args=[@{name="strarg",
17216value="0x11940 \"A string argument.\""@}],
17217file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17218(@value{GDBP})
17219@end smallexample
17220
17221Listing breakpoints and watchpoints, at different points in the program
17222execution. Note that once the watchpoint goes out of scope, it is
17223deleted.
17224
17225@smallexample
17226(@value{GDBP})
17227-break-watch C
17228^done,wpt=@{number="2",exp="C"@}
17229(@value{GDBP})
17230-break-list
17231^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17232hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17233@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17234@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17235@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17236@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17237@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17238body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17239addr="0x00010734",func="callee4",
17240file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17241bkpt=@{number="2",type="watchpoint",disp="keep",
17242enabled="y",addr="",what="C",times="0"@}]@}
17243(@value{GDBP})
17244-exec-continue
17245^running
17246^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17247value=@{old="-276895068",new="3"@},
17248frame=@{func="callee4",args=[],
17249file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
17250(@value{GDBP})
17251-break-list
17252^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17253hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17254@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17255@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17256@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17257@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17258@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17259body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17260addr="0x00010734",func="callee4",
17261file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17262bkpt=@{number="2",type="watchpoint",disp="keep",
17263enabled="y",addr="",what="C",times="-5"@}]@}
17264(@value{GDBP})
17265-exec-continue
17266^running
17267^done,reason="watchpoint-scope",wpnum="2",
17268frame=@{func="callee3",args=[@{name="strarg",
17269value="0x11940 \"A string argument.\""@}],
17270file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
17271(@value{GDBP})
17272-break-list
17273^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17274hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17275@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17276@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17277@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17278@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17279@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17280body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17281addr="0x00010734",func="callee4",
17282file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17283(@value{GDBP})
17284@end smallexample
17285
17286@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17287@node GDB/MI Data Manipulation
17288@section @sc{gdb/mi} Data Manipulation
17289
17290@cindex data manipulation, in @sc{gdb/mi}
17291@cindex @sc{gdb/mi}, data manipulation
17292This section describes the @sc{gdb/mi} commands that manipulate data:
17293examine memory and registers, evaluate expressions, etc.
17294
17295@c REMOVED FROM THE INTERFACE.
17296@c @subheading -data-assign
17297@c Change the value of a program variable. Plenty of side effects.
17298@c @subsubheading GDB command
17299@c set variable
17300@c @subsubheading Example
17301@c N.A.
17302
17303@subheading The @code{-data-disassemble} Command
17304@findex -data-disassemble
17305
17306@subsubheading Synopsis
17307
17308@smallexample
17309 -data-disassemble
17310 [ -s @var{start-addr} -e @var{end-addr} ]
17311 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17312 -- @var{mode}
17313@end smallexample
17314
17315@noindent
17316Where:
17317
17318@table @samp
17319@item @var{start-addr}
17320is the beginning address (or @code{$pc})
17321@item @var{end-addr}
17322is the end address
17323@item @var{filename}
17324is the name of the file to disassemble
17325@item @var{linenum}
17326is the line number to disassemble around
17327@item @var{lines}
17328is the the number of disassembly lines to be produced. If it is -1,
17329the whole function will be disassembled, in case no @var{end-addr} is
17330specified. If @var{end-addr} is specified as a non-zero value, and
17331@var{lines} is lower than the number of disassembly lines between
17332@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17333displayed; if @var{lines} is higher than the number of lines between
17334@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17335are displayed.
17336@item @var{mode}
17337is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17338disassembly).
17339@end table
17340
17341@subsubheading Result
17342
17343The output for each instruction is composed of four fields:
17344
17345@itemize @bullet
17346@item Address
17347@item Func-name
17348@item Offset
17349@item Instruction
17350@end itemize
17351
17352Note that whatever included in the instruction field, is not manipulated
17353directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17354
17355@subsubheading @value{GDBN} Command
17356
17357There's no direct mapping from this command to the CLI.
17358
17359@subsubheading Example
17360
17361Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17362
17363@smallexample
17364(@value{GDBP})
17365-data-disassemble -s $pc -e "$pc + 20" -- 0
17366^done,
17367asm_insns=[
17368@{address="0x000107c0",func-name="main",offset="4",
17369inst="mov 2, %o0"@},
17370@{address="0x000107c4",func-name="main",offset="8",
17371inst="sethi %hi(0x11800), %o2"@},
17372@{address="0x000107c8",func-name="main",offset="12",
17373inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17374@{address="0x000107cc",func-name="main",offset="16",
17375inst="sethi %hi(0x11800), %o2"@},
17376@{address="0x000107d0",func-name="main",offset="20",
17377inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17378(@value{GDBP})
17379@end smallexample
17380
17381Disassemble the whole @code{main} function. Line 32 is part of
17382@code{main}.
17383
17384@smallexample
17385-data-disassemble -f basics.c -l 32 -- 0
17386^done,asm_insns=[
17387@{address="0x000107bc",func-name="main",offset="0",
17388inst="save %sp, -112, %sp"@},
17389@{address="0x000107c0",func-name="main",offset="4",
17390inst="mov 2, %o0"@},
17391@{address="0x000107c4",func-name="main",offset="8",
17392inst="sethi %hi(0x11800), %o2"@},
17393[@dots{}]
17394@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17395@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17396(@value{GDBP})
17397@end smallexample
17398
17399Disassemble 3 instructions from the start of @code{main}:
17400
17401@smallexample
17402(@value{GDBP})
17403-data-disassemble -f basics.c -l 32 -n 3 -- 0
17404^done,asm_insns=[
17405@{address="0x000107bc",func-name="main",offset="0",
17406inst="save %sp, -112, %sp"@},
17407@{address="0x000107c0",func-name="main",offset="4",
17408inst="mov 2, %o0"@},
17409@{address="0x000107c4",func-name="main",offset="8",
17410inst="sethi %hi(0x11800), %o2"@}]
17411(@value{GDBP})
17412@end smallexample
17413
17414Disassemble 3 instructions from the start of @code{main} in mixed mode:
17415
17416@smallexample
17417(@value{GDBP})
17418-data-disassemble -f basics.c -l 32 -n 3 -- 1
17419^done,asm_insns=[
17420src_and_asm_line=@{line="31",
17421file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17422 testsuite/gdb.mi/basics.c",line_asm_insn=[
17423@{address="0x000107bc",func-name="main",offset="0",
17424inst="save %sp, -112, %sp"@}]@},
17425src_and_asm_line=@{line="32",
17426file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17427 testsuite/gdb.mi/basics.c",line_asm_insn=[
17428@{address="0x000107c0",func-name="main",offset="4",
17429inst="mov 2, %o0"@},
17430@{address="0x000107c4",func-name="main",offset="8",
17431inst="sethi %hi(0x11800), %o2"@}]@}]
17432(@value{GDBP})
17433@end smallexample
17434
17435
17436@subheading The @code{-data-evaluate-expression} Command
17437@findex -data-evaluate-expression
17438
17439@subsubheading Synopsis
17440
17441@smallexample
17442 -data-evaluate-expression @var{expr}
17443@end smallexample
17444
17445Evaluate @var{expr} as an expression. The expression could contain an
17446inferior function call. The function call will execute synchronously.
17447If the expression contains spaces, it must be enclosed in double quotes.
17448
17449@subsubheading @value{GDBN} Command
17450
17451The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17452@samp{call}. In @code{gdbtk} only, there's a corresponding
17453@samp{gdb_eval} command.
17454
17455@subsubheading Example
17456
17457In the following example, the numbers that precede the commands are the
17458@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17459Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17460output.
17461
17462@smallexample
17463211-data-evaluate-expression A
17464211^done,value="1"
17465(@value{GDBP})
17466311-data-evaluate-expression &A
17467311^done,value="0xefffeb7c"
17468(@value{GDBP})
17469411-data-evaluate-expression A+3
17470411^done,value="4"
17471(@value{GDBP})
17472511-data-evaluate-expression "A + 3"
17473511^done,value="4"
17474(@value{GDBP})
17475@end smallexample
17476
17477
17478@subheading The @code{-data-list-changed-registers} Command
17479@findex -data-list-changed-registers
17480
17481@subsubheading Synopsis
17482
17483@smallexample
17484 -data-list-changed-registers
17485@end smallexample
17486
17487Display a list of the registers that have changed.
17488
17489@subsubheading @value{GDBN} Command
17490
17491@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17492has the corresponding command @samp{gdb_changed_register_list}.
17493
17494@subsubheading Example
17495
17496On a PPC MBX board:
17497
17498@smallexample
17499(@value{GDBP})
17500-exec-continue
17501^running
17502
17503(@value{GDBP})
17504*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
17505args=[],file="try.c",line="5"@}
17506(@value{GDBP})
17507-data-list-changed-registers
17508^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17509"10","11","13","14","15","16","17","18","19","20","21","22","23",
17510"24","25","26","27","28","30","31","64","65","66","67","69"]
17511(@value{GDBP})
17512@end smallexample
17513
17514
17515@subheading The @code{-data-list-register-names} Command
17516@findex -data-list-register-names
17517
17518@subsubheading Synopsis
17519
17520@smallexample
17521 -data-list-register-names [ ( @var{regno} )+ ]
17522@end smallexample
17523
17524Show a list of register names for the current target. If no arguments
17525are given, it shows a list of the names of all the registers. If
17526integer numbers are given as arguments, it will print a list of the
17527names of the registers corresponding to the arguments. To ensure
17528consistency between a register name and its number, the output list may
17529include empty register names.
17530
17531@subsubheading @value{GDBN} Command
17532
17533@value{GDBN} does not have a command which corresponds to
17534@samp{-data-list-register-names}. In @code{gdbtk} there is a
17535corresponding command @samp{gdb_regnames}.
17536
17537@subsubheading Example
17538
17539For the PPC MBX board:
17540@smallexample
17541(@value{GDBP})
17542-data-list-register-names
17543^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17544"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17545"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17546"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17547"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17548"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17549"", "pc","ps","cr","lr","ctr","xer"]
17550(@value{GDBP})
17551-data-list-register-names 1 2 3
17552^done,register-names=["r1","r2","r3"]
17553(@value{GDBP})
17554@end smallexample
17555
17556@subheading The @code{-data-list-register-values} Command
17557@findex -data-list-register-values
17558
17559@subsubheading Synopsis
17560
17561@smallexample
17562 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17563@end smallexample
17564
17565Display the registers' contents. @var{fmt} is the format according to
17566which the registers' contents are to be returned, followed by an optional
17567list of numbers specifying the registers to display. A missing list of
17568numbers indicates that the contents of all the registers must be returned.
17569
17570Allowed formats for @var{fmt} are:
17571
17572@table @code
17573@item x
17574Hexadecimal
17575@item o
17576Octal
17577@item t
17578Binary
17579@item d
17580Decimal
17581@item r
17582Raw
17583@item N
17584Natural
17585@end table
17586
17587@subsubheading @value{GDBN} Command
17588
17589The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17590all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17591
17592@subsubheading Example
17593
17594For a PPC MBX board (note: line breaks are for readability only, they
17595don't appear in the actual output):
17596
17597@smallexample
17598(@value{GDBP})
17599-data-list-register-values r 64 65
17600^done,register-values=[@{number="64",value="0xfe00a300"@},
17601@{number="65",value="0x00029002"@}]
17602(@value{GDBP})
17603-data-list-register-values x
17604^done,register-values=[@{number="0",value="0xfe0043c8"@},
17605@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17606@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17607@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17608@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17609@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17610@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17611@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17612@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17613@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17614@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17615@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17616@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17617@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17618@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17619@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17620@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17621@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17622@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17623@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17624@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17625@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17626@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17627@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17628@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17629@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17630@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17631@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17632@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17633@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17634@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17635@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17636@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17637@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17638@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17639@{number="69",value="0x20002b03"@}]
17640(@value{GDBP})
17641@end smallexample
17642
17643
17644@subheading The @code{-data-read-memory} Command
17645@findex -data-read-memory
17646
17647@subsubheading Synopsis
17648
17649@smallexample
17650 -data-read-memory [ -o @var{byte-offset} ]
17651 @var{address} @var{word-format} @var{word-size}
17652 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17653@end smallexample
17654
17655@noindent
17656where:
17657
17658@table @samp
17659@item @var{address}
17660An expression specifying the address of the first memory word to be
17661read. Complex expressions containing embedded white space should be
17662quoted using the C convention.
17663
17664@item @var{word-format}
17665The format to be used to print the memory words. The notation is the
17666same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17667,Output formats}).
17668
17669@item @var{word-size}
17670The size of each memory word in bytes.
17671
17672@item @var{nr-rows}
17673The number of rows in the output table.
17674
17675@item @var{nr-cols}
17676The number of columns in the output table.
17677
17678@item @var{aschar}
17679If present, indicates that each row should include an @sc{ascii} dump. The
17680value of @var{aschar} is used as a padding character when a byte is not a
17681member of the printable @sc{ascii} character set (printable @sc{ascii}
17682characters are those whose code is between 32 and 126, inclusively).
17683
17684@item @var{byte-offset}
17685An offset to add to the @var{address} before fetching memory.
17686@end table
17687
17688This command displays memory contents as a table of @var{nr-rows} by
17689@var{nr-cols} words, each word being @var{word-size} bytes. In total,
17690@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
17691(returned as @samp{total-bytes}). Should less than the requested number
17692of bytes be returned by the target, the missing words are identified
17693using @samp{N/A}. The number of bytes read from the target is returned
17694in @samp{nr-bytes} and the starting address used to read memory in
17695@samp{addr}.
17696
17697The address of the next/previous row or page is available in
17698@samp{next-row} and @samp{prev-row}, @samp{next-page} and
17699@samp{prev-page}.
17700
17701@subsubheading @value{GDBN} Command
17702
17703The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
17704@samp{gdb_get_mem} memory read command.
17705
17706@subsubheading Example
17707
17708Read six bytes of memory starting at @code{bytes+6} but then offset by
17709@code{-6} bytes. Format as three rows of two columns. One byte per
17710word. Display each word in hex.
17711
17712@smallexample
17713(@value{GDBP})
177149-data-read-memory -o -6 -- bytes+6 x 1 3 2
177159^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
17716next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
17717prev-page="0x0000138a",memory=[
17718@{addr="0x00001390",data=["0x00","0x01"]@},
17719@{addr="0x00001392",data=["0x02","0x03"]@},
17720@{addr="0x00001394",data=["0x04","0x05"]@}]
17721(@value{GDBP})
17722@end smallexample
17723
17724Read two bytes of memory starting at address @code{shorts + 64} and
17725display as a single word formatted in decimal.
17726
17727@smallexample
17728(@value{GDBP})
177295-data-read-memory shorts+64 d 2 1 1
177305^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
17731next-row="0x00001512",prev-row="0x0000150e",
17732next-page="0x00001512",prev-page="0x0000150e",memory=[
17733@{addr="0x00001510",data=["128"]@}]
17734(@value{GDBP})
17735@end smallexample
17736
17737Read thirty two bytes of memory starting at @code{bytes+16} and format
17738as eight rows of four columns. Include a string encoding with @samp{x}
17739used as the non-printable character.
17740
17741@smallexample
17742(@value{GDBP})
177434-data-read-memory bytes+16 x 1 8 4 x
177444^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
17745next-row="0x000013c0",prev-row="0x0000139c",
17746next-page="0x000013c0",prev-page="0x00001380",memory=[
17747@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
17748@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
17749@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
17750@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
17751@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
17752@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
17753@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
17754@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
17755(@value{GDBP})
17756@end smallexample
17757
17758@subheading The @code{-display-delete} Command
17759@findex -display-delete
17760
17761@subsubheading Synopsis
17762
17763@smallexample
17764 -display-delete @var{number}
17765@end smallexample
17766
17767Delete the display @var{number}.
17768
17769@subsubheading @value{GDBN} Command
17770
17771The corresponding @value{GDBN} command is @samp{delete display}.
17772
17773@subsubheading Example
17774N.A.
17775
17776
17777@subheading The @code{-display-disable} Command
17778@findex -display-disable
17779
17780@subsubheading Synopsis
17781
17782@smallexample
17783 -display-disable @var{number}
17784@end smallexample
17785
17786Disable display @var{number}.
17787
17788@subsubheading @value{GDBN} Command
17789
17790The corresponding @value{GDBN} command is @samp{disable display}.
17791
17792@subsubheading Example
17793N.A.
17794
17795
17796@subheading The @code{-display-enable} Command
17797@findex -display-enable
17798
17799@subsubheading Synopsis
17800
17801@smallexample
17802 -display-enable @var{number}
17803@end smallexample
17804
17805Enable display @var{number}.
17806
17807@subsubheading @value{GDBN} Command
17808
17809The corresponding @value{GDBN} command is @samp{enable display}.
17810
17811@subsubheading Example
17812N.A.
17813
17814
17815@subheading The @code{-display-insert} Command
17816@findex -display-insert
17817
17818@subsubheading Synopsis
17819
17820@smallexample
17821 -display-insert @var{expression}
17822@end smallexample
17823
17824Display @var{expression} every time the program stops.
17825
17826@subsubheading @value{GDBN} Command
17827
17828The corresponding @value{GDBN} command is @samp{display}.
17829
17830@subsubheading Example
17831N.A.
17832
17833
17834@subheading The @code{-display-list} Command
17835@findex -display-list
17836
17837@subsubheading Synopsis
17838
17839@smallexample
17840 -display-list
17841@end smallexample
17842
17843List the displays. Do not show the current values.
17844
17845@subsubheading @value{GDBN} Command
17846
17847The corresponding @value{GDBN} command is @samp{info display}.
17848
17849@subsubheading Example
17850N.A.
17851
17852
17853@subheading The @code{-environment-cd} Command
17854@findex -environment-cd
17855
17856@subsubheading Synopsis
17857
17858@smallexample
17859 -environment-cd @var{pathdir}
17860@end smallexample
17861
17862Set @value{GDBN}'s working directory.
17863
17864@subsubheading @value{GDBN} Command
17865
17866The corresponding @value{GDBN} command is @samp{cd}.
17867
17868@subsubheading Example
17869
17870@smallexample
17871(@value{GDBP})
17872-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
17873^done
17874(@value{GDBP})
17875@end smallexample
17876
17877
17878@subheading The @code{-environment-directory} Command
17879@findex -environment-directory
17880
17881@subsubheading Synopsis
17882
17883@smallexample
17884 -environment-directory [ -r ] [ @var{pathdir} ]+
17885@end smallexample
17886
17887Add directories @var{pathdir} to beginning of search path for source files.
17888If the @samp{-r} option is used, the search path is reset to the default
b383017d 17889search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
17890@samp{-r} option, the search path is first reset and then addition
17891occurs as normal.
b383017d 17892Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
17893multiple directories in a single command
17894results in the directories added to the beginning of the
17895search path in the same order they were presented in the command.
17896If blanks are needed as
17897part of a directory name, double-quotes should be used around
17898the name. In the command output, the path will show up separated
b383017d 17899by the system directory-separator character. The directory-seperator
922fbb7b
AC
17900character must not be used
17901in any directory name.
17902If no directories are specified, the current search path is displayed.
17903
17904@subsubheading @value{GDBN} Command
17905
17906The corresponding @value{GDBN} command is @samp{dir}.
17907
17908@subsubheading Example
17909
17910@smallexample
17911(@value{GDBP})
17912-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
17913^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
17914(@value{GDBP})
17915-environment-directory ""
17916^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
17917(@value{GDBP})
17918-environment-directory -r /home/jjohnstn/src/gdb /usr/src
17919^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
17920(@value{GDBP})
17921-environment-directory -r
17922^done,source-path="$cdir:$cwd"
17923(@value{GDBP})
17924@end smallexample
17925
17926
17927@subheading The @code{-environment-path} Command
17928@findex -environment-path
17929
17930@subsubheading Synopsis
17931
17932@smallexample
17933 -environment-path [ -r ] [ @var{pathdir} ]+
17934@end smallexample
17935
17936Add directories @var{pathdir} to beginning of search path for object files.
17937If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
17938search path that existed at gdb start-up. If directories @var{pathdir} are
17939supplied in addition to the
922fbb7b
AC
17940@samp{-r} option, the search path is first reset and then addition
17941occurs as normal.
b383017d 17942Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
17943multiple directories in a single command
17944results in the directories added to the beginning of the
17945search path in the same order they were presented in the command.
17946If blanks are needed as
17947part of a directory name, double-quotes should be used around
17948the name. In the command output, the path will show up separated
b383017d 17949by the system directory-separator character. The directory-seperator
922fbb7b
AC
17950character must not be used
17951in any directory name.
17952If no directories are specified, the current path is displayed.
17953
17954
17955@subsubheading @value{GDBN} Command
17956
17957The corresponding @value{GDBN} command is @samp{path}.
17958
17959@subsubheading Example
17960
17961@smallexample
17962(@value{GDBP})
b383017d 17963-environment-path
922fbb7b
AC
17964^done,path="/usr/bin"
17965(@value{GDBP})
17966-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
17967^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
17968(@value{GDBP})
17969-environment-path -r /usr/local/bin
17970^done,path="/usr/local/bin:/usr/bin"
17971(@value{GDBP})
17972@end smallexample
17973
17974
17975@subheading The @code{-environment-pwd} Command
17976@findex -environment-pwd
17977
17978@subsubheading Synopsis
17979
17980@smallexample
17981 -environment-pwd
17982@end smallexample
17983
17984Show the current working directory.
17985
17986@subsubheading @value{GDBN} command
17987
17988The corresponding @value{GDBN} command is @samp{pwd}.
17989
17990@subsubheading Example
17991
17992@smallexample
17993(@value{GDBP})
17994-environment-pwd
17995^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
17996(@value{GDBP})
17997@end smallexample
17998
17999@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18000@node GDB/MI Program Control
18001@section @sc{gdb/mi} Program control
18002
18003@subsubheading Program termination
18004
18005As a result of execution, the inferior program can run to completion, if
18006it doesn't encounter any breakpoints. In this case the output will
18007include an exit code, if the program has exited exceptionally.
18008
18009@subsubheading Examples
18010
18011@noindent
18012Program exited normally:
18013
18014@smallexample
18015(@value{GDBP})
18016-exec-run
18017^running
18018(@value{GDBP})
18019x = 55
18020*stopped,reason="exited-normally"
18021(@value{GDBP})
18022@end smallexample
18023
18024@noindent
18025Program exited exceptionally:
18026
18027@smallexample
18028(@value{GDBP})
18029-exec-run
18030^running
18031(@value{GDBP})
18032x = 55
18033*stopped,reason="exited",exit-code="01"
18034(@value{GDBP})
18035@end smallexample
18036
18037Another way the program can terminate is if it receives a signal such as
18038@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18039
18040@smallexample
18041(@value{GDBP})
18042*stopped,reason="exited-signalled",signal-name="SIGINT",
18043signal-meaning="Interrupt"
18044@end smallexample
18045
18046
18047@subheading The @code{-exec-abort} Command
18048@findex -exec-abort
18049
18050@subsubheading Synopsis
18051
18052@smallexample
18053 -exec-abort
18054@end smallexample
18055
18056Kill the inferior running program.
18057
18058@subsubheading @value{GDBN} Command
18059
18060The corresponding @value{GDBN} command is @samp{kill}.
18061
18062@subsubheading Example
18063N.A.
18064
18065
18066@subheading The @code{-exec-arguments} Command
18067@findex -exec-arguments
18068
18069@subsubheading Synopsis
18070
18071@smallexample
18072 -exec-arguments @var{args}
18073@end smallexample
18074
18075Set the inferior program arguments, to be used in the next
18076@samp{-exec-run}.
18077
18078@subsubheading @value{GDBN} Command
18079
18080The corresponding @value{GDBN} command is @samp{set args}.
18081
18082@subsubheading Example
18083
18084@c FIXME!
18085Don't have one around.
18086
18087
18088@subheading The @code{-exec-continue} Command
18089@findex -exec-continue
18090
18091@subsubheading Synopsis
18092
18093@smallexample
18094 -exec-continue
18095@end smallexample
18096
18097Asynchronous command. Resumes the execution of the inferior program
18098until a breakpoint is encountered, or until the inferior exits.
18099
18100@subsubheading @value{GDBN} Command
18101
18102The corresponding @value{GDBN} corresponding is @samp{continue}.
18103
18104@subsubheading Example
18105
18106@smallexample
18107-exec-continue
18108^running
18109(@value{GDBP})
18110@@Hello world
18111*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
18112file="hello.c",line="13"@}
18113(@value{GDBP})
18114@end smallexample
18115
18116
18117@subheading The @code{-exec-finish} Command
18118@findex -exec-finish
18119
18120@subsubheading Synopsis
18121
18122@smallexample
18123 -exec-finish
18124@end smallexample
18125
18126Asynchronous command. Resumes the execution of the inferior program
18127until the current function is exited. Displays the results returned by
18128the function.
18129
18130@subsubheading @value{GDBN} Command
18131
18132The corresponding @value{GDBN} command is @samp{finish}.
18133
18134@subsubheading Example
18135
18136Function returning @code{void}.
18137
18138@smallexample
18139-exec-finish
18140^running
18141(@value{GDBP})
18142@@hello from foo
18143*stopped,reason="function-finished",frame=@{func="main",args=[],
18144file="hello.c",line="7"@}
18145(@value{GDBP})
18146@end smallexample
18147
18148Function returning other than @code{void}. The name of the internal
18149@value{GDBN} variable storing the result is printed, together with the
18150value itself.
18151
18152@smallexample
18153-exec-finish
18154^running
18155(@value{GDBP})
18156*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18157args=[@{name="a",value="1"],@{name="b",value="9"@}@},
18158file="recursive2.c",line="14"@},
18159gdb-result-var="$1",return-value="0"
18160(@value{GDBP})
18161@end smallexample
18162
18163
18164@subheading The @code{-exec-interrupt} Command
18165@findex -exec-interrupt
18166
18167@subsubheading Synopsis
18168
18169@smallexample
18170 -exec-interrupt
18171@end smallexample
18172
18173Asynchronous command. Interrupts the background execution of the target.
18174Note how the token associated with the stop message is the one for the
18175execution command that has been interrupted. The token for the interrupt
18176itself only appears in the @samp{^done} output. If the user is trying to
18177interrupt a non-running program, an error message will be printed.
18178
18179@subsubheading @value{GDBN} Command
18180
18181The corresponding @value{GDBN} command is @samp{interrupt}.
18182
18183@subsubheading Example
18184
18185@smallexample
18186(@value{GDBP})
18187111-exec-continue
18188111^running
18189
18190(@value{GDBP})
18191222-exec-interrupt
18192222^done
18193(@value{GDBP})
18194111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
18195frame=@{addr="0x00010140",func="foo",args=[],file="try.c",line="13"@}
18196(@value{GDBP})
18197
18198(@value{GDBP})
18199-exec-interrupt
18200^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18201(@value{GDBP})
18202@end smallexample
18203
18204
18205@subheading The @code{-exec-next} Command
18206@findex -exec-next
18207
18208@subsubheading Synopsis
18209
18210@smallexample
18211 -exec-next
18212@end smallexample
18213
18214Asynchronous command. Resumes execution of the inferior program, stopping
18215when the beginning of the next source line is reached.
18216
18217@subsubheading @value{GDBN} Command
18218
18219The corresponding @value{GDBN} command is @samp{next}.
18220
18221@subsubheading Example
18222
18223@smallexample
18224-exec-next
18225^running
18226(@value{GDBP})
18227*stopped,reason="end-stepping-range",line="8",file="hello.c"
18228(@value{GDBP})
18229@end smallexample
18230
18231
18232@subheading The @code{-exec-next-instruction} Command
18233@findex -exec-next-instruction
18234
18235@subsubheading Synopsis
18236
18237@smallexample
18238 -exec-next-instruction
18239@end smallexample
18240
18241Asynchronous command. Executes one machine instruction. If the
18242instruction is a function call continues until the function returns. If
18243the program stops at an instruction in the middle of a source line, the
18244address will be printed as well.
18245
18246@subsubheading @value{GDBN} Command
18247
18248The corresponding @value{GDBN} command is @samp{nexti}.
18249
18250@subsubheading Example
18251
18252@smallexample
18253(@value{GDBP})
18254-exec-next-instruction
18255^running
18256
18257(@value{GDBP})
18258*stopped,reason="end-stepping-range",
18259addr="0x000100d4",line="5",file="hello.c"
18260(@value{GDBP})
18261@end smallexample
18262
18263
18264@subheading The @code{-exec-return} Command
18265@findex -exec-return
18266
18267@subsubheading Synopsis
18268
18269@smallexample
18270 -exec-return
18271@end smallexample
18272
18273Makes current function return immediately. Doesn't execute the inferior.
18274Displays the new current frame.
18275
18276@subsubheading @value{GDBN} Command
18277
18278The corresponding @value{GDBN} command is @samp{return}.
18279
18280@subsubheading Example
18281
18282@smallexample
18283(@value{GDBP})
18284200-break-insert callee4
18285200^done,bkpt=@{number="1",addr="0x00010734",
18286file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18287(@value{GDBP})
18288000-exec-run
18289000^running
18290(@value{GDBP})
18291000*stopped,reason="breakpoint-hit",bkptno="1",
18292frame=@{func="callee4",args=[],
18293file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18294(@value{GDBP})
18295205-break-delete
18296205^done
18297(@value{GDBP})
18298111-exec-return
18299111^done,frame=@{level="0",func="callee3",
18300args=[@{name="strarg",
18301value="0x11940 \"A string argument.\""@}],
18302file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18303(@value{GDBP})
18304@end smallexample
18305
18306
18307@subheading The @code{-exec-run} Command
18308@findex -exec-run
18309
18310@subsubheading Synopsis
18311
18312@smallexample
18313 -exec-run
18314@end smallexample
18315
18316Asynchronous command. Starts execution of the inferior from the
18317beginning. The inferior executes until either a breakpoint is
18318encountered or the program exits.
18319
18320@subsubheading @value{GDBN} Command
18321
18322The corresponding @value{GDBN} command is @samp{run}.
18323
18324@subsubheading Example
18325
18326@smallexample
18327(@value{GDBP})
18328-break-insert main
18329^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18330(@value{GDBP})
18331-exec-run
18332^running
18333(@value{GDBP})
18334*stopped,reason="breakpoint-hit",bkptno="1",
18335frame=@{func="main",args=[],file="recursive2.c",line="4"@}
18336(@value{GDBP})
18337@end smallexample
18338
18339
18340@subheading The @code{-exec-show-arguments} Command
18341@findex -exec-show-arguments
18342
18343@subsubheading Synopsis
18344
18345@smallexample
18346 -exec-show-arguments
18347@end smallexample
18348
18349Print the arguments of the program.
18350
18351@subsubheading @value{GDBN} Command
18352
18353The corresponding @value{GDBN} command is @samp{show args}.
18354
18355@subsubheading Example
18356N.A.
18357
18358@c @subheading -exec-signal
18359
18360@subheading The @code{-exec-step} Command
18361@findex -exec-step
18362
18363@subsubheading Synopsis
18364
18365@smallexample
18366 -exec-step
18367@end smallexample
18368
18369Asynchronous command. Resumes execution of the inferior program, stopping
18370when the beginning of the next source line is reached, if the next
18371source line is not a function call. If it is, stop at the first
18372instruction of the called function.
18373
18374@subsubheading @value{GDBN} Command
18375
18376The corresponding @value{GDBN} command is @samp{step}.
18377
18378@subsubheading Example
18379
18380Stepping into a function:
18381
18382@smallexample
18383-exec-step
18384^running
18385(@value{GDBP})
18386*stopped,reason="end-stepping-range",
18387frame=@{func="foo",args=[@{name="a",value="10"@},
18388@{name="b",value="0"@}],file="recursive2.c",line="11"@}
18389(@value{GDBP})
18390@end smallexample
18391
18392Regular stepping:
18393
18394@smallexample
18395-exec-step
18396^running
18397(@value{GDBP})
18398*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18399(@value{GDBP})
18400@end smallexample
18401
18402
18403@subheading The @code{-exec-step-instruction} Command
18404@findex -exec-step-instruction
18405
18406@subsubheading Synopsis
18407
18408@smallexample
18409 -exec-step-instruction
18410@end smallexample
18411
18412Asynchronous command. Resumes the inferior which executes one machine
18413instruction. The output, once @value{GDBN} has stopped, will vary depending on
18414whether we have stopped in the middle of a source line or not. In the
18415former case, the address at which the program stopped will be printed as
18416well.
18417
18418@subsubheading @value{GDBN} Command
18419
18420The corresponding @value{GDBN} command is @samp{stepi}.
18421
18422@subsubheading Example
18423
18424@smallexample
18425(@value{GDBP})
18426-exec-step-instruction
18427^running
18428
18429(@value{GDBP})
18430*stopped,reason="end-stepping-range",
18431frame=@{func="foo",args=[],file="try.c",line="10"@}
18432(@value{GDBP})
18433-exec-step-instruction
18434^running
18435
18436(@value{GDBP})
18437*stopped,reason="end-stepping-range",
18438frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",line="10"@}
18439(@value{GDBP})
18440@end smallexample
18441
18442
18443@subheading The @code{-exec-until} Command
18444@findex -exec-until
18445
18446@subsubheading Synopsis
18447
18448@smallexample
18449 -exec-until [ @var{location} ]
18450@end smallexample
18451
18452Asynchronous command. Executes the inferior until the @var{location}
18453specified in the argument is reached. If there is no argument, the inferior
18454executes until a source line greater than the current one is reached.
18455The reason for stopping in this case will be @samp{location-reached}.
18456
18457@subsubheading @value{GDBN} Command
18458
18459The corresponding @value{GDBN} command is @samp{until}.
18460
18461@subsubheading Example
18462
18463@smallexample
18464(@value{GDBP})
18465-exec-until recursive2.c:6
18466^running
18467(@value{GDBP})
18468x = 55
18469*stopped,reason="location-reached",frame=@{func="main",args=[],
18470file="recursive2.c",line="6"@}
18471(@value{GDBP})
18472@end smallexample
18473
18474@ignore
18475@subheading -file-clear
18476Is this going away????
18477@end ignore
18478
18479
18480@subheading The @code{-file-exec-and-symbols} Command
18481@findex -file-exec-and-symbols
18482
18483@subsubheading Synopsis
18484
18485@smallexample
18486 -file-exec-and-symbols @var{file}
18487@end smallexample
18488
18489Specify the executable file to be debugged. This file is the one from
18490which the symbol table is also read. If no file is specified, the
18491command clears the executable and symbol information. If breakpoints
18492are set when using this command with no arguments, @value{GDBN} will produce
18493error messages. Otherwise, no output is produced, except a completion
18494notification.
18495
18496@subsubheading @value{GDBN} Command
18497
18498The corresponding @value{GDBN} command is @samp{file}.
18499
18500@subsubheading Example
18501
18502@smallexample
18503(@value{GDBP})
18504-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18505^done
18506(@value{GDBP})
18507@end smallexample
18508
18509
18510@subheading The @code{-file-exec-file} Command
18511@findex -file-exec-file
18512
18513@subsubheading Synopsis
18514
18515@smallexample
18516 -file-exec-file @var{file}
18517@end smallexample
18518
18519Specify the executable file to be debugged. Unlike
18520@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18521from this file. If used without argument, @value{GDBN} clears the information
18522about the executable file. No output is produced, except a completion
18523notification.
18524
18525@subsubheading @value{GDBN} Command
18526
18527The corresponding @value{GDBN} command is @samp{exec-file}.
18528
18529@subsubheading Example
18530
18531@smallexample
18532(@value{GDBP})
18533-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18534^done
18535(@value{GDBP})
18536@end smallexample
18537
18538
18539@subheading The @code{-file-list-exec-sections} Command
18540@findex -file-list-exec-sections
18541
18542@subsubheading Synopsis
18543
18544@smallexample
18545 -file-list-exec-sections
18546@end smallexample
18547
18548List the sections of the current executable file.
18549
18550@subsubheading @value{GDBN} Command
18551
18552The @value{GDBN} command @samp{info file} shows, among the rest, the same
18553information as this command. @code{gdbtk} has a corresponding command
18554@samp{gdb_load_info}.
18555
18556@subsubheading Example
18557N.A.
18558
18559
1abaf70c
BR
18560@subheading The @code{-file-list-exec-source-file} Command
18561@findex -file-list-exec-source-file
18562
18563@subsubheading Synopsis
18564
18565@smallexample
18566 -file-list-exec-source-file
18567@end smallexample
18568
b383017d 18569List the line number, the current source file, and the absolute path
1abaf70c
BR
18570to the current source file for the current executable.
18571
18572@subsubheading @value{GDBN} Command
18573
18574There's no @value{GDBN} command which directly corresponds to this one.
18575
18576@subsubheading Example
18577
18578@smallexample
18579(@value{GDBP})
18580123-file-list-exec-source-file
18581123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18582(@value{GDBP})
18583@end smallexample
18584
18585
922fbb7b
AC
18586@subheading The @code{-file-list-exec-source-files} Command
18587@findex -file-list-exec-source-files
18588
18589@subsubheading Synopsis
18590
18591@smallexample
18592 -file-list-exec-source-files
18593@end smallexample
18594
18595List the source files for the current executable.
18596
57c22c6c
BR
18597It will always output the filename, but only when GDB can find the absolute
18598file name of a source file, will it output the fullname.
18599
922fbb7b
AC
18600@subsubheading @value{GDBN} Command
18601
18602There's no @value{GDBN} command which directly corresponds to this one.
18603@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18604
18605@subsubheading Example
57c22c6c
BR
18606@smallexample
18607(@value{GDBP})
18608-file-list-exec-source-files
18609^done,files=[
18610@{file=foo.c,fullname=/home/foo.c@},
18611@{file=/home/bar.c,fullname=/home/bar.c@},
18612@{file=gdb_could_not_find_fullpath.c@}]
18613(@value{GDBP})
18614@end smallexample
922fbb7b
AC
18615
18616@subheading The @code{-file-list-shared-libraries} Command
18617@findex -file-list-shared-libraries
18618
18619@subsubheading Synopsis
18620
18621@smallexample
18622 -file-list-shared-libraries
18623@end smallexample
18624
18625List the shared libraries in the program.
18626
18627@subsubheading @value{GDBN} Command
18628
18629The corresponding @value{GDBN} command is @samp{info shared}.
18630
18631@subsubheading Example
18632N.A.
18633
18634
18635@subheading The @code{-file-list-symbol-files} Command
18636@findex -file-list-symbol-files
18637
18638@subsubheading Synopsis
18639
18640@smallexample
18641 -file-list-symbol-files
18642@end smallexample
18643
18644List symbol files.
18645
18646@subsubheading @value{GDBN} Command
18647
18648The corresponding @value{GDBN} command is @samp{info file} (part of it).
18649
18650@subsubheading Example
18651N.A.
18652
18653
18654@subheading The @code{-file-symbol-file} Command
18655@findex -file-symbol-file
18656
18657@subsubheading Synopsis
18658
18659@smallexample
18660 -file-symbol-file @var{file}
18661@end smallexample
18662
18663Read symbol table info from the specified @var{file} argument. When
18664used without arguments, clears @value{GDBN}'s symbol table info. No output is
18665produced, except for a completion notification.
18666
18667@subsubheading @value{GDBN} Command
18668
18669The corresponding @value{GDBN} command is @samp{symbol-file}.
18670
18671@subsubheading Example
18672
18673@smallexample
18674(@value{GDBP})
18675-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18676^done
18677(@value{GDBP})
18678@end smallexample
18679
18680@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18681@node GDB/MI Miscellaneous Commands
18682@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
18683
18684@c @subheading -gdb-complete
18685
18686@subheading The @code{-gdb-exit} Command
18687@findex -gdb-exit
18688
18689@subsubheading Synopsis
18690
18691@smallexample
18692 -gdb-exit
18693@end smallexample
18694
18695Exit @value{GDBN} immediately.
18696
18697@subsubheading @value{GDBN} Command
18698
18699Approximately corresponds to @samp{quit}.
18700
18701@subsubheading Example
18702
18703@smallexample
18704(@value{GDBP})
18705-gdb-exit
18706@end smallexample
18707
18708@subheading The @code{-gdb-set} Command
18709@findex -gdb-set
18710
18711@subsubheading Synopsis
18712
18713@smallexample
18714 -gdb-set
18715@end smallexample
18716
18717Set an internal @value{GDBN} variable.
18718@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
18719
18720@subsubheading @value{GDBN} Command
18721
18722The corresponding @value{GDBN} command is @samp{set}.
18723
18724@subsubheading Example
18725
18726@smallexample
18727(@value{GDBP})
18728-gdb-set $foo=3
18729^done
18730(@value{GDBP})
18731@end smallexample
18732
18733
18734@subheading The @code{-gdb-show} Command
18735@findex -gdb-show
18736
18737@subsubheading Synopsis
18738
18739@smallexample
18740 -gdb-show
18741@end smallexample
18742
18743Show the current value of a @value{GDBN} variable.
18744
18745@subsubheading @value{GDBN} command
18746
18747The corresponding @value{GDBN} command is @samp{show}.
18748
18749@subsubheading Example
18750
18751@smallexample
18752(@value{GDBP})
18753-gdb-show annotate
18754^done,value="0"
18755(@value{GDBP})
18756@end smallexample
18757
18758@c @subheading -gdb-source
18759
18760
18761@subheading The @code{-gdb-version} Command
18762@findex -gdb-version
18763
18764@subsubheading Synopsis
18765
18766@smallexample
18767 -gdb-version
18768@end smallexample
18769
18770Show version information for @value{GDBN}. Used mostly in testing.
18771
18772@subsubheading @value{GDBN} Command
18773
18774There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
18775information when you start an interactive session.
18776
18777@subsubheading Example
18778
18779@c This example modifies the actual output from GDB to avoid overfull
18780@c box in TeX.
18781@smallexample
18782(@value{GDBP})
18783-gdb-version
18784~GNU gdb 5.2.1
18785~Copyright 2000 Free Software Foundation, Inc.
18786~GDB is free software, covered by the GNU General Public License, and
18787~you are welcome to change it and/or distribute copies of it under
18788~ certain conditions.
18789~Type "show copying" to see the conditions.
18790~There is absolutely no warranty for GDB. Type "show warranty" for
18791~ details.
b383017d 18792~This GDB was configured as
922fbb7b
AC
18793 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
18794^done
18795(@value{GDBP})
18796@end smallexample
18797
18798@subheading The @code{-interpreter-exec} Command
18799@findex -interpreter-exec
18800
18801@subheading Synopsis
18802
18803@smallexample
18804-interpreter-exec @var{interpreter} @var{command}
18805@end smallexample
18806
18807Execute the specified @var{command} in the given @var{interpreter}.
18808
18809@subheading @value{GDBN} Command
18810
18811The corresponding @value{GDBN} command is @samp{interpreter-exec}.
18812
18813@subheading Example
18814
18815@smallexample
18816(@value{GDBP})
18817-interpreter-exec console "break main"
18818&"During symbol reading, couldn't parse type; debugger out of date?.\n"
18819&"During symbol reading, bad structure-type format.\n"
18820~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
18821^done
18822(@value{GDBP})
18823@end smallexample
18824
18825@ignore
18826@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18827@node GDB/MI Kod Commands
18828@section @sc{gdb/mi} Kod Commands
18829
18830The Kod commands are not implemented.
18831
18832@c @subheading -kod-info
18833
18834@c @subheading -kod-list
18835
18836@c @subheading -kod-list-object-types
18837
18838@c @subheading -kod-show
18839
18840@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18841@node GDB/MI Memory Overlay Commands
18842@section @sc{gdb/mi} Memory Overlay Commands
18843
18844The memory overlay commands are not implemented.
18845
18846@c @subheading -overlay-auto
18847
18848@c @subheading -overlay-list-mapping-state
18849
18850@c @subheading -overlay-list-overlays
18851
18852@c @subheading -overlay-map
18853
18854@c @subheading -overlay-off
18855
18856@c @subheading -overlay-on
18857
18858@c @subheading -overlay-unmap
18859
18860@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18861@node GDB/MI Signal Handling Commands
18862@section @sc{gdb/mi} Signal Handling Commands
18863
18864Signal handling commands are not implemented.
18865
18866@c @subheading -signal-handle
18867
18868@c @subheading -signal-list-handle-actions
18869
18870@c @subheading -signal-list-signal-types
18871@end ignore
18872
18873
18874@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18875@node GDB/MI Stack Manipulation
18876@section @sc{gdb/mi} Stack Manipulation Commands
18877
18878
18879@subheading The @code{-stack-info-frame} Command
18880@findex -stack-info-frame
18881
18882@subsubheading Synopsis
18883
18884@smallexample
18885 -stack-info-frame
18886@end smallexample
18887
18888Get info on the current frame.
18889
18890@subsubheading @value{GDBN} Command
18891
18892The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
18893(without arguments).
18894
18895@subsubheading Example
18896N.A.
18897
18898@subheading The @code{-stack-info-depth} Command
18899@findex -stack-info-depth
18900
18901@subsubheading Synopsis
18902
18903@smallexample
18904 -stack-info-depth [ @var{max-depth} ]
18905@end smallexample
18906
18907Return the depth of the stack. If the integer argument @var{max-depth}
18908is specified, do not count beyond @var{max-depth} frames.
18909
18910@subsubheading @value{GDBN} Command
18911
18912There's no equivalent @value{GDBN} command.
18913
18914@subsubheading Example
18915
18916For a stack with frame levels 0 through 11:
18917
18918@smallexample
18919(@value{GDBP})
18920-stack-info-depth
18921^done,depth="12"
18922(@value{GDBP})
18923-stack-info-depth 4
18924^done,depth="4"
18925(@value{GDBP})
18926-stack-info-depth 12
18927^done,depth="12"
18928(@value{GDBP})
18929-stack-info-depth 11
18930^done,depth="11"
18931(@value{GDBP})
18932-stack-info-depth 13
18933^done,depth="12"
18934(@value{GDBP})
18935@end smallexample
18936
18937@subheading The @code{-stack-list-arguments} Command
18938@findex -stack-list-arguments
18939
18940@subsubheading Synopsis
18941
18942@smallexample
18943 -stack-list-arguments @var{show-values}
18944 [ @var{low-frame} @var{high-frame} ]
18945@end smallexample
18946
18947Display a list of the arguments for the frames between @var{low-frame}
18948and @var{high-frame} (inclusive). If @var{low-frame} and
18949@var{high-frame} are not provided, list the arguments for the whole call
18950stack.
18951
18952The @var{show-values} argument must have a value of 0 or 1. A value of
189530 means that only the names of the arguments are listed, a value of 1
18954means that both names and values of the arguments are printed.
18955
18956@subsubheading @value{GDBN} Command
18957
18958@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
18959@samp{gdb_get_args} command which partially overlaps with the
18960functionality of @samp{-stack-list-arguments}.
18961
18962@subsubheading Example
18963
18964@smallexample
18965(@value{GDBP})
18966-stack-list-frames
18967^done,
18968stack=[
18969frame=@{level="0",addr="0x00010734",func="callee4",
18970file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
18971frame=@{level="1",addr="0x0001076c",func="callee3",
18972file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
18973frame=@{level="2",addr="0x0001078c",func="callee2",
18974file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
18975frame=@{level="3",addr="0x000107b4",func="callee1",
18976file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
18977frame=@{level="4",addr="0x000107e0",func="main",
18978file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
18979(@value{GDBP})
18980-stack-list-arguments 0
18981^done,
18982stack-args=[
18983frame=@{level="0",args=[]@},
18984frame=@{level="1",args=[name="strarg"]@},
18985frame=@{level="2",args=[name="intarg",name="strarg"]@},
18986frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
18987frame=@{level="4",args=[]@}]
18988(@value{GDBP})
18989-stack-list-arguments 1
18990^done,
18991stack-args=[
18992frame=@{level="0",args=[]@},
18993frame=@{level="1",
18994 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
18995frame=@{level="2",args=[
18996@{name="intarg",value="2"@},
18997@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
18998@{frame=@{level="3",args=[
18999@{name="intarg",value="2"@},
19000@{name="strarg",value="0x11940 \"A string argument.\""@},
19001@{name="fltarg",value="3.5"@}]@},
19002frame=@{level="4",args=[]@}]
19003(@value{GDBP})
19004-stack-list-arguments 0 2 2
19005^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19006(@value{GDBP})
19007-stack-list-arguments 1 2 2
19008^done,stack-args=[frame=@{level="2",
19009args=[@{name="intarg",value="2"@},
19010@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19011(@value{GDBP})
19012@end smallexample
19013
19014@c @subheading -stack-list-exception-handlers
19015
19016
19017@subheading The @code{-stack-list-frames} Command
19018@findex -stack-list-frames
19019
19020@subsubheading Synopsis
19021
19022@smallexample
19023 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19024@end smallexample
19025
19026List the frames currently on the stack. For each frame it displays the
19027following info:
19028
19029@table @samp
19030@item @var{level}
19031The frame number, 0 being the topmost frame, i.e. the innermost function.
19032@item @var{addr}
19033The @code{$pc} value for that frame.
19034@item @var{func}
19035Function name.
19036@item @var{file}
19037File name of the source file where the function lives.
19038@item @var{line}
19039Line number corresponding to the @code{$pc}.
19040@end table
19041
19042If invoked without arguments, this command prints a backtrace for the
19043whole stack. If given two integer arguments, it shows the frames whose
19044levels are between the two arguments (inclusive). If the two arguments
19045are equal, it shows the single frame at the corresponding level.
19046
19047@subsubheading @value{GDBN} Command
19048
19049The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19050
19051@subsubheading Example
19052
19053Full stack backtrace:
19054
19055@smallexample
19056(@value{GDBP})
19057-stack-list-frames
19058^done,stack=
19059[frame=@{level="0",addr="0x0001076c",func="foo",
19060 file="recursive2.c",line="11"@},
19061frame=@{level="1",addr="0x000107a4",func="foo",
19062 file="recursive2.c",line="14"@},
19063frame=@{level="2",addr="0x000107a4",func="foo",
19064 file="recursive2.c",line="14"@},
19065frame=@{level="3",addr="0x000107a4",func="foo",
19066 file="recursive2.c",line="14"@},
19067frame=@{level="4",addr="0x000107a4",func="foo",
19068 file="recursive2.c",line="14"@},
19069frame=@{level="5",addr="0x000107a4",func="foo",
19070 file="recursive2.c",line="14"@},
19071frame=@{level="6",addr="0x000107a4",func="foo",
19072 file="recursive2.c",line="14"@},
19073frame=@{level="7",addr="0x000107a4",func="foo",
19074 file="recursive2.c",line="14"@},
19075frame=@{level="8",addr="0x000107a4",func="foo",
19076 file="recursive2.c",line="14"@},
19077frame=@{level="9",addr="0x000107a4",func="foo",
19078 file="recursive2.c",line="14"@},
19079frame=@{level="10",addr="0x000107a4",func="foo",
19080 file="recursive2.c",line="14"@},
19081frame=@{level="11",addr="0x00010738",func="main",
19082 file="recursive2.c",line="4"@}]
19083(@value{GDBP})
19084@end smallexample
19085
19086Show frames between @var{low_frame} and @var{high_frame}:
19087
19088@smallexample
19089(@value{GDBP})
19090-stack-list-frames 3 5
19091^done,stack=
19092[frame=@{level="3",addr="0x000107a4",func="foo",
19093 file="recursive2.c",line="14"@},
19094frame=@{level="4",addr="0x000107a4",func="foo",
19095 file="recursive2.c",line="14"@},
19096frame=@{level="5",addr="0x000107a4",func="foo",
19097 file="recursive2.c",line="14"@}]
19098(@value{GDBP})
19099@end smallexample
19100
19101Show a single frame:
19102
19103@smallexample
19104(@value{GDBP})
19105-stack-list-frames 3 3
19106^done,stack=
19107[frame=@{level="3",addr="0x000107a4",func="foo",
19108 file="recursive2.c",line="14"@}]
19109(@value{GDBP})
19110@end smallexample
19111
19112
19113@subheading The @code{-stack-list-locals} Command
19114@findex -stack-list-locals
19115
19116@subsubheading Synopsis
19117
19118@smallexample
19119 -stack-list-locals @var{print-values}
19120@end smallexample
19121
19122Display the local variable names for the current frame. With an
bc8ced35
NR
19123argument of 0 or @code{--no-values}, prints only the names of the variables.
19124With argument of 1 or @code{--all-values}, prints also their values. With
19125argument of 2 or @code{--simple-values}, prints the name, type and value for
19126simple data types and the name and type for arrays, structures and
19127unions. In this last case, the idea is that the user can see the
19128value of simple data types immediately and he can create variable
19129objects for other data types if he wishes to explore their values in
19130more detail.
922fbb7b
AC
19131
19132@subsubheading @value{GDBN} Command
19133
19134@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19135
19136@subsubheading Example
19137
19138@smallexample
19139(@value{GDBP})
19140-stack-list-locals 0
19141^done,locals=[name="A",name="B",name="C"]
19142(@value{GDBP})
bc8ced35 19143-stack-list-locals --all-values
922fbb7b 19144^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19145 @{name="C",value="@{1, 2, 3@}"@}]
19146-stack-list-locals --simple-values
19147^done,locals=[@{name="A",type="int",value="1"@},
19148 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19149(@value{GDBP})
19150@end smallexample
19151
19152
19153@subheading The @code{-stack-select-frame} Command
19154@findex -stack-select-frame
19155
19156@subsubheading Synopsis
19157
19158@smallexample
19159 -stack-select-frame @var{framenum}
19160@end smallexample
19161
19162Change the current frame. Select a different frame @var{framenum} on
19163the stack.
19164
19165@subsubheading @value{GDBN} Command
19166
19167The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19168@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19169
19170@subsubheading Example
19171
19172@smallexample
19173(@value{GDBP})
19174-stack-select-frame 2
19175^done
19176(@value{GDBP})
19177@end smallexample
19178
19179@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19180@node GDB/MI Symbol Query
19181@section @sc{gdb/mi} Symbol Query Commands
19182
19183
19184@subheading The @code{-symbol-info-address} Command
19185@findex -symbol-info-address
19186
19187@subsubheading Synopsis
19188
19189@smallexample
19190 -symbol-info-address @var{symbol}
19191@end smallexample
19192
19193Describe where @var{symbol} is stored.
19194
19195@subsubheading @value{GDBN} Command
19196
19197The corresponding @value{GDBN} command is @samp{info address}.
19198
19199@subsubheading Example
19200N.A.
19201
19202
19203@subheading The @code{-symbol-info-file} Command
19204@findex -symbol-info-file
19205
19206@subsubheading Synopsis
19207
19208@smallexample
19209 -symbol-info-file
19210@end smallexample
19211
19212Show the file for the symbol.
19213
19214@subsubheading @value{GDBN} Command
19215
19216There's no equivalent @value{GDBN} command. @code{gdbtk} has
19217@samp{gdb_find_file}.
19218
19219@subsubheading Example
19220N.A.
19221
19222
19223@subheading The @code{-symbol-info-function} Command
19224@findex -symbol-info-function
19225
19226@subsubheading Synopsis
19227
19228@smallexample
19229 -symbol-info-function
19230@end smallexample
19231
19232Show which function the symbol lives in.
19233
19234@subsubheading @value{GDBN} Command
19235
19236@samp{gdb_get_function} in @code{gdbtk}.
19237
19238@subsubheading Example
19239N.A.
19240
19241
19242@subheading The @code{-symbol-info-line} Command
19243@findex -symbol-info-line
19244
19245@subsubheading Synopsis
19246
19247@smallexample
19248 -symbol-info-line
19249@end smallexample
19250
19251Show the core addresses of the code for a source line.
19252
19253@subsubheading @value{GDBN} Command
19254
71952f4c 19255The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19256@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19257
19258@subsubheading Example
19259N.A.
19260
19261
19262@subheading The @code{-symbol-info-symbol} Command
19263@findex -symbol-info-symbol
19264
19265@subsubheading Synopsis
19266
19267@smallexample
19268 -symbol-info-symbol @var{addr}
19269@end smallexample
19270
19271Describe what symbol is at location @var{addr}.
19272
19273@subsubheading @value{GDBN} Command
19274
19275The corresponding @value{GDBN} command is @samp{info symbol}.
19276
19277@subsubheading Example
19278N.A.
19279
19280
19281@subheading The @code{-symbol-list-functions} Command
19282@findex -symbol-list-functions
19283
19284@subsubheading Synopsis
19285
19286@smallexample
19287 -symbol-list-functions
19288@end smallexample
19289
19290List the functions in the executable.
19291
19292@subsubheading @value{GDBN} Command
19293
19294@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19295@samp{gdb_search} in @code{gdbtk}.
19296
19297@subsubheading Example
19298N.A.
19299
19300
32e7087d
JB
19301@subheading The @code{-symbol-list-lines} Command
19302@findex -symbol-list-lines
19303
19304@subsubheading Synopsis
19305
19306@smallexample
19307 -symbol-list-lines @var{filename}
19308@end smallexample
19309
19310Print the list of lines that contain code and their associated program
19311addresses for the given source filename. The entries are sorted in
19312ascending PC order.
19313
19314@subsubheading @value{GDBN} Command
19315
19316There is no corresponding @value{GDBN} command.
19317
19318@subsubheading Example
19319@smallexample
19320(@value{GDBP})
19321-symbol-list-lines basics.c
54ff5908 19322^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19323(@value{GDBP})
19324@end smallexample
19325
19326
922fbb7b
AC
19327@subheading The @code{-symbol-list-types} Command
19328@findex -symbol-list-types
19329
19330@subsubheading Synopsis
19331
19332@smallexample
19333 -symbol-list-types
19334@end smallexample
19335
19336List all the type names.
19337
19338@subsubheading @value{GDBN} Command
19339
19340The corresponding commands are @samp{info types} in @value{GDBN},
19341@samp{gdb_search} in @code{gdbtk}.
19342
19343@subsubheading Example
19344N.A.
19345
19346
19347@subheading The @code{-symbol-list-variables} Command
19348@findex -symbol-list-variables
19349
19350@subsubheading Synopsis
19351
19352@smallexample
19353 -symbol-list-variables
19354@end smallexample
19355
19356List all the global and static variable names.
19357
19358@subsubheading @value{GDBN} Command
19359
19360@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19361
19362@subsubheading Example
19363N.A.
19364
19365
19366@subheading The @code{-symbol-locate} Command
19367@findex -symbol-locate
19368
19369@subsubheading Synopsis
19370
19371@smallexample
19372 -symbol-locate
19373@end smallexample
19374
19375@subsubheading @value{GDBN} Command
19376
19377@samp{gdb_loc} in @code{gdbtk}.
19378
19379@subsubheading Example
19380N.A.
19381
19382
19383@subheading The @code{-symbol-type} Command
19384@findex -symbol-type
19385
19386@subsubheading Synopsis
19387
19388@smallexample
19389 -symbol-type @var{variable}
19390@end smallexample
19391
19392Show type of @var{variable}.
19393
19394@subsubheading @value{GDBN} Command
19395
19396The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19397@samp{gdb_obj_variable}.
19398
19399@subsubheading Example
19400N.A.
19401
19402
19403@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19404@node GDB/MI Target Manipulation
19405@section @sc{gdb/mi} Target Manipulation Commands
19406
19407
19408@subheading The @code{-target-attach} Command
19409@findex -target-attach
19410
19411@subsubheading Synopsis
19412
19413@smallexample
19414 -target-attach @var{pid} | @var{file}
19415@end smallexample
19416
19417Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19418
19419@subsubheading @value{GDBN} command
19420
19421The corresponding @value{GDBN} command is @samp{attach}.
19422
19423@subsubheading Example
19424N.A.
19425
19426
19427@subheading The @code{-target-compare-sections} Command
19428@findex -target-compare-sections
19429
19430@subsubheading Synopsis
19431
19432@smallexample
19433 -target-compare-sections [ @var{section} ]
19434@end smallexample
19435
19436Compare data of section @var{section} on target to the exec file.
19437Without the argument, all sections are compared.
19438
19439@subsubheading @value{GDBN} Command
19440
19441The @value{GDBN} equivalent is @samp{compare-sections}.
19442
19443@subsubheading Example
19444N.A.
19445
19446
19447@subheading The @code{-target-detach} Command
19448@findex -target-detach
19449
19450@subsubheading Synopsis
19451
19452@smallexample
19453 -target-detach
19454@end smallexample
19455
19456Disconnect from the remote target. There's no output.
19457
19458@subsubheading @value{GDBN} command
19459
19460The corresponding @value{GDBN} command is @samp{detach}.
19461
19462@subsubheading Example
19463
19464@smallexample
19465(@value{GDBP})
19466-target-detach
19467^done
19468(@value{GDBP})
19469@end smallexample
19470
19471
07f31aa6
DJ
19472@subheading The @code{-target-disconnect} Command
19473@findex -target-disconnect
19474
19475@subsubheading Synopsis
19476
19477@example
19478 -target-disconnect
19479@end example
19480
19481Disconnect from the remote target. There's no output.
19482
19483@subsubheading @value{GDBN} command
19484
19485The corresponding @value{GDBN} command is @samp{disconnect}.
19486
19487@subsubheading Example
19488
19489@smallexample
19490(@value{GDBP})
19491-target-disconnect
19492^done
19493(@value{GDBP})
19494@end smallexample
19495
19496
922fbb7b
AC
19497@subheading The @code{-target-download} Command
19498@findex -target-download
19499
19500@subsubheading Synopsis
19501
19502@smallexample
19503 -target-download
19504@end smallexample
19505
19506Loads the executable onto the remote target.
19507It prints out an update message every half second, which includes the fields:
19508
19509@table @samp
19510@item section
19511The name of the section.
19512@item section-sent
19513The size of what has been sent so far for that section.
19514@item section-size
19515The size of the section.
19516@item total-sent
19517The total size of what was sent so far (the current and the previous sections).
19518@item total-size
19519The size of the overall executable to download.
19520@end table
19521
19522@noindent
19523Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19524@sc{gdb/mi} Output Syntax}).
19525
19526In addition, it prints the name and size of the sections, as they are
19527downloaded. These messages include the following fields:
19528
19529@table @samp
19530@item section
19531The name of the section.
19532@item section-size
19533The size of the section.
19534@item total-size
19535The size of the overall executable to download.
19536@end table
19537
19538@noindent
19539At the end, a summary is printed.
19540
19541@subsubheading @value{GDBN} Command
19542
19543The corresponding @value{GDBN} command is @samp{load}.
19544
19545@subsubheading Example
19546
19547Note: each status message appears on a single line. Here the messages
19548have been broken down so that they can fit onto a page.
19549
19550@smallexample
19551(@value{GDBP})
19552-target-download
19553+download,@{section=".text",section-size="6668",total-size="9880"@}
19554+download,@{section=".text",section-sent="512",section-size="6668",
19555total-sent="512",total-size="9880"@}
19556+download,@{section=".text",section-sent="1024",section-size="6668",
19557total-sent="1024",total-size="9880"@}
19558+download,@{section=".text",section-sent="1536",section-size="6668",
19559total-sent="1536",total-size="9880"@}
19560+download,@{section=".text",section-sent="2048",section-size="6668",
19561total-sent="2048",total-size="9880"@}
19562+download,@{section=".text",section-sent="2560",section-size="6668",
19563total-sent="2560",total-size="9880"@}
19564+download,@{section=".text",section-sent="3072",section-size="6668",
19565total-sent="3072",total-size="9880"@}
19566+download,@{section=".text",section-sent="3584",section-size="6668",
19567total-sent="3584",total-size="9880"@}
19568+download,@{section=".text",section-sent="4096",section-size="6668",
19569total-sent="4096",total-size="9880"@}
19570+download,@{section=".text",section-sent="4608",section-size="6668",
19571total-sent="4608",total-size="9880"@}
19572+download,@{section=".text",section-sent="5120",section-size="6668",
19573total-sent="5120",total-size="9880"@}
19574+download,@{section=".text",section-sent="5632",section-size="6668",
19575total-sent="5632",total-size="9880"@}
19576+download,@{section=".text",section-sent="6144",section-size="6668",
19577total-sent="6144",total-size="9880"@}
19578+download,@{section=".text",section-sent="6656",section-size="6668",
19579total-sent="6656",total-size="9880"@}
19580+download,@{section=".init",section-size="28",total-size="9880"@}
19581+download,@{section=".fini",section-size="28",total-size="9880"@}
19582+download,@{section=".data",section-size="3156",total-size="9880"@}
19583+download,@{section=".data",section-sent="512",section-size="3156",
19584total-sent="7236",total-size="9880"@}
19585+download,@{section=".data",section-sent="1024",section-size="3156",
19586total-sent="7748",total-size="9880"@}
19587+download,@{section=".data",section-sent="1536",section-size="3156",
19588total-sent="8260",total-size="9880"@}
19589+download,@{section=".data",section-sent="2048",section-size="3156",
19590total-sent="8772",total-size="9880"@}
19591+download,@{section=".data",section-sent="2560",section-size="3156",
19592total-sent="9284",total-size="9880"@}
19593+download,@{section=".data",section-sent="3072",section-size="3156",
19594total-sent="9796",total-size="9880"@}
19595^done,address="0x10004",load-size="9880",transfer-rate="6586",
19596write-rate="429"
19597(@value{GDBP})
19598@end smallexample
19599
19600
19601@subheading The @code{-target-exec-status} Command
19602@findex -target-exec-status
19603
19604@subsubheading Synopsis
19605
19606@smallexample
19607 -target-exec-status
19608@end smallexample
19609
19610Provide information on the state of the target (whether it is running or
19611not, for instance).
19612
19613@subsubheading @value{GDBN} Command
19614
19615There's no equivalent @value{GDBN} command.
19616
19617@subsubheading Example
19618N.A.
19619
19620
19621@subheading The @code{-target-list-available-targets} Command
19622@findex -target-list-available-targets
19623
19624@subsubheading Synopsis
19625
19626@smallexample
19627 -target-list-available-targets
19628@end smallexample
19629
19630List the possible targets to connect to.
19631
19632@subsubheading @value{GDBN} Command
19633
19634The corresponding @value{GDBN} command is @samp{help target}.
19635
19636@subsubheading Example
19637N.A.
19638
19639
19640@subheading The @code{-target-list-current-targets} Command
19641@findex -target-list-current-targets
19642
19643@subsubheading Synopsis
19644
19645@smallexample
19646 -target-list-current-targets
19647@end smallexample
19648
19649Describe the current target.
19650
19651@subsubheading @value{GDBN} Command
19652
19653The corresponding information is printed by @samp{info file} (among
19654other things).
19655
19656@subsubheading Example
19657N.A.
19658
19659
19660@subheading The @code{-target-list-parameters} Command
19661@findex -target-list-parameters
19662
19663@subsubheading Synopsis
19664
19665@smallexample
19666 -target-list-parameters
19667@end smallexample
19668
19669@c ????
19670
19671@subsubheading @value{GDBN} Command
19672
19673No equivalent.
19674
19675@subsubheading Example
19676N.A.
19677
19678
19679@subheading The @code{-target-select} Command
19680@findex -target-select
19681
19682@subsubheading Synopsis
19683
19684@smallexample
19685 -target-select @var{type} @var{parameters @dots{}}
19686@end smallexample
19687
19688Connect @value{GDBN} to the remote target. This command takes two args:
19689
19690@table @samp
19691@item @var{type}
19692The type of target, for instance @samp{async}, @samp{remote}, etc.
19693@item @var{parameters}
19694Device names, host names and the like. @xref{Target Commands, ,
19695Commands for managing targets}, for more details.
19696@end table
19697
19698The output is a connection notification, followed by the address at
19699which the target program is, in the following form:
19700
19701@smallexample
19702^connected,addr="@var{address}",func="@var{function name}",
19703 args=[@var{arg list}]
19704@end smallexample
19705
19706@subsubheading @value{GDBN} Command
19707
19708The corresponding @value{GDBN} command is @samp{target}.
19709
19710@subsubheading Example
19711
19712@smallexample
19713(@value{GDBP})
19714-target-select async /dev/ttya
19715^connected,addr="0xfe00a300",func="??",args=[]
19716(@value{GDBP})
19717@end smallexample
19718
19719@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19720@node GDB/MI Thread Commands
19721@section @sc{gdb/mi} Thread Commands
19722
19723
19724@subheading The @code{-thread-info} Command
19725@findex -thread-info
19726
19727@subsubheading Synopsis
19728
19729@smallexample
19730 -thread-info
19731@end smallexample
19732
19733@subsubheading @value{GDBN} command
19734
19735No equivalent.
19736
19737@subsubheading Example
19738N.A.
19739
19740
19741@subheading The @code{-thread-list-all-threads} Command
19742@findex -thread-list-all-threads
19743
19744@subsubheading Synopsis
19745
19746@smallexample
19747 -thread-list-all-threads
19748@end smallexample
19749
19750@subsubheading @value{GDBN} Command
19751
19752The equivalent @value{GDBN} command is @samp{info threads}.
19753
19754@subsubheading Example
19755N.A.
19756
19757
19758@subheading The @code{-thread-list-ids} Command
19759@findex -thread-list-ids
19760
19761@subsubheading Synopsis
19762
19763@smallexample
19764 -thread-list-ids
19765@end smallexample
19766
19767Produces a list of the currently known @value{GDBN} thread ids. At the
19768end of the list it also prints the total number of such threads.
19769
19770@subsubheading @value{GDBN} Command
19771
19772Part of @samp{info threads} supplies the same information.
19773
19774@subsubheading Example
19775
19776No threads present, besides the main process:
19777
19778@smallexample
19779(@value{GDBP})
19780-thread-list-ids
19781^done,thread-ids=@{@},number-of-threads="0"
19782(@value{GDBP})
19783@end smallexample
19784
19785
19786Several threads:
19787
19788@smallexample
19789(@value{GDBP})
19790-thread-list-ids
19791^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
19792number-of-threads="3"
19793(@value{GDBP})
19794@end smallexample
19795
19796
19797@subheading The @code{-thread-select} Command
19798@findex -thread-select
19799
19800@subsubheading Synopsis
19801
19802@smallexample
19803 -thread-select @var{threadnum}
19804@end smallexample
19805
19806Make @var{threadnum} the current thread. It prints the number of the new
19807current thread, and the topmost frame for that thread.
19808
19809@subsubheading @value{GDBN} Command
19810
19811The corresponding @value{GDBN} command is @samp{thread}.
19812
19813@subsubheading Example
19814
19815@smallexample
19816(@value{GDBP})
19817-exec-next
19818^running
19819(@value{GDBP})
19820*stopped,reason="end-stepping-range",thread-id="2",line="187",
19821file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
19822(@value{GDBP})
19823-thread-list-ids
19824^done,
19825thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
19826number-of-threads="3"
19827(@value{GDBP})
19828-thread-select 3
19829^done,new-thread-id="3",
19830frame=@{level="0",func="vprintf",
19831args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
19832@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
19833(@value{GDBP})
19834@end smallexample
19835
19836@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19837@node GDB/MI Tracepoint Commands
19838@section @sc{gdb/mi} Tracepoint Commands
19839
19840The tracepoint commands are not yet implemented.
19841
19842@c @subheading -trace-actions
19843
19844@c @subheading -trace-delete
19845
19846@c @subheading -trace-disable
19847
19848@c @subheading -trace-dump
19849
19850@c @subheading -trace-enable
19851
19852@c @subheading -trace-exists
19853
19854@c @subheading -trace-find
19855
19856@c @subheading -trace-frame-number
19857
19858@c @subheading -trace-info
19859
19860@c @subheading -trace-insert
19861
19862@c @subheading -trace-list
19863
19864@c @subheading -trace-pass-count
19865
19866@c @subheading -trace-save
19867
19868@c @subheading -trace-start
19869
19870@c @subheading -trace-stop
19871
19872
19873@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19874@node GDB/MI Variable Objects
19875@section @sc{gdb/mi} Variable Objects
19876
19877
19878@subheading Motivation for Variable Objects in @sc{gdb/mi}
19879
19880For the implementation of a variable debugger window (locals, watched
19881expressions, etc.), we are proposing the adaptation of the existing code
19882used by @code{Insight}.
19883
19884The two main reasons for that are:
19885
19886@enumerate 1
19887@item
19888It has been proven in practice (it is already on its second generation).
19889
19890@item
19891It will shorten development time (needless to say how important it is
19892now).
19893@end enumerate
19894
19895The original interface was designed to be used by Tcl code, so it was
19896slightly changed so it could be used through @sc{gdb/mi}. This section
19897describes the @sc{gdb/mi} operations that will be available and gives some
19898hints about their use.
19899
19900@emph{Note}: In addition to the set of operations described here, we
19901expect the @sc{gui} implementation of a variable window to require, at
19902least, the following operations:
19903
19904@itemize @bullet
19905@item @code{-gdb-show} @code{output-radix}
19906@item @code{-stack-list-arguments}
19907@item @code{-stack-list-locals}
19908@item @code{-stack-select-frame}
19909@end itemize
19910
19911@subheading Introduction to Variable Objects in @sc{gdb/mi}
19912
19913@cindex variable objects in @sc{gdb/mi}
19914The basic idea behind variable objects is the creation of a named object
19915to represent a variable, an expression, a memory location or even a CPU
19916register. For each object created, a set of operations is available for
19917examining or changing its properties.
19918
19919Furthermore, complex data types, such as C structures, are represented
19920in a tree format. For instance, the @code{struct} type variable is the
19921root and the children will represent the struct members. If a child
19922is itself of a complex type, it will also have children of its own.
19923Appropriate language differences are handled for C, C@t{++} and Java.
19924
19925When returning the actual values of the objects, this facility allows
19926for the individual selection of the display format used in the result
19927creation. It can be chosen among: binary, decimal, hexadecimal, octal
19928and natural. Natural refers to a default format automatically
19929chosen based on the variable type (like decimal for an @code{int}, hex
19930for pointers, etc.).
19931
19932The following is the complete set of @sc{gdb/mi} operations defined to
19933access this functionality:
19934
19935@multitable @columnfractions .4 .6
19936@item @strong{Operation}
19937@tab @strong{Description}
19938
19939@item @code{-var-create}
19940@tab create a variable object
19941@item @code{-var-delete}
19942@tab delete the variable object and its children
19943@item @code{-var-set-format}
19944@tab set the display format of this variable
19945@item @code{-var-show-format}
19946@tab show the display format of this variable
19947@item @code{-var-info-num-children}
19948@tab tells how many children this object has
19949@item @code{-var-list-children}
19950@tab return a list of the object's children
19951@item @code{-var-info-type}
19952@tab show the type of this variable object
19953@item @code{-var-info-expression}
19954@tab print what this variable object represents
19955@item @code{-var-show-attributes}
19956@tab is this variable editable? does it exist here?
19957@item @code{-var-evaluate-expression}
19958@tab get the value of this variable
19959@item @code{-var-assign}
19960@tab set the value of this variable
19961@item @code{-var-update}
19962@tab update the variable and its children
19963@end multitable
19964
19965In the next subsection we describe each operation in detail and suggest
19966how it can be used.
19967
19968@subheading Description And Use of Operations on Variable Objects
19969
19970@subheading The @code{-var-create} Command
19971@findex -var-create
19972
19973@subsubheading Synopsis
19974
19975@smallexample
19976 -var-create @{@var{name} | "-"@}
19977 @{@var{frame-addr} | "*"@} @var{expression}
19978@end smallexample
19979
19980This operation creates a variable object, which allows the monitoring of
19981a variable, the result of an expression, a memory cell or a CPU
19982register.
19983
19984The @var{name} parameter is the string by which the object can be
19985referenced. It must be unique. If @samp{-} is specified, the varobj
19986system will generate a string ``varNNNNNN'' automatically. It will be
19987unique provided that one does not specify @var{name} on that format.
19988The command fails if a duplicate name is found.
19989
19990The frame under which the expression should be evaluated can be
19991specified by @var{frame-addr}. A @samp{*} indicates that the current
19992frame should be used.
19993
19994@var{expression} is any expression valid on the current language set (must not
19995begin with a @samp{*}), or one of the following:
19996
19997@itemize @bullet
19998@item
19999@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20000
20001@item
20002@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20003
20004@item
20005@samp{$@var{regname}} --- a CPU register name
20006@end itemize
20007
20008@subsubheading Result
20009
20010This operation returns the name, number of children and the type of the
20011object created. Type is returned as a string as the ones generated by
20012the @value{GDBN} CLI:
20013
20014@smallexample
20015 name="@var{name}",numchild="N",type="@var{type}"
20016@end smallexample
20017
20018
20019@subheading The @code{-var-delete} Command
20020@findex -var-delete
20021
20022@subsubheading Synopsis
20023
20024@smallexample
20025 -var-delete @var{name}
20026@end smallexample
20027
20028Deletes a previously created variable object and all of its children.
20029
20030Returns an error if the object @var{name} is not found.
20031
20032
20033@subheading The @code{-var-set-format} Command
20034@findex -var-set-format
20035
20036@subsubheading Synopsis
20037
20038@smallexample
20039 -var-set-format @var{name} @var{format-spec}
20040@end smallexample
20041
20042Sets the output format for the value of the object @var{name} to be
20043@var{format-spec}.
20044
20045The syntax for the @var{format-spec} is as follows:
20046
20047@smallexample
20048 @var{format-spec} @expansion{}
20049 @{binary | decimal | hexadecimal | octal | natural@}
20050@end smallexample
20051
20052
20053@subheading The @code{-var-show-format} Command
20054@findex -var-show-format
20055
20056@subsubheading Synopsis
20057
20058@smallexample
20059 -var-show-format @var{name}
20060@end smallexample
20061
20062Returns the format used to display the value of the object @var{name}.
20063
20064@smallexample
20065 @var{format} @expansion{}
20066 @var{format-spec}
20067@end smallexample
20068
20069
20070@subheading The @code{-var-info-num-children} Command
20071@findex -var-info-num-children
20072
20073@subsubheading Synopsis
20074
20075@smallexample
20076 -var-info-num-children @var{name}
20077@end smallexample
20078
20079Returns the number of children of a variable object @var{name}:
20080
20081@smallexample
20082 numchild=@var{n}
20083@end smallexample
20084
20085
20086@subheading The @code{-var-list-children} Command
20087@findex -var-list-children
20088
20089@subsubheading Synopsis
20090
20091@smallexample
bc8ced35 20092 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20093@end smallexample
20094
bc8ced35
NR
20095Returns a list of the children of the specified variable object. With
20096just the variable object name as an argument or with an optional
20097preceding argument of 0 or @code{--no-values}, prints only the names of the
20098variables. With an optional preceding argument of 1 or @code{--all-values},
20099also prints their values.
20100
20101@subsubheading Example
922fbb7b
AC
20102
20103@smallexample
bc8ced35
NR
20104(@value{GDBP})
20105 -var-list-children n
922fbb7b
AC
20106 numchild=@var{n},children=[@{name=@var{name},
20107 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20108(@value{GDBP})
20109 -var-list-children --all-values n
20110 numchild=@var{n},children=[@{name=@var{name},
20111 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20112@end smallexample
20113
20114
20115@subheading The @code{-var-info-type} Command
20116@findex -var-info-type
20117
20118@subsubheading Synopsis
20119
20120@smallexample
20121 -var-info-type @var{name}
20122@end smallexample
20123
20124Returns the type of the specified variable @var{name}. The type is
20125returned as a string in the same format as it is output by the
20126@value{GDBN} CLI:
20127
20128@smallexample
20129 type=@var{typename}
20130@end smallexample
20131
20132
20133@subheading The @code{-var-info-expression} Command
20134@findex -var-info-expression
20135
20136@subsubheading Synopsis
20137
20138@smallexample
20139 -var-info-expression @var{name}
20140@end smallexample
20141
20142Returns what is represented by the variable object @var{name}:
20143
20144@smallexample
20145 lang=@var{lang-spec},exp=@var{expression}
20146@end smallexample
20147
20148@noindent
20149where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20150
20151@subheading The @code{-var-show-attributes} Command
20152@findex -var-show-attributes
20153
20154@subsubheading Synopsis
20155
20156@smallexample
20157 -var-show-attributes @var{name}
20158@end smallexample
20159
20160List attributes of the specified variable object @var{name}:
20161
20162@smallexample
20163 status=@var{attr} [ ( ,@var{attr} )* ]
20164@end smallexample
20165
20166@noindent
20167where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20168
20169@subheading The @code{-var-evaluate-expression} Command
20170@findex -var-evaluate-expression
20171
20172@subsubheading Synopsis
20173
20174@smallexample
20175 -var-evaluate-expression @var{name}
20176@end smallexample
20177
20178Evaluates the expression that is represented by the specified variable
20179object and returns its value as a string in the current format specified
20180for the object:
20181
20182@smallexample
20183 value=@var{value}
20184@end smallexample
20185
20186Note that one must invoke @code{-var-list-children} for a variable
20187before the value of a child variable can be evaluated.
20188
20189@subheading The @code{-var-assign} Command
20190@findex -var-assign
20191
20192@subsubheading Synopsis
20193
20194@smallexample
20195 -var-assign @var{name} @var{expression}
20196@end smallexample
20197
20198Assigns the value of @var{expression} to the variable object specified
20199by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20200value is altered by the assign, the variable will show up in any
922fbb7b
AC
20201subsequent @code{-var-update} list.
20202
20203@subsubheading Example
20204
20205@smallexample
20206(@value{GDBP})
20207-var-assign var1 3
20208^done,value="3"
20209(@value{GDBP})
20210-var-update *
20211^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20212(@value{GDBP})
20213@end smallexample
20214
20215@subheading The @code{-var-update} Command
20216@findex -var-update
20217
20218@subsubheading Synopsis
20219
20220@smallexample
20221 -var-update @{@var{name} | "*"@}
20222@end smallexample
20223
20224Update the value of the variable object @var{name} by evaluating its
20225expression after fetching all the new values from memory or registers.
20226A @samp{*} causes all existing variable objects to be updated.
20227
20228
20229@node Annotations
20230@chapter @value{GDBN} Annotations
20231
086432e2
AC
20232This chapter describes annotations in @value{GDBN}. Annotations were
20233designed to interface @value{GDBN} to graphical user interfaces or other
20234similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20235relatively high level.
20236
086432e2
AC
20237The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20238(@pxref{GDB/MI}).
20239
922fbb7b
AC
20240@ignore
20241This is Edition @value{EDITION}, @value{DATE}.
20242@end ignore
20243
20244@menu
20245* Annotations Overview:: What annotations are; the general syntax.
20246* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
20247* Prompting:: Annotations marking @value{GDBN}'s need for input.
20248* Errors:: Annotations for error messages.
922fbb7b
AC
20249* Invalidation:: Some annotations describe things now invalid.
20250* Annotations for Running::
20251 Whether the program is running, how it stopped, etc.
20252* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20253@end menu
20254
20255@node Annotations Overview
20256@section What is an Annotation?
20257@cindex annotations
20258
922fbb7b
AC
20259Annotations start with a newline character, two @samp{control-z}
20260characters, and the name of the annotation. If there is no additional
20261information associated with this annotation, the name of the annotation
20262is followed immediately by a newline. If there is additional
20263information, the name of the annotation is followed by a space, the
20264additional information, and a newline. The additional information
20265cannot contain newline characters.
20266
20267Any output not beginning with a newline and two @samp{control-z}
20268characters denotes literal output from @value{GDBN}. Currently there is
20269no need for @value{GDBN} to output a newline followed by two
20270@samp{control-z} characters, but if there was such a need, the
20271annotations could be extended with an @samp{escape} annotation which
20272means those three characters as output.
20273
086432e2
AC
20274The annotation @var{level}, which is specified using the
20275@option{--annotate} command line option (@pxref{Mode Options}), controls
20276how much information @value{GDBN} prints together with its prompt,
20277values of expressions, source lines, and other types of output. Level 0
20278is for no anntations, level 1 is for use when @value{GDBN} is run as a
20279subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20280for programs that control @value{GDBN}, and level 2 annotations have
20281been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20282Interface, annotate, GDB's Obsolete Annotations}).
20283
20284@table @code
20285@kindex set annotate
20286@item set annotate @var{level}
20287The @value{GDB} command @code{set annotate} sets the level of
20288annotations to the specified @var{level}.
9c16f35a
EZ
20289
20290@item show annotate
20291@kindex show annotate
20292Show the current annotation level.
09d4efe1
EZ
20293@end table
20294
20295This chapter describes level 3 annotations.
086432e2 20296
922fbb7b
AC
20297A simple example of starting up @value{GDBN} with annotations is:
20298
20299@smallexample
086432e2
AC
20300$ @kbd{gdb --annotate=3}
20301GNU gdb 6.0
20302Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20303GDB is free software, covered by the GNU General Public License,
20304and you are welcome to change it and/or distribute copies of it
20305under certain conditions.
20306Type "show copying" to see the conditions.
20307There is absolutely no warranty for GDB. Type "show warranty"
20308for details.
086432e2 20309This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20310
20311^Z^Zpre-prompt
f7dc1244 20312(@value{GDBP})
922fbb7b 20313^Z^Zprompt
086432e2 20314@kbd{quit}
922fbb7b
AC
20315
20316^Z^Zpost-prompt
b383017d 20317$
922fbb7b
AC
20318@end smallexample
20319
20320Here @samp{quit} is input to @value{GDBN}; the rest is output from
20321@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20322denotes a @samp{control-z} character) are annotations; the rest is
20323output from @value{GDBN}.
20324
20325@node Server Prefix
20326@section The Server Prefix
20327@cindex server prefix for annotations
20328
20329To issue a command to @value{GDBN} without affecting certain aspects of
20330the state which is seen by users, prefix it with @samp{server }. This
20331means that this command will not affect the command history, nor will it
20332affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20333pressed on a line by itself.
20334
20335The server prefix does not affect the recording of values into the value
20336history; to print a value without recording it into the value history,
20337use the @code{output} command instead of the @code{print} command.
20338
922fbb7b
AC
20339@node Prompting
20340@section Annotation for @value{GDBN} Input
20341
20342@cindex annotations for prompts
20343When @value{GDBN} prompts for input, it annotates this fact so it is possible
20344to know when to send output, when the output from a given command is
20345over, etc.
20346
20347Different kinds of input each have a different @dfn{input type}. Each
20348input type has three annotations: a @code{pre-} annotation, which
20349denotes the beginning of any prompt which is being output, a plain
20350annotation, which denotes the end of the prompt, and then a @code{post-}
20351annotation which denotes the end of any echo which may (or may not) be
20352associated with the input. For example, the @code{prompt} input type
20353features the following annotations:
20354
20355@smallexample
20356^Z^Zpre-prompt
20357^Z^Zprompt
20358^Z^Zpost-prompt
20359@end smallexample
20360
20361The input types are
20362
20363@table @code
20364@findex pre-prompt
20365@findex prompt
20366@findex post-prompt
20367@item prompt
20368When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20369
20370@findex pre-commands
20371@findex commands
20372@findex post-commands
20373@item commands
20374When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20375command. The annotations are repeated for each command which is input.
20376
20377@findex pre-overload-choice
20378@findex overload-choice
20379@findex post-overload-choice
20380@item overload-choice
20381When @value{GDBN} wants the user to select between various overloaded functions.
20382
20383@findex pre-query
20384@findex query
20385@findex post-query
20386@item query
20387When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20388
20389@findex pre-prompt-for-continue
20390@findex prompt-for-continue
20391@findex post-prompt-for-continue
20392@item prompt-for-continue
20393When @value{GDBN} is asking the user to press return to continue. Note: Don't
20394expect this to work well; instead use @code{set height 0} to disable
20395prompting. This is because the counting of lines is buggy in the
20396presence of annotations.
20397@end table
20398
20399@node Errors
20400@section Errors
20401@cindex annotations for errors, warnings and interrupts
20402
20403@findex quit
20404@smallexample
20405^Z^Zquit
20406@end smallexample
20407
20408This annotation occurs right before @value{GDBN} responds to an interrupt.
20409
20410@findex error
20411@smallexample
20412^Z^Zerror
20413@end smallexample
20414
20415This annotation occurs right before @value{GDBN} responds to an error.
20416
20417Quit and error annotations indicate that any annotations which @value{GDBN} was
20418in the middle of may end abruptly. For example, if a
20419@code{value-history-begin} annotation is followed by a @code{error}, one
20420cannot expect to receive the matching @code{value-history-end}. One
20421cannot expect not to receive it either, however; an error annotation
20422does not necessarily mean that @value{GDBN} is immediately returning all the way
20423to the top level.
20424
20425@findex error-begin
20426A quit or error annotation may be preceded by
20427
20428@smallexample
20429^Z^Zerror-begin
20430@end smallexample
20431
20432Any output between that and the quit or error annotation is the error
20433message.
20434
20435Warning messages are not yet annotated.
20436@c If we want to change that, need to fix warning(), type_error(),
20437@c range_error(), and possibly other places.
20438
922fbb7b
AC
20439@node Invalidation
20440@section Invalidation Notices
20441
20442@cindex annotations for invalidation messages
20443The following annotations say that certain pieces of state may have
20444changed.
20445
20446@table @code
20447@findex frames-invalid
20448@item ^Z^Zframes-invalid
20449
20450The frames (for example, output from the @code{backtrace} command) may
20451have changed.
20452
20453@findex breakpoints-invalid
20454@item ^Z^Zbreakpoints-invalid
20455
20456The breakpoints may have changed. For example, the user just added or
20457deleted a breakpoint.
20458@end table
20459
20460@node Annotations for Running
20461@section Running the Program
20462@cindex annotations for running programs
20463
20464@findex starting
20465@findex stopping
20466When the program starts executing due to a @value{GDBN} command such as
b383017d 20467@code{step} or @code{continue},
922fbb7b
AC
20468
20469@smallexample
20470^Z^Zstarting
20471@end smallexample
20472
b383017d 20473is output. When the program stops,
922fbb7b
AC
20474
20475@smallexample
20476^Z^Zstopped
20477@end smallexample
20478
20479is output. Before the @code{stopped} annotation, a variety of
20480annotations describe how the program stopped.
20481
20482@table @code
20483@findex exited
20484@item ^Z^Zexited @var{exit-status}
20485The program exited, and @var{exit-status} is the exit status (zero for
20486successful exit, otherwise nonzero).
20487
20488@findex signalled
20489@findex signal-name
20490@findex signal-name-end
20491@findex signal-string
20492@findex signal-string-end
20493@item ^Z^Zsignalled
20494The program exited with a signal. After the @code{^Z^Zsignalled}, the
20495annotation continues:
20496
20497@smallexample
20498@var{intro-text}
20499^Z^Zsignal-name
20500@var{name}
20501^Z^Zsignal-name-end
20502@var{middle-text}
20503^Z^Zsignal-string
20504@var{string}
20505^Z^Zsignal-string-end
20506@var{end-text}
20507@end smallexample
20508
20509@noindent
20510where @var{name} is the name of the signal, such as @code{SIGILL} or
20511@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20512as @code{Illegal Instruction} or @code{Segmentation fault}.
20513@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20514user's benefit and have no particular format.
20515
20516@findex signal
20517@item ^Z^Zsignal
20518The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20519just saying that the program received the signal, not that it was
20520terminated with it.
20521
20522@findex breakpoint
20523@item ^Z^Zbreakpoint @var{number}
20524The program hit breakpoint number @var{number}.
20525
20526@findex watchpoint
20527@item ^Z^Zwatchpoint @var{number}
20528The program hit watchpoint number @var{number}.
20529@end table
20530
20531@node Source Annotations
20532@section Displaying Source
20533@cindex annotations for source display
20534
20535@findex source
20536The following annotation is used instead of displaying source code:
20537
20538@smallexample
20539^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20540@end smallexample
20541
20542where @var{filename} is an absolute file name indicating which source
20543file, @var{line} is the line number within that file (where 1 is the
20544first line in the file), @var{character} is the character position
20545within the file (where 0 is the first character in the file) (for most
20546debug formats this will necessarily point to the beginning of a line),
20547@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20548line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20549@var{addr} is the address in the target program associated with the
20550source which is being displayed. @var{addr} is in the form @samp{0x}
20551followed by one or more lowercase hex digits (note that this does not
20552depend on the language).
20553
8e04817f
AC
20554@node GDB Bugs
20555@chapter Reporting Bugs in @value{GDBN}
20556@cindex bugs in @value{GDBN}
20557@cindex reporting bugs in @value{GDBN}
c906108c 20558
8e04817f 20559Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20560
8e04817f
AC
20561Reporting a bug may help you by bringing a solution to your problem, or it
20562may not. But in any case the principal function of a bug report is to help
20563the entire community by making the next version of @value{GDBN} work better. Bug
20564reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20565
8e04817f
AC
20566In order for a bug report to serve its purpose, you must include the
20567information that enables us to fix the bug.
c4555f82
SC
20568
20569@menu
8e04817f
AC
20570* Bug Criteria:: Have you found a bug?
20571* Bug Reporting:: How to report bugs
c4555f82
SC
20572@end menu
20573
8e04817f
AC
20574@node Bug Criteria
20575@section Have you found a bug?
20576@cindex bug criteria
c4555f82 20577
8e04817f 20578If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20579
20580@itemize @bullet
8e04817f
AC
20581@cindex fatal signal
20582@cindex debugger crash
20583@cindex crash of debugger
c4555f82 20584@item
8e04817f
AC
20585If the debugger gets a fatal signal, for any input whatever, that is a
20586@value{GDBN} bug. Reliable debuggers never crash.
20587
20588@cindex error on valid input
20589@item
20590If @value{GDBN} produces an error message for valid input, that is a
20591bug. (Note that if you're cross debugging, the problem may also be
20592somewhere in the connection to the target.)
c4555f82 20593
8e04817f 20594@cindex invalid input
c4555f82 20595@item
8e04817f
AC
20596If @value{GDBN} does not produce an error message for invalid input,
20597that is a bug. However, you should note that your idea of
20598``invalid input'' might be our idea of ``an extension'' or ``support
20599for traditional practice''.
20600
20601@item
20602If you are an experienced user of debugging tools, your suggestions
20603for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
20604@end itemize
20605
8e04817f
AC
20606@node Bug Reporting
20607@section How to report bugs
20608@cindex bug reports
20609@cindex @value{GDBN} bugs, reporting
20610
20611A number of companies and individuals offer support for @sc{gnu} products.
20612If you obtained @value{GDBN} from a support organization, we recommend you
20613contact that organization first.
20614
20615You can find contact information for many support companies and
20616individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20617distribution.
20618@c should add a web page ref...
20619
129188f6
AC
20620In any event, we also recommend that you submit bug reports for
20621@value{GDBN}. The prefered method is to submit them directly using
20622@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20623page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20624be used.
8e04817f
AC
20625
20626@strong{Do not send bug reports to @samp{info-gdb}, or to
20627@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20628not want to receive bug reports. Those that do have arranged to receive
20629@samp{bug-gdb}.
20630
20631The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20632serves as a repeater. The mailing list and the newsgroup carry exactly
20633the same messages. Often people think of posting bug reports to the
20634newsgroup instead of mailing them. This appears to work, but it has one
20635problem which can be crucial: a newsgroup posting often lacks a mail
20636path back to the sender. Thus, if we need to ask for more information,
20637we may be unable to reach you. For this reason, it is better to send
20638bug reports to the mailing list.
c4555f82 20639
8e04817f
AC
20640The fundamental principle of reporting bugs usefully is this:
20641@strong{report all the facts}. If you are not sure whether to state a
20642fact or leave it out, state it!
c4555f82 20643
8e04817f
AC
20644Often people omit facts because they think they know what causes the
20645problem and assume that some details do not matter. Thus, you might
20646assume that the name of the variable you use in an example does not matter.
20647Well, probably it does not, but one cannot be sure. Perhaps the bug is a
20648stray memory reference which happens to fetch from the location where that
20649name is stored in memory; perhaps, if the name were different, the contents
20650of that location would fool the debugger into doing the right thing despite
20651the bug. Play it safe and give a specific, complete example. That is the
20652easiest thing for you to do, and the most helpful.
c4555f82 20653
8e04817f
AC
20654Keep in mind that the purpose of a bug report is to enable us to fix the
20655bug. It may be that the bug has been reported previously, but neither
20656you nor we can know that unless your bug report is complete and
20657self-contained.
c4555f82 20658
8e04817f
AC
20659Sometimes people give a few sketchy facts and ask, ``Does this ring a
20660bell?'' Those bug reports are useless, and we urge everyone to
20661@emph{refuse to respond to them} except to chide the sender to report
20662bugs properly.
20663
20664To enable us to fix the bug, you should include all these things:
c4555f82
SC
20665
20666@itemize @bullet
20667@item
8e04817f
AC
20668The version of @value{GDBN}. @value{GDBN} announces it if you start
20669with no arguments; you can also print it at any time using @code{show
20670version}.
c4555f82 20671
8e04817f
AC
20672Without this, we will not know whether there is any point in looking for
20673the bug in the current version of @value{GDBN}.
c4555f82
SC
20674
20675@item
8e04817f
AC
20676The type of machine you are using, and the operating system name and
20677version number.
c4555f82
SC
20678
20679@item
8e04817f
AC
20680What compiler (and its version) was used to compile @value{GDBN}---e.g.
20681``@value{GCC}--2.8.1''.
c4555f82
SC
20682
20683@item
8e04817f
AC
20684What compiler (and its version) was used to compile the program you are
20685debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
20686C Compiler''. For GCC, you can say @code{gcc --version} to get this
20687information; for other compilers, see the documentation for those
20688compilers.
c4555f82 20689
8e04817f
AC
20690@item
20691The command arguments you gave the compiler to compile your example and
20692observe the bug. For example, did you use @samp{-O}? To guarantee
20693you will not omit something important, list them all. A copy of the
20694Makefile (or the output from make) is sufficient.
c4555f82 20695
8e04817f
AC
20696If we were to try to guess the arguments, we would probably guess wrong
20697and then we might not encounter the bug.
c4555f82 20698
8e04817f
AC
20699@item
20700A complete input script, and all necessary source files, that will
20701reproduce the bug.
c4555f82 20702
8e04817f
AC
20703@item
20704A description of what behavior you observe that you believe is
20705incorrect. For example, ``It gets a fatal signal.''
c4555f82 20706
8e04817f
AC
20707Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
20708will certainly notice it. But if the bug is incorrect output, we might
20709not notice unless it is glaringly wrong. You might as well not give us
20710a chance to make a mistake.
c4555f82 20711
8e04817f
AC
20712Even if the problem you experience is a fatal signal, you should still
20713say so explicitly. Suppose something strange is going on, such as, your
20714copy of @value{GDBN} is out of synch, or you have encountered a bug in
20715the C library on your system. (This has happened!) Your copy might
20716crash and ours would not. If you told us to expect a crash, then when
20717ours fails to crash, we would know that the bug was not happening for
20718us. If you had not told us to expect a crash, then we would not be able
20719to draw any conclusion from our observations.
c4555f82 20720
e0c07bf0
MC
20721@pindex script
20722@cindex recording a session script
20723To collect all this information, you can use a session recording program
20724such as @command{script}, which is available on many Unix systems.
20725Just run your @value{GDBN} session inside @command{script} and then
20726include the @file{typescript} file with your bug report.
20727
20728Another way to record a @value{GDBN} session is to run @value{GDBN}
20729inside Emacs and then save the entire buffer to a file.
20730
8e04817f
AC
20731@item
20732If you wish to suggest changes to the @value{GDBN} source, send us context
20733diffs. If you even discuss something in the @value{GDBN} source, refer to
20734it by context, not by line number.
c4555f82 20735
8e04817f
AC
20736The line numbers in our development sources will not match those in your
20737sources. Your line numbers would convey no useful information to us.
c4555f82 20738
8e04817f 20739@end itemize
c4555f82 20740
8e04817f 20741Here are some things that are not necessary:
c4555f82 20742
8e04817f
AC
20743@itemize @bullet
20744@item
20745A description of the envelope of the bug.
c4555f82 20746
8e04817f
AC
20747Often people who encounter a bug spend a lot of time investigating
20748which changes to the input file will make the bug go away and which
20749changes will not affect it.
c4555f82 20750
8e04817f
AC
20751This is often time consuming and not very useful, because the way we
20752will find the bug is by running a single example under the debugger
20753with breakpoints, not by pure deduction from a series of examples.
20754We recommend that you save your time for something else.
c4555f82 20755
8e04817f
AC
20756Of course, if you can find a simpler example to report @emph{instead}
20757of the original one, that is a convenience for us. Errors in the
20758output will be easier to spot, running under the debugger will take
20759less time, and so on.
c4555f82 20760
8e04817f
AC
20761However, simplification is not vital; if you do not want to do this,
20762report the bug anyway and send us the entire test case you used.
c4555f82 20763
8e04817f
AC
20764@item
20765A patch for the bug.
c4555f82 20766
8e04817f
AC
20767A patch for the bug does help us if it is a good one. But do not omit
20768the necessary information, such as the test case, on the assumption that
20769a patch is all we need. We might see problems with your patch and decide
20770to fix the problem another way, or we might not understand it at all.
c4555f82 20771
8e04817f
AC
20772Sometimes with a program as complicated as @value{GDBN} it is very hard to
20773construct an example that will make the program follow a certain path
20774through the code. If you do not send us the example, we will not be able
20775to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 20776
8e04817f
AC
20777And if we cannot understand what bug you are trying to fix, or why your
20778patch should be an improvement, we will not install it. A test case will
20779help us to understand.
c4555f82 20780
8e04817f
AC
20781@item
20782A guess about what the bug is or what it depends on.
c4555f82 20783
8e04817f
AC
20784Such guesses are usually wrong. Even we cannot guess right about such
20785things without first using the debugger to find the facts.
20786@end itemize
c4555f82 20787
8e04817f
AC
20788@c The readline documentation is distributed with the readline code
20789@c and consists of the two following files:
20790@c rluser.texinfo
20791@c inc-hist.texinfo
20792@c Use -I with makeinfo to point to the appropriate directory,
20793@c environment var TEXINPUTS with TeX.
20794@include rluser.texinfo
20795@include inc-hist.texinfo
c4555f82 20796
c4555f82 20797
8e04817f
AC
20798@node Formatting Documentation
20799@appendix Formatting Documentation
c4555f82 20800
8e04817f
AC
20801@cindex @value{GDBN} reference card
20802@cindex reference card
20803The @value{GDBN} 4 release includes an already-formatted reference card, ready
20804for printing with PostScript or Ghostscript, in the @file{gdb}
20805subdirectory of the main source directory@footnote{In
20806@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
20807release.}. If you can use PostScript or Ghostscript with your printer,
20808you can print the reference card immediately with @file{refcard.ps}.
c4555f82 20809
8e04817f
AC
20810The release also includes the source for the reference card. You
20811can format it, using @TeX{}, by typing:
c4555f82 20812
474c8240 20813@smallexample
8e04817f 20814make refcard.dvi
474c8240 20815@end smallexample
c4555f82 20816
8e04817f
AC
20817The @value{GDBN} reference card is designed to print in @dfn{landscape}
20818mode on US ``letter'' size paper;
20819that is, on a sheet 11 inches wide by 8.5 inches
20820high. You will need to specify this form of printing as an option to
20821your @sc{dvi} output program.
c4555f82 20822
8e04817f 20823@cindex documentation
c4555f82 20824
8e04817f
AC
20825All the documentation for @value{GDBN} comes as part of the machine-readable
20826distribution. The documentation is written in Texinfo format, which is
20827a documentation system that uses a single source file to produce both
20828on-line information and a printed manual. You can use one of the Info
20829formatting commands to create the on-line version of the documentation
20830and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 20831
8e04817f
AC
20832@value{GDBN} includes an already formatted copy of the on-line Info
20833version of this manual in the @file{gdb} subdirectory. The main Info
20834file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
20835subordinate files matching @samp{gdb.info*} in the same directory. If
20836necessary, you can print out these files, or read them with any editor;
20837but they are easier to read using the @code{info} subsystem in @sc{gnu}
20838Emacs or the standalone @code{info} program, available as part of the
20839@sc{gnu} Texinfo distribution.
c4555f82 20840
8e04817f
AC
20841If you want to format these Info files yourself, you need one of the
20842Info formatting programs, such as @code{texinfo-format-buffer} or
20843@code{makeinfo}.
c4555f82 20844
8e04817f
AC
20845If you have @code{makeinfo} installed, and are in the top level
20846@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
20847version @value{GDBVN}), you can make the Info file by typing:
c4555f82 20848
474c8240 20849@smallexample
8e04817f
AC
20850cd gdb
20851make gdb.info
474c8240 20852@end smallexample
c4555f82 20853
8e04817f
AC
20854If you want to typeset and print copies of this manual, you need @TeX{},
20855a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
20856Texinfo definitions file.
c4555f82 20857
8e04817f
AC
20858@TeX{} is a typesetting program; it does not print files directly, but
20859produces output files called @sc{dvi} files. To print a typeset
20860document, you need a program to print @sc{dvi} files. If your system
20861has @TeX{} installed, chances are it has such a program. The precise
20862command to use depends on your system; @kbd{lpr -d} is common; another
20863(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
20864require a file name without any extension or a @samp{.dvi} extension.
c4555f82 20865
8e04817f
AC
20866@TeX{} also requires a macro definitions file called
20867@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
20868written in Texinfo format. On its own, @TeX{} cannot either read or
20869typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
20870and is located in the @file{gdb-@var{version-number}/texinfo}
20871directory.
c4555f82 20872
8e04817f
AC
20873If you have @TeX{} and a @sc{dvi} printer program installed, you can
20874typeset and print this manual. First switch to the the @file{gdb}
20875subdirectory of the main source directory (for example, to
20876@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 20877
474c8240 20878@smallexample
8e04817f 20879make gdb.dvi
474c8240 20880@end smallexample
c4555f82 20881
8e04817f 20882Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 20883
8e04817f
AC
20884@node Installing GDB
20885@appendix Installing @value{GDBN}
20886@cindex configuring @value{GDBN}
20887@cindex installation
94e91d6d 20888@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 20889
8e04817f
AC
20890@value{GDBN} comes with a @code{configure} script that automates the process
20891of preparing @value{GDBN} for installation; you can then use @code{make} to
20892build the @code{gdb} program.
20893@iftex
20894@c irrelevant in info file; it's as current as the code it lives with.
20895@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
20896look at the @file{README} file in the sources; we may have improved the
20897installation procedures since publishing this manual.}
20898@end iftex
c4555f82 20899
8e04817f
AC
20900The @value{GDBN} distribution includes all the source code you need for
20901@value{GDBN} in a single directory, whose name is usually composed by
20902appending the version number to @samp{gdb}.
c4555f82 20903
8e04817f
AC
20904For example, the @value{GDBN} version @value{GDBVN} distribution is in the
20905@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 20906
8e04817f
AC
20907@table @code
20908@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
20909script for configuring @value{GDBN} and all its supporting libraries
c4555f82 20910
8e04817f
AC
20911@item gdb-@value{GDBVN}/gdb
20912the source specific to @value{GDBN} itself
c4555f82 20913
8e04817f
AC
20914@item gdb-@value{GDBVN}/bfd
20915source for the Binary File Descriptor library
c906108c 20916
8e04817f
AC
20917@item gdb-@value{GDBVN}/include
20918@sc{gnu} include files
c906108c 20919
8e04817f
AC
20920@item gdb-@value{GDBVN}/libiberty
20921source for the @samp{-liberty} free software library
c906108c 20922
8e04817f
AC
20923@item gdb-@value{GDBVN}/opcodes
20924source for the library of opcode tables and disassemblers
c906108c 20925
8e04817f
AC
20926@item gdb-@value{GDBVN}/readline
20927source for the @sc{gnu} command-line interface
c906108c 20928
8e04817f
AC
20929@item gdb-@value{GDBVN}/glob
20930source for the @sc{gnu} filename pattern-matching subroutine
c906108c 20931
8e04817f
AC
20932@item gdb-@value{GDBVN}/mmalloc
20933source for the @sc{gnu} memory-mapped malloc package
20934@end table
c906108c 20935
8e04817f
AC
20936The simplest way to configure and build @value{GDBN} is to run @code{configure}
20937from the @file{gdb-@var{version-number}} source directory, which in
20938this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 20939
8e04817f
AC
20940First switch to the @file{gdb-@var{version-number}} source directory
20941if you are not already in it; then run @code{configure}. Pass the
20942identifier for the platform on which @value{GDBN} will run as an
20943argument.
c906108c 20944
8e04817f 20945For example:
c906108c 20946
474c8240 20947@smallexample
8e04817f
AC
20948cd gdb-@value{GDBVN}
20949./configure @var{host}
20950make
474c8240 20951@end smallexample
c906108c 20952
8e04817f
AC
20953@noindent
20954where @var{host} is an identifier such as @samp{sun4} or
20955@samp{decstation}, that identifies the platform where @value{GDBN} will run.
20956(You can often leave off @var{host}; @code{configure} tries to guess the
20957correct value by examining your system.)
c906108c 20958
8e04817f
AC
20959Running @samp{configure @var{host}} and then running @code{make} builds the
20960@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
20961libraries, then @code{gdb} itself. The configured source files, and the
20962binaries, are left in the corresponding source directories.
c906108c 20963
8e04817f
AC
20964@need 750
20965@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
20966system does not recognize this automatically when you run a different
20967shell, you may need to run @code{sh} on it explicitly:
c906108c 20968
474c8240 20969@smallexample
8e04817f 20970sh configure @var{host}
474c8240 20971@end smallexample
c906108c 20972
8e04817f
AC
20973If you run @code{configure} from a directory that contains source
20974directories for multiple libraries or programs, such as the
20975@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
20976creates configuration files for every directory level underneath (unless
20977you tell it not to, with the @samp{--norecursion} option).
20978
94e91d6d
MC
20979You should run the @code{configure} script from the top directory in the
20980source tree, the @file{gdb-@var{version-number}} directory. If you run
20981@code{configure} from one of the subdirectories, you will configure only
20982that subdirectory. That is usually not what you want. In particular,
20983if you run the first @code{configure} from the @file{gdb} subdirectory
20984of the @file{gdb-@var{version-number}} directory, you will omit the
20985configuration of @file{bfd}, @file{readline}, and other sibling
20986directories of the @file{gdb} subdirectory. This leads to build errors
20987about missing include files such as @file{bfd/bfd.h}.
c906108c 20988
8e04817f
AC
20989You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
20990However, you should make sure that the shell on your path (named by
20991the @samp{SHELL} environment variable) is publicly readable. Remember
20992that @value{GDBN} uses the shell to start your program---some systems refuse to
20993let @value{GDBN} debug child processes whose programs are not readable.
c906108c 20994
8e04817f
AC
20995@menu
20996* Separate Objdir:: Compiling @value{GDBN} in another directory
20997* Config Names:: Specifying names for hosts and targets
20998* Configure Options:: Summary of options for configure
20999@end menu
c906108c 21000
8e04817f
AC
21001@node Separate Objdir
21002@section Compiling @value{GDBN} in another directory
c906108c 21003
8e04817f
AC
21004If you want to run @value{GDBN} versions for several host or target machines,
21005you need a different @code{gdb} compiled for each combination of
21006host and target. @code{configure} is designed to make this easy by
21007allowing you to generate each configuration in a separate subdirectory,
21008rather than in the source directory. If your @code{make} program
21009handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21010@code{make} in each of these directories builds the @code{gdb}
21011program specified there.
c906108c 21012
8e04817f
AC
21013To build @code{gdb} in a separate directory, run @code{configure}
21014with the @samp{--srcdir} option to specify where to find the source.
21015(You also need to specify a path to find @code{configure}
21016itself from your working directory. If the path to @code{configure}
21017would be the same as the argument to @samp{--srcdir}, you can leave out
21018the @samp{--srcdir} option; it is assumed.)
c906108c 21019
8e04817f
AC
21020For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21021separate directory for a Sun 4 like this:
c906108c 21022
474c8240 21023@smallexample
8e04817f
AC
21024@group
21025cd gdb-@value{GDBVN}
21026mkdir ../gdb-sun4
21027cd ../gdb-sun4
21028../gdb-@value{GDBVN}/configure sun4
21029make
21030@end group
474c8240 21031@end smallexample
c906108c 21032
8e04817f
AC
21033When @code{configure} builds a configuration using a remote source
21034directory, it creates a tree for the binaries with the same structure
21035(and using the same names) as the tree under the source directory. In
21036the example, you'd find the Sun 4 library @file{libiberty.a} in the
21037directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21038@file{gdb-sun4/gdb}.
c906108c 21039
94e91d6d
MC
21040Make sure that your path to the @file{configure} script has just one
21041instance of @file{gdb} in it. If your path to @file{configure} looks
21042like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21043one subdirectory of @value{GDBN}, not the whole package. This leads to
21044build errors about missing include files such as @file{bfd/bfd.h}.
21045
8e04817f
AC
21046One popular reason to build several @value{GDBN} configurations in separate
21047directories is to configure @value{GDBN} for cross-compiling (where
21048@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21049programs that run on another machine---the @dfn{target}).
21050You specify a cross-debugging target by
21051giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21052
8e04817f
AC
21053When you run @code{make} to build a program or library, you must run
21054it in a configured directory---whatever directory you were in when you
21055called @code{configure} (or one of its subdirectories).
c906108c 21056
8e04817f
AC
21057The @code{Makefile} that @code{configure} generates in each source
21058directory also runs recursively. If you type @code{make} in a source
21059directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21060directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21061will build all the required libraries, and then build GDB.
c906108c 21062
8e04817f
AC
21063When you have multiple hosts or targets configured in separate
21064directories, you can run @code{make} on them in parallel (for example,
21065if they are NFS-mounted on each of the hosts); they will not interfere
21066with each other.
c906108c 21067
8e04817f
AC
21068@node Config Names
21069@section Specifying names for hosts and targets
c906108c 21070
8e04817f
AC
21071The specifications used for hosts and targets in the @code{configure}
21072script are based on a three-part naming scheme, but some short predefined
21073aliases are also supported. The full naming scheme encodes three pieces
21074of information in the following pattern:
c906108c 21075
474c8240 21076@smallexample
8e04817f 21077@var{architecture}-@var{vendor}-@var{os}
474c8240 21078@end smallexample
c906108c 21079
8e04817f
AC
21080For example, you can use the alias @code{sun4} as a @var{host} argument,
21081or as the value for @var{target} in a @code{--target=@var{target}}
21082option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21083
8e04817f
AC
21084The @code{configure} script accompanying @value{GDBN} does not provide
21085any query facility to list all supported host and target names or
21086aliases. @code{configure} calls the Bourne shell script
21087@code{config.sub} to map abbreviations to full names; you can read the
21088script, if you wish, or you can use it to test your guesses on
21089abbreviations---for example:
c906108c 21090
8e04817f
AC
21091@smallexample
21092% sh config.sub i386-linux
21093i386-pc-linux-gnu
21094% sh config.sub alpha-linux
21095alpha-unknown-linux-gnu
21096% sh config.sub hp9k700
21097hppa1.1-hp-hpux
21098% sh config.sub sun4
21099sparc-sun-sunos4.1.1
21100% sh config.sub sun3
21101m68k-sun-sunos4.1.1
21102% sh config.sub i986v
21103Invalid configuration `i986v': machine `i986v' not recognized
21104@end smallexample
c906108c 21105
8e04817f
AC
21106@noindent
21107@code{config.sub} is also distributed in the @value{GDBN} source
21108directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21109
8e04817f
AC
21110@node Configure Options
21111@section @code{configure} options
c906108c 21112
8e04817f
AC
21113Here is a summary of the @code{configure} options and arguments that
21114are most often useful for building @value{GDBN}. @code{configure} also has
21115several other options not listed here. @inforef{What Configure
21116Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21117
474c8240 21118@smallexample
8e04817f
AC
21119configure @r{[}--help@r{]}
21120 @r{[}--prefix=@var{dir}@r{]}
21121 @r{[}--exec-prefix=@var{dir}@r{]}
21122 @r{[}--srcdir=@var{dirname}@r{]}
21123 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21124 @r{[}--target=@var{target}@r{]}
21125 @var{host}
474c8240 21126@end smallexample
c906108c 21127
8e04817f
AC
21128@noindent
21129You may introduce options with a single @samp{-} rather than
21130@samp{--} if you prefer; but you may abbreviate option names if you use
21131@samp{--}.
c906108c 21132
8e04817f
AC
21133@table @code
21134@item --help
21135Display a quick summary of how to invoke @code{configure}.
c906108c 21136
8e04817f
AC
21137@item --prefix=@var{dir}
21138Configure the source to install programs and files under directory
21139@file{@var{dir}}.
c906108c 21140
8e04817f
AC
21141@item --exec-prefix=@var{dir}
21142Configure the source to install programs under directory
21143@file{@var{dir}}.
c906108c 21144
8e04817f
AC
21145@c avoid splitting the warning from the explanation:
21146@need 2000
21147@item --srcdir=@var{dirname}
21148@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21149@code{make} that implements the @code{VPATH} feature.}@*
21150Use this option to make configurations in directories separate from the
21151@value{GDBN} source directories. Among other things, you can use this to
21152build (or maintain) several configurations simultaneously, in separate
21153directories. @code{configure} writes configuration specific files in
21154the current directory, but arranges for them to use the source in the
21155directory @var{dirname}. @code{configure} creates directories under
21156the working directory in parallel to the source directories below
21157@var{dirname}.
c906108c 21158
8e04817f
AC
21159@item --norecursion
21160Configure only the directory level where @code{configure} is executed; do not
21161propagate configuration to subdirectories.
c906108c 21162
8e04817f
AC
21163@item --target=@var{target}
21164Configure @value{GDBN} for cross-debugging programs running on the specified
21165@var{target}. Without this option, @value{GDBN} is configured to debug
21166programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21167
8e04817f 21168There is no convenient way to generate a list of all available targets.
c906108c 21169
8e04817f
AC
21170@item @var{host} @dots{}
21171Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21172
8e04817f
AC
21173There is no convenient way to generate a list of all available hosts.
21174@end table
c906108c 21175
8e04817f
AC
21176There are many other options available as well, but they are generally
21177needed for special purposes only.
c906108c 21178
8e04817f
AC
21179@node Maintenance Commands
21180@appendix Maintenance Commands
21181@cindex maintenance commands
21182@cindex internal commands
c906108c 21183
8e04817f 21184In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21185includes a number of commands intended for @value{GDBN} developers,
21186that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21187provided here for reference. (For commands that turn on debugging
21188messages, see @ref{Debugging Output}.)
c906108c 21189
8e04817f 21190@table @code
09d4efe1
EZ
21191@kindex maint agent
21192@item maint agent @var{expression}
21193Translate the given @var{expression} into remote agent bytecodes.
21194This command is useful for debugging the Agent Expression mechanism
21195(@pxref{Agent Expressions}).
21196
8e04817f
AC
21197@kindex maint info breakpoints
21198@item @anchor{maint info breakpoints}maint info breakpoints
21199Using the same format as @samp{info breakpoints}, display both the
21200breakpoints you've set explicitly, and those @value{GDBN} is using for
21201internal purposes. Internal breakpoints are shown with negative
21202breakpoint numbers. The type column identifies what kind of breakpoint
21203is shown:
c906108c 21204
8e04817f
AC
21205@table @code
21206@item breakpoint
21207Normal, explicitly set breakpoint.
c906108c 21208
8e04817f
AC
21209@item watchpoint
21210Normal, explicitly set watchpoint.
c906108c 21211
8e04817f
AC
21212@item longjmp
21213Internal breakpoint, used to handle correctly stepping through
21214@code{longjmp} calls.
c906108c 21215
8e04817f
AC
21216@item longjmp resume
21217Internal breakpoint at the target of a @code{longjmp}.
c906108c 21218
8e04817f
AC
21219@item until
21220Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21221
8e04817f
AC
21222@item finish
21223Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21224
8e04817f
AC
21225@item shlib events
21226Shared library events.
c906108c 21227
8e04817f 21228@end table
c906108c 21229
09d4efe1
EZ
21230@kindex maint check-symtabs
21231@item maint check-symtabs
21232Check the consistency of psymtabs and symtabs.
21233
21234@kindex maint cplus first_component
21235@item maint cplus first_component @var{name}
21236Print the first C@t{++} class/namespace component of @var{name}.
21237
21238@kindex maint cplus namespace
21239@item maint cplus namespace
21240Print the list of possible C@t{++} namespaces.
21241
21242@kindex maint demangle
21243@item maint demangle @var{name}
21244Demangle a C@t{++} or Objective-C manled @var{name}.
21245
21246@kindex maint deprecate
21247@kindex maint undeprecate
21248@cindex deprecated commands
21249@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21250@itemx maint undeprecate @var{command}
21251Deprecate or undeprecate the named @var{command}. Deprecated commands
21252cause @value{GDBN} to issue a warning when you use them. The optional
21253argument @var{replacement} says which newer command should be used in
21254favor of the deprecated one; if it is given, @value{GDBN} will mention
21255the replacement as part of the warning.
21256
21257@kindex maint dump-me
21258@item maint dump-me
721c2651 21259@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21260Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21261This is supported only on systems which support aborting a program
21262with the @code{SIGQUIT} signal.
09d4efe1 21263
8d30a00d
AC
21264@kindex maint internal-error
21265@kindex maint internal-warning
09d4efe1
EZ
21266@item maint internal-error @r{[}@var{message-text}@r{]}
21267@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21268Cause @value{GDBN} to call the internal function @code{internal_error}
21269or @code{internal_warning} and hence behave as though an internal error
21270or internal warning has been detected. In addition to reporting the
21271internal problem, these functions give the user the opportunity to
21272either quit @value{GDBN} or create a core file of the current
21273@value{GDBN} session.
21274
09d4efe1
EZ
21275These commands take an optional parameter @var{message-text} that is
21276used as the text of the error or warning message.
21277
21278Here's an example of using @code{indernal-error}:
21279
8d30a00d 21280@smallexample
f7dc1244 21281(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21282@dots{}/maint.c:121: internal-error: testing, 1, 2
21283A problem internal to GDB has been detected. Further
21284debugging may prove unreliable.
21285Quit this debugging session? (y or n) @kbd{n}
21286Create a core file? (y or n) @kbd{n}
f7dc1244 21287(@value{GDBP})
8d30a00d
AC
21288@end smallexample
21289
09d4efe1
EZ
21290@kindex maint packet
21291@item maint packet @var{text}
21292If @value{GDBN} is talking to an inferior via the serial protocol,
21293then this command sends the string @var{text} to the inferior, and
21294displays the response packet. @value{GDBN} supplies the initial
21295@samp{$} character, the terminating @samp{#} character, and the
21296checksum.
21297
21298@kindex maint print architecture
21299@item maint print architecture @r{[}@var{file}@r{]}
21300Print the entire architecture configuration. The optional argument
21301@var{file} names the file where the output goes.
8d30a00d 21302
00905d52
AC
21303@kindex maint print dummy-frames
21304@item maint print dummy-frames
00905d52
AC
21305Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21306
21307@smallexample
f7dc1244 21308(@value{GDBP}) @kbd{b add}
00905d52 21309@dots{}
f7dc1244 21310(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21311Breakpoint 2, add (a=2, b=3) at @dots{}
2131258 return (a + b);
21313The program being debugged stopped while in a function called from GDB.
21314@dots{}
f7dc1244 21315(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
213160x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21317 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21318 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21319(@value{GDBP})
00905d52
AC
21320@end smallexample
21321
21322Takes an optional file parameter.
21323
0680b120
AC
21324@kindex maint print registers
21325@kindex maint print raw-registers
21326@kindex maint print cooked-registers
617073a9 21327@kindex maint print register-groups
09d4efe1
EZ
21328@item maint print registers @r{[}@var{file}@r{]}
21329@itemx maint print raw-registers @r{[}@var{file}@r{]}
21330@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21331@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21332Print @value{GDBN}'s internal register data structures.
21333
617073a9
AC
21334The command @code{maint print raw-registers} includes the contents of
21335the raw register cache; the command @code{maint print cooked-registers}
21336includes the (cooked) value of all registers; and the command
21337@code{maint print register-groups} includes the groups that each
21338register is a member of. @xref{Registers,, Registers, gdbint,
21339@value{GDBN} Internals}.
0680b120 21340
09d4efe1
EZ
21341These commands take an optional parameter, a file name to which to
21342write the information.
0680b120 21343
617073a9 21344@kindex maint print reggroups
09d4efe1
EZ
21345@item maint print reggroups @r{[}@var{file}@r{]}
21346Print @value{GDBN}'s internal register group data structures. The
21347optional argument @var{file} tells to what file to write the
21348information.
617073a9 21349
09d4efe1 21350The register groups info looks like this:
617073a9
AC
21351
21352@smallexample
f7dc1244 21353(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21354 Group Type
21355 general user
21356 float user
21357 all user
21358 vector user
21359 system user
21360 save internal
21361 restore internal
617073a9
AC
21362@end smallexample
21363
09d4efe1
EZ
21364@kindex flushregs
21365@item flushregs
21366This command forces @value{GDBN} to flush its internal register cache.
21367
21368@kindex maint print objfiles
21369@cindex info for known object files
21370@item maint print objfiles
21371Print a dump of all known object files. For each object file, this
21372command prints its name, address in memory, and all of its psymtabs
21373and symtabs.
21374
21375@kindex maint print statistics
21376@cindex bcache statistics
21377@item maint print statistics
21378This command prints, for each object file in the program, various data
21379about that object file followed by the byte cache (@dfn{bcache})
21380statistics for the object file. The objfile data includes the number
21381of minimal, partical, full, and stabs symbols, the number of types
21382defined by the objfile, the number of as yet unexpanded psym tables,
21383the number of line tables and string tables, and the amount of memory
21384used by the various tables. The bcache statistics include the counts,
21385sizes, and counts of duplicates of all and unique objects, max,
21386average, and median entry size, total memory used and its overhead and
21387savings, and various measures of the hash table size and chain
21388lengths.
21389
21390@kindex maint print type
21391@cindex type chain of a data type
21392@item maint print type @var{expr}
21393Print the type chain for a type specified by @var{expr}. The argument
21394can be either a type name or a symbol. If it is a symbol, the type of
21395that symbol is described. The type chain produced by this command is
21396a recursive definition of the data type as stored in @value{GDBN}'s
21397data structures, including its flags and contained types.
21398
21399@kindex maint set dwarf2 max-cache-age
21400@kindex maint show dwarf2 max-cache-age
21401@item maint set dwarf2 max-cache-age
21402@itemx maint show dwarf2 max-cache-age
21403Control the DWARF 2 compilation unit cache.
21404
21405@cindex DWARF 2 compilation units cache
21406In object files with inter-compilation-unit references, such as those
21407produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21408reader needs to frequently refer to previously read compilation units.
21409This setting controls how long a compilation unit will remain in the
21410cache if it is not referenced. A higher limit means that cached
21411compilation units will be stored in memory longer, and more total
21412memory will be used. Setting it to zero disables caching, which will
21413slow down @value{GDBN} startup, but reduce memory consumption.
21414
e7ba9c65
DJ
21415@kindex maint set profile
21416@kindex maint show profile
21417@cindex profiling GDB
21418@item maint set profile
21419@itemx maint show profile
21420Control profiling of @value{GDBN}.
21421
21422Profiling will be disabled until you use the @samp{maint set profile}
21423command to enable it. When you enable profiling, the system will begin
21424collecting timing and execution count data; when you disable profiling or
21425exit @value{GDBN}, the results will be written to a log file. Remember that
21426if you use profiling, @value{GDBN} will overwrite the profiling log file
21427(often called @file{gmon.out}). If you have a record of important profiling
21428data in a @file{gmon.out} file, be sure to move it to a safe location.
21429
21430Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21431compiled with the @samp{-pg} compiler option.
e7ba9c65 21432
09d4efe1
EZ
21433@kindex maint show-debug-regs
21434@cindex x86 hardware debug registers
21435@item maint show-debug-regs
21436Control whether to show variables that mirror the x86 hardware debug
21437registers. Use @code{ON} to enable, @code{OFF} to disable. If
21438enabled, the debug registers values are shown when GDB inserts or
21439removes a hardware breakpoint or watchpoint, and when the inferior
21440triggers a hardware-assisted breakpoint or watchpoint.
21441
21442@kindex maint space
21443@cindex memory used by commands
21444@item maint space
21445Control whether to display memory usage for each command. If set to a
21446nonzero value, @value{GDBN} will display how much memory each command
21447took, following the command's own output. This can also be requested
21448by invoking @value{GDBN} with the @option{--statistics} command-line
21449switch (@pxref{Mode Options}).
21450
21451@kindex maint time
21452@cindex time of command execution
21453@item maint time
21454Control whether to display the execution time for each command. If
21455set to a nonzero value, @value{GDBN} will display how much time it
21456took to execute each command, following the command's own output.
21457This can also be requested by invoking @value{GDBN} with the
21458@option{--statistics} command-line switch (@pxref{Mode Options}).
21459
21460@kindex maint translate-address
21461@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21462Find the symbol stored at the location specified by the address
21463@var{addr} and an optional section name @var{section}. If found,
21464@value{GDBN} prints the name of the closest symbol and an offset from
21465the symbol's location to the specified address. This is similar to
21466the @code{info address} command (@pxref{Symbols}), except that this
21467command also allows to find symbols in other sections.
ae038cb0 21468
8e04817f 21469@end table
c906108c 21470
9c16f35a
EZ
21471The following command is useful for non-interactive invocations of
21472@value{GDBN}, such as in the test suite.
21473
21474@table @code
21475@item set watchdog @var{nsec}
21476@kindex set watchdog
21477@cindex watchdog timer
21478@cindex timeout for commands
21479Set the maximum number of seconds @value{GDBN} will wait for the
21480target operation to finish. If this time expires, @value{GDBN}
21481reports and error and the command is aborted.
21482
21483@item show watchdog
21484Show the current setting of the target wait timeout.
21485@end table
c906108c 21486
e0ce93ac 21487@node Remote Protocol
8e04817f 21488@appendix @value{GDBN} Remote Serial Protocol
c906108c 21489
ee2d5c50
AC
21490@menu
21491* Overview::
21492* Packets::
21493* Stop Reply Packets::
21494* General Query Packets::
21495* Register Packet Format::
21496* Examples::
0ce1b118 21497* File-I/O remote protocol extension::
ee2d5c50
AC
21498@end menu
21499
21500@node Overview
21501@section Overview
21502
8e04817f
AC
21503There may be occasions when you need to know something about the
21504protocol---for example, if there is only one serial port to your target
21505machine, you might want your program to do something special if it
21506recognizes a packet meant for @value{GDBN}.
c906108c 21507
d2c6833e 21508In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21509transmitted and received data respectfully.
c906108c 21510
8e04817f
AC
21511@cindex protocol, @value{GDBN} remote serial
21512@cindex serial protocol, @value{GDBN} remote
21513@cindex remote serial protocol
21514All @value{GDBN} commands and responses (other than acknowledgments) are
21515sent as a @var{packet}. A @var{packet} is introduced with the character
21516@samp{$}, the actual @var{packet-data}, and the terminating character
21517@samp{#} followed by a two-digit @var{checksum}:
c906108c 21518
474c8240 21519@smallexample
8e04817f 21520@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21521@end smallexample
8e04817f 21522@noindent
c906108c 21523
8e04817f
AC
21524@cindex checksum, for @value{GDBN} remote
21525@noindent
21526The two-digit @var{checksum} is computed as the modulo 256 sum of all
21527characters between the leading @samp{$} and the trailing @samp{#} (an
21528eight bit unsigned checksum).
c906108c 21529
8e04817f
AC
21530Implementors should note that prior to @value{GDBN} 5.0 the protocol
21531specification also included an optional two-digit @var{sequence-id}:
c906108c 21532
474c8240 21533@smallexample
8e04817f 21534@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21535@end smallexample
c906108c 21536
8e04817f
AC
21537@cindex sequence-id, for @value{GDBN} remote
21538@noindent
21539That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21540has never output @var{sequence-id}s. Stubs that handle packets added
21541since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21542
8e04817f
AC
21543@cindex acknowledgment, for @value{GDBN} remote
21544When either the host or the target machine receives a packet, the first
21545response expected is an acknowledgment: either @samp{+} (to indicate
21546the package was received correctly) or @samp{-} (to request
21547retransmission):
c906108c 21548
474c8240 21549@smallexample
d2c6833e
AC
21550-> @code{$}@var{packet-data}@code{#}@var{checksum}
21551<- @code{+}
474c8240 21552@end smallexample
8e04817f 21553@noindent
53a5351d 21554
8e04817f
AC
21555The host (@value{GDBN}) sends @var{command}s, and the target (the
21556debugging stub incorporated in your program) sends a @var{response}. In
21557the case of step and continue @var{command}s, the response is only sent
21558when the operation has completed (the target has again stopped).
c906108c 21559
8e04817f
AC
21560@var{packet-data} consists of a sequence of characters with the
21561exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21562exceptions).
c906108c 21563
8e04817f 21564Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21565@cindex remote protocol, field separator
8e04817f 21566@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21567@sc{hex} with leading zeros suppressed.
c906108c 21568
8e04817f
AC
21569Implementors should note that prior to @value{GDBN} 5.0, the character
21570@samp{:} could not appear as the third character in a packet (as it
21571would potentially conflict with the @var{sequence-id}).
c906108c 21572
8e04817f
AC
21573Response @var{data} can be run-length encoded to save space. A @samp{*}
21574means that the next character is an @sc{ascii} encoding giving a repeat count
21575which stands for that many repetitions of the character preceding the
21576@samp{*}. The encoding is @code{n+29}, yielding a printable character
21577where @code{n >=3} (which is where rle starts to win). The printable
21578characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21579value greater than 126 should not be used.
c906108c 21580
8e04817f 21581So:
474c8240 21582@smallexample
8e04817f 21583"@code{0* }"
474c8240 21584@end smallexample
8e04817f
AC
21585@noindent
21586means the same as "0000".
c906108c 21587
8e04817f
AC
21588The error response returned for some packets includes a two character
21589error number. That number is not well defined.
c906108c 21590
8e04817f
AC
21591For any @var{command} not supported by the stub, an empty response
21592(@samp{$#00}) should be returned. That way it is possible to extend the
21593protocol. A newer @value{GDBN} can tell if a packet is supported based
21594on that response.
c906108c 21595
b383017d
RM
21596A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21597@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21598optional.
c906108c 21599
ee2d5c50
AC
21600@node Packets
21601@section Packets
21602
21603The following table provides a complete list of all currently defined
21604@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
21605@xref{File-I/O remote protocol extension}, for details about the File
21606I/O extension of the remote protocol.
ee2d5c50
AC
21607
21608@table @r
21609
21610@item @code{!} --- extended mode
21611@cindex @code{!} packet
21612
8e04817f
AC
21613Enable extended mode. In extended mode, the remote server is made
21614persistent. The @samp{R} packet is used to restart the program being
21615debugged.
ee2d5c50
AC
21616
21617Reply:
21618@table @samp
21619@item OK
8e04817f 21620The remote target both supports and has enabled extended mode.
ee2d5c50 21621@end table
c906108c 21622
ee2d5c50
AC
21623@item @code{?} --- last signal
21624@cindex @code{?} packet
c906108c 21625
ee2d5c50
AC
21626Indicate the reason the target halted. The reply is the same as for
21627step and continue.
c906108c 21628
ee2d5c50
AC
21629Reply:
21630@xref{Stop Reply Packets}, for the reply specifications.
21631
21632@item @code{a} --- reserved
21633
21634Reserved for future use.
21635
21636@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21637@cindex @code{A} packet
c906108c 21638
8e04817f
AC
21639Initialized @samp{argv[]} array passed into program. @var{arglen}
21640specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
21641See @code{gdbserver} for more details.
21642
21643Reply:
21644@table @samp
21645@item OK
21646@item E@var{NN}
21647@end table
21648
21649@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
21650@cindex @code{b} packet
21651
21652Change the serial line speed to @var{baud}.
21653
21654JTC: @emph{When does the transport layer state change? When it's
21655received, or after the ACK is transmitted. In either case, there are
21656problems if the command or the acknowledgment packet is dropped.}
21657
21658Stan: @emph{If people really wanted to add something like this, and get
21659it working for the first time, they ought to modify ser-unix.c to send
21660some kind of out-of-band message to a specially-setup stub and have the
21661switch happen "in between" packets, so that from remote protocol's point
21662of view, nothing actually happened.}
21663
21664@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
21665@cindex @code{B} packet
21666
8e04817f 21667Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
21668breakpoint at @var{addr}.
21669
21670This packet has been replaced by the @samp{Z} and @samp{z} packets
21671(@pxref{insert breakpoint or watchpoint packet}).
c906108c 21672
ee2d5c50
AC
21673@item @code{c}@var{addr} --- continue
21674@cindex @code{c} packet
21675
21676@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 21677current address.
c906108c 21678
ee2d5c50
AC
21679Reply:
21680@xref{Stop Reply Packets}, for the reply specifications.
21681
21682@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
21683@cindex @code{C} packet
21684
8e04817f
AC
21685Continue with signal @var{sig} (hex signal number). If
21686@code{;}@var{addr} is omitted, resume at same address.
c906108c 21687
ee2d5c50
AC
21688Reply:
21689@xref{Stop Reply Packets}, for the reply specifications.
c906108c 21690
ee2d5c50
AC
21691@item @code{d} --- toggle debug @strong{(deprecated)}
21692@cindex @code{d} packet
21693
21694Toggle debug flag.
21695
21696@item @code{D} --- detach
21697@cindex @code{D} packet
21698
21699Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 21700before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
21701
21702Reply:
21703@table @samp
21704@item @emph{no response}
8e04817f 21705@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 21706@end table
c906108c 21707
ee2d5c50 21708@item @code{e} --- reserved
c906108c 21709
ee2d5c50 21710Reserved for future use.
c906108c 21711
ee2d5c50 21712@item @code{E} --- reserved
c906108c 21713
ee2d5c50 21714Reserved for future use.
c906108c 21715
ee2d5c50
AC
21716@item @code{f} --- reserved
21717
21718Reserved for future use.
21719
0ce1b118
CV
21720@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
21721@cindex @code{F} packet
ee2d5c50 21722
0ce1b118
CV
21723This packet is send by @value{GDBN} as reply to a @code{F} request packet
21724sent by the target. This is part of the File-I/O protocol extension.
21725@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
21726
21727@item @code{g} --- read registers
21728@anchor{read registers packet}
21729@cindex @code{g} packet
21730
21731Read general registers.
21732
21733Reply:
21734@table @samp
21735@item @var{XX@dots{}}
8e04817f
AC
21736Each byte of register data is described by two hex digits. The bytes
21737with the register are transmitted in target byte order. The size of
21738each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
21739determined by the @value{GDBN} internal macros
21740@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
21741specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
21742@item E@var{NN}
21743for an error.
21744@end table
c906108c 21745
ee2d5c50
AC
21746@item @code{G}@var{XX@dots{}} --- write regs
21747@cindex @code{G} packet
c906108c 21748
ee2d5c50
AC
21749@xref{read registers packet}, for a description of the @var{XX@dots{}}
21750data.
21751
21752Reply:
21753@table @samp
21754@item OK
21755for success
21756@item E@var{NN}
21757for an error
21758@end table
21759
21760@item @code{h} --- reserved
21761
21762Reserved for future use.
21763
b383017d 21764@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 21765@cindex @code{H} packet
c906108c 21766
8e04817f 21767Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
21768@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
21769should be @samp{c} for step and continue operations, @samp{g} for other
21770operations. The thread designator @var{t@dots{}} may be -1, meaning all
21771the threads, a thread number, or zero which means pick any thread.
21772
21773Reply:
21774@table @samp
21775@item OK
21776for success
21777@item E@var{NN}
21778for an error
21779@end table
c906108c 21780
8e04817f
AC
21781@c FIXME: JTC:
21782@c 'H': How restrictive (or permissive) is the thread model. If a
21783@c thread is selected and stopped, are other threads allowed
21784@c to continue to execute? As I mentioned above, I think the
21785@c semantics of each command when a thread is selected must be
21786@c described. For example:
21787@c
21788@c 'g': If the stub supports threads and a specific thread is
21789@c selected, returns the register block from that thread;
21790@c otherwise returns current registers.
21791@c
21792@c 'G' If the stub supports threads and a specific thread is
21793@c selected, sets the registers of the register block of
21794@c that thread; otherwise sets current registers.
c906108c 21795
ee2d5c50
AC
21796@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
21797@anchor{cycle step packet}
21798@cindex @code{i} packet
21799
8e04817f
AC
21800Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
21801present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
21802step starting at that address.
c906108c 21803
ee2d5c50
AC
21804@item @code{I} --- signal then cycle step @strong{(reserved)}
21805@cindex @code{I} packet
21806
21807@xref{step with signal packet}. @xref{cycle step packet}.
21808
21809@item @code{j} --- reserved
21810
21811Reserved for future use.
21812
21813@item @code{J} --- reserved
c906108c 21814
ee2d5c50 21815Reserved for future use.
c906108c 21816
ee2d5c50
AC
21817@item @code{k} --- kill request
21818@cindex @code{k} packet
c906108c 21819
ac282366 21820FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
21821thread context has been selected (i.e.@: does 'k' kill only that
21822thread?)}.
c906108c 21823
ee2d5c50 21824@item @code{K} --- reserved
c906108c 21825
ee2d5c50
AC
21826Reserved for future use.
21827
21828@item @code{l} --- reserved
21829
21830Reserved for future use.
21831
21832@item @code{L} --- reserved
21833
21834Reserved for future use.
21835
21836@item @code{m}@var{addr}@code{,}@var{length} --- read memory
21837@cindex @code{m} packet
c906108c 21838
8e04817f 21839Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 21840Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 21841assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 21842transfer mechanism is needed.}
c906108c 21843
ee2d5c50
AC
21844Reply:
21845@table @samp
21846@item @var{XX@dots{}}
21847@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
21848to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 21849that sized memory transfers are assumed using word aligned
ee2d5c50
AC
21850accesses. FIXME: @emph{A word aligned memory transfer mechanism is
21851needed.}
21852@item E@var{NN}
21853@var{NN} is errno
21854@end table
21855
21856@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
21857@cindex @code{M} packet
21858
8e04817f 21859Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
21860@var{XX@dots{}} is the data.
21861
21862Reply:
21863@table @samp
21864@item OK
21865for success
21866@item E@var{NN}
8e04817f
AC
21867for an error (this includes the case where only part of the data was
21868written).
ee2d5c50 21869@end table
c906108c 21870
ee2d5c50 21871@item @code{n} --- reserved
c906108c 21872
ee2d5c50 21873Reserved for future use.
c906108c 21874
ee2d5c50 21875@item @code{N} --- reserved
c906108c 21876
ee2d5c50 21877Reserved for future use.
c906108c 21878
ee2d5c50
AC
21879@item @code{o} --- reserved
21880
21881Reserved for future use.
21882
21883@item @code{O} --- reserved
21884
2e868123 21885@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
21886@cindex @code{p} packet
21887
2e868123
AC
21888@xref{read registers packet}, for a description of how the returned
21889register value is encoded.
ee2d5c50
AC
21890
21891Reply:
21892@table @samp
2e868123
AC
21893@item @var{XX@dots{}}
21894the register's value
21895@item E@var{NN}
21896for an error
21897@item
21898Indicating an unrecognized @var{query}.
ee2d5c50
AC
21899@end table
21900
21901@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
21902@anchor{write register packet}
21903@cindex @code{P} packet
21904
21905Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 21906digits for each byte in the register (target byte order).
c906108c 21907
ee2d5c50
AC
21908Reply:
21909@table @samp
21910@item OK
21911for success
21912@item E@var{NN}
21913for an error
21914@end table
21915
21916@item @code{q}@var{query} --- general query
21917@anchor{general query packet}
21918@cindex @code{q} packet
21919
21920Request info about @var{query}. In general @value{GDBN} queries have a
21921leading upper case letter. Custom vendor queries should use a company
21922prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
21923be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
21924that they match the full @var{query} name.
21925
21926Reply:
21927@table @samp
21928@item @var{XX@dots{}}
21929Hex encoded data from query. The reply can not be empty.
21930@item E@var{NN}
21931error reply
8e04817f 21932@item
ee2d5c50
AC
21933Indicating an unrecognized @var{query}.
21934@end table
21935
21936@item @code{Q}@var{var}@code{=}@var{val} --- general set
21937@cindex @code{Q} packet
21938
21939Set value of @var{var} to @var{val}.
21940
21941@xref{general query packet}, for a discussion of naming conventions.
c906108c 21942
ee2d5c50
AC
21943@item @code{r} --- reset @strong{(deprecated)}
21944@cindex @code{r} packet
c906108c 21945
8e04817f 21946Reset the entire system.
c906108c 21947
ee2d5c50
AC
21948@item @code{R}@var{XX} --- remote restart
21949@cindex @code{R} packet
21950
8e04817f
AC
21951Restart the program being debugged. @var{XX}, while needed, is ignored.
21952This packet is only available in extended mode.
ee2d5c50
AC
21953
21954Reply:
21955@table @samp
21956@item @emph{no reply}
8e04817f 21957The @samp{R} packet has no reply.
ee2d5c50
AC
21958@end table
21959
21960@item @code{s}@var{addr} --- step
21961@cindex @code{s} packet
c906108c 21962
8e04817f
AC
21963@var{addr} is address to resume. If @var{addr} is omitted, resume at
21964same address.
c906108c 21965
ee2d5c50
AC
21966Reply:
21967@xref{Stop Reply Packets}, for the reply specifications.
21968
21969@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
21970@anchor{step with signal packet}
21971@cindex @code{S} packet
21972
8e04817f 21973Like @samp{C} but step not continue.
c906108c 21974
ee2d5c50
AC
21975Reply:
21976@xref{Stop Reply Packets}, for the reply specifications.
21977
b383017d 21978@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
21979@cindex @code{t} packet
21980
8e04817f 21981Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
21982@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
21983@var{addr} must be at least 3 digits.
c906108c 21984
ee2d5c50
AC
21985@item @code{T}@var{XX} --- thread alive
21986@cindex @code{T} packet
c906108c 21987
ee2d5c50 21988Find out if the thread XX is alive.
c906108c 21989
ee2d5c50
AC
21990Reply:
21991@table @samp
21992@item OK
21993thread is still alive
21994@item E@var{NN}
21995thread is dead
21996@end table
21997
21998@item @code{u} --- reserved
21999
22000Reserved for future use.
22001
22002@item @code{U} --- reserved
22003
22004Reserved for future use.
22005
86d30acc 22006@item @code{v} --- verbose packet prefix
ee2d5c50 22007
86d30acc
DJ
22008Packets starting with @code{v} are identified by a multi-letter name,
22009up to the first @code{;} or @code{?} (or the end of the packet).
22010
22011@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22012@cindex @code{vCont} packet
22013
22014Resume the inferior. Different actions may be specified for each thread.
22015If an action is specified with no @var{tid}, then it is applied to any
22016threads that don't have a specific action specified; if no default action is
22017specified then other threads should remain stopped. Specifying multiple
22018default actions is an error; specifying no actions is also an error.
22019Thread IDs are specified in hexadecimal. Currently supported actions are:
22020
22021@table @code
22022@item c
22023Continue.
22024@item C@var{sig}
22025Continue with signal @var{sig}. @var{sig} should be two hex digits.
22026@item s
22027Step.
22028@item S@var{sig}
22029Step with signal @var{sig}. @var{sig} should be two hex digits.
22030@end table
22031
22032The optional @var{addr} argument normally associated with these packets is
22033not supported in @code{vCont}.
22034
22035Reply:
22036@xref{Stop Reply Packets}, for the reply specifications.
22037
22038@item @code{vCont?} --- extended resume query
22039@cindex @code{vCont?} packet
22040
22041Query support for the @code{vCont} packet.
22042
22043Reply:
22044@table @samp
22045@item @code{vCont}[;@var{action}]...
22046The @code{vCont} packet is supported. Each @var{action} is a supported
22047command in the @code{vCont} packet.
22048@item
22049The @code{vCont} packet is not supported.
22050@end table
ee2d5c50
AC
22051
22052@item @code{V} --- reserved
c906108c 22053
ee2d5c50 22054Reserved for future use.
c906108c 22055
ee2d5c50 22056@item @code{w} --- reserved
c906108c 22057
ee2d5c50 22058Reserved for future use.
c906108c 22059
ee2d5c50 22060@item @code{W} --- reserved
c906108c 22061
ee2d5c50 22062Reserved for future use.
c906108c 22063
ee2d5c50
AC
22064@item @code{x} --- reserved
22065
22066Reserved for future use.
22067
22068@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22069@cindex @code{X} packet
22070
22071@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22072is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22073escaped using @code{0x7d}, and then XORed with @code{0x20}.
22074For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22075
ee2d5c50
AC
22076Reply:
22077@table @samp
22078@item OK
22079for success
22080@item E@var{NN}
22081for an error
22082@end table
22083
22084@item @code{y} --- reserved
c906108c 22085
ee2d5c50 22086Reserved for future use.
c906108c 22087
ee2d5c50
AC
22088@item @code{Y} reserved
22089
22090Reserved for future use.
22091
2f870471
AC
22092@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22093@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22094@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22095@cindex @code{z} packet
2f870471 22096@cindex @code{Z} packets
ee2d5c50 22097
2f870471
AC
22098Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22099watchpoint starting at address @var{address} and covering the next
22100@var{length} bytes.
ee2d5c50 22101
2f870471
AC
22102Each breakpoint and watchpoint packet @var{type} is documented
22103separately.
22104
512217c7
AC
22105@emph{Implementation notes: A remote target shall return an empty string
22106for an unrecognized breakpoint or watchpoint packet @var{type}. A
22107remote target shall support either both or neither of a given
2f870471
AC
22108@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22109avoid potential problems with duplicate packets, the operations should
22110be implemented in an idempotent way.}
22111
22112@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22113@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22114@cindex @code{z0} packet
22115@cindex @code{Z0} packet
22116
22117Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22118@code{addr} of size @code{length}.
22119
22120A memory breakpoint is implemented by replacing the instruction at
22121@var{addr} with a software breakpoint or trap instruction. The
22122@code{length} is used by targets that indicates the size of the
22123breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22124@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22125
2f870471
AC
22126@emph{Implementation note: It is possible for a target to copy or move
22127code that contains memory breakpoints (e.g., when implementing
22128overlays). The behavior of this packet, in the presence of such a
22129target, is not defined.}
c906108c 22130
ee2d5c50
AC
22131Reply:
22132@table @samp
2f870471
AC
22133@item OK
22134success
22135@item
22136not supported
ee2d5c50
AC
22137@item E@var{NN}
22138for an error
2f870471
AC
22139@end table
22140
22141@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22142@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22143@cindex @code{z1} packet
22144@cindex @code{Z1} packet
22145
22146Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22147address @code{addr} of size @code{length}.
22148
22149A hardware breakpoint is implemented using a mechanism that is not
22150dependant on being able to modify the target's memory.
22151
22152@emph{Implementation note: A hardware breakpoint is not affected by code
22153movement.}
22154
22155Reply:
22156@table @samp
ee2d5c50 22157@item OK
2f870471
AC
22158success
22159@item
22160not supported
22161@item E@var{NN}
22162for an error
22163@end table
22164
22165@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22166@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22167@cindex @code{z2} packet
22168@cindex @code{Z2} packet
22169
22170Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22171
22172Reply:
22173@table @samp
22174@item OK
22175success
22176@item
22177not supported
22178@item E@var{NN}
22179for an error
22180@end table
22181
22182@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22183@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22184@cindex @code{z3} packet
22185@cindex @code{Z3} packet
22186
2e834e49 22187Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22188
22189Reply:
22190@table @samp
22191@item OK
22192success
22193@item
22194not supported
22195@item E@var{NN}
22196for an error
22197@end table
22198
2e834e49
HPN
22199@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22200@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22201@cindex @code{z4} packet
22202@cindex @code{Z4} packet
22203
22204Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22205
22206Reply:
22207@table @samp
22208@item OK
22209success
22210@item
22211not supported
22212@item E@var{NN}
22213for an error
ee2d5c50
AC
22214@end table
22215
22216@end table
c906108c 22217
ee2d5c50
AC
22218@node Stop Reply Packets
22219@section Stop Reply Packets
22220@cindex stop reply packets
c906108c 22221
8e04817f
AC
22222The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22223receive any of the below as a reply. In the case of the @samp{C},
22224@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22225when the target halts. In the below the exact meaning of @samp{signal
22226number} is poorly defined. In general one of the UNIX signal numbering
22227conventions is used.
c906108c 22228
ee2d5c50 22229@table @samp
c906108c 22230
ee2d5c50
AC
22231@item S@var{AA}
22232@var{AA} is the signal number
c906108c 22233
8e04817f 22234@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
22235@cindex @code{T} packet reply
22236
8e04817f
AC
22237@var{AA} = two hex digit signal number; @var{n...} = register number
22238(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22239by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22240@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22241(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22242address, this is a hex integer; @var{n...} = other string not starting
22243with valid hex digit. @value{GDBN} should ignore this @var{n...},
22244@var{r...} pair and go on to the next. This way we can extend the
22245protocol.
c906108c 22246
ee2d5c50
AC
22247@item W@var{AA}
22248
8e04817f 22249The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22250applicable to certain targets.
22251
22252@item X@var{AA}
c906108c 22253
8e04817f 22254The process terminated with signal @var{AA}.
c906108c 22255
ee2d5c50 22256@item O@var{XX@dots{}}
c906108c 22257
ee2d5c50
AC
22258@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22259any time while the program is running and the debugger should continue
22260to wait for @samp{W}, @samp{T}, etc.
22261
0ce1b118
CV
22262@item F@var{call-id}@code{,}@var{parameter@dots{}}
22263
22264@var{call-id} is the identifier which says which host system call should
22265be called. This is just the name of the function. Translation into the
22266correct system call is only applicable as it's defined in @value{GDBN}.
22267@xref{File-I/O remote protocol extension}, for a list of implemented
22268system calls.
22269
22270@var{parameter@dots{}} is a list of parameters as defined for this very
22271system call.
22272
22273The target replies with this packet when it expects @value{GDBN} to call
22274a host system call on behalf of the target. @value{GDBN} replies with
22275an appropriate @code{F} packet and keeps up waiting for the next reply
22276packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22277@samp{s} action is expected to be continued.
22278@xref{File-I/O remote protocol extension}, for more details.
22279
ee2d5c50
AC
22280@end table
22281
22282@node General Query Packets
22283@section General Query Packets
9c16f35a 22284@cindex remote query requests
c906108c 22285
8e04817f 22286The following set and query packets have already been defined.
c906108c 22287
ee2d5c50 22288@table @r
c906108c 22289
ee2d5c50 22290@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22291@cindex current thread, remote request
22292@cindex @code{qC} packet
ee2d5c50
AC
22293Return the current thread id.
22294
22295Reply:
22296@table @samp
22297@item @code{QC}@var{pid}
e1aac25b 22298Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22299@item *
22300Any other reply implies the old pid.
22301@end table
22302
22303@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22304@cindex list active threads, remote request
22305@cindex @code{qfThreadInfo} packet
ee2d5c50 22306@code{q}@code{sThreadInfo}
c906108c 22307
8e04817f
AC
22308Obtain a list of active thread ids from the target (OS). Since there
22309may be too many active threads to fit into one reply packet, this query
22310works iteratively: it may require more than one query/reply sequence to
22311obtain the entire list of threads. The first query of the sequence will
22312be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22313sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22314
22315NOTE: replaces the @code{qL} query (see below).
22316
22317Reply:
22318@table @samp
22319@item @code{m}@var{id}
22320A single thread id
22321@item @code{m}@var{id},@var{id}@dots{}
22322a comma-separated list of thread ids
22323@item @code{l}
22324(lower case 'el') denotes end of list.
22325@end table
22326
22327In response to each query, the target will reply with a list of one or
e1aac25b
JB
22328more thread ids, in big-endian unsigned hex, separated by commas.
22329@value{GDBN} will respond to each reply with a request for more thread
22330ids (using the @code{qs} form of the query), until the target responds
22331with @code{l} (lower-case el, for @code{'last'}).
c906108c 22332
ee2d5c50 22333@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22334@cindex thread attributes info, remote request
22335@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22336Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22337string description of a thread's attributes from the target OS. This
22338string may contain anything that the target OS thinks is interesting for
22339@value{GDBN} to tell the user about the thread. The string is displayed
22340in @value{GDBN}'s @samp{info threads} display. Some examples of
22341possible thread extra info strings are ``Runnable'', or ``Blocked on
22342Mutex''.
22343
22344Reply:
22345@table @samp
22346@item @var{XX@dots{}}
22347Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22348the printable string containing the extra information about the thread's
8e04817f 22349attributes.
ee2d5c50
AC
22350@end table
22351
22352@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22353
8e04817f
AC
22354Obtain thread information from RTOS. Where: @var{startflag} (one hex
22355digit) is one to indicate the first query and zero to indicate a
22356subsequent query; @var{threadcount} (two hex digits) is the maximum
22357number of threads the response packet can contain; and @var{nextthread}
22358(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22359returned in the response as @var{argthread}.
ee2d5c50
AC
22360
22361NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22362(see above).
22363
22364Reply:
22365@table @samp
22366@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22367Where: @var{count} (two hex digits) is the number of threads being
22368returned; @var{done} (one hex digit) is zero to indicate more threads
22369and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22370digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22371is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22372digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22373@end table
c906108c 22374
ee2d5c50 22375@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22376@cindex CRC of memory block, remote request
22377@cindex @code{qCRC} packet
ee2d5c50
AC
22378Reply:
22379@table @samp
22380@item @code{E}@var{NN}
22381An error (such as memory fault)
22382@item @code{C}@var{CRC32}
22383A 32 bit cyclic redundancy check of the specified memory region.
22384@end table
22385
22386@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22387@cindex section offsets, remote request
22388@cindex @code{qOffsets} packet
8e04817f
AC
22389Get section offsets that the target used when re-locating the downloaded
22390image. @emph{Note: while a @code{Bss} offset is included in the
22391response, @value{GDBN} ignores this and instead applies the @code{Data}
22392offset to the @code{Bss} section.}
c906108c 22393
ee2d5c50
AC
22394Reply:
22395@table @samp
22396@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22397@end table
22398
22399@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22400@cindex thread information, remote request
22401@cindex @code{qP} packet
8e04817f
AC
22402Returns information on @var{threadid}. Where: @var{mode} is a hex
22403encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22404
22405Reply:
22406@table @samp
22407@item *
22408@end table
22409
8e04817f 22410See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22411
ee2d5c50 22412@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22413@cindex execute remote command, remote request
22414@cindex @code{qRcmd} packet
ee2d5c50 22415@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22416execution. Invalid commands should be reported using the output string.
22417Before the final result packet, the target may also respond with a
ee2d5c50
AC
22418number of intermediate @code{O}@var{output} console output packets.
22419@emph{Implementors should note that providing access to a stubs's
22420interpreter may have security implications}.
22421
22422Reply:
22423@table @samp
22424@item OK
8e04817f 22425A command response with no output.
ee2d5c50 22426@item @var{OUTPUT}
8e04817f 22427A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22428@item @code{E}@var{NN}
8e04817f 22429Indicate a badly formed request.
ee2d5c50 22430@item @samp{}
8e04817f 22431When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22432@end table
9c16f35a 22433z
ee2d5c50 22434@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22435@cindex symbol lookup, remote request
22436@cindex @code{qSymbol} packet
8e04817f
AC
22437Notify the target that @value{GDBN} is prepared to serve symbol lookup
22438requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22439
22440Reply:
22441@table @samp
22442@item @code{OK}
8e04817f 22443The target does not need to look up any (more) symbols.
ee2d5c50
AC
22444@item @code{qSymbol:}@var{sym_name}
22445The target requests the value of symbol @var{sym_name} (hex encoded).
22446@value{GDBN} may provide the value by using the
22447@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22448@end table
22449
22450@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22451
22452Set the value of @var{sym_name} to @var{sym_value}.
22453
22454@var{sym_name} (hex encoded) is the name of a symbol whose value the
22455target has previously requested.
22456
22457@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22458@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22459will be empty.
22460
22461Reply:
22462@table @samp
22463@item @code{OK}
8e04817f 22464The target does not need to look up any (more) symbols.
ee2d5c50
AC
22465@item @code{qSymbol:}@var{sym_name}
22466The target requests the value of a new symbol @var{sym_name} (hex
22467encoded). @value{GDBN} will continue to supply the values of symbols
22468(if available), until the target ceases to request them.
22469@end table
eb12ee30 22470
649e03f6 22471@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22472@cindex read special object, remote request
22473@cindex @code{qPart} packet
649e03f6
RM
22474Read uninterpreted bytes from the target's special data area
22475identified by the keyword @code{object}.
22476Request @var{length} bytes starting at @var{offset} bytes into the data.
22477The content and encoding of @var{annex} is specific to the object;
22478it can supply additional details about what data to access.
22479
22480Here are the specific requests of this form defined so far.
22481All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22482requests use the same reply formats, listed below.
22483
22484@table @asis
22485@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22486Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22487auxiliary vector}, and see @ref{Remote configuration,
22488read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22489@end table
22490
22491Reply:
22492@table @asis
22493@item @code{OK}
22494The @var{offset} in the request is at the end of the data.
22495There is no more data to be read.
22496
22497@item @var{XX@dots{}}
22498Hex encoded data bytes read.
22499This may be fewer bytes than the @var{length} in the request.
22500
22501@item @code{E00}
22502The request was malformed, or @var{annex} was invalid.
22503
22504@item @code{E}@var{nn}
22505The offset was invalid, or there was an error encountered reading the data.
22506@var{nn} is a hex-encoded @code{errno} value.
22507
22508@item @code{""} (empty)
22509An empty reply indicates the @var{object} or @var{annex} string was not
22510recognized by the stub.
22511@end table
22512
22513@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22514@cindex write data into object, remote request
649e03f6
RM
22515Write uninterpreted bytes into the target's special data area
22516identified by the keyword @code{object},
22517starting at @var{offset} bytes into the data.
22518@var{data@dots{}} is the hex-encoded data to be written.
22519The content and encoding of @var{annex} is specific to the object;
22520it can supply additional details about what data to access.
22521
22522No requests of this form are presently in use. This specification
22523serves as a placeholder to document the common format that new
22524specific request specifications ought to use.
22525
22526Reply:
22527@table @asis
22528@item @var{nn}
22529@var{nn} (hex encoded) is the number of bytes written.
22530This may be fewer bytes than supplied in the request.
22531
22532@item @code{E00}
22533The request was malformed, or @var{annex} was invalid.
22534
22535@item @code{E}@var{nn}
22536The offset was invalid, or there was an error encountered writing the data.
22537@var{nn} is a hex-encoded @code{errno} value.
22538
22539@item @code{""} (empty)
22540An empty reply indicates the @var{object} or @var{annex} string was not
22541recognized by the stub, or that the object does not support writing.
22542@end table
22543
22544@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22545Requests of this form may be added in the future. When a stub does
22546not recognize the @var{object} keyword, or its support for
22547@var{object} does not recognize the @var{operation} keyword,
22548the stub must respond with an empty packet.
83761cbd
KB
22549
22550@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22551@cindex get thread-local storage address, remote request
22552@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22553Fetch the address associated with thread local storage specified
22554by @var{thread-id}, @var{offset}, and @var{lm}.
22555
22556@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22557thread for which to fetch the TLS address.
22558
22559@var{offset} is the (big endian, hex encoded) offset associated with the
22560thread local variable. (This offset is obtained from the debug
22561information associated with the variable.)
22562
22563@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22564the load module associated with the thread local storage. For example,
22565a @sc{gnu}/Linux system will pass the link map address of the shared
22566object associated with the thread local storage under consideration.
22567Other operating environments may choose to represent the load module
22568differently, so the precise meaning of this parameter will vary.
22569
22570Reply:
22571@table @asis
68c71a2e 22572@item @var{XX@dots{}}
83761cbd
KB
22573Hex encoded (big endian) bytes representing the address of the thread
22574local storage requested.
22575
22576@item @code{E}@var{nn} (where @var{nn} are hex digits)
22577An error occurred.
22578
22579@item @code{""} (empty)
22580An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22581@end table
22582
ee2d5c50
AC
22583@end table
22584
22585@node Register Packet Format
22586@section Register Packet Format
eb12ee30 22587
8e04817f 22588The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22589In the below, some thirty-two bit registers are transferred as
22590sixty-four bits. Those registers should be zero/sign extended (which?)
22591to fill the space allocated. Register bytes are transfered in target
22592byte order. The two nibbles within a register byte are transfered
22593most-significant - least-significant.
eb12ee30 22594
ee2d5c50 22595@table @r
eb12ee30 22596
8e04817f 22597@item MIPS32
ee2d5c50 22598
8e04817f
AC
22599All registers are transfered as thirty-two bit quantities in the order:
2260032 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22601registers; fsr; fir; fp.
eb12ee30 22602
8e04817f 22603@item MIPS64
ee2d5c50 22604
8e04817f
AC
22605All registers are transfered as sixty-four bit quantities (including
22606thirty-two bit registers such as @code{sr}). The ordering is the same
22607as @code{MIPS32}.
eb12ee30 22608
ee2d5c50
AC
22609@end table
22610
22611@node Examples
22612@section Examples
eb12ee30 22613
8e04817f
AC
22614Example sequence of a target being re-started. Notice how the restart
22615does not get any direct output:
eb12ee30 22616
474c8240 22617@smallexample
d2c6833e
AC
22618-> @code{R00}
22619<- @code{+}
8e04817f 22620@emph{target restarts}
d2c6833e 22621-> @code{?}
8e04817f 22622<- @code{+}
d2c6833e
AC
22623<- @code{T001:1234123412341234}
22624-> @code{+}
474c8240 22625@end smallexample
eb12ee30 22626
8e04817f 22627Example sequence of a target being stepped by a single instruction:
eb12ee30 22628
474c8240 22629@smallexample
d2c6833e 22630-> @code{G1445@dots{}}
8e04817f 22631<- @code{+}
d2c6833e
AC
22632-> @code{s}
22633<- @code{+}
22634@emph{time passes}
22635<- @code{T001:1234123412341234}
8e04817f 22636-> @code{+}
d2c6833e 22637-> @code{g}
8e04817f 22638<- @code{+}
d2c6833e
AC
22639<- @code{1455@dots{}}
22640-> @code{+}
474c8240 22641@end smallexample
eb12ee30 22642
0ce1b118
CV
22643@node File-I/O remote protocol extension
22644@section File-I/O remote protocol extension
22645@cindex File-I/O remote protocol extension
22646
22647@menu
22648* File-I/O Overview::
22649* Protocol basics::
1d8b2f28
JB
22650* The F request packet::
22651* The F reply packet::
0ce1b118
CV
22652* Memory transfer::
22653* The Ctrl-C message::
22654* Console I/O::
22655* The isatty call::
22656* The system call::
22657* List of supported calls::
22658* Protocol specific representation of datatypes::
22659* Constants::
22660* File-I/O Examples::
22661@end menu
22662
22663@node File-I/O Overview
22664@subsection File-I/O Overview
22665@cindex file-i/o overview
22666
9c16f35a
EZ
22667The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
22668target to use the host's file system and console I/O when calling various
0ce1b118
CV
22669system calls. System calls on the target system are translated into a
22670remote protocol packet to the host system which then performs the needed
22671actions and returns with an adequate response packet to the target system.
22672This simulates file system operations even on targets that lack file systems.
22673
22674The protocol is defined host- and target-system independent. It uses
9c16f35a 22675its own independent representation of datatypes and values. Both,
0ce1b118
CV
22676@value{GDBN} and the target's @value{GDBN} stub are responsible for
22677translating the system dependent values into the unified protocol values
22678when data is transmitted.
22679
22680The communication is synchronous. A system call is possible only
22681when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
22682packets. While @value{GDBN} handles the request for a system call,
22683the target is stopped to allow deterministic access to the target's
22684memory. Therefore File-I/O is not interuptible by target signals. It
22685is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
22686
22687The target's request to perform a host system call does not finish
22688the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
22689after finishing the system call, the target returns to continuing the
22690previous activity (continue, step). No additional continue or step
22691request from @value{GDBN} is required.
22692
22693@smallexample
f7dc1244 22694(@value{GDBP}) continue
0ce1b118
CV
22695 <- target requests 'system call X'
22696 target is stopped, @value{GDBN} executes system call
22697 -> GDB returns result
22698 ... target continues, GDB returns to wait for the target
22699 <- target hits breakpoint and sends a Txx packet
22700@end smallexample
22701
22702The protocol is only used for files on the host file system and
22703for I/O on the console. Character or block special devices, pipes,
22704named pipes or sockets or any other communication method on the host
22705system are not supported by this protocol.
22706
22707@node Protocol basics
22708@subsection Protocol basics
22709@cindex protocol basics, file-i/o
22710
22711The File-I/O protocol uses the @code{F} packet, as request as well
22712as as reply packet. Since a File-I/O system call can only occur when
b383017d 22713@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
22714File-I/O request is a reply that @value{GDBN} has to expect as a result
22715of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
22716This @code{F} packet contains all information needed to allow @value{GDBN}
22717to call the appropriate host system call:
22718
22719@itemize @bullet
b383017d 22720@item
0ce1b118
CV
22721A unique identifier for the requested system call.
22722
22723@item
22724All parameters to the system call. Pointers are given as addresses
22725in the target memory address space. Pointers to strings are given as
b383017d 22726pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
22727Numerical control values are given in a protocol specific representation.
22728
22729@end itemize
22730
22731At that point @value{GDBN} has to perform the following actions.
22732
22733@itemize @bullet
b383017d 22734@item
0ce1b118
CV
22735If parameter pointer values are given, which point to data needed as input
22736to a system call, @value{GDBN} requests this data from the target with a
22737standard @code{m} packet request. This additional communication has to be
22738expected by the target implementation and is handled as any other @code{m}
22739packet.
22740
22741@item
22742@value{GDBN} translates all value from protocol representation to host
22743representation as needed. Datatypes are coerced into the host types.
22744
22745@item
22746@value{GDBN} calls the system call
22747
22748@item
22749It then coerces datatypes back to protocol representation.
22750
22751@item
22752If pointer parameters in the request packet point to buffer space in which
22753a system call is expected to copy data to, the data is transmitted to the
22754target using a @code{M} or @code{X} packet. This packet has to be expected
22755by the target implementation and is handled as any other @code{M} or @code{X}
22756packet.
22757
22758@end itemize
22759
22760Eventually @value{GDBN} replies with another @code{F} packet which contains all
22761necessary information for the target to continue. This at least contains
22762
22763@itemize @bullet
22764@item
22765Return value.
22766
22767@item
22768@code{errno}, if has been changed by the system call.
22769
22770@item
22771``Ctrl-C'' flag.
22772
22773@end itemize
22774
22775After having done the needed type and value coercion, the target continues
22776the latest continue or step action.
22777
1d8b2f28 22778@node The F request packet
0ce1b118
CV
22779@subsection The @code{F} request packet
22780@cindex file-i/o request packet
22781@cindex @code{F} request packet
22782
22783The @code{F} request packet has the following format:
22784
22785@table @samp
22786
22787@smallexample
22788@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
22789@end smallexample
22790
22791@var{call-id} is the identifier to indicate the host system call to be called.
22792This is just the name of the function.
22793
22794@var{parameter@dots{}} are the parameters to the system call.
22795
b383017d 22796@end table
0ce1b118
CV
22797
22798Parameters are hexadecimal integer values, either the real values in case
22799of scalar datatypes, as pointers to target buffer space in case of compound
22800datatypes and unspecified memory areas or as pointer/length pairs in case
22801of string parameters. These are appended to the call-id, each separated
22802from its predecessor by a comma. All values are transmitted in ASCII
22803string representation, pointer/length pairs separated by a slash.
22804
1d8b2f28 22805@node The F reply packet
0ce1b118
CV
22806@subsection The @code{F} reply packet
22807@cindex file-i/o reply packet
22808@cindex @code{F} reply packet
22809
22810The @code{F} reply packet has the following format:
22811
22812@table @samp
22813
22814@smallexample
22815@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
22816@end smallexample
22817
22818@var{retcode} is the return code of the system call as hexadecimal value.
22819
22820@var{errno} is the errno set by the call, in protocol specific representation.
22821This parameter can be omitted if the call was successful.
22822
22823@var{Ctrl-C flag} is only send if the user requested a break. In this
22824case, @var{errno} must be send as well, even if the call was successful.
22825The @var{Ctrl-C flag} itself consists of the character 'C':
22826
22827@smallexample
22828F0,0,C
22829@end smallexample
22830
22831@noindent
22832or, if the call was interupted before the host call has been performed:
22833
22834@smallexample
22835F-1,4,C
22836@end smallexample
22837
22838@noindent
22839assuming 4 is the protocol specific representation of @code{EINTR}.
22840
22841@end table
22842
22843@node Memory transfer
22844@subsection Memory transfer
22845@cindex memory transfer, in file-i/o protocol
22846
22847Structured data which is transferred using a memory read or write as e.g.@:
22848a @code{struct stat} is expected to be in a protocol specific format with
22849all scalar multibyte datatypes being big endian. This should be done by
22850the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
22851it transfers memory to the target. Transferred pointers to structured
22852data should point to the already coerced data at any time.
22853
22854@node The Ctrl-C message
22855@subsection The Ctrl-C message
22856@cindex ctrl-c message, in file-i/o protocol
22857
22858A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
22859reply packet. In this case the target should behave, as if it had
22860gotten a break message. The meaning for the target is ``system call
22861interupted by @code{SIGINT}''. Consequentially, the target should actually stop
22862(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 22863packet. In this case, it's important for the target to know, in which
0ce1b118
CV
22864state the system call was interrupted. Since this action is by design
22865not an atomic operation, we have to differ between two cases:
22866
22867@itemize @bullet
22868@item
22869The system call hasn't been performed on the host yet.
22870
22871@item
22872The system call on the host has been finished.
22873
22874@end itemize
22875
22876These two states can be distinguished by the target by the value of the
22877returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
22878call hasn't been performed. This is equivalent to the @code{EINTR} handling
22879on POSIX systems. In any other case, the target may presume that the
22880system call has been finished --- successful or not --- and should behave
22881as if the break message arrived right after the system call.
22882
22883@value{GDBN} must behave reliable. If the system call has not been called
22884yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
22885@code{errno} in the packet. If the system call on the host has been finished
22886before the user requests a break, the full action must be finshed by
22887@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
22888The @code{F} packet may only be send when either nothing has happened
22889or the full action has been completed.
22890
22891@node Console I/O
22892@subsection Console I/O
22893@cindex console i/o as part of file-i/o
22894
22895By default and if not explicitely closed by the target system, the file
22896descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
22897on the @value{GDBN} console is handled as any other file output operation
22898(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
22899by @value{GDBN} so that after the target read request from file descriptor
229000 all following typing is buffered until either one of the following
22901conditions is met:
22902
22903@itemize @bullet
22904@item
22905The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
22906@code{read}
22907system call is treated as finished.
22908
22909@item
22910The user presses @kbd{Enter}. This is treated as end of input with a trailing
22911line feed.
22912
22913@item
22914The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
22915character, especially no Ctrl-D is appended to the input.
22916
22917@end itemize
22918
22919If the user has typed more characters as fit in the buffer given to
22920the read call, the trailing characters are buffered in @value{GDBN} until
22921either another @code{read(0, @dots{})} is requested by the target or debugging
22922is stopped on users request.
22923
22924@node The isatty call
22925@subsection The isatty(3) call
22926@cindex isatty call, file-i/o protocol
22927
22928A special case in this protocol is the library call @code{isatty} which
9c16f35a 22929is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
229301 to the target if the file descriptor given as parameter is attached
22931to the @value{GDBN} console, 0 otherwise. Implementing through system calls
22932would require implementing @code{ioctl} and would be more complex than
22933needed.
22934
22935@node The system call
22936@subsection The system(3) call
22937@cindex system call, file-i/o protocol
22938
22939The other special case in this protocol is the @code{system} call which
9c16f35a 22940is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
22941task of calling the necessary host calls to perform the @code{system}
22942call. The return value of @code{system} is simplified before it's returned
22943to the target. Basically, the only signal transmitted back is @code{EINTR}
22944in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
22945entirely of the exit status of the called command.
22946
9c16f35a
EZ
22947Due to security concerns, the @code{system} call is by default refused
22948by @value{GDBN}. The user has to allow this call explicitly with the
22949@kbd{set remote system-call-allowed 1} command.
0ce1b118 22950
9c16f35a
EZ
22951@table @code
22952@item set remote system-call-allowed
22953@kindex set remote system-call-allowed
22954Control whether to allow the @code{system} calls in the File I/O
22955protocol for the remote target. The default is zero (disabled).
0ce1b118 22956
9c16f35a 22957@item show remote system-call-allowed
0ce1b118 22958@kindex show remote system-call-allowed
9c16f35a
EZ
22959Show the current setting of system calls for the remote File I/O
22960protocol.
0ce1b118
CV
22961@end table
22962
22963@node List of supported calls
22964@subsection List of supported calls
22965@cindex list of supported file-i/o calls
22966
22967@menu
22968* open::
22969* close::
22970* read::
22971* write::
22972* lseek::
22973* rename::
22974* unlink::
22975* stat/fstat::
22976* gettimeofday::
22977* isatty::
22978* system::
22979@end menu
22980
22981@node open
22982@unnumberedsubsubsec open
22983@cindex open, file-i/o system call
22984
22985@smallexample
22986@exdent Synopsis:
22987int open(const char *pathname, int flags);
22988int open(const char *pathname, int flags, mode_t mode);
22989
b383017d 22990@exdent Request:
0ce1b118
CV
22991Fopen,pathptr/len,flags,mode
22992@end smallexample
22993
22994@noindent
22995@code{flags} is the bitwise or of the following values:
22996
22997@table @code
b383017d 22998@item O_CREAT
0ce1b118
CV
22999If the file does not exist it will be created. The host
23000rules apply as far as file ownership and time stamps
23001are concerned.
23002
b383017d 23003@item O_EXCL
0ce1b118
CV
23004When used with O_CREAT, if the file already exists it is
23005an error and open() fails.
23006
b383017d 23007@item O_TRUNC
0ce1b118
CV
23008If the file already exists and the open mode allows
23009writing (O_RDWR or O_WRONLY is given) it will be
23010truncated to length 0.
23011
b383017d 23012@item O_APPEND
0ce1b118
CV
23013The file is opened in append mode.
23014
b383017d 23015@item O_RDONLY
0ce1b118
CV
23016The file is opened for reading only.
23017
b383017d 23018@item O_WRONLY
0ce1b118
CV
23019The file is opened for writing only.
23020
b383017d 23021@item O_RDWR
0ce1b118
CV
23022The file is opened for reading and writing.
23023
23024@noindent
23025Each other bit is silently ignored.
23026
23027@end table
23028
23029@noindent
23030@code{mode} is the bitwise or of the following values:
23031
23032@table @code
b383017d 23033@item S_IRUSR
0ce1b118
CV
23034User has read permission.
23035
b383017d 23036@item S_IWUSR
0ce1b118
CV
23037User has write permission.
23038
b383017d 23039@item S_IRGRP
0ce1b118
CV
23040Group has read permission.
23041
b383017d 23042@item S_IWGRP
0ce1b118
CV
23043Group has write permission.
23044
b383017d 23045@item S_IROTH
0ce1b118
CV
23046Others have read permission.
23047
b383017d 23048@item S_IWOTH
0ce1b118
CV
23049Others have write permission.
23050
23051@noindent
23052Each other bit is silently ignored.
23053
23054@end table
23055
23056@smallexample
23057@exdent Return value:
23058open returns the new file descriptor or -1 if an error
23059occured.
23060
23061@exdent Errors:
23062@end smallexample
23063
23064@table @code
b383017d 23065@item EEXIST
0ce1b118
CV
23066pathname already exists and O_CREAT and O_EXCL were used.
23067
b383017d 23068@item EISDIR
0ce1b118
CV
23069pathname refers to a directory.
23070
b383017d 23071@item EACCES
0ce1b118
CV
23072The requested access is not allowed.
23073
23074@item ENAMETOOLONG
23075pathname was too long.
23076
b383017d 23077@item ENOENT
0ce1b118
CV
23078A directory component in pathname does not exist.
23079
b383017d 23080@item ENODEV
0ce1b118
CV
23081pathname refers to a device, pipe, named pipe or socket.
23082
b383017d 23083@item EROFS
0ce1b118
CV
23084pathname refers to a file on a read-only filesystem and
23085write access was requested.
23086
b383017d 23087@item EFAULT
0ce1b118
CV
23088pathname is an invalid pointer value.
23089
b383017d 23090@item ENOSPC
0ce1b118
CV
23091No space on device to create the file.
23092
b383017d 23093@item EMFILE
0ce1b118
CV
23094The process already has the maximum number of files open.
23095
b383017d 23096@item ENFILE
0ce1b118
CV
23097The limit on the total number of files open on the system
23098has been reached.
23099
b383017d 23100@item EINTR
0ce1b118
CV
23101The call was interrupted by the user.
23102@end table
23103
23104@node close
23105@unnumberedsubsubsec close
23106@cindex close, file-i/o system call
23107
23108@smallexample
b383017d 23109@exdent Synopsis:
0ce1b118
CV
23110int close(int fd);
23111
b383017d 23112@exdent Request:
0ce1b118
CV
23113Fclose,fd
23114
23115@exdent Return value:
23116close returns zero on success, or -1 if an error occurred.
23117
23118@exdent Errors:
23119@end smallexample
23120
23121@table @code
b383017d 23122@item EBADF
0ce1b118
CV
23123fd isn't a valid open file descriptor.
23124
b383017d 23125@item EINTR
0ce1b118
CV
23126The call was interrupted by the user.
23127@end table
23128
23129@node read
23130@unnumberedsubsubsec read
23131@cindex read, file-i/o system call
23132
23133@smallexample
b383017d 23134@exdent Synopsis:
0ce1b118
CV
23135int read(int fd, void *buf, unsigned int count);
23136
b383017d 23137@exdent Request:
0ce1b118
CV
23138Fread,fd,bufptr,count
23139
23140@exdent Return value:
23141On success, the number of bytes read is returned.
23142Zero indicates end of file. If count is zero, read
b383017d 23143returns zero as well. On error, -1 is returned.
0ce1b118
CV
23144
23145@exdent Errors:
23146@end smallexample
23147
23148@table @code
b383017d 23149@item EBADF
0ce1b118
CV
23150fd is not a valid file descriptor or is not open for
23151reading.
23152
b383017d 23153@item EFAULT
0ce1b118
CV
23154buf is an invalid pointer value.
23155
b383017d 23156@item EINTR
0ce1b118
CV
23157The call was interrupted by the user.
23158@end table
23159
23160@node write
23161@unnumberedsubsubsec write
23162@cindex write, file-i/o system call
23163
23164@smallexample
b383017d 23165@exdent Synopsis:
0ce1b118
CV
23166int write(int fd, const void *buf, unsigned int count);
23167
b383017d 23168@exdent Request:
0ce1b118
CV
23169Fwrite,fd,bufptr,count
23170
23171@exdent Return value:
23172On success, the number of bytes written are returned.
23173Zero indicates nothing was written. On error, -1
23174is returned.
23175
23176@exdent Errors:
23177@end smallexample
23178
23179@table @code
b383017d 23180@item EBADF
0ce1b118
CV
23181fd is not a valid file descriptor or is not open for
23182writing.
23183
b383017d 23184@item EFAULT
0ce1b118
CV
23185buf is an invalid pointer value.
23186
b383017d 23187@item EFBIG
0ce1b118
CV
23188An attempt was made to write a file that exceeds the
23189host specific maximum file size allowed.
23190
b383017d 23191@item ENOSPC
0ce1b118
CV
23192No space on device to write the data.
23193
b383017d 23194@item EINTR
0ce1b118
CV
23195The call was interrupted by the user.
23196@end table
23197
23198@node lseek
23199@unnumberedsubsubsec lseek
23200@cindex lseek, file-i/o system call
23201
23202@smallexample
b383017d 23203@exdent Synopsis:
0ce1b118
CV
23204long lseek (int fd, long offset, int flag);
23205
b383017d 23206@exdent Request:
0ce1b118
CV
23207Flseek,fd,offset,flag
23208@end smallexample
23209
23210@code{flag} is one of:
23211
23212@table @code
b383017d 23213@item SEEK_SET
0ce1b118
CV
23214The offset is set to offset bytes.
23215
b383017d 23216@item SEEK_CUR
0ce1b118
CV
23217The offset is set to its current location plus offset
23218bytes.
23219
b383017d 23220@item SEEK_END
0ce1b118
CV
23221The offset is set to the size of the file plus offset
23222bytes.
23223@end table
23224
23225@smallexample
23226@exdent Return value:
23227On success, the resulting unsigned offset in bytes from
23228the beginning of the file is returned. Otherwise, a
23229value of -1 is returned.
23230
23231@exdent Errors:
23232@end smallexample
23233
23234@table @code
b383017d 23235@item EBADF
0ce1b118
CV
23236fd is not a valid open file descriptor.
23237
b383017d 23238@item ESPIPE
0ce1b118
CV
23239fd is associated with the @value{GDBN} console.
23240
b383017d 23241@item EINVAL
0ce1b118
CV
23242flag is not a proper value.
23243
b383017d 23244@item EINTR
0ce1b118
CV
23245The call was interrupted by the user.
23246@end table
23247
23248@node rename
23249@unnumberedsubsubsec rename
23250@cindex rename, file-i/o system call
23251
23252@smallexample
b383017d 23253@exdent Synopsis:
0ce1b118
CV
23254int rename(const char *oldpath, const char *newpath);
23255
b383017d 23256@exdent Request:
0ce1b118
CV
23257Frename,oldpathptr/len,newpathptr/len
23258
23259@exdent Return value:
23260On success, zero is returned. On error, -1 is returned.
23261
23262@exdent Errors:
23263@end smallexample
23264
23265@table @code
b383017d 23266@item EISDIR
0ce1b118
CV
23267newpath is an existing directory, but oldpath is not a
23268directory.
23269
b383017d 23270@item EEXIST
0ce1b118
CV
23271newpath is a non-empty directory.
23272
b383017d 23273@item EBUSY
0ce1b118
CV
23274oldpath or newpath is a directory that is in use by some
23275process.
23276
b383017d 23277@item EINVAL
0ce1b118
CV
23278An attempt was made to make a directory a subdirectory
23279of itself.
23280
b383017d 23281@item ENOTDIR
0ce1b118
CV
23282A component used as a directory in oldpath or new
23283path is not a directory. Or oldpath is a directory
23284and newpath exists but is not a directory.
23285
b383017d 23286@item EFAULT
0ce1b118
CV
23287oldpathptr or newpathptr are invalid pointer values.
23288
b383017d 23289@item EACCES
0ce1b118
CV
23290No access to the file or the path of the file.
23291
23292@item ENAMETOOLONG
b383017d 23293
0ce1b118
CV
23294oldpath or newpath was too long.
23295
b383017d 23296@item ENOENT
0ce1b118
CV
23297A directory component in oldpath or newpath does not exist.
23298
b383017d 23299@item EROFS
0ce1b118
CV
23300The file is on a read-only filesystem.
23301
b383017d 23302@item ENOSPC
0ce1b118
CV
23303The device containing the file has no room for the new
23304directory entry.
23305
b383017d 23306@item EINTR
0ce1b118
CV
23307The call was interrupted by the user.
23308@end table
23309
23310@node unlink
23311@unnumberedsubsubsec unlink
23312@cindex unlink, file-i/o system call
23313
23314@smallexample
b383017d 23315@exdent Synopsis:
0ce1b118
CV
23316int unlink(const char *pathname);
23317
b383017d 23318@exdent Request:
0ce1b118
CV
23319Funlink,pathnameptr/len
23320
23321@exdent Return value:
23322On success, zero is returned. On error, -1 is returned.
23323
23324@exdent Errors:
23325@end smallexample
23326
23327@table @code
b383017d 23328@item EACCES
0ce1b118
CV
23329No access to the file or the path of the file.
23330
b383017d 23331@item EPERM
0ce1b118
CV
23332The system does not allow unlinking of directories.
23333
b383017d 23334@item EBUSY
0ce1b118
CV
23335The file pathname cannot be unlinked because it's
23336being used by another process.
23337
b383017d 23338@item EFAULT
0ce1b118
CV
23339pathnameptr is an invalid pointer value.
23340
23341@item ENAMETOOLONG
23342pathname was too long.
23343
b383017d 23344@item ENOENT
0ce1b118
CV
23345A directory component in pathname does not exist.
23346
b383017d 23347@item ENOTDIR
0ce1b118
CV
23348A component of the path is not a directory.
23349
b383017d 23350@item EROFS
0ce1b118
CV
23351The file is on a read-only filesystem.
23352
b383017d 23353@item EINTR
0ce1b118
CV
23354The call was interrupted by the user.
23355@end table
23356
23357@node stat/fstat
23358@unnumberedsubsubsec stat/fstat
23359@cindex fstat, file-i/o system call
23360@cindex stat, file-i/o system call
23361
23362@smallexample
b383017d 23363@exdent Synopsis:
0ce1b118
CV
23364int stat(const char *pathname, struct stat *buf);
23365int fstat(int fd, struct stat *buf);
23366
b383017d 23367@exdent Request:
0ce1b118
CV
23368Fstat,pathnameptr/len,bufptr
23369Ffstat,fd,bufptr
23370
23371@exdent Return value:
23372On success, zero is returned. On error, -1 is returned.
23373
23374@exdent Errors:
23375@end smallexample
23376
23377@table @code
b383017d 23378@item EBADF
0ce1b118
CV
23379fd is not a valid open file.
23380
b383017d 23381@item ENOENT
0ce1b118
CV
23382A directory component in pathname does not exist or the
23383path is an empty string.
23384
b383017d 23385@item ENOTDIR
0ce1b118
CV
23386A component of the path is not a directory.
23387
b383017d 23388@item EFAULT
0ce1b118
CV
23389pathnameptr is an invalid pointer value.
23390
b383017d 23391@item EACCES
0ce1b118
CV
23392No access to the file or the path of the file.
23393
23394@item ENAMETOOLONG
23395pathname was too long.
23396
b383017d 23397@item EINTR
0ce1b118
CV
23398The call was interrupted by the user.
23399@end table
23400
23401@node gettimeofday
23402@unnumberedsubsubsec gettimeofday
23403@cindex gettimeofday, file-i/o system call
23404
23405@smallexample
b383017d 23406@exdent Synopsis:
0ce1b118
CV
23407int gettimeofday(struct timeval *tv, void *tz);
23408
b383017d 23409@exdent Request:
0ce1b118
CV
23410Fgettimeofday,tvptr,tzptr
23411
23412@exdent Return value:
23413On success, 0 is returned, -1 otherwise.
23414
23415@exdent Errors:
23416@end smallexample
23417
23418@table @code
b383017d 23419@item EINVAL
0ce1b118
CV
23420tz is a non-NULL pointer.
23421
b383017d 23422@item EFAULT
0ce1b118
CV
23423tvptr and/or tzptr is an invalid pointer value.
23424@end table
23425
23426@node isatty
23427@unnumberedsubsubsec isatty
23428@cindex isatty, file-i/o system call
23429
23430@smallexample
b383017d 23431@exdent Synopsis:
0ce1b118
CV
23432int isatty(int fd);
23433
b383017d 23434@exdent Request:
0ce1b118
CV
23435Fisatty,fd
23436
23437@exdent Return value:
23438Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23439
23440@exdent Errors:
23441@end smallexample
23442
23443@table @code
b383017d 23444@item EINTR
0ce1b118
CV
23445The call was interrupted by the user.
23446@end table
23447
23448@node system
23449@unnumberedsubsubsec system
23450@cindex system, file-i/o system call
23451
23452@smallexample
b383017d 23453@exdent Synopsis:
0ce1b118
CV
23454int system(const char *command);
23455
b383017d 23456@exdent Request:
0ce1b118
CV
23457Fsystem,commandptr/len
23458
23459@exdent Return value:
23460The value returned is -1 on error and the return status
23461of the command otherwise. Only the exit status of the
23462command is returned, which is extracted from the hosts
23463system return value by calling WEXITSTATUS(retval).
23464In case /bin/sh could not be executed, 127 is returned.
23465
23466@exdent Errors:
23467@end smallexample
23468
23469@table @code
b383017d 23470@item EINTR
0ce1b118
CV
23471The call was interrupted by the user.
23472@end table
23473
23474@node Protocol specific representation of datatypes
23475@subsection Protocol specific representation of datatypes
23476@cindex protocol specific representation of datatypes, in file-i/o protocol
23477
23478@menu
23479* Integral datatypes::
23480* Pointer values::
23481* struct stat::
23482* struct timeval::
23483@end menu
23484
23485@node Integral datatypes
23486@unnumberedsubsubsec Integral datatypes
23487@cindex integral datatypes, in file-i/o protocol
23488
23489The integral datatypes used in the system calls are
23490
23491@smallexample
23492int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23493@end smallexample
23494
23495@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23496implemented as 32 bit values in this protocol.
23497
b383017d
RM
23498@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23499
0ce1b118
CV
23500@xref{Limits}, for corresponding MIN and MAX values (similar to those
23501in @file{limits.h}) to allow range checking on host and target.
23502
23503@code{time_t} datatypes are defined as seconds since the Epoch.
23504
23505All integral datatypes transferred as part of a memory read or write of a
23506structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23507byte order.
23508
23509@node Pointer values
23510@unnumberedsubsubsec Pointer values
23511@cindex pointer values, in file-i/o protocol
23512
23513Pointers to target data are transmitted as they are. An exception
23514is made for pointers to buffers for which the length isn't
23515transmitted as part of the function call, namely strings. Strings
23516are transmitted as a pointer/length pair, both as hex values, e.g.@:
23517
23518@smallexample
23519@code{1aaf/12}
23520@end smallexample
23521
23522@noindent
23523which is a pointer to data of length 18 bytes at position 0x1aaf.
23524The length is defined as the full string length in bytes, including
23525the trailing null byte. Example:
23526
23527@smallexample
23528``hello, world'' at address 0x123456
23529@end smallexample
23530
23531@noindent
23532is transmitted as
23533
23534@smallexample
23535@code{123456/d}
23536@end smallexample
23537
23538@node struct stat
23539@unnumberedsubsubsec struct stat
23540@cindex struct stat, in file-i/o protocol
23541
23542The buffer of type struct stat used by the target and @value{GDBN} is defined
23543as follows:
23544
23545@smallexample
23546struct stat @{
23547 unsigned int st_dev; /* device */
23548 unsigned int st_ino; /* inode */
23549 mode_t st_mode; /* protection */
23550 unsigned int st_nlink; /* number of hard links */
23551 unsigned int st_uid; /* user ID of owner */
23552 unsigned int st_gid; /* group ID of owner */
23553 unsigned int st_rdev; /* device type (if inode device) */
23554 unsigned long st_size; /* total size, in bytes */
23555 unsigned long st_blksize; /* blocksize for filesystem I/O */
23556 unsigned long st_blocks; /* number of blocks allocated */
23557 time_t st_atime; /* time of last access */
23558 time_t st_mtime; /* time of last modification */
23559 time_t st_ctime; /* time of last change */
23560@};
23561@end smallexample
23562
23563The integral datatypes are conforming to the definitions given in the
23564approriate section (see @ref{Integral datatypes}, for details) so this
23565structure is of size 64 bytes.
23566
23567The values of several fields have a restricted meaning and/or
23568range of values.
23569
23570@smallexample
23571st_dev: 0 file
23572 1 console
23573
23574st_ino: No valid meaning for the target. Transmitted unchanged.
23575
23576st_mode: Valid mode bits are described in Appendix C. Any other
23577 bits have currently no meaning for the target.
23578
23579st_uid: No valid meaning for the target. Transmitted unchanged.
23580
23581st_gid: No valid meaning for the target. Transmitted unchanged.
23582
23583st_rdev: No valid meaning for the target. Transmitted unchanged.
23584
23585st_atime, st_mtime, st_ctime:
23586 These values have a host and file system dependent
23587 accuracy. Especially on Windows hosts the file systems
23588 don't support exact timing values.
23589@end smallexample
23590
23591The target gets a struct stat of the above representation and is
23592responsible to coerce it to the target representation before
23593continuing.
23594
23595Note that due to size differences between the host and target
23596representation of stat members, these members could eventually
23597get truncated on the target.
23598
23599@node struct timeval
23600@unnumberedsubsubsec struct timeval
23601@cindex struct timeval, in file-i/o protocol
23602
23603The buffer of type struct timeval used by the target and @value{GDBN}
23604is defined as follows:
23605
23606@smallexample
b383017d 23607struct timeval @{
0ce1b118
CV
23608 time_t tv_sec; /* second */
23609 long tv_usec; /* microsecond */
23610@};
23611@end smallexample
23612
23613The integral datatypes are conforming to the definitions given in the
23614approriate section (see @ref{Integral datatypes}, for details) so this
23615structure is of size 8 bytes.
23616
23617@node Constants
23618@subsection Constants
23619@cindex constants, in file-i/o protocol
23620
23621The following values are used for the constants inside of the
23622protocol. @value{GDBN} and target are resposible to translate these
23623values before and after the call as needed.
23624
23625@menu
23626* Open flags::
23627* mode_t values::
23628* Errno values::
23629* Lseek flags::
23630* Limits::
23631@end menu
23632
23633@node Open flags
23634@unnumberedsubsubsec Open flags
23635@cindex open flags, in file-i/o protocol
23636
23637All values are given in hexadecimal representation.
23638
23639@smallexample
23640 O_RDONLY 0x0
23641 O_WRONLY 0x1
23642 O_RDWR 0x2
23643 O_APPEND 0x8
23644 O_CREAT 0x200
23645 O_TRUNC 0x400
23646 O_EXCL 0x800
23647@end smallexample
23648
23649@node mode_t values
23650@unnumberedsubsubsec mode_t values
23651@cindex mode_t values, in file-i/o protocol
23652
23653All values are given in octal representation.
23654
23655@smallexample
23656 S_IFREG 0100000
23657 S_IFDIR 040000
23658 S_IRUSR 0400
23659 S_IWUSR 0200
23660 S_IXUSR 0100
23661 S_IRGRP 040
23662 S_IWGRP 020
23663 S_IXGRP 010
23664 S_IROTH 04
23665 S_IWOTH 02
23666 S_IXOTH 01
23667@end smallexample
23668
23669@node Errno values
23670@unnumberedsubsubsec Errno values
23671@cindex errno values, in file-i/o protocol
23672
23673All values are given in decimal representation.
23674
23675@smallexample
23676 EPERM 1
23677 ENOENT 2
23678 EINTR 4
23679 EBADF 9
23680 EACCES 13
23681 EFAULT 14
23682 EBUSY 16
23683 EEXIST 17
23684 ENODEV 19
23685 ENOTDIR 20
23686 EISDIR 21
23687 EINVAL 22
23688 ENFILE 23
23689 EMFILE 24
23690 EFBIG 27
23691 ENOSPC 28
23692 ESPIPE 29
23693 EROFS 30
23694 ENAMETOOLONG 91
23695 EUNKNOWN 9999
23696@end smallexample
23697
23698 EUNKNOWN is used as a fallback error value if a host system returns
23699 any error value not in the list of supported error numbers.
23700
23701@node Lseek flags
23702@unnumberedsubsubsec Lseek flags
23703@cindex lseek flags, in file-i/o protocol
23704
23705@smallexample
23706 SEEK_SET 0
23707 SEEK_CUR 1
23708 SEEK_END 2
23709@end smallexample
23710
23711@node Limits
23712@unnumberedsubsubsec Limits
23713@cindex limits, in file-i/o protocol
23714
23715All values are given in decimal representation.
23716
23717@smallexample
23718 INT_MIN -2147483648
23719 INT_MAX 2147483647
23720 UINT_MAX 4294967295
23721 LONG_MIN -9223372036854775808
23722 LONG_MAX 9223372036854775807
23723 ULONG_MAX 18446744073709551615
23724@end smallexample
23725
23726@node File-I/O Examples
23727@subsection File-I/O Examples
23728@cindex file-i/o examples
23729
23730Example sequence of a write call, file descriptor 3, buffer is at target
23731address 0x1234, 6 bytes should be written:
23732
23733@smallexample
23734<- @code{Fwrite,3,1234,6}
23735@emph{request memory read from target}
23736-> @code{m1234,6}
23737<- XXXXXX
23738@emph{return "6 bytes written"}
23739-> @code{F6}
23740@end smallexample
23741
23742Example sequence of a read call, file descriptor 3, buffer is at target
23743address 0x1234, 6 bytes should be read:
23744
23745@smallexample
23746<- @code{Fread,3,1234,6}
23747@emph{request memory write to target}
23748-> @code{X1234,6:XXXXXX}
23749@emph{return "6 bytes read"}
23750-> @code{F6}
23751@end smallexample
23752
23753Example sequence of a read call, call fails on the host due to invalid
23754file descriptor (EBADF):
23755
23756@smallexample
23757<- @code{Fread,3,1234,6}
23758-> @code{F-1,9}
23759@end smallexample
23760
23761Example sequence of a read call, user presses Ctrl-C before syscall on
23762host is called:
23763
23764@smallexample
23765<- @code{Fread,3,1234,6}
23766-> @code{F-1,4,C}
23767<- @code{T02}
23768@end smallexample
23769
23770Example sequence of a read call, user presses Ctrl-C after syscall on
23771host is called:
23772
23773@smallexample
23774<- @code{Fread,3,1234,6}
23775-> @code{X1234,6:XXXXXX}
23776<- @code{T02}
23777@end smallexample
23778
f418dd93
DJ
23779@include agentexpr.texi
23780
aab4e0ec 23781@include gpl.texi
eb12ee30 23782
2154891a 23783@raisesections
6826cf00 23784@include fdl.texi
2154891a 23785@lowersections
6826cf00 23786
6d2ebf8b 23787@node Index
c906108c
SS
23788@unnumbered Index
23789
23790@printindex cp
23791
23792@tex
23793% I think something like @colophon should be in texinfo. In the
23794% meantime:
23795\long\def\colophon{\hbox to0pt{}\vfill
23796\centerline{The body of this manual is set in}
23797\centerline{\fontname\tenrm,}
23798\centerline{with headings in {\bf\fontname\tenbf}}
23799\centerline{and examples in {\tt\fontname\tentt}.}
23800\centerline{{\it\fontname\tenit\/},}
23801\centerline{{\bf\fontname\tenbf}, and}
23802\centerline{{\sl\fontname\tensl\/}}
23803\centerline{are used for emphasis.}\vfill}
23804\page\colophon
23805% Blame: doc@cygnus.com, 1991.
23806@end tex
23807
c906108c 23808@bye
This page took 2.328326 seconds and 4 git commands to generate.