missed committing from
[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
ffed4509
AC
474Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
475Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
476
e2e0bcd1
JB
477Jim Blandy added support for preprocessor macros, while working for Red
478Hat.
c906108c 479
6d2ebf8b 480@node Sample Session
c906108c
SS
481@chapter A Sample @value{GDBN} Session
482
483You can use this manual at your leisure to read all about @value{GDBN}.
484However, a handful of commands are enough to get started using the
485debugger. This chapter illustrates those commands.
486
487@iftex
488In this sample session, we emphasize user input like this: @b{input},
489to make it easier to pick out from the surrounding output.
490@end iftex
491
492@c FIXME: this example may not be appropriate for some configs, where
493@c FIXME...primary interest is in remote use.
494
495One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
496processor) exhibits the following bug: sometimes, when we change its
497quote strings from the default, the commands used to capture one macro
498definition within another stop working. In the following short @code{m4}
499session, we define a macro @code{foo} which expands to @code{0000}; we
500then use the @code{m4} built-in @code{defn} to define @code{bar} as the
501same thing. However, when we change the open quote string to
502@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
503procedure fails to define a new synonym @code{baz}:
504
505@smallexample
506$ @b{cd gnu/m4}
507$ @b{./m4}
508@b{define(foo,0000)}
509
510@b{foo}
5110000
512@b{define(bar,defn(`foo'))}
513
514@b{bar}
5150000
516@b{changequote(<QUOTE>,<UNQUOTE>)}
517
518@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
519@b{baz}
520@b{C-d}
521m4: End of input: 0: fatal error: EOF in string
522@end smallexample
523
524@noindent
525Let us use @value{GDBN} to try to see what is going on.
526
c906108c
SS
527@smallexample
528$ @b{@value{GDBP} m4}
529@c FIXME: this falsifies the exact text played out, to permit smallbook
530@c FIXME... format to come out better.
531@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 532 of it under certain conditions; type "show copying" to see
c906108c 533 the conditions.
5d161b24 534There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
535 for details.
536
537@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
538(@value{GDBP})
539@end smallexample
c906108c
SS
540
541@noindent
542@value{GDBN} reads only enough symbol data to know where to find the
543rest when needed; as a result, the first prompt comes up very quickly.
544We now tell @value{GDBN} to use a narrower display width than usual, so
545that examples fit in this manual.
546
547@smallexample
548(@value{GDBP}) @b{set width 70}
549@end smallexample
550
551@noindent
552We need to see how the @code{m4} built-in @code{changequote} works.
553Having looked at the source, we know the relevant subroutine is
554@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
555@code{break} command.
556
557@smallexample
558(@value{GDBP}) @b{break m4_changequote}
559Breakpoint 1 at 0x62f4: file builtin.c, line 879.
560@end smallexample
561
562@noindent
563Using the @code{run} command, we start @code{m4} running under @value{GDBN}
564control; as long as control does not reach the @code{m4_changequote}
565subroutine, the program runs as usual:
566
567@smallexample
568(@value{GDBP}) @b{run}
569Starting program: /work/Editorial/gdb/gnu/m4/m4
570@b{define(foo,0000)}
571
572@b{foo}
5730000
574@end smallexample
575
576@noindent
577To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
578suspends execution of @code{m4}, displaying information about the
579context where it stops.
580
581@smallexample
582@b{changequote(<QUOTE>,<UNQUOTE>)}
583
5d161b24 584Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
585 at builtin.c:879
586879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
587@end smallexample
588
589@noindent
590Now we use the command @code{n} (@code{next}) to advance execution to
591the next line of the current function.
592
593@smallexample
594(@value{GDBP}) @b{n}
595882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
596 : nil,
597@end smallexample
598
599@noindent
600@code{set_quotes} looks like a promising subroutine. We can go into it
601by using the command @code{s} (@code{step}) instead of @code{next}.
602@code{step} goes to the next line to be executed in @emph{any}
603subroutine, so it steps into @code{set_quotes}.
604
605@smallexample
606(@value{GDBP}) @b{s}
607set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
608 at input.c:530
609530 if (lquote != def_lquote)
610@end smallexample
611
612@noindent
613The display that shows the subroutine where @code{m4} is now
614suspended (and its arguments) is called a stack frame display. It
615shows a summary of the stack. We can use the @code{backtrace}
616command (which can also be spelled @code{bt}), to see where we are
617in the stack as a whole: the @code{backtrace} command displays a
618stack frame for each active subroutine.
619
620@smallexample
621(@value{GDBP}) @b{bt}
622#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
623 at input.c:530
5d161b24 624#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
625 at builtin.c:882
626#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
627#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
628 at macro.c:71
629#4 0x79dc in expand_input () at macro.c:40
630#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
631@end smallexample
632
633@noindent
634We step through a few more lines to see what happens. The first two
635times, we can use @samp{s}; the next two times we use @code{n} to avoid
636falling into the @code{xstrdup} subroutine.
637
638@smallexample
639(@value{GDBP}) @b{s}
6400x3b5c 532 if (rquote != def_rquote)
641(@value{GDBP}) @b{s}
6420x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
643def_lquote : xstrdup(lq);
644(@value{GDBP}) @b{n}
645536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
646 : xstrdup(rq);
647(@value{GDBP}) @b{n}
648538 len_lquote = strlen(rquote);
649@end smallexample
650
651@noindent
652The last line displayed looks a little odd; we can examine the variables
653@code{lquote} and @code{rquote} to see if they are in fact the new left
654and right quotes we specified. We use the command @code{p}
655(@code{print}) to see their values.
656
657@smallexample
658(@value{GDBP}) @b{p lquote}
659$1 = 0x35d40 "<QUOTE>"
660(@value{GDBP}) @b{p rquote}
661$2 = 0x35d50 "<UNQUOTE>"
662@end smallexample
663
664@noindent
665@code{lquote} and @code{rquote} are indeed the new left and right quotes.
666To look at some context, we can display ten lines of source
667surrounding the current line with the @code{l} (@code{list}) command.
668
669@smallexample
670(@value{GDBP}) @b{l}
671533 xfree(rquote);
672534
673535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
674 : xstrdup (lq);
675536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
676 : xstrdup (rq);
677537
678538 len_lquote = strlen(rquote);
679539 len_rquote = strlen(lquote);
680540 @}
681541
682542 void
683@end smallexample
684
685@noindent
686Let us step past the two lines that set @code{len_lquote} and
687@code{len_rquote}, and then examine the values of those variables.
688
689@smallexample
690(@value{GDBP}) @b{n}
691539 len_rquote = strlen(lquote);
692(@value{GDBP}) @b{n}
693540 @}
694(@value{GDBP}) @b{p len_lquote}
695$3 = 9
696(@value{GDBP}) @b{p len_rquote}
697$4 = 7
698@end smallexample
699
700@noindent
701That certainly looks wrong, assuming @code{len_lquote} and
702@code{len_rquote} are meant to be the lengths of @code{lquote} and
703@code{rquote} respectively. We can set them to better values using
704the @code{p} command, since it can print the value of
705any expression---and that expression can include subroutine calls and
706assignments.
707
708@smallexample
709(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
710$5 = 7
711(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
712$6 = 9
713@end smallexample
714
715@noindent
716Is that enough to fix the problem of using the new quotes with the
717@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
718executing with the @code{c} (@code{continue}) command, and then try the
719example that caused trouble initially:
720
721@smallexample
722(@value{GDBP}) @b{c}
723Continuing.
724
725@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
726
727baz
7280000
729@end smallexample
730
731@noindent
732Success! The new quotes now work just as well as the default ones. The
733problem seems to have been just the two typos defining the wrong
734lengths. We allow @code{m4} exit by giving it an EOF as input:
735
736@smallexample
737@b{C-d}
738Program exited normally.
739@end smallexample
740
741@noindent
742The message @samp{Program exited normally.} is from @value{GDBN}; it
743indicates @code{m4} has finished executing. We can end our @value{GDBN}
744session with the @value{GDBN} @code{quit} command.
745
746@smallexample
747(@value{GDBP}) @b{quit}
748@end smallexample
c906108c 749
6d2ebf8b 750@node Invocation
c906108c
SS
751@chapter Getting In and Out of @value{GDBN}
752
753This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 754The essentials are:
c906108c 755@itemize @bullet
5d161b24 756@item
53a5351d 757type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 758@item
c906108c
SS
759type @kbd{quit} or @kbd{C-d} to exit.
760@end itemize
761
762@menu
763* Invoking GDB:: How to start @value{GDBN}
764* Quitting GDB:: How to quit @value{GDBN}
765* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 766* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
767@end menu
768
6d2ebf8b 769@node Invoking GDB
c906108c
SS
770@section Invoking @value{GDBN}
771
c906108c
SS
772Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
773@value{GDBN} reads commands from the terminal until you tell it to exit.
774
775You can also run @code{@value{GDBP}} with a variety of arguments and options,
776to specify more of your debugging environment at the outset.
777
c906108c
SS
778The command-line options described here are designed
779to cover a variety of situations; in some environments, some of these
5d161b24 780options may effectively be unavailable.
c906108c
SS
781
782The most usual way to start @value{GDBN} is with one argument,
783specifying an executable program:
784
474c8240 785@smallexample
c906108c 786@value{GDBP} @var{program}
474c8240 787@end smallexample
c906108c 788
c906108c
SS
789@noindent
790You can also start with both an executable program and a core file
791specified:
792
474c8240 793@smallexample
c906108c 794@value{GDBP} @var{program} @var{core}
474c8240 795@end smallexample
c906108c
SS
796
797You can, instead, specify a process ID as a second argument, if you want
798to debug a running process:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} 1234
474c8240 802@end smallexample
c906108c
SS
803
804@noindent
805would attach @value{GDBN} to process @code{1234} (unless you also have a file
806named @file{1234}; @value{GDBN} does check for a core file first).
807
c906108c 808Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
809complete operating system; when you use @value{GDBN} as a remote
810debugger attached to a bare board, there may not be any notion of
811``process'', and there is often no way to get a core dump. @value{GDBN}
812will warn you if it is unable to attach or to read core dumps.
c906108c 813
aa26fa3a
TT
814You can optionally have @code{@value{GDBP}} pass any arguments after the
815executable file to the inferior using @code{--args}. This option stops
816option processing.
474c8240 817@smallexample
aa26fa3a 818gdb --args gcc -O2 -c foo.c
474c8240 819@end smallexample
aa26fa3a
TT
820This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
821@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
822
96a2c332 823You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
824@value{GDBN}'s non-warranty, by specifying @code{-silent}:
825
826@smallexample
827@value{GDBP} -silent
828@end smallexample
829
830@noindent
831You can further control how @value{GDBN} starts up by using command-line
832options. @value{GDBN} itself can remind you of the options available.
833
834@noindent
835Type
836
474c8240 837@smallexample
c906108c 838@value{GDBP} -help
474c8240 839@end smallexample
c906108c
SS
840
841@noindent
842to display all available options and briefly describe their use
843(@samp{@value{GDBP} -h} is a shorter equivalent).
844
845All options and command line arguments you give are processed
846in sequential order. The order makes a difference when the
847@samp{-x} option is used.
848
849
850@menu
c906108c
SS
851* File Options:: Choosing files
852* Mode Options:: Choosing modes
6fc08d32 853* Startup:: What @value{GDBN} does during startup
c906108c
SS
854@end menu
855
6d2ebf8b 856@node File Options
c906108c
SS
857@subsection Choosing files
858
2df3850c 859When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
860specifying an executable file and core file (or process ID). This is
861the same as if the arguments were specified by the @samp{-se} and
19837790
MS
862@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
863first argument that does not have an associated option flag as
864equivalent to the @samp{-se} option followed by that argument; and the
865second argument that does not have an associated option flag, if any, as
866equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
867If the second argument begins with a decimal digit, @value{GDBN} will
868first attempt to attach to it as a process, and if that fails, attempt
869to open it as a corefile. If you have a corefile whose name begins with
b383017d 870a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 871prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
872
873If @value{GDBN} has not been configured to included core file support,
874such as for most embedded targets, then it will complain about a second
875argument and ignore it.
c906108c
SS
876
877Many options have both long and short forms; both are shown in the
878following list. @value{GDBN} also recognizes the long forms if you truncate
879them, so long as enough of the option is present to be unambiguous.
880(If you prefer, you can flag option arguments with @samp{--} rather
881than @samp{-}, though we illustrate the more usual convention.)
882
d700128c
EZ
883@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
884@c way, both those who look for -foo and --foo in the index, will find
885@c it.
886
c906108c
SS
887@table @code
888@item -symbols @var{file}
889@itemx -s @var{file}
d700128c
EZ
890@cindex @code{--symbols}
891@cindex @code{-s}
c906108c
SS
892Read symbol table from file @var{file}.
893
894@item -exec @var{file}
895@itemx -e @var{file}
d700128c
EZ
896@cindex @code{--exec}
897@cindex @code{-e}
7a292a7a
SS
898Use file @var{file} as the executable file to execute when appropriate,
899and for examining pure data in conjunction with a core dump.
c906108c
SS
900
901@item -se @var{file}
d700128c 902@cindex @code{--se}
c906108c
SS
903Read symbol table from file @var{file} and use it as the executable
904file.
905
c906108c
SS
906@item -core @var{file}
907@itemx -c @var{file}
d700128c
EZ
908@cindex @code{--core}
909@cindex @code{-c}
b383017d 910Use file @var{file} as a core dump to examine.
c906108c
SS
911
912@item -c @var{number}
19837790
MS
913@item -pid @var{number}
914@itemx -p @var{number}
915@cindex @code{--pid}
916@cindex @code{-p}
917Connect to process ID @var{number}, as with the @code{attach} command.
918If there is no such process, @value{GDBN} will attempt to open a core
919file named @var{number}.
c906108c
SS
920
921@item -command @var{file}
922@itemx -x @var{file}
d700128c
EZ
923@cindex @code{--command}
924@cindex @code{-x}
c906108c
SS
925Execute @value{GDBN} commands from file @var{file}. @xref{Command
926Files,, Command files}.
927
928@item -directory @var{directory}
929@itemx -d @var{directory}
d700128c
EZ
930@cindex @code{--directory}
931@cindex @code{-d}
c906108c
SS
932Add @var{directory} to the path to search for source files.
933
c906108c
SS
934@item -m
935@itemx -mapped
d700128c
EZ
936@cindex @code{--mapped}
937@cindex @code{-m}
c906108c
SS
938@emph{Warning: this option depends on operating system facilities that are not
939supported on all systems.}@*
940If memory-mapped files are available on your system through the @code{mmap}
5d161b24 941system call, you can use this option
c906108c
SS
942to have @value{GDBN} write the symbols from your
943program into a reusable file in the current directory. If the program you are debugging is
96a2c332 944called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
945Future @value{GDBN} debugging sessions notice the presence of this file,
946and can quickly map in symbol information from it, rather than reading
947the symbol table from the executable program.
948
949The @file{.syms} file is specific to the host machine where @value{GDBN}
950is run. It holds an exact image of the internal @value{GDBN} symbol
951table. It cannot be shared across multiple host platforms.
c906108c 952
c906108c
SS
953@item -r
954@itemx -readnow
d700128c
EZ
955@cindex @code{--readnow}
956@cindex @code{-r}
c906108c
SS
957Read each symbol file's entire symbol table immediately, rather than
958the default, which is to read it incrementally as it is needed.
959This makes startup slower, but makes future operations faster.
53a5351d 960
c906108c
SS
961@end table
962
2df3850c 963You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 964order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
965information. (@xref{Files,,Commands to specify files}, for information
966on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
967but build a @file{.syms} file for future use is:
c906108c 968
474c8240 969@smallexample
2df3850c 970gdb -batch -nx -mapped -readnow programname
474c8240 971@end smallexample
c906108c 972
6d2ebf8b 973@node Mode Options
c906108c
SS
974@subsection Choosing modes
975
976You can run @value{GDBN} in various alternative modes---for example, in
977batch mode or quiet mode.
978
979@table @code
980@item -nx
981@itemx -n
d700128c
EZ
982@cindex @code{--nx}
983@cindex @code{-n}
96565e91 984Do not execute commands found in any initialization files. Normally,
2df3850c
JM
985@value{GDBN} executes the commands in these files after all the command
986options and arguments have been processed. @xref{Command Files,,Command
987files}.
c906108c
SS
988
989@item -quiet
d700128c 990@itemx -silent
c906108c 991@itemx -q
d700128c
EZ
992@cindex @code{--quiet}
993@cindex @code{--silent}
994@cindex @code{-q}
c906108c
SS
995``Quiet''. Do not print the introductory and copyright messages. These
996messages are also suppressed in batch mode.
997
998@item -batch
d700128c 999@cindex @code{--batch}
c906108c
SS
1000Run in batch mode. Exit with status @code{0} after processing all the
1001command files specified with @samp{-x} (and all commands from
1002initialization files, if not inhibited with @samp{-n}). Exit with
1003nonzero status if an error occurs in executing the @value{GDBN} commands
1004in the command files.
1005
2df3850c
JM
1006Batch mode may be useful for running @value{GDBN} as a filter, for
1007example to download and run a program on another computer; in order to
1008make this more useful, the message
c906108c 1009
474c8240 1010@smallexample
c906108c 1011Program exited normally.
474c8240 1012@end smallexample
c906108c
SS
1013
1014@noindent
2df3850c
JM
1015(which is ordinarily issued whenever a program running under
1016@value{GDBN} control terminates) is not issued when running in batch
1017mode.
1018
1019@item -nowindows
1020@itemx -nw
d700128c
EZ
1021@cindex @code{--nowindows}
1022@cindex @code{-nw}
2df3850c 1023``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1024(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1025interface. If no GUI is available, this option has no effect.
1026
1027@item -windows
1028@itemx -w
d700128c
EZ
1029@cindex @code{--windows}
1030@cindex @code{-w}
2df3850c
JM
1031If @value{GDBN} includes a GUI, then this option requires it to be
1032used if possible.
c906108c
SS
1033
1034@item -cd @var{directory}
d700128c 1035@cindex @code{--cd}
c906108c
SS
1036Run @value{GDBN} using @var{directory} as its working directory,
1037instead of the current directory.
1038
c906108c
SS
1039@item -fullname
1040@itemx -f
d700128c
EZ
1041@cindex @code{--fullname}
1042@cindex @code{-f}
7a292a7a
SS
1043@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1044subprocess. It tells @value{GDBN} to output the full file name and line
1045number in a standard, recognizable fashion each time a stack frame is
1046displayed (which includes each time your program stops). This
1047recognizable format looks like two @samp{\032} characters, followed by
1048the file name, line number and character position separated by colons,
1049and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1050@samp{\032} characters as a signal to display the source code for the
1051frame.
c906108c 1052
d700128c
EZ
1053@item -epoch
1054@cindex @code{--epoch}
1055The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1056@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1057routines so as to allow Epoch to display values of expressions in a
1058separate window.
1059
1060@item -annotate @var{level}
1061@cindex @code{--annotate}
1062This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1063effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1064(@pxref{Annotations}). The annotation @var{level} controls how much
1065information @value{GDBN} prints together with its prompt, values of
1066expressions, source lines, and other types of output. Level 0 is the
1067normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1068@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1069that control @value{GDBN}, and level 2 has been deprecated.
1070
1071The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1072(@pxref{GDB/MI}).
d700128c 1073
aa26fa3a
TT
1074@item --args
1075@cindex @code{--args}
1076Change interpretation of command line so that arguments following the
1077executable file are passed as command line arguments to the inferior.
1078This option stops option processing.
1079
2df3850c
JM
1080@item -baud @var{bps}
1081@itemx -b @var{bps}
d700128c
EZ
1082@cindex @code{--baud}
1083@cindex @code{-b}
c906108c
SS
1084Set the line speed (baud rate or bits per second) of any serial
1085interface used by @value{GDBN} for remote debugging.
c906108c 1086
f47b1503
AS
1087@item -l @var{timeout}
1088@cindex @code{-l}
1089Set the timeout (in seconds) of any communication used by @value{GDBN}
1090for remote debugging.
1091
c906108c 1092@item -tty @var{device}
d700128c
EZ
1093@itemx -t @var{device}
1094@cindex @code{--tty}
1095@cindex @code{-t}
c906108c
SS
1096Run using @var{device} for your program's standard input and output.
1097@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1098
53a5351d 1099@c resolve the situation of these eventually
c4555f82
SC
1100@item -tui
1101@cindex @code{--tui}
d0d5df6f
AC
1102Activate the @dfn{Text User Interface} when starting. The Text User
1103Interface manages several text windows on the terminal, showing
1104source, assembly, registers and @value{GDBN} command outputs
1105(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1106Text User Interface can be enabled by invoking the program
1107@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1108Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1109
1110@c @item -xdb
d700128c 1111@c @cindex @code{--xdb}
53a5351d
JM
1112@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1113@c For information, see the file @file{xdb_trans.html}, which is usually
1114@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1115@c systems.
1116
d700128c
EZ
1117@item -interpreter @var{interp}
1118@cindex @code{--interpreter}
1119Use the interpreter @var{interp} for interface with the controlling
1120program or device. This option is meant to be set by programs which
94bbb2c0 1121communicate with @value{GDBN} using it as a back end.
21c294e6 1122@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1123
da0f9dcd 1124@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1125@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1126The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1127previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1128selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1129@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1130
1131@item -write
1132@cindex @code{--write}
1133Open the executable and core files for both reading and writing. This
1134is equivalent to the @samp{set write on} command inside @value{GDBN}
1135(@pxref{Patching}).
1136
1137@item -statistics
1138@cindex @code{--statistics}
1139This option causes @value{GDBN} to print statistics about time and
1140memory usage after it completes each command and returns to the prompt.
1141
1142@item -version
1143@cindex @code{--version}
1144This option causes @value{GDBN} to print its version number and
1145no-warranty blurb, and exit.
1146
c906108c
SS
1147@end table
1148
6fc08d32
EZ
1149@node Startup
1150@subsection What @value{GDBN} does during startup
1151@cindex @value{GDBN} startup
1152
1153Here's the description of what @value{GDBN} does during session startup:
1154
1155@enumerate
1156@item
1157Sets up the command interpreter as specified by the command line
1158(@pxref{Mode Options, interpreter}).
1159
1160@item
1161@cindex init file
1162Reads the @dfn{init file} (if any) in your home directory@footnote{On
1163DOS/Windows systems, the home directory is the one pointed to by the
1164@code{HOME} environment variable.} and executes all the commands in
1165that file.
1166
1167@item
1168Processes command line options and operands.
1169
1170@item
1171Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1172working directory. This is only done if the current directory is
1173different from your home directory. Thus, you can have more than one
1174init file, one generic in your home directory, and another, specific
1175to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1176@value{GDBN}.
1177
1178@item
1179Reads command files specified by the @samp{-x} option. @xref{Command
1180Files}, for more details about @value{GDBN} command files.
1181
1182@item
1183Reads the command history recorded in the @dfn{history file}.
1184@xref{History}, for more details about the command history and the
1185files where @value{GDBN} records it.
1186@end enumerate
1187
1188Init files use the same syntax as @dfn{command files} (@pxref{Command
1189Files}) and are processed by @value{GDBN} in the same way. The init
1190file in your home directory can set options (such as @samp{set
1191complaints}) that affect subsequent processing of command line options
1192and operands. Init files are not executed if you use the @samp{-nx}
1193option (@pxref{Mode Options, ,Choosing modes}).
1194
1195@cindex init file name
1196@cindex @file{.gdbinit}
119b882a 1197The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1198On some configurations of @value{GDBN}, the init file is known by a
1199different name (these are typically environments where a specialized
1200form of @value{GDBN} may need to coexist with other forms, hence a
1201different name for the specialized version's init file). These are the
1202environments with special init file names:
1203
6fc08d32 1204@itemize @bullet
119b882a
EZ
1205@cindex @file{gdb.ini}
1206@item
1207The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1208the limitations of file names imposed by DOS filesystems. The Windows
1209ports of @value{GDBN} use the standard name, but if they find a
1210@file{gdb.ini} file, they warn you about that and suggest to rename
1211the file to the standard name.
1212
1213@cindex @file{.vxgdbinit}
6fc08d32
EZ
1214@item
1215VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1216
1217@cindex @file{.os68gdbinit}
1218@item
1219OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1220
1221@cindex @file{.esgdbinit}
1222@item
1223ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1224
1225@item
1226CISCO 68k: @file{.cisco-gdbinit}
1227@end itemize
1228
1229
6d2ebf8b 1230@node Quitting GDB
c906108c
SS
1231@section Quitting @value{GDBN}
1232@cindex exiting @value{GDBN}
1233@cindex leaving @value{GDBN}
1234
1235@table @code
1236@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1237@kindex q @r{(@code{quit})}
96a2c332
SS
1238@item quit @r{[}@var{expression}@r{]}
1239@itemx q
1240To exit @value{GDBN}, use the @code{quit} command (abbreviated
1241@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1242do not supply @var{expression}, @value{GDBN} will terminate normally;
1243otherwise it will terminate using the result of @var{expression} as the
1244error code.
c906108c
SS
1245@end table
1246
1247@cindex interrupt
1248An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1249terminates the action of any @value{GDBN} command that is in progress and
1250returns to @value{GDBN} command level. It is safe to type the interrupt
1251character at any time because @value{GDBN} does not allow it to take effect
1252until a time when it is safe.
1253
c906108c
SS
1254If you have been using @value{GDBN} to control an attached process or
1255device, you can release it with the @code{detach} command
1256(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1257
6d2ebf8b 1258@node Shell Commands
c906108c
SS
1259@section Shell commands
1260
1261If you need to execute occasional shell commands during your
1262debugging session, there is no need to leave or suspend @value{GDBN}; you can
1263just use the @code{shell} command.
1264
1265@table @code
1266@kindex shell
1267@cindex shell escape
1268@item shell @var{command string}
1269Invoke a standard shell to execute @var{command string}.
c906108c 1270If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1271shell to run. Otherwise @value{GDBN} uses the default shell
1272(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1273@end table
1274
1275The utility @code{make} is often needed in development environments.
1276You do not have to use the @code{shell} command for this purpose in
1277@value{GDBN}:
1278
1279@table @code
1280@kindex make
1281@cindex calling make
1282@item make @var{make-args}
1283Execute the @code{make} program with the specified
1284arguments. This is equivalent to @samp{shell make @var{make-args}}.
1285@end table
1286
0fac0b41
DJ
1287@node Logging output
1288@section Logging output
1289@cindex logging @value{GDBN} output
9c16f35a 1290@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1291
1292You may want to save the output of @value{GDBN} commands to a file.
1293There are several commands to control @value{GDBN}'s logging.
1294
1295@table @code
1296@kindex set logging
1297@item set logging on
1298Enable logging.
1299@item set logging off
1300Disable logging.
9c16f35a 1301@cindex logging file name
0fac0b41
DJ
1302@item set logging file @var{file}
1303Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1304@item set logging overwrite [on|off]
1305By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1306you want @code{set logging on} to overwrite the logfile instead.
1307@item set logging redirect [on|off]
1308By default, @value{GDBN} output will go to both the terminal and the logfile.
1309Set @code{redirect} if you want output to go only to the log file.
1310@kindex show logging
1311@item show logging
1312Show the current values of the logging settings.
1313@end table
1314
6d2ebf8b 1315@node Commands
c906108c
SS
1316@chapter @value{GDBN} Commands
1317
1318You can abbreviate a @value{GDBN} command to the first few letters of the command
1319name, if that abbreviation is unambiguous; and you can repeat certain
1320@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1321key to get @value{GDBN} to fill out the rest of a word in a command (or to
1322show you the alternatives available, if there is more than one possibility).
1323
1324@menu
1325* Command Syntax:: How to give commands to @value{GDBN}
1326* Completion:: Command completion
1327* Help:: How to ask @value{GDBN} for help
1328@end menu
1329
6d2ebf8b 1330@node Command Syntax
c906108c
SS
1331@section Command syntax
1332
1333A @value{GDBN} command is a single line of input. There is no limit on
1334how long it can be. It starts with a command name, which is followed by
1335arguments whose meaning depends on the command name. For example, the
1336command @code{step} accepts an argument which is the number of times to
1337step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1338with no arguments. Some commands do not allow any arguments.
c906108c
SS
1339
1340@cindex abbreviation
1341@value{GDBN} command names may always be truncated if that abbreviation is
1342unambiguous. Other possible command abbreviations are listed in the
1343documentation for individual commands. In some cases, even ambiguous
1344abbreviations are allowed; for example, @code{s} is specially defined as
1345equivalent to @code{step} even though there are other commands whose
1346names start with @code{s}. You can test abbreviations by using them as
1347arguments to the @code{help} command.
1348
1349@cindex repeating commands
41afff9a 1350@kindex RET @r{(repeat last command)}
c906108c 1351A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1352repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1353will not repeat this way; these are commands whose unintentional
1354repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1355repeat. User-defined commands can disable this feature; see
1356@ref{Define, dont-repeat}.
c906108c
SS
1357
1358The @code{list} and @code{x} commands, when you repeat them with
1359@key{RET}, construct new arguments rather than repeating
1360exactly as typed. This permits easy scanning of source or memory.
1361
1362@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1363output, in a way similar to the common utility @code{more}
1364(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1365@key{RET} too many in this situation, @value{GDBN} disables command
1366repetition after any command that generates this sort of display.
1367
41afff9a 1368@kindex # @r{(a comment)}
c906108c
SS
1369@cindex comment
1370Any text from a @kbd{#} to the end of the line is a comment; it does
1371nothing. This is useful mainly in command files (@pxref{Command
1372Files,,Command files}).
1373
88118b3a
TT
1374@cindex repeating command sequences
1375@kindex C-o @r{(operate-and-get-next)}
1376The @kbd{C-o} binding is useful for repeating a complex sequence of
1377commands. This command accepts the current line, like @kbd{RET}, and
1378then fetches the next line relative to the current line from the history
1379for editing.
1380
6d2ebf8b 1381@node Completion
c906108c
SS
1382@section Command completion
1383
1384@cindex completion
1385@cindex word completion
1386@value{GDBN} can fill in the rest of a word in a command for you, if there is
1387only one possibility; it can also show you what the valid possibilities
1388are for the next word in a command, at any time. This works for @value{GDBN}
1389commands, @value{GDBN} subcommands, and the names of symbols in your program.
1390
1391Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1392of a word. If there is only one possibility, @value{GDBN} fills in the
1393word, and waits for you to finish the command (or press @key{RET} to
1394enter it). For example, if you type
1395
1396@c FIXME "@key" does not distinguish its argument sufficiently to permit
1397@c complete accuracy in these examples; space introduced for clarity.
1398@c If texinfo enhancements make it unnecessary, it would be nice to
1399@c replace " @key" by "@key" in the following...
474c8240 1400@smallexample
c906108c 1401(@value{GDBP}) info bre @key{TAB}
474c8240 1402@end smallexample
c906108c
SS
1403
1404@noindent
1405@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1406the only @code{info} subcommand beginning with @samp{bre}:
1407
474c8240 1408@smallexample
c906108c 1409(@value{GDBP}) info breakpoints
474c8240 1410@end smallexample
c906108c
SS
1411
1412@noindent
1413You can either press @key{RET} at this point, to run the @code{info
1414breakpoints} command, or backspace and enter something else, if
1415@samp{breakpoints} does not look like the command you expected. (If you
1416were sure you wanted @code{info breakpoints} in the first place, you
1417might as well just type @key{RET} immediately after @samp{info bre},
1418to exploit command abbreviations rather than command completion).
1419
1420If there is more than one possibility for the next word when you press
1421@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1422characters and try again, or just press @key{TAB} a second time;
1423@value{GDBN} displays all the possible completions for that word. For
1424example, you might want to set a breakpoint on a subroutine whose name
1425begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1426just sounds the bell. Typing @key{TAB} again displays all the
1427function names in your program that begin with those characters, for
1428example:
1429
474c8240 1430@smallexample
c906108c
SS
1431(@value{GDBP}) b make_ @key{TAB}
1432@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1433make_a_section_from_file make_environ
1434make_abs_section make_function_type
1435make_blockvector make_pointer_type
1436make_cleanup make_reference_type
c906108c
SS
1437make_command make_symbol_completion_list
1438(@value{GDBP}) b make_
474c8240 1439@end smallexample
c906108c
SS
1440
1441@noindent
1442After displaying the available possibilities, @value{GDBN} copies your
1443partial input (@samp{b make_} in the example) so you can finish the
1444command.
1445
1446If you just want to see the list of alternatives in the first place, you
b37052ae 1447can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1448means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1449key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1450one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1451
1452@cindex quotes in commands
1453@cindex completion of quoted strings
1454Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1455parentheses or other characters that @value{GDBN} normally excludes from
1456its notion of a word. To permit word completion to work in this
1457situation, you may enclose words in @code{'} (single quote marks) in
1458@value{GDBN} commands.
c906108c 1459
c906108c 1460The most likely situation where you might need this is in typing the
b37052ae
EZ
1461name of a C@t{++} function. This is because C@t{++} allows function
1462overloading (multiple definitions of the same function, distinguished
1463by argument type). For example, when you want to set a breakpoint you
1464may need to distinguish whether you mean the version of @code{name}
1465that takes an @code{int} parameter, @code{name(int)}, or the version
1466that takes a @code{float} parameter, @code{name(float)}. To use the
1467word-completion facilities in this situation, type a single quote
1468@code{'} at the beginning of the function name. This alerts
1469@value{GDBN} that it may need to consider more information than usual
1470when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1471
474c8240 1472@smallexample
96a2c332 1473(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1474bubble(double,double) bubble(int,int)
1475(@value{GDBP}) b 'bubble(
474c8240 1476@end smallexample
c906108c
SS
1477
1478In some cases, @value{GDBN} can tell that completing a name requires using
1479quotes. When this happens, @value{GDBN} inserts the quote for you (while
1480completing as much as it can) if you do not type the quote in the first
1481place:
1482
474c8240 1483@smallexample
c906108c
SS
1484(@value{GDBP}) b bub @key{TAB}
1485@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1486(@value{GDBP}) b 'bubble(
474c8240 1487@end smallexample
c906108c
SS
1488
1489@noindent
1490In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1491you have not yet started typing the argument list when you ask for
1492completion on an overloaded symbol.
1493
d4f3574e 1494For more information about overloaded functions, see @ref{C plus plus
b37052ae 1495expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1496overload-resolution off} to disable overload resolution;
b37052ae 1497see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1498
1499
6d2ebf8b 1500@node Help
c906108c
SS
1501@section Getting help
1502@cindex online documentation
1503@kindex help
1504
5d161b24 1505You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1506using the command @code{help}.
1507
1508@table @code
41afff9a 1509@kindex h @r{(@code{help})}
c906108c
SS
1510@item help
1511@itemx h
1512You can use @code{help} (abbreviated @code{h}) with no arguments to
1513display a short list of named classes of commands:
1514
1515@smallexample
1516(@value{GDBP}) help
1517List of classes of commands:
1518
2df3850c 1519aliases -- Aliases of other commands
c906108c 1520breakpoints -- Making program stop at certain points
2df3850c 1521data -- Examining data
c906108c 1522files -- Specifying and examining files
2df3850c
JM
1523internals -- Maintenance commands
1524obscure -- Obscure features
1525running -- Running the program
1526stack -- Examining the stack
c906108c
SS
1527status -- Status inquiries
1528support -- Support facilities
96a2c332
SS
1529tracepoints -- Tracing of program execution without@*
1530 stopping the program
c906108c 1531user-defined -- User-defined commands
c906108c 1532
5d161b24 1533Type "help" followed by a class name for a list of
c906108c 1534commands in that class.
5d161b24 1535Type "help" followed by command name for full
c906108c
SS
1536documentation.
1537Command name abbreviations are allowed if unambiguous.
1538(@value{GDBP})
1539@end smallexample
96a2c332 1540@c the above line break eliminates huge line overfull...
c906108c
SS
1541
1542@item help @var{class}
1543Using one of the general help classes as an argument, you can get a
1544list of the individual commands in that class. For example, here is the
1545help display for the class @code{status}:
1546
1547@smallexample
1548(@value{GDBP}) help status
1549Status inquiries.
1550
1551List of commands:
1552
1553@c Line break in "show" line falsifies real output, but needed
1554@c to fit in smallbook page size.
2df3850c
JM
1555info -- Generic command for showing things
1556 about the program being debugged
1557show -- Generic command for showing things
1558 about the debugger
c906108c 1559
5d161b24 1560Type "help" followed by command name for full
c906108c
SS
1561documentation.
1562Command name abbreviations are allowed if unambiguous.
1563(@value{GDBP})
1564@end smallexample
1565
1566@item help @var{command}
1567With a command name as @code{help} argument, @value{GDBN} displays a
1568short paragraph on how to use that command.
1569
6837a0a2
DB
1570@kindex apropos
1571@item apropos @var{args}
09d4efe1 1572The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1573commands, and their documentation, for the regular expression specified in
1574@var{args}. It prints out all matches found. For example:
1575
1576@smallexample
1577apropos reload
1578@end smallexample
1579
b37052ae
EZ
1580@noindent
1581results in:
6837a0a2
DB
1582
1583@smallexample
6d2ebf8b
SS
1584@c @group
1585set symbol-reloading -- Set dynamic symbol table reloading
1586 multiple times in one run
1587show symbol-reloading -- Show dynamic symbol table reloading
1588 multiple times in one run
1589@c @end group
6837a0a2
DB
1590@end smallexample
1591
c906108c
SS
1592@kindex complete
1593@item complete @var{args}
1594The @code{complete @var{args}} command lists all the possible completions
1595for the beginning of a command. Use @var{args} to specify the beginning of the
1596command you want completed. For example:
1597
1598@smallexample
1599complete i
1600@end smallexample
1601
1602@noindent results in:
1603
1604@smallexample
1605@group
2df3850c
JM
1606if
1607ignore
c906108c
SS
1608info
1609inspect
c906108c
SS
1610@end group
1611@end smallexample
1612
1613@noindent This is intended for use by @sc{gnu} Emacs.
1614@end table
1615
1616In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1617and @code{show} to inquire about the state of your program, or the state
1618of @value{GDBN} itself. Each command supports many topics of inquiry; this
1619manual introduces each of them in the appropriate context. The listings
1620under @code{info} and under @code{show} in the Index point to
1621all the sub-commands. @xref{Index}.
1622
1623@c @group
1624@table @code
1625@kindex info
41afff9a 1626@kindex i @r{(@code{info})}
c906108c
SS
1627@item info
1628This command (abbreviated @code{i}) is for describing the state of your
1629program. For example, you can list the arguments given to your program
1630with @code{info args}, list the registers currently in use with @code{info
1631registers}, or list the breakpoints you have set with @code{info breakpoints}.
1632You can get a complete list of the @code{info} sub-commands with
1633@w{@code{help info}}.
1634
1635@kindex set
1636@item set
5d161b24 1637You can assign the result of an expression to an environment variable with
c906108c
SS
1638@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1639@code{set prompt $}.
1640
1641@kindex show
1642@item show
5d161b24 1643In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1644@value{GDBN} itself.
1645You can change most of the things you can @code{show}, by using the
1646related command @code{set}; for example, you can control what number
1647system is used for displays with @code{set radix}, or simply inquire
1648which is currently in use with @code{show radix}.
1649
1650@kindex info set
1651To display all the settable parameters and their current
1652values, you can use @code{show} with no arguments; you may also use
1653@code{info set}. Both commands produce the same display.
1654@c FIXME: "info set" violates the rule that "info" is for state of
1655@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1656@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1657@end table
1658@c @end group
1659
1660Here are three miscellaneous @code{show} subcommands, all of which are
1661exceptional in lacking corresponding @code{set} commands:
1662
1663@table @code
1664@kindex show version
9c16f35a 1665@cindex @value{GDBN} version number
c906108c
SS
1666@item show version
1667Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1668information in @value{GDBN} bug-reports. If multiple versions of
1669@value{GDBN} are in use at your site, you may need to determine which
1670version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1671commands are introduced, and old ones may wither away. Also, many
1672system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1673variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1674The version number is the same as the one announced when you start
1675@value{GDBN}.
c906108c
SS
1676
1677@kindex show copying
09d4efe1 1678@kindex info copying
9c16f35a 1679@cindex display @value{GDBN} copyright
c906108c 1680@item show copying
09d4efe1 1681@itemx info copying
c906108c
SS
1682Display information about permission for copying @value{GDBN}.
1683
1684@kindex show warranty
09d4efe1 1685@kindex info warranty
c906108c 1686@item show warranty
09d4efe1 1687@itemx info warranty
2df3850c 1688Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1689if your version of @value{GDBN} comes with one.
2df3850c 1690
c906108c
SS
1691@end table
1692
6d2ebf8b 1693@node Running
c906108c
SS
1694@chapter Running Programs Under @value{GDBN}
1695
1696When you run a program under @value{GDBN}, you must first generate
1697debugging information when you compile it.
7a292a7a
SS
1698
1699You may start @value{GDBN} with its arguments, if any, in an environment
1700of your choice. If you are doing native debugging, you may redirect
1701your program's input and output, debug an already running process, or
1702kill a child process.
c906108c
SS
1703
1704@menu
1705* Compilation:: Compiling for debugging
1706* Starting:: Starting your program
c906108c
SS
1707* Arguments:: Your program's arguments
1708* Environment:: Your program's environment
c906108c
SS
1709
1710* Working Directory:: Your program's working directory
1711* Input/Output:: Your program's input and output
1712* Attach:: Debugging an already-running process
1713* Kill Process:: Killing the child process
c906108c
SS
1714
1715* Threads:: Debugging programs with multiple threads
1716* Processes:: Debugging programs with multiple processes
1717@end menu
1718
6d2ebf8b 1719@node Compilation
c906108c
SS
1720@section Compiling for debugging
1721
1722In order to debug a program effectively, you need to generate
1723debugging information when you compile it. This debugging information
1724is stored in the object file; it describes the data type of each
1725variable or function and the correspondence between source line numbers
1726and addresses in the executable code.
1727
1728To request debugging information, specify the @samp{-g} option when you run
1729the compiler.
1730
514c4d71
EZ
1731Programs that are to be shipped to your customers are compiled with
1732optimizations, using the @samp{-O} compiler option. However, many
1733compilers are unable to handle the @samp{-g} and @samp{-O} options
1734together. Using those compilers, you cannot generate optimized
c906108c
SS
1735executables containing debugging information.
1736
514c4d71 1737@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1738without @samp{-O}, making it possible to debug optimized code. We
1739recommend that you @emph{always} use @samp{-g} whenever you compile a
1740program. You may think your program is correct, but there is no sense
1741in pushing your luck.
c906108c
SS
1742
1743@cindex optimized code, debugging
1744@cindex debugging optimized code
1745When you debug a program compiled with @samp{-g -O}, remember that the
1746optimizer is rearranging your code; the debugger shows you what is
1747really there. Do not be too surprised when the execution path does not
1748exactly match your source file! An extreme example: if you define a
1749variable, but never use it, @value{GDBN} never sees that
1750variable---because the compiler optimizes it out of existence.
1751
1752Some things do not work as well with @samp{-g -O} as with just
1753@samp{-g}, particularly on machines with instruction scheduling. If in
1754doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1755please report it to us as a bug (including a test case!).
15387254 1756@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1757
1758Older versions of the @sc{gnu} C compiler permitted a variant option
1759@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1760format; if your @sc{gnu} C compiler has this option, do not use it.
1761
514c4d71
EZ
1762@value{GDBN} knows about preprocessor macros and can show you their
1763expansion (@pxref{Macros}). Most compilers do not include information
1764about preprocessor macros in the debugging information if you specify
1765the @option{-g} flag alone, because this information is rather large.
1766Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1767provides macro information if you specify the options
1768@option{-gdwarf-2} and @option{-g3}; the former option requests
1769debugging information in the Dwarf 2 format, and the latter requests
1770``extra information''. In the future, we hope to find more compact
1771ways to represent macro information, so that it can be included with
1772@option{-g} alone.
1773
c906108c 1774@need 2000
6d2ebf8b 1775@node Starting
c906108c
SS
1776@section Starting your program
1777@cindex starting
1778@cindex running
1779
1780@table @code
1781@kindex run
41afff9a 1782@kindex r @r{(@code{run})}
c906108c
SS
1783@item run
1784@itemx r
7a292a7a
SS
1785Use the @code{run} command to start your program under @value{GDBN}.
1786You must first specify the program name (except on VxWorks) with an
1787argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1788@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1789(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1790
1791@end table
1792
c906108c
SS
1793If you are running your program in an execution environment that
1794supports processes, @code{run} creates an inferior process and makes
1795that process run your program. (In environments without processes,
1796@code{run} jumps to the start of your program.)
1797
1798The execution of a program is affected by certain information it
1799receives from its superior. @value{GDBN} provides ways to specify this
1800information, which you must do @emph{before} starting your program. (You
1801can change it after starting your program, but such changes only affect
1802your program the next time you start it.) This information may be
1803divided into four categories:
1804
1805@table @asis
1806@item The @emph{arguments.}
1807Specify the arguments to give your program as the arguments of the
1808@code{run} command. If a shell is available on your target, the shell
1809is used to pass the arguments, so that you may use normal conventions
1810(such as wildcard expansion or variable substitution) in describing
1811the arguments.
1812In Unix systems, you can control which shell is used with the
1813@code{SHELL} environment variable.
1814@xref{Arguments, ,Your program's arguments}.
1815
1816@item The @emph{environment.}
1817Your program normally inherits its environment from @value{GDBN}, but you can
1818use the @value{GDBN} commands @code{set environment} and @code{unset
1819environment} to change parts of the environment that affect
1820your program. @xref{Environment, ,Your program's environment}.
1821
1822@item The @emph{working directory.}
1823Your program inherits its working directory from @value{GDBN}. You can set
1824the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1825@xref{Working Directory, ,Your program's working directory}.
1826
1827@item The @emph{standard input and output.}
1828Your program normally uses the same device for standard input and
1829standard output as @value{GDBN} is using. You can redirect input and output
1830in the @code{run} command line, or you can use the @code{tty} command to
1831set a different device for your program.
1832@xref{Input/Output, ,Your program's input and output}.
1833
1834@cindex pipes
1835@emph{Warning:} While input and output redirection work, you cannot use
1836pipes to pass the output of the program you are debugging to another
1837program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1838wrong program.
1839@end table
c906108c
SS
1840
1841When you issue the @code{run} command, your program begins to execute
1842immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1843of how to arrange for your program to stop. Once your program has
1844stopped, you may call functions in your program, using the @code{print}
1845or @code{call} commands. @xref{Data, ,Examining Data}.
1846
1847If the modification time of your symbol file has changed since the last
1848time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1849table, and reads it again. When it does this, @value{GDBN} tries to retain
1850your current breakpoints.
1851
4e8b0763
JB
1852@table @code
1853@kindex start
1854@item start
1855@cindex run to main procedure
1856The name of the main procedure can vary from language to language.
1857With C or C@t{++}, the main procedure name is always @code{main}, but
1858other languages such as Ada do not require a specific name for their
1859main procedure. The debugger provides a convenient way to start the
1860execution of the program and to stop at the beginning of the main
1861procedure, depending on the language used.
1862
1863The @samp{start} command does the equivalent of setting a temporary
1864breakpoint at the beginning of the main procedure and then invoking
1865the @samp{run} command.
1866
f018e82f
EZ
1867@cindex elaboration phase
1868Some programs contain an @dfn{elaboration} phase where some startup code is
1869executed before the main procedure is called. This depends on the
1870languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1871constructors for static and global objects are executed before
1872@code{main} is called. It is therefore possible that the debugger stops
1873before reaching the main procedure. However, the temporary breakpoint
1874will remain to halt execution.
1875
1876Specify the arguments to give to your program as arguments to the
1877@samp{start} command. These arguments will be given verbatim to the
1878underlying @samp{run} command. Note that the same arguments will be
1879reused if no argument is provided during subsequent calls to
1880@samp{start} or @samp{run}.
1881
1882It is sometimes necessary to debug the program during elaboration. In
1883these cases, using the @code{start} command would stop the execution of
1884your program too late, as the program would have already completed the
1885elaboration phase. Under these circumstances, insert breakpoints in your
1886elaboration code before running your program.
1887@end table
1888
6d2ebf8b 1889@node Arguments
c906108c
SS
1890@section Your program's arguments
1891
1892@cindex arguments (to your program)
1893The arguments to your program can be specified by the arguments of the
5d161b24 1894@code{run} command.
c906108c
SS
1895They are passed to a shell, which expands wildcard characters and
1896performs redirection of I/O, and thence to your program. Your
1897@code{SHELL} environment variable (if it exists) specifies what shell
1898@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1899the default shell (@file{/bin/sh} on Unix).
1900
1901On non-Unix systems, the program is usually invoked directly by
1902@value{GDBN}, which emulates I/O redirection via the appropriate system
1903calls, and the wildcard characters are expanded by the startup code of
1904the program, not by the shell.
c906108c
SS
1905
1906@code{run} with no arguments uses the same arguments used by the previous
1907@code{run}, or those set by the @code{set args} command.
1908
c906108c 1909@table @code
41afff9a 1910@kindex set args
c906108c
SS
1911@item set args
1912Specify the arguments to be used the next time your program is run. If
1913@code{set args} has no arguments, @code{run} executes your program
1914with no arguments. Once you have run your program with arguments,
1915using @code{set args} before the next @code{run} is the only way to run
1916it again without arguments.
1917
1918@kindex show args
1919@item show args
1920Show the arguments to give your program when it is started.
1921@end table
1922
6d2ebf8b 1923@node Environment
c906108c
SS
1924@section Your program's environment
1925
1926@cindex environment (of your program)
1927The @dfn{environment} consists of a set of environment variables and
1928their values. Environment variables conventionally record such things as
1929your user name, your home directory, your terminal type, and your search
1930path for programs to run. Usually you set up environment variables with
1931the shell and they are inherited by all the other programs you run. When
1932debugging, it can be useful to try running your program with a modified
1933environment without having to start @value{GDBN} over again.
1934
1935@table @code
1936@kindex path
1937@item path @var{directory}
1938Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1939(the search path for executables) that will be passed to your program.
1940The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1941You may specify several directory names, separated by whitespace or by a
1942system-dependent separator character (@samp{:} on Unix, @samp{;} on
1943MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1944is moved to the front, so it is searched sooner.
c906108c
SS
1945
1946You can use the string @samp{$cwd} to refer to whatever is the current
1947working directory at the time @value{GDBN} searches the path. If you
1948use @samp{.} instead, it refers to the directory where you executed the
1949@code{path} command. @value{GDBN} replaces @samp{.} in the
1950@var{directory} argument (with the current path) before adding
1951@var{directory} to the search path.
1952@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1953@c document that, since repeating it would be a no-op.
1954
1955@kindex show paths
1956@item show paths
1957Display the list of search paths for executables (the @code{PATH}
1958environment variable).
1959
1960@kindex show environment
1961@item show environment @r{[}@var{varname}@r{]}
1962Print the value of environment variable @var{varname} to be given to
1963your program when it starts. If you do not supply @var{varname},
1964print the names and values of all environment variables to be given to
1965your program. You can abbreviate @code{environment} as @code{env}.
1966
1967@kindex set environment
53a5351d 1968@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1969Set environment variable @var{varname} to @var{value}. The value
1970changes for your program only, not for @value{GDBN} itself. @var{value} may
1971be any string; the values of environment variables are just strings, and
1972any interpretation is supplied by your program itself. The @var{value}
1973parameter is optional; if it is eliminated, the variable is set to a
1974null value.
1975@c "any string" here does not include leading, trailing
1976@c blanks. Gnu asks: does anyone care?
1977
1978For example, this command:
1979
474c8240 1980@smallexample
c906108c 1981set env USER = foo
474c8240 1982@end smallexample
c906108c
SS
1983
1984@noindent
d4f3574e 1985tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1986@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1987are not actually required.)
1988
1989@kindex unset environment
1990@item unset environment @var{varname}
1991Remove variable @var{varname} from the environment to be passed to your
1992program. This is different from @samp{set env @var{varname} =};
1993@code{unset environment} removes the variable from the environment,
1994rather than assigning it an empty value.
1995@end table
1996
d4f3574e
SS
1997@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1998the shell indicated
c906108c
SS
1999by your @code{SHELL} environment variable if it exists (or
2000@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2001that runs an initialization file---such as @file{.cshrc} for C-shell, or
2002@file{.bashrc} for BASH---any variables you set in that file affect
2003your program. You may wish to move setting of environment variables to
2004files that are only run when you sign on, such as @file{.login} or
2005@file{.profile}.
2006
6d2ebf8b 2007@node Working Directory
c906108c
SS
2008@section Your program's working directory
2009
2010@cindex working directory (of your program)
2011Each time you start your program with @code{run}, it inherits its
2012working directory from the current working directory of @value{GDBN}.
2013The @value{GDBN} working directory is initially whatever it inherited
2014from its parent process (typically the shell), but you can specify a new
2015working directory in @value{GDBN} with the @code{cd} command.
2016
2017The @value{GDBN} working directory also serves as a default for the commands
2018that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2019specify files}.
2020
2021@table @code
2022@kindex cd
721c2651 2023@cindex change working directory
c906108c
SS
2024@item cd @var{directory}
2025Set the @value{GDBN} working directory to @var{directory}.
2026
2027@kindex pwd
2028@item pwd
2029Print the @value{GDBN} working directory.
2030@end table
2031
60bf7e09
EZ
2032It is generally impossible to find the current working directory of
2033the process being debugged (since a program can change its directory
2034during its run). If you work on a system where @value{GDBN} is
2035configured with the @file{/proc} support, you can use the @code{info
2036proc} command (@pxref{SVR4 Process Information}) to find out the
2037current working directory of the debuggee.
2038
6d2ebf8b 2039@node Input/Output
c906108c
SS
2040@section Your program's input and output
2041
2042@cindex redirection
2043@cindex i/o
2044@cindex terminal
2045By default, the program you run under @value{GDBN} does input and output to
5d161b24 2046the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2047to its own terminal modes to interact with you, but it records the terminal
2048modes your program was using and switches back to them when you continue
2049running your program.
2050
2051@table @code
2052@kindex info terminal
2053@item info terminal
2054Displays information recorded by @value{GDBN} about the terminal modes your
2055program is using.
2056@end table
2057
2058You can redirect your program's input and/or output using shell
2059redirection with the @code{run} command. For example,
2060
474c8240 2061@smallexample
c906108c 2062run > outfile
474c8240 2063@end smallexample
c906108c
SS
2064
2065@noindent
2066starts your program, diverting its output to the file @file{outfile}.
2067
2068@kindex tty
2069@cindex controlling terminal
2070Another way to specify where your program should do input and output is
2071with the @code{tty} command. This command accepts a file name as
2072argument, and causes this file to be the default for future @code{run}
2073commands. It also resets the controlling terminal for the child
2074process, for future @code{run} commands. For example,
2075
474c8240 2076@smallexample
c906108c 2077tty /dev/ttyb
474c8240 2078@end smallexample
c906108c
SS
2079
2080@noindent
2081directs that processes started with subsequent @code{run} commands
2082default to do input and output on the terminal @file{/dev/ttyb} and have
2083that as their controlling terminal.
2084
2085An explicit redirection in @code{run} overrides the @code{tty} command's
2086effect on the input/output device, but not its effect on the controlling
2087terminal.
2088
2089When you use the @code{tty} command or redirect input in the @code{run}
2090command, only the input @emph{for your program} is affected. The input
2091for @value{GDBN} still comes from your terminal.
2092
6d2ebf8b 2093@node Attach
c906108c
SS
2094@section Debugging an already-running process
2095@kindex attach
2096@cindex attach
2097
2098@table @code
2099@item attach @var{process-id}
2100This command attaches to a running process---one that was started
2101outside @value{GDBN}. (@code{info files} shows your active
2102targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2103find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2104or with the @samp{jobs -l} shell command.
2105
2106@code{attach} does not repeat if you press @key{RET} a second time after
2107executing the command.
2108@end table
2109
2110To use @code{attach}, your program must be running in an environment
2111which supports processes; for example, @code{attach} does not work for
2112programs on bare-board targets that lack an operating system. You must
2113also have permission to send the process a signal.
2114
2115When you use @code{attach}, the debugger finds the program running in
2116the process first by looking in the current working directory, then (if
2117the program is not found) by using the source file search path
2118(@pxref{Source Path, ,Specifying source directories}). You can also use
2119the @code{file} command to load the program. @xref{Files, ,Commands to
2120Specify Files}.
2121
2122The first thing @value{GDBN} does after arranging to debug the specified
2123process is to stop it. You can examine and modify an attached process
53a5351d
JM
2124with all the @value{GDBN} commands that are ordinarily available when
2125you start processes with @code{run}. You can insert breakpoints; you
2126can step and continue; you can modify storage. If you would rather the
2127process continue running, you may use the @code{continue} command after
c906108c
SS
2128attaching @value{GDBN} to the process.
2129
2130@table @code
2131@kindex detach
2132@item detach
2133When you have finished debugging the attached process, you can use the
2134@code{detach} command to release it from @value{GDBN} control. Detaching
2135the process continues its execution. After the @code{detach} command,
2136that process and @value{GDBN} become completely independent once more, and you
2137are ready to @code{attach} another process or start one with @code{run}.
2138@code{detach} does not repeat if you press @key{RET} again after
2139executing the command.
2140@end table
2141
2142If you exit @value{GDBN} or use the @code{run} command while you have an
2143attached process, you kill that process. By default, @value{GDBN} asks
2144for confirmation if you try to do either of these things; you can
2145control whether or not you need to confirm by using the @code{set
2146confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2147messages}).
2148
6d2ebf8b 2149@node Kill Process
c906108c 2150@section Killing the child process
c906108c
SS
2151
2152@table @code
2153@kindex kill
2154@item kill
2155Kill the child process in which your program is running under @value{GDBN}.
2156@end table
2157
2158This command is useful if you wish to debug a core dump instead of a
2159running process. @value{GDBN} ignores any core dump file while your program
2160is running.
2161
2162On some operating systems, a program cannot be executed outside @value{GDBN}
2163while you have breakpoints set on it inside @value{GDBN}. You can use the
2164@code{kill} command in this situation to permit running your program
2165outside the debugger.
2166
2167The @code{kill} command is also useful if you wish to recompile and
2168relink your program, since on many systems it is impossible to modify an
2169executable file while it is running in a process. In this case, when you
2170next type @code{run}, @value{GDBN} notices that the file has changed, and
2171reads the symbol table again (while trying to preserve your current
2172breakpoint settings).
2173
6d2ebf8b 2174@node Threads
c906108c 2175@section Debugging programs with multiple threads
c906108c
SS
2176
2177@cindex threads of execution
2178@cindex multiple threads
2179@cindex switching threads
2180In some operating systems, such as HP-UX and Solaris, a single program
2181may have more than one @dfn{thread} of execution. The precise semantics
2182of threads differ from one operating system to another, but in general
2183the threads of a single program are akin to multiple processes---except
2184that they share one address space (that is, they can all examine and
2185modify the same variables). On the other hand, each thread has its own
2186registers and execution stack, and perhaps private memory.
2187
2188@value{GDBN} provides these facilities for debugging multi-thread
2189programs:
2190
2191@itemize @bullet
2192@item automatic notification of new threads
2193@item @samp{thread @var{threadno}}, a command to switch among threads
2194@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2195@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2196a command to apply a command to a list of threads
2197@item thread-specific breakpoints
2198@end itemize
2199
c906108c
SS
2200@quotation
2201@emph{Warning:} These facilities are not yet available on every
2202@value{GDBN} configuration where the operating system supports threads.
2203If your @value{GDBN} does not support threads, these commands have no
2204effect. For example, a system without thread support shows no output
2205from @samp{info threads}, and always rejects the @code{thread} command,
2206like this:
2207
2208@smallexample
2209(@value{GDBP}) info threads
2210(@value{GDBP}) thread 1
2211Thread ID 1 not known. Use the "info threads" command to
2212see the IDs of currently known threads.
2213@end smallexample
2214@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2215@c doesn't support threads"?
2216@end quotation
c906108c
SS
2217
2218@cindex focus of debugging
2219@cindex current thread
2220The @value{GDBN} thread debugging facility allows you to observe all
2221threads while your program runs---but whenever @value{GDBN} takes
2222control, one thread in particular is always the focus of debugging.
2223This thread is called the @dfn{current thread}. Debugging commands show
2224program information from the perspective of the current thread.
2225
41afff9a 2226@cindex @code{New} @var{systag} message
c906108c
SS
2227@cindex thread identifier (system)
2228@c FIXME-implementors!! It would be more helpful if the [New...] message
2229@c included GDB's numeric thread handle, so you could just go to that
2230@c thread without first checking `info threads'.
2231Whenever @value{GDBN} detects a new thread in your program, it displays
2232the target system's identification for the thread with a message in the
2233form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2234whose form varies depending on the particular system. For example, on
2235LynxOS, you might see
2236
474c8240 2237@smallexample
c906108c 2238[New process 35 thread 27]
474c8240 2239@end smallexample
c906108c
SS
2240
2241@noindent
2242when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2243the @var{systag} is simply something like @samp{process 368}, with no
2244further qualifier.
2245
2246@c FIXME!! (1) Does the [New...] message appear even for the very first
2247@c thread of a program, or does it only appear for the
6ca652b0 2248@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2249@c program?
2250@c (2) *Is* there necessarily a first thread always? Or do some
2251@c multithread systems permit starting a program with multiple
5d161b24 2252@c threads ab initio?
c906108c
SS
2253
2254@cindex thread number
2255@cindex thread identifier (GDB)
2256For debugging purposes, @value{GDBN} associates its own thread
2257number---always a single integer---with each thread in your program.
2258
2259@table @code
2260@kindex info threads
2261@item info threads
2262Display a summary of all threads currently in your
2263program. @value{GDBN} displays for each thread (in this order):
2264
2265@enumerate
09d4efe1
EZ
2266@item
2267the thread number assigned by @value{GDBN}
c906108c 2268
09d4efe1
EZ
2269@item
2270the target system's thread identifier (@var{systag})
c906108c 2271
09d4efe1
EZ
2272@item
2273the current stack frame summary for that thread
c906108c
SS
2274@end enumerate
2275
2276@noindent
2277An asterisk @samp{*} to the left of the @value{GDBN} thread number
2278indicates the current thread.
2279
5d161b24 2280For example,
c906108c
SS
2281@end table
2282@c end table here to get a little more width for example
2283
2284@smallexample
2285(@value{GDBP}) info threads
2286 3 process 35 thread 27 0x34e5 in sigpause ()
2287 2 process 35 thread 23 0x34e5 in sigpause ()
2288* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2289 at threadtest.c:68
2290@end smallexample
53a5351d
JM
2291
2292On HP-UX systems:
c906108c 2293
4644b6e3
EZ
2294@cindex debugging multithreaded programs (on HP-UX)
2295@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2296For debugging purposes, @value{GDBN} associates its own thread
2297number---a small integer assigned in thread-creation order---with each
2298thread in your program.
2299
41afff9a
EZ
2300@cindex @code{New} @var{systag} message, on HP-UX
2301@cindex thread identifier (system), on HP-UX
c906108c
SS
2302@c FIXME-implementors!! It would be more helpful if the [New...] message
2303@c included GDB's numeric thread handle, so you could just go to that
2304@c thread without first checking `info threads'.
2305Whenever @value{GDBN} detects a new thread in your program, it displays
2306both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2307form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2308whose form varies depending on the particular system. For example, on
2309HP-UX, you see
2310
474c8240 2311@smallexample
c906108c 2312[New thread 2 (system thread 26594)]
474c8240 2313@end smallexample
c906108c
SS
2314
2315@noindent
5d161b24 2316when @value{GDBN} notices a new thread.
c906108c
SS
2317
2318@table @code
4644b6e3 2319@kindex info threads (HP-UX)
c906108c
SS
2320@item info threads
2321Display a summary of all threads currently in your
2322program. @value{GDBN} displays for each thread (in this order):
2323
2324@enumerate
2325@item the thread number assigned by @value{GDBN}
2326
2327@item the target system's thread identifier (@var{systag})
2328
2329@item the current stack frame summary for that thread
2330@end enumerate
2331
2332@noindent
2333An asterisk @samp{*} to the left of the @value{GDBN} thread number
2334indicates the current thread.
2335
5d161b24 2336For example,
c906108c
SS
2337@end table
2338@c end table here to get a little more width for example
2339
474c8240 2340@smallexample
c906108c 2341(@value{GDBP}) info threads
6d2ebf8b
SS
2342 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2343 at quicksort.c:137
2344 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2345 from /usr/lib/libc.2
2346 1 system thread 27905 0x7b003498 in _brk () \@*
2347 from /usr/lib/libc.2
474c8240 2348@end smallexample
c906108c 2349
c45da7e6
EZ
2350On Solaris, you can display more information about user threads with a
2351Solaris-specific command:
2352
2353@table @code
2354@item maint info sol-threads
2355@kindex maint info sol-threads
2356@cindex thread info (Solaris)
2357Display info on Solaris user threads.
2358@end table
2359
c906108c
SS
2360@table @code
2361@kindex thread @var{threadno}
2362@item thread @var{threadno}
2363Make thread number @var{threadno} the current thread. The command
2364argument @var{threadno} is the internal @value{GDBN} thread number, as
2365shown in the first field of the @samp{info threads} display.
2366@value{GDBN} responds by displaying the system identifier of the thread
2367you selected, and its current stack frame summary:
2368
2369@smallexample
2370@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2371(@value{GDBP}) thread 2
c906108c 2372[Switching to process 35 thread 23]
c906108c
SS
23730x34e5 in sigpause ()
2374@end smallexample
2375
2376@noindent
2377As with the @samp{[New @dots{}]} message, the form of the text after
2378@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2379threads.
c906108c 2380
9c16f35a 2381@kindex thread apply
c906108c
SS
2382@item thread apply [@var{threadno}] [@var{all}] @var{args}
2383The @code{thread apply} command allows you to apply a command to one or
2384more threads. Specify the numbers of the threads that you want affected
2385with the command argument @var{threadno}. @var{threadno} is the internal
2386@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2387threads} display. To apply a command to all threads, use
2388@code{thread apply all} @var{args}.
c906108c
SS
2389@end table
2390
2391@cindex automatic thread selection
2392@cindex switching threads automatically
2393@cindex threads, automatic switching
2394Whenever @value{GDBN} stops your program, due to a breakpoint or a
2395signal, it automatically selects the thread where that breakpoint or
2396signal happened. @value{GDBN} alerts you to the context switch with a
2397message of the form @samp{[Switching to @var{systag}]} to identify the
2398thread.
2399
2400@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2401more information about how @value{GDBN} behaves when you stop and start
2402programs with multiple threads.
2403
2404@xref{Set Watchpoints,,Setting watchpoints}, for information about
2405watchpoints in programs with multiple threads.
c906108c 2406
6d2ebf8b 2407@node Processes
c906108c
SS
2408@section Debugging programs with multiple processes
2409
2410@cindex fork, debugging programs which call
2411@cindex multiple processes
2412@cindex processes, multiple
53a5351d
JM
2413On most systems, @value{GDBN} has no special support for debugging
2414programs which create additional processes using the @code{fork}
2415function. When a program forks, @value{GDBN} will continue to debug the
2416parent process and the child process will run unimpeded. If you have
2417set a breakpoint in any code which the child then executes, the child
2418will get a @code{SIGTRAP} signal which (unless it catches the signal)
2419will cause it to terminate.
c906108c
SS
2420
2421However, if you want to debug the child process there is a workaround
2422which isn't too painful. Put a call to @code{sleep} in the code which
2423the child process executes after the fork. It may be useful to sleep
2424only if a certain environment variable is set, or a certain file exists,
2425so that the delay need not occur when you don't want to run @value{GDBN}
2426on the child. While the child is sleeping, use the @code{ps} program to
2427get its process ID. Then tell @value{GDBN} (a new invocation of
2428@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2429the child process (@pxref{Attach}). From that point on you can debug
c906108c 2430the child process just like any other process which you attached to.
c906108c 2431
b51970ac
DJ
2432On some systems, @value{GDBN} provides support for debugging programs that
2433create additional processes using the @code{fork} or @code{vfork} functions.
2434Currently, the only platforms with this feature are HP-UX (11.x and later
2435only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2436
2437By default, when a program forks, @value{GDBN} will continue to debug
2438the parent process and the child process will run unimpeded.
2439
2440If you want to follow the child process instead of the parent process,
2441use the command @w{@code{set follow-fork-mode}}.
2442
2443@table @code
2444@kindex set follow-fork-mode
2445@item set follow-fork-mode @var{mode}
2446Set the debugger response to a program call of @code{fork} or
2447@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2448process. The @var{mode} argument can be:
c906108c
SS
2449
2450@table @code
2451@item parent
2452The original process is debugged after a fork. The child process runs
2df3850c 2453unimpeded. This is the default.
c906108c
SS
2454
2455@item child
2456The new process is debugged after a fork. The parent process runs
2457unimpeded.
2458
c906108c
SS
2459@end table
2460
9c16f35a 2461@kindex show follow-fork-mode
c906108c 2462@item show follow-fork-mode
2df3850c 2463Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2464@end table
2465
2466If you ask to debug a child process and a @code{vfork} is followed by an
2467@code{exec}, @value{GDBN} executes the new target up to the first
2468breakpoint in the new target. If you have a breakpoint set on
2469@code{main} in your original program, the breakpoint will also be set on
2470the child process's @code{main}.
2471
2472When a child process is spawned by @code{vfork}, you cannot debug the
2473child or parent until an @code{exec} call completes.
2474
2475If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2476call executes, the new target restarts. To restart the parent process,
2477use the @code{file} command with the parent executable name as its
2478argument.
2479
2480You can use the @code{catch} command to make @value{GDBN} stop whenever
2481a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2482Catchpoints, ,Setting catchpoints}.
c906108c 2483
6d2ebf8b 2484@node Stopping
c906108c
SS
2485@chapter Stopping and Continuing
2486
2487The principal purposes of using a debugger are so that you can stop your
2488program before it terminates; or so that, if your program runs into
2489trouble, you can investigate and find out why.
2490
7a292a7a
SS
2491Inside @value{GDBN}, your program may stop for any of several reasons,
2492such as a signal, a breakpoint, or reaching a new line after a
2493@value{GDBN} command such as @code{step}. You may then examine and
2494change variables, set new breakpoints or remove old ones, and then
2495continue execution. Usually, the messages shown by @value{GDBN} provide
2496ample explanation of the status of your program---but you can also
2497explicitly request this information at any time.
c906108c
SS
2498
2499@table @code
2500@kindex info program
2501@item info program
2502Display information about the status of your program: whether it is
7a292a7a 2503running or not, what process it is, and why it stopped.
c906108c
SS
2504@end table
2505
2506@menu
2507* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2508* Continuing and Stepping:: Resuming execution
c906108c 2509* Signals:: Signals
c906108c 2510* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2511@end menu
2512
6d2ebf8b 2513@node Breakpoints
c906108c
SS
2514@section Breakpoints, watchpoints, and catchpoints
2515
2516@cindex breakpoints
2517A @dfn{breakpoint} makes your program stop whenever a certain point in
2518the program is reached. For each breakpoint, you can add conditions to
2519control in finer detail whether your program stops. You can set
2520breakpoints with the @code{break} command and its variants (@pxref{Set
2521Breaks, ,Setting breakpoints}), to specify the place where your program
2522should stop by line number, function name or exact address in the
2523program.
2524
09d4efe1
EZ
2525On some systems, you can set breakpoints in shared libraries before
2526the executable is run. There is a minor limitation on HP-UX systems:
2527you must wait until the executable is run in order to set breakpoints
2528in shared library routines that are not called directly by the program
2529(for example, routines that are arguments in a @code{pthread_create}
2530call).
c906108c
SS
2531
2532@cindex watchpoints
2533@cindex memory tracing
2534@cindex breakpoint on memory address
2535@cindex breakpoint on variable modification
2536A @dfn{watchpoint} is a special breakpoint that stops your program
2537when the value of an expression changes. You must use a different
2538command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2539watchpoints}), but aside from that, you can manage a watchpoint like
2540any other breakpoint: you enable, disable, and delete both breakpoints
2541and watchpoints using the same commands.
2542
2543You can arrange to have values from your program displayed automatically
2544whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2545Automatic display}.
2546
2547@cindex catchpoints
2548@cindex breakpoint on events
2549A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2550when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2551exception or the loading of a library. As with watchpoints, you use a
2552different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2553catchpoints}), but aside from that, you can manage a catchpoint like any
2554other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2555@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2556
2557@cindex breakpoint numbers
2558@cindex numbers for breakpoints
2559@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2560catchpoint when you create it; these numbers are successive integers
2561starting with one. In many of the commands for controlling various
2562features of breakpoints you use the breakpoint number to say which
2563breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2564@dfn{disabled}; if disabled, it has no effect on your program until you
2565enable it again.
2566
c5394b80
JM
2567@cindex breakpoint ranges
2568@cindex ranges of breakpoints
2569Some @value{GDBN} commands accept a range of breakpoints on which to
2570operate. A breakpoint range is either a single breakpoint number, like
2571@samp{5}, or two such numbers, in increasing order, separated by a
2572hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2573all breakpoint in that range are operated on.
2574
c906108c
SS
2575@menu
2576* Set Breaks:: Setting breakpoints
2577* Set Watchpoints:: Setting watchpoints
2578* Set Catchpoints:: Setting catchpoints
2579* Delete Breaks:: Deleting breakpoints
2580* Disabling:: Disabling breakpoints
2581* Conditions:: Break conditions
2582* Break Commands:: Breakpoint command lists
c906108c 2583* Breakpoint Menus:: Breakpoint menus
d4f3574e 2584* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2585* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2586@end menu
2587
6d2ebf8b 2588@node Set Breaks
c906108c
SS
2589@subsection Setting breakpoints
2590
5d161b24 2591@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2592@c consider in particular declaration with/without initialization.
2593@c
2594@c FIXME 2 is there stuff on this already? break at fun start, already init?
2595
2596@kindex break
41afff9a
EZ
2597@kindex b @r{(@code{break})}
2598@vindex $bpnum@r{, convenience variable}
c906108c
SS
2599@cindex latest breakpoint
2600Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2601@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2602number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2603Vars,, Convenience variables}, for a discussion of what you can do with
2604convenience variables.
2605
2606You have several ways to say where the breakpoint should go.
2607
2608@table @code
2609@item break @var{function}
5d161b24 2610Set a breakpoint at entry to function @var{function}.
c906108c 2611When using source languages that permit overloading of symbols, such as
b37052ae 2612C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2613@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2614
2615@item break +@var{offset}
2616@itemx break -@var{offset}
2617Set a breakpoint some number of lines forward or back from the position
d4f3574e 2618at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2619(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2620
2621@item break @var{linenum}
2622Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2623The current source file is the last file whose source text was printed.
2624The breakpoint will stop your program just before it executes any of the
c906108c
SS
2625code on that line.
2626
2627@item break @var{filename}:@var{linenum}
2628Set a breakpoint at line @var{linenum} in source file @var{filename}.
2629
2630@item break @var{filename}:@var{function}
2631Set a breakpoint at entry to function @var{function} found in file
2632@var{filename}. Specifying a file name as well as a function name is
2633superfluous except when multiple files contain similarly named
2634functions.
2635
2636@item break *@var{address}
2637Set a breakpoint at address @var{address}. You can use this to set
2638breakpoints in parts of your program which do not have debugging
2639information or source files.
2640
2641@item break
2642When called without any arguments, @code{break} sets a breakpoint at
2643the next instruction to be executed in the selected stack frame
2644(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2645innermost, this makes your program stop as soon as control
2646returns to that frame. This is similar to the effect of a
2647@code{finish} command in the frame inside the selected frame---except
2648that @code{finish} does not leave an active breakpoint. If you use
2649@code{break} without an argument in the innermost frame, @value{GDBN} stops
2650the next time it reaches the current location; this may be useful
2651inside loops.
2652
2653@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2654least one instruction has been executed. If it did not do this, you
2655would be unable to proceed past a breakpoint without first disabling the
2656breakpoint. This rule applies whether or not the breakpoint already
2657existed when your program stopped.
2658
2659@item break @dots{} if @var{cond}
2660Set a breakpoint with condition @var{cond}; evaluate the expression
2661@var{cond} each time the breakpoint is reached, and stop only if the
2662value is nonzero---that is, if @var{cond} evaluates as true.
2663@samp{@dots{}} stands for one of the possible arguments described
2664above (or no argument) specifying where to break. @xref{Conditions,
2665,Break conditions}, for more information on breakpoint conditions.
2666
2667@kindex tbreak
2668@item tbreak @var{args}
2669Set a breakpoint enabled only for one stop. @var{args} are the
2670same as for the @code{break} command, and the breakpoint is set in the same
2671way, but the breakpoint is automatically deleted after the first time your
2672program stops there. @xref{Disabling, ,Disabling breakpoints}.
2673
c906108c 2674@kindex hbreak
ba04e063 2675@cindex hardware breakpoints
c906108c 2676@item hbreak @var{args}
d4f3574e
SS
2677Set a hardware-assisted breakpoint. @var{args} are the same as for the
2678@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2679breakpoint requires hardware support and some target hardware may not
2680have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2681debugging, so you can set a breakpoint at an instruction without
2682changing the instruction. This can be used with the new trap-generation
09d4efe1 2683provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2684will generate traps when a program accesses some data or instruction
2685address that is assigned to the debug registers. However the hardware
2686breakpoint registers can take a limited number of breakpoints. For
2687example, on the DSU, only two data breakpoints can be set at a time, and
2688@value{GDBN} will reject this command if more than two are used. Delete
2689or disable unused hardware breakpoints before setting new ones
2690(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2691For remote targets, you can restrict the number of hardware
2692breakpoints @value{GDBN} will use, see @ref{set remote
2693hardware-breakpoint-limit}.
501eef12 2694
c906108c
SS
2695
2696@kindex thbreak
2697@item thbreak @var{args}
2698Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2699are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2700the same way. However, like the @code{tbreak} command,
c906108c
SS
2701the breakpoint is automatically deleted after the
2702first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2703command, the breakpoint requires hardware support and some target hardware
2704may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2705See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2706
2707@kindex rbreak
2708@cindex regular expression
c45da7e6
EZ
2709@cindex breakpoints in functions matching a regexp
2710@cindex set breakpoints in many functions
c906108c 2711@item rbreak @var{regex}
c906108c 2712Set breakpoints on all functions matching the regular expression
11cf8741
JM
2713@var{regex}. This command sets an unconditional breakpoint on all
2714matches, printing a list of all breakpoints it set. Once these
2715breakpoints are set, they are treated just like the breakpoints set with
2716the @code{break} command. You can delete them, disable them, or make
2717them conditional the same way as any other breakpoint.
2718
2719The syntax of the regular expression is the standard one used with tools
2720like @file{grep}. Note that this is different from the syntax used by
2721shells, so for instance @code{foo*} matches all functions that include
2722an @code{fo} followed by zero or more @code{o}s. There is an implicit
2723@code{.*} leading and trailing the regular expression you supply, so to
2724match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2725
f7dc1244 2726@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2727When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2728breakpoints on overloaded functions that are not members of any special
2729classes.
c906108c 2730
f7dc1244
EZ
2731@cindex set breakpoints on all functions
2732The @code{rbreak} command can be used to set breakpoints in
2733@strong{all} the functions in a program, like this:
2734
2735@smallexample
2736(@value{GDBP}) rbreak .
2737@end smallexample
2738
c906108c
SS
2739@kindex info breakpoints
2740@cindex @code{$_} and @code{info breakpoints}
2741@item info breakpoints @r{[}@var{n}@r{]}
2742@itemx info break @r{[}@var{n}@r{]}
2743@itemx info watchpoints @r{[}@var{n}@r{]}
2744Print a table of all breakpoints, watchpoints, and catchpoints set and
2745not deleted, with the following columns for each breakpoint:
2746
2747@table @emph
2748@item Breakpoint Numbers
2749@item Type
2750Breakpoint, watchpoint, or catchpoint.
2751@item Disposition
2752Whether the breakpoint is marked to be disabled or deleted when hit.
2753@item Enabled or Disabled
2754Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2755that are not enabled.
2756@item Address
2650777c
JJ
2757Where the breakpoint is in your program, as a memory address. If the
2758breakpoint is pending (see below for details) on a future load of a shared library, the address
2759will be listed as @samp{<PENDING>}.
c906108c
SS
2760@item What
2761Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2762line number. For a pending breakpoint, the original string passed to
2763the breakpoint command will be listed as it cannot be resolved until
2764the appropriate shared library is loaded in the future.
c906108c
SS
2765@end table
2766
2767@noindent
2768If a breakpoint is conditional, @code{info break} shows the condition on
2769the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2770are listed after that. A pending breakpoint is allowed to have a condition
2771specified for it. The condition is not parsed for validity until a shared
2772library is loaded that allows the pending breakpoint to resolve to a
2773valid location.
c906108c
SS
2774
2775@noindent
2776@code{info break} with a breakpoint
2777number @var{n} as argument lists only that breakpoint. The
2778convenience variable @code{$_} and the default examining-address for
2779the @code{x} command are set to the address of the last breakpoint
5d161b24 2780listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2781
2782@noindent
2783@code{info break} displays a count of the number of times the breakpoint
2784has been hit. This is especially useful in conjunction with the
2785@code{ignore} command. You can ignore a large number of breakpoint
2786hits, look at the breakpoint info to see how many times the breakpoint
2787was hit, and then run again, ignoring one less than that number. This
2788will get you quickly to the last hit of that breakpoint.
2789@end table
2790
2791@value{GDBN} allows you to set any number of breakpoints at the same place in
2792your program. There is nothing silly or meaningless about this. When
2793the breakpoints are conditional, this is even useful
2794(@pxref{Conditions, ,Break conditions}).
2795
2650777c 2796@cindex pending breakpoints
dd79a6cf
JJ
2797If a specified breakpoint location cannot be found, it may be due to the fact
2798that the location is in a shared library that is yet to be loaded. In such
2799a case, you may want @value{GDBN} to create a special breakpoint (known as
2800a @dfn{pending breakpoint}) that
2801attempts to resolve itself in the future when an appropriate shared library
2802gets loaded.
2803
2804Pending breakpoints are useful to set at the start of your
2650777c
JJ
2805@value{GDBN} session for locations that you know will be dynamically loaded
2806later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2807a check is made to see if the load resolves any pending breakpoint locations.
2808If a pending breakpoint location gets resolved,
2809a regular breakpoint is created and the original pending breakpoint is removed.
2810
2811@value{GDBN} provides some additional commands for controlling pending
2812breakpoint support:
2813
2814@kindex set breakpoint pending
2815@kindex show breakpoint pending
2816@table @code
2817@item set breakpoint pending auto
2818This is the default behavior. When @value{GDBN} cannot find the breakpoint
2819location, it queries you whether a pending breakpoint should be created.
2820
2821@item set breakpoint pending on
2822This indicates that an unrecognized breakpoint location should automatically
2823result in a pending breakpoint being created.
2824
2825@item set breakpoint pending off
2826This indicates that pending breakpoints are not to be created. Any
2827unrecognized breakpoint location results in an error. This setting does
2828not affect any pending breakpoints previously created.
2829
2830@item show breakpoint pending
2831Show the current behavior setting for creating pending breakpoints.
2832@end table
2650777c 2833
649e03f6
RM
2834@cindex operations allowed on pending breakpoints
2835Normal breakpoint operations apply to pending breakpoints as well. You may
2836specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2837breakpoint is reached. You can also enable or disable
2838the pending breakpoint. When you specify a condition for a pending breakpoint,
2839the parsing of the condition will be deferred until the point where the
2840pending breakpoint location is resolved. Disabling a pending breakpoint
2841tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2842shared library load. When a pending breakpoint is re-enabled,
649e03f6 2843@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2844This is done because any number of shared library loads could have
2845occurred since the time the breakpoint was disabled and one or more
2846of these loads could resolve the location.
2847
c906108c
SS
2848@cindex negative breakpoint numbers
2849@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2850@value{GDBN} itself sometimes sets breakpoints in your program for
2851special purposes, such as proper handling of @code{longjmp} (in C
2852programs). These internal breakpoints are assigned negative numbers,
2853starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2854You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2855@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2856
2857
6d2ebf8b 2858@node Set Watchpoints
c906108c
SS
2859@subsection Setting watchpoints
2860
2861@cindex setting watchpoints
c906108c
SS
2862You can use a watchpoint to stop execution whenever the value of an
2863expression changes, without having to predict a particular place where
2864this may happen.
2865
82f2d802
EZ
2866@cindex software watchpoints
2867@cindex hardware watchpoints
c906108c 2868Depending on your system, watchpoints may be implemented in software or
2df3850c 2869hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2870program and testing the variable's value each time, which is hundreds of
2871times slower than normal execution. (But this may still be worth it, to
2872catch errors where you have no clue what part of your program is the
2873culprit.)
2874
82f2d802
EZ
2875On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2876x86-based targets, @value{GDBN} includes support for hardware
2877watchpoints, which do not slow down the running of your program.
c906108c
SS
2878
2879@table @code
2880@kindex watch
2881@item watch @var{expr}
2882Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2883is written into by the program and its value changes.
2884
2885@kindex rwatch
2886@item rwatch @var{expr}
09d4efe1
EZ
2887Set a watchpoint that will break when the value of @var{expr} is read
2888by the program.
c906108c
SS
2889
2890@kindex awatch
2891@item awatch @var{expr}
09d4efe1
EZ
2892Set a watchpoint that will break when @var{expr} is either read from
2893or written into by the program.
c906108c
SS
2894
2895@kindex info watchpoints
2896@item info watchpoints
2897This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2898it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2899@end table
2900
2901@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2902watchpoints execute very quickly, and the debugger reports a change in
2903value at the exact instruction where the change occurs. If @value{GDBN}
2904cannot set a hardware watchpoint, it sets a software watchpoint, which
2905executes more slowly and reports the change in value at the next
82f2d802
EZ
2906@emph{statement}, not the instruction, after the change occurs.
2907
82f2d802
EZ
2908@cindex use only software watchpoints
2909You can force @value{GDBN} to use only software watchpoints with the
2910@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2911zero, @value{GDBN} will never try to use hardware watchpoints, even if
2912the underlying system supports them. (Note that hardware-assisted
2913watchpoints that were set @emph{before} setting
2914@code{can-use-hw-watchpoints} to zero will still use the hardware
2915mechanism of watching expressiion values.)
c906108c 2916
9c16f35a
EZ
2917@table @code
2918@item set can-use-hw-watchpoints
2919@kindex set can-use-hw-watchpoints
2920Set whether or not to use hardware watchpoints.
2921
2922@item show can-use-hw-watchpoints
2923@kindex show can-use-hw-watchpoints
2924Show the current mode of using hardware watchpoints.
2925@end table
2926
2927For remote targets, you can restrict the number of hardware
2928watchpoints @value{GDBN} will use, see @ref{set remote
2929hardware-breakpoint-limit}.
2930
c906108c
SS
2931When you issue the @code{watch} command, @value{GDBN} reports
2932
474c8240 2933@smallexample
c906108c 2934Hardware watchpoint @var{num}: @var{expr}
474c8240 2935@end smallexample
c906108c
SS
2936
2937@noindent
2938if it was able to set a hardware watchpoint.
2939
7be570e7
JM
2940Currently, the @code{awatch} and @code{rwatch} commands can only set
2941hardware watchpoints, because accesses to data that don't change the
2942value of the watched expression cannot be detected without examining
2943every instruction as it is being executed, and @value{GDBN} does not do
2944that currently. If @value{GDBN} finds that it is unable to set a
2945hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2946will print a message like this:
2947
2948@smallexample
2949Expression cannot be implemented with read/access watchpoint.
2950@end smallexample
2951
2952Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2953data type of the watched expression is wider than what a hardware
2954watchpoint on the target machine can handle. For example, some systems
2955can only watch regions that are up to 4 bytes wide; on such systems you
2956cannot set hardware watchpoints for an expression that yields a
2957double-precision floating-point number (which is typically 8 bytes
2958wide). As a work-around, it might be possible to break the large region
2959into a series of smaller ones and watch them with separate watchpoints.
2960
2961If you set too many hardware watchpoints, @value{GDBN} might be unable
2962to insert all of them when you resume the execution of your program.
2963Since the precise number of active watchpoints is unknown until such
2964time as the program is about to be resumed, @value{GDBN} might not be
2965able to warn you about this when you set the watchpoints, and the
2966warning will be printed only when the program is resumed:
2967
2968@smallexample
2969Hardware watchpoint @var{num}: Could not insert watchpoint
2970@end smallexample
2971
2972@noindent
2973If this happens, delete or disable some of the watchpoints.
2974
2975The SPARClite DSU will generate traps when a program accesses some data
2976or instruction address that is assigned to the debug registers. For the
2977data addresses, DSU facilitates the @code{watch} command. However the
2978hardware breakpoint registers can only take two data watchpoints, and
2979both watchpoints must be the same kind. For example, you can set two
2980watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2981@strong{or} two with @code{awatch} commands, but you cannot set one
2982watchpoint with one command and the other with a different command.
c906108c
SS
2983@value{GDBN} will reject the command if you try to mix watchpoints.
2984Delete or disable unused watchpoint commands before setting new ones.
2985
2986If you call a function interactively using @code{print} or @code{call},
2df3850c 2987any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2988kind of breakpoint or the call completes.
2989
7be570e7
JM
2990@value{GDBN} automatically deletes watchpoints that watch local
2991(automatic) variables, or expressions that involve such variables, when
2992they go out of scope, that is, when the execution leaves the block in
2993which these variables were defined. In particular, when the program
2994being debugged terminates, @emph{all} local variables go out of scope,
2995and so only watchpoints that watch global variables remain set. If you
2996rerun the program, you will need to set all such watchpoints again. One
2997way of doing that would be to set a code breakpoint at the entry to the
2998@code{main} function and when it breaks, set all the watchpoints.
2999
c906108c
SS
3000@quotation
3001@cindex watchpoints and threads
3002@cindex threads and watchpoints
c906108c
SS
3003@emph{Warning:} In multi-thread programs, watchpoints have only limited
3004usefulness. With the current watchpoint implementation, @value{GDBN}
3005can only watch the value of an expression @emph{in a single thread}. If
3006you are confident that the expression can only change due to the current
3007thread's activity (and if you are also confident that no other thread
3008can become current), then you can use watchpoints as usual. However,
3009@value{GDBN} may not notice when a non-current thread's activity changes
3010the expression.
53a5351d 3011
d4f3574e 3012@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3013@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3014have only limited usefulness. If @value{GDBN} creates a software
3015watchpoint, it can only watch the value of an expression @emph{in a
3016single thread}. If you are confident that the expression can only
3017change due to the current thread's activity (and if you are also
3018confident that no other thread can become current), then you can use
3019software watchpoints as usual. However, @value{GDBN} may not notice
3020when a non-current thread's activity changes the expression. (Hardware
3021watchpoints, in contrast, watch an expression in all threads.)
c906108c 3022@end quotation
c906108c 3023
501eef12
AC
3024@xref{set remote hardware-watchpoint-limit}.
3025
6d2ebf8b 3026@node Set Catchpoints
c906108c 3027@subsection Setting catchpoints
d4f3574e 3028@cindex catchpoints, setting
c906108c
SS
3029@cindex exception handlers
3030@cindex event handling
3031
3032You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3033kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3034shared library. Use the @code{catch} command to set a catchpoint.
3035
3036@table @code
3037@kindex catch
3038@item catch @var{event}
3039Stop when @var{event} occurs. @var{event} can be any of the following:
3040@table @code
3041@item throw
4644b6e3 3042@cindex stop on C@t{++} exceptions
b37052ae 3043The throwing of a C@t{++} exception.
c906108c
SS
3044
3045@item catch
b37052ae 3046The catching of a C@t{++} exception.
c906108c
SS
3047
3048@item exec
4644b6e3 3049@cindex break on fork/exec
c906108c
SS
3050A call to @code{exec}. This is currently only available for HP-UX.
3051
3052@item fork
c906108c
SS
3053A call to @code{fork}. This is currently only available for HP-UX.
3054
3055@item vfork
c906108c
SS
3056A call to @code{vfork}. This is currently only available for HP-UX.
3057
3058@item load
3059@itemx load @var{libname}
4644b6e3 3060@cindex break on load/unload of shared library
c906108c
SS
3061The dynamic loading of any shared library, or the loading of the library
3062@var{libname}. This is currently only available for HP-UX.
3063
3064@item unload
3065@itemx unload @var{libname}
c906108c
SS
3066The unloading of any dynamically loaded shared library, or the unloading
3067of the library @var{libname}. This is currently only available for HP-UX.
3068@end table
3069
3070@item tcatch @var{event}
3071Set a catchpoint that is enabled only for one stop. The catchpoint is
3072automatically deleted after the first time the event is caught.
3073
3074@end table
3075
3076Use the @code{info break} command to list the current catchpoints.
3077
b37052ae 3078There are currently some limitations to C@t{++} exception handling
c906108c
SS
3079(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3080
3081@itemize @bullet
3082@item
3083If you call a function interactively, @value{GDBN} normally returns
3084control to you when the function has finished executing. If the call
3085raises an exception, however, the call may bypass the mechanism that
3086returns control to you and cause your program either to abort or to
3087simply continue running until it hits a breakpoint, catches a signal
3088that @value{GDBN} is listening for, or exits. This is the case even if
3089you set a catchpoint for the exception; catchpoints on exceptions are
3090disabled within interactive calls.
3091
3092@item
3093You cannot raise an exception interactively.
3094
3095@item
3096You cannot install an exception handler interactively.
3097@end itemize
3098
3099@cindex raise exceptions
3100Sometimes @code{catch} is not the best way to debug exception handling:
3101if you need to know exactly where an exception is raised, it is better to
3102stop @emph{before} the exception handler is called, since that way you
3103can see the stack before any unwinding takes place. If you set a
3104breakpoint in an exception handler instead, it may not be easy to find
3105out where the exception was raised.
3106
3107To stop just before an exception handler is called, you need some
b37052ae 3108knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3109raised by calling a library function named @code{__raise_exception}
3110which has the following ANSI C interface:
3111
474c8240 3112@smallexample
c906108c 3113 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3114 @var{id} is the exception identifier. */
3115 void __raise_exception (void **addr, void *id);
474c8240 3116@end smallexample
c906108c
SS
3117
3118@noindent
3119To make the debugger catch all exceptions before any stack
3120unwinding takes place, set a breakpoint on @code{__raise_exception}
3121(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3122
3123With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3124that depends on the value of @var{id}, you can stop your program when
3125a specific exception is raised. You can use multiple conditional
3126breakpoints to stop your program when any of a number of exceptions are
3127raised.
3128
3129
6d2ebf8b 3130@node Delete Breaks
c906108c
SS
3131@subsection Deleting breakpoints
3132
3133@cindex clearing breakpoints, watchpoints, catchpoints
3134@cindex deleting breakpoints, watchpoints, catchpoints
3135It is often necessary to eliminate a breakpoint, watchpoint, or
3136catchpoint once it has done its job and you no longer want your program
3137to stop there. This is called @dfn{deleting} the breakpoint. A
3138breakpoint that has been deleted no longer exists; it is forgotten.
3139
3140With the @code{clear} command you can delete breakpoints according to
3141where they are in your program. With the @code{delete} command you can
3142delete individual breakpoints, watchpoints, or catchpoints by specifying
3143their breakpoint numbers.
3144
3145It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3146automatically ignores breakpoints on the first instruction to be executed
3147when you continue execution without changing the execution address.
3148
3149@table @code
3150@kindex clear
3151@item clear
3152Delete any breakpoints at the next instruction to be executed in the
3153selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3154the innermost frame is selected, this is a good way to delete a
3155breakpoint where your program just stopped.
3156
3157@item clear @var{function}
3158@itemx clear @var{filename}:@var{function}
09d4efe1 3159Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3160
3161@item clear @var{linenum}
3162@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3163Delete any breakpoints set at or within the code of the specified
3164@var{linenum} of the specified @var{filename}.
c906108c
SS
3165
3166@cindex delete breakpoints
3167@kindex delete
41afff9a 3168@kindex d @r{(@code{delete})}
c5394b80
JM
3169@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3170Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3171ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3172breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3173confirm off}). You can abbreviate this command as @code{d}.
3174@end table
3175
6d2ebf8b 3176@node Disabling
c906108c
SS
3177@subsection Disabling breakpoints
3178
4644b6e3 3179@cindex enable/disable a breakpoint
c906108c
SS
3180Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3181prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3182it had been deleted, but remembers the information on the breakpoint so
3183that you can @dfn{enable} it again later.
3184
3185You disable and enable breakpoints, watchpoints, and catchpoints with
3186the @code{enable} and @code{disable} commands, optionally specifying one
3187or more breakpoint numbers as arguments. Use @code{info break} or
3188@code{info watch} to print a list of breakpoints, watchpoints, and
3189catchpoints if you do not know which numbers to use.
3190
3191A breakpoint, watchpoint, or catchpoint can have any of four different
3192states of enablement:
3193
3194@itemize @bullet
3195@item
3196Enabled. The breakpoint stops your program. A breakpoint set
3197with the @code{break} command starts out in this state.
3198@item
3199Disabled. The breakpoint has no effect on your program.
3200@item
3201Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3202disabled.
c906108c
SS
3203@item
3204Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3205immediately after it does so it is deleted permanently. A breakpoint
3206set with the @code{tbreak} command starts out in this state.
c906108c
SS
3207@end itemize
3208
3209You can use the following commands to enable or disable breakpoints,
3210watchpoints, and catchpoints:
3211
3212@table @code
c906108c 3213@kindex disable
41afff9a 3214@kindex dis @r{(@code{disable})}
c5394b80 3215@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3216Disable the specified breakpoints---or all breakpoints, if none are
3217listed. A disabled breakpoint has no effect but is not forgotten. All
3218options such as ignore-counts, conditions and commands are remembered in
3219case the breakpoint is enabled again later. You may abbreviate
3220@code{disable} as @code{dis}.
3221
c906108c 3222@kindex enable
c5394b80 3223@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3224Enable the specified breakpoints (or all defined breakpoints). They
3225become effective once again in stopping your program.
3226
c5394b80 3227@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3228Enable the specified breakpoints temporarily. @value{GDBN} disables any
3229of these breakpoints immediately after stopping your program.
3230
c5394b80 3231@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3232Enable the specified breakpoints to work once, then die. @value{GDBN}
3233deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3234Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3235@end table
3236
d4f3574e
SS
3237@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3238@c confusing: tbreak is also initially enabled.
c906108c
SS
3239Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3240,Setting breakpoints}), breakpoints that you set are initially enabled;
3241subsequently, they become disabled or enabled only when you use one of
3242the commands above. (The command @code{until} can set and delete a
3243breakpoint of its own, but it does not change the state of your other
3244breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3245stepping}.)
3246
6d2ebf8b 3247@node Conditions
c906108c
SS
3248@subsection Break conditions
3249@cindex conditional breakpoints
3250@cindex breakpoint conditions
3251
3252@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3253@c in particular for a watchpoint?
c906108c
SS
3254The simplest sort of breakpoint breaks every time your program reaches a
3255specified place. You can also specify a @dfn{condition} for a
3256breakpoint. A condition is just a Boolean expression in your
3257programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3258a condition evaluates the expression each time your program reaches it,
3259and your program stops only if the condition is @emph{true}.
3260
3261This is the converse of using assertions for program validation; in that
3262situation, you want to stop when the assertion is violated---that is,
3263when the condition is false. In C, if you want to test an assertion expressed
3264by the condition @var{assert}, you should set the condition
3265@samp{! @var{assert}} on the appropriate breakpoint.
3266
3267Conditions are also accepted for watchpoints; you may not need them,
3268since a watchpoint is inspecting the value of an expression anyhow---but
3269it might be simpler, say, to just set a watchpoint on a variable name,
3270and specify a condition that tests whether the new value is an interesting
3271one.
3272
3273Break conditions can have side effects, and may even call functions in
3274your program. This can be useful, for example, to activate functions
3275that log program progress, or to use your own print functions to
3276format special data structures. The effects are completely predictable
3277unless there is another enabled breakpoint at the same address. (In
3278that case, @value{GDBN} might see the other breakpoint first and stop your
3279program without checking the condition of this one.) Note that
d4f3574e
SS
3280breakpoint commands are usually more convenient and flexible than break
3281conditions for the
c906108c
SS
3282purpose of performing side effects when a breakpoint is reached
3283(@pxref{Break Commands, ,Breakpoint command lists}).
3284
3285Break conditions can be specified when a breakpoint is set, by using
3286@samp{if} in the arguments to the @code{break} command. @xref{Set
3287Breaks, ,Setting breakpoints}. They can also be changed at any time
3288with the @code{condition} command.
53a5351d 3289
c906108c
SS
3290You can also use the @code{if} keyword with the @code{watch} command.
3291The @code{catch} command does not recognize the @code{if} keyword;
3292@code{condition} is the only way to impose a further condition on a
3293catchpoint.
c906108c
SS
3294
3295@table @code
3296@kindex condition
3297@item condition @var{bnum} @var{expression}
3298Specify @var{expression} as the break condition for breakpoint,
3299watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3300breakpoint @var{bnum} stops your program only if the value of
3301@var{expression} is true (nonzero, in C). When you use
3302@code{condition}, @value{GDBN} checks @var{expression} immediately for
3303syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3304referents in the context of your breakpoint. If @var{expression} uses
3305symbols not referenced in the context of the breakpoint, @value{GDBN}
3306prints an error message:
3307
474c8240 3308@smallexample
d4f3574e 3309No symbol "foo" in current context.
474c8240 3310@end smallexample
d4f3574e
SS
3311
3312@noindent
c906108c
SS
3313@value{GDBN} does
3314not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3315command (or a command that sets a breakpoint with a condition, like
3316@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3317
3318@item condition @var{bnum}
3319Remove the condition from breakpoint number @var{bnum}. It becomes
3320an ordinary unconditional breakpoint.
3321@end table
3322
3323@cindex ignore count (of breakpoint)
3324A special case of a breakpoint condition is to stop only when the
3325breakpoint has been reached a certain number of times. This is so
3326useful that there is a special way to do it, using the @dfn{ignore
3327count} of the breakpoint. Every breakpoint has an ignore count, which
3328is an integer. Most of the time, the ignore count is zero, and
3329therefore has no effect. But if your program reaches a breakpoint whose
3330ignore count is positive, then instead of stopping, it just decrements
3331the ignore count by one and continues. As a result, if the ignore count
3332value is @var{n}, the breakpoint does not stop the next @var{n} times
3333your program reaches it.
3334
3335@table @code
3336@kindex ignore
3337@item ignore @var{bnum} @var{count}
3338Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3339The next @var{count} times the breakpoint is reached, your program's
3340execution does not stop; other than to decrement the ignore count, @value{GDBN}
3341takes no action.
3342
3343To make the breakpoint stop the next time it is reached, specify
3344a count of zero.
3345
3346When you use @code{continue} to resume execution of your program from a
3347breakpoint, you can specify an ignore count directly as an argument to
3348@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3349Stepping,,Continuing and stepping}.
3350
3351If a breakpoint has a positive ignore count and a condition, the
3352condition is not checked. Once the ignore count reaches zero,
3353@value{GDBN} resumes checking the condition.
3354
3355You could achieve the effect of the ignore count with a condition such
3356as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3357is decremented each time. @xref{Convenience Vars, ,Convenience
3358variables}.
3359@end table
3360
3361Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3362
3363
6d2ebf8b 3364@node Break Commands
c906108c
SS
3365@subsection Breakpoint command lists
3366
3367@cindex breakpoint commands
3368You can give any breakpoint (or watchpoint or catchpoint) a series of
3369commands to execute when your program stops due to that breakpoint. For
3370example, you might want to print the values of certain expressions, or
3371enable other breakpoints.
3372
3373@table @code
3374@kindex commands
3375@kindex end
3376@item commands @r{[}@var{bnum}@r{]}
3377@itemx @dots{} @var{command-list} @dots{}
3378@itemx end
3379Specify a list of commands for breakpoint number @var{bnum}. The commands
3380themselves appear on the following lines. Type a line containing just
3381@code{end} to terminate the commands.
3382
3383To remove all commands from a breakpoint, type @code{commands} and
3384follow it immediately with @code{end}; that is, give no commands.
3385
3386With no @var{bnum} argument, @code{commands} refers to the last
3387breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3388recently encountered).
3389@end table
3390
3391Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3392disabled within a @var{command-list}.
3393
3394You can use breakpoint commands to start your program up again. Simply
3395use the @code{continue} command, or @code{step}, or any other command
3396that resumes execution.
3397
3398Any other commands in the command list, after a command that resumes
3399execution, are ignored. This is because any time you resume execution
3400(even with a simple @code{next} or @code{step}), you may encounter
3401another breakpoint---which could have its own command list, leading to
3402ambiguities about which list to execute.
3403
3404@kindex silent
3405If the first command you specify in a command list is @code{silent}, the
3406usual message about stopping at a breakpoint is not printed. This may
3407be desirable for breakpoints that are to print a specific message and
3408then continue. If none of the remaining commands print anything, you
3409see no sign that the breakpoint was reached. @code{silent} is
3410meaningful only at the beginning of a breakpoint command list.
3411
3412The commands @code{echo}, @code{output}, and @code{printf} allow you to
3413print precisely controlled output, and are often useful in silent
3414breakpoints. @xref{Output, ,Commands for controlled output}.
3415
3416For example, here is how you could use breakpoint commands to print the
3417value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3418
474c8240 3419@smallexample
c906108c
SS
3420break foo if x>0
3421commands
3422silent
3423printf "x is %d\n",x
3424cont
3425end
474c8240 3426@end smallexample
c906108c
SS
3427
3428One application for breakpoint commands is to compensate for one bug so
3429you can test for another. Put a breakpoint just after the erroneous line
3430of code, give it a condition to detect the case in which something
3431erroneous has been done, and give it commands to assign correct values
3432to any variables that need them. End with the @code{continue} command
3433so that your program does not stop, and start with the @code{silent}
3434command so that no output is produced. Here is an example:
3435
474c8240 3436@smallexample
c906108c
SS
3437break 403
3438commands
3439silent
3440set x = y + 4
3441cont
3442end
474c8240 3443@end smallexample
c906108c 3444
6d2ebf8b 3445@node Breakpoint Menus
c906108c
SS
3446@subsection Breakpoint menus
3447@cindex overloading
3448@cindex symbol overloading
3449
b383017d 3450Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3451single function name
c906108c
SS
3452to be defined several times, for application in different contexts.
3453This is called @dfn{overloading}. When a function name is overloaded,
3454@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3455a breakpoint. If you realize this is a problem, you can use
3456something like @samp{break @var{function}(@var{types})} to specify which
3457particular version of the function you want. Otherwise, @value{GDBN} offers
3458you a menu of numbered choices for different possible breakpoints, and
3459waits for your selection with the prompt @samp{>}. The first two
3460options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3461sets a breakpoint at each definition of @var{function}, and typing
3462@kbd{0} aborts the @code{break} command without setting any new
3463breakpoints.
3464
3465For example, the following session excerpt shows an attempt to set a
3466breakpoint at the overloaded symbol @code{String::after}.
3467We choose three particular definitions of that function name:
3468
3469@c FIXME! This is likely to change to show arg type lists, at least
3470@smallexample
3471@group
3472(@value{GDBP}) b String::after
3473[0] cancel
3474[1] all
3475[2] file:String.cc; line number:867
3476[3] file:String.cc; line number:860
3477[4] file:String.cc; line number:875
3478[5] file:String.cc; line number:853
3479[6] file:String.cc; line number:846
3480[7] file:String.cc; line number:735
3481> 2 4 6
3482Breakpoint 1 at 0xb26c: file String.cc, line 867.
3483Breakpoint 2 at 0xb344: file String.cc, line 875.
3484Breakpoint 3 at 0xafcc: file String.cc, line 846.
3485Multiple breakpoints were set.
3486Use the "delete" command to delete unwanted
3487 breakpoints.
3488(@value{GDBP})
3489@end group
3490@end smallexample
c906108c
SS
3491
3492@c @ifclear BARETARGET
6d2ebf8b 3493@node Error in Breakpoints
d4f3574e 3494@subsection ``Cannot insert breakpoints''
c906108c
SS
3495@c
3496@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3497@c
d4f3574e
SS
3498Under some operating systems, breakpoints cannot be used in a program if
3499any other process is running that program. In this situation,
5d161b24 3500attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3501@value{GDBN} to print an error message:
3502
474c8240 3503@smallexample
d4f3574e
SS
3504Cannot insert breakpoints.
3505The same program may be running in another process.
474c8240 3506@end smallexample
d4f3574e
SS
3507
3508When this happens, you have three ways to proceed:
3509
3510@enumerate
3511@item
3512Remove or disable the breakpoints, then continue.
3513
3514@item
5d161b24 3515Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3516name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3517that @value{GDBN} should run your program under that name.
d4f3574e
SS
3518Then start your program again.
3519
3520@item
3521Relink your program so that the text segment is nonsharable, using the
3522linker option @samp{-N}. The operating system limitation may not apply
3523to nonsharable executables.
3524@end enumerate
c906108c
SS
3525@c @end ifclear
3526
d4f3574e
SS
3527A similar message can be printed if you request too many active
3528hardware-assisted breakpoints and watchpoints:
3529
3530@c FIXME: the precise wording of this message may change; the relevant
3531@c source change is not committed yet (Sep 3, 1999).
3532@smallexample
3533Stopped; cannot insert breakpoints.
3534You may have requested too many hardware breakpoints and watchpoints.
3535@end smallexample
3536
3537@noindent
3538This message is printed when you attempt to resume the program, since
3539only then @value{GDBN} knows exactly how many hardware breakpoints and
3540watchpoints it needs to insert.
3541
3542When this message is printed, you need to disable or remove some of the
3543hardware-assisted breakpoints and watchpoints, and then continue.
3544
1485d690
KB
3545@node Breakpoint related warnings
3546@subsection ``Breakpoint address adjusted...''
3547@cindex breakpoint address adjusted
3548
3549Some processor architectures place constraints on the addresses at
3550which breakpoints may be placed. For architectures thus constrained,
3551@value{GDBN} will attempt to adjust the breakpoint's address to comply
3552with the constraints dictated by the architecture.
3553
3554One example of such an architecture is the Fujitsu FR-V. The FR-V is
3555a VLIW architecture in which a number of RISC-like instructions may be
3556bundled together for parallel execution. The FR-V architecture
3557constrains the location of a breakpoint instruction within such a
3558bundle to the instruction with the lowest address. @value{GDBN}
3559honors this constraint by adjusting a breakpoint's address to the
3560first in the bundle.
3561
3562It is not uncommon for optimized code to have bundles which contain
3563instructions from different source statements, thus it may happen that
3564a breakpoint's address will be adjusted from one source statement to
3565another. Since this adjustment may significantly alter @value{GDBN}'s
3566breakpoint related behavior from what the user expects, a warning is
3567printed when the breakpoint is first set and also when the breakpoint
3568is hit.
3569
3570A warning like the one below is printed when setting a breakpoint
3571that's been subject to address adjustment:
3572
3573@smallexample
3574warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3575@end smallexample
3576
3577Such warnings are printed both for user settable and @value{GDBN}'s
3578internal breakpoints. If you see one of these warnings, you should
3579verify that a breakpoint set at the adjusted address will have the
3580desired affect. If not, the breakpoint in question may be removed and
b383017d 3581other breakpoints may be set which will have the desired behavior.
1485d690
KB
3582E.g., it may be sufficient to place the breakpoint at a later
3583instruction. A conditional breakpoint may also be useful in some
3584cases to prevent the breakpoint from triggering too often.
3585
3586@value{GDBN} will also issue a warning when stopping at one of these
3587adjusted breakpoints:
3588
3589@smallexample
3590warning: Breakpoint 1 address previously adjusted from 0x00010414
3591to 0x00010410.
3592@end smallexample
3593
3594When this warning is encountered, it may be too late to take remedial
3595action except in cases where the breakpoint is hit earlier or more
3596frequently than expected.
d4f3574e 3597
6d2ebf8b 3598@node Continuing and Stepping
c906108c
SS
3599@section Continuing and stepping
3600
3601@cindex stepping
3602@cindex continuing
3603@cindex resuming execution
3604@dfn{Continuing} means resuming program execution until your program
3605completes normally. In contrast, @dfn{stepping} means executing just
3606one more ``step'' of your program, where ``step'' may mean either one
3607line of source code, or one machine instruction (depending on what
7a292a7a
SS
3608particular command you use). Either when continuing or when stepping,
3609your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3610it stops due to a signal, you may want to use @code{handle}, or use
3611@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3612
3613@table @code
3614@kindex continue
41afff9a
EZ
3615@kindex c @r{(@code{continue})}
3616@kindex fg @r{(resume foreground execution)}
c906108c
SS
3617@item continue @r{[}@var{ignore-count}@r{]}
3618@itemx c @r{[}@var{ignore-count}@r{]}
3619@itemx fg @r{[}@var{ignore-count}@r{]}
3620Resume program execution, at the address where your program last stopped;
3621any breakpoints set at that address are bypassed. The optional argument
3622@var{ignore-count} allows you to specify a further number of times to
3623ignore a breakpoint at this location; its effect is like that of
3624@code{ignore} (@pxref{Conditions, ,Break conditions}).
3625
3626The argument @var{ignore-count} is meaningful only when your program
3627stopped due to a breakpoint. At other times, the argument to
3628@code{continue} is ignored.
3629
d4f3574e
SS
3630The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3631debugged program is deemed to be the foreground program) are provided
3632purely for convenience, and have exactly the same behavior as
3633@code{continue}.
c906108c
SS
3634@end table
3635
3636To resume execution at a different place, you can use @code{return}
3637(@pxref{Returning, ,Returning from a function}) to go back to the
3638calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3639different address}) to go to an arbitrary location in your program.
3640
3641A typical technique for using stepping is to set a breakpoint
3642(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3643beginning of the function or the section of your program where a problem
3644is believed to lie, run your program until it stops at that breakpoint,
3645and then step through the suspect area, examining the variables that are
3646interesting, until you see the problem happen.
3647
3648@table @code
3649@kindex step
41afff9a 3650@kindex s @r{(@code{step})}
c906108c
SS
3651@item step
3652Continue running your program until control reaches a different source
3653line, then stop it and return control to @value{GDBN}. This command is
3654abbreviated @code{s}.
3655
3656@quotation
3657@c "without debugging information" is imprecise; actually "without line
3658@c numbers in the debugging information". (gcc -g1 has debugging info but
3659@c not line numbers). But it seems complex to try to make that
3660@c distinction here.
3661@emph{Warning:} If you use the @code{step} command while control is
3662within a function that was compiled without debugging information,
3663execution proceeds until control reaches a function that does have
3664debugging information. Likewise, it will not step into a function which
3665is compiled without debugging information. To step through functions
3666without debugging information, use the @code{stepi} command, described
3667below.
3668@end quotation
3669
4a92d011
EZ
3670The @code{step} command only stops at the first instruction of a source
3671line. This prevents the multiple stops that could otherwise occur in
3672@code{switch} statements, @code{for} loops, etc. @code{step} continues
3673to stop if a function that has debugging information is called within
3674the line. In other words, @code{step} @emph{steps inside} any functions
3675called within the line.
c906108c 3676
d4f3574e
SS
3677Also, the @code{step} command only enters a function if there is line
3678number information for the function. Otherwise it acts like the
5d161b24 3679@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3680on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3681was any debugging information about the routine.
c906108c
SS
3682
3683@item step @var{count}
3684Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3685breakpoint is reached, or a signal not related to stepping occurs before
3686@var{count} steps, stepping stops right away.
c906108c
SS
3687
3688@kindex next
41afff9a 3689@kindex n @r{(@code{next})}
c906108c
SS
3690@item next @r{[}@var{count}@r{]}
3691Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3692This is similar to @code{step}, but function calls that appear within
3693the line of code are executed without stopping. Execution stops when
3694control reaches a different line of code at the original stack level
3695that was executing when you gave the @code{next} command. This command
3696is abbreviated @code{n}.
c906108c
SS
3697
3698An argument @var{count} is a repeat count, as for @code{step}.
3699
3700
3701@c FIX ME!! Do we delete this, or is there a way it fits in with
3702@c the following paragraph? --- Vctoria
3703@c
3704@c @code{next} within a function that lacks debugging information acts like
3705@c @code{step}, but any function calls appearing within the code of the
3706@c function are executed without stopping.
3707
d4f3574e
SS
3708The @code{next} command only stops at the first instruction of a
3709source line. This prevents multiple stops that could otherwise occur in
4a92d011 3710@code{switch} statements, @code{for} loops, etc.
c906108c 3711
b90a5f51
CF
3712@kindex set step-mode
3713@item set step-mode
3714@cindex functions without line info, and stepping
3715@cindex stepping into functions with no line info
3716@itemx set step-mode on
4a92d011 3717The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3718stop at the first instruction of a function which contains no debug line
3719information rather than stepping over it.
3720
4a92d011
EZ
3721This is useful in cases where you may be interested in inspecting the
3722machine instructions of a function which has no symbolic info and do not
3723want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3724
3725@item set step-mode off
4a92d011 3726Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3727debug information. This is the default.
3728
9c16f35a
EZ
3729@item show step-mode
3730Show whether @value{GDBN} will stop in or step over functions without
3731source line debug information.
3732
c906108c
SS
3733@kindex finish
3734@item finish
3735Continue running until just after function in the selected stack frame
3736returns. Print the returned value (if any).
3737
3738Contrast this with the @code{return} command (@pxref{Returning,
3739,Returning from a function}).
3740
3741@kindex until
41afff9a 3742@kindex u @r{(@code{until})}
09d4efe1 3743@cindex run until specified location
c906108c
SS
3744@item until
3745@itemx u
3746Continue running until a source line past the current line, in the
3747current stack frame, is reached. This command is used to avoid single
3748stepping through a loop more than once. It is like the @code{next}
3749command, except that when @code{until} encounters a jump, it
3750automatically continues execution until the program counter is greater
3751than the address of the jump.
3752
3753This means that when you reach the end of a loop after single stepping
3754though it, @code{until} makes your program continue execution until it
3755exits the loop. In contrast, a @code{next} command at the end of a loop
3756simply steps back to the beginning of the loop, which forces you to step
3757through the next iteration.
3758
3759@code{until} always stops your program if it attempts to exit the current
3760stack frame.
3761
3762@code{until} may produce somewhat counterintuitive results if the order
3763of machine code does not match the order of the source lines. For
3764example, in the following excerpt from a debugging session, the @code{f}
3765(@code{frame}) command shows that execution is stopped at line
3766@code{206}; yet when we use @code{until}, we get to line @code{195}:
3767
474c8240 3768@smallexample
c906108c
SS
3769(@value{GDBP}) f
3770#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3771206 expand_input();
3772(@value{GDBP}) until
3773195 for ( ; argc > 0; NEXTARG) @{
474c8240 3774@end smallexample
c906108c
SS
3775
3776This happened because, for execution efficiency, the compiler had
3777generated code for the loop closure test at the end, rather than the
3778start, of the loop---even though the test in a C @code{for}-loop is
3779written before the body of the loop. The @code{until} command appeared
3780to step back to the beginning of the loop when it advanced to this
3781expression; however, it has not really gone to an earlier
3782statement---not in terms of the actual machine code.
3783
3784@code{until} with no argument works by means of single
3785instruction stepping, and hence is slower than @code{until} with an
3786argument.
3787
3788@item until @var{location}
3789@itemx u @var{location}
3790Continue running your program until either the specified location is
3791reached, or the current stack frame returns. @var{location} is any of
3792the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3793,Setting breakpoints}). This form of the command uses breakpoints, and
3794hence is quicker than @code{until} without an argument. The specified
3795location is actually reached only if it is in the current frame. This
3796implies that @code{until} can be used to skip over recursive function
3797invocations. For instance in the code below, if the current location is
3798line @code{96}, issuing @code{until 99} will execute the program up to
3799line @code{99} in the same invocation of factorial, i.e. after the inner
3800invocations have returned.
3801
3802@smallexample
380394 int factorial (int value)
380495 @{
380596 if (value > 1) @{
380697 value *= factorial (value - 1);
380798 @}
380899 return (value);
3809100 @}
3810@end smallexample
3811
3812
3813@kindex advance @var{location}
3814@itemx advance @var{location}
09d4efe1
EZ
3815Continue running the program up to the given @var{location}. An argument is
3816required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3817command. Execution will also stop upon exit from the current stack
3818frame. This command is similar to @code{until}, but @code{advance} will
3819not skip over recursive function calls, and the target location doesn't
3820have to be in the same frame as the current one.
3821
c906108c
SS
3822
3823@kindex stepi
41afff9a 3824@kindex si @r{(@code{stepi})}
c906108c 3825@item stepi
96a2c332 3826@itemx stepi @var{arg}
c906108c
SS
3827@itemx si
3828Execute one machine instruction, then stop and return to the debugger.
3829
3830It is often useful to do @samp{display/i $pc} when stepping by machine
3831instructions. This makes @value{GDBN} automatically display the next
3832instruction to be executed, each time your program stops. @xref{Auto
3833Display,, Automatic display}.
3834
3835An argument is a repeat count, as in @code{step}.
3836
3837@need 750
3838@kindex nexti
41afff9a 3839@kindex ni @r{(@code{nexti})}
c906108c 3840@item nexti
96a2c332 3841@itemx nexti @var{arg}
c906108c
SS
3842@itemx ni
3843Execute one machine instruction, but if it is a function call,
3844proceed until the function returns.
3845
3846An argument is a repeat count, as in @code{next}.
3847@end table
3848
6d2ebf8b 3849@node Signals
c906108c
SS
3850@section Signals
3851@cindex signals
3852
3853A signal is an asynchronous event that can happen in a program. The
3854operating system defines the possible kinds of signals, and gives each
3855kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3856signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3857@code{SIGSEGV} is the signal a program gets from referencing a place in
3858memory far away from all the areas in use; @code{SIGALRM} occurs when
3859the alarm clock timer goes off (which happens only if your program has
3860requested an alarm).
3861
3862@cindex fatal signals
3863Some signals, including @code{SIGALRM}, are a normal part of the
3864functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3865errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3866program has not specified in advance some other way to handle the signal.
3867@code{SIGINT} does not indicate an error in your program, but it is normally
3868fatal so it can carry out the purpose of the interrupt: to kill the program.
3869
3870@value{GDBN} has the ability to detect any occurrence of a signal in your
3871program. You can tell @value{GDBN} in advance what to do for each kind of
3872signal.
3873
3874@cindex handling signals
24f93129
EZ
3875Normally, @value{GDBN} is set up to let the non-erroneous signals like
3876@code{SIGALRM} be silently passed to your program
3877(so as not to interfere with their role in the program's functioning)
c906108c
SS
3878but to stop your program immediately whenever an error signal happens.
3879You can change these settings with the @code{handle} command.
3880
3881@table @code
3882@kindex info signals
09d4efe1 3883@kindex info handle
c906108c 3884@item info signals
96a2c332 3885@itemx info handle
c906108c
SS
3886Print a table of all the kinds of signals and how @value{GDBN} has been told to
3887handle each one. You can use this to see the signal numbers of all
3888the defined types of signals.
3889
d4f3574e 3890@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3891
3892@kindex handle
3893@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3894Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3895can be the number of a signal or its name (with or without the
24f93129 3896@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3897@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3898known signals. The @var{keywords} say what change to make.
c906108c
SS
3899@end table
3900
3901@c @group
3902The keywords allowed by the @code{handle} command can be abbreviated.
3903Their full names are:
3904
3905@table @code
3906@item nostop
3907@value{GDBN} should not stop your program when this signal happens. It may
3908still print a message telling you that the signal has come in.
3909
3910@item stop
3911@value{GDBN} should stop your program when this signal happens. This implies
3912the @code{print} keyword as well.
3913
3914@item print
3915@value{GDBN} should print a message when this signal happens.
3916
3917@item noprint
3918@value{GDBN} should not mention the occurrence of the signal at all. This
3919implies the @code{nostop} keyword as well.
3920
3921@item pass
5ece1a18 3922@itemx noignore
c906108c
SS
3923@value{GDBN} should allow your program to see this signal; your program
3924can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3925and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3926
3927@item nopass
5ece1a18 3928@itemx ignore
c906108c 3929@value{GDBN} should not allow your program to see this signal.
5ece1a18 3930@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3931@end table
3932@c @end group
3933
d4f3574e
SS
3934When a signal stops your program, the signal is not visible to the
3935program until you
c906108c
SS
3936continue. Your program sees the signal then, if @code{pass} is in
3937effect for the signal in question @emph{at that time}. In other words,
3938after @value{GDBN} reports a signal, you can use the @code{handle}
3939command with @code{pass} or @code{nopass} to control whether your
3940program sees that signal when you continue.
3941
24f93129
EZ
3942The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3943non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3944@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3945erroneous signals.
3946
c906108c
SS
3947You can also use the @code{signal} command to prevent your program from
3948seeing a signal, or cause it to see a signal it normally would not see,
3949or to give it any signal at any time. For example, if your program stopped
3950due to some sort of memory reference error, you might store correct
3951values into the erroneous variables and continue, hoping to see more
3952execution; but your program would probably terminate immediately as
3953a result of the fatal signal once it saw the signal. To prevent this,
3954you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3955program a signal}.
c906108c 3956
6d2ebf8b 3957@node Thread Stops
c906108c
SS
3958@section Stopping and starting multi-thread programs
3959
3960When your program has multiple threads (@pxref{Threads,, Debugging
3961programs with multiple threads}), you can choose whether to set
3962breakpoints on all threads, or on a particular thread.
3963
3964@table @code
3965@cindex breakpoints and threads
3966@cindex thread breakpoints
3967@kindex break @dots{} thread @var{threadno}
3968@item break @var{linespec} thread @var{threadno}
3969@itemx break @var{linespec} thread @var{threadno} if @dots{}
3970@var{linespec} specifies source lines; there are several ways of
3971writing them, but the effect is always to specify some source line.
3972
3973Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3974to specify that you only want @value{GDBN} to stop the program when a
3975particular thread reaches this breakpoint. @var{threadno} is one of the
3976numeric thread identifiers assigned by @value{GDBN}, shown in the first
3977column of the @samp{info threads} display.
3978
3979If you do not specify @samp{thread @var{threadno}} when you set a
3980breakpoint, the breakpoint applies to @emph{all} threads of your
3981program.
3982
3983You can use the @code{thread} qualifier on conditional breakpoints as
3984well; in this case, place @samp{thread @var{threadno}} before the
3985breakpoint condition, like this:
3986
3987@smallexample
2df3850c 3988(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3989@end smallexample
3990
3991@end table
3992
3993@cindex stopped threads
3994@cindex threads, stopped
3995Whenever your program stops under @value{GDBN} for any reason,
3996@emph{all} threads of execution stop, not just the current thread. This
3997allows you to examine the overall state of the program, including
3998switching between threads, without worrying that things may change
3999underfoot.
4000
36d86913
MC
4001@cindex thread breakpoints and system calls
4002@cindex system calls and thread breakpoints
4003@cindex premature return from system calls
4004There is an unfortunate side effect. If one thread stops for a
4005breakpoint, or for some other reason, and another thread is blocked in a
4006system call, then the system call may return prematurely. This is a
4007consequence of the interaction between multiple threads and the signals
4008that @value{GDBN} uses to implement breakpoints and other events that
4009stop execution.
4010
4011To handle this problem, your program should check the return value of
4012each system call and react appropriately. This is good programming
4013style anyways.
4014
4015For example, do not write code like this:
4016
4017@smallexample
4018 sleep (10);
4019@end smallexample
4020
4021The call to @code{sleep} will return early if a different thread stops
4022at a breakpoint or for some other reason.
4023
4024Instead, write this:
4025
4026@smallexample
4027 int unslept = 10;
4028 while (unslept > 0)
4029 unslept = sleep (unslept);
4030@end smallexample
4031
4032A system call is allowed to return early, so the system is still
4033conforming to its specification. But @value{GDBN} does cause your
4034multi-threaded program to behave differently than it would without
4035@value{GDBN}.
4036
4037Also, @value{GDBN} uses internal breakpoints in the thread library to
4038monitor certain events such as thread creation and thread destruction.
4039When such an event happens, a system call in another thread may return
4040prematurely, even though your program does not appear to stop.
4041
c906108c
SS
4042@cindex continuing threads
4043@cindex threads, continuing
4044Conversely, whenever you restart the program, @emph{all} threads start
4045executing. @emph{This is true even when single-stepping} with commands
5d161b24 4046like @code{step} or @code{next}.
c906108c
SS
4047
4048In particular, @value{GDBN} cannot single-step all threads in lockstep.
4049Since thread scheduling is up to your debugging target's operating
4050system (not controlled by @value{GDBN}), other threads may
4051execute more than one statement while the current thread completes a
4052single step. Moreover, in general other threads stop in the middle of a
4053statement, rather than at a clean statement boundary, when the program
4054stops.
4055
4056You might even find your program stopped in another thread after
4057continuing or even single-stepping. This happens whenever some other
4058thread runs into a breakpoint, a signal, or an exception before the
4059first thread completes whatever you requested.
4060
4061On some OSes, you can lock the OS scheduler and thus allow only a single
4062thread to run.
4063
4064@table @code
4065@item set scheduler-locking @var{mode}
9c16f35a
EZ
4066@cindex scheduler locking mode
4067@cindex lock scheduler
c906108c
SS
4068Set the scheduler locking mode. If it is @code{off}, then there is no
4069locking and any thread may run at any time. If @code{on}, then only the
4070current thread may run when the inferior is resumed. The @code{step}
4071mode optimizes for single-stepping. It stops other threads from
4072``seizing the prompt'' by preempting the current thread while you are
4073stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4074when you step. They are more likely to run when you @samp{next} over a
c906108c 4075function call, and they are completely free to run when you use commands
d4f3574e 4076like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4077thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4078@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4079
4080@item show scheduler-locking
4081Display the current scheduler locking mode.
4082@end table
4083
c906108c 4084
6d2ebf8b 4085@node Stack
c906108c
SS
4086@chapter Examining the Stack
4087
4088When your program has stopped, the first thing you need to know is where it
4089stopped and how it got there.
4090
4091@cindex call stack
5d161b24
DB
4092Each time your program performs a function call, information about the call
4093is generated.
4094That information includes the location of the call in your program,
4095the arguments of the call,
c906108c 4096and the local variables of the function being called.
5d161b24 4097The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4098The stack frames are allocated in a region of memory called the @dfn{call
4099stack}.
4100
4101When your program stops, the @value{GDBN} commands for examining the
4102stack allow you to see all of this information.
4103
4104@cindex selected frame
4105One of the stack frames is @dfn{selected} by @value{GDBN} and many
4106@value{GDBN} commands refer implicitly to the selected frame. In
4107particular, whenever you ask @value{GDBN} for the value of a variable in
4108your program, the value is found in the selected frame. There are
4109special @value{GDBN} commands to select whichever frame you are
4110interested in. @xref{Selection, ,Selecting a frame}.
4111
4112When your program stops, @value{GDBN} automatically selects the
5d161b24 4113currently executing frame and describes it briefly, similar to the
c906108c
SS
4114@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4115
4116@menu
4117* Frames:: Stack frames
4118* Backtrace:: Backtraces
4119* Selection:: Selecting a frame
4120* Frame Info:: Information on a frame
c906108c
SS
4121
4122@end menu
4123
6d2ebf8b 4124@node Frames
c906108c
SS
4125@section Stack frames
4126
d4f3574e 4127@cindex frame, definition
c906108c
SS
4128@cindex stack frame
4129The call stack is divided up into contiguous pieces called @dfn{stack
4130frames}, or @dfn{frames} for short; each frame is the data associated
4131with one call to one function. The frame contains the arguments given
4132to the function, the function's local variables, and the address at
4133which the function is executing.
4134
4135@cindex initial frame
4136@cindex outermost frame
4137@cindex innermost frame
4138When your program is started, the stack has only one frame, that of the
4139function @code{main}. This is called the @dfn{initial} frame or the
4140@dfn{outermost} frame. Each time a function is called, a new frame is
4141made. Each time a function returns, the frame for that function invocation
4142is eliminated. If a function is recursive, there can be many frames for
4143the same function. The frame for the function in which execution is
4144actually occurring is called the @dfn{innermost} frame. This is the most
4145recently created of all the stack frames that still exist.
4146
4147@cindex frame pointer
4148Inside your program, stack frames are identified by their addresses. A
4149stack frame consists of many bytes, each of which has its own address; each
4150kind of computer has a convention for choosing one byte whose
4151address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4152in a register called the @dfn{frame pointer register}
4153(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4154
4155@cindex frame number
4156@value{GDBN} assigns numbers to all existing stack frames, starting with
4157zero for the innermost frame, one for the frame that called it,
4158and so on upward. These numbers do not really exist in your program;
4159they are assigned by @value{GDBN} to give you a way of designating stack
4160frames in @value{GDBN} commands.
4161
6d2ebf8b
SS
4162@c The -fomit-frame-pointer below perennially causes hbox overflow
4163@c underflow problems.
c906108c
SS
4164@cindex frameless execution
4165Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4166without stack frames. (For example, the @value{GCC} option
474c8240 4167@smallexample
6d2ebf8b 4168@samp{-fomit-frame-pointer}
474c8240 4169@end smallexample
6d2ebf8b 4170generates functions without a frame.)
c906108c
SS
4171This is occasionally done with heavily used library functions to save
4172the frame setup time. @value{GDBN} has limited facilities for dealing
4173with these function invocations. If the innermost function invocation
4174has no stack frame, @value{GDBN} nevertheless regards it as though
4175it had a separate frame, which is numbered zero as usual, allowing
4176correct tracing of the function call chain. However, @value{GDBN} has
4177no provision for frameless functions elsewhere in the stack.
4178
4179@table @code
d4f3574e 4180@kindex frame@r{, command}
41afff9a 4181@cindex current stack frame
c906108c 4182@item frame @var{args}
5d161b24 4183The @code{frame} command allows you to move from one stack frame to another,
c906108c 4184and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4185address of the frame or the stack frame number. Without an argument,
4186@code{frame} prints the current stack frame.
c906108c
SS
4187
4188@kindex select-frame
41afff9a 4189@cindex selecting frame silently
c906108c
SS
4190@item select-frame
4191The @code{select-frame} command allows you to move from one stack frame
4192to another without printing the frame. This is the silent version of
4193@code{frame}.
4194@end table
4195
6d2ebf8b 4196@node Backtrace
c906108c
SS
4197@section Backtraces
4198
09d4efe1
EZ
4199@cindex traceback
4200@cindex call stack traces
c906108c
SS
4201A backtrace is a summary of how your program got where it is. It shows one
4202line per frame, for many frames, starting with the currently executing
4203frame (frame zero), followed by its caller (frame one), and on up the
4204stack.
4205
4206@table @code
4207@kindex backtrace
41afff9a 4208@kindex bt @r{(@code{backtrace})}
c906108c
SS
4209@item backtrace
4210@itemx bt
4211Print a backtrace of the entire stack: one line per frame for all
4212frames in the stack.
4213
4214You can stop the backtrace at any time by typing the system interrupt
4215character, normally @kbd{C-c}.
4216
4217@item backtrace @var{n}
4218@itemx bt @var{n}
4219Similar, but print only the innermost @var{n} frames.
4220
4221@item backtrace -@var{n}
4222@itemx bt -@var{n}
4223Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4224
4225@item backtrace full
4226Print the values of the local variables also.
4227@itemx bt full
c906108c
SS
4228@end table
4229
4230@kindex where
4231@kindex info stack
c906108c
SS
4232The names @code{where} and @code{info stack} (abbreviated @code{info s})
4233are additional aliases for @code{backtrace}.
4234
4235Each line in the backtrace shows the frame number and the function name.
4236The program counter value is also shown---unless you use @code{set
4237print address off}. The backtrace also shows the source file name and
4238line number, as well as the arguments to the function. The program
4239counter value is omitted if it is at the beginning of the code for that
4240line number.
4241
4242Here is an example of a backtrace. It was made with the command
4243@samp{bt 3}, so it shows the innermost three frames.
4244
4245@smallexample
4246@group
5d161b24 4247#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4248 at builtin.c:993
4249#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4250#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4251 at macro.c:71
4252(More stack frames follow...)
4253@end group
4254@end smallexample
4255
4256@noindent
4257The display for frame zero does not begin with a program counter
4258value, indicating that your program has stopped at the beginning of the
4259code for line @code{993} of @code{builtin.c}.
4260
18999be5
EZ
4261@cindex value optimized out, in backtrace
4262@cindex function call arguments, optimized out
4263If your program was compiled with optimizations, some compilers will
4264optimize away arguments passed to functions if those arguments are
4265never used after the call. Such optimizations generate code that
4266passes arguments through registers, but doesn't store those arguments
4267in the stack frame. @value{GDBN} has no way of displaying such
4268arguments in stack frames other than the innermost one. Here's what
4269such a backtrace might look like:
4270
4271@smallexample
4272@group
4273#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4274 at builtin.c:993
4275#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4276#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4277 at macro.c:71
4278(More stack frames follow...)
4279@end group
4280@end smallexample
4281
4282@noindent
4283The values of arguments that were not saved in their stack frames are
4284shown as @samp{<value optimized out>}.
4285
4286If you need to display the values of such optimized-out arguments,
4287either deduce that from other variables whose values depend on the one
4288you are interested in, or recompile without optimizations.
4289
a8f24a35
EZ
4290@cindex backtrace beyond @code{main} function
4291@cindex program entry point
4292@cindex startup code, and backtrace
25d29d70
AC
4293Most programs have a standard user entry point---a place where system
4294libraries and startup code transition into user code. For C this is
4295@code{main}. When @value{GDBN} finds the entry function in a backtrace
4296it will terminate the backtrace, to avoid tracing into highly
4297system-specific (and generally uninteresting) code.
4298
4299If you need to examine the startup code, or limit the number of levels
4300in a backtrace, you can change this behavior:
95f90d25
DJ
4301
4302@table @code
25d29d70
AC
4303@item set backtrace past-main
4304@itemx set backtrace past-main on
4644b6e3 4305@kindex set backtrace
25d29d70
AC
4306Backtraces will continue past the user entry point.
4307
4308@item set backtrace past-main off
95f90d25
DJ
4309Backtraces will stop when they encounter the user entry point. This is the
4310default.
4311
25d29d70 4312@item show backtrace past-main
4644b6e3 4313@kindex show backtrace
25d29d70
AC
4314Display the current user entry point backtrace policy.
4315
2315ffec
RC
4316@item set backtrace past-entry
4317@itemx set backtrace past-entry on
a8f24a35 4318Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4319This entry point is encoded by the linker when the application is built,
4320and is likely before the user entry point @code{main} (or equivalent) is called.
4321
4322@item set backtrace past-entry off
4323Backtraces will stop when they encouter the internal entry point of an
4324application. This is the default.
4325
4326@item show backtrace past-entry
4327Display the current internal entry point backtrace policy.
4328
25d29d70
AC
4329@item set backtrace limit @var{n}
4330@itemx set backtrace limit 0
4331@cindex backtrace limit
4332Limit the backtrace to @var{n} levels. A value of zero means
4333unlimited.
95f90d25 4334
25d29d70
AC
4335@item show backtrace limit
4336Display the current limit on backtrace levels.
95f90d25
DJ
4337@end table
4338
6d2ebf8b 4339@node Selection
c906108c
SS
4340@section Selecting a frame
4341
4342Most commands for examining the stack and other data in your program work on
4343whichever stack frame is selected at the moment. Here are the commands for
4344selecting a stack frame; all of them finish by printing a brief description
4345of the stack frame just selected.
4346
4347@table @code
d4f3574e 4348@kindex frame@r{, selecting}
41afff9a 4349@kindex f @r{(@code{frame})}
c906108c
SS
4350@item frame @var{n}
4351@itemx f @var{n}
4352Select frame number @var{n}. Recall that frame zero is the innermost
4353(currently executing) frame, frame one is the frame that called the
4354innermost one, and so on. The highest-numbered frame is the one for
4355@code{main}.
4356
4357@item frame @var{addr}
4358@itemx f @var{addr}
4359Select the frame at address @var{addr}. This is useful mainly if the
4360chaining of stack frames has been damaged by a bug, making it
4361impossible for @value{GDBN} to assign numbers properly to all frames. In
4362addition, this can be useful when your program has multiple stacks and
4363switches between them.
4364
c906108c
SS
4365On the SPARC architecture, @code{frame} needs two addresses to
4366select an arbitrary frame: a frame pointer and a stack pointer.
4367
4368On the MIPS and Alpha architecture, it needs two addresses: a stack
4369pointer and a program counter.
4370
4371On the 29k architecture, it needs three addresses: a register stack
4372pointer, a program counter, and a memory stack pointer.
4373@c note to future updaters: this is conditioned on a flag
4374@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4375@c as of 27 Jan 1994.
c906108c
SS
4376
4377@kindex up
4378@item up @var{n}
4379Move @var{n} frames up the stack. For positive numbers @var{n}, this
4380advances toward the outermost frame, to higher frame numbers, to frames
4381that have existed longer. @var{n} defaults to one.
4382
4383@kindex down
41afff9a 4384@kindex do @r{(@code{down})}
c906108c
SS
4385@item down @var{n}
4386Move @var{n} frames down the stack. For positive numbers @var{n}, this
4387advances toward the innermost frame, to lower frame numbers, to frames
4388that were created more recently. @var{n} defaults to one. You may
4389abbreviate @code{down} as @code{do}.
4390@end table
4391
4392All of these commands end by printing two lines of output describing the
4393frame. The first line shows the frame number, the function name, the
4394arguments, and the source file and line number of execution in that
5d161b24 4395frame. The second line shows the text of that source line.
c906108c
SS
4396
4397@need 1000
4398For example:
4399
4400@smallexample
4401@group
4402(@value{GDBP}) up
4403#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4404 at env.c:10
440510 read_input_file (argv[i]);
4406@end group
4407@end smallexample
4408
4409After such a printout, the @code{list} command with no arguments
4410prints ten lines centered on the point of execution in the frame.
87885426
FN
4411You can also edit the program at the point of execution with your favorite
4412editing program by typing @code{edit}.
4413@xref{List, ,Printing source lines},
4414for details.
c906108c
SS
4415
4416@table @code
4417@kindex down-silently
4418@kindex up-silently
4419@item up-silently @var{n}
4420@itemx down-silently @var{n}
4421These two commands are variants of @code{up} and @code{down},
4422respectively; they differ in that they do their work silently, without
4423causing display of the new frame. They are intended primarily for use
4424in @value{GDBN} command scripts, where the output might be unnecessary and
4425distracting.
4426@end table
4427
6d2ebf8b 4428@node Frame Info
c906108c
SS
4429@section Information about a frame
4430
4431There are several other commands to print information about the selected
4432stack frame.
4433
4434@table @code
4435@item frame
4436@itemx f
4437When used without any argument, this command does not change which
4438frame is selected, but prints a brief description of the currently
4439selected stack frame. It can be abbreviated @code{f}. With an
4440argument, this command is used to select a stack frame.
4441@xref{Selection, ,Selecting a frame}.
4442
4443@kindex info frame
41afff9a 4444@kindex info f @r{(@code{info frame})}
c906108c
SS
4445@item info frame
4446@itemx info f
4447This command prints a verbose description of the selected stack frame,
4448including:
4449
4450@itemize @bullet
5d161b24
DB
4451@item
4452the address of the frame
c906108c
SS
4453@item
4454the address of the next frame down (called by this frame)
4455@item
4456the address of the next frame up (caller of this frame)
4457@item
4458the language in which the source code corresponding to this frame is written
4459@item
4460the address of the frame's arguments
4461@item
d4f3574e
SS
4462the address of the frame's local variables
4463@item
c906108c
SS
4464the program counter saved in it (the address of execution in the caller frame)
4465@item
4466which registers were saved in the frame
4467@end itemize
4468
4469@noindent The verbose description is useful when
4470something has gone wrong that has made the stack format fail to fit
4471the usual conventions.
4472
4473@item info frame @var{addr}
4474@itemx info f @var{addr}
4475Print a verbose description of the frame at address @var{addr}, without
4476selecting that frame. The selected frame remains unchanged by this
4477command. This requires the same kind of address (more than one for some
4478architectures) that you specify in the @code{frame} command.
4479@xref{Selection, ,Selecting a frame}.
4480
4481@kindex info args
4482@item info args
4483Print the arguments of the selected frame, each on a separate line.
4484
4485@item info locals
4486@kindex info locals
4487Print the local variables of the selected frame, each on a separate
4488line. These are all variables (declared either static or automatic)
4489accessible at the point of execution of the selected frame.
4490
c906108c 4491@kindex info catch
d4f3574e
SS
4492@cindex catch exceptions, list active handlers
4493@cindex exception handlers, how to list
c906108c
SS
4494@item info catch
4495Print a list of all the exception handlers that are active in the
4496current stack frame at the current point of execution. To see other
4497exception handlers, visit the associated frame (using the @code{up},
4498@code{down}, or @code{frame} commands); then type @code{info catch}.
4499@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4500
c906108c
SS
4501@end table
4502
c906108c 4503
6d2ebf8b 4504@node Source
c906108c
SS
4505@chapter Examining Source Files
4506
4507@value{GDBN} can print parts of your program's source, since the debugging
4508information recorded in the program tells @value{GDBN} what source files were
4509used to build it. When your program stops, @value{GDBN} spontaneously prints
4510the line where it stopped. Likewise, when you select a stack frame
4511(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4512execution in that frame has stopped. You can print other portions of
4513source files by explicit command.
4514
7a292a7a 4515If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4516prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4517@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4518
4519@menu
4520* List:: Printing source lines
87885426 4521* Edit:: Editing source files
c906108c 4522* Search:: Searching source files
c906108c
SS
4523* Source Path:: Specifying source directories
4524* Machine Code:: Source and machine code
4525@end menu
4526
6d2ebf8b 4527@node List
c906108c
SS
4528@section Printing source lines
4529
4530@kindex list
41afff9a 4531@kindex l @r{(@code{list})}
c906108c 4532To print lines from a source file, use the @code{list} command
5d161b24 4533(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4534There are several ways to specify what part of the file you want to print.
4535
4536Here are the forms of the @code{list} command most commonly used:
4537
4538@table @code
4539@item list @var{linenum}
4540Print lines centered around line number @var{linenum} in the
4541current source file.
4542
4543@item list @var{function}
4544Print lines centered around the beginning of function
4545@var{function}.
4546
4547@item list
4548Print more lines. If the last lines printed were printed with a
4549@code{list} command, this prints lines following the last lines
4550printed; however, if the last line printed was a solitary line printed
4551as part of displaying a stack frame (@pxref{Stack, ,Examining the
4552Stack}), this prints lines centered around that line.
4553
4554@item list -
4555Print lines just before the lines last printed.
4556@end table
4557
9c16f35a 4558@cindex @code{list}, how many lines to display
c906108c
SS
4559By default, @value{GDBN} prints ten source lines with any of these forms of
4560the @code{list} command. You can change this using @code{set listsize}:
4561
4562@table @code
4563@kindex set listsize
4564@item set listsize @var{count}
4565Make the @code{list} command display @var{count} source lines (unless
4566the @code{list} argument explicitly specifies some other number).
4567
4568@kindex show listsize
4569@item show listsize
4570Display the number of lines that @code{list} prints.
4571@end table
4572
4573Repeating a @code{list} command with @key{RET} discards the argument,
4574so it is equivalent to typing just @code{list}. This is more useful
4575than listing the same lines again. An exception is made for an
4576argument of @samp{-}; that argument is preserved in repetition so that
4577each repetition moves up in the source file.
4578
4579@cindex linespec
4580In general, the @code{list} command expects you to supply zero, one or two
4581@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4582of writing them, but the effect is always to specify some source line.
c906108c
SS
4583Here is a complete description of the possible arguments for @code{list}:
4584
4585@table @code
4586@item list @var{linespec}
4587Print lines centered around the line specified by @var{linespec}.
4588
4589@item list @var{first},@var{last}
4590Print lines from @var{first} to @var{last}. Both arguments are
4591linespecs.
4592
4593@item list ,@var{last}
4594Print lines ending with @var{last}.
4595
4596@item list @var{first},
4597Print lines starting with @var{first}.
4598
4599@item list +
4600Print lines just after the lines last printed.
4601
4602@item list -
4603Print lines just before the lines last printed.
4604
4605@item list
4606As described in the preceding table.
4607@end table
4608
4609Here are the ways of specifying a single source line---all the
4610kinds of linespec.
4611
4612@table @code
4613@item @var{number}
4614Specifies line @var{number} of the current source file.
4615When a @code{list} command has two linespecs, this refers to
4616the same source file as the first linespec.
4617
4618@item +@var{offset}
4619Specifies the line @var{offset} lines after the last line printed.
4620When used as the second linespec in a @code{list} command that has
4621two, this specifies the line @var{offset} lines down from the
4622first linespec.
4623
4624@item -@var{offset}
4625Specifies the line @var{offset} lines before the last line printed.
4626
4627@item @var{filename}:@var{number}
4628Specifies line @var{number} in the source file @var{filename}.
4629
4630@item @var{function}
4631Specifies the line that begins the body of the function @var{function}.
4632For example: in C, this is the line with the open brace.
4633
4634@item @var{filename}:@var{function}
4635Specifies the line of the open-brace that begins the body of the
4636function @var{function} in the file @var{filename}. You only need the
4637file name with a function name to avoid ambiguity when there are
4638identically named functions in different source files.
4639
4640@item *@var{address}
4641Specifies the line containing the program address @var{address}.
4642@var{address} may be any expression.
4643@end table
4644
87885426
FN
4645@node Edit
4646@section Editing source files
4647@cindex editing source files
4648
4649@kindex edit
4650@kindex e @r{(@code{edit})}
4651To edit the lines in a source file, use the @code{edit} command.
4652The editing program of your choice
4653is invoked with the current line set to
4654the active line in the program.
4655Alternatively, there are several ways to specify what part of the file you
4656want to print if you want to see other parts of the program.
4657
4658Here are the forms of the @code{edit} command most commonly used:
4659
4660@table @code
4661@item edit
4662Edit the current source file at the active line number in the program.
4663
4664@item edit @var{number}
4665Edit the current source file with @var{number} as the active line number.
4666
4667@item edit @var{function}
4668Edit the file containing @var{function} at the beginning of its definition.
4669
4670@item edit @var{filename}:@var{number}
4671Specifies line @var{number} in the source file @var{filename}.
4672
4673@item edit @var{filename}:@var{function}
4674Specifies the line that begins the body of the
4675function @var{function} in the file @var{filename}. You only need the
4676file name with a function name to avoid ambiguity when there are
4677identically named functions in different source files.
4678
4679@item edit *@var{address}
4680Specifies the line containing the program address @var{address}.
4681@var{address} may be any expression.
4682@end table
4683
4684@subsection Choosing your editor
4685You can customize @value{GDBN} to use any editor you want
4686@footnote{
4687The only restriction is that your editor (say @code{ex}), recognizes the
4688following command-line syntax:
10998722 4689@smallexample
87885426 4690ex +@var{number} file
10998722 4691@end smallexample
15387254
EZ
4692The optional numeric value +@var{number} specifies the number of the line in
4693the file where to start editing.}.
4694By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4695by setting the environment variable @code{EDITOR} before using
4696@value{GDBN}. For example, to configure @value{GDBN} to use the
4697@code{vi} editor, you could use these commands with the @code{sh} shell:
4698@smallexample
87885426
FN
4699EDITOR=/usr/bin/vi
4700export EDITOR
15387254 4701gdb @dots{}
10998722 4702@end smallexample
87885426 4703or in the @code{csh} shell,
10998722 4704@smallexample
87885426 4705setenv EDITOR /usr/bin/vi
15387254 4706gdb @dots{}
10998722 4707@end smallexample
87885426 4708
6d2ebf8b 4709@node Search
c906108c 4710@section Searching source files
15387254 4711@cindex searching source files
c906108c
SS
4712
4713There are two commands for searching through the current source file for a
4714regular expression.
4715
4716@table @code
4717@kindex search
4718@kindex forward-search
4719@item forward-search @var{regexp}
4720@itemx search @var{regexp}
4721The command @samp{forward-search @var{regexp}} checks each line,
4722starting with the one following the last line listed, for a match for
5d161b24 4723@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4724synonym @samp{search @var{regexp}} or abbreviate the command name as
4725@code{fo}.
4726
09d4efe1 4727@kindex reverse-search
c906108c
SS
4728@item reverse-search @var{regexp}
4729The command @samp{reverse-search @var{regexp}} checks each line, starting
4730with the one before the last line listed and going backward, for a match
4731for @var{regexp}. It lists the line that is found. You can abbreviate
4732this command as @code{rev}.
4733@end table
c906108c 4734
6d2ebf8b 4735@node Source Path
c906108c
SS
4736@section Specifying source directories
4737
4738@cindex source path
4739@cindex directories for source files
4740Executable programs sometimes do not record the directories of the source
4741files from which they were compiled, just the names. Even when they do,
4742the directories could be moved between the compilation and your debugging
4743session. @value{GDBN} has a list of directories to search for source files;
4744this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4745it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4746in the list, until it finds a file with the desired name.
4747
4748For example, suppose an executable references the file
4749@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4750@file{/mnt/cross}. The file is first looked up literally; if this
4751fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4752fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4753message is printed. @value{GDBN} does not look up the parts of the
4754source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4755Likewise, the subdirectories of the source path are not searched: if
4756the source path is @file{/mnt/cross}, and the binary refers to
4757@file{foo.c}, @value{GDBN} would not find it under
4758@file{/mnt/cross/usr/src/foo-1.0/lib}.
4759
4760Plain file names, relative file names with leading directories, file
4761names containing dots, etc.@: are all treated as described above; for
4762instance, if the source path is @file{/mnt/cross}, and the source file
4763is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4764@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4765that---@file{/mnt/cross/foo.c}.
4766
4767Note that the executable search path is @emph{not} used to locate the
4768source files. Neither is the current working directory, unless it
4769happens to be in the source path.
c906108c
SS
4770
4771Whenever you reset or rearrange the source path, @value{GDBN} clears out
4772any information it has cached about where source files are found and where
4773each line is in the file.
4774
4775@kindex directory
4776@kindex dir
d4f3574e
SS
4777When you start @value{GDBN}, its source path includes only @samp{cdir}
4778and @samp{cwd}, in that order.
c906108c
SS
4779To add other directories, use the @code{directory} command.
4780
4781@table @code
4782@item directory @var{dirname} @dots{}
4783@item dir @var{dirname} @dots{}
4784Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4785directory names may be given to this command, separated by @samp{:}
4786(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4787part of absolute file names) or
c906108c
SS
4788whitespace. You may specify a directory that is already in the source
4789path; this moves it forward, so @value{GDBN} searches it sooner.
4790
4791@kindex cdir
4792@kindex cwd
41afff9a
EZ
4793@vindex $cdir@r{, convenience variable}
4794@vindex $cwdr@r{, convenience variable}
c906108c
SS
4795@cindex compilation directory
4796@cindex current directory
4797@cindex working directory
4798@cindex directory, current
4799@cindex directory, compilation
4800You can use the string @samp{$cdir} to refer to the compilation
4801directory (if one is recorded), and @samp{$cwd} to refer to the current
4802working directory. @samp{$cwd} is not the same as @samp{.}---the former
4803tracks the current working directory as it changes during your @value{GDBN}
4804session, while the latter is immediately expanded to the current
4805directory at the time you add an entry to the source path.
4806
4807@item directory
4808Reset the source path to empty again. This requires confirmation.
4809
4810@c RET-repeat for @code{directory} is explicitly disabled, but since
4811@c repeating it would be a no-op we do not say that. (thanks to RMS)
4812
4813@item show directories
4814@kindex show directories
4815Print the source path: show which directories it contains.
4816@end table
4817
4818If your source path is cluttered with directories that are no longer of
4819interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4820versions of source. You can correct the situation as follows:
4821
4822@enumerate
4823@item
4824Use @code{directory} with no argument to reset the source path to empty.
4825
4826@item
4827Use @code{directory} with suitable arguments to reinstall the
4828directories you want in the source path. You can add all the
4829directories in one command.
4830@end enumerate
4831
6d2ebf8b 4832@node Machine Code
c906108c 4833@section Source and machine code
15387254 4834@cindex source line and its code address
c906108c
SS
4835
4836You can use the command @code{info line} to map source lines to program
4837addresses (and vice versa), and the command @code{disassemble} to display
4838a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4839mode, the @code{info line} command causes the arrow to point to the
5d161b24 4840line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4841well as hex.
4842
4843@table @code
4844@kindex info line
4845@item info line @var{linespec}
4846Print the starting and ending addresses of the compiled code for
4847source line @var{linespec}. You can specify source lines in any of
4848the ways understood by the @code{list} command (@pxref{List, ,Printing
4849source lines}).
4850@end table
4851
4852For example, we can use @code{info line} to discover the location of
4853the object code for the first line of function
4854@code{m4_changequote}:
4855
d4f3574e
SS
4856@c FIXME: I think this example should also show the addresses in
4857@c symbolic form, as they usually would be displayed.
c906108c 4858@smallexample
96a2c332 4859(@value{GDBP}) info line m4_changequote
c906108c
SS
4860Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4861@end smallexample
4862
4863@noindent
15387254 4864@cindex code address and its source line
c906108c
SS
4865We can also inquire (using @code{*@var{addr}} as the form for
4866@var{linespec}) what source line covers a particular address:
4867@smallexample
4868(@value{GDBP}) info line *0x63ff
4869Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4870@end smallexample
4871
4872@cindex @code{$_} and @code{info line}
15387254 4873@cindex @code{x} command, default address
41afff9a 4874@kindex x@r{(examine), and} info line
c906108c
SS
4875After @code{info line}, the default address for the @code{x} command
4876is changed to the starting address of the line, so that @samp{x/i} is
4877sufficient to begin examining the machine code (@pxref{Memory,
4878,Examining memory}). Also, this address is saved as the value of the
4879convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4880variables}).
4881
4882@table @code
4883@kindex disassemble
4884@cindex assembly instructions
4885@cindex instructions, assembly
4886@cindex machine instructions
4887@cindex listing machine instructions
4888@item disassemble
4889This specialized command dumps a range of memory as machine
4890instructions. The default memory range is the function surrounding the
4891program counter of the selected frame. A single argument to this
4892command is a program counter value; @value{GDBN} dumps the function
4893surrounding this value. Two arguments specify a range of addresses
4894(first inclusive, second exclusive) to dump.
4895@end table
4896
c906108c
SS
4897The following example shows the disassembly of a range of addresses of
4898HP PA-RISC 2.0 code:
4899
4900@smallexample
4901(@value{GDBP}) disas 0x32c4 0x32e4
4902Dump of assembler code from 0x32c4 to 0x32e4:
49030x32c4 <main+204>: addil 0,dp
49040x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49050x32cc <main+212>: ldil 0x3000,r31
49060x32d0 <main+216>: ble 0x3f8(sr4,r31)
49070x32d4 <main+220>: ldo 0(r31),rp
49080x32d8 <main+224>: addil -0x800,dp
49090x32dc <main+228>: ldo 0x588(r1),r26
49100x32e0 <main+232>: ldil 0x3000,r31
4911End of assembler dump.
4912@end smallexample
c906108c
SS
4913
4914Some architectures have more than one commonly-used set of instruction
4915mnemonics or other syntax.
4916
4917@table @code
d4f3574e 4918@kindex set disassembly-flavor
d4f3574e
SS
4919@cindex Intel disassembly flavor
4920@cindex AT&T disassembly flavor
4921@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4922Select the instruction set to use when disassembling the
4923program via the @code{disassemble} or @code{x/i} commands.
4924
4925Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4926can set @var{instruction-set} to either @code{intel} or @code{att}.
4927The default is @code{att}, the AT&T flavor used by default by Unix
4928assemblers for x86-based targets.
9c16f35a
EZ
4929
4930@kindex show disassembly-flavor
4931@item show disassembly-flavor
4932Show the current setting of the disassembly flavor.
c906108c
SS
4933@end table
4934
4935
6d2ebf8b 4936@node Data
c906108c
SS
4937@chapter Examining Data
4938
4939@cindex printing data
4940@cindex examining data
4941@kindex print
4942@kindex inspect
4943@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4944@c document because it is nonstandard... Under Epoch it displays in a
4945@c different window or something like that.
4946The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4947command (abbreviated @code{p}), or its synonym @code{inspect}. It
4948evaluates and prints the value of an expression of the language your
4949program is written in (@pxref{Languages, ,Using @value{GDBN} with
4950Different Languages}).
c906108c
SS
4951
4952@table @code
d4f3574e
SS
4953@item print @var{expr}
4954@itemx print /@var{f} @var{expr}
4955@var{expr} is an expression (in the source language). By default the
4956value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4957you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4958@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4959formats}.
4960
4961@item print
4962@itemx print /@var{f}
15387254 4963@cindex reprint the last value
d4f3574e 4964If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4965@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4966conveniently inspect the same value in an alternative format.
4967@end table
4968
4969A more low-level way of examining data is with the @code{x} command.
4970It examines data in memory at a specified address and prints it in a
4971specified format. @xref{Memory, ,Examining memory}.
4972
7a292a7a 4973If you are interested in information about types, or about how the
d4f3574e
SS
4974fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4975command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4976Table}.
c906108c
SS
4977
4978@menu
4979* Expressions:: Expressions
4980* Variables:: Program variables
4981* Arrays:: Artificial arrays
4982* Output Formats:: Output formats
4983* Memory:: Examining memory
4984* Auto Display:: Automatic display
4985* Print Settings:: Print settings
4986* Value History:: Value history
4987* Convenience Vars:: Convenience variables
4988* Registers:: Registers
c906108c 4989* Floating Point Hardware:: Floating point hardware
53c69bd7 4990* Vector Unit:: Vector Unit
721c2651 4991* OS Information:: Auxiliary data provided by operating system
29e57380 4992* Memory Region Attributes:: Memory region attributes
16d9dec6 4993* Dump/Restore Files:: Copy between memory and a file
384ee23f 4994* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4995* Character Sets:: Debugging programs that use a different
4996 character set than GDB does
09d4efe1 4997* Caching Remote Data:: Data caching for remote targets
c906108c
SS
4998@end menu
4999
6d2ebf8b 5000@node Expressions
c906108c
SS
5001@section Expressions
5002
5003@cindex expressions
5004@code{print} and many other @value{GDBN} commands accept an expression and
5005compute its value. Any kind of constant, variable or operator defined
5006by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5007@value{GDBN}. This includes conditional expressions, function calls,
5008casts, and string constants. It also includes preprocessor macros, if
5009you compiled your program to include this information; see
5010@ref{Compilation}.
c906108c 5011
15387254 5012@cindex arrays in expressions
d4f3574e
SS
5013@value{GDBN} supports array constants in expressions input by
5014the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5015you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5016memory that is @code{malloc}ed in the target program.
c906108c 5017
c906108c
SS
5018Because C is so widespread, most of the expressions shown in examples in
5019this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5020Languages}, for information on how to use expressions in other
5021languages.
5022
5023In this section, we discuss operators that you can use in @value{GDBN}
5024expressions regardless of your programming language.
5025
15387254 5026@cindex casts, in expressions
c906108c
SS
5027Casts are supported in all languages, not just in C, because it is so
5028useful to cast a number into a pointer in order to examine a structure
5029at that address in memory.
5030@c FIXME: casts supported---Mod2 true?
c906108c
SS
5031
5032@value{GDBN} supports these operators, in addition to those common
5033to programming languages:
5034
5035@table @code
5036@item @@
5037@samp{@@} is a binary operator for treating parts of memory as arrays.
5038@xref{Arrays, ,Artificial arrays}, for more information.
5039
5040@item ::
5041@samp{::} allows you to specify a variable in terms of the file or
5042function where it is defined. @xref{Variables, ,Program variables}.
5043
5044@cindex @{@var{type}@}
5045@cindex type casting memory
5046@cindex memory, viewing as typed object
5047@cindex casts, to view memory
5048@item @{@var{type}@} @var{addr}
5049Refers to an object of type @var{type} stored at address @var{addr} in
5050memory. @var{addr} may be any expression whose value is an integer or
5051pointer (but parentheses are required around binary operators, just as in
5052a cast). This construct is allowed regardless of what kind of data is
5053normally supposed to reside at @var{addr}.
5054@end table
5055
6d2ebf8b 5056@node Variables
c906108c
SS
5057@section Program variables
5058
5059The most common kind of expression to use is the name of a variable
5060in your program.
5061
5062Variables in expressions are understood in the selected stack frame
5063(@pxref{Selection, ,Selecting a frame}); they must be either:
5064
5065@itemize @bullet
5066@item
5067global (or file-static)
5068@end itemize
5069
5d161b24 5070@noindent or
c906108c
SS
5071
5072@itemize @bullet
5073@item
5074visible according to the scope rules of the
5075programming language from the point of execution in that frame
5d161b24 5076@end itemize
c906108c
SS
5077
5078@noindent This means that in the function
5079
474c8240 5080@smallexample
c906108c
SS
5081foo (a)
5082 int a;
5083@{
5084 bar (a);
5085 @{
5086 int b = test ();
5087 bar (b);
5088 @}
5089@}
474c8240 5090@end smallexample
c906108c
SS
5091
5092@noindent
5093you can examine and use the variable @code{a} whenever your program is
5094executing within the function @code{foo}, but you can only use or
5095examine the variable @code{b} while your program is executing inside
5096the block where @code{b} is declared.
5097
5098@cindex variable name conflict
5099There is an exception: you can refer to a variable or function whose
5100scope is a single source file even if the current execution point is not
5101in this file. But it is possible to have more than one such variable or
5102function with the same name (in different source files). If that
5103happens, referring to that name has unpredictable effects. If you wish,
5104you can specify a static variable in a particular function or file,
15387254 5105using the colon-colon (@code{::}) notation:
c906108c 5106
d4f3574e 5107@cindex colon-colon, context for variables/functions
c906108c
SS
5108@iftex
5109@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5110@cindex @code{::}, context for variables/functions
c906108c 5111@end iftex
474c8240 5112@smallexample
c906108c
SS
5113@var{file}::@var{variable}
5114@var{function}::@var{variable}
474c8240 5115@end smallexample
c906108c
SS
5116
5117@noindent
5118Here @var{file} or @var{function} is the name of the context for the
5119static @var{variable}. In the case of file names, you can use quotes to
5120make sure @value{GDBN} parses the file name as a single word---for example,
5121to print a global value of @code{x} defined in @file{f2.c}:
5122
474c8240 5123@smallexample
c906108c 5124(@value{GDBP}) p 'f2.c'::x
474c8240 5125@end smallexample
c906108c 5126
b37052ae 5127@cindex C@t{++} scope resolution
c906108c 5128This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5129use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5130scope resolution operator in @value{GDBN} expressions.
5131@c FIXME: Um, so what happens in one of those rare cases where it's in
5132@c conflict?? --mew
c906108c
SS
5133
5134@cindex wrong values
5135@cindex variable values, wrong
15387254
EZ
5136@cindex function entry/exit, wrong values of variables
5137@cindex optimized code, wrong values of variables
c906108c
SS
5138@quotation
5139@emph{Warning:} Occasionally, a local variable may appear to have the
5140wrong value at certain points in a function---just after entry to a new
5141scope, and just before exit.
5142@end quotation
5143You may see this problem when you are stepping by machine instructions.
5144This is because, on most machines, it takes more than one instruction to
5145set up a stack frame (including local variable definitions); if you are
5146stepping by machine instructions, variables may appear to have the wrong
5147values until the stack frame is completely built. On exit, it usually
5148also takes more than one machine instruction to destroy a stack frame;
5149after you begin stepping through that group of instructions, local
5150variable definitions may be gone.
5151
5152This may also happen when the compiler does significant optimizations.
5153To be sure of always seeing accurate values, turn off all optimization
5154when compiling.
5155
d4f3574e
SS
5156@cindex ``No symbol "foo" in current context''
5157Another possible effect of compiler optimizations is to optimize
5158unused variables out of existence, or assign variables to registers (as
5159opposed to memory addresses). Depending on the support for such cases
5160offered by the debug info format used by the compiler, @value{GDBN}
5161might not be able to display values for such local variables. If that
5162happens, @value{GDBN} will print a message like this:
5163
474c8240 5164@smallexample
d4f3574e 5165No symbol "foo" in current context.
474c8240 5166@end smallexample
d4f3574e
SS
5167
5168To solve such problems, either recompile without optimizations, or use a
5169different debug info format, if the compiler supports several such
15387254 5170formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5171usually supports the @option{-gstabs+} option. @option{-gstabs+}
5172produces debug info in a format that is superior to formats such as
5173COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5174an effective form for debug info. @xref{Debugging Options,,Options
5175for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5176@xref{C, , Debugging C++}, for more info about debug info formats
5177that are best suited to C@t{++} programs.
d4f3574e 5178
6d2ebf8b 5179@node Arrays
c906108c
SS
5180@section Artificial arrays
5181
5182@cindex artificial array
15387254 5183@cindex arrays
41afff9a 5184@kindex @@@r{, referencing memory as an array}
c906108c
SS
5185It is often useful to print out several successive objects of the
5186same type in memory; a section of an array, or an array of
5187dynamically determined size for which only a pointer exists in the
5188program.
5189
5190You can do this by referring to a contiguous span of memory as an
5191@dfn{artificial array}, using the binary operator @samp{@@}. The left
5192operand of @samp{@@} should be the first element of the desired array
5193and be an individual object. The right operand should be the desired length
5194of the array. The result is an array value whose elements are all of
5195the type of the left argument. The first element is actually the left
5196argument; the second element comes from bytes of memory immediately
5197following those that hold the first element, and so on. Here is an
5198example. If a program says
5199
474c8240 5200@smallexample
c906108c 5201int *array = (int *) malloc (len * sizeof (int));
474c8240 5202@end smallexample
c906108c
SS
5203
5204@noindent
5205you can print the contents of @code{array} with
5206
474c8240 5207@smallexample
c906108c 5208p *array@@len
474c8240 5209@end smallexample
c906108c
SS
5210
5211The left operand of @samp{@@} must reside in memory. Array values made
5212with @samp{@@} in this way behave just like other arrays in terms of
5213subscripting, and are coerced to pointers when used in expressions.
5214Artificial arrays most often appear in expressions via the value history
5215(@pxref{Value History, ,Value history}), after printing one out.
5216
5217Another way to create an artificial array is to use a cast.
5218This re-interprets a value as if it were an array.
5219The value need not be in memory:
474c8240 5220@smallexample
c906108c
SS
5221(@value{GDBP}) p/x (short[2])0x12345678
5222$1 = @{0x1234, 0x5678@}
474c8240 5223@end smallexample
c906108c
SS
5224
5225As a convenience, if you leave the array length out (as in
c3f6f71d 5226@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5227the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5228@smallexample
c906108c
SS
5229(@value{GDBP}) p/x (short[])0x12345678
5230$2 = @{0x1234, 0x5678@}
474c8240 5231@end smallexample
c906108c
SS
5232
5233Sometimes the artificial array mechanism is not quite enough; in
5234moderately complex data structures, the elements of interest may not
5235actually be adjacent---for example, if you are interested in the values
5236of pointers in an array. One useful work-around in this situation is
5237to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5238variables}) as a counter in an expression that prints the first
5239interesting value, and then repeat that expression via @key{RET}. For
5240instance, suppose you have an array @code{dtab} of pointers to
5241structures, and you are interested in the values of a field @code{fv}
5242in each structure. Here is an example of what you might type:
5243
474c8240 5244@smallexample
c906108c
SS
5245set $i = 0
5246p dtab[$i++]->fv
5247@key{RET}
5248@key{RET}
5249@dots{}
474c8240 5250@end smallexample
c906108c 5251
6d2ebf8b 5252@node Output Formats
c906108c
SS
5253@section Output formats
5254
5255@cindex formatted output
5256@cindex output formats
5257By default, @value{GDBN} prints a value according to its data type. Sometimes
5258this is not what you want. For example, you might want to print a number
5259in hex, or a pointer in decimal. Or you might want to view data in memory
5260at a certain address as a character string or as an instruction. To do
5261these things, specify an @dfn{output format} when you print a value.
5262
5263The simplest use of output formats is to say how to print a value
5264already computed. This is done by starting the arguments of the
5265@code{print} command with a slash and a format letter. The format
5266letters supported are:
5267
5268@table @code
5269@item x
5270Regard the bits of the value as an integer, and print the integer in
5271hexadecimal.
5272
5273@item d
5274Print as integer in signed decimal.
5275
5276@item u
5277Print as integer in unsigned decimal.
5278
5279@item o
5280Print as integer in octal.
5281
5282@item t
5283Print as integer in binary. The letter @samp{t} stands for ``two''.
5284@footnote{@samp{b} cannot be used because these format letters are also
5285used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5286see @ref{Memory,,Examining memory}.}
c906108c
SS
5287
5288@item a
5289@cindex unknown address, locating
3d67e040 5290@cindex locate address
c906108c
SS
5291Print as an address, both absolute in hexadecimal and as an offset from
5292the nearest preceding symbol. You can use this format used to discover
5293where (in what function) an unknown address is located:
5294
474c8240 5295@smallexample
c906108c
SS
5296(@value{GDBP}) p/a 0x54320
5297$3 = 0x54320 <_initialize_vx+396>
474c8240 5298@end smallexample
c906108c 5299
3d67e040
EZ
5300@noindent
5301The command @code{info symbol 0x54320} yields similar results.
5302@xref{Symbols, info symbol}.
5303
c906108c
SS
5304@item c
5305Regard as an integer and print it as a character constant.
5306
5307@item f
5308Regard the bits of the value as a floating point number and print
5309using typical floating point syntax.
5310@end table
5311
5312For example, to print the program counter in hex (@pxref{Registers}), type
5313
474c8240 5314@smallexample
c906108c 5315p/x $pc
474c8240 5316@end smallexample
c906108c
SS
5317
5318@noindent
5319Note that no space is required before the slash; this is because command
5320names in @value{GDBN} cannot contain a slash.
5321
5322To reprint the last value in the value history with a different format,
5323you can use the @code{print} command with just a format and no
5324expression. For example, @samp{p/x} reprints the last value in hex.
5325
6d2ebf8b 5326@node Memory
c906108c
SS
5327@section Examining memory
5328
5329You can use the command @code{x} (for ``examine'') to examine memory in
5330any of several formats, independently of your program's data types.
5331
5332@cindex examining memory
5333@table @code
41afff9a 5334@kindex x @r{(examine memory)}
c906108c
SS
5335@item x/@var{nfu} @var{addr}
5336@itemx x @var{addr}
5337@itemx x
5338Use the @code{x} command to examine memory.
5339@end table
5340
5341@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5342much memory to display and how to format it; @var{addr} is an
5343expression giving the address where you want to start displaying memory.
5344If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5345Several commands set convenient defaults for @var{addr}.
5346
5347@table @r
5348@item @var{n}, the repeat count
5349The repeat count is a decimal integer; the default is 1. It specifies
5350how much memory (counting by units @var{u}) to display.
5351@c This really is **decimal**; unaffected by 'set radix' as of GDB
5352@c 4.1.2.
5353
5354@item @var{f}, the display format
5355The display format is one of the formats used by @code{print},
5356@samp{s} (null-terminated string), or @samp{i} (machine instruction).
5357The default is @samp{x} (hexadecimal) initially.
5358The default changes each time you use either @code{x} or @code{print}.
5359
5360@item @var{u}, the unit size
5361The unit size is any of
5362
5363@table @code
5364@item b
5365Bytes.
5366@item h
5367Halfwords (two bytes).
5368@item w
5369Words (four bytes). This is the initial default.
5370@item g
5371Giant words (eight bytes).
5372@end table
5373
5374Each time you specify a unit size with @code{x}, that size becomes the
5375default unit the next time you use @code{x}. (For the @samp{s} and
5376@samp{i} formats, the unit size is ignored and is normally not written.)
5377
5378@item @var{addr}, starting display address
5379@var{addr} is the address where you want @value{GDBN} to begin displaying
5380memory. The expression need not have a pointer value (though it may);
5381it is always interpreted as an integer address of a byte of memory.
5382@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5383@var{addr} is usually just after the last address examined---but several
5384other commands also set the default address: @code{info breakpoints} (to
5385the address of the last breakpoint listed), @code{info line} (to the
5386starting address of a line), and @code{print} (if you use it to display
5387a value from memory).
5388@end table
5389
5390For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5391(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5392starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5393words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5394@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5395
5396Since the letters indicating unit sizes are all distinct from the
5397letters specifying output formats, you do not have to remember whether
5398unit size or format comes first; either order works. The output
5399specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5400(However, the count @var{n} must come first; @samp{wx4} does not work.)
5401
5402Even though the unit size @var{u} is ignored for the formats @samp{s}
5403and @samp{i}, you might still want to use a count @var{n}; for example,
5404@samp{3i} specifies that you want to see three machine instructions,
5405including any operands. The command @code{disassemble} gives an
d4f3574e 5406alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5407Code,,Source and machine code}.
5408
5409All the defaults for the arguments to @code{x} are designed to make it
5410easy to continue scanning memory with minimal specifications each time
5411you use @code{x}. For example, after you have inspected three machine
5412instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5413with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5414the repeat count @var{n} is used again; the other arguments default as
5415for successive uses of @code{x}.
5416
5417@cindex @code{$_}, @code{$__}, and value history
5418The addresses and contents printed by the @code{x} command are not saved
5419in the value history because there is often too much of them and they
5420would get in the way. Instead, @value{GDBN} makes these values available for
5421subsequent use in expressions as values of the convenience variables
5422@code{$_} and @code{$__}. After an @code{x} command, the last address
5423examined is available for use in expressions in the convenience variable
5424@code{$_}. The contents of that address, as examined, are available in
5425the convenience variable @code{$__}.
5426
5427If the @code{x} command has a repeat count, the address and contents saved
5428are from the last memory unit printed; this is not the same as the last
5429address printed if several units were printed on the last line of output.
5430
09d4efe1
EZ
5431@cindex remote memory comparison
5432@cindex verify remote memory image
5433When you are debugging a program running on a remote target machine
5434(@pxref{Remote}), you may wish to verify the program's image in the
5435remote machine's memory against the executable file you downloaded to
5436the target. The @code{compare-sections} command is provided for such
5437situations.
5438
5439@table @code
5440@kindex compare-sections
5441@item compare-sections @r{[}@var{section-name}@r{]}
5442Compare the data of a loadable section @var{section-name} in the
5443executable file of the program being debugged with the same section in
5444the remote machine's memory, and report any mismatches. With no
5445arguments, compares all loadable sections. This command's
5446availability depends on the target's support for the @code{"qCRC"}
5447remote request.
5448@end table
5449
6d2ebf8b 5450@node Auto Display
c906108c
SS
5451@section Automatic display
5452@cindex automatic display
5453@cindex display of expressions
5454
5455If you find that you want to print the value of an expression frequently
5456(to see how it changes), you might want to add it to the @dfn{automatic
5457display list} so that @value{GDBN} prints its value each time your program stops.
5458Each expression added to the list is given a number to identify it;
5459to remove an expression from the list, you specify that number.
5460The automatic display looks like this:
5461
474c8240 5462@smallexample
c906108c
SS
54632: foo = 38
54643: bar[5] = (struct hack *) 0x3804
474c8240 5465@end smallexample
c906108c
SS
5466
5467@noindent
5468This display shows item numbers, expressions and their current values. As with
5469displays you request manually using @code{x} or @code{print}, you can
5470specify the output format you prefer; in fact, @code{display} decides
5471whether to use @code{print} or @code{x} depending on how elaborate your
5472format specification is---it uses @code{x} if you specify a unit size,
5473or one of the two formats (@samp{i} and @samp{s}) that are only
5474supported by @code{x}; otherwise it uses @code{print}.
5475
5476@table @code
5477@kindex display
d4f3574e
SS
5478@item display @var{expr}
5479Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5480each time your program stops. @xref{Expressions, ,Expressions}.
5481
5482@code{display} does not repeat if you press @key{RET} again after using it.
5483
d4f3574e 5484@item display/@var{fmt} @var{expr}
c906108c 5485For @var{fmt} specifying only a display format and not a size or
d4f3574e 5486count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5487arrange to display it each time in the specified format @var{fmt}.
5488@xref{Output Formats,,Output formats}.
5489
5490@item display/@var{fmt} @var{addr}
5491For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5492number of units, add the expression @var{addr} as a memory address to
5493be examined each time your program stops. Examining means in effect
5494doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5495@end table
5496
5497For example, @samp{display/i $pc} can be helpful, to see the machine
5498instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5499is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5500
5501@table @code
5502@kindex delete display
5503@kindex undisplay
5504@item undisplay @var{dnums}@dots{}
5505@itemx delete display @var{dnums}@dots{}
5506Remove item numbers @var{dnums} from the list of expressions to display.
5507
5508@code{undisplay} does not repeat if you press @key{RET} after using it.
5509(Otherwise you would just get the error @samp{No display number @dots{}}.)
5510
5511@kindex disable display
5512@item disable display @var{dnums}@dots{}
5513Disable the display of item numbers @var{dnums}. A disabled display
5514item is not printed automatically, but is not forgotten. It may be
5515enabled again later.
5516
5517@kindex enable display
5518@item enable display @var{dnums}@dots{}
5519Enable display of item numbers @var{dnums}. It becomes effective once
5520again in auto display of its expression, until you specify otherwise.
5521
5522@item display
5523Display the current values of the expressions on the list, just as is
5524done when your program stops.
5525
5526@kindex info display
5527@item info display
5528Print the list of expressions previously set up to display
5529automatically, each one with its item number, but without showing the
5530values. This includes disabled expressions, which are marked as such.
5531It also includes expressions which would not be displayed right now
5532because they refer to automatic variables not currently available.
5533@end table
5534
15387254 5535@cindex display disabled out of scope
c906108c
SS
5536If a display expression refers to local variables, then it does not make
5537sense outside the lexical context for which it was set up. Such an
5538expression is disabled when execution enters a context where one of its
5539variables is not defined. For example, if you give the command
5540@code{display last_char} while inside a function with an argument
5541@code{last_char}, @value{GDBN} displays this argument while your program
5542continues to stop inside that function. When it stops elsewhere---where
5543there is no variable @code{last_char}---the display is disabled
5544automatically. The next time your program stops where @code{last_char}
5545is meaningful, you can enable the display expression once again.
5546
6d2ebf8b 5547@node Print Settings
c906108c
SS
5548@section Print settings
5549
5550@cindex format options
5551@cindex print settings
5552@value{GDBN} provides the following ways to control how arrays, structures,
5553and symbols are printed.
5554
5555@noindent
5556These settings are useful for debugging programs in any language:
5557
5558@table @code
4644b6e3 5559@kindex set print
c906108c
SS
5560@item set print address
5561@itemx set print address on
4644b6e3 5562@cindex print/don't print memory addresses
c906108c
SS
5563@value{GDBN} prints memory addresses showing the location of stack
5564traces, structure values, pointer values, breakpoints, and so forth,
5565even when it also displays the contents of those addresses. The default
5566is @code{on}. For example, this is what a stack frame display looks like with
5567@code{set print address on}:
5568
5569@smallexample
5570@group
5571(@value{GDBP}) f
5572#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5573 at input.c:530
5574530 if (lquote != def_lquote)
5575@end group
5576@end smallexample
5577
5578@item set print address off
5579Do not print addresses when displaying their contents. For example,
5580this is the same stack frame displayed with @code{set print address off}:
5581
5582@smallexample
5583@group
5584(@value{GDBP}) set print addr off
5585(@value{GDBP}) f
5586#0 set_quotes (lq="<<", rq=">>") at input.c:530
5587530 if (lquote != def_lquote)
5588@end group
5589@end smallexample
5590
5591You can use @samp{set print address off} to eliminate all machine
5592dependent displays from the @value{GDBN} interface. For example, with
5593@code{print address off}, you should get the same text for backtraces on
5594all machines---whether or not they involve pointer arguments.
5595
4644b6e3 5596@kindex show print
c906108c
SS
5597@item show print address
5598Show whether or not addresses are to be printed.
5599@end table
5600
5601When @value{GDBN} prints a symbolic address, it normally prints the
5602closest earlier symbol plus an offset. If that symbol does not uniquely
5603identify the address (for example, it is a name whose scope is a single
5604source file), you may need to clarify. One way to do this is with
5605@code{info line}, for example @samp{info line *0x4537}. Alternately,
5606you can set @value{GDBN} to print the source file and line number when
5607it prints a symbolic address:
5608
5609@table @code
c906108c 5610@item set print symbol-filename on
9c16f35a
EZ
5611@cindex source file and line of a symbol
5612@cindex symbol, source file and line
c906108c
SS
5613Tell @value{GDBN} to print the source file name and line number of a
5614symbol in the symbolic form of an address.
5615
5616@item set print symbol-filename off
5617Do not print source file name and line number of a symbol. This is the
5618default.
5619
c906108c
SS
5620@item show print symbol-filename
5621Show whether or not @value{GDBN} will print the source file name and
5622line number of a symbol in the symbolic form of an address.
5623@end table
5624
5625Another situation where it is helpful to show symbol filenames and line
5626numbers is when disassembling code; @value{GDBN} shows you the line
5627number and source file that corresponds to each instruction.
5628
5629Also, you may wish to see the symbolic form only if the address being
5630printed is reasonably close to the closest earlier symbol:
5631
5632@table @code
c906108c 5633@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5634@cindex maximum value for offset of closest symbol
c906108c
SS
5635Tell @value{GDBN} to only display the symbolic form of an address if the
5636offset between the closest earlier symbol and the address is less than
5d161b24 5637@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5638to always print the symbolic form of an address if any symbol precedes it.
5639
c906108c
SS
5640@item show print max-symbolic-offset
5641Ask how large the maximum offset is that @value{GDBN} prints in a
5642symbolic address.
5643@end table
5644
5645@cindex wild pointer, interpreting
5646@cindex pointer, finding referent
5647If you have a pointer and you are not sure where it points, try
5648@samp{set print symbol-filename on}. Then you can determine the name
5649and source file location of the variable where it points, using
5650@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5651For example, here @value{GDBN} shows that a variable @code{ptt} points
5652at another variable @code{t}, defined in @file{hi2.c}:
5653
474c8240 5654@smallexample
c906108c
SS
5655(@value{GDBP}) set print symbol-filename on
5656(@value{GDBP}) p/a ptt
5657$4 = 0xe008 <t in hi2.c>
474c8240 5658@end smallexample
c906108c
SS
5659
5660@quotation
5661@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5662does not show the symbol name and filename of the referent, even with
5663the appropriate @code{set print} options turned on.
5664@end quotation
5665
5666Other settings control how different kinds of objects are printed:
5667
5668@table @code
c906108c
SS
5669@item set print array
5670@itemx set print array on
4644b6e3 5671@cindex pretty print arrays
c906108c
SS
5672Pretty print arrays. This format is more convenient to read,
5673but uses more space. The default is off.
5674
5675@item set print array off
5676Return to compressed format for arrays.
5677
c906108c
SS
5678@item show print array
5679Show whether compressed or pretty format is selected for displaying
5680arrays.
5681
c906108c 5682@item set print elements @var{number-of-elements}
4644b6e3 5683@cindex number of array elements to print
9c16f35a 5684@cindex limit on number of printed array elements
c906108c
SS
5685Set a limit on how many elements of an array @value{GDBN} will print.
5686If @value{GDBN} is printing a large array, it stops printing after it has
5687printed the number of elements set by the @code{set print elements} command.
5688This limit also applies to the display of strings.
d4f3574e 5689When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5690Setting @var{number-of-elements} to zero means that the printing is unlimited.
5691
c906108c
SS
5692@item show print elements
5693Display the number of elements of a large array that @value{GDBN} will print.
5694If the number is 0, then the printing is unlimited.
5695
9c16f35a
EZ
5696@item set print repeats
5697@cindex repeated array elements
5698Set the threshold for suppressing display of repeated array
5699elelments. When the number of consecutive identical elements of an
5700array exceeds the threshold, @value{GDBN} prints the string
5701@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5702identical repetitions, instead of displaying the identical elements
5703themselves. Setting the threshold to zero will cause all elements to
5704be individually printed. The default threshold is 10.
5705
5706@item show print repeats
5707Display the current threshold for printing repeated identical
5708elements.
5709
c906108c 5710@item set print null-stop
4644b6e3 5711@cindex @sc{null} elements in arrays
c906108c 5712Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5713@sc{null} is encountered. This is useful when large arrays actually
c906108c 5714contain only short strings.
d4f3574e 5715The default is off.
c906108c 5716
9c16f35a
EZ
5717@item show print null-stop
5718Show whether @value{GDBN} stops printing an array on the first
5719@sc{null} character.
5720
c906108c 5721@item set print pretty on
9c16f35a
EZ
5722@cindex print structures in indented form
5723@cindex indentation in structure display
5d161b24 5724Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5725per line, like this:
5726
5727@smallexample
5728@group
5729$1 = @{
5730 next = 0x0,
5731 flags = @{
5732 sweet = 1,
5733 sour = 1
5734 @},
5735 meat = 0x54 "Pork"
5736@}
5737@end group
5738@end smallexample
5739
5740@item set print pretty off
5741Cause @value{GDBN} to print structures in a compact format, like this:
5742
5743@smallexample
5744@group
5745$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5746meat = 0x54 "Pork"@}
5747@end group
5748@end smallexample
5749
5750@noindent
5751This is the default format.
5752
c906108c
SS
5753@item show print pretty
5754Show which format @value{GDBN} is using to print structures.
5755
c906108c 5756@item set print sevenbit-strings on
4644b6e3
EZ
5757@cindex eight-bit characters in strings
5758@cindex octal escapes in strings
c906108c
SS
5759Print using only seven-bit characters; if this option is set,
5760@value{GDBN} displays any eight-bit characters (in strings or
5761character values) using the notation @code{\}@var{nnn}. This setting is
5762best if you are working in English (@sc{ascii}) and you use the
5763high-order bit of characters as a marker or ``meta'' bit.
5764
5765@item set print sevenbit-strings off
5766Print full eight-bit characters. This allows the use of more
5767international character sets, and is the default.
5768
c906108c
SS
5769@item show print sevenbit-strings
5770Show whether or not @value{GDBN} is printing only seven-bit characters.
5771
c906108c 5772@item set print union on
4644b6e3 5773@cindex unions in structures, printing
9c16f35a
EZ
5774Tell @value{GDBN} to print unions which are contained in structures
5775and other unions. This is the default setting.
c906108c
SS
5776
5777@item set print union off
9c16f35a
EZ
5778Tell @value{GDBN} not to print unions which are contained in
5779structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5780instead.
c906108c 5781
c906108c
SS
5782@item show print union
5783Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5784structures and other unions.
c906108c
SS
5785
5786For example, given the declarations
5787
5788@smallexample
5789typedef enum @{Tree, Bug@} Species;
5790typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5791typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5792 Bug_forms;
5793
5794struct thing @{
5795 Species it;
5796 union @{
5797 Tree_forms tree;
5798 Bug_forms bug;
5799 @} form;
5800@};
5801
5802struct thing foo = @{Tree, @{Acorn@}@};
5803@end smallexample
5804
5805@noindent
5806with @code{set print union on} in effect @samp{p foo} would print
5807
5808@smallexample
5809$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5810@end smallexample
5811
5812@noindent
5813and with @code{set print union off} in effect it would print
5814
5815@smallexample
5816$1 = @{it = Tree, form = @{...@}@}
5817@end smallexample
9c16f35a
EZ
5818
5819@noindent
5820@code{set print union} affects programs written in C-like languages
5821and in Pascal.
c906108c
SS
5822@end table
5823
c906108c
SS
5824@need 1000
5825@noindent
b37052ae 5826These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5827
5828@table @code
4644b6e3 5829@cindex demangling C@t{++} names
c906108c
SS
5830@item set print demangle
5831@itemx set print demangle on
b37052ae 5832Print C@t{++} names in their source form rather than in the encoded
c906108c 5833(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5834linkage. The default is on.
c906108c 5835
c906108c 5836@item show print demangle
b37052ae 5837Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5838
c906108c
SS
5839@item set print asm-demangle
5840@itemx set print asm-demangle on
b37052ae 5841Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5842in assembler code printouts such as instruction disassemblies.
5843The default is off.
5844
c906108c 5845@item show print asm-demangle
b37052ae 5846Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5847or demangled form.
5848
b37052ae
EZ
5849@cindex C@t{++} symbol decoding style
5850@cindex symbol decoding style, C@t{++}
a8f24a35 5851@kindex set demangle-style
c906108c
SS
5852@item set demangle-style @var{style}
5853Choose among several encoding schemes used by different compilers to
b37052ae 5854represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5855
5856@table @code
5857@item auto
5858Allow @value{GDBN} to choose a decoding style by inspecting your program.
5859
5860@item gnu
b37052ae 5861Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5862This is the default.
c906108c
SS
5863
5864@item hp
b37052ae 5865Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5866
5867@item lucid
b37052ae 5868Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5869
5870@item arm
b37052ae 5871Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5872@strong{Warning:} this setting alone is not sufficient to allow
5873debugging @code{cfront}-generated executables. @value{GDBN} would
5874require further enhancement to permit that.
5875
5876@end table
5877If you omit @var{style}, you will see a list of possible formats.
5878
c906108c 5879@item show demangle-style
b37052ae 5880Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5881
c906108c
SS
5882@item set print object
5883@itemx set print object on
4644b6e3 5884@cindex derived type of an object, printing
9c16f35a 5885@cindex display derived types
c906108c
SS
5886When displaying a pointer to an object, identify the @emph{actual}
5887(derived) type of the object rather than the @emph{declared} type, using
5888the virtual function table.
5889
5890@item set print object off
5891Display only the declared type of objects, without reference to the
5892virtual function table. This is the default setting.
5893
c906108c
SS
5894@item show print object
5895Show whether actual, or declared, object types are displayed.
5896
c906108c
SS
5897@item set print static-members
5898@itemx set print static-members on
4644b6e3 5899@cindex static members of C@t{++} objects
b37052ae 5900Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5901
5902@item set print static-members off
b37052ae 5903Do not print static members when displaying a C@t{++} object.
c906108c 5904
c906108c 5905@item show print static-members
9c16f35a
EZ
5906Show whether C@t{++} static members are printed or not.
5907
5908@item set print pascal_static-members
5909@itemx set print pascal_static-members on
5910@cindex static members of Pacal objects
5911@cindex Pacal objects, static members display
5912Print static members when displaying a Pascal object. The default is on.
5913
5914@item set print pascal_static-members off
5915Do not print static members when displaying a Pascal object.
5916
5917@item show print pascal_static-members
5918Show whether Pascal static members are printed or not.
c906108c
SS
5919
5920@c These don't work with HP ANSI C++ yet.
c906108c
SS
5921@item set print vtbl
5922@itemx set print vtbl on
4644b6e3 5923@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5924@cindex virtual functions (C@t{++}) display
5925@cindex VTBL display
b37052ae 5926Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5927(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5928ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5929
5930@item set print vtbl off
b37052ae 5931Do not pretty print C@t{++} virtual function tables.
c906108c 5932
c906108c 5933@item show print vtbl
b37052ae 5934Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5935@end table
c906108c 5936
6d2ebf8b 5937@node Value History
c906108c
SS
5938@section Value history
5939
5940@cindex value history
9c16f35a 5941@cindex history of values printed by @value{GDBN}
5d161b24
DB
5942Values printed by the @code{print} command are saved in the @value{GDBN}
5943@dfn{value history}. This allows you to refer to them in other expressions.
5944Values are kept until the symbol table is re-read or discarded
5945(for example with the @code{file} or @code{symbol-file} commands).
5946When the symbol table changes, the value history is discarded,
5947since the values may contain pointers back to the types defined in the
c906108c
SS
5948symbol table.
5949
5950@cindex @code{$}
5951@cindex @code{$$}
5952@cindex history number
5953The values printed are given @dfn{history numbers} by which you can
5954refer to them. These are successive integers starting with one.
5955@code{print} shows you the history number assigned to a value by
5956printing @samp{$@var{num} = } before the value; here @var{num} is the
5957history number.
5958
5959To refer to any previous value, use @samp{$} followed by the value's
5960history number. The way @code{print} labels its output is designed to
5961remind you of this. Just @code{$} refers to the most recent value in
5962the history, and @code{$$} refers to the value before that.
5963@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5964is the value just prior to @code{$$}, @code{$$1} is equivalent to
5965@code{$$}, and @code{$$0} is equivalent to @code{$}.
5966
5967For example, suppose you have just printed a pointer to a structure and
5968want to see the contents of the structure. It suffices to type
5969
474c8240 5970@smallexample
c906108c 5971p *$
474c8240 5972@end smallexample
c906108c
SS
5973
5974If you have a chain of structures where the component @code{next} points
5975to the next one, you can print the contents of the next one with this:
5976
474c8240 5977@smallexample
c906108c 5978p *$.next
474c8240 5979@end smallexample
c906108c
SS
5980
5981@noindent
5982You can print successive links in the chain by repeating this
5983command---which you can do by just typing @key{RET}.
5984
5985Note that the history records values, not expressions. If the value of
5986@code{x} is 4 and you type these commands:
5987
474c8240 5988@smallexample
c906108c
SS
5989print x
5990set x=5
474c8240 5991@end smallexample
c906108c
SS
5992
5993@noindent
5994then the value recorded in the value history by the @code{print} command
5995remains 4 even though the value of @code{x} has changed.
5996
5997@table @code
5998@kindex show values
5999@item show values
6000Print the last ten values in the value history, with their item numbers.
6001This is like @samp{p@ $$9} repeated ten times, except that @code{show
6002values} does not change the history.
6003
6004@item show values @var{n}
6005Print ten history values centered on history item number @var{n}.
6006
6007@item show values +
6008Print ten history values just after the values last printed. If no more
6009values are available, @code{show values +} produces no display.
6010@end table
6011
6012Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6013same effect as @samp{show values +}.
6014
6d2ebf8b 6015@node Convenience Vars
c906108c
SS
6016@section Convenience variables
6017
6018@cindex convenience variables
9c16f35a 6019@cindex user-defined variables
c906108c
SS
6020@value{GDBN} provides @dfn{convenience variables} that you can use within
6021@value{GDBN} to hold on to a value and refer to it later. These variables
6022exist entirely within @value{GDBN}; they are not part of your program, and
6023setting a convenience variable has no direct effect on further execution
6024of your program. That is why you can use them freely.
6025
6026Convenience variables are prefixed with @samp{$}. Any name preceded by
6027@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6028the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6029(Value history references, in contrast, are @emph{numbers} preceded
6030by @samp{$}. @xref{Value History, ,Value history}.)
6031
6032You can save a value in a convenience variable with an assignment
6033expression, just as you would set a variable in your program.
6034For example:
6035
474c8240 6036@smallexample
c906108c 6037set $foo = *object_ptr
474c8240 6038@end smallexample
c906108c
SS
6039
6040@noindent
6041would save in @code{$foo} the value contained in the object pointed to by
6042@code{object_ptr}.
6043
6044Using a convenience variable for the first time creates it, but its
6045value is @code{void} until you assign a new value. You can alter the
6046value with another assignment at any time.
6047
6048Convenience variables have no fixed types. You can assign a convenience
6049variable any type of value, including structures and arrays, even if
6050that variable already has a value of a different type. The convenience
6051variable, when used as an expression, has the type of its current value.
6052
6053@table @code
6054@kindex show convenience
9c16f35a 6055@cindex show all user variables
c906108c
SS
6056@item show convenience
6057Print a list of convenience variables used so far, and their values.
d4f3574e 6058Abbreviated @code{show conv}.
c906108c
SS
6059@end table
6060
6061One of the ways to use a convenience variable is as a counter to be
6062incremented or a pointer to be advanced. For example, to print
6063a field from successive elements of an array of structures:
6064
474c8240 6065@smallexample
c906108c
SS
6066set $i = 0
6067print bar[$i++]->contents
474c8240 6068@end smallexample
c906108c 6069
d4f3574e
SS
6070@noindent
6071Repeat that command by typing @key{RET}.
c906108c
SS
6072
6073Some convenience variables are created automatically by @value{GDBN} and given
6074values likely to be useful.
6075
6076@table @code
41afff9a 6077@vindex $_@r{, convenience variable}
c906108c
SS
6078@item $_
6079The variable @code{$_} is automatically set by the @code{x} command to
6080the last address examined (@pxref{Memory, ,Examining memory}). Other
6081commands which provide a default address for @code{x} to examine also
6082set @code{$_} to that address; these commands include @code{info line}
6083and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6084except when set by the @code{x} command, in which case it is a pointer
6085to the type of @code{$__}.
6086
41afff9a 6087@vindex $__@r{, convenience variable}
c906108c
SS
6088@item $__
6089The variable @code{$__} is automatically set by the @code{x} command
6090to the value found in the last address examined. Its type is chosen
6091to match the format in which the data was printed.
6092
6093@item $_exitcode
41afff9a 6094@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6095The variable @code{$_exitcode} is automatically set to the exit code when
6096the program being debugged terminates.
6097@end table
6098
53a5351d
JM
6099On HP-UX systems, if you refer to a function or variable name that
6100begins with a dollar sign, @value{GDBN} searches for a user or system
6101name first, before it searches for a convenience variable.
c906108c 6102
6d2ebf8b 6103@node Registers
c906108c
SS
6104@section Registers
6105
6106@cindex registers
6107You can refer to machine register contents, in expressions, as variables
6108with names starting with @samp{$}. The names of registers are different
6109for each machine; use @code{info registers} to see the names used on
6110your machine.
6111
6112@table @code
6113@kindex info registers
6114@item info registers
6115Print the names and values of all registers except floating-point
c85508ee 6116and vector registers (in the selected stack frame).
c906108c
SS
6117
6118@kindex info all-registers
6119@cindex floating point registers
6120@item info all-registers
6121Print the names and values of all registers, including floating-point
c85508ee 6122and vector registers (in the selected stack frame).
c906108c
SS
6123
6124@item info registers @var{regname} @dots{}
6125Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6126As discussed in detail below, register values are normally relative to
6127the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6128the machine you are using, with or without the initial @samp{$}.
6129@end table
6130
e09f16f9
EZ
6131@cindex stack pointer register
6132@cindex program counter register
6133@cindex process status register
6134@cindex frame pointer register
6135@cindex standard registers
c906108c
SS
6136@value{GDBN} has four ``standard'' register names that are available (in
6137expressions) on most machines---whenever they do not conflict with an
6138architecture's canonical mnemonics for registers. The register names
6139@code{$pc} and @code{$sp} are used for the program counter register and
6140the stack pointer. @code{$fp} is used for a register that contains a
6141pointer to the current stack frame, and @code{$ps} is used for a
6142register that contains the processor status. For example,
6143you could print the program counter in hex with
6144
474c8240 6145@smallexample
c906108c 6146p/x $pc
474c8240 6147@end smallexample
c906108c
SS
6148
6149@noindent
6150or print the instruction to be executed next with
6151
474c8240 6152@smallexample
c906108c 6153x/i $pc
474c8240 6154@end smallexample
c906108c
SS
6155
6156@noindent
6157or add four to the stack pointer@footnote{This is a way of removing
6158one word from the stack, on machines where stacks grow downward in
6159memory (most machines, nowadays). This assumes that the innermost
6160stack frame is selected; setting @code{$sp} is not allowed when other
6161stack frames are selected. To pop entire frames off the stack,
6162regardless of machine architecture, use @code{return};
d4f3574e 6163see @ref{Returning, ,Returning from a function}.} with
c906108c 6164
474c8240 6165@smallexample
c906108c 6166set $sp += 4
474c8240 6167@end smallexample
c906108c
SS
6168
6169Whenever possible, these four standard register names are available on
6170your machine even though the machine has different canonical mnemonics,
6171so long as there is no conflict. The @code{info registers} command
6172shows the canonical names. For example, on the SPARC, @code{info
6173registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6174can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6175is an alias for the @sc{eflags} register.
c906108c
SS
6176
6177@value{GDBN} always considers the contents of an ordinary register as an
6178integer when the register is examined in this way. Some machines have
6179special registers which can hold nothing but floating point; these
6180registers are considered to have floating point values. There is no way
6181to refer to the contents of an ordinary register as floating point value
6182(although you can @emph{print} it as a floating point value with
6183@samp{print/f $@var{regname}}).
6184
6185Some registers have distinct ``raw'' and ``virtual'' data formats. This
6186means that the data format in which the register contents are saved by
6187the operating system is not the same one that your program normally
6188sees. For example, the registers of the 68881 floating point
6189coprocessor are always saved in ``extended'' (raw) format, but all C
6190programs expect to work with ``double'' (virtual) format. In such
5d161b24 6191cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6192that makes sense for your program), but the @code{info registers} command
6193prints the data in both formats.
6194
6195Normally, register values are relative to the selected stack frame
6196(@pxref{Selection, ,Selecting a frame}). This means that you get the
6197value that the register would contain if all stack frames farther in
6198were exited and their saved registers restored. In order to see the
6199true contents of hardware registers, you must select the innermost
6200frame (with @samp{frame 0}).
6201
6202However, @value{GDBN} must deduce where registers are saved, from the machine
6203code generated by your compiler. If some registers are not saved, or if
6204@value{GDBN} is unable to locate the saved registers, the selected stack
6205frame makes no difference.
6206
6d2ebf8b 6207@node Floating Point Hardware
c906108c
SS
6208@section Floating point hardware
6209@cindex floating point
6210
6211Depending on the configuration, @value{GDBN} may be able to give
6212you more information about the status of the floating point hardware.
6213
6214@table @code
6215@kindex info float
6216@item info float
6217Display hardware-dependent information about the floating
6218point unit. The exact contents and layout vary depending on the
6219floating point chip. Currently, @samp{info float} is supported on
6220the ARM and x86 machines.
6221@end table
c906108c 6222
e76f1f2e
AC
6223@node Vector Unit
6224@section Vector Unit
6225@cindex vector unit
6226
6227Depending on the configuration, @value{GDBN} may be able to give you
6228more information about the status of the vector unit.
6229
6230@table @code
6231@kindex info vector
6232@item info vector
6233Display information about the vector unit. The exact contents and
6234layout vary depending on the hardware.
6235@end table
6236
721c2651
EZ
6237@node OS Information
6238@section Operating system auxiliary information
6239@cindex OS information
6240
6241@value{GDBN} provides interfaces to useful OS facilities that can help
6242you debug your program.
6243
6244@cindex @code{ptrace} system call
6245@cindex @code{struct user} contents
6246When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6247machines), it interfaces with the inferior via the @code{ptrace}
6248system call. The operating system creates a special sata structure,
6249called @code{struct user}, for this interface. You can use the
6250command @code{info udot} to display the contents of this data
6251structure.
6252
6253@table @code
6254@item info udot
6255@kindex info udot
6256Display the contents of the @code{struct user} maintained by the OS
6257kernel for the program being debugged. @value{GDBN} displays the
6258contents of @code{struct user} as a list of hex numbers, similar to
6259the @code{examine} command.
6260@end table
6261
b383017d
RM
6262@cindex auxiliary vector
6263@cindex vector, auxiliary
b383017d
RM
6264Some operating systems supply an @dfn{auxiliary vector} to programs at
6265startup. This is akin to the arguments and environment that you
6266specify for a program, but contains a system-dependent variety of
6267binary values that tell system libraries important details about the
6268hardware, operating system, and process. Each value's purpose is
6269identified by an integer tag; the meanings are well-known but system-specific.
6270Depending on the configuration and operating system facilities,
9c16f35a
EZ
6271@value{GDBN} may be able to show you this information. For remote
6272targets, this functionality may further depend on the remote stub's
6273support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6274configuration, auxiliary vector}.
b383017d
RM
6275
6276@table @code
6277@kindex info auxv
6278@item info auxv
6279Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6280live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6281numerically, and also shows names and text descriptions for recognized
6282tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6283pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6284most appropriate form for a recognized tag, and in hexadecimal for
6285an unrecognized tag.
6286@end table
6287
721c2651 6288
29e57380 6289@node Memory Region Attributes
b383017d 6290@section Memory region attributes
29e57380
C
6291@cindex memory region attributes
6292
b383017d
RM
6293@dfn{Memory region attributes} allow you to describe special handling
6294required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6295to determine whether to allow certain types of memory accesses; whether to
6296use specific width accesses; and whether to cache target memory.
6297
6298Defined memory regions can be individually enabled and disabled. When a
6299memory region is disabled, @value{GDBN} uses the default attributes when
6300accessing memory in that region. Similarly, if no memory regions have
6301been defined, @value{GDBN} uses the default attributes when accessing
6302all memory.
6303
b383017d 6304When a memory region is defined, it is given a number to identify it;
29e57380
C
6305to enable, disable, or remove a memory region, you specify that number.
6306
6307@table @code
6308@kindex mem
bfac230e 6309@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6310Define a memory region bounded by @var{lower} and @var{upper} with
6311attributes @var{attributes}@dots{}, and add it to the list of regions
6312monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6313case: it is treated as the the target's maximum memory address.
bfac230e 6314(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6315
6316@kindex delete mem
6317@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6318Remove memory regions @var{nums}@dots{} from the list of regions
6319monitored by @value{GDBN}.
29e57380
C
6320
6321@kindex disable mem
6322@item disable mem @var{nums}@dots{}
09d4efe1 6323Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6324A disabled memory region is not forgotten.
29e57380
C
6325It may be enabled again later.
6326
6327@kindex enable mem
6328@item enable mem @var{nums}@dots{}
09d4efe1 6329Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6330
6331@kindex info mem
6332@item info mem
6333Print a table of all defined memory regions, with the following columns
09d4efe1 6334for each region:
29e57380
C
6335
6336@table @emph
6337@item Memory Region Number
6338@item Enabled or Disabled.
b383017d 6339Enabled memory regions are marked with @samp{y}.
29e57380
C
6340Disabled memory regions are marked with @samp{n}.
6341
6342@item Lo Address
6343The address defining the inclusive lower bound of the memory region.
6344
6345@item Hi Address
6346The address defining the exclusive upper bound of the memory region.
6347
6348@item Attributes
6349The list of attributes set for this memory region.
6350@end table
6351@end table
6352
6353
6354@subsection Attributes
6355
b383017d 6356@subsubsection Memory Access Mode
29e57380
C
6357The access mode attributes set whether @value{GDBN} may make read or
6358write accesses to a memory region.
6359
6360While these attributes prevent @value{GDBN} from performing invalid
6361memory accesses, they do nothing to prevent the target system, I/O DMA,
6362etc. from accessing memory.
6363
6364@table @code
6365@item ro
6366Memory is read only.
6367@item wo
6368Memory is write only.
6369@item rw
6ca652b0 6370Memory is read/write. This is the default.
29e57380
C
6371@end table
6372
6373@subsubsection Memory Access Size
6374The acccess size attributes tells @value{GDBN} to use specific sized
6375accesses in the memory region. Often memory mapped device registers
6376require specific sized accesses. If no access size attribute is
6377specified, @value{GDBN} may use accesses of any size.
6378
6379@table @code
6380@item 8
6381Use 8 bit memory accesses.
6382@item 16
6383Use 16 bit memory accesses.
6384@item 32
6385Use 32 bit memory accesses.
6386@item 64
6387Use 64 bit memory accesses.
6388@end table
6389
6390@c @subsubsection Hardware/Software Breakpoints
6391@c The hardware/software breakpoint attributes set whether @value{GDBN}
6392@c will use hardware or software breakpoints for the internal breakpoints
6393@c used by the step, next, finish, until, etc. commands.
6394@c
6395@c @table @code
6396@c @item hwbreak
b383017d 6397@c Always use hardware breakpoints
29e57380
C
6398@c @item swbreak (default)
6399@c @end table
6400
6401@subsubsection Data Cache
6402The data cache attributes set whether @value{GDBN} will cache target
6403memory. While this generally improves performance by reducing debug
6404protocol overhead, it can lead to incorrect results because @value{GDBN}
6405does not know about volatile variables or memory mapped device
6406registers.
6407
6408@table @code
6409@item cache
b383017d 6410Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6411@item nocache
6412Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6413@end table
6414
6415@c @subsubsection Memory Write Verification
b383017d 6416@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6417@c will re-reads data after each write to verify the write was successful.
6418@c
6419@c @table @code
6420@c @item verify
6421@c @item noverify (default)
6422@c @end table
6423
16d9dec6
MS
6424@node Dump/Restore Files
6425@section Copy between memory and a file
6426@cindex dump/restore files
6427@cindex append data to a file
6428@cindex dump data to a file
6429@cindex restore data from a file
16d9dec6 6430
df5215a6
JB
6431You can use the commands @code{dump}, @code{append}, and
6432@code{restore} to copy data between target memory and a file. The
6433@code{dump} and @code{append} commands write data to a file, and the
6434@code{restore} command reads data from a file back into the inferior's
6435memory. Files may be in binary, Motorola S-record, Intel hex, or
6436Tektronix Hex format; however, @value{GDBN} can only append to binary
6437files.
6438
6439@table @code
6440
6441@kindex dump
6442@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6443@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6444Dump the contents of memory from @var{start_addr} to @var{end_addr},
6445or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6446
df5215a6 6447The @var{format} parameter may be any one of:
16d9dec6 6448@table @code
df5215a6
JB
6449@item binary
6450Raw binary form.
6451@item ihex
6452Intel hex format.
6453@item srec
6454Motorola S-record format.
6455@item tekhex
6456Tektronix Hex format.
6457@end table
6458
6459@value{GDBN} uses the same definitions of these formats as the
6460@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6461@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6462form.
6463
6464@kindex append
6465@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6466@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6467Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6468or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6469(@value{GDBN} can only append data to files in raw binary form.)
6470
6471@kindex restore
6472@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6473Restore the contents of file @var{filename} into memory. The
6474@code{restore} command can automatically recognize any known @sc{bfd}
6475file format, except for raw binary. To restore a raw binary file you
6476must specify the optional keyword @code{binary} after the filename.
16d9dec6 6477
b383017d 6478If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6479contained in the file. Binary files always start at address zero, so
6480they will be restored at address @var{bias}. Other bfd files have
6481a built-in location; they will be restored at offset @var{bias}
6482from that location.
6483
6484If @var{start} and/or @var{end} are non-zero, then only data between
6485file offset @var{start} and file offset @var{end} will be restored.
b383017d 6486These offsets are relative to the addresses in the file, before
16d9dec6
MS
6487the @var{bias} argument is applied.
6488
6489@end table
6490
384ee23f
EZ
6491@node Core File Generation
6492@section How to Produce a Core File from Your Program
6493@cindex dump core from inferior
6494
6495A @dfn{core file} or @dfn{core dump} is a file that records the memory
6496image of a running process and its process status (register values
6497etc.). Its primary use is post-mortem debugging of a program that
6498crashed while it ran outside a debugger. A program that crashes
6499automatically produces a core file, unless this feature is disabled by
6500the user. @xref{Files}, for information on invoking @value{GDBN} in
6501the post-mortem debugging mode.
6502
6503Occasionally, you may wish to produce a core file of the program you
6504are debugging in order to preserve a snapshot of its state.
6505@value{GDBN} has a special command for that.
6506
6507@table @code
6508@kindex gcore
6509@kindex generate-core-file
6510@item generate-core-file [@var{file}]
6511@itemx gcore [@var{file}]
6512Produce a core dump of the inferior process. The optional argument
6513@var{file} specifies the file name where to put the core dump. If not
6514specified, the file name defaults to @file{core.@var{pid}}, where
6515@var{pid} is the inferior process ID.
6516
6517Note that this command is implemented only for some systems (as of
6518this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6519@end table
6520
a0eb71c5
KB
6521@node Character Sets
6522@section Character Sets
6523@cindex character sets
6524@cindex charset
6525@cindex translating between character sets
6526@cindex host character set
6527@cindex target character set
6528
6529If the program you are debugging uses a different character set to
6530represent characters and strings than the one @value{GDBN} uses itself,
6531@value{GDBN} can automatically translate between the character sets for
6532you. The character set @value{GDBN} uses we call the @dfn{host
6533character set}; the one the inferior program uses we call the
6534@dfn{target character set}.
6535
6536For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6537uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6538remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6539running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6540then the host character set is Latin-1, and the target character set is
6541@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6542target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6543@sc{ebcdic} and Latin 1 as you print character or string values, or use
6544character and string literals in expressions.
6545
6546@value{GDBN} has no way to automatically recognize which character set
6547the inferior program uses; you must tell it, using the @code{set
6548target-charset} command, described below.
6549
6550Here are the commands for controlling @value{GDBN}'s character set
6551support:
6552
6553@table @code
6554@item set target-charset @var{charset}
6555@kindex set target-charset
6556Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6557character set names @value{GDBN} recognizes below, but if you type
6558@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6559list the target character sets it supports.
a0eb71c5
KB
6560@end table
6561
6562@table @code
6563@item set host-charset @var{charset}
6564@kindex set host-charset
6565Set the current host character set to @var{charset}.
6566
6567By default, @value{GDBN} uses a host character set appropriate to the
6568system it is running on; you can override that default using the
6569@code{set host-charset} command.
6570
6571@value{GDBN} can only use certain character sets as its host character
6572set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6573indicate which can be host character sets, but if you type
6574@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6575list the host character sets it supports.
a0eb71c5
KB
6576
6577@item set charset @var{charset}
6578@kindex set charset
e33d66ec
EZ
6579Set the current host and target character sets to @var{charset}. As
6580above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6581@value{GDBN} will list the name of the character sets that can be used
6582for both host and target.
6583
a0eb71c5
KB
6584
6585@item show charset
a0eb71c5 6586@kindex show charset
b383017d 6587Show the names of the current host and target charsets.
e33d66ec
EZ
6588
6589@itemx show host-charset
a0eb71c5 6590@kindex show host-charset
b383017d 6591Show the name of the current host charset.
e33d66ec
EZ
6592
6593@itemx show target-charset
a0eb71c5 6594@kindex show target-charset
b383017d 6595Show the name of the current target charset.
a0eb71c5
KB
6596
6597@end table
6598
6599@value{GDBN} currently includes support for the following character
6600sets:
6601
6602@table @code
6603
6604@item ASCII
6605@cindex ASCII character set
6606Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6607character set.
6608
6609@item ISO-8859-1
6610@cindex ISO 8859-1 character set
6611@cindex ISO Latin 1 character set
e33d66ec 6612The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6613characters needed for French, German, and Spanish. @value{GDBN} can use
6614this as its host character set.
6615
6616@item EBCDIC-US
6617@itemx IBM1047
6618@cindex EBCDIC character set
6619@cindex IBM1047 character set
6620Variants of the @sc{ebcdic} character set, used on some of IBM's
6621mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6622@value{GDBN} cannot use these as its host character set.
6623
6624@end table
6625
6626Note that these are all single-byte character sets. More work inside
6627GDB is needed to support multi-byte or variable-width character
6628encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6629
6630Here is an example of @value{GDBN}'s character set support in action.
6631Assume that the following source code has been placed in the file
6632@file{charset-test.c}:
6633
6634@smallexample
6635#include <stdio.h>
6636
6637char ascii_hello[]
6638 = @{72, 101, 108, 108, 111, 44, 32, 119,
6639 111, 114, 108, 100, 33, 10, 0@};
6640char ibm1047_hello[]
6641 = @{200, 133, 147, 147, 150, 107, 64, 166,
6642 150, 153, 147, 132, 90, 37, 0@};
6643
6644main ()
6645@{
6646 printf ("Hello, world!\n");
6647@}
10998722 6648@end smallexample
a0eb71c5
KB
6649
6650In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6651containing the string @samp{Hello, world!} followed by a newline,
6652encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6653
6654We compile the program, and invoke the debugger on it:
6655
6656@smallexample
6657$ gcc -g charset-test.c -o charset-test
6658$ gdb -nw charset-test
6659GNU gdb 2001-12-19-cvs
6660Copyright 2001 Free Software Foundation, Inc.
6661@dots{}
f7dc1244 6662(@value{GDBP})
10998722 6663@end smallexample
a0eb71c5
KB
6664
6665We can use the @code{show charset} command to see what character sets
6666@value{GDBN} is currently using to interpret and display characters and
6667strings:
6668
6669@smallexample
f7dc1244 6670(@value{GDBP}) show charset
e33d66ec 6671The current host and target character set is `ISO-8859-1'.
f7dc1244 6672(@value{GDBP})
10998722 6673@end smallexample
a0eb71c5
KB
6674
6675For the sake of printing this manual, let's use @sc{ascii} as our
6676initial character set:
6677@smallexample
f7dc1244
EZ
6678(@value{GDBP}) set charset ASCII
6679(@value{GDBP}) show charset
e33d66ec 6680The current host and target character set is `ASCII'.
f7dc1244 6681(@value{GDBP})
10998722 6682@end smallexample
a0eb71c5
KB
6683
6684Let's assume that @sc{ascii} is indeed the correct character set for our
6685host system --- in other words, let's assume that if @value{GDBN} prints
6686characters using the @sc{ascii} character set, our terminal will display
6687them properly. Since our current target character set is also
6688@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6689
6690@smallexample
f7dc1244 6691(@value{GDBP}) print ascii_hello
a0eb71c5 6692$1 = 0x401698 "Hello, world!\n"
f7dc1244 6693(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6694$2 = 72 'H'
f7dc1244 6695(@value{GDBP})
10998722 6696@end smallexample
a0eb71c5
KB
6697
6698@value{GDBN} uses the target character set for character and string
6699literals you use in expressions:
6700
6701@smallexample
f7dc1244 6702(@value{GDBP}) print '+'
a0eb71c5 6703$3 = 43 '+'
f7dc1244 6704(@value{GDBP})
10998722 6705@end smallexample
a0eb71c5
KB
6706
6707The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6708character.
6709
6710@value{GDBN} relies on the user to tell it which character set the
6711target program uses. If we print @code{ibm1047_hello} while our target
6712character set is still @sc{ascii}, we get jibberish:
6713
6714@smallexample
f7dc1244 6715(@value{GDBP}) print ibm1047_hello
a0eb71c5 6716$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6717(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6718$5 = 200 '\310'
f7dc1244 6719(@value{GDBP})
10998722 6720@end smallexample
a0eb71c5 6721
e33d66ec 6722If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6723@value{GDBN} tells us the character sets it supports:
6724
6725@smallexample
f7dc1244 6726(@value{GDBP}) set target-charset
b383017d 6727ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6728(@value{GDBP}) set target-charset
10998722 6729@end smallexample
a0eb71c5
KB
6730
6731We can select @sc{ibm1047} as our target character set, and examine the
6732program's strings again. Now the @sc{ascii} string is wrong, but
6733@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6734target character set, @sc{ibm1047}, to the host character set,
6735@sc{ascii}, and they display correctly:
6736
6737@smallexample
f7dc1244
EZ
6738(@value{GDBP}) set target-charset IBM1047
6739(@value{GDBP}) show charset
e33d66ec
EZ
6740The current host character set is `ASCII'.
6741The current target character set is `IBM1047'.
f7dc1244 6742(@value{GDBP}) print ascii_hello
a0eb71c5 6743$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6744(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6745$7 = 72 '\110'
f7dc1244 6746(@value{GDBP}) print ibm1047_hello
a0eb71c5 6747$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6748(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6749$9 = 200 'H'
f7dc1244 6750(@value{GDBP})
10998722 6751@end smallexample
a0eb71c5
KB
6752
6753As above, @value{GDBN} uses the target character set for character and
6754string literals you use in expressions:
6755
6756@smallexample
f7dc1244 6757(@value{GDBP}) print '+'
a0eb71c5 6758$10 = 78 '+'
f7dc1244 6759(@value{GDBP})
10998722 6760@end smallexample
a0eb71c5 6761
e33d66ec 6762The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6763character.
6764
09d4efe1
EZ
6765@node Caching Remote Data
6766@section Caching Data of Remote Targets
6767@cindex caching data of remote targets
6768
6769@value{GDBN} can cache data exchanged between the debugger and a
6770remote target (@pxref{Remote}). Such caching generally improves
6771performance, because it reduces the overhead of the remote protocol by
6772bundling memory reads and writes into large chunks. Unfortunately,
6773@value{GDBN} does not currently know anything about volatile
6774registers, and thus data caching will produce incorrect results when
6775volatile registers are in use.
6776
6777@table @code
6778@kindex set remotecache
6779@item set remotecache on
6780@itemx set remotecache off
6781Set caching state for remote targets. When @code{ON}, use data
6782caching. By default, this option is @code{OFF}.
6783
6784@kindex show remotecache
6785@item show remotecache
6786Show the current state of data caching for remote targets.
6787
6788@kindex info dcache
6789@item info dcache
6790Print the information about the data cache performance. The
6791information displayed includes: the dcache width and depth; and for
6792each cache line, how many times it was referenced, and its data and
6793state (dirty, bad, ok, etc.). This command is useful for debugging
6794the data cache operation.
6795@end table
6796
a0eb71c5 6797
e2e0bcd1
JB
6798@node Macros
6799@chapter C Preprocessor Macros
6800
49efadf5 6801Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6802``preprocessor macros'' which expand into strings of tokens.
6803@value{GDBN} can evaluate expressions containing macro invocations, show
6804the result of macro expansion, and show a macro's definition, including
6805where it was defined.
6806
6807You may need to compile your program specially to provide @value{GDBN}
6808with information about preprocessor macros. Most compilers do not
6809include macros in their debugging information, even when you compile
6810with the @option{-g} flag. @xref{Compilation}.
6811
6812A program may define a macro at one point, remove that definition later,
6813and then provide a different definition after that. Thus, at different
6814points in the program, a macro may have different definitions, or have
6815no definition at all. If there is a current stack frame, @value{GDBN}
6816uses the macros in scope at that frame's source code line. Otherwise,
6817@value{GDBN} uses the macros in scope at the current listing location;
6818see @ref{List}.
6819
6820At the moment, @value{GDBN} does not support the @code{##}
6821token-splicing operator, the @code{#} stringification operator, or
6822variable-arity macros.
6823
6824Whenever @value{GDBN} evaluates an expression, it always expands any
6825macro invocations present in the expression. @value{GDBN} also provides
6826the following commands for working with macros explicitly.
6827
6828@table @code
6829
6830@kindex macro expand
6831@cindex macro expansion, showing the results of preprocessor
6832@cindex preprocessor macro expansion, showing the results of
6833@cindex expanding preprocessor macros
6834@item macro expand @var{expression}
6835@itemx macro exp @var{expression}
6836Show the results of expanding all preprocessor macro invocations in
6837@var{expression}. Since @value{GDBN} simply expands macros, but does
6838not parse the result, @var{expression} need not be a valid expression;
6839it can be any string of tokens.
6840
09d4efe1 6841@kindex macro exp1
e2e0bcd1
JB
6842@item macro expand-once @var{expression}
6843@itemx macro exp1 @var{expression}
4644b6e3 6844@cindex expand macro once
e2e0bcd1
JB
6845@i{(This command is not yet implemented.)} Show the results of
6846expanding those preprocessor macro invocations that appear explicitly in
6847@var{expression}. Macro invocations appearing in that expansion are
6848left unchanged. This command allows you to see the effect of a
6849particular macro more clearly, without being confused by further
6850expansions. Since @value{GDBN} simply expands macros, but does not
6851parse the result, @var{expression} need not be a valid expression; it
6852can be any string of tokens.
6853
475b0867 6854@kindex info macro
e2e0bcd1
JB
6855@cindex macro definition, showing
6856@cindex definition, showing a macro's
475b0867 6857@item info macro @var{macro}
e2e0bcd1
JB
6858Show the definition of the macro named @var{macro}, and describe the
6859source location where that definition was established.
6860
6861@kindex macro define
6862@cindex user-defined macros
6863@cindex defining macros interactively
6864@cindex macros, user-defined
6865@item macro define @var{macro} @var{replacement-list}
6866@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6867@i{(This command is not yet implemented.)} Introduce a definition for a
6868preprocessor macro named @var{macro}, invocations of which are replaced
6869by the tokens given in @var{replacement-list}. The first form of this
6870command defines an ``object-like'' macro, which takes no arguments; the
6871second form defines a ``function-like'' macro, which takes the arguments
6872given in @var{arglist}.
6873
6874A definition introduced by this command is in scope in every expression
6875evaluated in @value{GDBN}, until it is removed with the @command{macro
6876undef} command, described below. The definition overrides all
6877definitions for @var{macro} present in the program being debugged, as
6878well as any previous user-supplied definition.
6879
6880@kindex macro undef
6881@item macro undef @var{macro}
6882@i{(This command is not yet implemented.)} Remove any user-supplied
6883definition for the macro named @var{macro}. This command only affects
6884definitions provided with the @command{macro define} command, described
6885above; it cannot remove definitions present in the program being
6886debugged.
6887
09d4efe1
EZ
6888@kindex macro list
6889@item macro list
6890@i{(This command is not yet implemented.)} List all the macros
6891defined using the @code{macro define} command.
e2e0bcd1
JB
6892@end table
6893
6894@cindex macros, example of debugging with
6895Here is a transcript showing the above commands in action. First, we
6896show our source files:
6897
6898@smallexample
6899$ cat sample.c
6900#include <stdio.h>
6901#include "sample.h"
6902
6903#define M 42
6904#define ADD(x) (M + x)
6905
6906main ()
6907@{
6908#define N 28
6909 printf ("Hello, world!\n");
6910#undef N
6911 printf ("We're so creative.\n");
6912#define N 1729
6913 printf ("Goodbye, world!\n");
6914@}
6915$ cat sample.h
6916#define Q <
6917$
6918@end smallexample
6919
6920Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6921We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6922compiler includes information about preprocessor macros in the debugging
6923information.
6924
6925@smallexample
6926$ gcc -gdwarf-2 -g3 sample.c -o sample
6927$
6928@end smallexample
6929
6930Now, we start @value{GDBN} on our sample program:
6931
6932@smallexample
6933$ gdb -nw sample
6934GNU gdb 2002-05-06-cvs
6935Copyright 2002 Free Software Foundation, Inc.
6936GDB is free software, @dots{}
f7dc1244 6937(@value{GDBP})
e2e0bcd1
JB
6938@end smallexample
6939
6940We can expand macros and examine their definitions, even when the
6941program is not running. @value{GDBN} uses the current listing position
6942to decide which macro definitions are in scope:
6943
6944@smallexample
f7dc1244 6945(@value{GDBP}) list main
e2e0bcd1
JB
69463
69474 #define M 42
69485 #define ADD(x) (M + x)
69496
69507 main ()
69518 @{
69529 #define N 28
695310 printf ("Hello, world!\n");
695411 #undef N
695512 printf ("We're so creative.\n");
f7dc1244 6956(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6957Defined at /home/jimb/gdb/macros/play/sample.c:5
6958#define ADD(x) (M + x)
f7dc1244 6959(@value{GDBP}) info macro Q
e2e0bcd1
JB
6960Defined at /home/jimb/gdb/macros/play/sample.h:1
6961 included at /home/jimb/gdb/macros/play/sample.c:2
6962#define Q <
f7dc1244 6963(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6964expands to: (42 + 1)
f7dc1244 6965(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6966expands to: once (M + 1)
f7dc1244 6967(@value{GDBP})
e2e0bcd1
JB
6968@end smallexample
6969
6970In the example above, note that @command{macro expand-once} expands only
6971the macro invocation explicit in the original text --- the invocation of
6972@code{ADD} --- but does not expand the invocation of the macro @code{M},
6973which was introduced by @code{ADD}.
6974
6975Once the program is running, GDB uses the macro definitions in force at
6976the source line of the current stack frame:
6977
6978@smallexample
f7dc1244 6979(@value{GDBP}) break main
e2e0bcd1 6980Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 6981(@value{GDBP}) run
b383017d 6982Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
6983
6984Breakpoint 1, main () at sample.c:10
698510 printf ("Hello, world!\n");
f7dc1244 6986(@value{GDBP})
e2e0bcd1
JB
6987@end smallexample
6988
6989At line 10, the definition of the macro @code{N} at line 9 is in force:
6990
6991@smallexample
f7dc1244 6992(@value{GDBP}) info macro N
e2e0bcd1
JB
6993Defined at /home/jimb/gdb/macros/play/sample.c:9
6994#define N 28
f7dc1244 6995(@value{GDBP}) macro expand N Q M
e2e0bcd1 6996expands to: 28 < 42
f7dc1244 6997(@value{GDBP}) print N Q M
e2e0bcd1 6998$1 = 1
f7dc1244 6999(@value{GDBP})
e2e0bcd1
JB
7000@end smallexample
7001
7002As we step over directives that remove @code{N}'s definition, and then
7003give it a new definition, @value{GDBN} finds the definition (or lack
7004thereof) in force at each point:
7005
7006@smallexample
f7dc1244 7007(@value{GDBP}) next
e2e0bcd1
JB
7008Hello, world!
700912 printf ("We're so creative.\n");
f7dc1244 7010(@value{GDBP}) info macro N
e2e0bcd1
JB
7011The symbol `N' has no definition as a C/C++ preprocessor macro
7012at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7013(@value{GDBP}) next
e2e0bcd1
JB
7014We're so creative.
701514 printf ("Goodbye, world!\n");
f7dc1244 7016(@value{GDBP}) info macro N
e2e0bcd1
JB
7017Defined at /home/jimb/gdb/macros/play/sample.c:13
7018#define N 1729
f7dc1244 7019(@value{GDBP}) macro expand N Q M
e2e0bcd1 7020expands to: 1729 < 42
f7dc1244 7021(@value{GDBP}) print N Q M
e2e0bcd1 7022$2 = 0
f7dc1244 7023(@value{GDBP})
e2e0bcd1
JB
7024@end smallexample
7025
7026
b37052ae
EZ
7027@node Tracepoints
7028@chapter Tracepoints
7029@c This chapter is based on the documentation written by Michael
7030@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7031
7032@cindex tracepoints
7033In some applications, it is not feasible for the debugger to interrupt
7034the program's execution long enough for the developer to learn
7035anything helpful about its behavior. If the program's correctness
7036depends on its real-time behavior, delays introduced by a debugger
7037might cause the program to change its behavior drastically, or perhaps
7038fail, even when the code itself is correct. It is useful to be able
7039to observe the program's behavior without interrupting it.
7040
7041Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7042specify locations in the program, called @dfn{tracepoints}, and
7043arbitrary expressions to evaluate when those tracepoints are reached.
7044Later, using the @code{tfind} command, you can examine the values
7045those expressions had when the program hit the tracepoints. The
7046expressions may also denote objects in memory---structures or arrays,
7047for example---whose values @value{GDBN} should record; while visiting
7048a particular tracepoint, you may inspect those objects as if they were
7049in memory at that moment. However, because @value{GDBN} records these
7050values without interacting with you, it can do so quickly and
7051unobtrusively, hopefully not disturbing the program's behavior.
7052
7053The tracepoint facility is currently available only for remote
2c0069bb
EZ
7054targets. @xref{Targets}. In addition, your remote target must know how
7055to collect trace data. This functionality is implemented in the remote
7056stub; however, none of the stubs distributed with @value{GDBN} support
7057tracepoints as of this writing.
b37052ae
EZ
7058
7059This chapter describes the tracepoint commands and features.
7060
7061@menu
b383017d
RM
7062* Set Tracepoints::
7063* Analyze Collected Data::
7064* Tracepoint Variables::
b37052ae
EZ
7065@end menu
7066
7067@node Set Tracepoints
7068@section Commands to Set Tracepoints
7069
7070Before running such a @dfn{trace experiment}, an arbitrary number of
7071tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7072tracepoint has a number assigned to it by @value{GDBN}. Like with
7073breakpoints, tracepoint numbers are successive integers starting from
7074one. Many of the commands associated with tracepoints take the
7075tracepoint number as their argument, to identify which tracepoint to
7076work on.
7077
7078For each tracepoint, you can specify, in advance, some arbitrary set
7079of data that you want the target to collect in the trace buffer when
7080it hits that tracepoint. The collected data can include registers,
7081local variables, or global data. Later, you can use @value{GDBN}
7082commands to examine the values these data had at the time the
7083tracepoint was hit.
7084
7085This section describes commands to set tracepoints and associated
7086conditions and actions.
7087
7088@menu
b383017d
RM
7089* Create and Delete Tracepoints::
7090* Enable and Disable Tracepoints::
7091* Tracepoint Passcounts::
7092* Tracepoint Actions::
7093* Listing Tracepoints::
7094* Starting and Stopping Trace Experiment::
b37052ae
EZ
7095@end menu
7096
7097@node Create and Delete Tracepoints
7098@subsection Create and Delete Tracepoints
7099
7100@table @code
7101@cindex set tracepoint
7102@kindex trace
7103@item trace
7104The @code{trace} command is very similar to the @code{break} command.
7105Its argument can be a source line, a function name, or an address in
7106the target program. @xref{Set Breaks}. The @code{trace} command
7107defines a tracepoint, which is a point in the target program where the
7108debugger will briefly stop, collect some data, and then allow the
7109program to continue. Setting a tracepoint or changing its commands
7110doesn't take effect until the next @code{tstart} command; thus, you
7111cannot change the tracepoint attributes once a trace experiment is
7112running.
7113
7114Here are some examples of using the @code{trace} command:
7115
7116@smallexample
7117(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7118
7119(@value{GDBP}) @b{trace +2} // 2 lines forward
7120
7121(@value{GDBP}) @b{trace my_function} // first source line of function
7122
7123(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7124
7125(@value{GDBP}) @b{trace *0x2117c4} // an address
7126@end smallexample
7127
7128@noindent
7129You can abbreviate @code{trace} as @code{tr}.
7130
7131@vindex $tpnum
7132@cindex last tracepoint number
7133@cindex recent tracepoint number
7134@cindex tracepoint number
7135The convenience variable @code{$tpnum} records the tracepoint number
7136of the most recently set tracepoint.
7137
7138@kindex delete tracepoint
7139@cindex tracepoint deletion
7140@item delete tracepoint @r{[}@var{num}@r{]}
7141Permanently delete one or more tracepoints. With no argument, the
7142default is to delete all tracepoints.
7143
7144Examples:
7145
7146@smallexample
7147(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7148
7149(@value{GDBP}) @b{delete trace} // remove all tracepoints
7150@end smallexample
7151
7152@noindent
7153You can abbreviate this command as @code{del tr}.
7154@end table
7155
7156@node Enable and Disable Tracepoints
7157@subsection Enable and Disable Tracepoints
7158
7159@table @code
7160@kindex disable tracepoint
7161@item disable tracepoint @r{[}@var{num}@r{]}
7162Disable tracepoint @var{num}, or all tracepoints if no argument
7163@var{num} is given. A disabled tracepoint will have no effect during
7164the next trace experiment, but it is not forgotten. You can re-enable
7165a disabled tracepoint using the @code{enable tracepoint} command.
7166
7167@kindex enable tracepoint
7168@item enable tracepoint @r{[}@var{num}@r{]}
7169Enable tracepoint @var{num}, or all tracepoints. The enabled
7170tracepoints will become effective the next time a trace experiment is
7171run.
7172@end table
7173
7174@node Tracepoint Passcounts
7175@subsection Tracepoint Passcounts
7176
7177@table @code
7178@kindex passcount
7179@cindex tracepoint pass count
7180@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7181Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7182automatically stop a trace experiment. If a tracepoint's passcount is
7183@var{n}, then the trace experiment will be automatically stopped on
7184the @var{n}'th time that tracepoint is hit. If the tracepoint number
7185@var{num} is not specified, the @code{passcount} command sets the
7186passcount of the most recently defined tracepoint. If no passcount is
7187given, the trace experiment will run until stopped explicitly by the
7188user.
7189
7190Examples:
7191
7192@smallexample
b383017d 7193(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7194@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7195
7196(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7197@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7198(@value{GDBP}) @b{trace foo}
7199(@value{GDBP}) @b{pass 3}
7200(@value{GDBP}) @b{trace bar}
7201(@value{GDBP}) @b{pass 2}
7202(@value{GDBP}) @b{trace baz}
7203(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7204@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7205@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7206@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7207@end smallexample
7208@end table
7209
7210@node Tracepoint Actions
7211@subsection Tracepoint Action Lists
7212
7213@table @code
7214@kindex actions
7215@cindex tracepoint actions
7216@item actions @r{[}@var{num}@r{]}
7217This command will prompt for a list of actions to be taken when the
7218tracepoint is hit. If the tracepoint number @var{num} is not
7219specified, this command sets the actions for the one that was most
7220recently defined (so that you can define a tracepoint and then say
7221@code{actions} without bothering about its number). You specify the
7222actions themselves on the following lines, one action at a time, and
7223terminate the actions list with a line containing just @code{end}. So
7224far, the only defined actions are @code{collect} and
7225@code{while-stepping}.
7226
7227@cindex remove actions from a tracepoint
7228To remove all actions from a tracepoint, type @samp{actions @var{num}}
7229and follow it immediately with @samp{end}.
7230
7231@smallexample
7232(@value{GDBP}) @b{collect @var{data}} // collect some data
7233
6826cf00 7234(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7235
6826cf00 7236(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7237@end smallexample
7238
7239In the following example, the action list begins with @code{collect}
7240commands indicating the things to be collected when the tracepoint is
7241hit. Then, in order to single-step and collect additional data
7242following the tracepoint, a @code{while-stepping} command is used,
7243followed by the list of things to be collected while stepping. The
7244@code{while-stepping} command is terminated by its own separate
7245@code{end} command. Lastly, the action list is terminated by an
7246@code{end} command.
7247
7248@smallexample
7249(@value{GDBP}) @b{trace foo}
7250(@value{GDBP}) @b{actions}
7251Enter actions for tracepoint 1, one per line:
7252> collect bar,baz
7253> collect $regs
7254> while-stepping 12
7255 > collect $fp, $sp
7256 > end
7257end
7258@end smallexample
7259
7260@kindex collect @r{(tracepoints)}
7261@item collect @var{expr1}, @var{expr2}, @dots{}
7262Collect values of the given expressions when the tracepoint is hit.
7263This command accepts a comma-separated list of any valid expressions.
7264In addition to global, static, or local variables, the following
7265special arguments are supported:
7266
7267@table @code
7268@item $regs
7269collect all registers
7270
7271@item $args
7272collect all function arguments
7273
7274@item $locals
7275collect all local variables.
7276@end table
7277
7278You can give several consecutive @code{collect} commands, each one
7279with a single argument, or one @code{collect} command with several
7280arguments separated by commas: the effect is the same.
7281
f5c37c66
EZ
7282The command @code{info scope} (@pxref{Symbols, info scope}) is
7283particularly useful for figuring out what data to collect.
7284
b37052ae
EZ
7285@kindex while-stepping @r{(tracepoints)}
7286@item while-stepping @var{n}
7287Perform @var{n} single-step traces after the tracepoint, collecting
7288new data at each step. The @code{while-stepping} command is
7289followed by the list of what to collect while stepping (followed by
7290its own @code{end} command):
7291
7292@smallexample
7293> while-stepping 12
7294 > collect $regs, myglobal
7295 > end
7296>
7297@end smallexample
7298
7299@noindent
7300You may abbreviate @code{while-stepping} as @code{ws} or
7301@code{stepping}.
7302@end table
7303
7304@node Listing Tracepoints
7305@subsection Listing Tracepoints
7306
7307@table @code
7308@kindex info tracepoints
09d4efe1 7309@kindex info tp
b37052ae
EZ
7310@cindex information about tracepoints
7311@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7312Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7313a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7314defined so far. For each tracepoint, the following information is
7315shown:
7316
7317@itemize @bullet
7318@item
7319its number
7320@item
7321whether it is enabled or disabled
7322@item
7323its address
7324@item
7325its passcount as given by the @code{passcount @var{n}} command
7326@item
7327its step count as given by the @code{while-stepping @var{n}} command
7328@item
7329where in the source files is the tracepoint set
7330@item
7331its action list as given by the @code{actions} command
7332@end itemize
7333
7334@smallexample
7335(@value{GDBP}) @b{info trace}
7336Num Enb Address PassC StepC What
73371 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73382 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73393 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7340(@value{GDBP})
7341@end smallexample
7342
7343@noindent
7344This command can be abbreviated @code{info tp}.
7345@end table
7346
7347@node Starting and Stopping Trace Experiment
7348@subsection Starting and Stopping Trace Experiment
7349
7350@table @code
7351@kindex tstart
7352@cindex start a new trace experiment
7353@cindex collected data discarded
7354@item tstart
7355This command takes no arguments. It starts the trace experiment, and
7356begins collecting data. This has the side effect of discarding all
7357the data collected in the trace buffer during the previous trace
7358experiment.
7359
7360@kindex tstop
7361@cindex stop a running trace experiment
7362@item tstop
7363This command takes no arguments. It ends the trace experiment, and
7364stops collecting data.
7365
68c71a2e 7366@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7367automatically if any tracepoint's passcount is reached
7368(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7369
7370@kindex tstatus
7371@cindex status of trace data collection
7372@cindex trace experiment, status of
7373@item tstatus
7374This command displays the status of the current trace data
7375collection.
7376@end table
7377
7378Here is an example of the commands we described so far:
7379
7380@smallexample
7381(@value{GDBP}) @b{trace gdb_c_test}
7382(@value{GDBP}) @b{actions}
7383Enter actions for tracepoint #1, one per line.
7384> collect $regs,$locals,$args
7385> while-stepping 11
7386 > collect $regs
7387 > end
7388> end
7389(@value{GDBP}) @b{tstart}
7390 [time passes @dots{}]
7391(@value{GDBP}) @b{tstop}
7392@end smallexample
7393
7394
7395@node Analyze Collected Data
7396@section Using the collected data
7397
7398After the tracepoint experiment ends, you use @value{GDBN} commands
7399for examining the trace data. The basic idea is that each tracepoint
7400collects a trace @dfn{snapshot} every time it is hit and another
7401snapshot every time it single-steps. All these snapshots are
7402consecutively numbered from zero and go into a buffer, and you can
7403examine them later. The way you examine them is to @dfn{focus} on a
7404specific trace snapshot. When the remote stub is focused on a trace
7405snapshot, it will respond to all @value{GDBN} requests for memory and
7406registers by reading from the buffer which belongs to that snapshot,
7407rather than from @emph{real} memory or registers of the program being
7408debugged. This means that @strong{all} @value{GDBN} commands
7409(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7410behave as if we were currently debugging the program state as it was
7411when the tracepoint occurred. Any requests for data that are not in
7412the buffer will fail.
7413
7414@menu
7415* tfind:: How to select a trace snapshot
7416* tdump:: How to display all data for a snapshot
7417* save-tracepoints:: How to save tracepoints for a future run
7418@end menu
7419
7420@node tfind
7421@subsection @code{tfind @var{n}}
7422
7423@kindex tfind
7424@cindex select trace snapshot
7425@cindex find trace snapshot
7426The basic command for selecting a trace snapshot from the buffer is
7427@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7428counting from zero. If no argument @var{n} is given, the next
7429snapshot is selected.
7430
7431Here are the various forms of using the @code{tfind} command.
7432
7433@table @code
7434@item tfind start
7435Find the first snapshot in the buffer. This is a synonym for
7436@code{tfind 0} (since 0 is the number of the first snapshot).
7437
7438@item tfind none
7439Stop debugging trace snapshots, resume @emph{live} debugging.
7440
7441@item tfind end
7442Same as @samp{tfind none}.
7443
7444@item tfind
7445No argument means find the next trace snapshot.
7446
7447@item tfind -
7448Find the previous trace snapshot before the current one. This permits
7449retracing earlier steps.
7450
7451@item tfind tracepoint @var{num}
7452Find the next snapshot associated with tracepoint @var{num}. Search
7453proceeds forward from the last examined trace snapshot. If no
7454argument @var{num} is given, it means find the next snapshot collected
7455for the same tracepoint as the current snapshot.
7456
7457@item tfind pc @var{addr}
7458Find the next snapshot associated with the value @var{addr} of the
7459program counter. Search proceeds forward from the last examined trace
7460snapshot. If no argument @var{addr} is given, it means find the next
7461snapshot with the same value of PC as the current snapshot.
7462
7463@item tfind outside @var{addr1}, @var{addr2}
7464Find the next snapshot whose PC is outside the given range of
7465addresses.
7466
7467@item tfind range @var{addr1}, @var{addr2}
7468Find the next snapshot whose PC is between @var{addr1} and
7469@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7470
7471@item tfind line @r{[}@var{file}:@r{]}@var{n}
7472Find the next snapshot associated with the source line @var{n}. If
7473the optional argument @var{file} is given, refer to line @var{n} in
7474that source file. Search proceeds forward from the last examined
7475trace snapshot. If no argument @var{n} is given, it means find the
7476next line other than the one currently being examined; thus saying
7477@code{tfind line} repeatedly can appear to have the same effect as
7478stepping from line to line in a @emph{live} debugging session.
7479@end table
7480
7481The default arguments for the @code{tfind} commands are specifically
7482designed to make it easy to scan through the trace buffer. For
7483instance, @code{tfind} with no argument selects the next trace
7484snapshot, and @code{tfind -} with no argument selects the previous
7485trace snapshot. So, by giving one @code{tfind} command, and then
7486simply hitting @key{RET} repeatedly you can examine all the trace
7487snapshots in order. Or, by saying @code{tfind -} and then hitting
7488@key{RET} repeatedly you can examine the snapshots in reverse order.
7489The @code{tfind line} command with no argument selects the snapshot
7490for the next source line executed. The @code{tfind pc} command with
7491no argument selects the next snapshot with the same program counter
7492(PC) as the current frame. The @code{tfind tracepoint} command with
7493no argument selects the next trace snapshot collected by the same
7494tracepoint as the current one.
7495
7496In addition to letting you scan through the trace buffer manually,
7497these commands make it easy to construct @value{GDBN} scripts that
7498scan through the trace buffer and print out whatever collected data
7499you are interested in. Thus, if we want to examine the PC, FP, and SP
7500registers from each trace frame in the buffer, we can say this:
7501
7502@smallexample
7503(@value{GDBP}) @b{tfind start}
7504(@value{GDBP}) @b{while ($trace_frame != -1)}
7505> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7506 $trace_frame, $pc, $sp, $fp
7507> tfind
7508> end
7509
7510Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7511Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7512Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7513Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7514Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7515Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7516Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7517Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7518Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7519Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7520Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7521@end smallexample
7522
7523Or, if we want to examine the variable @code{X} at each source line in
7524the buffer:
7525
7526@smallexample
7527(@value{GDBP}) @b{tfind start}
7528(@value{GDBP}) @b{while ($trace_frame != -1)}
7529> printf "Frame %d, X == %d\n", $trace_frame, X
7530> tfind line
7531> end
7532
7533Frame 0, X = 1
7534Frame 7, X = 2
7535Frame 13, X = 255
7536@end smallexample
7537
7538@node tdump
7539@subsection @code{tdump}
7540@kindex tdump
7541@cindex dump all data collected at tracepoint
7542@cindex tracepoint data, display
7543
7544This command takes no arguments. It prints all the data collected at
7545the current trace snapshot.
7546
7547@smallexample
7548(@value{GDBP}) @b{trace 444}
7549(@value{GDBP}) @b{actions}
7550Enter actions for tracepoint #2, one per line:
7551> collect $regs, $locals, $args, gdb_long_test
7552> end
7553
7554(@value{GDBP}) @b{tstart}
7555
7556(@value{GDBP}) @b{tfind line 444}
7557#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7558at gdb_test.c:444
7559444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7560
7561(@value{GDBP}) @b{tdump}
7562Data collected at tracepoint 2, trace frame 1:
7563d0 0xc4aa0085 -995491707
7564d1 0x18 24
7565d2 0x80 128
7566d3 0x33 51
7567d4 0x71aea3d 119204413
7568d5 0x22 34
7569d6 0xe0 224
7570d7 0x380035 3670069
7571a0 0x19e24a 1696330
7572a1 0x3000668 50333288
7573a2 0x100 256
7574a3 0x322000 3284992
7575a4 0x3000698 50333336
7576a5 0x1ad3cc 1758156
7577fp 0x30bf3c 0x30bf3c
7578sp 0x30bf34 0x30bf34
7579ps 0x0 0
7580pc 0x20b2c8 0x20b2c8
7581fpcontrol 0x0 0
7582fpstatus 0x0 0
7583fpiaddr 0x0 0
7584p = 0x20e5b4 "gdb-test"
7585p1 = (void *) 0x11
7586p2 = (void *) 0x22
7587p3 = (void *) 0x33
7588p4 = (void *) 0x44
7589p5 = (void *) 0x55
7590p6 = (void *) 0x66
7591gdb_long_test = 17 '\021'
7592
7593(@value{GDBP})
7594@end smallexample
7595
7596@node save-tracepoints
7597@subsection @code{save-tracepoints @var{filename}}
7598@kindex save-tracepoints
7599@cindex save tracepoints for future sessions
7600
7601This command saves all current tracepoint definitions together with
7602their actions and passcounts, into a file @file{@var{filename}}
7603suitable for use in a later debugging session. To read the saved
7604tracepoint definitions, use the @code{source} command (@pxref{Command
7605Files}).
7606
7607@node Tracepoint Variables
7608@section Convenience Variables for Tracepoints
7609@cindex tracepoint variables
7610@cindex convenience variables for tracepoints
7611
7612@table @code
7613@vindex $trace_frame
7614@item (int) $trace_frame
7615The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7616snapshot is selected.
7617
7618@vindex $tracepoint
7619@item (int) $tracepoint
7620The tracepoint for the current trace snapshot.
7621
7622@vindex $trace_line
7623@item (int) $trace_line
7624The line number for the current trace snapshot.
7625
7626@vindex $trace_file
7627@item (char []) $trace_file
7628The source file for the current trace snapshot.
7629
7630@vindex $trace_func
7631@item (char []) $trace_func
7632The name of the function containing @code{$tracepoint}.
7633@end table
7634
7635Note: @code{$trace_file} is not suitable for use in @code{printf},
7636use @code{output} instead.
7637
7638Here's a simple example of using these convenience variables for
7639stepping through all the trace snapshots and printing some of their
7640data.
7641
7642@smallexample
7643(@value{GDBP}) @b{tfind start}
7644
7645(@value{GDBP}) @b{while $trace_frame != -1}
7646> output $trace_file
7647> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7648> tfind
7649> end
7650@end smallexample
7651
df0cd8c5
JB
7652@node Overlays
7653@chapter Debugging Programs That Use Overlays
7654@cindex overlays
7655
7656If your program is too large to fit completely in your target system's
7657memory, you can sometimes use @dfn{overlays} to work around this
7658problem. @value{GDBN} provides some support for debugging programs that
7659use overlays.
7660
7661@menu
7662* How Overlays Work:: A general explanation of overlays.
7663* Overlay Commands:: Managing overlays in @value{GDBN}.
7664* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7665 mapped by asking the inferior.
7666* Overlay Sample Program:: A sample program using overlays.
7667@end menu
7668
7669@node How Overlays Work
7670@section How Overlays Work
7671@cindex mapped overlays
7672@cindex unmapped overlays
7673@cindex load address, overlay's
7674@cindex mapped address
7675@cindex overlay area
7676
7677Suppose you have a computer whose instruction address space is only 64
7678kilobytes long, but which has much more memory which can be accessed by
7679other means: special instructions, segment registers, or memory
7680management hardware, for example. Suppose further that you want to
7681adapt a program which is larger than 64 kilobytes to run on this system.
7682
7683One solution is to identify modules of your program which are relatively
7684independent, and need not call each other directly; call these modules
7685@dfn{overlays}. Separate the overlays from the main program, and place
7686their machine code in the larger memory. Place your main program in
7687instruction memory, but leave at least enough space there to hold the
7688largest overlay as well.
7689
7690Now, to call a function located in an overlay, you must first copy that
7691overlay's machine code from the large memory into the space set aside
7692for it in the instruction memory, and then jump to its entry point
7693there.
7694
c928edc0
AC
7695@c NB: In the below the mapped area's size is greater or equal to the
7696@c size of all overlays. This is intentional to remind the developer
7697@c that overlays don't necessarily need to be the same size.
7698
474c8240 7699@smallexample
df0cd8c5 7700@group
c928edc0
AC
7701 Data Instruction Larger
7702Address Space Address Space Address Space
7703+-----------+ +-----------+ +-----------+
7704| | | | | |
7705+-----------+ +-----------+ +-----------+<-- overlay 1
7706| program | | main | .----| overlay 1 | load address
7707| variables | | program | | +-----------+
7708| and heap | | | | | |
7709+-----------+ | | | +-----------+<-- overlay 2
7710| | +-----------+ | | | load address
7711+-----------+ | | | .-| overlay 2 |
7712 | | | | | |
7713 mapped --->+-----------+ | | +-----------+
7714 address | | | | | |
7715 | overlay | <-' | | |
7716 | area | <---' +-----------+<-- overlay 3
7717 | | <---. | | load address
7718 +-----------+ `--| overlay 3 |
7719 | | | |
7720 +-----------+ | |
7721 +-----------+
7722 | |
7723 +-----------+
7724
7725 @anchor{A code overlay}A code overlay
df0cd8c5 7726@end group
474c8240 7727@end smallexample
df0cd8c5 7728
c928edc0
AC
7729The diagram (@pxref{A code overlay}) shows a system with separate data
7730and instruction address spaces. To map an overlay, the program copies
7731its code from the larger address space to the instruction address space.
7732Since the overlays shown here all use the same mapped address, only one
7733may be mapped at a time. For a system with a single address space for
7734data and instructions, the diagram would be similar, except that the
7735program variables and heap would share an address space with the main
7736program and the overlay area.
df0cd8c5
JB
7737
7738An overlay loaded into instruction memory and ready for use is called a
7739@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7740instruction memory. An overlay not present (or only partially present)
7741in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7742is its address in the larger memory. The mapped address is also called
7743the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7744called the @dfn{load memory address}, or @dfn{LMA}.
7745
7746Unfortunately, overlays are not a completely transparent way to adapt a
7747program to limited instruction memory. They introduce a new set of
7748global constraints you must keep in mind as you design your program:
7749
7750@itemize @bullet
7751
7752@item
7753Before calling or returning to a function in an overlay, your program
7754must make sure that overlay is actually mapped. Otherwise, the call or
7755return will transfer control to the right address, but in the wrong
7756overlay, and your program will probably crash.
7757
7758@item
7759If the process of mapping an overlay is expensive on your system, you
7760will need to choose your overlays carefully to minimize their effect on
7761your program's performance.
7762
7763@item
7764The executable file you load onto your system must contain each
7765overlay's instructions, appearing at the overlay's load address, not its
7766mapped address. However, each overlay's instructions must be relocated
7767and its symbols defined as if the overlay were at its mapped address.
7768You can use GNU linker scripts to specify different load and relocation
7769addresses for pieces of your program; see @ref{Overlay Description,,,
7770ld.info, Using ld: the GNU linker}.
7771
7772@item
7773The procedure for loading executable files onto your system must be able
7774to load their contents into the larger address space as well as the
7775instruction and data spaces.
7776
7777@end itemize
7778
7779The overlay system described above is rather simple, and could be
7780improved in many ways:
7781
7782@itemize @bullet
7783
7784@item
7785If your system has suitable bank switch registers or memory management
7786hardware, you could use those facilities to make an overlay's load area
7787contents simply appear at their mapped address in instruction space.
7788This would probably be faster than copying the overlay to its mapped
7789area in the usual way.
7790
7791@item
7792If your overlays are small enough, you could set aside more than one
7793overlay area, and have more than one overlay mapped at a time.
7794
7795@item
7796You can use overlays to manage data, as well as instructions. In
7797general, data overlays are even less transparent to your design than
7798code overlays: whereas code overlays only require care when you call or
7799return to functions, data overlays require care every time you access
7800the data. Also, if you change the contents of a data overlay, you
7801must copy its contents back out to its load address before you can copy a
7802different data overlay into the same mapped area.
7803
7804@end itemize
7805
7806
7807@node Overlay Commands
7808@section Overlay Commands
7809
7810To use @value{GDBN}'s overlay support, each overlay in your program must
7811correspond to a separate section of the executable file. The section's
7812virtual memory address and load memory address must be the overlay's
7813mapped and load addresses. Identifying overlays with sections allows
7814@value{GDBN} to determine the appropriate address of a function or
7815variable, depending on whether the overlay is mapped or not.
7816
7817@value{GDBN}'s overlay commands all start with the word @code{overlay};
7818you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7819
7820@table @code
7821@item overlay off
4644b6e3 7822@kindex overlay
df0cd8c5
JB
7823Disable @value{GDBN}'s overlay support. When overlay support is
7824disabled, @value{GDBN} assumes that all functions and variables are
7825always present at their mapped addresses. By default, @value{GDBN}'s
7826overlay support is disabled.
7827
7828@item overlay manual
df0cd8c5
JB
7829@cindex manual overlay debugging
7830Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7831relies on you to tell it which overlays are mapped, and which are not,
7832using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7833commands described below.
7834
7835@item overlay map-overlay @var{overlay}
7836@itemx overlay map @var{overlay}
df0cd8c5
JB
7837@cindex map an overlay
7838Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7839be the name of the object file section containing the overlay. When an
7840overlay is mapped, @value{GDBN} assumes it can find the overlay's
7841functions and variables at their mapped addresses. @value{GDBN} assumes
7842that any other overlays whose mapped ranges overlap that of
7843@var{overlay} are now unmapped.
7844
7845@item overlay unmap-overlay @var{overlay}
7846@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7847@cindex unmap an overlay
7848Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7849must be the name of the object file section containing the overlay.
7850When an overlay is unmapped, @value{GDBN} assumes it can find the
7851overlay's functions and variables at their load addresses.
7852
7853@item overlay auto
df0cd8c5
JB
7854Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7855consults a data structure the overlay manager maintains in the inferior
7856to see which overlays are mapped. For details, see @ref{Automatic
7857Overlay Debugging}.
7858
7859@item overlay load-target
7860@itemx overlay load
df0cd8c5
JB
7861@cindex reloading the overlay table
7862Re-read the overlay table from the inferior. Normally, @value{GDBN}
7863re-reads the table @value{GDBN} automatically each time the inferior
7864stops, so this command should only be necessary if you have changed the
7865overlay mapping yourself using @value{GDBN}. This command is only
7866useful when using automatic overlay debugging.
7867
7868@item overlay list-overlays
7869@itemx overlay list
7870@cindex listing mapped overlays
7871Display a list of the overlays currently mapped, along with their mapped
7872addresses, load addresses, and sizes.
7873
7874@end table
7875
7876Normally, when @value{GDBN} prints a code address, it includes the name
7877of the function the address falls in:
7878
474c8240 7879@smallexample
f7dc1244 7880(@value{GDBP}) print main
df0cd8c5 7881$3 = @{int ()@} 0x11a0 <main>
474c8240 7882@end smallexample
df0cd8c5
JB
7883@noindent
7884When overlay debugging is enabled, @value{GDBN} recognizes code in
7885unmapped overlays, and prints the names of unmapped functions with
7886asterisks around them. For example, if @code{foo} is a function in an
7887unmapped overlay, @value{GDBN} prints it this way:
7888
474c8240 7889@smallexample
f7dc1244 7890(@value{GDBP}) overlay list
df0cd8c5 7891No sections are mapped.
f7dc1244 7892(@value{GDBP}) print foo
df0cd8c5 7893$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7894@end smallexample
df0cd8c5
JB
7895@noindent
7896When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7897name normally:
7898
474c8240 7899@smallexample
f7dc1244 7900(@value{GDBP}) overlay list
b383017d 7901Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7902 mapped at 0x1016 - 0x104a
f7dc1244 7903(@value{GDBP}) print foo
df0cd8c5 7904$6 = @{int (int)@} 0x1016 <foo>
474c8240 7905@end smallexample
df0cd8c5
JB
7906
7907When overlay debugging is enabled, @value{GDBN} can find the correct
7908address for functions and variables in an overlay, whether or not the
7909overlay is mapped. This allows most @value{GDBN} commands, like
7910@code{break} and @code{disassemble}, to work normally, even on unmapped
7911code. However, @value{GDBN}'s breakpoint support has some limitations:
7912
7913@itemize @bullet
7914@item
7915@cindex breakpoints in overlays
7916@cindex overlays, setting breakpoints in
7917You can set breakpoints in functions in unmapped overlays, as long as
7918@value{GDBN} can write to the overlay at its load address.
7919@item
7920@value{GDBN} can not set hardware or simulator-based breakpoints in
7921unmapped overlays. However, if you set a breakpoint at the end of your
7922overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7923you are using manual overlay management), @value{GDBN} will re-set its
7924breakpoints properly.
7925@end itemize
7926
7927
7928@node Automatic Overlay Debugging
7929@section Automatic Overlay Debugging
7930@cindex automatic overlay debugging
7931
7932@value{GDBN} can automatically track which overlays are mapped and which
7933are not, given some simple co-operation from the overlay manager in the
7934inferior. If you enable automatic overlay debugging with the
7935@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7936looks in the inferior's memory for certain variables describing the
7937current state of the overlays.
7938
7939Here are the variables your overlay manager must define to support
7940@value{GDBN}'s automatic overlay debugging:
7941
7942@table @asis
7943
7944@item @code{_ovly_table}:
7945This variable must be an array of the following structures:
7946
474c8240 7947@smallexample
df0cd8c5
JB
7948struct
7949@{
7950 /* The overlay's mapped address. */
7951 unsigned long vma;
7952
7953 /* The size of the overlay, in bytes. */
7954 unsigned long size;
7955
7956 /* The overlay's load address. */
7957 unsigned long lma;
7958
7959 /* Non-zero if the overlay is currently mapped;
7960 zero otherwise. */
7961 unsigned long mapped;
7962@}
474c8240 7963@end smallexample
df0cd8c5
JB
7964
7965@item @code{_novlys}:
7966This variable must be a four-byte signed integer, holding the total
7967number of elements in @code{_ovly_table}.
7968
7969@end table
7970
7971To decide whether a particular overlay is mapped or not, @value{GDBN}
7972looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7973@code{lma} members equal the VMA and LMA of the overlay's section in the
7974executable file. When @value{GDBN} finds a matching entry, it consults
7975the entry's @code{mapped} member to determine whether the overlay is
7976currently mapped.
7977
81d46470 7978In addition, your overlay manager may define a function called
def71bfa 7979@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
7980will silently set a breakpoint there. If the overlay manager then
7981calls this function whenever it has changed the overlay table, this
7982will enable @value{GDBN} to accurately keep track of which overlays
7983are in program memory, and update any breakpoints that may be set
b383017d 7984in overlays. This will allow breakpoints to work even if the
81d46470
MS
7985overlays are kept in ROM or other non-writable memory while they
7986are not being executed.
df0cd8c5
JB
7987
7988@node Overlay Sample Program
7989@section Overlay Sample Program
7990@cindex overlay example program
7991
7992When linking a program which uses overlays, you must place the overlays
7993at their load addresses, while relocating them to run at their mapped
7994addresses. To do this, you must write a linker script (@pxref{Overlay
7995Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
7996since linker scripts are specific to a particular host system, target
7997architecture, and target memory layout, this manual cannot provide
7998portable sample code demonstrating @value{GDBN}'s overlay support.
7999
8000However, the @value{GDBN} source distribution does contain an overlaid
8001program, with linker scripts for a few systems, as part of its test
8002suite. The program consists of the following files from
8003@file{gdb/testsuite/gdb.base}:
8004
8005@table @file
8006@item overlays.c
8007The main program file.
8008@item ovlymgr.c
8009A simple overlay manager, used by @file{overlays.c}.
8010@item foo.c
8011@itemx bar.c
8012@itemx baz.c
8013@itemx grbx.c
8014Overlay modules, loaded and used by @file{overlays.c}.
8015@item d10v.ld
8016@itemx m32r.ld
8017Linker scripts for linking the test program on the @code{d10v-elf}
8018and @code{m32r-elf} targets.
8019@end table
8020
8021You can build the test program using the @code{d10v-elf} GCC
8022cross-compiler like this:
8023
474c8240 8024@smallexample
df0cd8c5
JB
8025$ d10v-elf-gcc -g -c overlays.c
8026$ d10v-elf-gcc -g -c ovlymgr.c
8027$ d10v-elf-gcc -g -c foo.c
8028$ d10v-elf-gcc -g -c bar.c
8029$ d10v-elf-gcc -g -c baz.c
8030$ d10v-elf-gcc -g -c grbx.c
8031$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8032 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8033@end smallexample
df0cd8c5
JB
8034
8035The build process is identical for any other architecture, except that
8036you must substitute the appropriate compiler and linker script for the
8037target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8038
8039
6d2ebf8b 8040@node Languages
c906108c
SS
8041@chapter Using @value{GDBN} with Different Languages
8042@cindex languages
8043
c906108c
SS
8044Although programming languages generally have common aspects, they are
8045rarely expressed in the same manner. For instance, in ANSI C,
8046dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8047Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8048represented (and displayed) differently. Hex numbers in C appear as
c906108c 8049@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8050
8051@cindex working language
8052Language-specific information is built into @value{GDBN} for some languages,
8053allowing you to express operations like the above in your program's
8054native language, and allowing @value{GDBN} to output values in a manner
8055consistent with the syntax of your program's native language. The
8056language you use to build expressions is called the @dfn{working
8057language}.
8058
8059@menu
8060* Setting:: Switching between source languages
8061* Show:: Displaying the language
c906108c 8062* Checks:: Type and range checks
9c16f35a 8063* Supported languages:: Supported languages
4e562065 8064* Unsupported languages:: Unsupported languages
c906108c
SS
8065@end menu
8066
6d2ebf8b 8067@node Setting
c906108c
SS
8068@section Switching between source languages
8069
8070There are two ways to control the working language---either have @value{GDBN}
8071set it automatically, or select it manually yourself. You can use the
8072@code{set language} command for either purpose. On startup, @value{GDBN}
8073defaults to setting the language automatically. The working language is
8074used to determine how expressions you type are interpreted, how values
8075are printed, etc.
8076
8077In addition to the working language, every source file that
8078@value{GDBN} knows about has its own working language. For some object
8079file formats, the compiler might indicate which language a particular
8080source file is in. However, most of the time @value{GDBN} infers the
8081language from the name of the file. The language of a source file
b37052ae 8082controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8083show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8084set the language of a source file from within @value{GDBN}, but you can
8085set the language associated with a filename extension. @xref{Show, ,
8086Displaying the language}.
c906108c
SS
8087
8088This is most commonly a problem when you use a program, such
5d161b24 8089as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8090another language. In that case, make the
8091program use @code{#line} directives in its C output; that way
8092@value{GDBN} will know the correct language of the source code of the original
8093program, and will display that source code, not the generated C code.
8094
8095@menu
8096* Filenames:: Filename extensions and languages.
8097* Manually:: Setting the working language manually
8098* Automatically:: Having @value{GDBN} infer the source language
8099@end menu
8100
6d2ebf8b 8101@node Filenames
c906108c
SS
8102@subsection List of filename extensions and languages
8103
8104If a source file name ends in one of the following extensions, then
8105@value{GDBN} infers that its language is the one indicated.
8106
8107@table @file
e07c999f
PH
8108@item .ada
8109@itemx .ads
8110@itemx .adb
8111@itemx .a
8112Ada source file.
c906108c
SS
8113
8114@item .c
8115C source file
8116
8117@item .C
8118@itemx .cc
8119@itemx .cp
8120@itemx .cpp
8121@itemx .cxx
8122@itemx .c++
b37052ae 8123C@t{++} source file
c906108c 8124
b37303ee
AF
8125@item .m
8126Objective-C source file
8127
c906108c
SS
8128@item .f
8129@itemx .F
8130Fortran source file
8131
c906108c
SS
8132@item .mod
8133Modula-2 source file
c906108c
SS
8134
8135@item .s
8136@itemx .S
8137Assembler source file. This actually behaves almost like C, but
8138@value{GDBN} does not skip over function prologues when stepping.
8139@end table
8140
8141In addition, you may set the language associated with a filename
8142extension. @xref{Show, , Displaying the language}.
8143
6d2ebf8b 8144@node Manually
c906108c
SS
8145@subsection Setting the working language
8146
8147If you allow @value{GDBN} to set the language automatically,
8148expressions are interpreted the same way in your debugging session and
8149your program.
8150
8151@kindex set language
8152If you wish, you may set the language manually. To do this, issue the
8153command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8154a language, such as
c906108c 8155@code{c} or @code{modula-2}.
c906108c
SS
8156For a list of the supported languages, type @samp{set language}.
8157
c906108c
SS
8158Setting the language manually prevents @value{GDBN} from updating the working
8159language automatically. This can lead to confusion if you try
8160to debug a program when the working language is not the same as the
8161source language, when an expression is acceptable to both
8162languages---but means different things. For instance, if the current
8163source file were written in C, and @value{GDBN} was parsing Modula-2, a
8164command such as:
8165
474c8240 8166@smallexample
c906108c 8167print a = b + c
474c8240 8168@end smallexample
c906108c
SS
8169
8170@noindent
8171might not have the effect you intended. In C, this means to add
8172@code{b} and @code{c} and place the result in @code{a}. The result
8173printed would be the value of @code{a}. In Modula-2, this means to compare
8174@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8175
6d2ebf8b 8176@node Automatically
c906108c
SS
8177@subsection Having @value{GDBN} infer the source language
8178
8179To have @value{GDBN} set the working language automatically, use
8180@samp{set language local} or @samp{set language auto}. @value{GDBN}
8181then infers the working language. That is, when your program stops in a
8182frame (usually by encountering a breakpoint), @value{GDBN} sets the
8183working language to the language recorded for the function in that
8184frame. If the language for a frame is unknown (that is, if the function
8185or block corresponding to the frame was defined in a source file that
8186does not have a recognized extension), the current working language is
8187not changed, and @value{GDBN} issues a warning.
8188
8189This may not seem necessary for most programs, which are written
8190entirely in one source language. However, program modules and libraries
8191written in one source language can be used by a main program written in
8192a different source language. Using @samp{set language auto} in this
8193case frees you from having to set the working language manually.
8194
6d2ebf8b 8195@node Show
c906108c 8196@section Displaying the language
c906108c
SS
8197
8198The following commands help you find out which language is the
8199working language, and also what language source files were written in.
8200
c906108c
SS
8201@table @code
8202@item show language
9c16f35a 8203@kindex show language
c906108c
SS
8204Display the current working language. This is the
8205language you can use with commands such as @code{print} to
8206build and compute expressions that may involve variables in your program.
8207
8208@item info frame
4644b6e3 8209@kindex info frame@r{, show the source language}
5d161b24 8210Display the source language for this frame. This language becomes the
c906108c 8211working language if you use an identifier from this frame.
5d161b24 8212@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8213information listed here.
8214
8215@item info source
4644b6e3 8216@kindex info source@r{, show the source language}
c906108c 8217Display the source language of this source file.
5d161b24 8218@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8219information listed here.
8220@end table
8221
8222In unusual circumstances, you may have source files with extensions
8223not in the standard list. You can then set the extension associated
8224with a language explicitly:
8225
c906108c 8226@table @code
09d4efe1 8227@item set extension-language @var{ext} @var{language}
9c16f35a 8228@kindex set extension-language
09d4efe1
EZ
8229Tell @value{GDBN} that source files with extension @var{ext} are to be
8230assumed as written in the source language @var{language}.
c906108c
SS
8231
8232@item info extensions
9c16f35a 8233@kindex info extensions
c906108c
SS
8234List all the filename extensions and the associated languages.
8235@end table
8236
6d2ebf8b 8237@node Checks
c906108c
SS
8238@section Type and range checking
8239
8240@quotation
8241@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8242checking are included, but they do not yet have any effect. This
8243section documents the intended facilities.
8244@end quotation
8245@c FIXME remove warning when type/range code added
8246
8247Some languages are designed to guard you against making seemingly common
8248errors through a series of compile- and run-time checks. These include
8249checking the type of arguments to functions and operators, and making
8250sure mathematical overflows are caught at run time. Checks such as
8251these help to ensure a program's correctness once it has been compiled
8252by eliminating type mismatches, and providing active checks for range
8253errors when your program is running.
8254
8255@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8256Although @value{GDBN} does not check the statements in your program,
8257it can check expressions entered directly into @value{GDBN} for
8258evaluation via the @code{print} command, for example. As with the
8259working language, @value{GDBN} can also decide whether or not to check
8260automatically based on your program's source language.
8261@xref{Supported languages, ,Supported languages}, for the default
8262settings of supported languages.
c906108c
SS
8263
8264@menu
8265* Type Checking:: An overview of type checking
8266* Range Checking:: An overview of range checking
8267@end menu
8268
8269@cindex type checking
8270@cindex checks, type
6d2ebf8b 8271@node Type Checking
c906108c
SS
8272@subsection An overview of type checking
8273
8274Some languages, such as Modula-2, are strongly typed, meaning that the
8275arguments to operators and functions have to be of the correct type,
8276otherwise an error occurs. These checks prevent type mismatch
8277errors from ever causing any run-time problems. For example,
8278
8279@smallexample
82801 + 2 @result{} 3
8281@exdent but
8282@error{} 1 + 2.3
8283@end smallexample
8284
8285The second example fails because the @code{CARDINAL} 1 is not
8286type-compatible with the @code{REAL} 2.3.
8287
5d161b24
DB
8288For the expressions you use in @value{GDBN} commands, you can tell the
8289@value{GDBN} type checker to skip checking;
8290to treat any mismatches as errors and abandon the expression;
8291or to only issue warnings when type mismatches occur,
c906108c
SS
8292but evaluate the expression anyway. When you choose the last of
8293these, @value{GDBN} evaluates expressions like the second example above, but
8294also issues a warning.
8295
5d161b24
DB
8296Even if you turn type checking off, there may be other reasons
8297related to type that prevent @value{GDBN} from evaluating an expression.
8298For instance, @value{GDBN} does not know how to add an @code{int} and
8299a @code{struct foo}. These particular type errors have nothing to do
8300with the language in use, and usually arise from expressions, such as
c906108c
SS
8301the one described above, which make little sense to evaluate anyway.
8302
8303Each language defines to what degree it is strict about type. For
8304instance, both Modula-2 and C require the arguments to arithmetical
8305operators to be numbers. In C, enumerated types and pointers can be
8306represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8307operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8308details on specific languages.
8309
8310@value{GDBN} provides some additional commands for controlling the type checker:
8311
c906108c
SS
8312@kindex set check type
8313@kindex show check type
8314@table @code
8315@item set check type auto
8316Set type checking on or off based on the current working language.
9c16f35a 8317@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8318each language.
8319
8320@item set check type on
8321@itemx set check type off
8322Set type checking on or off, overriding the default setting for the
8323current working language. Issue a warning if the setting does not
8324match the language default. If any type mismatches occur in
d4f3574e 8325evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8326message and aborts evaluation of the expression.
8327
8328@item set check type warn
8329Cause the type checker to issue warnings, but to always attempt to
8330evaluate the expression. Evaluating the expression may still
8331be impossible for other reasons. For example, @value{GDBN} cannot add
8332numbers and structures.
8333
8334@item show type
5d161b24 8335Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8336is setting it automatically.
8337@end table
8338
8339@cindex range checking
8340@cindex checks, range
6d2ebf8b 8341@node Range Checking
c906108c
SS
8342@subsection An overview of range checking
8343
8344In some languages (such as Modula-2), it is an error to exceed the
8345bounds of a type; this is enforced with run-time checks. Such range
8346checking is meant to ensure program correctness by making sure
8347computations do not overflow, or indices on an array element access do
8348not exceed the bounds of the array.
8349
8350For expressions you use in @value{GDBN} commands, you can tell
8351@value{GDBN} to treat range errors in one of three ways: ignore them,
8352always treat them as errors and abandon the expression, or issue
8353warnings but evaluate the expression anyway.
8354
8355A range error can result from numerical overflow, from exceeding an
8356array index bound, or when you type a constant that is not a member
8357of any type. Some languages, however, do not treat overflows as an
8358error. In many implementations of C, mathematical overflow causes the
8359result to ``wrap around'' to lower values---for example, if @var{m} is
8360the largest integer value, and @var{s} is the smallest, then
8361
474c8240 8362@smallexample
c906108c 8363@var{m} + 1 @result{} @var{s}
474c8240 8364@end smallexample
c906108c
SS
8365
8366This, too, is specific to individual languages, and in some cases
9c16f35a 8367specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8368Supported languages}, for further details on specific languages.
8369
8370@value{GDBN} provides some additional commands for controlling the range checker:
8371
c906108c
SS
8372@kindex set check range
8373@kindex show check range
8374@table @code
8375@item set check range auto
8376Set range checking on or off based on the current working language.
9c16f35a 8377@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8378each language.
8379
8380@item set check range on
8381@itemx set check range off
8382Set range checking on or off, overriding the default setting for the
8383current working language. A warning is issued if the setting does not
c3f6f71d
JM
8384match the language default. If a range error occurs and range checking is on,
8385then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8386
8387@item set check range warn
8388Output messages when the @value{GDBN} range checker detects a range error,
8389but attempt to evaluate the expression anyway. Evaluating the
8390expression may still be impossible for other reasons, such as accessing
8391memory that the process does not own (a typical example from many Unix
8392systems).
8393
8394@item show range
8395Show the current setting of the range checker, and whether or not it is
8396being set automatically by @value{GDBN}.
8397@end table
c906108c 8398
9c16f35a 8399@node Supported languages
c906108c 8400@section Supported languages
c906108c 8401
9c16f35a
EZ
8402@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8403assembly, Modula-2, and Ada.
cce74817 8404@c This is false ...
c906108c
SS
8405Some @value{GDBN} features may be used in expressions regardless of the
8406language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8407and the @samp{@{type@}addr} construct (@pxref{Expressions,
8408,Expressions}) can be used with the constructs of any supported
8409language.
8410
8411The following sections detail to what degree each source language is
8412supported by @value{GDBN}. These sections are not meant to be language
8413tutorials or references, but serve only as a reference guide to what the
8414@value{GDBN} expression parser accepts, and what input and output
8415formats should look like for different languages. There are many good
8416books written on each of these languages; please look to these for a
8417language reference or tutorial.
8418
c906108c 8419@menu
b37303ee 8420* C:: C and C@t{++}
b383017d 8421* Objective-C:: Objective-C
09d4efe1 8422* Fortran:: Fortran
9c16f35a 8423* Pascal:: Pascal
b37303ee 8424* Modula-2:: Modula-2
e07c999f 8425* Ada:: Ada
c906108c
SS
8426@end menu
8427
6d2ebf8b 8428@node C
b37052ae 8429@subsection C and C@t{++}
7a292a7a 8430
b37052ae
EZ
8431@cindex C and C@t{++}
8432@cindex expressions in C or C@t{++}
c906108c 8433
b37052ae 8434Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8435to both languages. Whenever this is the case, we discuss those languages
8436together.
8437
41afff9a
EZ
8438@cindex C@t{++}
8439@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8440@cindex @sc{gnu} C@t{++}
8441The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8442compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8443effectively, you must compile your C@t{++} programs with a supported
8444C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8445compiler (@code{aCC}).
8446
0179ffac
DC
8447For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8448format; if it doesn't work on your system, try the stabs+ debugging
8449format. You can select those formats explicitly with the @code{g++}
8450command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8451@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8452CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8453
c906108c 8454@menu
b37052ae
EZ
8455* C Operators:: C and C@t{++} operators
8456* C Constants:: C and C@t{++} constants
8457* C plus plus expressions:: C@t{++} expressions
8458* C Defaults:: Default settings for C and C@t{++}
8459* C Checks:: C and C@t{++} type and range checks
c906108c 8460* Debugging C:: @value{GDBN} and C
b37052ae 8461* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8462@end menu
c906108c 8463
6d2ebf8b 8464@node C Operators
b37052ae 8465@subsubsection C and C@t{++} operators
7a292a7a 8466
b37052ae 8467@cindex C and C@t{++} operators
c906108c
SS
8468
8469Operators must be defined on values of specific types. For instance,
8470@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8471often defined on groups of types.
c906108c 8472
b37052ae 8473For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8474
8475@itemize @bullet
53a5351d 8476
c906108c 8477@item
c906108c 8478@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8479specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8480
8481@item
d4f3574e
SS
8482@emph{Floating-point types} include @code{float}, @code{double}, and
8483@code{long double} (if supported by the target platform).
c906108c
SS
8484
8485@item
53a5351d 8486@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8487
8488@item
8489@emph{Scalar types} include all of the above.
53a5351d 8490
c906108c
SS
8491@end itemize
8492
8493@noindent
8494The following operators are supported. They are listed here
8495in order of increasing precedence:
8496
8497@table @code
8498@item ,
8499The comma or sequencing operator. Expressions in a comma-separated list
8500are evaluated from left to right, with the result of the entire
8501expression being the last expression evaluated.
8502
8503@item =
8504Assignment. The value of an assignment expression is the value
8505assigned. Defined on scalar types.
8506
8507@item @var{op}=
8508Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8509and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8510@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8511@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8512@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8513
8514@item ?:
8515The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8516of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8517integral type.
8518
8519@item ||
8520Logical @sc{or}. Defined on integral types.
8521
8522@item &&
8523Logical @sc{and}. Defined on integral types.
8524
8525@item |
8526Bitwise @sc{or}. Defined on integral types.
8527
8528@item ^
8529Bitwise exclusive-@sc{or}. Defined on integral types.
8530
8531@item &
8532Bitwise @sc{and}. Defined on integral types.
8533
8534@item ==@r{, }!=
8535Equality and inequality. Defined on scalar types. The value of these
8536expressions is 0 for false and non-zero for true.
8537
8538@item <@r{, }>@r{, }<=@r{, }>=
8539Less than, greater than, less than or equal, greater than or equal.
8540Defined on scalar types. The value of these expressions is 0 for false
8541and non-zero for true.
8542
8543@item <<@r{, }>>
8544left shift, and right shift. Defined on integral types.
8545
8546@item @@
8547The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8548
8549@item +@r{, }-
8550Addition and subtraction. Defined on integral types, floating-point types and
8551pointer types.
8552
8553@item *@r{, }/@r{, }%
8554Multiplication, division, and modulus. Multiplication and division are
8555defined on integral and floating-point types. Modulus is defined on
8556integral types.
8557
8558@item ++@r{, }--
8559Increment and decrement. When appearing before a variable, the
8560operation is performed before the variable is used in an expression;
8561when appearing after it, the variable's value is used before the
8562operation takes place.
8563
8564@item *
8565Pointer dereferencing. Defined on pointer types. Same precedence as
8566@code{++}.
8567
8568@item &
8569Address operator. Defined on variables. Same precedence as @code{++}.
8570
b37052ae
EZ
8571For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8572allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8573(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8574where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8575stored.
c906108c
SS
8576
8577@item -
8578Negative. Defined on integral and floating-point types. Same
8579precedence as @code{++}.
8580
8581@item !
8582Logical negation. Defined on integral types. Same precedence as
8583@code{++}.
8584
8585@item ~
8586Bitwise complement operator. Defined on integral types. Same precedence as
8587@code{++}.
8588
8589
8590@item .@r{, }->
8591Structure member, and pointer-to-structure member. For convenience,
8592@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8593pointer based on the stored type information.
8594Defined on @code{struct} and @code{union} data.
8595
c906108c
SS
8596@item .*@r{, }->*
8597Dereferences of pointers to members.
c906108c
SS
8598
8599@item []
8600Array indexing. @code{@var{a}[@var{i}]} is defined as
8601@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8602
8603@item ()
8604Function parameter list. Same precedence as @code{->}.
8605
c906108c 8606@item ::
b37052ae 8607C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8608and @code{class} types.
c906108c
SS
8609
8610@item ::
7a292a7a
SS
8611Doubled colons also represent the @value{GDBN} scope operator
8612(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8613above.
c906108c
SS
8614@end table
8615
c906108c
SS
8616If an operator is redefined in the user code, @value{GDBN} usually
8617attempts to invoke the redefined version instead of using the operator's
8618predefined meaning.
c906108c 8619
c906108c 8620@menu
5d161b24 8621* C Constants::
c906108c
SS
8622@end menu
8623
6d2ebf8b 8624@node C Constants
b37052ae 8625@subsubsection C and C@t{++} constants
c906108c 8626
b37052ae 8627@cindex C and C@t{++} constants
c906108c 8628
b37052ae 8629@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8630following ways:
c906108c
SS
8631
8632@itemize @bullet
8633@item
8634Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8635specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8636by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8637@samp{l}, specifying that the constant should be treated as a
8638@code{long} value.
8639
8640@item
8641Floating point constants are a sequence of digits, followed by a decimal
8642point, followed by a sequence of digits, and optionally followed by an
8643exponent. An exponent is of the form:
8644@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8645sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8646A floating-point constant may also end with a letter @samp{f} or
8647@samp{F}, specifying that the constant should be treated as being of
8648the @code{float} (as opposed to the default @code{double}) type; or with
8649a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8650constant.
c906108c
SS
8651
8652@item
8653Enumerated constants consist of enumerated identifiers, or their
8654integral equivalents.
8655
8656@item
8657Character constants are a single character surrounded by single quotes
8658(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8659(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8660be represented by a letter or by @dfn{escape sequences}, which are of
8661the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8662of the character's ordinal value; or of the form @samp{\@var{x}}, where
8663@samp{@var{x}} is a predefined special character---for example,
8664@samp{\n} for newline.
8665
8666@item
96a2c332
SS
8667String constants are a sequence of character constants surrounded by
8668double quotes (@code{"}). Any valid character constant (as described
8669above) may appear. Double quotes within the string must be preceded by
8670a backslash, so for instance @samp{"a\"b'c"} is a string of five
8671characters.
c906108c
SS
8672
8673@item
8674Pointer constants are an integral value. You can also write pointers
8675to constants using the C operator @samp{&}.
8676
8677@item
8678Array constants are comma-separated lists surrounded by braces @samp{@{}
8679and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8680integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8681and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8682@end itemize
8683
c906108c 8684@menu
5d161b24
DB
8685* C plus plus expressions::
8686* C Defaults::
8687* C Checks::
c906108c 8688
5d161b24 8689* Debugging C::
c906108c
SS
8690@end menu
8691
6d2ebf8b 8692@node C plus plus expressions
b37052ae
EZ
8693@subsubsection C@t{++} expressions
8694
8695@cindex expressions in C@t{++}
8696@value{GDBN} expression handling can interpret most C@t{++} expressions.
8697
0179ffac
DC
8698@cindex debugging C@t{++} programs
8699@cindex C@t{++} compilers
8700@cindex debug formats and C@t{++}
8701@cindex @value{NGCC} and C@t{++}
c906108c 8702@quotation
b37052ae 8703@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8704proper compiler and the proper debug format. Currently, @value{GDBN}
8705works best when debugging C@t{++} code that is compiled with
8706@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8707@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8708stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8709stabs+ as their default debug format, so you usually don't need to
8710specify a debug format explicitly. Other compilers and/or debug formats
8711are likely to work badly or not at all when using @value{GDBN} to debug
8712C@t{++} code.
c906108c 8713@end quotation
c906108c
SS
8714
8715@enumerate
8716
8717@cindex member functions
8718@item
8719Member function calls are allowed; you can use expressions like
8720
474c8240 8721@smallexample
c906108c 8722count = aml->GetOriginal(x, y)
474c8240 8723@end smallexample
c906108c 8724
41afff9a 8725@vindex this@r{, inside C@t{++} member functions}
b37052ae 8726@cindex namespace in C@t{++}
c906108c
SS
8727@item
8728While a member function is active (in the selected stack frame), your
8729expressions have the same namespace available as the member function;
8730that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8731pointer @code{this} following the same rules as C@t{++}.
c906108c 8732
c906108c 8733@cindex call overloaded functions
d4f3574e 8734@cindex overloaded functions, calling
b37052ae 8735@cindex type conversions in C@t{++}
c906108c
SS
8736@item
8737You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8738call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8739perform overload resolution involving user-defined type conversions,
8740calls to constructors, or instantiations of templates that do not exist
8741in the program. It also cannot handle ellipsis argument lists or
8742default arguments.
8743
8744It does perform integral conversions and promotions, floating-point
8745promotions, arithmetic conversions, pointer conversions, conversions of
8746class objects to base classes, and standard conversions such as those of
8747functions or arrays to pointers; it requires an exact match on the
8748number of function arguments.
8749
8750Overload resolution is always performed, unless you have specified
8751@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8752,@value{GDBN} features for C@t{++}}.
c906108c 8753
d4f3574e 8754You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8755explicit function signature to call an overloaded function, as in
8756@smallexample
8757p 'foo(char,int)'('x', 13)
8758@end smallexample
d4f3574e 8759
c906108c 8760The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8761see @ref{Completion, ,Command completion}.
c906108c 8762
c906108c
SS
8763@cindex reference declarations
8764@item
b37052ae
EZ
8765@value{GDBN} understands variables declared as C@t{++} references; you can use
8766them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8767dereferenced.
8768
8769In the parameter list shown when @value{GDBN} displays a frame, the values of
8770reference variables are not displayed (unlike other variables); this
8771avoids clutter, since references are often used for large structures.
8772The @emph{address} of a reference variable is always shown, unless
8773you have specified @samp{set print address off}.
8774
8775@item
b37052ae 8776@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8777expressions can use it just as expressions in your program do. Since
8778one scope may be defined in another, you can use @code{::} repeatedly if
8779necessary, for example in an expression like
8780@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8781resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8782debugging (@pxref{Variables, ,Program variables}).
8783@end enumerate
8784
b37052ae 8785In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8786calling virtual functions correctly, printing out virtual bases of
8787objects, calling functions in a base subobject, casting objects, and
8788invoking user-defined operators.
c906108c 8789
6d2ebf8b 8790@node C Defaults
b37052ae 8791@subsubsection C and C@t{++} defaults
7a292a7a 8792
b37052ae 8793@cindex C and C@t{++} defaults
c906108c 8794
c906108c
SS
8795If you allow @value{GDBN} to set type and range checking automatically, they
8796both default to @code{off} whenever the working language changes to
b37052ae 8797C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8798selects the working language.
c906108c
SS
8799
8800If you allow @value{GDBN} to set the language automatically, it
8801recognizes source files whose names end with @file{.c}, @file{.C}, or
8802@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8803these files, it sets the working language to C or C@t{++}.
c906108c
SS
8804@xref{Automatically, ,Having @value{GDBN} infer the source language},
8805for further details.
8806
c906108c
SS
8807@c Type checking is (a) primarily motivated by Modula-2, and (b)
8808@c unimplemented. If (b) changes, it might make sense to let this node
8809@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8810
6d2ebf8b 8811@node C Checks
b37052ae 8812@subsubsection C and C@t{++} type and range checks
7a292a7a 8813
b37052ae 8814@cindex C and C@t{++} checks
c906108c 8815
b37052ae 8816By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8817is not used. However, if you turn type checking on, @value{GDBN}
8818considers two variables type equivalent if:
8819
8820@itemize @bullet
8821@item
8822The two variables are structured and have the same structure, union, or
8823enumerated tag.
8824
8825@item
8826The two variables have the same type name, or types that have been
8827declared equivalent through @code{typedef}.
8828
8829@ignore
8830@c leaving this out because neither J Gilmore nor R Pesch understand it.
8831@c FIXME--beers?
8832@item
8833The two @code{struct}, @code{union}, or @code{enum} variables are
8834declared in the same declaration. (Note: this may not be true for all C
8835compilers.)
8836@end ignore
8837@end itemize
8838
8839Range checking, if turned on, is done on mathematical operations. Array
8840indices are not checked, since they are often used to index a pointer
8841that is not itself an array.
c906108c 8842
6d2ebf8b 8843@node Debugging C
c906108c 8844@subsubsection @value{GDBN} and C
c906108c
SS
8845
8846The @code{set print union} and @code{show print union} commands apply to
8847the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8848inside a @code{struct} or @code{class} is also printed. Otherwise, it
8849appears as @samp{@{...@}}.
c906108c
SS
8850
8851The @code{@@} operator aids in the debugging of dynamic arrays, formed
8852with pointers and a memory allocation function. @xref{Expressions,
8853,Expressions}.
8854
c906108c 8855@menu
5d161b24 8856* Debugging C plus plus::
c906108c
SS
8857@end menu
8858
6d2ebf8b 8859@node Debugging C plus plus
b37052ae 8860@subsubsection @value{GDBN} features for C@t{++}
c906108c 8861
b37052ae 8862@cindex commands for C@t{++}
7a292a7a 8863
b37052ae
EZ
8864Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8865designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8866
8867@table @code
8868@cindex break in overloaded functions
8869@item @r{breakpoint menus}
8870When you want a breakpoint in a function whose name is overloaded,
8871@value{GDBN} breakpoint menus help you specify which function definition
8872you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8873
b37052ae 8874@cindex overloading in C@t{++}
c906108c
SS
8875@item rbreak @var{regex}
8876Setting breakpoints using regular expressions is helpful for setting
8877breakpoints on overloaded functions that are not members of any special
8878classes.
8879@xref{Set Breaks, ,Setting breakpoints}.
8880
b37052ae 8881@cindex C@t{++} exception handling
c906108c
SS
8882@item catch throw
8883@itemx catch catch
b37052ae 8884Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8885Catchpoints, , Setting catchpoints}.
8886
8887@cindex inheritance
8888@item ptype @var{typename}
8889Print inheritance relationships as well as other information for type
8890@var{typename}.
8891@xref{Symbols, ,Examining the Symbol Table}.
8892
b37052ae 8893@cindex C@t{++} symbol display
c906108c
SS
8894@item set print demangle
8895@itemx show print demangle
8896@itemx set print asm-demangle
8897@itemx show print asm-demangle
b37052ae
EZ
8898Control whether C@t{++} symbols display in their source form, both when
8899displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8900@xref{Print Settings, ,Print settings}.
8901
8902@item set print object
8903@itemx show print object
8904Choose whether to print derived (actual) or declared types of objects.
8905@xref{Print Settings, ,Print settings}.
8906
8907@item set print vtbl
8908@itemx show print vtbl
8909Control the format for printing virtual function tables.
8910@xref{Print Settings, ,Print settings}.
c906108c 8911(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8912ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8913
8914@kindex set overload-resolution
d4f3574e 8915@cindex overloaded functions, overload resolution
c906108c 8916@item set overload-resolution on
b37052ae 8917Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8918is on. For overloaded functions, @value{GDBN} evaluates the arguments
8919and searches for a function whose signature matches the argument types,
b37052ae 8920using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8921expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8922message.
8923
8924@item set overload-resolution off
b37052ae 8925Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8926overloaded functions that are not class member functions, @value{GDBN}
8927chooses the first function of the specified name that it finds in the
8928symbol table, whether or not its arguments are of the correct type. For
8929overloaded functions that are class member functions, @value{GDBN}
8930searches for a function whose signature @emph{exactly} matches the
8931argument types.
c906108c 8932
9c16f35a
EZ
8933@kindex show overload-resolution
8934@item show overload-resolution
8935Show the current setting of overload resolution.
8936
c906108c
SS
8937@item @r{Overloaded symbol names}
8938You can specify a particular definition of an overloaded symbol, using
b37052ae 8939the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8940@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8941also use the @value{GDBN} command-line word completion facilities to list the
8942available choices, or to finish the type list for you.
8943@xref{Completion,, Command completion}, for details on how to do this.
8944@end table
c906108c 8945
b37303ee
AF
8946@node Objective-C
8947@subsection Objective-C
8948
8949@cindex Objective-C
8950This section provides information about some commands and command
721c2651
EZ
8951options that are useful for debugging Objective-C code. See also
8952@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8953few more commands specific to Objective-C support.
b37303ee
AF
8954
8955@menu
b383017d
RM
8956* Method Names in Commands::
8957* The Print Command with Objective-C::
b37303ee
AF
8958@end menu
8959
8960@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8961@subsubsection Method Names in Commands
8962
8963The following commands have been extended to accept Objective-C method
8964names as line specifications:
8965
8966@kindex clear@r{, and Objective-C}
8967@kindex break@r{, and Objective-C}
8968@kindex info line@r{, and Objective-C}
8969@kindex jump@r{, and Objective-C}
8970@kindex list@r{, and Objective-C}
8971@itemize
8972@item @code{clear}
8973@item @code{break}
8974@item @code{info line}
8975@item @code{jump}
8976@item @code{list}
8977@end itemize
8978
8979A fully qualified Objective-C method name is specified as
8980
8981@smallexample
8982-[@var{Class} @var{methodName}]
8983@end smallexample
8984
c552b3bb
JM
8985where the minus sign is used to indicate an instance method and a
8986plus sign (not shown) is used to indicate a class method. The class
8987name @var{Class} and method name @var{methodName} are enclosed in
8988brackets, similar to the way messages are specified in Objective-C
8989source code. For example, to set a breakpoint at the @code{create}
8990instance method of class @code{Fruit} in the program currently being
8991debugged, enter:
b37303ee
AF
8992
8993@smallexample
8994break -[Fruit create]
8995@end smallexample
8996
8997To list ten program lines around the @code{initialize} class method,
8998enter:
8999
9000@smallexample
9001list +[NSText initialize]
9002@end smallexample
9003
c552b3bb
JM
9004In the current version of @value{GDBN}, the plus or minus sign is
9005required. In future versions of @value{GDBN}, the plus or minus
9006sign will be optional, but you can use it to narrow the search. It
9007is also possible to specify just a method name:
b37303ee
AF
9008
9009@smallexample
9010break create
9011@end smallexample
9012
9013You must specify the complete method name, including any colons. If
9014your program's source files contain more than one @code{create} method,
9015you'll be presented with a numbered list of classes that implement that
9016method. Indicate your choice by number, or type @samp{0} to exit if
9017none apply.
9018
9019As another example, to clear a breakpoint established at the
9020@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9021
9022@smallexample
9023clear -[NSWindow makeKeyAndOrderFront:]
9024@end smallexample
9025
9026@node The Print Command with Objective-C
9027@subsubsection The Print Command With Objective-C
721c2651 9028@cindex Objective-C, print objects
c552b3bb
JM
9029@kindex print-object
9030@kindex po @r{(@code{print-object})}
b37303ee 9031
c552b3bb 9032The print command has also been extended to accept methods. For example:
b37303ee
AF
9033
9034@smallexample
c552b3bb 9035print -[@var{object} hash]
b37303ee
AF
9036@end smallexample
9037
9038@cindex print an Objective-C object description
c552b3bb
JM
9039@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9040@noindent
9041will tell @value{GDBN} to send the @code{hash} message to @var{object}
9042and print the result. Also, an additional command has been added,
9043@code{print-object} or @code{po} for short, which is meant to print
9044the description of an object. However, this command may only work
9045with certain Objective-C libraries that have a particular hook
9046function, @code{_NSPrintForDebugger}, defined.
b37303ee 9047
09d4efe1
EZ
9048@node Fortran
9049@subsection Fortran
9050@cindex Fortran-specific support in @value{GDBN}
9051
9052@table @code
9053@cindex @code{COMMON} blocks, Fortran
9054@kindex info common
9055@item info common @r{[}@var{common-name}@r{]}
9056This command prints the values contained in the Fortran @code{COMMON}
9057block whose name is @var{common-name}. With no argument, the names of
9058all @code{COMMON} blocks visible at current program location are
9059printed.
9060@end table
9061
a8f24a35
EZ
9062Fortran symbols are usually case-insensitive, so @value{GDBN} by
9063default uses case-insensitive matches for Fortran symbols. You can
9064change that with the @samp{set case-insensitive} command, see
9065@ref{Symbols}, for the details.
9066
9c16f35a
EZ
9067@node Pascal
9068@subsection Pascal
9069
9070@cindex Pascal support in @value{GDBN}, limitations
9071Debugging Pascal programs which use sets, subranges, file variables, or
9072nested functions does not currently work. @value{GDBN} does not support
9073entering expressions, printing values, or similar features using Pascal
9074syntax.
9075
9076The Pascal-specific command @code{set print pascal_static-members}
9077controls whether static members of Pascal objects are displayed.
9078@xref{Print Settings, pascal_static-members}.
9079
09d4efe1 9080@node Modula-2
c906108c 9081@subsection Modula-2
7a292a7a 9082
d4f3574e 9083@cindex Modula-2, @value{GDBN} support
c906108c
SS
9084
9085The extensions made to @value{GDBN} to support Modula-2 only support
9086output from the @sc{gnu} Modula-2 compiler (which is currently being
9087developed). Other Modula-2 compilers are not currently supported, and
9088attempting to debug executables produced by them is most likely
9089to give an error as @value{GDBN} reads in the executable's symbol
9090table.
9091
9092@cindex expressions in Modula-2
9093@menu
9094* M2 Operators:: Built-in operators
9095* Built-In Func/Proc:: Built-in functions and procedures
9096* M2 Constants:: Modula-2 constants
9097* M2 Defaults:: Default settings for Modula-2
9098* Deviations:: Deviations from standard Modula-2
9099* M2 Checks:: Modula-2 type and range checks
9100* M2 Scope:: The scope operators @code{::} and @code{.}
9101* GDB/M2:: @value{GDBN} and Modula-2
9102@end menu
9103
6d2ebf8b 9104@node M2 Operators
c906108c
SS
9105@subsubsection Operators
9106@cindex Modula-2 operators
9107
9108Operators must be defined on values of specific types. For instance,
9109@code{+} is defined on numbers, but not on structures. Operators are
9110often defined on groups of types. For the purposes of Modula-2, the
9111following definitions hold:
9112
9113@itemize @bullet
9114
9115@item
9116@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9117their subranges.
9118
9119@item
9120@emph{Character types} consist of @code{CHAR} and its subranges.
9121
9122@item
9123@emph{Floating-point types} consist of @code{REAL}.
9124
9125@item
9126@emph{Pointer types} consist of anything declared as @code{POINTER TO
9127@var{type}}.
9128
9129@item
9130@emph{Scalar types} consist of all of the above.
9131
9132@item
9133@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9134
9135@item
9136@emph{Boolean types} consist of @code{BOOLEAN}.
9137@end itemize
9138
9139@noindent
9140The following operators are supported, and appear in order of
9141increasing precedence:
9142
9143@table @code
9144@item ,
9145Function argument or array index separator.
9146
9147@item :=
9148Assignment. The value of @var{var} @code{:=} @var{value} is
9149@var{value}.
9150
9151@item <@r{, }>
9152Less than, greater than on integral, floating-point, or enumerated
9153types.
9154
9155@item <=@r{, }>=
96a2c332 9156Less than or equal to, greater than or equal to
c906108c
SS
9157on integral, floating-point and enumerated types, or set inclusion on
9158set types. Same precedence as @code{<}.
9159
9160@item =@r{, }<>@r{, }#
9161Equality and two ways of expressing inequality, valid on scalar types.
9162Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9163available for inequality, since @code{#} conflicts with the script
9164comment character.
9165
9166@item IN
9167Set membership. Defined on set types and the types of their members.
9168Same precedence as @code{<}.
9169
9170@item OR
9171Boolean disjunction. Defined on boolean types.
9172
9173@item AND@r{, }&
d4f3574e 9174Boolean conjunction. Defined on boolean types.
c906108c
SS
9175
9176@item @@
9177The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9178
9179@item +@r{, }-
9180Addition and subtraction on integral and floating-point types, or union
9181and difference on set types.
9182
9183@item *
9184Multiplication on integral and floating-point types, or set intersection
9185on set types.
9186
9187@item /
9188Division on floating-point types, or symmetric set difference on set
9189types. Same precedence as @code{*}.
9190
9191@item DIV@r{, }MOD
9192Integer division and remainder. Defined on integral types. Same
9193precedence as @code{*}.
9194
9195@item -
9196Negative. Defined on @code{INTEGER} and @code{REAL} data.
9197
9198@item ^
9199Pointer dereferencing. Defined on pointer types.
9200
9201@item NOT
9202Boolean negation. Defined on boolean types. Same precedence as
9203@code{^}.
9204
9205@item .
9206@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9207precedence as @code{^}.
9208
9209@item []
9210Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9211
9212@item ()
9213Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9214as @code{^}.
9215
9216@item ::@r{, }.
9217@value{GDBN} and Modula-2 scope operators.
9218@end table
9219
9220@quotation
9221@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9222treats the use of the operator @code{IN}, or the use of operators
9223@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9224@code{<=}, and @code{>=} on sets as an error.
9225@end quotation
9226
cb51c4e0 9227
6d2ebf8b 9228@node Built-In Func/Proc
c906108c 9229@subsubsection Built-in functions and procedures
cb51c4e0 9230@cindex Modula-2 built-ins
c906108c
SS
9231
9232Modula-2 also makes available several built-in procedures and functions.
9233In describing these, the following metavariables are used:
9234
9235@table @var
9236
9237@item a
9238represents an @code{ARRAY} variable.
9239
9240@item c
9241represents a @code{CHAR} constant or variable.
9242
9243@item i
9244represents a variable or constant of integral type.
9245
9246@item m
9247represents an identifier that belongs to a set. Generally used in the
9248same function with the metavariable @var{s}. The type of @var{s} should
9249be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9250
9251@item n
9252represents a variable or constant of integral or floating-point type.
9253
9254@item r
9255represents a variable or constant of floating-point type.
9256
9257@item t
9258represents a type.
9259
9260@item v
9261represents a variable.
9262
9263@item x
9264represents a variable or constant of one of many types. See the
9265explanation of the function for details.
9266@end table
9267
9268All Modula-2 built-in procedures also return a result, described below.
9269
9270@table @code
9271@item ABS(@var{n})
9272Returns the absolute value of @var{n}.
9273
9274@item CAP(@var{c})
9275If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9276equivalent, otherwise it returns its argument.
c906108c
SS
9277
9278@item CHR(@var{i})
9279Returns the character whose ordinal value is @var{i}.
9280
9281@item DEC(@var{v})
c3f6f71d 9282Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9283
9284@item DEC(@var{v},@var{i})
9285Decrements the value in the variable @var{v} by @var{i}. Returns the
9286new value.
9287
9288@item EXCL(@var{m},@var{s})
9289Removes the element @var{m} from the set @var{s}. Returns the new
9290set.
9291
9292@item FLOAT(@var{i})
9293Returns the floating point equivalent of the integer @var{i}.
9294
9295@item HIGH(@var{a})
9296Returns the index of the last member of @var{a}.
9297
9298@item INC(@var{v})
c3f6f71d 9299Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9300
9301@item INC(@var{v},@var{i})
9302Increments the value in the variable @var{v} by @var{i}. Returns the
9303new value.
9304
9305@item INCL(@var{m},@var{s})
9306Adds the element @var{m} to the set @var{s} if it is not already
9307there. Returns the new set.
9308
9309@item MAX(@var{t})
9310Returns the maximum value of the type @var{t}.
9311
9312@item MIN(@var{t})
9313Returns the minimum value of the type @var{t}.
9314
9315@item ODD(@var{i})
9316Returns boolean TRUE if @var{i} is an odd number.
9317
9318@item ORD(@var{x})
9319Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9320value of a character is its @sc{ascii} value (on machines supporting the
9321@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9322integral, character and enumerated types.
9323
9324@item SIZE(@var{x})
9325Returns the size of its argument. @var{x} can be a variable or a type.
9326
9327@item TRUNC(@var{r})
9328Returns the integral part of @var{r}.
9329
9330@item VAL(@var{t},@var{i})
9331Returns the member of the type @var{t} whose ordinal value is @var{i}.
9332@end table
9333
9334@quotation
9335@emph{Warning:} Sets and their operations are not yet supported, so
9336@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9337an error.
9338@end quotation
9339
9340@cindex Modula-2 constants
6d2ebf8b 9341@node M2 Constants
c906108c
SS
9342@subsubsection Constants
9343
9344@value{GDBN} allows you to express the constants of Modula-2 in the following
9345ways:
9346
9347@itemize @bullet
9348
9349@item
9350Integer constants are simply a sequence of digits. When used in an
9351expression, a constant is interpreted to be type-compatible with the
9352rest of the expression. Hexadecimal integers are specified by a
9353trailing @samp{H}, and octal integers by a trailing @samp{B}.
9354
9355@item
9356Floating point constants appear as a sequence of digits, followed by a
9357decimal point and another sequence of digits. An optional exponent can
9358then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9359@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9360digits of the floating point constant must be valid decimal (base 10)
9361digits.
9362
9363@item
9364Character constants consist of a single character enclosed by a pair of
9365like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9366also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9367followed by a @samp{C}.
9368
9369@item
9370String constants consist of a sequence of characters enclosed by a
9371pair of like quotes, either single (@code{'}) or double (@code{"}).
9372Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9373Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9374sequences.
9375
9376@item
9377Enumerated constants consist of an enumerated identifier.
9378
9379@item
9380Boolean constants consist of the identifiers @code{TRUE} and
9381@code{FALSE}.
9382
9383@item
9384Pointer constants consist of integral values only.
9385
9386@item
9387Set constants are not yet supported.
9388@end itemize
9389
6d2ebf8b 9390@node M2 Defaults
c906108c
SS
9391@subsubsection Modula-2 defaults
9392@cindex Modula-2 defaults
9393
9394If type and range checking are set automatically by @value{GDBN}, they
9395both default to @code{on} whenever the working language changes to
d4f3574e 9396Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9397selected the working language.
9398
9399If you allow @value{GDBN} to set the language automatically, then entering
9400code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9401working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9402the language automatically}, for further details.
9403
6d2ebf8b 9404@node Deviations
c906108c
SS
9405@subsubsection Deviations from standard Modula-2
9406@cindex Modula-2, deviations from
9407
9408A few changes have been made to make Modula-2 programs easier to debug.
9409This is done primarily via loosening its type strictness:
9410
9411@itemize @bullet
9412@item
9413Unlike in standard Modula-2, pointer constants can be formed by
9414integers. This allows you to modify pointer variables during
9415debugging. (In standard Modula-2, the actual address contained in a
9416pointer variable is hidden from you; it can only be modified
9417through direct assignment to another pointer variable or expression that
9418returned a pointer.)
9419
9420@item
9421C escape sequences can be used in strings and characters to represent
9422non-printable characters. @value{GDBN} prints out strings with these
9423escape sequences embedded. Single non-printable characters are
9424printed using the @samp{CHR(@var{nnn})} format.
9425
9426@item
9427The assignment operator (@code{:=}) returns the value of its right-hand
9428argument.
9429
9430@item
9431All built-in procedures both modify @emph{and} return their argument.
9432@end itemize
9433
6d2ebf8b 9434@node M2 Checks
c906108c
SS
9435@subsubsection Modula-2 type and range checks
9436@cindex Modula-2 checks
9437
9438@quotation
9439@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9440range checking.
9441@end quotation
9442@c FIXME remove warning when type/range checks added
9443
9444@value{GDBN} considers two Modula-2 variables type equivalent if:
9445
9446@itemize @bullet
9447@item
9448They are of types that have been declared equivalent via a @code{TYPE
9449@var{t1} = @var{t2}} statement
9450
9451@item
9452They have been declared on the same line. (Note: This is true of the
9453@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9454@end itemize
9455
9456As long as type checking is enabled, any attempt to combine variables
9457whose types are not equivalent is an error.
9458
9459Range checking is done on all mathematical operations, assignment, array
9460index bounds, and all built-in functions and procedures.
9461
6d2ebf8b 9462@node M2 Scope
c906108c
SS
9463@subsubsection The scope operators @code{::} and @code{.}
9464@cindex scope
41afff9a 9465@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9466@cindex colon, doubled as scope operator
9467@ifinfo
41afff9a 9468@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9469@c Info cannot handle :: but TeX can.
9470@end ifinfo
9471@iftex
41afff9a 9472@vindex ::@r{, in Modula-2}
c906108c
SS
9473@end iftex
9474
9475There are a few subtle differences between the Modula-2 scope operator
9476(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9477similar syntax:
9478
474c8240 9479@smallexample
c906108c
SS
9480
9481@var{module} . @var{id}
9482@var{scope} :: @var{id}
474c8240 9483@end smallexample
c906108c
SS
9484
9485@noindent
9486where @var{scope} is the name of a module or a procedure,
9487@var{module} the name of a module, and @var{id} is any declared
9488identifier within your program, except another module.
9489
9490Using the @code{::} operator makes @value{GDBN} search the scope
9491specified by @var{scope} for the identifier @var{id}. If it is not
9492found in the specified scope, then @value{GDBN} searches all scopes
9493enclosing the one specified by @var{scope}.
9494
9495Using the @code{.} operator makes @value{GDBN} search the current scope for
9496the identifier specified by @var{id} that was imported from the
9497definition module specified by @var{module}. With this operator, it is
9498an error if the identifier @var{id} was not imported from definition
9499module @var{module}, or if @var{id} is not an identifier in
9500@var{module}.
9501
6d2ebf8b 9502@node GDB/M2
c906108c
SS
9503@subsubsection @value{GDBN} and Modula-2
9504
9505Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9506Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9507specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9508@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9509apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9510analogue in Modula-2.
9511
9512The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9513with any language, is not useful with Modula-2. Its
c906108c 9514intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9515created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9516address can be specified by an integral constant, the construct
d4f3574e 9517@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9518
9519@cindex @code{#} in Modula-2
9520In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9521interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9522
e07c999f
PH
9523@node Ada
9524@subsection Ada
9525@cindex Ada
9526
9527The extensions made to @value{GDBN} for Ada only support
9528output from the @sc{gnu} Ada (GNAT) compiler.
9529Other Ada compilers are not currently supported, and
9530attempting to debug executables produced by them is most likely
9531to be difficult.
9532
9533
9534@cindex expressions in Ada
9535@menu
9536* Ada Mode Intro:: General remarks on the Ada syntax
9537 and semantics supported by Ada mode
9538 in @value{GDBN}.
9539* Omissions from Ada:: Restrictions on the Ada expression syntax.
9540* Additions to Ada:: Extensions of the Ada expression syntax.
9541* Stopping Before Main Program:: Debugging the program during elaboration.
9542* Ada Glitches:: Known peculiarities of Ada mode.
9543@end menu
9544
9545@node Ada Mode Intro
9546@subsubsection Introduction
9547@cindex Ada mode, general
9548
9549The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9550syntax, with some extensions.
9551The philosophy behind the design of this subset is
9552
9553@itemize @bullet
9554@item
9555That @value{GDBN} should provide basic literals and access to operations for
9556arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9557leaving more sophisticated computations to subprograms written into the
9558program (which therefore may be called from @value{GDBN}).
9559
9560@item
9561That type safety and strict adherence to Ada language restrictions
9562are not particularly important to the @value{GDBN} user.
9563
9564@item
9565That brevity is important to the @value{GDBN} user.
9566@end itemize
9567
9568Thus, for brevity, the debugger acts as if there were
9569implicit @code{with} and @code{use} clauses in effect for all user-written
9570packages, making it unnecessary to fully qualify most names with
9571their packages, regardless of context. Where this causes ambiguity,
9572@value{GDBN} asks the user's intent.
9573
9574The debugger will start in Ada mode if it detects an Ada main program.
9575As for other languages, it will enter Ada mode when stopped in a program that
9576was translated from an Ada source file.
9577
9578While in Ada mode, you may use `@t{--}' for comments. This is useful
9579mostly for documenting command files. The standard @value{GDBN} comment
9580(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9581middle (to allow based literals).
9582
9583The debugger supports limited overloading. Given a subprogram call in which
9584the function symbol has multiple definitions, it will use the number of
9585actual parameters and some information about their types to attempt to narrow
9586the set of definitions. It also makes very limited use of context, preferring
9587procedures to functions in the context of the @code{call} command, and
9588functions to procedures elsewhere.
9589
9590@node Omissions from Ada
9591@subsubsection Omissions from Ada
9592@cindex Ada, omissions from
9593
9594Here are the notable omissions from the subset:
9595
9596@itemize @bullet
9597@item
9598Only a subset of the attributes are supported:
9599
9600@itemize @minus
9601@item
9602@t{'First}, @t{'Last}, and @t{'Length}
9603 on array objects (not on types and subtypes).
9604
9605@item
9606@t{'Min} and @t{'Max}.
9607
9608@item
9609@t{'Pos} and @t{'Val}.
9610
9611@item
9612@t{'Tag}.
9613
9614@item
9615@t{'Range} on array objects (not subtypes), but only as the right
9616operand of the membership (@code{in}) operator.
9617
9618@item
9619@t{'Access}, @t{'Unchecked_Access}, and
9620@t{'Unrestricted_Access} (a GNAT extension).
9621
9622@item
9623@t{'Address}.
9624@end itemize
9625
9626@item
9627The names in
9628@code{Characters.Latin_1} are not available and
9629concatenation is not implemented. Thus, escape characters in strings are
9630not currently available.
9631
9632@item
9633Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9634equality of representations. They will generally work correctly
9635for strings and arrays whose elements have integer or enumeration types.
9636They may not work correctly for arrays whose element
9637types have user-defined equality, for arrays of real values
9638(in particular, IEEE-conformant floating point, because of negative
9639zeroes and NaNs), and for arrays whose elements contain unused bits with
9640indeterminate values.
9641
9642@item
9643The other component-by-component array operations (@code{and}, @code{or},
9644@code{xor}, @code{not}, and relational tests other than equality)
9645are not implemented.
9646
9647@item
9648There are no record or array aggregates.
9649
9650@item
9651Calls to dispatching subprograms are not implemented.
9652
9653@item
9654The overloading algorithm is much more limited (i.e., less selective)
9655than that of real Ada. It makes only limited use of the context in which a subexpression
9656appears to resolve its meaning, and it is much looser in its rules for allowing
9657type matches. As a result, some function calls will be ambiguous, and the user
9658will be asked to choose the proper resolution.
9659
9660@item
9661The @code{new} operator is not implemented.
9662
9663@item
9664Entry calls are not implemented.
9665
9666@item
9667Aside from printing, arithmetic operations on the native VAX floating-point
9668formats are not supported.
9669
9670@item
9671It is not possible to slice a packed array.
9672@end itemize
9673
9674@node Additions to Ada
9675@subsubsection Additions to Ada
9676@cindex Ada, deviations from
9677
9678As it does for other languages, @value{GDBN} makes certain generic
9679extensions to Ada (@pxref{Expressions}):
9680
9681@itemize @bullet
9682@item
9683If the expression @var{E} is a variable residing in memory
9684(typically a local variable or array element) and @var{N} is
9685a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9686@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9687In Ada, this operator is generally not necessary, since its prime use
9688is in displaying parts of an array, and slicing will usually do this in Ada.
9689However, there are occasional uses when debugging programs
9690in which certain debugging information has been optimized away.
9691
9692@item
9693@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9694in function or file @var{B}.'' When @var{B} is a file name, you must typically
9695surround it in single quotes.
9696
9697@item
9698The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9699@var{type} that appears at address @var{addr}.''
9700
9701@item
9702A name starting with @samp{$} is a convenience variable
9703(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9704@end itemize
9705
9706In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9707to Ada:
9708
9709@itemize @bullet
9710@item
9711The assignment statement is allowed as an expression, returning
9712its right-hand operand as its value. Thus, you may enter
9713
9714@smallexample
9715set x := y + 3
9716print A(tmp := y + 1)
9717@end smallexample
9718
9719@item
9720The semicolon is allowed as an ``operator,'' returning as its value
9721the value of its right-hand operand.
9722This allows, for example,
9723complex conditional breaks:
9724
9725@smallexample
9726break f
9727condition 1 (report(i); k += 1; A(k) > 100)
9728@end smallexample
9729
9730@item
9731Rather than use catenation and symbolic character names to introduce special
9732characters into strings, one may instead use a special bracket notation,
9733which is also used to print strings. A sequence of characters of the form
9734@samp{["@var{XX}"]} within a string or character literal denotes the
9735(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9736sequence of characters @samp{["""]} also denotes a single quotation mark
9737in strings. For example,
9738@smallexample
9739 "One line.["0a"]Next line.["0a"]"
9740@end smallexample
9741@noindent
9742contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9743period.
9744
9745@item
9746The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9747@t{'Max} is optional (and is ignored in any case). For example, it is valid
9748to write
9749
9750@smallexample
9751print 'max(x, y)
9752@end smallexample
9753
9754@item
9755When printing arrays, @value{GDBN} uses positional notation when the
9756array has a lower bound of 1, and uses a modified named notation otherwise.
9757For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9758
9759@smallexample
9760(3 => 10, 17, 1)
9761@end smallexample
9762
9763@noindent
9764That is, in contrast to valid Ada, only the first component has a @code{=>}
9765clause.
9766
9767@item
9768You may abbreviate attributes in expressions with any unique,
9769multi-character subsequence of
9770their names (an exact match gets preference).
9771For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9772in place of @t{a'length}.
9773
9774@item
9775@cindex quoting Ada internal identifiers
9776Since Ada is case-insensitive, the debugger normally maps identifiers you type
9777to lower case. The GNAT compiler uses upper-case characters for
9778some of its internal identifiers, which are normally of no interest to users.
9779For the rare occasions when you actually have to look at them,
9780enclose them in angle brackets to avoid the lower-case mapping.
9781For example,
9782@smallexample
9783@value{GDBP} print <JMPBUF_SAVE>[0]
9784@end smallexample
9785
9786@item
9787Printing an object of class-wide type or dereferencing an
9788access-to-class-wide value will display all the components of the object's
9789specific type (as indicated by its run-time tag). Likewise, component
9790selection on such a value will operate on the specific type of the
9791object.
9792
9793@end itemize
9794
9795@node Stopping Before Main Program
9796@subsubsection Stopping at the Very Beginning
9797
9798@cindex breakpointing Ada elaboration code
9799It is sometimes necessary to debug the program during elaboration, and
9800before reaching the main procedure.
9801As defined in the Ada Reference
9802Manual, the elaboration code is invoked from a procedure called
9803@code{adainit}. To run your program up to the beginning of
9804elaboration, simply use the following two commands:
9805@code{tbreak adainit} and @code{run}.
9806
9807@node Ada Glitches
9808@subsubsection Known Peculiarities of Ada Mode
9809@cindex Ada, problems
9810
9811Besides the omissions listed previously (@pxref{Omissions from Ada}),
9812we know of several problems with and limitations of Ada mode in
9813@value{GDBN},
9814some of which will be fixed with planned future releases of the debugger
9815and the GNU Ada compiler.
9816
9817@itemize @bullet
9818@item
9819Currently, the debugger
9820has insufficient information to determine whether certain pointers represent
9821pointers to objects or the objects themselves.
9822Thus, the user may have to tack an extra @code{.all} after an expression
9823to get it printed properly.
9824
9825@item
9826Static constants that the compiler chooses not to materialize as objects in
9827storage are invisible to the debugger.
9828
9829@item
9830Named parameter associations in function argument lists are ignored (the
9831argument lists are treated as positional).
9832
9833@item
9834Many useful library packages are currently invisible to the debugger.
9835
9836@item
9837Fixed-point arithmetic, conversions, input, and output is carried out using
9838floating-point arithmetic, and may give results that only approximate those on
9839the host machine.
9840
9841@item
9842The type of the @t{'Address} attribute may not be @code{System.Address}.
9843
9844@item
9845The GNAT compiler never generates the prefix @code{Standard} for any of
9846the standard symbols defined by the Ada language. @value{GDBN} knows about
9847this: it will strip the prefix from names when you use it, and will never
9848look for a name you have so qualified among local symbols, nor match against
9849symbols in other packages or subprograms. If you have
9850defined entities anywhere in your program other than parameters and
9851local variables whose simple names match names in @code{Standard},
9852GNAT's lack of qualification here can cause confusion. When this happens,
9853you can usually resolve the confusion
9854by qualifying the problematic names with package
9855@code{Standard} explicitly.
9856@end itemize
9857
4e562065
JB
9858@node Unsupported languages
9859@section Unsupported languages
9860
9861@cindex unsupported languages
9862@cindex minimal language
9863In addition to the other fully-supported programming languages,
9864@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9865It does not represent a real programming language, but provides a set
9866of capabilities close to what the C or assembly languages provide.
9867This should allow most simple operations to be performed while debugging
9868an application that uses a language currently not supported by @value{GDBN}.
9869
9870If the language is set to @code{auto}, @value{GDBN} will automatically
9871select this language if the current frame corresponds to an unsupported
9872language.
9873
6d2ebf8b 9874@node Symbols
c906108c
SS
9875@chapter Examining the Symbol Table
9876
d4f3574e 9877The commands described in this chapter allow you to inquire about the
c906108c
SS
9878symbols (names of variables, functions and types) defined in your
9879program. This information is inherent in the text of your program and
9880does not change as your program executes. @value{GDBN} finds it in your
9881program's symbol table, in the file indicated when you started @value{GDBN}
9882(@pxref{File Options, ,Choosing files}), or by one of the
9883file-management commands (@pxref{Files, ,Commands to specify files}).
9884
9885@cindex symbol names
9886@cindex names of symbols
9887@cindex quoting names
9888Occasionally, you may need to refer to symbols that contain unusual
9889characters, which @value{GDBN} ordinarily treats as word delimiters. The
9890most frequent case is in referring to static variables in other
9891source files (@pxref{Variables,,Program variables}). File names
9892are recorded in object files as debugging symbols, but @value{GDBN} would
9893ordinarily parse a typical file name, like @file{foo.c}, as the three words
9894@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9895@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9896
474c8240 9897@smallexample
c906108c 9898p 'foo.c'::x
474c8240 9899@end smallexample
c906108c
SS
9900
9901@noindent
9902looks up the value of @code{x} in the scope of the file @file{foo.c}.
9903
9904@table @code
a8f24a35
EZ
9905@cindex case-insensitive symbol names
9906@cindex case sensitivity in symbol names
9907@kindex set case-sensitive
9908@item set case-sensitive on
9909@itemx set case-sensitive off
9910@itemx set case-sensitive auto
9911Normally, when @value{GDBN} looks up symbols, it matches their names
9912with case sensitivity determined by the current source language.
9913Occasionally, you may wish to control that. The command @code{set
9914case-sensitive} lets you do that by specifying @code{on} for
9915case-sensitive matches or @code{off} for case-insensitive ones. If
9916you specify @code{auto}, case sensitivity is reset to the default
9917suitable for the source language. The default is case-sensitive
9918matches for all languages except for Fortran, for which the default is
9919case-insensitive matches.
9920
9c16f35a
EZ
9921@kindex show case-sensitive
9922@item show case-sensitive
a8f24a35
EZ
9923This command shows the current setting of case sensitivity for symbols
9924lookups.
9925
c906108c 9926@kindex info address
b37052ae 9927@cindex address of a symbol
c906108c
SS
9928@item info address @var{symbol}
9929Describe where the data for @var{symbol} is stored. For a register
9930variable, this says which register it is kept in. For a non-register
9931local variable, this prints the stack-frame offset at which the variable
9932is always stored.
9933
9934Note the contrast with @samp{print &@var{symbol}}, which does not work
9935at all for a register variable, and for a stack local variable prints
9936the exact address of the current instantiation of the variable.
9937
3d67e040 9938@kindex info symbol
b37052ae 9939@cindex symbol from address
9c16f35a 9940@cindex closest symbol and offset for an address
3d67e040
EZ
9941@item info symbol @var{addr}
9942Print the name of a symbol which is stored at the address @var{addr}.
9943If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9944nearest symbol and an offset from it:
9945
474c8240 9946@smallexample
3d67e040
EZ
9947(@value{GDBP}) info symbol 0x54320
9948_initialize_vx + 396 in section .text
474c8240 9949@end smallexample
3d67e040
EZ
9950
9951@noindent
9952This is the opposite of the @code{info address} command. You can use
9953it to find out the name of a variable or a function given its address.
9954
c906108c 9955@kindex whatis
d4f3574e
SS
9956@item whatis @var{expr}
9957Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9958actually evaluated, and any side-effecting operations (such as
9959assignments or function calls) inside it do not take place.
9960@xref{Expressions, ,Expressions}.
9961
9962@item whatis
9963Print the data type of @code{$}, the last value in the value history.
9964
9965@kindex ptype
9966@item ptype @var{typename}
9967Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9968the name of a type, or for C code it may have the form @samp{class
9969@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9970@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9971
d4f3574e 9972@item ptype @var{expr}
c906108c 9973@itemx ptype
d4f3574e 9974Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9975differs from @code{whatis} by printing a detailed description, instead
9976of just the name of the type.
9977
9978For example, for this variable declaration:
9979
474c8240 9980@smallexample
c906108c 9981struct complex @{double real; double imag;@} v;
474c8240 9982@end smallexample
c906108c
SS
9983
9984@noindent
9985the two commands give this output:
9986
474c8240 9987@smallexample
c906108c
SS
9988@group
9989(@value{GDBP}) whatis v
9990type = struct complex
9991(@value{GDBP}) ptype v
9992type = struct complex @{
9993 double real;
9994 double imag;
9995@}
9996@end group
474c8240 9997@end smallexample
c906108c
SS
9998
9999@noindent
10000As with @code{whatis}, using @code{ptype} without an argument refers to
10001the type of @code{$}, the last value in the value history.
10002
10003@kindex info types
10004@item info types @var{regexp}
10005@itemx info types
09d4efe1
EZ
10006Print a brief description of all types whose names match the regular
10007expression @var{regexp} (or all types in your program, if you supply
10008no argument). Each complete typename is matched as though it were a
10009complete line; thus, @samp{i type value} gives information on all
10010types in your program whose names include the string @code{value}, but
10011@samp{i type ^value$} gives information only on types whose complete
10012name is @code{value}.
c906108c
SS
10013
10014This command differs from @code{ptype} in two ways: first, like
10015@code{whatis}, it does not print a detailed description; second, it
10016lists all source files where a type is defined.
10017
b37052ae
EZ
10018@kindex info scope
10019@cindex local variables
09d4efe1 10020@item info scope @var{location}
b37052ae 10021List all the variables local to a particular scope. This command
09d4efe1
EZ
10022accepts a @var{location} argument---a function name, a source line, or
10023an address preceded by a @samp{*}, and prints all the variables local
10024to the scope defined by that location. For example:
b37052ae
EZ
10025
10026@smallexample
10027(@value{GDBP}) @b{info scope command_line_handler}
10028Scope for command_line_handler:
10029Symbol rl is an argument at stack/frame offset 8, length 4.
10030Symbol linebuffer is in static storage at address 0x150a18, length 4.
10031Symbol linelength is in static storage at address 0x150a1c, length 4.
10032Symbol p is a local variable in register $esi, length 4.
10033Symbol p1 is a local variable in register $ebx, length 4.
10034Symbol nline is a local variable in register $edx, length 4.
10035Symbol repeat is a local variable at frame offset -8, length 4.
10036@end smallexample
10037
f5c37c66
EZ
10038@noindent
10039This command is especially useful for determining what data to collect
10040during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10041collect}.
10042
c906108c
SS
10043@kindex info source
10044@item info source
919d772c
JB
10045Show information about the current source file---that is, the source file for
10046the function containing the current point of execution:
10047@itemize @bullet
10048@item
10049the name of the source file, and the directory containing it,
10050@item
10051the directory it was compiled in,
10052@item
10053its length, in lines,
10054@item
10055which programming language it is written in,
10056@item
10057whether the executable includes debugging information for that file, and
10058if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10059@item
10060whether the debugging information includes information about
10061preprocessor macros.
10062@end itemize
10063
c906108c
SS
10064
10065@kindex info sources
10066@item info sources
10067Print the names of all source files in your program for which there is
10068debugging information, organized into two lists: files whose symbols
10069have already been read, and files whose symbols will be read when needed.
10070
10071@kindex info functions
10072@item info functions
10073Print the names and data types of all defined functions.
10074
10075@item info functions @var{regexp}
10076Print the names and data types of all defined functions
10077whose names contain a match for regular expression @var{regexp}.
10078Thus, @samp{info fun step} finds all functions whose names
10079include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10080start with @code{step}. If a function name contains characters
10081that conflict with the regular expression language (eg.
1c5dfdad 10082@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10083
10084@kindex info variables
10085@item info variables
10086Print the names and data types of all variables that are declared
6ca652b0 10087outside of functions (i.e.@: excluding local variables).
c906108c
SS
10088
10089@item info variables @var{regexp}
10090Print the names and data types of all variables (except for local
10091variables) whose names contain a match for regular expression
10092@var{regexp}.
10093
b37303ee 10094@kindex info classes
721c2651 10095@cindex Objective-C, classes and selectors
b37303ee
AF
10096@item info classes
10097@itemx info classes @var{regexp}
10098Display all Objective-C classes in your program, or
10099(with the @var{regexp} argument) all those matching a particular regular
10100expression.
10101
10102@kindex info selectors
10103@item info selectors
10104@itemx info selectors @var{regexp}
10105Display all Objective-C selectors in your program, or
10106(with the @var{regexp} argument) all those matching a particular regular
10107expression.
10108
c906108c
SS
10109@ignore
10110This was never implemented.
10111@kindex info methods
10112@item info methods
10113@itemx info methods @var{regexp}
10114The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10115methods within C@t{++} program, or (with the @var{regexp} argument) a
10116specific set of methods found in the various C@t{++} classes. Many
10117C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10118from the @code{ptype} command can be overwhelming and hard to use. The
10119@code{info-methods} command filters the methods, printing only those
10120which match the regular-expression @var{regexp}.
10121@end ignore
10122
c906108c
SS
10123@cindex reloading symbols
10124Some systems allow individual object files that make up your program to
7a292a7a
SS
10125be replaced without stopping and restarting your program. For example,
10126in VxWorks you can simply recompile a defective object file and keep on
10127running. If you are running on one of these systems, you can allow
10128@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10129
10130@table @code
10131@kindex set symbol-reloading
10132@item set symbol-reloading on
10133Replace symbol definitions for the corresponding source file when an
10134object file with a particular name is seen again.
10135
10136@item set symbol-reloading off
6d2ebf8b
SS
10137Do not replace symbol definitions when encountering object files of the
10138same name more than once. This is the default state; if you are not
10139running on a system that permits automatic relinking of modules, you
10140should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10141may discard symbols when linking large programs, that may contain
10142several modules (from different directories or libraries) with the same
10143name.
c906108c
SS
10144
10145@kindex show symbol-reloading
10146@item show symbol-reloading
10147Show the current @code{on} or @code{off} setting.
10148@end table
c906108c 10149
9c16f35a 10150@cindex opaque data types
c906108c
SS
10151@kindex set opaque-type-resolution
10152@item set opaque-type-resolution on
10153Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10154declared as a pointer to a @code{struct}, @code{class}, or
10155@code{union}---for example, @code{struct MyType *}---that is used in one
10156source file although the full declaration of @code{struct MyType} is in
10157another source file. The default is on.
10158
10159A change in the setting of this subcommand will not take effect until
10160the next time symbols for a file are loaded.
10161
10162@item set opaque-type-resolution off
10163Tell @value{GDBN} not to resolve opaque types. In this case, the type
10164is printed as follows:
10165@smallexample
10166@{<no data fields>@}
10167@end smallexample
10168
10169@kindex show opaque-type-resolution
10170@item show opaque-type-resolution
10171Show whether opaque types are resolved or not.
c906108c
SS
10172
10173@kindex maint print symbols
10174@cindex symbol dump
10175@kindex maint print psymbols
10176@cindex partial symbol dump
10177@item maint print symbols @var{filename}
10178@itemx maint print psymbols @var{filename}
10179@itemx maint print msymbols @var{filename}
10180Write a dump of debugging symbol data into the file @var{filename}.
10181These commands are used to debug the @value{GDBN} symbol-reading code. Only
10182symbols with debugging data are included. If you use @samp{maint print
10183symbols}, @value{GDBN} includes all the symbols for which it has already
10184collected full details: that is, @var{filename} reflects symbols for
10185only those files whose symbols @value{GDBN} has read. You can use the
10186command @code{info sources} to find out which files these are. If you
10187use @samp{maint print psymbols} instead, the dump shows information about
10188symbols that @value{GDBN} only knows partially---that is, symbols defined in
10189files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10190@samp{maint print msymbols} dumps just the minimal symbol information
10191required for each object file from which @value{GDBN} has read some symbols.
10192@xref{Files, ,Commands to specify files}, for a discussion of how
10193@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10194
5e7b2f39
JB
10195@kindex maint info symtabs
10196@kindex maint info psymtabs
44ea7b70
JB
10197@cindex listing @value{GDBN}'s internal symbol tables
10198@cindex symbol tables, listing @value{GDBN}'s internal
10199@cindex full symbol tables, listing @value{GDBN}'s internal
10200@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10201@item maint info symtabs @r{[} @var{regexp} @r{]}
10202@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10203
10204List the @code{struct symtab} or @code{struct partial_symtab}
10205structures whose names match @var{regexp}. If @var{regexp} is not
10206given, list them all. The output includes expressions which you can
10207copy into a @value{GDBN} debugging this one to examine a particular
10208structure in more detail. For example:
10209
10210@smallexample
5e7b2f39 10211(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10212@{ objfile /home/gnu/build/gdb/gdb
10213 ((struct objfile *) 0x82e69d0)
b383017d 10214 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10215 ((struct partial_symtab *) 0x8474b10)
10216 readin no
10217 fullname (null)
10218 text addresses 0x814d3c8 -- 0x8158074
10219 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10220 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10221 dependencies (none)
10222 @}
10223@}
5e7b2f39 10224(@value{GDBP}) maint info symtabs
44ea7b70
JB
10225(@value{GDBP})
10226@end smallexample
10227@noindent
10228We see that there is one partial symbol table whose filename contains
10229the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10230and we see that @value{GDBN} has not read in any symtabs yet at all.
10231If we set a breakpoint on a function, that will cause @value{GDBN} to
10232read the symtab for the compilation unit containing that function:
10233
10234@smallexample
10235(@value{GDBP}) break dwarf2_psymtab_to_symtab
10236Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10237line 1574.
5e7b2f39 10238(@value{GDBP}) maint info symtabs
b383017d 10239@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10240 ((struct objfile *) 0x82e69d0)
b383017d 10241 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10242 ((struct symtab *) 0x86c1f38)
10243 dirname (null)
10244 fullname (null)
10245 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10246 debugformat DWARF 2
10247 @}
10248@}
b383017d 10249(@value{GDBP})
44ea7b70 10250@end smallexample
c906108c
SS
10251@end table
10252
44ea7b70 10253
6d2ebf8b 10254@node Altering
c906108c
SS
10255@chapter Altering Execution
10256
10257Once you think you have found an error in your program, you might want to
10258find out for certain whether correcting the apparent error would lead to
10259correct results in the rest of the run. You can find the answer by
10260experiment, using the @value{GDBN} features for altering execution of the
10261program.
10262
10263For example, you can store new values into variables or memory
7a292a7a
SS
10264locations, give your program a signal, restart it at a different
10265address, or even return prematurely from a function.
c906108c
SS
10266
10267@menu
10268* Assignment:: Assignment to variables
10269* Jumping:: Continuing at a different address
c906108c 10270* Signaling:: Giving your program a signal
c906108c
SS
10271* Returning:: Returning from a function
10272* Calling:: Calling your program's functions
10273* Patching:: Patching your program
10274@end menu
10275
6d2ebf8b 10276@node Assignment
c906108c
SS
10277@section Assignment to variables
10278
10279@cindex assignment
10280@cindex setting variables
10281To alter the value of a variable, evaluate an assignment expression.
10282@xref{Expressions, ,Expressions}. For example,
10283
474c8240 10284@smallexample
c906108c 10285print x=4
474c8240 10286@end smallexample
c906108c
SS
10287
10288@noindent
10289stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10290value of the assignment expression (which is 4).
c906108c
SS
10291@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10292information on operators in supported languages.
c906108c
SS
10293
10294@kindex set variable
10295@cindex variables, setting
10296If you are not interested in seeing the value of the assignment, use the
10297@code{set} command instead of the @code{print} command. @code{set} is
10298really the same as @code{print} except that the expression's value is
10299not printed and is not put in the value history (@pxref{Value History,
10300,Value history}). The expression is evaluated only for its effects.
10301
c906108c
SS
10302If the beginning of the argument string of the @code{set} command
10303appears identical to a @code{set} subcommand, use the @code{set
10304variable} command instead of just @code{set}. This command is identical
10305to @code{set} except for its lack of subcommands. For example, if your
10306program has a variable @code{width}, you get an error if you try to set
10307a new value with just @samp{set width=13}, because @value{GDBN} has the
10308command @code{set width}:
10309
474c8240 10310@smallexample
c906108c
SS
10311(@value{GDBP}) whatis width
10312type = double
10313(@value{GDBP}) p width
10314$4 = 13
10315(@value{GDBP}) set width=47
10316Invalid syntax in expression.
474c8240 10317@end smallexample
c906108c
SS
10318
10319@noindent
10320The invalid expression, of course, is @samp{=47}. In
10321order to actually set the program's variable @code{width}, use
10322
474c8240 10323@smallexample
c906108c 10324(@value{GDBP}) set var width=47
474c8240 10325@end smallexample
53a5351d 10326
c906108c
SS
10327Because the @code{set} command has many subcommands that can conflict
10328with the names of program variables, it is a good idea to use the
10329@code{set variable} command instead of just @code{set}. For example, if
10330your program has a variable @code{g}, you run into problems if you try
10331to set a new value with just @samp{set g=4}, because @value{GDBN} has
10332the command @code{set gnutarget}, abbreviated @code{set g}:
10333
474c8240 10334@smallexample
c906108c
SS
10335@group
10336(@value{GDBP}) whatis g
10337type = double
10338(@value{GDBP}) p g
10339$1 = 1
10340(@value{GDBP}) set g=4
2df3850c 10341(@value{GDBP}) p g
c906108c
SS
10342$2 = 1
10343(@value{GDBP}) r
10344The program being debugged has been started already.
10345Start it from the beginning? (y or n) y
10346Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10347"/home/smith/cc_progs/a.out": can't open to read symbols:
10348 Invalid bfd target.
c906108c
SS
10349(@value{GDBP}) show g
10350The current BFD target is "=4".
10351@end group
474c8240 10352@end smallexample
c906108c
SS
10353
10354@noindent
10355The program variable @code{g} did not change, and you silently set the
10356@code{gnutarget} to an invalid value. In order to set the variable
10357@code{g}, use
10358
474c8240 10359@smallexample
c906108c 10360(@value{GDBP}) set var g=4
474c8240 10361@end smallexample
c906108c
SS
10362
10363@value{GDBN} allows more implicit conversions in assignments than C; you can
10364freely store an integer value into a pointer variable or vice versa,
10365and you can convert any structure to any other structure that is the
10366same length or shorter.
10367@comment FIXME: how do structs align/pad in these conversions?
10368@comment /doc@cygnus.com 18dec1990
10369
10370To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10371construct to generate a value of specified type at a specified address
10372(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10373to memory location @code{0x83040} as an integer (which implies a certain size
10374and representation in memory), and
10375
474c8240 10376@smallexample
c906108c 10377set @{int@}0x83040 = 4
474c8240 10378@end smallexample
c906108c
SS
10379
10380@noindent
10381stores the value 4 into that memory location.
10382
6d2ebf8b 10383@node Jumping
c906108c
SS
10384@section Continuing at a different address
10385
10386Ordinarily, when you continue your program, you do so at the place where
10387it stopped, with the @code{continue} command. You can instead continue at
10388an address of your own choosing, with the following commands:
10389
10390@table @code
10391@kindex jump
10392@item jump @var{linespec}
10393Resume execution at line @var{linespec}. Execution stops again
10394immediately if there is a breakpoint there. @xref{List, ,Printing
10395source lines}, for a description of the different forms of
10396@var{linespec}. It is common practice to use the @code{tbreak} command
10397in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10398breakpoints}.
10399
10400The @code{jump} command does not change the current stack frame, or
10401the stack pointer, or the contents of any memory location or any
10402register other than the program counter. If line @var{linespec} is in
10403a different function from the one currently executing, the results may
10404be bizarre if the two functions expect different patterns of arguments or
10405of local variables. For this reason, the @code{jump} command requests
10406confirmation if the specified line is not in the function currently
10407executing. However, even bizarre results are predictable if you are
10408well acquainted with the machine-language code of your program.
10409
10410@item jump *@var{address}
10411Resume execution at the instruction at address @var{address}.
10412@end table
10413
c906108c 10414@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10415On many systems, you can get much the same effect as the @code{jump}
10416command by storing a new value into the register @code{$pc}. The
10417difference is that this does not start your program running; it only
10418changes the address of where it @emph{will} run when you continue. For
10419example,
c906108c 10420
474c8240 10421@smallexample
c906108c 10422set $pc = 0x485
474c8240 10423@end smallexample
c906108c
SS
10424
10425@noindent
10426makes the next @code{continue} command or stepping command execute at
10427address @code{0x485}, rather than at the address where your program stopped.
10428@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10429
10430The most common occasion to use the @code{jump} command is to back
10431up---perhaps with more breakpoints set---over a portion of a program
10432that has already executed, in order to examine its execution in more
10433detail.
10434
c906108c 10435@c @group
6d2ebf8b 10436@node Signaling
c906108c 10437@section Giving your program a signal
9c16f35a 10438@cindex deliver a signal to a program
c906108c
SS
10439
10440@table @code
10441@kindex signal
10442@item signal @var{signal}
10443Resume execution where your program stopped, but immediately give it the
10444signal @var{signal}. @var{signal} can be the name or the number of a
10445signal. For example, on many systems @code{signal 2} and @code{signal
10446SIGINT} are both ways of sending an interrupt signal.
10447
10448Alternatively, if @var{signal} is zero, continue execution without
10449giving a signal. This is useful when your program stopped on account of
10450a signal and would ordinary see the signal when resumed with the
10451@code{continue} command; @samp{signal 0} causes it to resume without a
10452signal.
10453
10454@code{signal} does not repeat when you press @key{RET} a second time
10455after executing the command.
10456@end table
10457@c @end group
10458
10459Invoking the @code{signal} command is not the same as invoking the
10460@code{kill} utility from the shell. Sending a signal with @code{kill}
10461causes @value{GDBN} to decide what to do with the signal depending on
10462the signal handling tables (@pxref{Signals}). The @code{signal} command
10463passes the signal directly to your program.
10464
c906108c 10465
6d2ebf8b 10466@node Returning
c906108c
SS
10467@section Returning from a function
10468
10469@table @code
10470@cindex returning from a function
10471@kindex return
10472@item return
10473@itemx return @var{expression}
10474You can cancel execution of a function call with the @code{return}
10475command. If you give an
10476@var{expression} argument, its value is used as the function's return
10477value.
10478@end table
10479
10480When you use @code{return}, @value{GDBN} discards the selected stack frame
10481(and all frames within it). You can think of this as making the
10482discarded frame return prematurely. If you wish to specify a value to
10483be returned, give that value as the argument to @code{return}.
10484
10485This pops the selected stack frame (@pxref{Selection, ,Selecting a
10486frame}), and any other frames inside of it, leaving its caller as the
10487innermost remaining frame. That frame becomes selected. The
10488specified value is stored in the registers used for returning values
10489of functions.
10490
10491The @code{return} command does not resume execution; it leaves the
10492program stopped in the state that would exist if the function had just
10493returned. In contrast, the @code{finish} command (@pxref{Continuing
10494and Stepping, ,Continuing and stepping}) resumes execution until the
10495selected stack frame returns naturally.
10496
6d2ebf8b 10497@node Calling
c906108c
SS
10498@section Calling program functions
10499
f8568604 10500@table @code
c906108c 10501@cindex calling functions
f8568604
EZ
10502@cindex inferior functions, calling
10503@item print @var{expr}
9c16f35a 10504Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10505@var{expr} may include calls to functions in the program being
10506debugged.
10507
c906108c 10508@kindex call
c906108c
SS
10509@item call @var{expr}
10510Evaluate the expression @var{expr} without displaying @code{void}
10511returned values.
c906108c
SS
10512
10513You can use this variant of the @code{print} command if you want to
f8568604
EZ
10514execute a function from your program that does not return anything
10515(a.k.a.@: @dfn{a void function}), but without cluttering the output
10516with @code{void} returned values that @value{GDBN} will otherwise
10517print. If the result is not void, it is printed and saved in the
10518value history.
10519@end table
10520
9c16f35a
EZ
10521It is possible for the function you call via the @code{print} or
10522@code{call} command to generate a signal (e.g., if there's a bug in
10523the function, or if you passed it incorrect arguments). What happens
10524in that case is controlled by the @code{set unwindonsignal} command.
10525
10526@table @code
10527@item set unwindonsignal
10528@kindex set unwindonsignal
10529@cindex unwind stack in called functions
10530@cindex call dummy stack unwinding
10531Set unwinding of the stack if a signal is received while in a function
10532that @value{GDBN} called in the program being debugged. If set to on,
10533@value{GDBN} unwinds the stack it created for the call and restores
10534the context to what it was before the call. If set to off (the
10535default), @value{GDBN} stops in the frame where the signal was
10536received.
10537
10538@item show unwindonsignal
10539@kindex show unwindonsignal
10540Show the current setting of stack unwinding in the functions called by
10541@value{GDBN}.
10542@end table
10543
f8568604
EZ
10544@cindex weak alias functions
10545Sometimes, a function you wish to call is actually a @dfn{weak alias}
10546for another function. In such case, @value{GDBN} might not pick up
10547the type information, including the types of the function arguments,
10548which causes @value{GDBN} to call the inferior function incorrectly.
10549As a result, the called function will function erroneously and may
10550even crash. A solution to that is to use the name of the aliased
10551function instead.
c906108c 10552
6d2ebf8b 10553@node Patching
c906108c 10554@section Patching programs
7a292a7a 10555
c906108c
SS
10556@cindex patching binaries
10557@cindex writing into executables
c906108c 10558@cindex writing into corefiles
c906108c 10559
7a292a7a
SS
10560By default, @value{GDBN} opens the file containing your program's
10561executable code (or the corefile) read-only. This prevents accidental
10562alterations to machine code; but it also prevents you from intentionally
10563patching your program's binary.
c906108c
SS
10564
10565If you'd like to be able to patch the binary, you can specify that
10566explicitly with the @code{set write} command. For example, you might
10567want to turn on internal debugging flags, or even to make emergency
10568repairs.
10569
10570@table @code
10571@kindex set write
10572@item set write on
10573@itemx set write off
7a292a7a
SS
10574If you specify @samp{set write on}, @value{GDBN} opens executable and
10575core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10576off} (the default), @value{GDBN} opens them read-only.
10577
10578If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10579@code{exec-file} or @code{core-file} command) after changing @code{set
10580write}, for your new setting to take effect.
c906108c
SS
10581
10582@item show write
10583@kindex show write
7a292a7a
SS
10584Display whether executable files and core files are opened for writing
10585as well as reading.
c906108c
SS
10586@end table
10587
6d2ebf8b 10588@node GDB Files
c906108c
SS
10589@chapter @value{GDBN} Files
10590
7a292a7a
SS
10591@value{GDBN} needs to know the file name of the program to be debugged,
10592both in order to read its symbol table and in order to start your
10593program. To debug a core dump of a previous run, you must also tell
10594@value{GDBN} the name of the core dump file.
c906108c
SS
10595
10596@menu
10597* Files:: Commands to specify files
5b5d99cf 10598* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10599* Symbol Errors:: Errors reading symbol files
10600@end menu
10601
6d2ebf8b 10602@node Files
c906108c 10603@section Commands to specify files
c906108c 10604
7a292a7a 10605@cindex symbol table
c906108c 10606@cindex core dump file
7a292a7a
SS
10607
10608You may want to specify executable and core dump file names. The usual
10609way to do this is at start-up time, using the arguments to
10610@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10611Out of @value{GDBN}}).
c906108c
SS
10612
10613Occasionally it is necessary to change to a different file during a
10614@value{GDBN} session. Or you may run @value{GDBN} and forget to specify
10615a file you want to use. In these situations the @value{GDBN} commands
10616to specify new files are useful.
10617
10618@table @code
10619@cindex executable file
10620@kindex file
10621@item file @var{filename}
10622Use @var{filename} as the program to be debugged. It is read for its
10623symbols and for the contents of pure memory. It is also the program
10624executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10625directory and the file is not found in the @value{GDBN} working directory,
10626@value{GDBN} uses the environment variable @code{PATH} as a list of
10627directories to search, just as the shell does when looking for a program
10628to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10629and your program, using the @code{path} command.
10630
6d2ebf8b 10631On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10632@file{@var{filename}.syms} may hold symbol table information for
10633@var{filename}. If so, @value{GDBN} maps in the symbol table from
10634@file{@var{filename}.syms}, starting up more quickly. See the
10635descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10636(available on the command line, see @ref{File Options, , -readnow},
10637and with the commands @code{file}, @code{symbol-file}, or
10638@code{add-symbol-file}, described below), for more information.
c906108c
SS
10639
10640@item file
10641@code{file} with no argument makes @value{GDBN} discard any information it
10642has on both executable file and the symbol table.
10643
10644@kindex exec-file
10645@item exec-file @r{[} @var{filename} @r{]}
10646Specify that the program to be run (but not the symbol table) is found
10647in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10648if necessary to locate your program. Omitting @var{filename} means to
10649discard information on the executable file.
10650
10651@kindex symbol-file
10652@item symbol-file @r{[} @var{filename} @r{]}
10653Read symbol table information from file @var{filename}. @code{PATH} is
10654searched when necessary. Use the @code{file} command to get both symbol
10655table and program to run from the same file.
10656
10657@code{symbol-file} with no argument clears out @value{GDBN} information on your
10658program's symbol table.
10659
5d161b24 10660The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10661of its convenience variables, the value history, and all breakpoints and
10662auto-display expressions. This is because they may contain pointers to
10663the internal data recording symbols and data types, which are part of
10664the old symbol table data being discarded inside @value{GDBN}.
10665
10666@code{symbol-file} does not repeat if you press @key{RET} again after
10667executing it once.
10668
10669When @value{GDBN} is configured for a particular environment, it
10670understands debugging information in whatever format is the standard
10671generated for that environment; you may use either a @sc{gnu} compiler, or
10672other compilers that adhere to the local conventions.
c906108c
SS
10673Best results are usually obtained from @sc{gnu} compilers; for example,
10674using @code{@value{GCC}} you can generate debugging information for
10675optimized code.
c906108c
SS
10676
10677For most kinds of object files, with the exception of old SVR3 systems
10678using COFF, the @code{symbol-file} command does not normally read the
10679symbol table in full right away. Instead, it scans the symbol table
10680quickly to find which source files and which symbols are present. The
10681details are read later, one source file at a time, as they are needed.
10682
10683The purpose of this two-stage reading strategy is to make @value{GDBN}
10684start up faster. For the most part, it is invisible except for
10685occasional pauses while the symbol table details for a particular source
10686file are being read. (The @code{set verbose} command can turn these
10687pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10688warnings and messages}.)
10689
c906108c
SS
10690We have not implemented the two-stage strategy for COFF yet. When the
10691symbol table is stored in COFF format, @code{symbol-file} reads the
10692symbol table data in full right away. Note that ``stabs-in-COFF''
10693still does the two-stage strategy, since the debug info is actually
10694in stabs format.
10695
10696@kindex readnow
10697@cindex reading symbols immediately
10698@cindex symbols, reading immediately
10699@kindex mapped
10700@cindex memory-mapped symbol file
10701@cindex saving symbol table
10702@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10703@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10704You can override the @value{GDBN} two-stage strategy for reading symbol
10705tables by using the @samp{-readnow} option with any of the commands that
10706load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10707entire symbol table available.
c906108c 10708
c906108c
SS
10709If memory-mapped files are available on your system through the
10710@code{mmap} system call, you can use another option, @samp{-mapped}, to
10711cause @value{GDBN} to write the symbols for your program into a reusable
10712file. Future @value{GDBN} debugging sessions map in symbol information
10713from this auxiliary symbol file (if the program has not changed), rather
10714than spending time reading the symbol table from the executable
10715program. Using the @samp{-mapped} option has the same effect as
10716starting @value{GDBN} with the @samp{-mapped} command-line option.
10717
10718You can use both options together, to make sure the auxiliary symbol
10719file has all the symbol information for your program.
10720
10721The auxiliary symbol file for a program called @var{myprog} is called
10722@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10723than the corresponding executable), @value{GDBN} always attempts to use
10724it when you debug @var{myprog}; no special options or commands are
10725needed.
10726
10727The @file{.syms} file is specific to the host machine where you run
10728@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10729symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10730
10731@c FIXME: for now no mention of directories, since this seems to be in
10732@c flux. 13mar1992 status is that in theory GDB would look either in
10733@c current dir or in same dir as myprog; but issues like competing
10734@c GDB's, or clutter in system dirs, mean that in practice right now
10735@c only current dir is used. FFish says maybe a special GDB hierarchy
10736@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10737@c files.
10738
c906108c 10739@kindex core-file
09d4efe1 10740@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10741@itemx core
c906108c
SS
10742Specify the whereabouts of a core dump file to be used as the ``contents
10743of memory''. Traditionally, core files contain only some parts of the
10744address space of the process that generated them; @value{GDBN} can access the
10745executable file itself for other parts.
10746
10747@code{core-file} with no argument specifies that no core file is
10748to be used.
10749
10750Note that the core file is ignored when your program is actually running
7a292a7a
SS
10751under @value{GDBN}. So, if you have been running your program and you
10752wish to debug a core file instead, you must kill the subprocess in which
10753the program is running. To do this, use the @code{kill} command
c906108c 10754(@pxref{Kill Process, ,Killing the child process}).
c906108c 10755
c906108c
SS
10756@kindex add-symbol-file
10757@cindex dynamic linking
10758@item add-symbol-file @var{filename} @var{address}
10759@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10760@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10761The @code{add-symbol-file} command reads additional symbol table
10762information from the file @var{filename}. You would use this command
10763when @var{filename} has been dynamically loaded (by some other means)
10764into the program that is running. @var{address} should be the memory
10765address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10766this out for itself. You can additionally specify an arbitrary number
10767of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10768section name and base address for that section. You can specify any
10769@var{address} as an expression.
c906108c
SS
10770
10771The symbol table of the file @var{filename} is added to the symbol table
10772originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10773@code{add-symbol-file} command any number of times; the new symbol data
10774thus read keeps adding to the old. To discard all old symbol data
10775instead, use the @code{symbol-file} command without any arguments.
c906108c 10776
17d9d558
JB
10777@cindex relocatable object files, reading symbols from
10778@cindex object files, relocatable, reading symbols from
10779@cindex reading symbols from relocatable object files
10780@cindex symbols, reading from relocatable object files
10781@cindex @file{.o} files, reading symbols from
10782Although @var{filename} is typically a shared library file, an
10783executable file, or some other object file which has been fully
10784relocated for loading into a process, you can also load symbolic
10785information from relocatable @file{.o} files, as long as:
10786
10787@itemize @bullet
10788@item
10789the file's symbolic information refers only to linker symbols defined in
10790that file, not to symbols defined by other object files,
10791@item
10792every section the file's symbolic information refers to has actually
10793been loaded into the inferior, as it appears in the file, and
10794@item
10795you can determine the address at which every section was loaded, and
10796provide these to the @code{add-symbol-file} command.
10797@end itemize
10798
10799@noindent
10800Some embedded operating systems, like Sun Chorus and VxWorks, can load
10801relocatable files into an already running program; such systems
10802typically make the requirements above easy to meet. However, it's
10803important to recognize that many native systems use complex link
49efadf5 10804procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10805assembly, for example) that make the requirements difficult to meet. In
10806general, one cannot assume that using @code{add-symbol-file} to read a
10807relocatable object file's symbolic information will have the same effect
10808as linking the relocatable object file into the program in the normal
10809way.
10810
c906108c
SS
10811@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10812
10813You can use the @samp{-mapped} and @samp{-readnow} options just as with
10814the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10815table information for @var{filename}.
10816
c45da7e6
EZ
10817@kindex add-symbol-file-from-memory
10818@cindex @code{syscall DSO}
10819@cindex load symbols from memory
10820@item add-symbol-file-from-memory @var{address}
10821Load symbols from the given @var{address} in a dynamically loaded
10822object file whose image is mapped directly into the inferior's memory.
10823For example, the Linux kernel maps a @code{syscall DSO} into each
10824process's address space; this DSO provides kernel-specific code for
10825some system calls. The argument can be any expression whose
10826evaluation yields the address of the file's shared object file header.
10827For this command to work, you must have used @code{symbol-file} or
10828@code{exec-file} commands in advance.
10829
09d4efe1
EZ
10830@kindex add-shared-symbol-files
10831@kindex assf
10832@item add-shared-symbol-files @var{library-file}
10833@itemx assf @var{library-file}
10834The @code{add-shared-symbol-files} command can currently be used only
10835in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10836alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10837@value{GDBN} automatically looks for shared libraries, however if
10838@value{GDBN} does not find yours, you can invoke
10839@code{add-shared-symbol-files}. It takes one argument: the shared
10840library's file name. @code{assf} is a shorthand alias for
10841@code{add-shared-symbol-files}.
c906108c 10842
c906108c 10843@kindex section
09d4efe1
EZ
10844@item section @var{section} @var{addr}
10845The @code{section} command changes the base address of the named
10846@var{section} of the exec file to @var{addr}. This can be used if the
10847exec file does not contain section addresses, (such as in the
10848@code{a.out} format), or when the addresses specified in the file
10849itself are wrong. Each section must be changed separately. The
10850@code{info files} command, described below, lists all the sections and
10851their addresses.
c906108c
SS
10852
10853@kindex info files
10854@kindex info target
10855@item info files
10856@itemx info target
7a292a7a
SS
10857@code{info files} and @code{info target} are synonymous; both print the
10858current target (@pxref{Targets, ,Specifying a Debugging Target}),
10859including the names of the executable and core dump files currently in
10860use by @value{GDBN}, and the files from which symbols were loaded. The
10861command @code{help target} lists all possible targets rather than
10862current ones.
10863
fe95c787
MS
10864@kindex maint info sections
10865@item maint info sections
10866Another command that can give you extra information about program sections
10867is @code{maint info sections}. In addition to the section information
10868displayed by @code{info files}, this command displays the flags and file
10869offset of each section in the executable and core dump files. In addition,
10870@code{maint info sections} provides the following command options (which
10871may be arbitrarily combined):
10872
10873@table @code
10874@item ALLOBJ
10875Display sections for all loaded object files, including shared libraries.
10876@item @var{sections}
6600abed 10877Display info only for named @var{sections}.
fe95c787
MS
10878@item @var{section-flags}
10879Display info only for sections for which @var{section-flags} are true.
10880The section flags that @value{GDBN} currently knows about are:
10881@table @code
10882@item ALLOC
10883Section will have space allocated in the process when loaded.
10884Set for all sections except those containing debug information.
10885@item LOAD
10886Section will be loaded from the file into the child process memory.
10887Set for pre-initialized code and data, clear for @code{.bss} sections.
10888@item RELOC
10889Section needs to be relocated before loading.
10890@item READONLY
10891Section cannot be modified by the child process.
10892@item CODE
10893Section contains executable code only.
6600abed 10894@item DATA
fe95c787
MS
10895Section contains data only (no executable code).
10896@item ROM
10897Section will reside in ROM.
10898@item CONSTRUCTOR
10899Section contains data for constructor/destructor lists.
10900@item HAS_CONTENTS
10901Section is not empty.
10902@item NEVER_LOAD
10903An instruction to the linker to not output the section.
10904@item COFF_SHARED_LIBRARY
10905A notification to the linker that the section contains
10906COFF shared library information.
10907@item IS_COMMON
10908Section contains common symbols.
10909@end table
10910@end table
6763aef9 10911@kindex set trust-readonly-sections
9c16f35a 10912@cindex read-only sections
6763aef9
MS
10913@item set trust-readonly-sections on
10914Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10915really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10916In that case, @value{GDBN} can fetch values from these sections
10917out of the object file, rather than from the target program.
10918For some targets (notably embedded ones), this can be a significant
10919enhancement to debugging performance.
10920
10921The default is off.
10922
10923@item set trust-readonly-sections off
15110bc3 10924Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10925the contents of the section might change while the program is running,
10926and must therefore be fetched from the target when needed.
9c16f35a
EZ
10927
10928@item show trust-readonly-sections
10929Show the current setting of trusting readonly sections.
c906108c
SS
10930@end table
10931
10932All file-specifying commands allow both absolute and relative file names
10933as arguments. @value{GDBN} always converts the file name to an absolute file
10934name and remembers it that way.
10935
c906108c 10936@cindex shared libraries
9c16f35a
EZ
10937@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10938and IBM RS/6000 AIX shared libraries.
53a5351d 10939
c906108c
SS
10940@value{GDBN} automatically loads symbol definitions from shared libraries
10941when you use the @code{run} command, or when you examine a core file.
10942(Before you issue the @code{run} command, @value{GDBN} does not understand
10943references to a function in a shared library, however---unless you are
10944debugging a core file).
53a5351d
JM
10945
10946On HP-UX, if the program loads a library explicitly, @value{GDBN}
10947automatically loads the symbols at the time of the @code{shl_load} call.
10948
c906108c
SS
10949@c FIXME: some @value{GDBN} release may permit some refs to undef
10950@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10951@c FIXME...lib; check this from time to time when updating manual
10952
b7209cb4
FF
10953There are times, however, when you may wish to not automatically load
10954symbol definitions from shared libraries, such as when they are
10955particularly large or there are many of them.
10956
10957To control the automatic loading of shared library symbols, use the
10958commands:
10959
10960@table @code
10961@kindex set auto-solib-add
10962@item set auto-solib-add @var{mode}
10963If @var{mode} is @code{on}, symbols from all shared object libraries
10964will be loaded automatically when the inferior begins execution, you
10965attach to an independently started inferior, or when the dynamic linker
10966informs @value{GDBN} that a new library has been loaded. If @var{mode}
10967is @code{off}, symbols must be loaded manually, using the
10968@code{sharedlibrary} command. The default value is @code{on}.
10969
dcaf7c2c
EZ
10970@cindex memory used for symbol tables
10971If your program uses lots of shared libraries with debug info that
10972takes large amounts of memory, you can decrease the @value{GDBN}
10973memory footprint by preventing it from automatically loading the
10974symbols from shared libraries. To that end, type @kbd{set
10975auto-solib-add off} before running the inferior, then load each
10976library whose debug symbols you do need with @kbd{sharedlibrary
10977@var{regexp}}, where @var{regexp} is a regular expresion that matches
10978the libraries whose symbols you want to be loaded.
10979
b7209cb4
FF
10980@kindex show auto-solib-add
10981@item show auto-solib-add
10982Display the current autoloading mode.
10983@end table
10984
c45da7e6 10985@cindex load shared library
b7209cb4
FF
10986To explicitly load shared library symbols, use the @code{sharedlibrary}
10987command:
10988
c906108c
SS
10989@table @code
10990@kindex info sharedlibrary
10991@kindex info share
10992@item info share
10993@itemx info sharedlibrary
10994Print the names of the shared libraries which are currently loaded.
10995
10996@kindex sharedlibrary
10997@kindex share
10998@item sharedlibrary @var{regex}
10999@itemx share @var{regex}
c906108c
SS
11000Load shared object library symbols for files matching a
11001Unix regular expression.
11002As with files loaded automatically, it only loads shared libraries
11003required by your program for a core file or after typing @code{run}. If
11004@var{regex} is omitted all shared libraries required by your program are
11005loaded.
c45da7e6
EZ
11006
11007@item nosharedlibrary
11008@kindex nosharedlibrary
11009@cindex unload symbols from shared libraries
11010Unload all shared object library symbols. This discards all symbols
11011that have been loaded from all shared libraries. Symbols from shared
11012libraries that were loaded by explicit user requests are not
11013discarded.
c906108c
SS
11014@end table
11015
721c2651
EZ
11016Sometimes you may wish that @value{GDBN} stops and gives you control
11017when any of shared library events happen. Use the @code{set
11018stop-on-solib-events} command for this:
11019
11020@table @code
11021@item set stop-on-solib-events
11022@kindex set stop-on-solib-events
11023This command controls whether @value{GDBN} should give you control
11024when the dynamic linker notifies it about some shared library event.
11025The most common event of interest is loading or unloading of a new
11026shared library.
11027
11028@item show stop-on-solib-events
11029@kindex show stop-on-solib-events
11030Show whether @value{GDBN} stops and gives you control when shared
11031library events happen.
11032@end table
11033
f5ebfba0
DJ
11034Shared libraries are also supported in many cross or remote debugging
11035configurations. A copy of the target's libraries need to be present on the
11036host system; they need to be the same as the target libraries, although the
11037copies on the target can be stripped as long as the copies on the host are
11038not.
11039
11040You need to tell @value{GDBN} where the target libraries are, so that it can
11041load the correct copies---otherwise, it may try to load the host's libraries.
11042@value{GDBN} has two variables to specify the search directories for target
11043libraries.
11044
11045@table @code
11046@kindex set solib-absolute-prefix
11047@item set solib-absolute-prefix @var{path}
11048If this variable is set, @var{path} will be used as a prefix for any
11049absolute shared library paths; many runtime loaders store the absolute
11050paths to the shared library in the target program's memory. If you use
11051@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11052out in the same way that they are on the target, with e.g.@: a
11053@file{/usr/lib} hierarchy under @var{path}.
11054
11055You can set the default value of @samp{solib-absolute-prefix} by using the
11056configure-time @samp{--with-sysroot} option.
11057
11058@kindex show solib-absolute-prefix
11059@item show solib-absolute-prefix
11060Display the current shared library prefix.
11061
11062@kindex set solib-search-path
11063@item set solib-search-path @var{path}
11064If this variable is set, @var{path} is a colon-separated list of directories
11065to search for shared libraries. @samp{solib-search-path} is used after
11066@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11067the library is relative instead of absolute. If you want to use
11068@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11069set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11070@value{GDBN} from finding your host's libraries.
11071
11072@kindex show solib-search-path
11073@item show solib-search-path
11074Display the current shared library search path.
11075@end table
11076
5b5d99cf
JB
11077
11078@node Separate Debug Files
11079@section Debugging Information in Separate Files
11080@cindex separate debugging information files
11081@cindex debugging information in separate files
11082@cindex @file{.debug} subdirectories
11083@cindex debugging information directory, global
11084@cindex global debugging information directory
11085
11086@value{GDBN} allows you to put a program's debugging information in a
11087file separate from the executable itself, in a way that allows
11088@value{GDBN} to find and load the debugging information automatically.
11089Since debugging information can be very large --- sometimes larger
11090than the executable code itself --- some systems distribute debugging
11091information for their executables in separate files, which users can
11092install only when they need to debug a problem.
11093
11094If an executable's debugging information has been extracted to a
11095separate file, the executable should contain a @dfn{debug link} giving
11096the name of the debugging information file (with no directory
11097components), and a checksum of its contents. (The exact form of a
11098debug link is described below.) If the full name of the directory
11099containing the executable is @var{execdir}, and the executable has a
11100debug link that specifies the name @var{debugfile}, then @value{GDBN}
11101will automatically search for the debugging information file in three
11102places:
11103
11104@itemize @bullet
11105@item
11106the directory containing the executable file (that is, it will look
11107for a file named @file{@var{execdir}/@var{debugfile}},
11108@item
11109a subdirectory of that directory named @file{.debug} (that is, the
11110file @file{@var{execdir}/.debug/@var{debugfile}}, and
11111@item
11112a subdirectory of the global debug file directory that includes the
11113executable's full path, and the name from the link (that is, the file
11114@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11115@var{globaldebugdir} is the global debug file directory, and
11116@var{execdir} has been turned into a relative path).
11117@end itemize
11118@noindent
11119@value{GDBN} checks under each of these names for a debugging
11120information file whose checksum matches that given in the link, and
11121reads the debugging information from the first one it finds.
11122
11123So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11124which has a link containing the name @file{ls.debug}, and the global
11125debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11126for debug information in @file{/usr/bin/ls.debug},
11127@file{/usr/bin/.debug/ls.debug}, and
11128@file{/usr/lib/debug/usr/bin/ls.debug}.
11129
11130You can set the global debugging info directory's name, and view the
11131name @value{GDBN} is currently using.
11132
11133@table @code
11134
11135@kindex set debug-file-directory
11136@item set debug-file-directory @var{directory}
11137Set the directory which @value{GDBN} searches for separate debugging
11138information files to @var{directory}.
11139
11140@kindex show debug-file-directory
11141@item show debug-file-directory
11142Show the directory @value{GDBN} searches for separate debugging
11143information files.
11144
11145@end table
11146
11147@cindex @code{.gnu_debuglink} sections
11148@cindex debug links
11149A debug link is a special section of the executable file named
11150@code{.gnu_debuglink}. The section must contain:
11151
11152@itemize
11153@item
11154A filename, with any leading directory components removed, followed by
11155a zero byte,
11156@item
11157zero to three bytes of padding, as needed to reach the next four-byte
11158boundary within the section, and
11159@item
11160a four-byte CRC checksum, stored in the same endianness used for the
11161executable file itself. The checksum is computed on the debugging
11162information file's full contents by the function given below, passing
11163zero as the @var{crc} argument.
11164@end itemize
11165
11166Any executable file format can carry a debug link, as long as it can
11167contain a section named @code{.gnu_debuglink} with the contents
11168described above.
11169
11170The debugging information file itself should be an ordinary
11171executable, containing a full set of linker symbols, sections, and
11172debugging information. The sections of the debugging information file
11173should have the same names, addresses and sizes as the original file,
11174but they need not contain any data --- much like a @code{.bss} section
11175in an ordinary executable.
11176
11177As of December 2002, there is no standard GNU utility to produce
11178separated executable / debugging information file pairs. Ulrich
11179Drepper's @file{elfutils} package, starting with version 0.53,
11180contains a version of the @code{strip} command such that the command
11181@kbd{strip foo -f foo.debug} removes the debugging information from
11182the executable file @file{foo}, places it in the file
11183@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11184
11185Since there are many different ways to compute CRC's (different
11186polynomials, reversals, byte ordering, etc.), the simplest way to
11187describe the CRC used in @code{.gnu_debuglink} sections is to give the
11188complete code for a function that computes it:
11189
4644b6e3 11190@kindex gnu_debuglink_crc32
5b5d99cf
JB
11191@smallexample
11192unsigned long
11193gnu_debuglink_crc32 (unsigned long crc,
11194 unsigned char *buf, size_t len)
11195@{
11196 static const unsigned long crc32_table[256] =
11197 @{
11198 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11199 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11200 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11201 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11202 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11203 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11204 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11205 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11206 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11207 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11208 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11209 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11210 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11211 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11212 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11213 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11214 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11215 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11216 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11217 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11218 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11219 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11220 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11221 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11222 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11223 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11224 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11225 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11226 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11227 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11228 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11229 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11230 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11231 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11232 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11233 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11234 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11235 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11236 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11237 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11238 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11239 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11240 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11241 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11242 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11243 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11244 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11245 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11246 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11247 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11248 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11249 0x2d02ef8d
11250 @};
11251 unsigned char *end;
11252
11253 crc = ~crc & 0xffffffff;
11254 for (end = buf + len; buf < end; ++buf)
11255 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11256 return ~crc & 0xffffffff;
5b5d99cf
JB
11257@}
11258@end smallexample
11259
11260
6d2ebf8b 11261@node Symbol Errors
c906108c
SS
11262@section Errors reading symbol files
11263
11264While reading a symbol file, @value{GDBN} occasionally encounters problems,
11265such as symbol types it does not recognize, or known bugs in compiler
11266output. By default, @value{GDBN} does not notify you of such problems, since
11267they are relatively common and primarily of interest to people
11268debugging compilers. If you are interested in seeing information
11269about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11270only one message about each such type of problem, no matter how many
11271times the problem occurs; or you can ask @value{GDBN} to print more messages,
11272to see how many times the problems occur, with the @code{set
11273complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11274messages}).
11275
11276The messages currently printed, and their meanings, include:
11277
11278@table @code
11279@item inner block not inside outer block in @var{symbol}
11280
11281The symbol information shows where symbol scopes begin and end
11282(such as at the start of a function or a block of statements). This
11283error indicates that an inner scope block is not fully contained
11284in its outer scope blocks.
11285
11286@value{GDBN} circumvents the problem by treating the inner block as if it had
11287the same scope as the outer block. In the error message, @var{symbol}
11288may be shown as ``@code{(don't know)}'' if the outer block is not a
11289function.
11290
11291@item block at @var{address} out of order
11292
11293The symbol information for symbol scope blocks should occur in
11294order of increasing addresses. This error indicates that it does not
11295do so.
11296
11297@value{GDBN} does not circumvent this problem, and has trouble
11298locating symbols in the source file whose symbols it is reading. (You
11299can often determine what source file is affected by specifying
11300@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11301messages}.)
11302
11303@item bad block start address patched
11304
11305The symbol information for a symbol scope block has a start address
11306smaller than the address of the preceding source line. This is known
11307to occur in the SunOS 4.1.1 (and earlier) C compiler.
11308
11309@value{GDBN} circumvents the problem by treating the symbol scope block as
11310starting on the previous source line.
11311
11312@item bad string table offset in symbol @var{n}
11313
11314@cindex foo
11315Symbol number @var{n} contains a pointer into the string table which is
11316larger than the size of the string table.
11317
11318@value{GDBN} circumvents the problem by considering the symbol to have the
11319name @code{foo}, which may cause other problems if many symbols end up
11320with this name.
11321
11322@item unknown symbol type @code{0x@var{nn}}
11323
7a292a7a
SS
11324The symbol information contains new data types that @value{GDBN} does
11325not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11326uncomprehended information, in hexadecimal.
c906108c 11327
7a292a7a
SS
11328@value{GDBN} circumvents the error by ignoring this symbol information.
11329This usually allows you to debug your program, though certain symbols
c906108c 11330are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11331debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11332on @code{complain}, then go up to the function @code{read_dbx_symtab}
11333and examine @code{*bufp} to see the symbol.
c906108c
SS
11334
11335@item stub type has NULL name
c906108c 11336
7a292a7a 11337@value{GDBN} could not find the full definition for a struct or class.
c906108c 11338
7a292a7a 11339@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11340The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11341information that recent versions of the compiler should have output for
11342it.
c906108c
SS
11343
11344@item info mismatch between compiler and debugger
11345
11346@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11347
c906108c
SS
11348@end table
11349
6d2ebf8b 11350@node Targets
c906108c 11351@chapter Specifying a Debugging Target
7a292a7a 11352
c906108c 11353@cindex debugging target
c906108c 11354A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11355
11356Often, @value{GDBN} runs in the same host environment as your program;
11357in that case, the debugging target is specified as a side effect when
11358you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11359flexibility---for example, running @value{GDBN} on a physically separate
11360host, or controlling a standalone system over a serial port or a
53a5351d
JM
11361realtime system over a TCP/IP connection---you can use the @code{target}
11362command to specify one of the target types configured for @value{GDBN}
11363(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11364
a8f24a35
EZ
11365@cindex target architecture
11366It is possible to build @value{GDBN} for several different @dfn{target
11367architectures}. When @value{GDBN} is built like that, you can choose
11368one of the available architectures with the @kbd{set architecture}
11369command.
11370
11371@table @code
11372@kindex set architecture
11373@kindex show architecture
11374@item set architecture @var{arch}
11375This command sets the current target architecture to @var{arch}. The
11376value of @var{arch} can be @code{"auto"}, in addition to one of the
11377supported architectures.
11378
11379@item show architecture
11380Show the current target architecture.
9c16f35a
EZ
11381
11382@item set processor
11383@itemx processor
11384@kindex set processor
11385@kindex show processor
11386These are alias commands for, respectively, @code{set architecture}
11387and @code{show architecture}.
a8f24a35
EZ
11388@end table
11389
c906108c
SS
11390@menu
11391* Active Targets:: Active targets
11392* Target Commands:: Commands for managing targets
c906108c
SS
11393* Byte Order:: Choosing target byte order
11394* Remote:: Remote debugging
96baa820 11395* KOD:: Kernel Object Display
c906108c
SS
11396
11397@end menu
11398
6d2ebf8b 11399@node Active Targets
c906108c 11400@section Active targets
7a292a7a 11401
c906108c
SS
11402@cindex stacking targets
11403@cindex active targets
11404@cindex multiple targets
11405
c906108c 11406There are three classes of targets: processes, core files, and
7a292a7a
SS
11407executable files. @value{GDBN} can work concurrently on up to three
11408active targets, one in each class. This allows you to (for example)
11409start a process and inspect its activity without abandoning your work on
11410a core file.
c906108c
SS
11411
11412For example, if you execute @samp{gdb a.out}, then the executable file
11413@code{a.out} is the only active target. If you designate a core file as
11414well---presumably from a prior run that crashed and coredumped---then
11415@value{GDBN} has two active targets and uses them in tandem, looking
11416first in the corefile target, then in the executable file, to satisfy
11417requests for memory addresses. (Typically, these two classes of target
11418are complementary, since core files contain only a program's
11419read-write memory---variables and so on---plus machine status, while
11420executable files contain only the program text and initialized data.)
c906108c
SS
11421
11422When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11423target as well. When a process target is active, all @value{GDBN}
11424commands requesting memory addresses refer to that target; addresses in
11425an active core file or executable file target are obscured while the
11426process target is active.
c906108c 11427
7a292a7a
SS
11428Use the @code{core-file} and @code{exec-file} commands to select a new
11429core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11430files}). To specify as a target a process that is already running, use
7a292a7a
SS
11431the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11432process}).
c906108c 11433
6d2ebf8b 11434@node Target Commands
c906108c
SS
11435@section Commands for managing targets
11436
11437@table @code
11438@item target @var{type} @var{parameters}
7a292a7a
SS
11439Connects the @value{GDBN} host environment to a target machine or
11440process. A target is typically a protocol for talking to debugging
11441facilities. You use the argument @var{type} to specify the type or
11442protocol of the target machine.
c906108c
SS
11443
11444Further @var{parameters} are interpreted by the target protocol, but
11445typically include things like device names or host names to connect
11446with, process numbers, and baud rates.
c906108c
SS
11447
11448The @code{target} command does not repeat if you press @key{RET} again
11449after executing the command.
11450
11451@kindex help target
11452@item help target
11453Displays the names of all targets available. To display targets
11454currently selected, use either @code{info target} or @code{info files}
11455(@pxref{Files, ,Commands to specify files}).
11456
11457@item help target @var{name}
11458Describe a particular target, including any parameters necessary to
11459select it.
11460
11461@kindex set gnutarget
11462@item set gnutarget @var{args}
5d161b24 11463@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11464knows whether it is reading an @dfn{executable},
5d161b24
DB
11465a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11466with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11467with @code{gnutarget} the @code{target} refers to a program, not a machine.
11468
d4f3574e 11469@quotation
c906108c
SS
11470@emph{Warning:} To specify a file format with @code{set gnutarget},
11471you must know the actual BFD name.
d4f3574e 11472@end quotation
c906108c 11473
d4f3574e
SS
11474@noindent
11475@xref{Files, , Commands to specify files}.
c906108c 11476
5d161b24 11477@kindex show gnutarget
c906108c
SS
11478@item show gnutarget
11479Use the @code{show gnutarget} command to display what file format
11480@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11481@value{GDBN} will determine the file format for each file automatically,
11482and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11483@end table
11484
4644b6e3 11485@cindex common targets
c906108c
SS
11486Here are some common targets (available, or not, depending on the GDB
11487configuration):
c906108c
SS
11488
11489@table @code
4644b6e3 11490@kindex target
c906108c 11491@item target exec @var{program}
4644b6e3 11492@cindex executable file target
c906108c
SS
11493An executable file. @samp{target exec @var{program}} is the same as
11494@samp{exec-file @var{program}}.
11495
c906108c 11496@item target core @var{filename}
4644b6e3 11497@cindex core dump file target
c906108c
SS
11498A core dump file. @samp{target core @var{filename}} is the same as
11499@samp{core-file @var{filename}}.
c906108c 11500
c906108c 11501@item target remote @var{dev}
4644b6e3 11502@cindex remote target
c906108c
SS
11503Remote serial target in GDB-specific protocol. The argument @var{dev}
11504specifies what serial device to use for the connection (e.g.
11505@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11506supports the @code{load} command. This is only useful if you have
c906108c
SS
11507some other way of getting the stub to the target system, and you can put
11508it somewhere in memory where it won't get clobbered by the download.
11509
c906108c 11510@item target sim
4644b6e3 11511@cindex built-in simulator target
2df3850c 11512Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11513In general,
474c8240 11514@smallexample
104c1213
JM
11515 target sim
11516 load
11517 run
474c8240 11518@end smallexample
d4f3574e 11519@noindent
104c1213 11520works; however, you cannot assume that a specific memory map, device
d4f3574e 11521drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11522provide these. For info about any processor-specific simulator details,
11523see the appropriate section in @ref{Embedded Processors, ,Embedded
11524Processors}.
11525
c906108c
SS
11526@end table
11527
104c1213 11528Some configurations may include these targets as well:
c906108c
SS
11529
11530@table @code
11531
c906108c 11532@item target nrom @var{dev}
4644b6e3 11533@cindex NetROM ROM emulator target
c906108c
SS
11534NetROM ROM emulator. This target only supports downloading.
11535
c906108c
SS
11536@end table
11537
5d161b24 11538Different targets are available on different configurations of @value{GDBN};
c906108c 11539your configuration may have more or fewer targets.
c906108c 11540
721c2651
EZ
11541Many remote targets require you to download the executable's code once
11542you've successfully established a connection. You may wish to control
11543various aspects of this process, such as the size of the data chunks
11544used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11545
11546@table @code
11547@kindex set download-write-size
11548@item set download-write-size @var{size}
11549Set the write size used when downloading a program. Only used when
11550downloading a program onto a remote target. Specify zero or a
11551negative value to disable blocked writes. The actual size of each
11552transfer is also limited by the size of the target packet and the
11553memory cache.
11554
11555@kindex show download-write-size
11556@item show download-write-size
721c2651 11557@kindex show download-write-size
a8f24a35 11558Show the current value of the write size.
721c2651
EZ
11559
11560@item set hash
11561@kindex set hash@r{, for remote monitors}
11562@cindex hash mark while downloading
11563This command controls whether a hash mark @samp{#} is displayed while
11564downloading a file to the remote monitor. If on, a hash mark is
11565displayed after each S-record is successfully downloaded to the
11566monitor.
11567
11568@item show hash
11569@kindex show hash@r{, for remote monitors}
11570Show the current status of displaying the hash mark.
11571
11572@item set debug monitor
11573@kindex set debug monitor
11574@cindex display remote monitor communications
11575Enable or disable display of communications messages between
11576@value{GDBN} and the remote monitor.
11577
11578@item show debug monitor
11579@kindex show debug monitor
11580Show the current status of displaying communications between
11581@value{GDBN} and the remote monitor.
a8f24a35 11582@end table
c906108c
SS
11583
11584@table @code
11585
11586@kindex load @var{filename}
11587@item load @var{filename}
c906108c
SS
11588Depending on what remote debugging facilities are configured into
11589@value{GDBN}, the @code{load} command may be available. Where it exists, it
11590is meant to make @var{filename} (an executable) available for debugging
11591on the remote system---by downloading, or dynamic linking, for example.
11592@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11593the @code{add-symbol-file} command.
11594
11595If your @value{GDBN} does not have a @code{load} command, attempting to
11596execute it gets the error message ``@code{You can't do that when your
11597target is @dots{}}''
c906108c
SS
11598
11599The file is loaded at whatever address is specified in the executable.
11600For some object file formats, you can specify the load address when you
11601link the program; for other formats, like a.out, the object file format
11602specifies a fixed address.
11603@c FIXME! This would be a good place for an xref to the GNU linker doc.
11604
c906108c
SS
11605@code{load} does not repeat if you press @key{RET} again after using it.
11606@end table
11607
6d2ebf8b 11608@node Byte Order
c906108c 11609@section Choosing target byte order
7a292a7a 11610
c906108c
SS
11611@cindex choosing target byte order
11612@cindex target byte order
c906108c 11613
172c2a43 11614Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11615offer the ability to run either big-endian or little-endian byte
11616orders. Usually the executable or symbol will include a bit to
11617designate the endian-ness, and you will not need to worry about
11618which to use. However, you may still find it useful to adjust
d4f3574e 11619@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11620
11621@table @code
4644b6e3 11622@kindex set endian
c906108c
SS
11623@item set endian big
11624Instruct @value{GDBN} to assume the target is big-endian.
11625
c906108c
SS
11626@item set endian little
11627Instruct @value{GDBN} to assume the target is little-endian.
11628
c906108c
SS
11629@item set endian auto
11630Instruct @value{GDBN} to use the byte order associated with the
11631executable.
11632
11633@item show endian
11634Display @value{GDBN}'s current idea of the target byte order.
11635
11636@end table
11637
11638Note that these commands merely adjust interpretation of symbolic
11639data on the host, and that they have absolutely no effect on the
11640target system.
11641
6d2ebf8b 11642@node Remote
c906108c
SS
11643@section Remote debugging
11644@cindex remote debugging
11645
11646If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11647@value{GDBN} in the usual way, it is often useful to use remote debugging.
11648For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11649or on a small system which does not have a general purpose operating system
11650powerful enough to run a full-featured debugger.
11651
11652Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11653to make this work with particular debugging targets. In addition,
5d161b24 11654@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11655but not specific to any particular target system) which you can use if you
11656write the remote stubs---the code that runs on the remote system to
11657communicate with @value{GDBN}.
11658
11659Other remote targets may be available in your
11660configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11661
c45da7e6
EZ
11662Once you've connected to the remote target, @value{GDBN} allows you to
11663send arbitrary commands to the remote monitor:
11664
11665@table @code
11666@item remote @var{command}
11667@kindex remote@r{, a command}
11668@cindex send command to remote monitor
11669Send an arbitrary @var{command} string to the remote monitor.
11670@end table
11671
11672
6f05cf9f
AC
11673@node KOD
11674@section Kernel Object Display
6f05cf9f 11675@cindex kernel object display
6f05cf9f
AC
11676@cindex KOD
11677
11678Some targets support kernel object display. Using this facility,
11679@value{GDBN} communicates specially with the underlying operating system
11680and can display information about operating system-level objects such as
11681mutexes and other synchronization objects. Exactly which objects can be
11682displayed is determined on a per-OS basis.
11683
3bbe9696 11684@kindex set os
6f05cf9f
AC
11685Use the @code{set os} command to set the operating system. This tells
11686@value{GDBN} which kernel object display module to initialize:
11687
474c8240 11688@smallexample
6f05cf9f 11689(@value{GDBP}) set os cisco
474c8240 11690@end smallexample
6f05cf9f 11691
3bbe9696
EZ
11692@kindex show os
11693The associated command @code{show os} displays the operating system
11694set with the @code{set os} command; if no operating system has been
11695set, @code{show os} will display an empty string @samp{""}.
11696
6f05cf9f
AC
11697If @code{set os} succeeds, @value{GDBN} will display some information
11698about the operating system, and will create a new @code{info} command
11699which can be used to query the target. The @code{info} command is named
11700after the operating system:
c906108c 11701
3bbe9696 11702@kindex info cisco
474c8240 11703@smallexample
6f05cf9f
AC
11704(@value{GDBP}) info cisco
11705List of Cisco Kernel Objects
11706Object Description
11707any Any and all objects
474c8240 11708@end smallexample
6f05cf9f
AC
11709
11710Further subcommands can be used to query about particular objects known
11711by the kernel.
11712
3bbe9696
EZ
11713There is currently no way to determine whether a given operating
11714system is supported other than to try setting it with @kbd{set os
11715@var{name}}, where @var{name} is the name of the operating system you
11716want to try.
6f05cf9f
AC
11717
11718
11719@node Remote Debugging
11720@chapter Debugging remote programs
11721
6b2f586d 11722@menu
07f31aa6 11723* Connecting:: Connecting to a remote target
6b2f586d
AC
11724* Server:: Using the gdbserver program
11725* NetWare:: Using the gdbserve.nlm program
501eef12 11726* Remote configuration:: Remote configuration
6b2f586d 11727* remote stub:: Implementing a remote stub
6b2f586d
AC
11728@end menu
11729
07f31aa6
DJ
11730@node Connecting
11731@section Connecting to a remote target
11732
11733On the @value{GDBN} host machine, you will need an unstripped copy of
11734your program, since @value{GDBN} needs symobl and debugging information.
11735Start up @value{GDBN} as usual, using the name of the local copy of your
11736program as the first argument.
11737
11738@cindex serial line, @code{target remote}
11739If you're using a serial line, you may want to give @value{GDBN} the
11740@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11741(@pxref{Remote configuration, set remotebaud}) before the
11742@code{target} command.
07f31aa6
DJ
11743
11744After that, use @code{target remote} to establish communications with
11745the target machine. Its argument specifies how to communicate---either
11746via a devicename attached to a direct serial line, or a TCP or UDP port
11747(possibly to a terminal server which in turn has a serial line to the
11748target). For example, to use a serial line connected to the device
11749named @file{/dev/ttyb}:
11750
11751@smallexample
11752target remote /dev/ttyb
11753@end smallexample
11754
11755@cindex TCP port, @code{target remote}
11756To use a TCP connection, use an argument of the form
11757@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11758For example, to connect to port 2828 on a
11759terminal server named @code{manyfarms}:
11760
11761@smallexample
11762target remote manyfarms:2828
11763@end smallexample
11764
11765If your remote target is actually running on the same machine as
11766your debugger session (e.g.@: a simulator of your target running on
11767the same host), you can omit the hostname. For example, to connect
11768to port 1234 on your local machine:
11769
11770@smallexample
11771target remote :1234
11772@end smallexample
11773@noindent
11774
11775Note that the colon is still required here.
11776
11777@cindex UDP port, @code{target remote}
11778To use a UDP connection, use an argument of the form
11779@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11780on a terminal server named @code{manyfarms}:
11781
11782@smallexample
11783target remote udp:manyfarms:2828
11784@end smallexample
11785
11786When using a UDP connection for remote debugging, you should keep in mind
11787that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11788busy or unreliable networks, which will cause havoc with your debugging
11789session.
11790
11791Now you can use all the usual commands to examine and change data and to
11792step and continue the remote program.
11793
11794@cindex interrupting remote programs
11795@cindex remote programs, interrupting
11796Whenever @value{GDBN} is waiting for the remote program, if you type the
11797interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11798program. This may or may not succeed, depending in part on the hardware
11799and the serial drivers the remote system uses. If you type the
11800interrupt character once again, @value{GDBN} displays this prompt:
11801
11802@smallexample
11803Interrupted while waiting for the program.
11804Give up (and stop debugging it)? (y or n)
11805@end smallexample
11806
11807If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11808(If you decide you want to try again later, you can use @samp{target
11809remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11810goes back to waiting.
11811
11812@table @code
11813@kindex detach (remote)
11814@item detach
11815When you have finished debugging the remote program, you can use the
11816@code{detach} command to release it from @value{GDBN} control.
11817Detaching from the target normally resumes its execution, but the results
11818will depend on your particular remote stub. After the @code{detach}
11819command, @value{GDBN} is free to connect to another target.
11820
11821@kindex disconnect
11822@item disconnect
11823The @code{disconnect} command behaves like @code{detach}, except that
11824the target is generally not resumed. It will wait for @value{GDBN}
11825(this instance or another one) to connect and continue debugging. After
11826the @code{disconnect} command, @value{GDBN} is again free to connect to
11827another target.
09d4efe1
EZ
11828
11829@cindex send command to remote monitor
11830@kindex monitor
11831@item monitor @var{cmd}
11832This command allows you to send commands directly to the remote
11833monitor.
07f31aa6
DJ
11834@end table
11835
6f05cf9f
AC
11836@node Server
11837@section Using the @code{gdbserver} program
11838
11839@kindex gdbserver
11840@cindex remote connection without stubs
11841@code{gdbserver} is a control program for Unix-like systems, which
11842allows you to connect your program with a remote @value{GDBN} via
11843@code{target remote}---but without linking in the usual debugging stub.
11844
11845@code{gdbserver} is not a complete replacement for the debugging stubs,
11846because it requires essentially the same operating-system facilities
11847that @value{GDBN} itself does. In fact, a system that can run
11848@code{gdbserver} to connect to a remote @value{GDBN} could also run
11849@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11850because it is a much smaller program than @value{GDBN} itself. It is
11851also easier to port than all of @value{GDBN}, so you may be able to get
11852started more quickly on a new system by using @code{gdbserver}.
11853Finally, if you develop code for real-time systems, you may find that
11854the tradeoffs involved in real-time operation make it more convenient to
11855do as much development work as possible on another system, for example
11856by cross-compiling. You can use @code{gdbserver} to make a similar
11857choice for debugging.
11858
11859@value{GDBN} and @code{gdbserver} communicate via either a serial line
11860or a TCP connection, using the standard @value{GDBN} remote serial
11861protocol.
11862
11863@table @emph
11864@item On the target machine,
11865you need to have a copy of the program you want to debug.
11866@code{gdbserver} does not need your program's symbol table, so you can
11867strip the program if necessary to save space. @value{GDBN} on the host
11868system does all the symbol handling.
11869
11870To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11871the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11872syntax is:
11873
11874@smallexample
11875target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11876@end smallexample
11877
11878@var{comm} is either a device name (to use a serial line) or a TCP
11879hostname and portnumber. For example, to debug Emacs with the argument
11880@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11881@file{/dev/com1}:
11882
11883@smallexample
11884target> gdbserver /dev/com1 emacs foo.txt
11885@end smallexample
11886
11887@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11888with it.
11889
11890To use a TCP connection instead of a serial line:
11891
11892@smallexample
11893target> gdbserver host:2345 emacs foo.txt
11894@end smallexample
11895
11896The only difference from the previous example is the first argument,
11897specifying that you are communicating with the host @value{GDBN} via
11898TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11899expect a TCP connection from machine @samp{host} to local TCP port 2345.
11900(Currently, the @samp{host} part is ignored.) You can choose any number
11901you want for the port number as long as it does not conflict with any
11902TCP ports already in use on the target system (for example, @code{23} is
11903reserved for @code{telnet}).@footnote{If you choose a port number that
11904conflicts with another service, @code{gdbserver} prints an error message
11905and exits.} You must use the same port number with the host @value{GDBN}
11906@code{target remote} command.
11907
56460a61
DJ
11908On some targets, @code{gdbserver} can also attach to running programs.
11909This is accomplished via the @code{--attach} argument. The syntax is:
11910
11911@smallexample
11912target> gdbserver @var{comm} --attach @var{pid}
11913@end smallexample
11914
11915@var{pid} is the process ID of a currently running process. It isn't necessary
11916to point @code{gdbserver} at a binary for the running process.
11917
b1fe9455
DJ
11918@pindex pidof
11919@cindex attach to a program by name
11920You can debug processes by name instead of process ID if your target has the
11921@code{pidof} utility:
11922
11923@smallexample
11924target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11925@end smallexample
11926
11927In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11928has multiple threads, most versions of @code{pidof} support the
11929@code{-s} option to only return the first process ID.
11930
07f31aa6
DJ
11931@item On the host machine,
11932connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11933For TCP connections, you must start up @code{gdbserver} prior to using
11934the @code{target remote} command. Otherwise you may get an error whose
11935text depends on the host system, but which usually looks something like
07f31aa6
DJ
11936@samp{Connection refused}. You don't need to use the @code{load}
11937command in @value{GDBN} when using gdbserver, since the program is
11938already on the target.
11939
6f05cf9f
AC
11940@end table
11941
11942@node NetWare
11943@section Using the @code{gdbserve.nlm} program
11944
11945@kindex gdbserve.nlm
11946@code{gdbserve.nlm} is a control program for NetWare systems, which
11947allows you to connect your program with a remote @value{GDBN} via
11948@code{target remote}.
11949
11950@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11951using the standard @value{GDBN} remote serial protocol.
11952
11953@table @emph
11954@item On the target machine,
11955you need to have a copy of the program you want to debug.
11956@code{gdbserve.nlm} does not need your program's symbol table, so you
11957can strip the program if necessary to save space. @value{GDBN} on the
11958host system does all the symbol handling.
11959
11960To use the server, you must tell it how to communicate with
11961@value{GDBN}; the name of your program; and the arguments for your
11962program. The syntax is:
11963
11964@smallexample
11965load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11966 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
11967@end smallexample
11968
11969@var{board} and @var{port} specify the serial line; @var{baud} specifies
11970the baud rate used by the connection. @var{port} and @var{node} default
11971to 0, @var{baud} defaults to 9600@dmn{bps}.
11972
11973For example, to debug Emacs with the argument @samp{foo.txt}and
11974communicate with @value{GDBN} over serial port number 2 or board 1
11975using a 19200@dmn{bps} connection:
11976
11977@smallexample
11978load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
11979@end smallexample
11980
07f31aa6
DJ
11981@item
11982On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
11983Connecting to a remote target}).
6f05cf9f 11984
6f05cf9f
AC
11985@end table
11986
501eef12
AC
11987@node Remote configuration
11988@section Remote configuration
11989
9c16f35a
EZ
11990@kindex set remote
11991@kindex show remote
11992This section documents the configuration options available when
11993debugging remote programs. For the options related to the File I/O
11994extensions of the remote protocol, see @ref{The system call,
11995system-call-allowed}.
501eef12
AC
11996
11997@table @code
9c16f35a
EZ
11998@item set remoteaddresssize @var{bits}
11999@cindex adress size for remote targets
12000@cindex bits in remote address
12001Set the maximum size of address in a memory packet to the specified
12002number of bits. @value{GDBN} will mask off the address bits above
12003that number, when it passes addresses to the remote target. The
12004default value is the number of bits in the target's address.
12005
12006@item show remoteaddresssize
12007Show the current value of remote address size in bits.
12008
12009@item set remotebaud @var{n}
12010@cindex baud rate for remote targets
12011Set the baud rate for the remote serial I/O to @var{n} baud. The
12012value is used to set the speed of the serial port used for debugging
12013remote targets.
12014
12015@item show remotebaud
12016Show the current speed of the remote connection.
12017
12018@item set remotebreak
12019@cindex interrupt remote programs
12020@cindex BREAK signal instead of Ctrl-C
12021If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12022when you press the @key{Ctrl-C} key to interrupt the program running
12023on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12024character instead. The default is off, since most remote systems
12025expect to see @samp{Ctrl-C} as the interrupt signal.
12026
12027@item show remotebreak
12028Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12029interrupt the remote program.
12030
12031@item set remotedebug
12032@cindex debug remote protocol
12033@cindex remote protocol debugging
12034@cindex display remote packets
12035Control the debugging of the remote protocol. When enabled, each
12036packet sent to or received from the remote target is displayed. The
12037defaults is off.
12038
12039@item show remotedebug
12040Show the current setting of the remote protocol debugging.
12041
12042@item set remotedevice @var{device}
12043@cindex serial port name
12044Set the name of the serial port through which to communicate to the
12045remote target to @var{device}. This is the device used by
12046@value{GDBN} to open the serial communications line to the remote
12047target. There's no default, so you must set a valid port name for the
12048remote serial communications to work. (Some varieties of the
12049@code{target} command accept the port name as part of their
12050arguments.)
12051
12052@item show remotedevice
12053Show the current name of the serial port.
12054
12055@item set remotelogbase @var{base}
12056Set the base (a.k.a.@: radix) of logging serial protocol
12057communications to @var{base}. Supported values of @var{base} are:
12058@code{ascii}, @code{octal}, and @code{hex}. The default is
12059@code{ascii}.
12060
12061@item show remotelogbase
12062Show the current setting of the radix for logging remote serial
12063protocol.
12064
12065@item set remotelogfile @var{file}
12066@cindex record serial communications on file
12067Record remote serial communications on the named @var{file}. The
12068default is not to record at all.
12069
12070@item show remotelogfile.
12071Show the current setting of the file name on which to record the
12072serial communications.
12073
12074@item set remotetimeout @var{num}
12075@cindex timeout for serial communications
12076@cindex remote timeout
12077Set the timeout limit to wait for the remote target to respond to
12078@var{num} seconds. The default is 2 seconds.
12079
12080@item show remotetimeout
12081Show the current number of seconds to wait for the remote target
12082responses.
12083
12084@cindex limit hardware breakpoints and watchpoints
12085@cindex remote target, limit break- and watchpoints
501eef12
AC
12086@anchor{set remote hardware-watchpoint-limit}
12087@anchor{set remote hardware-breakpoint-limit}
12088@item set remote hardware-watchpoint-limit @var{limit}
12089@itemx set remote hardware-breakpoint-limit @var{limit}
12090Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12091watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12092
12093@item set remote fetch-register-packet
12094@itemx set remote set-register-packet
12095@itemx set remote P-packet
12096@itemx set remote p-packet
12097@cindex P-packet
12098@cindex fetch registers from remote targets
12099@cindex set registers in remote targets
12100Determine whether @value{GDBN} can set and fetch registers from the
12101remote target using the @samp{P} packets. The default depends on the
12102remote stub's support of the @samp{P} packets (@value{GDBN} queries
12103the stub when this packet is first required).
12104
12105@item show remote fetch-register-packet
12106@itemx show remote set-register-packet
12107@itemx show remote P-packet
12108@itemx show remote p-packet
12109Show the current setting of using the @samp{P} packets for setting and
12110fetching registers from the remote target.
12111
12112@cindex binary downloads
12113@cindex X-packet
12114@item set remote binary-download-packet
12115@itemx set remote X-packet
12116Determine whether @value{GDBN} sends downloads in binary mode using
12117the @samp{X} packets. The default is on.
12118
12119@item show remote binary-download-packet
12120@itemx show remote X-packet
12121Show the current setting of using the @samp{X} packets for binary
12122downloads.
12123
12124@item set remote read-aux-vector-packet
12125@cindex auxiliary vector of remote target
12126@cindex @code{auxv}, and remote targets
12127Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12128auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12129remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12130Auxiliary Vector}. The default setting depends on the remote stub's
12131support of this request (@value{GDBN} queries the stub when this
12132request is first required). @xref{General Query Packets, qPart}, for
12133more information about this request.
9c16f35a
EZ
12134
12135@item show remote read-aux-vector-packet
12136Show the current setting of use of the @samp{qPart:auxv:read} request.
12137
12138@item set remote symbol-lookup-packet
12139@cindex remote symbol lookup request
12140Set the use of the remote protocol's @samp{qSymbol} (target symbol
12141lookup) request. This request is used to communicate symbol
12142information to the remote target, e.g., whenever a new shared library
12143is loaded by the remote (@pxref{Files, shared libraries}). The
12144default setting depends on the remote stub's support of this request
12145(@value{GDBN} queries the stub when this request is first required).
12146@xref{General Query Packets, qSymbol}, for more information about this
12147request.
12148
12149@item show remote symbol-lookup-packet
12150Show the current setting of use of the @samp{qSymbol} request.
12151
12152@item set remote verbose-resume-packet
12153@cindex resume remote target
12154@cindex signal thread, and remote targets
12155@cindex single-step thread, and remote targets
12156@cindex thread-specific operations on remote targets
12157Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12158request. This request is used to resume specific threads in the
12159remote target, and to single-step or signal them. The default setting
12160depends on the remote stub's support of this request (@value{GDBN}
12161queries the stub when this request is first required). This setting
12162affects debugging of multithreaded programs: if @samp{vCont} cannot be
12163used, @value{GDBN} might be unable to single-step a specific thread,
12164especially under @code{set scheduler-locking off}; it is also
12165impossible to pause a specific thread. @xref{Packets, vCont}, for
12166more details.
12167
12168@item show remote verbose-resume-packet
12169Show the current setting of use of the @samp{vCont} request
12170
12171@item set remote software-breakpoint-packet
12172@itemx set remote hardware-breakpoint-packet
12173@itemx set remote write-watchpoint-packet
12174@itemx set remote read-watchpoint-packet
12175@itemx set remote access-watchpoint-packet
12176@itemx set remote Z-packet
12177@cindex Z-packet
12178@cindex remote hardware breakpoints and watchpoints
12179These commands enable or disable the use of @samp{Z} packets for
12180setting breakpoints and watchpoints in the remote target. The default
12181depends on the remote stub's support of the @samp{Z} packets
12182(@value{GDBN} queries the stub when each packet is first required).
12183The command @code{set remote Z-packet}, kept for back-compatibility,
12184turns on or off all the features that require the use of @samp{Z}
12185packets.
12186
12187@item show remote software-breakpoint-packet
12188@itemx show remote hardware-breakpoint-packet
12189@itemx show remote write-watchpoint-packet
12190@itemx show remote read-watchpoint-packet
12191@itemx show remote access-watchpoint-packet
12192@itemx show remote Z-packet
12193Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12194
12195@item set remote get-thread-local-storage-address
12196@kindex set remote get-thread-local-storage-address
12197@cindex thread local storage of remote targets
12198This command enables or disables the use of the @samp{qGetTLSAddr}
12199(Get Thread Local Storage Address) request packet. The default
12200depends on whether the remote stub supports this request.
12201@xref{General Query Packets, qGetTLSAddr}, for more details about this
12202packet.
12203
12204@item show remote get-thread-local-storage-address
12205@kindex show remote get-thread-local-storage-address
12206Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12207@end table
12208
6f05cf9f
AC
12209@node remote stub
12210@section Implementing a remote stub
7a292a7a 12211
8e04817f
AC
12212@cindex debugging stub, example
12213@cindex remote stub, example
12214@cindex stub example, remote debugging
12215The stub files provided with @value{GDBN} implement the target side of the
12216communication protocol, and the @value{GDBN} side is implemented in the
12217@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12218these subroutines to communicate, and ignore the details. (If you're
12219implementing your own stub file, you can still ignore the details: start
12220with one of the existing stub files. @file{sparc-stub.c} is the best
12221organized, and therefore the easiest to read.)
12222
104c1213
JM
12223@cindex remote serial debugging, overview
12224To debug a program running on another machine (the debugging
12225@dfn{target} machine), you must first arrange for all the usual
12226prerequisites for the program to run by itself. For example, for a C
12227program, you need:
c906108c 12228
104c1213
JM
12229@enumerate
12230@item
12231A startup routine to set up the C runtime environment; these usually
12232have a name like @file{crt0}. The startup routine may be supplied by
12233your hardware supplier, or you may have to write your own.
96baa820 12234
5d161b24 12235@item
d4f3574e 12236A C subroutine library to support your program's
104c1213 12237subroutine calls, notably managing input and output.
96baa820 12238
104c1213
JM
12239@item
12240A way of getting your program to the other machine---for example, a
12241download program. These are often supplied by the hardware
12242manufacturer, but you may have to write your own from hardware
12243documentation.
12244@end enumerate
96baa820 12245
104c1213
JM
12246The next step is to arrange for your program to use a serial port to
12247communicate with the machine where @value{GDBN} is running (the @dfn{host}
12248machine). In general terms, the scheme looks like this:
96baa820 12249
104c1213
JM
12250@table @emph
12251@item On the host,
12252@value{GDBN} already understands how to use this protocol; when everything
12253else is set up, you can simply use the @samp{target remote} command
12254(@pxref{Targets,,Specifying a Debugging Target}).
12255
12256@item On the target,
12257you must link with your program a few special-purpose subroutines that
12258implement the @value{GDBN} remote serial protocol. The file containing these
12259subroutines is called a @dfn{debugging stub}.
12260
12261On certain remote targets, you can use an auxiliary program
12262@code{gdbserver} instead of linking a stub into your program.
12263@xref{Server,,Using the @code{gdbserver} program}, for details.
12264@end table
96baa820 12265
104c1213
JM
12266The debugging stub is specific to the architecture of the remote
12267machine; for example, use @file{sparc-stub.c} to debug programs on
12268@sc{sparc} boards.
96baa820 12269
104c1213
JM
12270@cindex remote serial stub list
12271These working remote stubs are distributed with @value{GDBN}:
96baa820 12272
104c1213
JM
12273@table @code
12274
12275@item i386-stub.c
41afff9a 12276@cindex @file{i386-stub.c}
104c1213
JM
12277@cindex Intel
12278@cindex i386
12279For Intel 386 and compatible architectures.
12280
12281@item m68k-stub.c
41afff9a 12282@cindex @file{m68k-stub.c}
104c1213
JM
12283@cindex Motorola 680x0
12284@cindex m680x0
12285For Motorola 680x0 architectures.
12286
12287@item sh-stub.c
41afff9a 12288@cindex @file{sh-stub.c}
172c2a43 12289@cindex Renesas
104c1213 12290@cindex SH
172c2a43 12291For Renesas SH architectures.
104c1213
JM
12292
12293@item sparc-stub.c
41afff9a 12294@cindex @file{sparc-stub.c}
104c1213
JM
12295@cindex Sparc
12296For @sc{sparc} architectures.
12297
12298@item sparcl-stub.c
41afff9a 12299@cindex @file{sparcl-stub.c}
104c1213
JM
12300@cindex Fujitsu
12301@cindex SparcLite
12302For Fujitsu @sc{sparclite} architectures.
12303
12304@end table
12305
12306The @file{README} file in the @value{GDBN} distribution may list other
12307recently added stubs.
12308
12309@menu
12310* Stub Contents:: What the stub can do for you
12311* Bootstrapping:: What you must do for the stub
12312* Debug Session:: Putting it all together
104c1213
JM
12313@end menu
12314
6d2ebf8b 12315@node Stub Contents
6f05cf9f 12316@subsection What the stub can do for you
104c1213
JM
12317
12318@cindex remote serial stub
12319The debugging stub for your architecture supplies these three
12320subroutines:
12321
12322@table @code
12323@item set_debug_traps
4644b6e3 12324@findex set_debug_traps
104c1213
JM
12325@cindex remote serial stub, initialization
12326This routine arranges for @code{handle_exception} to run when your
12327program stops. You must call this subroutine explicitly near the
12328beginning of your program.
12329
12330@item handle_exception
4644b6e3 12331@findex handle_exception
104c1213
JM
12332@cindex remote serial stub, main routine
12333This is the central workhorse, but your program never calls it
12334explicitly---the setup code arranges for @code{handle_exception} to
12335run when a trap is triggered.
12336
12337@code{handle_exception} takes control when your program stops during
12338execution (for example, on a breakpoint), and mediates communications
12339with @value{GDBN} on the host machine. This is where the communications
12340protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12341representative on the target machine. It begins by sending summary
104c1213
JM
12342information on the state of your program, then continues to execute,
12343retrieving and transmitting any information @value{GDBN} needs, until you
12344execute a @value{GDBN} command that makes your program resume; at that point,
12345@code{handle_exception} returns control to your own code on the target
5d161b24 12346machine.
104c1213
JM
12347
12348@item breakpoint
12349@cindex @code{breakpoint} subroutine, remote
12350Use this auxiliary subroutine to make your program contain a
12351breakpoint. Depending on the particular situation, this may be the only
12352way for @value{GDBN} to get control. For instance, if your target
12353machine has some sort of interrupt button, you won't need to call this;
12354pressing the interrupt button transfers control to
12355@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12356simply receiving characters on the serial port may also trigger a trap;
12357again, in that situation, you don't need to call @code{breakpoint} from
12358your own program---simply running @samp{target remote} from the host
5d161b24 12359@value{GDBN} session gets control.
104c1213
JM
12360
12361Call @code{breakpoint} if none of these is true, or if you simply want
12362to make certain your program stops at a predetermined point for the
12363start of your debugging session.
12364@end table
12365
6d2ebf8b 12366@node Bootstrapping
6f05cf9f 12367@subsection What you must do for the stub
104c1213
JM
12368
12369@cindex remote stub, support routines
12370The debugging stubs that come with @value{GDBN} are set up for a particular
12371chip architecture, but they have no information about the rest of your
12372debugging target machine.
12373
12374First of all you need to tell the stub how to communicate with the
12375serial port.
12376
12377@table @code
12378@item int getDebugChar()
4644b6e3 12379@findex getDebugChar
104c1213
JM
12380Write this subroutine to read a single character from the serial port.
12381It may be identical to @code{getchar} for your target system; a
12382different name is used to allow you to distinguish the two if you wish.
12383
12384@item void putDebugChar(int)
4644b6e3 12385@findex putDebugChar
104c1213 12386Write this subroutine to write a single character to the serial port.
5d161b24 12387It may be identical to @code{putchar} for your target system; a
104c1213
JM
12388different name is used to allow you to distinguish the two if you wish.
12389@end table
12390
12391@cindex control C, and remote debugging
12392@cindex interrupting remote targets
12393If you want @value{GDBN} to be able to stop your program while it is
12394running, you need to use an interrupt-driven serial driver, and arrange
12395for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12396character). That is the character which @value{GDBN} uses to tell the
12397remote system to stop.
12398
12399Getting the debugging target to return the proper status to @value{GDBN}
12400probably requires changes to the standard stub; one quick and dirty way
12401is to just execute a breakpoint instruction (the ``dirty'' part is that
12402@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12403
12404Other routines you need to supply are:
12405
12406@table @code
12407@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12408@findex exceptionHandler
104c1213
JM
12409Write this function to install @var{exception_address} in the exception
12410handling tables. You need to do this because the stub does not have any
12411way of knowing what the exception handling tables on your target system
12412are like (for example, the processor's table might be in @sc{rom},
12413containing entries which point to a table in @sc{ram}).
12414@var{exception_number} is the exception number which should be changed;
12415its meaning is architecture-dependent (for example, different numbers
12416might represent divide by zero, misaligned access, etc). When this
12417exception occurs, control should be transferred directly to
12418@var{exception_address}, and the processor state (stack, registers,
12419and so on) should be just as it is when a processor exception occurs. So if
12420you want to use a jump instruction to reach @var{exception_address}, it
12421should be a simple jump, not a jump to subroutine.
12422
12423For the 386, @var{exception_address} should be installed as an interrupt
12424gate so that interrupts are masked while the handler runs. The gate
12425should be at privilege level 0 (the most privileged level). The
12426@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12427help from @code{exceptionHandler}.
12428
12429@item void flush_i_cache()
4644b6e3 12430@findex flush_i_cache
d4f3574e 12431On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12432instruction cache, if any, on your target machine. If there is no
12433instruction cache, this subroutine may be a no-op.
12434
12435On target machines that have instruction caches, @value{GDBN} requires this
12436function to make certain that the state of your program is stable.
12437@end table
12438
12439@noindent
12440You must also make sure this library routine is available:
12441
12442@table @code
12443@item void *memset(void *, int, int)
4644b6e3 12444@findex memset
104c1213
JM
12445This is the standard library function @code{memset} that sets an area of
12446memory to a known value. If you have one of the free versions of
12447@code{libc.a}, @code{memset} can be found there; otherwise, you must
12448either obtain it from your hardware manufacturer, or write your own.
12449@end table
12450
12451If you do not use the GNU C compiler, you may need other standard
12452library subroutines as well; this varies from one stub to another,
12453but in general the stubs are likely to use any of the common library
d4f3574e 12454subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12455
12456
6d2ebf8b 12457@node Debug Session
6f05cf9f 12458@subsection Putting it all together
104c1213
JM
12459
12460@cindex remote serial debugging summary
12461In summary, when your program is ready to debug, you must follow these
12462steps.
12463
12464@enumerate
12465@item
6d2ebf8b 12466Make sure you have defined the supporting low-level routines
104c1213
JM
12467(@pxref{Bootstrapping,,What you must do for the stub}):
12468@display
12469@code{getDebugChar}, @code{putDebugChar},
12470@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12471@end display
12472
12473@item
12474Insert these lines near the top of your program:
12475
474c8240 12476@smallexample
104c1213
JM
12477set_debug_traps();
12478breakpoint();
474c8240 12479@end smallexample
104c1213
JM
12480
12481@item
12482For the 680x0 stub only, you need to provide a variable called
12483@code{exceptionHook}. Normally you just use:
12484
474c8240 12485@smallexample
104c1213 12486void (*exceptionHook)() = 0;
474c8240 12487@end smallexample
104c1213 12488
d4f3574e 12489@noindent
104c1213 12490but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12491function in your program, that function is called when
104c1213
JM
12492@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12493error). The function indicated by @code{exceptionHook} is called with
12494one parameter: an @code{int} which is the exception number.
12495
12496@item
12497Compile and link together: your program, the @value{GDBN} debugging stub for
12498your target architecture, and the supporting subroutines.
12499
12500@item
12501Make sure you have a serial connection between your target machine and
12502the @value{GDBN} host, and identify the serial port on the host.
12503
12504@item
12505@c The "remote" target now provides a `load' command, so we should
12506@c document that. FIXME.
12507Download your program to your target machine (or get it there by
12508whatever means the manufacturer provides), and start it.
12509
12510@item
07f31aa6
DJ
12511Start @value{GDBN} on the host, and connect to the target
12512(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12513
104c1213
JM
12514@end enumerate
12515
8e04817f
AC
12516@node Configurations
12517@chapter Configuration-Specific Information
104c1213 12518
8e04817f
AC
12519While nearly all @value{GDBN} commands are available for all native and
12520cross versions of the debugger, there are some exceptions. This chapter
12521describes things that are only available in certain configurations.
104c1213 12522
8e04817f
AC
12523There are three major categories of configurations: native
12524configurations, where the host and target are the same, embedded
12525operating system configurations, which are usually the same for several
12526different processor architectures, and bare embedded processors, which
12527are quite different from each other.
104c1213 12528
8e04817f
AC
12529@menu
12530* Native::
12531* Embedded OS::
12532* Embedded Processors::
12533* Architectures::
12534@end menu
104c1213 12535
8e04817f
AC
12536@node Native
12537@section Native
104c1213 12538
8e04817f
AC
12539This section describes details specific to particular native
12540configurations.
6cf7e474 12541
8e04817f
AC
12542@menu
12543* HP-UX:: HP-UX
7561d450 12544* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12545* SVR4 Process Information:: SVR4 process information
12546* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12547* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12548* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12549* Neutrino:: Features specific to QNX Neutrino
8e04817f 12550@end menu
6cf7e474 12551
8e04817f
AC
12552@node HP-UX
12553@subsection HP-UX
104c1213 12554
8e04817f
AC
12555On HP-UX systems, if you refer to a function or variable name that
12556begins with a dollar sign, @value{GDBN} searches for a user or system
12557name first, before it searches for a convenience variable.
104c1213 12558
9c16f35a 12559
7561d450
MK
12560@node BSD libkvm Interface
12561@subsection BSD libkvm Interface
12562
12563@cindex libkvm
12564@cindex kernel memory image
12565@cindex kernel crash dump
12566
12567BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12568interface that provides a uniform interface for accessing kernel virtual
12569memory images, including live systems and crash dumps. @value{GDBN}
12570uses this interface to allow you to debug live kernels and kernel crash
12571dumps on many native BSD configurations. This is implemented as a
12572special @code{kvm} debugging target. For debugging a live system, load
12573the currently running kernel into @value{GDBN} and connect to the
12574@code{kvm} target:
12575
12576@smallexample
12577(@value{GDBP}) @b{target kvm}
12578@end smallexample
12579
12580For debugging crash dumps, provide the file name of the crash dump as an
12581argument:
12582
12583@smallexample
12584(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12585@end smallexample
12586
12587Once connected to the @code{kvm} target, the following commands are
12588available:
12589
12590@table @code
12591@kindex kvm
12592@item kvm pcb
721c2651 12593Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12594
12595@item kvm proc
12596Set current context from proc address. This command isn't available on
12597modern FreeBSD systems.
12598@end table
12599
8e04817f
AC
12600@node SVR4 Process Information
12601@subsection SVR4 process information
60bf7e09
EZ
12602@cindex /proc
12603@cindex examine process image
12604@cindex process info via @file{/proc}
104c1213 12605
60bf7e09
EZ
12606Many versions of SVR4 and compatible systems provide a facility called
12607@samp{/proc} that can be used to examine the image of a running
12608process using file-system subroutines. If @value{GDBN} is configured
12609for an operating system with this facility, the command @code{info
12610proc} is available to report information about the process running
12611your program, or about any process running on your system. @code{info
12612proc} works only on SVR4 systems that include the @code{procfs} code.
12613This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12614Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12615
8e04817f
AC
12616@table @code
12617@kindex info proc
60bf7e09 12618@cindex process ID
8e04817f 12619@item info proc
60bf7e09
EZ
12620@itemx info proc @var{process-id}
12621Summarize available information about any running process. If a
12622process ID is specified by @var{process-id}, display information about
12623that process; otherwise display information about the program being
12624debugged. The summary includes the debugged process ID, the command
12625line used to invoke it, its current working directory, and its
12626executable file's absolute file name.
12627
12628On some systems, @var{process-id} can be of the form
12629@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12630within a process. If the optional @var{pid} part is missing, it means
12631a thread from the process being debugged (the leading @samp{/} still
12632needs to be present, or else @value{GDBN} will interpret the number as
12633a process ID rather than a thread ID).
6cf7e474 12634
8e04817f 12635@item info proc mappings
60bf7e09
EZ
12636@cindex memory address space mappings
12637Report the memory address space ranges accessible in the program, with
12638information on whether the process has read, write, or execute access
12639rights to each range. On @sc{gnu}/Linux systems, each memory range
12640includes the object file which is mapped to that range, instead of the
12641memory access rights to that range.
12642
12643@item info proc stat
12644@itemx info proc status
12645@cindex process detailed status information
12646These subcommands are specific to @sc{gnu}/Linux systems. They show
12647the process-related information, including the user ID and group ID;
12648how many threads are there in the process; its virtual memory usage;
12649the signals that are pending, blocked, and ignored; its TTY; its
12650consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12651value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12652(type @kbd{man 5 proc} from your shell prompt).
12653
12654@item info proc all
12655Show all the information about the process described under all of the
12656above @code{info proc} subcommands.
12657
8e04817f
AC
12658@ignore
12659@comment These sub-options of 'info proc' were not included when
12660@comment procfs.c was re-written. Keep their descriptions around
12661@comment against the day when someone finds the time to put them back in.
12662@kindex info proc times
12663@item info proc times
12664Starting time, user CPU time, and system CPU time for your program and
12665its children.
6cf7e474 12666
8e04817f
AC
12667@kindex info proc id
12668@item info proc id
12669Report on the process IDs related to your program: its own process ID,
12670the ID of its parent, the process group ID, and the session ID.
8e04817f 12671@end ignore
721c2651
EZ
12672
12673@item set procfs-trace
12674@kindex set procfs-trace
12675@cindex @code{procfs} API calls
12676This command enables and disables tracing of @code{procfs} API calls.
12677
12678@item show procfs-trace
12679@kindex show procfs-trace
12680Show the current state of @code{procfs} API call tracing.
12681
12682@item set procfs-file @var{file}
12683@kindex set procfs-file
12684Tell @value{GDBN} to write @code{procfs} API trace to the named
12685@var{file}. @value{GDBN} appends the trace info to the previous
12686contents of the file. The default is to display the trace on the
12687standard output.
12688
12689@item show procfs-file
12690@kindex show procfs-file
12691Show the file to which @code{procfs} API trace is written.
12692
12693@item proc-trace-entry
12694@itemx proc-trace-exit
12695@itemx proc-untrace-entry
12696@itemx proc-untrace-exit
12697@kindex proc-trace-entry
12698@kindex proc-trace-exit
12699@kindex proc-untrace-entry
12700@kindex proc-untrace-exit
12701These commands enable and disable tracing of entries into and exits
12702from the @code{syscall} interface.
12703
12704@item info pidlist
12705@kindex info pidlist
12706@cindex process list, QNX Neutrino
12707For QNX Neutrino only, this command displays the list of all the
12708processes and all the threads within each process.
12709
12710@item info meminfo
12711@kindex info meminfo
12712@cindex mapinfo list, QNX Neutrino
12713For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12714@end table
104c1213 12715
8e04817f
AC
12716@node DJGPP Native
12717@subsection Features for Debugging @sc{djgpp} Programs
12718@cindex @sc{djgpp} debugging
12719@cindex native @sc{djgpp} debugging
12720@cindex MS-DOS-specific commands
104c1213 12721
514c4d71
EZ
12722@cindex DPMI
12723@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12724MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12725that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12726top of real-mode DOS systems and their emulations.
104c1213 12727
8e04817f
AC
12728@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12729defines a few commands specific to the @sc{djgpp} port. This
12730subsection describes those commands.
104c1213 12731
8e04817f
AC
12732@table @code
12733@kindex info dos
12734@item info dos
12735This is a prefix of @sc{djgpp}-specific commands which print
12736information about the target system and important OS structures.
f1251bdd 12737
8e04817f
AC
12738@kindex sysinfo
12739@cindex MS-DOS system info
12740@cindex free memory information (MS-DOS)
12741@item info dos sysinfo
12742This command displays assorted information about the underlying
12743platform: the CPU type and features, the OS version and flavor, the
12744DPMI version, and the available conventional and DPMI memory.
104c1213 12745
8e04817f
AC
12746@cindex GDT
12747@cindex LDT
12748@cindex IDT
12749@cindex segment descriptor tables
12750@cindex descriptor tables display
12751@item info dos gdt
12752@itemx info dos ldt
12753@itemx info dos idt
12754These 3 commands display entries from, respectively, Global, Local,
12755and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12756tables are data structures which store a descriptor for each segment
12757that is currently in use. The segment's selector is an index into a
12758descriptor table; the table entry for that index holds the
12759descriptor's base address and limit, and its attributes and access
12760rights.
104c1213 12761
8e04817f
AC
12762A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12763segment (used for both data and the stack), and a DOS segment (which
12764allows access to DOS/BIOS data structures and absolute addresses in
12765conventional memory). However, the DPMI host will usually define
12766additional segments in order to support the DPMI environment.
d4f3574e 12767
8e04817f
AC
12768@cindex garbled pointers
12769These commands allow to display entries from the descriptor tables.
12770Without an argument, all entries from the specified table are
12771displayed. An argument, which should be an integer expression, means
12772display a single entry whose index is given by the argument. For
12773example, here's a convenient way to display information about the
12774debugged program's data segment:
104c1213 12775
8e04817f
AC
12776@smallexample
12777@exdent @code{(@value{GDBP}) info dos ldt $ds}
12778@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12779@end smallexample
104c1213 12780
8e04817f
AC
12781@noindent
12782This comes in handy when you want to see whether a pointer is outside
12783the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12784
8e04817f
AC
12785@cindex page tables display (MS-DOS)
12786@item info dos pde
12787@itemx info dos pte
12788These two commands display entries from, respectively, the Page
12789Directory and the Page Tables. Page Directories and Page Tables are
12790data structures which control how virtual memory addresses are mapped
12791into physical addresses. A Page Table includes an entry for every
12792page of memory that is mapped into the program's address space; there
12793may be several Page Tables, each one holding up to 4096 entries. A
12794Page Directory has up to 4096 entries, one each for every Page Table
12795that is currently in use.
104c1213 12796
8e04817f
AC
12797Without an argument, @kbd{info dos pde} displays the entire Page
12798Directory, and @kbd{info dos pte} displays all the entries in all of
12799the Page Tables. An argument, an integer expression, given to the
12800@kbd{info dos pde} command means display only that entry from the Page
12801Directory table. An argument given to the @kbd{info dos pte} command
12802means display entries from a single Page Table, the one pointed to by
12803the specified entry in the Page Directory.
104c1213 12804
8e04817f
AC
12805@cindex direct memory access (DMA) on MS-DOS
12806These commands are useful when your program uses @dfn{DMA} (Direct
12807Memory Access), which needs physical addresses to program the DMA
12808controller.
104c1213 12809
8e04817f 12810These commands are supported only with some DPMI servers.
104c1213 12811
8e04817f
AC
12812@cindex physical address from linear address
12813@item info dos address-pte @var{addr}
12814This command displays the Page Table entry for a specified linear
514c4d71
EZ
12815address. The argument @var{addr} is a linear address which should
12816already have the appropriate segment's base address added to it,
12817because this command accepts addresses which may belong to @emph{any}
12818segment. For example, here's how to display the Page Table entry for
12819the page where a variable @code{i} is stored:
104c1213 12820
b383017d 12821@smallexample
8e04817f
AC
12822@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12823@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12824@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12825@end smallexample
104c1213 12826
8e04817f
AC
12827@noindent
12828This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12829whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12830attributes of that page.
104c1213 12831
8e04817f
AC
12832Note that you must cast the addresses of variables to a @code{char *},
12833since otherwise the value of @code{__djgpp_base_address}, the base
12834address of all variables and functions in a @sc{djgpp} program, will
12835be added using the rules of C pointer arithmetics: if @code{i} is
12836declared an @code{int}, @value{GDBN} will add 4 times the value of
12837@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12838
8e04817f
AC
12839Here's another example, it displays the Page Table entry for the
12840transfer buffer:
104c1213 12841
8e04817f
AC
12842@smallexample
12843@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12844@exdent @code{Page Table entry for address 0x29110:}
12845@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12846@end smallexample
104c1213 12847
8e04817f
AC
12848@noindent
12849(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128503rd member of the @code{_go32_info_block} structure.) The output
12851clearly shows that this DPMI server maps the addresses in conventional
12852memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12853linear (@code{0x29110}) addresses are identical.
104c1213 12854
8e04817f
AC
12855This command is supported only with some DPMI servers.
12856@end table
104c1213 12857
c45da7e6 12858@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12859In addition to native debugging, the DJGPP port supports remote
12860debugging via a serial data link. The following commands are specific
12861to remote serial debugging in the DJGPP port of @value{GDBN}.
12862
12863@table @code
12864@kindex set com1base
12865@kindex set com1irq
12866@kindex set com2base
12867@kindex set com2irq
12868@kindex set com3base
12869@kindex set com3irq
12870@kindex set com4base
12871@kindex set com4irq
12872@item set com1base @var{addr}
12873This command sets the base I/O port address of the @file{COM1} serial
12874port.
12875
12876@item set com1irq @var{irq}
12877This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12878for the @file{COM1} serial port.
12879
12880There are similar commands @samp{set com2base}, @samp{set com3irq},
12881etc.@: for setting the port address and the @code{IRQ} lines for the
12882other 3 COM ports.
12883
12884@kindex show com1base
12885@kindex show com1irq
12886@kindex show com2base
12887@kindex show com2irq
12888@kindex show com3base
12889@kindex show com3irq
12890@kindex show com4base
12891@kindex show com4irq
12892The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12893display the current settings of the base address and the @code{IRQ}
12894lines used by the COM ports.
c45da7e6
EZ
12895
12896@item info serial
12897@kindex info serial
12898@cindex DOS serial port status
12899This command prints the status of the 4 DOS serial ports. For each
12900port, it prints whether it's active or not, its I/O base address and
12901IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12902counts of various errors encountered so far.
a8f24a35
EZ
12903@end table
12904
12905
78c47bea
PM
12906@node Cygwin Native
12907@subsection Features for Debugging MS Windows PE executables
12908@cindex MS Windows debugging
12909@cindex native Cygwin debugging
12910@cindex Cygwin-specific commands
12911
be448670
CF
12912@value{GDBN} supports native debugging of MS Windows programs, including
12913DLLs with and without symbolic debugging information. There are various
12914additional Cygwin-specific commands, described in this subsection. The
12915subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12916that have no debugging symbols.
12917
78c47bea
PM
12918
12919@table @code
12920@kindex info w32
12921@item info w32
12922This is a prefix of MS Windows specific commands which print
12923information about the target system and important OS structures.
12924
12925@item info w32 selector
12926This command displays information returned by
12927the Win32 API @code{GetThreadSelectorEntry} function.
12928It takes an optional argument that is evaluated to
12929a long value to give the information about this given selector.
12930Without argument, this command displays information
12931about the the six segment registers.
12932
12933@kindex info dll
12934@item info dll
12935This is a Cygwin specific alias of info shared.
12936
12937@kindex dll-symbols
12938@item dll-symbols
12939This command loads symbols from a dll similarly to
12940add-sym command but without the need to specify a base address.
12941
b383017d 12942@kindex set new-console
78c47bea 12943@item set new-console @var{mode}
b383017d 12944If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12945be started in a new console on next start.
12946If @var{mode} is @code{off}i, the debuggee will
12947be started in the same console as the debugger.
12948
12949@kindex show new-console
12950@item show new-console
12951Displays whether a new console is used
12952when the debuggee is started.
12953
12954@kindex set new-group
12955@item set new-group @var{mode}
12956This boolean value controls whether the debuggee should
12957start a new group or stay in the same group as the debugger.
12958This affects the way the Windows OS handles
12959Ctrl-C.
12960
12961@kindex show new-group
12962@item show new-group
12963Displays current value of new-group boolean.
12964
12965@kindex set debugevents
12966@item set debugevents
12967This boolean value adds debug output concerning events seen by the debugger.
12968
12969@kindex set debugexec
12970@item set debugexec
b383017d 12971This boolean value adds debug output concerning execute events
78c47bea
PM
12972seen by the debugger.
12973
12974@kindex set debugexceptions
12975@item set debugexceptions
b383017d 12976This boolean value adds debug ouptut concerning exception events
78c47bea
PM
12977seen by the debugger.
12978
12979@kindex set debugmemory
12980@item set debugmemory
b383017d 12981This boolean value adds debug ouptut concerning memory events
78c47bea
PM
12982seen by the debugger.
12983
12984@kindex set shell
12985@item set shell
12986This boolean values specifies whether the debuggee is called
12987via a shell or directly (default value is on).
12988
12989@kindex show shell
12990@item show shell
12991Displays if the debuggee will be started with a shell.
12992
12993@end table
12994
be448670
CF
12995@menu
12996* Non-debug DLL symbols:: Support for DLLs without debugging symbols
12997@end menu
12998
12999@node Non-debug DLL symbols
13000@subsubsection Support for DLLs without debugging symbols
13001@cindex DLLs with no debugging symbols
13002@cindex Minimal symbols and DLLs
13003
13004Very often on windows, some of the DLLs that your program relies on do
13005not include symbolic debugging information (for example,
13006@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13007symbols in a DLL, it relies on the minimal amount of symbolic
13008information contained in the DLL's export table. This subsubsection
13009describes working with such symbols, known internally to @value{GDBN} as
13010``minimal symbols''.
13011
13012Note that before the debugged program has started execution, no DLLs
13013will have been loaded. The easiest way around this problem is simply to
13014start the program --- either by setting a breakpoint or letting the
13015program run once to completion. It is also possible to force
13016@value{GDBN} to load a particular DLL before starting the executable ---
13017see the shared library information in @pxref{Files} or the
13018@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13019explicitly loading symbols from a DLL with no debugging information will
13020cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13021which may adversely affect symbol lookup performance.
13022
13023@subsubsection DLL name prefixes
13024
13025In keeping with the naming conventions used by the Microsoft debugging
13026tools, DLL export symbols are made available with a prefix based on the
13027DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13028also entered into the symbol table, so @code{CreateFileA} is often
13029sufficient. In some cases there will be name clashes within a program
13030(particularly if the executable itself includes full debugging symbols)
13031necessitating the use of the fully qualified name when referring to the
13032contents of the DLL. Use single-quotes around the name to avoid the
13033exclamation mark (``!'') being interpreted as a language operator.
13034
13035Note that the internal name of the DLL may be all upper-case, even
13036though the file name of the DLL is lower-case, or vice-versa. Since
13037symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13038some confusion. If in doubt, try the @code{info functions} and
13039@code{info variables} commands or even @code{maint print msymbols} (see
13040@pxref{Symbols}). Here's an example:
13041
13042@smallexample
f7dc1244 13043(@value{GDBP}) info function CreateFileA
be448670
CF
13044All functions matching regular expression "CreateFileA":
13045
13046Non-debugging symbols:
130470x77e885f4 CreateFileA
130480x77e885f4 KERNEL32!CreateFileA
13049@end smallexample
13050
13051@smallexample
f7dc1244 13052(@value{GDBP}) info function !
be448670
CF
13053All functions matching regular expression "!":
13054
13055Non-debugging symbols:
130560x6100114c cygwin1!__assert
130570x61004034 cygwin1!_dll_crt0@@0
130580x61004240 cygwin1!dll_crt0(per_process *)
13059[etc...]
13060@end smallexample
13061
13062@subsubsection Working with minimal symbols
13063
13064Symbols extracted from a DLL's export table do not contain very much
13065type information. All that @value{GDBN} can do is guess whether a symbol
13066refers to a function or variable depending on the linker section that
13067contains the symbol. Also note that the actual contents of the memory
13068contained in a DLL are not available unless the program is running. This
13069means that you cannot examine the contents of a variable or disassemble
13070a function within a DLL without a running program.
13071
13072Variables are generally treated as pointers and dereferenced
13073automatically. For this reason, it is often necessary to prefix a
13074variable name with the address-of operator (``&'') and provide explicit
13075type information in the command. Here's an example of the type of
13076problem:
13077
13078@smallexample
f7dc1244 13079(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13080$1 = 268572168
13081@end smallexample
13082
13083@smallexample
f7dc1244 13084(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
130850x10021610: "\230y\""
13086@end smallexample
13087
13088And two possible solutions:
13089
13090@smallexample
f7dc1244 13091(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13092$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13093@end smallexample
13094
13095@smallexample
f7dc1244 13096(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 130970x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13098(@value{GDBP}) x/x 0x10021608
be448670 130990x10021608: 0x0022fd98
f7dc1244 13100(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131010x22fd98: "/cygdrive/c/mydirectory/myprogram"
13102@end smallexample
13103
13104Setting a break point within a DLL is possible even before the program
13105starts execution. However, under these circumstances, @value{GDBN} can't
13106examine the initial instructions of the function in order to skip the
13107function's frame set-up code. You can work around this by using ``*&''
13108to set the breakpoint at a raw memory address:
13109
13110@smallexample
f7dc1244 13111(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13112Breakpoint 1 at 0x1e04eff0
13113@end smallexample
13114
13115The author of these extensions is not entirely convinced that setting a
13116break point within a shared DLL like @file{kernel32.dll} is completely
13117safe.
13118
14d6dd68
EZ
13119@node Hurd Native
13120@subsection Commands specific to @sc{gnu} Hurd systems
13121@cindex @sc{gnu} Hurd debugging
13122
13123This subsection describes @value{GDBN} commands specific to the
13124@sc{gnu} Hurd native debugging.
13125
13126@table @code
13127@item set signals
13128@itemx set sigs
13129@kindex set signals@r{, Hurd command}
13130@kindex set sigs@r{, Hurd command}
13131This command toggles the state of inferior signal interception by
13132@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13133affected by this command. @code{sigs} is a shorthand alias for
13134@code{signals}.
13135
13136@item show signals
13137@itemx show sigs
13138@kindex show signals@r{, Hurd command}
13139@kindex show sigs@r{, Hurd command}
13140Show the current state of intercepting inferior's signals.
13141
13142@item set signal-thread
13143@itemx set sigthread
13144@kindex set signal-thread
13145@kindex set sigthread
13146This command tells @value{GDBN} which thread is the @code{libc} signal
13147thread. That thread is run when a signal is delivered to a running
13148process. @code{set sigthread} is the shorthand alias of @code{set
13149signal-thread}.
13150
13151@item show signal-thread
13152@itemx show sigthread
13153@kindex show signal-thread
13154@kindex show sigthread
13155These two commands show which thread will run when the inferior is
13156delivered a signal.
13157
13158@item set stopped
13159@kindex set stopped@r{, Hurd command}
13160This commands tells @value{GDBN} that the inferior process is stopped,
13161as with the @code{SIGSTOP} signal. The stopped process can be
13162continued by delivering a signal to it.
13163
13164@item show stopped
13165@kindex show stopped@r{, Hurd command}
13166This command shows whether @value{GDBN} thinks the debuggee is
13167stopped.
13168
13169@item set exceptions
13170@kindex set exceptions@r{, Hurd command}
13171Use this command to turn off trapping of exceptions in the inferior.
13172When exception trapping is off, neither breakpoints nor
13173single-stepping will work. To restore the default, set exception
13174trapping on.
13175
13176@item show exceptions
13177@kindex show exceptions@r{, Hurd command}
13178Show the current state of trapping exceptions in the inferior.
13179
13180@item set task pause
13181@kindex set task@r{, Hurd commands}
13182@cindex task attributes (@sc{gnu} Hurd)
13183@cindex pause current task (@sc{gnu} Hurd)
13184This command toggles task suspension when @value{GDBN} has control.
13185Setting it to on takes effect immediately, and the task is suspended
13186whenever @value{GDBN} gets control. Setting it to off will take
13187effect the next time the inferior is continued. If this option is set
13188to off, you can use @code{set thread default pause on} or @code{set
13189thread pause on} (see below) to pause individual threads.
13190
13191@item show task pause
13192@kindex show task@r{, Hurd commands}
13193Show the current state of task suspension.
13194
13195@item set task detach-suspend-count
13196@cindex task suspend count
13197@cindex detach from task, @sc{gnu} Hurd
13198This command sets the suspend count the task will be left with when
13199@value{GDBN} detaches from it.
13200
13201@item show task detach-suspend-count
13202Show the suspend count the task will be left with when detaching.
13203
13204@item set task exception-port
13205@itemx set task excp
13206@cindex task exception port, @sc{gnu} Hurd
13207This command sets the task exception port to which @value{GDBN} will
13208forward exceptions. The argument should be the value of the @dfn{send
13209rights} of the task. @code{set task excp} is a shorthand alias.
13210
13211@item set noninvasive
13212@cindex noninvasive task options
13213This command switches @value{GDBN} to a mode that is the least
13214invasive as far as interfering with the inferior is concerned. This
13215is the same as using @code{set task pause}, @code{set exceptions}, and
13216@code{set signals} to values opposite to the defaults.
13217
13218@item info send-rights
13219@itemx info receive-rights
13220@itemx info port-rights
13221@itemx info port-sets
13222@itemx info dead-names
13223@itemx info ports
13224@itemx info psets
13225@cindex send rights, @sc{gnu} Hurd
13226@cindex receive rights, @sc{gnu} Hurd
13227@cindex port rights, @sc{gnu} Hurd
13228@cindex port sets, @sc{gnu} Hurd
13229@cindex dead names, @sc{gnu} Hurd
13230These commands display information about, respectively, send rights,
13231receive rights, port rights, port sets, and dead names of a task.
13232There are also shorthand aliases: @code{info ports} for @code{info
13233port-rights} and @code{info psets} for @code{info port-sets}.
13234
13235@item set thread pause
13236@kindex set thread@r{, Hurd command}
13237@cindex thread properties, @sc{gnu} Hurd
13238@cindex pause current thread (@sc{gnu} Hurd)
13239This command toggles current thread suspension when @value{GDBN} has
13240control. Setting it to on takes effect immediately, and the current
13241thread is suspended whenever @value{GDBN} gets control. Setting it to
13242off will take effect the next time the inferior is continued.
13243Normally, this command has no effect, since when @value{GDBN} has
13244control, the whole task is suspended. However, if you used @code{set
13245task pause off} (see above), this command comes in handy to suspend
13246only the current thread.
13247
13248@item show thread pause
13249@kindex show thread@r{, Hurd command}
13250This command shows the state of current thread suspension.
13251
13252@item set thread run
13253This comamnd sets whether the current thread is allowed to run.
13254
13255@item show thread run
13256Show whether the current thread is allowed to run.
13257
13258@item set thread detach-suspend-count
13259@cindex thread suspend count, @sc{gnu} Hurd
13260@cindex detach from thread, @sc{gnu} Hurd
13261This command sets the suspend count @value{GDBN} will leave on a
13262thread when detaching. This number is relative to the suspend count
13263found by @value{GDBN} when it notices the thread; use @code{set thread
13264takeover-suspend-count} to force it to an absolute value.
13265
13266@item show thread detach-suspend-count
13267Show the suspend count @value{GDBN} will leave on the thread when
13268detaching.
13269
13270@item set thread exception-port
13271@itemx set thread excp
13272Set the thread exception port to which to forward exceptions. This
13273overrides the port set by @code{set task exception-port} (see above).
13274@code{set thread excp} is the shorthand alias.
13275
13276@item set thread takeover-suspend-count
13277Normally, @value{GDBN}'s thread suspend counts are relative to the
13278value @value{GDBN} finds when it notices each thread. This command
13279changes the suspend counts to be absolute instead.
13280
13281@item set thread default
13282@itemx show thread default
13283@cindex thread default settings, @sc{gnu} Hurd
13284Each of the above @code{set thread} commands has a @code{set thread
13285default} counterpart (e.g., @code{set thread default pause}, @code{set
13286thread default exception-port}, etc.). The @code{thread default}
13287variety of commands sets the default thread properties for all
13288threads; you can then change the properties of individual threads with
13289the non-default commands.
13290@end table
13291
13292
a64548ea
EZ
13293@node Neutrino
13294@subsection QNX Neutrino
13295@cindex QNX Neutrino
13296
13297@value{GDBN} provides the following commands specific to the QNX
13298Neutrino target:
13299
13300@table @code
13301@item set debug nto-debug
13302@kindex set debug nto-debug
13303When set to on, enables debugging messages specific to the QNX
13304Neutrino support.
13305
13306@item show debug nto-debug
13307@kindex show debug nto-debug
13308Show the current state of QNX Neutrino messages.
13309@end table
13310
13311
8e04817f
AC
13312@node Embedded OS
13313@section Embedded Operating Systems
104c1213 13314
8e04817f
AC
13315This section describes configurations involving the debugging of
13316embedded operating systems that are available for several different
13317architectures.
d4f3574e 13318
8e04817f
AC
13319@menu
13320* VxWorks:: Using @value{GDBN} with VxWorks
13321@end menu
104c1213 13322
8e04817f
AC
13323@value{GDBN} includes the ability to debug programs running on
13324various real-time operating systems.
104c1213 13325
8e04817f
AC
13326@node VxWorks
13327@subsection Using @value{GDBN} with VxWorks
104c1213 13328
8e04817f 13329@cindex VxWorks
104c1213 13330
8e04817f 13331@table @code
104c1213 13332
8e04817f
AC
13333@kindex target vxworks
13334@item target vxworks @var{machinename}
13335A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13336is the target system's machine name or IP address.
104c1213 13337
8e04817f 13338@end table
104c1213 13339
8e04817f
AC
13340On VxWorks, @code{load} links @var{filename} dynamically on the
13341current target system as well as adding its symbols in @value{GDBN}.
104c1213 13342
8e04817f
AC
13343@value{GDBN} enables developers to spawn and debug tasks running on networked
13344VxWorks targets from a Unix host. Already-running tasks spawned from
13345the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13346both the Unix host and on the VxWorks target. The program
13347@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13348installed with the name @code{vxgdb}, to distinguish it from a
13349@value{GDBN} for debugging programs on the host itself.)
104c1213 13350
8e04817f
AC
13351@table @code
13352@item VxWorks-timeout @var{args}
13353@kindex vxworks-timeout
13354All VxWorks-based targets now support the option @code{vxworks-timeout}.
13355This option is set by the user, and @var{args} represents the number of
13356seconds @value{GDBN} waits for responses to rpc's. You might use this if
13357your VxWorks target is a slow software simulator or is on the far side
13358of a thin network line.
13359@end table
104c1213 13360
8e04817f
AC
13361The following information on connecting to VxWorks was current when
13362this manual was produced; newer releases of VxWorks may use revised
13363procedures.
104c1213 13364
4644b6e3 13365@findex INCLUDE_RDB
8e04817f
AC
13366To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13367to include the remote debugging interface routines in the VxWorks
13368library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13369VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13370kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13371source debugging task @code{tRdbTask} when VxWorks is booted. For more
13372information on configuring and remaking VxWorks, see the manufacturer's
13373manual.
13374@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13375
8e04817f
AC
13376Once you have included @file{rdb.a} in your VxWorks system image and set
13377your Unix execution search path to find @value{GDBN}, you are ready to
13378run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13379@code{vxgdb}, depending on your installation).
104c1213 13380
8e04817f 13381@value{GDBN} comes up showing the prompt:
104c1213 13382
474c8240 13383@smallexample
8e04817f 13384(vxgdb)
474c8240 13385@end smallexample
104c1213 13386
8e04817f
AC
13387@menu
13388* VxWorks Connection:: Connecting to VxWorks
13389* VxWorks Download:: VxWorks download
13390* VxWorks Attach:: Running tasks
13391@end menu
104c1213 13392
8e04817f
AC
13393@node VxWorks Connection
13394@subsubsection Connecting to VxWorks
104c1213 13395
8e04817f
AC
13396The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13397network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13398
474c8240 13399@smallexample
8e04817f 13400(vxgdb) target vxworks tt
474c8240 13401@end smallexample
104c1213 13402
8e04817f
AC
13403@need 750
13404@value{GDBN} displays messages like these:
104c1213 13405
8e04817f
AC
13406@smallexample
13407Attaching remote machine across net...
13408Connected to tt.
13409@end smallexample
104c1213 13410
8e04817f
AC
13411@need 1000
13412@value{GDBN} then attempts to read the symbol tables of any object modules
13413loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13414these files by searching the directories listed in the command search
13415path (@pxref{Environment, ,Your program's environment}); if it fails
13416to find an object file, it displays a message such as:
5d161b24 13417
474c8240 13418@smallexample
8e04817f 13419prog.o: No such file or directory.
474c8240 13420@end smallexample
104c1213 13421
8e04817f
AC
13422When this happens, add the appropriate directory to the search path with
13423the @value{GDBN} command @code{path}, and execute the @code{target}
13424command again.
104c1213 13425
8e04817f
AC
13426@node VxWorks Download
13427@subsubsection VxWorks download
104c1213 13428
8e04817f
AC
13429@cindex download to VxWorks
13430If you have connected to the VxWorks target and you want to debug an
13431object that has not yet been loaded, you can use the @value{GDBN}
13432@code{load} command to download a file from Unix to VxWorks
13433incrementally. The object file given as an argument to the @code{load}
13434command is actually opened twice: first by the VxWorks target in order
13435to download the code, then by @value{GDBN} in order to read the symbol
13436table. This can lead to problems if the current working directories on
13437the two systems differ. If both systems have NFS mounted the same
13438filesystems, you can avoid these problems by using absolute paths.
13439Otherwise, it is simplest to set the working directory on both systems
13440to the directory in which the object file resides, and then to reference
13441the file by its name, without any path. For instance, a program
13442@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13443and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13444program, type this on VxWorks:
104c1213 13445
474c8240 13446@smallexample
8e04817f 13447-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13448@end smallexample
104c1213 13449
8e04817f
AC
13450@noindent
13451Then, in @value{GDBN}, type:
104c1213 13452
474c8240 13453@smallexample
8e04817f
AC
13454(vxgdb) cd @var{hostpath}/vw/demo/rdb
13455(vxgdb) load prog.o
474c8240 13456@end smallexample
104c1213 13457
8e04817f 13458@value{GDBN} displays a response similar to this:
104c1213 13459
8e04817f
AC
13460@smallexample
13461Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13462@end smallexample
104c1213 13463
8e04817f
AC
13464You can also use the @code{load} command to reload an object module
13465after editing and recompiling the corresponding source file. Note that
13466this makes @value{GDBN} delete all currently-defined breakpoints,
13467auto-displays, and convenience variables, and to clear the value
13468history. (This is necessary in order to preserve the integrity of
13469debugger's data structures that reference the target system's symbol
13470table.)
104c1213 13471
8e04817f
AC
13472@node VxWorks Attach
13473@subsubsection Running tasks
104c1213
JM
13474
13475@cindex running VxWorks tasks
13476You can also attach to an existing task using the @code{attach} command as
13477follows:
13478
474c8240 13479@smallexample
104c1213 13480(vxgdb) attach @var{task}
474c8240 13481@end smallexample
104c1213
JM
13482
13483@noindent
13484where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13485or suspended when you attach to it. Running tasks are suspended at
13486the time of attachment.
13487
6d2ebf8b 13488@node Embedded Processors
104c1213
JM
13489@section Embedded Processors
13490
13491This section goes into details specific to particular embedded
13492configurations.
13493
c45da7e6
EZ
13494@cindex send command to simulator
13495Whenever a specific embedded processor has a simulator, @value{GDBN}
13496allows to send an arbitrary command to the simulator.
13497
13498@table @code
13499@item sim @var{command}
13500@kindex sim@r{, a command}
13501Send an arbitrary @var{command} string to the simulator. Consult the
13502documentation for the specific simulator in use for information about
13503acceptable commands.
13504@end table
13505
7d86b5d5 13506
104c1213 13507@menu
c45da7e6 13508* ARM:: ARM RDI
172c2a43
KI
13509* H8/300:: Renesas H8/300
13510* H8/500:: Renesas H8/500
13511* M32R/D:: Renesas M32R/D
104c1213 13512* M68K:: Motorola M68K
104c1213 13513* MIPS Embedded:: MIPS Embedded
a37295f9 13514* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13515* PA:: HP PA Embedded
13516* PowerPC: PowerPC
172c2a43 13517* SH:: Renesas SH
104c1213
JM
13518* Sparclet:: Tsqware Sparclet
13519* Sparclite:: Fujitsu Sparclite
13520* ST2000:: Tandem ST2000
13521* Z8000:: Zilog Z8000
a64548ea
EZ
13522* AVR:: Atmel AVR
13523* CRIS:: CRIS
13524* Super-H:: Renesas Super-H
c45da7e6 13525* WinCE:: Windows CE child processes
104c1213
JM
13526@end menu
13527
6d2ebf8b 13528@node ARM
104c1213 13529@subsection ARM
c45da7e6 13530@cindex ARM RDI
104c1213
JM
13531
13532@table @code
8e04817f
AC
13533@kindex target rdi
13534@item target rdi @var{dev}
13535ARM Angel monitor, via RDI library interface to ADP protocol. You may
13536use this target to communicate with both boards running the Angel
13537monitor, or with the EmbeddedICE JTAG debug device.
13538
13539@kindex target rdp
13540@item target rdp @var{dev}
13541ARM Demon monitor.
13542
13543@end table
13544
e2f4edfd
EZ
13545@value{GDBN} provides the following ARM-specific commands:
13546
13547@table @code
13548@item set arm disassembler
13549@kindex set arm
13550This commands selects from a list of disassembly styles. The
13551@code{"std"} style is the standard style.
13552
13553@item show arm disassembler
13554@kindex show arm
13555Show the current disassembly style.
13556
13557@item set arm apcs32
13558@cindex ARM 32-bit mode
13559This command toggles ARM operation mode between 32-bit and 26-bit.
13560
13561@item show arm apcs32
13562Display the current usage of the ARM 32-bit mode.
13563
13564@item set arm fpu @var{fputype}
13565This command sets the ARM floating-point unit (FPU) type. The
13566argument @var{fputype} can be one of these:
13567
13568@table @code
13569@item auto
13570Determine the FPU type by querying the OS ABI.
13571@item softfpa
13572Software FPU, with mixed-endian doubles on little-endian ARM
13573processors.
13574@item fpa
13575GCC-compiled FPA co-processor.
13576@item softvfp
13577Software FPU with pure-endian doubles.
13578@item vfp
13579VFP co-processor.
13580@end table
13581
13582@item show arm fpu
13583Show the current type of the FPU.
13584
13585@item set arm abi
13586This command forces @value{GDBN} to use the specified ABI.
13587
13588@item show arm abi
13589Show the currently used ABI.
13590
13591@item set debug arm
13592Toggle whether to display ARM-specific debugging messages from the ARM
13593target support subsystem.
13594
13595@item show debug arm
13596Show whether ARM-specific debugging messages are enabled.
13597@end table
13598
c45da7e6
EZ
13599The following commands are available when an ARM target is debugged
13600using the RDI interface:
13601
13602@table @code
13603@item rdilogfile @r{[}@var{file}@r{]}
13604@kindex rdilogfile
13605@cindex ADP (Angel Debugger Protocol) logging
13606Set the filename for the ADP (Angel Debugger Protocol) packet log.
13607With an argument, sets the log file to the specified @var{file}. With
13608no argument, show the current log file name. The default log file is
13609@file{rdi.log}.
13610
13611@item rdilogenable @r{[}@var{arg}@r{]}
13612@kindex rdilogenable
13613Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13614enables logging, with an argument 0 or @code{"no"} disables it. With
13615no arguments displays the current setting. When logging is enabled,
13616ADP packets exchanged between @value{GDBN} and the RDI target device
13617are logged to a file.
13618
13619@item set rdiromatzero
13620@kindex set rdiromatzero
13621@cindex ROM at zero address, RDI
13622Tell @value{GDBN} whether the target has ROM at address 0. If on,
13623vector catching is disabled, so that zero address can be used. If off
13624(the default), vector catching is enabled. For this command to take
13625effect, it needs to be invoked prior to the @code{target rdi} command.
13626
13627@item show rdiromatzero
13628@kindex show rdiromatzero
13629Show the current setting of ROM at zero address.
13630
13631@item set rdiheartbeat
13632@kindex set rdiheartbeat
13633@cindex RDI heartbeat
13634Enable or disable RDI heartbeat packets. It is not recommended to
13635turn on this option, since it confuses ARM and EPI JTAG interface, as
13636well as the Angel monitor.
13637
13638@item show rdiheartbeat
13639@kindex show rdiheartbeat
13640Show the setting of RDI heartbeat packets.
13641@end table
13642
e2f4edfd 13643
8e04817f 13644@node H8/300
172c2a43 13645@subsection Renesas H8/300
8e04817f
AC
13646
13647@table @code
13648
13649@kindex target hms@r{, with H8/300}
13650@item target hms @var{dev}
172c2a43 13651A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13652Use special commands @code{device} and @code{speed} to control the serial
13653line and the communications speed used.
13654
13655@kindex target e7000@r{, with H8/300}
13656@item target e7000 @var{dev}
172c2a43 13657E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13658
13659@kindex target sh3@r{, with H8/300}
13660@kindex target sh3e@r{, with H8/300}
13661@item target sh3 @var{dev}
13662@itemx target sh3e @var{dev}
172c2a43 13663Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13664
13665@end table
13666
13667@cindex download to H8/300 or H8/500
13668@cindex H8/300 or H8/500 download
172c2a43
KI
13669@cindex download to Renesas SH
13670@cindex Renesas SH download
13671When you select remote debugging to a Renesas SH, H8/300, or H8/500
13672board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13673board and also opens it as the current executable target for
13674@value{GDBN} on your host (like the @code{file} command).
13675
13676@value{GDBN} needs to know these things to talk to your
172c2a43 13677Renesas SH, H8/300, or H8/500:
8e04817f
AC
13678
13679@enumerate
13680@item
13681that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13682for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13683emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13684the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13685H8/300, or H8/500.)
13686
13687@item
172c2a43 13688what serial device connects your host to your Renesas board (the first
8e04817f
AC
13689serial device available on your host is the default).
13690
13691@item
13692what speed to use over the serial device.
13693@end enumerate
13694
13695@menu
172c2a43
KI
13696* Renesas Boards:: Connecting to Renesas boards.
13697* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13698* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13699@end menu
13700
172c2a43
KI
13701@node Renesas Boards
13702@subsubsection Connecting to Renesas boards
8e04817f
AC
13703
13704@c only for Unix hosts
13705@kindex device
172c2a43 13706@cindex serial device, Renesas micros
8e04817f
AC
13707Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13708need to explicitly set the serial device. The default @var{port} is the
13709first available port on your host. This is only necessary on Unix
13710hosts, where it is typically something like @file{/dev/ttya}.
13711
13712@kindex speed
172c2a43 13713@cindex serial line speed, Renesas micros
8e04817f
AC
13714@code{@value{GDBN}} has another special command to set the communications
13715speed: @samp{speed @var{bps}}. This command also is only used from Unix
13716hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13717the DOS @code{mode} command (for instance,
13718@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13719
13720The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13721use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13722use a DOS host,
13723@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13724called @code{asynctsr} to communicate with the development board
13725through a PC serial port. You must also use the DOS @code{mode} command
13726to set up the serial port on the DOS side.
13727
13728The following sample session illustrates the steps needed to start a
13729program under @value{GDBN} control on an H8/300. The example uses a
13730sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13731the Renesas SH and the H8/500.
8e04817f
AC
13732
13733First hook up your development board. In this example, we use a
13734board attached to serial port @code{COM2}; if you use a different serial
13735port, substitute its name in the argument of the @code{mode} command.
13736When you call @code{asynctsr}, the auxiliary comms program used by the
13737debugger, you give it just the numeric part of the serial port's name;
13738for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13739@code{COM2}.
13740
474c8240 13741@smallexample
8e04817f
AC
13742C:\H8300\TEST> asynctsr 2
13743C:\H8300\TEST> mode com2:9600,n,8,1,p
13744
13745Resident portion of MODE loaded
13746
13747COM2: 9600, n, 8, 1, p
13748
474c8240 13749@end smallexample
8e04817f
AC
13750
13751@quotation
13752@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13753@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13754disable it, or even boot without it, to use @code{asynctsr} to control
13755your development board.
13756@end quotation
13757
13758@kindex target hms@r{, and serial protocol}
13759Now that serial communications are set up, and the development board is
9c16f35a 13760connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13761the name of your program as the argument. @code{@value{GDBN}} prompts
13762you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13763commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13764cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13765download your program to the board. @code{load} displays the names of
13766the program's sections, and a @samp{*} for each 2K of data downloaded.
13767(If you want to refresh @value{GDBN} data on symbols or on the
13768executable file without downloading, use the @value{GDBN} commands
13769@code{file} or @code{symbol-file}. These commands, and @code{load}
13770itself, are described in @ref{Files,,Commands to specify files}.)
13771
13772@smallexample
13773(eg-C:\H8300\TEST) @value{GDBP} t.x
13774@value{GDBN} is free software and you are welcome to distribute copies
13775 of it under certain conditions; type "show copying" to see
13776 the conditions.
13777There is absolutely no warranty for @value{GDBN}; type "show warranty"
13778for details.
13779@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13780(@value{GDBP}) target hms
13781Connected to remote H8/300 HMS system.
13782(@value{GDBP}) load t.x
13783.text : 0x8000 .. 0xabde ***********
13784.data : 0xabde .. 0xad30 *
13785.stack : 0xf000 .. 0xf014 *
13786@end smallexample
13787
13788At this point, you're ready to run or debug your program. From here on,
13789you can use all the usual @value{GDBN} commands. The @code{break} command
13790sets breakpoints; the @code{run} command starts your program;
13791@code{print} or @code{x} display data; the @code{continue} command
13792resumes execution after stopping at a breakpoint. You can use the
13793@code{help} command at any time to find out more about @value{GDBN} commands.
13794
13795Remember, however, that @emph{operating system} facilities aren't
13796available on your development board; for example, if your program hangs,
13797you can't send an interrupt---but you can press the @sc{reset} switch!
13798
13799Use the @sc{reset} button on the development board
13800@itemize @bullet
13801@item
13802to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13803no way to pass an interrupt signal to the development board); and
13804
13805@item
13806to return to the @value{GDBN} command prompt after your program finishes
13807normally. The communications protocol provides no other way for @value{GDBN}
13808to detect program completion.
13809@end itemize
13810
13811In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13812development board as a ``normal exit'' of your program.
13813
172c2a43 13814@node Renesas ICE
8e04817f
AC
13815@subsubsection Using the E7000 in-circuit emulator
13816
172c2a43 13817@kindex target e7000@r{, with Renesas ICE}
8e04817f 13818You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13819Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13820e7000} command to connect @value{GDBN} to your E7000:
13821
13822@table @code
13823@item target e7000 @var{port} @var{speed}
13824Use this form if your E7000 is connected to a serial port. The
13825@var{port} argument identifies what serial port to use (for example,
13826@samp{com2}). The third argument is the line speed in bits per second
13827(for example, @samp{9600}).
13828
13829@item target e7000 @var{hostname}
13830If your E7000 is installed as a host on a TCP/IP network, you can just
13831specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13832@end table
13833
ba04e063
EZ
13834The following special commands are available when debugging with the
13835Renesas E7000 ICE:
13836
13837@table @code
13838@item e7000 @var{command}
13839@kindex e7000
13840@cindex send command to E7000 monitor
13841This sends the specified @var{command} to the E7000 monitor.
13842
13843@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13844@kindex ftplogin@r{, E7000}
13845This command records information for subsequent interface with the
13846E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13847named @var{machine} using specified @var{username} and @var{password},
13848and then chdir to the named directory @var{dir}.
13849
13850@item ftpload @var{file}
13851@kindex ftpload@r{, E7000}
13852This command uses credentials recorded by @code{ftplogin} to fetch and
13853load the named @var{file} from the E7000 monitor.
13854
13855@item drain
13856@kindex drain@r{, E7000}
13857This command drains any pending text buffers stored on the E7000.
13858
13859@item set usehardbreakpoints
13860@itemx show usehardbreakpoints
13861@kindex set usehardbreakpoints@r{, E7000}
13862@kindex show usehardbreakpoints@r{, E7000}
13863@cindex hardware breakpoints, and E7000
13864These commands set and show the use of hardware breakpoints for all
13865breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13866more information about using hardware breakpoints selectively.
13867@end table
13868
172c2a43
KI
13869@node Renesas Special
13870@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13871
13872Some @value{GDBN} commands are available only for the H8/300:
13873
13874@table @code
13875
13876@kindex set machine
13877@kindex show machine
13878@item set machine h8300
13879@itemx set machine h8300h
13880Condition @value{GDBN} for one of the two variants of the H8/300
13881architecture with @samp{set machine}. You can use @samp{show machine}
13882to check which variant is currently in effect.
104c1213
JM
13883
13884@end table
13885
8e04817f
AC
13886@node H8/500
13887@subsection H8/500
104c1213
JM
13888
13889@table @code
13890
8e04817f
AC
13891@kindex set memory @var{mod}
13892@cindex memory models, H8/500
13893@item set memory @var{mod}
13894@itemx show memory
13895Specify which H8/500 memory model (@var{mod}) you are using with
13896@samp{set memory}; check which memory model is in effect with @samp{show
13897memory}. The accepted values for @var{mod} are @code{small},
13898@code{big}, @code{medium}, and @code{compact}.
104c1213 13899
8e04817f 13900@end table
104c1213 13901
8e04817f 13902@node M32R/D
ba04e063 13903@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13904
13905@table @code
8e04817f
AC
13906@kindex target m32r
13907@item target m32r @var{dev}
172c2a43 13908Renesas M32R/D ROM monitor.
8e04817f 13909
fb3e19c0
KI
13910@kindex target m32rsdi
13911@item target m32rsdi @var{dev}
13912Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13913@end table
13914
13915The following @value{GDBN} commands are specific to the M32R monitor:
13916
13917@table @code
13918@item set download-path @var{path}
13919@kindex set download-path
13920@cindex find downloadable @sc{srec} files (M32R)
13921Set the default path for finding donwloadable @sc{srec} files.
13922
13923@item show download-path
13924@kindex show download-path
13925Show the default path for downloadable @sc{srec} files.
fb3e19c0 13926
721c2651
EZ
13927@item set board-address @var{addr}
13928@kindex set board-address
13929@cindex M32-EVA target board address
13930Set the IP address for the M32R-EVA target board.
13931
13932@item show board-address
13933@kindex show board-address
13934Show the current IP address of the target board.
13935
13936@item set server-address @var{addr}
13937@kindex set server-address
13938@cindex download server address (M32R)
13939Set the IP address for the download server, which is the @value{GDBN}'s
13940host machine.
13941
13942@item show server-address
13943@kindex show server-address
13944Display the IP address of the download server.
13945
13946@item upload @r{[}@var{file}@r{]}
13947@kindex upload@r{, M32R}
13948Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13949upload capability. If no @var{file} argument is given, the current
13950executable file is uploaded.
13951
13952@item tload @r{[}@var{file}@r{]}
13953@kindex tload@r{, M32R}
13954Test the @code{upload} command.
8e04817f
AC
13955@end table
13956
ba04e063
EZ
13957The following commands are available for M32R/SDI:
13958
13959@table @code
13960@item sdireset
13961@kindex sdireset
13962@cindex reset SDI connection, M32R
13963This command resets the SDI connection.
13964
13965@item sdistatus
13966@kindex sdistatus
13967This command shows the SDI connection status.
13968
13969@item debug_chaos
13970@kindex debug_chaos
13971@cindex M32R/Chaos debugging
13972Instructs the remote that M32R/Chaos debugging is to be used.
13973
13974@item use_debug_dma
13975@kindex use_debug_dma
13976Instructs the remote to use the DEBUG_DMA method of accessing memory.
13977
13978@item use_mon_code
13979@kindex use_mon_code
13980Instructs the remote to use the MON_CODE method of accessing memory.
13981
13982@item use_ib_break
13983@kindex use_ib_break
13984Instructs the remote to set breakpoints by IB break.
13985
13986@item use_dbt_break
13987@kindex use_dbt_break
13988Instructs the remote to set breakpoints by DBT.
13989@end table
13990
8e04817f
AC
13991@node M68K
13992@subsection M68k
13993
13994The Motorola m68k configuration includes ColdFire support, and
13995target command for the following ROM monitors.
13996
13997@table @code
13998
13999@kindex target abug
14000@item target abug @var{dev}
14001ABug ROM monitor for M68K.
14002
14003@kindex target cpu32bug
14004@item target cpu32bug @var{dev}
14005CPU32BUG monitor, running on a CPU32 (M68K) board.
14006
14007@kindex target dbug
14008@item target dbug @var{dev}
14009dBUG ROM monitor for Motorola ColdFire.
14010
14011@kindex target est
14012@item target est @var{dev}
14013EST-300 ICE monitor, running on a CPU32 (M68K) board.
14014
14015@kindex target rom68k
14016@item target rom68k @var{dev}
14017ROM 68K monitor, running on an M68K IDP board.
14018
14019@end table
14020
8e04817f
AC
14021@table @code
14022
14023@kindex target rombug
14024@item target rombug @var{dev}
14025ROMBUG ROM monitor for OS/9000.
14026
14027@end table
14028
8e04817f
AC
14029@node MIPS Embedded
14030@subsection MIPS Embedded
14031
14032@cindex MIPS boards
14033@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14034MIPS board attached to a serial line. This is available when
14035you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14036
8e04817f
AC
14037@need 1000
14038Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14039
8e04817f
AC
14040@table @code
14041@item target mips @var{port}
14042@kindex target mips @var{port}
14043To run a program on the board, start up @code{@value{GDBP}} with the
14044name of your program as the argument. To connect to the board, use the
14045command @samp{target mips @var{port}}, where @var{port} is the name of
14046the serial port connected to the board. If the program has not already
14047been downloaded to the board, you may use the @code{load} command to
14048download it. You can then use all the usual @value{GDBN} commands.
104c1213 14049
8e04817f
AC
14050For example, this sequence connects to the target board through a serial
14051port, and loads and runs a program called @var{prog} through the
14052debugger:
104c1213 14053
474c8240 14054@smallexample
8e04817f
AC
14055host$ @value{GDBP} @var{prog}
14056@value{GDBN} is free software and @dots{}
14057(@value{GDBP}) target mips /dev/ttyb
14058(@value{GDBP}) load @var{prog}
14059(@value{GDBP}) run
474c8240 14060@end smallexample
104c1213 14061
8e04817f
AC
14062@item target mips @var{hostname}:@var{portnumber}
14063On some @value{GDBN} host configurations, you can specify a TCP
14064connection (for instance, to a serial line managed by a terminal
14065concentrator) instead of a serial port, using the syntax
14066@samp{@var{hostname}:@var{portnumber}}.
104c1213 14067
8e04817f
AC
14068@item target pmon @var{port}
14069@kindex target pmon @var{port}
14070PMON ROM monitor.
104c1213 14071
8e04817f
AC
14072@item target ddb @var{port}
14073@kindex target ddb @var{port}
14074NEC's DDB variant of PMON for Vr4300.
104c1213 14075
8e04817f
AC
14076@item target lsi @var{port}
14077@kindex target lsi @var{port}
14078LSI variant of PMON.
104c1213 14079
8e04817f
AC
14080@kindex target r3900
14081@item target r3900 @var{dev}
14082Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14083
8e04817f
AC
14084@kindex target array
14085@item target array @var{dev}
14086Array Tech LSI33K RAID controller board.
104c1213 14087
8e04817f 14088@end table
104c1213 14089
104c1213 14090
8e04817f
AC
14091@noindent
14092@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14093
8e04817f 14094@table @code
8e04817f
AC
14095@item set mipsfpu double
14096@itemx set mipsfpu single
14097@itemx set mipsfpu none
a64548ea 14098@itemx set mipsfpu auto
8e04817f
AC
14099@itemx show mipsfpu
14100@kindex set mipsfpu
14101@kindex show mipsfpu
14102@cindex MIPS remote floating point
14103@cindex floating point, MIPS remote
14104If your target board does not support the MIPS floating point
14105coprocessor, you should use the command @samp{set mipsfpu none} (if you
14106need this, you may wish to put the command in your @value{GDBN} init
14107file). This tells @value{GDBN} how to find the return value of
14108functions which return floating point values. It also allows
14109@value{GDBN} to avoid saving the floating point registers when calling
14110functions on the board. If you are using a floating point coprocessor
14111with only single precision floating point support, as on the @sc{r4650}
14112processor, use the command @samp{set mipsfpu single}. The default
14113double precision floating point coprocessor may be selected using
14114@samp{set mipsfpu double}.
104c1213 14115
8e04817f
AC
14116In previous versions the only choices were double precision or no
14117floating point, so @samp{set mipsfpu on} will select double precision
14118and @samp{set mipsfpu off} will select no floating point.
104c1213 14119
8e04817f
AC
14120As usual, you can inquire about the @code{mipsfpu} variable with
14121@samp{show mipsfpu}.
104c1213 14122
8e04817f
AC
14123@item set timeout @var{seconds}
14124@itemx set retransmit-timeout @var{seconds}
14125@itemx show timeout
14126@itemx show retransmit-timeout
14127@cindex @code{timeout}, MIPS protocol
14128@cindex @code{retransmit-timeout}, MIPS protocol
14129@kindex set timeout
14130@kindex show timeout
14131@kindex set retransmit-timeout
14132@kindex show retransmit-timeout
14133You can control the timeout used while waiting for a packet, in the MIPS
14134remote protocol, with the @code{set timeout @var{seconds}} command. The
14135default is 5 seconds. Similarly, you can control the timeout used while
14136waiting for an acknowledgement of a packet with the @code{set
14137retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14138You can inspect both values with @code{show timeout} and @code{show
14139retransmit-timeout}. (These commands are @emph{only} available when
14140@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14141
8e04817f
AC
14142The timeout set by @code{set timeout} does not apply when @value{GDBN}
14143is waiting for your program to stop. In that case, @value{GDBN} waits
14144forever because it has no way of knowing how long the program is going
14145to run before stopping.
ba04e063
EZ
14146
14147@item set syn-garbage-limit @var{num}
14148@kindex set syn-garbage-limit@r{, MIPS remote}
14149@cindex synchronize with remote MIPS target
14150Limit the maximum number of characters @value{GDBN} should ignore when
14151it tries to synchronize with the remote target. The default is 10
14152characters. Setting the limit to -1 means there's no limit.
14153
14154@item show syn-garbage-limit
14155@kindex show syn-garbage-limit@r{, MIPS remote}
14156Show the current limit on the number of characters to ignore when
14157trying to synchronize with the remote system.
14158
14159@item set monitor-prompt @var{prompt}
14160@kindex set monitor-prompt@r{, MIPS remote}
14161@cindex remote monitor prompt
14162Tell @value{GDBN} to expect the specified @var{prompt} string from the
14163remote monitor. The default depends on the target:
14164@table @asis
14165@item pmon target
14166@samp{PMON}
14167@item ddb target
14168@samp{NEC010}
14169@item lsi target
14170@samp{PMON>}
14171@end table
14172
14173@item show monitor-prompt
14174@kindex show monitor-prompt@r{, MIPS remote}
14175Show the current strings @value{GDBN} expects as the prompt from the
14176remote monitor.
14177
14178@item set monitor-warnings
14179@kindex set monitor-warnings@r{, MIPS remote}
14180Enable or disable monitor warnings about hardware breakpoints. This
14181has effect only for the @code{lsi} target. When on, @value{GDBN} will
14182display warning messages whose codes are returned by the @code{lsi}
14183PMON monitor for breakpoint commands.
14184
14185@item show monitor-warnings
14186@kindex show monitor-warnings@r{, MIPS remote}
14187Show the current setting of printing monitor warnings.
14188
14189@item pmon @var{command}
14190@kindex pmon@r{, MIPS remote}
14191@cindex send PMON command
14192This command allows sending an arbitrary @var{command} string to the
14193monitor. The monitor must be in debug mode for this to work.
8e04817f 14194@end table
104c1213 14195
a37295f9
MM
14196@node OpenRISC 1000
14197@subsection OpenRISC 1000
14198@cindex OpenRISC 1000
14199
14200@cindex or1k boards
14201See OR1k Architecture document (@uref{www.opencores.org}) for more information
14202about platform and commands.
14203
14204@table @code
14205
14206@kindex target jtag
14207@item target jtag jtag://@var{host}:@var{port}
14208
14209Connects to remote JTAG server.
14210JTAG remote server can be either an or1ksim or JTAG server,
14211connected via parallel port to the board.
14212
14213Example: @code{target jtag jtag://localhost:9999}
14214
14215@kindex or1ksim
14216@item or1ksim @var{command}
14217If connected to @code{or1ksim} OpenRISC 1000 Architectural
14218Simulator, proprietary commands can be executed.
14219
14220@kindex info or1k spr
14221@item info or1k spr
14222Displays spr groups.
14223
14224@item info or1k spr @var{group}
14225@itemx info or1k spr @var{groupno}
14226Displays register names in selected group.
14227
14228@item info or1k spr @var{group} @var{register}
14229@itemx info or1k spr @var{register}
14230@itemx info or1k spr @var{groupno} @var{registerno}
14231@itemx info or1k spr @var{registerno}
14232Shows information about specified spr register.
14233
14234@kindex spr
14235@item spr @var{group} @var{register} @var{value}
14236@itemx spr @var{register @var{value}}
14237@itemx spr @var{groupno} @var{registerno @var{value}}
14238@itemx spr @var{registerno @var{value}}
14239Writes @var{value} to specified spr register.
14240@end table
14241
14242Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14243It is very similar to @value{GDBN} trace, except it does not interfere with normal
14244program execution and is thus much faster. Hardware breakpoints/watchpoint
14245triggers can be set using:
14246@table @code
14247@item $LEA/$LDATA
14248Load effective address/data
14249@item $SEA/$SDATA
14250Store effective address/data
14251@item $AEA/$ADATA
14252Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14253@item $FETCH
14254Fetch data
14255@end table
14256
14257When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14258@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14259
14260@code{htrace} commands:
14261@cindex OpenRISC 1000 htrace
14262@table @code
14263@kindex hwatch
14264@item hwatch @var{conditional}
14265Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14266or Data. For example:
14267
14268@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14269
14270@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14271
4644b6e3 14272@kindex htrace
a37295f9
MM
14273@item htrace info
14274Display information about current HW trace configuration.
14275
a37295f9
MM
14276@item htrace trigger @var{conditional}
14277Set starting criteria for HW trace.
14278
a37295f9
MM
14279@item htrace qualifier @var{conditional}
14280Set acquisition qualifier for HW trace.
14281
a37295f9
MM
14282@item htrace stop @var{conditional}
14283Set HW trace stopping criteria.
14284
f153cc92 14285@item htrace record [@var{data}]*
a37295f9
MM
14286Selects the data to be recorded, when qualifier is met and HW trace was
14287triggered.
14288
a37295f9 14289@item htrace enable
a37295f9
MM
14290@itemx htrace disable
14291Enables/disables the HW trace.
14292
f153cc92 14293@item htrace rewind [@var{filename}]
a37295f9
MM
14294Clears currently recorded trace data.
14295
14296If filename is specified, new trace file is made and any newly collected data
14297will be written there.
14298
f153cc92 14299@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14300Prints trace buffer, using current record configuration.
14301
a37295f9
MM
14302@item htrace mode continuous
14303Set continuous trace mode.
14304
a37295f9
MM
14305@item htrace mode suspend
14306Set suspend trace mode.
14307
14308@end table
14309
8e04817f
AC
14310@node PowerPC
14311@subsection PowerPC
104c1213
JM
14312
14313@table @code
8e04817f
AC
14314@kindex target dink32
14315@item target dink32 @var{dev}
14316DINK32 ROM monitor.
104c1213 14317
8e04817f
AC
14318@kindex target ppcbug
14319@item target ppcbug @var{dev}
14320@kindex target ppcbug1
14321@item target ppcbug1 @var{dev}
14322PPCBUG ROM monitor for PowerPC.
104c1213 14323
8e04817f
AC
14324@kindex target sds
14325@item target sds @var{dev}
14326SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14327@end table
8e04817f 14328
c45da7e6
EZ
14329@cindex SDS protocol
14330The following commands specifi to the SDS protocol are supported
14331by@value{GDBN}:
14332
14333@table @code
14334@item set sdstimeout @var{nsec}
14335@kindex set sdstimeout
14336Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14337default is 2 seconds.
14338
14339@item show sdstimeout
14340@kindex show sdstimeout
14341Show the current value of the SDS timeout.
14342
14343@item sds @var{command}
14344@kindex sds@r{, a command}
14345Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14346@end table
14347
c45da7e6 14348
8e04817f
AC
14349@node PA
14350@subsection HP PA Embedded
104c1213
JM
14351
14352@table @code
14353
8e04817f
AC
14354@kindex target op50n
14355@item target op50n @var{dev}
14356OP50N monitor, running on an OKI HPPA board.
14357
14358@kindex target w89k
14359@item target w89k @var{dev}
14360W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14361
14362@end table
14363
8e04817f 14364@node SH
172c2a43 14365@subsection Renesas SH
104c1213
JM
14366
14367@table @code
14368
172c2a43 14369@kindex target hms@r{, with Renesas SH}
8e04817f 14370@item target hms @var{dev}
172c2a43 14371A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14372commands @code{device} and @code{speed} to control the serial line and
14373the communications speed used.
104c1213 14374
172c2a43 14375@kindex target e7000@r{, with Renesas SH}
8e04817f 14376@item target e7000 @var{dev}
172c2a43 14377E7000 emulator for Renesas SH.
104c1213 14378
8e04817f
AC
14379@kindex target sh3@r{, with SH}
14380@kindex target sh3e@r{, with SH}
14381@item target sh3 @var{dev}
14382@item target sh3e @var{dev}
172c2a43 14383Renesas SH-3 and SH-3E target systems.
104c1213 14384
8e04817f 14385@end table
104c1213 14386
8e04817f
AC
14387@node Sparclet
14388@subsection Tsqware Sparclet
104c1213 14389
8e04817f
AC
14390@cindex Sparclet
14391
14392@value{GDBN} enables developers to debug tasks running on
14393Sparclet targets from a Unix host.
14394@value{GDBN} uses code that runs on
14395both the Unix host and on the Sparclet target. The program
14396@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14397
8e04817f
AC
14398@table @code
14399@item remotetimeout @var{args}
14400@kindex remotetimeout
14401@value{GDBN} supports the option @code{remotetimeout}.
14402This option is set by the user, and @var{args} represents the number of
14403seconds @value{GDBN} waits for responses.
104c1213
JM
14404@end table
14405
8e04817f
AC
14406@cindex compiling, on Sparclet
14407When compiling for debugging, include the options @samp{-g} to get debug
14408information and @samp{-Ttext} to relocate the program to where you wish to
14409load it on the target. You may also want to add the options @samp{-n} or
14410@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14411
474c8240 14412@smallexample
8e04817f 14413sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14414@end smallexample
104c1213 14415
8e04817f 14416You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14417
474c8240 14418@smallexample
8e04817f 14419sparclet-aout-objdump --headers --syms prog
474c8240 14420@end smallexample
104c1213 14421
8e04817f
AC
14422@cindex running, on Sparclet
14423Once you have set
14424your Unix execution search path to find @value{GDBN}, you are ready to
14425run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14426(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14427
8e04817f
AC
14428@value{GDBN} comes up showing the prompt:
14429
474c8240 14430@smallexample
8e04817f 14431(gdbslet)
474c8240 14432@end smallexample
104c1213
JM
14433
14434@menu
8e04817f
AC
14435* Sparclet File:: Setting the file to debug
14436* Sparclet Connection:: Connecting to Sparclet
14437* Sparclet Download:: Sparclet download
14438* Sparclet Execution:: Running and debugging
104c1213
JM
14439@end menu
14440
8e04817f
AC
14441@node Sparclet File
14442@subsubsection Setting file to debug
104c1213 14443
8e04817f 14444The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14445
474c8240 14446@smallexample
8e04817f 14447(gdbslet) file prog
474c8240 14448@end smallexample
104c1213 14449
8e04817f
AC
14450@need 1000
14451@value{GDBN} then attempts to read the symbol table of @file{prog}.
14452@value{GDBN} locates
14453the file by searching the directories listed in the command search
14454path.
14455If the file was compiled with debug information (option "-g"), source
14456files will be searched as well.
14457@value{GDBN} locates
14458the source files by searching the directories listed in the directory search
14459path (@pxref{Environment, ,Your program's environment}).
14460If it fails
14461to find a file, it displays a message such as:
104c1213 14462
474c8240 14463@smallexample
8e04817f 14464prog: No such file or directory.
474c8240 14465@end smallexample
104c1213 14466
8e04817f
AC
14467When this happens, add the appropriate directories to the search paths with
14468the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14469@code{target} command again.
104c1213 14470
8e04817f
AC
14471@node Sparclet Connection
14472@subsubsection Connecting to Sparclet
104c1213 14473
8e04817f
AC
14474The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14475To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14476
474c8240 14477@smallexample
8e04817f
AC
14478(gdbslet) target sparclet /dev/ttya
14479Remote target sparclet connected to /dev/ttya
14480main () at ../prog.c:3
474c8240 14481@end smallexample
104c1213 14482
8e04817f
AC
14483@need 750
14484@value{GDBN} displays messages like these:
104c1213 14485
474c8240 14486@smallexample
8e04817f 14487Connected to ttya.
474c8240 14488@end smallexample
104c1213 14489
8e04817f
AC
14490@node Sparclet Download
14491@subsubsection Sparclet download
104c1213 14492
8e04817f
AC
14493@cindex download to Sparclet
14494Once connected to the Sparclet target,
14495you can use the @value{GDBN}
14496@code{load} command to download the file from the host to the target.
14497The file name and load offset should be given as arguments to the @code{load}
14498command.
14499Since the file format is aout, the program must be loaded to the starting
14500address. You can use @code{objdump} to find out what this value is. The load
14501offset is an offset which is added to the VMA (virtual memory address)
14502of each of the file's sections.
14503For instance, if the program
14504@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14505and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14506
474c8240 14507@smallexample
8e04817f
AC
14508(gdbslet) load prog 0x12010000
14509Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14510@end smallexample
104c1213 14511
8e04817f
AC
14512If the code is loaded at a different address then what the program was linked
14513to, you may need to use the @code{section} and @code{add-symbol-file} commands
14514to tell @value{GDBN} where to map the symbol table.
14515
14516@node Sparclet Execution
14517@subsubsection Running and debugging
14518
14519@cindex running and debugging Sparclet programs
14520You can now begin debugging the task using @value{GDBN}'s execution control
14521commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14522manual for the list of commands.
14523
474c8240 14524@smallexample
8e04817f
AC
14525(gdbslet) b main
14526Breakpoint 1 at 0x12010000: file prog.c, line 3.
14527(gdbslet) run
14528Starting program: prog
14529Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145303 char *symarg = 0;
14531(gdbslet) step
145324 char *execarg = "hello!";
14533(gdbslet)
474c8240 14534@end smallexample
8e04817f
AC
14535
14536@node Sparclite
14537@subsection Fujitsu Sparclite
104c1213
JM
14538
14539@table @code
14540
8e04817f
AC
14541@kindex target sparclite
14542@item target sparclite @var{dev}
14543Fujitsu sparclite boards, used only for the purpose of loading.
14544You must use an additional command to debug the program.
14545For example: target remote @var{dev} using @value{GDBN} standard
14546remote protocol.
104c1213
JM
14547
14548@end table
14549
8e04817f
AC
14550@node ST2000
14551@subsection Tandem ST2000
104c1213 14552
8e04817f
AC
14553@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14554STDBUG protocol.
104c1213 14555
8e04817f
AC
14556To connect your ST2000 to the host system, see the manufacturer's
14557manual. Once the ST2000 is physically attached, you can run:
104c1213 14558
474c8240 14559@smallexample
8e04817f 14560target st2000 @var{dev} @var{speed}
474c8240 14561@end smallexample
104c1213 14562
8e04817f
AC
14563@noindent
14564to establish it as your debugging environment. @var{dev} is normally
14565the name of a serial device, such as @file{/dev/ttya}, connected to the
14566ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14567connection (for example, to a serial line attached via a terminal
14568concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14569
8e04817f
AC
14570The @code{load} and @code{attach} commands are @emph{not} defined for
14571this target; you must load your program into the ST2000 as you normally
14572would for standalone operation. @value{GDBN} reads debugging information
14573(such as symbols) from a separate, debugging version of the program
14574available on your host computer.
14575@c FIXME!! This is terribly vague; what little content is here is
14576@c basically hearsay.
104c1213 14577
8e04817f
AC
14578@cindex ST2000 auxiliary commands
14579These auxiliary @value{GDBN} commands are available to help you with the ST2000
14580environment:
104c1213 14581
8e04817f
AC
14582@table @code
14583@item st2000 @var{command}
14584@kindex st2000 @var{cmd}
14585@cindex STDBUG commands (ST2000)
14586@cindex commands to STDBUG (ST2000)
14587Send a @var{command} to the STDBUG monitor. See the manufacturer's
14588manual for available commands.
104c1213 14589
8e04817f
AC
14590@item connect
14591@cindex connect (to STDBUG)
14592Connect the controlling terminal to the STDBUG command monitor. When
14593you are done interacting with STDBUG, typing either of two character
14594sequences gets you back to the @value{GDBN} command prompt:
14595@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14596@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14597@end table
14598
8e04817f
AC
14599@node Z8000
14600@subsection Zilog Z8000
104c1213 14601
8e04817f
AC
14602@cindex Z8000
14603@cindex simulator, Z8000
14604@cindex Zilog Z8000 simulator
104c1213 14605
8e04817f
AC
14606When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14607a Z8000 simulator.
14608
14609For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14610unsegmented variant of the Z8000 architecture) or the Z8001 (the
14611segmented variant). The simulator recognizes which architecture is
14612appropriate by inspecting the object code.
104c1213 14613
8e04817f
AC
14614@table @code
14615@item target sim @var{args}
14616@kindex sim
14617@kindex target sim@r{, with Z8000}
14618Debug programs on a simulated CPU. If the simulator supports setup
14619options, specify them via @var{args}.
104c1213
JM
14620@end table
14621
8e04817f
AC
14622@noindent
14623After specifying this target, you can debug programs for the simulated
14624CPU in the same style as programs for your host computer; use the
14625@code{file} command to load a new program image, the @code{run} command
14626to run your program, and so on.
14627
14628As well as making available all the usual machine registers
14629(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14630additional items of information as specially named registers:
104c1213
JM
14631
14632@table @code
14633
8e04817f
AC
14634@item cycles
14635Counts clock-ticks in the simulator.
104c1213 14636
8e04817f
AC
14637@item insts
14638Counts instructions run in the simulator.
104c1213 14639
8e04817f
AC
14640@item time
14641Execution time in 60ths of a second.
104c1213 14642
8e04817f 14643@end table
104c1213 14644
8e04817f
AC
14645You can refer to these values in @value{GDBN} expressions with the usual
14646conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14647conditional breakpoint that suspends only after at least 5000
14648simulated clock ticks.
104c1213 14649
a64548ea
EZ
14650@node AVR
14651@subsection Atmel AVR
14652@cindex AVR
14653
14654When configured for debugging the Atmel AVR, @value{GDBN} supports the
14655following AVR-specific commands:
14656
14657@table @code
14658@item info io_registers
14659@kindex info io_registers@r{, AVR}
14660@cindex I/O registers (Atmel AVR)
14661This command displays information about the AVR I/O registers. For
14662each register, @value{GDBN} prints its number and value.
14663@end table
14664
14665@node CRIS
14666@subsection CRIS
14667@cindex CRIS
14668
14669When configured for debugging CRIS, @value{GDBN} provides the
14670following CRIS-specific commands:
14671
14672@table @code
14673@item set cris-version @var{ver}
14674@cindex CRIS version
e22e55c9
OF
14675Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14676The CRIS version affects register names and sizes. This command is useful in
14677case autodetection of the CRIS version fails.
a64548ea
EZ
14678
14679@item show cris-version
14680Show the current CRIS version.
14681
14682@item set cris-dwarf2-cfi
14683@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14684Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14685Change to @samp{off} when using @code{gcc-cris} whose version is below
14686@code{R59}.
a64548ea
EZ
14687
14688@item show cris-dwarf2-cfi
14689Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14690
14691@item set cris-mode @var{mode}
14692@cindex CRIS mode
14693Set the current CRIS mode to @var{mode}. It should only be changed when
14694debugging in guru mode, in which case it should be set to
14695@samp{guru} (the default is @samp{normal}).
14696
14697@item show cris-mode
14698Show the current CRIS mode.
a64548ea
EZ
14699@end table
14700
14701@node Super-H
14702@subsection Renesas Super-H
14703@cindex Super-H
14704
14705For the Renesas Super-H processor, @value{GDBN} provides these
14706commands:
14707
14708@table @code
14709@item regs
14710@kindex regs@r{, Super-H}
14711Show the values of all Super-H registers.
14712@end table
14713
c45da7e6
EZ
14714@node WinCE
14715@subsection Windows CE
14716@cindex Windows CE
14717
14718The following commands are available for Windows CE:
14719
14720@table @code
14721@item set remotedirectory @var{dir}
14722@kindex set remotedirectory
14723Tell @value{GDBN} to upload files from the named directory @var{dir}.
14724The default is @file{/gdb}, i.e.@: the root directory on the current
14725drive.
14726
14727@item show remotedirectory
14728@kindex show remotedirectory
14729Show the current value of the upload directory.
14730
14731@item set remoteupload @var{method}
14732@kindex set remoteupload
14733Set the method used to upload files to remote device. Valid values
14734for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14735The default is @samp{newer}.
14736
14737@item show remoteupload
14738@kindex show remoteupload
14739Show the current setting of the upload method.
14740
14741@item set remoteaddhost
14742@kindex set remoteaddhost
14743Tell @value{GDBN} whether to add this host to the remote stub's
14744arguments when you debug over a network.
14745
14746@item show remoteaddhost
14747@kindex show remoteaddhost
14748Show whether to add this host to remote stub's arguments when
14749debugging over a network.
14750@end table
14751
a64548ea 14752
8e04817f
AC
14753@node Architectures
14754@section Architectures
104c1213 14755
8e04817f
AC
14756This section describes characteristics of architectures that affect
14757all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14758
8e04817f 14759@menu
9c16f35a 14760* i386::
8e04817f
AC
14761* A29K::
14762* Alpha::
14763* MIPS::
a64548ea 14764* HPPA:: HP PA architecture
8e04817f 14765@end menu
104c1213 14766
9c16f35a
EZ
14767@node i386
14768@subsection x86 Architecture-specific issues.
14769
14770@table @code
14771@item set struct-convention @var{mode}
14772@kindex set struct-convention
14773@cindex struct return convention
14774@cindex struct/union returned in registers
14775Set the convention used by the inferior to return @code{struct}s and
14776@code{union}s from functions to @var{mode}. Possible values of
14777@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14778default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14779are returned on the stack, while @code{"reg"} means that a
14780@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14781be returned in a register.
14782
14783@item show struct-convention
14784@kindex show struct-convention
14785Show the current setting of the convention to return @code{struct}s
14786from functions.
14787@end table
14788
8e04817f
AC
14789@node A29K
14790@subsection A29K
104c1213
JM
14791
14792@table @code
104c1213 14793
8e04817f
AC
14794@kindex set rstack_high_address
14795@cindex AMD 29K register stack
14796@cindex register stack, AMD29K
14797@item set rstack_high_address @var{address}
14798On AMD 29000 family processors, registers are saved in a separate
14799@dfn{register stack}. There is no way for @value{GDBN} to determine the
14800extent of this stack. Normally, @value{GDBN} just assumes that the
14801stack is ``large enough''. This may result in @value{GDBN} referencing
14802memory locations that do not exist. If necessary, you can get around
14803this problem by specifying the ending address of the register stack with
14804the @code{set rstack_high_address} command. The argument should be an
14805address, which you probably want to precede with @samp{0x} to specify in
14806hexadecimal.
104c1213 14807
8e04817f
AC
14808@kindex show rstack_high_address
14809@item show rstack_high_address
14810Display the current limit of the register stack, on AMD 29000 family
14811processors.
104c1213 14812
8e04817f 14813@end table
104c1213 14814
8e04817f
AC
14815@node Alpha
14816@subsection Alpha
104c1213 14817
8e04817f 14818See the following section.
104c1213 14819
8e04817f
AC
14820@node MIPS
14821@subsection MIPS
104c1213 14822
8e04817f
AC
14823@cindex stack on Alpha
14824@cindex stack on MIPS
14825@cindex Alpha stack
14826@cindex MIPS stack
14827Alpha- and MIPS-based computers use an unusual stack frame, which
14828sometimes requires @value{GDBN} to search backward in the object code to
14829find the beginning of a function.
104c1213 14830
8e04817f
AC
14831@cindex response time, MIPS debugging
14832To improve response time (especially for embedded applications, where
14833@value{GDBN} may be restricted to a slow serial line for this search)
14834you may want to limit the size of this search, using one of these
14835commands:
104c1213 14836
8e04817f
AC
14837@table @code
14838@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14839@item set heuristic-fence-post @var{limit}
14840Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14841search for the beginning of a function. A value of @var{0} (the
14842default) means there is no limit. However, except for @var{0}, the
14843larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14844and therefore the longer it takes to run. You should only need to use
14845this command when debugging a stripped executable.
104c1213 14846
8e04817f
AC
14847@item show heuristic-fence-post
14848Display the current limit.
14849@end table
104c1213
JM
14850
14851@noindent
8e04817f
AC
14852These commands are available @emph{only} when @value{GDBN} is configured
14853for debugging programs on Alpha or MIPS processors.
104c1213 14854
a64548ea
EZ
14855Several MIPS-specific commands are available when debugging MIPS
14856programs:
14857
14858@table @code
14859@item set mips saved-gpreg-size @var{size}
14860@kindex set mips saved-gpreg-size
14861@cindex MIPS GP register size on stack
14862Set the size of MIPS general-purpose registers saved on the stack.
14863The argument @var{size} can be one of the following:
14864
14865@table @samp
14866@item 32
1486732-bit GP registers
14868@item 64
1486964-bit GP registers
14870@item auto
14871Use the target's default setting or autodetect the saved size from the
14872information contained in the executable. This is the default
14873@end table
14874
14875@item show mips saved-gpreg-size
14876@kindex show mips saved-gpreg-size
14877Show the current size of MIPS GP registers on the stack.
14878
14879@item set mips stack-arg-size @var{size}
14880@kindex set mips stack-arg-size
14881@cindex MIPS stack space for arguments
14882Set the amount of stack space reserved for arguments to functions.
14883The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14884(the default).
14885
14886@item set mips abi @var{arg}
14887@kindex set mips abi
14888@cindex set ABI for MIPS
14889Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14890values of @var{arg} are:
14891
14892@table @samp
14893@item auto
14894The default ABI associated with the current binary (this is the
14895default).
14896@item o32
14897@item o64
14898@item n32
14899@item n64
14900@item eabi32
14901@item eabi64
14902@item auto
14903@end table
14904
14905@item show mips abi
14906@kindex show mips abi
14907Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14908
14909@item set mipsfpu
14910@itemx show mipsfpu
14911@xref{MIPS Embedded, set mipsfpu}.
14912
14913@item set mips mask-address @var{arg}
14914@kindex set mips mask-address
14915@cindex MIPS addresses, masking
14916This command determines whether the most-significant 32 bits of 64-bit
14917MIPS addresses are masked off. The argument @var{arg} can be
14918@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14919setting, which lets @value{GDBN} determine the correct value.
14920
14921@item show mips mask-address
14922@kindex show mips mask-address
14923Show whether the upper 32 bits of MIPS addresses are masked off or
14924not.
14925
14926@item set remote-mips64-transfers-32bit-regs
14927@kindex set remote-mips64-transfers-32bit-regs
14928This command controls compatibility with 64-bit MIPS targets that
14929transfer data in 32-bit quantities. If you have an old MIPS 64 target
14930that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14931and 64 bits for other registers, set this option to @samp{on}.
14932
14933@item show remote-mips64-transfers-32bit-regs
14934@kindex show remote-mips64-transfers-32bit-regs
14935Show the current setting of compatibility with older MIPS 64 targets.
14936
14937@item set debug mips
14938@kindex set debug mips
14939This command turns on and off debugging messages for the MIPS-specific
14940target code in @value{GDBN}.
14941
14942@item show debug mips
14943@kindex show debug mips
14944Show the current setting of MIPS debugging messages.
14945@end table
14946
14947
14948@node HPPA
14949@subsection HPPA
14950@cindex HPPA support
14951
14952When @value{GDBN} is debugging te HP PA architecture, it provides the
14953following special commands:
14954
14955@table @code
14956@item set debug hppa
14957@kindex set debug hppa
14958THis command determines whether HPPA architecture specific debugging
14959messages are to be displayed.
14960
14961@item show debug hppa
14962Show whether HPPA debugging messages are displayed.
14963
14964@item maint print unwind @var{address}
14965@kindex maint print unwind@r{, HPPA}
14966This command displays the contents of the unwind table entry at the
14967given @var{address}.
14968
14969@end table
14970
104c1213 14971
8e04817f
AC
14972@node Controlling GDB
14973@chapter Controlling @value{GDBN}
14974
14975You can alter the way @value{GDBN} interacts with you by using the
14976@code{set} command. For commands controlling how @value{GDBN} displays
14977data, see @ref{Print Settings, ,Print settings}. Other settings are
14978described here.
14979
14980@menu
14981* Prompt:: Prompt
14982* Editing:: Command editing
14983* History:: Command history
14984* Screen Size:: Screen size
14985* Numbers:: Numbers
1e698235 14986* ABI:: Configuring the current ABI
8e04817f
AC
14987* Messages/Warnings:: Optional warnings and messages
14988* Debugging Output:: Optional messages about internal happenings
14989@end menu
14990
14991@node Prompt
14992@section Prompt
104c1213 14993
8e04817f 14994@cindex prompt
104c1213 14995
8e04817f
AC
14996@value{GDBN} indicates its readiness to read a command by printing a string
14997called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
14998can change the prompt string with the @code{set prompt} command. For
14999instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15000the prompt in one of the @value{GDBN} sessions so that you can always tell
15001which one you are talking to.
104c1213 15002
8e04817f
AC
15003@emph{Note:} @code{set prompt} does not add a space for you after the
15004prompt you set. This allows you to set a prompt which ends in a space
15005or a prompt that does not.
104c1213 15006
8e04817f
AC
15007@table @code
15008@kindex set prompt
15009@item set prompt @var{newprompt}
15010Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15011
8e04817f
AC
15012@kindex show prompt
15013@item show prompt
15014Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15015@end table
15016
8e04817f
AC
15017@node Editing
15018@section Command editing
15019@cindex readline
15020@cindex command line editing
104c1213 15021
703663ab 15022@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15023@sc{gnu} library provides consistent behavior for programs which provide a
15024command line interface to the user. Advantages are @sc{gnu} Emacs-style
15025or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15026substitution, and a storage and recall of command history across
15027debugging sessions.
104c1213 15028
8e04817f
AC
15029You may control the behavior of command line editing in @value{GDBN} with the
15030command @code{set}.
104c1213 15031
8e04817f
AC
15032@table @code
15033@kindex set editing
15034@cindex editing
15035@item set editing
15036@itemx set editing on
15037Enable command line editing (enabled by default).
104c1213 15038
8e04817f
AC
15039@item set editing off
15040Disable command line editing.
104c1213 15041
8e04817f
AC
15042@kindex show editing
15043@item show editing
15044Show whether command line editing is enabled.
104c1213
JM
15045@end table
15046
703663ab
EZ
15047@xref{Command Line Editing}, for more details about the Readline
15048interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15049encouraged to read that chapter.
15050
8e04817f
AC
15051@node History
15052@section Command history
703663ab 15053@cindex command history
8e04817f
AC
15054
15055@value{GDBN} can keep track of the commands you type during your
15056debugging sessions, so that you can be certain of precisely what
15057happened. Use these commands to manage the @value{GDBN} command
15058history facility.
104c1213 15059
703663ab
EZ
15060@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15061package, to provide the history facility. @xref{Using History
15062Interactively}, for the detailed description of the History library.
15063
15064Here is the description of @value{GDBN} commands related to command
15065history.
15066
104c1213 15067@table @code
8e04817f
AC
15068@cindex history substitution
15069@cindex history file
15070@kindex set history filename
4644b6e3 15071@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15072@item set history filename @var{fname}
15073Set the name of the @value{GDBN} command history file to @var{fname}.
15074This is the file where @value{GDBN} reads an initial command history
15075list, and where it writes the command history from this session when it
15076exits. You can access this list through history expansion or through
15077the history command editing characters listed below. This file defaults
15078to the value of the environment variable @code{GDBHISTFILE}, or to
15079@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15080is not set.
104c1213 15081
9c16f35a
EZ
15082@cindex save command history
15083@kindex set history save
8e04817f
AC
15084@item set history save
15085@itemx set history save on
15086Record command history in a file, whose name may be specified with the
15087@code{set history filename} command. By default, this option is disabled.
104c1213 15088
8e04817f
AC
15089@item set history save off
15090Stop recording command history in a file.
104c1213 15091
8e04817f 15092@cindex history size
9c16f35a 15093@kindex set history size
6fc08d32 15094@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15095@item set history size @var{size}
15096Set the number of commands which @value{GDBN} keeps in its history list.
15097This defaults to the value of the environment variable
15098@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15099@end table
15100
8e04817f 15101History expansion assigns special meaning to the character @kbd{!}.
703663ab 15102@xref{Event Designators}, for more details.
8e04817f 15103
703663ab 15104@cindex history expansion, turn on/off
8e04817f
AC
15105Since @kbd{!} is also the logical not operator in C, history expansion
15106is off by default. If you decide to enable history expansion with the
15107@code{set history expansion on} command, you may sometimes need to
15108follow @kbd{!} (when it is used as logical not, in an expression) with
15109a space or a tab to prevent it from being expanded. The readline
15110history facilities do not attempt substitution on the strings
15111@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15112
15113The commands to control history expansion are:
104c1213
JM
15114
15115@table @code
8e04817f
AC
15116@item set history expansion on
15117@itemx set history expansion
703663ab 15118@kindex set history expansion
8e04817f 15119Enable history expansion. History expansion is off by default.
104c1213 15120
8e04817f
AC
15121@item set history expansion off
15122Disable history expansion.
104c1213 15123
8e04817f
AC
15124@c @group
15125@kindex show history
15126@item show history
15127@itemx show history filename
15128@itemx show history save
15129@itemx show history size
15130@itemx show history expansion
15131These commands display the state of the @value{GDBN} history parameters.
15132@code{show history} by itself displays all four states.
15133@c @end group
15134@end table
15135
15136@table @code
9c16f35a
EZ
15137@kindex show commands
15138@cindex show last commands
15139@cindex display command history
8e04817f
AC
15140@item show commands
15141Display the last ten commands in the command history.
104c1213 15142
8e04817f
AC
15143@item show commands @var{n}
15144Print ten commands centered on command number @var{n}.
15145
15146@item show commands +
15147Print ten commands just after the commands last printed.
104c1213
JM
15148@end table
15149
8e04817f
AC
15150@node Screen Size
15151@section Screen size
15152@cindex size of screen
15153@cindex pauses in output
104c1213 15154
8e04817f
AC
15155Certain commands to @value{GDBN} may produce large amounts of
15156information output to the screen. To help you read all of it,
15157@value{GDBN} pauses and asks you for input at the end of each page of
15158output. Type @key{RET} when you want to continue the output, or @kbd{q}
15159to discard the remaining output. Also, the screen width setting
15160determines when to wrap lines of output. Depending on what is being
15161printed, @value{GDBN} tries to break the line at a readable place,
15162rather than simply letting it overflow onto the following line.
15163
15164Normally @value{GDBN} knows the size of the screen from the terminal
15165driver software. For example, on Unix @value{GDBN} uses the termcap data base
15166together with the value of the @code{TERM} environment variable and the
15167@code{stty rows} and @code{stty cols} settings. If this is not correct,
15168you can override it with the @code{set height} and @code{set
15169width} commands:
15170
15171@table @code
15172@kindex set height
15173@kindex set width
15174@kindex show width
15175@kindex show height
15176@item set height @var{lpp}
15177@itemx show height
15178@itemx set width @var{cpl}
15179@itemx show width
15180These @code{set} commands specify a screen height of @var{lpp} lines and
15181a screen width of @var{cpl} characters. The associated @code{show}
15182commands display the current settings.
104c1213 15183
8e04817f
AC
15184If you specify a height of zero lines, @value{GDBN} does not pause during
15185output no matter how long the output is. This is useful if output is to a
15186file or to an editor buffer.
104c1213 15187
8e04817f
AC
15188Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15189from wrapping its output.
9c16f35a
EZ
15190
15191@item set pagination on
15192@itemx set pagination off
15193@kindex set pagination
15194Turn the output pagination on or off; the default is on. Turning
15195pagination off is the alternative to @code{set height 0}.
15196
15197@item show pagination
15198@kindex show pagination
15199Show the current pagination mode.
104c1213
JM
15200@end table
15201
8e04817f
AC
15202@node Numbers
15203@section Numbers
15204@cindex number representation
15205@cindex entering numbers
104c1213 15206
8e04817f
AC
15207You can always enter numbers in octal, decimal, or hexadecimal in
15208@value{GDBN} by the usual conventions: octal numbers begin with
15209@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15210begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15211@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1521210; likewise, the default display for numbers---when no particular
15213format is specified---is base 10. You can change the default base for
15214both input and output with the commands described below.
104c1213 15215
8e04817f
AC
15216@table @code
15217@kindex set input-radix
15218@item set input-radix @var{base}
15219Set the default base for numeric input. Supported choices
15220for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15221specified either unambiguously or using the current input radix; for
8e04817f 15222example, any of
104c1213 15223
8e04817f 15224@smallexample
9c16f35a
EZ
15225set input-radix 012
15226set input-radix 10.
15227set input-radix 0xa
8e04817f 15228@end smallexample
104c1213 15229
8e04817f 15230@noindent
9c16f35a 15231sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15232leaves the input radix unchanged, no matter what it was, since
15233@samp{10}, being without any leading or trailing signs of its base, is
15234interpreted in the current radix. Thus, if the current radix is 16,
15235@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15236change the radix.
104c1213 15237
8e04817f
AC
15238@kindex set output-radix
15239@item set output-radix @var{base}
15240Set the default base for numeric display. Supported choices
15241for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15242specified either unambiguously or using the current input radix.
104c1213 15243
8e04817f
AC
15244@kindex show input-radix
15245@item show input-radix
15246Display the current default base for numeric input.
104c1213 15247
8e04817f
AC
15248@kindex show output-radix
15249@item show output-radix
15250Display the current default base for numeric display.
9c16f35a
EZ
15251
15252@item set radix @r{[}@var{base}@r{]}
15253@itemx show radix
15254@kindex set radix
15255@kindex show radix
15256These commands set and show the default base for both input and output
15257of numbers. @code{set radix} sets the radix of input and output to
15258the same base; without an argument, it resets the radix back to its
15259default value of 10.
15260
8e04817f 15261@end table
104c1213 15262
1e698235
DJ
15263@node ABI
15264@section Configuring the current ABI
15265
15266@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15267application automatically. However, sometimes you need to override its
15268conclusions. Use these commands to manage @value{GDBN}'s view of the
15269current ABI.
15270
98b45e30
DJ
15271@cindex OS ABI
15272@kindex set osabi
b4e9345d 15273@kindex show osabi
98b45e30
DJ
15274
15275One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15276system targets, either via remote debugging or native emulation.
98b45e30
DJ
15277@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15278but you can override its conclusion using the @code{set osabi} command.
15279One example where this is useful is in debugging of binaries which use
15280an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15281not have the same identifying marks that the standard C library for your
15282platform provides.
15283
15284@table @code
15285@item show osabi
15286Show the OS ABI currently in use.
15287
15288@item set osabi
15289With no argument, show the list of registered available OS ABI's.
15290
15291@item set osabi @var{abi}
15292Set the current OS ABI to @var{abi}.
15293@end table
15294
1e698235 15295@cindex float promotion
1e698235
DJ
15296
15297Generally, the way that an argument of type @code{float} is passed to a
15298function depends on whether the function is prototyped. For a prototyped
15299(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15300according to the architecture's convention for @code{float}. For unprototyped
15301(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15302@code{double} and then passed.
15303
15304Unfortunately, some forms of debug information do not reliably indicate whether
15305a function is prototyped. If @value{GDBN} calls a function that is not marked
15306as prototyped, it consults @kbd{set coerce-float-to-double}.
15307
15308@table @code
a8f24a35 15309@kindex set coerce-float-to-double
1e698235
DJ
15310@item set coerce-float-to-double
15311@itemx set coerce-float-to-double on
15312Arguments of type @code{float} will be promoted to @code{double} when passed
15313to an unprototyped function. This is the default setting.
15314
15315@item set coerce-float-to-double off
15316Arguments of type @code{float} will be passed directly to unprototyped
15317functions.
9c16f35a
EZ
15318
15319@kindex show coerce-float-to-double
15320@item show coerce-float-to-double
15321Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15322@end table
15323
f1212245
DJ
15324@kindex set cp-abi
15325@kindex show cp-abi
15326@value{GDBN} needs to know the ABI used for your program's C@t{++}
15327objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15328used to build your application. @value{GDBN} only fully supports
15329programs with a single C@t{++} ABI; if your program contains code using
15330multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15331program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15332Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15333before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15334``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15335use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15336``auto''.
15337
15338@table @code
15339@item show cp-abi
15340Show the C@t{++} ABI currently in use.
15341
15342@item set cp-abi
15343With no argument, show the list of supported C@t{++} ABI's.
15344
15345@item set cp-abi @var{abi}
15346@itemx set cp-abi auto
15347Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15348@end table
15349
8e04817f
AC
15350@node Messages/Warnings
15351@section Optional warnings and messages
104c1213 15352
9c16f35a
EZ
15353@cindex verbose operation
15354@cindex optional warnings
8e04817f
AC
15355By default, @value{GDBN} is silent about its inner workings. If you are
15356running on a slow machine, you may want to use the @code{set verbose}
15357command. This makes @value{GDBN} tell you when it does a lengthy
15358internal operation, so you will not think it has crashed.
104c1213 15359
8e04817f
AC
15360Currently, the messages controlled by @code{set verbose} are those
15361which announce that the symbol table for a source file is being read;
15362see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15363
8e04817f
AC
15364@table @code
15365@kindex set verbose
15366@item set verbose on
15367Enables @value{GDBN} output of certain informational messages.
104c1213 15368
8e04817f
AC
15369@item set verbose off
15370Disables @value{GDBN} output of certain informational messages.
104c1213 15371
8e04817f
AC
15372@kindex show verbose
15373@item show verbose
15374Displays whether @code{set verbose} is on or off.
15375@end table
104c1213 15376
8e04817f
AC
15377By default, if @value{GDBN} encounters bugs in the symbol table of an
15378object file, it is silent; but if you are debugging a compiler, you may
15379find this information useful (@pxref{Symbol Errors, ,Errors reading
15380symbol files}).
104c1213 15381
8e04817f 15382@table @code
104c1213 15383
8e04817f
AC
15384@kindex set complaints
15385@item set complaints @var{limit}
15386Permits @value{GDBN} to output @var{limit} complaints about each type of
15387unusual symbols before becoming silent about the problem. Set
15388@var{limit} to zero to suppress all complaints; set it to a large number
15389to prevent complaints from being suppressed.
104c1213 15390
8e04817f
AC
15391@kindex show complaints
15392@item show complaints
15393Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15394
8e04817f 15395@end table
104c1213 15396
8e04817f
AC
15397By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15398lot of stupid questions to confirm certain commands. For example, if
15399you try to run a program which is already running:
104c1213 15400
474c8240 15401@smallexample
8e04817f
AC
15402(@value{GDBP}) run
15403The program being debugged has been started already.
15404Start it from the beginning? (y or n)
474c8240 15405@end smallexample
104c1213 15406
8e04817f
AC
15407If you are willing to unflinchingly face the consequences of your own
15408commands, you can disable this ``feature'':
104c1213 15409
8e04817f 15410@table @code
104c1213 15411
8e04817f
AC
15412@kindex set confirm
15413@cindex flinching
15414@cindex confirmation
15415@cindex stupid questions
15416@item set confirm off
15417Disables confirmation requests.
104c1213 15418
8e04817f
AC
15419@item set confirm on
15420Enables confirmation requests (the default).
104c1213 15421
8e04817f
AC
15422@kindex show confirm
15423@item show confirm
15424Displays state of confirmation requests.
15425
15426@end table
104c1213 15427
8e04817f
AC
15428@node Debugging Output
15429@section Optional messages about internal happenings
4644b6e3
EZ
15430@cindex optional debugging messages
15431
da316a69
EZ
15432@value{GDBN} has commands that enable optional debugging messages from
15433various @value{GDBN} subsystems; normally these commands are of
15434interest to @value{GDBN} maintainers, or when reporting a bug. This
15435section documents those commands.
15436
104c1213 15437@table @code
a8f24a35
EZ
15438@kindex set exec-done-display
15439@item set exec-done-display
15440Turns on or off the notification of asynchronous commands'
15441completion. When on, @value{GDBN} will print a message when an
15442asynchronous command finishes its execution. The default is off.
15443@kindex show exec-done-display
15444@item show exec-done-display
15445Displays the current setting of asynchronous command completion
15446notification.
4644b6e3
EZ
15447@kindex set debug
15448@cindex gdbarch debugging info
a8f24a35 15449@cindex architecture debugging info
8e04817f 15450@item set debug arch
a8f24a35 15451Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15452@kindex show debug
8e04817f
AC
15453@item show debug arch
15454Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15455@item set debug aix-thread
15456@cindex AIX threads
15457Display debugging messages about inner workings of the AIX thread
15458module.
15459@item show debug aix-thread
15460Show the current state of AIX thread debugging info display.
8e04817f 15461@item set debug event
4644b6e3 15462@cindex event debugging info
a8f24a35 15463Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15464default is off.
8e04817f
AC
15465@item show debug event
15466Displays the current state of displaying @value{GDBN} event debugging
15467info.
8e04817f 15468@item set debug expression
4644b6e3 15469@cindex expression debugging info
721c2651
EZ
15470Turns on or off display of debugging info about @value{GDBN}
15471expression parsing. The default is off.
8e04817f 15472@item show debug expression
721c2651
EZ
15473Displays the current state of displaying debugging info about
15474@value{GDBN} expression parsing.
7453dc06 15475@item set debug frame
4644b6e3 15476@cindex frame debugging info
7453dc06
AC
15477Turns on or off display of @value{GDBN} frame debugging info. The
15478default is off.
7453dc06
AC
15479@item show debug frame
15480Displays the current state of displaying @value{GDBN} frame debugging
15481info.
30e91e0b
RC
15482@item set debug infrun
15483@cindex inferior debugging info
15484Turns on or off display of @value{GDBN} debugging info for running the inferior.
15485The default is off. @file{infrun.c} contains GDB's runtime state machine used
15486for implementing operations such as single-stepping the inferior.
15487@item show debug infrun
15488Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15489@item set debug lin-lwp
15490@cindex @sc{gnu}/Linux LWP debug messages
15491@cindex Linux lightweight processes
721c2651 15492Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15493@item show debug lin-lwp
15494Show the current state of Linux LWP debugging messages.
2b4855ab 15495@item set debug observer
4644b6e3 15496@cindex observer debugging info
2b4855ab
AC
15497Turns on or off display of @value{GDBN} observer debugging. This
15498includes info such as the notification of observable events.
2b4855ab
AC
15499@item show debug observer
15500Displays the current state of observer debugging.
8e04817f 15501@item set debug overload
4644b6e3 15502@cindex C@t{++} overload debugging info
8e04817f
AC
15503Turns on or off display of @value{GDBN} C@t{++} overload debugging
15504info. This includes info such as ranking of functions, etc. The default
15505is off.
8e04817f
AC
15506@item show debug overload
15507Displays the current state of displaying @value{GDBN} C@t{++} overload
15508debugging info.
8e04817f
AC
15509@cindex packets, reporting on stdout
15510@cindex serial connections, debugging
15511@item set debug remote
15512Turns on or off display of reports on all packets sent back and forth across
15513the serial line to the remote machine. The info is printed on the
15514@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15515@item show debug remote
15516Displays the state of display of remote packets.
8e04817f
AC
15517@item set debug serial
15518Turns on or off display of @value{GDBN} serial debugging info. The
15519default is off.
8e04817f
AC
15520@item show debug serial
15521Displays the current state of displaying @value{GDBN} serial debugging
15522info.
c45da7e6
EZ
15523@item set debug solib-frv
15524@cindex FR-V shared-library debugging
15525Turns on or off debugging messages for FR-V shared-library code.
15526@item show debug solib-frv
15527Display the current state of FR-V shared-library code debugging
15528messages.
8e04817f 15529@item set debug target
4644b6e3 15530@cindex target debugging info
8e04817f
AC
15531Turns on or off display of @value{GDBN} target debugging info. This info
15532includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15533default is 0. Set it to 1 to track events, and to 2 to also track the
15534value of large memory transfers. Changes to this flag do not take effect
15535until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15536@item show debug target
15537Displays the current state of displaying @value{GDBN} target debugging
15538info.
c45da7e6 15539@item set debugvarobj
4644b6e3 15540@cindex variable object debugging info
8e04817f
AC
15541Turns on or off display of @value{GDBN} variable object debugging
15542info. The default is off.
c45da7e6 15543@item show debugvarobj
8e04817f
AC
15544Displays the current state of displaying @value{GDBN} variable object
15545debugging info.
15546@end table
104c1213 15547
8e04817f
AC
15548@node Sequences
15549@chapter Canned Sequences of Commands
104c1213 15550
8e04817f
AC
15551Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15552command lists}), @value{GDBN} provides two ways to store sequences of
15553commands for execution as a unit: user-defined commands and command
15554files.
104c1213 15555
8e04817f
AC
15556@menu
15557* Define:: User-defined commands
15558* Hooks:: User-defined command hooks
15559* Command Files:: Command files
15560* Output:: Commands for controlled output
15561@end menu
104c1213 15562
8e04817f
AC
15563@node Define
15564@section User-defined commands
104c1213 15565
8e04817f
AC
15566@cindex user-defined command
15567A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15568which you assign a new name as a command. This is done with the
15569@code{define} command. User commands may accept up to 10 arguments
15570separated by whitespace. Arguments are accessed within the user command
15571via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15572
8e04817f
AC
15573@smallexample
15574define adder
15575 print $arg0 + $arg1 + $arg2
15576@end smallexample
104c1213
JM
15577
15578@noindent
8e04817f 15579To execute the command use:
104c1213 15580
8e04817f
AC
15581@smallexample
15582adder 1 2 3
15583@end smallexample
104c1213 15584
8e04817f
AC
15585@noindent
15586This defines the command @code{adder}, which prints the sum of
15587its three arguments. Note the arguments are text substitutions, so they may
15588reference variables, use complex expressions, or even perform inferior
15589functions calls.
104c1213
JM
15590
15591@table @code
104c1213 15592
8e04817f
AC
15593@kindex define
15594@item define @var{commandname}
15595Define a command named @var{commandname}. If there is already a command
15596by that name, you are asked to confirm that you want to redefine it.
104c1213 15597
8e04817f
AC
15598The definition of the command is made up of other @value{GDBN} command lines,
15599which are given following the @code{define} command. The end of these
15600commands is marked by a line containing @code{end}.
104c1213 15601
8e04817f
AC
15602@kindex if
15603@kindex else
15604@item if
09d4efe1 15605@itemx else
8e04817f
AC
15606Takes a single argument, which is an expression to evaluate.
15607It is followed by a series of commands that are executed
15608only if the expression is true (nonzero).
15609There can then optionally be a line @code{else}, followed
15610by a series of commands that are only executed if the expression
15611was false. The end of the list is marked by a line containing @code{end}.
104c1213 15612
8e04817f
AC
15613@kindex while
15614@item while
15615The syntax is similar to @code{if}: the command takes a single argument,
15616which is an expression to evaluate, and must be followed by the commands to
15617execute, one per line, terminated by an @code{end}.
15618The commands are executed repeatedly as long as the expression
15619evaluates to true.
104c1213 15620
8e04817f
AC
15621@kindex document
15622@item document @var{commandname}
15623Document the user-defined command @var{commandname}, so that it can be
15624accessed by @code{help}. The command @var{commandname} must already be
15625defined. This command reads lines of documentation just as @code{define}
15626reads the lines of the command definition, ending with @code{end}.
15627After the @code{document} command is finished, @code{help} on command
15628@var{commandname} displays the documentation you have written.
104c1213 15629
8e04817f
AC
15630You may use the @code{document} command again to change the
15631documentation of a command. Redefining the command with @code{define}
15632does not change the documentation.
104c1213 15633
c45da7e6
EZ
15634@kindex dont-repeat
15635@cindex don't repeat command
15636@item dont-repeat
15637Used inside a user-defined command, this tells @value{GDBN} that this
15638command should not be repeated when the user hits @key{RET}
15639(@pxref{Command Syntax, repeat last command}).
15640
8e04817f
AC
15641@kindex help user-defined
15642@item help user-defined
15643List all user-defined commands, with the first line of the documentation
15644(if any) for each.
104c1213 15645
8e04817f
AC
15646@kindex show user
15647@item show user
15648@itemx show user @var{commandname}
15649Display the @value{GDBN} commands used to define @var{commandname} (but
15650not its documentation). If no @var{commandname} is given, display the
15651definitions for all user-defined commands.
104c1213 15652
9c16f35a 15653@cindex infinite recusrion in user-defined commands
20f01a46
DH
15654@kindex show max-user-call-depth
15655@kindex set max-user-call-depth
15656@item show max-user-call-depth
5ca0cb28
DH
15657@itemx set max-user-call-depth
15658The value of @code{max-user-call-depth} controls how many recursion
15659levels are allowed in user-defined commands before GDB suspects an
15660infinite recursion and aborts the command.
20f01a46 15661
104c1213
JM
15662@end table
15663
8e04817f
AC
15664When user-defined commands are executed, the
15665commands of the definition are not printed. An error in any command
15666stops execution of the user-defined command.
104c1213 15667
8e04817f
AC
15668If used interactively, commands that would ask for confirmation proceed
15669without asking when used inside a user-defined command. Many @value{GDBN}
15670commands that normally print messages to say what they are doing omit the
15671messages when used in a user-defined command.
104c1213 15672
8e04817f
AC
15673@node Hooks
15674@section User-defined command hooks
15675@cindex command hooks
15676@cindex hooks, for commands
15677@cindex hooks, pre-command
104c1213 15678
8e04817f 15679@kindex hook
8e04817f
AC
15680You may define @dfn{hooks}, which are a special kind of user-defined
15681command. Whenever you run the command @samp{foo}, if the user-defined
15682command @samp{hook-foo} exists, it is executed (with no arguments)
15683before that command.
104c1213 15684
8e04817f
AC
15685@cindex hooks, post-command
15686@kindex hookpost
8e04817f
AC
15687A hook may also be defined which is run after the command you executed.
15688Whenever you run the command @samp{foo}, if the user-defined command
15689@samp{hookpost-foo} exists, it is executed (with no arguments) after
15690that command. Post-execution hooks may exist simultaneously with
15691pre-execution hooks, for the same command.
104c1213 15692
8e04817f 15693It is valid for a hook to call the command which it hooks. If this
9f1c6395 15694occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15695
8e04817f
AC
15696@c It would be nice if hookpost could be passed a parameter indicating
15697@c if the command it hooks executed properly or not. FIXME!
104c1213 15698
8e04817f
AC
15699@kindex stop@r{, a pseudo-command}
15700In addition, a pseudo-command, @samp{stop} exists. Defining
15701(@samp{hook-stop}) makes the associated commands execute every time
15702execution stops in your program: before breakpoint commands are run,
15703displays are printed, or the stack frame is printed.
104c1213 15704
8e04817f
AC
15705For example, to ignore @code{SIGALRM} signals while
15706single-stepping, but treat them normally during normal execution,
15707you could define:
104c1213 15708
474c8240 15709@smallexample
8e04817f
AC
15710define hook-stop
15711handle SIGALRM nopass
15712end
104c1213 15713
8e04817f
AC
15714define hook-run
15715handle SIGALRM pass
15716end
104c1213 15717
8e04817f
AC
15718define hook-continue
15719handle SIGLARM pass
15720end
474c8240 15721@end smallexample
104c1213 15722
8e04817f 15723As a further example, to hook at the begining and end of the @code{echo}
b383017d 15724command, and to add extra text to the beginning and end of the message,
8e04817f 15725you could define:
104c1213 15726
474c8240 15727@smallexample
8e04817f
AC
15728define hook-echo
15729echo <<<---
15730end
104c1213 15731
8e04817f
AC
15732define hookpost-echo
15733echo --->>>\n
15734end
104c1213 15735
8e04817f
AC
15736(@value{GDBP}) echo Hello World
15737<<<---Hello World--->>>
15738(@value{GDBP})
104c1213 15739
474c8240 15740@end smallexample
104c1213 15741
8e04817f
AC
15742You can define a hook for any single-word command in @value{GDBN}, but
15743not for command aliases; you should define a hook for the basic command
15744name, e.g. @code{backtrace} rather than @code{bt}.
15745@c FIXME! So how does Joe User discover whether a command is an alias
15746@c or not?
15747If an error occurs during the execution of your hook, execution of
15748@value{GDBN} commands stops and @value{GDBN} issues a prompt
15749(before the command that you actually typed had a chance to run).
104c1213 15750
8e04817f
AC
15751If you try to define a hook which does not match any known command, you
15752get a warning from the @code{define} command.
c906108c 15753
8e04817f
AC
15754@node Command Files
15755@section Command files
c906108c 15756
8e04817f 15757@cindex command files
6fc08d32
EZ
15758A command file for @value{GDBN} is a text file made of lines that are
15759@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15760also be included. An empty line in a command file does nothing; it
15761does not mean to repeat the last command, as it would from the
15762terminal.
c906108c 15763
6fc08d32
EZ
15764You can request the execution of a command file with the @code{source}
15765command:
c906108c 15766
8e04817f
AC
15767@table @code
15768@kindex source
15769@item source @var{filename}
15770Execute the command file @var{filename}.
c906108c
SS
15771@end table
15772
8e04817f 15773The lines in a command file are executed sequentially. They are not
a71ec265
DH
15774printed as they are executed. An error in any command terminates
15775execution of the command file and control is returned to the console.
c906108c 15776
8e04817f
AC
15777Commands that would ask for confirmation if used interactively proceed
15778without asking when used in a command file. Many @value{GDBN} commands that
15779normally print messages to say what they are doing omit the messages
15780when called from command files.
c906108c 15781
8e04817f
AC
15782@value{GDBN} also accepts command input from standard input. In this
15783mode, normal output goes to standard output and error output goes to
15784standard error. Errors in a command file supplied on standard input do
6fc08d32 15785not terminate execution of the command file---execution continues with
8e04817f 15786the next command.
c906108c 15787
474c8240 15788@smallexample
8e04817f 15789gdb < cmds > log 2>&1
474c8240 15790@end smallexample
c906108c 15791
8e04817f
AC
15792(The syntax above will vary depending on the shell used.) This example
15793will execute commands from the file @file{cmds}. All output and errors
15794would be directed to @file{log}.
c906108c 15795
8e04817f
AC
15796@node Output
15797@section Commands for controlled output
c906108c 15798
8e04817f
AC
15799During the execution of a command file or a user-defined command, normal
15800@value{GDBN} output is suppressed; the only output that appears is what is
15801explicitly printed by the commands in the definition. This section
15802describes three commands useful for generating exactly the output you
15803want.
c906108c
SS
15804
15805@table @code
8e04817f
AC
15806@kindex echo
15807@item echo @var{text}
15808@c I do not consider backslash-space a standard C escape sequence
15809@c because it is not in ANSI.
15810Print @var{text}. Nonprinting characters can be included in
15811@var{text} using C escape sequences, such as @samp{\n} to print a
15812newline. @strong{No newline is printed unless you specify one.}
15813In addition to the standard C escape sequences, a backslash followed
15814by a space stands for a space. This is useful for displaying a
15815string with spaces at the beginning or the end, since leading and
15816trailing spaces are otherwise trimmed from all arguments.
15817To print @samp{@w{ }and foo =@w{ }}, use the command
15818@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15819
8e04817f
AC
15820A backslash at the end of @var{text} can be used, as in C, to continue
15821the command onto subsequent lines. For example,
c906108c 15822
474c8240 15823@smallexample
8e04817f
AC
15824echo This is some text\n\
15825which is continued\n\
15826onto several lines.\n
474c8240 15827@end smallexample
c906108c 15828
8e04817f 15829produces the same output as
c906108c 15830
474c8240 15831@smallexample
8e04817f
AC
15832echo This is some text\n
15833echo which is continued\n
15834echo onto several lines.\n
474c8240 15835@end smallexample
c906108c 15836
8e04817f
AC
15837@kindex output
15838@item output @var{expression}
15839Print the value of @var{expression} and nothing but that value: no
15840newlines, no @samp{$@var{nn} = }. The value is not entered in the
15841value history either. @xref{Expressions, ,Expressions}, for more information
15842on expressions.
c906108c 15843
8e04817f
AC
15844@item output/@var{fmt} @var{expression}
15845Print the value of @var{expression} in format @var{fmt}. You can use
15846the same formats as for @code{print}. @xref{Output Formats,,Output
15847formats}, for more information.
c906108c 15848
8e04817f
AC
15849@kindex printf
15850@item printf @var{string}, @var{expressions}@dots{}
15851Print the values of the @var{expressions} under the control of
15852@var{string}. The @var{expressions} are separated by commas and may be
15853either numbers or pointers. Their values are printed as specified by
15854@var{string}, exactly as if your program were to execute the C
15855subroutine
15856@c FIXME: the above implies that at least all ANSI C formats are
15857@c supported, but it isn't true: %E and %G don't work (or so it seems).
15858@c Either this is a bug, or the manual should document what formats are
15859@c supported.
c906108c 15860
474c8240 15861@smallexample
8e04817f 15862printf (@var{string}, @var{expressions}@dots{});
474c8240 15863@end smallexample
c906108c 15864
8e04817f 15865For example, you can print two values in hex like this:
c906108c 15866
8e04817f
AC
15867@smallexample
15868printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15869@end smallexample
c906108c 15870
8e04817f
AC
15871The only backslash-escape sequences that you can use in the format
15872string are the simple ones that consist of backslash followed by a
15873letter.
c906108c
SS
15874@end table
15875
21c294e6
AC
15876@node Interpreters
15877@chapter Command Interpreters
15878@cindex command interpreters
15879
15880@value{GDBN} supports multiple command interpreters, and some command
15881infrastructure to allow users or user interface writers to switch
15882between interpreters or run commands in other interpreters.
15883
15884@value{GDBN} currently supports two command interpreters, the console
15885interpreter (sometimes called the command-line interpreter or @sc{cli})
15886and the machine interface interpreter (or @sc{gdb/mi}). This manual
15887describes both of these interfaces in great detail.
15888
15889By default, @value{GDBN} will start with the console interpreter.
15890However, the user may choose to start @value{GDBN} with another
15891interpreter by specifying the @option{-i} or @option{--interpreter}
15892startup options. Defined interpreters include:
15893
15894@table @code
15895@item console
15896@cindex console interpreter
15897The traditional console or command-line interpreter. This is the most often
15898used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15899@value{GDBN} will use this interpreter.
15900
15901@item mi
15902@cindex mi interpreter
15903The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15904by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15905or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15906Interface}.
15907
15908@item mi2
15909@cindex mi2 interpreter
15910The current @sc{gdb/mi} interface.
15911
15912@item mi1
15913@cindex mi1 interpreter
15914The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15915
15916@end table
15917
15918@cindex invoke another interpreter
15919The interpreter being used by @value{GDBN} may not be dynamically
15920switched at runtime. Although possible, this could lead to a very
15921precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15922enters the command "interpreter-set console" in a console view,
15923@value{GDBN} would switch to using the console interpreter, rendering
15924the IDE inoperable!
15925
15926@kindex interpreter-exec
15927Although you may only choose a single interpreter at startup, you may execute
15928commands in any interpreter from the current interpreter using the appropriate
15929command. If you are running the console interpreter, simply use the
15930@code{interpreter-exec} command:
15931
15932@smallexample
15933interpreter-exec mi "-data-list-register-names"
15934@end smallexample
15935
15936@sc{gdb/mi} has a similar command, although it is only available in versions of
15937@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15938
8e04817f
AC
15939@node TUI
15940@chapter @value{GDBN} Text User Interface
15941@cindex TUI
d0d5df6f 15942@cindex Text User Interface
c906108c 15943
8e04817f
AC
15944@menu
15945* TUI Overview:: TUI overview
15946* TUI Keys:: TUI key bindings
7cf36c78 15947* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15948* TUI Commands:: TUI specific commands
15949* TUI Configuration:: TUI configuration variables
15950@end menu
c906108c 15951
d0d5df6f
AC
15952The @value{GDBN} Text User Interface, TUI in short, is a terminal
15953interface which uses the @code{curses} library to show the source
15954file, the assembly output, the program registers and @value{GDBN}
15955commands in separate text windows.
15956
15957The TUI is enabled by invoking @value{GDBN} using either
15958@pindex gdbtui
15959@samp{gdbtui} or @samp{gdb -tui}.
c906108c 15960
8e04817f
AC
15961@node TUI Overview
15962@section TUI overview
c906108c 15963
8e04817f
AC
15964The TUI has two display modes that can be switched while
15965@value{GDBN} runs:
c906108c 15966
8e04817f
AC
15967@itemize @bullet
15968@item
15969A curses (or TUI) mode in which it displays several text
15970windows on the terminal.
c906108c 15971
8e04817f
AC
15972@item
15973A standard mode which corresponds to the @value{GDBN} configured without
15974the TUI.
15975@end itemize
c906108c 15976
8e04817f
AC
15977In the TUI mode, @value{GDBN} can display several text window
15978on the terminal:
c906108c 15979
8e04817f
AC
15980@table @emph
15981@item command
15982This window is the @value{GDBN} command window with the @value{GDBN}
15983prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
15984managed using readline but through the TUI. The @emph{command}
15985window is always visible.
c906108c 15986
8e04817f
AC
15987@item source
15988The source window shows the source file of the program. The current
15989line as well as active breakpoints are displayed in this window.
c906108c 15990
8e04817f
AC
15991@item assembly
15992The assembly window shows the disassembly output of the program.
c906108c 15993
8e04817f
AC
15994@item register
15995This window shows the processor registers. It detects when
15996a register is changed and when this is the case, registers that have
6a1b180d 15997changed are highlighted.
c906108c 15998
c906108c
SS
15999@end table
16000
269c21fe
SC
16001The source and assembly windows show the current program position
16002by highlighting the current line and marking them with the @samp{>} marker.
16003Breakpoints are also indicated with two markers. A first one
16004indicates the breakpoint type:
16005
16006@table @code
16007@item B
16008Breakpoint which was hit at least once.
16009
16010@item b
16011Breakpoint which was never hit.
16012
16013@item H
16014Hardware breakpoint which was hit at least once.
16015
16016@item h
16017Hardware breakpoint which was never hit.
16018
16019@end table
16020
16021The second marker indicates whether the breakpoint is enabled or not:
16022
16023@table @code
16024@item +
16025Breakpoint is enabled.
16026
16027@item -
16028Breakpoint is disabled.
16029
16030@end table
16031
8e04817f
AC
16032The source, assembly and register windows are attached to the thread
16033and the frame position. They are updated when the current thread
16034changes, when the frame changes or when the program counter changes.
16035These three windows are arranged by the TUI according to several
16036layouts. The layout defines which of these three windows are visible.
16037The following layouts are available:
c906108c 16038
8e04817f
AC
16039@itemize @bullet
16040@item
16041source
2df3850c 16042
8e04817f
AC
16043@item
16044assembly
16045
16046@item
16047source and assembly
16048
16049@item
16050source and registers
c906108c 16051
8e04817f
AC
16052@item
16053assembly and registers
2df3850c 16054
8e04817f 16055@end itemize
c906108c 16056
b7bb15bc
SC
16057On top of the command window a status line gives various information
16058concerning the current process begin debugged. The status line is
16059updated when the information it shows changes. The following fields
16060are displayed:
16061
16062@table @emph
16063@item target
16064Indicates the current gdb target
16065(@pxref{Targets, ,Specifying a Debugging Target}).
16066
16067@item process
16068Gives information about the current process or thread number.
16069When no process is being debugged, this field is set to @code{No process}.
16070
16071@item function
16072Gives the current function name for the selected frame.
16073The name is demangled if demangling is turned on (@pxref{Print Settings}).
16074When there is no symbol corresponding to the current program counter
16075the string @code{??} is displayed.
16076
16077@item line
16078Indicates the current line number for the selected frame.
16079When the current line number is not known the string @code{??} is displayed.
16080
16081@item pc
16082Indicates the current program counter address.
16083
16084@end table
16085
8e04817f
AC
16086@node TUI Keys
16087@section TUI Key Bindings
16088@cindex TUI key bindings
c906108c 16089
8e04817f
AC
16090The TUI installs several key bindings in the readline keymaps
16091(@pxref{Command Line Editing}).
16092They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16093directly on the TUI layout and windows. The TUI also provides
16094a @emph{SingleKey} keymap which binds several keys directly to
16095@value{GDBN} commands. The following key bindings
8e04817f 16096are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16097
8e04817f
AC
16098@table @kbd
16099@kindex C-x C-a
16100@item C-x C-a
16101@kindex C-x a
16102@itemx C-x a
16103@kindex C-x A
16104@itemx C-x A
16105Enter or leave the TUI mode. When the TUI mode is left,
16106the curses window management is left and @value{GDBN} operates using
16107its standard mode writing on the terminal directly. When the TUI
16108mode is entered, the control is given back to the curses windows.
16109The screen is then refreshed.
c906108c 16110
8e04817f
AC
16111@kindex C-x 1
16112@item C-x 1
16113Use a TUI layout with only one window. The layout will
16114either be @samp{source} or @samp{assembly}. When the TUI mode
16115is not active, it will switch to the TUI mode.
2df3850c 16116
8e04817f 16117Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16118
8e04817f
AC
16119@kindex C-x 2
16120@item C-x 2
16121Use a TUI layout with at least two windows. When the current
16122layout shows already two windows, a next layout with two windows is used.
16123When a new layout is chosen, one window will always be common to the
16124previous layout and the new one.
c906108c 16125
8e04817f 16126Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16127
72ffddc9
SC
16128@kindex C-x o
16129@item C-x o
16130Change the active window. The TUI associates several key bindings
16131(like scrolling and arrow keys) to the active window. This command
16132gives the focus to the next TUI window.
16133
16134Think of it as the Emacs @kbd{C-x o} binding.
16135
7cf36c78
SC
16136@kindex C-x s
16137@item C-x s
16138Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16139(@pxref{TUI Single Key Mode}).
16140
c906108c
SS
16141@end table
16142
8e04817f 16143The following key bindings are handled only by the TUI mode:
5d161b24 16144
8e04817f
AC
16145@table @key
16146@kindex PgUp
16147@item PgUp
16148Scroll the active window one page up.
c906108c 16149
8e04817f
AC
16150@kindex PgDn
16151@item PgDn
16152Scroll the active window one page down.
c906108c 16153
8e04817f
AC
16154@kindex Up
16155@item Up
16156Scroll the active window one line up.
c906108c 16157
8e04817f
AC
16158@kindex Down
16159@item Down
16160Scroll the active window one line down.
c906108c 16161
8e04817f
AC
16162@kindex Left
16163@item Left
16164Scroll the active window one column left.
c906108c 16165
8e04817f
AC
16166@kindex Right
16167@item Right
16168Scroll the active window one column right.
c906108c 16169
8e04817f
AC
16170@kindex C-L
16171@item C-L
16172Refresh the screen.
c906108c 16173
8e04817f 16174@end table
c906108c 16175
8e04817f 16176In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16177for scrolling. This means they are available for readline when the
16178active window is the command window. When the command window
16179does not have the focus, it is necessary to use other readline
16180key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16181
7cf36c78
SC
16182@node TUI Single Key Mode
16183@section TUI Single Key Mode
16184@cindex TUI single key mode
16185
16186The TUI provides a @emph{SingleKey} mode in which it installs a particular
16187key binding in the readline keymaps to connect single keys to
b383017d 16188some gdb commands.
7cf36c78
SC
16189
16190@table @kbd
16191@kindex c @r{(SingleKey TUI key)}
16192@item c
16193continue
16194
16195@kindex d @r{(SingleKey TUI key)}
16196@item d
16197down
16198
16199@kindex f @r{(SingleKey TUI key)}
16200@item f
16201finish
16202
16203@kindex n @r{(SingleKey TUI key)}
16204@item n
16205next
16206
16207@kindex q @r{(SingleKey TUI key)}
16208@item q
16209exit the @emph{SingleKey} mode.
16210
16211@kindex r @r{(SingleKey TUI key)}
16212@item r
16213run
16214
16215@kindex s @r{(SingleKey TUI key)}
16216@item s
16217step
16218
16219@kindex u @r{(SingleKey TUI key)}
16220@item u
16221up
16222
16223@kindex v @r{(SingleKey TUI key)}
16224@item v
16225info locals
16226
16227@kindex w @r{(SingleKey TUI key)}
16228@item w
16229where
16230
16231@end table
16232
16233Other keys temporarily switch to the @value{GDBN} command prompt.
16234The key that was pressed is inserted in the editing buffer so that
16235it is possible to type most @value{GDBN} commands without interaction
16236with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16237@emph{SingleKey} mode is restored. The only way to permanently leave
16238this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16239
16240
8e04817f
AC
16241@node TUI Commands
16242@section TUI specific commands
16243@cindex TUI commands
16244
16245The TUI has specific commands to control the text windows.
16246These commands are always available, that is they do not depend on
16247the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16248is in the standard mode, using these commands will automatically switch
16249in the TUI mode.
c906108c
SS
16250
16251@table @code
3d757584
SC
16252@item info win
16253@kindex info win
16254List and give the size of all displayed windows.
16255
8e04817f 16256@item layout next
4644b6e3 16257@kindex layout
8e04817f 16258Display the next layout.
2df3850c 16259
8e04817f 16260@item layout prev
8e04817f 16261Display the previous layout.
c906108c 16262
8e04817f 16263@item layout src
8e04817f 16264Display the source window only.
c906108c 16265
8e04817f 16266@item layout asm
8e04817f 16267Display the assembly window only.
c906108c 16268
8e04817f 16269@item layout split
8e04817f 16270Display the source and assembly window.
c906108c 16271
8e04817f 16272@item layout regs
8e04817f
AC
16273Display the register window together with the source or assembly window.
16274
16275@item focus next | prev | src | asm | regs | split
16276@kindex focus
16277Set the focus to the named window.
16278This command allows to change the active window so that scrolling keys
16279can be affected to another window.
c906108c 16280
8e04817f
AC
16281@item refresh
16282@kindex refresh
16283Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16284
6a1b180d
SC
16285@item tui reg float
16286@kindex tui reg
16287Show the floating point registers in the register window.
16288
16289@item tui reg general
16290Show the general registers in the register window.
16291
16292@item tui reg next
16293Show the next register group. The list of register groups as well as
16294their order is target specific. The predefined register groups are the
16295following: @code{general}, @code{float}, @code{system}, @code{vector},
16296@code{all}, @code{save}, @code{restore}.
16297
16298@item tui reg system
16299Show the system registers in the register window.
16300
8e04817f
AC
16301@item update
16302@kindex update
16303Update the source window and the current execution point.
c906108c 16304
8e04817f
AC
16305@item winheight @var{name} +@var{count}
16306@itemx winheight @var{name} -@var{count}
16307@kindex winheight
16308Change the height of the window @var{name} by @var{count}
16309lines. Positive counts increase the height, while negative counts
16310decrease it.
2df3850c 16311
c45da7e6
EZ
16312@item tabset
16313@kindex tabset @var{nchars}
16314Set the width of tab stops to be @var{nchars} characters.
16315
c906108c
SS
16316@end table
16317
8e04817f
AC
16318@node TUI Configuration
16319@section TUI configuration variables
16320@cindex TUI configuration variables
c906108c 16321
8e04817f
AC
16322The TUI has several configuration variables that control the
16323appearance of windows on the terminal.
c906108c 16324
8e04817f
AC
16325@table @code
16326@item set tui border-kind @var{kind}
16327@kindex set tui border-kind
16328Select the border appearance for the source, assembly and register windows.
16329The possible values are the following:
16330@table @code
16331@item space
16332Use a space character to draw the border.
c906108c 16333
8e04817f
AC
16334@item ascii
16335Use ascii characters + - and | to draw the border.
c906108c 16336
8e04817f
AC
16337@item acs
16338Use the Alternate Character Set to draw the border. The border is
16339drawn using character line graphics if the terminal supports them.
c78b4128 16340
8e04817f 16341@end table
c78b4128 16342
8e04817f
AC
16343@item set tui active-border-mode @var{mode}
16344@kindex set tui active-border-mode
16345Select the attributes to display the border of the active window.
16346The possible values are @code{normal}, @code{standout}, @code{reverse},
16347@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16348
8e04817f
AC
16349@item set tui border-mode @var{mode}
16350@kindex set tui border-mode
16351Select the attributes to display the border of other windows.
16352The @var{mode} can be one of the following:
16353@table @code
16354@item normal
16355Use normal attributes to display the border.
c906108c 16356
8e04817f
AC
16357@item standout
16358Use standout mode.
c906108c 16359
8e04817f
AC
16360@item reverse
16361Use reverse video mode.
c906108c 16362
8e04817f
AC
16363@item half
16364Use half bright mode.
c906108c 16365
8e04817f
AC
16366@item half-standout
16367Use half bright and standout mode.
c906108c 16368
8e04817f
AC
16369@item bold
16370Use extra bright or bold mode.
c78b4128 16371
8e04817f
AC
16372@item bold-standout
16373Use extra bright or bold and standout mode.
c78b4128 16374
8e04817f 16375@end table
c78b4128 16376
8e04817f 16377@end table
c78b4128 16378
8e04817f
AC
16379@node Emacs
16380@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16381
8e04817f
AC
16382@cindex Emacs
16383@cindex @sc{gnu} Emacs
16384A special interface allows you to use @sc{gnu} Emacs to view (and
16385edit) the source files for the program you are debugging with
16386@value{GDBN}.
c906108c 16387
8e04817f
AC
16388To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16389executable file you want to debug as an argument. This command starts
16390@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16391created Emacs buffer.
16392@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16393
8e04817f
AC
16394Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16395things:
c906108c 16396
8e04817f
AC
16397@itemize @bullet
16398@item
16399All ``terminal'' input and output goes through the Emacs buffer.
16400@end itemize
c906108c 16401
8e04817f
AC
16402This applies both to @value{GDBN} commands and their output, and to the input
16403and output done by the program you are debugging.
bf0184be 16404
8e04817f
AC
16405This is useful because it means that you can copy the text of previous
16406commands and input them again; you can even use parts of the output
16407in this way.
bf0184be 16408
8e04817f
AC
16409All the facilities of Emacs' Shell mode are available for interacting
16410with your program. In particular, you can send signals the usual
16411way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16412stop.
bf0184be 16413
8e04817f 16414@itemize @bullet
bf0184be 16415@item
8e04817f
AC
16416@value{GDBN} displays source code through Emacs.
16417@end itemize
bf0184be 16418
8e04817f
AC
16419Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16420source file for that frame and puts an arrow (@samp{=>}) at the
16421left margin of the current line. Emacs uses a separate buffer for
16422source display, and splits the screen to show both your @value{GDBN} session
16423and the source.
bf0184be 16424
8e04817f
AC
16425Explicit @value{GDBN} @code{list} or search commands still produce output as
16426usual, but you probably have no reason to use them from Emacs.
c906108c 16427
64fabec2
AC
16428If you specify an absolute file name when prompted for the @kbd{M-x
16429gdb} argument, then Emacs sets your current working directory to where
16430your program resides. If you only specify the file name, then Emacs
16431sets your current working directory to to the directory associated
16432with the previous buffer. In this case, @value{GDBN} may find your
16433program by searching your environment's @code{PATH} variable, but on
16434some operating systems it might not find the source. So, although the
16435@value{GDBN} input and output session proceeds normally, the auxiliary
16436buffer does not display the current source and line of execution.
16437
16438The initial working directory of @value{GDBN} is printed on the top
16439line of the @value{GDBN} I/O buffer and this serves as a default for
16440the commands that specify files for @value{GDBN} to operate
16441on. @xref{Files, ,Commands to specify files}.
16442
16443By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16444need to call @value{GDBN} by a different name (for example, if you
16445keep several configurations around, with different names) you can
16446customize the Emacs variable @code{gud-gdb-command-name} to run the
16447one you want.
8e04817f
AC
16448
16449In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16450addition to the standard Shell mode commands:
c906108c 16451
8e04817f
AC
16452@table @kbd
16453@item C-h m
16454Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16455
64fabec2 16456@item C-c C-s
8e04817f
AC
16457Execute to another source line, like the @value{GDBN} @code{step} command; also
16458update the display window to show the current file and location.
c906108c 16459
64fabec2 16460@item C-c C-n
8e04817f
AC
16461Execute to next source line in this function, skipping all function
16462calls, like the @value{GDBN} @code{next} command. Then update the display window
16463to show the current file and location.
c906108c 16464
64fabec2 16465@item C-c C-i
8e04817f
AC
16466Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16467display window accordingly.
c906108c 16468
8e04817f
AC
16469@item C-c C-f
16470Execute until exit from the selected stack frame, like the @value{GDBN}
16471@code{finish} command.
c906108c 16472
64fabec2 16473@item C-c C-r
8e04817f
AC
16474Continue execution of your program, like the @value{GDBN} @code{continue}
16475command.
b433d00b 16476
64fabec2 16477@item C-c <
8e04817f
AC
16478Go up the number of frames indicated by the numeric argument
16479(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16480like the @value{GDBN} @code{up} command.
b433d00b 16481
64fabec2 16482@item C-c >
8e04817f
AC
16483Go down the number of frames indicated by the numeric argument, like the
16484@value{GDBN} @code{down} command.
8e04817f 16485@end table
c906108c 16486
64fabec2 16487In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16488tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16489
64fabec2
AC
16490If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16491shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16492point to any frame in the stack and type @key{RET} to make it become the
16493current frame and display the associated source in the source buffer.
16494Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16495current one.
16496
8e04817f
AC
16497If you accidentally delete the source-display buffer, an easy way to get
16498it back is to type the command @code{f} in the @value{GDBN} buffer, to
16499request a frame display; when you run under Emacs, this recreates
16500the source buffer if necessary to show you the context of the current
16501frame.
c906108c 16502
8e04817f
AC
16503The source files displayed in Emacs are in ordinary Emacs buffers
16504which are visiting the source files in the usual way. You can edit
16505the files with these buffers if you wish; but keep in mind that @value{GDBN}
16506communicates with Emacs in terms of line numbers. If you add or
16507delete lines from the text, the line numbers that @value{GDBN} knows cease
16508to correspond properly with the code.
b383017d 16509
64fabec2
AC
16510The description given here is for GNU Emacs version 21.3 and a more
16511detailed description of its interaction with @value{GDBN} is given in
16512the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16513
8e04817f
AC
16514@c The following dropped because Epoch is nonstandard. Reactivate
16515@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16516@ignore
16517@kindex Emacs Epoch environment
16518@kindex Epoch
16519@kindex inspect
c906108c 16520
8e04817f
AC
16521Version 18 of @sc{gnu} Emacs has a built-in window system
16522called the @code{epoch}
16523environment. Users of this environment can use a new command,
16524@code{inspect} which performs identically to @code{print} except that
16525each value is printed in its own window.
16526@end ignore
c906108c 16527
922fbb7b
AC
16528
16529@node GDB/MI
16530@chapter The @sc{gdb/mi} Interface
16531
16532@unnumberedsec Function and Purpose
16533
16534@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16535@sc{gdb/mi} is a line based machine oriented text interface to
16536@value{GDBN} and is activated by specifying using the
16537@option{--interpreter} command line option (@pxref{Mode Options}). It
16538is specifically intended to support the development of systems which
16539use the debugger as just one small component of a larger system.
922fbb7b
AC
16540
16541This chapter is a specification of the @sc{gdb/mi} interface. It is written
16542in the form of a reference manual.
16543
16544Note that @sc{gdb/mi} is still under construction, so some of the
16545features described below are incomplete and subject to change.
16546
16547@unnumberedsec Notation and Terminology
16548
16549@cindex notational conventions, for @sc{gdb/mi}
16550This chapter uses the following notation:
16551
16552@itemize @bullet
16553@item
16554@code{|} separates two alternatives.
16555
16556@item
16557@code{[ @var{something} ]} indicates that @var{something} is optional:
16558it may or may not be given.
16559
16560@item
16561@code{( @var{group} )*} means that @var{group} inside the parentheses
16562may repeat zero or more times.
16563
16564@item
16565@code{( @var{group} )+} means that @var{group} inside the parentheses
16566may repeat one or more times.
16567
16568@item
16569@code{"@var{string}"} means a literal @var{string}.
16570@end itemize
16571
16572@ignore
16573@heading Dependencies
16574@end ignore
16575
16576@heading Acknowledgments
16577
16578In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16579Elena Zannoni.
16580
16581@menu
16582* GDB/MI Command Syntax::
16583* GDB/MI Compatibility with CLI::
16584* GDB/MI Output Records::
16585* GDB/MI Command Description Format::
16586* GDB/MI Breakpoint Table Commands::
16587* GDB/MI Data Manipulation::
16588* GDB/MI Program Control::
16589* GDB/MI Miscellaneous Commands::
16590@ignore
16591* GDB/MI Kod Commands::
16592* GDB/MI Memory Overlay Commands::
16593* GDB/MI Signal Handling Commands::
16594@end ignore
16595* GDB/MI Stack Manipulation::
16596* GDB/MI Symbol Query::
16597* GDB/MI Target Manipulation::
16598* GDB/MI Thread Commands::
16599* GDB/MI Tracepoint Commands::
16600* GDB/MI Variable Objects::
16601@end menu
16602
16603@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16604@node GDB/MI Command Syntax
16605@section @sc{gdb/mi} Command Syntax
16606
16607@menu
16608* GDB/MI Input Syntax::
16609* GDB/MI Output Syntax::
16610* GDB/MI Simple Examples::
16611@end menu
16612
16613@node GDB/MI Input Syntax
16614@subsection @sc{gdb/mi} Input Syntax
16615
16616@cindex input syntax for @sc{gdb/mi}
16617@cindex @sc{gdb/mi}, input syntax
16618@table @code
16619@item @var{command} @expansion{}
16620@code{@var{cli-command} | @var{mi-command}}
16621
16622@item @var{cli-command} @expansion{}
16623@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16624@var{cli-command} is any existing @value{GDBN} CLI command.
16625
16626@item @var{mi-command} @expansion{}
16627@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16628@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16629
16630@item @var{token} @expansion{}
16631"any sequence of digits"
16632
16633@item @var{option} @expansion{}
16634@code{"-" @var{parameter} [ " " @var{parameter} ]}
16635
16636@item @var{parameter} @expansion{}
16637@code{@var{non-blank-sequence} | @var{c-string}}
16638
16639@item @var{operation} @expansion{}
16640@emph{any of the operations described in this chapter}
16641
16642@item @var{non-blank-sequence} @expansion{}
16643@emph{anything, provided it doesn't contain special characters such as
16644"-", @var{nl}, """ and of course " "}
16645
16646@item @var{c-string} @expansion{}
16647@code{""" @var{seven-bit-iso-c-string-content} """}
16648
16649@item @var{nl} @expansion{}
16650@code{CR | CR-LF}
16651@end table
16652
16653@noindent
16654Notes:
16655
16656@itemize @bullet
16657@item
16658The CLI commands are still handled by the @sc{mi} interpreter; their
16659output is described below.
16660
16661@item
16662The @code{@var{token}}, when present, is passed back when the command
16663finishes.
16664
16665@item
16666Some @sc{mi} commands accept optional arguments as part of the parameter
16667list. Each option is identified by a leading @samp{-} (dash) and may be
16668followed by an optional argument parameter. Options occur first in the
16669parameter list and can be delimited from normal parameters using
16670@samp{--} (this is useful when some parameters begin with a dash).
16671@end itemize
16672
16673Pragmatics:
16674
16675@itemize @bullet
16676@item
16677We want easy access to the existing CLI syntax (for debugging).
16678
16679@item
16680We want it to be easy to spot a @sc{mi} operation.
16681@end itemize
16682
16683@node GDB/MI Output Syntax
16684@subsection @sc{gdb/mi} Output Syntax
16685
16686@cindex output syntax of @sc{gdb/mi}
16687@cindex @sc{gdb/mi}, output syntax
16688The output from @sc{gdb/mi} consists of zero or more out-of-band records
16689followed, optionally, by a single result record. This result record
16690is for the most recent command. The sequence of output records is
16691terminated by @samp{(@value{GDBP})}.
16692
16693If an input command was prefixed with a @code{@var{token}} then the
16694corresponding output for that command will also be prefixed by that same
16695@var{token}.
16696
16697@table @code
16698@item @var{output} @expansion{}
f7dc1244 16699@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16700
16701@item @var{result-record} @expansion{}
16702@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16703
16704@item @var{out-of-band-record} @expansion{}
16705@code{@var{async-record} | @var{stream-record}}
16706
16707@item @var{async-record} @expansion{}
16708@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16709
16710@item @var{exec-async-output} @expansion{}
16711@code{[ @var{token} ] "*" @var{async-output}}
16712
16713@item @var{status-async-output} @expansion{}
16714@code{[ @var{token} ] "+" @var{async-output}}
16715
16716@item @var{notify-async-output} @expansion{}
16717@code{[ @var{token} ] "=" @var{async-output}}
16718
16719@item @var{async-output} @expansion{}
16720@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16721
16722@item @var{result-class} @expansion{}
16723@code{"done" | "running" | "connected" | "error" | "exit"}
16724
16725@item @var{async-class} @expansion{}
16726@code{"stopped" | @var{others}} (where @var{others} will be added
16727depending on the needs---this is still in development).
16728
16729@item @var{result} @expansion{}
16730@code{ @var{variable} "=" @var{value}}
16731
16732@item @var{variable} @expansion{}
16733@code{ @var{string} }
16734
16735@item @var{value} @expansion{}
16736@code{ @var{const} | @var{tuple} | @var{list} }
16737
16738@item @var{const} @expansion{}
16739@code{@var{c-string}}
16740
16741@item @var{tuple} @expansion{}
16742@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16743
16744@item @var{list} @expansion{}
16745@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16746@var{result} ( "," @var{result} )* "]" }
16747
16748@item @var{stream-record} @expansion{}
16749@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16750
16751@item @var{console-stream-output} @expansion{}
16752@code{"~" @var{c-string}}
16753
16754@item @var{target-stream-output} @expansion{}
16755@code{"@@" @var{c-string}}
16756
16757@item @var{log-stream-output} @expansion{}
16758@code{"&" @var{c-string}}
16759
16760@item @var{nl} @expansion{}
16761@code{CR | CR-LF}
16762
16763@item @var{token} @expansion{}
16764@emph{any sequence of digits}.
16765@end table
16766
16767@noindent
16768Notes:
16769
16770@itemize @bullet
16771@item
16772All output sequences end in a single line containing a period.
16773
16774@item
16775The @code{@var{token}} is from the corresponding request. If an execution
16776command is interrupted by the @samp{-exec-interrupt} command, the
16777@var{token} associated with the @samp{*stopped} message is the one of the
16778original execution command, not the one of the interrupt command.
16779
16780@item
16781@cindex status output in @sc{gdb/mi}
16782@var{status-async-output} contains on-going status information about the
16783progress of a slow operation. It can be discarded. All status output is
16784prefixed by @samp{+}.
16785
16786@item
16787@cindex async output in @sc{gdb/mi}
16788@var{exec-async-output} contains asynchronous state change on the target
16789(stopped, started, disappeared). All async output is prefixed by
16790@samp{*}.
16791
16792@item
16793@cindex notify output in @sc{gdb/mi}
16794@var{notify-async-output} contains supplementary information that the
16795client should handle (e.g., a new breakpoint information). All notify
16796output is prefixed by @samp{=}.
16797
16798@item
16799@cindex console output in @sc{gdb/mi}
16800@var{console-stream-output} is output that should be displayed as is in the
16801console. It is the textual response to a CLI command. All the console
16802output is prefixed by @samp{~}.
16803
16804@item
16805@cindex target output in @sc{gdb/mi}
16806@var{target-stream-output} is the output produced by the target program.
16807All the target output is prefixed by @samp{@@}.
16808
16809@item
16810@cindex log output in @sc{gdb/mi}
16811@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16812instance messages that should be displayed as part of an error log. All
16813the log output is prefixed by @samp{&}.
16814
16815@item
16816@cindex list output in @sc{gdb/mi}
16817New @sc{gdb/mi} commands should only output @var{lists} containing
16818@var{values}.
16819
16820
16821@end itemize
16822
16823@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16824details about the various output records.
16825
16826@node GDB/MI Simple Examples
16827@subsection Simple Examples of @sc{gdb/mi} Interaction
16828@cindex @sc{gdb/mi}, simple examples
16829
16830This subsection presents several simple examples of interaction using
16831the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16832following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16833the output received from @sc{gdb/mi}.
16834
16835@subsubheading Target Stop
16836@c Ummm... There is no "-stop" command. This assumes async, no?
16837Here's an example of stopping the inferior process:
16838
16839@smallexample
16840-> -stop
16841<- (@value{GDBP})
16842@end smallexample
16843
16844@noindent
16845and later:
16846
16847@smallexample
16848<- *stop,reason="stop",address="0x123",source="a.c:123"
16849<- (@value{GDBP})
16850@end smallexample
16851
16852@subsubheading Simple CLI Command
16853
16854Here's an example of a simple CLI command being passed through
16855@sc{gdb/mi} and on to the CLI.
16856
16857@smallexample
16858-> print 1+2
16859<- &"print 1+2\n"
16860<- ~"$1 = 3\n"
16861<- ^done
16862<- (@value{GDBP})
16863@end smallexample
16864
16865@subsubheading Command With Side Effects
16866
16867@smallexample
16868-> -symbol-file xyz.exe
16869<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16870<- (@value{GDBP})
16871@end smallexample
16872
16873@subsubheading A Bad Command
16874
16875Here's what happens if you pass a non-existent command:
16876
16877@smallexample
16878-> -rubbish
16879<- ^error,msg="Undefined MI command: rubbish"
16880<- (@value{GDBP})
16881@end smallexample
16882
16883@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16884@node GDB/MI Compatibility with CLI
16885@section @sc{gdb/mi} Compatibility with CLI
16886
16887@cindex compatibility, @sc{gdb/mi} and CLI
16888@cindex @sc{gdb/mi}, compatibility with CLI
16889To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16890accepts existing CLI commands. As specified by the syntax, such
16891commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16892respond.
16893
16894This mechanism is provided as an aid to developers of @sc{gdb/mi}
16895clients and not as a reliable interface into the CLI. Since the command
16896is being interpreteted in an environment that assumes @sc{gdb/mi}
16897behaviour, the exact output of such commands is likely to end up being
16898an un-supported hybrid of @sc{gdb/mi} and CLI output.
16899
16900@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16901@node GDB/MI Output Records
16902@section @sc{gdb/mi} Output Records
16903
16904@menu
16905* GDB/MI Result Records::
16906* GDB/MI Stream Records::
16907* GDB/MI Out-of-band Records::
16908@end menu
16909
16910@node GDB/MI Result Records
16911@subsection @sc{gdb/mi} Result Records
16912
16913@cindex result records in @sc{gdb/mi}
16914@cindex @sc{gdb/mi}, result records
16915In addition to a number of out-of-band notifications, the response to a
16916@sc{gdb/mi} command includes one of the following result indications:
16917
16918@table @code
16919@findex ^done
16920@item "^done" [ "," @var{results} ]
16921The synchronous operation was successful, @code{@var{results}} are the return
16922values.
16923
16924@item "^running"
16925@findex ^running
16926@c Is this one correct? Should it be an out-of-band notification?
16927The asynchronous operation was successfully started. The target is
16928running.
16929
16930@item "^error" "," @var{c-string}
16931@findex ^error
16932The operation failed. The @code{@var{c-string}} contains the corresponding
16933error message.
16934@end table
16935
16936@node GDB/MI Stream Records
16937@subsection @sc{gdb/mi} Stream Records
16938
16939@cindex @sc{gdb/mi}, stream records
16940@cindex stream records in @sc{gdb/mi}
16941@value{GDBN} internally maintains a number of output streams: the console, the
16942target, and the log. The output intended for each of these streams is
16943funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16944
16945Each stream record begins with a unique @dfn{prefix character} which
16946identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16947Syntax}). In addition to the prefix, each stream record contains a
16948@code{@var{string-output}}. This is either raw text (with an implicit new
16949line) or a quoted C string (which does not contain an implicit newline).
16950
16951@table @code
16952@item "~" @var{string-output}
16953The console output stream contains text that should be displayed in the
16954CLI console window. It contains the textual responses to CLI commands.
16955
16956@item "@@" @var{string-output}
16957The target output stream contains any textual output from the running
16958target.
16959
16960@item "&" @var{string-output}
16961The log stream contains debugging messages being produced by @value{GDBN}'s
16962internals.
16963@end table
16964
16965@node GDB/MI Out-of-band Records
16966@subsection @sc{gdb/mi} Out-of-band Records
16967
16968@cindex out-of-band records in @sc{gdb/mi}
16969@cindex @sc{gdb/mi}, out-of-band records
16970@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
16971additional changes that have occurred. Those changes can either be a
16972consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
16973target activity (e.g., target stopped).
16974
16975The following is a preliminary list of possible out-of-band records.
034dad6f 16976In particular, the @var{exec-async-output} records.
922fbb7b
AC
16977
16978@table @code
034dad6f
BR
16979@item *stopped,reason="@var{reason}"
16980@end table
16981
16982@var{reason} can be one of the following:
16983
16984@table @code
16985@item breakpoint-hit
16986A breakpoint was reached.
16987@item watchpoint-trigger
16988A watchpoint was triggered.
16989@item read-watchpoint-trigger
16990A read watchpoint was triggered.
16991@item access-watchpoint-trigger
16992An access watchpoint was triggered.
16993@item function-finished
16994An -exec-finish or similar CLI command was accomplished.
16995@item location-reached
16996An -exec-until or similar CLI command was accomplished.
16997@item watchpoint-scope
16998A watchpoint has gone out of scope.
16999@item end-stepping-range
17000An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17001similar CLI command was accomplished.
17002@item exited-signalled
17003The inferior exited because of a signal.
17004@item exited
17005The inferior exited.
17006@item exited-normally
17007The inferior exited normally.
17008@item signal-received
17009A signal was received by the inferior.
922fbb7b
AC
17010@end table
17011
17012
17013@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17014@node GDB/MI Command Description Format
17015@section @sc{gdb/mi} Command Description Format
17016
17017The remaining sections describe blocks of commands. Each block of
17018commands is laid out in a fashion similar to this section.
17019
17020Note the the line breaks shown in the examples are here only for
17021readability. They don't appear in the real output.
17022Also note that the commands with a non-available example (N.A.@:) are
17023not yet implemented.
17024
17025@subheading Motivation
17026
17027The motivation for this collection of commands.
17028
17029@subheading Introduction
17030
17031A brief introduction to this collection of commands as a whole.
17032
17033@subheading Commands
17034
17035For each command in the block, the following is described:
17036
17037@subsubheading Synopsis
17038
17039@smallexample
17040 -command @var{args}@dots{}
17041@end smallexample
17042
17043@subsubheading @value{GDBN} Command
17044
17045The corresponding @value{GDBN} CLI command.
17046
17047@subsubheading Result
17048
17049@subsubheading Out-of-band
17050
17051@subsubheading Notes
17052
17053@subsubheading Example
17054
17055
17056@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17057@node GDB/MI Breakpoint Table Commands
17058@section @sc{gdb/mi} Breakpoint table commands
17059
17060@cindex breakpoint commands for @sc{gdb/mi}
17061@cindex @sc{gdb/mi}, breakpoint commands
17062This section documents @sc{gdb/mi} commands for manipulating
17063breakpoints.
17064
17065@subheading The @code{-break-after} Command
17066@findex -break-after
17067
17068@subsubheading Synopsis
17069
17070@smallexample
17071 -break-after @var{number} @var{count}
17072@end smallexample
17073
17074The breakpoint number @var{number} is not in effect until it has been
17075hit @var{count} times. To see how this is reflected in the output of
17076the @samp{-break-list} command, see the description of the
17077@samp{-break-list} command below.
17078
17079@subsubheading @value{GDBN} Command
17080
17081The corresponding @value{GDBN} command is @samp{ignore}.
17082
17083@subsubheading Example
17084
17085@smallexample
17086(@value{GDBP})
17087-break-insert main
17088^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17089(@value{GDBP})
17090-break-after 1 3
17091~
17092^done
17093(@value{GDBP})
17094-break-list
17095^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17096hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17097@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17098@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17099@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17100@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17101@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17102body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17103addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17104ignore="3"@}]@}
17105(@value{GDBP})
17106@end smallexample
17107
17108@ignore
17109@subheading The @code{-break-catch} Command
17110@findex -break-catch
17111
17112@subheading The @code{-break-commands} Command
17113@findex -break-commands
17114@end ignore
17115
17116
17117@subheading The @code{-break-condition} Command
17118@findex -break-condition
17119
17120@subsubheading Synopsis
17121
17122@smallexample
17123 -break-condition @var{number} @var{expr}
17124@end smallexample
17125
17126Breakpoint @var{number} will stop the program only if the condition in
17127@var{expr} is true. The condition becomes part of the
17128@samp{-break-list} output (see the description of the @samp{-break-list}
17129command below).
17130
17131@subsubheading @value{GDBN} Command
17132
17133The corresponding @value{GDBN} command is @samp{condition}.
17134
17135@subsubheading Example
17136
17137@smallexample
17138(@value{GDBP})
17139-break-condition 1 1
17140^done
17141(@value{GDBP})
17142-break-list
17143^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17144hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17145@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17146@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17147@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17148@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17149@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17150body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17151addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17152times="0",ignore="3"@}]@}
17153(@value{GDBP})
17154@end smallexample
17155
17156@subheading The @code{-break-delete} Command
17157@findex -break-delete
17158
17159@subsubheading Synopsis
17160
17161@smallexample
17162 -break-delete ( @var{breakpoint} )+
17163@end smallexample
17164
17165Delete the breakpoint(s) whose number(s) are specified in the argument
17166list. This is obviously reflected in the breakpoint list.
17167
17168@subsubheading @value{GDBN} command
17169
17170The corresponding @value{GDBN} command is @samp{delete}.
17171
17172@subsubheading Example
17173
17174@smallexample
17175(@value{GDBP})
17176-break-delete 1
17177^done
17178(@value{GDBP})
17179-break-list
17180^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17181hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17182@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17183@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17184@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17185@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17186@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17187body=[]@}
17188(@value{GDBP})
17189@end smallexample
17190
17191@subheading The @code{-break-disable} Command
17192@findex -break-disable
17193
17194@subsubheading Synopsis
17195
17196@smallexample
17197 -break-disable ( @var{breakpoint} )+
17198@end smallexample
17199
17200Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17201break list is now set to @samp{n} for the named @var{breakpoint}(s).
17202
17203@subsubheading @value{GDBN} Command
17204
17205The corresponding @value{GDBN} command is @samp{disable}.
17206
17207@subsubheading Example
17208
17209@smallexample
17210(@value{GDBP})
17211-break-disable 2
17212^done
17213(@value{GDBP})
17214-break-list
17215^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17216hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17217@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17218@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17219@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17220@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17221@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17222body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17223addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17224(@value{GDBP})
17225@end smallexample
17226
17227@subheading The @code{-break-enable} Command
17228@findex -break-enable
17229
17230@subsubheading Synopsis
17231
17232@smallexample
17233 -break-enable ( @var{breakpoint} )+
17234@end smallexample
17235
17236Enable (previously disabled) @var{breakpoint}(s).
17237
17238@subsubheading @value{GDBN} Command
17239
17240The corresponding @value{GDBN} command is @samp{enable}.
17241
17242@subsubheading Example
17243
17244@smallexample
17245(@value{GDBP})
17246-break-enable 2
17247^done
17248(@value{GDBP})
17249-break-list
17250^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17251hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17252@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17253@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17254@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17255@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17256@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17257body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17258addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17259(@value{GDBP})
17260@end smallexample
17261
17262@subheading The @code{-break-info} Command
17263@findex -break-info
17264
17265@subsubheading Synopsis
17266
17267@smallexample
17268 -break-info @var{breakpoint}
17269@end smallexample
17270
17271@c REDUNDANT???
17272Get information about a single breakpoint.
17273
17274@subsubheading @value{GDBN} command
17275
17276The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17277
17278@subsubheading Example
17279N.A.
17280
17281@subheading The @code{-break-insert} Command
17282@findex -break-insert
17283
17284@subsubheading Synopsis
17285
17286@smallexample
17287 -break-insert [ -t ] [ -h ] [ -r ]
17288 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17289 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17290@end smallexample
17291
17292@noindent
17293If specified, @var{line}, can be one of:
17294
17295@itemize @bullet
17296@item function
17297@c @item +offset
17298@c @item -offset
17299@c @item linenum
17300@item filename:linenum
17301@item filename:function
17302@item *address
17303@end itemize
17304
17305The possible optional parameters of this command are:
17306
17307@table @samp
17308@item -t
17309Insert a tempoary breakpoint.
17310@item -h
17311Insert a hardware breakpoint.
17312@item -c @var{condition}
17313Make the breakpoint conditional on @var{condition}.
17314@item -i @var{ignore-count}
17315Initialize the @var{ignore-count}.
17316@item -r
17317Insert a regular breakpoint in all the functions whose names match the
17318given regular expression. Other flags are not applicable to regular
17319expresson.
17320@end table
17321
17322@subsubheading Result
17323
17324The result is in the form:
17325
17326@smallexample
17327 ^done,bkptno="@var{number}",func="@var{funcname}",
17328 file="@var{filename}",line="@var{lineno}"
17329@end smallexample
17330
17331@noindent
17332where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17333is the name of the function where the breakpoint was inserted,
17334@var{filename} is the name of the source file which contains this
17335function, and @var{lineno} is the source line number within that file.
17336
17337Note: this format is open to change.
17338@c An out-of-band breakpoint instead of part of the result?
17339
17340@subsubheading @value{GDBN} Command
17341
17342The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17343@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17344
17345@subsubheading Example
17346
17347@smallexample
17348(@value{GDBP})
17349-break-insert main
17350^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17351(@value{GDBP})
17352-break-insert -t foo
17353^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17354(@value{GDBP})
17355-break-list
17356^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17357hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17358@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17359@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17360@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17361@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17362@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17363body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17364addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17365bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17366addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17367(@value{GDBP})
17368-break-insert -r foo.*
17369~int foo(int, int);
17370^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17371(@value{GDBP})
17372@end smallexample
17373
17374@subheading The @code{-break-list} Command
17375@findex -break-list
17376
17377@subsubheading Synopsis
17378
17379@smallexample
17380 -break-list
17381@end smallexample
17382
17383Displays the list of inserted breakpoints, showing the following fields:
17384
17385@table @samp
17386@item Number
17387number of the breakpoint
17388@item Type
17389type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17390@item Disposition
17391should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17392or @samp{nokeep}
17393@item Enabled
17394is the breakpoint enabled or no: @samp{y} or @samp{n}
17395@item Address
17396memory location at which the breakpoint is set
17397@item What
17398logical location of the breakpoint, expressed by function name, file
17399name, line number
17400@item Times
17401number of times the breakpoint has been hit
17402@end table
17403
17404If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17405@code{body} field is an empty list.
17406
17407@subsubheading @value{GDBN} Command
17408
17409The corresponding @value{GDBN} command is @samp{info break}.
17410
17411@subsubheading Example
17412
17413@smallexample
17414(@value{GDBP})
17415-break-list
17416^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17417hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17418@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17419@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17420@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17421@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17422@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17423body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17424addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17425bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17426addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17427(@value{GDBP})
17428@end smallexample
17429
17430Here's an example of the result when there are no breakpoints:
17431
17432@smallexample
17433(@value{GDBP})
17434-break-list
17435^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17436hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17437@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17438@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17439@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17440@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17441@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17442body=[]@}
17443(@value{GDBP})
17444@end smallexample
17445
17446@subheading The @code{-break-watch} Command
17447@findex -break-watch
17448
17449@subsubheading Synopsis
17450
17451@smallexample
17452 -break-watch [ -a | -r ]
17453@end smallexample
17454
17455Create a watchpoint. With the @samp{-a} option it will create an
17456@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17457read from or on a write to the memory location. With the @samp{-r}
17458option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17459trigger only when the memory location is accessed for reading. Without
17460either of the options, the watchpoint created is a regular watchpoint,
17461i.e. it will trigger when the memory location is accessed for writing.
17462@xref{Set Watchpoints, , Setting watchpoints}.
17463
17464Note that @samp{-break-list} will report a single list of watchpoints and
17465breakpoints inserted.
17466
17467@subsubheading @value{GDBN} Command
17468
17469The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17470@samp{rwatch}.
17471
17472@subsubheading Example
17473
17474Setting a watchpoint on a variable in the @code{main} function:
17475
17476@smallexample
17477(@value{GDBP})
17478-break-watch x
17479^done,wpt=@{number="2",exp="x"@}
17480(@value{GDBP})
17481-exec-continue
17482^running
17483^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17484value=@{old="-268439212",new="55"@},
76ff342d
DJ
17485frame=@{func="main",args=[],file="recursive2.c",
17486fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17487(@value{GDBP})
17488@end smallexample
17489
17490Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17491the program execution twice: first for the variable changing value, then
17492for the watchpoint going out of scope.
17493
17494@smallexample
17495(@value{GDBP})
17496-break-watch C
17497^done,wpt=@{number="5",exp="C"@}
17498(@value{GDBP})
17499-exec-continue
17500^running
17501^done,reason="watchpoint-trigger",
17502wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17503frame=@{func="callee4",args=[],
76ff342d
DJ
17504file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17505fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17506(@value{GDBP})
17507-exec-continue
17508^running
17509^done,reason="watchpoint-scope",wpnum="5",
17510frame=@{func="callee3",args=[@{name="strarg",
17511value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17512file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17513fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17514(@value{GDBP})
17515@end smallexample
17516
17517Listing breakpoints and watchpoints, at different points in the program
17518execution. Note that once the watchpoint goes out of scope, it is
17519deleted.
17520
17521@smallexample
17522(@value{GDBP})
17523-break-watch C
17524^done,wpt=@{number="2",exp="C"@}
17525(@value{GDBP})
17526-break-list
17527^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17528hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17529@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17530@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17531@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17532@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17533@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17534body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17535addr="0x00010734",func="callee4",
17536file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17537bkpt=@{number="2",type="watchpoint",disp="keep",
17538enabled="y",addr="",what="C",times="0"@}]@}
17539(@value{GDBP})
17540-exec-continue
17541^running
17542^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17543value=@{old="-276895068",new="3"@},
17544frame=@{func="callee4",args=[],
76ff342d
DJ
17545file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17546fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17547(@value{GDBP})
17548-break-list
17549^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17550hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17551@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17552@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17553@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17554@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17555@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17556body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17557addr="0x00010734",func="callee4",
17558file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17559bkpt=@{number="2",type="watchpoint",disp="keep",
17560enabled="y",addr="",what="C",times="-5"@}]@}
17561(@value{GDBP})
17562-exec-continue
17563^running
17564^done,reason="watchpoint-scope",wpnum="2",
17565frame=@{func="callee3",args=[@{name="strarg",
17566value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17567file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17568fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17569(@value{GDBP})
17570-break-list
17571^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17572hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17573@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17574@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17575@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17576@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17577@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17578body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17579addr="0x00010734",func="callee4",
17580file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17581(@value{GDBP})
17582@end smallexample
17583
17584@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17585@node GDB/MI Data Manipulation
17586@section @sc{gdb/mi} Data Manipulation
17587
17588@cindex data manipulation, in @sc{gdb/mi}
17589@cindex @sc{gdb/mi}, data manipulation
17590This section describes the @sc{gdb/mi} commands that manipulate data:
17591examine memory and registers, evaluate expressions, etc.
17592
17593@c REMOVED FROM THE INTERFACE.
17594@c @subheading -data-assign
17595@c Change the value of a program variable. Plenty of side effects.
17596@c @subsubheading GDB command
17597@c set variable
17598@c @subsubheading Example
17599@c N.A.
17600
17601@subheading The @code{-data-disassemble} Command
17602@findex -data-disassemble
17603
17604@subsubheading Synopsis
17605
17606@smallexample
17607 -data-disassemble
17608 [ -s @var{start-addr} -e @var{end-addr} ]
17609 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17610 -- @var{mode}
17611@end smallexample
17612
17613@noindent
17614Where:
17615
17616@table @samp
17617@item @var{start-addr}
17618is the beginning address (or @code{$pc})
17619@item @var{end-addr}
17620is the end address
17621@item @var{filename}
17622is the name of the file to disassemble
17623@item @var{linenum}
17624is the line number to disassemble around
17625@item @var{lines}
17626is the the number of disassembly lines to be produced. If it is -1,
17627the whole function will be disassembled, in case no @var{end-addr} is
17628specified. If @var{end-addr} is specified as a non-zero value, and
17629@var{lines} is lower than the number of disassembly lines between
17630@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17631displayed; if @var{lines} is higher than the number of lines between
17632@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17633are displayed.
17634@item @var{mode}
17635is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17636disassembly).
17637@end table
17638
17639@subsubheading Result
17640
17641The output for each instruction is composed of four fields:
17642
17643@itemize @bullet
17644@item Address
17645@item Func-name
17646@item Offset
17647@item Instruction
17648@end itemize
17649
17650Note that whatever included in the instruction field, is not manipulated
17651directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17652
17653@subsubheading @value{GDBN} Command
17654
17655There's no direct mapping from this command to the CLI.
17656
17657@subsubheading Example
17658
17659Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17660
17661@smallexample
17662(@value{GDBP})
17663-data-disassemble -s $pc -e "$pc + 20" -- 0
17664^done,
17665asm_insns=[
17666@{address="0x000107c0",func-name="main",offset="4",
17667inst="mov 2, %o0"@},
17668@{address="0x000107c4",func-name="main",offset="8",
17669inst="sethi %hi(0x11800), %o2"@},
17670@{address="0x000107c8",func-name="main",offset="12",
17671inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17672@{address="0x000107cc",func-name="main",offset="16",
17673inst="sethi %hi(0x11800), %o2"@},
17674@{address="0x000107d0",func-name="main",offset="20",
17675inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17676(@value{GDBP})
17677@end smallexample
17678
17679Disassemble the whole @code{main} function. Line 32 is part of
17680@code{main}.
17681
17682@smallexample
17683-data-disassemble -f basics.c -l 32 -- 0
17684^done,asm_insns=[
17685@{address="0x000107bc",func-name="main",offset="0",
17686inst="save %sp, -112, %sp"@},
17687@{address="0x000107c0",func-name="main",offset="4",
17688inst="mov 2, %o0"@},
17689@{address="0x000107c4",func-name="main",offset="8",
17690inst="sethi %hi(0x11800), %o2"@},
17691[@dots{}]
17692@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17693@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17694(@value{GDBP})
17695@end smallexample
17696
17697Disassemble 3 instructions from the start of @code{main}:
17698
17699@smallexample
17700(@value{GDBP})
17701-data-disassemble -f basics.c -l 32 -n 3 -- 0
17702^done,asm_insns=[
17703@{address="0x000107bc",func-name="main",offset="0",
17704inst="save %sp, -112, %sp"@},
17705@{address="0x000107c0",func-name="main",offset="4",
17706inst="mov 2, %o0"@},
17707@{address="0x000107c4",func-name="main",offset="8",
17708inst="sethi %hi(0x11800), %o2"@}]
17709(@value{GDBP})
17710@end smallexample
17711
17712Disassemble 3 instructions from the start of @code{main} in mixed mode:
17713
17714@smallexample
17715(@value{GDBP})
17716-data-disassemble -f basics.c -l 32 -n 3 -- 1
17717^done,asm_insns=[
17718src_and_asm_line=@{line="31",
17719file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17720 testsuite/gdb.mi/basics.c",line_asm_insn=[
17721@{address="0x000107bc",func-name="main",offset="0",
17722inst="save %sp, -112, %sp"@}]@},
17723src_and_asm_line=@{line="32",
17724file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17725 testsuite/gdb.mi/basics.c",line_asm_insn=[
17726@{address="0x000107c0",func-name="main",offset="4",
17727inst="mov 2, %o0"@},
17728@{address="0x000107c4",func-name="main",offset="8",
17729inst="sethi %hi(0x11800), %o2"@}]@}]
17730(@value{GDBP})
17731@end smallexample
17732
17733
17734@subheading The @code{-data-evaluate-expression} Command
17735@findex -data-evaluate-expression
17736
17737@subsubheading Synopsis
17738
17739@smallexample
17740 -data-evaluate-expression @var{expr}
17741@end smallexample
17742
17743Evaluate @var{expr} as an expression. The expression could contain an
17744inferior function call. The function call will execute synchronously.
17745If the expression contains spaces, it must be enclosed in double quotes.
17746
17747@subsubheading @value{GDBN} Command
17748
17749The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17750@samp{call}. In @code{gdbtk} only, there's a corresponding
17751@samp{gdb_eval} command.
17752
17753@subsubheading Example
17754
17755In the following example, the numbers that precede the commands are the
17756@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17757Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17758output.
17759
17760@smallexample
17761211-data-evaluate-expression A
17762211^done,value="1"
17763(@value{GDBP})
17764311-data-evaluate-expression &A
17765311^done,value="0xefffeb7c"
17766(@value{GDBP})
17767411-data-evaluate-expression A+3
17768411^done,value="4"
17769(@value{GDBP})
17770511-data-evaluate-expression "A + 3"
17771511^done,value="4"
17772(@value{GDBP})
17773@end smallexample
17774
17775
17776@subheading The @code{-data-list-changed-registers} Command
17777@findex -data-list-changed-registers
17778
17779@subsubheading Synopsis
17780
17781@smallexample
17782 -data-list-changed-registers
17783@end smallexample
17784
17785Display a list of the registers that have changed.
17786
17787@subsubheading @value{GDBN} Command
17788
17789@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17790has the corresponding command @samp{gdb_changed_register_list}.
17791
17792@subsubheading Example
17793
17794On a PPC MBX board:
17795
17796@smallexample
17797(@value{GDBP})
17798-exec-continue
17799^running
17800
17801(@value{GDBP})
17802*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17803args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17804(@value{GDBP})
17805-data-list-changed-registers
17806^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17807"10","11","13","14","15","16","17","18","19","20","21","22","23",
17808"24","25","26","27","28","30","31","64","65","66","67","69"]
17809(@value{GDBP})
17810@end smallexample
17811
17812
17813@subheading The @code{-data-list-register-names} Command
17814@findex -data-list-register-names
17815
17816@subsubheading Synopsis
17817
17818@smallexample
17819 -data-list-register-names [ ( @var{regno} )+ ]
17820@end smallexample
17821
17822Show a list of register names for the current target. If no arguments
17823are given, it shows a list of the names of all the registers. If
17824integer numbers are given as arguments, it will print a list of the
17825names of the registers corresponding to the arguments. To ensure
17826consistency between a register name and its number, the output list may
17827include empty register names.
17828
17829@subsubheading @value{GDBN} Command
17830
17831@value{GDBN} does not have a command which corresponds to
17832@samp{-data-list-register-names}. In @code{gdbtk} there is a
17833corresponding command @samp{gdb_regnames}.
17834
17835@subsubheading Example
17836
17837For the PPC MBX board:
17838@smallexample
17839(@value{GDBP})
17840-data-list-register-names
17841^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17842"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17843"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17844"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17845"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17846"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17847"", "pc","ps","cr","lr","ctr","xer"]
17848(@value{GDBP})
17849-data-list-register-names 1 2 3
17850^done,register-names=["r1","r2","r3"]
17851(@value{GDBP})
17852@end smallexample
17853
17854@subheading The @code{-data-list-register-values} Command
17855@findex -data-list-register-values
17856
17857@subsubheading Synopsis
17858
17859@smallexample
17860 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17861@end smallexample
17862
17863Display the registers' contents. @var{fmt} is the format according to
17864which the registers' contents are to be returned, followed by an optional
17865list of numbers specifying the registers to display. A missing list of
17866numbers indicates that the contents of all the registers must be returned.
17867
17868Allowed formats for @var{fmt} are:
17869
17870@table @code
17871@item x
17872Hexadecimal
17873@item o
17874Octal
17875@item t
17876Binary
17877@item d
17878Decimal
17879@item r
17880Raw
17881@item N
17882Natural
17883@end table
17884
17885@subsubheading @value{GDBN} Command
17886
17887The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17888all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17889
17890@subsubheading Example
17891
17892For a PPC MBX board (note: line breaks are for readability only, they
17893don't appear in the actual output):
17894
17895@smallexample
17896(@value{GDBP})
17897-data-list-register-values r 64 65
17898^done,register-values=[@{number="64",value="0xfe00a300"@},
17899@{number="65",value="0x00029002"@}]
17900(@value{GDBP})
17901-data-list-register-values x
17902^done,register-values=[@{number="0",value="0xfe0043c8"@},
17903@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17904@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17905@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17906@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17907@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17908@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17909@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17910@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17911@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17912@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17913@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17914@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17915@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17916@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17917@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17918@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17919@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17920@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17921@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17922@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17923@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17924@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17925@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17926@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17927@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17928@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17929@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17930@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17931@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17932@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17933@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17934@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17935@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17936@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17937@{number="69",value="0x20002b03"@}]
17938(@value{GDBP})
17939@end smallexample
17940
17941
17942@subheading The @code{-data-read-memory} Command
17943@findex -data-read-memory
17944
17945@subsubheading Synopsis
17946
17947@smallexample
17948 -data-read-memory [ -o @var{byte-offset} ]
17949 @var{address} @var{word-format} @var{word-size}
17950 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17951@end smallexample
17952
17953@noindent
17954where:
17955
17956@table @samp
17957@item @var{address}
17958An expression specifying the address of the first memory word to be
17959read. Complex expressions containing embedded white space should be
17960quoted using the C convention.
17961
17962@item @var{word-format}
17963The format to be used to print the memory words. The notation is the
17964same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
17965,Output formats}).
17966
17967@item @var{word-size}
17968The size of each memory word in bytes.
17969
17970@item @var{nr-rows}
17971The number of rows in the output table.
17972
17973@item @var{nr-cols}
17974The number of columns in the output table.
17975
17976@item @var{aschar}
17977If present, indicates that each row should include an @sc{ascii} dump. The
17978value of @var{aschar} is used as a padding character when a byte is not a
17979member of the printable @sc{ascii} character set (printable @sc{ascii}
17980characters are those whose code is between 32 and 126, inclusively).
17981
17982@item @var{byte-offset}
17983An offset to add to the @var{address} before fetching memory.
17984@end table
17985
17986This command displays memory contents as a table of @var{nr-rows} by
17987@var{nr-cols} words, each word being @var{word-size} bytes. In total,
17988@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
17989(returned as @samp{total-bytes}). Should less than the requested number
17990of bytes be returned by the target, the missing words are identified
17991using @samp{N/A}. The number of bytes read from the target is returned
17992in @samp{nr-bytes} and the starting address used to read memory in
17993@samp{addr}.
17994
17995The address of the next/previous row or page is available in
17996@samp{next-row} and @samp{prev-row}, @samp{next-page} and
17997@samp{prev-page}.
17998
17999@subsubheading @value{GDBN} Command
18000
18001The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18002@samp{gdb_get_mem} memory read command.
18003
18004@subsubheading Example
18005
18006Read six bytes of memory starting at @code{bytes+6} but then offset by
18007@code{-6} bytes. Format as three rows of two columns. One byte per
18008word. Display each word in hex.
18009
18010@smallexample
18011(@value{GDBP})
180129-data-read-memory -o -6 -- bytes+6 x 1 3 2
180139^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18014next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18015prev-page="0x0000138a",memory=[
18016@{addr="0x00001390",data=["0x00","0x01"]@},
18017@{addr="0x00001392",data=["0x02","0x03"]@},
18018@{addr="0x00001394",data=["0x04","0x05"]@}]
18019(@value{GDBP})
18020@end smallexample
18021
18022Read two bytes of memory starting at address @code{shorts + 64} and
18023display as a single word formatted in decimal.
18024
18025@smallexample
18026(@value{GDBP})
180275-data-read-memory shorts+64 d 2 1 1
180285^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18029next-row="0x00001512",prev-row="0x0000150e",
18030next-page="0x00001512",prev-page="0x0000150e",memory=[
18031@{addr="0x00001510",data=["128"]@}]
18032(@value{GDBP})
18033@end smallexample
18034
18035Read thirty two bytes of memory starting at @code{bytes+16} and format
18036as eight rows of four columns. Include a string encoding with @samp{x}
18037used as the non-printable character.
18038
18039@smallexample
18040(@value{GDBP})
180414-data-read-memory bytes+16 x 1 8 4 x
180424^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18043next-row="0x000013c0",prev-row="0x0000139c",
18044next-page="0x000013c0",prev-page="0x00001380",memory=[
18045@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18046@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18047@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18048@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18049@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18050@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18051@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18052@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18053(@value{GDBP})
18054@end smallexample
18055
18056@subheading The @code{-display-delete} Command
18057@findex -display-delete
18058
18059@subsubheading Synopsis
18060
18061@smallexample
18062 -display-delete @var{number}
18063@end smallexample
18064
18065Delete the display @var{number}.
18066
18067@subsubheading @value{GDBN} Command
18068
18069The corresponding @value{GDBN} command is @samp{delete display}.
18070
18071@subsubheading Example
18072N.A.
18073
18074
18075@subheading The @code{-display-disable} Command
18076@findex -display-disable
18077
18078@subsubheading Synopsis
18079
18080@smallexample
18081 -display-disable @var{number}
18082@end smallexample
18083
18084Disable display @var{number}.
18085
18086@subsubheading @value{GDBN} Command
18087
18088The corresponding @value{GDBN} command is @samp{disable display}.
18089
18090@subsubheading Example
18091N.A.
18092
18093
18094@subheading The @code{-display-enable} Command
18095@findex -display-enable
18096
18097@subsubheading Synopsis
18098
18099@smallexample
18100 -display-enable @var{number}
18101@end smallexample
18102
18103Enable display @var{number}.
18104
18105@subsubheading @value{GDBN} Command
18106
18107The corresponding @value{GDBN} command is @samp{enable display}.
18108
18109@subsubheading Example
18110N.A.
18111
18112
18113@subheading The @code{-display-insert} Command
18114@findex -display-insert
18115
18116@subsubheading Synopsis
18117
18118@smallexample
18119 -display-insert @var{expression}
18120@end smallexample
18121
18122Display @var{expression} every time the program stops.
18123
18124@subsubheading @value{GDBN} Command
18125
18126The corresponding @value{GDBN} command is @samp{display}.
18127
18128@subsubheading Example
18129N.A.
18130
18131
18132@subheading The @code{-display-list} Command
18133@findex -display-list
18134
18135@subsubheading Synopsis
18136
18137@smallexample
18138 -display-list
18139@end smallexample
18140
18141List the displays. Do not show the current values.
18142
18143@subsubheading @value{GDBN} Command
18144
18145The corresponding @value{GDBN} command is @samp{info display}.
18146
18147@subsubheading Example
18148N.A.
18149
18150
18151@subheading The @code{-environment-cd} Command
18152@findex -environment-cd
18153
18154@subsubheading Synopsis
18155
18156@smallexample
18157 -environment-cd @var{pathdir}
18158@end smallexample
18159
18160Set @value{GDBN}'s working directory.
18161
18162@subsubheading @value{GDBN} Command
18163
18164The corresponding @value{GDBN} command is @samp{cd}.
18165
18166@subsubheading Example
18167
18168@smallexample
18169(@value{GDBP})
18170-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18171^done
18172(@value{GDBP})
18173@end smallexample
18174
18175
18176@subheading The @code{-environment-directory} Command
18177@findex -environment-directory
18178
18179@subsubheading Synopsis
18180
18181@smallexample
18182 -environment-directory [ -r ] [ @var{pathdir} ]+
18183@end smallexample
18184
18185Add directories @var{pathdir} to beginning of search path for source files.
18186If the @samp{-r} option is used, the search path is reset to the default
b383017d 18187search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18188@samp{-r} option, the search path is first reset and then addition
18189occurs as normal.
b383017d 18190Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18191multiple directories in a single command
18192results in the directories added to the beginning of the
18193search path in the same order they were presented in the command.
18194If blanks are needed as
18195part of a directory name, double-quotes should be used around
18196the name. In the command output, the path will show up separated
b383017d 18197by the system directory-separator character. The directory-seperator
922fbb7b
AC
18198character must not be used
18199in any directory name.
18200If no directories are specified, the current search path is displayed.
18201
18202@subsubheading @value{GDBN} Command
18203
18204The corresponding @value{GDBN} command is @samp{dir}.
18205
18206@subsubheading Example
18207
18208@smallexample
18209(@value{GDBP})
18210-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18211^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18212(@value{GDBP})
18213-environment-directory ""
18214^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18215(@value{GDBP})
18216-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18217^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18218(@value{GDBP})
18219-environment-directory -r
18220^done,source-path="$cdir:$cwd"
18221(@value{GDBP})
18222@end smallexample
18223
18224
18225@subheading The @code{-environment-path} Command
18226@findex -environment-path
18227
18228@subsubheading Synopsis
18229
18230@smallexample
18231 -environment-path [ -r ] [ @var{pathdir} ]+
18232@end smallexample
18233
18234Add directories @var{pathdir} to beginning of search path for object files.
18235If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18236search path that existed at gdb start-up. If directories @var{pathdir} are
18237supplied in addition to the
922fbb7b
AC
18238@samp{-r} option, the search path is first reset and then addition
18239occurs as normal.
b383017d 18240Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18241multiple directories in a single command
18242results in the directories added to the beginning of the
18243search path in the same order they were presented in the command.
18244If blanks are needed as
18245part of a directory name, double-quotes should be used around
18246the name. In the command output, the path will show up separated
b383017d 18247by the system directory-separator character. The directory-seperator
922fbb7b
AC
18248character must not be used
18249in any directory name.
18250If no directories are specified, the current path is displayed.
18251
18252
18253@subsubheading @value{GDBN} Command
18254
18255The corresponding @value{GDBN} command is @samp{path}.
18256
18257@subsubheading Example
18258
18259@smallexample
18260(@value{GDBP})
b383017d 18261-environment-path
922fbb7b
AC
18262^done,path="/usr/bin"
18263(@value{GDBP})
18264-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18265^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18266(@value{GDBP})
18267-environment-path -r /usr/local/bin
18268^done,path="/usr/local/bin:/usr/bin"
18269(@value{GDBP})
18270@end smallexample
18271
18272
18273@subheading The @code{-environment-pwd} Command
18274@findex -environment-pwd
18275
18276@subsubheading Synopsis
18277
18278@smallexample
18279 -environment-pwd
18280@end smallexample
18281
18282Show the current working directory.
18283
18284@subsubheading @value{GDBN} command
18285
18286The corresponding @value{GDBN} command is @samp{pwd}.
18287
18288@subsubheading Example
18289
18290@smallexample
18291(@value{GDBP})
18292-environment-pwd
18293^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18294(@value{GDBP})
18295@end smallexample
18296
18297@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18298@node GDB/MI Program Control
18299@section @sc{gdb/mi} Program control
18300
18301@subsubheading Program termination
18302
18303As a result of execution, the inferior program can run to completion, if
18304it doesn't encounter any breakpoints. In this case the output will
18305include an exit code, if the program has exited exceptionally.
18306
18307@subsubheading Examples
18308
18309@noindent
18310Program exited normally:
18311
18312@smallexample
18313(@value{GDBP})
18314-exec-run
18315^running
18316(@value{GDBP})
18317x = 55
18318*stopped,reason="exited-normally"
18319(@value{GDBP})
18320@end smallexample
18321
18322@noindent
18323Program exited exceptionally:
18324
18325@smallexample
18326(@value{GDBP})
18327-exec-run
18328^running
18329(@value{GDBP})
18330x = 55
18331*stopped,reason="exited",exit-code="01"
18332(@value{GDBP})
18333@end smallexample
18334
18335Another way the program can terminate is if it receives a signal such as
18336@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18337
18338@smallexample
18339(@value{GDBP})
18340*stopped,reason="exited-signalled",signal-name="SIGINT",
18341signal-meaning="Interrupt"
18342@end smallexample
18343
18344
18345@subheading The @code{-exec-abort} Command
18346@findex -exec-abort
18347
18348@subsubheading Synopsis
18349
18350@smallexample
18351 -exec-abort
18352@end smallexample
18353
18354Kill the inferior running program.
18355
18356@subsubheading @value{GDBN} Command
18357
18358The corresponding @value{GDBN} command is @samp{kill}.
18359
18360@subsubheading Example
18361N.A.
18362
18363
18364@subheading The @code{-exec-arguments} Command
18365@findex -exec-arguments
18366
18367@subsubheading Synopsis
18368
18369@smallexample
18370 -exec-arguments @var{args}
18371@end smallexample
18372
18373Set the inferior program arguments, to be used in the next
18374@samp{-exec-run}.
18375
18376@subsubheading @value{GDBN} Command
18377
18378The corresponding @value{GDBN} command is @samp{set args}.
18379
18380@subsubheading Example
18381
18382@c FIXME!
18383Don't have one around.
18384
18385
18386@subheading The @code{-exec-continue} Command
18387@findex -exec-continue
18388
18389@subsubheading Synopsis
18390
18391@smallexample
18392 -exec-continue
18393@end smallexample
18394
18395Asynchronous command. Resumes the execution of the inferior program
18396until a breakpoint is encountered, or until the inferior exits.
18397
18398@subsubheading @value{GDBN} Command
18399
18400The corresponding @value{GDBN} corresponding is @samp{continue}.
18401
18402@subsubheading Example
18403
18404@smallexample
18405-exec-continue
18406^running
18407(@value{GDBP})
18408@@Hello world
18409*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18410file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18411(@value{GDBP})
18412@end smallexample
18413
18414
18415@subheading The @code{-exec-finish} Command
18416@findex -exec-finish
18417
18418@subsubheading Synopsis
18419
18420@smallexample
18421 -exec-finish
18422@end smallexample
18423
18424Asynchronous command. Resumes the execution of the inferior program
18425until the current function is exited. Displays the results returned by
18426the function.
18427
18428@subsubheading @value{GDBN} Command
18429
18430The corresponding @value{GDBN} command is @samp{finish}.
18431
18432@subsubheading Example
18433
18434Function returning @code{void}.
18435
18436@smallexample
18437-exec-finish
18438^running
18439(@value{GDBP})
18440@@hello from foo
18441*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18442file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18443(@value{GDBP})
18444@end smallexample
18445
18446Function returning other than @code{void}. The name of the internal
18447@value{GDBN} variable storing the result is printed, together with the
18448value itself.
18449
18450@smallexample
18451-exec-finish
18452^running
18453(@value{GDBP})
18454*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18455args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18456file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18457gdb-result-var="$1",return-value="0"
18458(@value{GDBP})
18459@end smallexample
18460
18461
18462@subheading The @code{-exec-interrupt} Command
18463@findex -exec-interrupt
18464
18465@subsubheading Synopsis
18466
18467@smallexample
18468 -exec-interrupt
18469@end smallexample
18470
18471Asynchronous command. Interrupts the background execution of the target.
18472Note how the token associated with the stop message is the one for the
18473execution command that has been interrupted. The token for the interrupt
18474itself only appears in the @samp{^done} output. If the user is trying to
18475interrupt a non-running program, an error message will be printed.
18476
18477@subsubheading @value{GDBN} Command
18478
18479The corresponding @value{GDBN} command is @samp{interrupt}.
18480
18481@subsubheading Example
18482
18483@smallexample
18484(@value{GDBP})
18485111-exec-continue
18486111^running
18487
18488(@value{GDBP})
18489222-exec-interrupt
18490222^done
18491(@value{GDBP})
18492111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18493frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18494fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18495(@value{GDBP})
18496
18497(@value{GDBP})
18498-exec-interrupt
18499^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18500(@value{GDBP})
18501@end smallexample
18502
18503
18504@subheading The @code{-exec-next} Command
18505@findex -exec-next
18506
18507@subsubheading Synopsis
18508
18509@smallexample
18510 -exec-next
18511@end smallexample
18512
18513Asynchronous command. Resumes execution of the inferior program, stopping
18514when the beginning of the next source line is reached.
18515
18516@subsubheading @value{GDBN} Command
18517
18518The corresponding @value{GDBN} command is @samp{next}.
18519
18520@subsubheading Example
18521
18522@smallexample
18523-exec-next
18524^running
18525(@value{GDBP})
18526*stopped,reason="end-stepping-range",line="8",file="hello.c"
18527(@value{GDBP})
18528@end smallexample
18529
18530
18531@subheading The @code{-exec-next-instruction} Command
18532@findex -exec-next-instruction
18533
18534@subsubheading Synopsis
18535
18536@smallexample
18537 -exec-next-instruction
18538@end smallexample
18539
18540Asynchronous command. Executes one machine instruction. If the
18541instruction is a function call continues until the function returns. If
18542the program stops at an instruction in the middle of a source line, the
18543address will be printed as well.
18544
18545@subsubheading @value{GDBN} Command
18546
18547The corresponding @value{GDBN} command is @samp{nexti}.
18548
18549@subsubheading Example
18550
18551@smallexample
18552(@value{GDBP})
18553-exec-next-instruction
18554^running
18555
18556(@value{GDBP})
18557*stopped,reason="end-stepping-range",
18558addr="0x000100d4",line="5",file="hello.c"
18559(@value{GDBP})
18560@end smallexample
18561
18562
18563@subheading The @code{-exec-return} Command
18564@findex -exec-return
18565
18566@subsubheading Synopsis
18567
18568@smallexample
18569 -exec-return
18570@end smallexample
18571
18572Makes current function return immediately. Doesn't execute the inferior.
18573Displays the new current frame.
18574
18575@subsubheading @value{GDBN} Command
18576
18577The corresponding @value{GDBN} command is @samp{return}.
18578
18579@subsubheading Example
18580
18581@smallexample
18582(@value{GDBP})
18583200-break-insert callee4
18584200^done,bkpt=@{number="1",addr="0x00010734",
18585file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18586(@value{GDBP})
18587000-exec-run
18588000^running
18589(@value{GDBP})
18590000*stopped,reason="breakpoint-hit",bkptno="1",
18591frame=@{func="callee4",args=[],
76ff342d
DJ
18592file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18593fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18594(@value{GDBP})
18595205-break-delete
18596205^done
18597(@value{GDBP})
18598111-exec-return
18599111^done,frame=@{level="0",func="callee3",
18600args=[@{name="strarg",
18601value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18602file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18603fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18604(@value{GDBP})
18605@end smallexample
18606
18607
18608@subheading The @code{-exec-run} Command
18609@findex -exec-run
18610
18611@subsubheading Synopsis
18612
18613@smallexample
18614 -exec-run
18615@end smallexample
18616
18617Asynchronous command. Starts execution of the inferior from the
18618beginning. The inferior executes until either a breakpoint is
18619encountered or the program exits.
18620
18621@subsubheading @value{GDBN} Command
18622
18623The corresponding @value{GDBN} command is @samp{run}.
18624
18625@subsubheading Example
18626
18627@smallexample
18628(@value{GDBP})
18629-break-insert main
18630^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18631(@value{GDBP})
18632-exec-run
18633^running
18634(@value{GDBP})
18635*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18636frame=@{func="main",args=[],file="recursive2.c",
18637fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18638(@value{GDBP})
18639@end smallexample
18640
18641
18642@subheading The @code{-exec-show-arguments} Command
18643@findex -exec-show-arguments
18644
18645@subsubheading Synopsis
18646
18647@smallexample
18648 -exec-show-arguments
18649@end smallexample
18650
18651Print the arguments of the program.
18652
18653@subsubheading @value{GDBN} Command
18654
18655The corresponding @value{GDBN} command is @samp{show args}.
18656
18657@subsubheading Example
18658N.A.
18659
18660@c @subheading -exec-signal
18661
18662@subheading The @code{-exec-step} Command
18663@findex -exec-step
18664
18665@subsubheading Synopsis
18666
18667@smallexample
18668 -exec-step
18669@end smallexample
18670
18671Asynchronous command. Resumes execution of the inferior program, stopping
18672when the beginning of the next source line is reached, if the next
18673source line is not a function call. If it is, stop at the first
18674instruction of the called function.
18675
18676@subsubheading @value{GDBN} Command
18677
18678The corresponding @value{GDBN} command is @samp{step}.
18679
18680@subsubheading Example
18681
18682Stepping into a function:
18683
18684@smallexample
18685-exec-step
18686^running
18687(@value{GDBP})
18688*stopped,reason="end-stepping-range",
18689frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18690@{name="b",value="0"@}],file="recursive2.c",
18691fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18692(@value{GDBP})
18693@end smallexample
18694
18695Regular stepping:
18696
18697@smallexample
18698-exec-step
18699^running
18700(@value{GDBP})
18701*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18702(@value{GDBP})
18703@end smallexample
18704
18705
18706@subheading The @code{-exec-step-instruction} Command
18707@findex -exec-step-instruction
18708
18709@subsubheading Synopsis
18710
18711@smallexample
18712 -exec-step-instruction
18713@end smallexample
18714
18715Asynchronous command. Resumes the inferior which executes one machine
18716instruction. The output, once @value{GDBN} has stopped, will vary depending on
18717whether we have stopped in the middle of a source line or not. In the
18718former case, the address at which the program stopped will be printed as
18719well.
18720
18721@subsubheading @value{GDBN} Command
18722
18723The corresponding @value{GDBN} command is @samp{stepi}.
18724
18725@subsubheading Example
18726
18727@smallexample
18728(@value{GDBP})
18729-exec-step-instruction
18730^running
18731
18732(@value{GDBP})
18733*stopped,reason="end-stepping-range",
76ff342d
DJ
18734frame=@{func="foo",args=[],file="try.c",
18735fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18736(@value{GDBP})
18737-exec-step-instruction
18738^running
18739
18740(@value{GDBP})
18741*stopped,reason="end-stepping-range",
76ff342d
DJ
18742frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18743fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18744(@value{GDBP})
18745@end smallexample
18746
18747
18748@subheading The @code{-exec-until} Command
18749@findex -exec-until
18750
18751@subsubheading Synopsis
18752
18753@smallexample
18754 -exec-until [ @var{location} ]
18755@end smallexample
18756
18757Asynchronous command. Executes the inferior until the @var{location}
18758specified in the argument is reached. If there is no argument, the inferior
18759executes until a source line greater than the current one is reached.
18760The reason for stopping in this case will be @samp{location-reached}.
18761
18762@subsubheading @value{GDBN} Command
18763
18764The corresponding @value{GDBN} command is @samp{until}.
18765
18766@subsubheading Example
18767
18768@smallexample
18769(@value{GDBP})
18770-exec-until recursive2.c:6
18771^running
18772(@value{GDBP})
18773x = 55
18774*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18775file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18776(@value{GDBP})
18777@end smallexample
18778
18779@ignore
18780@subheading -file-clear
18781Is this going away????
18782@end ignore
18783
18784
18785@subheading The @code{-file-exec-and-symbols} Command
18786@findex -file-exec-and-symbols
18787
18788@subsubheading Synopsis
18789
18790@smallexample
18791 -file-exec-and-symbols @var{file}
18792@end smallexample
18793
18794Specify the executable file to be debugged. This file is the one from
18795which the symbol table is also read. If no file is specified, the
18796command clears the executable and symbol information. If breakpoints
18797are set when using this command with no arguments, @value{GDBN} will produce
18798error messages. Otherwise, no output is produced, except a completion
18799notification.
18800
18801@subsubheading @value{GDBN} Command
18802
18803The corresponding @value{GDBN} command is @samp{file}.
18804
18805@subsubheading Example
18806
18807@smallexample
18808(@value{GDBP})
18809-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18810^done
18811(@value{GDBP})
18812@end smallexample
18813
18814
18815@subheading The @code{-file-exec-file} Command
18816@findex -file-exec-file
18817
18818@subsubheading Synopsis
18819
18820@smallexample
18821 -file-exec-file @var{file}
18822@end smallexample
18823
18824Specify the executable file to be debugged. Unlike
18825@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18826from this file. If used without argument, @value{GDBN} clears the information
18827about the executable file. No output is produced, except a completion
18828notification.
18829
18830@subsubheading @value{GDBN} Command
18831
18832The corresponding @value{GDBN} command is @samp{exec-file}.
18833
18834@subsubheading Example
18835
18836@smallexample
18837(@value{GDBP})
18838-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18839^done
18840(@value{GDBP})
18841@end smallexample
18842
18843
18844@subheading The @code{-file-list-exec-sections} Command
18845@findex -file-list-exec-sections
18846
18847@subsubheading Synopsis
18848
18849@smallexample
18850 -file-list-exec-sections
18851@end smallexample
18852
18853List the sections of the current executable file.
18854
18855@subsubheading @value{GDBN} Command
18856
18857The @value{GDBN} command @samp{info file} shows, among the rest, the same
18858information as this command. @code{gdbtk} has a corresponding command
18859@samp{gdb_load_info}.
18860
18861@subsubheading Example
18862N.A.
18863
18864
1abaf70c
BR
18865@subheading The @code{-file-list-exec-source-file} Command
18866@findex -file-list-exec-source-file
18867
18868@subsubheading Synopsis
18869
18870@smallexample
18871 -file-list-exec-source-file
18872@end smallexample
18873
b383017d 18874List the line number, the current source file, and the absolute path
1abaf70c
BR
18875to the current source file for the current executable.
18876
18877@subsubheading @value{GDBN} Command
18878
18879There's no @value{GDBN} command which directly corresponds to this one.
18880
18881@subsubheading Example
18882
18883@smallexample
18884(@value{GDBP})
18885123-file-list-exec-source-file
18886123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18887(@value{GDBP})
18888@end smallexample
18889
18890
922fbb7b
AC
18891@subheading The @code{-file-list-exec-source-files} Command
18892@findex -file-list-exec-source-files
18893
18894@subsubheading Synopsis
18895
18896@smallexample
18897 -file-list-exec-source-files
18898@end smallexample
18899
18900List the source files for the current executable.
18901
57c22c6c
BR
18902It will always output the filename, but only when GDB can find the absolute
18903file name of a source file, will it output the fullname.
18904
922fbb7b
AC
18905@subsubheading @value{GDBN} Command
18906
18907There's no @value{GDBN} command which directly corresponds to this one.
18908@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18909
18910@subsubheading Example
57c22c6c
BR
18911@smallexample
18912(@value{GDBP})
18913-file-list-exec-source-files
18914^done,files=[
18915@{file=foo.c,fullname=/home/foo.c@},
18916@{file=/home/bar.c,fullname=/home/bar.c@},
18917@{file=gdb_could_not_find_fullpath.c@}]
18918(@value{GDBP})
18919@end smallexample
922fbb7b
AC
18920
18921@subheading The @code{-file-list-shared-libraries} Command
18922@findex -file-list-shared-libraries
18923
18924@subsubheading Synopsis
18925
18926@smallexample
18927 -file-list-shared-libraries
18928@end smallexample
18929
18930List the shared libraries in the program.
18931
18932@subsubheading @value{GDBN} Command
18933
18934The corresponding @value{GDBN} command is @samp{info shared}.
18935
18936@subsubheading Example
18937N.A.
18938
18939
18940@subheading The @code{-file-list-symbol-files} Command
18941@findex -file-list-symbol-files
18942
18943@subsubheading Synopsis
18944
18945@smallexample
18946 -file-list-symbol-files
18947@end smallexample
18948
18949List symbol files.
18950
18951@subsubheading @value{GDBN} Command
18952
18953The corresponding @value{GDBN} command is @samp{info file} (part of it).
18954
18955@subsubheading Example
18956N.A.
18957
18958
18959@subheading The @code{-file-symbol-file} Command
18960@findex -file-symbol-file
18961
18962@subsubheading Synopsis
18963
18964@smallexample
18965 -file-symbol-file @var{file}
18966@end smallexample
18967
18968Read symbol table info from the specified @var{file} argument. When
18969used without arguments, clears @value{GDBN}'s symbol table info. No output is
18970produced, except for a completion notification.
18971
18972@subsubheading @value{GDBN} Command
18973
18974The corresponding @value{GDBN} command is @samp{symbol-file}.
18975
18976@subsubheading Example
18977
18978@smallexample
18979(@value{GDBP})
18980-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18981^done
18982(@value{GDBP})
18983@end smallexample
18984
18985@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18986@node GDB/MI Miscellaneous Commands
18987@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
18988
18989@c @subheading -gdb-complete
18990
18991@subheading The @code{-gdb-exit} Command
18992@findex -gdb-exit
18993
18994@subsubheading Synopsis
18995
18996@smallexample
18997 -gdb-exit
18998@end smallexample
18999
19000Exit @value{GDBN} immediately.
19001
19002@subsubheading @value{GDBN} Command
19003
19004Approximately corresponds to @samp{quit}.
19005
19006@subsubheading Example
19007
19008@smallexample
19009(@value{GDBP})
19010-gdb-exit
19011@end smallexample
19012
19013@subheading The @code{-gdb-set} Command
19014@findex -gdb-set
19015
19016@subsubheading Synopsis
19017
19018@smallexample
19019 -gdb-set
19020@end smallexample
19021
19022Set an internal @value{GDBN} variable.
19023@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19024
19025@subsubheading @value{GDBN} Command
19026
19027The corresponding @value{GDBN} command is @samp{set}.
19028
19029@subsubheading Example
19030
19031@smallexample
19032(@value{GDBP})
19033-gdb-set $foo=3
19034^done
19035(@value{GDBP})
19036@end smallexample
19037
19038
19039@subheading The @code{-gdb-show} Command
19040@findex -gdb-show
19041
19042@subsubheading Synopsis
19043
19044@smallexample
19045 -gdb-show
19046@end smallexample
19047
19048Show the current value of a @value{GDBN} variable.
19049
19050@subsubheading @value{GDBN} command
19051
19052The corresponding @value{GDBN} command is @samp{show}.
19053
19054@subsubheading Example
19055
19056@smallexample
19057(@value{GDBP})
19058-gdb-show annotate
19059^done,value="0"
19060(@value{GDBP})
19061@end smallexample
19062
19063@c @subheading -gdb-source
19064
19065
19066@subheading The @code{-gdb-version} Command
19067@findex -gdb-version
19068
19069@subsubheading Synopsis
19070
19071@smallexample
19072 -gdb-version
19073@end smallexample
19074
19075Show version information for @value{GDBN}. Used mostly in testing.
19076
19077@subsubheading @value{GDBN} Command
19078
19079There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19080information when you start an interactive session.
19081
19082@subsubheading Example
19083
19084@c This example modifies the actual output from GDB to avoid overfull
19085@c box in TeX.
19086@smallexample
19087(@value{GDBP})
19088-gdb-version
19089~GNU gdb 5.2.1
19090~Copyright 2000 Free Software Foundation, Inc.
19091~GDB is free software, covered by the GNU General Public License, and
19092~you are welcome to change it and/or distribute copies of it under
19093~ certain conditions.
19094~Type "show copying" to see the conditions.
19095~There is absolutely no warranty for GDB. Type "show warranty" for
19096~ details.
b383017d 19097~This GDB was configured as
922fbb7b
AC
19098 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19099^done
19100(@value{GDBP})
19101@end smallexample
19102
19103@subheading The @code{-interpreter-exec} Command
19104@findex -interpreter-exec
19105
19106@subheading Synopsis
19107
19108@smallexample
19109-interpreter-exec @var{interpreter} @var{command}
19110@end smallexample
19111
19112Execute the specified @var{command} in the given @var{interpreter}.
19113
19114@subheading @value{GDBN} Command
19115
19116The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19117
19118@subheading Example
19119
19120@smallexample
19121(@value{GDBP})
19122-interpreter-exec console "break main"
19123&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19124&"During symbol reading, bad structure-type format.\n"
19125~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19126^done
19127(@value{GDBP})
19128@end smallexample
19129
19130@ignore
19131@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19132@node GDB/MI Kod Commands
19133@section @sc{gdb/mi} Kod Commands
19134
19135The Kod commands are not implemented.
19136
19137@c @subheading -kod-info
19138
19139@c @subheading -kod-list
19140
19141@c @subheading -kod-list-object-types
19142
19143@c @subheading -kod-show
19144
19145@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19146@node GDB/MI Memory Overlay Commands
19147@section @sc{gdb/mi} Memory Overlay Commands
19148
19149The memory overlay commands are not implemented.
19150
19151@c @subheading -overlay-auto
19152
19153@c @subheading -overlay-list-mapping-state
19154
19155@c @subheading -overlay-list-overlays
19156
19157@c @subheading -overlay-map
19158
19159@c @subheading -overlay-off
19160
19161@c @subheading -overlay-on
19162
19163@c @subheading -overlay-unmap
19164
19165@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19166@node GDB/MI Signal Handling Commands
19167@section @sc{gdb/mi} Signal Handling Commands
19168
19169Signal handling commands are not implemented.
19170
19171@c @subheading -signal-handle
19172
19173@c @subheading -signal-list-handle-actions
19174
19175@c @subheading -signal-list-signal-types
19176@end ignore
19177
19178
19179@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19180@node GDB/MI Stack Manipulation
19181@section @sc{gdb/mi} Stack Manipulation Commands
19182
19183
19184@subheading The @code{-stack-info-frame} Command
19185@findex -stack-info-frame
19186
19187@subsubheading Synopsis
19188
19189@smallexample
19190 -stack-info-frame
19191@end smallexample
19192
19193Get info on the current frame.
19194
19195@subsubheading @value{GDBN} Command
19196
19197The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19198(without arguments).
19199
19200@subsubheading Example
19201N.A.
19202
19203@subheading The @code{-stack-info-depth} Command
19204@findex -stack-info-depth
19205
19206@subsubheading Synopsis
19207
19208@smallexample
19209 -stack-info-depth [ @var{max-depth} ]
19210@end smallexample
19211
19212Return the depth of the stack. If the integer argument @var{max-depth}
19213is specified, do not count beyond @var{max-depth} frames.
19214
19215@subsubheading @value{GDBN} Command
19216
19217There's no equivalent @value{GDBN} command.
19218
19219@subsubheading Example
19220
19221For a stack with frame levels 0 through 11:
19222
19223@smallexample
19224(@value{GDBP})
19225-stack-info-depth
19226^done,depth="12"
19227(@value{GDBP})
19228-stack-info-depth 4
19229^done,depth="4"
19230(@value{GDBP})
19231-stack-info-depth 12
19232^done,depth="12"
19233(@value{GDBP})
19234-stack-info-depth 11
19235^done,depth="11"
19236(@value{GDBP})
19237-stack-info-depth 13
19238^done,depth="12"
19239(@value{GDBP})
19240@end smallexample
19241
19242@subheading The @code{-stack-list-arguments} Command
19243@findex -stack-list-arguments
19244
19245@subsubheading Synopsis
19246
19247@smallexample
19248 -stack-list-arguments @var{show-values}
19249 [ @var{low-frame} @var{high-frame} ]
19250@end smallexample
19251
19252Display a list of the arguments for the frames between @var{low-frame}
19253and @var{high-frame} (inclusive). If @var{low-frame} and
19254@var{high-frame} are not provided, list the arguments for the whole call
19255stack.
19256
19257The @var{show-values} argument must have a value of 0 or 1. A value of
192580 means that only the names of the arguments are listed, a value of 1
19259means that both names and values of the arguments are printed.
19260
19261@subsubheading @value{GDBN} Command
19262
19263@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19264@samp{gdb_get_args} command which partially overlaps with the
19265functionality of @samp{-stack-list-arguments}.
19266
19267@subsubheading Example
19268
19269@smallexample
19270(@value{GDBP})
19271-stack-list-frames
19272^done,
19273stack=[
19274frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19275file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19276fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19277frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19278file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19279fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19280frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19281file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19282fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19283frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19284file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19285fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19286frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19287file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19288fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19289(@value{GDBP})
19290-stack-list-arguments 0
19291^done,
19292stack-args=[
19293frame=@{level="0",args=[]@},
19294frame=@{level="1",args=[name="strarg"]@},
19295frame=@{level="2",args=[name="intarg",name="strarg"]@},
19296frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19297frame=@{level="4",args=[]@}]
19298(@value{GDBP})
19299-stack-list-arguments 1
19300^done,
19301stack-args=[
19302frame=@{level="0",args=[]@},
19303frame=@{level="1",
19304 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19305frame=@{level="2",args=[
19306@{name="intarg",value="2"@},
19307@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19308@{frame=@{level="3",args=[
19309@{name="intarg",value="2"@},
19310@{name="strarg",value="0x11940 \"A string argument.\""@},
19311@{name="fltarg",value="3.5"@}]@},
19312frame=@{level="4",args=[]@}]
19313(@value{GDBP})
19314-stack-list-arguments 0 2 2
19315^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19316(@value{GDBP})
19317-stack-list-arguments 1 2 2
19318^done,stack-args=[frame=@{level="2",
19319args=[@{name="intarg",value="2"@},
19320@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19321(@value{GDBP})
19322@end smallexample
19323
19324@c @subheading -stack-list-exception-handlers
19325
19326
19327@subheading The @code{-stack-list-frames} Command
19328@findex -stack-list-frames
19329
19330@subsubheading Synopsis
19331
19332@smallexample
19333 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19334@end smallexample
19335
19336List the frames currently on the stack. For each frame it displays the
19337following info:
19338
19339@table @samp
19340@item @var{level}
19341The frame number, 0 being the topmost frame, i.e. the innermost function.
19342@item @var{addr}
19343The @code{$pc} value for that frame.
19344@item @var{func}
19345Function name.
19346@item @var{file}
19347File name of the source file where the function lives.
19348@item @var{line}
19349Line number corresponding to the @code{$pc}.
19350@end table
19351
19352If invoked without arguments, this command prints a backtrace for the
19353whole stack. If given two integer arguments, it shows the frames whose
19354levels are between the two arguments (inclusive). If the two arguments
19355are equal, it shows the single frame at the corresponding level.
19356
19357@subsubheading @value{GDBN} Command
19358
19359The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19360
19361@subsubheading Example
19362
19363Full stack backtrace:
19364
19365@smallexample
19366(@value{GDBP})
19367-stack-list-frames
19368^done,stack=
19369[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19370 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19371frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19372 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19373frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19374 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19375frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19376 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19377frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19378 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19379frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19380 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19381frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19382 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19383frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19384 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19385frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19386 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19387frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19388 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19389frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19390 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19391frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19392 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19393(@value{GDBP})
19394@end smallexample
19395
19396Show frames between @var{low_frame} and @var{high_frame}:
19397
19398@smallexample
19399(@value{GDBP})
19400-stack-list-frames 3 5
19401^done,stack=
19402[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19403 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19404frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19405 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19406frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19407 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19408(@value{GDBP})
19409@end smallexample
19410
19411Show a single frame:
19412
19413@smallexample
19414(@value{GDBP})
19415-stack-list-frames 3 3
19416^done,stack=
19417[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19418 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19419(@value{GDBP})
19420@end smallexample
19421
19422
19423@subheading The @code{-stack-list-locals} Command
19424@findex -stack-list-locals
19425
19426@subsubheading Synopsis
19427
19428@smallexample
19429 -stack-list-locals @var{print-values}
19430@end smallexample
19431
19432Display the local variable names for the current frame. With an
bc8ced35
NR
19433argument of 0 or @code{--no-values}, prints only the names of the variables.
19434With argument of 1 or @code{--all-values}, prints also their values. With
19435argument of 2 or @code{--simple-values}, prints the name, type and value for
19436simple data types and the name and type for arrays, structures and
19437unions. In this last case, the idea is that the user can see the
19438value of simple data types immediately and he can create variable
19439objects for other data types if he wishes to explore their values in
19440more detail.
922fbb7b
AC
19441
19442@subsubheading @value{GDBN} Command
19443
19444@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19445
19446@subsubheading Example
19447
19448@smallexample
19449(@value{GDBP})
19450-stack-list-locals 0
19451^done,locals=[name="A",name="B",name="C"]
19452(@value{GDBP})
bc8ced35 19453-stack-list-locals --all-values
922fbb7b 19454^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19455 @{name="C",value="@{1, 2, 3@}"@}]
19456-stack-list-locals --simple-values
19457^done,locals=[@{name="A",type="int",value="1"@},
19458 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19459(@value{GDBP})
19460@end smallexample
19461
19462
19463@subheading The @code{-stack-select-frame} Command
19464@findex -stack-select-frame
19465
19466@subsubheading Synopsis
19467
19468@smallexample
19469 -stack-select-frame @var{framenum}
19470@end smallexample
19471
19472Change the current frame. Select a different frame @var{framenum} on
19473the stack.
19474
19475@subsubheading @value{GDBN} Command
19476
19477The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19478@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19479
19480@subsubheading Example
19481
19482@smallexample
19483(@value{GDBP})
19484-stack-select-frame 2
19485^done
19486(@value{GDBP})
19487@end smallexample
19488
19489@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19490@node GDB/MI Symbol Query
19491@section @sc{gdb/mi} Symbol Query Commands
19492
19493
19494@subheading The @code{-symbol-info-address} Command
19495@findex -symbol-info-address
19496
19497@subsubheading Synopsis
19498
19499@smallexample
19500 -symbol-info-address @var{symbol}
19501@end smallexample
19502
19503Describe where @var{symbol} is stored.
19504
19505@subsubheading @value{GDBN} Command
19506
19507The corresponding @value{GDBN} command is @samp{info address}.
19508
19509@subsubheading Example
19510N.A.
19511
19512
19513@subheading The @code{-symbol-info-file} Command
19514@findex -symbol-info-file
19515
19516@subsubheading Synopsis
19517
19518@smallexample
19519 -symbol-info-file
19520@end smallexample
19521
19522Show the file for the symbol.
19523
19524@subsubheading @value{GDBN} Command
19525
19526There's no equivalent @value{GDBN} command. @code{gdbtk} has
19527@samp{gdb_find_file}.
19528
19529@subsubheading Example
19530N.A.
19531
19532
19533@subheading The @code{-symbol-info-function} Command
19534@findex -symbol-info-function
19535
19536@subsubheading Synopsis
19537
19538@smallexample
19539 -symbol-info-function
19540@end smallexample
19541
19542Show which function the symbol lives in.
19543
19544@subsubheading @value{GDBN} Command
19545
19546@samp{gdb_get_function} in @code{gdbtk}.
19547
19548@subsubheading Example
19549N.A.
19550
19551
19552@subheading The @code{-symbol-info-line} Command
19553@findex -symbol-info-line
19554
19555@subsubheading Synopsis
19556
19557@smallexample
19558 -symbol-info-line
19559@end smallexample
19560
19561Show the core addresses of the code for a source line.
19562
19563@subsubheading @value{GDBN} Command
19564
71952f4c 19565The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19566@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19567
19568@subsubheading Example
19569N.A.
19570
19571
19572@subheading The @code{-symbol-info-symbol} Command
19573@findex -symbol-info-symbol
19574
19575@subsubheading Synopsis
19576
19577@smallexample
19578 -symbol-info-symbol @var{addr}
19579@end smallexample
19580
19581Describe what symbol is at location @var{addr}.
19582
19583@subsubheading @value{GDBN} Command
19584
19585The corresponding @value{GDBN} command is @samp{info symbol}.
19586
19587@subsubheading Example
19588N.A.
19589
19590
19591@subheading The @code{-symbol-list-functions} Command
19592@findex -symbol-list-functions
19593
19594@subsubheading Synopsis
19595
19596@smallexample
19597 -symbol-list-functions
19598@end smallexample
19599
19600List the functions in the executable.
19601
19602@subsubheading @value{GDBN} Command
19603
19604@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19605@samp{gdb_search} in @code{gdbtk}.
19606
19607@subsubheading Example
19608N.A.
19609
19610
32e7087d
JB
19611@subheading The @code{-symbol-list-lines} Command
19612@findex -symbol-list-lines
19613
19614@subsubheading Synopsis
19615
19616@smallexample
19617 -symbol-list-lines @var{filename}
19618@end smallexample
19619
19620Print the list of lines that contain code and their associated program
19621addresses for the given source filename. The entries are sorted in
19622ascending PC order.
19623
19624@subsubheading @value{GDBN} Command
19625
19626There is no corresponding @value{GDBN} command.
19627
19628@subsubheading Example
19629@smallexample
19630(@value{GDBP})
19631-symbol-list-lines basics.c
54ff5908 19632^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19633(@value{GDBP})
19634@end smallexample
19635
19636
922fbb7b
AC
19637@subheading The @code{-symbol-list-types} Command
19638@findex -symbol-list-types
19639
19640@subsubheading Synopsis
19641
19642@smallexample
19643 -symbol-list-types
19644@end smallexample
19645
19646List all the type names.
19647
19648@subsubheading @value{GDBN} Command
19649
19650The corresponding commands are @samp{info types} in @value{GDBN},
19651@samp{gdb_search} in @code{gdbtk}.
19652
19653@subsubheading Example
19654N.A.
19655
19656
19657@subheading The @code{-symbol-list-variables} Command
19658@findex -symbol-list-variables
19659
19660@subsubheading Synopsis
19661
19662@smallexample
19663 -symbol-list-variables
19664@end smallexample
19665
19666List all the global and static variable names.
19667
19668@subsubheading @value{GDBN} Command
19669
19670@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19671
19672@subsubheading Example
19673N.A.
19674
19675
19676@subheading The @code{-symbol-locate} Command
19677@findex -symbol-locate
19678
19679@subsubheading Synopsis
19680
19681@smallexample
19682 -symbol-locate
19683@end smallexample
19684
19685@subsubheading @value{GDBN} Command
19686
19687@samp{gdb_loc} in @code{gdbtk}.
19688
19689@subsubheading Example
19690N.A.
19691
19692
19693@subheading The @code{-symbol-type} Command
19694@findex -symbol-type
19695
19696@subsubheading Synopsis
19697
19698@smallexample
19699 -symbol-type @var{variable}
19700@end smallexample
19701
19702Show type of @var{variable}.
19703
19704@subsubheading @value{GDBN} Command
19705
19706The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19707@samp{gdb_obj_variable}.
19708
19709@subsubheading Example
19710N.A.
19711
19712
19713@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19714@node GDB/MI Target Manipulation
19715@section @sc{gdb/mi} Target Manipulation Commands
19716
19717
19718@subheading The @code{-target-attach} Command
19719@findex -target-attach
19720
19721@subsubheading Synopsis
19722
19723@smallexample
19724 -target-attach @var{pid} | @var{file}
19725@end smallexample
19726
19727Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19728
19729@subsubheading @value{GDBN} command
19730
19731The corresponding @value{GDBN} command is @samp{attach}.
19732
19733@subsubheading Example
19734N.A.
19735
19736
19737@subheading The @code{-target-compare-sections} Command
19738@findex -target-compare-sections
19739
19740@subsubheading Synopsis
19741
19742@smallexample
19743 -target-compare-sections [ @var{section} ]
19744@end smallexample
19745
19746Compare data of section @var{section} on target to the exec file.
19747Without the argument, all sections are compared.
19748
19749@subsubheading @value{GDBN} Command
19750
19751The @value{GDBN} equivalent is @samp{compare-sections}.
19752
19753@subsubheading Example
19754N.A.
19755
19756
19757@subheading The @code{-target-detach} Command
19758@findex -target-detach
19759
19760@subsubheading Synopsis
19761
19762@smallexample
19763 -target-detach
19764@end smallexample
19765
19766Disconnect from the remote target. There's no output.
19767
19768@subsubheading @value{GDBN} command
19769
19770The corresponding @value{GDBN} command is @samp{detach}.
19771
19772@subsubheading Example
19773
19774@smallexample
19775(@value{GDBP})
19776-target-detach
19777^done
19778(@value{GDBP})
19779@end smallexample
19780
19781
07f31aa6
DJ
19782@subheading The @code{-target-disconnect} Command
19783@findex -target-disconnect
19784
19785@subsubheading Synopsis
19786
19787@example
19788 -target-disconnect
19789@end example
19790
19791Disconnect from the remote target. There's no output.
19792
19793@subsubheading @value{GDBN} command
19794
19795The corresponding @value{GDBN} command is @samp{disconnect}.
19796
19797@subsubheading Example
19798
19799@smallexample
19800(@value{GDBP})
19801-target-disconnect
19802^done
19803(@value{GDBP})
19804@end smallexample
19805
19806
922fbb7b
AC
19807@subheading The @code{-target-download} Command
19808@findex -target-download
19809
19810@subsubheading Synopsis
19811
19812@smallexample
19813 -target-download
19814@end smallexample
19815
19816Loads the executable onto the remote target.
19817It prints out an update message every half second, which includes the fields:
19818
19819@table @samp
19820@item section
19821The name of the section.
19822@item section-sent
19823The size of what has been sent so far for that section.
19824@item section-size
19825The size of the section.
19826@item total-sent
19827The total size of what was sent so far (the current and the previous sections).
19828@item total-size
19829The size of the overall executable to download.
19830@end table
19831
19832@noindent
19833Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19834@sc{gdb/mi} Output Syntax}).
19835
19836In addition, it prints the name and size of the sections, as they are
19837downloaded. These messages include the following fields:
19838
19839@table @samp
19840@item section
19841The name of the section.
19842@item section-size
19843The size of the section.
19844@item total-size
19845The size of the overall executable to download.
19846@end table
19847
19848@noindent
19849At the end, a summary is printed.
19850
19851@subsubheading @value{GDBN} Command
19852
19853The corresponding @value{GDBN} command is @samp{load}.
19854
19855@subsubheading Example
19856
19857Note: each status message appears on a single line. Here the messages
19858have been broken down so that they can fit onto a page.
19859
19860@smallexample
19861(@value{GDBP})
19862-target-download
19863+download,@{section=".text",section-size="6668",total-size="9880"@}
19864+download,@{section=".text",section-sent="512",section-size="6668",
19865total-sent="512",total-size="9880"@}
19866+download,@{section=".text",section-sent="1024",section-size="6668",
19867total-sent="1024",total-size="9880"@}
19868+download,@{section=".text",section-sent="1536",section-size="6668",
19869total-sent="1536",total-size="9880"@}
19870+download,@{section=".text",section-sent="2048",section-size="6668",
19871total-sent="2048",total-size="9880"@}
19872+download,@{section=".text",section-sent="2560",section-size="6668",
19873total-sent="2560",total-size="9880"@}
19874+download,@{section=".text",section-sent="3072",section-size="6668",
19875total-sent="3072",total-size="9880"@}
19876+download,@{section=".text",section-sent="3584",section-size="6668",
19877total-sent="3584",total-size="9880"@}
19878+download,@{section=".text",section-sent="4096",section-size="6668",
19879total-sent="4096",total-size="9880"@}
19880+download,@{section=".text",section-sent="4608",section-size="6668",
19881total-sent="4608",total-size="9880"@}
19882+download,@{section=".text",section-sent="5120",section-size="6668",
19883total-sent="5120",total-size="9880"@}
19884+download,@{section=".text",section-sent="5632",section-size="6668",
19885total-sent="5632",total-size="9880"@}
19886+download,@{section=".text",section-sent="6144",section-size="6668",
19887total-sent="6144",total-size="9880"@}
19888+download,@{section=".text",section-sent="6656",section-size="6668",
19889total-sent="6656",total-size="9880"@}
19890+download,@{section=".init",section-size="28",total-size="9880"@}
19891+download,@{section=".fini",section-size="28",total-size="9880"@}
19892+download,@{section=".data",section-size="3156",total-size="9880"@}
19893+download,@{section=".data",section-sent="512",section-size="3156",
19894total-sent="7236",total-size="9880"@}
19895+download,@{section=".data",section-sent="1024",section-size="3156",
19896total-sent="7748",total-size="9880"@}
19897+download,@{section=".data",section-sent="1536",section-size="3156",
19898total-sent="8260",total-size="9880"@}
19899+download,@{section=".data",section-sent="2048",section-size="3156",
19900total-sent="8772",total-size="9880"@}
19901+download,@{section=".data",section-sent="2560",section-size="3156",
19902total-sent="9284",total-size="9880"@}
19903+download,@{section=".data",section-sent="3072",section-size="3156",
19904total-sent="9796",total-size="9880"@}
19905^done,address="0x10004",load-size="9880",transfer-rate="6586",
19906write-rate="429"
19907(@value{GDBP})
19908@end smallexample
19909
19910
19911@subheading The @code{-target-exec-status} Command
19912@findex -target-exec-status
19913
19914@subsubheading Synopsis
19915
19916@smallexample
19917 -target-exec-status
19918@end smallexample
19919
19920Provide information on the state of the target (whether it is running or
19921not, for instance).
19922
19923@subsubheading @value{GDBN} Command
19924
19925There's no equivalent @value{GDBN} command.
19926
19927@subsubheading Example
19928N.A.
19929
19930
19931@subheading The @code{-target-list-available-targets} Command
19932@findex -target-list-available-targets
19933
19934@subsubheading Synopsis
19935
19936@smallexample
19937 -target-list-available-targets
19938@end smallexample
19939
19940List the possible targets to connect to.
19941
19942@subsubheading @value{GDBN} Command
19943
19944The corresponding @value{GDBN} command is @samp{help target}.
19945
19946@subsubheading Example
19947N.A.
19948
19949
19950@subheading The @code{-target-list-current-targets} Command
19951@findex -target-list-current-targets
19952
19953@subsubheading Synopsis
19954
19955@smallexample
19956 -target-list-current-targets
19957@end smallexample
19958
19959Describe the current target.
19960
19961@subsubheading @value{GDBN} Command
19962
19963The corresponding information is printed by @samp{info file} (among
19964other things).
19965
19966@subsubheading Example
19967N.A.
19968
19969
19970@subheading The @code{-target-list-parameters} Command
19971@findex -target-list-parameters
19972
19973@subsubheading Synopsis
19974
19975@smallexample
19976 -target-list-parameters
19977@end smallexample
19978
19979@c ????
19980
19981@subsubheading @value{GDBN} Command
19982
19983No equivalent.
19984
19985@subsubheading Example
19986N.A.
19987
19988
19989@subheading The @code{-target-select} Command
19990@findex -target-select
19991
19992@subsubheading Synopsis
19993
19994@smallexample
19995 -target-select @var{type} @var{parameters @dots{}}
19996@end smallexample
19997
19998Connect @value{GDBN} to the remote target. This command takes two args:
19999
20000@table @samp
20001@item @var{type}
20002The type of target, for instance @samp{async}, @samp{remote}, etc.
20003@item @var{parameters}
20004Device names, host names and the like. @xref{Target Commands, ,
20005Commands for managing targets}, for more details.
20006@end table
20007
20008The output is a connection notification, followed by the address at
20009which the target program is, in the following form:
20010
20011@smallexample
20012^connected,addr="@var{address}",func="@var{function name}",
20013 args=[@var{arg list}]
20014@end smallexample
20015
20016@subsubheading @value{GDBN} Command
20017
20018The corresponding @value{GDBN} command is @samp{target}.
20019
20020@subsubheading Example
20021
20022@smallexample
20023(@value{GDBP})
20024-target-select async /dev/ttya
20025^connected,addr="0xfe00a300",func="??",args=[]
20026(@value{GDBP})
20027@end smallexample
20028
20029@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20030@node GDB/MI Thread Commands
20031@section @sc{gdb/mi} Thread Commands
20032
20033
20034@subheading The @code{-thread-info} Command
20035@findex -thread-info
20036
20037@subsubheading Synopsis
20038
20039@smallexample
20040 -thread-info
20041@end smallexample
20042
20043@subsubheading @value{GDBN} command
20044
20045No equivalent.
20046
20047@subsubheading Example
20048N.A.
20049
20050
20051@subheading The @code{-thread-list-all-threads} Command
20052@findex -thread-list-all-threads
20053
20054@subsubheading Synopsis
20055
20056@smallexample
20057 -thread-list-all-threads
20058@end smallexample
20059
20060@subsubheading @value{GDBN} Command
20061
20062The equivalent @value{GDBN} command is @samp{info threads}.
20063
20064@subsubheading Example
20065N.A.
20066
20067
20068@subheading The @code{-thread-list-ids} Command
20069@findex -thread-list-ids
20070
20071@subsubheading Synopsis
20072
20073@smallexample
20074 -thread-list-ids
20075@end smallexample
20076
20077Produces a list of the currently known @value{GDBN} thread ids. At the
20078end of the list it also prints the total number of such threads.
20079
20080@subsubheading @value{GDBN} Command
20081
20082Part of @samp{info threads} supplies the same information.
20083
20084@subsubheading Example
20085
20086No threads present, besides the main process:
20087
20088@smallexample
20089(@value{GDBP})
20090-thread-list-ids
20091^done,thread-ids=@{@},number-of-threads="0"
20092(@value{GDBP})
20093@end smallexample
20094
20095
20096Several threads:
20097
20098@smallexample
20099(@value{GDBP})
20100-thread-list-ids
20101^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20102number-of-threads="3"
20103(@value{GDBP})
20104@end smallexample
20105
20106
20107@subheading The @code{-thread-select} Command
20108@findex -thread-select
20109
20110@subsubheading Synopsis
20111
20112@smallexample
20113 -thread-select @var{threadnum}
20114@end smallexample
20115
20116Make @var{threadnum} the current thread. It prints the number of the new
20117current thread, and the topmost frame for that thread.
20118
20119@subsubheading @value{GDBN} Command
20120
20121The corresponding @value{GDBN} command is @samp{thread}.
20122
20123@subsubheading Example
20124
20125@smallexample
20126(@value{GDBP})
20127-exec-next
20128^running
20129(@value{GDBP})
20130*stopped,reason="end-stepping-range",thread-id="2",line="187",
20131file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20132(@value{GDBP})
20133-thread-list-ids
20134^done,
20135thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20136number-of-threads="3"
20137(@value{GDBP})
20138-thread-select 3
20139^done,new-thread-id="3",
20140frame=@{level="0",func="vprintf",
20141args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20142@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20143(@value{GDBP})
20144@end smallexample
20145
20146@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20147@node GDB/MI Tracepoint Commands
20148@section @sc{gdb/mi} Tracepoint Commands
20149
20150The tracepoint commands are not yet implemented.
20151
20152@c @subheading -trace-actions
20153
20154@c @subheading -trace-delete
20155
20156@c @subheading -trace-disable
20157
20158@c @subheading -trace-dump
20159
20160@c @subheading -trace-enable
20161
20162@c @subheading -trace-exists
20163
20164@c @subheading -trace-find
20165
20166@c @subheading -trace-frame-number
20167
20168@c @subheading -trace-info
20169
20170@c @subheading -trace-insert
20171
20172@c @subheading -trace-list
20173
20174@c @subheading -trace-pass-count
20175
20176@c @subheading -trace-save
20177
20178@c @subheading -trace-start
20179
20180@c @subheading -trace-stop
20181
20182
20183@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20184@node GDB/MI Variable Objects
20185@section @sc{gdb/mi} Variable Objects
20186
20187
20188@subheading Motivation for Variable Objects in @sc{gdb/mi}
20189
20190For the implementation of a variable debugger window (locals, watched
20191expressions, etc.), we are proposing the adaptation of the existing code
20192used by @code{Insight}.
20193
20194The two main reasons for that are:
20195
20196@enumerate 1
20197@item
20198It has been proven in practice (it is already on its second generation).
20199
20200@item
20201It will shorten development time (needless to say how important it is
20202now).
20203@end enumerate
20204
20205The original interface was designed to be used by Tcl code, so it was
20206slightly changed so it could be used through @sc{gdb/mi}. This section
20207describes the @sc{gdb/mi} operations that will be available and gives some
20208hints about their use.
20209
20210@emph{Note}: In addition to the set of operations described here, we
20211expect the @sc{gui} implementation of a variable window to require, at
20212least, the following operations:
20213
20214@itemize @bullet
20215@item @code{-gdb-show} @code{output-radix}
20216@item @code{-stack-list-arguments}
20217@item @code{-stack-list-locals}
20218@item @code{-stack-select-frame}
20219@end itemize
20220
20221@subheading Introduction to Variable Objects in @sc{gdb/mi}
20222
20223@cindex variable objects in @sc{gdb/mi}
20224The basic idea behind variable objects is the creation of a named object
20225to represent a variable, an expression, a memory location or even a CPU
20226register. For each object created, a set of operations is available for
20227examining or changing its properties.
20228
20229Furthermore, complex data types, such as C structures, are represented
20230in a tree format. For instance, the @code{struct} type variable is the
20231root and the children will represent the struct members. If a child
20232is itself of a complex type, it will also have children of its own.
20233Appropriate language differences are handled for C, C@t{++} and Java.
20234
20235When returning the actual values of the objects, this facility allows
20236for the individual selection of the display format used in the result
20237creation. It can be chosen among: binary, decimal, hexadecimal, octal
20238and natural. Natural refers to a default format automatically
20239chosen based on the variable type (like decimal for an @code{int}, hex
20240for pointers, etc.).
20241
20242The following is the complete set of @sc{gdb/mi} operations defined to
20243access this functionality:
20244
20245@multitable @columnfractions .4 .6
20246@item @strong{Operation}
20247@tab @strong{Description}
20248
20249@item @code{-var-create}
20250@tab create a variable object
20251@item @code{-var-delete}
20252@tab delete the variable object and its children
20253@item @code{-var-set-format}
20254@tab set the display format of this variable
20255@item @code{-var-show-format}
20256@tab show the display format of this variable
20257@item @code{-var-info-num-children}
20258@tab tells how many children this object has
20259@item @code{-var-list-children}
20260@tab return a list of the object's children
20261@item @code{-var-info-type}
20262@tab show the type of this variable object
20263@item @code{-var-info-expression}
20264@tab print what this variable object represents
20265@item @code{-var-show-attributes}
20266@tab is this variable editable? does it exist here?
20267@item @code{-var-evaluate-expression}
20268@tab get the value of this variable
20269@item @code{-var-assign}
20270@tab set the value of this variable
20271@item @code{-var-update}
20272@tab update the variable and its children
20273@end multitable
20274
20275In the next subsection we describe each operation in detail and suggest
20276how it can be used.
20277
20278@subheading Description And Use of Operations on Variable Objects
20279
20280@subheading The @code{-var-create} Command
20281@findex -var-create
20282
20283@subsubheading Synopsis
20284
20285@smallexample
20286 -var-create @{@var{name} | "-"@}
20287 @{@var{frame-addr} | "*"@} @var{expression}
20288@end smallexample
20289
20290This operation creates a variable object, which allows the monitoring of
20291a variable, the result of an expression, a memory cell or a CPU
20292register.
20293
20294The @var{name} parameter is the string by which the object can be
20295referenced. It must be unique. If @samp{-} is specified, the varobj
20296system will generate a string ``varNNNNNN'' automatically. It will be
20297unique provided that one does not specify @var{name} on that format.
20298The command fails if a duplicate name is found.
20299
20300The frame under which the expression should be evaluated can be
20301specified by @var{frame-addr}. A @samp{*} indicates that the current
20302frame should be used.
20303
20304@var{expression} is any expression valid on the current language set (must not
20305begin with a @samp{*}), or one of the following:
20306
20307@itemize @bullet
20308@item
20309@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20310
20311@item
20312@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20313
20314@item
20315@samp{$@var{regname}} --- a CPU register name
20316@end itemize
20317
20318@subsubheading Result
20319
20320This operation returns the name, number of children and the type of the
20321object created. Type is returned as a string as the ones generated by
20322the @value{GDBN} CLI:
20323
20324@smallexample
20325 name="@var{name}",numchild="N",type="@var{type}"
20326@end smallexample
20327
20328
20329@subheading The @code{-var-delete} Command
20330@findex -var-delete
20331
20332@subsubheading Synopsis
20333
20334@smallexample
20335 -var-delete @var{name}
20336@end smallexample
20337
20338Deletes a previously created variable object and all of its children.
20339
20340Returns an error if the object @var{name} is not found.
20341
20342
20343@subheading The @code{-var-set-format} Command
20344@findex -var-set-format
20345
20346@subsubheading Synopsis
20347
20348@smallexample
20349 -var-set-format @var{name} @var{format-spec}
20350@end smallexample
20351
20352Sets the output format for the value of the object @var{name} to be
20353@var{format-spec}.
20354
20355The syntax for the @var{format-spec} is as follows:
20356
20357@smallexample
20358 @var{format-spec} @expansion{}
20359 @{binary | decimal | hexadecimal | octal | natural@}
20360@end smallexample
20361
20362
20363@subheading The @code{-var-show-format} Command
20364@findex -var-show-format
20365
20366@subsubheading Synopsis
20367
20368@smallexample
20369 -var-show-format @var{name}
20370@end smallexample
20371
20372Returns the format used to display the value of the object @var{name}.
20373
20374@smallexample
20375 @var{format} @expansion{}
20376 @var{format-spec}
20377@end smallexample
20378
20379
20380@subheading The @code{-var-info-num-children} Command
20381@findex -var-info-num-children
20382
20383@subsubheading Synopsis
20384
20385@smallexample
20386 -var-info-num-children @var{name}
20387@end smallexample
20388
20389Returns the number of children of a variable object @var{name}:
20390
20391@smallexample
20392 numchild=@var{n}
20393@end smallexample
20394
20395
20396@subheading The @code{-var-list-children} Command
20397@findex -var-list-children
20398
20399@subsubheading Synopsis
20400
20401@smallexample
bc8ced35 20402 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20403@end smallexample
20404
bc8ced35
NR
20405Returns a list of the children of the specified variable object. With
20406just the variable object name as an argument or with an optional
20407preceding argument of 0 or @code{--no-values}, prints only the names of the
20408variables. With an optional preceding argument of 1 or @code{--all-values},
20409also prints their values.
20410
20411@subsubheading Example
922fbb7b
AC
20412
20413@smallexample
bc8ced35
NR
20414(@value{GDBP})
20415 -var-list-children n
922fbb7b
AC
20416 numchild=@var{n},children=[@{name=@var{name},
20417 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20418(@value{GDBP})
20419 -var-list-children --all-values n
20420 numchild=@var{n},children=[@{name=@var{name},
20421 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20422@end smallexample
20423
20424
20425@subheading The @code{-var-info-type} Command
20426@findex -var-info-type
20427
20428@subsubheading Synopsis
20429
20430@smallexample
20431 -var-info-type @var{name}
20432@end smallexample
20433
20434Returns the type of the specified variable @var{name}. The type is
20435returned as a string in the same format as it is output by the
20436@value{GDBN} CLI:
20437
20438@smallexample
20439 type=@var{typename}
20440@end smallexample
20441
20442
20443@subheading The @code{-var-info-expression} Command
20444@findex -var-info-expression
20445
20446@subsubheading Synopsis
20447
20448@smallexample
20449 -var-info-expression @var{name}
20450@end smallexample
20451
20452Returns what is represented by the variable object @var{name}:
20453
20454@smallexample
20455 lang=@var{lang-spec},exp=@var{expression}
20456@end smallexample
20457
20458@noindent
20459where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20460
20461@subheading The @code{-var-show-attributes} Command
20462@findex -var-show-attributes
20463
20464@subsubheading Synopsis
20465
20466@smallexample
20467 -var-show-attributes @var{name}
20468@end smallexample
20469
20470List attributes of the specified variable object @var{name}:
20471
20472@smallexample
20473 status=@var{attr} [ ( ,@var{attr} )* ]
20474@end smallexample
20475
20476@noindent
20477where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20478
20479@subheading The @code{-var-evaluate-expression} Command
20480@findex -var-evaluate-expression
20481
20482@subsubheading Synopsis
20483
20484@smallexample
20485 -var-evaluate-expression @var{name}
20486@end smallexample
20487
20488Evaluates the expression that is represented by the specified variable
20489object and returns its value as a string in the current format specified
20490for the object:
20491
20492@smallexample
20493 value=@var{value}
20494@end smallexample
20495
20496Note that one must invoke @code{-var-list-children} for a variable
20497before the value of a child variable can be evaluated.
20498
20499@subheading The @code{-var-assign} Command
20500@findex -var-assign
20501
20502@subsubheading Synopsis
20503
20504@smallexample
20505 -var-assign @var{name} @var{expression}
20506@end smallexample
20507
20508Assigns the value of @var{expression} to the variable object specified
20509by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20510value is altered by the assign, the variable will show up in any
922fbb7b
AC
20511subsequent @code{-var-update} list.
20512
20513@subsubheading Example
20514
20515@smallexample
20516(@value{GDBP})
20517-var-assign var1 3
20518^done,value="3"
20519(@value{GDBP})
20520-var-update *
20521^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20522(@value{GDBP})
20523@end smallexample
20524
20525@subheading The @code{-var-update} Command
20526@findex -var-update
20527
20528@subsubheading Synopsis
20529
20530@smallexample
20531 -var-update @{@var{name} | "*"@}
20532@end smallexample
20533
20534Update the value of the variable object @var{name} by evaluating its
20535expression after fetching all the new values from memory or registers.
20536A @samp{*} causes all existing variable objects to be updated.
20537
20538
20539@node Annotations
20540@chapter @value{GDBN} Annotations
20541
086432e2
AC
20542This chapter describes annotations in @value{GDBN}. Annotations were
20543designed to interface @value{GDBN} to graphical user interfaces or other
20544similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20545relatively high level.
20546
086432e2
AC
20547The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20548(@pxref{GDB/MI}).
20549
922fbb7b
AC
20550@ignore
20551This is Edition @value{EDITION}, @value{DATE}.
20552@end ignore
20553
20554@menu
20555* Annotations Overview:: What annotations are; the general syntax.
20556* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
20557* Prompting:: Annotations marking @value{GDBN}'s need for input.
20558* Errors:: Annotations for error messages.
922fbb7b
AC
20559* Invalidation:: Some annotations describe things now invalid.
20560* Annotations for Running::
20561 Whether the program is running, how it stopped, etc.
20562* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20563@end menu
20564
20565@node Annotations Overview
20566@section What is an Annotation?
20567@cindex annotations
20568
922fbb7b
AC
20569Annotations start with a newline character, two @samp{control-z}
20570characters, and the name of the annotation. If there is no additional
20571information associated with this annotation, the name of the annotation
20572is followed immediately by a newline. If there is additional
20573information, the name of the annotation is followed by a space, the
20574additional information, and a newline. The additional information
20575cannot contain newline characters.
20576
20577Any output not beginning with a newline and two @samp{control-z}
20578characters denotes literal output from @value{GDBN}. Currently there is
20579no need for @value{GDBN} to output a newline followed by two
20580@samp{control-z} characters, but if there was such a need, the
20581annotations could be extended with an @samp{escape} annotation which
20582means those three characters as output.
20583
086432e2
AC
20584The annotation @var{level}, which is specified using the
20585@option{--annotate} command line option (@pxref{Mode Options}), controls
20586how much information @value{GDBN} prints together with its prompt,
20587values of expressions, source lines, and other types of output. Level 0
20588is for no anntations, level 1 is for use when @value{GDBN} is run as a
20589subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20590for programs that control @value{GDBN}, and level 2 annotations have
20591been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20592Interface, annotate, GDB's Obsolete Annotations}).
20593
20594@table @code
20595@kindex set annotate
20596@item set annotate @var{level}
e09f16f9 20597The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20598annotations to the specified @var{level}.
9c16f35a
EZ
20599
20600@item show annotate
20601@kindex show annotate
20602Show the current annotation level.
09d4efe1
EZ
20603@end table
20604
20605This chapter describes level 3 annotations.
086432e2 20606
922fbb7b
AC
20607A simple example of starting up @value{GDBN} with annotations is:
20608
20609@smallexample
086432e2
AC
20610$ @kbd{gdb --annotate=3}
20611GNU gdb 6.0
20612Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20613GDB is free software, covered by the GNU General Public License,
20614and you are welcome to change it and/or distribute copies of it
20615under certain conditions.
20616Type "show copying" to see the conditions.
20617There is absolutely no warranty for GDB. Type "show warranty"
20618for details.
086432e2 20619This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20620
20621^Z^Zpre-prompt
f7dc1244 20622(@value{GDBP})
922fbb7b 20623^Z^Zprompt
086432e2 20624@kbd{quit}
922fbb7b
AC
20625
20626^Z^Zpost-prompt
b383017d 20627$
922fbb7b
AC
20628@end smallexample
20629
20630Here @samp{quit} is input to @value{GDBN}; the rest is output from
20631@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20632denotes a @samp{control-z} character) are annotations; the rest is
20633output from @value{GDBN}.
20634
20635@node Server Prefix
20636@section The Server Prefix
20637@cindex server prefix for annotations
20638
20639To issue a command to @value{GDBN} without affecting certain aspects of
20640the state which is seen by users, prefix it with @samp{server }. This
20641means that this command will not affect the command history, nor will it
20642affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20643pressed on a line by itself.
20644
20645The server prefix does not affect the recording of values into the value
20646history; to print a value without recording it into the value history,
20647use the @code{output} command instead of the @code{print} command.
20648
922fbb7b
AC
20649@node Prompting
20650@section Annotation for @value{GDBN} Input
20651
20652@cindex annotations for prompts
20653When @value{GDBN} prompts for input, it annotates this fact so it is possible
20654to know when to send output, when the output from a given command is
20655over, etc.
20656
20657Different kinds of input each have a different @dfn{input type}. Each
20658input type has three annotations: a @code{pre-} annotation, which
20659denotes the beginning of any prompt which is being output, a plain
20660annotation, which denotes the end of the prompt, and then a @code{post-}
20661annotation which denotes the end of any echo which may (or may not) be
20662associated with the input. For example, the @code{prompt} input type
20663features the following annotations:
20664
20665@smallexample
20666^Z^Zpre-prompt
20667^Z^Zprompt
20668^Z^Zpost-prompt
20669@end smallexample
20670
20671The input types are
20672
20673@table @code
20674@findex pre-prompt
20675@findex prompt
20676@findex post-prompt
20677@item prompt
20678When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20679
20680@findex pre-commands
20681@findex commands
20682@findex post-commands
20683@item commands
20684When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20685command. The annotations are repeated for each command which is input.
20686
20687@findex pre-overload-choice
20688@findex overload-choice
20689@findex post-overload-choice
20690@item overload-choice
20691When @value{GDBN} wants the user to select between various overloaded functions.
20692
20693@findex pre-query
20694@findex query
20695@findex post-query
20696@item query
20697When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20698
20699@findex pre-prompt-for-continue
20700@findex prompt-for-continue
20701@findex post-prompt-for-continue
20702@item prompt-for-continue
20703When @value{GDBN} is asking the user to press return to continue. Note: Don't
20704expect this to work well; instead use @code{set height 0} to disable
20705prompting. This is because the counting of lines is buggy in the
20706presence of annotations.
20707@end table
20708
20709@node Errors
20710@section Errors
20711@cindex annotations for errors, warnings and interrupts
20712
20713@findex quit
20714@smallexample
20715^Z^Zquit
20716@end smallexample
20717
20718This annotation occurs right before @value{GDBN} responds to an interrupt.
20719
20720@findex error
20721@smallexample
20722^Z^Zerror
20723@end smallexample
20724
20725This annotation occurs right before @value{GDBN} responds to an error.
20726
20727Quit and error annotations indicate that any annotations which @value{GDBN} was
20728in the middle of may end abruptly. For example, if a
20729@code{value-history-begin} annotation is followed by a @code{error}, one
20730cannot expect to receive the matching @code{value-history-end}. One
20731cannot expect not to receive it either, however; an error annotation
20732does not necessarily mean that @value{GDBN} is immediately returning all the way
20733to the top level.
20734
20735@findex error-begin
20736A quit or error annotation may be preceded by
20737
20738@smallexample
20739^Z^Zerror-begin
20740@end smallexample
20741
20742Any output between that and the quit or error annotation is the error
20743message.
20744
20745Warning messages are not yet annotated.
20746@c If we want to change that, need to fix warning(), type_error(),
20747@c range_error(), and possibly other places.
20748
922fbb7b
AC
20749@node Invalidation
20750@section Invalidation Notices
20751
20752@cindex annotations for invalidation messages
20753The following annotations say that certain pieces of state may have
20754changed.
20755
20756@table @code
20757@findex frames-invalid
20758@item ^Z^Zframes-invalid
20759
20760The frames (for example, output from the @code{backtrace} command) may
20761have changed.
20762
20763@findex breakpoints-invalid
20764@item ^Z^Zbreakpoints-invalid
20765
20766The breakpoints may have changed. For example, the user just added or
20767deleted a breakpoint.
20768@end table
20769
20770@node Annotations for Running
20771@section Running the Program
20772@cindex annotations for running programs
20773
20774@findex starting
20775@findex stopping
20776When the program starts executing due to a @value{GDBN} command such as
b383017d 20777@code{step} or @code{continue},
922fbb7b
AC
20778
20779@smallexample
20780^Z^Zstarting
20781@end smallexample
20782
b383017d 20783is output. When the program stops,
922fbb7b
AC
20784
20785@smallexample
20786^Z^Zstopped
20787@end smallexample
20788
20789is output. Before the @code{stopped} annotation, a variety of
20790annotations describe how the program stopped.
20791
20792@table @code
20793@findex exited
20794@item ^Z^Zexited @var{exit-status}
20795The program exited, and @var{exit-status} is the exit status (zero for
20796successful exit, otherwise nonzero).
20797
20798@findex signalled
20799@findex signal-name
20800@findex signal-name-end
20801@findex signal-string
20802@findex signal-string-end
20803@item ^Z^Zsignalled
20804The program exited with a signal. After the @code{^Z^Zsignalled}, the
20805annotation continues:
20806
20807@smallexample
20808@var{intro-text}
20809^Z^Zsignal-name
20810@var{name}
20811^Z^Zsignal-name-end
20812@var{middle-text}
20813^Z^Zsignal-string
20814@var{string}
20815^Z^Zsignal-string-end
20816@var{end-text}
20817@end smallexample
20818
20819@noindent
20820where @var{name} is the name of the signal, such as @code{SIGILL} or
20821@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20822as @code{Illegal Instruction} or @code{Segmentation fault}.
20823@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20824user's benefit and have no particular format.
20825
20826@findex signal
20827@item ^Z^Zsignal
20828The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20829just saying that the program received the signal, not that it was
20830terminated with it.
20831
20832@findex breakpoint
20833@item ^Z^Zbreakpoint @var{number}
20834The program hit breakpoint number @var{number}.
20835
20836@findex watchpoint
20837@item ^Z^Zwatchpoint @var{number}
20838The program hit watchpoint number @var{number}.
20839@end table
20840
20841@node Source Annotations
20842@section Displaying Source
20843@cindex annotations for source display
20844
20845@findex source
20846The following annotation is used instead of displaying source code:
20847
20848@smallexample
20849^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20850@end smallexample
20851
20852where @var{filename} is an absolute file name indicating which source
20853file, @var{line} is the line number within that file (where 1 is the
20854first line in the file), @var{character} is the character position
20855within the file (where 0 is the first character in the file) (for most
20856debug formats this will necessarily point to the beginning of a line),
20857@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20858line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20859@var{addr} is the address in the target program associated with the
20860source which is being displayed. @var{addr} is in the form @samp{0x}
20861followed by one or more lowercase hex digits (note that this does not
20862depend on the language).
20863
8e04817f
AC
20864@node GDB Bugs
20865@chapter Reporting Bugs in @value{GDBN}
20866@cindex bugs in @value{GDBN}
20867@cindex reporting bugs in @value{GDBN}
c906108c 20868
8e04817f 20869Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20870
8e04817f
AC
20871Reporting a bug may help you by bringing a solution to your problem, or it
20872may not. But in any case the principal function of a bug report is to help
20873the entire community by making the next version of @value{GDBN} work better. Bug
20874reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20875
8e04817f
AC
20876In order for a bug report to serve its purpose, you must include the
20877information that enables us to fix the bug.
c4555f82
SC
20878
20879@menu
8e04817f
AC
20880* Bug Criteria:: Have you found a bug?
20881* Bug Reporting:: How to report bugs
c4555f82
SC
20882@end menu
20883
8e04817f
AC
20884@node Bug Criteria
20885@section Have you found a bug?
20886@cindex bug criteria
c4555f82 20887
8e04817f 20888If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20889
20890@itemize @bullet
8e04817f
AC
20891@cindex fatal signal
20892@cindex debugger crash
20893@cindex crash of debugger
c4555f82 20894@item
8e04817f
AC
20895If the debugger gets a fatal signal, for any input whatever, that is a
20896@value{GDBN} bug. Reliable debuggers never crash.
20897
20898@cindex error on valid input
20899@item
20900If @value{GDBN} produces an error message for valid input, that is a
20901bug. (Note that if you're cross debugging, the problem may also be
20902somewhere in the connection to the target.)
c4555f82 20903
8e04817f 20904@cindex invalid input
c4555f82 20905@item
8e04817f
AC
20906If @value{GDBN} does not produce an error message for invalid input,
20907that is a bug. However, you should note that your idea of
20908``invalid input'' might be our idea of ``an extension'' or ``support
20909for traditional practice''.
20910
20911@item
20912If you are an experienced user of debugging tools, your suggestions
20913for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
20914@end itemize
20915
8e04817f
AC
20916@node Bug Reporting
20917@section How to report bugs
20918@cindex bug reports
20919@cindex @value{GDBN} bugs, reporting
20920
20921A number of companies and individuals offer support for @sc{gnu} products.
20922If you obtained @value{GDBN} from a support organization, we recommend you
20923contact that organization first.
20924
20925You can find contact information for many support companies and
20926individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20927distribution.
20928@c should add a web page ref...
20929
129188f6
AC
20930In any event, we also recommend that you submit bug reports for
20931@value{GDBN}. The prefered method is to submit them directly using
20932@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20933page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20934be used.
8e04817f
AC
20935
20936@strong{Do not send bug reports to @samp{info-gdb}, or to
20937@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20938not want to receive bug reports. Those that do have arranged to receive
20939@samp{bug-gdb}.
20940
20941The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20942serves as a repeater. The mailing list and the newsgroup carry exactly
20943the same messages. Often people think of posting bug reports to the
20944newsgroup instead of mailing them. This appears to work, but it has one
20945problem which can be crucial: a newsgroup posting often lacks a mail
20946path back to the sender. Thus, if we need to ask for more information,
20947we may be unable to reach you. For this reason, it is better to send
20948bug reports to the mailing list.
c4555f82 20949
8e04817f
AC
20950The fundamental principle of reporting bugs usefully is this:
20951@strong{report all the facts}. If you are not sure whether to state a
20952fact or leave it out, state it!
c4555f82 20953
8e04817f
AC
20954Often people omit facts because they think they know what causes the
20955problem and assume that some details do not matter. Thus, you might
20956assume that the name of the variable you use in an example does not matter.
20957Well, probably it does not, but one cannot be sure. Perhaps the bug is a
20958stray memory reference which happens to fetch from the location where that
20959name is stored in memory; perhaps, if the name were different, the contents
20960of that location would fool the debugger into doing the right thing despite
20961the bug. Play it safe and give a specific, complete example. That is the
20962easiest thing for you to do, and the most helpful.
c4555f82 20963
8e04817f
AC
20964Keep in mind that the purpose of a bug report is to enable us to fix the
20965bug. It may be that the bug has been reported previously, but neither
20966you nor we can know that unless your bug report is complete and
20967self-contained.
c4555f82 20968
8e04817f
AC
20969Sometimes people give a few sketchy facts and ask, ``Does this ring a
20970bell?'' Those bug reports are useless, and we urge everyone to
20971@emph{refuse to respond to them} except to chide the sender to report
20972bugs properly.
20973
20974To enable us to fix the bug, you should include all these things:
c4555f82
SC
20975
20976@itemize @bullet
20977@item
8e04817f
AC
20978The version of @value{GDBN}. @value{GDBN} announces it if you start
20979with no arguments; you can also print it at any time using @code{show
20980version}.
c4555f82 20981
8e04817f
AC
20982Without this, we will not know whether there is any point in looking for
20983the bug in the current version of @value{GDBN}.
c4555f82
SC
20984
20985@item
8e04817f
AC
20986The type of machine you are using, and the operating system name and
20987version number.
c4555f82
SC
20988
20989@item
8e04817f
AC
20990What compiler (and its version) was used to compile @value{GDBN}---e.g.
20991``@value{GCC}--2.8.1''.
c4555f82
SC
20992
20993@item
8e04817f
AC
20994What compiler (and its version) was used to compile the program you are
20995debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
20996C Compiler''. For GCC, you can say @code{gcc --version} to get this
20997information; for other compilers, see the documentation for those
20998compilers.
c4555f82 20999
8e04817f
AC
21000@item
21001The command arguments you gave the compiler to compile your example and
21002observe the bug. For example, did you use @samp{-O}? To guarantee
21003you will not omit something important, list them all. A copy of the
21004Makefile (or the output from make) is sufficient.
c4555f82 21005
8e04817f
AC
21006If we were to try to guess the arguments, we would probably guess wrong
21007and then we might not encounter the bug.
c4555f82 21008
8e04817f
AC
21009@item
21010A complete input script, and all necessary source files, that will
21011reproduce the bug.
c4555f82 21012
8e04817f
AC
21013@item
21014A description of what behavior you observe that you believe is
21015incorrect. For example, ``It gets a fatal signal.''
c4555f82 21016
8e04817f
AC
21017Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21018will certainly notice it. But if the bug is incorrect output, we might
21019not notice unless it is glaringly wrong. You might as well not give us
21020a chance to make a mistake.
c4555f82 21021
8e04817f
AC
21022Even if the problem you experience is a fatal signal, you should still
21023say so explicitly. Suppose something strange is going on, such as, your
21024copy of @value{GDBN} is out of synch, or you have encountered a bug in
21025the C library on your system. (This has happened!) Your copy might
21026crash and ours would not. If you told us to expect a crash, then when
21027ours fails to crash, we would know that the bug was not happening for
21028us. If you had not told us to expect a crash, then we would not be able
21029to draw any conclusion from our observations.
c4555f82 21030
e0c07bf0
MC
21031@pindex script
21032@cindex recording a session script
21033To collect all this information, you can use a session recording program
21034such as @command{script}, which is available on many Unix systems.
21035Just run your @value{GDBN} session inside @command{script} and then
21036include the @file{typescript} file with your bug report.
21037
21038Another way to record a @value{GDBN} session is to run @value{GDBN}
21039inside Emacs and then save the entire buffer to a file.
21040
8e04817f
AC
21041@item
21042If you wish to suggest changes to the @value{GDBN} source, send us context
21043diffs. If you even discuss something in the @value{GDBN} source, refer to
21044it by context, not by line number.
c4555f82 21045
8e04817f
AC
21046The line numbers in our development sources will not match those in your
21047sources. Your line numbers would convey no useful information to us.
c4555f82 21048
8e04817f 21049@end itemize
c4555f82 21050
8e04817f 21051Here are some things that are not necessary:
c4555f82 21052
8e04817f
AC
21053@itemize @bullet
21054@item
21055A description of the envelope of the bug.
c4555f82 21056
8e04817f
AC
21057Often people who encounter a bug spend a lot of time investigating
21058which changes to the input file will make the bug go away and which
21059changes will not affect it.
c4555f82 21060
8e04817f
AC
21061This is often time consuming and not very useful, because the way we
21062will find the bug is by running a single example under the debugger
21063with breakpoints, not by pure deduction from a series of examples.
21064We recommend that you save your time for something else.
c4555f82 21065
8e04817f
AC
21066Of course, if you can find a simpler example to report @emph{instead}
21067of the original one, that is a convenience for us. Errors in the
21068output will be easier to spot, running under the debugger will take
21069less time, and so on.
c4555f82 21070
8e04817f
AC
21071However, simplification is not vital; if you do not want to do this,
21072report the bug anyway and send us the entire test case you used.
c4555f82 21073
8e04817f
AC
21074@item
21075A patch for the bug.
c4555f82 21076
8e04817f
AC
21077A patch for the bug does help us if it is a good one. But do not omit
21078the necessary information, such as the test case, on the assumption that
21079a patch is all we need. We might see problems with your patch and decide
21080to fix the problem another way, or we might not understand it at all.
c4555f82 21081
8e04817f
AC
21082Sometimes with a program as complicated as @value{GDBN} it is very hard to
21083construct an example that will make the program follow a certain path
21084through the code. If you do not send us the example, we will not be able
21085to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21086
8e04817f
AC
21087And if we cannot understand what bug you are trying to fix, or why your
21088patch should be an improvement, we will not install it. A test case will
21089help us to understand.
c4555f82 21090
8e04817f
AC
21091@item
21092A guess about what the bug is or what it depends on.
c4555f82 21093
8e04817f
AC
21094Such guesses are usually wrong. Even we cannot guess right about such
21095things without first using the debugger to find the facts.
21096@end itemize
c4555f82 21097
8e04817f
AC
21098@c The readline documentation is distributed with the readline code
21099@c and consists of the two following files:
21100@c rluser.texinfo
21101@c inc-hist.texinfo
21102@c Use -I with makeinfo to point to the appropriate directory,
21103@c environment var TEXINPUTS with TeX.
21104@include rluser.texinfo
21105@include inc-hist.texinfo
c4555f82 21106
c4555f82 21107
8e04817f
AC
21108@node Formatting Documentation
21109@appendix Formatting Documentation
c4555f82 21110
8e04817f
AC
21111@cindex @value{GDBN} reference card
21112@cindex reference card
21113The @value{GDBN} 4 release includes an already-formatted reference card, ready
21114for printing with PostScript or Ghostscript, in the @file{gdb}
21115subdirectory of the main source directory@footnote{In
21116@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21117release.}. If you can use PostScript or Ghostscript with your printer,
21118you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21119
8e04817f
AC
21120The release also includes the source for the reference card. You
21121can format it, using @TeX{}, by typing:
c4555f82 21122
474c8240 21123@smallexample
8e04817f 21124make refcard.dvi
474c8240 21125@end smallexample
c4555f82 21126
8e04817f
AC
21127The @value{GDBN} reference card is designed to print in @dfn{landscape}
21128mode on US ``letter'' size paper;
21129that is, on a sheet 11 inches wide by 8.5 inches
21130high. You will need to specify this form of printing as an option to
21131your @sc{dvi} output program.
c4555f82 21132
8e04817f 21133@cindex documentation
c4555f82 21134
8e04817f
AC
21135All the documentation for @value{GDBN} comes as part of the machine-readable
21136distribution. The documentation is written in Texinfo format, which is
21137a documentation system that uses a single source file to produce both
21138on-line information and a printed manual. You can use one of the Info
21139formatting commands to create the on-line version of the documentation
21140and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21141
8e04817f
AC
21142@value{GDBN} includes an already formatted copy of the on-line Info
21143version of this manual in the @file{gdb} subdirectory. The main Info
21144file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21145subordinate files matching @samp{gdb.info*} in the same directory. If
21146necessary, you can print out these files, or read them with any editor;
21147but they are easier to read using the @code{info} subsystem in @sc{gnu}
21148Emacs or the standalone @code{info} program, available as part of the
21149@sc{gnu} Texinfo distribution.
c4555f82 21150
8e04817f
AC
21151If you want to format these Info files yourself, you need one of the
21152Info formatting programs, such as @code{texinfo-format-buffer} or
21153@code{makeinfo}.
c4555f82 21154
8e04817f
AC
21155If you have @code{makeinfo} installed, and are in the top level
21156@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21157version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21158
474c8240 21159@smallexample
8e04817f
AC
21160cd gdb
21161make gdb.info
474c8240 21162@end smallexample
c4555f82 21163
8e04817f
AC
21164If you want to typeset and print copies of this manual, you need @TeX{},
21165a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21166Texinfo definitions file.
c4555f82 21167
8e04817f
AC
21168@TeX{} is a typesetting program; it does not print files directly, but
21169produces output files called @sc{dvi} files. To print a typeset
21170document, you need a program to print @sc{dvi} files. If your system
21171has @TeX{} installed, chances are it has such a program. The precise
21172command to use depends on your system; @kbd{lpr -d} is common; another
21173(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21174require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21175
8e04817f
AC
21176@TeX{} also requires a macro definitions file called
21177@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21178written in Texinfo format. On its own, @TeX{} cannot either read or
21179typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21180and is located in the @file{gdb-@var{version-number}/texinfo}
21181directory.
c4555f82 21182
8e04817f
AC
21183If you have @TeX{} and a @sc{dvi} printer program installed, you can
21184typeset and print this manual. First switch to the the @file{gdb}
21185subdirectory of the main source directory (for example, to
21186@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21187
474c8240 21188@smallexample
8e04817f 21189make gdb.dvi
474c8240 21190@end smallexample
c4555f82 21191
8e04817f 21192Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21193
8e04817f
AC
21194@node Installing GDB
21195@appendix Installing @value{GDBN}
21196@cindex configuring @value{GDBN}
21197@cindex installation
94e91d6d 21198@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21199
8e04817f
AC
21200@value{GDBN} comes with a @code{configure} script that automates the process
21201of preparing @value{GDBN} for installation; you can then use @code{make} to
21202build the @code{gdb} program.
21203@iftex
21204@c irrelevant in info file; it's as current as the code it lives with.
21205@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21206look at the @file{README} file in the sources; we may have improved the
21207installation procedures since publishing this manual.}
21208@end iftex
c4555f82 21209
8e04817f
AC
21210The @value{GDBN} distribution includes all the source code you need for
21211@value{GDBN} in a single directory, whose name is usually composed by
21212appending the version number to @samp{gdb}.
c4555f82 21213
8e04817f
AC
21214For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21215@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21216
8e04817f
AC
21217@table @code
21218@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21219script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21220
8e04817f
AC
21221@item gdb-@value{GDBVN}/gdb
21222the source specific to @value{GDBN} itself
c4555f82 21223
8e04817f
AC
21224@item gdb-@value{GDBVN}/bfd
21225source for the Binary File Descriptor library
c906108c 21226
8e04817f
AC
21227@item gdb-@value{GDBVN}/include
21228@sc{gnu} include files
c906108c 21229
8e04817f
AC
21230@item gdb-@value{GDBVN}/libiberty
21231source for the @samp{-liberty} free software library
c906108c 21232
8e04817f
AC
21233@item gdb-@value{GDBVN}/opcodes
21234source for the library of opcode tables and disassemblers
c906108c 21235
8e04817f
AC
21236@item gdb-@value{GDBVN}/readline
21237source for the @sc{gnu} command-line interface
c906108c 21238
8e04817f
AC
21239@item gdb-@value{GDBVN}/glob
21240source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21241
8e04817f
AC
21242@item gdb-@value{GDBVN}/mmalloc
21243source for the @sc{gnu} memory-mapped malloc package
21244@end table
c906108c 21245
8e04817f
AC
21246The simplest way to configure and build @value{GDBN} is to run @code{configure}
21247from the @file{gdb-@var{version-number}} source directory, which in
21248this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21249
8e04817f
AC
21250First switch to the @file{gdb-@var{version-number}} source directory
21251if you are not already in it; then run @code{configure}. Pass the
21252identifier for the platform on which @value{GDBN} will run as an
21253argument.
c906108c 21254
8e04817f 21255For example:
c906108c 21256
474c8240 21257@smallexample
8e04817f
AC
21258cd gdb-@value{GDBVN}
21259./configure @var{host}
21260make
474c8240 21261@end smallexample
c906108c 21262
8e04817f
AC
21263@noindent
21264where @var{host} is an identifier such as @samp{sun4} or
21265@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21266(You can often leave off @var{host}; @code{configure} tries to guess the
21267correct value by examining your system.)
c906108c 21268
8e04817f
AC
21269Running @samp{configure @var{host}} and then running @code{make} builds the
21270@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21271libraries, then @code{gdb} itself. The configured source files, and the
21272binaries, are left in the corresponding source directories.
c906108c 21273
8e04817f
AC
21274@need 750
21275@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21276system does not recognize this automatically when you run a different
21277shell, you may need to run @code{sh} on it explicitly:
c906108c 21278
474c8240 21279@smallexample
8e04817f 21280sh configure @var{host}
474c8240 21281@end smallexample
c906108c 21282
8e04817f
AC
21283If you run @code{configure} from a directory that contains source
21284directories for multiple libraries or programs, such as the
21285@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21286creates configuration files for every directory level underneath (unless
21287you tell it not to, with the @samp{--norecursion} option).
21288
94e91d6d
MC
21289You should run the @code{configure} script from the top directory in the
21290source tree, the @file{gdb-@var{version-number}} directory. If you run
21291@code{configure} from one of the subdirectories, you will configure only
21292that subdirectory. That is usually not what you want. In particular,
21293if you run the first @code{configure} from the @file{gdb} subdirectory
21294of the @file{gdb-@var{version-number}} directory, you will omit the
21295configuration of @file{bfd}, @file{readline}, and other sibling
21296directories of the @file{gdb} subdirectory. This leads to build errors
21297about missing include files such as @file{bfd/bfd.h}.
c906108c 21298
8e04817f
AC
21299You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21300However, you should make sure that the shell on your path (named by
21301the @samp{SHELL} environment variable) is publicly readable. Remember
21302that @value{GDBN} uses the shell to start your program---some systems refuse to
21303let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21304
8e04817f
AC
21305@menu
21306* Separate Objdir:: Compiling @value{GDBN} in another directory
21307* Config Names:: Specifying names for hosts and targets
21308* Configure Options:: Summary of options for configure
21309@end menu
c906108c 21310
8e04817f
AC
21311@node Separate Objdir
21312@section Compiling @value{GDBN} in another directory
c906108c 21313
8e04817f
AC
21314If you want to run @value{GDBN} versions for several host or target machines,
21315you need a different @code{gdb} compiled for each combination of
21316host and target. @code{configure} is designed to make this easy by
21317allowing you to generate each configuration in a separate subdirectory,
21318rather than in the source directory. If your @code{make} program
21319handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21320@code{make} in each of these directories builds the @code{gdb}
21321program specified there.
c906108c 21322
8e04817f
AC
21323To build @code{gdb} in a separate directory, run @code{configure}
21324with the @samp{--srcdir} option to specify where to find the source.
21325(You also need to specify a path to find @code{configure}
21326itself from your working directory. If the path to @code{configure}
21327would be the same as the argument to @samp{--srcdir}, you can leave out
21328the @samp{--srcdir} option; it is assumed.)
c906108c 21329
8e04817f
AC
21330For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21331separate directory for a Sun 4 like this:
c906108c 21332
474c8240 21333@smallexample
8e04817f
AC
21334@group
21335cd gdb-@value{GDBVN}
21336mkdir ../gdb-sun4
21337cd ../gdb-sun4
21338../gdb-@value{GDBVN}/configure sun4
21339make
21340@end group
474c8240 21341@end smallexample
c906108c 21342
8e04817f
AC
21343When @code{configure} builds a configuration using a remote source
21344directory, it creates a tree for the binaries with the same structure
21345(and using the same names) as the tree under the source directory. In
21346the example, you'd find the Sun 4 library @file{libiberty.a} in the
21347directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21348@file{gdb-sun4/gdb}.
c906108c 21349
94e91d6d
MC
21350Make sure that your path to the @file{configure} script has just one
21351instance of @file{gdb} in it. If your path to @file{configure} looks
21352like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21353one subdirectory of @value{GDBN}, not the whole package. This leads to
21354build errors about missing include files such as @file{bfd/bfd.h}.
21355
8e04817f
AC
21356One popular reason to build several @value{GDBN} configurations in separate
21357directories is to configure @value{GDBN} for cross-compiling (where
21358@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21359programs that run on another machine---the @dfn{target}).
21360You specify a cross-debugging target by
21361giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21362
8e04817f
AC
21363When you run @code{make} to build a program or library, you must run
21364it in a configured directory---whatever directory you were in when you
21365called @code{configure} (or one of its subdirectories).
c906108c 21366
8e04817f
AC
21367The @code{Makefile} that @code{configure} generates in each source
21368directory also runs recursively. If you type @code{make} in a source
21369directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21370directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21371will build all the required libraries, and then build GDB.
c906108c 21372
8e04817f
AC
21373When you have multiple hosts or targets configured in separate
21374directories, you can run @code{make} on them in parallel (for example,
21375if they are NFS-mounted on each of the hosts); they will not interfere
21376with each other.
c906108c 21377
8e04817f
AC
21378@node Config Names
21379@section Specifying names for hosts and targets
c906108c 21380
8e04817f
AC
21381The specifications used for hosts and targets in the @code{configure}
21382script are based on a three-part naming scheme, but some short predefined
21383aliases are also supported. The full naming scheme encodes three pieces
21384of information in the following pattern:
c906108c 21385
474c8240 21386@smallexample
8e04817f 21387@var{architecture}-@var{vendor}-@var{os}
474c8240 21388@end smallexample
c906108c 21389
8e04817f
AC
21390For example, you can use the alias @code{sun4} as a @var{host} argument,
21391or as the value for @var{target} in a @code{--target=@var{target}}
21392option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21393
8e04817f
AC
21394The @code{configure} script accompanying @value{GDBN} does not provide
21395any query facility to list all supported host and target names or
21396aliases. @code{configure} calls the Bourne shell script
21397@code{config.sub} to map abbreviations to full names; you can read the
21398script, if you wish, or you can use it to test your guesses on
21399abbreviations---for example:
c906108c 21400
8e04817f
AC
21401@smallexample
21402% sh config.sub i386-linux
21403i386-pc-linux-gnu
21404% sh config.sub alpha-linux
21405alpha-unknown-linux-gnu
21406% sh config.sub hp9k700
21407hppa1.1-hp-hpux
21408% sh config.sub sun4
21409sparc-sun-sunos4.1.1
21410% sh config.sub sun3
21411m68k-sun-sunos4.1.1
21412% sh config.sub i986v
21413Invalid configuration `i986v': machine `i986v' not recognized
21414@end smallexample
c906108c 21415
8e04817f
AC
21416@noindent
21417@code{config.sub} is also distributed in the @value{GDBN} source
21418directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21419
8e04817f
AC
21420@node Configure Options
21421@section @code{configure} options
c906108c 21422
8e04817f
AC
21423Here is a summary of the @code{configure} options and arguments that
21424are most often useful for building @value{GDBN}. @code{configure} also has
21425several other options not listed here. @inforef{What Configure
21426Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21427
474c8240 21428@smallexample
8e04817f
AC
21429configure @r{[}--help@r{]}
21430 @r{[}--prefix=@var{dir}@r{]}
21431 @r{[}--exec-prefix=@var{dir}@r{]}
21432 @r{[}--srcdir=@var{dirname}@r{]}
21433 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21434 @r{[}--target=@var{target}@r{]}
21435 @var{host}
474c8240 21436@end smallexample
c906108c 21437
8e04817f
AC
21438@noindent
21439You may introduce options with a single @samp{-} rather than
21440@samp{--} if you prefer; but you may abbreviate option names if you use
21441@samp{--}.
c906108c 21442
8e04817f
AC
21443@table @code
21444@item --help
21445Display a quick summary of how to invoke @code{configure}.
c906108c 21446
8e04817f
AC
21447@item --prefix=@var{dir}
21448Configure the source to install programs and files under directory
21449@file{@var{dir}}.
c906108c 21450
8e04817f
AC
21451@item --exec-prefix=@var{dir}
21452Configure the source to install programs under directory
21453@file{@var{dir}}.
c906108c 21454
8e04817f
AC
21455@c avoid splitting the warning from the explanation:
21456@need 2000
21457@item --srcdir=@var{dirname}
21458@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21459@code{make} that implements the @code{VPATH} feature.}@*
21460Use this option to make configurations in directories separate from the
21461@value{GDBN} source directories. Among other things, you can use this to
21462build (or maintain) several configurations simultaneously, in separate
21463directories. @code{configure} writes configuration specific files in
21464the current directory, but arranges for them to use the source in the
21465directory @var{dirname}. @code{configure} creates directories under
21466the working directory in parallel to the source directories below
21467@var{dirname}.
c906108c 21468
8e04817f
AC
21469@item --norecursion
21470Configure only the directory level where @code{configure} is executed; do not
21471propagate configuration to subdirectories.
c906108c 21472
8e04817f
AC
21473@item --target=@var{target}
21474Configure @value{GDBN} for cross-debugging programs running on the specified
21475@var{target}. Without this option, @value{GDBN} is configured to debug
21476programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21477
8e04817f 21478There is no convenient way to generate a list of all available targets.
c906108c 21479
8e04817f
AC
21480@item @var{host} @dots{}
21481Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21482
8e04817f
AC
21483There is no convenient way to generate a list of all available hosts.
21484@end table
c906108c 21485
8e04817f
AC
21486There are many other options available as well, but they are generally
21487needed for special purposes only.
c906108c 21488
8e04817f
AC
21489@node Maintenance Commands
21490@appendix Maintenance Commands
21491@cindex maintenance commands
21492@cindex internal commands
c906108c 21493
8e04817f 21494In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21495includes a number of commands intended for @value{GDBN} developers,
21496that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21497provided here for reference. (For commands that turn on debugging
21498messages, see @ref{Debugging Output}.)
c906108c 21499
8e04817f 21500@table @code
09d4efe1
EZ
21501@kindex maint agent
21502@item maint agent @var{expression}
21503Translate the given @var{expression} into remote agent bytecodes.
21504This command is useful for debugging the Agent Expression mechanism
21505(@pxref{Agent Expressions}).
21506
8e04817f
AC
21507@kindex maint info breakpoints
21508@item @anchor{maint info breakpoints}maint info breakpoints
21509Using the same format as @samp{info breakpoints}, display both the
21510breakpoints you've set explicitly, and those @value{GDBN} is using for
21511internal purposes. Internal breakpoints are shown with negative
21512breakpoint numbers. The type column identifies what kind of breakpoint
21513is shown:
c906108c 21514
8e04817f
AC
21515@table @code
21516@item breakpoint
21517Normal, explicitly set breakpoint.
c906108c 21518
8e04817f
AC
21519@item watchpoint
21520Normal, explicitly set watchpoint.
c906108c 21521
8e04817f
AC
21522@item longjmp
21523Internal breakpoint, used to handle correctly stepping through
21524@code{longjmp} calls.
c906108c 21525
8e04817f
AC
21526@item longjmp resume
21527Internal breakpoint at the target of a @code{longjmp}.
c906108c 21528
8e04817f
AC
21529@item until
21530Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21531
8e04817f
AC
21532@item finish
21533Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21534
8e04817f
AC
21535@item shlib events
21536Shared library events.
c906108c 21537
8e04817f 21538@end table
c906108c 21539
09d4efe1
EZ
21540@kindex maint check-symtabs
21541@item maint check-symtabs
21542Check the consistency of psymtabs and symtabs.
21543
21544@kindex maint cplus first_component
21545@item maint cplus first_component @var{name}
21546Print the first C@t{++} class/namespace component of @var{name}.
21547
21548@kindex maint cplus namespace
21549@item maint cplus namespace
21550Print the list of possible C@t{++} namespaces.
21551
21552@kindex maint demangle
21553@item maint demangle @var{name}
21554Demangle a C@t{++} or Objective-C manled @var{name}.
21555
21556@kindex maint deprecate
21557@kindex maint undeprecate
21558@cindex deprecated commands
21559@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21560@itemx maint undeprecate @var{command}
21561Deprecate or undeprecate the named @var{command}. Deprecated commands
21562cause @value{GDBN} to issue a warning when you use them. The optional
21563argument @var{replacement} says which newer command should be used in
21564favor of the deprecated one; if it is given, @value{GDBN} will mention
21565the replacement as part of the warning.
21566
21567@kindex maint dump-me
21568@item maint dump-me
721c2651 21569@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21570Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21571This is supported only on systems which support aborting a program
21572with the @code{SIGQUIT} signal.
09d4efe1 21573
8d30a00d
AC
21574@kindex maint internal-error
21575@kindex maint internal-warning
09d4efe1
EZ
21576@item maint internal-error @r{[}@var{message-text}@r{]}
21577@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21578Cause @value{GDBN} to call the internal function @code{internal_error}
21579or @code{internal_warning} and hence behave as though an internal error
21580or internal warning has been detected. In addition to reporting the
21581internal problem, these functions give the user the opportunity to
21582either quit @value{GDBN} or create a core file of the current
21583@value{GDBN} session.
21584
09d4efe1
EZ
21585These commands take an optional parameter @var{message-text} that is
21586used as the text of the error or warning message.
21587
21588Here's an example of using @code{indernal-error}:
21589
8d30a00d 21590@smallexample
f7dc1244 21591(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21592@dots{}/maint.c:121: internal-error: testing, 1, 2
21593A problem internal to GDB has been detected. Further
21594debugging may prove unreliable.
21595Quit this debugging session? (y or n) @kbd{n}
21596Create a core file? (y or n) @kbd{n}
f7dc1244 21597(@value{GDBP})
8d30a00d
AC
21598@end smallexample
21599
09d4efe1
EZ
21600@kindex maint packet
21601@item maint packet @var{text}
21602If @value{GDBN} is talking to an inferior via the serial protocol,
21603then this command sends the string @var{text} to the inferior, and
21604displays the response packet. @value{GDBN} supplies the initial
21605@samp{$} character, the terminating @samp{#} character, and the
21606checksum.
21607
21608@kindex maint print architecture
21609@item maint print architecture @r{[}@var{file}@r{]}
21610Print the entire architecture configuration. The optional argument
21611@var{file} names the file where the output goes.
8d30a00d 21612
00905d52
AC
21613@kindex maint print dummy-frames
21614@item maint print dummy-frames
00905d52
AC
21615Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21616
21617@smallexample
f7dc1244 21618(@value{GDBP}) @kbd{b add}
00905d52 21619@dots{}
f7dc1244 21620(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21621Breakpoint 2, add (a=2, b=3) at @dots{}
2162258 return (a + b);
21623The program being debugged stopped while in a function called from GDB.
21624@dots{}
f7dc1244 21625(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
216260x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21627 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21628 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21629(@value{GDBP})
00905d52
AC
21630@end smallexample
21631
21632Takes an optional file parameter.
21633
0680b120
AC
21634@kindex maint print registers
21635@kindex maint print raw-registers
21636@kindex maint print cooked-registers
617073a9 21637@kindex maint print register-groups
09d4efe1
EZ
21638@item maint print registers @r{[}@var{file}@r{]}
21639@itemx maint print raw-registers @r{[}@var{file}@r{]}
21640@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21641@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21642Print @value{GDBN}'s internal register data structures.
21643
617073a9
AC
21644The command @code{maint print raw-registers} includes the contents of
21645the raw register cache; the command @code{maint print cooked-registers}
21646includes the (cooked) value of all registers; and the command
21647@code{maint print register-groups} includes the groups that each
21648register is a member of. @xref{Registers,, Registers, gdbint,
21649@value{GDBN} Internals}.
0680b120 21650
09d4efe1
EZ
21651These commands take an optional parameter, a file name to which to
21652write the information.
0680b120 21653
617073a9 21654@kindex maint print reggroups
09d4efe1
EZ
21655@item maint print reggroups @r{[}@var{file}@r{]}
21656Print @value{GDBN}'s internal register group data structures. The
21657optional argument @var{file} tells to what file to write the
21658information.
617073a9 21659
09d4efe1 21660The register groups info looks like this:
617073a9
AC
21661
21662@smallexample
f7dc1244 21663(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21664 Group Type
21665 general user
21666 float user
21667 all user
21668 vector user
21669 system user
21670 save internal
21671 restore internal
617073a9
AC
21672@end smallexample
21673
09d4efe1
EZ
21674@kindex flushregs
21675@item flushregs
21676This command forces @value{GDBN} to flush its internal register cache.
21677
21678@kindex maint print objfiles
21679@cindex info for known object files
21680@item maint print objfiles
21681Print a dump of all known object files. For each object file, this
21682command prints its name, address in memory, and all of its psymtabs
21683and symtabs.
21684
21685@kindex maint print statistics
21686@cindex bcache statistics
21687@item maint print statistics
21688This command prints, for each object file in the program, various data
21689about that object file followed by the byte cache (@dfn{bcache})
21690statistics for the object file. The objfile data includes the number
21691of minimal, partical, full, and stabs symbols, the number of types
21692defined by the objfile, the number of as yet unexpanded psym tables,
21693the number of line tables and string tables, and the amount of memory
21694used by the various tables. The bcache statistics include the counts,
21695sizes, and counts of duplicates of all and unique objects, max,
21696average, and median entry size, total memory used and its overhead and
21697savings, and various measures of the hash table size and chain
21698lengths.
21699
21700@kindex maint print type
21701@cindex type chain of a data type
21702@item maint print type @var{expr}
21703Print the type chain for a type specified by @var{expr}. The argument
21704can be either a type name or a symbol. If it is a symbol, the type of
21705that symbol is described. The type chain produced by this command is
21706a recursive definition of the data type as stored in @value{GDBN}'s
21707data structures, including its flags and contained types.
21708
21709@kindex maint set dwarf2 max-cache-age
21710@kindex maint show dwarf2 max-cache-age
21711@item maint set dwarf2 max-cache-age
21712@itemx maint show dwarf2 max-cache-age
21713Control the DWARF 2 compilation unit cache.
21714
21715@cindex DWARF 2 compilation units cache
21716In object files with inter-compilation-unit references, such as those
21717produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21718reader needs to frequently refer to previously read compilation units.
21719This setting controls how long a compilation unit will remain in the
21720cache if it is not referenced. A higher limit means that cached
21721compilation units will be stored in memory longer, and more total
21722memory will be used. Setting it to zero disables caching, which will
21723slow down @value{GDBN} startup, but reduce memory consumption.
21724
e7ba9c65
DJ
21725@kindex maint set profile
21726@kindex maint show profile
21727@cindex profiling GDB
21728@item maint set profile
21729@itemx maint show profile
21730Control profiling of @value{GDBN}.
21731
21732Profiling will be disabled until you use the @samp{maint set profile}
21733command to enable it. When you enable profiling, the system will begin
21734collecting timing and execution count data; when you disable profiling or
21735exit @value{GDBN}, the results will be written to a log file. Remember that
21736if you use profiling, @value{GDBN} will overwrite the profiling log file
21737(often called @file{gmon.out}). If you have a record of important profiling
21738data in a @file{gmon.out} file, be sure to move it to a safe location.
21739
21740Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21741compiled with the @samp{-pg} compiler option.
e7ba9c65 21742
09d4efe1
EZ
21743@kindex maint show-debug-regs
21744@cindex x86 hardware debug registers
21745@item maint show-debug-regs
21746Control whether to show variables that mirror the x86 hardware debug
21747registers. Use @code{ON} to enable, @code{OFF} to disable. If
21748enabled, the debug registers values are shown when GDB inserts or
21749removes a hardware breakpoint or watchpoint, and when the inferior
21750triggers a hardware-assisted breakpoint or watchpoint.
21751
21752@kindex maint space
21753@cindex memory used by commands
21754@item maint space
21755Control whether to display memory usage for each command. If set to a
21756nonzero value, @value{GDBN} will display how much memory each command
21757took, following the command's own output. This can also be requested
21758by invoking @value{GDBN} with the @option{--statistics} command-line
21759switch (@pxref{Mode Options}).
21760
21761@kindex maint time
21762@cindex time of command execution
21763@item maint time
21764Control whether to display the execution time for each command. If
21765set to a nonzero value, @value{GDBN} will display how much time it
21766took to execute each command, following the command's own output.
21767This can also be requested by invoking @value{GDBN} with the
21768@option{--statistics} command-line switch (@pxref{Mode Options}).
21769
21770@kindex maint translate-address
21771@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21772Find the symbol stored at the location specified by the address
21773@var{addr} and an optional section name @var{section}. If found,
21774@value{GDBN} prints the name of the closest symbol and an offset from
21775the symbol's location to the specified address. This is similar to
21776the @code{info address} command (@pxref{Symbols}), except that this
21777command also allows to find symbols in other sections.
ae038cb0 21778
8e04817f 21779@end table
c906108c 21780
9c16f35a
EZ
21781The following command is useful for non-interactive invocations of
21782@value{GDBN}, such as in the test suite.
21783
21784@table @code
21785@item set watchdog @var{nsec}
21786@kindex set watchdog
21787@cindex watchdog timer
21788@cindex timeout for commands
21789Set the maximum number of seconds @value{GDBN} will wait for the
21790target operation to finish. If this time expires, @value{GDBN}
21791reports and error and the command is aborted.
21792
21793@item show watchdog
21794Show the current setting of the target wait timeout.
21795@end table
c906108c 21796
e0ce93ac 21797@node Remote Protocol
8e04817f 21798@appendix @value{GDBN} Remote Serial Protocol
c906108c 21799
ee2d5c50
AC
21800@menu
21801* Overview::
21802* Packets::
21803* Stop Reply Packets::
21804* General Query Packets::
21805* Register Packet Format::
21806* Examples::
0ce1b118 21807* File-I/O remote protocol extension::
ee2d5c50
AC
21808@end menu
21809
21810@node Overview
21811@section Overview
21812
8e04817f
AC
21813There may be occasions when you need to know something about the
21814protocol---for example, if there is only one serial port to your target
21815machine, you might want your program to do something special if it
21816recognizes a packet meant for @value{GDBN}.
c906108c 21817
d2c6833e 21818In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21819transmitted and received data respectfully.
c906108c 21820
8e04817f
AC
21821@cindex protocol, @value{GDBN} remote serial
21822@cindex serial protocol, @value{GDBN} remote
21823@cindex remote serial protocol
21824All @value{GDBN} commands and responses (other than acknowledgments) are
21825sent as a @var{packet}. A @var{packet} is introduced with the character
21826@samp{$}, the actual @var{packet-data}, and the terminating character
21827@samp{#} followed by a two-digit @var{checksum}:
c906108c 21828
474c8240 21829@smallexample
8e04817f 21830@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21831@end smallexample
8e04817f 21832@noindent
c906108c 21833
8e04817f
AC
21834@cindex checksum, for @value{GDBN} remote
21835@noindent
21836The two-digit @var{checksum} is computed as the modulo 256 sum of all
21837characters between the leading @samp{$} and the trailing @samp{#} (an
21838eight bit unsigned checksum).
c906108c 21839
8e04817f
AC
21840Implementors should note that prior to @value{GDBN} 5.0 the protocol
21841specification also included an optional two-digit @var{sequence-id}:
c906108c 21842
474c8240 21843@smallexample
8e04817f 21844@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21845@end smallexample
c906108c 21846
8e04817f
AC
21847@cindex sequence-id, for @value{GDBN} remote
21848@noindent
21849That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21850has never output @var{sequence-id}s. Stubs that handle packets added
21851since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21852
8e04817f
AC
21853@cindex acknowledgment, for @value{GDBN} remote
21854When either the host or the target machine receives a packet, the first
21855response expected is an acknowledgment: either @samp{+} (to indicate
21856the package was received correctly) or @samp{-} (to request
21857retransmission):
c906108c 21858
474c8240 21859@smallexample
d2c6833e
AC
21860-> @code{$}@var{packet-data}@code{#}@var{checksum}
21861<- @code{+}
474c8240 21862@end smallexample
8e04817f 21863@noindent
53a5351d 21864
8e04817f
AC
21865The host (@value{GDBN}) sends @var{command}s, and the target (the
21866debugging stub incorporated in your program) sends a @var{response}. In
21867the case of step and continue @var{command}s, the response is only sent
21868when the operation has completed (the target has again stopped).
c906108c 21869
8e04817f
AC
21870@var{packet-data} consists of a sequence of characters with the
21871exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21872exceptions).
c906108c 21873
8e04817f 21874Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21875@cindex remote protocol, field separator
8e04817f 21876@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21877@sc{hex} with leading zeros suppressed.
c906108c 21878
8e04817f
AC
21879Implementors should note that prior to @value{GDBN} 5.0, the character
21880@samp{:} could not appear as the third character in a packet (as it
21881would potentially conflict with the @var{sequence-id}).
c906108c 21882
8e04817f
AC
21883Response @var{data} can be run-length encoded to save space. A @samp{*}
21884means that the next character is an @sc{ascii} encoding giving a repeat count
21885which stands for that many repetitions of the character preceding the
21886@samp{*}. The encoding is @code{n+29}, yielding a printable character
21887where @code{n >=3} (which is where rle starts to win). The printable
21888characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21889value greater than 126 should not be used.
c906108c 21890
8e04817f 21891So:
474c8240 21892@smallexample
8e04817f 21893"@code{0* }"
474c8240 21894@end smallexample
8e04817f
AC
21895@noindent
21896means the same as "0000".
c906108c 21897
8e04817f
AC
21898The error response returned for some packets includes a two character
21899error number. That number is not well defined.
c906108c 21900
8e04817f
AC
21901For any @var{command} not supported by the stub, an empty response
21902(@samp{$#00}) should be returned. That way it is possible to extend the
21903protocol. A newer @value{GDBN} can tell if a packet is supported based
21904on that response.
c906108c 21905
b383017d
RM
21906A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21907@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21908optional.
c906108c 21909
ee2d5c50
AC
21910@node Packets
21911@section Packets
21912
21913The following table provides a complete list of all currently defined
21914@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
21915@xref{File-I/O remote protocol extension}, for details about the File
21916I/O extension of the remote protocol.
ee2d5c50
AC
21917
21918@table @r
21919
21920@item @code{!} --- extended mode
21921@cindex @code{!} packet
21922
8e04817f
AC
21923Enable extended mode. In extended mode, the remote server is made
21924persistent. The @samp{R} packet is used to restart the program being
21925debugged.
ee2d5c50
AC
21926
21927Reply:
21928@table @samp
21929@item OK
8e04817f 21930The remote target both supports and has enabled extended mode.
ee2d5c50 21931@end table
c906108c 21932
ee2d5c50
AC
21933@item @code{?} --- last signal
21934@cindex @code{?} packet
c906108c 21935
ee2d5c50
AC
21936Indicate the reason the target halted. The reply is the same as for
21937step and continue.
c906108c 21938
ee2d5c50
AC
21939Reply:
21940@xref{Stop Reply Packets}, for the reply specifications.
21941
21942@item @code{a} --- reserved
21943
21944Reserved for future use.
21945
21946@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21947@cindex @code{A} packet
c906108c 21948
8e04817f
AC
21949Initialized @samp{argv[]} array passed into program. @var{arglen}
21950specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
21951See @code{gdbserver} for more details.
21952
21953Reply:
21954@table @samp
21955@item OK
21956@item E@var{NN}
21957@end table
21958
21959@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
21960@cindex @code{b} packet
21961
21962Change the serial line speed to @var{baud}.
21963
21964JTC: @emph{When does the transport layer state change? When it's
21965received, or after the ACK is transmitted. In either case, there are
21966problems if the command or the acknowledgment packet is dropped.}
21967
21968Stan: @emph{If people really wanted to add something like this, and get
21969it working for the first time, they ought to modify ser-unix.c to send
21970some kind of out-of-band message to a specially-setup stub and have the
21971switch happen "in between" packets, so that from remote protocol's point
21972of view, nothing actually happened.}
21973
21974@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
21975@cindex @code{B} packet
21976
8e04817f 21977Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
21978breakpoint at @var{addr}.
21979
21980This packet has been replaced by the @samp{Z} and @samp{z} packets
21981(@pxref{insert breakpoint or watchpoint packet}).
c906108c 21982
ee2d5c50
AC
21983@item @code{c}@var{addr} --- continue
21984@cindex @code{c} packet
21985
21986@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 21987current address.
c906108c 21988
ee2d5c50
AC
21989Reply:
21990@xref{Stop Reply Packets}, for the reply specifications.
21991
21992@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
21993@cindex @code{C} packet
21994
8e04817f
AC
21995Continue with signal @var{sig} (hex signal number). If
21996@code{;}@var{addr} is omitted, resume at same address.
c906108c 21997
ee2d5c50
AC
21998Reply:
21999@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22000
ee2d5c50
AC
22001@item @code{d} --- toggle debug @strong{(deprecated)}
22002@cindex @code{d} packet
22003
22004Toggle debug flag.
22005
22006@item @code{D} --- detach
22007@cindex @code{D} packet
22008
22009Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22010before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22011
22012Reply:
22013@table @samp
22014@item @emph{no response}
8e04817f 22015@value{GDBN} does not check for any response after sending this packet.
ee2d5c50 22016@end table
c906108c 22017
ee2d5c50 22018@item @code{e} --- reserved
c906108c 22019
ee2d5c50 22020Reserved for future use.
c906108c 22021
ee2d5c50 22022@item @code{E} --- reserved
c906108c 22023
ee2d5c50 22024Reserved for future use.
c906108c 22025
ee2d5c50
AC
22026@item @code{f} --- reserved
22027
22028Reserved for future use.
22029
0ce1b118
CV
22030@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22031@cindex @code{F} packet
ee2d5c50 22032
0ce1b118
CV
22033This packet is send by @value{GDBN} as reply to a @code{F} request packet
22034sent by the target. This is part of the File-I/O protocol extension.
22035@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22036
22037@item @code{g} --- read registers
22038@anchor{read registers packet}
22039@cindex @code{g} packet
22040
22041Read general registers.
22042
22043Reply:
22044@table @samp
22045@item @var{XX@dots{}}
8e04817f
AC
22046Each byte of register data is described by two hex digits. The bytes
22047with the register are transmitted in target byte order. The size of
22048each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22049determined by the @value{GDBN} internal macros
22050@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22051specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22052@item E@var{NN}
22053for an error.
22054@end table
c906108c 22055
ee2d5c50
AC
22056@item @code{G}@var{XX@dots{}} --- write regs
22057@cindex @code{G} packet
c906108c 22058
ee2d5c50
AC
22059@xref{read registers packet}, for a description of the @var{XX@dots{}}
22060data.
22061
22062Reply:
22063@table @samp
22064@item OK
22065for success
22066@item E@var{NN}
22067for an error
22068@end table
22069
22070@item @code{h} --- reserved
22071
22072Reserved for future use.
22073
b383017d 22074@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22075@cindex @code{H} packet
c906108c 22076
8e04817f 22077Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22078@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22079should be @samp{c} for step and continue operations, @samp{g} for other
22080operations. The thread designator @var{t@dots{}} may be -1, meaning all
22081the threads, a thread number, or zero which means pick any thread.
22082
22083Reply:
22084@table @samp
22085@item OK
22086for success
22087@item E@var{NN}
22088for an error
22089@end table
c906108c 22090
8e04817f
AC
22091@c FIXME: JTC:
22092@c 'H': How restrictive (or permissive) is the thread model. If a
22093@c thread is selected and stopped, are other threads allowed
22094@c to continue to execute? As I mentioned above, I think the
22095@c semantics of each command when a thread is selected must be
22096@c described. For example:
22097@c
22098@c 'g': If the stub supports threads and a specific thread is
22099@c selected, returns the register block from that thread;
22100@c otherwise returns current registers.
22101@c
22102@c 'G' If the stub supports threads and a specific thread is
22103@c selected, sets the registers of the register block of
22104@c that thread; otherwise sets current registers.
c906108c 22105
ee2d5c50
AC
22106@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22107@anchor{cycle step packet}
22108@cindex @code{i} packet
22109
8e04817f
AC
22110Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22111present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22112step starting at that address.
c906108c 22113
ee2d5c50
AC
22114@item @code{I} --- signal then cycle step @strong{(reserved)}
22115@cindex @code{I} packet
22116
22117@xref{step with signal packet}. @xref{cycle step packet}.
22118
22119@item @code{j} --- reserved
22120
22121Reserved for future use.
22122
22123@item @code{J} --- reserved
c906108c 22124
ee2d5c50 22125Reserved for future use.
c906108c 22126
ee2d5c50
AC
22127@item @code{k} --- kill request
22128@cindex @code{k} packet
c906108c 22129
ac282366 22130FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22131thread context has been selected (i.e.@: does 'k' kill only that
22132thread?)}.
c906108c 22133
ee2d5c50 22134@item @code{K} --- reserved
c906108c 22135
ee2d5c50
AC
22136Reserved for future use.
22137
22138@item @code{l} --- reserved
22139
22140Reserved for future use.
22141
22142@item @code{L} --- reserved
22143
22144Reserved for future use.
22145
22146@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22147@cindex @code{m} packet
c906108c 22148
8e04817f 22149Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22150Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22151assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22152transfer mechanism is needed.}
c906108c 22153
ee2d5c50
AC
22154Reply:
22155@table @samp
22156@item @var{XX@dots{}}
22157@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22158to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22159that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22160accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22161needed.}
22162@item E@var{NN}
22163@var{NN} is errno
22164@end table
22165
22166@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22167@cindex @code{M} packet
22168
8e04817f 22169Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22170@var{XX@dots{}} is the data.
22171
22172Reply:
22173@table @samp
22174@item OK
22175for success
22176@item E@var{NN}
8e04817f
AC
22177for an error (this includes the case where only part of the data was
22178written).
ee2d5c50 22179@end table
c906108c 22180
ee2d5c50 22181@item @code{n} --- reserved
c906108c 22182
ee2d5c50 22183Reserved for future use.
c906108c 22184
ee2d5c50 22185@item @code{N} --- reserved
c906108c 22186
ee2d5c50 22187Reserved for future use.
c906108c 22188
ee2d5c50
AC
22189@item @code{o} --- reserved
22190
22191Reserved for future use.
22192
22193@item @code{O} --- reserved
22194
2e868123 22195@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22196@cindex @code{p} packet
22197
2e868123
AC
22198@xref{read registers packet}, for a description of how the returned
22199register value is encoded.
ee2d5c50
AC
22200
22201Reply:
22202@table @samp
2e868123
AC
22203@item @var{XX@dots{}}
22204the register's value
22205@item E@var{NN}
22206for an error
22207@item
22208Indicating an unrecognized @var{query}.
ee2d5c50
AC
22209@end table
22210
22211@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22212@anchor{write register packet}
22213@cindex @code{P} packet
22214
22215Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22216digits for each byte in the register (target byte order).
c906108c 22217
ee2d5c50
AC
22218Reply:
22219@table @samp
22220@item OK
22221for success
22222@item E@var{NN}
22223for an error
22224@end table
22225
22226@item @code{q}@var{query} --- general query
22227@anchor{general query packet}
22228@cindex @code{q} packet
22229
22230Request info about @var{query}. In general @value{GDBN} queries have a
22231leading upper case letter. Custom vendor queries should use a company
22232prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22233be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22234that they match the full @var{query} name.
22235
22236Reply:
22237@table @samp
22238@item @var{XX@dots{}}
22239Hex encoded data from query. The reply can not be empty.
22240@item E@var{NN}
22241error reply
8e04817f 22242@item
ee2d5c50
AC
22243Indicating an unrecognized @var{query}.
22244@end table
22245
22246@item @code{Q}@var{var}@code{=}@var{val} --- general set
22247@cindex @code{Q} packet
22248
22249Set value of @var{var} to @var{val}.
22250
22251@xref{general query packet}, for a discussion of naming conventions.
c906108c 22252
ee2d5c50
AC
22253@item @code{r} --- reset @strong{(deprecated)}
22254@cindex @code{r} packet
c906108c 22255
8e04817f 22256Reset the entire system.
c906108c 22257
ee2d5c50
AC
22258@item @code{R}@var{XX} --- remote restart
22259@cindex @code{R} packet
22260
8e04817f
AC
22261Restart the program being debugged. @var{XX}, while needed, is ignored.
22262This packet is only available in extended mode.
ee2d5c50
AC
22263
22264Reply:
22265@table @samp
22266@item @emph{no reply}
8e04817f 22267The @samp{R} packet has no reply.
ee2d5c50
AC
22268@end table
22269
22270@item @code{s}@var{addr} --- step
22271@cindex @code{s} packet
c906108c 22272
8e04817f
AC
22273@var{addr} is address to resume. If @var{addr} is omitted, resume at
22274same address.
c906108c 22275
ee2d5c50
AC
22276Reply:
22277@xref{Stop Reply Packets}, for the reply specifications.
22278
22279@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22280@anchor{step with signal packet}
22281@cindex @code{S} packet
22282
8e04817f 22283Like @samp{C} but step not continue.
c906108c 22284
ee2d5c50
AC
22285Reply:
22286@xref{Stop Reply Packets}, for the reply specifications.
22287
b383017d 22288@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22289@cindex @code{t} packet
22290
8e04817f 22291Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22292@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22293@var{addr} must be at least 3 digits.
c906108c 22294
ee2d5c50
AC
22295@item @code{T}@var{XX} --- thread alive
22296@cindex @code{T} packet
c906108c 22297
ee2d5c50 22298Find out if the thread XX is alive.
c906108c 22299
ee2d5c50
AC
22300Reply:
22301@table @samp
22302@item OK
22303thread is still alive
22304@item E@var{NN}
22305thread is dead
22306@end table
22307
22308@item @code{u} --- reserved
22309
22310Reserved for future use.
22311
22312@item @code{U} --- reserved
22313
22314Reserved for future use.
22315
86d30acc 22316@item @code{v} --- verbose packet prefix
ee2d5c50 22317
86d30acc
DJ
22318Packets starting with @code{v} are identified by a multi-letter name,
22319up to the first @code{;} or @code{?} (or the end of the packet).
22320
22321@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22322@cindex @code{vCont} packet
22323
22324Resume the inferior. Different actions may be specified for each thread.
22325If an action is specified with no @var{tid}, then it is applied to any
22326threads that don't have a specific action specified; if no default action is
22327specified then other threads should remain stopped. Specifying multiple
22328default actions is an error; specifying no actions is also an error.
22329Thread IDs are specified in hexadecimal. Currently supported actions are:
22330
22331@table @code
22332@item c
22333Continue.
22334@item C@var{sig}
22335Continue with signal @var{sig}. @var{sig} should be two hex digits.
22336@item s
22337Step.
22338@item S@var{sig}
22339Step with signal @var{sig}. @var{sig} should be two hex digits.
22340@end table
22341
22342The optional @var{addr} argument normally associated with these packets is
22343not supported in @code{vCont}.
22344
22345Reply:
22346@xref{Stop Reply Packets}, for the reply specifications.
22347
22348@item @code{vCont?} --- extended resume query
22349@cindex @code{vCont?} packet
22350
22351Query support for the @code{vCont} packet.
22352
22353Reply:
22354@table @samp
22355@item @code{vCont}[;@var{action}]...
22356The @code{vCont} packet is supported. Each @var{action} is a supported
22357command in the @code{vCont} packet.
22358@item
22359The @code{vCont} packet is not supported.
22360@end table
ee2d5c50
AC
22361
22362@item @code{V} --- reserved
c906108c 22363
ee2d5c50 22364Reserved for future use.
c906108c 22365
ee2d5c50 22366@item @code{w} --- reserved
c906108c 22367
ee2d5c50 22368Reserved for future use.
c906108c 22369
ee2d5c50 22370@item @code{W} --- reserved
c906108c 22371
ee2d5c50 22372Reserved for future use.
c906108c 22373
ee2d5c50
AC
22374@item @code{x} --- reserved
22375
22376Reserved for future use.
22377
22378@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22379@cindex @code{X} packet
22380
22381@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22382is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22383escaped using @code{0x7d}, and then XORed with @code{0x20}.
22384For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22385
ee2d5c50
AC
22386Reply:
22387@table @samp
22388@item OK
22389for success
22390@item E@var{NN}
22391for an error
22392@end table
22393
22394@item @code{y} --- reserved
c906108c 22395
ee2d5c50 22396Reserved for future use.
c906108c 22397
ee2d5c50
AC
22398@item @code{Y} reserved
22399
22400Reserved for future use.
22401
2f870471
AC
22402@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22403@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22404@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22405@cindex @code{z} packet
2f870471 22406@cindex @code{Z} packets
ee2d5c50 22407
2f870471
AC
22408Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22409watchpoint starting at address @var{address} and covering the next
22410@var{length} bytes.
ee2d5c50 22411
2f870471
AC
22412Each breakpoint and watchpoint packet @var{type} is documented
22413separately.
22414
512217c7
AC
22415@emph{Implementation notes: A remote target shall return an empty string
22416for an unrecognized breakpoint or watchpoint packet @var{type}. A
22417remote target shall support either both or neither of a given
2f870471
AC
22418@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22419avoid potential problems with duplicate packets, the operations should
22420be implemented in an idempotent way.}
22421
22422@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22423@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22424@cindex @code{z0} packet
22425@cindex @code{Z0} packet
22426
22427Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22428@code{addr} of size @code{length}.
22429
22430A memory breakpoint is implemented by replacing the instruction at
22431@var{addr} with a software breakpoint or trap instruction. The
22432@code{length} is used by targets that indicates the size of the
22433breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22434@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22435
2f870471
AC
22436@emph{Implementation note: It is possible for a target to copy or move
22437code that contains memory breakpoints (e.g., when implementing
22438overlays). The behavior of this packet, in the presence of such a
22439target, is not defined.}
c906108c 22440
ee2d5c50
AC
22441Reply:
22442@table @samp
2f870471
AC
22443@item OK
22444success
22445@item
22446not supported
ee2d5c50
AC
22447@item E@var{NN}
22448for an error
2f870471
AC
22449@end table
22450
22451@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22452@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22453@cindex @code{z1} packet
22454@cindex @code{Z1} packet
22455
22456Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22457address @code{addr} of size @code{length}.
22458
22459A hardware breakpoint is implemented using a mechanism that is not
22460dependant on being able to modify the target's memory.
22461
22462@emph{Implementation note: A hardware breakpoint is not affected by code
22463movement.}
22464
22465Reply:
22466@table @samp
ee2d5c50 22467@item OK
2f870471
AC
22468success
22469@item
22470not supported
22471@item E@var{NN}
22472for an error
22473@end table
22474
22475@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22476@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22477@cindex @code{z2} packet
22478@cindex @code{Z2} packet
22479
22480Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22481
22482Reply:
22483@table @samp
22484@item OK
22485success
22486@item
22487not supported
22488@item E@var{NN}
22489for an error
22490@end table
22491
22492@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22493@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22494@cindex @code{z3} packet
22495@cindex @code{Z3} packet
22496
2e834e49 22497Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22498
22499Reply:
22500@table @samp
22501@item OK
22502success
22503@item
22504not supported
22505@item E@var{NN}
22506for an error
22507@end table
22508
2e834e49
HPN
22509@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22510@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22511@cindex @code{z4} packet
22512@cindex @code{Z4} packet
22513
22514Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22515
22516Reply:
22517@table @samp
22518@item OK
22519success
22520@item
22521not supported
22522@item E@var{NN}
22523for an error
ee2d5c50
AC
22524@end table
22525
22526@end table
c906108c 22527
ee2d5c50
AC
22528@node Stop Reply Packets
22529@section Stop Reply Packets
22530@cindex stop reply packets
c906108c 22531
8e04817f
AC
22532The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22533receive any of the below as a reply. In the case of the @samp{C},
22534@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22535when the target halts. In the below the exact meaning of @samp{signal
22536number} is poorly defined. In general one of the UNIX signal numbering
22537conventions is used.
c906108c 22538
ee2d5c50 22539@table @samp
c906108c 22540
ee2d5c50
AC
22541@item S@var{AA}
22542@var{AA} is the signal number
c906108c 22543
8e04817f 22544@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
22545@cindex @code{T} packet reply
22546
8e04817f
AC
22547@var{AA} = two hex digit signal number; @var{n...} = register number
22548(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22549by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22550@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22551(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22552address, this is a hex integer; @var{n...} = other string not starting
22553with valid hex digit. @value{GDBN} should ignore this @var{n...},
22554@var{r...} pair and go on to the next. This way we can extend the
22555protocol.
c906108c 22556
ee2d5c50
AC
22557@item W@var{AA}
22558
8e04817f 22559The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22560applicable to certain targets.
22561
22562@item X@var{AA}
c906108c 22563
8e04817f 22564The process terminated with signal @var{AA}.
c906108c 22565
ee2d5c50 22566@item O@var{XX@dots{}}
c906108c 22567
ee2d5c50
AC
22568@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22569any time while the program is running and the debugger should continue
22570to wait for @samp{W}, @samp{T}, etc.
22571
0ce1b118
CV
22572@item F@var{call-id}@code{,}@var{parameter@dots{}}
22573
22574@var{call-id} is the identifier which says which host system call should
22575be called. This is just the name of the function. Translation into the
22576correct system call is only applicable as it's defined in @value{GDBN}.
22577@xref{File-I/O remote protocol extension}, for a list of implemented
22578system calls.
22579
22580@var{parameter@dots{}} is a list of parameters as defined for this very
22581system call.
22582
22583The target replies with this packet when it expects @value{GDBN} to call
22584a host system call on behalf of the target. @value{GDBN} replies with
22585an appropriate @code{F} packet and keeps up waiting for the next reply
22586packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22587@samp{s} action is expected to be continued.
22588@xref{File-I/O remote protocol extension}, for more details.
22589
ee2d5c50
AC
22590@end table
22591
22592@node General Query Packets
22593@section General Query Packets
9c16f35a 22594@cindex remote query requests
c906108c 22595
8e04817f 22596The following set and query packets have already been defined.
c906108c 22597
ee2d5c50 22598@table @r
c906108c 22599
ee2d5c50 22600@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22601@cindex current thread, remote request
22602@cindex @code{qC} packet
ee2d5c50
AC
22603Return the current thread id.
22604
22605Reply:
22606@table @samp
22607@item @code{QC}@var{pid}
e1aac25b 22608Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22609@item *
22610Any other reply implies the old pid.
22611@end table
22612
22613@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22614@cindex list active threads, remote request
22615@cindex @code{qfThreadInfo} packet
ee2d5c50 22616@code{q}@code{sThreadInfo}
c906108c 22617
8e04817f
AC
22618Obtain a list of active thread ids from the target (OS). Since there
22619may be too many active threads to fit into one reply packet, this query
22620works iteratively: it may require more than one query/reply sequence to
22621obtain the entire list of threads. The first query of the sequence will
22622be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22623sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22624
22625NOTE: replaces the @code{qL} query (see below).
22626
22627Reply:
22628@table @samp
22629@item @code{m}@var{id}
22630A single thread id
22631@item @code{m}@var{id},@var{id}@dots{}
22632a comma-separated list of thread ids
22633@item @code{l}
22634(lower case 'el') denotes end of list.
22635@end table
22636
22637In response to each query, the target will reply with a list of one or
e1aac25b
JB
22638more thread ids, in big-endian unsigned hex, separated by commas.
22639@value{GDBN} will respond to each reply with a request for more thread
22640ids (using the @code{qs} form of the query), until the target responds
22641with @code{l} (lower-case el, for @code{'last'}).
c906108c 22642
ee2d5c50 22643@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22644@cindex thread attributes info, remote request
22645@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22646Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22647string description of a thread's attributes from the target OS. This
22648string may contain anything that the target OS thinks is interesting for
22649@value{GDBN} to tell the user about the thread. The string is displayed
22650in @value{GDBN}'s @samp{info threads} display. Some examples of
22651possible thread extra info strings are ``Runnable'', or ``Blocked on
22652Mutex''.
22653
22654Reply:
22655@table @samp
22656@item @var{XX@dots{}}
22657Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22658the printable string containing the extra information about the thread's
8e04817f 22659attributes.
ee2d5c50
AC
22660@end table
22661
22662@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22663
8e04817f
AC
22664Obtain thread information from RTOS. Where: @var{startflag} (one hex
22665digit) is one to indicate the first query and zero to indicate a
22666subsequent query; @var{threadcount} (two hex digits) is the maximum
22667number of threads the response packet can contain; and @var{nextthread}
22668(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22669returned in the response as @var{argthread}.
ee2d5c50
AC
22670
22671NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22672(see above).
22673
22674Reply:
22675@table @samp
22676@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22677Where: @var{count} (two hex digits) is the number of threads being
22678returned; @var{done} (one hex digit) is zero to indicate more threads
22679and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22680digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22681is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22682digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22683@end table
c906108c 22684
ee2d5c50 22685@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22686@cindex CRC of memory block, remote request
22687@cindex @code{qCRC} packet
ee2d5c50
AC
22688Reply:
22689@table @samp
22690@item @code{E}@var{NN}
22691An error (such as memory fault)
22692@item @code{C}@var{CRC32}
22693A 32 bit cyclic redundancy check of the specified memory region.
22694@end table
22695
22696@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22697@cindex section offsets, remote request
22698@cindex @code{qOffsets} packet
8e04817f
AC
22699Get section offsets that the target used when re-locating the downloaded
22700image. @emph{Note: while a @code{Bss} offset is included in the
22701response, @value{GDBN} ignores this and instead applies the @code{Data}
22702offset to the @code{Bss} section.}
c906108c 22703
ee2d5c50
AC
22704Reply:
22705@table @samp
22706@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22707@end table
22708
22709@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22710@cindex thread information, remote request
22711@cindex @code{qP} packet
8e04817f
AC
22712Returns information on @var{threadid}. Where: @var{mode} is a hex
22713encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22714
22715Reply:
22716@table @samp
22717@item *
22718@end table
22719
8e04817f 22720See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22721
ee2d5c50 22722@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22723@cindex execute remote command, remote request
22724@cindex @code{qRcmd} packet
ee2d5c50 22725@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22726execution. Invalid commands should be reported using the output string.
22727Before the final result packet, the target may also respond with a
ee2d5c50
AC
22728number of intermediate @code{O}@var{output} console output packets.
22729@emph{Implementors should note that providing access to a stubs's
22730interpreter may have security implications}.
22731
22732Reply:
22733@table @samp
22734@item OK
8e04817f 22735A command response with no output.
ee2d5c50 22736@item @var{OUTPUT}
8e04817f 22737A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22738@item @code{E}@var{NN}
8e04817f 22739Indicate a badly formed request.
ee2d5c50 22740@item @samp{}
8e04817f 22741When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22742@end table
9c16f35a 22743z
ee2d5c50 22744@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22745@cindex symbol lookup, remote request
22746@cindex @code{qSymbol} packet
8e04817f
AC
22747Notify the target that @value{GDBN} is prepared to serve symbol lookup
22748requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22749
22750Reply:
22751@table @samp
22752@item @code{OK}
8e04817f 22753The target does not need to look up any (more) symbols.
ee2d5c50
AC
22754@item @code{qSymbol:}@var{sym_name}
22755The target requests the value of symbol @var{sym_name} (hex encoded).
22756@value{GDBN} may provide the value by using the
22757@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22758@end table
22759
22760@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22761
22762Set the value of @var{sym_name} to @var{sym_value}.
22763
22764@var{sym_name} (hex encoded) is the name of a symbol whose value the
22765target has previously requested.
22766
22767@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22768@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22769will be empty.
22770
22771Reply:
22772@table @samp
22773@item @code{OK}
8e04817f 22774The target does not need to look up any (more) symbols.
ee2d5c50
AC
22775@item @code{qSymbol:}@var{sym_name}
22776The target requests the value of a new symbol @var{sym_name} (hex
22777encoded). @value{GDBN} will continue to supply the values of symbols
22778(if available), until the target ceases to request them.
22779@end table
eb12ee30 22780
649e03f6 22781@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22782@cindex read special object, remote request
22783@cindex @code{qPart} packet
649e03f6
RM
22784Read uninterpreted bytes from the target's special data area
22785identified by the keyword @code{object}.
22786Request @var{length} bytes starting at @var{offset} bytes into the data.
22787The content and encoding of @var{annex} is specific to the object;
22788it can supply additional details about what data to access.
22789
22790Here are the specific requests of this form defined so far.
22791All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22792requests use the same reply formats, listed below.
22793
22794@table @asis
22795@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22796Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22797auxiliary vector}, and see @ref{Remote configuration,
22798read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22799@end table
22800
22801Reply:
22802@table @asis
22803@item @code{OK}
22804The @var{offset} in the request is at the end of the data.
22805There is no more data to be read.
22806
22807@item @var{XX@dots{}}
22808Hex encoded data bytes read.
22809This may be fewer bytes than the @var{length} in the request.
22810
22811@item @code{E00}
22812The request was malformed, or @var{annex} was invalid.
22813
22814@item @code{E}@var{nn}
22815The offset was invalid, or there was an error encountered reading the data.
22816@var{nn} is a hex-encoded @code{errno} value.
22817
22818@item @code{""} (empty)
22819An empty reply indicates the @var{object} or @var{annex} string was not
22820recognized by the stub.
22821@end table
22822
22823@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22824@cindex write data into object, remote request
649e03f6
RM
22825Write uninterpreted bytes into the target's special data area
22826identified by the keyword @code{object},
22827starting at @var{offset} bytes into the data.
22828@var{data@dots{}} is the hex-encoded data to be written.
22829The content and encoding of @var{annex} is specific to the object;
22830it can supply additional details about what data to access.
22831
22832No requests of this form are presently in use. This specification
22833serves as a placeholder to document the common format that new
22834specific request specifications ought to use.
22835
22836Reply:
22837@table @asis
22838@item @var{nn}
22839@var{nn} (hex encoded) is the number of bytes written.
22840This may be fewer bytes than supplied in the request.
22841
22842@item @code{E00}
22843The request was malformed, or @var{annex} was invalid.
22844
22845@item @code{E}@var{nn}
22846The offset was invalid, or there was an error encountered writing the data.
22847@var{nn} is a hex-encoded @code{errno} value.
22848
22849@item @code{""} (empty)
22850An empty reply indicates the @var{object} or @var{annex} string was not
22851recognized by the stub, or that the object does not support writing.
22852@end table
22853
22854@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22855Requests of this form may be added in the future. When a stub does
22856not recognize the @var{object} keyword, or its support for
22857@var{object} does not recognize the @var{operation} keyword,
22858the stub must respond with an empty packet.
83761cbd
KB
22859
22860@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22861@cindex get thread-local storage address, remote request
22862@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22863Fetch the address associated with thread local storage specified
22864by @var{thread-id}, @var{offset}, and @var{lm}.
22865
22866@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22867thread for which to fetch the TLS address.
22868
22869@var{offset} is the (big endian, hex encoded) offset associated with the
22870thread local variable. (This offset is obtained from the debug
22871information associated with the variable.)
22872
22873@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22874the load module associated with the thread local storage. For example,
22875a @sc{gnu}/Linux system will pass the link map address of the shared
22876object associated with the thread local storage under consideration.
22877Other operating environments may choose to represent the load module
22878differently, so the precise meaning of this parameter will vary.
22879
22880Reply:
22881@table @asis
68c71a2e 22882@item @var{XX@dots{}}
83761cbd
KB
22883Hex encoded (big endian) bytes representing the address of the thread
22884local storage requested.
22885
22886@item @code{E}@var{nn} (where @var{nn} are hex digits)
22887An error occurred.
22888
22889@item @code{""} (empty)
22890An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22891@end table
22892
0abb7bc7
EZ
22893Use of this request packet is controlled by the @code{set remote
22894get-thread-local-storage-address} command (@pxref{Remote
22895configuration, set remote get-thread-local-storage-address}).
22896
ee2d5c50
AC
22897@end table
22898
22899@node Register Packet Format
22900@section Register Packet Format
eb12ee30 22901
8e04817f 22902The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22903In the below, some thirty-two bit registers are transferred as
22904sixty-four bits. Those registers should be zero/sign extended (which?)
22905to fill the space allocated. Register bytes are transfered in target
22906byte order. The two nibbles within a register byte are transfered
22907most-significant - least-significant.
eb12ee30 22908
ee2d5c50 22909@table @r
eb12ee30 22910
8e04817f 22911@item MIPS32
ee2d5c50 22912
8e04817f
AC
22913All registers are transfered as thirty-two bit quantities in the order:
2291432 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22915registers; fsr; fir; fp.
eb12ee30 22916
8e04817f 22917@item MIPS64
ee2d5c50 22918
8e04817f
AC
22919All registers are transfered as sixty-four bit quantities (including
22920thirty-two bit registers such as @code{sr}). The ordering is the same
22921as @code{MIPS32}.
eb12ee30 22922
ee2d5c50
AC
22923@end table
22924
22925@node Examples
22926@section Examples
eb12ee30 22927
8e04817f
AC
22928Example sequence of a target being re-started. Notice how the restart
22929does not get any direct output:
eb12ee30 22930
474c8240 22931@smallexample
d2c6833e
AC
22932-> @code{R00}
22933<- @code{+}
8e04817f 22934@emph{target restarts}
d2c6833e 22935-> @code{?}
8e04817f 22936<- @code{+}
d2c6833e
AC
22937<- @code{T001:1234123412341234}
22938-> @code{+}
474c8240 22939@end smallexample
eb12ee30 22940
8e04817f 22941Example sequence of a target being stepped by a single instruction:
eb12ee30 22942
474c8240 22943@smallexample
d2c6833e 22944-> @code{G1445@dots{}}
8e04817f 22945<- @code{+}
d2c6833e
AC
22946-> @code{s}
22947<- @code{+}
22948@emph{time passes}
22949<- @code{T001:1234123412341234}
8e04817f 22950-> @code{+}
d2c6833e 22951-> @code{g}
8e04817f 22952<- @code{+}
d2c6833e
AC
22953<- @code{1455@dots{}}
22954-> @code{+}
474c8240 22955@end smallexample
eb12ee30 22956
0ce1b118
CV
22957@node File-I/O remote protocol extension
22958@section File-I/O remote protocol extension
22959@cindex File-I/O remote protocol extension
22960
22961@menu
22962* File-I/O Overview::
22963* Protocol basics::
1d8b2f28
JB
22964* The F request packet::
22965* The F reply packet::
0ce1b118
CV
22966* Memory transfer::
22967* The Ctrl-C message::
22968* Console I/O::
22969* The isatty call::
22970* The system call::
22971* List of supported calls::
22972* Protocol specific representation of datatypes::
22973* Constants::
22974* File-I/O Examples::
22975@end menu
22976
22977@node File-I/O Overview
22978@subsection File-I/O Overview
22979@cindex file-i/o overview
22980
9c16f35a
EZ
22981The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
22982target to use the host's file system and console I/O when calling various
0ce1b118
CV
22983system calls. System calls on the target system are translated into a
22984remote protocol packet to the host system which then performs the needed
22985actions and returns with an adequate response packet to the target system.
22986This simulates file system operations even on targets that lack file systems.
22987
22988The protocol is defined host- and target-system independent. It uses
9c16f35a 22989its own independent representation of datatypes and values. Both,
0ce1b118
CV
22990@value{GDBN} and the target's @value{GDBN} stub are responsible for
22991translating the system dependent values into the unified protocol values
22992when data is transmitted.
22993
22994The communication is synchronous. A system call is possible only
22995when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
22996packets. While @value{GDBN} handles the request for a system call,
22997the target is stopped to allow deterministic access to the target's
22998memory. Therefore File-I/O is not interuptible by target signals. It
22999is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23000
23001The target's request to perform a host system call does not finish
23002the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23003after finishing the system call, the target returns to continuing the
23004previous activity (continue, step). No additional continue or step
23005request from @value{GDBN} is required.
23006
23007@smallexample
f7dc1244 23008(@value{GDBP}) continue
0ce1b118
CV
23009 <- target requests 'system call X'
23010 target is stopped, @value{GDBN} executes system call
23011 -> GDB returns result
23012 ... target continues, GDB returns to wait for the target
23013 <- target hits breakpoint and sends a Txx packet
23014@end smallexample
23015
23016The protocol is only used for files on the host file system and
23017for I/O on the console. Character or block special devices, pipes,
23018named pipes or sockets or any other communication method on the host
23019system are not supported by this protocol.
23020
23021@node Protocol basics
23022@subsection Protocol basics
23023@cindex protocol basics, file-i/o
23024
23025The File-I/O protocol uses the @code{F} packet, as request as well
23026as as reply packet. Since a File-I/O system call can only occur when
b383017d 23027@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23028File-I/O request is a reply that @value{GDBN} has to expect as a result
23029of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23030This @code{F} packet contains all information needed to allow @value{GDBN}
23031to call the appropriate host system call:
23032
23033@itemize @bullet
b383017d 23034@item
0ce1b118
CV
23035A unique identifier for the requested system call.
23036
23037@item
23038All parameters to the system call. Pointers are given as addresses
23039in the target memory address space. Pointers to strings are given as
b383017d 23040pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23041Numerical control values are given in a protocol specific representation.
23042
23043@end itemize
23044
23045At that point @value{GDBN} has to perform the following actions.
23046
23047@itemize @bullet
b383017d 23048@item
0ce1b118
CV
23049If parameter pointer values are given, which point to data needed as input
23050to a system call, @value{GDBN} requests this data from the target with a
23051standard @code{m} packet request. This additional communication has to be
23052expected by the target implementation and is handled as any other @code{m}
23053packet.
23054
23055@item
23056@value{GDBN} translates all value from protocol representation to host
23057representation as needed. Datatypes are coerced into the host types.
23058
23059@item
23060@value{GDBN} calls the system call
23061
23062@item
23063It then coerces datatypes back to protocol representation.
23064
23065@item
23066If pointer parameters in the request packet point to buffer space in which
23067a system call is expected to copy data to, the data is transmitted to the
23068target using a @code{M} or @code{X} packet. This packet has to be expected
23069by the target implementation and is handled as any other @code{M} or @code{X}
23070packet.
23071
23072@end itemize
23073
23074Eventually @value{GDBN} replies with another @code{F} packet which contains all
23075necessary information for the target to continue. This at least contains
23076
23077@itemize @bullet
23078@item
23079Return value.
23080
23081@item
23082@code{errno}, if has been changed by the system call.
23083
23084@item
23085``Ctrl-C'' flag.
23086
23087@end itemize
23088
23089After having done the needed type and value coercion, the target continues
23090the latest continue or step action.
23091
1d8b2f28 23092@node The F request packet
0ce1b118
CV
23093@subsection The @code{F} request packet
23094@cindex file-i/o request packet
23095@cindex @code{F} request packet
23096
23097The @code{F} request packet has the following format:
23098
23099@table @samp
23100
23101@smallexample
23102@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23103@end smallexample
23104
23105@var{call-id} is the identifier to indicate the host system call to be called.
23106This is just the name of the function.
23107
23108@var{parameter@dots{}} are the parameters to the system call.
23109
b383017d 23110@end table
0ce1b118
CV
23111
23112Parameters are hexadecimal integer values, either the real values in case
23113of scalar datatypes, as pointers to target buffer space in case of compound
23114datatypes and unspecified memory areas or as pointer/length pairs in case
23115of string parameters. These are appended to the call-id, each separated
23116from its predecessor by a comma. All values are transmitted in ASCII
23117string representation, pointer/length pairs separated by a slash.
23118
1d8b2f28 23119@node The F reply packet
0ce1b118
CV
23120@subsection The @code{F} reply packet
23121@cindex file-i/o reply packet
23122@cindex @code{F} reply packet
23123
23124The @code{F} reply packet has the following format:
23125
23126@table @samp
23127
23128@smallexample
23129@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23130@end smallexample
23131
23132@var{retcode} is the return code of the system call as hexadecimal value.
23133
23134@var{errno} is the errno set by the call, in protocol specific representation.
23135This parameter can be omitted if the call was successful.
23136
23137@var{Ctrl-C flag} is only send if the user requested a break. In this
23138case, @var{errno} must be send as well, even if the call was successful.
23139The @var{Ctrl-C flag} itself consists of the character 'C':
23140
23141@smallexample
23142F0,0,C
23143@end smallexample
23144
23145@noindent
23146or, if the call was interupted before the host call has been performed:
23147
23148@smallexample
23149F-1,4,C
23150@end smallexample
23151
23152@noindent
23153assuming 4 is the protocol specific representation of @code{EINTR}.
23154
23155@end table
23156
23157@node Memory transfer
23158@subsection Memory transfer
23159@cindex memory transfer, in file-i/o protocol
23160
23161Structured data which is transferred using a memory read or write as e.g.@:
23162a @code{struct stat} is expected to be in a protocol specific format with
23163all scalar multibyte datatypes being big endian. This should be done by
23164the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23165it transfers memory to the target. Transferred pointers to structured
23166data should point to the already coerced data at any time.
23167
23168@node The Ctrl-C message
23169@subsection The Ctrl-C message
23170@cindex ctrl-c message, in file-i/o protocol
23171
23172A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23173reply packet. In this case the target should behave, as if it had
23174gotten a break message. The meaning for the target is ``system call
23175interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23176(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23177packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23178state the system call was interrupted. Since this action is by design
23179not an atomic operation, we have to differ between two cases:
23180
23181@itemize @bullet
23182@item
23183The system call hasn't been performed on the host yet.
23184
23185@item
23186The system call on the host has been finished.
23187
23188@end itemize
23189
23190These two states can be distinguished by the target by the value of the
23191returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23192call hasn't been performed. This is equivalent to the @code{EINTR} handling
23193on POSIX systems. In any other case, the target may presume that the
23194system call has been finished --- successful or not --- and should behave
23195as if the break message arrived right after the system call.
23196
23197@value{GDBN} must behave reliable. If the system call has not been called
23198yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23199@code{errno} in the packet. If the system call on the host has been finished
23200before the user requests a break, the full action must be finshed by
23201@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23202The @code{F} packet may only be send when either nothing has happened
23203or the full action has been completed.
23204
23205@node Console I/O
23206@subsection Console I/O
23207@cindex console i/o as part of file-i/o
23208
23209By default and if not explicitely closed by the target system, the file
23210descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23211on the @value{GDBN} console is handled as any other file output operation
23212(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23213by @value{GDBN} so that after the target read request from file descriptor
232140 all following typing is buffered until either one of the following
23215conditions is met:
23216
23217@itemize @bullet
23218@item
23219The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23220@code{read}
23221system call is treated as finished.
23222
23223@item
23224The user presses @kbd{Enter}. This is treated as end of input with a trailing
23225line feed.
23226
23227@item
23228The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23229character, especially no Ctrl-D is appended to the input.
23230
23231@end itemize
23232
23233If the user has typed more characters as fit in the buffer given to
23234the read call, the trailing characters are buffered in @value{GDBN} until
23235either another @code{read(0, @dots{})} is requested by the target or debugging
23236is stopped on users request.
23237
23238@node The isatty call
2eecc4ab 23239@subsection The @samp{isatty} function call
0ce1b118
CV
23240@cindex isatty call, file-i/o protocol
23241
23242A special case in this protocol is the library call @code{isatty} which
9c16f35a 23243is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
232441 to the target if the file descriptor given as parameter is attached
23245to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23246would require implementing @code{ioctl} and would be more complex than
23247needed.
23248
23249@node The system call
2eecc4ab 23250@subsection The @samp{system} function call
0ce1b118
CV
23251@cindex system call, file-i/o protocol
23252
23253The other special case in this protocol is the @code{system} call which
9c16f35a 23254is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23255task of calling the necessary host calls to perform the @code{system}
23256call. The return value of @code{system} is simplified before it's returned
23257to the target. Basically, the only signal transmitted back is @code{EINTR}
23258in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23259entirely of the exit status of the called command.
23260
9c16f35a
EZ
23261Due to security concerns, the @code{system} call is by default refused
23262by @value{GDBN}. The user has to allow this call explicitly with the
23263@kbd{set remote system-call-allowed 1} command.
0ce1b118 23264
9c16f35a
EZ
23265@table @code
23266@item set remote system-call-allowed
23267@kindex set remote system-call-allowed
23268Control whether to allow the @code{system} calls in the File I/O
23269protocol for the remote target. The default is zero (disabled).
0ce1b118 23270
9c16f35a 23271@item show remote system-call-allowed
0ce1b118 23272@kindex show remote system-call-allowed
9c16f35a
EZ
23273Show the current setting of system calls for the remote File I/O
23274protocol.
0ce1b118
CV
23275@end table
23276
23277@node List of supported calls
23278@subsection List of supported calls
23279@cindex list of supported file-i/o calls
23280
23281@menu
23282* open::
23283* close::
23284* read::
23285* write::
23286* lseek::
23287* rename::
23288* unlink::
23289* stat/fstat::
23290* gettimeofday::
23291* isatty::
23292* system::
23293@end menu
23294
23295@node open
23296@unnumberedsubsubsec open
23297@cindex open, file-i/o system call
23298
23299@smallexample
23300@exdent Synopsis:
23301int open(const char *pathname, int flags);
23302int open(const char *pathname, int flags, mode_t mode);
23303
b383017d 23304@exdent Request:
0ce1b118
CV
23305Fopen,pathptr/len,flags,mode
23306@end smallexample
23307
23308@noindent
23309@code{flags} is the bitwise or of the following values:
23310
23311@table @code
b383017d 23312@item O_CREAT
0ce1b118
CV
23313If the file does not exist it will be created. The host
23314rules apply as far as file ownership and time stamps
23315are concerned.
23316
b383017d 23317@item O_EXCL
0ce1b118
CV
23318When used with O_CREAT, if the file already exists it is
23319an error and open() fails.
23320
b383017d 23321@item O_TRUNC
0ce1b118
CV
23322If the file already exists and the open mode allows
23323writing (O_RDWR or O_WRONLY is given) it will be
23324truncated to length 0.
23325
b383017d 23326@item O_APPEND
0ce1b118
CV
23327The file is opened in append mode.
23328
b383017d 23329@item O_RDONLY
0ce1b118
CV
23330The file is opened for reading only.
23331
b383017d 23332@item O_WRONLY
0ce1b118
CV
23333The file is opened for writing only.
23334
b383017d 23335@item O_RDWR
0ce1b118
CV
23336The file is opened for reading and writing.
23337
23338@noindent
23339Each other bit is silently ignored.
23340
23341@end table
23342
23343@noindent
23344@code{mode} is the bitwise or of the following values:
23345
23346@table @code
b383017d 23347@item S_IRUSR
0ce1b118
CV
23348User has read permission.
23349
b383017d 23350@item S_IWUSR
0ce1b118
CV
23351User has write permission.
23352
b383017d 23353@item S_IRGRP
0ce1b118
CV
23354Group has read permission.
23355
b383017d 23356@item S_IWGRP
0ce1b118
CV
23357Group has write permission.
23358
b383017d 23359@item S_IROTH
0ce1b118
CV
23360Others have read permission.
23361
b383017d 23362@item S_IWOTH
0ce1b118
CV
23363Others have write permission.
23364
23365@noindent
23366Each other bit is silently ignored.
23367
23368@end table
23369
23370@smallexample
23371@exdent Return value:
23372open returns the new file descriptor or -1 if an error
23373occured.
23374
23375@exdent Errors:
23376@end smallexample
23377
23378@table @code
b383017d 23379@item EEXIST
0ce1b118
CV
23380pathname already exists and O_CREAT and O_EXCL were used.
23381
b383017d 23382@item EISDIR
0ce1b118
CV
23383pathname refers to a directory.
23384
b383017d 23385@item EACCES
0ce1b118
CV
23386The requested access is not allowed.
23387
23388@item ENAMETOOLONG
23389pathname was too long.
23390
b383017d 23391@item ENOENT
0ce1b118
CV
23392A directory component in pathname does not exist.
23393
b383017d 23394@item ENODEV
0ce1b118
CV
23395pathname refers to a device, pipe, named pipe or socket.
23396
b383017d 23397@item EROFS
0ce1b118
CV
23398pathname refers to a file on a read-only filesystem and
23399write access was requested.
23400
b383017d 23401@item EFAULT
0ce1b118
CV
23402pathname is an invalid pointer value.
23403
b383017d 23404@item ENOSPC
0ce1b118
CV
23405No space on device to create the file.
23406
b383017d 23407@item EMFILE
0ce1b118
CV
23408The process already has the maximum number of files open.
23409
b383017d 23410@item ENFILE
0ce1b118
CV
23411The limit on the total number of files open on the system
23412has been reached.
23413
b383017d 23414@item EINTR
0ce1b118
CV
23415The call was interrupted by the user.
23416@end table
23417
23418@node close
23419@unnumberedsubsubsec close
23420@cindex close, file-i/o system call
23421
23422@smallexample
b383017d 23423@exdent Synopsis:
0ce1b118
CV
23424int close(int fd);
23425
b383017d 23426@exdent Request:
0ce1b118
CV
23427Fclose,fd
23428
23429@exdent Return value:
23430close returns zero on success, or -1 if an error occurred.
23431
23432@exdent Errors:
23433@end smallexample
23434
23435@table @code
b383017d 23436@item EBADF
0ce1b118
CV
23437fd isn't a valid open file descriptor.
23438
b383017d 23439@item EINTR
0ce1b118
CV
23440The call was interrupted by the user.
23441@end table
23442
23443@node read
23444@unnumberedsubsubsec read
23445@cindex read, file-i/o system call
23446
23447@smallexample
b383017d 23448@exdent Synopsis:
0ce1b118
CV
23449int read(int fd, void *buf, unsigned int count);
23450
b383017d 23451@exdent Request:
0ce1b118
CV
23452Fread,fd,bufptr,count
23453
23454@exdent Return value:
23455On success, the number of bytes read is returned.
23456Zero indicates end of file. If count is zero, read
b383017d 23457returns zero as well. On error, -1 is returned.
0ce1b118
CV
23458
23459@exdent Errors:
23460@end smallexample
23461
23462@table @code
b383017d 23463@item EBADF
0ce1b118
CV
23464fd is not a valid file descriptor or is not open for
23465reading.
23466
b383017d 23467@item EFAULT
0ce1b118
CV
23468buf is an invalid pointer value.
23469
b383017d 23470@item EINTR
0ce1b118
CV
23471The call was interrupted by the user.
23472@end table
23473
23474@node write
23475@unnumberedsubsubsec write
23476@cindex write, file-i/o system call
23477
23478@smallexample
b383017d 23479@exdent Synopsis:
0ce1b118
CV
23480int write(int fd, const void *buf, unsigned int count);
23481
b383017d 23482@exdent Request:
0ce1b118
CV
23483Fwrite,fd,bufptr,count
23484
23485@exdent Return value:
23486On success, the number of bytes written are returned.
23487Zero indicates nothing was written. On error, -1
23488is returned.
23489
23490@exdent Errors:
23491@end smallexample
23492
23493@table @code
b383017d 23494@item EBADF
0ce1b118
CV
23495fd is not a valid file descriptor or is not open for
23496writing.
23497
b383017d 23498@item EFAULT
0ce1b118
CV
23499buf is an invalid pointer value.
23500
b383017d 23501@item EFBIG
0ce1b118
CV
23502An attempt was made to write a file that exceeds the
23503host specific maximum file size allowed.
23504
b383017d 23505@item ENOSPC
0ce1b118
CV
23506No space on device to write the data.
23507
b383017d 23508@item EINTR
0ce1b118
CV
23509The call was interrupted by the user.
23510@end table
23511
23512@node lseek
23513@unnumberedsubsubsec lseek
23514@cindex lseek, file-i/o system call
23515
23516@smallexample
b383017d 23517@exdent Synopsis:
0ce1b118
CV
23518long lseek (int fd, long offset, int flag);
23519
b383017d 23520@exdent Request:
0ce1b118
CV
23521Flseek,fd,offset,flag
23522@end smallexample
23523
23524@code{flag} is one of:
23525
23526@table @code
b383017d 23527@item SEEK_SET
0ce1b118
CV
23528The offset is set to offset bytes.
23529
b383017d 23530@item SEEK_CUR
0ce1b118
CV
23531The offset is set to its current location plus offset
23532bytes.
23533
b383017d 23534@item SEEK_END
0ce1b118
CV
23535The offset is set to the size of the file plus offset
23536bytes.
23537@end table
23538
23539@smallexample
23540@exdent Return value:
23541On success, the resulting unsigned offset in bytes from
23542the beginning of the file is returned. Otherwise, a
23543value of -1 is returned.
23544
23545@exdent Errors:
23546@end smallexample
23547
23548@table @code
b383017d 23549@item EBADF
0ce1b118
CV
23550fd is not a valid open file descriptor.
23551
b383017d 23552@item ESPIPE
0ce1b118
CV
23553fd is associated with the @value{GDBN} console.
23554
b383017d 23555@item EINVAL
0ce1b118
CV
23556flag is not a proper value.
23557
b383017d 23558@item EINTR
0ce1b118
CV
23559The call was interrupted by the user.
23560@end table
23561
23562@node rename
23563@unnumberedsubsubsec rename
23564@cindex rename, file-i/o system call
23565
23566@smallexample
b383017d 23567@exdent Synopsis:
0ce1b118
CV
23568int rename(const char *oldpath, const char *newpath);
23569
b383017d 23570@exdent Request:
0ce1b118
CV
23571Frename,oldpathptr/len,newpathptr/len
23572
23573@exdent Return value:
23574On success, zero is returned. On error, -1 is returned.
23575
23576@exdent Errors:
23577@end smallexample
23578
23579@table @code
b383017d 23580@item EISDIR
0ce1b118
CV
23581newpath is an existing directory, but oldpath is not a
23582directory.
23583
b383017d 23584@item EEXIST
0ce1b118
CV
23585newpath is a non-empty directory.
23586
b383017d 23587@item EBUSY
0ce1b118
CV
23588oldpath or newpath is a directory that is in use by some
23589process.
23590
b383017d 23591@item EINVAL
0ce1b118
CV
23592An attempt was made to make a directory a subdirectory
23593of itself.
23594
b383017d 23595@item ENOTDIR
0ce1b118
CV
23596A component used as a directory in oldpath or new
23597path is not a directory. Or oldpath is a directory
23598and newpath exists but is not a directory.
23599
b383017d 23600@item EFAULT
0ce1b118
CV
23601oldpathptr or newpathptr are invalid pointer values.
23602
b383017d 23603@item EACCES
0ce1b118
CV
23604No access to the file or the path of the file.
23605
23606@item ENAMETOOLONG
b383017d 23607
0ce1b118
CV
23608oldpath or newpath was too long.
23609
b383017d 23610@item ENOENT
0ce1b118
CV
23611A directory component in oldpath or newpath does not exist.
23612
b383017d 23613@item EROFS
0ce1b118
CV
23614The file is on a read-only filesystem.
23615
b383017d 23616@item ENOSPC
0ce1b118
CV
23617The device containing the file has no room for the new
23618directory entry.
23619
b383017d 23620@item EINTR
0ce1b118
CV
23621The call was interrupted by the user.
23622@end table
23623
23624@node unlink
23625@unnumberedsubsubsec unlink
23626@cindex unlink, file-i/o system call
23627
23628@smallexample
b383017d 23629@exdent Synopsis:
0ce1b118
CV
23630int unlink(const char *pathname);
23631
b383017d 23632@exdent Request:
0ce1b118
CV
23633Funlink,pathnameptr/len
23634
23635@exdent Return value:
23636On success, zero is returned. On error, -1 is returned.
23637
23638@exdent Errors:
23639@end smallexample
23640
23641@table @code
b383017d 23642@item EACCES
0ce1b118
CV
23643No access to the file or the path of the file.
23644
b383017d 23645@item EPERM
0ce1b118
CV
23646The system does not allow unlinking of directories.
23647
b383017d 23648@item EBUSY
0ce1b118
CV
23649The file pathname cannot be unlinked because it's
23650being used by another process.
23651
b383017d 23652@item EFAULT
0ce1b118
CV
23653pathnameptr is an invalid pointer value.
23654
23655@item ENAMETOOLONG
23656pathname was too long.
23657
b383017d 23658@item ENOENT
0ce1b118
CV
23659A directory component in pathname does not exist.
23660
b383017d 23661@item ENOTDIR
0ce1b118
CV
23662A component of the path is not a directory.
23663
b383017d 23664@item EROFS
0ce1b118
CV
23665The file is on a read-only filesystem.
23666
b383017d 23667@item EINTR
0ce1b118
CV
23668The call was interrupted by the user.
23669@end table
23670
23671@node stat/fstat
23672@unnumberedsubsubsec stat/fstat
23673@cindex fstat, file-i/o system call
23674@cindex stat, file-i/o system call
23675
23676@smallexample
b383017d 23677@exdent Synopsis:
0ce1b118
CV
23678int stat(const char *pathname, struct stat *buf);
23679int fstat(int fd, struct stat *buf);
23680
b383017d 23681@exdent Request:
0ce1b118
CV
23682Fstat,pathnameptr/len,bufptr
23683Ffstat,fd,bufptr
23684
23685@exdent Return value:
23686On success, zero is returned. On error, -1 is returned.
23687
23688@exdent Errors:
23689@end smallexample
23690
23691@table @code
b383017d 23692@item EBADF
0ce1b118
CV
23693fd is not a valid open file.
23694
b383017d 23695@item ENOENT
0ce1b118
CV
23696A directory component in pathname does not exist or the
23697path is an empty string.
23698
b383017d 23699@item ENOTDIR
0ce1b118
CV
23700A component of the path is not a directory.
23701
b383017d 23702@item EFAULT
0ce1b118
CV
23703pathnameptr is an invalid pointer value.
23704
b383017d 23705@item EACCES
0ce1b118
CV
23706No access to the file or the path of the file.
23707
23708@item ENAMETOOLONG
23709pathname was too long.
23710
b383017d 23711@item EINTR
0ce1b118
CV
23712The call was interrupted by the user.
23713@end table
23714
23715@node gettimeofday
23716@unnumberedsubsubsec gettimeofday
23717@cindex gettimeofday, file-i/o system call
23718
23719@smallexample
b383017d 23720@exdent Synopsis:
0ce1b118
CV
23721int gettimeofday(struct timeval *tv, void *tz);
23722
b383017d 23723@exdent Request:
0ce1b118
CV
23724Fgettimeofday,tvptr,tzptr
23725
23726@exdent Return value:
23727On success, 0 is returned, -1 otherwise.
23728
23729@exdent Errors:
23730@end smallexample
23731
23732@table @code
b383017d 23733@item EINVAL
0ce1b118
CV
23734tz is a non-NULL pointer.
23735
b383017d 23736@item EFAULT
0ce1b118
CV
23737tvptr and/or tzptr is an invalid pointer value.
23738@end table
23739
23740@node isatty
23741@unnumberedsubsubsec isatty
23742@cindex isatty, file-i/o system call
23743
23744@smallexample
b383017d 23745@exdent Synopsis:
0ce1b118
CV
23746int isatty(int fd);
23747
b383017d 23748@exdent Request:
0ce1b118
CV
23749Fisatty,fd
23750
23751@exdent Return value:
23752Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23753
23754@exdent Errors:
23755@end smallexample
23756
23757@table @code
b383017d 23758@item EINTR
0ce1b118
CV
23759The call was interrupted by the user.
23760@end table
23761
23762@node system
23763@unnumberedsubsubsec system
23764@cindex system, file-i/o system call
23765
23766@smallexample
b383017d 23767@exdent Synopsis:
0ce1b118
CV
23768int system(const char *command);
23769
b383017d 23770@exdent Request:
0ce1b118
CV
23771Fsystem,commandptr/len
23772
23773@exdent Return value:
23774The value returned is -1 on error and the return status
23775of the command otherwise. Only the exit status of the
23776command is returned, which is extracted from the hosts
23777system return value by calling WEXITSTATUS(retval).
23778In case /bin/sh could not be executed, 127 is returned.
23779
23780@exdent Errors:
23781@end smallexample
23782
23783@table @code
b383017d 23784@item EINTR
0ce1b118
CV
23785The call was interrupted by the user.
23786@end table
23787
23788@node Protocol specific representation of datatypes
23789@subsection Protocol specific representation of datatypes
23790@cindex protocol specific representation of datatypes, in file-i/o protocol
23791
23792@menu
23793* Integral datatypes::
23794* Pointer values::
23795* struct stat::
23796* struct timeval::
23797@end menu
23798
23799@node Integral datatypes
23800@unnumberedsubsubsec Integral datatypes
23801@cindex integral datatypes, in file-i/o protocol
23802
23803The integral datatypes used in the system calls are
23804
23805@smallexample
23806int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23807@end smallexample
23808
23809@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23810implemented as 32 bit values in this protocol.
23811
b383017d
RM
23812@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23813
0ce1b118
CV
23814@xref{Limits}, for corresponding MIN and MAX values (similar to those
23815in @file{limits.h}) to allow range checking on host and target.
23816
23817@code{time_t} datatypes are defined as seconds since the Epoch.
23818
23819All integral datatypes transferred as part of a memory read or write of a
23820structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23821byte order.
23822
23823@node Pointer values
23824@unnumberedsubsubsec Pointer values
23825@cindex pointer values, in file-i/o protocol
23826
23827Pointers to target data are transmitted as they are. An exception
23828is made for pointers to buffers for which the length isn't
23829transmitted as part of the function call, namely strings. Strings
23830are transmitted as a pointer/length pair, both as hex values, e.g.@:
23831
23832@smallexample
23833@code{1aaf/12}
23834@end smallexample
23835
23836@noindent
23837which is a pointer to data of length 18 bytes at position 0x1aaf.
23838The length is defined as the full string length in bytes, including
23839the trailing null byte. Example:
23840
23841@smallexample
23842``hello, world'' at address 0x123456
23843@end smallexample
23844
23845@noindent
23846is transmitted as
23847
23848@smallexample
23849@code{123456/d}
23850@end smallexample
23851
23852@node struct stat
23853@unnumberedsubsubsec struct stat
23854@cindex struct stat, in file-i/o protocol
23855
23856The buffer of type struct stat used by the target and @value{GDBN} is defined
23857as follows:
23858
23859@smallexample
23860struct stat @{
23861 unsigned int st_dev; /* device */
23862 unsigned int st_ino; /* inode */
23863 mode_t st_mode; /* protection */
23864 unsigned int st_nlink; /* number of hard links */
23865 unsigned int st_uid; /* user ID of owner */
23866 unsigned int st_gid; /* group ID of owner */
23867 unsigned int st_rdev; /* device type (if inode device) */
23868 unsigned long st_size; /* total size, in bytes */
23869 unsigned long st_blksize; /* blocksize for filesystem I/O */
23870 unsigned long st_blocks; /* number of blocks allocated */
23871 time_t st_atime; /* time of last access */
23872 time_t st_mtime; /* time of last modification */
23873 time_t st_ctime; /* time of last change */
23874@};
23875@end smallexample
23876
23877The integral datatypes are conforming to the definitions given in the
23878approriate section (see @ref{Integral datatypes}, for details) so this
23879structure is of size 64 bytes.
23880
23881The values of several fields have a restricted meaning and/or
23882range of values.
23883
23884@smallexample
23885st_dev: 0 file
23886 1 console
23887
23888st_ino: No valid meaning for the target. Transmitted unchanged.
23889
23890st_mode: Valid mode bits are described in Appendix C. Any other
23891 bits have currently no meaning for the target.
23892
23893st_uid: No valid meaning for the target. Transmitted unchanged.
23894
23895st_gid: No valid meaning for the target. Transmitted unchanged.
23896
23897st_rdev: No valid meaning for the target. Transmitted unchanged.
23898
23899st_atime, st_mtime, st_ctime:
23900 These values have a host and file system dependent
23901 accuracy. Especially on Windows hosts the file systems
23902 don't support exact timing values.
23903@end smallexample
23904
23905The target gets a struct stat of the above representation and is
23906responsible to coerce it to the target representation before
23907continuing.
23908
23909Note that due to size differences between the host and target
23910representation of stat members, these members could eventually
23911get truncated on the target.
23912
23913@node struct timeval
23914@unnumberedsubsubsec struct timeval
23915@cindex struct timeval, in file-i/o protocol
23916
23917The buffer of type struct timeval used by the target and @value{GDBN}
23918is defined as follows:
23919
23920@smallexample
b383017d 23921struct timeval @{
0ce1b118
CV
23922 time_t tv_sec; /* second */
23923 long tv_usec; /* microsecond */
23924@};
23925@end smallexample
23926
23927The integral datatypes are conforming to the definitions given in the
23928approriate section (see @ref{Integral datatypes}, for details) so this
23929structure is of size 8 bytes.
23930
23931@node Constants
23932@subsection Constants
23933@cindex constants, in file-i/o protocol
23934
23935The following values are used for the constants inside of the
23936protocol. @value{GDBN} and target are resposible to translate these
23937values before and after the call as needed.
23938
23939@menu
23940* Open flags::
23941* mode_t values::
23942* Errno values::
23943* Lseek flags::
23944* Limits::
23945@end menu
23946
23947@node Open flags
23948@unnumberedsubsubsec Open flags
23949@cindex open flags, in file-i/o protocol
23950
23951All values are given in hexadecimal representation.
23952
23953@smallexample
23954 O_RDONLY 0x0
23955 O_WRONLY 0x1
23956 O_RDWR 0x2
23957 O_APPEND 0x8
23958 O_CREAT 0x200
23959 O_TRUNC 0x400
23960 O_EXCL 0x800
23961@end smallexample
23962
23963@node mode_t values
23964@unnumberedsubsubsec mode_t values
23965@cindex mode_t values, in file-i/o protocol
23966
23967All values are given in octal representation.
23968
23969@smallexample
23970 S_IFREG 0100000
23971 S_IFDIR 040000
23972 S_IRUSR 0400
23973 S_IWUSR 0200
23974 S_IXUSR 0100
23975 S_IRGRP 040
23976 S_IWGRP 020
23977 S_IXGRP 010
23978 S_IROTH 04
23979 S_IWOTH 02
23980 S_IXOTH 01
23981@end smallexample
23982
23983@node Errno values
23984@unnumberedsubsubsec Errno values
23985@cindex errno values, in file-i/o protocol
23986
23987All values are given in decimal representation.
23988
23989@smallexample
23990 EPERM 1
23991 ENOENT 2
23992 EINTR 4
23993 EBADF 9
23994 EACCES 13
23995 EFAULT 14
23996 EBUSY 16
23997 EEXIST 17
23998 ENODEV 19
23999 ENOTDIR 20
24000 EISDIR 21
24001 EINVAL 22
24002 ENFILE 23
24003 EMFILE 24
24004 EFBIG 27
24005 ENOSPC 28
24006 ESPIPE 29
24007 EROFS 30
24008 ENAMETOOLONG 91
24009 EUNKNOWN 9999
24010@end smallexample
24011
24012 EUNKNOWN is used as a fallback error value if a host system returns
24013 any error value not in the list of supported error numbers.
24014
24015@node Lseek flags
24016@unnumberedsubsubsec Lseek flags
24017@cindex lseek flags, in file-i/o protocol
24018
24019@smallexample
24020 SEEK_SET 0
24021 SEEK_CUR 1
24022 SEEK_END 2
24023@end smallexample
24024
24025@node Limits
24026@unnumberedsubsubsec Limits
24027@cindex limits, in file-i/o protocol
24028
24029All values are given in decimal representation.
24030
24031@smallexample
24032 INT_MIN -2147483648
24033 INT_MAX 2147483647
24034 UINT_MAX 4294967295
24035 LONG_MIN -9223372036854775808
24036 LONG_MAX 9223372036854775807
24037 ULONG_MAX 18446744073709551615
24038@end smallexample
24039
24040@node File-I/O Examples
24041@subsection File-I/O Examples
24042@cindex file-i/o examples
24043
24044Example sequence of a write call, file descriptor 3, buffer is at target
24045address 0x1234, 6 bytes should be written:
24046
24047@smallexample
24048<- @code{Fwrite,3,1234,6}
24049@emph{request memory read from target}
24050-> @code{m1234,6}
24051<- XXXXXX
24052@emph{return "6 bytes written"}
24053-> @code{F6}
24054@end smallexample
24055
24056Example sequence of a read call, file descriptor 3, buffer is at target
24057address 0x1234, 6 bytes should be read:
24058
24059@smallexample
24060<- @code{Fread,3,1234,6}
24061@emph{request memory write to target}
24062-> @code{X1234,6:XXXXXX}
24063@emph{return "6 bytes read"}
24064-> @code{F6}
24065@end smallexample
24066
24067Example sequence of a read call, call fails on the host due to invalid
24068file descriptor (EBADF):
24069
24070@smallexample
24071<- @code{Fread,3,1234,6}
24072-> @code{F-1,9}
24073@end smallexample
24074
24075Example sequence of a read call, user presses Ctrl-C before syscall on
24076host is called:
24077
24078@smallexample
24079<- @code{Fread,3,1234,6}
24080-> @code{F-1,4,C}
24081<- @code{T02}
24082@end smallexample
24083
24084Example sequence of a read call, user presses Ctrl-C after syscall on
24085host is called:
24086
24087@smallexample
24088<- @code{Fread,3,1234,6}
24089-> @code{X1234,6:XXXXXX}
24090<- @code{T02}
24091@end smallexample
24092
f418dd93
DJ
24093@include agentexpr.texi
24094
aab4e0ec 24095@include gpl.texi
eb12ee30 24096
2154891a 24097@raisesections
6826cf00 24098@include fdl.texi
2154891a 24099@lowersections
6826cf00 24100
6d2ebf8b 24101@node Index
c906108c
SS
24102@unnumbered Index
24103
24104@printindex cp
24105
24106@tex
24107% I think something like @colophon should be in texinfo. In the
24108% meantime:
24109\long\def\colophon{\hbox to0pt{}\vfill
24110\centerline{The body of this manual is set in}
24111\centerline{\fontname\tenrm,}
24112\centerline{with headings in {\bf\fontname\tenbf}}
24113\centerline{and examples in {\tt\fontname\tentt}.}
24114\centerline{{\it\fontname\tenit\/},}
24115\centerline{{\bf\fontname\tenbf}, and}
24116\centerline{{\sl\fontname\tensl\/}}
24117\centerline{are used for emphasis.}\vfill}
24118\page\colophon
24119% Blame: doc@cygnus.com, 1991.
24120@end tex
24121
c906108c 24122@bye
This page took 1.820831 seconds and 4 git commands to generate.