]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/doc/gdb.texinfo
2005-07-06 H.J. Lu <hongjiu.lu@intel.com>
[thirdparty/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
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
a9967aef
AC
480Andrew Cagney designed @value{GDBN}'s architecture vector. Many
481people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
482Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
483Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
484Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
485with the migration of old architectures to this new framework.
486
6d2ebf8b 487@node Sample Session
c906108c
SS
488@chapter A Sample @value{GDBN} Session
489
490You can use this manual at your leisure to read all about @value{GDBN}.
491However, a handful of commands are enough to get started using the
492debugger. This chapter illustrates those commands.
493
494@iftex
495In this sample session, we emphasize user input like this: @b{input},
496to make it easier to pick out from the surrounding output.
497@end iftex
498
499@c FIXME: this example may not be appropriate for some configs, where
500@c FIXME...primary interest is in remote use.
501
502One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
503processor) exhibits the following bug: sometimes, when we change its
504quote strings from the default, the commands used to capture one macro
505definition within another stop working. In the following short @code{m4}
506session, we define a macro @code{foo} which expands to @code{0000}; we
507then use the @code{m4} built-in @code{defn} to define @code{bar} as the
508same thing. However, when we change the open quote string to
509@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
510procedure fails to define a new synonym @code{baz}:
511
512@smallexample
513$ @b{cd gnu/m4}
514$ @b{./m4}
515@b{define(foo,0000)}
516
517@b{foo}
5180000
519@b{define(bar,defn(`foo'))}
520
521@b{bar}
5220000
523@b{changequote(<QUOTE>,<UNQUOTE>)}
524
525@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
526@b{baz}
527@b{C-d}
528m4: End of input: 0: fatal error: EOF in string
529@end smallexample
530
531@noindent
532Let us use @value{GDBN} to try to see what is going on.
533
c906108c
SS
534@smallexample
535$ @b{@value{GDBP} m4}
536@c FIXME: this falsifies the exact text played out, to permit smallbook
537@c FIXME... format to come out better.
538@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 539 of it under certain conditions; type "show copying" to see
c906108c 540 the conditions.
5d161b24 541There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
542 for details.
543
544@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
545(@value{GDBP})
546@end smallexample
c906108c
SS
547
548@noindent
549@value{GDBN} reads only enough symbol data to know where to find the
550rest when needed; as a result, the first prompt comes up very quickly.
551We now tell @value{GDBN} to use a narrower display width than usual, so
552that examples fit in this manual.
553
554@smallexample
555(@value{GDBP}) @b{set width 70}
556@end smallexample
557
558@noindent
559We need to see how the @code{m4} built-in @code{changequote} works.
560Having looked at the source, we know the relevant subroutine is
561@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
562@code{break} command.
563
564@smallexample
565(@value{GDBP}) @b{break m4_changequote}
566Breakpoint 1 at 0x62f4: file builtin.c, line 879.
567@end smallexample
568
569@noindent
570Using the @code{run} command, we start @code{m4} running under @value{GDBN}
571control; as long as control does not reach the @code{m4_changequote}
572subroutine, the program runs as usual:
573
574@smallexample
575(@value{GDBP}) @b{run}
576Starting program: /work/Editorial/gdb/gnu/m4/m4
577@b{define(foo,0000)}
578
579@b{foo}
5800000
581@end smallexample
582
583@noindent
584To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
585suspends execution of @code{m4}, displaying information about the
586context where it stops.
587
588@smallexample
589@b{changequote(<QUOTE>,<UNQUOTE>)}
590
5d161b24 591Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
592 at builtin.c:879
593879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
594@end smallexample
595
596@noindent
597Now we use the command @code{n} (@code{next}) to advance execution to
598the next line of the current function.
599
600@smallexample
601(@value{GDBP}) @b{n}
602882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
603 : nil,
604@end smallexample
605
606@noindent
607@code{set_quotes} looks like a promising subroutine. We can go into it
608by using the command @code{s} (@code{step}) instead of @code{next}.
609@code{step} goes to the next line to be executed in @emph{any}
610subroutine, so it steps into @code{set_quotes}.
611
612@smallexample
613(@value{GDBP}) @b{s}
614set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
615 at input.c:530
616530 if (lquote != def_lquote)
617@end smallexample
618
619@noindent
620The display that shows the subroutine where @code{m4} is now
621suspended (and its arguments) is called a stack frame display. It
622shows a summary of the stack. We can use the @code{backtrace}
623command (which can also be spelled @code{bt}), to see where we are
624in the stack as a whole: the @code{backtrace} command displays a
625stack frame for each active subroutine.
626
627@smallexample
628(@value{GDBP}) @b{bt}
629#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
630 at input.c:530
5d161b24 631#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
632 at builtin.c:882
633#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
634#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
635 at macro.c:71
636#4 0x79dc in expand_input () at macro.c:40
637#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
638@end smallexample
639
640@noindent
641We step through a few more lines to see what happens. The first two
642times, we can use @samp{s}; the next two times we use @code{n} to avoid
643falling into the @code{xstrdup} subroutine.
644
645@smallexample
646(@value{GDBP}) @b{s}
6470x3b5c 532 if (rquote != def_rquote)
648(@value{GDBP}) @b{s}
6490x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
650def_lquote : xstrdup(lq);
651(@value{GDBP}) @b{n}
652536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
653 : xstrdup(rq);
654(@value{GDBP}) @b{n}
655538 len_lquote = strlen(rquote);
656@end smallexample
657
658@noindent
659The last line displayed looks a little odd; we can examine the variables
660@code{lquote} and @code{rquote} to see if they are in fact the new left
661and right quotes we specified. We use the command @code{p}
662(@code{print}) to see their values.
663
664@smallexample
665(@value{GDBP}) @b{p lquote}
666$1 = 0x35d40 "<QUOTE>"
667(@value{GDBP}) @b{p rquote}
668$2 = 0x35d50 "<UNQUOTE>"
669@end smallexample
670
671@noindent
672@code{lquote} and @code{rquote} are indeed the new left and right quotes.
673To look at some context, we can display ten lines of source
674surrounding the current line with the @code{l} (@code{list}) command.
675
676@smallexample
677(@value{GDBP}) @b{l}
678533 xfree(rquote);
679534
680535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
681 : xstrdup (lq);
682536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
683 : xstrdup (rq);
684537
685538 len_lquote = strlen(rquote);
686539 len_rquote = strlen(lquote);
687540 @}
688541
689542 void
690@end smallexample
691
692@noindent
693Let us step past the two lines that set @code{len_lquote} and
694@code{len_rquote}, and then examine the values of those variables.
695
696@smallexample
697(@value{GDBP}) @b{n}
698539 len_rquote = strlen(lquote);
699(@value{GDBP}) @b{n}
700540 @}
701(@value{GDBP}) @b{p len_lquote}
702$3 = 9
703(@value{GDBP}) @b{p len_rquote}
704$4 = 7
705@end smallexample
706
707@noindent
708That certainly looks wrong, assuming @code{len_lquote} and
709@code{len_rquote} are meant to be the lengths of @code{lquote} and
710@code{rquote} respectively. We can set them to better values using
711the @code{p} command, since it can print the value of
712any expression---and that expression can include subroutine calls and
713assignments.
714
715@smallexample
716(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
717$5 = 7
718(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
719$6 = 9
720@end smallexample
721
722@noindent
723Is that enough to fix the problem of using the new quotes with the
724@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
725executing with the @code{c} (@code{continue}) command, and then try the
726example that caused trouble initially:
727
728@smallexample
729(@value{GDBP}) @b{c}
730Continuing.
731
732@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
733
734baz
7350000
736@end smallexample
737
738@noindent
739Success! The new quotes now work just as well as the default ones. The
740problem seems to have been just the two typos defining the wrong
741lengths. We allow @code{m4} exit by giving it an EOF as input:
742
743@smallexample
744@b{C-d}
745Program exited normally.
746@end smallexample
747
748@noindent
749The message @samp{Program exited normally.} is from @value{GDBN}; it
750indicates @code{m4} has finished executing. We can end our @value{GDBN}
751session with the @value{GDBN} @code{quit} command.
752
753@smallexample
754(@value{GDBP}) @b{quit}
755@end smallexample
c906108c 756
6d2ebf8b 757@node Invocation
c906108c
SS
758@chapter Getting In and Out of @value{GDBN}
759
760This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 761The essentials are:
c906108c 762@itemize @bullet
5d161b24 763@item
53a5351d 764type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 765@item
c906108c
SS
766type @kbd{quit} or @kbd{C-d} to exit.
767@end itemize
768
769@menu
770* Invoking GDB:: How to start @value{GDBN}
771* Quitting GDB:: How to quit @value{GDBN}
772* Shell Commands:: How to use shell commands inside @value{GDBN}
0fac0b41 773* Logging output:: How to log @value{GDBN}'s output to a file
c906108c
SS
774@end menu
775
6d2ebf8b 776@node Invoking GDB
c906108c
SS
777@section Invoking @value{GDBN}
778
c906108c
SS
779Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
780@value{GDBN} reads commands from the terminal until you tell it to exit.
781
782You can also run @code{@value{GDBP}} with a variety of arguments and options,
783to specify more of your debugging environment at the outset.
784
c906108c
SS
785The command-line options described here are designed
786to cover a variety of situations; in some environments, some of these
5d161b24 787options may effectively be unavailable.
c906108c
SS
788
789The most usual way to start @value{GDBN} is with one argument,
790specifying an executable program:
791
474c8240 792@smallexample
c906108c 793@value{GDBP} @var{program}
474c8240 794@end smallexample
c906108c 795
c906108c
SS
796@noindent
797You can also start with both an executable program and a core file
798specified:
799
474c8240 800@smallexample
c906108c 801@value{GDBP} @var{program} @var{core}
474c8240 802@end smallexample
c906108c
SS
803
804You can, instead, specify a process ID as a second argument, if you want
805to debug a running process:
806
474c8240 807@smallexample
c906108c 808@value{GDBP} @var{program} 1234
474c8240 809@end smallexample
c906108c
SS
810
811@noindent
812would attach @value{GDBN} to process @code{1234} (unless you also have a file
813named @file{1234}; @value{GDBN} does check for a core file first).
814
c906108c 815Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
816complete operating system; when you use @value{GDBN} as a remote
817debugger attached to a bare board, there may not be any notion of
818``process'', and there is often no way to get a core dump. @value{GDBN}
819will warn you if it is unable to attach or to read core dumps.
c906108c 820
aa26fa3a
TT
821You can optionally have @code{@value{GDBP}} pass any arguments after the
822executable file to the inferior using @code{--args}. This option stops
823option processing.
474c8240 824@smallexample
aa26fa3a 825gdb --args gcc -O2 -c foo.c
474c8240 826@end smallexample
aa26fa3a
TT
827This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
828@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
829
96a2c332 830You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
831@value{GDBN}'s non-warranty, by specifying @code{-silent}:
832
833@smallexample
834@value{GDBP} -silent
835@end smallexample
836
837@noindent
838You can further control how @value{GDBN} starts up by using command-line
839options. @value{GDBN} itself can remind you of the options available.
840
841@noindent
842Type
843
474c8240 844@smallexample
c906108c 845@value{GDBP} -help
474c8240 846@end smallexample
c906108c
SS
847
848@noindent
849to display all available options and briefly describe their use
850(@samp{@value{GDBP} -h} is a shorter equivalent).
851
852All options and command line arguments you give are processed
853in sequential order. The order makes a difference when the
854@samp{-x} option is used.
855
856
857@menu
c906108c
SS
858* File Options:: Choosing files
859* Mode Options:: Choosing modes
6fc08d32 860* Startup:: What @value{GDBN} does during startup
c906108c
SS
861@end menu
862
6d2ebf8b 863@node File Options
c906108c
SS
864@subsection Choosing files
865
2df3850c 866When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
867specifying an executable file and core file (or process ID). This is
868the same as if the arguments were specified by the @samp{-se} and
19837790
MS
869@samp{-c} (or @samp{-p} options respectively. (@value{GDBN} reads the
870first argument that does not have an associated option flag as
871equivalent to the @samp{-se} option followed by that argument; and the
872second argument that does not have an associated option flag, if any, as
873equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
874If the second argument begins with a decimal digit, @value{GDBN} will
875first attempt to attach to it as a process, and if that fails, attempt
876to open it as a corefile. If you have a corefile whose name begins with
b383017d 877a digit, you can prevent @value{GDBN} from treating it as a pid by
79f12247 878prefixing it with @file{./}, eg. @file{./12345}.
7a292a7a
SS
879
880If @value{GDBN} has not been configured to included core file support,
881such as for most embedded targets, then it will complain about a second
882argument and ignore it.
c906108c
SS
883
884Many options have both long and short forms; both are shown in the
885following list. @value{GDBN} also recognizes the long forms if you truncate
886them, so long as enough of the option is present to be unambiguous.
887(If you prefer, you can flag option arguments with @samp{--} rather
888than @samp{-}, though we illustrate the more usual convention.)
889
d700128c
EZ
890@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
891@c way, both those who look for -foo and --foo in the index, will find
892@c it.
893
c906108c
SS
894@table @code
895@item -symbols @var{file}
896@itemx -s @var{file}
d700128c
EZ
897@cindex @code{--symbols}
898@cindex @code{-s}
c906108c
SS
899Read symbol table from file @var{file}.
900
901@item -exec @var{file}
902@itemx -e @var{file}
d700128c
EZ
903@cindex @code{--exec}
904@cindex @code{-e}
7a292a7a
SS
905Use file @var{file} as the executable file to execute when appropriate,
906and for examining pure data in conjunction with a core dump.
c906108c
SS
907
908@item -se @var{file}
d700128c 909@cindex @code{--se}
c906108c
SS
910Read symbol table from file @var{file} and use it as the executable
911file.
912
c906108c
SS
913@item -core @var{file}
914@itemx -c @var{file}
d700128c
EZ
915@cindex @code{--core}
916@cindex @code{-c}
b383017d 917Use file @var{file} as a core dump to examine.
c906108c
SS
918
919@item -c @var{number}
19837790
MS
920@item -pid @var{number}
921@itemx -p @var{number}
922@cindex @code{--pid}
923@cindex @code{-p}
924Connect to process ID @var{number}, as with the @code{attach} command.
925If there is no such process, @value{GDBN} will attempt to open a core
926file named @var{number}.
c906108c
SS
927
928@item -command @var{file}
929@itemx -x @var{file}
d700128c
EZ
930@cindex @code{--command}
931@cindex @code{-x}
c906108c
SS
932Execute @value{GDBN} commands from file @var{file}. @xref{Command
933Files,, Command files}.
934
935@item -directory @var{directory}
936@itemx -d @var{directory}
d700128c
EZ
937@cindex @code{--directory}
938@cindex @code{-d}
c906108c
SS
939Add @var{directory} to the path to search for source files.
940
c906108c
SS
941@item -m
942@itemx -mapped
d700128c
EZ
943@cindex @code{--mapped}
944@cindex @code{-m}
c906108c
SS
945@emph{Warning: this option depends on operating system facilities that are not
946supported on all systems.}@*
947If memory-mapped files are available on your system through the @code{mmap}
5d161b24 948system call, you can use this option
c906108c
SS
949to have @value{GDBN} write the symbols from your
950program into a reusable file in the current directory. If the program you are debugging is
96a2c332 951called @file{/tmp/fred}, the mapped symbol file is @file{/tmp/fred.syms}.
c906108c
SS
952Future @value{GDBN} debugging sessions notice the presence of this file,
953and can quickly map in symbol information from it, rather than reading
954the symbol table from the executable program.
955
956The @file{.syms} file is specific to the host machine where @value{GDBN}
957is run. It holds an exact image of the internal @value{GDBN} symbol
958table. It cannot be shared across multiple host platforms.
c906108c 959
c906108c
SS
960@item -r
961@itemx -readnow
d700128c
EZ
962@cindex @code{--readnow}
963@cindex @code{-r}
c906108c
SS
964Read each symbol file's entire symbol table immediately, rather than
965the default, which is to read it incrementally as it is needed.
966This makes startup slower, but makes future operations faster.
53a5351d 967
c906108c
SS
968@end table
969
2df3850c 970You typically combine the @code{-mapped} and @code{-readnow} options in
c906108c 971order to build a @file{.syms} file that contains complete symbol
2df3850c
JM
972information. (@xref{Files,,Commands to specify files}, for information
973on @file{.syms} files.) A simple @value{GDBN} invocation to do nothing
974but build a @file{.syms} file for future use is:
c906108c 975
474c8240 976@smallexample
2df3850c 977gdb -batch -nx -mapped -readnow programname
474c8240 978@end smallexample
c906108c 979
6d2ebf8b 980@node Mode Options
c906108c
SS
981@subsection Choosing modes
982
983You can run @value{GDBN} in various alternative modes---for example, in
984batch mode or quiet mode.
985
986@table @code
987@item -nx
988@itemx -n
d700128c
EZ
989@cindex @code{--nx}
990@cindex @code{-n}
96565e91 991Do not execute commands found in any initialization files. Normally,
2df3850c
JM
992@value{GDBN} executes the commands in these files after all the command
993options and arguments have been processed. @xref{Command Files,,Command
994files}.
c906108c
SS
995
996@item -quiet
d700128c 997@itemx -silent
c906108c 998@itemx -q
d700128c
EZ
999@cindex @code{--quiet}
1000@cindex @code{--silent}
1001@cindex @code{-q}
c906108c
SS
1002``Quiet''. Do not print the introductory and copyright messages. These
1003messages are also suppressed in batch mode.
1004
1005@item -batch
d700128c 1006@cindex @code{--batch}
c906108c
SS
1007Run in batch mode. Exit with status @code{0} after processing all the
1008command files specified with @samp{-x} (and all commands from
1009initialization files, if not inhibited with @samp{-n}). Exit with
1010nonzero status if an error occurs in executing the @value{GDBN} commands
1011in the command files.
1012
2df3850c
JM
1013Batch mode may be useful for running @value{GDBN} as a filter, for
1014example to download and run a program on another computer; in order to
1015make this more useful, the message
c906108c 1016
474c8240 1017@smallexample
c906108c 1018Program exited normally.
474c8240 1019@end smallexample
c906108c
SS
1020
1021@noindent
2df3850c
JM
1022(which is ordinarily issued whenever a program running under
1023@value{GDBN} control terminates) is not issued when running in batch
1024mode.
1025
1026@item -nowindows
1027@itemx -nw
d700128c
EZ
1028@cindex @code{--nowindows}
1029@cindex @code{-nw}
2df3850c 1030``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1031(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1032interface. If no GUI is available, this option has no effect.
1033
1034@item -windows
1035@itemx -w
d700128c
EZ
1036@cindex @code{--windows}
1037@cindex @code{-w}
2df3850c
JM
1038If @value{GDBN} includes a GUI, then this option requires it to be
1039used if possible.
c906108c
SS
1040
1041@item -cd @var{directory}
d700128c 1042@cindex @code{--cd}
c906108c
SS
1043Run @value{GDBN} using @var{directory} as its working directory,
1044instead of the current directory.
1045
c906108c
SS
1046@item -fullname
1047@itemx -f
d700128c
EZ
1048@cindex @code{--fullname}
1049@cindex @code{-f}
7a292a7a
SS
1050@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1051subprocess. It tells @value{GDBN} to output the full file name and line
1052number in a standard, recognizable fashion each time a stack frame is
1053displayed (which includes each time your program stops). This
1054recognizable format looks like two @samp{\032} characters, followed by
1055the file name, line number and character position separated by colons,
1056and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1057@samp{\032} characters as a signal to display the source code for the
1058frame.
c906108c 1059
d700128c
EZ
1060@item -epoch
1061@cindex @code{--epoch}
1062The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1063@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1064routines so as to allow Epoch to display values of expressions in a
1065separate window.
1066
1067@item -annotate @var{level}
1068@cindex @code{--annotate}
1069This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1070effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1071(@pxref{Annotations}). The annotation @var{level} controls how much
1072information @value{GDBN} prints together with its prompt, values of
1073expressions, source lines, and other types of output. Level 0 is the
1074normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1075@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1076that control @value{GDBN}, and level 2 has been deprecated.
1077
1078The annotation mechanism has largely been superseeded by @sc{gdb/mi}
1079(@pxref{GDB/MI}).
d700128c 1080
aa26fa3a
TT
1081@item --args
1082@cindex @code{--args}
1083Change interpretation of command line so that arguments following the
1084executable file are passed as command line arguments to the inferior.
1085This option stops option processing.
1086
2df3850c
JM
1087@item -baud @var{bps}
1088@itemx -b @var{bps}
d700128c
EZ
1089@cindex @code{--baud}
1090@cindex @code{-b}
c906108c
SS
1091Set the line speed (baud rate or bits per second) of any serial
1092interface used by @value{GDBN} for remote debugging.
c906108c 1093
f47b1503
AS
1094@item -l @var{timeout}
1095@cindex @code{-l}
1096Set the timeout (in seconds) of any communication used by @value{GDBN}
1097for remote debugging.
1098
c906108c 1099@item -tty @var{device}
d700128c
EZ
1100@itemx -t @var{device}
1101@cindex @code{--tty}
1102@cindex @code{-t}
c906108c
SS
1103Run using @var{device} for your program's standard input and output.
1104@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1105
53a5351d 1106@c resolve the situation of these eventually
c4555f82
SC
1107@item -tui
1108@cindex @code{--tui}
d0d5df6f
AC
1109Activate the @dfn{Text User Interface} when starting. The Text User
1110Interface manages several text windows on the terminal, showing
1111source, assembly, registers and @value{GDBN} command outputs
1112(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1113Text User Interface can be enabled by invoking the program
1114@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1115Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1116
1117@c @item -xdb
d700128c 1118@c @cindex @code{--xdb}
53a5351d
JM
1119@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1120@c For information, see the file @file{xdb_trans.html}, which is usually
1121@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1122@c systems.
1123
d700128c
EZ
1124@item -interpreter @var{interp}
1125@cindex @code{--interpreter}
1126Use the interpreter @var{interp} for interface with the controlling
1127program or device. This option is meant to be set by programs which
94bbb2c0 1128communicate with @value{GDBN} using it as a back end.
21c294e6 1129@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1130
da0f9dcd 1131@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1132@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1133The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1134previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1135selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1136@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1137
1138@item -write
1139@cindex @code{--write}
1140Open the executable and core files for both reading and writing. This
1141is equivalent to the @samp{set write on} command inside @value{GDBN}
1142(@pxref{Patching}).
1143
1144@item -statistics
1145@cindex @code{--statistics}
1146This option causes @value{GDBN} to print statistics about time and
1147memory usage after it completes each command and returns to the prompt.
1148
1149@item -version
1150@cindex @code{--version}
1151This option causes @value{GDBN} to print its version number and
1152no-warranty blurb, and exit.
1153
c906108c
SS
1154@end table
1155
6fc08d32
EZ
1156@node Startup
1157@subsection What @value{GDBN} does during startup
1158@cindex @value{GDBN} startup
1159
1160Here's the description of what @value{GDBN} does during session startup:
1161
1162@enumerate
1163@item
1164Sets up the command interpreter as specified by the command line
1165(@pxref{Mode Options, interpreter}).
1166
1167@item
1168@cindex init file
1169Reads the @dfn{init file} (if any) in your home directory@footnote{On
1170DOS/Windows systems, the home directory is the one pointed to by the
1171@code{HOME} environment variable.} and executes all the commands in
1172that file.
1173
1174@item
1175Processes command line options and operands.
1176
1177@item
1178Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1179working directory. This is only done if the current directory is
1180different from your home directory. Thus, you can have more than one
1181init file, one generic in your home directory, and another, specific
1182to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1183@value{GDBN}.
1184
1185@item
1186Reads command files specified by the @samp{-x} option. @xref{Command
1187Files}, for more details about @value{GDBN} command files.
1188
1189@item
1190Reads the command history recorded in the @dfn{history file}.
d620b259 1191@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1192files where @value{GDBN} records it.
1193@end enumerate
1194
1195Init files use the same syntax as @dfn{command files} (@pxref{Command
1196Files}) and are processed by @value{GDBN} in the same way. The init
1197file in your home directory can set options (such as @samp{set
1198complaints}) that affect subsequent processing of command line options
1199and operands. Init files are not executed if you use the @samp{-nx}
1200option (@pxref{Mode Options, ,Choosing modes}).
1201
1202@cindex init file name
1203@cindex @file{.gdbinit}
119b882a 1204The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1205On some configurations of @value{GDBN}, the init file is known by a
1206different name (these are typically environments where a specialized
1207form of @value{GDBN} may need to coexist with other forms, hence a
1208different name for the specialized version's init file). These are the
1209environments with special init file names:
1210
6fc08d32 1211@itemize @bullet
119b882a
EZ
1212@cindex @file{gdb.ini}
1213@item
1214The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1215the limitations of file names imposed by DOS filesystems. The Windows
1216ports of @value{GDBN} use the standard name, but if they find a
1217@file{gdb.ini} file, they warn you about that and suggest to rename
1218the file to the standard name.
1219
1220@cindex @file{.vxgdbinit}
6fc08d32
EZ
1221@item
1222VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1223
1224@cindex @file{.os68gdbinit}
1225@item
1226OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1227
1228@cindex @file{.esgdbinit}
1229@item
1230ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1231
1232@item
1233CISCO 68k: @file{.cisco-gdbinit}
1234@end itemize
1235
1236
6d2ebf8b 1237@node Quitting GDB
c906108c
SS
1238@section Quitting @value{GDBN}
1239@cindex exiting @value{GDBN}
1240@cindex leaving @value{GDBN}
1241
1242@table @code
1243@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1244@kindex q @r{(@code{quit})}
96a2c332
SS
1245@item quit @r{[}@var{expression}@r{]}
1246@itemx q
1247To exit @value{GDBN}, use the @code{quit} command (abbreviated
1248@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1249do not supply @var{expression}, @value{GDBN} will terminate normally;
1250otherwise it will terminate using the result of @var{expression} as the
1251error code.
c906108c
SS
1252@end table
1253
1254@cindex interrupt
1255An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1256terminates the action of any @value{GDBN} command that is in progress and
1257returns to @value{GDBN} command level. It is safe to type the interrupt
1258character at any time because @value{GDBN} does not allow it to take effect
1259until a time when it is safe.
1260
c906108c
SS
1261If you have been using @value{GDBN} to control an attached process or
1262device, you can release it with the @code{detach} command
1263(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1264
6d2ebf8b 1265@node Shell Commands
c906108c
SS
1266@section Shell commands
1267
1268If you need to execute occasional shell commands during your
1269debugging session, there is no need to leave or suspend @value{GDBN}; you can
1270just use the @code{shell} command.
1271
1272@table @code
1273@kindex shell
1274@cindex shell escape
1275@item shell @var{command string}
1276Invoke a standard shell to execute @var{command string}.
c906108c 1277If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1278shell to run. Otherwise @value{GDBN} uses the default shell
1279(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1280@end table
1281
1282The utility @code{make} is often needed in development environments.
1283You do not have to use the @code{shell} command for this purpose in
1284@value{GDBN}:
1285
1286@table @code
1287@kindex make
1288@cindex calling make
1289@item make @var{make-args}
1290Execute the @code{make} program with the specified
1291arguments. This is equivalent to @samp{shell make @var{make-args}}.
1292@end table
1293
0fac0b41
DJ
1294@node Logging output
1295@section Logging output
1296@cindex logging @value{GDBN} output
9c16f35a 1297@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1298
1299You may want to save the output of @value{GDBN} commands to a file.
1300There are several commands to control @value{GDBN}'s logging.
1301
1302@table @code
1303@kindex set logging
1304@item set logging on
1305Enable logging.
1306@item set logging off
1307Disable logging.
9c16f35a 1308@cindex logging file name
0fac0b41
DJ
1309@item set logging file @var{file}
1310Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1311@item set logging overwrite [on|off]
1312By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1313you want @code{set logging on} to overwrite the logfile instead.
1314@item set logging redirect [on|off]
1315By default, @value{GDBN} output will go to both the terminal and the logfile.
1316Set @code{redirect} if you want output to go only to the log file.
1317@kindex show logging
1318@item show logging
1319Show the current values of the logging settings.
1320@end table
1321
6d2ebf8b 1322@node Commands
c906108c
SS
1323@chapter @value{GDBN} Commands
1324
1325You can abbreviate a @value{GDBN} command to the first few letters of the command
1326name, if that abbreviation is unambiguous; and you can repeat certain
1327@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1328key to get @value{GDBN} to fill out the rest of a word in a command (or to
1329show you the alternatives available, if there is more than one possibility).
1330
1331@menu
1332* Command Syntax:: How to give commands to @value{GDBN}
1333* Completion:: Command completion
1334* Help:: How to ask @value{GDBN} for help
1335@end menu
1336
6d2ebf8b 1337@node Command Syntax
c906108c
SS
1338@section Command syntax
1339
1340A @value{GDBN} command is a single line of input. There is no limit on
1341how long it can be. It starts with a command name, which is followed by
1342arguments whose meaning depends on the command name. For example, the
1343command @code{step} accepts an argument which is the number of times to
1344step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1345with no arguments. Some commands do not allow any arguments.
c906108c
SS
1346
1347@cindex abbreviation
1348@value{GDBN} command names may always be truncated if that abbreviation is
1349unambiguous. Other possible command abbreviations are listed in the
1350documentation for individual commands. In some cases, even ambiguous
1351abbreviations are allowed; for example, @code{s} is specially defined as
1352equivalent to @code{step} even though there are other commands whose
1353names start with @code{s}. You can test abbreviations by using them as
1354arguments to the @code{help} command.
1355
1356@cindex repeating commands
41afff9a 1357@kindex RET @r{(repeat last command)}
c906108c 1358A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1359repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1360will not repeat this way; these are commands whose unintentional
1361repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1362repeat. User-defined commands can disable this feature; see
1363@ref{Define, dont-repeat}.
c906108c
SS
1364
1365The @code{list} and @code{x} commands, when you repeat them with
1366@key{RET}, construct new arguments rather than repeating
1367exactly as typed. This permits easy scanning of source or memory.
1368
1369@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1370output, in a way similar to the common utility @code{more}
1371(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1372@key{RET} too many in this situation, @value{GDBN} disables command
1373repetition after any command that generates this sort of display.
1374
41afff9a 1375@kindex # @r{(a comment)}
c906108c
SS
1376@cindex comment
1377Any text from a @kbd{#} to the end of the line is a comment; it does
1378nothing. This is useful mainly in command files (@pxref{Command
1379Files,,Command files}).
1380
88118b3a
TT
1381@cindex repeating command sequences
1382@kindex C-o @r{(operate-and-get-next)}
1383The @kbd{C-o} binding is useful for repeating a complex sequence of
1384commands. This command accepts the current line, like @kbd{RET}, and
1385then fetches the next line relative to the current line from the history
1386for editing.
1387
6d2ebf8b 1388@node Completion
c906108c
SS
1389@section Command completion
1390
1391@cindex completion
1392@cindex word completion
1393@value{GDBN} can fill in the rest of a word in a command for you, if there is
1394only one possibility; it can also show you what the valid possibilities
1395are for the next word in a command, at any time. This works for @value{GDBN}
1396commands, @value{GDBN} subcommands, and the names of symbols in your program.
1397
1398Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1399of a word. If there is only one possibility, @value{GDBN} fills in the
1400word, and waits for you to finish the command (or press @key{RET} to
1401enter it). For example, if you type
1402
1403@c FIXME "@key" does not distinguish its argument sufficiently to permit
1404@c complete accuracy in these examples; space introduced for clarity.
1405@c If texinfo enhancements make it unnecessary, it would be nice to
1406@c replace " @key" by "@key" in the following...
474c8240 1407@smallexample
c906108c 1408(@value{GDBP}) info bre @key{TAB}
474c8240 1409@end smallexample
c906108c
SS
1410
1411@noindent
1412@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1413the only @code{info} subcommand beginning with @samp{bre}:
1414
474c8240 1415@smallexample
c906108c 1416(@value{GDBP}) info breakpoints
474c8240 1417@end smallexample
c906108c
SS
1418
1419@noindent
1420You can either press @key{RET} at this point, to run the @code{info
1421breakpoints} command, or backspace and enter something else, if
1422@samp{breakpoints} does not look like the command you expected. (If you
1423were sure you wanted @code{info breakpoints} in the first place, you
1424might as well just type @key{RET} immediately after @samp{info bre},
1425to exploit command abbreviations rather than command completion).
1426
1427If there is more than one possibility for the next word when you press
1428@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1429characters and try again, or just press @key{TAB} a second time;
1430@value{GDBN} displays all the possible completions for that word. For
1431example, you might want to set a breakpoint on a subroutine whose name
1432begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1433just sounds the bell. Typing @key{TAB} again displays all the
1434function names in your program that begin with those characters, for
1435example:
1436
474c8240 1437@smallexample
c906108c
SS
1438(@value{GDBP}) b make_ @key{TAB}
1439@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1440make_a_section_from_file make_environ
1441make_abs_section make_function_type
1442make_blockvector make_pointer_type
1443make_cleanup make_reference_type
c906108c
SS
1444make_command make_symbol_completion_list
1445(@value{GDBP}) b make_
474c8240 1446@end smallexample
c906108c
SS
1447
1448@noindent
1449After displaying the available possibilities, @value{GDBN} copies your
1450partial input (@samp{b make_} in the example) so you can finish the
1451command.
1452
1453If you just want to see the list of alternatives in the first place, you
b37052ae 1454can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1455means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1456key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1457one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1458
1459@cindex quotes in commands
1460@cindex completion of quoted strings
1461Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1462parentheses or other characters that @value{GDBN} normally excludes from
1463its notion of a word. To permit word completion to work in this
1464situation, you may enclose words in @code{'} (single quote marks) in
1465@value{GDBN} commands.
c906108c 1466
c906108c 1467The most likely situation where you might need this is in typing the
b37052ae
EZ
1468name of a C@t{++} function. This is because C@t{++} allows function
1469overloading (multiple definitions of the same function, distinguished
1470by argument type). For example, when you want to set a breakpoint you
1471may need to distinguish whether you mean the version of @code{name}
1472that takes an @code{int} parameter, @code{name(int)}, or the version
1473that takes a @code{float} parameter, @code{name(float)}. To use the
1474word-completion facilities in this situation, type a single quote
1475@code{'} at the beginning of the function name. This alerts
1476@value{GDBN} that it may need to consider more information than usual
1477when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1478
474c8240 1479@smallexample
96a2c332 1480(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1481bubble(double,double) bubble(int,int)
1482(@value{GDBP}) b 'bubble(
474c8240 1483@end smallexample
c906108c
SS
1484
1485In some cases, @value{GDBN} can tell that completing a name requires using
1486quotes. When this happens, @value{GDBN} inserts the quote for you (while
1487completing as much as it can) if you do not type the quote in the first
1488place:
1489
474c8240 1490@smallexample
c906108c
SS
1491(@value{GDBP}) b bub @key{TAB}
1492@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1493(@value{GDBP}) b 'bubble(
474c8240 1494@end smallexample
c906108c
SS
1495
1496@noindent
1497In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1498you have not yet started typing the argument list when you ask for
1499completion on an overloaded symbol.
1500
d4f3574e 1501For more information about overloaded functions, see @ref{C plus plus
b37052ae 1502expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1503overload-resolution off} to disable overload resolution;
b37052ae 1504see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1505
1506
6d2ebf8b 1507@node Help
c906108c
SS
1508@section Getting help
1509@cindex online documentation
1510@kindex help
1511
5d161b24 1512You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1513using the command @code{help}.
1514
1515@table @code
41afff9a 1516@kindex h @r{(@code{help})}
c906108c
SS
1517@item help
1518@itemx h
1519You can use @code{help} (abbreviated @code{h}) with no arguments to
1520display a short list of named classes of commands:
1521
1522@smallexample
1523(@value{GDBP}) help
1524List of classes of commands:
1525
2df3850c 1526aliases -- Aliases of other commands
c906108c 1527breakpoints -- Making program stop at certain points
2df3850c 1528data -- Examining data
c906108c 1529files -- Specifying and examining files
2df3850c
JM
1530internals -- Maintenance commands
1531obscure -- Obscure features
1532running -- Running the program
1533stack -- Examining the stack
c906108c
SS
1534status -- Status inquiries
1535support -- Support facilities
96a2c332
SS
1536tracepoints -- Tracing of program execution without@*
1537 stopping the program
c906108c 1538user-defined -- User-defined commands
c906108c 1539
5d161b24 1540Type "help" followed by a class name for a list of
c906108c 1541commands in that class.
5d161b24 1542Type "help" followed by command name for full
c906108c
SS
1543documentation.
1544Command name abbreviations are allowed if unambiguous.
1545(@value{GDBP})
1546@end smallexample
96a2c332 1547@c the above line break eliminates huge line overfull...
c906108c
SS
1548
1549@item help @var{class}
1550Using one of the general help classes as an argument, you can get a
1551list of the individual commands in that class. For example, here is the
1552help display for the class @code{status}:
1553
1554@smallexample
1555(@value{GDBP}) help status
1556Status inquiries.
1557
1558List of commands:
1559
1560@c Line break in "show" line falsifies real output, but needed
1561@c to fit in smallbook page size.
2df3850c
JM
1562info -- Generic command for showing things
1563 about the program being debugged
1564show -- Generic command for showing things
1565 about the debugger
c906108c 1566
5d161b24 1567Type "help" followed by command name for full
c906108c
SS
1568documentation.
1569Command name abbreviations are allowed if unambiguous.
1570(@value{GDBP})
1571@end smallexample
1572
1573@item help @var{command}
1574With a command name as @code{help} argument, @value{GDBN} displays a
1575short paragraph on how to use that command.
1576
6837a0a2
DB
1577@kindex apropos
1578@item apropos @var{args}
09d4efe1 1579The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1580commands, and their documentation, for the regular expression specified in
1581@var{args}. It prints out all matches found. For example:
1582
1583@smallexample
1584apropos reload
1585@end smallexample
1586
b37052ae
EZ
1587@noindent
1588results in:
6837a0a2
DB
1589
1590@smallexample
6d2ebf8b
SS
1591@c @group
1592set symbol-reloading -- Set dynamic symbol table reloading
1593 multiple times in one run
1594show symbol-reloading -- Show dynamic symbol table reloading
1595 multiple times in one run
1596@c @end group
6837a0a2
DB
1597@end smallexample
1598
c906108c
SS
1599@kindex complete
1600@item complete @var{args}
1601The @code{complete @var{args}} command lists all the possible completions
1602for the beginning of a command. Use @var{args} to specify the beginning of the
1603command you want completed. For example:
1604
1605@smallexample
1606complete i
1607@end smallexample
1608
1609@noindent results in:
1610
1611@smallexample
1612@group
2df3850c
JM
1613if
1614ignore
c906108c
SS
1615info
1616inspect
c906108c
SS
1617@end group
1618@end smallexample
1619
1620@noindent This is intended for use by @sc{gnu} Emacs.
1621@end table
1622
1623In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1624and @code{show} to inquire about the state of your program, or the state
1625of @value{GDBN} itself. Each command supports many topics of inquiry; this
1626manual introduces each of them in the appropriate context. The listings
1627under @code{info} and under @code{show} in the Index point to
1628all the sub-commands. @xref{Index}.
1629
1630@c @group
1631@table @code
1632@kindex info
41afff9a 1633@kindex i @r{(@code{info})}
c906108c
SS
1634@item info
1635This command (abbreviated @code{i}) is for describing the state of your
1636program. For example, you can list the arguments given to your program
1637with @code{info args}, list the registers currently in use with @code{info
1638registers}, or list the breakpoints you have set with @code{info breakpoints}.
1639You can get a complete list of the @code{info} sub-commands with
1640@w{@code{help info}}.
1641
1642@kindex set
1643@item set
5d161b24 1644You can assign the result of an expression to an environment variable with
c906108c
SS
1645@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1646@code{set prompt $}.
1647
1648@kindex show
1649@item show
5d161b24 1650In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1651@value{GDBN} itself.
1652You can change most of the things you can @code{show}, by using the
1653related command @code{set}; for example, you can control what number
1654system is used for displays with @code{set radix}, or simply inquire
1655which is currently in use with @code{show radix}.
1656
1657@kindex info set
1658To display all the settable parameters and their current
1659values, you can use @code{show} with no arguments; you may also use
1660@code{info set}. Both commands produce the same display.
1661@c FIXME: "info set" violates the rule that "info" is for state of
1662@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1663@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1664@end table
1665@c @end group
1666
1667Here are three miscellaneous @code{show} subcommands, all of which are
1668exceptional in lacking corresponding @code{set} commands:
1669
1670@table @code
1671@kindex show version
9c16f35a 1672@cindex @value{GDBN} version number
c906108c
SS
1673@item show version
1674Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1675information in @value{GDBN} bug-reports. If multiple versions of
1676@value{GDBN} are in use at your site, you may need to determine which
1677version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1678commands are introduced, and old ones may wither away. Also, many
1679system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1680variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1681The version number is the same as the one announced when you start
1682@value{GDBN}.
c906108c
SS
1683
1684@kindex show copying
09d4efe1 1685@kindex info copying
9c16f35a 1686@cindex display @value{GDBN} copyright
c906108c 1687@item show copying
09d4efe1 1688@itemx info copying
c906108c
SS
1689Display information about permission for copying @value{GDBN}.
1690
1691@kindex show warranty
09d4efe1 1692@kindex info warranty
c906108c 1693@item show warranty
09d4efe1 1694@itemx info warranty
2df3850c 1695Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1696if your version of @value{GDBN} comes with one.
2df3850c 1697
c906108c
SS
1698@end table
1699
6d2ebf8b 1700@node Running
c906108c
SS
1701@chapter Running Programs Under @value{GDBN}
1702
1703When you run a program under @value{GDBN}, you must first generate
1704debugging information when you compile it.
7a292a7a
SS
1705
1706You may start @value{GDBN} with its arguments, if any, in an environment
1707of your choice. If you are doing native debugging, you may redirect
1708your program's input and output, debug an already running process, or
1709kill a child process.
c906108c
SS
1710
1711@menu
1712* Compilation:: Compiling for debugging
1713* Starting:: Starting your program
c906108c
SS
1714* Arguments:: Your program's arguments
1715* Environment:: Your program's environment
c906108c
SS
1716
1717* Working Directory:: Your program's working directory
1718* Input/Output:: Your program's input and output
1719* Attach:: Debugging an already-running process
1720* Kill Process:: Killing the child process
c906108c
SS
1721
1722* Threads:: Debugging programs with multiple threads
1723* Processes:: Debugging programs with multiple processes
1724@end menu
1725
6d2ebf8b 1726@node Compilation
c906108c
SS
1727@section Compiling for debugging
1728
1729In order to debug a program effectively, you need to generate
1730debugging information when you compile it. This debugging information
1731is stored in the object file; it describes the data type of each
1732variable or function and the correspondence between source line numbers
1733and addresses in the executable code.
1734
1735To request debugging information, specify the @samp{-g} option when you run
1736the compiler.
1737
514c4d71
EZ
1738Programs that are to be shipped to your customers are compiled with
1739optimizations, using the @samp{-O} compiler option. However, many
1740compilers are unable to handle the @samp{-g} and @samp{-O} options
1741together. Using those compilers, you cannot generate optimized
c906108c
SS
1742executables containing debugging information.
1743
514c4d71 1744@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1745without @samp{-O}, making it possible to debug optimized code. We
1746recommend that you @emph{always} use @samp{-g} whenever you compile a
1747program. You may think your program is correct, but there is no sense
1748in pushing your luck.
c906108c
SS
1749
1750@cindex optimized code, debugging
1751@cindex debugging optimized code
1752When you debug a program compiled with @samp{-g -O}, remember that the
1753optimizer is rearranging your code; the debugger shows you what is
1754really there. Do not be too surprised when the execution path does not
1755exactly match your source file! An extreme example: if you define a
1756variable, but never use it, @value{GDBN} never sees that
1757variable---because the compiler optimizes it out of existence.
1758
1759Some things do not work as well with @samp{-g -O} as with just
1760@samp{-g}, particularly on machines with instruction scheduling. If in
1761doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1762please report it to us as a bug (including a test case!).
15387254 1763@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1764
1765Older versions of the @sc{gnu} C compiler permitted a variant option
1766@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1767format; if your @sc{gnu} C compiler has this option, do not use it.
1768
514c4d71
EZ
1769@value{GDBN} knows about preprocessor macros and can show you their
1770expansion (@pxref{Macros}). Most compilers do not include information
1771about preprocessor macros in the debugging information if you specify
1772the @option{-g} flag alone, because this information is rather large.
1773Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1774provides macro information if you specify the options
1775@option{-gdwarf-2} and @option{-g3}; the former option requests
1776debugging information in the Dwarf 2 format, and the latter requests
1777``extra information''. In the future, we hope to find more compact
1778ways to represent macro information, so that it can be included with
1779@option{-g} alone.
1780
c906108c 1781@need 2000
6d2ebf8b 1782@node Starting
c906108c
SS
1783@section Starting your program
1784@cindex starting
1785@cindex running
1786
1787@table @code
1788@kindex run
41afff9a 1789@kindex r @r{(@code{run})}
c906108c
SS
1790@item run
1791@itemx r
7a292a7a
SS
1792Use the @code{run} command to start your program under @value{GDBN}.
1793You must first specify the program name (except on VxWorks) with an
1794argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1795@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1796(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1797
1798@end table
1799
c906108c
SS
1800If you are running your program in an execution environment that
1801supports processes, @code{run} creates an inferior process and makes
1802that process run your program. (In environments without processes,
1803@code{run} jumps to the start of your program.)
1804
1805The execution of a program is affected by certain information it
1806receives from its superior. @value{GDBN} provides ways to specify this
1807information, which you must do @emph{before} starting your program. (You
1808can change it after starting your program, but such changes only affect
1809your program the next time you start it.) This information may be
1810divided into four categories:
1811
1812@table @asis
1813@item The @emph{arguments.}
1814Specify the arguments to give your program as the arguments of the
1815@code{run} command. If a shell is available on your target, the shell
1816is used to pass the arguments, so that you may use normal conventions
1817(such as wildcard expansion or variable substitution) in describing
1818the arguments.
1819In Unix systems, you can control which shell is used with the
1820@code{SHELL} environment variable.
1821@xref{Arguments, ,Your program's arguments}.
1822
1823@item The @emph{environment.}
1824Your program normally inherits its environment from @value{GDBN}, but you can
1825use the @value{GDBN} commands @code{set environment} and @code{unset
1826environment} to change parts of the environment that affect
1827your program. @xref{Environment, ,Your program's environment}.
1828
1829@item The @emph{working directory.}
1830Your program inherits its working directory from @value{GDBN}. You can set
1831the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1832@xref{Working Directory, ,Your program's working directory}.
1833
1834@item The @emph{standard input and output.}
1835Your program normally uses the same device for standard input and
1836standard output as @value{GDBN} is using. You can redirect input and output
1837in the @code{run} command line, or you can use the @code{tty} command to
1838set a different device for your program.
1839@xref{Input/Output, ,Your program's input and output}.
1840
1841@cindex pipes
1842@emph{Warning:} While input and output redirection work, you cannot use
1843pipes to pass the output of the program you are debugging to another
1844program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1845wrong program.
1846@end table
c906108c
SS
1847
1848When you issue the @code{run} command, your program begins to execute
1849immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1850of how to arrange for your program to stop. Once your program has
1851stopped, you may call functions in your program, using the @code{print}
1852or @code{call} commands. @xref{Data, ,Examining Data}.
1853
1854If the modification time of your symbol file has changed since the last
1855time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1856table, and reads it again. When it does this, @value{GDBN} tries to retain
1857your current breakpoints.
1858
4e8b0763
JB
1859@table @code
1860@kindex start
1861@item start
1862@cindex run to main procedure
1863The name of the main procedure can vary from language to language.
1864With C or C@t{++}, the main procedure name is always @code{main}, but
1865other languages such as Ada do not require a specific name for their
1866main procedure. The debugger provides a convenient way to start the
1867execution of the program and to stop at the beginning of the main
1868procedure, depending on the language used.
1869
1870The @samp{start} command does the equivalent of setting a temporary
1871breakpoint at the beginning of the main procedure and then invoking
1872the @samp{run} command.
1873
f018e82f
EZ
1874@cindex elaboration phase
1875Some programs contain an @dfn{elaboration} phase where some startup code is
1876executed before the main procedure is called. This depends on the
1877languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1878constructors for static and global objects are executed before
1879@code{main} is called. It is therefore possible that the debugger stops
1880before reaching the main procedure. However, the temporary breakpoint
1881will remain to halt execution.
1882
1883Specify the arguments to give to your program as arguments to the
1884@samp{start} command. These arguments will be given verbatim to the
1885underlying @samp{run} command. Note that the same arguments will be
1886reused if no argument is provided during subsequent calls to
1887@samp{start} or @samp{run}.
1888
1889It is sometimes necessary to debug the program during elaboration. In
1890these cases, using the @code{start} command would stop the execution of
1891your program too late, as the program would have already completed the
1892elaboration phase. Under these circumstances, insert breakpoints in your
1893elaboration code before running your program.
1894@end table
1895
6d2ebf8b 1896@node Arguments
c906108c
SS
1897@section Your program's arguments
1898
1899@cindex arguments (to your program)
1900The arguments to your program can be specified by the arguments of the
5d161b24 1901@code{run} command.
c906108c
SS
1902They are passed to a shell, which expands wildcard characters and
1903performs redirection of I/O, and thence to your program. Your
1904@code{SHELL} environment variable (if it exists) specifies what shell
1905@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1906the default shell (@file{/bin/sh} on Unix).
1907
1908On non-Unix systems, the program is usually invoked directly by
1909@value{GDBN}, which emulates I/O redirection via the appropriate system
1910calls, and the wildcard characters are expanded by the startup code of
1911the program, not by the shell.
c906108c
SS
1912
1913@code{run} with no arguments uses the same arguments used by the previous
1914@code{run}, or those set by the @code{set args} command.
1915
c906108c 1916@table @code
41afff9a 1917@kindex set args
c906108c
SS
1918@item set args
1919Specify the arguments to be used the next time your program is run. If
1920@code{set args} has no arguments, @code{run} executes your program
1921with no arguments. Once you have run your program with arguments,
1922using @code{set args} before the next @code{run} is the only way to run
1923it again without arguments.
1924
1925@kindex show args
1926@item show args
1927Show the arguments to give your program when it is started.
1928@end table
1929
6d2ebf8b 1930@node Environment
c906108c
SS
1931@section Your program's environment
1932
1933@cindex environment (of your program)
1934The @dfn{environment} consists of a set of environment variables and
1935their values. Environment variables conventionally record such things as
1936your user name, your home directory, your terminal type, and your search
1937path for programs to run. Usually you set up environment variables with
1938the shell and they are inherited by all the other programs you run. When
1939debugging, it can be useful to try running your program with a modified
1940environment without having to start @value{GDBN} over again.
1941
1942@table @code
1943@kindex path
1944@item path @var{directory}
1945Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1946(the search path for executables) that will be passed to your program.
1947The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1948You may specify several directory names, separated by whitespace or by a
1949system-dependent separator character (@samp{:} on Unix, @samp{;} on
1950MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1951is moved to the front, so it is searched sooner.
c906108c
SS
1952
1953You can use the string @samp{$cwd} to refer to whatever is the current
1954working directory at the time @value{GDBN} searches the path. If you
1955use @samp{.} instead, it refers to the directory where you executed the
1956@code{path} command. @value{GDBN} replaces @samp{.} in the
1957@var{directory} argument (with the current path) before adding
1958@var{directory} to the search path.
1959@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1960@c document that, since repeating it would be a no-op.
1961
1962@kindex show paths
1963@item show paths
1964Display the list of search paths for executables (the @code{PATH}
1965environment variable).
1966
1967@kindex show environment
1968@item show environment @r{[}@var{varname}@r{]}
1969Print the value of environment variable @var{varname} to be given to
1970your program when it starts. If you do not supply @var{varname},
1971print the names and values of all environment variables to be given to
1972your program. You can abbreviate @code{environment} as @code{env}.
1973
1974@kindex set environment
53a5351d 1975@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1976Set environment variable @var{varname} to @var{value}. The value
1977changes for your program only, not for @value{GDBN} itself. @var{value} may
1978be any string; the values of environment variables are just strings, and
1979any interpretation is supplied by your program itself. The @var{value}
1980parameter is optional; if it is eliminated, the variable is set to a
1981null value.
1982@c "any string" here does not include leading, trailing
1983@c blanks. Gnu asks: does anyone care?
1984
1985For example, this command:
1986
474c8240 1987@smallexample
c906108c 1988set env USER = foo
474c8240 1989@end smallexample
c906108c
SS
1990
1991@noindent
d4f3574e 1992tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1993@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1994are not actually required.)
1995
1996@kindex unset environment
1997@item unset environment @var{varname}
1998Remove variable @var{varname} from the environment to be passed to your
1999program. This is different from @samp{set env @var{varname} =};
2000@code{unset environment} removes the variable from the environment,
2001rather than assigning it an empty value.
2002@end table
2003
d4f3574e
SS
2004@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2005the shell indicated
c906108c
SS
2006by your @code{SHELL} environment variable if it exists (or
2007@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2008that runs an initialization file---such as @file{.cshrc} for C-shell, or
2009@file{.bashrc} for BASH---any variables you set in that file affect
2010your program. You may wish to move setting of environment variables to
2011files that are only run when you sign on, such as @file{.login} or
2012@file{.profile}.
2013
6d2ebf8b 2014@node Working Directory
c906108c
SS
2015@section Your program's working directory
2016
2017@cindex working directory (of your program)
2018Each time you start your program with @code{run}, it inherits its
2019working directory from the current working directory of @value{GDBN}.
2020The @value{GDBN} working directory is initially whatever it inherited
2021from its parent process (typically the shell), but you can specify a new
2022working directory in @value{GDBN} with the @code{cd} command.
2023
2024The @value{GDBN} working directory also serves as a default for the commands
2025that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2026specify files}.
2027
2028@table @code
2029@kindex cd
721c2651 2030@cindex change working directory
c906108c
SS
2031@item cd @var{directory}
2032Set the @value{GDBN} working directory to @var{directory}.
2033
2034@kindex pwd
2035@item pwd
2036Print the @value{GDBN} working directory.
2037@end table
2038
60bf7e09
EZ
2039It is generally impossible to find the current working directory of
2040the process being debugged (since a program can change its directory
2041during its run). If you work on a system where @value{GDBN} is
2042configured with the @file{/proc} support, you can use the @code{info
2043proc} command (@pxref{SVR4 Process Information}) to find out the
2044current working directory of the debuggee.
2045
6d2ebf8b 2046@node Input/Output
c906108c
SS
2047@section Your program's input and output
2048
2049@cindex redirection
2050@cindex i/o
2051@cindex terminal
2052By default, the program you run under @value{GDBN} does input and output to
5d161b24 2053the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2054to its own terminal modes to interact with you, but it records the terminal
2055modes your program was using and switches back to them when you continue
2056running your program.
2057
2058@table @code
2059@kindex info terminal
2060@item info terminal
2061Displays information recorded by @value{GDBN} about the terminal modes your
2062program is using.
2063@end table
2064
2065You can redirect your program's input and/or output using shell
2066redirection with the @code{run} command. For example,
2067
474c8240 2068@smallexample
c906108c 2069run > outfile
474c8240 2070@end smallexample
c906108c
SS
2071
2072@noindent
2073starts your program, diverting its output to the file @file{outfile}.
2074
2075@kindex tty
2076@cindex controlling terminal
2077Another way to specify where your program should do input and output is
2078with the @code{tty} command. This command accepts a file name as
2079argument, and causes this file to be the default for future @code{run}
2080commands. It also resets the controlling terminal for the child
2081process, for future @code{run} commands. For example,
2082
474c8240 2083@smallexample
c906108c 2084tty /dev/ttyb
474c8240 2085@end smallexample
c906108c
SS
2086
2087@noindent
2088directs that processes started with subsequent @code{run} commands
2089default to do input and output on the terminal @file{/dev/ttyb} and have
2090that as their controlling terminal.
2091
2092An explicit redirection in @code{run} overrides the @code{tty} command's
2093effect on the input/output device, but not its effect on the controlling
2094terminal.
2095
2096When you use the @code{tty} command or redirect input in the @code{run}
2097command, only the input @emph{for your program} is affected. The input
2098for @value{GDBN} still comes from your terminal.
2099
6d2ebf8b 2100@node Attach
c906108c
SS
2101@section Debugging an already-running process
2102@kindex attach
2103@cindex attach
2104
2105@table @code
2106@item attach @var{process-id}
2107This command attaches to a running process---one that was started
2108outside @value{GDBN}. (@code{info files} shows your active
2109targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2110find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2111or with the @samp{jobs -l} shell command.
2112
2113@code{attach} does not repeat if you press @key{RET} a second time after
2114executing the command.
2115@end table
2116
2117To use @code{attach}, your program must be running in an environment
2118which supports processes; for example, @code{attach} does not work for
2119programs on bare-board targets that lack an operating system. You must
2120also have permission to send the process a signal.
2121
2122When you use @code{attach}, the debugger finds the program running in
2123the process first by looking in the current working directory, then (if
2124the program is not found) by using the source file search path
2125(@pxref{Source Path, ,Specifying source directories}). You can also use
2126the @code{file} command to load the program. @xref{Files, ,Commands to
2127Specify Files}.
2128
2129The first thing @value{GDBN} does after arranging to debug the specified
2130process is to stop it. You can examine and modify an attached process
53a5351d
JM
2131with all the @value{GDBN} commands that are ordinarily available when
2132you start processes with @code{run}. You can insert breakpoints; you
2133can step and continue; you can modify storage. If you would rather the
2134process continue running, you may use the @code{continue} command after
c906108c
SS
2135attaching @value{GDBN} to the process.
2136
2137@table @code
2138@kindex detach
2139@item detach
2140When you have finished debugging the attached process, you can use the
2141@code{detach} command to release it from @value{GDBN} control. Detaching
2142the process continues its execution. After the @code{detach} command,
2143that process and @value{GDBN} become completely independent once more, and you
2144are ready to @code{attach} another process or start one with @code{run}.
2145@code{detach} does not repeat if you press @key{RET} again after
2146executing the command.
2147@end table
2148
2149If you exit @value{GDBN} or use the @code{run} command while you have an
2150attached process, you kill that process. By default, @value{GDBN} asks
2151for confirmation if you try to do either of these things; you can
2152control whether or not you need to confirm by using the @code{set
2153confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2154messages}).
2155
6d2ebf8b 2156@node Kill Process
c906108c 2157@section Killing the child process
c906108c
SS
2158
2159@table @code
2160@kindex kill
2161@item kill
2162Kill the child process in which your program is running under @value{GDBN}.
2163@end table
2164
2165This command is useful if you wish to debug a core dump instead of a
2166running process. @value{GDBN} ignores any core dump file while your program
2167is running.
2168
2169On some operating systems, a program cannot be executed outside @value{GDBN}
2170while you have breakpoints set on it inside @value{GDBN}. You can use the
2171@code{kill} command in this situation to permit running your program
2172outside the debugger.
2173
2174The @code{kill} command is also useful if you wish to recompile and
2175relink your program, since on many systems it is impossible to modify an
2176executable file while it is running in a process. In this case, when you
2177next type @code{run}, @value{GDBN} notices that the file has changed, and
2178reads the symbol table again (while trying to preserve your current
2179breakpoint settings).
2180
6d2ebf8b 2181@node Threads
c906108c 2182@section Debugging programs with multiple threads
c906108c
SS
2183
2184@cindex threads of execution
2185@cindex multiple threads
2186@cindex switching threads
2187In some operating systems, such as HP-UX and Solaris, a single program
2188may have more than one @dfn{thread} of execution. The precise semantics
2189of threads differ from one operating system to another, but in general
2190the threads of a single program are akin to multiple processes---except
2191that they share one address space (that is, they can all examine and
2192modify the same variables). On the other hand, each thread has its own
2193registers and execution stack, and perhaps private memory.
2194
2195@value{GDBN} provides these facilities for debugging multi-thread
2196programs:
2197
2198@itemize @bullet
2199@item automatic notification of new threads
2200@item @samp{thread @var{threadno}}, a command to switch among threads
2201@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2202@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2203a command to apply a command to a list of threads
2204@item thread-specific breakpoints
2205@end itemize
2206
c906108c
SS
2207@quotation
2208@emph{Warning:} These facilities are not yet available on every
2209@value{GDBN} configuration where the operating system supports threads.
2210If your @value{GDBN} does not support threads, these commands have no
2211effect. For example, a system without thread support shows no output
2212from @samp{info threads}, and always rejects the @code{thread} command,
2213like this:
2214
2215@smallexample
2216(@value{GDBP}) info threads
2217(@value{GDBP}) thread 1
2218Thread ID 1 not known. Use the "info threads" command to
2219see the IDs of currently known threads.
2220@end smallexample
2221@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2222@c doesn't support threads"?
2223@end quotation
c906108c
SS
2224
2225@cindex focus of debugging
2226@cindex current thread
2227The @value{GDBN} thread debugging facility allows you to observe all
2228threads while your program runs---but whenever @value{GDBN} takes
2229control, one thread in particular is always the focus of debugging.
2230This thread is called the @dfn{current thread}. Debugging commands show
2231program information from the perspective of the current thread.
2232
41afff9a 2233@cindex @code{New} @var{systag} message
c906108c
SS
2234@cindex thread identifier (system)
2235@c FIXME-implementors!! It would be more helpful if the [New...] message
2236@c included GDB's numeric thread handle, so you could just go to that
2237@c thread without first checking `info threads'.
2238Whenever @value{GDBN} detects a new thread in your program, it displays
2239the target system's identification for the thread with a message in the
2240form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2241whose form varies depending on the particular system. For example, on
2242LynxOS, you might see
2243
474c8240 2244@smallexample
c906108c 2245[New process 35 thread 27]
474c8240 2246@end smallexample
c906108c
SS
2247
2248@noindent
2249when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2250the @var{systag} is simply something like @samp{process 368}, with no
2251further qualifier.
2252
2253@c FIXME!! (1) Does the [New...] message appear even for the very first
2254@c thread of a program, or does it only appear for the
6ca652b0 2255@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2256@c program?
2257@c (2) *Is* there necessarily a first thread always? Or do some
2258@c multithread systems permit starting a program with multiple
5d161b24 2259@c threads ab initio?
c906108c
SS
2260
2261@cindex thread number
2262@cindex thread identifier (GDB)
2263For debugging purposes, @value{GDBN} associates its own thread
2264number---always a single integer---with each thread in your program.
2265
2266@table @code
2267@kindex info threads
2268@item info threads
2269Display a summary of all threads currently in your
2270program. @value{GDBN} displays for each thread (in this order):
2271
2272@enumerate
09d4efe1
EZ
2273@item
2274the thread number assigned by @value{GDBN}
c906108c 2275
09d4efe1
EZ
2276@item
2277the target system's thread identifier (@var{systag})
c906108c 2278
09d4efe1
EZ
2279@item
2280the current stack frame summary for that thread
c906108c
SS
2281@end enumerate
2282
2283@noindent
2284An asterisk @samp{*} to the left of the @value{GDBN} thread number
2285indicates the current thread.
2286
5d161b24 2287For example,
c906108c
SS
2288@end table
2289@c end table here to get a little more width for example
2290
2291@smallexample
2292(@value{GDBP}) info threads
2293 3 process 35 thread 27 0x34e5 in sigpause ()
2294 2 process 35 thread 23 0x34e5 in sigpause ()
2295* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2296 at threadtest.c:68
2297@end smallexample
53a5351d
JM
2298
2299On HP-UX systems:
c906108c 2300
4644b6e3
EZ
2301@cindex debugging multithreaded programs (on HP-UX)
2302@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2303For debugging purposes, @value{GDBN} associates its own thread
2304number---a small integer assigned in thread-creation order---with each
2305thread in your program.
2306
41afff9a
EZ
2307@cindex @code{New} @var{systag} message, on HP-UX
2308@cindex thread identifier (system), on HP-UX
c906108c
SS
2309@c FIXME-implementors!! It would be more helpful if the [New...] message
2310@c included GDB's numeric thread handle, so you could just go to that
2311@c thread without first checking `info threads'.
2312Whenever @value{GDBN} detects a new thread in your program, it displays
2313both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2314form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2315whose form varies depending on the particular system. For example, on
2316HP-UX, you see
2317
474c8240 2318@smallexample
c906108c 2319[New thread 2 (system thread 26594)]
474c8240 2320@end smallexample
c906108c
SS
2321
2322@noindent
5d161b24 2323when @value{GDBN} notices a new thread.
c906108c
SS
2324
2325@table @code
4644b6e3 2326@kindex info threads (HP-UX)
c906108c
SS
2327@item info threads
2328Display a summary of all threads currently in your
2329program. @value{GDBN} displays for each thread (in this order):
2330
2331@enumerate
2332@item the thread number assigned by @value{GDBN}
2333
2334@item the target system's thread identifier (@var{systag})
2335
2336@item the current stack frame summary for that thread
2337@end enumerate
2338
2339@noindent
2340An asterisk @samp{*} to the left of the @value{GDBN} thread number
2341indicates the current thread.
2342
5d161b24 2343For example,
c906108c
SS
2344@end table
2345@c end table here to get a little more width for example
2346
474c8240 2347@smallexample
c906108c 2348(@value{GDBP}) info threads
6d2ebf8b
SS
2349 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2350 at quicksort.c:137
2351 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2352 from /usr/lib/libc.2
2353 1 system thread 27905 0x7b003498 in _brk () \@*
2354 from /usr/lib/libc.2
474c8240 2355@end smallexample
c906108c 2356
c45da7e6
EZ
2357On Solaris, you can display more information about user threads with a
2358Solaris-specific command:
2359
2360@table @code
2361@item maint info sol-threads
2362@kindex maint info sol-threads
2363@cindex thread info (Solaris)
2364Display info on Solaris user threads.
2365@end table
2366
c906108c
SS
2367@table @code
2368@kindex thread @var{threadno}
2369@item thread @var{threadno}
2370Make thread number @var{threadno} the current thread. The command
2371argument @var{threadno} is the internal @value{GDBN} thread number, as
2372shown in the first field of the @samp{info threads} display.
2373@value{GDBN} responds by displaying the system identifier of the thread
2374you selected, and its current stack frame summary:
2375
2376@smallexample
2377@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2378(@value{GDBP}) thread 2
c906108c 2379[Switching to process 35 thread 23]
c906108c
SS
23800x34e5 in sigpause ()
2381@end smallexample
2382
2383@noindent
2384As with the @samp{[New @dots{}]} message, the form of the text after
2385@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2386threads.
c906108c 2387
9c16f35a 2388@kindex thread apply
638ac427 2389@cindex apply command to several threads
c906108c
SS
2390@item thread apply [@var{threadno}] [@var{all}] @var{args}
2391The @code{thread apply} command allows you to apply a command to one or
2392more threads. Specify the numbers of the threads that you want affected
2393with the command argument @var{threadno}. @var{threadno} is the internal
2394@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2395threads} display. To apply a command to all threads, use
2396@code{thread apply all} @var{args}.
c906108c
SS
2397@end table
2398
2399@cindex automatic thread selection
2400@cindex switching threads automatically
2401@cindex threads, automatic switching
2402Whenever @value{GDBN} stops your program, due to a breakpoint or a
2403signal, it automatically selects the thread where that breakpoint or
2404signal happened. @value{GDBN} alerts you to the context switch with a
2405message of the form @samp{[Switching to @var{systag}]} to identify the
2406thread.
2407
2408@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2409more information about how @value{GDBN} behaves when you stop and start
2410programs with multiple threads.
2411
2412@xref{Set Watchpoints,,Setting watchpoints}, for information about
2413watchpoints in programs with multiple threads.
c906108c 2414
6d2ebf8b 2415@node Processes
c906108c
SS
2416@section Debugging programs with multiple processes
2417
2418@cindex fork, debugging programs which call
2419@cindex multiple processes
2420@cindex processes, multiple
53a5351d
JM
2421On most systems, @value{GDBN} has no special support for debugging
2422programs which create additional processes using the @code{fork}
2423function. When a program forks, @value{GDBN} will continue to debug the
2424parent process and the child process will run unimpeded. If you have
2425set a breakpoint in any code which the child then executes, the child
2426will get a @code{SIGTRAP} signal which (unless it catches the signal)
2427will cause it to terminate.
c906108c
SS
2428
2429However, if you want to debug the child process there is a workaround
2430which isn't too painful. Put a call to @code{sleep} in the code which
2431the child process executes after the fork. It may be useful to sleep
2432only if a certain environment variable is set, or a certain file exists,
2433so that the delay need not occur when you don't want to run @value{GDBN}
2434on the child. While the child is sleeping, use the @code{ps} program to
2435get its process ID. Then tell @value{GDBN} (a new invocation of
2436@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2437the child process (@pxref{Attach}). From that point on you can debug
c906108c 2438the child process just like any other process which you attached to.
c906108c 2439
b51970ac
DJ
2440On some systems, @value{GDBN} provides support for debugging programs that
2441create additional processes using the @code{fork} or @code{vfork} functions.
2442Currently, the only platforms with this feature are HP-UX (11.x and later
2443only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2444
2445By default, when a program forks, @value{GDBN} will continue to debug
2446the parent process and the child process will run unimpeded.
2447
2448If you want to follow the child process instead of the parent process,
2449use the command @w{@code{set follow-fork-mode}}.
2450
2451@table @code
2452@kindex set follow-fork-mode
2453@item set follow-fork-mode @var{mode}
2454Set the debugger response to a program call of @code{fork} or
2455@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2456process. The @var{mode} argument can be:
c906108c
SS
2457
2458@table @code
2459@item parent
2460The original process is debugged after a fork. The child process runs
2df3850c 2461unimpeded. This is the default.
c906108c
SS
2462
2463@item child
2464The new process is debugged after a fork. The parent process runs
2465unimpeded.
2466
c906108c
SS
2467@end table
2468
9c16f35a 2469@kindex show follow-fork-mode
c906108c 2470@item show follow-fork-mode
2df3850c 2471Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2472@end table
2473
2474If you ask to debug a child process and a @code{vfork} is followed by an
2475@code{exec}, @value{GDBN} executes the new target up to the first
2476breakpoint in the new target. If you have a breakpoint set on
2477@code{main} in your original program, the breakpoint will also be set on
2478the child process's @code{main}.
2479
2480When a child process is spawned by @code{vfork}, you cannot debug the
2481child or parent until an @code{exec} call completes.
2482
2483If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2484call executes, the new target restarts. To restart the parent process,
2485use the @code{file} command with the parent executable name as its
2486argument.
2487
2488You can use the @code{catch} command to make @value{GDBN} stop whenever
2489a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2490Catchpoints, ,Setting catchpoints}.
c906108c 2491
6d2ebf8b 2492@node Stopping
c906108c
SS
2493@chapter Stopping and Continuing
2494
2495The principal purposes of using a debugger are so that you can stop your
2496program before it terminates; or so that, if your program runs into
2497trouble, you can investigate and find out why.
2498
7a292a7a
SS
2499Inside @value{GDBN}, your program may stop for any of several reasons,
2500such as a signal, a breakpoint, or reaching a new line after a
2501@value{GDBN} command such as @code{step}. You may then examine and
2502change variables, set new breakpoints or remove old ones, and then
2503continue execution. Usually, the messages shown by @value{GDBN} provide
2504ample explanation of the status of your program---but you can also
2505explicitly request this information at any time.
c906108c
SS
2506
2507@table @code
2508@kindex info program
2509@item info program
2510Display information about the status of your program: whether it is
7a292a7a 2511running or not, what process it is, and why it stopped.
c906108c
SS
2512@end table
2513
2514@menu
2515* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2516* Continuing and Stepping:: Resuming execution
c906108c 2517* Signals:: Signals
c906108c 2518* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2519@end menu
2520
6d2ebf8b 2521@node Breakpoints
c906108c
SS
2522@section Breakpoints, watchpoints, and catchpoints
2523
2524@cindex breakpoints
2525A @dfn{breakpoint} makes your program stop whenever a certain point in
2526the program is reached. For each breakpoint, you can add conditions to
2527control in finer detail whether your program stops. You can set
2528breakpoints with the @code{break} command and its variants (@pxref{Set
2529Breaks, ,Setting breakpoints}), to specify the place where your program
2530should stop by line number, function name or exact address in the
2531program.
2532
09d4efe1
EZ
2533On some systems, you can set breakpoints in shared libraries before
2534the executable is run. There is a minor limitation on HP-UX systems:
2535you must wait until the executable is run in order to set breakpoints
2536in shared library routines that are not called directly by the program
2537(for example, routines that are arguments in a @code{pthread_create}
2538call).
c906108c
SS
2539
2540@cindex watchpoints
2541@cindex memory tracing
2542@cindex breakpoint on memory address
2543@cindex breakpoint on variable modification
2544A @dfn{watchpoint} is a special breakpoint that stops your program
2545when the value of an expression changes. You must use a different
2546command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2547watchpoints}), but aside from that, you can manage a watchpoint like
2548any other breakpoint: you enable, disable, and delete both breakpoints
2549and watchpoints using the same commands.
2550
2551You can arrange to have values from your program displayed automatically
2552whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2553Automatic display}.
2554
2555@cindex catchpoints
2556@cindex breakpoint on events
2557A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2558when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2559exception or the loading of a library. As with watchpoints, you use a
2560different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2561catchpoints}), but aside from that, you can manage a catchpoint like any
2562other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2563@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2564
2565@cindex breakpoint numbers
2566@cindex numbers for breakpoints
2567@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2568catchpoint when you create it; these numbers are successive integers
2569starting with one. In many of the commands for controlling various
2570features of breakpoints you use the breakpoint number to say which
2571breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2572@dfn{disabled}; if disabled, it has no effect on your program until you
2573enable it again.
2574
c5394b80
JM
2575@cindex breakpoint ranges
2576@cindex ranges of breakpoints
2577Some @value{GDBN} commands accept a range of breakpoints on which to
2578operate. A breakpoint range is either a single breakpoint number, like
2579@samp{5}, or two such numbers, in increasing order, separated by a
2580hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2581all breakpoint in that range are operated on.
2582
c906108c
SS
2583@menu
2584* Set Breaks:: Setting breakpoints
2585* Set Watchpoints:: Setting watchpoints
2586* Set Catchpoints:: Setting catchpoints
2587* Delete Breaks:: Deleting breakpoints
2588* Disabling:: Disabling breakpoints
2589* Conditions:: Break conditions
2590* Break Commands:: Breakpoint command lists
c906108c 2591* Breakpoint Menus:: Breakpoint menus
d4f3574e 2592* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2593* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2594@end menu
2595
6d2ebf8b 2596@node Set Breaks
c906108c
SS
2597@subsection Setting breakpoints
2598
5d161b24 2599@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2600@c consider in particular declaration with/without initialization.
2601@c
2602@c FIXME 2 is there stuff on this already? break at fun start, already init?
2603
2604@kindex break
41afff9a
EZ
2605@kindex b @r{(@code{break})}
2606@vindex $bpnum@r{, convenience variable}
c906108c
SS
2607@cindex latest breakpoint
2608Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2609@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2610number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2611Vars,, Convenience variables}, for a discussion of what you can do with
2612convenience variables.
2613
2614You have several ways to say where the breakpoint should go.
2615
2616@table @code
2617@item break @var{function}
5d161b24 2618Set a breakpoint at entry to function @var{function}.
c906108c 2619When using source languages that permit overloading of symbols, such as
b37052ae 2620C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2621@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2622
2623@item break +@var{offset}
2624@itemx break -@var{offset}
2625Set a breakpoint some number of lines forward or back from the position
d4f3574e 2626at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2627(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2628
2629@item break @var{linenum}
2630Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2631The current source file is the last file whose source text was printed.
2632The breakpoint will stop your program just before it executes any of the
c906108c
SS
2633code on that line.
2634
2635@item break @var{filename}:@var{linenum}
2636Set a breakpoint at line @var{linenum} in source file @var{filename}.
2637
2638@item break @var{filename}:@var{function}
2639Set a breakpoint at entry to function @var{function} found in file
2640@var{filename}. Specifying a file name as well as a function name is
2641superfluous except when multiple files contain similarly named
2642functions.
2643
2644@item break *@var{address}
2645Set a breakpoint at address @var{address}. You can use this to set
2646breakpoints in parts of your program which do not have debugging
2647information or source files.
2648
2649@item break
2650When called without any arguments, @code{break} sets a breakpoint at
2651the next instruction to be executed in the selected stack frame
2652(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2653innermost, this makes your program stop as soon as control
2654returns to that frame. This is similar to the effect of a
2655@code{finish} command in the frame inside the selected frame---except
2656that @code{finish} does not leave an active breakpoint. If you use
2657@code{break} without an argument in the innermost frame, @value{GDBN} stops
2658the next time it reaches the current location; this may be useful
2659inside loops.
2660
2661@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2662least one instruction has been executed. If it did not do this, you
2663would be unable to proceed past a breakpoint without first disabling the
2664breakpoint. This rule applies whether or not the breakpoint already
2665existed when your program stopped.
2666
2667@item break @dots{} if @var{cond}
2668Set a breakpoint with condition @var{cond}; evaluate the expression
2669@var{cond} each time the breakpoint is reached, and stop only if the
2670value is nonzero---that is, if @var{cond} evaluates as true.
2671@samp{@dots{}} stands for one of the possible arguments described
2672above (or no argument) specifying where to break. @xref{Conditions,
2673,Break conditions}, for more information on breakpoint conditions.
2674
2675@kindex tbreak
2676@item tbreak @var{args}
2677Set a breakpoint enabled only for one stop. @var{args} are the
2678same as for the @code{break} command, and the breakpoint is set in the same
2679way, but the breakpoint is automatically deleted after the first time your
2680program stops there. @xref{Disabling, ,Disabling breakpoints}.
2681
c906108c 2682@kindex hbreak
ba04e063 2683@cindex hardware breakpoints
c906108c 2684@item hbreak @var{args}
d4f3574e
SS
2685Set a hardware-assisted breakpoint. @var{args} are the same as for the
2686@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2687breakpoint requires hardware support and some target hardware may not
2688have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2689debugging, so you can set a breakpoint at an instruction without
2690changing the instruction. This can be used with the new trap-generation
09d4efe1 2691provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2692will generate traps when a program accesses some data or instruction
2693address that is assigned to the debug registers. However the hardware
2694breakpoint registers can take a limited number of breakpoints. For
2695example, on the DSU, only two data breakpoints can be set at a time, and
2696@value{GDBN} will reject this command if more than two are used. Delete
2697or disable unused hardware breakpoints before setting new ones
2698(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2699For remote targets, you can restrict the number of hardware
2700breakpoints @value{GDBN} will use, see @ref{set remote
2701hardware-breakpoint-limit}.
501eef12 2702
c906108c
SS
2703
2704@kindex thbreak
2705@item thbreak @var{args}
2706Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2707are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2708the same way. However, like the @code{tbreak} command,
c906108c
SS
2709the breakpoint is automatically deleted after the
2710first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2711command, the breakpoint requires hardware support and some target hardware
2712may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2713See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2714
2715@kindex rbreak
2716@cindex regular expression
c45da7e6
EZ
2717@cindex breakpoints in functions matching a regexp
2718@cindex set breakpoints in many functions
c906108c 2719@item rbreak @var{regex}
c906108c 2720Set breakpoints on all functions matching the regular expression
11cf8741
JM
2721@var{regex}. This command sets an unconditional breakpoint on all
2722matches, printing a list of all breakpoints it set. Once these
2723breakpoints are set, they are treated just like the breakpoints set with
2724the @code{break} command. You can delete them, disable them, or make
2725them conditional the same way as any other breakpoint.
2726
2727The syntax of the regular expression is the standard one used with tools
2728like @file{grep}. Note that this is different from the syntax used by
2729shells, so for instance @code{foo*} matches all functions that include
2730an @code{fo} followed by zero or more @code{o}s. There is an implicit
2731@code{.*} leading and trailing the regular expression you supply, so to
2732match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2733
f7dc1244 2734@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2735When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2736breakpoints on overloaded functions that are not members of any special
2737classes.
c906108c 2738
f7dc1244
EZ
2739@cindex set breakpoints on all functions
2740The @code{rbreak} command can be used to set breakpoints in
2741@strong{all} the functions in a program, like this:
2742
2743@smallexample
2744(@value{GDBP}) rbreak .
2745@end smallexample
2746
c906108c
SS
2747@kindex info breakpoints
2748@cindex @code{$_} and @code{info breakpoints}
2749@item info breakpoints @r{[}@var{n}@r{]}
2750@itemx info break @r{[}@var{n}@r{]}
2751@itemx info watchpoints @r{[}@var{n}@r{]}
2752Print a table of all breakpoints, watchpoints, and catchpoints set and
2753not deleted, with the following columns for each breakpoint:
2754
2755@table @emph
2756@item Breakpoint Numbers
2757@item Type
2758Breakpoint, watchpoint, or catchpoint.
2759@item Disposition
2760Whether the breakpoint is marked to be disabled or deleted when hit.
2761@item Enabled or Disabled
2762Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2763that are not enabled.
2764@item Address
2650777c
JJ
2765Where the breakpoint is in your program, as a memory address. If the
2766breakpoint is pending (see below for details) on a future load of a shared library, the address
2767will be listed as @samp{<PENDING>}.
c906108c
SS
2768@item What
2769Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2770line number. For a pending breakpoint, the original string passed to
2771the breakpoint command will be listed as it cannot be resolved until
2772the appropriate shared library is loaded in the future.
c906108c
SS
2773@end table
2774
2775@noindent
2776If a breakpoint is conditional, @code{info break} shows the condition on
2777the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2778are listed after that. A pending breakpoint is allowed to have a condition
2779specified for it. The condition is not parsed for validity until a shared
2780library is loaded that allows the pending breakpoint to resolve to a
2781valid location.
c906108c
SS
2782
2783@noindent
2784@code{info break} with a breakpoint
2785number @var{n} as argument lists only that breakpoint. The
2786convenience variable @code{$_} and the default examining-address for
2787the @code{x} command are set to the address of the last breakpoint
5d161b24 2788listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2789
2790@noindent
2791@code{info break} displays a count of the number of times the breakpoint
2792has been hit. This is especially useful in conjunction with the
2793@code{ignore} command. You can ignore a large number of breakpoint
2794hits, look at the breakpoint info to see how many times the breakpoint
2795was hit, and then run again, ignoring one less than that number. This
2796will get you quickly to the last hit of that breakpoint.
2797@end table
2798
2799@value{GDBN} allows you to set any number of breakpoints at the same place in
2800your program. There is nothing silly or meaningless about this. When
2801the breakpoints are conditional, this is even useful
2802(@pxref{Conditions, ,Break conditions}).
2803
2650777c 2804@cindex pending breakpoints
dd79a6cf
JJ
2805If a specified breakpoint location cannot be found, it may be due to the fact
2806that the location is in a shared library that is yet to be loaded. In such
2807a case, you may want @value{GDBN} to create a special breakpoint (known as
2808a @dfn{pending breakpoint}) that
2809attempts to resolve itself in the future when an appropriate shared library
2810gets loaded.
2811
2812Pending breakpoints are useful to set at the start of your
2650777c
JJ
2813@value{GDBN} session for locations that you know will be dynamically loaded
2814later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2815a check is made to see if the load resolves any pending breakpoint locations.
2816If a pending breakpoint location gets resolved,
2817a regular breakpoint is created and the original pending breakpoint is removed.
2818
2819@value{GDBN} provides some additional commands for controlling pending
2820breakpoint support:
2821
2822@kindex set breakpoint pending
2823@kindex show breakpoint pending
2824@table @code
2825@item set breakpoint pending auto
2826This is the default behavior. When @value{GDBN} cannot find the breakpoint
2827location, it queries you whether a pending breakpoint should be created.
2828
2829@item set breakpoint pending on
2830This indicates that an unrecognized breakpoint location should automatically
2831result in a pending breakpoint being created.
2832
2833@item set breakpoint pending off
2834This indicates that pending breakpoints are not to be created. Any
2835unrecognized breakpoint location results in an error. This setting does
2836not affect any pending breakpoints previously created.
2837
2838@item show breakpoint pending
2839Show the current behavior setting for creating pending breakpoints.
2840@end table
2650777c 2841
649e03f6
RM
2842@cindex operations allowed on pending breakpoints
2843Normal breakpoint operations apply to pending breakpoints as well. You may
2844specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2845breakpoint is reached. You can also enable or disable
2846the pending breakpoint. When you specify a condition for a pending breakpoint,
2847the parsing of the condition will be deferred until the point where the
2848pending breakpoint location is resolved. Disabling a pending breakpoint
2849tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2850shared library load. When a pending breakpoint is re-enabled,
649e03f6 2851@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2852This is done because any number of shared library loads could have
2853occurred since the time the breakpoint was disabled and one or more
2854of these loads could resolve the location.
2855
c906108c
SS
2856@cindex negative breakpoint numbers
2857@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2858@value{GDBN} itself sometimes sets breakpoints in your program for
2859special purposes, such as proper handling of @code{longjmp} (in C
2860programs). These internal breakpoints are assigned negative numbers,
2861starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2862You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2863@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2864
2865
6d2ebf8b 2866@node Set Watchpoints
c906108c
SS
2867@subsection Setting watchpoints
2868
2869@cindex setting watchpoints
c906108c
SS
2870You can use a watchpoint to stop execution whenever the value of an
2871expression changes, without having to predict a particular place where
2872this may happen.
2873
82f2d802
EZ
2874@cindex software watchpoints
2875@cindex hardware watchpoints
c906108c 2876Depending on your system, watchpoints may be implemented in software or
2df3850c 2877hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2878program and testing the variable's value each time, which is hundreds of
2879times slower than normal execution. (But this may still be worth it, to
2880catch errors where you have no clue what part of your program is the
2881culprit.)
2882
82f2d802
EZ
2883On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2884x86-based targets, @value{GDBN} includes support for hardware
2885watchpoints, which do not slow down the running of your program.
c906108c
SS
2886
2887@table @code
2888@kindex watch
2889@item watch @var{expr}
2890Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2891is written into by the program and its value changes.
2892
2893@kindex rwatch
2894@item rwatch @var{expr}
09d4efe1
EZ
2895Set a watchpoint that will break when the value of @var{expr} is read
2896by the program.
c906108c
SS
2897
2898@kindex awatch
2899@item awatch @var{expr}
09d4efe1
EZ
2900Set a watchpoint that will break when @var{expr} is either read from
2901or written into by the program.
c906108c
SS
2902
2903@kindex info watchpoints
2904@item info watchpoints
2905This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2906it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2907@end table
2908
2909@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2910watchpoints execute very quickly, and the debugger reports a change in
2911value at the exact instruction where the change occurs. If @value{GDBN}
2912cannot set a hardware watchpoint, it sets a software watchpoint, which
2913executes more slowly and reports the change in value at the next
82f2d802
EZ
2914@emph{statement}, not the instruction, after the change occurs.
2915
82f2d802
EZ
2916@cindex use only software watchpoints
2917You can force @value{GDBN} to use only software watchpoints with the
2918@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2919zero, @value{GDBN} will never try to use hardware watchpoints, even if
2920the underlying system supports them. (Note that hardware-assisted
2921watchpoints that were set @emph{before} setting
2922@code{can-use-hw-watchpoints} to zero will still use the hardware
2923mechanism of watching expressiion values.)
c906108c 2924
9c16f35a
EZ
2925@table @code
2926@item set can-use-hw-watchpoints
2927@kindex set can-use-hw-watchpoints
2928Set whether or not to use hardware watchpoints.
2929
2930@item show can-use-hw-watchpoints
2931@kindex show can-use-hw-watchpoints
2932Show the current mode of using hardware watchpoints.
2933@end table
2934
2935For remote targets, you can restrict the number of hardware
2936watchpoints @value{GDBN} will use, see @ref{set remote
2937hardware-breakpoint-limit}.
2938
c906108c
SS
2939When you issue the @code{watch} command, @value{GDBN} reports
2940
474c8240 2941@smallexample
c906108c 2942Hardware watchpoint @var{num}: @var{expr}
474c8240 2943@end smallexample
c906108c
SS
2944
2945@noindent
2946if it was able to set a hardware watchpoint.
2947
7be570e7
JM
2948Currently, the @code{awatch} and @code{rwatch} commands can only set
2949hardware watchpoints, because accesses to data that don't change the
2950value of the watched expression cannot be detected without examining
2951every instruction as it is being executed, and @value{GDBN} does not do
2952that currently. If @value{GDBN} finds that it is unable to set a
2953hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2954will print a message like this:
2955
2956@smallexample
2957Expression cannot be implemented with read/access watchpoint.
2958@end smallexample
2959
2960Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2961data type of the watched expression is wider than what a hardware
2962watchpoint on the target machine can handle. For example, some systems
2963can only watch regions that are up to 4 bytes wide; on such systems you
2964cannot set hardware watchpoints for an expression that yields a
2965double-precision floating-point number (which is typically 8 bytes
2966wide). As a work-around, it might be possible to break the large region
2967into a series of smaller ones and watch them with separate watchpoints.
2968
2969If you set too many hardware watchpoints, @value{GDBN} might be unable
2970to insert all of them when you resume the execution of your program.
2971Since the precise number of active watchpoints is unknown until such
2972time as the program is about to be resumed, @value{GDBN} might not be
2973able to warn you about this when you set the watchpoints, and the
2974warning will be printed only when the program is resumed:
2975
2976@smallexample
2977Hardware watchpoint @var{num}: Could not insert watchpoint
2978@end smallexample
2979
2980@noindent
2981If this happens, delete or disable some of the watchpoints.
2982
2983The SPARClite DSU will generate traps when a program accesses some data
2984or instruction address that is assigned to the debug registers. For the
2985data addresses, DSU facilitates the @code{watch} command. However the
2986hardware breakpoint registers can only take two data watchpoints, and
2987both watchpoints must be the same kind. For example, you can set two
2988watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2989@strong{or} two with @code{awatch} commands, but you cannot set one
2990watchpoint with one command and the other with a different command.
c906108c
SS
2991@value{GDBN} will reject the command if you try to mix watchpoints.
2992Delete or disable unused watchpoint commands before setting new ones.
2993
2994If you call a function interactively using @code{print} or @code{call},
2df3850c 2995any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2996kind of breakpoint or the call completes.
2997
7be570e7
JM
2998@value{GDBN} automatically deletes watchpoints that watch local
2999(automatic) variables, or expressions that involve such variables, when
3000they go out of scope, that is, when the execution leaves the block in
3001which these variables were defined. In particular, when the program
3002being debugged terminates, @emph{all} local variables go out of scope,
3003and so only watchpoints that watch global variables remain set. If you
3004rerun the program, you will need to set all such watchpoints again. One
3005way of doing that would be to set a code breakpoint at the entry to the
3006@code{main} function and when it breaks, set all the watchpoints.
3007
c906108c
SS
3008@quotation
3009@cindex watchpoints and threads
3010@cindex threads and watchpoints
c906108c
SS
3011@emph{Warning:} In multi-thread programs, watchpoints have only limited
3012usefulness. With the current watchpoint implementation, @value{GDBN}
3013can only watch the value of an expression @emph{in a single thread}. If
3014you are confident that the expression can only change due to the current
3015thread's activity (and if you are also confident that no other thread
3016can become current), then you can use watchpoints as usual. However,
3017@value{GDBN} may not notice when a non-current thread's activity changes
3018the expression.
53a5351d 3019
d4f3574e 3020@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3021@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3022have only limited usefulness. If @value{GDBN} creates a software
3023watchpoint, it can only watch the value of an expression @emph{in a
3024single thread}. If you are confident that the expression can only
3025change due to the current thread's activity (and if you are also
3026confident that no other thread can become current), then you can use
3027software watchpoints as usual. However, @value{GDBN} may not notice
3028when a non-current thread's activity changes the expression. (Hardware
3029watchpoints, in contrast, watch an expression in all threads.)
c906108c 3030@end quotation
c906108c 3031
501eef12
AC
3032@xref{set remote hardware-watchpoint-limit}.
3033
6d2ebf8b 3034@node Set Catchpoints
c906108c 3035@subsection Setting catchpoints
d4f3574e 3036@cindex catchpoints, setting
c906108c
SS
3037@cindex exception handlers
3038@cindex event handling
3039
3040You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3041kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3042shared library. Use the @code{catch} command to set a catchpoint.
3043
3044@table @code
3045@kindex catch
3046@item catch @var{event}
3047Stop when @var{event} occurs. @var{event} can be any of the following:
3048@table @code
3049@item throw
4644b6e3 3050@cindex stop on C@t{++} exceptions
b37052ae 3051The throwing of a C@t{++} exception.
c906108c
SS
3052
3053@item catch
b37052ae 3054The catching of a C@t{++} exception.
c906108c
SS
3055
3056@item exec
4644b6e3 3057@cindex break on fork/exec
c906108c
SS
3058A call to @code{exec}. This is currently only available for HP-UX.
3059
3060@item fork
c906108c
SS
3061A call to @code{fork}. This is currently only available for HP-UX.
3062
3063@item vfork
c906108c
SS
3064A call to @code{vfork}. This is currently only available for HP-UX.
3065
3066@item load
3067@itemx load @var{libname}
4644b6e3 3068@cindex break on load/unload of shared library
c906108c
SS
3069The dynamic loading of any shared library, or the loading of the library
3070@var{libname}. This is currently only available for HP-UX.
3071
3072@item unload
3073@itemx unload @var{libname}
c906108c
SS
3074The unloading of any dynamically loaded shared library, or the unloading
3075of the library @var{libname}. This is currently only available for HP-UX.
3076@end table
3077
3078@item tcatch @var{event}
3079Set a catchpoint that is enabled only for one stop. The catchpoint is
3080automatically deleted after the first time the event is caught.
3081
3082@end table
3083
3084Use the @code{info break} command to list the current catchpoints.
3085
b37052ae 3086There are currently some limitations to C@t{++} exception handling
c906108c
SS
3087(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3088
3089@itemize @bullet
3090@item
3091If you call a function interactively, @value{GDBN} normally returns
3092control to you when the function has finished executing. If the call
3093raises an exception, however, the call may bypass the mechanism that
3094returns control to you and cause your program either to abort or to
3095simply continue running until it hits a breakpoint, catches a signal
3096that @value{GDBN} is listening for, or exits. This is the case even if
3097you set a catchpoint for the exception; catchpoints on exceptions are
3098disabled within interactive calls.
3099
3100@item
3101You cannot raise an exception interactively.
3102
3103@item
3104You cannot install an exception handler interactively.
3105@end itemize
3106
3107@cindex raise exceptions
3108Sometimes @code{catch} is not the best way to debug exception handling:
3109if you need to know exactly where an exception is raised, it is better to
3110stop @emph{before} the exception handler is called, since that way you
3111can see the stack before any unwinding takes place. If you set a
3112breakpoint in an exception handler instead, it may not be easy to find
3113out where the exception was raised.
3114
3115To stop just before an exception handler is called, you need some
b37052ae 3116knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3117raised by calling a library function named @code{__raise_exception}
3118which has the following ANSI C interface:
3119
474c8240 3120@smallexample
c906108c 3121 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3122 @var{id} is the exception identifier. */
3123 void __raise_exception (void **addr, void *id);
474c8240 3124@end smallexample
c906108c
SS
3125
3126@noindent
3127To make the debugger catch all exceptions before any stack
3128unwinding takes place, set a breakpoint on @code{__raise_exception}
3129(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3130
3131With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3132that depends on the value of @var{id}, you can stop your program when
3133a specific exception is raised. You can use multiple conditional
3134breakpoints to stop your program when any of a number of exceptions are
3135raised.
3136
3137
6d2ebf8b 3138@node Delete Breaks
c906108c
SS
3139@subsection Deleting breakpoints
3140
3141@cindex clearing breakpoints, watchpoints, catchpoints
3142@cindex deleting breakpoints, watchpoints, catchpoints
3143It is often necessary to eliminate a breakpoint, watchpoint, or
3144catchpoint once it has done its job and you no longer want your program
3145to stop there. This is called @dfn{deleting} the breakpoint. A
3146breakpoint that has been deleted no longer exists; it is forgotten.
3147
3148With the @code{clear} command you can delete breakpoints according to
3149where they are in your program. With the @code{delete} command you can
3150delete individual breakpoints, watchpoints, or catchpoints by specifying
3151their breakpoint numbers.
3152
3153It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3154automatically ignores breakpoints on the first instruction to be executed
3155when you continue execution without changing the execution address.
3156
3157@table @code
3158@kindex clear
3159@item clear
3160Delete any breakpoints at the next instruction to be executed in the
3161selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3162the innermost frame is selected, this is a good way to delete a
3163breakpoint where your program just stopped.
3164
3165@item clear @var{function}
3166@itemx clear @var{filename}:@var{function}
09d4efe1 3167Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3168
3169@item clear @var{linenum}
3170@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3171Delete any breakpoints set at or within the code of the specified
3172@var{linenum} of the specified @var{filename}.
c906108c
SS
3173
3174@cindex delete breakpoints
3175@kindex delete
41afff9a 3176@kindex d @r{(@code{delete})}
c5394b80
JM
3177@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3178Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3179ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3180breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3181confirm off}). You can abbreviate this command as @code{d}.
3182@end table
3183
6d2ebf8b 3184@node Disabling
c906108c
SS
3185@subsection Disabling breakpoints
3186
4644b6e3 3187@cindex enable/disable a breakpoint
c906108c
SS
3188Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3189prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3190it had been deleted, but remembers the information on the breakpoint so
3191that you can @dfn{enable} it again later.
3192
3193You disable and enable breakpoints, watchpoints, and catchpoints with
3194the @code{enable} and @code{disable} commands, optionally specifying one
3195or more breakpoint numbers as arguments. Use @code{info break} or
3196@code{info watch} to print a list of breakpoints, watchpoints, and
3197catchpoints if you do not know which numbers to use.
3198
3199A breakpoint, watchpoint, or catchpoint can have any of four different
3200states of enablement:
3201
3202@itemize @bullet
3203@item
3204Enabled. The breakpoint stops your program. A breakpoint set
3205with the @code{break} command starts out in this state.
3206@item
3207Disabled. The breakpoint has no effect on your program.
3208@item
3209Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3210disabled.
c906108c
SS
3211@item
3212Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3213immediately after it does so it is deleted permanently. A breakpoint
3214set with the @code{tbreak} command starts out in this state.
c906108c
SS
3215@end itemize
3216
3217You can use the following commands to enable or disable breakpoints,
3218watchpoints, and catchpoints:
3219
3220@table @code
c906108c 3221@kindex disable
41afff9a 3222@kindex dis @r{(@code{disable})}
c5394b80 3223@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3224Disable the specified breakpoints---or all breakpoints, if none are
3225listed. A disabled breakpoint has no effect but is not forgotten. All
3226options such as ignore-counts, conditions and commands are remembered in
3227case the breakpoint is enabled again later. You may abbreviate
3228@code{disable} as @code{dis}.
3229
c906108c 3230@kindex enable
c5394b80 3231@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3232Enable the specified breakpoints (or all defined breakpoints). They
3233become effective once again in stopping your program.
3234
c5394b80 3235@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3236Enable the specified breakpoints temporarily. @value{GDBN} disables any
3237of these breakpoints immediately after stopping your program.
3238
c5394b80 3239@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3240Enable the specified breakpoints to work once, then die. @value{GDBN}
3241deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3242Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3243@end table
3244
d4f3574e
SS
3245@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3246@c confusing: tbreak is also initially enabled.
c906108c
SS
3247Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3248,Setting breakpoints}), breakpoints that you set are initially enabled;
3249subsequently, they become disabled or enabled only when you use one of
3250the commands above. (The command @code{until} can set and delete a
3251breakpoint of its own, but it does not change the state of your other
3252breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3253stepping}.)
3254
6d2ebf8b 3255@node Conditions
c906108c
SS
3256@subsection Break conditions
3257@cindex conditional breakpoints
3258@cindex breakpoint conditions
3259
3260@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3261@c in particular for a watchpoint?
c906108c
SS
3262The simplest sort of breakpoint breaks every time your program reaches a
3263specified place. You can also specify a @dfn{condition} for a
3264breakpoint. A condition is just a Boolean expression in your
3265programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3266a condition evaluates the expression each time your program reaches it,
3267and your program stops only if the condition is @emph{true}.
3268
3269This is the converse of using assertions for program validation; in that
3270situation, you want to stop when the assertion is violated---that is,
3271when the condition is false. In C, if you want to test an assertion expressed
3272by the condition @var{assert}, you should set the condition
3273@samp{! @var{assert}} on the appropriate breakpoint.
3274
3275Conditions are also accepted for watchpoints; you may not need them,
3276since a watchpoint is inspecting the value of an expression anyhow---but
3277it might be simpler, say, to just set a watchpoint on a variable name,
3278and specify a condition that tests whether the new value is an interesting
3279one.
3280
3281Break conditions can have side effects, and may even call functions in
3282your program. This can be useful, for example, to activate functions
3283that log program progress, or to use your own print functions to
3284format special data structures. The effects are completely predictable
3285unless there is another enabled breakpoint at the same address. (In
3286that case, @value{GDBN} might see the other breakpoint first and stop your
3287program without checking the condition of this one.) Note that
d4f3574e
SS
3288breakpoint commands are usually more convenient and flexible than break
3289conditions for the
c906108c
SS
3290purpose of performing side effects when a breakpoint is reached
3291(@pxref{Break Commands, ,Breakpoint command lists}).
3292
3293Break conditions can be specified when a breakpoint is set, by using
3294@samp{if} in the arguments to the @code{break} command. @xref{Set
3295Breaks, ,Setting breakpoints}. They can also be changed at any time
3296with the @code{condition} command.
53a5351d 3297
c906108c
SS
3298You can also use the @code{if} keyword with the @code{watch} command.
3299The @code{catch} command does not recognize the @code{if} keyword;
3300@code{condition} is the only way to impose a further condition on a
3301catchpoint.
c906108c
SS
3302
3303@table @code
3304@kindex condition
3305@item condition @var{bnum} @var{expression}
3306Specify @var{expression} as the break condition for breakpoint,
3307watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3308breakpoint @var{bnum} stops your program only if the value of
3309@var{expression} is true (nonzero, in C). When you use
3310@code{condition}, @value{GDBN} checks @var{expression} immediately for
3311syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3312referents in the context of your breakpoint. If @var{expression} uses
3313symbols not referenced in the context of the breakpoint, @value{GDBN}
3314prints an error message:
3315
474c8240 3316@smallexample
d4f3574e 3317No symbol "foo" in current context.
474c8240 3318@end smallexample
d4f3574e
SS
3319
3320@noindent
c906108c
SS
3321@value{GDBN} does
3322not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3323command (or a command that sets a breakpoint with a condition, like
3324@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3325
3326@item condition @var{bnum}
3327Remove the condition from breakpoint number @var{bnum}. It becomes
3328an ordinary unconditional breakpoint.
3329@end table
3330
3331@cindex ignore count (of breakpoint)
3332A special case of a breakpoint condition is to stop only when the
3333breakpoint has been reached a certain number of times. This is so
3334useful that there is a special way to do it, using the @dfn{ignore
3335count} of the breakpoint. Every breakpoint has an ignore count, which
3336is an integer. Most of the time, the ignore count is zero, and
3337therefore has no effect. But if your program reaches a breakpoint whose
3338ignore count is positive, then instead of stopping, it just decrements
3339the ignore count by one and continues. As a result, if the ignore count
3340value is @var{n}, the breakpoint does not stop the next @var{n} times
3341your program reaches it.
3342
3343@table @code
3344@kindex ignore
3345@item ignore @var{bnum} @var{count}
3346Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3347The next @var{count} times the breakpoint is reached, your program's
3348execution does not stop; other than to decrement the ignore count, @value{GDBN}
3349takes no action.
3350
3351To make the breakpoint stop the next time it is reached, specify
3352a count of zero.
3353
3354When you use @code{continue} to resume execution of your program from a
3355breakpoint, you can specify an ignore count directly as an argument to
3356@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3357Stepping,,Continuing and stepping}.
3358
3359If a breakpoint has a positive ignore count and a condition, the
3360condition is not checked. Once the ignore count reaches zero,
3361@value{GDBN} resumes checking the condition.
3362
3363You could achieve the effect of the ignore count with a condition such
3364as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3365is decremented each time. @xref{Convenience Vars, ,Convenience
3366variables}.
3367@end table
3368
3369Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3370
3371
6d2ebf8b 3372@node Break Commands
c906108c
SS
3373@subsection Breakpoint command lists
3374
3375@cindex breakpoint commands
3376You can give any breakpoint (or watchpoint or catchpoint) a series of
3377commands to execute when your program stops due to that breakpoint. For
3378example, you might want to print the values of certain expressions, or
3379enable other breakpoints.
3380
3381@table @code
3382@kindex commands
3383@kindex end
3384@item commands @r{[}@var{bnum}@r{]}
3385@itemx @dots{} @var{command-list} @dots{}
3386@itemx end
3387Specify a list of commands for breakpoint number @var{bnum}. The commands
3388themselves appear on the following lines. Type a line containing just
3389@code{end} to terminate the commands.
3390
3391To remove all commands from a breakpoint, type @code{commands} and
3392follow it immediately with @code{end}; that is, give no commands.
3393
3394With no @var{bnum} argument, @code{commands} refers to the last
3395breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3396recently encountered).
3397@end table
3398
3399Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3400disabled within a @var{command-list}.
3401
3402You can use breakpoint commands to start your program up again. Simply
3403use the @code{continue} command, or @code{step}, or any other command
3404that resumes execution.
3405
3406Any other commands in the command list, after a command that resumes
3407execution, are ignored. This is because any time you resume execution
3408(even with a simple @code{next} or @code{step}), you may encounter
3409another breakpoint---which could have its own command list, leading to
3410ambiguities about which list to execute.
3411
3412@kindex silent
3413If the first command you specify in a command list is @code{silent}, the
3414usual message about stopping at a breakpoint is not printed. This may
3415be desirable for breakpoints that are to print a specific message and
3416then continue. If none of the remaining commands print anything, you
3417see no sign that the breakpoint was reached. @code{silent} is
3418meaningful only at the beginning of a breakpoint command list.
3419
3420The commands @code{echo}, @code{output}, and @code{printf} allow you to
3421print precisely controlled output, and are often useful in silent
3422breakpoints. @xref{Output, ,Commands for controlled output}.
3423
3424For example, here is how you could use breakpoint commands to print the
3425value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3426
474c8240 3427@smallexample
c906108c
SS
3428break foo if x>0
3429commands
3430silent
3431printf "x is %d\n",x
3432cont
3433end
474c8240 3434@end smallexample
c906108c
SS
3435
3436One application for breakpoint commands is to compensate for one bug so
3437you can test for another. Put a breakpoint just after the erroneous line
3438of code, give it a condition to detect the case in which something
3439erroneous has been done, and give it commands to assign correct values
3440to any variables that need them. End with the @code{continue} command
3441so that your program does not stop, and start with the @code{silent}
3442command so that no output is produced. Here is an example:
3443
474c8240 3444@smallexample
c906108c
SS
3445break 403
3446commands
3447silent
3448set x = y + 4
3449cont
3450end
474c8240 3451@end smallexample
c906108c 3452
6d2ebf8b 3453@node Breakpoint Menus
c906108c
SS
3454@subsection Breakpoint menus
3455@cindex overloading
3456@cindex symbol overloading
3457
b383017d 3458Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3459single function name
c906108c
SS
3460to be defined several times, for application in different contexts.
3461This is called @dfn{overloading}. When a function name is overloaded,
3462@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3463a breakpoint. If you realize this is a problem, you can use
3464something like @samp{break @var{function}(@var{types})} to specify which
3465particular version of the function you want. Otherwise, @value{GDBN} offers
3466you a menu of numbered choices for different possible breakpoints, and
3467waits for your selection with the prompt @samp{>}. The first two
3468options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3469sets a breakpoint at each definition of @var{function}, and typing
3470@kbd{0} aborts the @code{break} command without setting any new
3471breakpoints.
3472
3473For example, the following session excerpt shows an attempt to set a
3474breakpoint at the overloaded symbol @code{String::after}.
3475We choose three particular definitions of that function name:
3476
3477@c FIXME! This is likely to change to show arg type lists, at least
3478@smallexample
3479@group
3480(@value{GDBP}) b String::after
3481[0] cancel
3482[1] all
3483[2] file:String.cc; line number:867
3484[3] file:String.cc; line number:860
3485[4] file:String.cc; line number:875
3486[5] file:String.cc; line number:853
3487[6] file:String.cc; line number:846
3488[7] file:String.cc; line number:735
3489> 2 4 6
3490Breakpoint 1 at 0xb26c: file String.cc, line 867.
3491Breakpoint 2 at 0xb344: file String.cc, line 875.
3492Breakpoint 3 at 0xafcc: file String.cc, line 846.
3493Multiple breakpoints were set.
3494Use the "delete" command to delete unwanted
3495 breakpoints.
3496(@value{GDBP})
3497@end group
3498@end smallexample
c906108c
SS
3499
3500@c @ifclear BARETARGET
6d2ebf8b 3501@node Error in Breakpoints
d4f3574e 3502@subsection ``Cannot insert breakpoints''
c906108c
SS
3503@c
3504@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3505@c
d4f3574e
SS
3506Under some operating systems, breakpoints cannot be used in a program if
3507any other process is running that program. In this situation,
5d161b24 3508attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3509@value{GDBN} to print an error message:
3510
474c8240 3511@smallexample
d4f3574e
SS
3512Cannot insert breakpoints.
3513The same program may be running in another process.
474c8240 3514@end smallexample
d4f3574e
SS
3515
3516When this happens, you have three ways to proceed:
3517
3518@enumerate
3519@item
3520Remove or disable the breakpoints, then continue.
3521
3522@item
5d161b24 3523Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3524name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3525that @value{GDBN} should run your program under that name.
d4f3574e
SS
3526Then start your program again.
3527
3528@item
3529Relink your program so that the text segment is nonsharable, using the
3530linker option @samp{-N}. The operating system limitation may not apply
3531to nonsharable executables.
3532@end enumerate
c906108c
SS
3533@c @end ifclear
3534
d4f3574e
SS
3535A similar message can be printed if you request too many active
3536hardware-assisted breakpoints and watchpoints:
3537
3538@c FIXME: the precise wording of this message may change; the relevant
3539@c source change is not committed yet (Sep 3, 1999).
3540@smallexample
3541Stopped; cannot insert breakpoints.
3542You may have requested too many hardware breakpoints and watchpoints.
3543@end smallexample
3544
3545@noindent
3546This message is printed when you attempt to resume the program, since
3547only then @value{GDBN} knows exactly how many hardware breakpoints and
3548watchpoints it needs to insert.
3549
3550When this message is printed, you need to disable or remove some of the
3551hardware-assisted breakpoints and watchpoints, and then continue.
3552
1485d690
KB
3553@node Breakpoint related warnings
3554@subsection ``Breakpoint address adjusted...''
3555@cindex breakpoint address adjusted
3556
3557Some processor architectures place constraints on the addresses at
3558which breakpoints may be placed. For architectures thus constrained,
3559@value{GDBN} will attempt to adjust the breakpoint's address to comply
3560with the constraints dictated by the architecture.
3561
3562One example of such an architecture is the Fujitsu FR-V. The FR-V is
3563a VLIW architecture in which a number of RISC-like instructions may be
3564bundled together for parallel execution. The FR-V architecture
3565constrains the location of a breakpoint instruction within such a
3566bundle to the instruction with the lowest address. @value{GDBN}
3567honors this constraint by adjusting a breakpoint's address to the
3568first in the bundle.
3569
3570It is not uncommon for optimized code to have bundles which contain
3571instructions from different source statements, thus it may happen that
3572a breakpoint's address will be adjusted from one source statement to
3573another. Since this adjustment may significantly alter @value{GDBN}'s
3574breakpoint related behavior from what the user expects, a warning is
3575printed when the breakpoint is first set and also when the breakpoint
3576is hit.
3577
3578A warning like the one below is printed when setting a breakpoint
3579that's been subject to address adjustment:
3580
3581@smallexample
3582warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3583@end smallexample
3584
3585Such warnings are printed both for user settable and @value{GDBN}'s
3586internal breakpoints. If you see one of these warnings, you should
3587verify that a breakpoint set at the adjusted address will have the
3588desired affect. If not, the breakpoint in question may be removed and
b383017d 3589other breakpoints may be set which will have the desired behavior.
1485d690
KB
3590E.g., it may be sufficient to place the breakpoint at a later
3591instruction. A conditional breakpoint may also be useful in some
3592cases to prevent the breakpoint from triggering too often.
3593
3594@value{GDBN} will also issue a warning when stopping at one of these
3595adjusted breakpoints:
3596
3597@smallexample
3598warning: Breakpoint 1 address previously adjusted from 0x00010414
3599to 0x00010410.
3600@end smallexample
3601
3602When this warning is encountered, it may be too late to take remedial
3603action except in cases where the breakpoint is hit earlier or more
3604frequently than expected.
d4f3574e 3605
6d2ebf8b 3606@node Continuing and Stepping
c906108c
SS
3607@section Continuing and stepping
3608
3609@cindex stepping
3610@cindex continuing
3611@cindex resuming execution
3612@dfn{Continuing} means resuming program execution until your program
3613completes normally. In contrast, @dfn{stepping} means executing just
3614one more ``step'' of your program, where ``step'' may mean either one
3615line of source code, or one machine instruction (depending on what
7a292a7a
SS
3616particular command you use). Either when continuing or when stepping,
3617your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3618it stops due to a signal, you may want to use @code{handle}, or use
3619@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3620
3621@table @code
3622@kindex continue
41afff9a
EZ
3623@kindex c @r{(@code{continue})}
3624@kindex fg @r{(resume foreground execution)}
c906108c
SS
3625@item continue @r{[}@var{ignore-count}@r{]}
3626@itemx c @r{[}@var{ignore-count}@r{]}
3627@itemx fg @r{[}@var{ignore-count}@r{]}
3628Resume program execution, at the address where your program last stopped;
3629any breakpoints set at that address are bypassed. The optional argument
3630@var{ignore-count} allows you to specify a further number of times to
3631ignore a breakpoint at this location; its effect is like that of
3632@code{ignore} (@pxref{Conditions, ,Break conditions}).
3633
3634The argument @var{ignore-count} is meaningful only when your program
3635stopped due to a breakpoint. At other times, the argument to
3636@code{continue} is ignored.
3637
d4f3574e
SS
3638The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3639debugged program is deemed to be the foreground program) are provided
3640purely for convenience, and have exactly the same behavior as
3641@code{continue}.
c906108c
SS
3642@end table
3643
3644To resume execution at a different place, you can use @code{return}
3645(@pxref{Returning, ,Returning from a function}) to go back to the
3646calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3647different address}) to go to an arbitrary location in your program.
3648
3649A typical technique for using stepping is to set a breakpoint
3650(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3651beginning of the function or the section of your program where a problem
3652is believed to lie, run your program until it stops at that breakpoint,
3653and then step through the suspect area, examining the variables that are
3654interesting, until you see the problem happen.
3655
3656@table @code
3657@kindex step
41afff9a 3658@kindex s @r{(@code{step})}
c906108c
SS
3659@item step
3660Continue running your program until control reaches a different source
3661line, then stop it and return control to @value{GDBN}. This command is
3662abbreviated @code{s}.
3663
3664@quotation
3665@c "without debugging information" is imprecise; actually "without line
3666@c numbers in the debugging information". (gcc -g1 has debugging info but
3667@c not line numbers). But it seems complex to try to make that
3668@c distinction here.
3669@emph{Warning:} If you use the @code{step} command while control is
3670within a function that was compiled without debugging information,
3671execution proceeds until control reaches a function that does have
3672debugging information. Likewise, it will not step into a function which
3673is compiled without debugging information. To step through functions
3674without debugging information, use the @code{stepi} command, described
3675below.
3676@end quotation
3677
4a92d011
EZ
3678The @code{step} command only stops at the first instruction of a source
3679line. This prevents the multiple stops that could otherwise occur in
3680@code{switch} statements, @code{for} loops, etc. @code{step} continues
3681to stop if a function that has debugging information is called within
3682the line. In other words, @code{step} @emph{steps inside} any functions
3683called within the line.
c906108c 3684
d4f3574e
SS
3685Also, the @code{step} command only enters a function if there is line
3686number information for the function. Otherwise it acts like the
5d161b24 3687@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3688on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3689was any debugging information about the routine.
c906108c
SS
3690
3691@item step @var{count}
3692Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3693breakpoint is reached, or a signal not related to stepping occurs before
3694@var{count} steps, stepping stops right away.
c906108c
SS
3695
3696@kindex next
41afff9a 3697@kindex n @r{(@code{next})}
c906108c
SS
3698@item next @r{[}@var{count}@r{]}
3699Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3700This is similar to @code{step}, but function calls that appear within
3701the line of code are executed without stopping. Execution stops when
3702control reaches a different line of code at the original stack level
3703that was executing when you gave the @code{next} command. This command
3704is abbreviated @code{n}.
c906108c
SS
3705
3706An argument @var{count} is a repeat count, as for @code{step}.
3707
3708
3709@c FIX ME!! Do we delete this, or is there a way it fits in with
3710@c the following paragraph? --- Vctoria
3711@c
3712@c @code{next} within a function that lacks debugging information acts like
3713@c @code{step}, but any function calls appearing within the code of the
3714@c function are executed without stopping.
3715
d4f3574e
SS
3716The @code{next} command only stops at the first instruction of a
3717source line. This prevents multiple stops that could otherwise occur in
4a92d011 3718@code{switch} statements, @code{for} loops, etc.
c906108c 3719
b90a5f51
CF
3720@kindex set step-mode
3721@item set step-mode
3722@cindex functions without line info, and stepping
3723@cindex stepping into functions with no line info
3724@itemx set step-mode on
4a92d011 3725The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3726stop at the first instruction of a function which contains no debug line
3727information rather than stepping over it.
3728
4a92d011
EZ
3729This is useful in cases where you may be interested in inspecting the
3730machine instructions of a function which has no symbolic info and do not
3731want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3732
3733@item set step-mode off
4a92d011 3734Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3735debug information. This is the default.
3736
9c16f35a
EZ
3737@item show step-mode
3738Show whether @value{GDBN} will stop in or step over functions without
3739source line debug information.
3740
c906108c
SS
3741@kindex finish
3742@item finish
3743Continue running until just after function in the selected stack frame
3744returns. Print the returned value (if any).
3745
3746Contrast this with the @code{return} command (@pxref{Returning,
3747,Returning from a function}).
3748
3749@kindex until
41afff9a 3750@kindex u @r{(@code{until})}
09d4efe1 3751@cindex run until specified location
c906108c
SS
3752@item until
3753@itemx u
3754Continue running until a source line past the current line, in the
3755current stack frame, is reached. This command is used to avoid single
3756stepping through a loop more than once. It is like the @code{next}
3757command, except that when @code{until} encounters a jump, it
3758automatically continues execution until the program counter is greater
3759than the address of the jump.
3760
3761This means that when you reach the end of a loop after single stepping
3762though it, @code{until} makes your program continue execution until it
3763exits the loop. In contrast, a @code{next} command at the end of a loop
3764simply steps back to the beginning of the loop, which forces you to step
3765through the next iteration.
3766
3767@code{until} always stops your program if it attempts to exit the current
3768stack frame.
3769
3770@code{until} may produce somewhat counterintuitive results if the order
3771of machine code does not match the order of the source lines. For
3772example, in the following excerpt from a debugging session, the @code{f}
3773(@code{frame}) command shows that execution is stopped at line
3774@code{206}; yet when we use @code{until}, we get to line @code{195}:
3775
474c8240 3776@smallexample
c906108c
SS
3777(@value{GDBP}) f
3778#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3779206 expand_input();
3780(@value{GDBP}) until
3781195 for ( ; argc > 0; NEXTARG) @{
474c8240 3782@end smallexample
c906108c
SS
3783
3784This happened because, for execution efficiency, the compiler had
3785generated code for the loop closure test at the end, rather than the
3786start, of the loop---even though the test in a C @code{for}-loop is
3787written before the body of the loop. The @code{until} command appeared
3788to step back to the beginning of the loop when it advanced to this
3789expression; however, it has not really gone to an earlier
3790statement---not in terms of the actual machine code.
3791
3792@code{until} with no argument works by means of single
3793instruction stepping, and hence is slower than @code{until} with an
3794argument.
3795
3796@item until @var{location}
3797@itemx u @var{location}
3798Continue running your program until either the specified location is
3799reached, or the current stack frame returns. @var{location} is any of
3800the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3801,Setting breakpoints}). This form of the command uses breakpoints, and
3802hence is quicker than @code{until} without an argument. The specified
3803location is actually reached only if it is in the current frame. This
3804implies that @code{until} can be used to skip over recursive function
3805invocations. For instance in the code below, if the current location is
3806line @code{96}, issuing @code{until 99} will execute the program up to
3807line @code{99} in the same invocation of factorial, i.e. after the inner
3808invocations have returned.
3809
3810@smallexample
381194 int factorial (int value)
381295 @{
381396 if (value > 1) @{
381497 value *= factorial (value - 1);
381598 @}
381699 return (value);
3817100 @}
3818@end smallexample
3819
3820
3821@kindex advance @var{location}
3822@itemx advance @var{location}
09d4efe1
EZ
3823Continue running the program up to the given @var{location}. An argument is
3824required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3825command. Execution will also stop upon exit from the current stack
3826frame. This command is similar to @code{until}, but @code{advance} will
3827not skip over recursive function calls, and the target location doesn't
3828have to be in the same frame as the current one.
3829
c906108c
SS
3830
3831@kindex stepi
41afff9a 3832@kindex si @r{(@code{stepi})}
c906108c 3833@item stepi
96a2c332 3834@itemx stepi @var{arg}
c906108c
SS
3835@itemx si
3836Execute one machine instruction, then stop and return to the debugger.
3837
3838It is often useful to do @samp{display/i $pc} when stepping by machine
3839instructions. This makes @value{GDBN} automatically display the next
3840instruction to be executed, each time your program stops. @xref{Auto
3841Display,, Automatic display}.
3842
3843An argument is a repeat count, as in @code{step}.
3844
3845@need 750
3846@kindex nexti
41afff9a 3847@kindex ni @r{(@code{nexti})}
c906108c 3848@item nexti
96a2c332 3849@itemx nexti @var{arg}
c906108c
SS
3850@itemx ni
3851Execute one machine instruction, but if it is a function call,
3852proceed until the function returns.
3853
3854An argument is a repeat count, as in @code{next}.
3855@end table
3856
6d2ebf8b 3857@node Signals
c906108c
SS
3858@section Signals
3859@cindex signals
3860
3861A signal is an asynchronous event that can happen in a program. The
3862operating system defines the possible kinds of signals, and gives each
3863kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3864signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3865@code{SIGSEGV} is the signal a program gets from referencing a place in
3866memory far away from all the areas in use; @code{SIGALRM} occurs when
3867the alarm clock timer goes off (which happens only if your program has
3868requested an alarm).
3869
3870@cindex fatal signals
3871Some signals, including @code{SIGALRM}, are a normal part of the
3872functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3873errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3874program has not specified in advance some other way to handle the signal.
3875@code{SIGINT} does not indicate an error in your program, but it is normally
3876fatal so it can carry out the purpose of the interrupt: to kill the program.
3877
3878@value{GDBN} has the ability to detect any occurrence of a signal in your
3879program. You can tell @value{GDBN} in advance what to do for each kind of
3880signal.
3881
3882@cindex handling signals
24f93129
EZ
3883Normally, @value{GDBN} is set up to let the non-erroneous signals like
3884@code{SIGALRM} be silently passed to your program
3885(so as not to interfere with their role in the program's functioning)
c906108c
SS
3886but to stop your program immediately whenever an error signal happens.
3887You can change these settings with the @code{handle} command.
3888
3889@table @code
3890@kindex info signals
09d4efe1 3891@kindex info handle
c906108c 3892@item info signals
96a2c332 3893@itemx info handle
c906108c
SS
3894Print a table of all the kinds of signals and how @value{GDBN} has been told to
3895handle each one. You can use this to see the signal numbers of all
3896the defined types of signals.
3897
d4f3574e 3898@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3899
3900@kindex handle
3901@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3902Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3903can be the number of a signal or its name (with or without the
24f93129 3904@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3905@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3906known signals. The @var{keywords} say what change to make.
c906108c
SS
3907@end table
3908
3909@c @group
3910The keywords allowed by the @code{handle} command can be abbreviated.
3911Their full names are:
3912
3913@table @code
3914@item nostop
3915@value{GDBN} should not stop your program when this signal happens. It may
3916still print a message telling you that the signal has come in.
3917
3918@item stop
3919@value{GDBN} should stop your program when this signal happens. This implies
3920the @code{print} keyword as well.
3921
3922@item print
3923@value{GDBN} should print a message when this signal happens.
3924
3925@item noprint
3926@value{GDBN} should not mention the occurrence of the signal at all. This
3927implies the @code{nostop} keyword as well.
3928
3929@item pass
5ece1a18 3930@itemx noignore
c906108c
SS
3931@value{GDBN} should allow your program to see this signal; your program
3932can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3933and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3934
3935@item nopass
5ece1a18 3936@itemx ignore
c906108c 3937@value{GDBN} should not allow your program to see this signal.
5ece1a18 3938@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3939@end table
3940@c @end group
3941
d4f3574e
SS
3942When a signal stops your program, the signal is not visible to the
3943program until you
c906108c
SS
3944continue. Your program sees the signal then, if @code{pass} is in
3945effect for the signal in question @emph{at that time}. In other words,
3946after @value{GDBN} reports a signal, you can use the @code{handle}
3947command with @code{pass} or @code{nopass} to control whether your
3948program sees that signal when you continue.
3949
24f93129
EZ
3950The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3951non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3952@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3953erroneous signals.
3954
c906108c
SS
3955You can also use the @code{signal} command to prevent your program from
3956seeing a signal, or cause it to see a signal it normally would not see,
3957or to give it any signal at any time. For example, if your program stopped
3958due to some sort of memory reference error, you might store correct
3959values into the erroneous variables and continue, hoping to see more
3960execution; but your program would probably terminate immediately as
3961a result of the fatal signal once it saw the signal. To prevent this,
3962you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3963program a signal}.
c906108c 3964
6d2ebf8b 3965@node Thread Stops
c906108c
SS
3966@section Stopping and starting multi-thread programs
3967
3968When your program has multiple threads (@pxref{Threads,, Debugging
3969programs with multiple threads}), you can choose whether to set
3970breakpoints on all threads, or on a particular thread.
3971
3972@table @code
3973@cindex breakpoints and threads
3974@cindex thread breakpoints
3975@kindex break @dots{} thread @var{threadno}
3976@item break @var{linespec} thread @var{threadno}
3977@itemx break @var{linespec} thread @var{threadno} if @dots{}
3978@var{linespec} specifies source lines; there are several ways of
3979writing them, but the effect is always to specify some source line.
3980
3981Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3982to specify that you only want @value{GDBN} to stop the program when a
3983particular thread reaches this breakpoint. @var{threadno} is one of the
3984numeric thread identifiers assigned by @value{GDBN}, shown in the first
3985column of the @samp{info threads} display.
3986
3987If you do not specify @samp{thread @var{threadno}} when you set a
3988breakpoint, the breakpoint applies to @emph{all} threads of your
3989program.
3990
3991You can use the @code{thread} qualifier on conditional breakpoints as
3992well; in this case, place @samp{thread @var{threadno}} before the
3993breakpoint condition, like this:
3994
3995@smallexample
2df3850c 3996(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3997@end smallexample
3998
3999@end table
4000
4001@cindex stopped threads
4002@cindex threads, stopped
4003Whenever your program stops under @value{GDBN} for any reason,
4004@emph{all} threads of execution stop, not just the current thread. This
4005allows you to examine the overall state of the program, including
4006switching between threads, without worrying that things may change
4007underfoot.
4008
36d86913
MC
4009@cindex thread breakpoints and system calls
4010@cindex system calls and thread breakpoints
4011@cindex premature return from system calls
4012There is an unfortunate side effect. If one thread stops for a
4013breakpoint, or for some other reason, and another thread is blocked in a
4014system call, then the system call may return prematurely. This is a
4015consequence of the interaction between multiple threads and the signals
4016that @value{GDBN} uses to implement breakpoints and other events that
4017stop execution.
4018
4019To handle this problem, your program should check the return value of
4020each system call and react appropriately. This is good programming
4021style anyways.
4022
4023For example, do not write code like this:
4024
4025@smallexample
4026 sleep (10);
4027@end smallexample
4028
4029The call to @code{sleep} will return early if a different thread stops
4030at a breakpoint or for some other reason.
4031
4032Instead, write this:
4033
4034@smallexample
4035 int unslept = 10;
4036 while (unslept > 0)
4037 unslept = sleep (unslept);
4038@end smallexample
4039
4040A system call is allowed to return early, so the system is still
4041conforming to its specification. But @value{GDBN} does cause your
4042multi-threaded program to behave differently than it would without
4043@value{GDBN}.
4044
4045Also, @value{GDBN} uses internal breakpoints in the thread library to
4046monitor certain events such as thread creation and thread destruction.
4047When such an event happens, a system call in another thread may return
4048prematurely, even though your program does not appear to stop.
4049
c906108c
SS
4050@cindex continuing threads
4051@cindex threads, continuing
4052Conversely, whenever you restart the program, @emph{all} threads start
4053executing. @emph{This is true even when single-stepping} with commands
5d161b24 4054like @code{step} or @code{next}.
c906108c
SS
4055
4056In particular, @value{GDBN} cannot single-step all threads in lockstep.
4057Since thread scheduling is up to your debugging target's operating
4058system (not controlled by @value{GDBN}), other threads may
4059execute more than one statement while the current thread completes a
4060single step. Moreover, in general other threads stop in the middle of a
4061statement, rather than at a clean statement boundary, when the program
4062stops.
4063
4064You might even find your program stopped in another thread after
4065continuing or even single-stepping. This happens whenever some other
4066thread runs into a breakpoint, a signal, or an exception before the
4067first thread completes whatever you requested.
4068
4069On some OSes, you can lock the OS scheduler and thus allow only a single
4070thread to run.
4071
4072@table @code
4073@item set scheduler-locking @var{mode}
9c16f35a
EZ
4074@cindex scheduler locking mode
4075@cindex lock scheduler
c906108c
SS
4076Set the scheduler locking mode. If it is @code{off}, then there is no
4077locking and any thread may run at any time. If @code{on}, then only the
4078current thread may run when the inferior is resumed. The @code{step}
4079mode optimizes for single-stepping. It stops other threads from
4080``seizing the prompt'' by preempting the current thread while you are
4081stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4082when you step. They are more likely to run when you @samp{next} over a
c906108c 4083function call, and they are completely free to run when you use commands
d4f3574e 4084like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4085thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4086@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4087
4088@item show scheduler-locking
4089Display the current scheduler locking mode.
4090@end table
4091
c906108c 4092
6d2ebf8b 4093@node Stack
c906108c
SS
4094@chapter Examining the Stack
4095
4096When your program has stopped, the first thing you need to know is where it
4097stopped and how it got there.
4098
4099@cindex call stack
5d161b24
DB
4100Each time your program performs a function call, information about the call
4101is generated.
4102That information includes the location of the call in your program,
4103the arguments of the call,
c906108c 4104and the local variables of the function being called.
5d161b24 4105The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4106The stack frames are allocated in a region of memory called the @dfn{call
4107stack}.
4108
4109When your program stops, the @value{GDBN} commands for examining the
4110stack allow you to see all of this information.
4111
4112@cindex selected frame
4113One of the stack frames is @dfn{selected} by @value{GDBN} and many
4114@value{GDBN} commands refer implicitly to the selected frame. In
4115particular, whenever you ask @value{GDBN} for the value of a variable in
4116your program, the value is found in the selected frame. There are
4117special @value{GDBN} commands to select whichever frame you are
4118interested in. @xref{Selection, ,Selecting a frame}.
4119
4120When your program stops, @value{GDBN} automatically selects the
5d161b24 4121currently executing frame and describes it briefly, similar to the
c906108c
SS
4122@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4123
4124@menu
4125* Frames:: Stack frames
4126* Backtrace:: Backtraces
4127* Selection:: Selecting a frame
4128* Frame Info:: Information on a frame
c906108c
SS
4129
4130@end menu
4131
6d2ebf8b 4132@node Frames
c906108c
SS
4133@section Stack frames
4134
d4f3574e 4135@cindex frame, definition
c906108c
SS
4136@cindex stack frame
4137The call stack is divided up into contiguous pieces called @dfn{stack
4138frames}, or @dfn{frames} for short; each frame is the data associated
4139with one call to one function. The frame contains the arguments given
4140to the function, the function's local variables, and the address at
4141which the function is executing.
4142
4143@cindex initial frame
4144@cindex outermost frame
4145@cindex innermost frame
4146When your program is started, the stack has only one frame, that of the
4147function @code{main}. This is called the @dfn{initial} frame or the
4148@dfn{outermost} frame. Each time a function is called, a new frame is
4149made. Each time a function returns, the frame for that function invocation
4150is eliminated. If a function is recursive, there can be many frames for
4151the same function. The frame for the function in which execution is
4152actually occurring is called the @dfn{innermost} frame. This is the most
4153recently created of all the stack frames that still exist.
4154
4155@cindex frame pointer
4156Inside your program, stack frames are identified by their addresses. A
4157stack frame consists of many bytes, each of which has its own address; each
4158kind of computer has a convention for choosing one byte whose
4159address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4160in a register called the @dfn{frame pointer register}
4161(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4162
4163@cindex frame number
4164@value{GDBN} assigns numbers to all existing stack frames, starting with
4165zero for the innermost frame, one for the frame that called it,
4166and so on upward. These numbers do not really exist in your program;
4167they are assigned by @value{GDBN} to give you a way of designating stack
4168frames in @value{GDBN} commands.
4169
6d2ebf8b
SS
4170@c The -fomit-frame-pointer below perennially causes hbox overflow
4171@c underflow problems.
c906108c
SS
4172@cindex frameless execution
4173Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4174without stack frames. (For example, the @value{GCC} option
474c8240 4175@smallexample
6d2ebf8b 4176@samp{-fomit-frame-pointer}
474c8240 4177@end smallexample
6d2ebf8b 4178generates functions without a frame.)
c906108c
SS
4179This is occasionally done with heavily used library functions to save
4180the frame setup time. @value{GDBN} has limited facilities for dealing
4181with these function invocations. If the innermost function invocation
4182has no stack frame, @value{GDBN} nevertheless regards it as though
4183it had a separate frame, which is numbered zero as usual, allowing
4184correct tracing of the function call chain. However, @value{GDBN} has
4185no provision for frameless functions elsewhere in the stack.
4186
4187@table @code
d4f3574e 4188@kindex frame@r{, command}
41afff9a 4189@cindex current stack frame
c906108c 4190@item frame @var{args}
5d161b24 4191The @code{frame} command allows you to move from one stack frame to another,
c906108c 4192and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4193address of the frame or the stack frame number. Without an argument,
4194@code{frame} prints the current stack frame.
c906108c
SS
4195
4196@kindex select-frame
41afff9a 4197@cindex selecting frame silently
c906108c
SS
4198@item select-frame
4199The @code{select-frame} command allows you to move from one stack frame
4200to another without printing the frame. This is the silent version of
4201@code{frame}.
4202@end table
4203
6d2ebf8b 4204@node Backtrace
c906108c
SS
4205@section Backtraces
4206
09d4efe1
EZ
4207@cindex traceback
4208@cindex call stack traces
c906108c
SS
4209A backtrace is a summary of how your program got where it is. It shows one
4210line per frame, for many frames, starting with the currently executing
4211frame (frame zero), followed by its caller (frame one), and on up the
4212stack.
4213
4214@table @code
4215@kindex backtrace
41afff9a 4216@kindex bt @r{(@code{backtrace})}
c906108c
SS
4217@item backtrace
4218@itemx bt
4219Print a backtrace of the entire stack: one line per frame for all
4220frames in the stack.
4221
4222You can stop the backtrace at any time by typing the system interrupt
4223character, normally @kbd{C-c}.
4224
4225@item backtrace @var{n}
4226@itemx bt @var{n}
4227Similar, but print only the innermost @var{n} frames.
4228
4229@item backtrace -@var{n}
4230@itemx bt -@var{n}
4231Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4232
4233@item backtrace full
4234Print the values of the local variables also.
4235@itemx bt full
c906108c
SS
4236@end table
4237
4238@kindex where
4239@kindex info stack
c906108c
SS
4240The names @code{where} and @code{info stack} (abbreviated @code{info s})
4241are additional aliases for @code{backtrace}.
4242
4243Each line in the backtrace shows the frame number and the function name.
4244The program counter value is also shown---unless you use @code{set
4245print address off}. The backtrace also shows the source file name and
4246line number, as well as the arguments to the function. The program
4247counter value is omitted if it is at the beginning of the code for that
4248line number.
4249
4250Here is an example of a backtrace. It was made with the command
4251@samp{bt 3}, so it shows the innermost three frames.
4252
4253@smallexample
4254@group
5d161b24 4255#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4256 at builtin.c:993
4257#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4258#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4259 at macro.c:71
4260(More stack frames follow...)
4261@end group
4262@end smallexample
4263
4264@noindent
4265The display for frame zero does not begin with a program counter
4266value, indicating that your program has stopped at the beginning of the
4267code for line @code{993} of @code{builtin.c}.
4268
18999be5
EZ
4269@cindex value optimized out, in backtrace
4270@cindex function call arguments, optimized out
4271If your program was compiled with optimizations, some compilers will
4272optimize away arguments passed to functions if those arguments are
4273never used after the call. Such optimizations generate code that
4274passes arguments through registers, but doesn't store those arguments
4275in the stack frame. @value{GDBN} has no way of displaying such
4276arguments in stack frames other than the innermost one. Here's what
4277such a backtrace might look like:
4278
4279@smallexample
4280@group
4281#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4282 at builtin.c:993
4283#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4284#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4285 at macro.c:71
4286(More stack frames follow...)
4287@end group
4288@end smallexample
4289
4290@noindent
4291The values of arguments that were not saved in their stack frames are
4292shown as @samp{<value optimized out>}.
4293
4294If you need to display the values of such optimized-out arguments,
4295either deduce that from other variables whose values depend on the one
4296you are interested in, or recompile without optimizations.
4297
a8f24a35
EZ
4298@cindex backtrace beyond @code{main} function
4299@cindex program entry point
4300@cindex startup code, and backtrace
25d29d70
AC
4301Most programs have a standard user entry point---a place where system
4302libraries and startup code transition into user code. For C this is
d416eeec
EZ
4303@code{main}@footnote{
4304Note that embedded programs (the so-called ``free-standing''
4305environment) are not required to have a @code{main} function as the
4306entry point. They could even have multiple entry points.}.
4307When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4308it will terminate the backtrace, to avoid tracing into highly
4309system-specific (and generally uninteresting) code.
4310
4311If you need to examine the startup code, or limit the number of levels
4312in a backtrace, you can change this behavior:
95f90d25
DJ
4313
4314@table @code
25d29d70
AC
4315@item set backtrace past-main
4316@itemx set backtrace past-main on
4644b6e3 4317@kindex set backtrace
25d29d70
AC
4318Backtraces will continue past the user entry point.
4319
4320@item set backtrace past-main off
95f90d25
DJ
4321Backtraces will stop when they encounter the user entry point. This is the
4322default.
4323
25d29d70 4324@item show backtrace past-main
4644b6e3 4325@kindex show backtrace
25d29d70
AC
4326Display the current user entry point backtrace policy.
4327
2315ffec
RC
4328@item set backtrace past-entry
4329@itemx set backtrace past-entry on
a8f24a35 4330Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4331This entry point is encoded by the linker when the application is built,
4332and is likely before the user entry point @code{main} (or equivalent) is called.
4333
4334@item set backtrace past-entry off
4335Backtraces will stop when they encouter the internal entry point of an
4336application. This is the default.
4337
4338@item show backtrace past-entry
4339Display the current internal entry point backtrace policy.
4340
25d29d70
AC
4341@item set backtrace limit @var{n}
4342@itemx set backtrace limit 0
4343@cindex backtrace limit
4344Limit the backtrace to @var{n} levels. A value of zero means
4345unlimited.
95f90d25 4346
25d29d70
AC
4347@item show backtrace limit
4348Display the current limit on backtrace levels.
95f90d25
DJ
4349@end table
4350
6d2ebf8b 4351@node Selection
c906108c
SS
4352@section Selecting a frame
4353
4354Most commands for examining the stack and other data in your program work on
4355whichever stack frame is selected at the moment. Here are the commands for
4356selecting a stack frame; all of them finish by printing a brief description
4357of the stack frame just selected.
4358
4359@table @code
d4f3574e 4360@kindex frame@r{, selecting}
41afff9a 4361@kindex f @r{(@code{frame})}
c906108c
SS
4362@item frame @var{n}
4363@itemx f @var{n}
4364Select frame number @var{n}. Recall that frame zero is the innermost
4365(currently executing) frame, frame one is the frame that called the
4366innermost one, and so on. The highest-numbered frame is the one for
4367@code{main}.
4368
4369@item frame @var{addr}
4370@itemx f @var{addr}
4371Select the frame at address @var{addr}. This is useful mainly if the
4372chaining of stack frames has been damaged by a bug, making it
4373impossible for @value{GDBN} to assign numbers properly to all frames. In
4374addition, this can be useful when your program has multiple stacks and
4375switches between them.
4376
c906108c
SS
4377On the SPARC architecture, @code{frame} needs two addresses to
4378select an arbitrary frame: a frame pointer and a stack pointer.
4379
4380On the MIPS and Alpha architecture, it needs two addresses: a stack
4381pointer and a program counter.
4382
4383On the 29k architecture, it needs three addresses: a register stack
4384pointer, a program counter, and a memory stack pointer.
4385@c note to future updaters: this is conditioned on a flag
4386@c SETUP_ARBITRARY_FRAME in the tm-*.h files. The above is up to date
4387@c as of 27 Jan 1994.
c906108c
SS
4388
4389@kindex up
4390@item up @var{n}
4391Move @var{n} frames up the stack. For positive numbers @var{n}, this
4392advances toward the outermost frame, to higher frame numbers, to frames
4393that have existed longer. @var{n} defaults to one.
4394
4395@kindex down
41afff9a 4396@kindex do @r{(@code{down})}
c906108c
SS
4397@item down @var{n}
4398Move @var{n} frames down the stack. For positive numbers @var{n}, this
4399advances toward the innermost frame, to lower frame numbers, to frames
4400that were created more recently. @var{n} defaults to one. You may
4401abbreviate @code{down} as @code{do}.
4402@end table
4403
4404All of these commands end by printing two lines of output describing the
4405frame. The first line shows the frame number, the function name, the
4406arguments, and the source file and line number of execution in that
5d161b24 4407frame. The second line shows the text of that source line.
c906108c
SS
4408
4409@need 1000
4410For example:
4411
4412@smallexample
4413@group
4414(@value{GDBP}) up
4415#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4416 at env.c:10
441710 read_input_file (argv[i]);
4418@end group
4419@end smallexample
4420
4421After such a printout, the @code{list} command with no arguments
4422prints ten lines centered on the point of execution in the frame.
87885426
FN
4423You can also edit the program at the point of execution with your favorite
4424editing program by typing @code{edit}.
4425@xref{List, ,Printing source lines},
4426for details.
c906108c
SS
4427
4428@table @code
4429@kindex down-silently
4430@kindex up-silently
4431@item up-silently @var{n}
4432@itemx down-silently @var{n}
4433These two commands are variants of @code{up} and @code{down},
4434respectively; they differ in that they do their work silently, without
4435causing display of the new frame. They are intended primarily for use
4436in @value{GDBN} command scripts, where the output might be unnecessary and
4437distracting.
4438@end table
4439
6d2ebf8b 4440@node Frame Info
c906108c
SS
4441@section Information about a frame
4442
4443There are several other commands to print information about the selected
4444stack frame.
4445
4446@table @code
4447@item frame
4448@itemx f
4449When used without any argument, this command does not change which
4450frame is selected, but prints a brief description of the currently
4451selected stack frame. It can be abbreviated @code{f}. With an
4452argument, this command is used to select a stack frame.
4453@xref{Selection, ,Selecting a frame}.
4454
4455@kindex info frame
41afff9a 4456@kindex info f @r{(@code{info frame})}
c906108c
SS
4457@item info frame
4458@itemx info f
4459This command prints a verbose description of the selected stack frame,
4460including:
4461
4462@itemize @bullet
5d161b24
DB
4463@item
4464the address of the frame
c906108c
SS
4465@item
4466the address of the next frame down (called by this frame)
4467@item
4468the address of the next frame up (caller of this frame)
4469@item
4470the language in which the source code corresponding to this frame is written
4471@item
4472the address of the frame's arguments
4473@item
d4f3574e
SS
4474the address of the frame's local variables
4475@item
c906108c
SS
4476the program counter saved in it (the address of execution in the caller frame)
4477@item
4478which registers were saved in the frame
4479@end itemize
4480
4481@noindent The verbose description is useful when
4482something has gone wrong that has made the stack format fail to fit
4483the usual conventions.
4484
4485@item info frame @var{addr}
4486@itemx info f @var{addr}
4487Print a verbose description of the frame at address @var{addr}, without
4488selecting that frame. The selected frame remains unchanged by this
4489command. This requires the same kind of address (more than one for some
4490architectures) that you specify in the @code{frame} command.
4491@xref{Selection, ,Selecting a frame}.
4492
4493@kindex info args
4494@item info args
4495Print the arguments of the selected frame, each on a separate line.
4496
4497@item info locals
4498@kindex info locals
4499Print the local variables of the selected frame, each on a separate
4500line. These are all variables (declared either static or automatic)
4501accessible at the point of execution of the selected frame.
4502
c906108c 4503@kindex info catch
d4f3574e
SS
4504@cindex catch exceptions, list active handlers
4505@cindex exception handlers, how to list
c906108c
SS
4506@item info catch
4507Print a list of all the exception handlers that are active in the
4508current stack frame at the current point of execution. To see other
4509exception handlers, visit the associated frame (using the @code{up},
4510@code{down}, or @code{frame} commands); then type @code{info catch}.
4511@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4512
c906108c
SS
4513@end table
4514
c906108c 4515
6d2ebf8b 4516@node Source
c906108c
SS
4517@chapter Examining Source Files
4518
4519@value{GDBN} can print parts of your program's source, since the debugging
4520information recorded in the program tells @value{GDBN} what source files were
4521used to build it. When your program stops, @value{GDBN} spontaneously prints
4522the line where it stopped. Likewise, when you select a stack frame
4523(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4524execution in that frame has stopped. You can print other portions of
4525source files by explicit command.
4526
7a292a7a 4527If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4528prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4529@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4530
4531@menu
4532* List:: Printing source lines
87885426 4533* Edit:: Editing source files
c906108c 4534* Search:: Searching source files
c906108c
SS
4535* Source Path:: Specifying source directories
4536* Machine Code:: Source and machine code
4537@end menu
4538
6d2ebf8b 4539@node List
c906108c
SS
4540@section Printing source lines
4541
4542@kindex list
41afff9a 4543@kindex l @r{(@code{list})}
c906108c 4544To print lines from a source file, use the @code{list} command
5d161b24 4545(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4546There are several ways to specify what part of the file you want to print.
4547
4548Here are the forms of the @code{list} command most commonly used:
4549
4550@table @code
4551@item list @var{linenum}
4552Print lines centered around line number @var{linenum} in the
4553current source file.
4554
4555@item list @var{function}
4556Print lines centered around the beginning of function
4557@var{function}.
4558
4559@item list
4560Print more lines. If the last lines printed were printed with a
4561@code{list} command, this prints lines following the last lines
4562printed; however, if the last line printed was a solitary line printed
4563as part of displaying a stack frame (@pxref{Stack, ,Examining the
4564Stack}), this prints lines centered around that line.
4565
4566@item list -
4567Print lines just before the lines last printed.
4568@end table
4569
9c16f35a 4570@cindex @code{list}, how many lines to display
c906108c
SS
4571By default, @value{GDBN} prints ten source lines with any of these forms of
4572the @code{list} command. You can change this using @code{set listsize}:
4573
4574@table @code
4575@kindex set listsize
4576@item set listsize @var{count}
4577Make the @code{list} command display @var{count} source lines (unless
4578the @code{list} argument explicitly specifies some other number).
4579
4580@kindex show listsize
4581@item show listsize
4582Display the number of lines that @code{list} prints.
4583@end table
4584
4585Repeating a @code{list} command with @key{RET} discards the argument,
4586so it is equivalent to typing just @code{list}. This is more useful
4587than listing the same lines again. An exception is made for an
4588argument of @samp{-}; that argument is preserved in repetition so that
4589each repetition moves up in the source file.
4590
4591@cindex linespec
4592In general, the @code{list} command expects you to supply zero, one or two
4593@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4594of writing them, but the effect is always to specify some source line.
c906108c
SS
4595Here is a complete description of the possible arguments for @code{list}:
4596
4597@table @code
4598@item list @var{linespec}
4599Print lines centered around the line specified by @var{linespec}.
4600
4601@item list @var{first},@var{last}
4602Print lines from @var{first} to @var{last}. Both arguments are
4603linespecs.
4604
4605@item list ,@var{last}
4606Print lines ending with @var{last}.
4607
4608@item list @var{first},
4609Print lines starting with @var{first}.
4610
4611@item list +
4612Print lines just after the lines last printed.
4613
4614@item list -
4615Print lines just before the lines last printed.
4616
4617@item list
4618As described in the preceding table.
4619@end table
4620
4621Here are the ways of specifying a single source line---all the
4622kinds of linespec.
4623
4624@table @code
4625@item @var{number}
4626Specifies line @var{number} of the current source file.
4627When a @code{list} command has two linespecs, this refers to
4628the same source file as the first linespec.
4629
4630@item +@var{offset}
4631Specifies the line @var{offset} lines after the last line printed.
4632When used as the second linespec in a @code{list} command that has
4633two, this specifies the line @var{offset} lines down from the
4634first linespec.
4635
4636@item -@var{offset}
4637Specifies the line @var{offset} lines before the last line printed.
4638
4639@item @var{filename}:@var{number}
4640Specifies line @var{number} in the source file @var{filename}.
4641
4642@item @var{function}
4643Specifies the line that begins the body of the function @var{function}.
4644For example: in C, this is the line with the open brace.
4645
4646@item @var{filename}:@var{function}
4647Specifies the line of the open-brace that begins the body of the
4648function @var{function} in the file @var{filename}. You only need the
4649file name with a function name to avoid ambiguity when there are
4650identically named functions in different source files.
4651
4652@item *@var{address}
4653Specifies the line containing the program address @var{address}.
4654@var{address} may be any expression.
4655@end table
4656
87885426
FN
4657@node Edit
4658@section Editing source files
4659@cindex editing source files
4660
4661@kindex edit
4662@kindex e @r{(@code{edit})}
4663To edit the lines in a source file, use the @code{edit} command.
4664The editing program of your choice
4665is invoked with the current line set to
4666the active line in the program.
4667Alternatively, there are several ways to specify what part of the file you
4668want to print if you want to see other parts of the program.
4669
4670Here are the forms of the @code{edit} command most commonly used:
4671
4672@table @code
4673@item edit
4674Edit the current source file at the active line number in the program.
4675
4676@item edit @var{number}
4677Edit the current source file with @var{number} as the active line number.
4678
4679@item edit @var{function}
4680Edit the file containing @var{function} at the beginning of its definition.
4681
4682@item edit @var{filename}:@var{number}
4683Specifies line @var{number} in the source file @var{filename}.
4684
4685@item edit @var{filename}:@var{function}
4686Specifies the line that begins the body of the
4687function @var{function} in the file @var{filename}. You only need the
4688file name with a function name to avoid ambiguity when there are
4689identically named functions in different source files.
4690
4691@item edit *@var{address}
4692Specifies the line containing the program address @var{address}.
4693@var{address} may be any expression.
4694@end table
4695
4696@subsection Choosing your editor
4697You can customize @value{GDBN} to use any editor you want
4698@footnote{
4699The only restriction is that your editor (say @code{ex}), recognizes the
4700following command-line syntax:
10998722 4701@smallexample
87885426 4702ex +@var{number} file
10998722 4703@end smallexample
15387254
EZ
4704The optional numeric value +@var{number} specifies the number of the line in
4705the file where to start editing.}.
4706By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4707by setting the environment variable @code{EDITOR} before using
4708@value{GDBN}. For example, to configure @value{GDBN} to use the
4709@code{vi} editor, you could use these commands with the @code{sh} shell:
4710@smallexample
87885426
FN
4711EDITOR=/usr/bin/vi
4712export EDITOR
15387254 4713gdb @dots{}
10998722 4714@end smallexample
87885426 4715or in the @code{csh} shell,
10998722 4716@smallexample
87885426 4717setenv EDITOR /usr/bin/vi
15387254 4718gdb @dots{}
10998722 4719@end smallexample
87885426 4720
6d2ebf8b 4721@node Search
c906108c 4722@section Searching source files
15387254 4723@cindex searching source files
c906108c
SS
4724
4725There are two commands for searching through the current source file for a
4726regular expression.
4727
4728@table @code
4729@kindex search
4730@kindex forward-search
4731@item forward-search @var{regexp}
4732@itemx search @var{regexp}
4733The command @samp{forward-search @var{regexp}} checks each line,
4734starting with the one following the last line listed, for a match for
5d161b24 4735@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4736synonym @samp{search @var{regexp}} or abbreviate the command name as
4737@code{fo}.
4738
09d4efe1 4739@kindex reverse-search
c906108c
SS
4740@item reverse-search @var{regexp}
4741The command @samp{reverse-search @var{regexp}} checks each line, starting
4742with the one before the last line listed and going backward, for a match
4743for @var{regexp}. It lists the line that is found. You can abbreviate
4744this command as @code{rev}.
4745@end table
c906108c 4746
6d2ebf8b 4747@node Source Path
c906108c
SS
4748@section Specifying source directories
4749
4750@cindex source path
4751@cindex directories for source files
4752Executable programs sometimes do not record the directories of the source
4753files from which they were compiled, just the names. Even when they do,
4754the directories could be moved between the compilation and your debugging
4755session. @value{GDBN} has a list of directories to search for source files;
4756this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4757it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4758in the list, until it finds a file with the desired name.
4759
4760For example, suppose an executable references the file
4761@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4762@file{/mnt/cross}. The file is first looked up literally; if this
4763fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4764fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4765message is printed. @value{GDBN} does not look up the parts of the
4766source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4767Likewise, the subdirectories of the source path are not searched: if
4768the source path is @file{/mnt/cross}, and the binary refers to
4769@file{foo.c}, @value{GDBN} would not find it under
4770@file{/mnt/cross/usr/src/foo-1.0/lib}.
4771
4772Plain file names, relative file names with leading directories, file
4773names containing dots, etc.@: are all treated as described above; for
4774instance, if the source path is @file{/mnt/cross}, and the source file
4775is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4776@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4777that---@file{/mnt/cross/foo.c}.
4778
4779Note that the executable search path is @emph{not} used to locate the
4780source files. Neither is the current working directory, unless it
4781happens to be in the source path.
c906108c
SS
4782
4783Whenever you reset or rearrange the source path, @value{GDBN} clears out
4784any information it has cached about where source files are found and where
4785each line is in the file.
4786
4787@kindex directory
4788@kindex dir
d4f3574e
SS
4789When you start @value{GDBN}, its source path includes only @samp{cdir}
4790and @samp{cwd}, in that order.
c906108c
SS
4791To add other directories, use the @code{directory} command.
4792
4793@table @code
4794@item directory @var{dirname} @dots{}
4795@item dir @var{dirname} @dots{}
4796Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4797directory names may be given to this command, separated by @samp{:}
4798(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4799part of absolute file names) or
c906108c
SS
4800whitespace. You may specify a directory that is already in the source
4801path; this moves it forward, so @value{GDBN} searches it sooner.
4802
4803@kindex cdir
4804@kindex cwd
41afff9a
EZ
4805@vindex $cdir@r{, convenience variable}
4806@vindex $cwdr@r{, convenience variable}
c906108c
SS
4807@cindex compilation directory
4808@cindex current directory
4809@cindex working directory
4810@cindex directory, current
4811@cindex directory, compilation
4812You can use the string @samp{$cdir} to refer to the compilation
4813directory (if one is recorded), and @samp{$cwd} to refer to the current
4814working directory. @samp{$cwd} is not the same as @samp{.}---the former
4815tracks the current working directory as it changes during your @value{GDBN}
4816session, while the latter is immediately expanded to the current
4817directory at the time you add an entry to the source path.
4818
4819@item directory
4820Reset the source path to empty again. This requires confirmation.
4821
4822@c RET-repeat for @code{directory} is explicitly disabled, but since
4823@c repeating it would be a no-op we do not say that. (thanks to RMS)
4824
4825@item show directories
4826@kindex show directories
4827Print the source path: show which directories it contains.
4828@end table
4829
4830If your source path is cluttered with directories that are no longer of
4831interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4832versions of source. You can correct the situation as follows:
4833
4834@enumerate
4835@item
4836Use @code{directory} with no argument to reset the source path to empty.
4837
4838@item
4839Use @code{directory} with suitable arguments to reinstall the
4840directories you want in the source path. You can add all the
4841directories in one command.
4842@end enumerate
4843
6d2ebf8b 4844@node Machine Code
c906108c 4845@section Source and machine code
15387254 4846@cindex source line and its code address
c906108c
SS
4847
4848You can use the command @code{info line} to map source lines to program
4849addresses (and vice versa), and the command @code{disassemble} to display
4850a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4851mode, the @code{info line} command causes the arrow to point to the
5d161b24 4852line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4853well as hex.
4854
4855@table @code
4856@kindex info line
4857@item info line @var{linespec}
4858Print the starting and ending addresses of the compiled code for
4859source line @var{linespec}. You can specify source lines in any of
4860the ways understood by the @code{list} command (@pxref{List, ,Printing
4861source lines}).
4862@end table
4863
4864For example, we can use @code{info line} to discover the location of
4865the object code for the first line of function
4866@code{m4_changequote}:
4867
d4f3574e
SS
4868@c FIXME: I think this example should also show the addresses in
4869@c symbolic form, as they usually would be displayed.
c906108c 4870@smallexample
96a2c332 4871(@value{GDBP}) info line m4_changequote
c906108c
SS
4872Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4873@end smallexample
4874
4875@noindent
15387254 4876@cindex code address and its source line
c906108c
SS
4877We can also inquire (using @code{*@var{addr}} as the form for
4878@var{linespec}) what source line covers a particular address:
4879@smallexample
4880(@value{GDBP}) info line *0x63ff
4881Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4882@end smallexample
4883
4884@cindex @code{$_} and @code{info line}
15387254 4885@cindex @code{x} command, default address
41afff9a 4886@kindex x@r{(examine), and} info line
c906108c
SS
4887After @code{info line}, the default address for the @code{x} command
4888is changed to the starting address of the line, so that @samp{x/i} is
4889sufficient to begin examining the machine code (@pxref{Memory,
4890,Examining memory}). Also, this address is saved as the value of the
4891convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4892variables}).
4893
4894@table @code
4895@kindex disassemble
4896@cindex assembly instructions
4897@cindex instructions, assembly
4898@cindex machine instructions
4899@cindex listing machine instructions
4900@item disassemble
4901This specialized command dumps a range of memory as machine
4902instructions. The default memory range is the function surrounding the
4903program counter of the selected frame. A single argument to this
4904command is a program counter value; @value{GDBN} dumps the function
4905surrounding this value. Two arguments specify a range of addresses
4906(first inclusive, second exclusive) to dump.
4907@end table
4908
c906108c
SS
4909The following example shows the disassembly of a range of addresses of
4910HP PA-RISC 2.0 code:
4911
4912@smallexample
4913(@value{GDBP}) disas 0x32c4 0x32e4
4914Dump of assembler code from 0x32c4 to 0x32e4:
49150x32c4 <main+204>: addil 0,dp
49160x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49170x32cc <main+212>: ldil 0x3000,r31
49180x32d0 <main+216>: ble 0x3f8(sr4,r31)
49190x32d4 <main+220>: ldo 0(r31),rp
49200x32d8 <main+224>: addil -0x800,dp
49210x32dc <main+228>: ldo 0x588(r1),r26
49220x32e0 <main+232>: ldil 0x3000,r31
4923End of assembler dump.
4924@end smallexample
c906108c
SS
4925
4926Some architectures have more than one commonly-used set of instruction
4927mnemonics or other syntax.
4928
76d17f34
EZ
4929For programs that were dynamically linked and use shared libraries,
4930instructions that call functions or branch to locations in the shared
4931libraries might show a seemingly bogus location---it's actually a
4932location of the relocation table. On some architectures, @value{GDBN}
4933might be able to resolve these to actual function names.
4934
c906108c 4935@table @code
d4f3574e 4936@kindex set disassembly-flavor
d4f3574e
SS
4937@cindex Intel disassembly flavor
4938@cindex AT&T disassembly flavor
4939@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4940Select the instruction set to use when disassembling the
4941program via the @code{disassemble} or @code{x/i} commands.
4942
4943Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4944can set @var{instruction-set} to either @code{intel} or @code{att}.
4945The default is @code{att}, the AT&T flavor used by default by Unix
4946assemblers for x86-based targets.
9c16f35a
EZ
4947
4948@kindex show disassembly-flavor
4949@item show disassembly-flavor
4950Show the current setting of the disassembly flavor.
c906108c
SS
4951@end table
4952
4953
6d2ebf8b 4954@node Data
c906108c
SS
4955@chapter Examining Data
4956
4957@cindex printing data
4958@cindex examining data
4959@kindex print
4960@kindex inspect
4961@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4962@c document because it is nonstandard... Under Epoch it displays in a
4963@c different window or something like that.
4964The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4965command (abbreviated @code{p}), or its synonym @code{inspect}. It
4966evaluates and prints the value of an expression of the language your
4967program is written in (@pxref{Languages, ,Using @value{GDBN} with
4968Different Languages}).
c906108c
SS
4969
4970@table @code
d4f3574e
SS
4971@item print @var{expr}
4972@itemx print /@var{f} @var{expr}
4973@var{expr} is an expression (in the source language). By default the
4974value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4975you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4976@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4977formats}.
4978
4979@item print
4980@itemx print /@var{f}
15387254 4981@cindex reprint the last value
d4f3574e 4982If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4983@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4984conveniently inspect the same value in an alternative format.
4985@end table
4986
4987A more low-level way of examining data is with the @code{x} command.
4988It examines data in memory at a specified address and prints it in a
4989specified format. @xref{Memory, ,Examining memory}.
4990
7a292a7a 4991If you are interested in information about types, or about how the
d4f3574e
SS
4992fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4993command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4994Table}.
c906108c
SS
4995
4996@menu
4997* Expressions:: Expressions
4998* Variables:: Program variables
4999* Arrays:: Artificial arrays
5000* Output Formats:: Output formats
5001* Memory:: Examining memory
5002* Auto Display:: Automatic display
5003* Print Settings:: Print settings
5004* Value History:: Value history
5005* Convenience Vars:: Convenience variables
5006* Registers:: Registers
c906108c 5007* Floating Point Hardware:: Floating point hardware
53c69bd7 5008* Vector Unit:: Vector Unit
721c2651 5009* OS Information:: Auxiliary data provided by operating system
29e57380 5010* Memory Region Attributes:: Memory region attributes
16d9dec6 5011* Dump/Restore Files:: Copy between memory and a file
384ee23f 5012* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5013* Character Sets:: Debugging programs that use a different
5014 character set than GDB does
09d4efe1 5015* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5016@end menu
5017
6d2ebf8b 5018@node Expressions
c906108c
SS
5019@section Expressions
5020
5021@cindex expressions
5022@code{print} and many other @value{GDBN} commands accept an expression and
5023compute its value. Any kind of constant, variable or operator defined
5024by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5025@value{GDBN}. This includes conditional expressions, function calls,
5026casts, and string constants. It also includes preprocessor macros, if
5027you compiled your program to include this information; see
5028@ref{Compilation}.
c906108c 5029
15387254 5030@cindex arrays in expressions
d4f3574e
SS
5031@value{GDBN} supports array constants in expressions input by
5032the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5033you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5034memory that is @code{malloc}ed in the target program.
c906108c 5035
c906108c
SS
5036Because C is so widespread, most of the expressions shown in examples in
5037this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5038Languages}, for information on how to use expressions in other
5039languages.
5040
5041In this section, we discuss operators that you can use in @value{GDBN}
5042expressions regardless of your programming language.
5043
15387254 5044@cindex casts, in expressions
c906108c
SS
5045Casts are supported in all languages, not just in C, because it is so
5046useful to cast a number into a pointer in order to examine a structure
5047at that address in memory.
5048@c FIXME: casts supported---Mod2 true?
c906108c
SS
5049
5050@value{GDBN} supports these operators, in addition to those common
5051to programming languages:
5052
5053@table @code
5054@item @@
5055@samp{@@} is a binary operator for treating parts of memory as arrays.
5056@xref{Arrays, ,Artificial arrays}, for more information.
5057
5058@item ::
5059@samp{::} allows you to specify a variable in terms of the file or
5060function where it is defined. @xref{Variables, ,Program variables}.
5061
5062@cindex @{@var{type}@}
5063@cindex type casting memory
5064@cindex memory, viewing as typed object
5065@cindex casts, to view memory
5066@item @{@var{type}@} @var{addr}
5067Refers to an object of type @var{type} stored at address @var{addr} in
5068memory. @var{addr} may be any expression whose value is an integer or
5069pointer (but parentheses are required around binary operators, just as in
5070a cast). This construct is allowed regardless of what kind of data is
5071normally supposed to reside at @var{addr}.
5072@end table
5073
6d2ebf8b 5074@node Variables
c906108c
SS
5075@section Program variables
5076
5077The most common kind of expression to use is the name of a variable
5078in your program.
5079
5080Variables in expressions are understood in the selected stack frame
5081(@pxref{Selection, ,Selecting a frame}); they must be either:
5082
5083@itemize @bullet
5084@item
5085global (or file-static)
5086@end itemize
5087
5d161b24 5088@noindent or
c906108c
SS
5089
5090@itemize @bullet
5091@item
5092visible according to the scope rules of the
5093programming language from the point of execution in that frame
5d161b24 5094@end itemize
c906108c
SS
5095
5096@noindent This means that in the function
5097
474c8240 5098@smallexample
c906108c
SS
5099foo (a)
5100 int a;
5101@{
5102 bar (a);
5103 @{
5104 int b = test ();
5105 bar (b);
5106 @}
5107@}
474c8240 5108@end smallexample
c906108c
SS
5109
5110@noindent
5111you can examine and use the variable @code{a} whenever your program is
5112executing within the function @code{foo}, but you can only use or
5113examine the variable @code{b} while your program is executing inside
5114the block where @code{b} is declared.
5115
5116@cindex variable name conflict
5117There is an exception: you can refer to a variable or function whose
5118scope is a single source file even if the current execution point is not
5119in this file. But it is possible to have more than one such variable or
5120function with the same name (in different source files). If that
5121happens, referring to that name has unpredictable effects. If you wish,
5122you can specify a static variable in a particular function or file,
15387254 5123using the colon-colon (@code{::}) notation:
c906108c 5124
d4f3574e 5125@cindex colon-colon, context for variables/functions
c906108c
SS
5126@iftex
5127@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5128@cindex @code{::}, context for variables/functions
c906108c 5129@end iftex
474c8240 5130@smallexample
c906108c
SS
5131@var{file}::@var{variable}
5132@var{function}::@var{variable}
474c8240 5133@end smallexample
c906108c
SS
5134
5135@noindent
5136Here @var{file} or @var{function} is the name of the context for the
5137static @var{variable}. In the case of file names, you can use quotes to
5138make sure @value{GDBN} parses the file name as a single word---for example,
5139to print a global value of @code{x} defined in @file{f2.c}:
5140
474c8240 5141@smallexample
c906108c 5142(@value{GDBP}) p 'f2.c'::x
474c8240 5143@end smallexample
c906108c 5144
b37052ae 5145@cindex C@t{++} scope resolution
c906108c 5146This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5147use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5148scope resolution operator in @value{GDBN} expressions.
5149@c FIXME: Um, so what happens in one of those rare cases where it's in
5150@c conflict?? --mew
c906108c
SS
5151
5152@cindex wrong values
5153@cindex variable values, wrong
15387254
EZ
5154@cindex function entry/exit, wrong values of variables
5155@cindex optimized code, wrong values of variables
c906108c
SS
5156@quotation
5157@emph{Warning:} Occasionally, a local variable may appear to have the
5158wrong value at certain points in a function---just after entry to a new
5159scope, and just before exit.
5160@end quotation
5161You may see this problem when you are stepping by machine instructions.
5162This is because, on most machines, it takes more than one instruction to
5163set up a stack frame (including local variable definitions); if you are
5164stepping by machine instructions, variables may appear to have the wrong
5165values until the stack frame is completely built. On exit, it usually
5166also takes more than one machine instruction to destroy a stack frame;
5167after you begin stepping through that group of instructions, local
5168variable definitions may be gone.
5169
5170This may also happen when the compiler does significant optimizations.
5171To be sure of always seeing accurate values, turn off all optimization
5172when compiling.
5173
d4f3574e
SS
5174@cindex ``No symbol "foo" in current context''
5175Another possible effect of compiler optimizations is to optimize
5176unused variables out of existence, or assign variables to registers (as
5177opposed to memory addresses). Depending on the support for such cases
5178offered by the debug info format used by the compiler, @value{GDBN}
5179might not be able to display values for such local variables. If that
5180happens, @value{GDBN} will print a message like this:
5181
474c8240 5182@smallexample
d4f3574e 5183No symbol "foo" in current context.
474c8240 5184@end smallexample
d4f3574e
SS
5185
5186To solve such problems, either recompile without optimizations, or use a
5187different debug info format, if the compiler supports several such
15387254 5188formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5189usually supports the @option{-gstabs+} option. @option{-gstabs+}
5190produces debug info in a format that is superior to formats such as
5191COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5192an effective form for debug info. @xref{Debugging Options,,Options
5193for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5194@xref{C, , Debugging C++}, for more info about debug info formats
5195that are best suited to C@t{++} programs.
d4f3574e 5196
6d2ebf8b 5197@node Arrays
c906108c
SS
5198@section Artificial arrays
5199
5200@cindex artificial array
15387254 5201@cindex arrays
41afff9a 5202@kindex @@@r{, referencing memory as an array}
c906108c
SS
5203It is often useful to print out several successive objects of the
5204same type in memory; a section of an array, or an array of
5205dynamically determined size for which only a pointer exists in the
5206program.
5207
5208You can do this by referring to a contiguous span of memory as an
5209@dfn{artificial array}, using the binary operator @samp{@@}. The left
5210operand of @samp{@@} should be the first element of the desired array
5211and be an individual object. The right operand should be the desired length
5212of the array. The result is an array value whose elements are all of
5213the type of the left argument. The first element is actually the left
5214argument; the second element comes from bytes of memory immediately
5215following those that hold the first element, and so on. Here is an
5216example. If a program says
5217
474c8240 5218@smallexample
c906108c 5219int *array = (int *) malloc (len * sizeof (int));
474c8240 5220@end smallexample
c906108c
SS
5221
5222@noindent
5223you can print the contents of @code{array} with
5224
474c8240 5225@smallexample
c906108c 5226p *array@@len
474c8240 5227@end smallexample
c906108c
SS
5228
5229The left operand of @samp{@@} must reside in memory. Array values made
5230with @samp{@@} in this way behave just like other arrays in terms of
5231subscripting, and are coerced to pointers when used in expressions.
5232Artificial arrays most often appear in expressions via the value history
5233(@pxref{Value History, ,Value history}), after printing one out.
5234
5235Another way to create an artificial array is to use a cast.
5236This re-interprets a value as if it were an array.
5237The value need not be in memory:
474c8240 5238@smallexample
c906108c
SS
5239(@value{GDBP}) p/x (short[2])0x12345678
5240$1 = @{0x1234, 0x5678@}
474c8240 5241@end smallexample
c906108c
SS
5242
5243As a convenience, if you leave the array length out (as in
c3f6f71d 5244@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5245the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5246@smallexample
c906108c
SS
5247(@value{GDBP}) p/x (short[])0x12345678
5248$2 = @{0x1234, 0x5678@}
474c8240 5249@end smallexample
c906108c
SS
5250
5251Sometimes the artificial array mechanism is not quite enough; in
5252moderately complex data structures, the elements of interest may not
5253actually be adjacent---for example, if you are interested in the values
5254of pointers in an array. One useful work-around in this situation is
5255to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5256variables}) as a counter in an expression that prints the first
5257interesting value, and then repeat that expression via @key{RET}. For
5258instance, suppose you have an array @code{dtab} of pointers to
5259structures, and you are interested in the values of a field @code{fv}
5260in each structure. Here is an example of what you might type:
5261
474c8240 5262@smallexample
c906108c
SS
5263set $i = 0
5264p dtab[$i++]->fv
5265@key{RET}
5266@key{RET}
5267@dots{}
474c8240 5268@end smallexample
c906108c 5269
6d2ebf8b 5270@node Output Formats
c906108c
SS
5271@section Output formats
5272
5273@cindex formatted output
5274@cindex output formats
5275By default, @value{GDBN} prints a value according to its data type. Sometimes
5276this is not what you want. For example, you might want to print a number
5277in hex, or a pointer in decimal. Or you might want to view data in memory
5278at a certain address as a character string or as an instruction. To do
5279these things, specify an @dfn{output format} when you print a value.
5280
5281The simplest use of output formats is to say how to print a value
5282already computed. This is done by starting the arguments of the
5283@code{print} command with a slash and a format letter. The format
5284letters supported are:
5285
5286@table @code
5287@item x
5288Regard the bits of the value as an integer, and print the integer in
5289hexadecimal.
5290
5291@item d
5292Print as integer in signed decimal.
5293
5294@item u
5295Print as integer in unsigned decimal.
5296
5297@item o
5298Print as integer in octal.
5299
5300@item t
5301Print as integer in binary. The letter @samp{t} stands for ``two''.
5302@footnote{@samp{b} cannot be used because these format letters are also
5303used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5304see @ref{Memory,,Examining memory}.}
c906108c
SS
5305
5306@item a
5307@cindex unknown address, locating
3d67e040 5308@cindex locate address
c906108c
SS
5309Print as an address, both absolute in hexadecimal and as an offset from
5310the nearest preceding symbol. You can use this format used to discover
5311where (in what function) an unknown address is located:
5312
474c8240 5313@smallexample
c906108c
SS
5314(@value{GDBP}) p/a 0x54320
5315$3 = 0x54320 <_initialize_vx+396>
474c8240 5316@end smallexample
c906108c 5317
3d67e040
EZ
5318@noindent
5319The command @code{info symbol 0x54320} yields similar results.
5320@xref{Symbols, info symbol}.
5321
c906108c 5322@item c
51274035
EZ
5323Regard as an integer and print it as a character constant. This
5324prints both the numerical value and its character representation. The
5325character representation is replaced with the octal escape @samp{\nnn}
5326for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5327
5328@item f
5329Regard the bits of the value as a floating point number and print
5330using typical floating point syntax.
5331@end table
5332
5333For example, to print the program counter in hex (@pxref{Registers}), type
5334
474c8240 5335@smallexample
c906108c 5336p/x $pc
474c8240 5337@end smallexample
c906108c
SS
5338
5339@noindent
5340Note that no space is required before the slash; this is because command
5341names in @value{GDBN} cannot contain a slash.
5342
5343To reprint the last value in the value history with a different format,
5344you can use the @code{print} command with just a format and no
5345expression. For example, @samp{p/x} reprints the last value in hex.
5346
6d2ebf8b 5347@node Memory
c906108c
SS
5348@section Examining memory
5349
5350You can use the command @code{x} (for ``examine'') to examine memory in
5351any of several formats, independently of your program's data types.
5352
5353@cindex examining memory
5354@table @code
41afff9a 5355@kindex x @r{(examine memory)}
c906108c
SS
5356@item x/@var{nfu} @var{addr}
5357@itemx x @var{addr}
5358@itemx x
5359Use the @code{x} command to examine memory.
5360@end table
5361
5362@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5363much memory to display and how to format it; @var{addr} is an
5364expression giving the address where you want to start displaying memory.
5365If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5366Several commands set convenient defaults for @var{addr}.
5367
5368@table @r
5369@item @var{n}, the repeat count
5370The repeat count is a decimal integer; the default is 1. It specifies
5371how much memory (counting by units @var{u}) to display.
5372@c This really is **decimal**; unaffected by 'set radix' as of GDB
5373@c 4.1.2.
5374
5375@item @var{f}, the display format
51274035
EZ
5376The display format is one of the formats used by @code{print}
5377(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5378@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5379@samp{i} (for machine instructions). The default is @samp{x}
5380(hexadecimal) initially. The default changes each time you use either
5381@code{x} or @code{print}.
c906108c
SS
5382
5383@item @var{u}, the unit size
5384The unit size is any of
5385
5386@table @code
5387@item b
5388Bytes.
5389@item h
5390Halfwords (two bytes).
5391@item w
5392Words (four bytes). This is the initial default.
5393@item g
5394Giant words (eight bytes).
5395@end table
5396
5397Each time you specify a unit size with @code{x}, that size becomes the
5398default unit the next time you use @code{x}. (For the @samp{s} and
5399@samp{i} formats, the unit size is ignored and is normally not written.)
5400
5401@item @var{addr}, starting display address
5402@var{addr} is the address where you want @value{GDBN} to begin displaying
5403memory. The expression need not have a pointer value (though it may);
5404it is always interpreted as an integer address of a byte of memory.
5405@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5406@var{addr} is usually just after the last address examined---but several
5407other commands also set the default address: @code{info breakpoints} (to
5408the address of the last breakpoint listed), @code{info line} (to the
5409starting address of a line), and @code{print} (if you use it to display
5410a value from memory).
5411@end table
5412
5413For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5414(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5415starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5416words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5417@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5418
5419Since the letters indicating unit sizes are all distinct from the
5420letters specifying output formats, you do not have to remember whether
5421unit size or format comes first; either order works. The output
5422specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5423(However, the count @var{n} must come first; @samp{wx4} does not work.)
5424
5425Even though the unit size @var{u} is ignored for the formats @samp{s}
5426and @samp{i}, you might still want to use a count @var{n}; for example,
5427@samp{3i} specifies that you want to see three machine instructions,
5428including any operands. The command @code{disassemble} gives an
d4f3574e 5429alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5430Code,,Source and machine code}.
5431
5432All the defaults for the arguments to @code{x} are designed to make it
5433easy to continue scanning memory with minimal specifications each time
5434you use @code{x}. For example, after you have inspected three machine
5435instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5436with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5437the repeat count @var{n} is used again; the other arguments default as
5438for successive uses of @code{x}.
5439
5440@cindex @code{$_}, @code{$__}, and value history
5441The addresses and contents printed by the @code{x} command are not saved
5442in the value history because there is often too much of them and they
5443would get in the way. Instead, @value{GDBN} makes these values available for
5444subsequent use in expressions as values of the convenience variables
5445@code{$_} and @code{$__}. After an @code{x} command, the last address
5446examined is available for use in expressions in the convenience variable
5447@code{$_}. The contents of that address, as examined, are available in
5448the convenience variable @code{$__}.
5449
5450If the @code{x} command has a repeat count, the address and contents saved
5451are from the last memory unit printed; this is not the same as the last
5452address printed if several units were printed on the last line of output.
5453
09d4efe1
EZ
5454@cindex remote memory comparison
5455@cindex verify remote memory image
5456When you are debugging a program running on a remote target machine
5457(@pxref{Remote}), you may wish to verify the program's image in the
5458remote machine's memory against the executable file you downloaded to
5459the target. The @code{compare-sections} command is provided for such
5460situations.
5461
5462@table @code
5463@kindex compare-sections
5464@item compare-sections @r{[}@var{section-name}@r{]}
5465Compare the data of a loadable section @var{section-name} in the
5466executable file of the program being debugged with the same section in
5467the remote machine's memory, and report any mismatches. With no
5468arguments, compares all loadable sections. This command's
5469availability depends on the target's support for the @code{"qCRC"}
5470remote request.
5471@end table
5472
6d2ebf8b 5473@node Auto Display
c906108c
SS
5474@section Automatic display
5475@cindex automatic display
5476@cindex display of expressions
5477
5478If you find that you want to print the value of an expression frequently
5479(to see how it changes), you might want to add it to the @dfn{automatic
5480display list} so that @value{GDBN} prints its value each time your program stops.
5481Each expression added to the list is given a number to identify it;
5482to remove an expression from the list, you specify that number.
5483The automatic display looks like this:
5484
474c8240 5485@smallexample
c906108c
SS
54862: foo = 38
54873: bar[5] = (struct hack *) 0x3804
474c8240 5488@end smallexample
c906108c
SS
5489
5490@noindent
5491This display shows item numbers, expressions and their current values. As with
5492displays you request manually using @code{x} or @code{print}, you can
5493specify the output format you prefer; in fact, @code{display} decides
5494whether to use @code{print} or @code{x} depending on how elaborate your
5495format specification is---it uses @code{x} if you specify a unit size,
5496or one of the two formats (@samp{i} and @samp{s}) that are only
5497supported by @code{x}; otherwise it uses @code{print}.
5498
5499@table @code
5500@kindex display
d4f3574e
SS
5501@item display @var{expr}
5502Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5503each time your program stops. @xref{Expressions, ,Expressions}.
5504
5505@code{display} does not repeat if you press @key{RET} again after using it.
5506
d4f3574e 5507@item display/@var{fmt} @var{expr}
c906108c 5508For @var{fmt} specifying only a display format and not a size or
d4f3574e 5509count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5510arrange to display it each time in the specified format @var{fmt}.
5511@xref{Output Formats,,Output formats}.
5512
5513@item display/@var{fmt} @var{addr}
5514For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5515number of units, add the expression @var{addr} as a memory address to
5516be examined each time your program stops. Examining means in effect
5517doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5518@end table
5519
5520For example, @samp{display/i $pc} can be helpful, to see the machine
5521instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5522is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5523
5524@table @code
5525@kindex delete display
5526@kindex undisplay
5527@item undisplay @var{dnums}@dots{}
5528@itemx delete display @var{dnums}@dots{}
5529Remove item numbers @var{dnums} from the list of expressions to display.
5530
5531@code{undisplay} does not repeat if you press @key{RET} after using it.
5532(Otherwise you would just get the error @samp{No display number @dots{}}.)
5533
5534@kindex disable display
5535@item disable display @var{dnums}@dots{}
5536Disable the display of item numbers @var{dnums}. A disabled display
5537item is not printed automatically, but is not forgotten. It may be
5538enabled again later.
5539
5540@kindex enable display
5541@item enable display @var{dnums}@dots{}
5542Enable display of item numbers @var{dnums}. It becomes effective once
5543again in auto display of its expression, until you specify otherwise.
5544
5545@item display
5546Display the current values of the expressions on the list, just as is
5547done when your program stops.
5548
5549@kindex info display
5550@item info display
5551Print the list of expressions previously set up to display
5552automatically, each one with its item number, but without showing the
5553values. This includes disabled expressions, which are marked as such.
5554It also includes expressions which would not be displayed right now
5555because they refer to automatic variables not currently available.
5556@end table
5557
15387254 5558@cindex display disabled out of scope
c906108c
SS
5559If a display expression refers to local variables, then it does not make
5560sense outside the lexical context for which it was set up. Such an
5561expression is disabled when execution enters a context where one of its
5562variables is not defined. For example, if you give the command
5563@code{display last_char} while inside a function with an argument
5564@code{last_char}, @value{GDBN} displays this argument while your program
5565continues to stop inside that function. When it stops elsewhere---where
5566there is no variable @code{last_char}---the display is disabled
5567automatically. The next time your program stops where @code{last_char}
5568is meaningful, you can enable the display expression once again.
5569
6d2ebf8b 5570@node Print Settings
c906108c
SS
5571@section Print settings
5572
5573@cindex format options
5574@cindex print settings
5575@value{GDBN} provides the following ways to control how arrays, structures,
5576and symbols are printed.
5577
5578@noindent
5579These settings are useful for debugging programs in any language:
5580
5581@table @code
4644b6e3 5582@kindex set print
c906108c
SS
5583@item set print address
5584@itemx set print address on
4644b6e3 5585@cindex print/don't print memory addresses
c906108c
SS
5586@value{GDBN} prints memory addresses showing the location of stack
5587traces, structure values, pointer values, breakpoints, and so forth,
5588even when it also displays the contents of those addresses. The default
5589is @code{on}. For example, this is what a stack frame display looks like with
5590@code{set print address on}:
5591
5592@smallexample
5593@group
5594(@value{GDBP}) f
5595#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5596 at input.c:530
5597530 if (lquote != def_lquote)
5598@end group
5599@end smallexample
5600
5601@item set print address off
5602Do not print addresses when displaying their contents. For example,
5603this is the same stack frame displayed with @code{set print address off}:
5604
5605@smallexample
5606@group
5607(@value{GDBP}) set print addr off
5608(@value{GDBP}) f
5609#0 set_quotes (lq="<<", rq=">>") at input.c:530
5610530 if (lquote != def_lquote)
5611@end group
5612@end smallexample
5613
5614You can use @samp{set print address off} to eliminate all machine
5615dependent displays from the @value{GDBN} interface. For example, with
5616@code{print address off}, you should get the same text for backtraces on
5617all machines---whether or not they involve pointer arguments.
5618
4644b6e3 5619@kindex show print
c906108c
SS
5620@item show print address
5621Show whether or not addresses are to be printed.
5622@end table
5623
5624When @value{GDBN} prints a symbolic address, it normally prints the
5625closest earlier symbol plus an offset. If that symbol does not uniquely
5626identify the address (for example, it is a name whose scope is a single
5627source file), you may need to clarify. One way to do this is with
5628@code{info line}, for example @samp{info line *0x4537}. Alternately,
5629you can set @value{GDBN} to print the source file and line number when
5630it prints a symbolic address:
5631
5632@table @code
c906108c 5633@item set print symbol-filename on
9c16f35a
EZ
5634@cindex source file and line of a symbol
5635@cindex symbol, source file and line
c906108c
SS
5636Tell @value{GDBN} to print the source file name and line number of a
5637symbol in the symbolic form of an address.
5638
5639@item set print symbol-filename off
5640Do not print source file name and line number of a symbol. This is the
5641default.
5642
c906108c
SS
5643@item show print symbol-filename
5644Show whether or not @value{GDBN} will print the source file name and
5645line number of a symbol in the symbolic form of an address.
5646@end table
5647
5648Another situation where it is helpful to show symbol filenames and line
5649numbers is when disassembling code; @value{GDBN} shows you the line
5650number and source file that corresponds to each instruction.
5651
5652Also, you may wish to see the symbolic form only if the address being
5653printed is reasonably close to the closest earlier symbol:
5654
5655@table @code
c906108c 5656@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5657@cindex maximum value for offset of closest symbol
c906108c
SS
5658Tell @value{GDBN} to only display the symbolic form of an address if the
5659offset between the closest earlier symbol and the address is less than
5d161b24 5660@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5661to always print the symbolic form of an address if any symbol precedes it.
5662
c906108c
SS
5663@item show print max-symbolic-offset
5664Ask how large the maximum offset is that @value{GDBN} prints in a
5665symbolic address.
5666@end table
5667
5668@cindex wild pointer, interpreting
5669@cindex pointer, finding referent
5670If you have a pointer and you are not sure where it points, try
5671@samp{set print symbol-filename on}. Then you can determine the name
5672and source file location of the variable where it points, using
5673@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5674For example, here @value{GDBN} shows that a variable @code{ptt} points
5675at another variable @code{t}, defined in @file{hi2.c}:
5676
474c8240 5677@smallexample
c906108c
SS
5678(@value{GDBP}) set print symbol-filename on
5679(@value{GDBP}) p/a ptt
5680$4 = 0xe008 <t in hi2.c>
474c8240 5681@end smallexample
c906108c
SS
5682
5683@quotation
5684@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5685does not show the symbol name and filename of the referent, even with
5686the appropriate @code{set print} options turned on.
5687@end quotation
5688
5689Other settings control how different kinds of objects are printed:
5690
5691@table @code
c906108c
SS
5692@item set print array
5693@itemx set print array on
4644b6e3 5694@cindex pretty print arrays
c906108c
SS
5695Pretty print arrays. This format is more convenient to read,
5696but uses more space. The default is off.
5697
5698@item set print array off
5699Return to compressed format for arrays.
5700
c906108c
SS
5701@item show print array
5702Show whether compressed or pretty format is selected for displaying
5703arrays.
5704
c906108c 5705@item set print elements @var{number-of-elements}
4644b6e3 5706@cindex number of array elements to print
9c16f35a 5707@cindex limit on number of printed array elements
c906108c
SS
5708Set a limit on how many elements of an array @value{GDBN} will print.
5709If @value{GDBN} is printing a large array, it stops printing after it has
5710printed the number of elements set by the @code{set print elements} command.
5711This limit also applies to the display of strings.
d4f3574e 5712When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5713Setting @var{number-of-elements} to zero means that the printing is unlimited.
5714
c906108c
SS
5715@item show print elements
5716Display the number of elements of a large array that @value{GDBN} will print.
5717If the number is 0, then the printing is unlimited.
5718
9c16f35a
EZ
5719@item set print repeats
5720@cindex repeated array elements
5721Set the threshold for suppressing display of repeated array
5722elelments. When the number of consecutive identical elements of an
5723array exceeds the threshold, @value{GDBN} prints the string
5724@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5725identical repetitions, instead of displaying the identical elements
5726themselves. Setting the threshold to zero will cause all elements to
5727be individually printed. The default threshold is 10.
5728
5729@item show print repeats
5730Display the current threshold for printing repeated identical
5731elements.
5732
c906108c 5733@item set print null-stop
4644b6e3 5734@cindex @sc{null} elements in arrays
c906108c 5735Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5736@sc{null} is encountered. This is useful when large arrays actually
c906108c 5737contain only short strings.
d4f3574e 5738The default is off.
c906108c 5739
9c16f35a
EZ
5740@item show print null-stop
5741Show whether @value{GDBN} stops printing an array on the first
5742@sc{null} character.
5743
c906108c 5744@item set print pretty on
9c16f35a
EZ
5745@cindex print structures in indented form
5746@cindex indentation in structure display
5d161b24 5747Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5748per line, like this:
5749
5750@smallexample
5751@group
5752$1 = @{
5753 next = 0x0,
5754 flags = @{
5755 sweet = 1,
5756 sour = 1
5757 @},
5758 meat = 0x54 "Pork"
5759@}
5760@end group
5761@end smallexample
5762
5763@item set print pretty off
5764Cause @value{GDBN} to print structures in a compact format, like this:
5765
5766@smallexample
5767@group
5768$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5769meat = 0x54 "Pork"@}
5770@end group
5771@end smallexample
5772
5773@noindent
5774This is the default format.
5775
c906108c
SS
5776@item show print pretty
5777Show which format @value{GDBN} is using to print structures.
5778
c906108c 5779@item set print sevenbit-strings on
4644b6e3
EZ
5780@cindex eight-bit characters in strings
5781@cindex octal escapes in strings
c906108c
SS
5782Print using only seven-bit characters; if this option is set,
5783@value{GDBN} displays any eight-bit characters (in strings or
5784character values) using the notation @code{\}@var{nnn}. This setting is
5785best if you are working in English (@sc{ascii}) and you use the
5786high-order bit of characters as a marker or ``meta'' bit.
5787
5788@item set print sevenbit-strings off
5789Print full eight-bit characters. This allows the use of more
5790international character sets, and is the default.
5791
c906108c
SS
5792@item show print sevenbit-strings
5793Show whether or not @value{GDBN} is printing only seven-bit characters.
5794
c906108c 5795@item set print union on
4644b6e3 5796@cindex unions in structures, printing
9c16f35a
EZ
5797Tell @value{GDBN} to print unions which are contained in structures
5798and other unions. This is the default setting.
c906108c
SS
5799
5800@item set print union off
9c16f35a
EZ
5801Tell @value{GDBN} not to print unions which are contained in
5802structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5803instead.
c906108c 5804
c906108c
SS
5805@item show print union
5806Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5807structures and other unions.
c906108c
SS
5808
5809For example, given the declarations
5810
5811@smallexample
5812typedef enum @{Tree, Bug@} Species;
5813typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5814typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5815 Bug_forms;
5816
5817struct thing @{
5818 Species it;
5819 union @{
5820 Tree_forms tree;
5821 Bug_forms bug;
5822 @} form;
5823@};
5824
5825struct thing foo = @{Tree, @{Acorn@}@};
5826@end smallexample
5827
5828@noindent
5829with @code{set print union on} in effect @samp{p foo} would print
5830
5831@smallexample
5832$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5833@end smallexample
5834
5835@noindent
5836and with @code{set print union off} in effect it would print
5837
5838@smallexample
5839$1 = @{it = Tree, form = @{...@}@}
5840@end smallexample
9c16f35a
EZ
5841
5842@noindent
5843@code{set print union} affects programs written in C-like languages
5844and in Pascal.
c906108c
SS
5845@end table
5846
c906108c
SS
5847@need 1000
5848@noindent
b37052ae 5849These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5850
5851@table @code
4644b6e3 5852@cindex demangling C@t{++} names
c906108c
SS
5853@item set print demangle
5854@itemx set print demangle on
b37052ae 5855Print C@t{++} names in their source form rather than in the encoded
c906108c 5856(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5857linkage. The default is on.
c906108c 5858
c906108c 5859@item show print demangle
b37052ae 5860Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5861
c906108c
SS
5862@item set print asm-demangle
5863@itemx set print asm-demangle on
b37052ae 5864Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5865in assembler code printouts such as instruction disassemblies.
5866The default is off.
5867
c906108c 5868@item show print asm-demangle
b37052ae 5869Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5870or demangled form.
5871
b37052ae
EZ
5872@cindex C@t{++} symbol decoding style
5873@cindex symbol decoding style, C@t{++}
a8f24a35 5874@kindex set demangle-style
c906108c
SS
5875@item set demangle-style @var{style}
5876Choose among several encoding schemes used by different compilers to
b37052ae 5877represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5878
5879@table @code
5880@item auto
5881Allow @value{GDBN} to choose a decoding style by inspecting your program.
5882
5883@item gnu
b37052ae 5884Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5885This is the default.
c906108c
SS
5886
5887@item hp
b37052ae 5888Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5889
5890@item lucid
b37052ae 5891Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5892
5893@item arm
b37052ae 5894Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5895@strong{Warning:} this setting alone is not sufficient to allow
5896debugging @code{cfront}-generated executables. @value{GDBN} would
5897require further enhancement to permit that.
5898
5899@end table
5900If you omit @var{style}, you will see a list of possible formats.
5901
c906108c 5902@item show demangle-style
b37052ae 5903Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5904
c906108c
SS
5905@item set print object
5906@itemx set print object on
4644b6e3 5907@cindex derived type of an object, printing
9c16f35a 5908@cindex display derived types
c906108c
SS
5909When displaying a pointer to an object, identify the @emph{actual}
5910(derived) type of the object rather than the @emph{declared} type, using
5911the virtual function table.
5912
5913@item set print object off
5914Display only the declared type of objects, without reference to the
5915virtual function table. This is the default setting.
5916
c906108c
SS
5917@item show print object
5918Show whether actual, or declared, object types are displayed.
5919
c906108c
SS
5920@item set print static-members
5921@itemx set print static-members on
4644b6e3 5922@cindex static members of C@t{++} objects
b37052ae 5923Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5924
5925@item set print static-members off
b37052ae 5926Do not print static members when displaying a C@t{++} object.
c906108c 5927
c906108c 5928@item show print static-members
9c16f35a
EZ
5929Show whether C@t{++} static members are printed or not.
5930
5931@item set print pascal_static-members
5932@itemx set print pascal_static-members on
5933@cindex static members of Pacal objects
5934@cindex Pacal objects, static members display
5935Print static members when displaying a Pascal object. The default is on.
5936
5937@item set print pascal_static-members off
5938Do not print static members when displaying a Pascal object.
5939
5940@item show print pascal_static-members
5941Show whether Pascal static members are printed or not.
c906108c
SS
5942
5943@c These don't work with HP ANSI C++ yet.
c906108c
SS
5944@item set print vtbl
5945@itemx set print vtbl on
4644b6e3 5946@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5947@cindex virtual functions (C@t{++}) display
5948@cindex VTBL display
b37052ae 5949Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5950(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5951ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5952
5953@item set print vtbl off
b37052ae 5954Do not pretty print C@t{++} virtual function tables.
c906108c 5955
c906108c 5956@item show print vtbl
b37052ae 5957Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5958@end table
c906108c 5959
6d2ebf8b 5960@node Value History
c906108c
SS
5961@section Value history
5962
5963@cindex value history
9c16f35a 5964@cindex history of values printed by @value{GDBN}
5d161b24
DB
5965Values printed by the @code{print} command are saved in the @value{GDBN}
5966@dfn{value history}. This allows you to refer to them in other expressions.
5967Values are kept until the symbol table is re-read or discarded
5968(for example with the @code{file} or @code{symbol-file} commands).
5969When the symbol table changes, the value history is discarded,
5970since the values may contain pointers back to the types defined in the
c906108c
SS
5971symbol table.
5972
5973@cindex @code{$}
5974@cindex @code{$$}
5975@cindex history number
5976The values printed are given @dfn{history numbers} by which you can
5977refer to them. These are successive integers starting with one.
5978@code{print} shows you the history number assigned to a value by
5979printing @samp{$@var{num} = } before the value; here @var{num} is the
5980history number.
5981
5982To refer to any previous value, use @samp{$} followed by the value's
5983history number. The way @code{print} labels its output is designed to
5984remind you of this. Just @code{$} refers to the most recent value in
5985the history, and @code{$$} refers to the value before that.
5986@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5987is the value just prior to @code{$$}, @code{$$1} is equivalent to
5988@code{$$}, and @code{$$0} is equivalent to @code{$}.
5989
5990For example, suppose you have just printed a pointer to a structure and
5991want to see the contents of the structure. It suffices to type
5992
474c8240 5993@smallexample
c906108c 5994p *$
474c8240 5995@end smallexample
c906108c
SS
5996
5997If you have a chain of structures where the component @code{next} points
5998to the next one, you can print the contents of the next one with this:
5999
474c8240 6000@smallexample
c906108c 6001p *$.next
474c8240 6002@end smallexample
c906108c
SS
6003
6004@noindent
6005You can print successive links in the chain by repeating this
6006command---which you can do by just typing @key{RET}.
6007
6008Note that the history records values, not expressions. If the value of
6009@code{x} is 4 and you type these commands:
6010
474c8240 6011@smallexample
c906108c
SS
6012print x
6013set x=5
474c8240 6014@end smallexample
c906108c
SS
6015
6016@noindent
6017then the value recorded in the value history by the @code{print} command
6018remains 4 even though the value of @code{x} has changed.
6019
6020@table @code
6021@kindex show values
6022@item show values
6023Print the last ten values in the value history, with their item numbers.
6024This is like @samp{p@ $$9} repeated ten times, except that @code{show
6025values} does not change the history.
6026
6027@item show values @var{n}
6028Print ten history values centered on history item number @var{n}.
6029
6030@item show values +
6031Print ten history values just after the values last printed. If no more
6032values are available, @code{show values +} produces no display.
6033@end table
6034
6035Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6036same effect as @samp{show values +}.
6037
6d2ebf8b 6038@node Convenience Vars
c906108c
SS
6039@section Convenience variables
6040
6041@cindex convenience variables
9c16f35a 6042@cindex user-defined variables
c906108c
SS
6043@value{GDBN} provides @dfn{convenience variables} that you can use within
6044@value{GDBN} to hold on to a value and refer to it later. These variables
6045exist entirely within @value{GDBN}; they are not part of your program, and
6046setting a convenience variable has no direct effect on further execution
6047of your program. That is why you can use them freely.
6048
6049Convenience variables are prefixed with @samp{$}. Any name preceded by
6050@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6051the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6052(Value history references, in contrast, are @emph{numbers} preceded
6053by @samp{$}. @xref{Value History, ,Value history}.)
6054
6055You can save a value in a convenience variable with an assignment
6056expression, just as you would set a variable in your program.
6057For example:
6058
474c8240 6059@smallexample
c906108c 6060set $foo = *object_ptr
474c8240 6061@end smallexample
c906108c
SS
6062
6063@noindent
6064would save in @code{$foo} the value contained in the object pointed to by
6065@code{object_ptr}.
6066
6067Using a convenience variable for the first time creates it, but its
6068value is @code{void} until you assign a new value. You can alter the
6069value with another assignment at any time.
6070
6071Convenience variables have no fixed types. You can assign a convenience
6072variable any type of value, including structures and arrays, even if
6073that variable already has a value of a different type. The convenience
6074variable, when used as an expression, has the type of its current value.
6075
6076@table @code
6077@kindex show convenience
9c16f35a 6078@cindex show all user variables
c906108c
SS
6079@item show convenience
6080Print a list of convenience variables used so far, and their values.
d4f3574e 6081Abbreviated @code{show conv}.
c906108c
SS
6082@end table
6083
6084One of the ways to use a convenience variable is as a counter to be
6085incremented or a pointer to be advanced. For example, to print
6086a field from successive elements of an array of structures:
6087
474c8240 6088@smallexample
c906108c
SS
6089set $i = 0
6090print bar[$i++]->contents
474c8240 6091@end smallexample
c906108c 6092
d4f3574e
SS
6093@noindent
6094Repeat that command by typing @key{RET}.
c906108c
SS
6095
6096Some convenience variables are created automatically by @value{GDBN} and given
6097values likely to be useful.
6098
6099@table @code
41afff9a 6100@vindex $_@r{, convenience variable}
c906108c
SS
6101@item $_
6102The variable @code{$_} is automatically set by the @code{x} command to
6103the last address examined (@pxref{Memory, ,Examining memory}). Other
6104commands which provide a default address for @code{x} to examine also
6105set @code{$_} to that address; these commands include @code{info line}
6106and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6107except when set by the @code{x} command, in which case it is a pointer
6108to the type of @code{$__}.
6109
41afff9a 6110@vindex $__@r{, convenience variable}
c906108c
SS
6111@item $__
6112The variable @code{$__} is automatically set by the @code{x} command
6113to the value found in the last address examined. Its type is chosen
6114to match the format in which the data was printed.
6115
6116@item $_exitcode
41afff9a 6117@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6118The variable @code{$_exitcode} is automatically set to the exit code when
6119the program being debugged terminates.
6120@end table
6121
53a5351d
JM
6122On HP-UX systems, if you refer to a function or variable name that
6123begins with a dollar sign, @value{GDBN} searches for a user or system
6124name first, before it searches for a convenience variable.
c906108c 6125
6d2ebf8b 6126@node Registers
c906108c
SS
6127@section Registers
6128
6129@cindex registers
6130You can refer to machine register contents, in expressions, as variables
6131with names starting with @samp{$}. The names of registers are different
6132for each machine; use @code{info registers} to see the names used on
6133your machine.
6134
6135@table @code
6136@kindex info registers
6137@item info registers
6138Print the names and values of all registers except floating-point
c85508ee 6139and vector registers (in the selected stack frame).
c906108c
SS
6140
6141@kindex info all-registers
6142@cindex floating point registers
6143@item info all-registers
6144Print the names and values of all registers, including floating-point
c85508ee 6145and vector registers (in the selected stack frame).
c906108c
SS
6146
6147@item info registers @var{regname} @dots{}
6148Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6149As discussed in detail below, register values are normally relative to
6150the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6151the machine you are using, with or without the initial @samp{$}.
6152@end table
6153
e09f16f9
EZ
6154@cindex stack pointer register
6155@cindex program counter register
6156@cindex process status register
6157@cindex frame pointer register
6158@cindex standard registers
c906108c
SS
6159@value{GDBN} has four ``standard'' register names that are available (in
6160expressions) on most machines---whenever they do not conflict with an
6161architecture's canonical mnemonics for registers. The register names
6162@code{$pc} and @code{$sp} are used for the program counter register and
6163the stack pointer. @code{$fp} is used for a register that contains a
6164pointer to the current stack frame, and @code{$ps} is used for a
6165register that contains the processor status. For example,
6166you could print the program counter in hex with
6167
474c8240 6168@smallexample
c906108c 6169p/x $pc
474c8240 6170@end smallexample
c906108c
SS
6171
6172@noindent
6173or print the instruction to be executed next with
6174
474c8240 6175@smallexample
c906108c 6176x/i $pc
474c8240 6177@end smallexample
c906108c
SS
6178
6179@noindent
6180or add four to the stack pointer@footnote{This is a way of removing
6181one word from the stack, on machines where stacks grow downward in
6182memory (most machines, nowadays). This assumes that the innermost
6183stack frame is selected; setting @code{$sp} is not allowed when other
6184stack frames are selected. To pop entire frames off the stack,
6185regardless of machine architecture, use @code{return};
d4f3574e 6186see @ref{Returning, ,Returning from a function}.} with
c906108c 6187
474c8240 6188@smallexample
c906108c 6189set $sp += 4
474c8240 6190@end smallexample
c906108c
SS
6191
6192Whenever possible, these four standard register names are available on
6193your machine even though the machine has different canonical mnemonics,
6194so long as there is no conflict. The @code{info registers} command
6195shows the canonical names. For example, on the SPARC, @code{info
6196registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6197can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6198is an alias for the @sc{eflags} register.
c906108c
SS
6199
6200@value{GDBN} always considers the contents of an ordinary register as an
6201integer when the register is examined in this way. Some machines have
6202special registers which can hold nothing but floating point; these
6203registers are considered to have floating point values. There is no way
6204to refer to the contents of an ordinary register as floating point value
6205(although you can @emph{print} it as a floating point value with
6206@samp{print/f $@var{regname}}).
6207
6208Some registers have distinct ``raw'' and ``virtual'' data formats. This
6209means that the data format in which the register contents are saved by
6210the operating system is not the same one that your program normally
6211sees. For example, the registers of the 68881 floating point
6212coprocessor are always saved in ``extended'' (raw) format, but all C
6213programs expect to work with ``double'' (virtual) format. In such
5d161b24 6214cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6215that makes sense for your program), but the @code{info registers} command
6216prints the data in both formats.
6217
6218Normally, register values are relative to the selected stack frame
6219(@pxref{Selection, ,Selecting a frame}). This means that you get the
6220value that the register would contain if all stack frames farther in
6221were exited and their saved registers restored. In order to see the
6222true contents of hardware registers, you must select the innermost
6223frame (with @samp{frame 0}).
6224
6225However, @value{GDBN} must deduce where registers are saved, from the machine
6226code generated by your compiler. If some registers are not saved, or if
6227@value{GDBN} is unable to locate the saved registers, the selected stack
6228frame makes no difference.
6229
6d2ebf8b 6230@node Floating Point Hardware
c906108c
SS
6231@section Floating point hardware
6232@cindex floating point
6233
6234Depending on the configuration, @value{GDBN} may be able to give
6235you more information about the status of the floating point hardware.
6236
6237@table @code
6238@kindex info float
6239@item info float
6240Display hardware-dependent information about the floating
6241point unit. The exact contents and layout vary depending on the
6242floating point chip. Currently, @samp{info float} is supported on
6243the ARM and x86 machines.
6244@end table
c906108c 6245
e76f1f2e
AC
6246@node Vector Unit
6247@section Vector Unit
6248@cindex vector unit
6249
6250Depending on the configuration, @value{GDBN} may be able to give you
6251more information about the status of the vector unit.
6252
6253@table @code
6254@kindex info vector
6255@item info vector
6256Display information about the vector unit. The exact contents and
6257layout vary depending on the hardware.
6258@end table
6259
721c2651
EZ
6260@node OS Information
6261@section Operating system auxiliary information
6262@cindex OS information
6263
6264@value{GDBN} provides interfaces to useful OS facilities that can help
6265you debug your program.
6266
6267@cindex @code{ptrace} system call
6268@cindex @code{struct user} contents
6269When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6270machines), it interfaces with the inferior via the @code{ptrace}
6271system call. The operating system creates a special sata structure,
6272called @code{struct user}, for this interface. You can use the
6273command @code{info udot} to display the contents of this data
6274structure.
6275
6276@table @code
6277@item info udot
6278@kindex info udot
6279Display the contents of the @code{struct user} maintained by the OS
6280kernel for the program being debugged. @value{GDBN} displays the
6281contents of @code{struct user} as a list of hex numbers, similar to
6282the @code{examine} command.
6283@end table
6284
b383017d
RM
6285@cindex auxiliary vector
6286@cindex vector, auxiliary
b383017d
RM
6287Some operating systems supply an @dfn{auxiliary vector} to programs at
6288startup. This is akin to the arguments and environment that you
6289specify for a program, but contains a system-dependent variety of
6290binary values that tell system libraries important details about the
6291hardware, operating system, and process. Each value's purpose is
6292identified by an integer tag; the meanings are well-known but system-specific.
6293Depending on the configuration and operating system facilities,
9c16f35a
EZ
6294@value{GDBN} may be able to show you this information. For remote
6295targets, this functionality may further depend on the remote stub's
6296support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6297configuration, auxiliary vector}.
b383017d
RM
6298
6299@table @code
6300@kindex info auxv
6301@item info auxv
6302Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6303live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6304numerically, and also shows names and text descriptions for recognized
6305tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6306pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6307most appropriate form for a recognized tag, and in hexadecimal for
6308an unrecognized tag.
6309@end table
6310
721c2651 6311
29e57380 6312@node Memory Region Attributes
b383017d 6313@section Memory region attributes
29e57380
C
6314@cindex memory region attributes
6315
b383017d
RM
6316@dfn{Memory region attributes} allow you to describe special handling
6317required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6318to determine whether to allow certain types of memory accesses; whether to
6319use specific width accesses; and whether to cache target memory.
6320
6321Defined memory regions can be individually enabled and disabled. When a
6322memory region is disabled, @value{GDBN} uses the default attributes when
6323accessing memory in that region. Similarly, if no memory regions have
6324been defined, @value{GDBN} uses the default attributes when accessing
6325all memory.
6326
b383017d 6327When a memory region is defined, it is given a number to identify it;
29e57380
C
6328to enable, disable, or remove a memory region, you specify that number.
6329
6330@table @code
6331@kindex mem
bfac230e 6332@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6333Define a memory region bounded by @var{lower} and @var{upper} with
6334attributes @var{attributes}@dots{}, and add it to the list of regions
6335monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6336case: it is treated as the the target's maximum memory address.
bfac230e 6337(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6338
6339@kindex delete mem
6340@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6341Remove memory regions @var{nums}@dots{} from the list of regions
6342monitored by @value{GDBN}.
29e57380
C
6343
6344@kindex disable mem
6345@item disable mem @var{nums}@dots{}
09d4efe1 6346Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6347A disabled memory region is not forgotten.
29e57380
C
6348It may be enabled again later.
6349
6350@kindex enable mem
6351@item enable mem @var{nums}@dots{}
09d4efe1 6352Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6353
6354@kindex info mem
6355@item info mem
6356Print a table of all defined memory regions, with the following columns
09d4efe1 6357for each region:
29e57380
C
6358
6359@table @emph
6360@item Memory Region Number
6361@item Enabled or Disabled.
b383017d 6362Enabled memory regions are marked with @samp{y}.
29e57380
C
6363Disabled memory regions are marked with @samp{n}.
6364
6365@item Lo Address
6366The address defining the inclusive lower bound of the memory region.
6367
6368@item Hi Address
6369The address defining the exclusive upper bound of the memory region.
6370
6371@item Attributes
6372The list of attributes set for this memory region.
6373@end table
6374@end table
6375
6376
6377@subsection Attributes
6378
b383017d 6379@subsubsection Memory Access Mode
29e57380
C
6380The access mode attributes set whether @value{GDBN} may make read or
6381write accesses to a memory region.
6382
6383While these attributes prevent @value{GDBN} from performing invalid
6384memory accesses, they do nothing to prevent the target system, I/O DMA,
6385etc. from accessing memory.
6386
6387@table @code
6388@item ro
6389Memory is read only.
6390@item wo
6391Memory is write only.
6392@item rw
6ca652b0 6393Memory is read/write. This is the default.
29e57380
C
6394@end table
6395
6396@subsubsection Memory Access Size
6397The acccess size attributes tells @value{GDBN} to use specific sized
6398accesses in the memory region. Often memory mapped device registers
6399require specific sized accesses. If no access size attribute is
6400specified, @value{GDBN} may use accesses of any size.
6401
6402@table @code
6403@item 8
6404Use 8 bit memory accesses.
6405@item 16
6406Use 16 bit memory accesses.
6407@item 32
6408Use 32 bit memory accesses.
6409@item 64
6410Use 64 bit memory accesses.
6411@end table
6412
6413@c @subsubsection Hardware/Software Breakpoints
6414@c The hardware/software breakpoint attributes set whether @value{GDBN}
6415@c will use hardware or software breakpoints for the internal breakpoints
6416@c used by the step, next, finish, until, etc. commands.
6417@c
6418@c @table @code
6419@c @item hwbreak
b383017d 6420@c Always use hardware breakpoints
29e57380
C
6421@c @item swbreak (default)
6422@c @end table
6423
6424@subsubsection Data Cache
6425The data cache attributes set whether @value{GDBN} will cache target
6426memory. While this generally improves performance by reducing debug
6427protocol overhead, it can lead to incorrect results because @value{GDBN}
6428does not know about volatile variables or memory mapped device
6429registers.
6430
6431@table @code
6432@item cache
b383017d 6433Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6434@item nocache
6435Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6436@end table
6437
6438@c @subsubsection Memory Write Verification
b383017d 6439@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6440@c will re-reads data after each write to verify the write was successful.
6441@c
6442@c @table @code
6443@c @item verify
6444@c @item noverify (default)
6445@c @end table
6446
16d9dec6
MS
6447@node Dump/Restore Files
6448@section Copy between memory and a file
6449@cindex dump/restore files
6450@cindex append data to a file
6451@cindex dump data to a file
6452@cindex restore data from a file
16d9dec6 6453
df5215a6
JB
6454You can use the commands @code{dump}, @code{append}, and
6455@code{restore} to copy data between target memory and a file. The
6456@code{dump} and @code{append} commands write data to a file, and the
6457@code{restore} command reads data from a file back into the inferior's
6458memory. Files may be in binary, Motorola S-record, Intel hex, or
6459Tektronix Hex format; however, @value{GDBN} can only append to binary
6460files.
6461
6462@table @code
6463
6464@kindex dump
6465@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6466@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6467Dump the contents of memory from @var{start_addr} to @var{end_addr},
6468or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6469
df5215a6 6470The @var{format} parameter may be any one of:
16d9dec6 6471@table @code
df5215a6
JB
6472@item binary
6473Raw binary form.
6474@item ihex
6475Intel hex format.
6476@item srec
6477Motorola S-record format.
6478@item tekhex
6479Tektronix Hex format.
6480@end table
6481
6482@value{GDBN} uses the same definitions of these formats as the
6483@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6484@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6485form.
6486
6487@kindex append
6488@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6489@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6490Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6491or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6492(@value{GDBN} can only append data to files in raw binary form.)
6493
6494@kindex restore
6495@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6496Restore the contents of file @var{filename} into memory. The
6497@code{restore} command can automatically recognize any known @sc{bfd}
6498file format, except for raw binary. To restore a raw binary file you
6499must specify the optional keyword @code{binary} after the filename.
16d9dec6 6500
b383017d 6501If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6502contained in the file. Binary files always start at address zero, so
6503they will be restored at address @var{bias}. Other bfd files have
6504a built-in location; they will be restored at offset @var{bias}
6505from that location.
6506
6507If @var{start} and/or @var{end} are non-zero, then only data between
6508file offset @var{start} and file offset @var{end} will be restored.
b383017d 6509These offsets are relative to the addresses in the file, before
16d9dec6
MS
6510the @var{bias} argument is applied.
6511
6512@end table
6513
384ee23f
EZ
6514@node Core File Generation
6515@section How to Produce a Core File from Your Program
6516@cindex dump core from inferior
6517
6518A @dfn{core file} or @dfn{core dump} is a file that records the memory
6519image of a running process and its process status (register values
6520etc.). Its primary use is post-mortem debugging of a program that
6521crashed while it ran outside a debugger. A program that crashes
6522automatically produces a core file, unless this feature is disabled by
6523the user. @xref{Files}, for information on invoking @value{GDBN} in
6524the post-mortem debugging mode.
6525
6526Occasionally, you may wish to produce a core file of the program you
6527are debugging in order to preserve a snapshot of its state.
6528@value{GDBN} has a special command for that.
6529
6530@table @code
6531@kindex gcore
6532@kindex generate-core-file
6533@item generate-core-file [@var{file}]
6534@itemx gcore [@var{file}]
6535Produce a core dump of the inferior process. The optional argument
6536@var{file} specifies the file name where to put the core dump. If not
6537specified, the file name defaults to @file{core.@var{pid}}, where
6538@var{pid} is the inferior process ID.
6539
6540Note that this command is implemented only for some systems (as of
6541this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6542@end table
6543
a0eb71c5
KB
6544@node Character Sets
6545@section Character Sets
6546@cindex character sets
6547@cindex charset
6548@cindex translating between character sets
6549@cindex host character set
6550@cindex target character set
6551
6552If the program you are debugging uses a different character set to
6553represent characters and strings than the one @value{GDBN} uses itself,
6554@value{GDBN} can automatically translate between the character sets for
6555you. The character set @value{GDBN} uses we call the @dfn{host
6556character set}; the one the inferior program uses we call the
6557@dfn{target character set}.
6558
6559For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6560uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6561remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6562running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6563then the host character set is Latin-1, and the target character set is
6564@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6565target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6566@sc{ebcdic} and Latin 1 as you print character or string values, or use
6567character and string literals in expressions.
6568
6569@value{GDBN} has no way to automatically recognize which character set
6570the inferior program uses; you must tell it, using the @code{set
6571target-charset} command, described below.
6572
6573Here are the commands for controlling @value{GDBN}'s character set
6574support:
6575
6576@table @code
6577@item set target-charset @var{charset}
6578@kindex set target-charset
6579Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6580character set names @value{GDBN} recognizes below, but if you type
6581@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6582list the target character sets it supports.
a0eb71c5
KB
6583@end table
6584
6585@table @code
6586@item set host-charset @var{charset}
6587@kindex set host-charset
6588Set the current host character set to @var{charset}.
6589
6590By default, @value{GDBN} uses a host character set appropriate to the
6591system it is running on; you can override that default using the
6592@code{set host-charset} command.
6593
6594@value{GDBN} can only use certain character sets as its host character
6595set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6596indicate which can be host character sets, but if you type
6597@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6598list the host character sets it supports.
a0eb71c5
KB
6599
6600@item set charset @var{charset}
6601@kindex set charset
e33d66ec
EZ
6602Set the current host and target character sets to @var{charset}. As
6603above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6604@value{GDBN} will list the name of the character sets that can be used
6605for both host and target.
6606
a0eb71c5
KB
6607
6608@item show charset
a0eb71c5 6609@kindex show charset
b383017d 6610Show the names of the current host and target charsets.
e33d66ec
EZ
6611
6612@itemx show host-charset
a0eb71c5 6613@kindex show host-charset
b383017d 6614Show the name of the current host charset.
e33d66ec
EZ
6615
6616@itemx show target-charset
a0eb71c5 6617@kindex show target-charset
b383017d 6618Show the name of the current target charset.
a0eb71c5
KB
6619
6620@end table
6621
6622@value{GDBN} currently includes support for the following character
6623sets:
6624
6625@table @code
6626
6627@item ASCII
6628@cindex ASCII character set
6629Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6630character set.
6631
6632@item ISO-8859-1
6633@cindex ISO 8859-1 character set
6634@cindex ISO Latin 1 character set
e33d66ec 6635The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6636characters needed for French, German, and Spanish. @value{GDBN} can use
6637this as its host character set.
6638
6639@item EBCDIC-US
6640@itemx IBM1047
6641@cindex EBCDIC character set
6642@cindex IBM1047 character set
6643Variants of the @sc{ebcdic} character set, used on some of IBM's
6644mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6645@value{GDBN} cannot use these as its host character set.
6646
6647@end table
6648
6649Note that these are all single-byte character sets. More work inside
6650GDB is needed to support multi-byte or variable-width character
6651encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6652
6653Here is an example of @value{GDBN}'s character set support in action.
6654Assume that the following source code has been placed in the file
6655@file{charset-test.c}:
6656
6657@smallexample
6658#include <stdio.h>
6659
6660char ascii_hello[]
6661 = @{72, 101, 108, 108, 111, 44, 32, 119,
6662 111, 114, 108, 100, 33, 10, 0@};
6663char ibm1047_hello[]
6664 = @{200, 133, 147, 147, 150, 107, 64, 166,
6665 150, 153, 147, 132, 90, 37, 0@};
6666
6667main ()
6668@{
6669 printf ("Hello, world!\n");
6670@}
10998722 6671@end smallexample
a0eb71c5
KB
6672
6673In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6674containing the string @samp{Hello, world!} followed by a newline,
6675encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6676
6677We compile the program, and invoke the debugger on it:
6678
6679@smallexample
6680$ gcc -g charset-test.c -o charset-test
6681$ gdb -nw charset-test
6682GNU gdb 2001-12-19-cvs
6683Copyright 2001 Free Software Foundation, Inc.
6684@dots{}
f7dc1244 6685(@value{GDBP})
10998722 6686@end smallexample
a0eb71c5
KB
6687
6688We can use the @code{show charset} command to see what character sets
6689@value{GDBN} is currently using to interpret and display characters and
6690strings:
6691
6692@smallexample
f7dc1244 6693(@value{GDBP}) show charset
e33d66ec 6694The current host and target character set is `ISO-8859-1'.
f7dc1244 6695(@value{GDBP})
10998722 6696@end smallexample
a0eb71c5
KB
6697
6698For the sake of printing this manual, let's use @sc{ascii} as our
6699initial character set:
6700@smallexample
f7dc1244
EZ
6701(@value{GDBP}) set charset ASCII
6702(@value{GDBP}) show charset
e33d66ec 6703The current host and target character set is `ASCII'.
f7dc1244 6704(@value{GDBP})
10998722 6705@end smallexample
a0eb71c5
KB
6706
6707Let's assume that @sc{ascii} is indeed the correct character set for our
6708host system --- in other words, let's assume that if @value{GDBN} prints
6709characters using the @sc{ascii} character set, our terminal will display
6710them properly. Since our current target character set is also
6711@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6712
6713@smallexample
f7dc1244 6714(@value{GDBP}) print ascii_hello
a0eb71c5 6715$1 = 0x401698 "Hello, world!\n"
f7dc1244 6716(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6717$2 = 72 'H'
f7dc1244 6718(@value{GDBP})
10998722 6719@end smallexample
a0eb71c5
KB
6720
6721@value{GDBN} uses the target character set for character and string
6722literals you use in expressions:
6723
6724@smallexample
f7dc1244 6725(@value{GDBP}) print '+'
a0eb71c5 6726$3 = 43 '+'
f7dc1244 6727(@value{GDBP})
10998722 6728@end smallexample
a0eb71c5
KB
6729
6730The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6731character.
6732
6733@value{GDBN} relies on the user to tell it which character set the
6734target program uses. If we print @code{ibm1047_hello} while our target
6735character set is still @sc{ascii}, we get jibberish:
6736
6737@smallexample
f7dc1244 6738(@value{GDBP}) print ibm1047_hello
a0eb71c5 6739$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6740(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6741$5 = 200 '\310'
f7dc1244 6742(@value{GDBP})
10998722 6743@end smallexample
a0eb71c5 6744
e33d66ec 6745If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6746@value{GDBN} tells us the character sets it supports:
6747
6748@smallexample
f7dc1244 6749(@value{GDBP}) set target-charset
b383017d 6750ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6751(@value{GDBP}) set target-charset
10998722 6752@end smallexample
a0eb71c5
KB
6753
6754We can select @sc{ibm1047} as our target character set, and examine the
6755program's strings again. Now the @sc{ascii} string is wrong, but
6756@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6757target character set, @sc{ibm1047}, to the host character set,
6758@sc{ascii}, and they display correctly:
6759
6760@smallexample
f7dc1244
EZ
6761(@value{GDBP}) set target-charset IBM1047
6762(@value{GDBP}) show charset
e33d66ec
EZ
6763The current host character set is `ASCII'.
6764The current target character set is `IBM1047'.
f7dc1244 6765(@value{GDBP}) print ascii_hello
a0eb71c5 6766$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6767(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6768$7 = 72 '\110'
f7dc1244 6769(@value{GDBP}) print ibm1047_hello
a0eb71c5 6770$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6771(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6772$9 = 200 'H'
f7dc1244 6773(@value{GDBP})
10998722 6774@end smallexample
a0eb71c5
KB
6775
6776As above, @value{GDBN} uses the target character set for character and
6777string literals you use in expressions:
6778
6779@smallexample
f7dc1244 6780(@value{GDBP}) print '+'
a0eb71c5 6781$10 = 78 '+'
f7dc1244 6782(@value{GDBP})
10998722 6783@end smallexample
a0eb71c5 6784
e33d66ec 6785The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6786character.
6787
09d4efe1
EZ
6788@node Caching Remote Data
6789@section Caching Data of Remote Targets
6790@cindex caching data of remote targets
6791
6792@value{GDBN} can cache data exchanged between the debugger and a
6793remote target (@pxref{Remote}). Such caching generally improves
6794performance, because it reduces the overhead of the remote protocol by
6795bundling memory reads and writes into large chunks. Unfortunately,
6796@value{GDBN} does not currently know anything about volatile
6797registers, and thus data caching will produce incorrect results when
6798volatile registers are in use.
6799
6800@table @code
6801@kindex set remotecache
6802@item set remotecache on
6803@itemx set remotecache off
6804Set caching state for remote targets. When @code{ON}, use data
6805caching. By default, this option is @code{OFF}.
6806
6807@kindex show remotecache
6808@item show remotecache
6809Show the current state of data caching for remote targets.
6810
6811@kindex info dcache
6812@item info dcache
6813Print the information about the data cache performance. The
6814information displayed includes: the dcache width and depth; and for
6815each cache line, how many times it was referenced, and its data and
6816state (dirty, bad, ok, etc.). This command is useful for debugging
6817the data cache operation.
6818@end table
6819
a0eb71c5 6820
e2e0bcd1
JB
6821@node Macros
6822@chapter C Preprocessor Macros
6823
49efadf5 6824Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6825``preprocessor macros'' which expand into strings of tokens.
6826@value{GDBN} can evaluate expressions containing macro invocations, show
6827the result of macro expansion, and show a macro's definition, including
6828where it was defined.
6829
6830You may need to compile your program specially to provide @value{GDBN}
6831with information about preprocessor macros. Most compilers do not
6832include macros in their debugging information, even when you compile
6833with the @option{-g} flag. @xref{Compilation}.
6834
6835A program may define a macro at one point, remove that definition later,
6836and then provide a different definition after that. Thus, at different
6837points in the program, a macro may have different definitions, or have
6838no definition at all. If there is a current stack frame, @value{GDBN}
6839uses the macros in scope at that frame's source code line. Otherwise,
6840@value{GDBN} uses the macros in scope at the current listing location;
6841see @ref{List}.
6842
6843At the moment, @value{GDBN} does not support the @code{##}
6844token-splicing operator, the @code{#} stringification operator, or
6845variable-arity macros.
6846
6847Whenever @value{GDBN} evaluates an expression, it always expands any
6848macro invocations present in the expression. @value{GDBN} also provides
6849the following commands for working with macros explicitly.
6850
6851@table @code
6852
6853@kindex macro expand
6854@cindex macro expansion, showing the results of preprocessor
6855@cindex preprocessor macro expansion, showing the results of
6856@cindex expanding preprocessor macros
6857@item macro expand @var{expression}
6858@itemx macro exp @var{expression}
6859Show the results of expanding all preprocessor macro invocations in
6860@var{expression}. Since @value{GDBN} simply expands macros, but does
6861not parse the result, @var{expression} need not be a valid expression;
6862it can be any string of tokens.
6863
09d4efe1 6864@kindex macro exp1
e2e0bcd1
JB
6865@item macro expand-once @var{expression}
6866@itemx macro exp1 @var{expression}
4644b6e3 6867@cindex expand macro once
e2e0bcd1
JB
6868@i{(This command is not yet implemented.)} Show the results of
6869expanding those preprocessor macro invocations that appear explicitly in
6870@var{expression}. Macro invocations appearing in that expansion are
6871left unchanged. This command allows you to see the effect of a
6872particular macro more clearly, without being confused by further
6873expansions. Since @value{GDBN} simply expands macros, but does not
6874parse the result, @var{expression} need not be a valid expression; it
6875can be any string of tokens.
6876
475b0867 6877@kindex info macro
e2e0bcd1
JB
6878@cindex macro definition, showing
6879@cindex definition, showing a macro's
475b0867 6880@item info macro @var{macro}
e2e0bcd1
JB
6881Show the definition of the macro named @var{macro}, and describe the
6882source location where that definition was established.
6883
6884@kindex macro define
6885@cindex user-defined macros
6886@cindex defining macros interactively
6887@cindex macros, user-defined
6888@item macro define @var{macro} @var{replacement-list}
6889@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6890@i{(This command is not yet implemented.)} Introduce a definition for a
6891preprocessor macro named @var{macro}, invocations of which are replaced
6892by the tokens given in @var{replacement-list}. The first form of this
6893command defines an ``object-like'' macro, which takes no arguments; the
6894second form defines a ``function-like'' macro, which takes the arguments
6895given in @var{arglist}.
6896
6897A definition introduced by this command is in scope in every expression
6898evaluated in @value{GDBN}, until it is removed with the @command{macro
6899undef} command, described below. The definition overrides all
6900definitions for @var{macro} present in the program being debugged, as
6901well as any previous user-supplied definition.
6902
6903@kindex macro undef
6904@item macro undef @var{macro}
6905@i{(This command is not yet implemented.)} Remove any user-supplied
6906definition for the macro named @var{macro}. This command only affects
6907definitions provided with the @command{macro define} command, described
6908above; it cannot remove definitions present in the program being
6909debugged.
6910
09d4efe1
EZ
6911@kindex macro list
6912@item macro list
6913@i{(This command is not yet implemented.)} List all the macros
6914defined using the @code{macro define} command.
e2e0bcd1
JB
6915@end table
6916
6917@cindex macros, example of debugging with
6918Here is a transcript showing the above commands in action. First, we
6919show our source files:
6920
6921@smallexample
6922$ cat sample.c
6923#include <stdio.h>
6924#include "sample.h"
6925
6926#define M 42
6927#define ADD(x) (M + x)
6928
6929main ()
6930@{
6931#define N 28
6932 printf ("Hello, world!\n");
6933#undef N
6934 printf ("We're so creative.\n");
6935#define N 1729
6936 printf ("Goodbye, world!\n");
6937@}
6938$ cat sample.h
6939#define Q <
6940$
6941@end smallexample
6942
6943Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6944We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6945compiler includes information about preprocessor macros in the debugging
6946information.
6947
6948@smallexample
6949$ gcc -gdwarf-2 -g3 sample.c -o sample
6950$
6951@end smallexample
6952
6953Now, we start @value{GDBN} on our sample program:
6954
6955@smallexample
6956$ gdb -nw sample
6957GNU gdb 2002-05-06-cvs
6958Copyright 2002 Free Software Foundation, Inc.
6959GDB is free software, @dots{}
f7dc1244 6960(@value{GDBP})
e2e0bcd1
JB
6961@end smallexample
6962
6963We can expand macros and examine their definitions, even when the
6964program is not running. @value{GDBN} uses the current listing position
6965to decide which macro definitions are in scope:
6966
6967@smallexample
f7dc1244 6968(@value{GDBP}) list main
e2e0bcd1
JB
69693
69704 #define M 42
69715 #define ADD(x) (M + x)
69726
69737 main ()
69748 @{
69759 #define N 28
697610 printf ("Hello, world!\n");
697711 #undef N
697812 printf ("We're so creative.\n");
f7dc1244 6979(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6980Defined at /home/jimb/gdb/macros/play/sample.c:5
6981#define ADD(x) (M + x)
f7dc1244 6982(@value{GDBP}) info macro Q
e2e0bcd1
JB
6983Defined at /home/jimb/gdb/macros/play/sample.h:1
6984 included at /home/jimb/gdb/macros/play/sample.c:2
6985#define Q <
f7dc1244 6986(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6987expands to: (42 + 1)
f7dc1244 6988(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6989expands to: once (M + 1)
f7dc1244 6990(@value{GDBP})
e2e0bcd1
JB
6991@end smallexample
6992
6993In the example above, note that @command{macro expand-once} expands only
6994the macro invocation explicit in the original text --- the invocation of
6995@code{ADD} --- but does not expand the invocation of the macro @code{M},
6996which was introduced by @code{ADD}.
6997
6998Once the program is running, GDB uses the macro definitions in force at
6999the source line of the current stack frame:
7000
7001@smallexample
f7dc1244 7002(@value{GDBP}) break main
e2e0bcd1 7003Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7004(@value{GDBP}) run
b383017d 7005Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7006
7007Breakpoint 1, main () at sample.c:10
700810 printf ("Hello, world!\n");
f7dc1244 7009(@value{GDBP})
e2e0bcd1
JB
7010@end smallexample
7011
7012At line 10, the definition of the macro @code{N} at line 9 is in force:
7013
7014@smallexample
f7dc1244 7015(@value{GDBP}) info macro N
e2e0bcd1
JB
7016Defined at /home/jimb/gdb/macros/play/sample.c:9
7017#define N 28
f7dc1244 7018(@value{GDBP}) macro expand N Q M
e2e0bcd1 7019expands to: 28 < 42
f7dc1244 7020(@value{GDBP}) print N Q M
e2e0bcd1 7021$1 = 1
f7dc1244 7022(@value{GDBP})
e2e0bcd1
JB
7023@end smallexample
7024
7025As we step over directives that remove @code{N}'s definition, and then
7026give it a new definition, @value{GDBN} finds the definition (or lack
7027thereof) in force at each point:
7028
7029@smallexample
f7dc1244 7030(@value{GDBP}) next
e2e0bcd1
JB
7031Hello, world!
703212 printf ("We're so creative.\n");
f7dc1244 7033(@value{GDBP}) info macro N
e2e0bcd1
JB
7034The symbol `N' has no definition as a C/C++ preprocessor macro
7035at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7036(@value{GDBP}) next
e2e0bcd1
JB
7037We're so creative.
703814 printf ("Goodbye, world!\n");
f7dc1244 7039(@value{GDBP}) info macro N
e2e0bcd1
JB
7040Defined at /home/jimb/gdb/macros/play/sample.c:13
7041#define N 1729
f7dc1244 7042(@value{GDBP}) macro expand N Q M
e2e0bcd1 7043expands to: 1729 < 42
f7dc1244 7044(@value{GDBP}) print N Q M
e2e0bcd1 7045$2 = 0
f7dc1244 7046(@value{GDBP})
e2e0bcd1
JB
7047@end smallexample
7048
7049
b37052ae
EZ
7050@node Tracepoints
7051@chapter Tracepoints
7052@c This chapter is based on the documentation written by Michael
7053@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7054
7055@cindex tracepoints
7056In some applications, it is not feasible for the debugger to interrupt
7057the program's execution long enough for the developer to learn
7058anything helpful about its behavior. If the program's correctness
7059depends on its real-time behavior, delays introduced by a debugger
7060might cause the program to change its behavior drastically, or perhaps
7061fail, even when the code itself is correct. It is useful to be able
7062to observe the program's behavior without interrupting it.
7063
7064Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7065specify locations in the program, called @dfn{tracepoints}, and
7066arbitrary expressions to evaluate when those tracepoints are reached.
7067Later, using the @code{tfind} command, you can examine the values
7068those expressions had when the program hit the tracepoints. The
7069expressions may also denote objects in memory---structures or arrays,
7070for example---whose values @value{GDBN} should record; while visiting
7071a particular tracepoint, you may inspect those objects as if they were
7072in memory at that moment. However, because @value{GDBN} records these
7073values without interacting with you, it can do so quickly and
7074unobtrusively, hopefully not disturbing the program's behavior.
7075
7076The tracepoint facility is currently available only for remote
2c0069bb
EZ
7077targets. @xref{Targets}. In addition, your remote target must know how
7078to collect trace data. This functionality is implemented in the remote
7079stub; however, none of the stubs distributed with @value{GDBN} support
7080tracepoints as of this writing.
b37052ae
EZ
7081
7082This chapter describes the tracepoint commands and features.
7083
7084@menu
b383017d
RM
7085* Set Tracepoints::
7086* Analyze Collected Data::
7087* Tracepoint Variables::
b37052ae
EZ
7088@end menu
7089
7090@node Set Tracepoints
7091@section Commands to Set Tracepoints
7092
7093Before running such a @dfn{trace experiment}, an arbitrary number of
7094tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7095tracepoint has a number assigned to it by @value{GDBN}. Like with
7096breakpoints, tracepoint numbers are successive integers starting from
7097one. Many of the commands associated with tracepoints take the
7098tracepoint number as their argument, to identify which tracepoint to
7099work on.
7100
7101For each tracepoint, you can specify, in advance, some arbitrary set
7102of data that you want the target to collect in the trace buffer when
7103it hits that tracepoint. The collected data can include registers,
7104local variables, or global data. Later, you can use @value{GDBN}
7105commands to examine the values these data had at the time the
7106tracepoint was hit.
7107
7108This section describes commands to set tracepoints and associated
7109conditions and actions.
7110
7111@menu
b383017d
RM
7112* Create and Delete Tracepoints::
7113* Enable and Disable Tracepoints::
7114* Tracepoint Passcounts::
7115* Tracepoint Actions::
7116* Listing Tracepoints::
7117* Starting and Stopping Trace Experiment::
b37052ae
EZ
7118@end menu
7119
7120@node Create and Delete Tracepoints
7121@subsection Create and Delete Tracepoints
7122
7123@table @code
7124@cindex set tracepoint
7125@kindex trace
7126@item trace
7127The @code{trace} command is very similar to the @code{break} command.
7128Its argument can be a source line, a function name, or an address in
7129the target program. @xref{Set Breaks}. The @code{trace} command
7130defines a tracepoint, which is a point in the target program where the
7131debugger will briefly stop, collect some data, and then allow the
7132program to continue. Setting a tracepoint or changing its commands
7133doesn't take effect until the next @code{tstart} command; thus, you
7134cannot change the tracepoint attributes once a trace experiment is
7135running.
7136
7137Here are some examples of using the @code{trace} command:
7138
7139@smallexample
7140(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7141
7142(@value{GDBP}) @b{trace +2} // 2 lines forward
7143
7144(@value{GDBP}) @b{trace my_function} // first source line of function
7145
7146(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7147
7148(@value{GDBP}) @b{trace *0x2117c4} // an address
7149@end smallexample
7150
7151@noindent
7152You can abbreviate @code{trace} as @code{tr}.
7153
7154@vindex $tpnum
7155@cindex last tracepoint number
7156@cindex recent tracepoint number
7157@cindex tracepoint number
7158The convenience variable @code{$tpnum} records the tracepoint number
7159of the most recently set tracepoint.
7160
7161@kindex delete tracepoint
7162@cindex tracepoint deletion
7163@item delete tracepoint @r{[}@var{num}@r{]}
7164Permanently delete one or more tracepoints. With no argument, the
7165default is to delete all tracepoints.
7166
7167Examples:
7168
7169@smallexample
7170(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7171
7172(@value{GDBP}) @b{delete trace} // remove all tracepoints
7173@end smallexample
7174
7175@noindent
7176You can abbreviate this command as @code{del tr}.
7177@end table
7178
7179@node Enable and Disable Tracepoints
7180@subsection Enable and Disable Tracepoints
7181
7182@table @code
7183@kindex disable tracepoint
7184@item disable tracepoint @r{[}@var{num}@r{]}
7185Disable tracepoint @var{num}, or all tracepoints if no argument
7186@var{num} is given. A disabled tracepoint will have no effect during
7187the next trace experiment, but it is not forgotten. You can re-enable
7188a disabled tracepoint using the @code{enable tracepoint} command.
7189
7190@kindex enable tracepoint
7191@item enable tracepoint @r{[}@var{num}@r{]}
7192Enable tracepoint @var{num}, or all tracepoints. The enabled
7193tracepoints will become effective the next time a trace experiment is
7194run.
7195@end table
7196
7197@node Tracepoint Passcounts
7198@subsection Tracepoint Passcounts
7199
7200@table @code
7201@kindex passcount
7202@cindex tracepoint pass count
7203@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7204Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7205automatically stop a trace experiment. If a tracepoint's passcount is
7206@var{n}, then the trace experiment will be automatically stopped on
7207the @var{n}'th time that tracepoint is hit. If the tracepoint number
7208@var{num} is not specified, the @code{passcount} command sets the
7209passcount of the most recently defined tracepoint. If no passcount is
7210given, the trace experiment will run until stopped explicitly by the
7211user.
7212
7213Examples:
7214
7215@smallexample
b383017d 7216(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7217@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7218
7219(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7220@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7221(@value{GDBP}) @b{trace foo}
7222(@value{GDBP}) @b{pass 3}
7223(@value{GDBP}) @b{trace bar}
7224(@value{GDBP}) @b{pass 2}
7225(@value{GDBP}) @b{trace baz}
7226(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7227@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7228@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7229@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7230@end smallexample
7231@end table
7232
7233@node Tracepoint Actions
7234@subsection Tracepoint Action Lists
7235
7236@table @code
7237@kindex actions
7238@cindex tracepoint actions
7239@item actions @r{[}@var{num}@r{]}
7240This command will prompt for a list of actions to be taken when the
7241tracepoint is hit. If the tracepoint number @var{num} is not
7242specified, this command sets the actions for the one that was most
7243recently defined (so that you can define a tracepoint and then say
7244@code{actions} without bothering about its number). You specify the
7245actions themselves on the following lines, one action at a time, and
7246terminate the actions list with a line containing just @code{end}. So
7247far, the only defined actions are @code{collect} and
7248@code{while-stepping}.
7249
7250@cindex remove actions from a tracepoint
7251To remove all actions from a tracepoint, type @samp{actions @var{num}}
7252and follow it immediately with @samp{end}.
7253
7254@smallexample
7255(@value{GDBP}) @b{collect @var{data}} // collect some data
7256
6826cf00 7257(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7258
6826cf00 7259(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7260@end smallexample
7261
7262In the following example, the action list begins with @code{collect}
7263commands indicating the things to be collected when the tracepoint is
7264hit. Then, in order to single-step and collect additional data
7265following the tracepoint, a @code{while-stepping} command is used,
7266followed by the list of things to be collected while stepping. The
7267@code{while-stepping} command is terminated by its own separate
7268@code{end} command. Lastly, the action list is terminated by an
7269@code{end} command.
7270
7271@smallexample
7272(@value{GDBP}) @b{trace foo}
7273(@value{GDBP}) @b{actions}
7274Enter actions for tracepoint 1, one per line:
7275> collect bar,baz
7276> collect $regs
7277> while-stepping 12
7278 > collect $fp, $sp
7279 > end
7280end
7281@end smallexample
7282
7283@kindex collect @r{(tracepoints)}
7284@item collect @var{expr1}, @var{expr2}, @dots{}
7285Collect values of the given expressions when the tracepoint is hit.
7286This command accepts a comma-separated list of any valid expressions.
7287In addition to global, static, or local variables, the following
7288special arguments are supported:
7289
7290@table @code
7291@item $regs
7292collect all registers
7293
7294@item $args
7295collect all function arguments
7296
7297@item $locals
7298collect all local variables.
7299@end table
7300
7301You can give several consecutive @code{collect} commands, each one
7302with a single argument, or one @code{collect} command with several
7303arguments separated by commas: the effect is the same.
7304
f5c37c66
EZ
7305The command @code{info scope} (@pxref{Symbols, info scope}) is
7306particularly useful for figuring out what data to collect.
7307
b37052ae
EZ
7308@kindex while-stepping @r{(tracepoints)}
7309@item while-stepping @var{n}
7310Perform @var{n} single-step traces after the tracepoint, collecting
7311new data at each step. The @code{while-stepping} command is
7312followed by the list of what to collect while stepping (followed by
7313its own @code{end} command):
7314
7315@smallexample
7316> while-stepping 12
7317 > collect $regs, myglobal
7318 > end
7319>
7320@end smallexample
7321
7322@noindent
7323You may abbreviate @code{while-stepping} as @code{ws} or
7324@code{stepping}.
7325@end table
7326
7327@node Listing Tracepoints
7328@subsection Listing Tracepoints
7329
7330@table @code
7331@kindex info tracepoints
09d4efe1 7332@kindex info tp
b37052ae
EZ
7333@cindex information about tracepoints
7334@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7335Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7336a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7337defined so far. For each tracepoint, the following information is
7338shown:
7339
7340@itemize @bullet
7341@item
7342its number
7343@item
7344whether it is enabled or disabled
7345@item
7346its address
7347@item
7348its passcount as given by the @code{passcount @var{n}} command
7349@item
7350its step count as given by the @code{while-stepping @var{n}} command
7351@item
7352where in the source files is the tracepoint set
7353@item
7354its action list as given by the @code{actions} command
7355@end itemize
7356
7357@smallexample
7358(@value{GDBP}) @b{info trace}
7359Num Enb Address PassC StepC What
73601 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73612 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73623 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7363(@value{GDBP})
7364@end smallexample
7365
7366@noindent
7367This command can be abbreviated @code{info tp}.
7368@end table
7369
7370@node Starting and Stopping Trace Experiment
7371@subsection Starting and Stopping Trace Experiment
7372
7373@table @code
7374@kindex tstart
7375@cindex start a new trace experiment
7376@cindex collected data discarded
7377@item tstart
7378This command takes no arguments. It starts the trace experiment, and
7379begins collecting data. This has the side effect of discarding all
7380the data collected in the trace buffer during the previous trace
7381experiment.
7382
7383@kindex tstop
7384@cindex stop a running trace experiment
7385@item tstop
7386This command takes no arguments. It ends the trace experiment, and
7387stops collecting data.
7388
68c71a2e 7389@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7390automatically if any tracepoint's passcount is reached
7391(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7392
7393@kindex tstatus
7394@cindex status of trace data collection
7395@cindex trace experiment, status of
7396@item tstatus
7397This command displays the status of the current trace data
7398collection.
7399@end table
7400
7401Here is an example of the commands we described so far:
7402
7403@smallexample
7404(@value{GDBP}) @b{trace gdb_c_test}
7405(@value{GDBP}) @b{actions}
7406Enter actions for tracepoint #1, one per line.
7407> collect $regs,$locals,$args
7408> while-stepping 11
7409 > collect $regs
7410 > end
7411> end
7412(@value{GDBP}) @b{tstart}
7413 [time passes @dots{}]
7414(@value{GDBP}) @b{tstop}
7415@end smallexample
7416
7417
7418@node Analyze Collected Data
7419@section Using the collected data
7420
7421After the tracepoint experiment ends, you use @value{GDBN} commands
7422for examining the trace data. The basic idea is that each tracepoint
7423collects a trace @dfn{snapshot} every time it is hit and another
7424snapshot every time it single-steps. All these snapshots are
7425consecutively numbered from zero and go into a buffer, and you can
7426examine them later. The way you examine them is to @dfn{focus} on a
7427specific trace snapshot. When the remote stub is focused on a trace
7428snapshot, it will respond to all @value{GDBN} requests for memory and
7429registers by reading from the buffer which belongs to that snapshot,
7430rather than from @emph{real} memory or registers of the program being
7431debugged. This means that @strong{all} @value{GDBN} commands
7432(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7433behave as if we were currently debugging the program state as it was
7434when the tracepoint occurred. Any requests for data that are not in
7435the buffer will fail.
7436
7437@menu
7438* tfind:: How to select a trace snapshot
7439* tdump:: How to display all data for a snapshot
7440* save-tracepoints:: How to save tracepoints for a future run
7441@end menu
7442
7443@node tfind
7444@subsection @code{tfind @var{n}}
7445
7446@kindex tfind
7447@cindex select trace snapshot
7448@cindex find trace snapshot
7449The basic command for selecting a trace snapshot from the buffer is
7450@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7451counting from zero. If no argument @var{n} is given, the next
7452snapshot is selected.
7453
7454Here are the various forms of using the @code{tfind} command.
7455
7456@table @code
7457@item tfind start
7458Find the first snapshot in the buffer. This is a synonym for
7459@code{tfind 0} (since 0 is the number of the first snapshot).
7460
7461@item tfind none
7462Stop debugging trace snapshots, resume @emph{live} debugging.
7463
7464@item tfind end
7465Same as @samp{tfind none}.
7466
7467@item tfind
7468No argument means find the next trace snapshot.
7469
7470@item tfind -
7471Find the previous trace snapshot before the current one. This permits
7472retracing earlier steps.
7473
7474@item tfind tracepoint @var{num}
7475Find the next snapshot associated with tracepoint @var{num}. Search
7476proceeds forward from the last examined trace snapshot. If no
7477argument @var{num} is given, it means find the next snapshot collected
7478for the same tracepoint as the current snapshot.
7479
7480@item tfind pc @var{addr}
7481Find the next snapshot associated with the value @var{addr} of the
7482program counter. Search proceeds forward from the last examined trace
7483snapshot. If no argument @var{addr} is given, it means find the next
7484snapshot with the same value of PC as the current snapshot.
7485
7486@item tfind outside @var{addr1}, @var{addr2}
7487Find the next snapshot whose PC is outside the given range of
7488addresses.
7489
7490@item tfind range @var{addr1}, @var{addr2}
7491Find the next snapshot whose PC is between @var{addr1} and
7492@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7493
7494@item tfind line @r{[}@var{file}:@r{]}@var{n}
7495Find the next snapshot associated with the source line @var{n}. If
7496the optional argument @var{file} is given, refer to line @var{n} in
7497that source file. Search proceeds forward from the last examined
7498trace snapshot. If no argument @var{n} is given, it means find the
7499next line other than the one currently being examined; thus saying
7500@code{tfind line} repeatedly can appear to have the same effect as
7501stepping from line to line in a @emph{live} debugging session.
7502@end table
7503
7504The default arguments for the @code{tfind} commands are specifically
7505designed to make it easy to scan through the trace buffer. For
7506instance, @code{tfind} with no argument selects the next trace
7507snapshot, and @code{tfind -} with no argument selects the previous
7508trace snapshot. So, by giving one @code{tfind} command, and then
7509simply hitting @key{RET} repeatedly you can examine all the trace
7510snapshots in order. Or, by saying @code{tfind -} and then hitting
7511@key{RET} repeatedly you can examine the snapshots in reverse order.
7512The @code{tfind line} command with no argument selects the snapshot
7513for the next source line executed. The @code{tfind pc} command with
7514no argument selects the next snapshot with the same program counter
7515(PC) as the current frame. The @code{tfind tracepoint} command with
7516no argument selects the next trace snapshot collected by the same
7517tracepoint as the current one.
7518
7519In addition to letting you scan through the trace buffer manually,
7520these commands make it easy to construct @value{GDBN} scripts that
7521scan through the trace buffer and print out whatever collected data
7522you are interested in. Thus, if we want to examine the PC, FP, and SP
7523registers from each trace frame in the buffer, we can say this:
7524
7525@smallexample
7526(@value{GDBP}) @b{tfind start}
7527(@value{GDBP}) @b{while ($trace_frame != -1)}
7528> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7529 $trace_frame, $pc, $sp, $fp
7530> tfind
7531> end
7532
7533Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7534Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7535Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7536Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7537Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7538Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7539Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7540Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7541Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7542Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7543Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7544@end smallexample
7545
7546Or, if we want to examine the variable @code{X} at each source line in
7547the buffer:
7548
7549@smallexample
7550(@value{GDBP}) @b{tfind start}
7551(@value{GDBP}) @b{while ($trace_frame != -1)}
7552> printf "Frame %d, X == %d\n", $trace_frame, X
7553> tfind line
7554> end
7555
7556Frame 0, X = 1
7557Frame 7, X = 2
7558Frame 13, X = 255
7559@end smallexample
7560
7561@node tdump
7562@subsection @code{tdump}
7563@kindex tdump
7564@cindex dump all data collected at tracepoint
7565@cindex tracepoint data, display
7566
7567This command takes no arguments. It prints all the data collected at
7568the current trace snapshot.
7569
7570@smallexample
7571(@value{GDBP}) @b{trace 444}
7572(@value{GDBP}) @b{actions}
7573Enter actions for tracepoint #2, one per line:
7574> collect $regs, $locals, $args, gdb_long_test
7575> end
7576
7577(@value{GDBP}) @b{tstart}
7578
7579(@value{GDBP}) @b{tfind line 444}
7580#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7581at gdb_test.c:444
7582444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7583
7584(@value{GDBP}) @b{tdump}
7585Data collected at tracepoint 2, trace frame 1:
7586d0 0xc4aa0085 -995491707
7587d1 0x18 24
7588d2 0x80 128
7589d3 0x33 51
7590d4 0x71aea3d 119204413
7591d5 0x22 34
7592d6 0xe0 224
7593d7 0x380035 3670069
7594a0 0x19e24a 1696330
7595a1 0x3000668 50333288
7596a2 0x100 256
7597a3 0x322000 3284992
7598a4 0x3000698 50333336
7599a5 0x1ad3cc 1758156
7600fp 0x30bf3c 0x30bf3c
7601sp 0x30bf34 0x30bf34
7602ps 0x0 0
7603pc 0x20b2c8 0x20b2c8
7604fpcontrol 0x0 0
7605fpstatus 0x0 0
7606fpiaddr 0x0 0
7607p = 0x20e5b4 "gdb-test"
7608p1 = (void *) 0x11
7609p2 = (void *) 0x22
7610p3 = (void *) 0x33
7611p4 = (void *) 0x44
7612p5 = (void *) 0x55
7613p6 = (void *) 0x66
7614gdb_long_test = 17 '\021'
7615
7616(@value{GDBP})
7617@end smallexample
7618
7619@node save-tracepoints
7620@subsection @code{save-tracepoints @var{filename}}
7621@kindex save-tracepoints
7622@cindex save tracepoints for future sessions
7623
7624This command saves all current tracepoint definitions together with
7625their actions and passcounts, into a file @file{@var{filename}}
7626suitable for use in a later debugging session. To read the saved
7627tracepoint definitions, use the @code{source} command (@pxref{Command
7628Files}).
7629
7630@node Tracepoint Variables
7631@section Convenience Variables for Tracepoints
7632@cindex tracepoint variables
7633@cindex convenience variables for tracepoints
7634
7635@table @code
7636@vindex $trace_frame
7637@item (int) $trace_frame
7638The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7639snapshot is selected.
7640
7641@vindex $tracepoint
7642@item (int) $tracepoint
7643The tracepoint for the current trace snapshot.
7644
7645@vindex $trace_line
7646@item (int) $trace_line
7647The line number for the current trace snapshot.
7648
7649@vindex $trace_file
7650@item (char []) $trace_file
7651The source file for the current trace snapshot.
7652
7653@vindex $trace_func
7654@item (char []) $trace_func
7655The name of the function containing @code{$tracepoint}.
7656@end table
7657
7658Note: @code{$trace_file} is not suitable for use in @code{printf},
7659use @code{output} instead.
7660
7661Here's a simple example of using these convenience variables for
7662stepping through all the trace snapshots and printing some of their
7663data.
7664
7665@smallexample
7666(@value{GDBP}) @b{tfind start}
7667
7668(@value{GDBP}) @b{while $trace_frame != -1}
7669> output $trace_file
7670> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7671> tfind
7672> end
7673@end smallexample
7674
df0cd8c5
JB
7675@node Overlays
7676@chapter Debugging Programs That Use Overlays
7677@cindex overlays
7678
7679If your program is too large to fit completely in your target system's
7680memory, you can sometimes use @dfn{overlays} to work around this
7681problem. @value{GDBN} provides some support for debugging programs that
7682use overlays.
7683
7684@menu
7685* How Overlays Work:: A general explanation of overlays.
7686* Overlay Commands:: Managing overlays in @value{GDBN}.
7687* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7688 mapped by asking the inferior.
7689* Overlay Sample Program:: A sample program using overlays.
7690@end menu
7691
7692@node How Overlays Work
7693@section How Overlays Work
7694@cindex mapped overlays
7695@cindex unmapped overlays
7696@cindex load address, overlay's
7697@cindex mapped address
7698@cindex overlay area
7699
7700Suppose you have a computer whose instruction address space is only 64
7701kilobytes long, but which has much more memory which can be accessed by
7702other means: special instructions, segment registers, or memory
7703management hardware, for example. Suppose further that you want to
7704adapt a program which is larger than 64 kilobytes to run on this system.
7705
7706One solution is to identify modules of your program which are relatively
7707independent, and need not call each other directly; call these modules
7708@dfn{overlays}. Separate the overlays from the main program, and place
7709their machine code in the larger memory. Place your main program in
7710instruction memory, but leave at least enough space there to hold the
7711largest overlay as well.
7712
7713Now, to call a function located in an overlay, you must first copy that
7714overlay's machine code from the large memory into the space set aside
7715for it in the instruction memory, and then jump to its entry point
7716there.
7717
c928edc0
AC
7718@c NB: In the below the mapped area's size is greater or equal to the
7719@c size of all overlays. This is intentional to remind the developer
7720@c that overlays don't necessarily need to be the same size.
7721
474c8240 7722@smallexample
df0cd8c5 7723@group
c928edc0
AC
7724 Data Instruction Larger
7725Address Space Address Space Address Space
7726+-----------+ +-----------+ +-----------+
7727| | | | | |
7728+-----------+ +-----------+ +-----------+<-- overlay 1
7729| program | | main | .----| overlay 1 | load address
7730| variables | | program | | +-----------+
7731| and heap | | | | | |
7732+-----------+ | | | +-----------+<-- overlay 2
7733| | +-----------+ | | | load address
7734+-----------+ | | | .-| overlay 2 |
7735 | | | | | |
7736 mapped --->+-----------+ | | +-----------+
7737 address | | | | | |
7738 | overlay | <-' | | |
7739 | area | <---' +-----------+<-- overlay 3
7740 | | <---. | | load address
7741 +-----------+ `--| overlay 3 |
7742 | | | |
7743 +-----------+ | |
7744 +-----------+
7745 | |
7746 +-----------+
7747
7748 @anchor{A code overlay}A code overlay
df0cd8c5 7749@end group
474c8240 7750@end smallexample
df0cd8c5 7751
c928edc0
AC
7752The diagram (@pxref{A code overlay}) shows a system with separate data
7753and instruction address spaces. To map an overlay, the program copies
7754its code from the larger address space to the instruction address space.
7755Since the overlays shown here all use the same mapped address, only one
7756may be mapped at a time. For a system with a single address space for
7757data and instructions, the diagram would be similar, except that the
7758program variables and heap would share an address space with the main
7759program and the overlay area.
df0cd8c5
JB
7760
7761An overlay loaded into instruction memory and ready for use is called a
7762@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7763instruction memory. An overlay not present (or only partially present)
7764in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7765is its address in the larger memory. The mapped address is also called
7766the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7767called the @dfn{load memory address}, or @dfn{LMA}.
7768
7769Unfortunately, overlays are not a completely transparent way to adapt a
7770program to limited instruction memory. They introduce a new set of
7771global constraints you must keep in mind as you design your program:
7772
7773@itemize @bullet
7774
7775@item
7776Before calling or returning to a function in an overlay, your program
7777must make sure that overlay is actually mapped. Otherwise, the call or
7778return will transfer control to the right address, but in the wrong
7779overlay, and your program will probably crash.
7780
7781@item
7782If the process of mapping an overlay is expensive on your system, you
7783will need to choose your overlays carefully to minimize their effect on
7784your program's performance.
7785
7786@item
7787The executable file you load onto your system must contain each
7788overlay's instructions, appearing at the overlay's load address, not its
7789mapped address. However, each overlay's instructions must be relocated
7790and its symbols defined as if the overlay were at its mapped address.
7791You can use GNU linker scripts to specify different load and relocation
7792addresses for pieces of your program; see @ref{Overlay Description,,,
7793ld.info, Using ld: the GNU linker}.
7794
7795@item
7796The procedure for loading executable files onto your system must be able
7797to load their contents into the larger address space as well as the
7798instruction and data spaces.
7799
7800@end itemize
7801
7802The overlay system described above is rather simple, and could be
7803improved in many ways:
7804
7805@itemize @bullet
7806
7807@item
7808If your system has suitable bank switch registers or memory management
7809hardware, you could use those facilities to make an overlay's load area
7810contents simply appear at their mapped address in instruction space.
7811This would probably be faster than copying the overlay to its mapped
7812area in the usual way.
7813
7814@item
7815If your overlays are small enough, you could set aside more than one
7816overlay area, and have more than one overlay mapped at a time.
7817
7818@item
7819You can use overlays to manage data, as well as instructions. In
7820general, data overlays are even less transparent to your design than
7821code overlays: whereas code overlays only require care when you call or
7822return to functions, data overlays require care every time you access
7823the data. Also, if you change the contents of a data overlay, you
7824must copy its contents back out to its load address before you can copy a
7825different data overlay into the same mapped area.
7826
7827@end itemize
7828
7829
7830@node Overlay Commands
7831@section Overlay Commands
7832
7833To use @value{GDBN}'s overlay support, each overlay in your program must
7834correspond to a separate section of the executable file. The section's
7835virtual memory address and load memory address must be the overlay's
7836mapped and load addresses. Identifying overlays with sections allows
7837@value{GDBN} to determine the appropriate address of a function or
7838variable, depending on whether the overlay is mapped or not.
7839
7840@value{GDBN}'s overlay commands all start with the word @code{overlay};
7841you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7842
7843@table @code
7844@item overlay off
4644b6e3 7845@kindex overlay
df0cd8c5
JB
7846Disable @value{GDBN}'s overlay support. When overlay support is
7847disabled, @value{GDBN} assumes that all functions and variables are
7848always present at their mapped addresses. By default, @value{GDBN}'s
7849overlay support is disabled.
7850
7851@item overlay manual
df0cd8c5
JB
7852@cindex manual overlay debugging
7853Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7854relies on you to tell it which overlays are mapped, and which are not,
7855using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7856commands described below.
7857
7858@item overlay map-overlay @var{overlay}
7859@itemx overlay map @var{overlay}
df0cd8c5
JB
7860@cindex map an overlay
7861Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7862be the name of the object file section containing the overlay. When an
7863overlay is mapped, @value{GDBN} assumes it can find the overlay's
7864functions and variables at their mapped addresses. @value{GDBN} assumes
7865that any other overlays whose mapped ranges overlap that of
7866@var{overlay} are now unmapped.
7867
7868@item overlay unmap-overlay @var{overlay}
7869@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7870@cindex unmap an overlay
7871Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7872must be the name of the object file section containing the overlay.
7873When an overlay is unmapped, @value{GDBN} assumes it can find the
7874overlay's functions and variables at their load addresses.
7875
7876@item overlay auto
df0cd8c5
JB
7877Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7878consults a data structure the overlay manager maintains in the inferior
7879to see which overlays are mapped. For details, see @ref{Automatic
7880Overlay Debugging}.
7881
7882@item overlay load-target
7883@itemx overlay load
df0cd8c5
JB
7884@cindex reloading the overlay table
7885Re-read the overlay table from the inferior. Normally, @value{GDBN}
7886re-reads the table @value{GDBN} automatically each time the inferior
7887stops, so this command should only be necessary if you have changed the
7888overlay mapping yourself using @value{GDBN}. This command is only
7889useful when using automatic overlay debugging.
7890
7891@item overlay list-overlays
7892@itemx overlay list
7893@cindex listing mapped overlays
7894Display a list of the overlays currently mapped, along with their mapped
7895addresses, load addresses, and sizes.
7896
7897@end table
7898
7899Normally, when @value{GDBN} prints a code address, it includes the name
7900of the function the address falls in:
7901
474c8240 7902@smallexample
f7dc1244 7903(@value{GDBP}) print main
df0cd8c5 7904$3 = @{int ()@} 0x11a0 <main>
474c8240 7905@end smallexample
df0cd8c5
JB
7906@noindent
7907When overlay debugging is enabled, @value{GDBN} recognizes code in
7908unmapped overlays, and prints the names of unmapped functions with
7909asterisks around them. For example, if @code{foo} is a function in an
7910unmapped overlay, @value{GDBN} prints it this way:
7911
474c8240 7912@smallexample
f7dc1244 7913(@value{GDBP}) overlay list
df0cd8c5 7914No sections are mapped.
f7dc1244 7915(@value{GDBP}) print foo
df0cd8c5 7916$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7917@end smallexample
df0cd8c5
JB
7918@noindent
7919When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7920name normally:
7921
474c8240 7922@smallexample
f7dc1244 7923(@value{GDBP}) overlay list
b383017d 7924Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7925 mapped at 0x1016 - 0x104a
f7dc1244 7926(@value{GDBP}) print foo
df0cd8c5 7927$6 = @{int (int)@} 0x1016 <foo>
474c8240 7928@end smallexample
df0cd8c5
JB
7929
7930When overlay debugging is enabled, @value{GDBN} can find the correct
7931address for functions and variables in an overlay, whether or not the
7932overlay is mapped. This allows most @value{GDBN} commands, like
7933@code{break} and @code{disassemble}, to work normally, even on unmapped
7934code. However, @value{GDBN}'s breakpoint support has some limitations:
7935
7936@itemize @bullet
7937@item
7938@cindex breakpoints in overlays
7939@cindex overlays, setting breakpoints in
7940You can set breakpoints in functions in unmapped overlays, as long as
7941@value{GDBN} can write to the overlay at its load address.
7942@item
7943@value{GDBN} can not set hardware or simulator-based breakpoints in
7944unmapped overlays. However, if you set a breakpoint at the end of your
7945overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7946you are using manual overlay management), @value{GDBN} will re-set its
7947breakpoints properly.
7948@end itemize
7949
7950
7951@node Automatic Overlay Debugging
7952@section Automatic Overlay Debugging
7953@cindex automatic overlay debugging
7954
7955@value{GDBN} can automatically track which overlays are mapped and which
7956are not, given some simple co-operation from the overlay manager in the
7957inferior. If you enable automatic overlay debugging with the
7958@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7959looks in the inferior's memory for certain variables describing the
7960current state of the overlays.
7961
7962Here are the variables your overlay manager must define to support
7963@value{GDBN}'s automatic overlay debugging:
7964
7965@table @asis
7966
7967@item @code{_ovly_table}:
7968This variable must be an array of the following structures:
7969
474c8240 7970@smallexample
df0cd8c5
JB
7971struct
7972@{
7973 /* The overlay's mapped address. */
7974 unsigned long vma;
7975
7976 /* The size of the overlay, in bytes. */
7977 unsigned long size;
7978
7979 /* The overlay's load address. */
7980 unsigned long lma;
7981
7982 /* Non-zero if the overlay is currently mapped;
7983 zero otherwise. */
7984 unsigned long mapped;
7985@}
474c8240 7986@end smallexample
df0cd8c5
JB
7987
7988@item @code{_novlys}:
7989This variable must be a four-byte signed integer, holding the total
7990number of elements in @code{_ovly_table}.
7991
7992@end table
7993
7994To decide whether a particular overlay is mapped or not, @value{GDBN}
7995looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
7996@code{lma} members equal the VMA and LMA of the overlay's section in the
7997executable file. When @value{GDBN} finds a matching entry, it consults
7998the entry's @code{mapped} member to determine whether the overlay is
7999currently mapped.
8000
81d46470 8001In addition, your overlay manager may define a function called
def71bfa 8002@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8003will silently set a breakpoint there. If the overlay manager then
8004calls this function whenever it has changed the overlay table, this
8005will enable @value{GDBN} to accurately keep track of which overlays
8006are in program memory, and update any breakpoints that may be set
b383017d 8007in overlays. This will allow breakpoints to work even if the
81d46470
MS
8008overlays are kept in ROM or other non-writable memory while they
8009are not being executed.
df0cd8c5
JB
8010
8011@node Overlay Sample Program
8012@section Overlay Sample Program
8013@cindex overlay example program
8014
8015When linking a program which uses overlays, you must place the overlays
8016at their load addresses, while relocating them to run at their mapped
8017addresses. To do this, you must write a linker script (@pxref{Overlay
8018Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8019since linker scripts are specific to a particular host system, target
8020architecture, and target memory layout, this manual cannot provide
8021portable sample code demonstrating @value{GDBN}'s overlay support.
8022
8023However, the @value{GDBN} source distribution does contain an overlaid
8024program, with linker scripts for a few systems, as part of its test
8025suite. The program consists of the following files from
8026@file{gdb/testsuite/gdb.base}:
8027
8028@table @file
8029@item overlays.c
8030The main program file.
8031@item ovlymgr.c
8032A simple overlay manager, used by @file{overlays.c}.
8033@item foo.c
8034@itemx bar.c
8035@itemx baz.c
8036@itemx grbx.c
8037Overlay modules, loaded and used by @file{overlays.c}.
8038@item d10v.ld
8039@itemx m32r.ld
8040Linker scripts for linking the test program on the @code{d10v-elf}
8041and @code{m32r-elf} targets.
8042@end table
8043
8044You can build the test program using the @code{d10v-elf} GCC
8045cross-compiler like this:
8046
474c8240 8047@smallexample
df0cd8c5
JB
8048$ d10v-elf-gcc -g -c overlays.c
8049$ d10v-elf-gcc -g -c ovlymgr.c
8050$ d10v-elf-gcc -g -c foo.c
8051$ d10v-elf-gcc -g -c bar.c
8052$ d10v-elf-gcc -g -c baz.c
8053$ d10v-elf-gcc -g -c grbx.c
8054$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8055 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8056@end smallexample
df0cd8c5
JB
8057
8058The build process is identical for any other architecture, except that
8059you must substitute the appropriate compiler and linker script for the
8060target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8061
8062
6d2ebf8b 8063@node Languages
c906108c
SS
8064@chapter Using @value{GDBN} with Different Languages
8065@cindex languages
8066
c906108c
SS
8067Although programming languages generally have common aspects, they are
8068rarely expressed in the same manner. For instance, in ANSI C,
8069dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8070Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8071represented (and displayed) differently. Hex numbers in C appear as
c906108c 8072@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8073
8074@cindex working language
8075Language-specific information is built into @value{GDBN} for some languages,
8076allowing you to express operations like the above in your program's
8077native language, and allowing @value{GDBN} to output values in a manner
8078consistent with the syntax of your program's native language. The
8079language you use to build expressions is called the @dfn{working
8080language}.
8081
8082@menu
8083* Setting:: Switching between source languages
8084* Show:: Displaying the language
c906108c 8085* Checks:: Type and range checks
9c16f35a 8086* Supported languages:: Supported languages
4e562065 8087* Unsupported languages:: Unsupported languages
c906108c
SS
8088@end menu
8089
6d2ebf8b 8090@node Setting
c906108c
SS
8091@section Switching between source languages
8092
8093There are two ways to control the working language---either have @value{GDBN}
8094set it automatically, or select it manually yourself. You can use the
8095@code{set language} command for either purpose. On startup, @value{GDBN}
8096defaults to setting the language automatically. The working language is
8097used to determine how expressions you type are interpreted, how values
8098are printed, etc.
8099
8100In addition to the working language, every source file that
8101@value{GDBN} knows about has its own working language. For some object
8102file formats, the compiler might indicate which language a particular
8103source file is in. However, most of the time @value{GDBN} infers the
8104language from the name of the file. The language of a source file
b37052ae 8105controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8106show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8107set the language of a source file from within @value{GDBN}, but you can
8108set the language associated with a filename extension. @xref{Show, ,
8109Displaying the language}.
c906108c
SS
8110
8111This is most commonly a problem when you use a program, such
5d161b24 8112as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8113another language. In that case, make the
8114program use @code{#line} directives in its C output; that way
8115@value{GDBN} will know the correct language of the source code of the original
8116program, and will display that source code, not the generated C code.
8117
8118@menu
8119* Filenames:: Filename extensions and languages.
8120* Manually:: Setting the working language manually
8121* Automatically:: Having @value{GDBN} infer the source language
8122@end menu
8123
6d2ebf8b 8124@node Filenames
c906108c
SS
8125@subsection List of filename extensions and languages
8126
8127If a source file name ends in one of the following extensions, then
8128@value{GDBN} infers that its language is the one indicated.
8129
8130@table @file
e07c999f
PH
8131@item .ada
8132@itemx .ads
8133@itemx .adb
8134@itemx .a
8135Ada source file.
c906108c
SS
8136
8137@item .c
8138C source file
8139
8140@item .C
8141@itemx .cc
8142@itemx .cp
8143@itemx .cpp
8144@itemx .cxx
8145@itemx .c++
b37052ae 8146C@t{++} source file
c906108c 8147
b37303ee
AF
8148@item .m
8149Objective-C source file
8150
c906108c
SS
8151@item .f
8152@itemx .F
8153Fortran source file
8154
c906108c
SS
8155@item .mod
8156Modula-2 source file
c906108c
SS
8157
8158@item .s
8159@itemx .S
8160Assembler source file. This actually behaves almost like C, but
8161@value{GDBN} does not skip over function prologues when stepping.
8162@end table
8163
8164In addition, you may set the language associated with a filename
8165extension. @xref{Show, , Displaying the language}.
8166
6d2ebf8b 8167@node Manually
c906108c
SS
8168@subsection Setting the working language
8169
8170If you allow @value{GDBN} to set the language automatically,
8171expressions are interpreted the same way in your debugging session and
8172your program.
8173
8174@kindex set language
8175If you wish, you may set the language manually. To do this, issue the
8176command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8177a language, such as
c906108c 8178@code{c} or @code{modula-2}.
c906108c
SS
8179For a list of the supported languages, type @samp{set language}.
8180
c906108c
SS
8181Setting the language manually prevents @value{GDBN} from updating the working
8182language automatically. This can lead to confusion if you try
8183to debug a program when the working language is not the same as the
8184source language, when an expression is acceptable to both
8185languages---but means different things. For instance, if the current
8186source file were written in C, and @value{GDBN} was parsing Modula-2, a
8187command such as:
8188
474c8240 8189@smallexample
c906108c 8190print a = b + c
474c8240 8191@end smallexample
c906108c
SS
8192
8193@noindent
8194might not have the effect you intended. In C, this means to add
8195@code{b} and @code{c} and place the result in @code{a}. The result
8196printed would be the value of @code{a}. In Modula-2, this means to compare
8197@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8198
6d2ebf8b 8199@node Automatically
c906108c
SS
8200@subsection Having @value{GDBN} infer the source language
8201
8202To have @value{GDBN} set the working language automatically, use
8203@samp{set language local} or @samp{set language auto}. @value{GDBN}
8204then infers the working language. That is, when your program stops in a
8205frame (usually by encountering a breakpoint), @value{GDBN} sets the
8206working language to the language recorded for the function in that
8207frame. If the language for a frame is unknown (that is, if the function
8208or block corresponding to the frame was defined in a source file that
8209does not have a recognized extension), the current working language is
8210not changed, and @value{GDBN} issues a warning.
8211
8212This may not seem necessary for most programs, which are written
8213entirely in one source language. However, program modules and libraries
8214written in one source language can be used by a main program written in
8215a different source language. Using @samp{set language auto} in this
8216case frees you from having to set the working language manually.
8217
6d2ebf8b 8218@node Show
c906108c 8219@section Displaying the language
c906108c
SS
8220
8221The following commands help you find out which language is the
8222working language, and also what language source files were written in.
8223
c906108c
SS
8224@table @code
8225@item show language
9c16f35a 8226@kindex show language
c906108c
SS
8227Display the current working language. This is the
8228language you can use with commands such as @code{print} to
8229build and compute expressions that may involve variables in your program.
8230
8231@item info frame
4644b6e3 8232@kindex info frame@r{, show the source language}
5d161b24 8233Display the source language for this frame. This language becomes the
c906108c 8234working language if you use an identifier from this frame.
5d161b24 8235@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8236information listed here.
8237
8238@item info source
4644b6e3 8239@kindex info source@r{, show the source language}
c906108c 8240Display the source language of this source file.
5d161b24 8241@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8242information listed here.
8243@end table
8244
8245In unusual circumstances, you may have source files with extensions
8246not in the standard list. You can then set the extension associated
8247with a language explicitly:
8248
c906108c 8249@table @code
09d4efe1 8250@item set extension-language @var{ext} @var{language}
9c16f35a 8251@kindex set extension-language
09d4efe1
EZ
8252Tell @value{GDBN} that source files with extension @var{ext} are to be
8253assumed as written in the source language @var{language}.
c906108c
SS
8254
8255@item info extensions
9c16f35a 8256@kindex info extensions
c906108c
SS
8257List all the filename extensions and the associated languages.
8258@end table
8259
6d2ebf8b 8260@node Checks
c906108c
SS
8261@section Type and range checking
8262
8263@quotation
8264@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8265checking are included, but they do not yet have any effect. This
8266section documents the intended facilities.
8267@end quotation
8268@c FIXME remove warning when type/range code added
8269
8270Some languages are designed to guard you against making seemingly common
8271errors through a series of compile- and run-time checks. These include
8272checking the type of arguments to functions and operators, and making
8273sure mathematical overflows are caught at run time. Checks such as
8274these help to ensure a program's correctness once it has been compiled
8275by eliminating type mismatches, and providing active checks for range
8276errors when your program is running.
8277
8278@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8279Although @value{GDBN} does not check the statements in your program,
8280it can check expressions entered directly into @value{GDBN} for
8281evaluation via the @code{print} command, for example. As with the
8282working language, @value{GDBN} can also decide whether or not to check
8283automatically based on your program's source language.
8284@xref{Supported languages, ,Supported languages}, for the default
8285settings of supported languages.
c906108c
SS
8286
8287@menu
8288* Type Checking:: An overview of type checking
8289* Range Checking:: An overview of range checking
8290@end menu
8291
8292@cindex type checking
8293@cindex checks, type
6d2ebf8b 8294@node Type Checking
c906108c
SS
8295@subsection An overview of type checking
8296
8297Some languages, such as Modula-2, are strongly typed, meaning that the
8298arguments to operators and functions have to be of the correct type,
8299otherwise an error occurs. These checks prevent type mismatch
8300errors from ever causing any run-time problems. For example,
8301
8302@smallexample
83031 + 2 @result{} 3
8304@exdent but
8305@error{} 1 + 2.3
8306@end smallexample
8307
8308The second example fails because the @code{CARDINAL} 1 is not
8309type-compatible with the @code{REAL} 2.3.
8310
5d161b24
DB
8311For the expressions you use in @value{GDBN} commands, you can tell the
8312@value{GDBN} type checker to skip checking;
8313to treat any mismatches as errors and abandon the expression;
8314or to only issue warnings when type mismatches occur,
c906108c
SS
8315but evaluate the expression anyway. When you choose the last of
8316these, @value{GDBN} evaluates expressions like the second example above, but
8317also issues a warning.
8318
5d161b24
DB
8319Even if you turn type checking off, there may be other reasons
8320related to type that prevent @value{GDBN} from evaluating an expression.
8321For instance, @value{GDBN} does not know how to add an @code{int} and
8322a @code{struct foo}. These particular type errors have nothing to do
8323with the language in use, and usually arise from expressions, such as
c906108c
SS
8324the one described above, which make little sense to evaluate anyway.
8325
8326Each language defines to what degree it is strict about type. For
8327instance, both Modula-2 and C require the arguments to arithmetical
8328operators to be numbers. In C, enumerated types and pointers can be
8329represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8330operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8331details on specific languages.
8332
8333@value{GDBN} provides some additional commands for controlling the type checker:
8334
c906108c
SS
8335@kindex set check type
8336@kindex show check type
8337@table @code
8338@item set check type auto
8339Set type checking on or off based on the current working language.
9c16f35a 8340@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8341each language.
8342
8343@item set check type on
8344@itemx set check type off
8345Set type checking on or off, overriding the default setting for the
8346current working language. Issue a warning if the setting does not
8347match the language default. If any type mismatches occur in
d4f3574e 8348evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8349message and aborts evaluation of the expression.
8350
8351@item set check type warn
8352Cause the type checker to issue warnings, but to always attempt to
8353evaluate the expression. Evaluating the expression may still
8354be impossible for other reasons. For example, @value{GDBN} cannot add
8355numbers and structures.
8356
8357@item show type
5d161b24 8358Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8359is setting it automatically.
8360@end table
8361
8362@cindex range checking
8363@cindex checks, range
6d2ebf8b 8364@node Range Checking
c906108c
SS
8365@subsection An overview of range checking
8366
8367In some languages (such as Modula-2), it is an error to exceed the
8368bounds of a type; this is enforced with run-time checks. Such range
8369checking is meant to ensure program correctness by making sure
8370computations do not overflow, or indices on an array element access do
8371not exceed the bounds of the array.
8372
8373For expressions you use in @value{GDBN} commands, you can tell
8374@value{GDBN} to treat range errors in one of three ways: ignore them,
8375always treat them as errors and abandon the expression, or issue
8376warnings but evaluate the expression anyway.
8377
8378A range error can result from numerical overflow, from exceeding an
8379array index bound, or when you type a constant that is not a member
8380of any type. Some languages, however, do not treat overflows as an
8381error. In many implementations of C, mathematical overflow causes the
8382result to ``wrap around'' to lower values---for example, if @var{m} is
8383the largest integer value, and @var{s} is the smallest, then
8384
474c8240 8385@smallexample
c906108c 8386@var{m} + 1 @result{} @var{s}
474c8240 8387@end smallexample
c906108c
SS
8388
8389This, too, is specific to individual languages, and in some cases
9c16f35a 8390specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8391Supported languages}, for further details on specific languages.
8392
8393@value{GDBN} provides some additional commands for controlling the range checker:
8394
c906108c
SS
8395@kindex set check range
8396@kindex show check range
8397@table @code
8398@item set check range auto
8399Set range checking on or off based on the current working language.
9c16f35a 8400@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8401each language.
8402
8403@item set check range on
8404@itemx set check range off
8405Set range checking on or off, overriding the default setting for the
8406current working language. A warning is issued if the setting does not
c3f6f71d
JM
8407match the language default. If a range error occurs and range checking is on,
8408then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8409
8410@item set check range warn
8411Output messages when the @value{GDBN} range checker detects a range error,
8412but attempt to evaluate the expression anyway. Evaluating the
8413expression may still be impossible for other reasons, such as accessing
8414memory that the process does not own (a typical example from many Unix
8415systems).
8416
8417@item show range
8418Show the current setting of the range checker, and whether or not it is
8419being set automatically by @value{GDBN}.
8420@end table
c906108c 8421
9c16f35a 8422@node Supported languages
c906108c 8423@section Supported languages
c906108c 8424
9c16f35a
EZ
8425@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8426assembly, Modula-2, and Ada.
cce74817 8427@c This is false ...
c906108c
SS
8428Some @value{GDBN} features may be used in expressions regardless of the
8429language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8430and the @samp{@{type@}addr} construct (@pxref{Expressions,
8431,Expressions}) can be used with the constructs of any supported
8432language.
8433
8434The following sections detail to what degree each source language is
8435supported by @value{GDBN}. These sections are not meant to be language
8436tutorials or references, but serve only as a reference guide to what the
8437@value{GDBN} expression parser accepts, and what input and output
8438formats should look like for different languages. There are many good
8439books written on each of these languages; please look to these for a
8440language reference or tutorial.
8441
c906108c 8442@menu
b37303ee 8443* C:: C and C@t{++}
b383017d 8444* Objective-C:: Objective-C
09d4efe1 8445* Fortran:: Fortran
9c16f35a 8446* Pascal:: Pascal
b37303ee 8447* Modula-2:: Modula-2
e07c999f 8448* Ada:: Ada
c906108c
SS
8449@end menu
8450
6d2ebf8b 8451@node C
b37052ae 8452@subsection C and C@t{++}
7a292a7a 8453
b37052ae
EZ
8454@cindex C and C@t{++}
8455@cindex expressions in C or C@t{++}
c906108c 8456
b37052ae 8457Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8458to both languages. Whenever this is the case, we discuss those languages
8459together.
8460
41afff9a
EZ
8461@cindex C@t{++}
8462@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8463@cindex @sc{gnu} C@t{++}
8464The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8465compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8466effectively, you must compile your C@t{++} programs with a supported
8467C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8468compiler (@code{aCC}).
8469
0179ffac
DC
8470For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8471format; if it doesn't work on your system, try the stabs+ debugging
8472format. You can select those formats explicitly with the @code{g++}
8473command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8474@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8475CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8476
c906108c 8477@menu
b37052ae
EZ
8478* C Operators:: C and C@t{++} operators
8479* C Constants:: C and C@t{++} constants
8480* C plus plus expressions:: C@t{++} expressions
8481* C Defaults:: Default settings for C and C@t{++}
8482* C Checks:: C and C@t{++} type and range checks
c906108c 8483* Debugging C:: @value{GDBN} and C
b37052ae 8484* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8485@end menu
c906108c 8486
6d2ebf8b 8487@node C Operators
b37052ae 8488@subsubsection C and C@t{++} operators
7a292a7a 8489
b37052ae 8490@cindex C and C@t{++} operators
c906108c
SS
8491
8492Operators must be defined on values of specific types. For instance,
8493@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8494often defined on groups of types.
c906108c 8495
b37052ae 8496For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8497
8498@itemize @bullet
53a5351d 8499
c906108c 8500@item
c906108c 8501@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8502specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8503
8504@item
d4f3574e
SS
8505@emph{Floating-point types} include @code{float}, @code{double}, and
8506@code{long double} (if supported by the target platform).
c906108c
SS
8507
8508@item
53a5351d 8509@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8510
8511@item
8512@emph{Scalar types} include all of the above.
53a5351d 8513
c906108c
SS
8514@end itemize
8515
8516@noindent
8517The following operators are supported. They are listed here
8518in order of increasing precedence:
8519
8520@table @code
8521@item ,
8522The comma or sequencing operator. Expressions in a comma-separated list
8523are evaluated from left to right, with the result of the entire
8524expression being the last expression evaluated.
8525
8526@item =
8527Assignment. The value of an assignment expression is the value
8528assigned. Defined on scalar types.
8529
8530@item @var{op}=
8531Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8532and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8533@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8534@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8535@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8536
8537@item ?:
8538The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8539of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8540integral type.
8541
8542@item ||
8543Logical @sc{or}. Defined on integral types.
8544
8545@item &&
8546Logical @sc{and}. Defined on integral types.
8547
8548@item |
8549Bitwise @sc{or}. Defined on integral types.
8550
8551@item ^
8552Bitwise exclusive-@sc{or}. Defined on integral types.
8553
8554@item &
8555Bitwise @sc{and}. Defined on integral types.
8556
8557@item ==@r{, }!=
8558Equality and inequality. Defined on scalar types. The value of these
8559expressions is 0 for false and non-zero for true.
8560
8561@item <@r{, }>@r{, }<=@r{, }>=
8562Less than, greater than, less than or equal, greater than or equal.
8563Defined on scalar types. The value of these expressions is 0 for false
8564and non-zero for true.
8565
8566@item <<@r{, }>>
8567left shift, and right shift. Defined on integral types.
8568
8569@item @@
8570The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8571
8572@item +@r{, }-
8573Addition and subtraction. Defined on integral types, floating-point types and
8574pointer types.
8575
8576@item *@r{, }/@r{, }%
8577Multiplication, division, and modulus. Multiplication and division are
8578defined on integral and floating-point types. Modulus is defined on
8579integral types.
8580
8581@item ++@r{, }--
8582Increment and decrement. When appearing before a variable, the
8583operation is performed before the variable is used in an expression;
8584when appearing after it, the variable's value is used before the
8585operation takes place.
8586
8587@item *
8588Pointer dereferencing. Defined on pointer types. Same precedence as
8589@code{++}.
8590
8591@item &
8592Address operator. Defined on variables. Same precedence as @code{++}.
8593
b37052ae
EZ
8594For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8595allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8596(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8597where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8598stored.
c906108c
SS
8599
8600@item -
8601Negative. Defined on integral and floating-point types. Same
8602precedence as @code{++}.
8603
8604@item !
8605Logical negation. Defined on integral types. Same precedence as
8606@code{++}.
8607
8608@item ~
8609Bitwise complement operator. Defined on integral types. Same precedence as
8610@code{++}.
8611
8612
8613@item .@r{, }->
8614Structure member, and pointer-to-structure member. For convenience,
8615@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8616pointer based on the stored type information.
8617Defined on @code{struct} and @code{union} data.
8618
c906108c
SS
8619@item .*@r{, }->*
8620Dereferences of pointers to members.
c906108c
SS
8621
8622@item []
8623Array indexing. @code{@var{a}[@var{i}]} is defined as
8624@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8625
8626@item ()
8627Function parameter list. Same precedence as @code{->}.
8628
c906108c 8629@item ::
b37052ae 8630C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8631and @code{class} types.
c906108c
SS
8632
8633@item ::
7a292a7a
SS
8634Doubled colons also represent the @value{GDBN} scope operator
8635(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8636above.
c906108c
SS
8637@end table
8638
c906108c
SS
8639If an operator is redefined in the user code, @value{GDBN} usually
8640attempts to invoke the redefined version instead of using the operator's
8641predefined meaning.
c906108c 8642
c906108c 8643@menu
5d161b24 8644* C Constants::
c906108c
SS
8645@end menu
8646
6d2ebf8b 8647@node C Constants
b37052ae 8648@subsubsection C and C@t{++} constants
c906108c 8649
b37052ae 8650@cindex C and C@t{++} constants
c906108c 8651
b37052ae 8652@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8653following ways:
c906108c
SS
8654
8655@itemize @bullet
8656@item
8657Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8658specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8659by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8660@samp{l}, specifying that the constant should be treated as a
8661@code{long} value.
8662
8663@item
8664Floating point constants are a sequence of digits, followed by a decimal
8665point, followed by a sequence of digits, and optionally followed by an
8666exponent. An exponent is of the form:
8667@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8668sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8669A floating-point constant may also end with a letter @samp{f} or
8670@samp{F}, specifying that the constant should be treated as being of
8671the @code{float} (as opposed to the default @code{double}) type; or with
8672a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8673constant.
c906108c
SS
8674
8675@item
8676Enumerated constants consist of enumerated identifiers, or their
8677integral equivalents.
8678
8679@item
8680Character constants are a single character surrounded by single quotes
8681(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8682(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8683be represented by a letter or by @dfn{escape sequences}, which are of
8684the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8685of the character's ordinal value; or of the form @samp{\@var{x}}, where
8686@samp{@var{x}} is a predefined special character---for example,
8687@samp{\n} for newline.
8688
8689@item
96a2c332
SS
8690String constants are a sequence of character constants surrounded by
8691double quotes (@code{"}). Any valid character constant (as described
8692above) may appear. Double quotes within the string must be preceded by
8693a backslash, so for instance @samp{"a\"b'c"} is a string of five
8694characters.
c906108c
SS
8695
8696@item
8697Pointer constants are an integral value. You can also write pointers
8698to constants using the C operator @samp{&}.
8699
8700@item
8701Array constants are comma-separated lists surrounded by braces @samp{@{}
8702and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8703integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8704and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8705@end itemize
8706
c906108c 8707@menu
5d161b24
DB
8708* C plus plus expressions::
8709* C Defaults::
8710* C Checks::
c906108c 8711
5d161b24 8712* Debugging C::
c906108c
SS
8713@end menu
8714
6d2ebf8b 8715@node C plus plus expressions
b37052ae
EZ
8716@subsubsection C@t{++} expressions
8717
8718@cindex expressions in C@t{++}
8719@value{GDBN} expression handling can interpret most C@t{++} expressions.
8720
0179ffac
DC
8721@cindex debugging C@t{++} programs
8722@cindex C@t{++} compilers
8723@cindex debug formats and C@t{++}
8724@cindex @value{NGCC} and C@t{++}
c906108c 8725@quotation
b37052ae 8726@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8727proper compiler and the proper debug format. Currently, @value{GDBN}
8728works best when debugging C@t{++} code that is compiled with
8729@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8730@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8731stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8732stabs+ as their default debug format, so you usually don't need to
8733specify a debug format explicitly. Other compilers and/or debug formats
8734are likely to work badly or not at all when using @value{GDBN} to debug
8735C@t{++} code.
c906108c 8736@end quotation
c906108c
SS
8737
8738@enumerate
8739
8740@cindex member functions
8741@item
8742Member function calls are allowed; you can use expressions like
8743
474c8240 8744@smallexample
c906108c 8745count = aml->GetOriginal(x, y)
474c8240 8746@end smallexample
c906108c 8747
41afff9a 8748@vindex this@r{, inside C@t{++} member functions}
b37052ae 8749@cindex namespace in C@t{++}
c906108c
SS
8750@item
8751While a member function is active (in the selected stack frame), your
8752expressions have the same namespace available as the member function;
8753that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8754pointer @code{this} following the same rules as C@t{++}.
c906108c 8755
c906108c 8756@cindex call overloaded functions
d4f3574e 8757@cindex overloaded functions, calling
b37052ae 8758@cindex type conversions in C@t{++}
c906108c
SS
8759@item
8760You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8761call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8762perform overload resolution involving user-defined type conversions,
8763calls to constructors, or instantiations of templates that do not exist
8764in the program. It also cannot handle ellipsis argument lists or
8765default arguments.
8766
8767It does perform integral conversions and promotions, floating-point
8768promotions, arithmetic conversions, pointer conversions, conversions of
8769class objects to base classes, and standard conversions such as those of
8770functions or arrays to pointers; it requires an exact match on the
8771number of function arguments.
8772
8773Overload resolution is always performed, unless you have specified
8774@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8775,@value{GDBN} features for C@t{++}}.
c906108c 8776
d4f3574e 8777You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8778explicit function signature to call an overloaded function, as in
8779@smallexample
8780p 'foo(char,int)'('x', 13)
8781@end smallexample
d4f3574e 8782
c906108c 8783The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8784see @ref{Completion, ,Command completion}.
c906108c 8785
c906108c
SS
8786@cindex reference declarations
8787@item
b37052ae
EZ
8788@value{GDBN} understands variables declared as C@t{++} references; you can use
8789them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8790dereferenced.
8791
8792In the parameter list shown when @value{GDBN} displays a frame, the values of
8793reference variables are not displayed (unlike other variables); this
8794avoids clutter, since references are often used for large structures.
8795The @emph{address} of a reference variable is always shown, unless
8796you have specified @samp{set print address off}.
8797
8798@item
b37052ae 8799@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8800expressions can use it just as expressions in your program do. Since
8801one scope may be defined in another, you can use @code{::} repeatedly if
8802necessary, for example in an expression like
8803@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8804resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8805debugging (@pxref{Variables, ,Program variables}).
8806@end enumerate
8807
b37052ae 8808In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8809calling virtual functions correctly, printing out virtual bases of
8810objects, calling functions in a base subobject, casting objects, and
8811invoking user-defined operators.
c906108c 8812
6d2ebf8b 8813@node C Defaults
b37052ae 8814@subsubsection C and C@t{++} defaults
7a292a7a 8815
b37052ae 8816@cindex C and C@t{++} defaults
c906108c 8817
c906108c
SS
8818If you allow @value{GDBN} to set type and range checking automatically, they
8819both default to @code{off} whenever the working language changes to
b37052ae 8820C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8821selects the working language.
c906108c
SS
8822
8823If you allow @value{GDBN} to set the language automatically, it
8824recognizes source files whose names end with @file{.c}, @file{.C}, or
8825@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8826these files, it sets the working language to C or C@t{++}.
c906108c
SS
8827@xref{Automatically, ,Having @value{GDBN} infer the source language},
8828for further details.
8829
c906108c
SS
8830@c Type checking is (a) primarily motivated by Modula-2, and (b)
8831@c unimplemented. If (b) changes, it might make sense to let this node
8832@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8833
6d2ebf8b 8834@node C Checks
b37052ae 8835@subsubsection C and C@t{++} type and range checks
7a292a7a 8836
b37052ae 8837@cindex C and C@t{++} checks
c906108c 8838
b37052ae 8839By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8840is not used. However, if you turn type checking on, @value{GDBN}
8841considers two variables type equivalent if:
8842
8843@itemize @bullet
8844@item
8845The two variables are structured and have the same structure, union, or
8846enumerated tag.
8847
8848@item
8849The two variables have the same type name, or types that have been
8850declared equivalent through @code{typedef}.
8851
8852@ignore
8853@c leaving this out because neither J Gilmore nor R Pesch understand it.
8854@c FIXME--beers?
8855@item
8856The two @code{struct}, @code{union}, or @code{enum} variables are
8857declared in the same declaration. (Note: this may not be true for all C
8858compilers.)
8859@end ignore
8860@end itemize
8861
8862Range checking, if turned on, is done on mathematical operations. Array
8863indices are not checked, since they are often used to index a pointer
8864that is not itself an array.
c906108c 8865
6d2ebf8b 8866@node Debugging C
c906108c 8867@subsubsection @value{GDBN} and C
c906108c
SS
8868
8869The @code{set print union} and @code{show print union} commands apply to
8870the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8871inside a @code{struct} or @code{class} is also printed. Otherwise, it
8872appears as @samp{@{...@}}.
c906108c
SS
8873
8874The @code{@@} operator aids in the debugging of dynamic arrays, formed
8875with pointers and a memory allocation function. @xref{Expressions,
8876,Expressions}.
8877
c906108c 8878@menu
5d161b24 8879* Debugging C plus plus::
c906108c
SS
8880@end menu
8881
6d2ebf8b 8882@node Debugging C plus plus
b37052ae 8883@subsubsection @value{GDBN} features for C@t{++}
c906108c 8884
b37052ae 8885@cindex commands for C@t{++}
7a292a7a 8886
b37052ae
EZ
8887Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8888designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8889
8890@table @code
8891@cindex break in overloaded functions
8892@item @r{breakpoint menus}
8893When you want a breakpoint in a function whose name is overloaded,
8894@value{GDBN} breakpoint menus help you specify which function definition
8895you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8896
b37052ae 8897@cindex overloading in C@t{++}
c906108c
SS
8898@item rbreak @var{regex}
8899Setting breakpoints using regular expressions is helpful for setting
8900breakpoints on overloaded functions that are not members of any special
8901classes.
8902@xref{Set Breaks, ,Setting breakpoints}.
8903
b37052ae 8904@cindex C@t{++} exception handling
c906108c
SS
8905@item catch throw
8906@itemx catch catch
b37052ae 8907Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8908Catchpoints, , Setting catchpoints}.
8909
8910@cindex inheritance
8911@item ptype @var{typename}
8912Print inheritance relationships as well as other information for type
8913@var{typename}.
8914@xref{Symbols, ,Examining the Symbol Table}.
8915
b37052ae 8916@cindex C@t{++} symbol display
c906108c
SS
8917@item set print demangle
8918@itemx show print demangle
8919@itemx set print asm-demangle
8920@itemx show print asm-demangle
b37052ae
EZ
8921Control whether C@t{++} symbols display in their source form, both when
8922displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8923@xref{Print Settings, ,Print settings}.
8924
8925@item set print object
8926@itemx show print object
8927Choose whether to print derived (actual) or declared types of objects.
8928@xref{Print Settings, ,Print settings}.
8929
8930@item set print vtbl
8931@itemx show print vtbl
8932Control the format for printing virtual function tables.
8933@xref{Print Settings, ,Print settings}.
c906108c 8934(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8935ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8936
8937@kindex set overload-resolution
d4f3574e 8938@cindex overloaded functions, overload resolution
c906108c 8939@item set overload-resolution on
b37052ae 8940Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8941is on. For overloaded functions, @value{GDBN} evaluates the arguments
8942and searches for a function whose signature matches the argument types,
b37052ae 8943using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8944expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8945message.
8946
8947@item set overload-resolution off
b37052ae 8948Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8949overloaded functions that are not class member functions, @value{GDBN}
8950chooses the first function of the specified name that it finds in the
8951symbol table, whether or not its arguments are of the correct type. For
8952overloaded functions that are class member functions, @value{GDBN}
8953searches for a function whose signature @emph{exactly} matches the
8954argument types.
c906108c 8955
9c16f35a
EZ
8956@kindex show overload-resolution
8957@item show overload-resolution
8958Show the current setting of overload resolution.
8959
c906108c
SS
8960@item @r{Overloaded symbol names}
8961You can specify a particular definition of an overloaded symbol, using
b37052ae 8962the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8963@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8964also use the @value{GDBN} command-line word completion facilities to list the
8965available choices, or to finish the type list for you.
8966@xref{Completion,, Command completion}, for details on how to do this.
8967@end table
c906108c 8968
b37303ee
AF
8969@node Objective-C
8970@subsection Objective-C
8971
8972@cindex Objective-C
8973This section provides information about some commands and command
721c2651
EZ
8974options that are useful for debugging Objective-C code. See also
8975@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8976few more commands specific to Objective-C support.
b37303ee
AF
8977
8978@menu
b383017d
RM
8979* Method Names in Commands::
8980* The Print Command with Objective-C::
b37303ee
AF
8981@end menu
8982
8983@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8984@subsubsection Method Names in Commands
8985
8986The following commands have been extended to accept Objective-C method
8987names as line specifications:
8988
8989@kindex clear@r{, and Objective-C}
8990@kindex break@r{, and Objective-C}
8991@kindex info line@r{, and Objective-C}
8992@kindex jump@r{, and Objective-C}
8993@kindex list@r{, and Objective-C}
8994@itemize
8995@item @code{clear}
8996@item @code{break}
8997@item @code{info line}
8998@item @code{jump}
8999@item @code{list}
9000@end itemize
9001
9002A fully qualified Objective-C method name is specified as
9003
9004@smallexample
9005-[@var{Class} @var{methodName}]
9006@end smallexample
9007
c552b3bb
JM
9008where the minus sign is used to indicate an instance method and a
9009plus sign (not shown) is used to indicate a class method. The class
9010name @var{Class} and method name @var{methodName} are enclosed in
9011brackets, similar to the way messages are specified in Objective-C
9012source code. For example, to set a breakpoint at the @code{create}
9013instance method of class @code{Fruit} in the program currently being
9014debugged, enter:
b37303ee
AF
9015
9016@smallexample
9017break -[Fruit create]
9018@end smallexample
9019
9020To list ten program lines around the @code{initialize} class method,
9021enter:
9022
9023@smallexample
9024list +[NSText initialize]
9025@end smallexample
9026
c552b3bb
JM
9027In the current version of @value{GDBN}, the plus or minus sign is
9028required. In future versions of @value{GDBN}, the plus or minus
9029sign will be optional, but you can use it to narrow the search. It
9030is also possible to specify just a method name:
b37303ee
AF
9031
9032@smallexample
9033break create
9034@end smallexample
9035
9036You must specify the complete method name, including any colons. If
9037your program's source files contain more than one @code{create} method,
9038you'll be presented with a numbered list of classes that implement that
9039method. Indicate your choice by number, or type @samp{0} to exit if
9040none apply.
9041
9042As another example, to clear a breakpoint established at the
9043@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9044
9045@smallexample
9046clear -[NSWindow makeKeyAndOrderFront:]
9047@end smallexample
9048
9049@node The Print Command with Objective-C
9050@subsubsection The Print Command With Objective-C
721c2651 9051@cindex Objective-C, print objects
c552b3bb
JM
9052@kindex print-object
9053@kindex po @r{(@code{print-object})}
b37303ee 9054
c552b3bb 9055The print command has also been extended to accept methods. For example:
b37303ee
AF
9056
9057@smallexample
c552b3bb 9058print -[@var{object} hash]
b37303ee
AF
9059@end smallexample
9060
9061@cindex print an Objective-C object description
c552b3bb
JM
9062@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9063@noindent
9064will tell @value{GDBN} to send the @code{hash} message to @var{object}
9065and print the result. Also, an additional command has been added,
9066@code{print-object} or @code{po} for short, which is meant to print
9067the description of an object. However, this command may only work
9068with certain Objective-C libraries that have a particular hook
9069function, @code{_NSPrintForDebugger}, defined.
b37303ee 9070
09d4efe1
EZ
9071@node Fortran
9072@subsection Fortran
9073@cindex Fortran-specific support in @value{GDBN}
9074
9075@table @code
9076@cindex @code{COMMON} blocks, Fortran
9077@kindex info common
9078@item info common @r{[}@var{common-name}@r{]}
9079This command prints the values contained in the Fortran @code{COMMON}
9080block whose name is @var{common-name}. With no argument, the names of
9081all @code{COMMON} blocks visible at current program location are
9082printed.
9083@end table
9084
a8f24a35
EZ
9085Fortran symbols are usually case-insensitive, so @value{GDBN} by
9086default uses case-insensitive matches for Fortran symbols. You can
9087change that with the @samp{set case-insensitive} command, see
9088@ref{Symbols}, for the details.
9089
9c16f35a
EZ
9090@node Pascal
9091@subsection Pascal
9092
9093@cindex Pascal support in @value{GDBN}, limitations
9094Debugging Pascal programs which use sets, subranges, file variables, or
9095nested functions does not currently work. @value{GDBN} does not support
9096entering expressions, printing values, or similar features using Pascal
9097syntax.
9098
9099The Pascal-specific command @code{set print pascal_static-members}
9100controls whether static members of Pascal objects are displayed.
9101@xref{Print Settings, pascal_static-members}.
9102
09d4efe1 9103@node Modula-2
c906108c 9104@subsection Modula-2
7a292a7a 9105
d4f3574e 9106@cindex Modula-2, @value{GDBN} support
c906108c
SS
9107
9108The extensions made to @value{GDBN} to support Modula-2 only support
9109output from the @sc{gnu} Modula-2 compiler (which is currently being
9110developed). Other Modula-2 compilers are not currently supported, and
9111attempting to debug executables produced by them is most likely
9112to give an error as @value{GDBN} reads in the executable's symbol
9113table.
9114
9115@cindex expressions in Modula-2
9116@menu
9117* M2 Operators:: Built-in operators
9118* Built-In Func/Proc:: Built-in functions and procedures
9119* M2 Constants:: Modula-2 constants
9120* M2 Defaults:: Default settings for Modula-2
9121* Deviations:: Deviations from standard Modula-2
9122* M2 Checks:: Modula-2 type and range checks
9123* M2 Scope:: The scope operators @code{::} and @code{.}
9124* GDB/M2:: @value{GDBN} and Modula-2
9125@end menu
9126
6d2ebf8b 9127@node M2 Operators
c906108c
SS
9128@subsubsection Operators
9129@cindex Modula-2 operators
9130
9131Operators must be defined on values of specific types. For instance,
9132@code{+} is defined on numbers, but not on structures. Operators are
9133often defined on groups of types. For the purposes of Modula-2, the
9134following definitions hold:
9135
9136@itemize @bullet
9137
9138@item
9139@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9140their subranges.
9141
9142@item
9143@emph{Character types} consist of @code{CHAR} and its subranges.
9144
9145@item
9146@emph{Floating-point types} consist of @code{REAL}.
9147
9148@item
9149@emph{Pointer types} consist of anything declared as @code{POINTER TO
9150@var{type}}.
9151
9152@item
9153@emph{Scalar types} consist of all of the above.
9154
9155@item
9156@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9157
9158@item
9159@emph{Boolean types} consist of @code{BOOLEAN}.
9160@end itemize
9161
9162@noindent
9163The following operators are supported, and appear in order of
9164increasing precedence:
9165
9166@table @code
9167@item ,
9168Function argument or array index separator.
9169
9170@item :=
9171Assignment. The value of @var{var} @code{:=} @var{value} is
9172@var{value}.
9173
9174@item <@r{, }>
9175Less than, greater than on integral, floating-point, or enumerated
9176types.
9177
9178@item <=@r{, }>=
96a2c332 9179Less than or equal to, greater than or equal to
c906108c
SS
9180on integral, floating-point and enumerated types, or set inclusion on
9181set types. Same precedence as @code{<}.
9182
9183@item =@r{, }<>@r{, }#
9184Equality and two ways of expressing inequality, valid on scalar types.
9185Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9186available for inequality, since @code{#} conflicts with the script
9187comment character.
9188
9189@item IN
9190Set membership. Defined on set types and the types of their members.
9191Same precedence as @code{<}.
9192
9193@item OR
9194Boolean disjunction. Defined on boolean types.
9195
9196@item AND@r{, }&
d4f3574e 9197Boolean conjunction. Defined on boolean types.
c906108c
SS
9198
9199@item @@
9200The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9201
9202@item +@r{, }-
9203Addition and subtraction on integral and floating-point types, or union
9204and difference on set types.
9205
9206@item *
9207Multiplication on integral and floating-point types, or set intersection
9208on set types.
9209
9210@item /
9211Division on floating-point types, or symmetric set difference on set
9212types. Same precedence as @code{*}.
9213
9214@item DIV@r{, }MOD
9215Integer division and remainder. Defined on integral types. Same
9216precedence as @code{*}.
9217
9218@item -
9219Negative. Defined on @code{INTEGER} and @code{REAL} data.
9220
9221@item ^
9222Pointer dereferencing. Defined on pointer types.
9223
9224@item NOT
9225Boolean negation. Defined on boolean types. Same precedence as
9226@code{^}.
9227
9228@item .
9229@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9230precedence as @code{^}.
9231
9232@item []
9233Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9234
9235@item ()
9236Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9237as @code{^}.
9238
9239@item ::@r{, }.
9240@value{GDBN} and Modula-2 scope operators.
9241@end table
9242
9243@quotation
9244@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9245treats the use of the operator @code{IN}, or the use of operators
9246@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9247@code{<=}, and @code{>=} on sets as an error.
9248@end quotation
9249
cb51c4e0 9250
6d2ebf8b 9251@node Built-In Func/Proc
c906108c 9252@subsubsection Built-in functions and procedures
cb51c4e0 9253@cindex Modula-2 built-ins
c906108c
SS
9254
9255Modula-2 also makes available several built-in procedures and functions.
9256In describing these, the following metavariables are used:
9257
9258@table @var
9259
9260@item a
9261represents an @code{ARRAY} variable.
9262
9263@item c
9264represents a @code{CHAR} constant or variable.
9265
9266@item i
9267represents a variable or constant of integral type.
9268
9269@item m
9270represents an identifier that belongs to a set. Generally used in the
9271same function with the metavariable @var{s}. The type of @var{s} should
9272be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9273
9274@item n
9275represents a variable or constant of integral or floating-point type.
9276
9277@item r
9278represents a variable or constant of floating-point type.
9279
9280@item t
9281represents a type.
9282
9283@item v
9284represents a variable.
9285
9286@item x
9287represents a variable or constant of one of many types. See the
9288explanation of the function for details.
9289@end table
9290
9291All Modula-2 built-in procedures also return a result, described below.
9292
9293@table @code
9294@item ABS(@var{n})
9295Returns the absolute value of @var{n}.
9296
9297@item CAP(@var{c})
9298If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9299equivalent, otherwise it returns its argument.
c906108c
SS
9300
9301@item CHR(@var{i})
9302Returns the character whose ordinal value is @var{i}.
9303
9304@item DEC(@var{v})
c3f6f71d 9305Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9306
9307@item DEC(@var{v},@var{i})
9308Decrements the value in the variable @var{v} by @var{i}. Returns the
9309new value.
9310
9311@item EXCL(@var{m},@var{s})
9312Removes the element @var{m} from the set @var{s}. Returns the new
9313set.
9314
9315@item FLOAT(@var{i})
9316Returns the floating point equivalent of the integer @var{i}.
9317
9318@item HIGH(@var{a})
9319Returns the index of the last member of @var{a}.
9320
9321@item INC(@var{v})
c3f6f71d 9322Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9323
9324@item INC(@var{v},@var{i})
9325Increments the value in the variable @var{v} by @var{i}. Returns the
9326new value.
9327
9328@item INCL(@var{m},@var{s})
9329Adds the element @var{m} to the set @var{s} if it is not already
9330there. Returns the new set.
9331
9332@item MAX(@var{t})
9333Returns the maximum value of the type @var{t}.
9334
9335@item MIN(@var{t})
9336Returns the minimum value of the type @var{t}.
9337
9338@item ODD(@var{i})
9339Returns boolean TRUE if @var{i} is an odd number.
9340
9341@item ORD(@var{x})
9342Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9343value of a character is its @sc{ascii} value (on machines supporting the
9344@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9345integral, character and enumerated types.
9346
9347@item SIZE(@var{x})
9348Returns the size of its argument. @var{x} can be a variable or a type.
9349
9350@item TRUNC(@var{r})
9351Returns the integral part of @var{r}.
9352
9353@item VAL(@var{t},@var{i})
9354Returns the member of the type @var{t} whose ordinal value is @var{i}.
9355@end table
9356
9357@quotation
9358@emph{Warning:} Sets and their operations are not yet supported, so
9359@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9360an error.
9361@end quotation
9362
9363@cindex Modula-2 constants
6d2ebf8b 9364@node M2 Constants
c906108c
SS
9365@subsubsection Constants
9366
9367@value{GDBN} allows you to express the constants of Modula-2 in the following
9368ways:
9369
9370@itemize @bullet
9371
9372@item
9373Integer constants are simply a sequence of digits. When used in an
9374expression, a constant is interpreted to be type-compatible with the
9375rest of the expression. Hexadecimal integers are specified by a
9376trailing @samp{H}, and octal integers by a trailing @samp{B}.
9377
9378@item
9379Floating point constants appear as a sequence of digits, followed by a
9380decimal point and another sequence of digits. An optional exponent can
9381then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9382@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9383digits of the floating point constant must be valid decimal (base 10)
9384digits.
9385
9386@item
9387Character constants consist of a single character enclosed by a pair of
9388like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9389also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9390followed by a @samp{C}.
9391
9392@item
9393String constants consist of a sequence of characters enclosed by a
9394pair of like quotes, either single (@code{'}) or double (@code{"}).
9395Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9396Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9397sequences.
9398
9399@item
9400Enumerated constants consist of an enumerated identifier.
9401
9402@item
9403Boolean constants consist of the identifiers @code{TRUE} and
9404@code{FALSE}.
9405
9406@item
9407Pointer constants consist of integral values only.
9408
9409@item
9410Set constants are not yet supported.
9411@end itemize
9412
6d2ebf8b 9413@node M2 Defaults
c906108c
SS
9414@subsubsection Modula-2 defaults
9415@cindex Modula-2 defaults
9416
9417If type and range checking are set automatically by @value{GDBN}, they
9418both default to @code{on} whenever the working language changes to
d4f3574e 9419Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9420selected the working language.
9421
9422If you allow @value{GDBN} to set the language automatically, then entering
9423code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9424working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9425the language automatically}, for further details.
9426
6d2ebf8b 9427@node Deviations
c906108c
SS
9428@subsubsection Deviations from standard Modula-2
9429@cindex Modula-2, deviations from
9430
9431A few changes have been made to make Modula-2 programs easier to debug.
9432This is done primarily via loosening its type strictness:
9433
9434@itemize @bullet
9435@item
9436Unlike in standard Modula-2, pointer constants can be formed by
9437integers. This allows you to modify pointer variables during
9438debugging. (In standard Modula-2, the actual address contained in a
9439pointer variable is hidden from you; it can only be modified
9440through direct assignment to another pointer variable or expression that
9441returned a pointer.)
9442
9443@item
9444C escape sequences can be used in strings and characters to represent
9445non-printable characters. @value{GDBN} prints out strings with these
9446escape sequences embedded. Single non-printable characters are
9447printed using the @samp{CHR(@var{nnn})} format.
9448
9449@item
9450The assignment operator (@code{:=}) returns the value of its right-hand
9451argument.
9452
9453@item
9454All built-in procedures both modify @emph{and} return their argument.
9455@end itemize
9456
6d2ebf8b 9457@node M2 Checks
c906108c
SS
9458@subsubsection Modula-2 type and range checks
9459@cindex Modula-2 checks
9460
9461@quotation
9462@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9463range checking.
9464@end quotation
9465@c FIXME remove warning when type/range checks added
9466
9467@value{GDBN} considers two Modula-2 variables type equivalent if:
9468
9469@itemize @bullet
9470@item
9471They are of types that have been declared equivalent via a @code{TYPE
9472@var{t1} = @var{t2}} statement
9473
9474@item
9475They have been declared on the same line. (Note: This is true of the
9476@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9477@end itemize
9478
9479As long as type checking is enabled, any attempt to combine variables
9480whose types are not equivalent is an error.
9481
9482Range checking is done on all mathematical operations, assignment, array
9483index bounds, and all built-in functions and procedures.
9484
6d2ebf8b 9485@node M2 Scope
c906108c
SS
9486@subsubsection The scope operators @code{::} and @code{.}
9487@cindex scope
41afff9a 9488@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9489@cindex colon, doubled as scope operator
9490@ifinfo
41afff9a 9491@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9492@c Info cannot handle :: but TeX can.
9493@end ifinfo
9494@iftex
41afff9a 9495@vindex ::@r{, in Modula-2}
c906108c
SS
9496@end iftex
9497
9498There are a few subtle differences between the Modula-2 scope operator
9499(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9500similar syntax:
9501
474c8240 9502@smallexample
c906108c
SS
9503
9504@var{module} . @var{id}
9505@var{scope} :: @var{id}
474c8240 9506@end smallexample
c906108c
SS
9507
9508@noindent
9509where @var{scope} is the name of a module or a procedure,
9510@var{module} the name of a module, and @var{id} is any declared
9511identifier within your program, except another module.
9512
9513Using the @code{::} operator makes @value{GDBN} search the scope
9514specified by @var{scope} for the identifier @var{id}. If it is not
9515found in the specified scope, then @value{GDBN} searches all scopes
9516enclosing the one specified by @var{scope}.
9517
9518Using the @code{.} operator makes @value{GDBN} search the current scope for
9519the identifier specified by @var{id} that was imported from the
9520definition module specified by @var{module}. With this operator, it is
9521an error if the identifier @var{id} was not imported from definition
9522module @var{module}, or if @var{id} is not an identifier in
9523@var{module}.
9524
6d2ebf8b 9525@node GDB/M2
c906108c
SS
9526@subsubsection @value{GDBN} and Modula-2
9527
9528Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9529Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9530specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9531@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9532apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9533analogue in Modula-2.
9534
9535The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9536with any language, is not useful with Modula-2. Its
c906108c 9537intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9538created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9539address can be specified by an integral constant, the construct
d4f3574e 9540@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9541
9542@cindex @code{#} in Modula-2
9543In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9544interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9545
e07c999f
PH
9546@node Ada
9547@subsection Ada
9548@cindex Ada
9549
9550The extensions made to @value{GDBN} for Ada only support
9551output from the @sc{gnu} Ada (GNAT) compiler.
9552Other Ada compilers are not currently supported, and
9553attempting to debug executables produced by them is most likely
9554to be difficult.
9555
9556
9557@cindex expressions in Ada
9558@menu
9559* Ada Mode Intro:: General remarks on the Ada syntax
9560 and semantics supported by Ada mode
9561 in @value{GDBN}.
9562* Omissions from Ada:: Restrictions on the Ada expression syntax.
9563* Additions to Ada:: Extensions of the Ada expression syntax.
9564* Stopping Before Main Program:: Debugging the program during elaboration.
9565* Ada Glitches:: Known peculiarities of Ada mode.
9566@end menu
9567
9568@node Ada Mode Intro
9569@subsubsection Introduction
9570@cindex Ada mode, general
9571
9572The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9573syntax, with some extensions.
9574The philosophy behind the design of this subset is
9575
9576@itemize @bullet
9577@item
9578That @value{GDBN} should provide basic literals and access to operations for
9579arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9580leaving more sophisticated computations to subprograms written into the
9581program (which therefore may be called from @value{GDBN}).
9582
9583@item
9584That type safety and strict adherence to Ada language restrictions
9585are not particularly important to the @value{GDBN} user.
9586
9587@item
9588That brevity is important to the @value{GDBN} user.
9589@end itemize
9590
9591Thus, for brevity, the debugger acts as if there were
9592implicit @code{with} and @code{use} clauses in effect for all user-written
9593packages, making it unnecessary to fully qualify most names with
9594their packages, regardless of context. Where this causes ambiguity,
9595@value{GDBN} asks the user's intent.
9596
9597The debugger will start in Ada mode if it detects an Ada main program.
9598As for other languages, it will enter Ada mode when stopped in a program that
9599was translated from an Ada source file.
9600
9601While in Ada mode, you may use `@t{--}' for comments. This is useful
9602mostly for documenting command files. The standard @value{GDBN} comment
9603(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9604middle (to allow based literals).
9605
9606The debugger supports limited overloading. Given a subprogram call in which
9607the function symbol has multiple definitions, it will use the number of
9608actual parameters and some information about their types to attempt to narrow
9609the set of definitions. It also makes very limited use of context, preferring
9610procedures to functions in the context of the @code{call} command, and
9611functions to procedures elsewhere.
9612
9613@node Omissions from Ada
9614@subsubsection Omissions from Ada
9615@cindex Ada, omissions from
9616
9617Here are the notable omissions from the subset:
9618
9619@itemize @bullet
9620@item
9621Only a subset of the attributes are supported:
9622
9623@itemize @minus
9624@item
9625@t{'First}, @t{'Last}, and @t{'Length}
9626 on array objects (not on types and subtypes).
9627
9628@item
9629@t{'Min} and @t{'Max}.
9630
9631@item
9632@t{'Pos} and @t{'Val}.
9633
9634@item
9635@t{'Tag}.
9636
9637@item
9638@t{'Range} on array objects (not subtypes), but only as the right
9639operand of the membership (@code{in}) operator.
9640
9641@item
9642@t{'Access}, @t{'Unchecked_Access}, and
9643@t{'Unrestricted_Access} (a GNAT extension).
9644
9645@item
9646@t{'Address}.
9647@end itemize
9648
9649@item
9650The names in
9651@code{Characters.Latin_1} are not available and
9652concatenation is not implemented. Thus, escape characters in strings are
9653not currently available.
9654
9655@item
9656Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9657equality of representations. They will generally work correctly
9658for strings and arrays whose elements have integer or enumeration types.
9659They may not work correctly for arrays whose element
9660types have user-defined equality, for arrays of real values
9661(in particular, IEEE-conformant floating point, because of negative
9662zeroes and NaNs), and for arrays whose elements contain unused bits with
9663indeterminate values.
9664
9665@item
9666The other component-by-component array operations (@code{and}, @code{or},
9667@code{xor}, @code{not}, and relational tests other than equality)
9668are not implemented.
9669
9670@item
9671There are no record or array aggregates.
9672
9673@item
9674Calls to dispatching subprograms are not implemented.
9675
9676@item
9677The overloading algorithm is much more limited (i.e., less selective)
9678than that of real Ada. It makes only limited use of the context in which a subexpression
9679appears to resolve its meaning, and it is much looser in its rules for allowing
9680type matches. As a result, some function calls will be ambiguous, and the user
9681will be asked to choose the proper resolution.
9682
9683@item
9684The @code{new} operator is not implemented.
9685
9686@item
9687Entry calls are not implemented.
9688
9689@item
9690Aside from printing, arithmetic operations on the native VAX floating-point
9691formats are not supported.
9692
9693@item
9694It is not possible to slice a packed array.
9695@end itemize
9696
9697@node Additions to Ada
9698@subsubsection Additions to Ada
9699@cindex Ada, deviations from
9700
9701As it does for other languages, @value{GDBN} makes certain generic
9702extensions to Ada (@pxref{Expressions}):
9703
9704@itemize @bullet
9705@item
9706If the expression @var{E} is a variable residing in memory
9707(typically a local variable or array element) and @var{N} is
9708a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9709@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9710In Ada, this operator is generally not necessary, since its prime use
9711is in displaying parts of an array, and slicing will usually do this in Ada.
9712However, there are occasional uses when debugging programs
9713in which certain debugging information has been optimized away.
9714
9715@item
9716@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9717in function or file @var{B}.'' When @var{B} is a file name, you must typically
9718surround it in single quotes.
9719
9720@item
9721The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9722@var{type} that appears at address @var{addr}.''
9723
9724@item
9725A name starting with @samp{$} is a convenience variable
9726(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9727@end itemize
9728
9729In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9730to Ada:
9731
9732@itemize @bullet
9733@item
9734The assignment statement is allowed as an expression, returning
9735its right-hand operand as its value. Thus, you may enter
9736
9737@smallexample
9738set x := y + 3
9739print A(tmp := y + 1)
9740@end smallexample
9741
9742@item
9743The semicolon is allowed as an ``operator,'' returning as its value
9744the value of its right-hand operand.
9745This allows, for example,
9746complex conditional breaks:
9747
9748@smallexample
9749break f
9750condition 1 (report(i); k += 1; A(k) > 100)
9751@end smallexample
9752
9753@item
9754Rather than use catenation and symbolic character names to introduce special
9755characters into strings, one may instead use a special bracket notation,
9756which is also used to print strings. A sequence of characters of the form
9757@samp{["@var{XX}"]} within a string or character literal denotes the
9758(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9759sequence of characters @samp{["""]} also denotes a single quotation mark
9760in strings. For example,
9761@smallexample
9762 "One line.["0a"]Next line.["0a"]"
9763@end smallexample
9764@noindent
9765contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9766period.
9767
9768@item
9769The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9770@t{'Max} is optional (and is ignored in any case). For example, it is valid
9771to write
9772
9773@smallexample
9774print 'max(x, y)
9775@end smallexample
9776
9777@item
9778When printing arrays, @value{GDBN} uses positional notation when the
9779array has a lower bound of 1, and uses a modified named notation otherwise.
9780For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9781
9782@smallexample
9783(3 => 10, 17, 1)
9784@end smallexample
9785
9786@noindent
9787That is, in contrast to valid Ada, only the first component has a @code{=>}
9788clause.
9789
9790@item
9791You may abbreviate attributes in expressions with any unique,
9792multi-character subsequence of
9793their names (an exact match gets preference).
9794For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9795in place of @t{a'length}.
9796
9797@item
9798@cindex quoting Ada internal identifiers
9799Since Ada is case-insensitive, the debugger normally maps identifiers you type
9800to lower case. The GNAT compiler uses upper-case characters for
9801some of its internal identifiers, which are normally of no interest to users.
9802For the rare occasions when you actually have to look at them,
9803enclose them in angle brackets to avoid the lower-case mapping.
9804For example,
9805@smallexample
9806@value{GDBP} print <JMPBUF_SAVE>[0]
9807@end smallexample
9808
9809@item
9810Printing an object of class-wide type or dereferencing an
9811access-to-class-wide value will display all the components of the object's
9812specific type (as indicated by its run-time tag). Likewise, component
9813selection on such a value will operate on the specific type of the
9814object.
9815
9816@end itemize
9817
9818@node Stopping Before Main Program
9819@subsubsection Stopping at the Very Beginning
9820
9821@cindex breakpointing Ada elaboration code
9822It is sometimes necessary to debug the program during elaboration, and
9823before reaching the main procedure.
9824As defined in the Ada Reference
9825Manual, the elaboration code is invoked from a procedure called
9826@code{adainit}. To run your program up to the beginning of
9827elaboration, simply use the following two commands:
9828@code{tbreak adainit} and @code{run}.
9829
9830@node Ada Glitches
9831@subsubsection Known Peculiarities of Ada Mode
9832@cindex Ada, problems
9833
9834Besides the omissions listed previously (@pxref{Omissions from Ada}),
9835we know of several problems with and limitations of Ada mode in
9836@value{GDBN},
9837some of which will be fixed with planned future releases of the debugger
9838and the GNU Ada compiler.
9839
9840@itemize @bullet
9841@item
9842Currently, the debugger
9843has insufficient information to determine whether certain pointers represent
9844pointers to objects or the objects themselves.
9845Thus, the user may have to tack an extra @code{.all} after an expression
9846to get it printed properly.
9847
9848@item
9849Static constants that the compiler chooses not to materialize as objects in
9850storage are invisible to the debugger.
9851
9852@item
9853Named parameter associations in function argument lists are ignored (the
9854argument lists are treated as positional).
9855
9856@item
9857Many useful library packages are currently invisible to the debugger.
9858
9859@item
9860Fixed-point arithmetic, conversions, input, and output is carried out using
9861floating-point arithmetic, and may give results that only approximate those on
9862the host machine.
9863
9864@item
9865The type of the @t{'Address} attribute may not be @code{System.Address}.
9866
9867@item
9868The GNAT compiler never generates the prefix @code{Standard} for any of
9869the standard symbols defined by the Ada language. @value{GDBN} knows about
9870this: it will strip the prefix from names when you use it, and will never
9871look for a name you have so qualified among local symbols, nor match against
9872symbols in other packages or subprograms. If you have
9873defined entities anywhere in your program other than parameters and
9874local variables whose simple names match names in @code{Standard},
9875GNAT's lack of qualification here can cause confusion. When this happens,
9876you can usually resolve the confusion
9877by qualifying the problematic names with package
9878@code{Standard} explicitly.
9879@end itemize
9880
4e562065
JB
9881@node Unsupported languages
9882@section Unsupported languages
9883
9884@cindex unsupported languages
9885@cindex minimal language
9886In addition to the other fully-supported programming languages,
9887@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9888It does not represent a real programming language, but provides a set
9889of capabilities close to what the C or assembly languages provide.
9890This should allow most simple operations to be performed while debugging
9891an application that uses a language currently not supported by @value{GDBN}.
9892
9893If the language is set to @code{auto}, @value{GDBN} will automatically
9894select this language if the current frame corresponds to an unsupported
9895language.
9896
6d2ebf8b 9897@node Symbols
c906108c
SS
9898@chapter Examining the Symbol Table
9899
d4f3574e 9900The commands described in this chapter allow you to inquire about the
c906108c
SS
9901symbols (names of variables, functions and types) defined in your
9902program. This information is inherent in the text of your program and
9903does not change as your program executes. @value{GDBN} finds it in your
9904program's symbol table, in the file indicated when you started @value{GDBN}
9905(@pxref{File Options, ,Choosing files}), or by one of the
9906file-management commands (@pxref{Files, ,Commands to specify files}).
9907
9908@cindex symbol names
9909@cindex names of symbols
9910@cindex quoting names
9911Occasionally, you may need to refer to symbols that contain unusual
9912characters, which @value{GDBN} ordinarily treats as word delimiters. The
9913most frequent case is in referring to static variables in other
9914source files (@pxref{Variables,,Program variables}). File names
9915are recorded in object files as debugging symbols, but @value{GDBN} would
9916ordinarily parse a typical file name, like @file{foo.c}, as the three words
9917@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9918@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9919
474c8240 9920@smallexample
c906108c 9921p 'foo.c'::x
474c8240 9922@end smallexample
c906108c
SS
9923
9924@noindent
9925looks up the value of @code{x} in the scope of the file @file{foo.c}.
9926
9927@table @code
a8f24a35
EZ
9928@cindex case-insensitive symbol names
9929@cindex case sensitivity in symbol names
9930@kindex set case-sensitive
9931@item set case-sensitive on
9932@itemx set case-sensitive off
9933@itemx set case-sensitive auto
9934Normally, when @value{GDBN} looks up symbols, it matches their names
9935with case sensitivity determined by the current source language.
9936Occasionally, you may wish to control that. The command @code{set
9937case-sensitive} lets you do that by specifying @code{on} for
9938case-sensitive matches or @code{off} for case-insensitive ones. If
9939you specify @code{auto}, case sensitivity is reset to the default
9940suitable for the source language. The default is case-sensitive
9941matches for all languages except for Fortran, for which the default is
9942case-insensitive matches.
9943
9c16f35a
EZ
9944@kindex show case-sensitive
9945@item show case-sensitive
a8f24a35
EZ
9946This command shows the current setting of case sensitivity for symbols
9947lookups.
9948
c906108c 9949@kindex info address
b37052ae 9950@cindex address of a symbol
c906108c
SS
9951@item info address @var{symbol}
9952Describe where the data for @var{symbol} is stored. For a register
9953variable, this says which register it is kept in. For a non-register
9954local variable, this prints the stack-frame offset at which the variable
9955is always stored.
9956
9957Note the contrast with @samp{print &@var{symbol}}, which does not work
9958at all for a register variable, and for a stack local variable prints
9959the exact address of the current instantiation of the variable.
9960
3d67e040 9961@kindex info symbol
b37052ae 9962@cindex symbol from address
9c16f35a 9963@cindex closest symbol and offset for an address
3d67e040
EZ
9964@item info symbol @var{addr}
9965Print the name of a symbol which is stored at the address @var{addr}.
9966If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9967nearest symbol and an offset from it:
9968
474c8240 9969@smallexample
3d67e040
EZ
9970(@value{GDBP}) info symbol 0x54320
9971_initialize_vx + 396 in section .text
474c8240 9972@end smallexample
3d67e040
EZ
9973
9974@noindent
9975This is the opposite of the @code{info address} command. You can use
9976it to find out the name of a variable or a function given its address.
9977
c906108c 9978@kindex whatis
d4f3574e
SS
9979@item whatis @var{expr}
9980Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9981actually evaluated, and any side-effecting operations (such as
9982assignments or function calls) inside it do not take place.
9983@xref{Expressions, ,Expressions}.
9984
9985@item whatis
9986Print the data type of @code{$}, the last value in the value history.
9987
9988@kindex ptype
9989@item ptype @var{typename}
9990Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9991the name of a type, or for C code it may have the form @samp{class
9992@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9993@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9994
d4f3574e 9995@item ptype @var{expr}
c906108c 9996@itemx ptype
d4f3574e 9997Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
9998differs from @code{whatis} by printing a detailed description, instead
9999of just the name of the type.
10000
10001For example, for this variable declaration:
10002
474c8240 10003@smallexample
c906108c 10004struct complex @{double real; double imag;@} v;
474c8240 10005@end smallexample
c906108c
SS
10006
10007@noindent
10008the two commands give this output:
10009
474c8240 10010@smallexample
c906108c
SS
10011@group
10012(@value{GDBP}) whatis v
10013type = struct complex
10014(@value{GDBP}) ptype v
10015type = struct complex @{
10016 double real;
10017 double imag;
10018@}
10019@end group
474c8240 10020@end smallexample
c906108c
SS
10021
10022@noindent
10023As with @code{whatis}, using @code{ptype} without an argument refers to
10024the type of @code{$}, the last value in the value history.
10025
10026@kindex info types
10027@item info types @var{regexp}
10028@itemx info types
09d4efe1
EZ
10029Print a brief description of all types whose names match the regular
10030expression @var{regexp} (or all types in your program, if you supply
10031no argument). Each complete typename is matched as though it were a
10032complete line; thus, @samp{i type value} gives information on all
10033types in your program whose names include the string @code{value}, but
10034@samp{i type ^value$} gives information only on types whose complete
10035name is @code{value}.
c906108c
SS
10036
10037This command differs from @code{ptype} in two ways: first, like
10038@code{whatis}, it does not print a detailed description; second, it
10039lists all source files where a type is defined.
10040
b37052ae
EZ
10041@kindex info scope
10042@cindex local variables
09d4efe1 10043@item info scope @var{location}
b37052ae 10044List all the variables local to a particular scope. This command
09d4efe1
EZ
10045accepts a @var{location} argument---a function name, a source line, or
10046an address preceded by a @samp{*}, and prints all the variables local
10047to the scope defined by that location. For example:
b37052ae
EZ
10048
10049@smallexample
10050(@value{GDBP}) @b{info scope command_line_handler}
10051Scope for command_line_handler:
10052Symbol rl is an argument at stack/frame offset 8, length 4.
10053Symbol linebuffer is in static storage at address 0x150a18, length 4.
10054Symbol linelength is in static storage at address 0x150a1c, length 4.
10055Symbol p is a local variable in register $esi, length 4.
10056Symbol p1 is a local variable in register $ebx, length 4.
10057Symbol nline is a local variable in register $edx, length 4.
10058Symbol repeat is a local variable at frame offset -8, length 4.
10059@end smallexample
10060
f5c37c66
EZ
10061@noindent
10062This command is especially useful for determining what data to collect
10063during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10064collect}.
10065
c906108c
SS
10066@kindex info source
10067@item info source
919d772c
JB
10068Show information about the current source file---that is, the source file for
10069the function containing the current point of execution:
10070@itemize @bullet
10071@item
10072the name of the source file, and the directory containing it,
10073@item
10074the directory it was compiled in,
10075@item
10076its length, in lines,
10077@item
10078which programming language it is written in,
10079@item
10080whether the executable includes debugging information for that file, and
10081if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10082@item
10083whether the debugging information includes information about
10084preprocessor macros.
10085@end itemize
10086
c906108c
SS
10087
10088@kindex info sources
10089@item info sources
10090Print the names of all source files in your program for which there is
10091debugging information, organized into two lists: files whose symbols
10092have already been read, and files whose symbols will be read when needed.
10093
10094@kindex info functions
10095@item info functions
10096Print the names and data types of all defined functions.
10097
10098@item info functions @var{regexp}
10099Print the names and data types of all defined functions
10100whose names contain a match for regular expression @var{regexp}.
10101Thus, @samp{info fun step} finds all functions whose names
10102include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10103start with @code{step}. If a function name contains characters
10104that conflict with the regular expression language (eg.
1c5dfdad 10105@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10106
10107@kindex info variables
10108@item info variables
10109Print the names and data types of all variables that are declared
6ca652b0 10110outside of functions (i.e.@: excluding local variables).
c906108c
SS
10111
10112@item info variables @var{regexp}
10113Print the names and data types of all variables (except for local
10114variables) whose names contain a match for regular expression
10115@var{regexp}.
10116
b37303ee 10117@kindex info classes
721c2651 10118@cindex Objective-C, classes and selectors
b37303ee
AF
10119@item info classes
10120@itemx info classes @var{regexp}
10121Display all Objective-C classes in your program, or
10122(with the @var{regexp} argument) all those matching a particular regular
10123expression.
10124
10125@kindex info selectors
10126@item info selectors
10127@itemx info selectors @var{regexp}
10128Display all Objective-C selectors in your program, or
10129(with the @var{regexp} argument) all those matching a particular regular
10130expression.
10131
c906108c
SS
10132@ignore
10133This was never implemented.
10134@kindex info methods
10135@item info methods
10136@itemx info methods @var{regexp}
10137The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10138methods within C@t{++} program, or (with the @var{regexp} argument) a
10139specific set of methods found in the various C@t{++} classes. Many
10140C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10141from the @code{ptype} command can be overwhelming and hard to use. The
10142@code{info-methods} command filters the methods, printing only those
10143which match the regular-expression @var{regexp}.
10144@end ignore
10145
c906108c
SS
10146@cindex reloading symbols
10147Some systems allow individual object files that make up your program to
7a292a7a
SS
10148be replaced without stopping and restarting your program. For example,
10149in VxWorks you can simply recompile a defective object file and keep on
10150running. If you are running on one of these systems, you can allow
10151@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10152
10153@table @code
10154@kindex set symbol-reloading
10155@item set symbol-reloading on
10156Replace symbol definitions for the corresponding source file when an
10157object file with a particular name is seen again.
10158
10159@item set symbol-reloading off
6d2ebf8b
SS
10160Do not replace symbol definitions when encountering object files of the
10161same name more than once. This is the default state; if you are not
10162running on a system that permits automatic relinking of modules, you
10163should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10164may discard symbols when linking large programs, that may contain
10165several modules (from different directories or libraries) with the same
10166name.
c906108c
SS
10167
10168@kindex show symbol-reloading
10169@item show symbol-reloading
10170Show the current @code{on} or @code{off} setting.
10171@end table
c906108c 10172
9c16f35a 10173@cindex opaque data types
c906108c
SS
10174@kindex set opaque-type-resolution
10175@item set opaque-type-resolution on
10176Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10177declared as a pointer to a @code{struct}, @code{class}, or
10178@code{union}---for example, @code{struct MyType *}---that is used in one
10179source file although the full declaration of @code{struct MyType} is in
10180another source file. The default is on.
10181
10182A change in the setting of this subcommand will not take effect until
10183the next time symbols for a file are loaded.
10184
10185@item set opaque-type-resolution off
10186Tell @value{GDBN} not to resolve opaque types. In this case, the type
10187is printed as follows:
10188@smallexample
10189@{<no data fields>@}
10190@end smallexample
10191
10192@kindex show opaque-type-resolution
10193@item show opaque-type-resolution
10194Show whether opaque types are resolved or not.
c906108c
SS
10195
10196@kindex maint print symbols
10197@cindex symbol dump
10198@kindex maint print psymbols
10199@cindex partial symbol dump
10200@item maint print symbols @var{filename}
10201@itemx maint print psymbols @var{filename}
10202@itemx maint print msymbols @var{filename}
10203Write a dump of debugging symbol data into the file @var{filename}.
10204These commands are used to debug the @value{GDBN} symbol-reading code. Only
10205symbols with debugging data are included. If you use @samp{maint print
10206symbols}, @value{GDBN} includes all the symbols for which it has already
10207collected full details: that is, @var{filename} reflects symbols for
10208only those files whose symbols @value{GDBN} has read. You can use the
10209command @code{info sources} to find out which files these are. If you
10210use @samp{maint print psymbols} instead, the dump shows information about
10211symbols that @value{GDBN} only knows partially---that is, symbols defined in
10212files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10213@samp{maint print msymbols} dumps just the minimal symbol information
10214required for each object file from which @value{GDBN} has read some symbols.
10215@xref{Files, ,Commands to specify files}, for a discussion of how
10216@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10217
5e7b2f39
JB
10218@kindex maint info symtabs
10219@kindex maint info psymtabs
44ea7b70
JB
10220@cindex listing @value{GDBN}'s internal symbol tables
10221@cindex symbol tables, listing @value{GDBN}'s internal
10222@cindex full symbol tables, listing @value{GDBN}'s internal
10223@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10224@item maint info symtabs @r{[} @var{regexp} @r{]}
10225@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10226
10227List the @code{struct symtab} or @code{struct partial_symtab}
10228structures whose names match @var{regexp}. If @var{regexp} is not
10229given, list them all. The output includes expressions which you can
10230copy into a @value{GDBN} debugging this one to examine a particular
10231structure in more detail. For example:
10232
10233@smallexample
5e7b2f39 10234(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10235@{ objfile /home/gnu/build/gdb/gdb
10236 ((struct objfile *) 0x82e69d0)
b383017d 10237 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10238 ((struct partial_symtab *) 0x8474b10)
10239 readin no
10240 fullname (null)
10241 text addresses 0x814d3c8 -- 0x8158074
10242 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10243 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10244 dependencies (none)
10245 @}
10246@}
5e7b2f39 10247(@value{GDBP}) maint info symtabs
44ea7b70
JB
10248(@value{GDBP})
10249@end smallexample
10250@noindent
10251We see that there is one partial symbol table whose filename contains
10252the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10253and we see that @value{GDBN} has not read in any symtabs yet at all.
10254If we set a breakpoint on a function, that will cause @value{GDBN} to
10255read the symtab for the compilation unit containing that function:
10256
10257@smallexample
10258(@value{GDBP}) break dwarf2_psymtab_to_symtab
10259Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10260line 1574.
5e7b2f39 10261(@value{GDBP}) maint info symtabs
b383017d 10262@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10263 ((struct objfile *) 0x82e69d0)
b383017d 10264 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10265 ((struct symtab *) 0x86c1f38)
10266 dirname (null)
10267 fullname (null)
10268 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10269 debugformat DWARF 2
10270 @}
10271@}
b383017d 10272(@value{GDBP})
44ea7b70 10273@end smallexample
c906108c
SS
10274@end table
10275
44ea7b70 10276
6d2ebf8b 10277@node Altering
c906108c
SS
10278@chapter Altering Execution
10279
10280Once you think you have found an error in your program, you might want to
10281find out for certain whether correcting the apparent error would lead to
10282correct results in the rest of the run. You can find the answer by
10283experiment, using the @value{GDBN} features for altering execution of the
10284program.
10285
10286For example, you can store new values into variables or memory
7a292a7a
SS
10287locations, give your program a signal, restart it at a different
10288address, or even return prematurely from a function.
c906108c
SS
10289
10290@menu
10291* Assignment:: Assignment to variables
10292* Jumping:: Continuing at a different address
c906108c 10293* Signaling:: Giving your program a signal
c906108c
SS
10294* Returning:: Returning from a function
10295* Calling:: Calling your program's functions
10296* Patching:: Patching your program
10297@end menu
10298
6d2ebf8b 10299@node Assignment
c906108c
SS
10300@section Assignment to variables
10301
10302@cindex assignment
10303@cindex setting variables
10304To alter the value of a variable, evaluate an assignment expression.
10305@xref{Expressions, ,Expressions}. For example,
10306
474c8240 10307@smallexample
c906108c 10308print x=4
474c8240 10309@end smallexample
c906108c
SS
10310
10311@noindent
10312stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10313value of the assignment expression (which is 4).
c906108c
SS
10314@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10315information on operators in supported languages.
c906108c
SS
10316
10317@kindex set variable
10318@cindex variables, setting
10319If you are not interested in seeing the value of the assignment, use the
10320@code{set} command instead of the @code{print} command. @code{set} is
10321really the same as @code{print} except that the expression's value is
10322not printed and is not put in the value history (@pxref{Value History,
10323,Value history}). The expression is evaluated only for its effects.
10324
c906108c
SS
10325If the beginning of the argument string of the @code{set} command
10326appears identical to a @code{set} subcommand, use the @code{set
10327variable} command instead of just @code{set}. This command is identical
10328to @code{set} except for its lack of subcommands. For example, if your
10329program has a variable @code{width}, you get an error if you try to set
10330a new value with just @samp{set width=13}, because @value{GDBN} has the
10331command @code{set width}:
10332
474c8240 10333@smallexample
c906108c
SS
10334(@value{GDBP}) whatis width
10335type = double
10336(@value{GDBP}) p width
10337$4 = 13
10338(@value{GDBP}) set width=47
10339Invalid syntax in expression.
474c8240 10340@end smallexample
c906108c
SS
10341
10342@noindent
10343The invalid expression, of course, is @samp{=47}. In
10344order to actually set the program's variable @code{width}, use
10345
474c8240 10346@smallexample
c906108c 10347(@value{GDBP}) set var width=47
474c8240 10348@end smallexample
53a5351d 10349
c906108c
SS
10350Because the @code{set} command has many subcommands that can conflict
10351with the names of program variables, it is a good idea to use the
10352@code{set variable} command instead of just @code{set}. For example, if
10353your program has a variable @code{g}, you run into problems if you try
10354to set a new value with just @samp{set g=4}, because @value{GDBN} has
10355the command @code{set gnutarget}, abbreviated @code{set g}:
10356
474c8240 10357@smallexample
c906108c
SS
10358@group
10359(@value{GDBP}) whatis g
10360type = double
10361(@value{GDBP}) p g
10362$1 = 1
10363(@value{GDBP}) set g=4
2df3850c 10364(@value{GDBP}) p g
c906108c
SS
10365$2 = 1
10366(@value{GDBP}) r
10367The program being debugged has been started already.
10368Start it from the beginning? (y or n) y
10369Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10370"/home/smith/cc_progs/a.out": can't open to read symbols:
10371 Invalid bfd target.
c906108c
SS
10372(@value{GDBP}) show g
10373The current BFD target is "=4".
10374@end group
474c8240 10375@end smallexample
c906108c
SS
10376
10377@noindent
10378The program variable @code{g} did not change, and you silently set the
10379@code{gnutarget} to an invalid value. In order to set the variable
10380@code{g}, use
10381
474c8240 10382@smallexample
c906108c 10383(@value{GDBP}) set var g=4
474c8240 10384@end smallexample
c906108c
SS
10385
10386@value{GDBN} allows more implicit conversions in assignments than C; you can
10387freely store an integer value into a pointer variable or vice versa,
10388and you can convert any structure to any other structure that is the
10389same length or shorter.
10390@comment FIXME: how do structs align/pad in these conversions?
10391@comment /doc@cygnus.com 18dec1990
10392
10393To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10394construct to generate a value of specified type at a specified address
10395(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10396to memory location @code{0x83040} as an integer (which implies a certain size
10397and representation in memory), and
10398
474c8240 10399@smallexample
c906108c 10400set @{int@}0x83040 = 4
474c8240 10401@end smallexample
c906108c
SS
10402
10403@noindent
10404stores the value 4 into that memory location.
10405
6d2ebf8b 10406@node Jumping
c906108c
SS
10407@section Continuing at a different address
10408
10409Ordinarily, when you continue your program, you do so at the place where
10410it stopped, with the @code{continue} command. You can instead continue at
10411an address of your own choosing, with the following commands:
10412
10413@table @code
10414@kindex jump
10415@item jump @var{linespec}
10416Resume execution at line @var{linespec}. Execution stops again
10417immediately if there is a breakpoint there. @xref{List, ,Printing
10418source lines}, for a description of the different forms of
10419@var{linespec}. It is common practice to use the @code{tbreak} command
10420in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10421breakpoints}.
10422
10423The @code{jump} command does not change the current stack frame, or
10424the stack pointer, or the contents of any memory location or any
10425register other than the program counter. If line @var{linespec} is in
10426a different function from the one currently executing, the results may
10427be bizarre if the two functions expect different patterns of arguments or
10428of local variables. For this reason, the @code{jump} command requests
10429confirmation if the specified line is not in the function currently
10430executing. However, even bizarre results are predictable if you are
10431well acquainted with the machine-language code of your program.
10432
10433@item jump *@var{address}
10434Resume execution at the instruction at address @var{address}.
10435@end table
10436
c906108c 10437@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10438On many systems, you can get much the same effect as the @code{jump}
10439command by storing a new value into the register @code{$pc}. The
10440difference is that this does not start your program running; it only
10441changes the address of where it @emph{will} run when you continue. For
10442example,
c906108c 10443
474c8240 10444@smallexample
c906108c 10445set $pc = 0x485
474c8240 10446@end smallexample
c906108c
SS
10447
10448@noindent
10449makes the next @code{continue} command or stepping command execute at
10450address @code{0x485}, rather than at the address where your program stopped.
10451@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10452
10453The most common occasion to use the @code{jump} command is to back
10454up---perhaps with more breakpoints set---over a portion of a program
10455that has already executed, in order to examine its execution in more
10456detail.
10457
c906108c 10458@c @group
6d2ebf8b 10459@node Signaling
c906108c 10460@section Giving your program a signal
9c16f35a 10461@cindex deliver a signal to a program
c906108c
SS
10462
10463@table @code
10464@kindex signal
10465@item signal @var{signal}
10466Resume execution where your program stopped, but immediately give it the
10467signal @var{signal}. @var{signal} can be the name or the number of a
10468signal. For example, on many systems @code{signal 2} and @code{signal
10469SIGINT} are both ways of sending an interrupt signal.
10470
10471Alternatively, if @var{signal} is zero, continue execution without
10472giving a signal. This is useful when your program stopped on account of
10473a signal and would ordinary see the signal when resumed with the
10474@code{continue} command; @samp{signal 0} causes it to resume without a
10475signal.
10476
10477@code{signal} does not repeat when you press @key{RET} a second time
10478after executing the command.
10479@end table
10480@c @end group
10481
10482Invoking the @code{signal} command is not the same as invoking the
10483@code{kill} utility from the shell. Sending a signal with @code{kill}
10484causes @value{GDBN} to decide what to do with the signal depending on
10485the signal handling tables (@pxref{Signals}). The @code{signal} command
10486passes the signal directly to your program.
10487
c906108c 10488
6d2ebf8b 10489@node Returning
c906108c
SS
10490@section Returning from a function
10491
10492@table @code
10493@cindex returning from a function
10494@kindex return
10495@item return
10496@itemx return @var{expression}
10497You can cancel execution of a function call with the @code{return}
10498command. If you give an
10499@var{expression} argument, its value is used as the function's return
10500value.
10501@end table
10502
10503When you use @code{return}, @value{GDBN} discards the selected stack frame
10504(and all frames within it). You can think of this as making the
10505discarded frame return prematurely. If you wish to specify a value to
10506be returned, give that value as the argument to @code{return}.
10507
10508This pops the selected stack frame (@pxref{Selection, ,Selecting a
10509frame}), and any other frames inside of it, leaving its caller as the
10510innermost remaining frame. That frame becomes selected. The
10511specified value is stored in the registers used for returning values
10512of functions.
10513
10514The @code{return} command does not resume execution; it leaves the
10515program stopped in the state that would exist if the function had just
10516returned. In contrast, the @code{finish} command (@pxref{Continuing
10517and Stepping, ,Continuing and stepping}) resumes execution until the
10518selected stack frame returns naturally.
10519
6d2ebf8b 10520@node Calling
c906108c
SS
10521@section Calling program functions
10522
f8568604 10523@table @code
c906108c 10524@cindex calling functions
f8568604
EZ
10525@cindex inferior functions, calling
10526@item print @var{expr}
9c16f35a 10527Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10528@var{expr} may include calls to functions in the program being
10529debugged.
10530
c906108c 10531@kindex call
c906108c
SS
10532@item call @var{expr}
10533Evaluate the expression @var{expr} without displaying @code{void}
10534returned values.
c906108c
SS
10535
10536You can use this variant of the @code{print} command if you want to
f8568604
EZ
10537execute a function from your program that does not return anything
10538(a.k.a.@: @dfn{a void function}), but without cluttering the output
10539with @code{void} returned values that @value{GDBN} will otherwise
10540print. If the result is not void, it is printed and saved in the
10541value history.
10542@end table
10543
9c16f35a
EZ
10544It is possible for the function you call via the @code{print} or
10545@code{call} command to generate a signal (e.g., if there's a bug in
10546the function, or if you passed it incorrect arguments). What happens
10547in that case is controlled by the @code{set unwindonsignal} command.
10548
10549@table @code
10550@item set unwindonsignal
10551@kindex set unwindonsignal
10552@cindex unwind stack in called functions
10553@cindex call dummy stack unwinding
10554Set unwinding of the stack if a signal is received while in a function
10555that @value{GDBN} called in the program being debugged. If set to on,
10556@value{GDBN} unwinds the stack it created for the call and restores
10557the context to what it was before the call. If set to off (the
10558default), @value{GDBN} stops in the frame where the signal was
10559received.
10560
10561@item show unwindonsignal
10562@kindex show unwindonsignal
10563Show the current setting of stack unwinding in the functions called by
10564@value{GDBN}.
10565@end table
10566
f8568604
EZ
10567@cindex weak alias functions
10568Sometimes, a function you wish to call is actually a @dfn{weak alias}
10569for another function. In such case, @value{GDBN} might not pick up
10570the type information, including the types of the function arguments,
10571which causes @value{GDBN} to call the inferior function incorrectly.
10572As a result, the called function will function erroneously and may
10573even crash. A solution to that is to use the name of the aliased
10574function instead.
c906108c 10575
6d2ebf8b 10576@node Patching
c906108c 10577@section Patching programs
7a292a7a 10578
c906108c
SS
10579@cindex patching binaries
10580@cindex writing into executables
c906108c 10581@cindex writing into corefiles
c906108c 10582
7a292a7a
SS
10583By default, @value{GDBN} opens the file containing your program's
10584executable code (or the corefile) read-only. This prevents accidental
10585alterations to machine code; but it also prevents you from intentionally
10586patching your program's binary.
c906108c
SS
10587
10588If you'd like to be able to patch the binary, you can specify that
10589explicitly with the @code{set write} command. For example, you might
10590want to turn on internal debugging flags, or even to make emergency
10591repairs.
10592
10593@table @code
10594@kindex set write
10595@item set write on
10596@itemx set write off
7a292a7a
SS
10597If you specify @samp{set write on}, @value{GDBN} opens executable and
10598core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10599off} (the default), @value{GDBN} opens them read-only.
10600
10601If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10602@code{exec-file} or @code{core-file} command) after changing @code{set
10603write}, for your new setting to take effect.
c906108c
SS
10604
10605@item show write
10606@kindex show write
7a292a7a
SS
10607Display whether executable files and core files are opened for writing
10608as well as reading.
c906108c
SS
10609@end table
10610
6d2ebf8b 10611@node GDB Files
c906108c
SS
10612@chapter @value{GDBN} Files
10613
7a292a7a
SS
10614@value{GDBN} needs to know the file name of the program to be debugged,
10615both in order to read its symbol table and in order to start your
10616program. To debug a core dump of a previous run, you must also tell
10617@value{GDBN} the name of the core dump file.
c906108c
SS
10618
10619@menu
10620* Files:: Commands to specify files
5b5d99cf 10621* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10622* Symbol Errors:: Errors reading symbol files
10623@end menu
10624
6d2ebf8b 10625@node Files
c906108c 10626@section Commands to specify files
c906108c 10627
7a292a7a 10628@cindex symbol table
c906108c 10629@cindex core dump file
7a292a7a
SS
10630
10631You may want to specify executable and core dump file names. The usual
10632way to do this is at start-up time, using the arguments to
10633@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10634Out of @value{GDBN}}).
c906108c
SS
10635
10636Occasionally it is necessary to change to a different file during a
397ca115
EZ
10637@value{GDBN} session. Or you may run @value{GDBN} and forget to
10638specify a file you want to use. Or you are debugging a remote target
10639via @code{gdbserver} (@pxref{Server, file}). In these situations the
10640@value{GDBN} commands to specify new files are useful.
c906108c
SS
10641
10642@table @code
10643@cindex executable file
10644@kindex file
10645@item file @var{filename}
10646Use @var{filename} as the program to be debugged. It is read for its
10647symbols and for the contents of pure memory. It is also the program
10648executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10649directory and the file is not found in the @value{GDBN} working directory,
10650@value{GDBN} uses the environment variable @code{PATH} as a list of
10651directories to search, just as the shell does when looking for a program
10652to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10653and your program, using the @code{path} command.
10654
6d2ebf8b 10655On systems with memory-mapped files, an auxiliary file named
c906108c
SS
10656@file{@var{filename}.syms} may hold symbol table information for
10657@var{filename}. If so, @value{GDBN} maps in the symbol table from
10658@file{@var{filename}.syms}, starting up more quickly. See the
10659descriptions of the file options @samp{-mapped} and @samp{-readnow}
7b5ba0cc
EZ
10660(available on the command line, see @ref{File Options, , -readnow},
10661and with the commands @code{file}, @code{symbol-file}, or
10662@code{add-symbol-file}, described below), for more information.
c906108c 10663
fc8be69e
EZ
10664@cindex unlinked object files
10665@cindex patching object files
10666You can load unlinked object @file{.o} files into @value{GDBN} using
10667the @code{file} command. You will not be able to ``run'' an object
10668file, but you can disassemble functions and inspect variables. Also,
10669if the underlying BFD functionality supports it, you could use
10670@kbd{gdb -write} to patch object files using this technique. Note
10671that @value{GDBN} can neither interpret nor modify relocations in this
10672case, so branches and some initialized variables will appear to go to
10673the wrong place. But this feature is still handy from time to time.
10674
c906108c
SS
10675@item file
10676@code{file} with no argument makes @value{GDBN} discard any information it
10677has on both executable file and the symbol table.
10678
10679@kindex exec-file
10680@item exec-file @r{[} @var{filename} @r{]}
10681Specify that the program to be run (but not the symbol table) is found
10682in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10683if necessary to locate your program. Omitting @var{filename} means to
10684discard information on the executable file.
10685
10686@kindex symbol-file
10687@item symbol-file @r{[} @var{filename} @r{]}
10688Read symbol table information from file @var{filename}. @code{PATH} is
10689searched when necessary. Use the @code{file} command to get both symbol
10690table and program to run from the same file.
10691
10692@code{symbol-file} with no argument clears out @value{GDBN} information on your
10693program's symbol table.
10694
5d161b24 10695The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10696of its convenience variables, the value history, and all breakpoints and
10697auto-display expressions. This is because they may contain pointers to
10698the internal data recording symbols and data types, which are part of
10699the old symbol table data being discarded inside @value{GDBN}.
10700
10701@code{symbol-file} does not repeat if you press @key{RET} again after
10702executing it once.
10703
10704When @value{GDBN} is configured for a particular environment, it
10705understands debugging information in whatever format is the standard
10706generated for that environment; you may use either a @sc{gnu} compiler, or
10707other compilers that adhere to the local conventions.
c906108c
SS
10708Best results are usually obtained from @sc{gnu} compilers; for example,
10709using @code{@value{GCC}} you can generate debugging information for
10710optimized code.
c906108c
SS
10711
10712For most kinds of object files, with the exception of old SVR3 systems
10713using COFF, the @code{symbol-file} command does not normally read the
10714symbol table in full right away. Instead, it scans the symbol table
10715quickly to find which source files and which symbols are present. The
10716details are read later, one source file at a time, as they are needed.
10717
10718The purpose of this two-stage reading strategy is to make @value{GDBN}
10719start up faster. For the most part, it is invisible except for
10720occasional pauses while the symbol table details for a particular source
10721file are being read. (The @code{set verbose} command can turn these
10722pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10723warnings and messages}.)
10724
c906108c
SS
10725We have not implemented the two-stage strategy for COFF yet. When the
10726symbol table is stored in COFF format, @code{symbol-file} reads the
10727symbol table data in full right away. Note that ``stabs-in-COFF''
10728still does the two-stage strategy, since the debug info is actually
10729in stabs format.
10730
10731@kindex readnow
10732@cindex reading symbols immediately
10733@cindex symbols, reading immediately
10734@kindex mapped
10735@cindex memory-mapped symbol file
10736@cindex saving symbol table
10737@item symbol-file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10738@itemx file @var{filename} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
10739You can override the @value{GDBN} two-stage strategy for reading symbol
10740tables by using the @samp{-readnow} option with any of the commands that
10741load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10742entire symbol table available.
c906108c 10743
c906108c
SS
10744If memory-mapped files are available on your system through the
10745@code{mmap} system call, you can use another option, @samp{-mapped}, to
10746cause @value{GDBN} to write the symbols for your program into a reusable
10747file. Future @value{GDBN} debugging sessions map in symbol information
10748from this auxiliary symbol file (if the program has not changed), rather
10749than spending time reading the symbol table from the executable
10750program. Using the @samp{-mapped} option has the same effect as
10751starting @value{GDBN} with the @samp{-mapped} command-line option.
10752
10753You can use both options together, to make sure the auxiliary symbol
10754file has all the symbol information for your program.
10755
10756The auxiliary symbol file for a program called @var{myprog} is called
10757@samp{@var{myprog}.syms}. Once this file exists (so long as it is newer
10758than the corresponding executable), @value{GDBN} always attempts to use
10759it when you debug @var{myprog}; no special options or commands are
10760needed.
10761
10762The @file{.syms} file is specific to the host machine where you run
10763@value{GDBN}. It holds an exact image of the internal @value{GDBN}
10764symbol table. It cannot be shared across multiple host platforms.
c906108c
SS
10765
10766@c FIXME: for now no mention of directories, since this seems to be in
10767@c flux. 13mar1992 status is that in theory GDB would look either in
10768@c current dir or in same dir as myprog; but issues like competing
10769@c GDB's, or clutter in system dirs, mean that in practice right now
10770@c only current dir is used. FFish says maybe a special GDB hierarchy
10771@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10772@c files.
10773
c906108c 10774@kindex core-file
09d4efe1 10775@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10776@itemx core
c906108c
SS
10777Specify the whereabouts of a core dump file to be used as the ``contents
10778of memory''. Traditionally, core files contain only some parts of the
10779address space of the process that generated them; @value{GDBN} can access the
10780executable file itself for other parts.
10781
10782@code{core-file} with no argument specifies that no core file is
10783to be used.
10784
10785Note that the core file is ignored when your program is actually running
7a292a7a
SS
10786under @value{GDBN}. So, if you have been running your program and you
10787wish to debug a core file instead, you must kill the subprocess in which
10788the program is running. To do this, use the @code{kill} command
c906108c 10789(@pxref{Kill Process, ,Killing the child process}).
c906108c 10790
c906108c
SS
10791@kindex add-symbol-file
10792@cindex dynamic linking
10793@item add-symbol-file @var{filename} @var{address}
10794@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]} @r{[} -mapped @r{]}
17d9d558 10795@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10796The @code{add-symbol-file} command reads additional symbol table
10797information from the file @var{filename}. You would use this command
10798when @var{filename} has been dynamically loaded (by some other means)
10799into the program that is running. @var{address} should be the memory
10800address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10801this out for itself. You can additionally specify an arbitrary number
10802of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10803section name and base address for that section. You can specify any
10804@var{address} as an expression.
c906108c
SS
10805
10806The symbol table of the file @var{filename} is added to the symbol table
10807originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10808@code{add-symbol-file} command any number of times; the new symbol data
10809thus read keeps adding to the old. To discard all old symbol data
10810instead, use the @code{symbol-file} command without any arguments.
c906108c 10811
17d9d558
JB
10812@cindex relocatable object files, reading symbols from
10813@cindex object files, relocatable, reading symbols from
10814@cindex reading symbols from relocatable object files
10815@cindex symbols, reading from relocatable object files
10816@cindex @file{.o} files, reading symbols from
10817Although @var{filename} is typically a shared library file, an
10818executable file, or some other object file which has been fully
10819relocated for loading into a process, you can also load symbolic
10820information from relocatable @file{.o} files, as long as:
10821
10822@itemize @bullet
10823@item
10824the file's symbolic information refers only to linker symbols defined in
10825that file, not to symbols defined by other object files,
10826@item
10827every section the file's symbolic information refers to has actually
10828been loaded into the inferior, as it appears in the file, and
10829@item
10830you can determine the address at which every section was loaded, and
10831provide these to the @code{add-symbol-file} command.
10832@end itemize
10833
10834@noindent
10835Some embedded operating systems, like Sun Chorus and VxWorks, can load
10836relocatable files into an already running program; such systems
10837typically make the requirements above easy to meet. However, it's
10838important to recognize that many native systems use complex link
49efadf5 10839procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10840assembly, for example) that make the requirements difficult to meet. In
10841general, one cannot assume that using @code{add-symbol-file} to read a
10842relocatable object file's symbolic information will have the same effect
10843as linking the relocatable object file into the program in the normal
10844way.
10845
c906108c
SS
10846@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10847
10848You can use the @samp{-mapped} and @samp{-readnow} options just as with
10849the @code{symbol-file} command, to change how @value{GDBN} manages the symbol
10850table information for @var{filename}.
10851
c45da7e6
EZ
10852@kindex add-symbol-file-from-memory
10853@cindex @code{syscall DSO}
10854@cindex load symbols from memory
10855@item add-symbol-file-from-memory @var{address}
10856Load symbols from the given @var{address} in a dynamically loaded
10857object file whose image is mapped directly into the inferior's memory.
10858For example, the Linux kernel maps a @code{syscall DSO} into each
10859process's address space; this DSO provides kernel-specific code for
10860some system calls. The argument can be any expression whose
10861evaluation yields the address of the file's shared object file header.
10862For this command to work, you must have used @code{symbol-file} or
10863@code{exec-file} commands in advance.
10864
09d4efe1
EZ
10865@kindex add-shared-symbol-files
10866@kindex assf
10867@item add-shared-symbol-files @var{library-file}
10868@itemx assf @var{library-file}
10869The @code{add-shared-symbol-files} command can currently be used only
10870in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10871alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10872@value{GDBN} automatically looks for shared libraries, however if
10873@value{GDBN} does not find yours, you can invoke
10874@code{add-shared-symbol-files}. It takes one argument: the shared
10875library's file name. @code{assf} is a shorthand alias for
10876@code{add-shared-symbol-files}.
c906108c 10877
c906108c 10878@kindex section
09d4efe1
EZ
10879@item section @var{section} @var{addr}
10880The @code{section} command changes the base address of the named
10881@var{section} of the exec file to @var{addr}. This can be used if the
10882exec file does not contain section addresses, (such as in the
10883@code{a.out} format), or when the addresses specified in the file
10884itself are wrong. Each section must be changed separately. The
10885@code{info files} command, described below, lists all the sections and
10886their addresses.
c906108c
SS
10887
10888@kindex info files
10889@kindex info target
10890@item info files
10891@itemx info target
7a292a7a
SS
10892@code{info files} and @code{info target} are synonymous; both print the
10893current target (@pxref{Targets, ,Specifying a Debugging Target}),
10894including the names of the executable and core dump files currently in
10895use by @value{GDBN}, and the files from which symbols were loaded. The
10896command @code{help target} lists all possible targets rather than
10897current ones.
10898
fe95c787
MS
10899@kindex maint info sections
10900@item maint info sections
10901Another command that can give you extra information about program sections
10902is @code{maint info sections}. In addition to the section information
10903displayed by @code{info files}, this command displays the flags and file
10904offset of each section in the executable and core dump files. In addition,
10905@code{maint info sections} provides the following command options (which
10906may be arbitrarily combined):
10907
10908@table @code
10909@item ALLOBJ
10910Display sections for all loaded object files, including shared libraries.
10911@item @var{sections}
6600abed 10912Display info only for named @var{sections}.
fe95c787
MS
10913@item @var{section-flags}
10914Display info only for sections for which @var{section-flags} are true.
10915The section flags that @value{GDBN} currently knows about are:
10916@table @code
10917@item ALLOC
10918Section will have space allocated in the process when loaded.
10919Set for all sections except those containing debug information.
10920@item LOAD
10921Section will be loaded from the file into the child process memory.
10922Set for pre-initialized code and data, clear for @code{.bss} sections.
10923@item RELOC
10924Section needs to be relocated before loading.
10925@item READONLY
10926Section cannot be modified by the child process.
10927@item CODE
10928Section contains executable code only.
6600abed 10929@item DATA
fe95c787
MS
10930Section contains data only (no executable code).
10931@item ROM
10932Section will reside in ROM.
10933@item CONSTRUCTOR
10934Section contains data for constructor/destructor lists.
10935@item HAS_CONTENTS
10936Section is not empty.
10937@item NEVER_LOAD
10938An instruction to the linker to not output the section.
10939@item COFF_SHARED_LIBRARY
10940A notification to the linker that the section contains
10941COFF shared library information.
10942@item IS_COMMON
10943Section contains common symbols.
10944@end table
10945@end table
6763aef9 10946@kindex set trust-readonly-sections
9c16f35a 10947@cindex read-only sections
6763aef9
MS
10948@item set trust-readonly-sections on
10949Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10950really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10951In that case, @value{GDBN} can fetch values from these sections
10952out of the object file, rather than from the target program.
10953For some targets (notably embedded ones), this can be a significant
10954enhancement to debugging performance.
10955
10956The default is off.
10957
10958@item set trust-readonly-sections off
15110bc3 10959Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10960the contents of the section might change while the program is running,
10961and must therefore be fetched from the target when needed.
9c16f35a
EZ
10962
10963@item show trust-readonly-sections
10964Show the current setting of trusting readonly sections.
c906108c
SS
10965@end table
10966
10967All file-specifying commands allow both absolute and relative file names
10968as arguments. @value{GDBN} always converts the file name to an absolute file
10969name and remembers it that way.
10970
c906108c 10971@cindex shared libraries
9c16f35a
EZ
10972@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10973and IBM RS/6000 AIX shared libraries.
53a5351d 10974
c906108c
SS
10975@value{GDBN} automatically loads symbol definitions from shared libraries
10976when you use the @code{run} command, or when you examine a core file.
10977(Before you issue the @code{run} command, @value{GDBN} does not understand
10978references to a function in a shared library, however---unless you are
10979debugging a core file).
53a5351d
JM
10980
10981On HP-UX, if the program loads a library explicitly, @value{GDBN}
10982automatically loads the symbols at the time of the @code{shl_load} call.
10983
c906108c
SS
10984@c FIXME: some @value{GDBN} release may permit some refs to undef
10985@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10986@c FIXME...lib; check this from time to time when updating manual
10987
b7209cb4
FF
10988There are times, however, when you may wish to not automatically load
10989symbol definitions from shared libraries, such as when they are
10990particularly large or there are many of them.
10991
10992To control the automatic loading of shared library symbols, use the
10993commands:
10994
10995@table @code
10996@kindex set auto-solib-add
10997@item set auto-solib-add @var{mode}
10998If @var{mode} is @code{on}, symbols from all shared object libraries
10999will be loaded automatically when the inferior begins execution, you
11000attach to an independently started inferior, or when the dynamic linker
11001informs @value{GDBN} that a new library has been loaded. If @var{mode}
11002is @code{off}, symbols must be loaded manually, using the
11003@code{sharedlibrary} command. The default value is @code{on}.
11004
dcaf7c2c
EZ
11005@cindex memory used for symbol tables
11006If your program uses lots of shared libraries with debug info that
11007takes large amounts of memory, you can decrease the @value{GDBN}
11008memory footprint by preventing it from automatically loading the
11009symbols from shared libraries. To that end, type @kbd{set
11010auto-solib-add off} before running the inferior, then load each
11011library whose debug symbols you do need with @kbd{sharedlibrary
11012@var{regexp}}, where @var{regexp} is a regular expresion that matches
11013the libraries whose symbols you want to be loaded.
11014
b7209cb4
FF
11015@kindex show auto-solib-add
11016@item show auto-solib-add
11017Display the current autoloading mode.
11018@end table
11019
c45da7e6 11020@cindex load shared library
b7209cb4
FF
11021To explicitly load shared library symbols, use the @code{sharedlibrary}
11022command:
11023
c906108c
SS
11024@table @code
11025@kindex info sharedlibrary
11026@kindex info share
11027@item info share
11028@itemx info sharedlibrary
11029Print the names of the shared libraries which are currently loaded.
11030
11031@kindex sharedlibrary
11032@kindex share
11033@item sharedlibrary @var{regex}
11034@itemx share @var{regex}
c906108c
SS
11035Load shared object library symbols for files matching a
11036Unix regular expression.
11037As with files loaded automatically, it only loads shared libraries
11038required by your program for a core file or after typing @code{run}. If
11039@var{regex} is omitted all shared libraries required by your program are
11040loaded.
c45da7e6
EZ
11041
11042@item nosharedlibrary
11043@kindex nosharedlibrary
11044@cindex unload symbols from shared libraries
11045Unload all shared object library symbols. This discards all symbols
11046that have been loaded from all shared libraries. Symbols from shared
11047libraries that were loaded by explicit user requests are not
11048discarded.
c906108c
SS
11049@end table
11050
721c2651
EZ
11051Sometimes you may wish that @value{GDBN} stops and gives you control
11052when any of shared library events happen. Use the @code{set
11053stop-on-solib-events} command for this:
11054
11055@table @code
11056@item set stop-on-solib-events
11057@kindex set stop-on-solib-events
11058This command controls whether @value{GDBN} should give you control
11059when the dynamic linker notifies it about some shared library event.
11060The most common event of interest is loading or unloading of a new
11061shared library.
11062
11063@item show stop-on-solib-events
11064@kindex show stop-on-solib-events
11065Show whether @value{GDBN} stops and gives you control when shared
11066library events happen.
11067@end table
11068
f5ebfba0
DJ
11069Shared libraries are also supported in many cross or remote debugging
11070configurations. A copy of the target's libraries need to be present on the
11071host system; they need to be the same as the target libraries, although the
11072copies on the target can be stripped as long as the copies on the host are
11073not.
11074
59b7b46f
EZ
11075@cindex where to look for shared libraries
11076For remote debugging, you need to tell @value{GDBN} where the target
11077libraries are, so that it can load the correct copies---otherwise, it
11078may try to load the host's libraries. @value{GDBN} has two variables
11079to specify the search directories for target libraries.
f5ebfba0
DJ
11080
11081@table @code
59b7b46f 11082@cindex prefix for shared library file names
f5ebfba0
DJ
11083@kindex set solib-absolute-prefix
11084@item set solib-absolute-prefix @var{path}
11085If this variable is set, @var{path} will be used as a prefix for any
11086absolute shared library paths; many runtime loaders store the absolute
11087paths to the shared library in the target program's memory. If you use
11088@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11089out in the same way that they are on the target, with e.g.@: a
11090@file{/usr/lib} hierarchy under @var{path}.
11091
59b7b46f
EZ
11092@cindex default value of @samp{solib-absolute-prefix}
11093@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11094You can set the default value of @samp{solib-absolute-prefix} by using the
11095configure-time @samp{--with-sysroot} option.
11096
11097@kindex show solib-absolute-prefix
11098@item show solib-absolute-prefix
11099Display the current shared library prefix.
11100
11101@kindex set solib-search-path
11102@item set solib-search-path @var{path}
11103If this variable is set, @var{path} is a colon-separated list of directories
11104to search for shared libraries. @samp{solib-search-path} is used after
11105@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11106the library is relative instead of absolute. If you want to use
11107@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11108set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11109@value{GDBN} from finding your host's libraries.
11110
11111@kindex show solib-search-path
11112@item show solib-search-path
11113Display the current shared library search path.
11114@end table
11115
5b5d99cf
JB
11116
11117@node Separate Debug Files
11118@section Debugging Information in Separate Files
11119@cindex separate debugging information files
11120@cindex debugging information in separate files
11121@cindex @file{.debug} subdirectories
11122@cindex debugging information directory, global
11123@cindex global debugging information directory
11124
11125@value{GDBN} allows you to put a program's debugging information in a
11126file separate from the executable itself, in a way that allows
11127@value{GDBN} to find and load the debugging information automatically.
11128Since debugging information can be very large --- sometimes larger
11129than the executable code itself --- some systems distribute debugging
11130information for their executables in separate files, which users can
11131install only when they need to debug a problem.
11132
11133If an executable's debugging information has been extracted to a
11134separate file, the executable should contain a @dfn{debug link} giving
11135the name of the debugging information file (with no directory
11136components), and a checksum of its contents. (The exact form of a
11137debug link is described below.) If the full name of the directory
11138containing the executable is @var{execdir}, and the executable has a
11139debug link that specifies the name @var{debugfile}, then @value{GDBN}
11140will automatically search for the debugging information file in three
11141places:
11142
11143@itemize @bullet
11144@item
11145the directory containing the executable file (that is, it will look
11146for a file named @file{@var{execdir}/@var{debugfile}},
11147@item
11148a subdirectory of that directory named @file{.debug} (that is, the
11149file @file{@var{execdir}/.debug/@var{debugfile}}, and
11150@item
11151a subdirectory of the global debug file directory that includes the
11152executable's full path, and the name from the link (that is, the file
11153@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11154@var{globaldebugdir} is the global debug file directory, and
11155@var{execdir} has been turned into a relative path).
11156@end itemize
11157@noindent
11158@value{GDBN} checks under each of these names for a debugging
11159information file whose checksum matches that given in the link, and
11160reads the debugging information from the first one it finds.
11161
11162So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11163which has a link containing the name @file{ls.debug}, and the global
11164debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11165for debug information in @file{/usr/bin/ls.debug},
11166@file{/usr/bin/.debug/ls.debug}, and
11167@file{/usr/lib/debug/usr/bin/ls.debug}.
11168
11169You can set the global debugging info directory's name, and view the
11170name @value{GDBN} is currently using.
11171
11172@table @code
11173
11174@kindex set debug-file-directory
11175@item set debug-file-directory @var{directory}
11176Set the directory which @value{GDBN} searches for separate debugging
11177information files to @var{directory}.
11178
11179@kindex show debug-file-directory
11180@item show debug-file-directory
11181Show the directory @value{GDBN} searches for separate debugging
11182information files.
11183
11184@end table
11185
11186@cindex @code{.gnu_debuglink} sections
11187@cindex debug links
11188A debug link is a special section of the executable file named
11189@code{.gnu_debuglink}. The section must contain:
11190
11191@itemize
11192@item
11193A filename, with any leading directory components removed, followed by
11194a zero byte,
11195@item
11196zero to three bytes of padding, as needed to reach the next four-byte
11197boundary within the section, and
11198@item
11199a four-byte CRC checksum, stored in the same endianness used for the
11200executable file itself. The checksum is computed on the debugging
11201information file's full contents by the function given below, passing
11202zero as the @var{crc} argument.
11203@end itemize
11204
11205Any executable file format can carry a debug link, as long as it can
11206contain a section named @code{.gnu_debuglink} with the contents
11207described above.
11208
11209The debugging information file itself should be an ordinary
11210executable, containing a full set of linker symbols, sections, and
11211debugging information. The sections of the debugging information file
11212should have the same names, addresses and sizes as the original file,
11213but they need not contain any data --- much like a @code{.bss} section
11214in an ordinary executable.
11215
11216As of December 2002, there is no standard GNU utility to produce
11217separated executable / debugging information file pairs. Ulrich
11218Drepper's @file{elfutils} package, starting with version 0.53,
11219contains a version of the @code{strip} command such that the command
11220@kbd{strip foo -f foo.debug} removes the debugging information from
11221the executable file @file{foo}, places it in the file
11222@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11223
11224Since there are many different ways to compute CRC's (different
11225polynomials, reversals, byte ordering, etc.), the simplest way to
11226describe the CRC used in @code{.gnu_debuglink} sections is to give the
11227complete code for a function that computes it:
11228
4644b6e3 11229@kindex gnu_debuglink_crc32
5b5d99cf
JB
11230@smallexample
11231unsigned long
11232gnu_debuglink_crc32 (unsigned long crc,
11233 unsigned char *buf, size_t len)
11234@{
11235 static const unsigned long crc32_table[256] =
11236 @{
11237 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11238 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11239 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11240 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11241 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11242 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11243 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11244 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11245 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11246 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11247 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11248 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11249 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11250 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11251 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11252 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11253 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11254 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11255 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11256 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11257 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11258 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11259 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11260 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11261 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11262 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11263 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11264 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11265 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11266 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11267 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11268 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11269 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11270 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11271 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11272 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11273 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11274 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11275 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11276 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11277 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11278 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11279 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11280 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11281 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11282 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11283 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11284 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11285 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11286 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11287 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11288 0x2d02ef8d
11289 @};
11290 unsigned char *end;
11291
11292 crc = ~crc & 0xffffffff;
11293 for (end = buf + len; buf < end; ++buf)
11294 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11295 return ~crc & 0xffffffff;
5b5d99cf
JB
11296@}
11297@end smallexample
11298
11299
6d2ebf8b 11300@node Symbol Errors
c906108c
SS
11301@section Errors reading symbol files
11302
11303While reading a symbol file, @value{GDBN} occasionally encounters problems,
11304such as symbol types it does not recognize, or known bugs in compiler
11305output. By default, @value{GDBN} does not notify you of such problems, since
11306they are relatively common and primarily of interest to people
11307debugging compilers. If you are interested in seeing information
11308about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11309only one message about each such type of problem, no matter how many
11310times the problem occurs; or you can ask @value{GDBN} to print more messages,
11311to see how many times the problems occur, with the @code{set
11312complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11313messages}).
11314
11315The messages currently printed, and their meanings, include:
11316
11317@table @code
11318@item inner block not inside outer block in @var{symbol}
11319
11320The symbol information shows where symbol scopes begin and end
11321(such as at the start of a function or a block of statements). This
11322error indicates that an inner scope block is not fully contained
11323in its outer scope blocks.
11324
11325@value{GDBN} circumvents the problem by treating the inner block as if it had
11326the same scope as the outer block. In the error message, @var{symbol}
11327may be shown as ``@code{(don't know)}'' if the outer block is not a
11328function.
11329
11330@item block at @var{address} out of order
11331
11332The symbol information for symbol scope blocks should occur in
11333order of increasing addresses. This error indicates that it does not
11334do so.
11335
11336@value{GDBN} does not circumvent this problem, and has trouble
11337locating symbols in the source file whose symbols it is reading. (You
11338can often determine what source file is affected by specifying
11339@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11340messages}.)
11341
11342@item bad block start address patched
11343
11344The symbol information for a symbol scope block has a start address
11345smaller than the address of the preceding source line. This is known
11346to occur in the SunOS 4.1.1 (and earlier) C compiler.
11347
11348@value{GDBN} circumvents the problem by treating the symbol scope block as
11349starting on the previous source line.
11350
11351@item bad string table offset in symbol @var{n}
11352
11353@cindex foo
11354Symbol number @var{n} contains a pointer into the string table which is
11355larger than the size of the string table.
11356
11357@value{GDBN} circumvents the problem by considering the symbol to have the
11358name @code{foo}, which may cause other problems if many symbols end up
11359with this name.
11360
11361@item unknown symbol type @code{0x@var{nn}}
11362
7a292a7a
SS
11363The symbol information contains new data types that @value{GDBN} does
11364not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11365uncomprehended information, in hexadecimal.
c906108c 11366
7a292a7a
SS
11367@value{GDBN} circumvents the error by ignoring this symbol information.
11368This usually allows you to debug your program, though certain symbols
c906108c 11369are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11370debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11371on @code{complain}, then go up to the function @code{read_dbx_symtab}
11372and examine @code{*bufp} to see the symbol.
c906108c
SS
11373
11374@item stub type has NULL name
c906108c 11375
7a292a7a 11376@value{GDBN} could not find the full definition for a struct or class.
c906108c 11377
7a292a7a 11378@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11379The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11380information that recent versions of the compiler should have output for
11381it.
c906108c
SS
11382
11383@item info mismatch between compiler and debugger
11384
11385@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11386
c906108c
SS
11387@end table
11388
6d2ebf8b 11389@node Targets
c906108c 11390@chapter Specifying a Debugging Target
7a292a7a 11391
c906108c 11392@cindex debugging target
c906108c 11393A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11394
11395Often, @value{GDBN} runs in the same host environment as your program;
11396in that case, the debugging target is specified as a side effect when
11397you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11398flexibility---for example, running @value{GDBN} on a physically separate
11399host, or controlling a standalone system over a serial port or a
53a5351d
JM
11400realtime system over a TCP/IP connection---you can use the @code{target}
11401command to specify one of the target types configured for @value{GDBN}
11402(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11403
a8f24a35
EZ
11404@cindex target architecture
11405It is possible to build @value{GDBN} for several different @dfn{target
11406architectures}. When @value{GDBN} is built like that, you can choose
11407one of the available architectures with the @kbd{set architecture}
11408command.
11409
11410@table @code
11411@kindex set architecture
11412@kindex show architecture
11413@item set architecture @var{arch}
11414This command sets the current target architecture to @var{arch}. The
11415value of @var{arch} can be @code{"auto"}, in addition to one of the
11416supported architectures.
11417
11418@item show architecture
11419Show the current target architecture.
9c16f35a
EZ
11420
11421@item set processor
11422@itemx processor
11423@kindex set processor
11424@kindex show processor
11425These are alias commands for, respectively, @code{set architecture}
11426and @code{show architecture}.
a8f24a35
EZ
11427@end table
11428
c906108c
SS
11429@menu
11430* Active Targets:: Active targets
11431* Target Commands:: Commands for managing targets
c906108c
SS
11432* Byte Order:: Choosing target byte order
11433* Remote:: Remote debugging
96baa820 11434* KOD:: Kernel Object Display
c906108c
SS
11435
11436@end menu
11437
6d2ebf8b 11438@node Active Targets
c906108c 11439@section Active targets
7a292a7a 11440
c906108c
SS
11441@cindex stacking targets
11442@cindex active targets
11443@cindex multiple targets
11444
c906108c 11445There are three classes of targets: processes, core files, and
7a292a7a
SS
11446executable files. @value{GDBN} can work concurrently on up to three
11447active targets, one in each class. This allows you to (for example)
11448start a process and inspect its activity without abandoning your work on
11449a core file.
c906108c
SS
11450
11451For example, if you execute @samp{gdb a.out}, then the executable file
11452@code{a.out} is the only active target. If you designate a core file as
11453well---presumably from a prior run that crashed and coredumped---then
11454@value{GDBN} has two active targets and uses them in tandem, looking
11455first in the corefile target, then in the executable file, to satisfy
11456requests for memory addresses. (Typically, these two classes of target
11457are complementary, since core files contain only a program's
11458read-write memory---variables and so on---plus machine status, while
11459executable files contain only the program text and initialized data.)
c906108c
SS
11460
11461When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11462target as well. When a process target is active, all @value{GDBN}
11463commands requesting memory addresses refer to that target; addresses in
11464an active core file or executable file target are obscured while the
11465process target is active.
c906108c 11466
7a292a7a
SS
11467Use the @code{core-file} and @code{exec-file} commands to select a new
11468core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11469files}). To specify as a target a process that is already running, use
7a292a7a
SS
11470the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11471process}).
c906108c 11472
6d2ebf8b 11473@node Target Commands
c906108c
SS
11474@section Commands for managing targets
11475
11476@table @code
11477@item target @var{type} @var{parameters}
7a292a7a
SS
11478Connects the @value{GDBN} host environment to a target machine or
11479process. A target is typically a protocol for talking to debugging
11480facilities. You use the argument @var{type} to specify the type or
11481protocol of the target machine.
c906108c
SS
11482
11483Further @var{parameters} are interpreted by the target protocol, but
11484typically include things like device names or host names to connect
11485with, process numbers, and baud rates.
c906108c
SS
11486
11487The @code{target} command does not repeat if you press @key{RET} again
11488after executing the command.
11489
11490@kindex help target
11491@item help target
11492Displays the names of all targets available. To display targets
11493currently selected, use either @code{info target} or @code{info files}
11494(@pxref{Files, ,Commands to specify files}).
11495
11496@item help target @var{name}
11497Describe a particular target, including any parameters necessary to
11498select it.
11499
11500@kindex set gnutarget
11501@item set gnutarget @var{args}
5d161b24 11502@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11503knows whether it is reading an @dfn{executable},
5d161b24
DB
11504a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11505with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11506with @code{gnutarget} the @code{target} refers to a program, not a machine.
11507
d4f3574e 11508@quotation
c906108c
SS
11509@emph{Warning:} To specify a file format with @code{set gnutarget},
11510you must know the actual BFD name.
d4f3574e 11511@end quotation
c906108c 11512
d4f3574e
SS
11513@noindent
11514@xref{Files, , Commands to specify files}.
c906108c 11515
5d161b24 11516@kindex show gnutarget
c906108c
SS
11517@item show gnutarget
11518Use the @code{show gnutarget} command to display what file format
11519@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11520@value{GDBN} will determine the file format for each file automatically,
11521and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11522@end table
11523
4644b6e3 11524@cindex common targets
c906108c
SS
11525Here are some common targets (available, or not, depending on the GDB
11526configuration):
c906108c
SS
11527
11528@table @code
4644b6e3 11529@kindex target
c906108c 11530@item target exec @var{program}
4644b6e3 11531@cindex executable file target
c906108c
SS
11532An executable file. @samp{target exec @var{program}} is the same as
11533@samp{exec-file @var{program}}.
11534
c906108c 11535@item target core @var{filename}
4644b6e3 11536@cindex core dump file target
c906108c
SS
11537A core dump file. @samp{target core @var{filename}} is the same as
11538@samp{core-file @var{filename}}.
c906108c 11539
c906108c 11540@item target remote @var{dev}
4644b6e3 11541@cindex remote target
c906108c
SS
11542Remote serial target in GDB-specific protocol. The argument @var{dev}
11543specifies what serial device to use for the connection (e.g.
11544@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11545supports the @code{load} command. This is only useful if you have
c906108c
SS
11546some other way of getting the stub to the target system, and you can put
11547it somewhere in memory where it won't get clobbered by the download.
11548
c906108c 11549@item target sim
4644b6e3 11550@cindex built-in simulator target
2df3850c 11551Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11552In general,
474c8240 11553@smallexample
104c1213
JM
11554 target sim
11555 load
11556 run
474c8240 11557@end smallexample
d4f3574e 11558@noindent
104c1213 11559works; however, you cannot assume that a specific memory map, device
d4f3574e 11560drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11561provide these. For info about any processor-specific simulator details,
11562see the appropriate section in @ref{Embedded Processors, ,Embedded
11563Processors}.
11564
c906108c
SS
11565@end table
11566
104c1213 11567Some configurations may include these targets as well:
c906108c
SS
11568
11569@table @code
11570
c906108c 11571@item target nrom @var{dev}
4644b6e3 11572@cindex NetROM ROM emulator target
c906108c
SS
11573NetROM ROM emulator. This target only supports downloading.
11574
c906108c
SS
11575@end table
11576
5d161b24 11577Different targets are available on different configurations of @value{GDBN};
c906108c 11578your configuration may have more or fewer targets.
c906108c 11579
721c2651
EZ
11580Many remote targets require you to download the executable's code once
11581you've successfully established a connection. You may wish to control
11582various aspects of this process, such as the size of the data chunks
11583used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11584
11585@table @code
11586@kindex set download-write-size
11587@item set download-write-size @var{size}
11588Set the write size used when downloading a program. Only used when
11589downloading a program onto a remote target. Specify zero or a
11590negative value to disable blocked writes. The actual size of each
11591transfer is also limited by the size of the target packet and the
11592memory cache.
11593
11594@kindex show download-write-size
11595@item show download-write-size
721c2651 11596@kindex show download-write-size
a8f24a35 11597Show the current value of the write size.
721c2651
EZ
11598
11599@item set hash
11600@kindex set hash@r{, for remote monitors}
11601@cindex hash mark while downloading
11602This command controls whether a hash mark @samp{#} is displayed while
11603downloading a file to the remote monitor. If on, a hash mark is
11604displayed after each S-record is successfully downloaded to the
11605monitor.
11606
11607@item show hash
11608@kindex show hash@r{, for remote monitors}
11609Show the current status of displaying the hash mark.
11610
11611@item set debug monitor
11612@kindex set debug monitor
11613@cindex display remote monitor communications
11614Enable or disable display of communications messages between
11615@value{GDBN} and the remote monitor.
11616
11617@item show debug monitor
11618@kindex show debug monitor
11619Show the current status of displaying communications between
11620@value{GDBN} and the remote monitor.
a8f24a35 11621@end table
c906108c
SS
11622
11623@table @code
11624
11625@kindex load @var{filename}
11626@item load @var{filename}
c906108c
SS
11627Depending on what remote debugging facilities are configured into
11628@value{GDBN}, the @code{load} command may be available. Where it exists, it
11629is meant to make @var{filename} (an executable) available for debugging
11630on the remote system---by downloading, or dynamic linking, for example.
11631@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11632the @code{add-symbol-file} command.
11633
11634If your @value{GDBN} does not have a @code{load} command, attempting to
11635execute it gets the error message ``@code{You can't do that when your
11636target is @dots{}}''
c906108c
SS
11637
11638The file is loaded at whatever address is specified in the executable.
11639For some object file formats, you can specify the load address when you
11640link the program; for other formats, like a.out, the object file format
11641specifies a fixed address.
11642@c FIXME! This would be a good place for an xref to the GNU linker doc.
11643
c906108c
SS
11644@code{load} does not repeat if you press @key{RET} again after using it.
11645@end table
11646
6d2ebf8b 11647@node Byte Order
c906108c 11648@section Choosing target byte order
7a292a7a 11649
c906108c
SS
11650@cindex choosing target byte order
11651@cindex target byte order
c906108c 11652
172c2a43 11653Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11654offer the ability to run either big-endian or little-endian byte
11655orders. Usually the executable or symbol will include a bit to
11656designate the endian-ness, and you will not need to worry about
11657which to use. However, you may still find it useful to adjust
d4f3574e 11658@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11659
11660@table @code
4644b6e3 11661@kindex set endian
c906108c
SS
11662@item set endian big
11663Instruct @value{GDBN} to assume the target is big-endian.
11664
c906108c
SS
11665@item set endian little
11666Instruct @value{GDBN} to assume the target is little-endian.
11667
c906108c
SS
11668@item set endian auto
11669Instruct @value{GDBN} to use the byte order associated with the
11670executable.
11671
11672@item show endian
11673Display @value{GDBN}'s current idea of the target byte order.
11674
11675@end table
11676
11677Note that these commands merely adjust interpretation of symbolic
11678data on the host, and that they have absolutely no effect on the
11679target system.
11680
6d2ebf8b 11681@node Remote
c906108c
SS
11682@section Remote debugging
11683@cindex remote debugging
11684
11685If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11686@value{GDBN} in the usual way, it is often useful to use remote debugging.
11687For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11688or on a small system which does not have a general purpose operating system
11689powerful enough to run a full-featured debugger.
11690
11691Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11692to make this work with particular debugging targets. In addition,
5d161b24 11693@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11694but not specific to any particular target system) which you can use if you
11695write the remote stubs---the code that runs on the remote system to
11696communicate with @value{GDBN}.
11697
11698Other remote targets may be available in your
11699configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11700
c45da7e6
EZ
11701Once you've connected to the remote target, @value{GDBN} allows you to
11702send arbitrary commands to the remote monitor:
11703
11704@table @code
11705@item remote @var{command}
11706@kindex remote@r{, a command}
11707@cindex send command to remote monitor
11708Send an arbitrary @var{command} string to the remote monitor.
11709@end table
11710
11711
6f05cf9f
AC
11712@node KOD
11713@section Kernel Object Display
6f05cf9f 11714@cindex kernel object display
6f05cf9f
AC
11715@cindex KOD
11716
11717Some targets support kernel object display. Using this facility,
11718@value{GDBN} communicates specially with the underlying operating system
11719and can display information about operating system-level objects such as
11720mutexes and other synchronization objects. Exactly which objects can be
11721displayed is determined on a per-OS basis.
11722
3bbe9696 11723@kindex set os
6f05cf9f
AC
11724Use the @code{set os} command to set the operating system. This tells
11725@value{GDBN} which kernel object display module to initialize:
11726
474c8240 11727@smallexample
6f05cf9f 11728(@value{GDBP}) set os cisco
474c8240 11729@end smallexample
6f05cf9f 11730
3bbe9696
EZ
11731@kindex show os
11732The associated command @code{show os} displays the operating system
11733set with the @code{set os} command; if no operating system has been
11734set, @code{show os} will display an empty string @samp{""}.
11735
6f05cf9f
AC
11736If @code{set os} succeeds, @value{GDBN} will display some information
11737about the operating system, and will create a new @code{info} command
11738which can be used to query the target. The @code{info} command is named
11739after the operating system:
c906108c 11740
3bbe9696 11741@kindex info cisco
474c8240 11742@smallexample
6f05cf9f
AC
11743(@value{GDBP}) info cisco
11744List of Cisco Kernel Objects
11745Object Description
11746any Any and all objects
474c8240 11747@end smallexample
6f05cf9f
AC
11748
11749Further subcommands can be used to query about particular objects known
11750by the kernel.
11751
3bbe9696
EZ
11752There is currently no way to determine whether a given operating
11753system is supported other than to try setting it with @kbd{set os
11754@var{name}}, where @var{name} is the name of the operating system you
11755want to try.
6f05cf9f
AC
11756
11757
11758@node Remote Debugging
11759@chapter Debugging remote programs
11760
6b2f586d 11761@menu
07f31aa6 11762* Connecting:: Connecting to a remote target
6b2f586d
AC
11763* Server:: Using the gdbserver program
11764* NetWare:: Using the gdbserve.nlm program
501eef12 11765* Remote configuration:: Remote configuration
6b2f586d 11766* remote stub:: Implementing a remote stub
6b2f586d
AC
11767@end menu
11768
07f31aa6
DJ
11769@node Connecting
11770@section Connecting to a remote target
11771
11772On the @value{GDBN} host machine, you will need an unstripped copy of
11773your program, since @value{GDBN} needs symobl and debugging information.
11774Start up @value{GDBN} as usual, using the name of the local copy of your
11775program as the first argument.
11776
11777@cindex serial line, @code{target remote}
11778If you're using a serial line, you may want to give @value{GDBN} the
11779@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11780(@pxref{Remote configuration, set remotebaud}) before the
11781@code{target} command.
07f31aa6
DJ
11782
11783After that, use @code{target remote} to establish communications with
11784the target machine. Its argument specifies how to communicate---either
11785via a devicename attached to a direct serial line, or a TCP or UDP port
11786(possibly to a terminal server which in turn has a serial line to the
11787target). For example, to use a serial line connected to the device
11788named @file{/dev/ttyb}:
11789
11790@smallexample
11791target remote /dev/ttyb
11792@end smallexample
11793
11794@cindex TCP port, @code{target remote}
11795To use a TCP connection, use an argument of the form
11796@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11797For example, to connect to port 2828 on a
11798terminal server named @code{manyfarms}:
11799
11800@smallexample
11801target remote manyfarms:2828
11802@end smallexample
11803
11804If your remote target is actually running on the same machine as
11805your debugger session (e.g.@: a simulator of your target running on
11806the same host), you can omit the hostname. For example, to connect
11807to port 1234 on your local machine:
11808
11809@smallexample
11810target remote :1234
11811@end smallexample
11812@noindent
11813
11814Note that the colon is still required here.
11815
11816@cindex UDP port, @code{target remote}
11817To use a UDP connection, use an argument of the form
11818@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11819on a terminal server named @code{manyfarms}:
11820
11821@smallexample
11822target remote udp:manyfarms:2828
11823@end smallexample
11824
11825When using a UDP connection for remote debugging, you should keep in mind
11826that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11827busy or unreliable networks, which will cause havoc with your debugging
11828session.
11829
11830Now you can use all the usual commands to examine and change data and to
11831step and continue the remote program.
11832
11833@cindex interrupting remote programs
11834@cindex remote programs, interrupting
11835Whenever @value{GDBN} is waiting for the remote program, if you type the
11836interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11837program. This may or may not succeed, depending in part on the hardware
11838and the serial drivers the remote system uses. If you type the
11839interrupt character once again, @value{GDBN} displays this prompt:
11840
11841@smallexample
11842Interrupted while waiting for the program.
11843Give up (and stop debugging it)? (y or n)
11844@end smallexample
11845
11846If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11847(If you decide you want to try again later, you can use @samp{target
11848remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11849goes back to waiting.
11850
11851@table @code
11852@kindex detach (remote)
11853@item detach
11854When you have finished debugging the remote program, you can use the
11855@code{detach} command to release it from @value{GDBN} control.
11856Detaching from the target normally resumes its execution, but the results
11857will depend on your particular remote stub. After the @code{detach}
11858command, @value{GDBN} is free to connect to another target.
11859
11860@kindex disconnect
11861@item disconnect
11862The @code{disconnect} command behaves like @code{detach}, except that
11863the target is generally not resumed. It will wait for @value{GDBN}
11864(this instance or another one) to connect and continue debugging. After
11865the @code{disconnect} command, @value{GDBN} is again free to connect to
11866another target.
09d4efe1
EZ
11867
11868@cindex send command to remote monitor
11869@kindex monitor
11870@item monitor @var{cmd}
11871This command allows you to send commands directly to the remote
11872monitor.
07f31aa6
DJ
11873@end table
11874
6f05cf9f
AC
11875@node Server
11876@section Using the @code{gdbserver} program
11877
11878@kindex gdbserver
11879@cindex remote connection without stubs
11880@code{gdbserver} is a control program for Unix-like systems, which
11881allows you to connect your program with a remote @value{GDBN} via
11882@code{target remote}---but without linking in the usual debugging stub.
11883
11884@code{gdbserver} is not a complete replacement for the debugging stubs,
11885because it requires essentially the same operating-system facilities
11886that @value{GDBN} itself does. In fact, a system that can run
11887@code{gdbserver} to connect to a remote @value{GDBN} could also run
11888@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11889because it is a much smaller program than @value{GDBN} itself. It is
11890also easier to port than all of @value{GDBN}, so you may be able to get
11891started more quickly on a new system by using @code{gdbserver}.
11892Finally, if you develop code for real-time systems, you may find that
11893the tradeoffs involved in real-time operation make it more convenient to
11894do as much development work as possible on another system, for example
11895by cross-compiling. You can use @code{gdbserver} to make a similar
11896choice for debugging.
11897
11898@value{GDBN} and @code{gdbserver} communicate via either a serial line
11899or a TCP connection, using the standard @value{GDBN} remote serial
11900protocol.
11901
11902@table @emph
11903@item On the target machine,
11904you need to have a copy of the program you want to debug.
11905@code{gdbserver} does not need your program's symbol table, so you can
11906strip the program if necessary to save space. @value{GDBN} on the host
11907system does all the symbol handling.
11908
11909To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11910the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11911syntax is:
11912
11913@smallexample
11914target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11915@end smallexample
11916
11917@var{comm} is either a device name (to use a serial line) or a TCP
11918hostname and portnumber. For example, to debug Emacs with the argument
11919@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11920@file{/dev/com1}:
11921
11922@smallexample
11923target> gdbserver /dev/com1 emacs foo.txt
11924@end smallexample
11925
11926@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11927with it.
11928
11929To use a TCP connection instead of a serial line:
11930
11931@smallexample
11932target> gdbserver host:2345 emacs foo.txt
11933@end smallexample
11934
11935The only difference from the previous example is the first argument,
11936specifying that you are communicating with the host @value{GDBN} via
11937TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11938expect a TCP connection from machine @samp{host} to local TCP port 2345.
11939(Currently, the @samp{host} part is ignored.) You can choose any number
11940you want for the port number as long as it does not conflict with any
11941TCP ports already in use on the target system (for example, @code{23} is
11942reserved for @code{telnet}).@footnote{If you choose a port number that
11943conflicts with another service, @code{gdbserver} prints an error message
11944and exits.} You must use the same port number with the host @value{GDBN}
11945@code{target remote} command.
11946
56460a61
DJ
11947On some targets, @code{gdbserver} can also attach to running programs.
11948This is accomplished via the @code{--attach} argument. The syntax is:
11949
11950@smallexample
11951target> gdbserver @var{comm} --attach @var{pid}
11952@end smallexample
11953
11954@var{pid} is the process ID of a currently running process. It isn't necessary
11955to point @code{gdbserver} at a binary for the running process.
11956
b1fe9455
DJ
11957@pindex pidof
11958@cindex attach to a program by name
11959You can debug processes by name instead of process ID if your target has the
11960@code{pidof} utility:
11961
11962@smallexample
11963target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11964@end smallexample
11965
11966In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11967has multiple threads, most versions of @code{pidof} support the
11968@code{-s} option to only return the first process ID.
11969
07f31aa6
DJ
11970@item On the host machine,
11971connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11972For TCP connections, you must start up @code{gdbserver} prior to using
11973the @code{target remote} command. Otherwise you may get an error whose
11974text depends on the host system, but which usually looks something like
07f31aa6 11975@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11976command in @value{GDBN} when using @code{gdbserver}, since the program is
11977already on the target. However, if you want to load the symbols (as
11978you normally would), do that with the @code{file} command, and issue
11979it @emph{before} connecting to the server; otherwise, you will get an
11980error message saying @code{"Program is already running"}, since the
11981program is considered running after the connection.
07f31aa6 11982
6f05cf9f
AC
11983@end table
11984
11985@node NetWare
11986@section Using the @code{gdbserve.nlm} program
11987
11988@kindex gdbserve.nlm
11989@code{gdbserve.nlm} is a control program for NetWare systems, which
11990allows you to connect your program with a remote @value{GDBN} via
11991@code{target remote}.
11992
11993@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11994using the standard @value{GDBN} remote serial protocol.
11995
11996@table @emph
11997@item On the target machine,
11998you need to have a copy of the program you want to debug.
11999@code{gdbserve.nlm} does not need your program's symbol table, so you
12000can strip the program if necessary to save space. @value{GDBN} on the
12001host system does all the symbol handling.
12002
12003To use the server, you must tell it how to communicate with
12004@value{GDBN}; the name of your program; and the arguments for your
12005program. The syntax is:
12006
12007@smallexample
12008load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12009 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12010@end smallexample
12011
12012@var{board} and @var{port} specify the serial line; @var{baud} specifies
12013the baud rate used by the connection. @var{port} and @var{node} default
12014to 0, @var{baud} defaults to 9600@dmn{bps}.
12015
12016For example, to debug Emacs with the argument @samp{foo.txt}and
12017communicate with @value{GDBN} over serial port number 2 or board 1
12018using a 19200@dmn{bps} connection:
12019
12020@smallexample
12021load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12022@end smallexample
12023
07f31aa6
DJ
12024@item
12025On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12026Connecting to a remote target}).
6f05cf9f 12027
6f05cf9f
AC
12028@end table
12029
501eef12
AC
12030@node Remote configuration
12031@section Remote configuration
12032
9c16f35a
EZ
12033@kindex set remote
12034@kindex show remote
12035This section documents the configuration options available when
12036debugging remote programs. For the options related to the File I/O
12037extensions of the remote protocol, see @ref{The system call,
12038system-call-allowed}.
501eef12
AC
12039
12040@table @code
9c16f35a
EZ
12041@item set remoteaddresssize @var{bits}
12042@cindex adress size for remote targets
12043@cindex bits in remote address
12044Set the maximum size of address in a memory packet to the specified
12045number of bits. @value{GDBN} will mask off the address bits above
12046that number, when it passes addresses to the remote target. The
12047default value is the number of bits in the target's address.
12048
12049@item show remoteaddresssize
12050Show the current value of remote address size in bits.
12051
12052@item set remotebaud @var{n}
12053@cindex baud rate for remote targets
12054Set the baud rate for the remote serial I/O to @var{n} baud. The
12055value is used to set the speed of the serial port used for debugging
12056remote targets.
12057
12058@item show remotebaud
12059Show the current speed of the remote connection.
12060
12061@item set remotebreak
12062@cindex interrupt remote programs
12063@cindex BREAK signal instead of Ctrl-C
12064If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12065when you press the @key{Ctrl-C} key to interrupt the program running
12066on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12067character instead. The default is off, since most remote systems
12068expect to see @samp{Ctrl-C} as the interrupt signal.
12069
12070@item show remotebreak
12071Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12072interrupt the remote program.
12073
12074@item set remotedebug
12075@cindex debug remote protocol
12076@cindex remote protocol debugging
12077@cindex display remote packets
12078Control the debugging of the remote protocol. When enabled, each
12079packet sent to or received from the remote target is displayed. The
12080defaults is off.
12081
12082@item show remotedebug
12083Show the current setting of the remote protocol debugging.
12084
12085@item set remotedevice @var{device}
12086@cindex serial port name
12087Set the name of the serial port through which to communicate to the
12088remote target to @var{device}. This is the device used by
12089@value{GDBN} to open the serial communications line to the remote
12090target. There's no default, so you must set a valid port name for the
12091remote serial communications to work. (Some varieties of the
12092@code{target} command accept the port name as part of their
12093arguments.)
12094
12095@item show remotedevice
12096Show the current name of the serial port.
12097
12098@item set remotelogbase @var{base}
12099Set the base (a.k.a.@: radix) of logging serial protocol
12100communications to @var{base}. Supported values of @var{base} are:
12101@code{ascii}, @code{octal}, and @code{hex}. The default is
12102@code{ascii}.
12103
12104@item show remotelogbase
12105Show the current setting of the radix for logging remote serial
12106protocol.
12107
12108@item set remotelogfile @var{file}
12109@cindex record serial communications on file
12110Record remote serial communications on the named @var{file}. The
12111default is not to record at all.
12112
12113@item show remotelogfile.
12114Show the current setting of the file name on which to record the
12115serial communications.
12116
12117@item set remotetimeout @var{num}
12118@cindex timeout for serial communications
12119@cindex remote timeout
12120Set the timeout limit to wait for the remote target to respond to
12121@var{num} seconds. The default is 2 seconds.
12122
12123@item show remotetimeout
12124Show the current number of seconds to wait for the remote target
12125responses.
12126
12127@cindex limit hardware breakpoints and watchpoints
12128@cindex remote target, limit break- and watchpoints
501eef12
AC
12129@anchor{set remote hardware-watchpoint-limit}
12130@anchor{set remote hardware-breakpoint-limit}
12131@item set remote hardware-watchpoint-limit @var{limit}
12132@itemx set remote hardware-breakpoint-limit @var{limit}
12133Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12134watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12135
12136@item set remote fetch-register-packet
12137@itemx set remote set-register-packet
12138@itemx set remote P-packet
12139@itemx set remote p-packet
12140@cindex P-packet
12141@cindex fetch registers from remote targets
12142@cindex set registers in remote targets
12143Determine whether @value{GDBN} can set and fetch registers from the
12144remote target using the @samp{P} packets. The default depends on the
12145remote stub's support of the @samp{P} packets (@value{GDBN} queries
12146the stub when this packet is first required).
12147
12148@item show remote fetch-register-packet
12149@itemx show remote set-register-packet
12150@itemx show remote P-packet
12151@itemx show remote p-packet
12152Show the current setting of using the @samp{P} packets for setting and
12153fetching registers from the remote target.
12154
12155@cindex binary downloads
12156@cindex X-packet
12157@item set remote binary-download-packet
12158@itemx set remote X-packet
12159Determine whether @value{GDBN} sends downloads in binary mode using
12160the @samp{X} packets. The default is on.
12161
12162@item show remote binary-download-packet
12163@itemx show remote X-packet
12164Show the current setting of using the @samp{X} packets for binary
12165downloads.
12166
12167@item set remote read-aux-vector-packet
12168@cindex auxiliary vector of remote target
12169@cindex @code{auxv}, and remote targets
12170Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12171auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12172remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12173Auxiliary Vector}. The default setting depends on the remote stub's
12174support of this request (@value{GDBN} queries the stub when this
12175request is first required). @xref{General Query Packets, qPart}, for
12176more information about this request.
9c16f35a
EZ
12177
12178@item show remote read-aux-vector-packet
12179Show the current setting of use of the @samp{qPart:auxv:read} request.
12180
12181@item set remote symbol-lookup-packet
12182@cindex remote symbol lookup request
12183Set the use of the remote protocol's @samp{qSymbol} (target symbol
12184lookup) request. This request is used to communicate symbol
12185information to the remote target, e.g., whenever a new shared library
12186is loaded by the remote (@pxref{Files, shared libraries}). The
12187default setting depends on the remote stub's support of this request
12188(@value{GDBN} queries the stub when this request is first required).
12189@xref{General Query Packets, qSymbol}, for more information about this
12190request.
12191
12192@item show remote symbol-lookup-packet
12193Show the current setting of use of the @samp{qSymbol} request.
12194
12195@item set remote verbose-resume-packet
12196@cindex resume remote target
12197@cindex signal thread, and remote targets
12198@cindex single-step thread, and remote targets
12199@cindex thread-specific operations on remote targets
12200Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12201request. This request is used to resume specific threads in the
12202remote target, and to single-step or signal them. The default setting
12203depends on the remote stub's support of this request (@value{GDBN}
12204queries the stub when this request is first required). This setting
12205affects debugging of multithreaded programs: if @samp{vCont} cannot be
12206used, @value{GDBN} might be unable to single-step a specific thread,
12207especially under @code{set scheduler-locking off}; it is also
12208impossible to pause a specific thread. @xref{Packets, vCont}, for
12209more details.
12210
12211@item show remote verbose-resume-packet
12212Show the current setting of use of the @samp{vCont} request
12213
12214@item set remote software-breakpoint-packet
12215@itemx set remote hardware-breakpoint-packet
12216@itemx set remote write-watchpoint-packet
12217@itemx set remote read-watchpoint-packet
12218@itemx set remote access-watchpoint-packet
12219@itemx set remote Z-packet
12220@cindex Z-packet
12221@cindex remote hardware breakpoints and watchpoints
12222These commands enable or disable the use of @samp{Z} packets for
12223setting breakpoints and watchpoints in the remote target. The default
12224depends on the remote stub's support of the @samp{Z} packets
12225(@value{GDBN} queries the stub when each packet is first required).
12226The command @code{set remote Z-packet}, kept for back-compatibility,
12227turns on or off all the features that require the use of @samp{Z}
12228packets.
12229
12230@item show remote software-breakpoint-packet
12231@itemx show remote hardware-breakpoint-packet
12232@itemx show remote write-watchpoint-packet
12233@itemx show remote read-watchpoint-packet
12234@itemx show remote access-watchpoint-packet
12235@itemx show remote Z-packet
12236Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12237
12238@item set remote get-thread-local-storage-address
12239@kindex set remote get-thread-local-storage-address
12240@cindex thread local storage of remote targets
12241This command enables or disables the use of the @samp{qGetTLSAddr}
12242(Get Thread Local Storage Address) request packet. The default
12243depends on whether the remote stub supports this request.
12244@xref{General Query Packets, qGetTLSAddr}, for more details about this
12245packet.
12246
12247@item show remote get-thread-local-storage-address
12248@kindex show remote get-thread-local-storage-address
12249Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12250@end table
12251
6f05cf9f
AC
12252@node remote stub
12253@section Implementing a remote stub
7a292a7a 12254
8e04817f
AC
12255@cindex debugging stub, example
12256@cindex remote stub, example
12257@cindex stub example, remote debugging
12258The stub files provided with @value{GDBN} implement the target side of the
12259communication protocol, and the @value{GDBN} side is implemented in the
12260@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12261these subroutines to communicate, and ignore the details. (If you're
12262implementing your own stub file, you can still ignore the details: start
12263with one of the existing stub files. @file{sparc-stub.c} is the best
12264organized, and therefore the easiest to read.)
12265
104c1213
JM
12266@cindex remote serial debugging, overview
12267To debug a program running on another machine (the debugging
12268@dfn{target} machine), you must first arrange for all the usual
12269prerequisites for the program to run by itself. For example, for a C
12270program, you need:
c906108c 12271
104c1213
JM
12272@enumerate
12273@item
12274A startup routine to set up the C runtime environment; these usually
12275have a name like @file{crt0}. The startup routine may be supplied by
12276your hardware supplier, or you may have to write your own.
96baa820 12277
5d161b24 12278@item
d4f3574e 12279A C subroutine library to support your program's
104c1213 12280subroutine calls, notably managing input and output.
96baa820 12281
104c1213
JM
12282@item
12283A way of getting your program to the other machine---for example, a
12284download program. These are often supplied by the hardware
12285manufacturer, but you may have to write your own from hardware
12286documentation.
12287@end enumerate
96baa820 12288
104c1213
JM
12289The next step is to arrange for your program to use a serial port to
12290communicate with the machine where @value{GDBN} is running (the @dfn{host}
12291machine). In general terms, the scheme looks like this:
96baa820 12292
104c1213
JM
12293@table @emph
12294@item On the host,
12295@value{GDBN} already understands how to use this protocol; when everything
12296else is set up, you can simply use the @samp{target remote} command
12297(@pxref{Targets,,Specifying a Debugging Target}).
12298
12299@item On the target,
12300you must link with your program a few special-purpose subroutines that
12301implement the @value{GDBN} remote serial protocol. The file containing these
12302subroutines is called a @dfn{debugging stub}.
12303
12304On certain remote targets, you can use an auxiliary program
12305@code{gdbserver} instead of linking a stub into your program.
12306@xref{Server,,Using the @code{gdbserver} program}, for details.
12307@end table
96baa820 12308
104c1213
JM
12309The debugging stub is specific to the architecture of the remote
12310machine; for example, use @file{sparc-stub.c} to debug programs on
12311@sc{sparc} boards.
96baa820 12312
104c1213
JM
12313@cindex remote serial stub list
12314These working remote stubs are distributed with @value{GDBN}:
96baa820 12315
104c1213
JM
12316@table @code
12317
12318@item i386-stub.c
41afff9a 12319@cindex @file{i386-stub.c}
104c1213
JM
12320@cindex Intel
12321@cindex i386
12322For Intel 386 and compatible architectures.
12323
12324@item m68k-stub.c
41afff9a 12325@cindex @file{m68k-stub.c}
104c1213
JM
12326@cindex Motorola 680x0
12327@cindex m680x0
12328For Motorola 680x0 architectures.
12329
12330@item sh-stub.c
41afff9a 12331@cindex @file{sh-stub.c}
172c2a43 12332@cindex Renesas
104c1213 12333@cindex SH
172c2a43 12334For Renesas SH architectures.
104c1213
JM
12335
12336@item sparc-stub.c
41afff9a 12337@cindex @file{sparc-stub.c}
104c1213
JM
12338@cindex Sparc
12339For @sc{sparc} architectures.
12340
12341@item sparcl-stub.c
41afff9a 12342@cindex @file{sparcl-stub.c}
104c1213
JM
12343@cindex Fujitsu
12344@cindex SparcLite
12345For Fujitsu @sc{sparclite} architectures.
12346
12347@end table
12348
12349The @file{README} file in the @value{GDBN} distribution may list other
12350recently added stubs.
12351
12352@menu
12353* Stub Contents:: What the stub can do for you
12354* Bootstrapping:: What you must do for the stub
12355* Debug Session:: Putting it all together
104c1213
JM
12356@end menu
12357
6d2ebf8b 12358@node Stub Contents
6f05cf9f 12359@subsection What the stub can do for you
104c1213
JM
12360
12361@cindex remote serial stub
12362The debugging stub for your architecture supplies these three
12363subroutines:
12364
12365@table @code
12366@item set_debug_traps
4644b6e3 12367@findex set_debug_traps
104c1213
JM
12368@cindex remote serial stub, initialization
12369This routine arranges for @code{handle_exception} to run when your
12370program stops. You must call this subroutine explicitly near the
12371beginning of your program.
12372
12373@item handle_exception
4644b6e3 12374@findex handle_exception
104c1213
JM
12375@cindex remote serial stub, main routine
12376This is the central workhorse, but your program never calls it
12377explicitly---the setup code arranges for @code{handle_exception} to
12378run when a trap is triggered.
12379
12380@code{handle_exception} takes control when your program stops during
12381execution (for example, on a breakpoint), and mediates communications
12382with @value{GDBN} on the host machine. This is where the communications
12383protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12384representative on the target machine. It begins by sending summary
104c1213
JM
12385information on the state of your program, then continues to execute,
12386retrieving and transmitting any information @value{GDBN} needs, until you
12387execute a @value{GDBN} command that makes your program resume; at that point,
12388@code{handle_exception} returns control to your own code on the target
5d161b24 12389machine.
104c1213
JM
12390
12391@item breakpoint
12392@cindex @code{breakpoint} subroutine, remote
12393Use this auxiliary subroutine to make your program contain a
12394breakpoint. Depending on the particular situation, this may be the only
12395way for @value{GDBN} to get control. For instance, if your target
12396machine has some sort of interrupt button, you won't need to call this;
12397pressing the interrupt button transfers control to
12398@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12399simply receiving characters on the serial port may also trigger a trap;
12400again, in that situation, you don't need to call @code{breakpoint} from
12401your own program---simply running @samp{target remote} from the host
5d161b24 12402@value{GDBN} session gets control.
104c1213
JM
12403
12404Call @code{breakpoint} if none of these is true, or if you simply want
12405to make certain your program stops at a predetermined point for the
12406start of your debugging session.
12407@end table
12408
6d2ebf8b 12409@node Bootstrapping
6f05cf9f 12410@subsection What you must do for the stub
104c1213
JM
12411
12412@cindex remote stub, support routines
12413The debugging stubs that come with @value{GDBN} are set up for a particular
12414chip architecture, but they have no information about the rest of your
12415debugging target machine.
12416
12417First of all you need to tell the stub how to communicate with the
12418serial port.
12419
12420@table @code
12421@item int getDebugChar()
4644b6e3 12422@findex getDebugChar
104c1213
JM
12423Write this subroutine to read a single character from the serial port.
12424It may be identical to @code{getchar} for your target system; a
12425different name is used to allow you to distinguish the two if you wish.
12426
12427@item void putDebugChar(int)
4644b6e3 12428@findex putDebugChar
104c1213 12429Write this subroutine to write a single character to the serial port.
5d161b24 12430It may be identical to @code{putchar} for your target system; a
104c1213
JM
12431different name is used to allow you to distinguish the two if you wish.
12432@end table
12433
12434@cindex control C, and remote debugging
12435@cindex interrupting remote targets
12436If you want @value{GDBN} to be able to stop your program while it is
12437running, you need to use an interrupt-driven serial driver, and arrange
12438for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12439character). That is the character which @value{GDBN} uses to tell the
12440remote system to stop.
12441
12442Getting the debugging target to return the proper status to @value{GDBN}
12443probably requires changes to the standard stub; one quick and dirty way
12444is to just execute a breakpoint instruction (the ``dirty'' part is that
12445@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12446
12447Other routines you need to supply are:
12448
12449@table @code
12450@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12451@findex exceptionHandler
104c1213
JM
12452Write this function to install @var{exception_address} in the exception
12453handling tables. You need to do this because the stub does not have any
12454way of knowing what the exception handling tables on your target system
12455are like (for example, the processor's table might be in @sc{rom},
12456containing entries which point to a table in @sc{ram}).
12457@var{exception_number} is the exception number which should be changed;
12458its meaning is architecture-dependent (for example, different numbers
12459might represent divide by zero, misaligned access, etc). When this
12460exception occurs, control should be transferred directly to
12461@var{exception_address}, and the processor state (stack, registers,
12462and so on) should be just as it is when a processor exception occurs. So if
12463you want to use a jump instruction to reach @var{exception_address}, it
12464should be a simple jump, not a jump to subroutine.
12465
12466For the 386, @var{exception_address} should be installed as an interrupt
12467gate so that interrupts are masked while the handler runs. The gate
12468should be at privilege level 0 (the most privileged level). The
12469@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12470help from @code{exceptionHandler}.
12471
12472@item void flush_i_cache()
4644b6e3 12473@findex flush_i_cache
d4f3574e 12474On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12475instruction cache, if any, on your target machine. If there is no
12476instruction cache, this subroutine may be a no-op.
12477
12478On target machines that have instruction caches, @value{GDBN} requires this
12479function to make certain that the state of your program is stable.
12480@end table
12481
12482@noindent
12483You must also make sure this library routine is available:
12484
12485@table @code
12486@item void *memset(void *, int, int)
4644b6e3 12487@findex memset
104c1213
JM
12488This is the standard library function @code{memset} that sets an area of
12489memory to a known value. If you have one of the free versions of
12490@code{libc.a}, @code{memset} can be found there; otherwise, you must
12491either obtain it from your hardware manufacturer, or write your own.
12492@end table
12493
12494If you do not use the GNU C compiler, you may need other standard
12495library subroutines as well; this varies from one stub to another,
12496but in general the stubs are likely to use any of the common library
d4f3574e 12497subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12498
12499
6d2ebf8b 12500@node Debug Session
6f05cf9f 12501@subsection Putting it all together
104c1213
JM
12502
12503@cindex remote serial debugging summary
12504In summary, when your program is ready to debug, you must follow these
12505steps.
12506
12507@enumerate
12508@item
6d2ebf8b 12509Make sure you have defined the supporting low-level routines
104c1213
JM
12510(@pxref{Bootstrapping,,What you must do for the stub}):
12511@display
12512@code{getDebugChar}, @code{putDebugChar},
12513@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12514@end display
12515
12516@item
12517Insert these lines near the top of your program:
12518
474c8240 12519@smallexample
104c1213
JM
12520set_debug_traps();
12521breakpoint();
474c8240 12522@end smallexample
104c1213
JM
12523
12524@item
12525For the 680x0 stub only, you need to provide a variable called
12526@code{exceptionHook}. Normally you just use:
12527
474c8240 12528@smallexample
104c1213 12529void (*exceptionHook)() = 0;
474c8240 12530@end smallexample
104c1213 12531
d4f3574e 12532@noindent
104c1213 12533but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12534function in your program, that function is called when
104c1213
JM
12535@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12536error). The function indicated by @code{exceptionHook} is called with
12537one parameter: an @code{int} which is the exception number.
12538
12539@item
12540Compile and link together: your program, the @value{GDBN} debugging stub for
12541your target architecture, and the supporting subroutines.
12542
12543@item
12544Make sure you have a serial connection between your target machine and
12545the @value{GDBN} host, and identify the serial port on the host.
12546
12547@item
12548@c The "remote" target now provides a `load' command, so we should
12549@c document that. FIXME.
12550Download your program to your target machine (or get it there by
12551whatever means the manufacturer provides), and start it.
12552
12553@item
07f31aa6
DJ
12554Start @value{GDBN} on the host, and connect to the target
12555(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12556
104c1213
JM
12557@end enumerate
12558
8e04817f
AC
12559@node Configurations
12560@chapter Configuration-Specific Information
104c1213 12561
8e04817f
AC
12562While nearly all @value{GDBN} commands are available for all native and
12563cross versions of the debugger, there are some exceptions. This chapter
12564describes things that are only available in certain configurations.
104c1213 12565
8e04817f
AC
12566There are three major categories of configurations: native
12567configurations, where the host and target are the same, embedded
12568operating system configurations, which are usually the same for several
12569different processor architectures, and bare embedded processors, which
12570are quite different from each other.
104c1213 12571
8e04817f
AC
12572@menu
12573* Native::
12574* Embedded OS::
12575* Embedded Processors::
12576* Architectures::
12577@end menu
104c1213 12578
8e04817f
AC
12579@node Native
12580@section Native
104c1213 12581
8e04817f
AC
12582This section describes details specific to particular native
12583configurations.
6cf7e474 12584
8e04817f
AC
12585@menu
12586* HP-UX:: HP-UX
7561d450 12587* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12588* SVR4 Process Information:: SVR4 process information
12589* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12590* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12591* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12592* Neutrino:: Features specific to QNX Neutrino
8e04817f 12593@end menu
6cf7e474 12594
8e04817f
AC
12595@node HP-UX
12596@subsection HP-UX
104c1213 12597
8e04817f
AC
12598On HP-UX systems, if you refer to a function or variable name that
12599begins with a dollar sign, @value{GDBN} searches for a user or system
12600name first, before it searches for a convenience variable.
104c1213 12601
9c16f35a 12602
7561d450
MK
12603@node BSD libkvm Interface
12604@subsection BSD libkvm Interface
12605
12606@cindex libkvm
12607@cindex kernel memory image
12608@cindex kernel crash dump
12609
12610BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12611interface that provides a uniform interface for accessing kernel virtual
12612memory images, including live systems and crash dumps. @value{GDBN}
12613uses this interface to allow you to debug live kernels and kernel crash
12614dumps on many native BSD configurations. This is implemented as a
12615special @code{kvm} debugging target. For debugging a live system, load
12616the currently running kernel into @value{GDBN} and connect to the
12617@code{kvm} target:
12618
12619@smallexample
12620(@value{GDBP}) @b{target kvm}
12621@end smallexample
12622
12623For debugging crash dumps, provide the file name of the crash dump as an
12624argument:
12625
12626@smallexample
12627(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12628@end smallexample
12629
12630Once connected to the @code{kvm} target, the following commands are
12631available:
12632
12633@table @code
12634@kindex kvm
12635@item kvm pcb
721c2651 12636Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12637
12638@item kvm proc
12639Set current context from proc address. This command isn't available on
12640modern FreeBSD systems.
12641@end table
12642
8e04817f
AC
12643@node SVR4 Process Information
12644@subsection SVR4 process information
60bf7e09
EZ
12645@cindex /proc
12646@cindex examine process image
12647@cindex process info via @file{/proc}
104c1213 12648
60bf7e09
EZ
12649Many versions of SVR4 and compatible systems provide a facility called
12650@samp{/proc} that can be used to examine the image of a running
12651process using file-system subroutines. If @value{GDBN} is configured
12652for an operating system with this facility, the command @code{info
12653proc} is available to report information about the process running
12654your program, or about any process running on your system. @code{info
12655proc} works only on SVR4 systems that include the @code{procfs} code.
12656This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12657Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12658
8e04817f
AC
12659@table @code
12660@kindex info proc
60bf7e09 12661@cindex process ID
8e04817f 12662@item info proc
60bf7e09
EZ
12663@itemx info proc @var{process-id}
12664Summarize available information about any running process. If a
12665process ID is specified by @var{process-id}, display information about
12666that process; otherwise display information about the program being
12667debugged. The summary includes the debugged process ID, the command
12668line used to invoke it, its current working directory, and its
12669executable file's absolute file name.
12670
12671On some systems, @var{process-id} can be of the form
12672@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12673within a process. If the optional @var{pid} part is missing, it means
12674a thread from the process being debugged (the leading @samp{/} still
12675needs to be present, or else @value{GDBN} will interpret the number as
12676a process ID rather than a thread ID).
6cf7e474 12677
8e04817f 12678@item info proc mappings
60bf7e09
EZ
12679@cindex memory address space mappings
12680Report the memory address space ranges accessible in the program, with
12681information on whether the process has read, write, or execute access
12682rights to each range. On @sc{gnu}/Linux systems, each memory range
12683includes the object file which is mapped to that range, instead of the
12684memory access rights to that range.
12685
12686@item info proc stat
12687@itemx info proc status
12688@cindex process detailed status information
12689These subcommands are specific to @sc{gnu}/Linux systems. They show
12690the process-related information, including the user ID and group ID;
12691how many threads are there in the process; its virtual memory usage;
12692the signals that are pending, blocked, and ignored; its TTY; its
12693consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12694value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12695(type @kbd{man 5 proc} from your shell prompt).
12696
12697@item info proc all
12698Show all the information about the process described under all of the
12699above @code{info proc} subcommands.
12700
8e04817f
AC
12701@ignore
12702@comment These sub-options of 'info proc' were not included when
12703@comment procfs.c was re-written. Keep their descriptions around
12704@comment against the day when someone finds the time to put them back in.
12705@kindex info proc times
12706@item info proc times
12707Starting time, user CPU time, and system CPU time for your program and
12708its children.
6cf7e474 12709
8e04817f
AC
12710@kindex info proc id
12711@item info proc id
12712Report on the process IDs related to your program: its own process ID,
12713the ID of its parent, the process group ID, and the session ID.
8e04817f 12714@end ignore
721c2651
EZ
12715
12716@item set procfs-trace
12717@kindex set procfs-trace
12718@cindex @code{procfs} API calls
12719This command enables and disables tracing of @code{procfs} API calls.
12720
12721@item show procfs-trace
12722@kindex show procfs-trace
12723Show the current state of @code{procfs} API call tracing.
12724
12725@item set procfs-file @var{file}
12726@kindex set procfs-file
12727Tell @value{GDBN} to write @code{procfs} API trace to the named
12728@var{file}. @value{GDBN} appends the trace info to the previous
12729contents of the file. The default is to display the trace on the
12730standard output.
12731
12732@item show procfs-file
12733@kindex show procfs-file
12734Show the file to which @code{procfs} API trace is written.
12735
12736@item proc-trace-entry
12737@itemx proc-trace-exit
12738@itemx proc-untrace-entry
12739@itemx proc-untrace-exit
12740@kindex proc-trace-entry
12741@kindex proc-trace-exit
12742@kindex proc-untrace-entry
12743@kindex proc-untrace-exit
12744These commands enable and disable tracing of entries into and exits
12745from the @code{syscall} interface.
12746
12747@item info pidlist
12748@kindex info pidlist
12749@cindex process list, QNX Neutrino
12750For QNX Neutrino only, this command displays the list of all the
12751processes and all the threads within each process.
12752
12753@item info meminfo
12754@kindex info meminfo
12755@cindex mapinfo list, QNX Neutrino
12756For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12757@end table
104c1213 12758
8e04817f
AC
12759@node DJGPP Native
12760@subsection Features for Debugging @sc{djgpp} Programs
12761@cindex @sc{djgpp} debugging
12762@cindex native @sc{djgpp} debugging
12763@cindex MS-DOS-specific commands
104c1213 12764
514c4d71
EZ
12765@cindex DPMI
12766@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12767MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12768that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12769top of real-mode DOS systems and their emulations.
104c1213 12770
8e04817f
AC
12771@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12772defines a few commands specific to the @sc{djgpp} port. This
12773subsection describes those commands.
104c1213 12774
8e04817f
AC
12775@table @code
12776@kindex info dos
12777@item info dos
12778This is a prefix of @sc{djgpp}-specific commands which print
12779information about the target system and important OS structures.
f1251bdd 12780
8e04817f
AC
12781@kindex sysinfo
12782@cindex MS-DOS system info
12783@cindex free memory information (MS-DOS)
12784@item info dos sysinfo
12785This command displays assorted information about the underlying
12786platform: the CPU type and features, the OS version and flavor, the
12787DPMI version, and the available conventional and DPMI memory.
104c1213 12788
8e04817f
AC
12789@cindex GDT
12790@cindex LDT
12791@cindex IDT
12792@cindex segment descriptor tables
12793@cindex descriptor tables display
12794@item info dos gdt
12795@itemx info dos ldt
12796@itemx info dos idt
12797These 3 commands display entries from, respectively, Global, Local,
12798and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12799tables are data structures which store a descriptor for each segment
12800that is currently in use. The segment's selector is an index into a
12801descriptor table; the table entry for that index holds the
12802descriptor's base address and limit, and its attributes and access
12803rights.
104c1213 12804
8e04817f
AC
12805A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12806segment (used for both data and the stack), and a DOS segment (which
12807allows access to DOS/BIOS data structures and absolute addresses in
12808conventional memory). However, the DPMI host will usually define
12809additional segments in order to support the DPMI environment.
d4f3574e 12810
8e04817f
AC
12811@cindex garbled pointers
12812These commands allow to display entries from the descriptor tables.
12813Without an argument, all entries from the specified table are
12814displayed. An argument, which should be an integer expression, means
12815display a single entry whose index is given by the argument. For
12816example, here's a convenient way to display information about the
12817debugged program's data segment:
104c1213 12818
8e04817f
AC
12819@smallexample
12820@exdent @code{(@value{GDBP}) info dos ldt $ds}
12821@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12822@end smallexample
104c1213 12823
8e04817f
AC
12824@noindent
12825This comes in handy when you want to see whether a pointer is outside
12826the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12827
8e04817f
AC
12828@cindex page tables display (MS-DOS)
12829@item info dos pde
12830@itemx info dos pte
12831These two commands display entries from, respectively, the Page
12832Directory and the Page Tables. Page Directories and Page Tables are
12833data structures which control how virtual memory addresses are mapped
12834into physical addresses. A Page Table includes an entry for every
12835page of memory that is mapped into the program's address space; there
12836may be several Page Tables, each one holding up to 4096 entries. A
12837Page Directory has up to 4096 entries, one each for every Page Table
12838that is currently in use.
104c1213 12839
8e04817f
AC
12840Without an argument, @kbd{info dos pde} displays the entire Page
12841Directory, and @kbd{info dos pte} displays all the entries in all of
12842the Page Tables. An argument, an integer expression, given to the
12843@kbd{info dos pde} command means display only that entry from the Page
12844Directory table. An argument given to the @kbd{info dos pte} command
12845means display entries from a single Page Table, the one pointed to by
12846the specified entry in the Page Directory.
104c1213 12847
8e04817f
AC
12848@cindex direct memory access (DMA) on MS-DOS
12849These commands are useful when your program uses @dfn{DMA} (Direct
12850Memory Access), which needs physical addresses to program the DMA
12851controller.
104c1213 12852
8e04817f 12853These commands are supported only with some DPMI servers.
104c1213 12854
8e04817f
AC
12855@cindex physical address from linear address
12856@item info dos address-pte @var{addr}
12857This command displays the Page Table entry for a specified linear
514c4d71
EZ
12858address. The argument @var{addr} is a linear address which should
12859already have the appropriate segment's base address added to it,
12860because this command accepts addresses which may belong to @emph{any}
12861segment. For example, here's how to display the Page Table entry for
12862the page where a variable @code{i} is stored:
104c1213 12863
b383017d 12864@smallexample
8e04817f
AC
12865@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12866@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12867@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12868@end smallexample
104c1213 12869
8e04817f
AC
12870@noindent
12871This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12872whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12873attributes of that page.
104c1213 12874
8e04817f
AC
12875Note that you must cast the addresses of variables to a @code{char *},
12876since otherwise the value of @code{__djgpp_base_address}, the base
12877address of all variables and functions in a @sc{djgpp} program, will
12878be added using the rules of C pointer arithmetics: if @code{i} is
12879declared an @code{int}, @value{GDBN} will add 4 times the value of
12880@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12881
8e04817f
AC
12882Here's another example, it displays the Page Table entry for the
12883transfer buffer:
104c1213 12884
8e04817f
AC
12885@smallexample
12886@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12887@exdent @code{Page Table entry for address 0x29110:}
12888@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12889@end smallexample
104c1213 12890
8e04817f
AC
12891@noindent
12892(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128933rd member of the @code{_go32_info_block} structure.) The output
12894clearly shows that this DPMI server maps the addresses in conventional
12895memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12896linear (@code{0x29110}) addresses are identical.
104c1213 12897
8e04817f
AC
12898This command is supported only with some DPMI servers.
12899@end table
104c1213 12900
c45da7e6 12901@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12902In addition to native debugging, the DJGPP port supports remote
12903debugging via a serial data link. The following commands are specific
12904to remote serial debugging in the DJGPP port of @value{GDBN}.
12905
12906@table @code
12907@kindex set com1base
12908@kindex set com1irq
12909@kindex set com2base
12910@kindex set com2irq
12911@kindex set com3base
12912@kindex set com3irq
12913@kindex set com4base
12914@kindex set com4irq
12915@item set com1base @var{addr}
12916This command sets the base I/O port address of the @file{COM1} serial
12917port.
12918
12919@item set com1irq @var{irq}
12920This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12921for the @file{COM1} serial port.
12922
12923There are similar commands @samp{set com2base}, @samp{set com3irq},
12924etc.@: for setting the port address and the @code{IRQ} lines for the
12925other 3 COM ports.
12926
12927@kindex show com1base
12928@kindex show com1irq
12929@kindex show com2base
12930@kindex show com2irq
12931@kindex show com3base
12932@kindex show com3irq
12933@kindex show com4base
12934@kindex show com4irq
12935The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12936display the current settings of the base address and the @code{IRQ}
12937lines used by the COM ports.
c45da7e6
EZ
12938
12939@item info serial
12940@kindex info serial
12941@cindex DOS serial port status
12942This command prints the status of the 4 DOS serial ports. For each
12943port, it prints whether it's active or not, its I/O base address and
12944IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12945counts of various errors encountered so far.
a8f24a35
EZ
12946@end table
12947
12948
78c47bea
PM
12949@node Cygwin Native
12950@subsection Features for Debugging MS Windows PE executables
12951@cindex MS Windows debugging
12952@cindex native Cygwin debugging
12953@cindex Cygwin-specific commands
12954
be448670
CF
12955@value{GDBN} supports native debugging of MS Windows programs, including
12956DLLs with and without symbolic debugging information. There are various
12957additional Cygwin-specific commands, described in this subsection. The
12958subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12959that have no debugging symbols.
12960
78c47bea
PM
12961
12962@table @code
12963@kindex info w32
12964@item info w32
12965This is a prefix of MS Windows specific commands which print
12966information about the target system and important OS structures.
12967
12968@item info w32 selector
12969This command displays information returned by
12970the Win32 API @code{GetThreadSelectorEntry} function.
12971It takes an optional argument that is evaluated to
12972a long value to give the information about this given selector.
12973Without argument, this command displays information
12974about the the six segment registers.
12975
12976@kindex info dll
12977@item info dll
12978This is a Cygwin specific alias of info shared.
12979
12980@kindex dll-symbols
12981@item dll-symbols
12982This command loads symbols from a dll similarly to
12983add-sym command but without the need to specify a base address.
12984
b383017d 12985@kindex set new-console
78c47bea 12986@item set new-console @var{mode}
b383017d 12987If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12988be started in a new console on next start.
12989If @var{mode} is @code{off}i, the debuggee will
12990be started in the same console as the debugger.
12991
12992@kindex show new-console
12993@item show new-console
12994Displays whether a new console is used
12995when the debuggee is started.
12996
12997@kindex set new-group
12998@item set new-group @var{mode}
12999This boolean value controls whether the debuggee should
13000start a new group or stay in the same group as the debugger.
13001This affects the way the Windows OS handles
13002Ctrl-C.
13003
13004@kindex show new-group
13005@item show new-group
13006Displays current value of new-group boolean.
13007
13008@kindex set debugevents
13009@item set debugevents
13010This boolean value adds debug output concerning events seen by the debugger.
13011
13012@kindex set debugexec
13013@item set debugexec
b383017d 13014This boolean value adds debug output concerning execute events
78c47bea
PM
13015seen by the debugger.
13016
13017@kindex set debugexceptions
13018@item set debugexceptions
b383017d 13019This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13020seen by the debugger.
13021
13022@kindex set debugmemory
13023@item set debugmemory
b383017d 13024This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13025seen by the debugger.
13026
13027@kindex set shell
13028@item set shell
13029This boolean values specifies whether the debuggee is called
13030via a shell or directly (default value is on).
13031
13032@kindex show shell
13033@item show shell
13034Displays if the debuggee will be started with a shell.
13035
13036@end table
13037
be448670
CF
13038@menu
13039* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13040@end menu
13041
13042@node Non-debug DLL symbols
13043@subsubsection Support for DLLs without debugging symbols
13044@cindex DLLs with no debugging symbols
13045@cindex Minimal symbols and DLLs
13046
13047Very often on windows, some of the DLLs that your program relies on do
13048not include symbolic debugging information (for example,
13049@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13050symbols in a DLL, it relies on the minimal amount of symbolic
13051information contained in the DLL's export table. This subsubsection
13052describes working with such symbols, known internally to @value{GDBN} as
13053``minimal symbols''.
13054
13055Note that before the debugged program has started execution, no DLLs
13056will have been loaded. The easiest way around this problem is simply to
13057start the program --- either by setting a breakpoint or letting the
13058program run once to completion. It is also possible to force
13059@value{GDBN} to load a particular DLL before starting the executable ---
13060see the shared library information in @pxref{Files} or the
13061@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13062explicitly loading symbols from a DLL with no debugging information will
13063cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13064which may adversely affect symbol lookup performance.
13065
13066@subsubsection DLL name prefixes
13067
13068In keeping with the naming conventions used by the Microsoft debugging
13069tools, DLL export symbols are made available with a prefix based on the
13070DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13071also entered into the symbol table, so @code{CreateFileA} is often
13072sufficient. In some cases there will be name clashes within a program
13073(particularly if the executable itself includes full debugging symbols)
13074necessitating the use of the fully qualified name when referring to the
13075contents of the DLL. Use single-quotes around the name to avoid the
13076exclamation mark (``!'') being interpreted as a language operator.
13077
13078Note that the internal name of the DLL may be all upper-case, even
13079though the file name of the DLL is lower-case, or vice-versa. Since
13080symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13081some confusion. If in doubt, try the @code{info functions} and
13082@code{info variables} commands or even @code{maint print msymbols} (see
13083@pxref{Symbols}). Here's an example:
13084
13085@smallexample
f7dc1244 13086(@value{GDBP}) info function CreateFileA
be448670
CF
13087All functions matching regular expression "CreateFileA":
13088
13089Non-debugging symbols:
130900x77e885f4 CreateFileA
130910x77e885f4 KERNEL32!CreateFileA
13092@end smallexample
13093
13094@smallexample
f7dc1244 13095(@value{GDBP}) info function !
be448670
CF
13096All functions matching regular expression "!":
13097
13098Non-debugging symbols:
130990x6100114c cygwin1!__assert
131000x61004034 cygwin1!_dll_crt0@@0
131010x61004240 cygwin1!dll_crt0(per_process *)
13102[etc...]
13103@end smallexample
13104
13105@subsubsection Working with minimal symbols
13106
13107Symbols extracted from a DLL's export table do not contain very much
13108type information. All that @value{GDBN} can do is guess whether a symbol
13109refers to a function or variable depending on the linker section that
13110contains the symbol. Also note that the actual contents of the memory
13111contained in a DLL are not available unless the program is running. This
13112means that you cannot examine the contents of a variable or disassemble
13113a function within a DLL without a running program.
13114
13115Variables are generally treated as pointers and dereferenced
13116automatically. For this reason, it is often necessary to prefix a
13117variable name with the address-of operator (``&'') and provide explicit
13118type information in the command. Here's an example of the type of
13119problem:
13120
13121@smallexample
f7dc1244 13122(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13123$1 = 268572168
13124@end smallexample
13125
13126@smallexample
f7dc1244 13127(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131280x10021610: "\230y\""
13129@end smallexample
13130
13131And two possible solutions:
13132
13133@smallexample
f7dc1244 13134(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13135$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13136@end smallexample
13137
13138@smallexample
f7dc1244 13139(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131400x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13141(@value{GDBP}) x/x 0x10021608
be448670 131420x10021608: 0x0022fd98
f7dc1244 13143(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131440x22fd98: "/cygdrive/c/mydirectory/myprogram"
13145@end smallexample
13146
13147Setting a break point within a DLL is possible even before the program
13148starts execution. However, under these circumstances, @value{GDBN} can't
13149examine the initial instructions of the function in order to skip the
13150function's frame set-up code. You can work around this by using ``*&''
13151to set the breakpoint at a raw memory address:
13152
13153@smallexample
f7dc1244 13154(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13155Breakpoint 1 at 0x1e04eff0
13156@end smallexample
13157
13158The author of these extensions is not entirely convinced that setting a
13159break point within a shared DLL like @file{kernel32.dll} is completely
13160safe.
13161
14d6dd68
EZ
13162@node Hurd Native
13163@subsection Commands specific to @sc{gnu} Hurd systems
13164@cindex @sc{gnu} Hurd debugging
13165
13166This subsection describes @value{GDBN} commands specific to the
13167@sc{gnu} Hurd native debugging.
13168
13169@table @code
13170@item set signals
13171@itemx set sigs
13172@kindex set signals@r{, Hurd command}
13173@kindex set sigs@r{, Hurd command}
13174This command toggles the state of inferior signal interception by
13175@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13176affected by this command. @code{sigs} is a shorthand alias for
13177@code{signals}.
13178
13179@item show signals
13180@itemx show sigs
13181@kindex show signals@r{, Hurd command}
13182@kindex show sigs@r{, Hurd command}
13183Show the current state of intercepting inferior's signals.
13184
13185@item set signal-thread
13186@itemx set sigthread
13187@kindex set signal-thread
13188@kindex set sigthread
13189This command tells @value{GDBN} which thread is the @code{libc} signal
13190thread. That thread is run when a signal is delivered to a running
13191process. @code{set sigthread} is the shorthand alias of @code{set
13192signal-thread}.
13193
13194@item show signal-thread
13195@itemx show sigthread
13196@kindex show signal-thread
13197@kindex show sigthread
13198These two commands show which thread will run when the inferior is
13199delivered a signal.
13200
13201@item set stopped
13202@kindex set stopped@r{, Hurd command}
13203This commands tells @value{GDBN} that the inferior process is stopped,
13204as with the @code{SIGSTOP} signal. The stopped process can be
13205continued by delivering a signal to it.
13206
13207@item show stopped
13208@kindex show stopped@r{, Hurd command}
13209This command shows whether @value{GDBN} thinks the debuggee is
13210stopped.
13211
13212@item set exceptions
13213@kindex set exceptions@r{, Hurd command}
13214Use this command to turn off trapping of exceptions in the inferior.
13215When exception trapping is off, neither breakpoints nor
13216single-stepping will work. To restore the default, set exception
13217trapping on.
13218
13219@item show exceptions
13220@kindex show exceptions@r{, Hurd command}
13221Show the current state of trapping exceptions in the inferior.
13222
13223@item set task pause
13224@kindex set task@r{, Hurd commands}
13225@cindex task attributes (@sc{gnu} Hurd)
13226@cindex pause current task (@sc{gnu} Hurd)
13227This command toggles task suspension when @value{GDBN} has control.
13228Setting it to on takes effect immediately, and the task is suspended
13229whenever @value{GDBN} gets control. Setting it to off will take
13230effect the next time the inferior is continued. If this option is set
13231to off, you can use @code{set thread default pause on} or @code{set
13232thread pause on} (see below) to pause individual threads.
13233
13234@item show task pause
13235@kindex show task@r{, Hurd commands}
13236Show the current state of task suspension.
13237
13238@item set task detach-suspend-count
13239@cindex task suspend count
13240@cindex detach from task, @sc{gnu} Hurd
13241This command sets the suspend count the task will be left with when
13242@value{GDBN} detaches from it.
13243
13244@item show task detach-suspend-count
13245Show the suspend count the task will be left with when detaching.
13246
13247@item set task exception-port
13248@itemx set task excp
13249@cindex task exception port, @sc{gnu} Hurd
13250This command sets the task exception port to which @value{GDBN} will
13251forward exceptions. The argument should be the value of the @dfn{send
13252rights} of the task. @code{set task excp} is a shorthand alias.
13253
13254@item set noninvasive
13255@cindex noninvasive task options
13256This command switches @value{GDBN} to a mode that is the least
13257invasive as far as interfering with the inferior is concerned. This
13258is the same as using @code{set task pause}, @code{set exceptions}, and
13259@code{set signals} to values opposite to the defaults.
13260
13261@item info send-rights
13262@itemx info receive-rights
13263@itemx info port-rights
13264@itemx info port-sets
13265@itemx info dead-names
13266@itemx info ports
13267@itemx info psets
13268@cindex send rights, @sc{gnu} Hurd
13269@cindex receive rights, @sc{gnu} Hurd
13270@cindex port rights, @sc{gnu} Hurd
13271@cindex port sets, @sc{gnu} Hurd
13272@cindex dead names, @sc{gnu} Hurd
13273These commands display information about, respectively, send rights,
13274receive rights, port rights, port sets, and dead names of a task.
13275There are also shorthand aliases: @code{info ports} for @code{info
13276port-rights} and @code{info psets} for @code{info port-sets}.
13277
13278@item set thread pause
13279@kindex set thread@r{, Hurd command}
13280@cindex thread properties, @sc{gnu} Hurd
13281@cindex pause current thread (@sc{gnu} Hurd)
13282This command toggles current thread suspension when @value{GDBN} has
13283control. Setting it to on takes effect immediately, and the current
13284thread is suspended whenever @value{GDBN} gets control. Setting it to
13285off will take effect the next time the inferior is continued.
13286Normally, this command has no effect, since when @value{GDBN} has
13287control, the whole task is suspended. However, if you used @code{set
13288task pause off} (see above), this command comes in handy to suspend
13289only the current thread.
13290
13291@item show thread pause
13292@kindex show thread@r{, Hurd command}
13293This command shows the state of current thread suspension.
13294
13295@item set thread run
13296This comamnd sets whether the current thread is allowed to run.
13297
13298@item show thread run
13299Show whether the current thread is allowed to run.
13300
13301@item set thread detach-suspend-count
13302@cindex thread suspend count, @sc{gnu} Hurd
13303@cindex detach from thread, @sc{gnu} Hurd
13304This command sets the suspend count @value{GDBN} will leave on a
13305thread when detaching. This number is relative to the suspend count
13306found by @value{GDBN} when it notices the thread; use @code{set thread
13307takeover-suspend-count} to force it to an absolute value.
13308
13309@item show thread detach-suspend-count
13310Show the suspend count @value{GDBN} will leave on the thread when
13311detaching.
13312
13313@item set thread exception-port
13314@itemx set thread excp
13315Set the thread exception port to which to forward exceptions. This
13316overrides the port set by @code{set task exception-port} (see above).
13317@code{set thread excp} is the shorthand alias.
13318
13319@item set thread takeover-suspend-count
13320Normally, @value{GDBN}'s thread suspend counts are relative to the
13321value @value{GDBN} finds when it notices each thread. This command
13322changes the suspend counts to be absolute instead.
13323
13324@item set thread default
13325@itemx show thread default
13326@cindex thread default settings, @sc{gnu} Hurd
13327Each of the above @code{set thread} commands has a @code{set thread
13328default} counterpart (e.g., @code{set thread default pause}, @code{set
13329thread default exception-port}, etc.). The @code{thread default}
13330variety of commands sets the default thread properties for all
13331threads; you can then change the properties of individual threads with
13332the non-default commands.
13333@end table
13334
13335
a64548ea
EZ
13336@node Neutrino
13337@subsection QNX Neutrino
13338@cindex QNX Neutrino
13339
13340@value{GDBN} provides the following commands specific to the QNX
13341Neutrino target:
13342
13343@table @code
13344@item set debug nto-debug
13345@kindex set debug nto-debug
13346When set to on, enables debugging messages specific to the QNX
13347Neutrino support.
13348
13349@item show debug nto-debug
13350@kindex show debug nto-debug
13351Show the current state of QNX Neutrino messages.
13352@end table
13353
13354
8e04817f
AC
13355@node Embedded OS
13356@section Embedded Operating Systems
104c1213 13357
8e04817f
AC
13358This section describes configurations involving the debugging of
13359embedded operating systems that are available for several different
13360architectures.
d4f3574e 13361
8e04817f
AC
13362@menu
13363* VxWorks:: Using @value{GDBN} with VxWorks
13364@end menu
104c1213 13365
8e04817f
AC
13366@value{GDBN} includes the ability to debug programs running on
13367various real-time operating systems.
104c1213 13368
8e04817f
AC
13369@node VxWorks
13370@subsection Using @value{GDBN} with VxWorks
104c1213 13371
8e04817f 13372@cindex VxWorks
104c1213 13373
8e04817f 13374@table @code
104c1213 13375
8e04817f
AC
13376@kindex target vxworks
13377@item target vxworks @var{machinename}
13378A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13379is the target system's machine name or IP address.
104c1213 13380
8e04817f 13381@end table
104c1213 13382
8e04817f
AC
13383On VxWorks, @code{load} links @var{filename} dynamically on the
13384current target system as well as adding its symbols in @value{GDBN}.
104c1213 13385
8e04817f
AC
13386@value{GDBN} enables developers to spawn and debug tasks running on networked
13387VxWorks targets from a Unix host. Already-running tasks spawned from
13388the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13389both the Unix host and on the VxWorks target. The program
13390@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13391installed with the name @code{vxgdb}, to distinguish it from a
13392@value{GDBN} for debugging programs on the host itself.)
104c1213 13393
8e04817f
AC
13394@table @code
13395@item VxWorks-timeout @var{args}
13396@kindex vxworks-timeout
13397All VxWorks-based targets now support the option @code{vxworks-timeout}.
13398This option is set by the user, and @var{args} represents the number of
13399seconds @value{GDBN} waits for responses to rpc's. You might use this if
13400your VxWorks target is a slow software simulator or is on the far side
13401of a thin network line.
13402@end table
104c1213 13403
8e04817f
AC
13404The following information on connecting to VxWorks was current when
13405this manual was produced; newer releases of VxWorks may use revised
13406procedures.
104c1213 13407
4644b6e3 13408@findex INCLUDE_RDB
8e04817f
AC
13409To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13410to include the remote debugging interface routines in the VxWorks
13411library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13412VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13413kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13414source debugging task @code{tRdbTask} when VxWorks is booted. For more
13415information on configuring and remaking VxWorks, see the manufacturer's
13416manual.
13417@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13418
8e04817f
AC
13419Once you have included @file{rdb.a} in your VxWorks system image and set
13420your Unix execution search path to find @value{GDBN}, you are ready to
13421run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13422@code{vxgdb}, depending on your installation).
104c1213 13423
8e04817f 13424@value{GDBN} comes up showing the prompt:
104c1213 13425
474c8240 13426@smallexample
8e04817f 13427(vxgdb)
474c8240 13428@end smallexample
104c1213 13429
8e04817f
AC
13430@menu
13431* VxWorks Connection:: Connecting to VxWorks
13432* VxWorks Download:: VxWorks download
13433* VxWorks Attach:: Running tasks
13434@end menu
104c1213 13435
8e04817f
AC
13436@node VxWorks Connection
13437@subsubsection Connecting to VxWorks
104c1213 13438
8e04817f
AC
13439The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13440network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13441
474c8240 13442@smallexample
8e04817f 13443(vxgdb) target vxworks tt
474c8240 13444@end smallexample
104c1213 13445
8e04817f
AC
13446@need 750
13447@value{GDBN} displays messages like these:
104c1213 13448
8e04817f
AC
13449@smallexample
13450Attaching remote machine across net...
13451Connected to tt.
13452@end smallexample
104c1213 13453
8e04817f
AC
13454@need 1000
13455@value{GDBN} then attempts to read the symbol tables of any object modules
13456loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13457these files by searching the directories listed in the command search
13458path (@pxref{Environment, ,Your program's environment}); if it fails
13459to find an object file, it displays a message such as:
5d161b24 13460
474c8240 13461@smallexample
8e04817f 13462prog.o: No such file or directory.
474c8240 13463@end smallexample
104c1213 13464
8e04817f
AC
13465When this happens, add the appropriate directory to the search path with
13466the @value{GDBN} command @code{path}, and execute the @code{target}
13467command again.
104c1213 13468
8e04817f
AC
13469@node VxWorks Download
13470@subsubsection VxWorks download
104c1213 13471
8e04817f
AC
13472@cindex download to VxWorks
13473If you have connected to the VxWorks target and you want to debug an
13474object that has not yet been loaded, you can use the @value{GDBN}
13475@code{load} command to download a file from Unix to VxWorks
13476incrementally. The object file given as an argument to the @code{load}
13477command is actually opened twice: first by the VxWorks target in order
13478to download the code, then by @value{GDBN} in order to read the symbol
13479table. This can lead to problems if the current working directories on
13480the two systems differ. If both systems have NFS mounted the same
13481filesystems, you can avoid these problems by using absolute paths.
13482Otherwise, it is simplest to set the working directory on both systems
13483to the directory in which the object file resides, and then to reference
13484the file by its name, without any path. For instance, a program
13485@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13486and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13487program, type this on VxWorks:
104c1213 13488
474c8240 13489@smallexample
8e04817f 13490-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13491@end smallexample
104c1213 13492
8e04817f
AC
13493@noindent
13494Then, in @value{GDBN}, type:
104c1213 13495
474c8240 13496@smallexample
8e04817f
AC
13497(vxgdb) cd @var{hostpath}/vw/demo/rdb
13498(vxgdb) load prog.o
474c8240 13499@end smallexample
104c1213 13500
8e04817f 13501@value{GDBN} displays a response similar to this:
104c1213 13502
8e04817f
AC
13503@smallexample
13504Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13505@end smallexample
104c1213 13506
8e04817f
AC
13507You can also use the @code{load} command to reload an object module
13508after editing and recompiling the corresponding source file. Note that
13509this makes @value{GDBN} delete all currently-defined breakpoints,
13510auto-displays, and convenience variables, and to clear the value
13511history. (This is necessary in order to preserve the integrity of
13512debugger's data structures that reference the target system's symbol
13513table.)
104c1213 13514
8e04817f
AC
13515@node VxWorks Attach
13516@subsubsection Running tasks
104c1213
JM
13517
13518@cindex running VxWorks tasks
13519You can also attach to an existing task using the @code{attach} command as
13520follows:
13521
474c8240 13522@smallexample
104c1213 13523(vxgdb) attach @var{task}
474c8240 13524@end smallexample
104c1213
JM
13525
13526@noindent
13527where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13528or suspended when you attach to it. Running tasks are suspended at
13529the time of attachment.
13530
6d2ebf8b 13531@node Embedded Processors
104c1213
JM
13532@section Embedded Processors
13533
13534This section goes into details specific to particular embedded
13535configurations.
13536
c45da7e6
EZ
13537@cindex send command to simulator
13538Whenever a specific embedded processor has a simulator, @value{GDBN}
13539allows to send an arbitrary command to the simulator.
13540
13541@table @code
13542@item sim @var{command}
13543@kindex sim@r{, a command}
13544Send an arbitrary @var{command} string to the simulator. Consult the
13545documentation for the specific simulator in use for information about
13546acceptable commands.
13547@end table
13548
7d86b5d5 13549
104c1213 13550@menu
c45da7e6 13551* ARM:: ARM RDI
172c2a43
KI
13552* H8/300:: Renesas H8/300
13553* H8/500:: Renesas H8/500
13554* M32R/D:: Renesas M32R/D
104c1213 13555* M68K:: Motorola M68K
104c1213 13556* MIPS Embedded:: MIPS Embedded
a37295f9 13557* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13558* PA:: HP PA Embedded
13559* PowerPC: PowerPC
172c2a43 13560* SH:: Renesas SH
104c1213
JM
13561* Sparclet:: Tsqware Sparclet
13562* Sparclite:: Fujitsu Sparclite
13563* ST2000:: Tandem ST2000
13564* Z8000:: Zilog Z8000
a64548ea
EZ
13565* AVR:: Atmel AVR
13566* CRIS:: CRIS
13567* Super-H:: Renesas Super-H
c45da7e6 13568* WinCE:: Windows CE child processes
104c1213
JM
13569@end menu
13570
6d2ebf8b 13571@node ARM
104c1213 13572@subsection ARM
c45da7e6 13573@cindex ARM RDI
104c1213
JM
13574
13575@table @code
8e04817f
AC
13576@kindex target rdi
13577@item target rdi @var{dev}
13578ARM Angel monitor, via RDI library interface to ADP protocol. You may
13579use this target to communicate with both boards running the Angel
13580monitor, or with the EmbeddedICE JTAG debug device.
13581
13582@kindex target rdp
13583@item target rdp @var{dev}
13584ARM Demon monitor.
13585
13586@end table
13587
e2f4edfd
EZ
13588@value{GDBN} provides the following ARM-specific commands:
13589
13590@table @code
13591@item set arm disassembler
13592@kindex set arm
13593This commands selects from a list of disassembly styles. The
13594@code{"std"} style is the standard style.
13595
13596@item show arm disassembler
13597@kindex show arm
13598Show the current disassembly style.
13599
13600@item set arm apcs32
13601@cindex ARM 32-bit mode
13602This command toggles ARM operation mode between 32-bit and 26-bit.
13603
13604@item show arm apcs32
13605Display the current usage of the ARM 32-bit mode.
13606
13607@item set arm fpu @var{fputype}
13608This command sets the ARM floating-point unit (FPU) type. The
13609argument @var{fputype} can be one of these:
13610
13611@table @code
13612@item auto
13613Determine the FPU type by querying the OS ABI.
13614@item softfpa
13615Software FPU, with mixed-endian doubles on little-endian ARM
13616processors.
13617@item fpa
13618GCC-compiled FPA co-processor.
13619@item softvfp
13620Software FPU with pure-endian doubles.
13621@item vfp
13622VFP co-processor.
13623@end table
13624
13625@item show arm fpu
13626Show the current type of the FPU.
13627
13628@item set arm abi
13629This command forces @value{GDBN} to use the specified ABI.
13630
13631@item show arm abi
13632Show the currently used ABI.
13633
13634@item set debug arm
13635Toggle whether to display ARM-specific debugging messages from the ARM
13636target support subsystem.
13637
13638@item show debug arm
13639Show whether ARM-specific debugging messages are enabled.
13640@end table
13641
c45da7e6
EZ
13642The following commands are available when an ARM target is debugged
13643using the RDI interface:
13644
13645@table @code
13646@item rdilogfile @r{[}@var{file}@r{]}
13647@kindex rdilogfile
13648@cindex ADP (Angel Debugger Protocol) logging
13649Set the filename for the ADP (Angel Debugger Protocol) packet log.
13650With an argument, sets the log file to the specified @var{file}. With
13651no argument, show the current log file name. The default log file is
13652@file{rdi.log}.
13653
13654@item rdilogenable @r{[}@var{arg}@r{]}
13655@kindex rdilogenable
13656Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13657enables logging, with an argument 0 or @code{"no"} disables it. With
13658no arguments displays the current setting. When logging is enabled,
13659ADP packets exchanged between @value{GDBN} and the RDI target device
13660are logged to a file.
13661
13662@item set rdiromatzero
13663@kindex set rdiromatzero
13664@cindex ROM at zero address, RDI
13665Tell @value{GDBN} whether the target has ROM at address 0. If on,
13666vector catching is disabled, so that zero address can be used. If off
13667(the default), vector catching is enabled. For this command to take
13668effect, it needs to be invoked prior to the @code{target rdi} command.
13669
13670@item show rdiromatzero
13671@kindex show rdiromatzero
13672Show the current setting of ROM at zero address.
13673
13674@item set rdiheartbeat
13675@kindex set rdiheartbeat
13676@cindex RDI heartbeat
13677Enable or disable RDI heartbeat packets. It is not recommended to
13678turn on this option, since it confuses ARM and EPI JTAG interface, as
13679well as the Angel monitor.
13680
13681@item show rdiheartbeat
13682@kindex show rdiheartbeat
13683Show the setting of RDI heartbeat packets.
13684@end table
13685
e2f4edfd 13686
8e04817f 13687@node H8/300
172c2a43 13688@subsection Renesas H8/300
8e04817f
AC
13689
13690@table @code
13691
13692@kindex target hms@r{, with H8/300}
13693@item target hms @var{dev}
172c2a43 13694A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13695Use special commands @code{device} and @code{speed} to control the serial
13696line and the communications speed used.
13697
13698@kindex target e7000@r{, with H8/300}
13699@item target e7000 @var{dev}
172c2a43 13700E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13701
13702@kindex target sh3@r{, with H8/300}
13703@kindex target sh3e@r{, with H8/300}
13704@item target sh3 @var{dev}
13705@itemx target sh3e @var{dev}
172c2a43 13706Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13707
13708@end table
13709
13710@cindex download to H8/300 or H8/500
13711@cindex H8/300 or H8/500 download
172c2a43
KI
13712@cindex download to Renesas SH
13713@cindex Renesas SH download
13714When you select remote debugging to a Renesas SH, H8/300, or H8/500
13715board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13716board and also opens it as the current executable target for
13717@value{GDBN} on your host (like the @code{file} command).
13718
13719@value{GDBN} needs to know these things to talk to your
172c2a43 13720Renesas SH, H8/300, or H8/500:
8e04817f
AC
13721
13722@enumerate
13723@item
13724that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13725for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13726emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13727the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13728H8/300, or H8/500.)
13729
13730@item
172c2a43 13731what serial device connects your host to your Renesas board (the first
8e04817f
AC
13732serial device available on your host is the default).
13733
13734@item
13735what speed to use over the serial device.
13736@end enumerate
13737
13738@menu
172c2a43
KI
13739* Renesas Boards:: Connecting to Renesas boards.
13740* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13741* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13742@end menu
13743
172c2a43
KI
13744@node Renesas Boards
13745@subsubsection Connecting to Renesas boards
8e04817f
AC
13746
13747@c only for Unix hosts
13748@kindex device
172c2a43 13749@cindex serial device, Renesas micros
8e04817f
AC
13750Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13751need to explicitly set the serial device. The default @var{port} is the
13752first available port on your host. This is only necessary on Unix
13753hosts, where it is typically something like @file{/dev/ttya}.
13754
13755@kindex speed
172c2a43 13756@cindex serial line speed, Renesas micros
8e04817f
AC
13757@code{@value{GDBN}} has another special command to set the communications
13758speed: @samp{speed @var{bps}}. This command also is only used from Unix
13759hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13760the DOS @code{mode} command (for instance,
13761@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13762
13763The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13764use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13765use a DOS host,
13766@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13767called @code{asynctsr} to communicate with the development board
13768through a PC serial port. You must also use the DOS @code{mode} command
13769to set up the serial port on the DOS side.
13770
13771The following sample session illustrates the steps needed to start a
13772program under @value{GDBN} control on an H8/300. The example uses a
13773sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13774the Renesas SH and the H8/500.
8e04817f
AC
13775
13776First hook up your development board. In this example, we use a
13777board attached to serial port @code{COM2}; if you use a different serial
13778port, substitute its name in the argument of the @code{mode} command.
13779When you call @code{asynctsr}, the auxiliary comms program used by the
13780debugger, you give it just the numeric part of the serial port's name;
13781for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13782@code{COM2}.
13783
474c8240 13784@smallexample
8e04817f
AC
13785C:\H8300\TEST> asynctsr 2
13786C:\H8300\TEST> mode com2:9600,n,8,1,p
13787
13788Resident portion of MODE loaded
13789
13790COM2: 9600, n, 8, 1, p
13791
474c8240 13792@end smallexample
8e04817f
AC
13793
13794@quotation
13795@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13796@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13797disable it, or even boot without it, to use @code{asynctsr} to control
13798your development board.
13799@end quotation
13800
13801@kindex target hms@r{, and serial protocol}
13802Now that serial communications are set up, and the development board is
9c16f35a 13803connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13804the name of your program as the argument. @code{@value{GDBN}} prompts
13805you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13806commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13807cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13808download your program to the board. @code{load} displays the names of
13809the program's sections, and a @samp{*} for each 2K of data downloaded.
13810(If you want to refresh @value{GDBN} data on symbols or on the
13811executable file without downloading, use the @value{GDBN} commands
13812@code{file} or @code{symbol-file}. These commands, and @code{load}
13813itself, are described in @ref{Files,,Commands to specify files}.)
13814
13815@smallexample
13816(eg-C:\H8300\TEST) @value{GDBP} t.x
13817@value{GDBN} is free software and you are welcome to distribute copies
13818 of it under certain conditions; type "show copying" to see
13819 the conditions.
13820There is absolutely no warranty for @value{GDBN}; type "show warranty"
13821for details.
13822@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13823(@value{GDBP}) target hms
13824Connected to remote H8/300 HMS system.
13825(@value{GDBP}) load t.x
13826.text : 0x8000 .. 0xabde ***********
13827.data : 0xabde .. 0xad30 *
13828.stack : 0xf000 .. 0xf014 *
13829@end smallexample
13830
13831At this point, you're ready to run or debug your program. From here on,
13832you can use all the usual @value{GDBN} commands. The @code{break} command
13833sets breakpoints; the @code{run} command starts your program;
13834@code{print} or @code{x} display data; the @code{continue} command
13835resumes execution after stopping at a breakpoint. You can use the
13836@code{help} command at any time to find out more about @value{GDBN} commands.
13837
13838Remember, however, that @emph{operating system} facilities aren't
13839available on your development board; for example, if your program hangs,
13840you can't send an interrupt---but you can press the @sc{reset} switch!
13841
13842Use the @sc{reset} button on the development board
13843@itemize @bullet
13844@item
13845to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13846no way to pass an interrupt signal to the development board); and
13847
13848@item
13849to return to the @value{GDBN} command prompt after your program finishes
13850normally. The communications protocol provides no other way for @value{GDBN}
13851to detect program completion.
13852@end itemize
13853
13854In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13855development board as a ``normal exit'' of your program.
13856
172c2a43 13857@node Renesas ICE
8e04817f
AC
13858@subsubsection Using the E7000 in-circuit emulator
13859
172c2a43 13860@kindex target e7000@r{, with Renesas ICE}
8e04817f 13861You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13862Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13863e7000} command to connect @value{GDBN} to your E7000:
13864
13865@table @code
13866@item target e7000 @var{port} @var{speed}
13867Use this form if your E7000 is connected to a serial port. The
13868@var{port} argument identifies what serial port to use (for example,
13869@samp{com2}). The third argument is the line speed in bits per second
13870(for example, @samp{9600}).
13871
13872@item target e7000 @var{hostname}
13873If your E7000 is installed as a host on a TCP/IP network, you can just
13874specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13875@end table
13876
ba04e063
EZ
13877The following special commands are available when debugging with the
13878Renesas E7000 ICE:
13879
13880@table @code
13881@item e7000 @var{command}
13882@kindex e7000
13883@cindex send command to E7000 monitor
13884This sends the specified @var{command} to the E7000 monitor.
13885
13886@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13887@kindex ftplogin@r{, E7000}
13888This command records information for subsequent interface with the
13889E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13890named @var{machine} using specified @var{username} and @var{password},
13891and then chdir to the named directory @var{dir}.
13892
13893@item ftpload @var{file}
13894@kindex ftpload@r{, E7000}
13895This command uses credentials recorded by @code{ftplogin} to fetch and
13896load the named @var{file} from the E7000 monitor.
13897
13898@item drain
13899@kindex drain@r{, E7000}
13900This command drains any pending text buffers stored on the E7000.
13901
13902@item set usehardbreakpoints
13903@itemx show usehardbreakpoints
13904@kindex set usehardbreakpoints@r{, E7000}
13905@kindex show usehardbreakpoints@r{, E7000}
13906@cindex hardware breakpoints, and E7000
13907These commands set and show the use of hardware breakpoints for all
13908breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13909more information about using hardware breakpoints selectively.
13910@end table
13911
172c2a43
KI
13912@node Renesas Special
13913@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13914
13915Some @value{GDBN} commands are available only for the H8/300:
13916
13917@table @code
13918
13919@kindex set machine
13920@kindex show machine
13921@item set machine h8300
13922@itemx set machine h8300h
13923Condition @value{GDBN} for one of the two variants of the H8/300
13924architecture with @samp{set machine}. You can use @samp{show machine}
13925to check which variant is currently in effect.
104c1213
JM
13926
13927@end table
13928
8e04817f
AC
13929@node H8/500
13930@subsection H8/500
104c1213
JM
13931
13932@table @code
13933
8e04817f
AC
13934@kindex set memory @var{mod}
13935@cindex memory models, H8/500
13936@item set memory @var{mod}
13937@itemx show memory
13938Specify which H8/500 memory model (@var{mod}) you are using with
13939@samp{set memory}; check which memory model is in effect with @samp{show
13940memory}. The accepted values for @var{mod} are @code{small},
13941@code{big}, @code{medium}, and @code{compact}.
104c1213 13942
8e04817f 13943@end table
104c1213 13944
8e04817f 13945@node M32R/D
ba04e063 13946@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13947
13948@table @code
8e04817f
AC
13949@kindex target m32r
13950@item target m32r @var{dev}
172c2a43 13951Renesas M32R/D ROM monitor.
8e04817f 13952
fb3e19c0
KI
13953@kindex target m32rsdi
13954@item target m32rsdi @var{dev}
13955Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13956@end table
13957
13958The following @value{GDBN} commands are specific to the M32R monitor:
13959
13960@table @code
13961@item set download-path @var{path}
13962@kindex set download-path
13963@cindex find downloadable @sc{srec} files (M32R)
13964Set the default path for finding donwloadable @sc{srec} files.
13965
13966@item show download-path
13967@kindex show download-path
13968Show the default path for downloadable @sc{srec} files.
fb3e19c0 13969
721c2651
EZ
13970@item set board-address @var{addr}
13971@kindex set board-address
13972@cindex M32-EVA target board address
13973Set the IP address for the M32R-EVA target board.
13974
13975@item show board-address
13976@kindex show board-address
13977Show the current IP address of the target board.
13978
13979@item set server-address @var{addr}
13980@kindex set server-address
13981@cindex download server address (M32R)
13982Set the IP address for the download server, which is the @value{GDBN}'s
13983host machine.
13984
13985@item show server-address
13986@kindex show server-address
13987Display the IP address of the download server.
13988
13989@item upload @r{[}@var{file}@r{]}
13990@kindex upload@r{, M32R}
13991Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13992upload capability. If no @var{file} argument is given, the current
13993executable file is uploaded.
13994
13995@item tload @r{[}@var{file}@r{]}
13996@kindex tload@r{, M32R}
13997Test the @code{upload} command.
8e04817f
AC
13998@end table
13999
ba04e063
EZ
14000The following commands are available for M32R/SDI:
14001
14002@table @code
14003@item sdireset
14004@kindex sdireset
14005@cindex reset SDI connection, M32R
14006This command resets the SDI connection.
14007
14008@item sdistatus
14009@kindex sdistatus
14010This command shows the SDI connection status.
14011
14012@item debug_chaos
14013@kindex debug_chaos
14014@cindex M32R/Chaos debugging
14015Instructs the remote that M32R/Chaos debugging is to be used.
14016
14017@item use_debug_dma
14018@kindex use_debug_dma
14019Instructs the remote to use the DEBUG_DMA method of accessing memory.
14020
14021@item use_mon_code
14022@kindex use_mon_code
14023Instructs the remote to use the MON_CODE method of accessing memory.
14024
14025@item use_ib_break
14026@kindex use_ib_break
14027Instructs the remote to set breakpoints by IB break.
14028
14029@item use_dbt_break
14030@kindex use_dbt_break
14031Instructs the remote to set breakpoints by DBT.
14032@end table
14033
8e04817f
AC
14034@node M68K
14035@subsection M68k
14036
14037The Motorola m68k configuration includes ColdFire support, and
14038target command for the following ROM monitors.
14039
14040@table @code
14041
14042@kindex target abug
14043@item target abug @var{dev}
14044ABug ROM monitor for M68K.
14045
14046@kindex target cpu32bug
14047@item target cpu32bug @var{dev}
14048CPU32BUG monitor, running on a CPU32 (M68K) board.
14049
14050@kindex target dbug
14051@item target dbug @var{dev}
14052dBUG ROM monitor for Motorola ColdFire.
14053
14054@kindex target est
14055@item target est @var{dev}
14056EST-300 ICE monitor, running on a CPU32 (M68K) board.
14057
14058@kindex target rom68k
14059@item target rom68k @var{dev}
14060ROM 68K monitor, running on an M68K IDP board.
14061
14062@end table
14063
8e04817f
AC
14064@table @code
14065
14066@kindex target rombug
14067@item target rombug @var{dev}
14068ROMBUG ROM monitor for OS/9000.
14069
14070@end table
14071
8e04817f
AC
14072@node MIPS Embedded
14073@subsection MIPS Embedded
14074
14075@cindex MIPS boards
14076@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14077MIPS board attached to a serial line. This is available when
14078you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14079
8e04817f
AC
14080@need 1000
14081Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14082
8e04817f
AC
14083@table @code
14084@item target mips @var{port}
14085@kindex target mips @var{port}
14086To run a program on the board, start up @code{@value{GDBP}} with the
14087name of your program as the argument. To connect to the board, use the
14088command @samp{target mips @var{port}}, where @var{port} is the name of
14089the serial port connected to the board. If the program has not already
14090been downloaded to the board, you may use the @code{load} command to
14091download it. You can then use all the usual @value{GDBN} commands.
104c1213 14092
8e04817f
AC
14093For example, this sequence connects to the target board through a serial
14094port, and loads and runs a program called @var{prog} through the
14095debugger:
104c1213 14096
474c8240 14097@smallexample
8e04817f
AC
14098host$ @value{GDBP} @var{prog}
14099@value{GDBN} is free software and @dots{}
14100(@value{GDBP}) target mips /dev/ttyb
14101(@value{GDBP}) load @var{prog}
14102(@value{GDBP}) run
474c8240 14103@end smallexample
104c1213 14104
8e04817f
AC
14105@item target mips @var{hostname}:@var{portnumber}
14106On some @value{GDBN} host configurations, you can specify a TCP
14107connection (for instance, to a serial line managed by a terminal
14108concentrator) instead of a serial port, using the syntax
14109@samp{@var{hostname}:@var{portnumber}}.
104c1213 14110
8e04817f
AC
14111@item target pmon @var{port}
14112@kindex target pmon @var{port}
14113PMON ROM monitor.
104c1213 14114
8e04817f
AC
14115@item target ddb @var{port}
14116@kindex target ddb @var{port}
14117NEC's DDB variant of PMON for Vr4300.
104c1213 14118
8e04817f
AC
14119@item target lsi @var{port}
14120@kindex target lsi @var{port}
14121LSI variant of PMON.
104c1213 14122
8e04817f
AC
14123@kindex target r3900
14124@item target r3900 @var{dev}
14125Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14126
8e04817f
AC
14127@kindex target array
14128@item target array @var{dev}
14129Array Tech LSI33K RAID controller board.
104c1213 14130
8e04817f 14131@end table
104c1213 14132
104c1213 14133
8e04817f
AC
14134@noindent
14135@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14136
8e04817f 14137@table @code
8e04817f
AC
14138@item set mipsfpu double
14139@itemx set mipsfpu single
14140@itemx set mipsfpu none
a64548ea 14141@itemx set mipsfpu auto
8e04817f
AC
14142@itemx show mipsfpu
14143@kindex set mipsfpu
14144@kindex show mipsfpu
14145@cindex MIPS remote floating point
14146@cindex floating point, MIPS remote
14147If your target board does not support the MIPS floating point
14148coprocessor, you should use the command @samp{set mipsfpu none} (if you
14149need this, you may wish to put the command in your @value{GDBN} init
14150file). This tells @value{GDBN} how to find the return value of
14151functions which return floating point values. It also allows
14152@value{GDBN} to avoid saving the floating point registers when calling
14153functions on the board. If you are using a floating point coprocessor
14154with only single precision floating point support, as on the @sc{r4650}
14155processor, use the command @samp{set mipsfpu single}. The default
14156double precision floating point coprocessor may be selected using
14157@samp{set mipsfpu double}.
104c1213 14158
8e04817f
AC
14159In previous versions the only choices were double precision or no
14160floating point, so @samp{set mipsfpu on} will select double precision
14161and @samp{set mipsfpu off} will select no floating point.
104c1213 14162
8e04817f
AC
14163As usual, you can inquire about the @code{mipsfpu} variable with
14164@samp{show mipsfpu}.
104c1213 14165
8e04817f
AC
14166@item set timeout @var{seconds}
14167@itemx set retransmit-timeout @var{seconds}
14168@itemx show timeout
14169@itemx show retransmit-timeout
14170@cindex @code{timeout}, MIPS protocol
14171@cindex @code{retransmit-timeout}, MIPS protocol
14172@kindex set timeout
14173@kindex show timeout
14174@kindex set retransmit-timeout
14175@kindex show retransmit-timeout
14176You can control the timeout used while waiting for a packet, in the MIPS
14177remote protocol, with the @code{set timeout @var{seconds}} command. The
14178default is 5 seconds. Similarly, you can control the timeout used while
14179waiting for an acknowledgement of a packet with the @code{set
14180retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14181You can inspect both values with @code{show timeout} and @code{show
14182retransmit-timeout}. (These commands are @emph{only} available when
14183@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14184
8e04817f
AC
14185The timeout set by @code{set timeout} does not apply when @value{GDBN}
14186is waiting for your program to stop. In that case, @value{GDBN} waits
14187forever because it has no way of knowing how long the program is going
14188to run before stopping.
ba04e063
EZ
14189
14190@item set syn-garbage-limit @var{num}
14191@kindex set syn-garbage-limit@r{, MIPS remote}
14192@cindex synchronize with remote MIPS target
14193Limit the maximum number of characters @value{GDBN} should ignore when
14194it tries to synchronize with the remote target. The default is 10
14195characters. Setting the limit to -1 means there's no limit.
14196
14197@item show syn-garbage-limit
14198@kindex show syn-garbage-limit@r{, MIPS remote}
14199Show the current limit on the number of characters to ignore when
14200trying to synchronize with the remote system.
14201
14202@item set monitor-prompt @var{prompt}
14203@kindex set monitor-prompt@r{, MIPS remote}
14204@cindex remote monitor prompt
14205Tell @value{GDBN} to expect the specified @var{prompt} string from the
14206remote monitor. The default depends on the target:
14207@table @asis
14208@item pmon target
14209@samp{PMON}
14210@item ddb target
14211@samp{NEC010}
14212@item lsi target
14213@samp{PMON>}
14214@end table
14215
14216@item show monitor-prompt
14217@kindex show monitor-prompt@r{, MIPS remote}
14218Show the current strings @value{GDBN} expects as the prompt from the
14219remote monitor.
14220
14221@item set monitor-warnings
14222@kindex set monitor-warnings@r{, MIPS remote}
14223Enable or disable monitor warnings about hardware breakpoints. This
14224has effect only for the @code{lsi} target. When on, @value{GDBN} will
14225display warning messages whose codes are returned by the @code{lsi}
14226PMON monitor for breakpoint commands.
14227
14228@item show monitor-warnings
14229@kindex show monitor-warnings@r{, MIPS remote}
14230Show the current setting of printing monitor warnings.
14231
14232@item pmon @var{command}
14233@kindex pmon@r{, MIPS remote}
14234@cindex send PMON command
14235This command allows sending an arbitrary @var{command} string to the
14236monitor. The monitor must be in debug mode for this to work.
8e04817f 14237@end table
104c1213 14238
a37295f9
MM
14239@node OpenRISC 1000
14240@subsection OpenRISC 1000
14241@cindex OpenRISC 1000
14242
14243@cindex or1k boards
14244See OR1k Architecture document (@uref{www.opencores.org}) for more information
14245about platform and commands.
14246
14247@table @code
14248
14249@kindex target jtag
14250@item target jtag jtag://@var{host}:@var{port}
14251
14252Connects to remote JTAG server.
14253JTAG remote server can be either an or1ksim or JTAG server,
14254connected via parallel port to the board.
14255
14256Example: @code{target jtag jtag://localhost:9999}
14257
14258@kindex or1ksim
14259@item or1ksim @var{command}
14260If connected to @code{or1ksim} OpenRISC 1000 Architectural
14261Simulator, proprietary commands can be executed.
14262
14263@kindex info or1k spr
14264@item info or1k spr
14265Displays spr groups.
14266
14267@item info or1k spr @var{group}
14268@itemx info or1k spr @var{groupno}
14269Displays register names in selected group.
14270
14271@item info or1k spr @var{group} @var{register}
14272@itemx info or1k spr @var{register}
14273@itemx info or1k spr @var{groupno} @var{registerno}
14274@itemx info or1k spr @var{registerno}
14275Shows information about specified spr register.
14276
14277@kindex spr
14278@item spr @var{group} @var{register} @var{value}
14279@itemx spr @var{register @var{value}}
14280@itemx spr @var{groupno} @var{registerno @var{value}}
14281@itemx spr @var{registerno @var{value}}
14282Writes @var{value} to specified spr register.
14283@end table
14284
14285Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14286It is very similar to @value{GDBN} trace, except it does not interfere with normal
14287program execution and is thus much faster. Hardware breakpoints/watchpoint
14288triggers can be set using:
14289@table @code
14290@item $LEA/$LDATA
14291Load effective address/data
14292@item $SEA/$SDATA
14293Store effective address/data
14294@item $AEA/$ADATA
14295Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14296@item $FETCH
14297Fetch data
14298@end table
14299
14300When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14301@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14302
14303@code{htrace} commands:
14304@cindex OpenRISC 1000 htrace
14305@table @code
14306@kindex hwatch
14307@item hwatch @var{conditional}
14308Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14309or Data. For example:
14310
14311@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14312
14313@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14314
4644b6e3 14315@kindex htrace
a37295f9
MM
14316@item htrace info
14317Display information about current HW trace configuration.
14318
a37295f9
MM
14319@item htrace trigger @var{conditional}
14320Set starting criteria for HW trace.
14321
a37295f9
MM
14322@item htrace qualifier @var{conditional}
14323Set acquisition qualifier for HW trace.
14324
a37295f9
MM
14325@item htrace stop @var{conditional}
14326Set HW trace stopping criteria.
14327
f153cc92 14328@item htrace record [@var{data}]*
a37295f9
MM
14329Selects the data to be recorded, when qualifier is met and HW trace was
14330triggered.
14331
a37295f9 14332@item htrace enable
a37295f9
MM
14333@itemx htrace disable
14334Enables/disables the HW trace.
14335
f153cc92 14336@item htrace rewind [@var{filename}]
a37295f9
MM
14337Clears currently recorded trace data.
14338
14339If filename is specified, new trace file is made and any newly collected data
14340will be written there.
14341
f153cc92 14342@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14343Prints trace buffer, using current record configuration.
14344
a37295f9
MM
14345@item htrace mode continuous
14346Set continuous trace mode.
14347
a37295f9
MM
14348@item htrace mode suspend
14349Set suspend trace mode.
14350
14351@end table
14352
8e04817f
AC
14353@node PowerPC
14354@subsection PowerPC
104c1213
JM
14355
14356@table @code
8e04817f
AC
14357@kindex target dink32
14358@item target dink32 @var{dev}
14359DINK32 ROM monitor.
104c1213 14360
8e04817f
AC
14361@kindex target ppcbug
14362@item target ppcbug @var{dev}
14363@kindex target ppcbug1
14364@item target ppcbug1 @var{dev}
14365PPCBUG ROM monitor for PowerPC.
104c1213 14366
8e04817f
AC
14367@kindex target sds
14368@item target sds @var{dev}
14369SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14370@end table
8e04817f 14371
c45da7e6
EZ
14372@cindex SDS protocol
14373The following commands specifi to the SDS protocol are supported
14374by@value{GDBN}:
14375
14376@table @code
14377@item set sdstimeout @var{nsec}
14378@kindex set sdstimeout
14379Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14380default is 2 seconds.
14381
14382@item show sdstimeout
14383@kindex show sdstimeout
14384Show the current value of the SDS timeout.
14385
14386@item sds @var{command}
14387@kindex sds@r{, a command}
14388Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14389@end table
14390
c45da7e6 14391
8e04817f
AC
14392@node PA
14393@subsection HP PA Embedded
104c1213
JM
14394
14395@table @code
14396
8e04817f
AC
14397@kindex target op50n
14398@item target op50n @var{dev}
14399OP50N monitor, running on an OKI HPPA board.
14400
14401@kindex target w89k
14402@item target w89k @var{dev}
14403W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14404
14405@end table
14406
8e04817f 14407@node SH
172c2a43 14408@subsection Renesas SH
104c1213
JM
14409
14410@table @code
14411
172c2a43 14412@kindex target hms@r{, with Renesas SH}
8e04817f 14413@item target hms @var{dev}
172c2a43 14414A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14415commands @code{device} and @code{speed} to control the serial line and
14416the communications speed used.
104c1213 14417
172c2a43 14418@kindex target e7000@r{, with Renesas SH}
8e04817f 14419@item target e7000 @var{dev}
172c2a43 14420E7000 emulator for Renesas SH.
104c1213 14421
8e04817f
AC
14422@kindex target sh3@r{, with SH}
14423@kindex target sh3e@r{, with SH}
14424@item target sh3 @var{dev}
14425@item target sh3e @var{dev}
172c2a43 14426Renesas SH-3 and SH-3E target systems.
104c1213 14427
8e04817f 14428@end table
104c1213 14429
8e04817f
AC
14430@node Sparclet
14431@subsection Tsqware Sparclet
104c1213 14432
8e04817f
AC
14433@cindex Sparclet
14434
14435@value{GDBN} enables developers to debug tasks running on
14436Sparclet targets from a Unix host.
14437@value{GDBN} uses code that runs on
14438both the Unix host and on the Sparclet target. The program
14439@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14440
8e04817f
AC
14441@table @code
14442@item remotetimeout @var{args}
14443@kindex remotetimeout
14444@value{GDBN} supports the option @code{remotetimeout}.
14445This option is set by the user, and @var{args} represents the number of
14446seconds @value{GDBN} waits for responses.
104c1213
JM
14447@end table
14448
8e04817f
AC
14449@cindex compiling, on Sparclet
14450When compiling for debugging, include the options @samp{-g} to get debug
14451information and @samp{-Ttext} to relocate the program to where you wish to
14452load it on the target. You may also want to add the options @samp{-n} or
14453@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14454
474c8240 14455@smallexample
8e04817f 14456sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14457@end smallexample
104c1213 14458
8e04817f 14459You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14460
474c8240 14461@smallexample
8e04817f 14462sparclet-aout-objdump --headers --syms prog
474c8240 14463@end smallexample
104c1213 14464
8e04817f
AC
14465@cindex running, on Sparclet
14466Once you have set
14467your Unix execution search path to find @value{GDBN}, you are ready to
14468run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14469(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14470
8e04817f
AC
14471@value{GDBN} comes up showing the prompt:
14472
474c8240 14473@smallexample
8e04817f 14474(gdbslet)
474c8240 14475@end smallexample
104c1213
JM
14476
14477@menu
8e04817f
AC
14478* Sparclet File:: Setting the file to debug
14479* Sparclet Connection:: Connecting to Sparclet
14480* Sparclet Download:: Sparclet download
14481* Sparclet Execution:: Running and debugging
104c1213
JM
14482@end menu
14483
8e04817f
AC
14484@node Sparclet File
14485@subsubsection Setting file to debug
104c1213 14486
8e04817f 14487The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14488
474c8240 14489@smallexample
8e04817f 14490(gdbslet) file prog
474c8240 14491@end smallexample
104c1213 14492
8e04817f
AC
14493@need 1000
14494@value{GDBN} then attempts to read the symbol table of @file{prog}.
14495@value{GDBN} locates
14496the file by searching the directories listed in the command search
14497path.
14498If the file was compiled with debug information (option "-g"), source
14499files will be searched as well.
14500@value{GDBN} locates
14501the source files by searching the directories listed in the directory search
14502path (@pxref{Environment, ,Your program's environment}).
14503If it fails
14504to find a file, it displays a message such as:
104c1213 14505
474c8240 14506@smallexample
8e04817f 14507prog: No such file or directory.
474c8240 14508@end smallexample
104c1213 14509
8e04817f
AC
14510When this happens, add the appropriate directories to the search paths with
14511the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14512@code{target} command again.
104c1213 14513
8e04817f
AC
14514@node Sparclet Connection
14515@subsubsection Connecting to Sparclet
104c1213 14516
8e04817f
AC
14517The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14518To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14519
474c8240 14520@smallexample
8e04817f
AC
14521(gdbslet) target sparclet /dev/ttya
14522Remote target sparclet connected to /dev/ttya
14523main () at ../prog.c:3
474c8240 14524@end smallexample
104c1213 14525
8e04817f
AC
14526@need 750
14527@value{GDBN} displays messages like these:
104c1213 14528
474c8240 14529@smallexample
8e04817f 14530Connected to ttya.
474c8240 14531@end smallexample
104c1213 14532
8e04817f
AC
14533@node Sparclet Download
14534@subsubsection Sparclet download
104c1213 14535
8e04817f
AC
14536@cindex download to Sparclet
14537Once connected to the Sparclet target,
14538you can use the @value{GDBN}
14539@code{load} command to download the file from the host to the target.
14540The file name and load offset should be given as arguments to the @code{load}
14541command.
14542Since the file format is aout, the program must be loaded to the starting
14543address. You can use @code{objdump} to find out what this value is. The load
14544offset is an offset which is added to the VMA (virtual memory address)
14545of each of the file's sections.
14546For instance, if the program
14547@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14548and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14549
474c8240 14550@smallexample
8e04817f
AC
14551(gdbslet) load prog 0x12010000
14552Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14553@end smallexample
104c1213 14554
8e04817f
AC
14555If the code is loaded at a different address then what the program was linked
14556to, you may need to use the @code{section} and @code{add-symbol-file} commands
14557to tell @value{GDBN} where to map the symbol table.
14558
14559@node Sparclet Execution
14560@subsubsection Running and debugging
14561
14562@cindex running and debugging Sparclet programs
14563You can now begin debugging the task using @value{GDBN}'s execution control
14564commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14565manual for the list of commands.
14566
474c8240 14567@smallexample
8e04817f
AC
14568(gdbslet) b main
14569Breakpoint 1 at 0x12010000: file prog.c, line 3.
14570(gdbslet) run
14571Starting program: prog
14572Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145733 char *symarg = 0;
14574(gdbslet) step
145754 char *execarg = "hello!";
14576(gdbslet)
474c8240 14577@end smallexample
8e04817f
AC
14578
14579@node Sparclite
14580@subsection Fujitsu Sparclite
104c1213
JM
14581
14582@table @code
14583
8e04817f
AC
14584@kindex target sparclite
14585@item target sparclite @var{dev}
14586Fujitsu sparclite boards, used only for the purpose of loading.
14587You must use an additional command to debug the program.
14588For example: target remote @var{dev} using @value{GDBN} standard
14589remote protocol.
104c1213
JM
14590
14591@end table
14592
8e04817f
AC
14593@node ST2000
14594@subsection Tandem ST2000
104c1213 14595
8e04817f
AC
14596@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14597STDBUG protocol.
104c1213 14598
8e04817f
AC
14599To connect your ST2000 to the host system, see the manufacturer's
14600manual. Once the ST2000 is physically attached, you can run:
104c1213 14601
474c8240 14602@smallexample
8e04817f 14603target st2000 @var{dev} @var{speed}
474c8240 14604@end smallexample
104c1213 14605
8e04817f
AC
14606@noindent
14607to establish it as your debugging environment. @var{dev} is normally
14608the name of a serial device, such as @file{/dev/ttya}, connected to the
14609ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14610connection (for example, to a serial line attached via a terminal
14611concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14612
8e04817f
AC
14613The @code{load} and @code{attach} commands are @emph{not} defined for
14614this target; you must load your program into the ST2000 as you normally
14615would for standalone operation. @value{GDBN} reads debugging information
14616(such as symbols) from a separate, debugging version of the program
14617available on your host computer.
14618@c FIXME!! This is terribly vague; what little content is here is
14619@c basically hearsay.
104c1213 14620
8e04817f
AC
14621@cindex ST2000 auxiliary commands
14622These auxiliary @value{GDBN} commands are available to help you with the ST2000
14623environment:
104c1213 14624
8e04817f
AC
14625@table @code
14626@item st2000 @var{command}
14627@kindex st2000 @var{cmd}
14628@cindex STDBUG commands (ST2000)
14629@cindex commands to STDBUG (ST2000)
14630Send a @var{command} to the STDBUG monitor. See the manufacturer's
14631manual for available commands.
104c1213 14632
8e04817f
AC
14633@item connect
14634@cindex connect (to STDBUG)
14635Connect the controlling terminal to the STDBUG command monitor. When
14636you are done interacting with STDBUG, typing either of two character
14637sequences gets you back to the @value{GDBN} command prompt:
14638@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14639@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14640@end table
14641
8e04817f
AC
14642@node Z8000
14643@subsection Zilog Z8000
104c1213 14644
8e04817f
AC
14645@cindex Z8000
14646@cindex simulator, Z8000
14647@cindex Zilog Z8000 simulator
104c1213 14648
8e04817f
AC
14649When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14650a Z8000 simulator.
14651
14652For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14653unsegmented variant of the Z8000 architecture) or the Z8001 (the
14654segmented variant). The simulator recognizes which architecture is
14655appropriate by inspecting the object code.
104c1213 14656
8e04817f
AC
14657@table @code
14658@item target sim @var{args}
14659@kindex sim
14660@kindex target sim@r{, with Z8000}
14661Debug programs on a simulated CPU. If the simulator supports setup
14662options, specify them via @var{args}.
104c1213
JM
14663@end table
14664
8e04817f
AC
14665@noindent
14666After specifying this target, you can debug programs for the simulated
14667CPU in the same style as programs for your host computer; use the
14668@code{file} command to load a new program image, the @code{run} command
14669to run your program, and so on.
14670
14671As well as making available all the usual machine registers
14672(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14673additional items of information as specially named registers:
104c1213
JM
14674
14675@table @code
14676
8e04817f
AC
14677@item cycles
14678Counts clock-ticks in the simulator.
104c1213 14679
8e04817f
AC
14680@item insts
14681Counts instructions run in the simulator.
104c1213 14682
8e04817f
AC
14683@item time
14684Execution time in 60ths of a second.
104c1213 14685
8e04817f 14686@end table
104c1213 14687
8e04817f
AC
14688You can refer to these values in @value{GDBN} expressions with the usual
14689conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14690conditional breakpoint that suspends only after at least 5000
14691simulated clock ticks.
104c1213 14692
a64548ea
EZ
14693@node AVR
14694@subsection Atmel AVR
14695@cindex AVR
14696
14697When configured for debugging the Atmel AVR, @value{GDBN} supports the
14698following AVR-specific commands:
14699
14700@table @code
14701@item info io_registers
14702@kindex info io_registers@r{, AVR}
14703@cindex I/O registers (Atmel AVR)
14704This command displays information about the AVR I/O registers. For
14705each register, @value{GDBN} prints its number and value.
14706@end table
14707
14708@node CRIS
14709@subsection CRIS
14710@cindex CRIS
14711
14712When configured for debugging CRIS, @value{GDBN} provides the
14713following CRIS-specific commands:
14714
14715@table @code
14716@item set cris-version @var{ver}
14717@cindex CRIS version
e22e55c9
OF
14718Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14719The CRIS version affects register names and sizes. This command is useful in
14720case autodetection of the CRIS version fails.
a64548ea
EZ
14721
14722@item show cris-version
14723Show the current CRIS version.
14724
14725@item set cris-dwarf2-cfi
14726@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14727Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14728Change to @samp{off} when using @code{gcc-cris} whose version is below
14729@code{R59}.
a64548ea
EZ
14730
14731@item show cris-dwarf2-cfi
14732Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14733
14734@item set cris-mode @var{mode}
14735@cindex CRIS mode
14736Set the current CRIS mode to @var{mode}. It should only be changed when
14737debugging in guru mode, in which case it should be set to
14738@samp{guru} (the default is @samp{normal}).
14739
14740@item show cris-mode
14741Show the current CRIS mode.
a64548ea
EZ
14742@end table
14743
14744@node Super-H
14745@subsection Renesas Super-H
14746@cindex Super-H
14747
14748For the Renesas Super-H processor, @value{GDBN} provides these
14749commands:
14750
14751@table @code
14752@item regs
14753@kindex regs@r{, Super-H}
14754Show the values of all Super-H registers.
14755@end table
14756
c45da7e6
EZ
14757@node WinCE
14758@subsection Windows CE
14759@cindex Windows CE
14760
14761The following commands are available for Windows CE:
14762
14763@table @code
14764@item set remotedirectory @var{dir}
14765@kindex set remotedirectory
14766Tell @value{GDBN} to upload files from the named directory @var{dir}.
14767The default is @file{/gdb}, i.e.@: the root directory on the current
14768drive.
14769
14770@item show remotedirectory
14771@kindex show remotedirectory
14772Show the current value of the upload directory.
14773
14774@item set remoteupload @var{method}
14775@kindex set remoteupload
14776Set the method used to upload files to remote device. Valid values
14777for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14778The default is @samp{newer}.
14779
14780@item show remoteupload
14781@kindex show remoteupload
14782Show the current setting of the upload method.
14783
14784@item set remoteaddhost
14785@kindex set remoteaddhost
14786Tell @value{GDBN} whether to add this host to the remote stub's
14787arguments when you debug over a network.
14788
14789@item show remoteaddhost
14790@kindex show remoteaddhost
14791Show whether to add this host to remote stub's arguments when
14792debugging over a network.
14793@end table
14794
a64548ea 14795
8e04817f
AC
14796@node Architectures
14797@section Architectures
104c1213 14798
8e04817f
AC
14799This section describes characteristics of architectures that affect
14800all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14801
8e04817f 14802@menu
9c16f35a 14803* i386::
8e04817f
AC
14804* A29K::
14805* Alpha::
14806* MIPS::
a64548ea 14807* HPPA:: HP PA architecture
8e04817f 14808@end menu
104c1213 14809
9c16f35a
EZ
14810@node i386
14811@subsection x86 Architecture-specific issues.
14812
14813@table @code
14814@item set struct-convention @var{mode}
14815@kindex set struct-convention
14816@cindex struct return convention
14817@cindex struct/union returned in registers
14818Set the convention used by the inferior to return @code{struct}s and
14819@code{union}s from functions to @var{mode}. Possible values of
14820@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14821default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14822are returned on the stack, while @code{"reg"} means that a
14823@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14824be returned in a register.
14825
14826@item show struct-convention
14827@kindex show struct-convention
14828Show the current setting of the convention to return @code{struct}s
14829from functions.
14830@end table
14831
8e04817f
AC
14832@node A29K
14833@subsection A29K
104c1213
JM
14834
14835@table @code
104c1213 14836
8e04817f
AC
14837@kindex set rstack_high_address
14838@cindex AMD 29K register stack
14839@cindex register stack, AMD29K
14840@item set rstack_high_address @var{address}
14841On AMD 29000 family processors, registers are saved in a separate
14842@dfn{register stack}. There is no way for @value{GDBN} to determine the
14843extent of this stack. Normally, @value{GDBN} just assumes that the
14844stack is ``large enough''. This may result in @value{GDBN} referencing
14845memory locations that do not exist. If necessary, you can get around
14846this problem by specifying the ending address of the register stack with
14847the @code{set rstack_high_address} command. The argument should be an
14848address, which you probably want to precede with @samp{0x} to specify in
14849hexadecimal.
104c1213 14850
8e04817f
AC
14851@kindex show rstack_high_address
14852@item show rstack_high_address
14853Display the current limit of the register stack, on AMD 29000 family
14854processors.
104c1213 14855
8e04817f 14856@end table
104c1213 14857
8e04817f
AC
14858@node Alpha
14859@subsection Alpha
104c1213 14860
8e04817f 14861See the following section.
104c1213 14862
8e04817f
AC
14863@node MIPS
14864@subsection MIPS
104c1213 14865
8e04817f
AC
14866@cindex stack on Alpha
14867@cindex stack on MIPS
14868@cindex Alpha stack
14869@cindex MIPS stack
14870Alpha- and MIPS-based computers use an unusual stack frame, which
14871sometimes requires @value{GDBN} to search backward in the object code to
14872find the beginning of a function.
104c1213 14873
8e04817f
AC
14874@cindex response time, MIPS debugging
14875To improve response time (especially for embedded applications, where
14876@value{GDBN} may be restricted to a slow serial line for this search)
14877you may want to limit the size of this search, using one of these
14878commands:
104c1213 14879
8e04817f
AC
14880@table @code
14881@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14882@item set heuristic-fence-post @var{limit}
14883Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14884search for the beginning of a function. A value of @var{0} (the
14885default) means there is no limit. However, except for @var{0}, the
14886larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14887and therefore the longer it takes to run. You should only need to use
14888this command when debugging a stripped executable.
104c1213 14889
8e04817f
AC
14890@item show heuristic-fence-post
14891Display the current limit.
14892@end table
104c1213
JM
14893
14894@noindent
8e04817f
AC
14895These commands are available @emph{only} when @value{GDBN} is configured
14896for debugging programs on Alpha or MIPS processors.
104c1213 14897
a64548ea
EZ
14898Several MIPS-specific commands are available when debugging MIPS
14899programs:
14900
14901@table @code
14902@item set mips saved-gpreg-size @var{size}
14903@kindex set mips saved-gpreg-size
14904@cindex MIPS GP register size on stack
14905Set the size of MIPS general-purpose registers saved on the stack.
14906The argument @var{size} can be one of the following:
14907
14908@table @samp
14909@item 32
1491032-bit GP registers
14911@item 64
1491264-bit GP registers
14913@item auto
14914Use the target's default setting or autodetect the saved size from the
14915information contained in the executable. This is the default
14916@end table
14917
14918@item show mips saved-gpreg-size
14919@kindex show mips saved-gpreg-size
14920Show the current size of MIPS GP registers on the stack.
14921
14922@item set mips stack-arg-size @var{size}
14923@kindex set mips stack-arg-size
14924@cindex MIPS stack space for arguments
14925Set the amount of stack space reserved for arguments to functions.
14926The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14927(the default).
14928
14929@item set mips abi @var{arg}
14930@kindex set mips abi
14931@cindex set ABI for MIPS
14932Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14933values of @var{arg} are:
14934
14935@table @samp
14936@item auto
14937The default ABI associated with the current binary (this is the
14938default).
14939@item o32
14940@item o64
14941@item n32
14942@item n64
14943@item eabi32
14944@item eabi64
14945@item auto
14946@end table
14947
14948@item show mips abi
14949@kindex show mips abi
14950Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14951
14952@item set mipsfpu
14953@itemx show mipsfpu
14954@xref{MIPS Embedded, set mipsfpu}.
14955
14956@item set mips mask-address @var{arg}
14957@kindex set mips mask-address
14958@cindex MIPS addresses, masking
14959This command determines whether the most-significant 32 bits of 64-bit
14960MIPS addresses are masked off. The argument @var{arg} can be
14961@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14962setting, which lets @value{GDBN} determine the correct value.
14963
14964@item show mips mask-address
14965@kindex show mips mask-address
14966Show whether the upper 32 bits of MIPS addresses are masked off or
14967not.
14968
14969@item set remote-mips64-transfers-32bit-regs
14970@kindex set remote-mips64-transfers-32bit-regs
14971This command controls compatibility with 64-bit MIPS targets that
14972transfer data in 32-bit quantities. If you have an old MIPS 64 target
14973that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14974and 64 bits for other registers, set this option to @samp{on}.
14975
14976@item show remote-mips64-transfers-32bit-regs
14977@kindex show remote-mips64-transfers-32bit-regs
14978Show the current setting of compatibility with older MIPS 64 targets.
14979
14980@item set debug mips
14981@kindex set debug mips
14982This command turns on and off debugging messages for the MIPS-specific
14983target code in @value{GDBN}.
14984
14985@item show debug mips
14986@kindex show debug mips
14987Show the current setting of MIPS debugging messages.
14988@end table
14989
14990
14991@node HPPA
14992@subsection HPPA
14993@cindex HPPA support
14994
14995When @value{GDBN} is debugging te HP PA architecture, it provides the
14996following special commands:
14997
14998@table @code
14999@item set debug hppa
15000@kindex set debug hppa
15001THis command determines whether HPPA architecture specific debugging
15002messages are to be displayed.
15003
15004@item show debug hppa
15005Show whether HPPA debugging messages are displayed.
15006
15007@item maint print unwind @var{address}
15008@kindex maint print unwind@r{, HPPA}
15009This command displays the contents of the unwind table entry at the
15010given @var{address}.
15011
15012@end table
15013
104c1213 15014
8e04817f
AC
15015@node Controlling GDB
15016@chapter Controlling @value{GDBN}
15017
15018You can alter the way @value{GDBN} interacts with you by using the
15019@code{set} command. For commands controlling how @value{GDBN} displays
15020data, see @ref{Print Settings, ,Print settings}. Other settings are
15021described here.
15022
15023@menu
15024* Prompt:: Prompt
15025* Editing:: Command editing
d620b259 15026* Command History:: Command history
8e04817f
AC
15027* Screen Size:: Screen size
15028* Numbers:: Numbers
1e698235 15029* ABI:: Configuring the current ABI
8e04817f
AC
15030* Messages/Warnings:: Optional warnings and messages
15031* Debugging Output:: Optional messages about internal happenings
15032@end menu
15033
15034@node Prompt
15035@section Prompt
104c1213 15036
8e04817f 15037@cindex prompt
104c1213 15038
8e04817f
AC
15039@value{GDBN} indicates its readiness to read a command by printing a string
15040called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15041can change the prompt string with the @code{set prompt} command. For
15042instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15043the prompt in one of the @value{GDBN} sessions so that you can always tell
15044which one you are talking to.
104c1213 15045
8e04817f
AC
15046@emph{Note:} @code{set prompt} does not add a space for you after the
15047prompt you set. This allows you to set a prompt which ends in a space
15048or a prompt that does not.
104c1213 15049
8e04817f
AC
15050@table @code
15051@kindex set prompt
15052@item set prompt @var{newprompt}
15053Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15054
8e04817f
AC
15055@kindex show prompt
15056@item show prompt
15057Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15058@end table
15059
8e04817f
AC
15060@node Editing
15061@section Command editing
15062@cindex readline
15063@cindex command line editing
104c1213 15064
703663ab 15065@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15066@sc{gnu} library provides consistent behavior for programs which provide a
15067command line interface to the user. Advantages are @sc{gnu} Emacs-style
15068or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15069substitution, and a storage and recall of command history across
15070debugging sessions.
104c1213 15071
8e04817f
AC
15072You may control the behavior of command line editing in @value{GDBN} with the
15073command @code{set}.
104c1213 15074
8e04817f
AC
15075@table @code
15076@kindex set editing
15077@cindex editing
15078@item set editing
15079@itemx set editing on
15080Enable command line editing (enabled by default).
104c1213 15081
8e04817f
AC
15082@item set editing off
15083Disable command line editing.
104c1213 15084
8e04817f
AC
15085@kindex show editing
15086@item show editing
15087Show whether command line editing is enabled.
104c1213
JM
15088@end table
15089
703663ab
EZ
15090@xref{Command Line Editing}, for more details about the Readline
15091interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15092encouraged to read that chapter.
15093
d620b259 15094@node Command History
8e04817f 15095@section Command history
703663ab 15096@cindex command history
8e04817f
AC
15097
15098@value{GDBN} can keep track of the commands you type during your
15099debugging sessions, so that you can be certain of precisely what
15100happened. Use these commands to manage the @value{GDBN} command
15101history facility.
104c1213 15102
703663ab
EZ
15103@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15104package, to provide the history facility. @xref{Using History
15105Interactively}, for the detailed description of the History library.
15106
d620b259
NR
15107To issue a command to @value{GDBN} without affecting certain aspects of
15108the state which is seen by users, prefix it with @samp{server }. This
15109means that this command will not affect the command history, nor will it
15110affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15111pressed on a line by itself.
15112
15113@cindex @code{server}, command prefix
15114The server prefix does not affect the recording of values into the value
15115history; to print a value without recording it into the value history,
15116use the @code{output} command instead of the @code{print} command.
15117
703663ab
EZ
15118Here is the description of @value{GDBN} commands related to command
15119history.
15120
104c1213 15121@table @code
8e04817f
AC
15122@cindex history substitution
15123@cindex history file
15124@kindex set history filename
4644b6e3 15125@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15126@item set history filename @var{fname}
15127Set the name of the @value{GDBN} command history file to @var{fname}.
15128This is the file where @value{GDBN} reads an initial command history
15129list, and where it writes the command history from this session when it
15130exits. You can access this list through history expansion or through
15131the history command editing characters listed below. This file defaults
15132to the value of the environment variable @code{GDBHISTFILE}, or to
15133@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15134is not set.
104c1213 15135
9c16f35a
EZ
15136@cindex save command history
15137@kindex set history save
8e04817f
AC
15138@item set history save
15139@itemx set history save on
15140Record command history in a file, whose name may be specified with the
15141@code{set history filename} command. By default, this option is disabled.
104c1213 15142
8e04817f
AC
15143@item set history save off
15144Stop recording command history in a file.
104c1213 15145
8e04817f 15146@cindex history size
9c16f35a 15147@kindex set history size
6fc08d32 15148@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15149@item set history size @var{size}
15150Set the number of commands which @value{GDBN} keeps in its history list.
15151This defaults to the value of the environment variable
15152@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15153@end table
15154
8e04817f 15155History expansion assigns special meaning to the character @kbd{!}.
703663ab 15156@xref{Event Designators}, for more details.
8e04817f 15157
703663ab 15158@cindex history expansion, turn on/off
8e04817f
AC
15159Since @kbd{!} is also the logical not operator in C, history expansion
15160is off by default. If you decide to enable history expansion with the
15161@code{set history expansion on} command, you may sometimes need to
15162follow @kbd{!} (when it is used as logical not, in an expression) with
15163a space or a tab to prevent it from being expanded. The readline
15164history facilities do not attempt substitution on the strings
15165@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15166
15167The commands to control history expansion are:
104c1213
JM
15168
15169@table @code
8e04817f
AC
15170@item set history expansion on
15171@itemx set history expansion
703663ab 15172@kindex set history expansion
8e04817f 15173Enable history expansion. History expansion is off by default.
104c1213 15174
8e04817f
AC
15175@item set history expansion off
15176Disable history expansion.
104c1213 15177
8e04817f
AC
15178@c @group
15179@kindex show history
15180@item show history
15181@itemx show history filename
15182@itemx show history save
15183@itemx show history size
15184@itemx show history expansion
15185These commands display the state of the @value{GDBN} history parameters.
15186@code{show history} by itself displays all four states.
15187@c @end group
15188@end table
15189
15190@table @code
9c16f35a
EZ
15191@kindex show commands
15192@cindex show last commands
15193@cindex display command history
8e04817f
AC
15194@item show commands
15195Display the last ten commands in the command history.
104c1213 15196
8e04817f
AC
15197@item show commands @var{n}
15198Print ten commands centered on command number @var{n}.
15199
15200@item show commands +
15201Print ten commands just after the commands last printed.
104c1213
JM
15202@end table
15203
8e04817f
AC
15204@node Screen Size
15205@section Screen size
15206@cindex size of screen
15207@cindex pauses in output
104c1213 15208
8e04817f
AC
15209Certain commands to @value{GDBN} may produce large amounts of
15210information output to the screen. To help you read all of it,
15211@value{GDBN} pauses and asks you for input at the end of each page of
15212output. Type @key{RET} when you want to continue the output, or @kbd{q}
15213to discard the remaining output. Also, the screen width setting
15214determines when to wrap lines of output. Depending on what is being
15215printed, @value{GDBN} tries to break the line at a readable place,
15216rather than simply letting it overflow onto the following line.
15217
15218Normally @value{GDBN} knows the size of the screen from the terminal
15219driver software. For example, on Unix @value{GDBN} uses the termcap data base
15220together with the value of the @code{TERM} environment variable and the
15221@code{stty rows} and @code{stty cols} settings. If this is not correct,
15222you can override it with the @code{set height} and @code{set
15223width} commands:
15224
15225@table @code
15226@kindex set height
15227@kindex set width
15228@kindex show width
15229@kindex show height
15230@item set height @var{lpp}
15231@itemx show height
15232@itemx set width @var{cpl}
15233@itemx show width
15234These @code{set} commands specify a screen height of @var{lpp} lines and
15235a screen width of @var{cpl} characters. The associated @code{show}
15236commands display the current settings.
104c1213 15237
8e04817f
AC
15238If you specify a height of zero lines, @value{GDBN} does not pause during
15239output no matter how long the output is. This is useful if output is to a
15240file or to an editor buffer.
104c1213 15241
8e04817f
AC
15242Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15243from wrapping its output.
9c16f35a
EZ
15244
15245@item set pagination on
15246@itemx set pagination off
15247@kindex set pagination
15248Turn the output pagination on or off; the default is on. Turning
15249pagination off is the alternative to @code{set height 0}.
15250
15251@item show pagination
15252@kindex show pagination
15253Show the current pagination mode.
104c1213
JM
15254@end table
15255
8e04817f
AC
15256@node Numbers
15257@section Numbers
15258@cindex number representation
15259@cindex entering numbers
104c1213 15260
8e04817f
AC
15261You can always enter numbers in octal, decimal, or hexadecimal in
15262@value{GDBN} by the usual conventions: octal numbers begin with
15263@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15264begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15265@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1526610; likewise, the default display for numbers---when no particular
15267format is specified---is base 10. You can change the default base for
15268both input and output with the commands described below.
104c1213 15269
8e04817f
AC
15270@table @code
15271@kindex set input-radix
15272@item set input-radix @var{base}
15273Set the default base for numeric input. Supported choices
15274for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15275specified either unambiguously or using the current input radix; for
8e04817f 15276example, any of
104c1213 15277
8e04817f 15278@smallexample
9c16f35a
EZ
15279set input-radix 012
15280set input-radix 10.
15281set input-radix 0xa
8e04817f 15282@end smallexample
104c1213 15283
8e04817f 15284@noindent
9c16f35a 15285sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15286leaves the input radix unchanged, no matter what it was, since
15287@samp{10}, being without any leading or trailing signs of its base, is
15288interpreted in the current radix. Thus, if the current radix is 16,
15289@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15290change the radix.
104c1213 15291
8e04817f
AC
15292@kindex set output-radix
15293@item set output-radix @var{base}
15294Set the default base for numeric display. Supported choices
15295for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15296specified either unambiguously or using the current input radix.
104c1213 15297
8e04817f
AC
15298@kindex show input-radix
15299@item show input-radix
15300Display the current default base for numeric input.
104c1213 15301
8e04817f
AC
15302@kindex show output-radix
15303@item show output-radix
15304Display the current default base for numeric display.
9c16f35a
EZ
15305
15306@item set radix @r{[}@var{base}@r{]}
15307@itemx show radix
15308@kindex set radix
15309@kindex show radix
15310These commands set and show the default base for both input and output
15311of numbers. @code{set radix} sets the radix of input and output to
15312the same base; without an argument, it resets the radix back to its
15313default value of 10.
15314
8e04817f 15315@end table
104c1213 15316
1e698235
DJ
15317@node ABI
15318@section Configuring the current ABI
15319
15320@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15321application automatically. However, sometimes you need to override its
15322conclusions. Use these commands to manage @value{GDBN}'s view of the
15323current ABI.
15324
98b45e30
DJ
15325@cindex OS ABI
15326@kindex set osabi
b4e9345d 15327@kindex show osabi
98b45e30
DJ
15328
15329One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15330system targets, either via remote debugging or native emulation.
98b45e30
DJ
15331@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15332but you can override its conclusion using the @code{set osabi} command.
15333One example where this is useful is in debugging of binaries which use
15334an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15335not have the same identifying marks that the standard C library for your
15336platform provides.
15337
15338@table @code
15339@item show osabi
15340Show the OS ABI currently in use.
15341
15342@item set osabi
15343With no argument, show the list of registered available OS ABI's.
15344
15345@item set osabi @var{abi}
15346Set the current OS ABI to @var{abi}.
15347@end table
15348
1e698235 15349@cindex float promotion
1e698235
DJ
15350
15351Generally, the way that an argument of type @code{float} is passed to a
15352function depends on whether the function is prototyped. For a prototyped
15353(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15354according to the architecture's convention for @code{float}. For unprototyped
15355(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15356@code{double} and then passed.
15357
15358Unfortunately, some forms of debug information do not reliably indicate whether
15359a function is prototyped. If @value{GDBN} calls a function that is not marked
15360as prototyped, it consults @kbd{set coerce-float-to-double}.
15361
15362@table @code
a8f24a35 15363@kindex set coerce-float-to-double
1e698235
DJ
15364@item set coerce-float-to-double
15365@itemx set coerce-float-to-double on
15366Arguments of type @code{float} will be promoted to @code{double} when passed
15367to an unprototyped function. This is the default setting.
15368
15369@item set coerce-float-to-double off
15370Arguments of type @code{float} will be passed directly to unprototyped
15371functions.
9c16f35a
EZ
15372
15373@kindex show coerce-float-to-double
15374@item show coerce-float-to-double
15375Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15376@end table
15377
f1212245
DJ
15378@kindex set cp-abi
15379@kindex show cp-abi
15380@value{GDBN} needs to know the ABI used for your program's C@t{++}
15381objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15382used to build your application. @value{GDBN} only fully supports
15383programs with a single C@t{++} ABI; if your program contains code using
15384multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15385program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15386Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15387before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15388``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15389use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15390``auto''.
15391
15392@table @code
15393@item show cp-abi
15394Show the C@t{++} ABI currently in use.
15395
15396@item set cp-abi
15397With no argument, show the list of supported C@t{++} ABI's.
15398
15399@item set cp-abi @var{abi}
15400@itemx set cp-abi auto
15401Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15402@end table
15403
8e04817f
AC
15404@node Messages/Warnings
15405@section Optional warnings and messages
104c1213 15406
9c16f35a
EZ
15407@cindex verbose operation
15408@cindex optional warnings
8e04817f
AC
15409By default, @value{GDBN} is silent about its inner workings. If you are
15410running on a slow machine, you may want to use the @code{set verbose}
15411command. This makes @value{GDBN} tell you when it does a lengthy
15412internal operation, so you will not think it has crashed.
104c1213 15413
8e04817f
AC
15414Currently, the messages controlled by @code{set verbose} are those
15415which announce that the symbol table for a source file is being read;
15416see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15417
8e04817f
AC
15418@table @code
15419@kindex set verbose
15420@item set verbose on
15421Enables @value{GDBN} output of certain informational messages.
104c1213 15422
8e04817f
AC
15423@item set verbose off
15424Disables @value{GDBN} output of certain informational messages.
104c1213 15425
8e04817f
AC
15426@kindex show verbose
15427@item show verbose
15428Displays whether @code{set verbose} is on or off.
15429@end table
104c1213 15430
8e04817f
AC
15431By default, if @value{GDBN} encounters bugs in the symbol table of an
15432object file, it is silent; but if you are debugging a compiler, you may
15433find this information useful (@pxref{Symbol Errors, ,Errors reading
15434symbol files}).
104c1213 15435
8e04817f 15436@table @code
104c1213 15437
8e04817f
AC
15438@kindex set complaints
15439@item set complaints @var{limit}
15440Permits @value{GDBN} to output @var{limit} complaints about each type of
15441unusual symbols before becoming silent about the problem. Set
15442@var{limit} to zero to suppress all complaints; set it to a large number
15443to prevent complaints from being suppressed.
104c1213 15444
8e04817f
AC
15445@kindex show complaints
15446@item show complaints
15447Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15448
8e04817f 15449@end table
104c1213 15450
8e04817f
AC
15451By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15452lot of stupid questions to confirm certain commands. For example, if
15453you try to run a program which is already running:
104c1213 15454
474c8240 15455@smallexample
8e04817f
AC
15456(@value{GDBP}) run
15457The program being debugged has been started already.
15458Start it from the beginning? (y or n)
474c8240 15459@end smallexample
104c1213 15460
8e04817f
AC
15461If you are willing to unflinchingly face the consequences of your own
15462commands, you can disable this ``feature'':
104c1213 15463
8e04817f 15464@table @code
104c1213 15465
8e04817f
AC
15466@kindex set confirm
15467@cindex flinching
15468@cindex confirmation
15469@cindex stupid questions
15470@item set confirm off
15471Disables confirmation requests.
104c1213 15472
8e04817f
AC
15473@item set confirm on
15474Enables confirmation requests (the default).
104c1213 15475
8e04817f
AC
15476@kindex show confirm
15477@item show confirm
15478Displays state of confirmation requests.
15479
15480@end table
104c1213 15481
8e04817f
AC
15482@node Debugging Output
15483@section Optional messages about internal happenings
4644b6e3
EZ
15484@cindex optional debugging messages
15485
da316a69
EZ
15486@value{GDBN} has commands that enable optional debugging messages from
15487various @value{GDBN} subsystems; normally these commands are of
15488interest to @value{GDBN} maintainers, or when reporting a bug. This
15489section documents those commands.
15490
104c1213 15491@table @code
a8f24a35
EZ
15492@kindex set exec-done-display
15493@item set exec-done-display
15494Turns on or off the notification of asynchronous commands'
15495completion. When on, @value{GDBN} will print a message when an
15496asynchronous command finishes its execution. The default is off.
15497@kindex show exec-done-display
15498@item show exec-done-display
15499Displays the current setting of asynchronous command completion
15500notification.
4644b6e3
EZ
15501@kindex set debug
15502@cindex gdbarch debugging info
a8f24a35 15503@cindex architecture debugging info
8e04817f 15504@item set debug arch
a8f24a35 15505Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15506@kindex show debug
8e04817f
AC
15507@item show debug arch
15508Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15509@item set debug aix-thread
15510@cindex AIX threads
15511Display debugging messages about inner workings of the AIX thread
15512module.
15513@item show debug aix-thread
15514Show the current state of AIX thread debugging info display.
8e04817f 15515@item set debug event
4644b6e3 15516@cindex event debugging info
a8f24a35 15517Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15518default is off.
8e04817f
AC
15519@item show debug event
15520Displays the current state of displaying @value{GDBN} event debugging
15521info.
8e04817f 15522@item set debug expression
4644b6e3 15523@cindex expression debugging info
721c2651
EZ
15524Turns on or off display of debugging info about @value{GDBN}
15525expression parsing. The default is off.
8e04817f 15526@item show debug expression
721c2651
EZ
15527Displays the current state of displaying debugging info about
15528@value{GDBN} expression parsing.
7453dc06 15529@item set debug frame
4644b6e3 15530@cindex frame debugging info
7453dc06
AC
15531Turns on or off display of @value{GDBN} frame debugging info. The
15532default is off.
7453dc06
AC
15533@item show debug frame
15534Displays the current state of displaying @value{GDBN} frame debugging
15535info.
30e91e0b
RC
15536@item set debug infrun
15537@cindex inferior debugging info
15538Turns on or off display of @value{GDBN} debugging info for running the inferior.
15539The default is off. @file{infrun.c} contains GDB's runtime state machine used
15540for implementing operations such as single-stepping the inferior.
15541@item show debug infrun
15542Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15543@item set debug lin-lwp
15544@cindex @sc{gnu}/Linux LWP debug messages
15545@cindex Linux lightweight processes
721c2651 15546Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15547@item show debug lin-lwp
15548Show the current state of Linux LWP debugging messages.
2b4855ab 15549@item set debug observer
4644b6e3 15550@cindex observer debugging info
2b4855ab
AC
15551Turns on or off display of @value{GDBN} observer debugging. This
15552includes info such as the notification of observable events.
2b4855ab
AC
15553@item show debug observer
15554Displays the current state of observer debugging.
8e04817f 15555@item set debug overload
4644b6e3 15556@cindex C@t{++} overload debugging info
8e04817f
AC
15557Turns on or off display of @value{GDBN} C@t{++} overload debugging
15558info. This includes info such as ranking of functions, etc. The default
15559is off.
8e04817f
AC
15560@item show debug overload
15561Displays the current state of displaying @value{GDBN} C@t{++} overload
15562debugging info.
8e04817f
AC
15563@cindex packets, reporting on stdout
15564@cindex serial connections, debugging
15565@item set debug remote
15566Turns on or off display of reports on all packets sent back and forth across
15567the serial line to the remote machine. The info is printed on the
15568@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15569@item show debug remote
15570Displays the state of display of remote packets.
8e04817f
AC
15571@item set debug serial
15572Turns on or off display of @value{GDBN} serial debugging info. The
15573default is off.
8e04817f
AC
15574@item show debug serial
15575Displays the current state of displaying @value{GDBN} serial debugging
15576info.
c45da7e6
EZ
15577@item set debug solib-frv
15578@cindex FR-V shared-library debugging
15579Turns on or off debugging messages for FR-V shared-library code.
15580@item show debug solib-frv
15581Display the current state of FR-V shared-library code debugging
15582messages.
8e04817f 15583@item set debug target
4644b6e3 15584@cindex target debugging info
8e04817f
AC
15585Turns on or off display of @value{GDBN} target debugging info. This info
15586includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15587default is 0. Set it to 1 to track events, and to 2 to also track the
15588value of large memory transfers. Changes to this flag do not take effect
15589until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15590@item show debug target
15591Displays the current state of displaying @value{GDBN} target debugging
15592info.
c45da7e6 15593@item set debugvarobj
4644b6e3 15594@cindex variable object debugging info
8e04817f
AC
15595Turns on or off display of @value{GDBN} variable object debugging
15596info. The default is off.
c45da7e6 15597@item show debugvarobj
8e04817f
AC
15598Displays the current state of displaying @value{GDBN} variable object
15599debugging info.
15600@end table
104c1213 15601
8e04817f
AC
15602@node Sequences
15603@chapter Canned Sequences of Commands
104c1213 15604
8e04817f
AC
15605Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15606command lists}), @value{GDBN} provides two ways to store sequences of
15607commands for execution as a unit: user-defined commands and command
15608files.
104c1213 15609
8e04817f
AC
15610@menu
15611* Define:: User-defined commands
15612* Hooks:: User-defined command hooks
15613* Command Files:: Command files
15614* Output:: Commands for controlled output
15615@end menu
104c1213 15616
8e04817f
AC
15617@node Define
15618@section User-defined commands
104c1213 15619
8e04817f
AC
15620@cindex user-defined command
15621A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15622which you assign a new name as a command. This is done with the
15623@code{define} command. User commands may accept up to 10 arguments
15624separated by whitespace. Arguments are accessed within the user command
15625via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15626
8e04817f
AC
15627@smallexample
15628define adder
15629 print $arg0 + $arg1 + $arg2
15630@end smallexample
104c1213
JM
15631
15632@noindent
8e04817f 15633To execute the command use:
104c1213 15634
8e04817f
AC
15635@smallexample
15636adder 1 2 3
15637@end smallexample
104c1213 15638
8e04817f
AC
15639@noindent
15640This defines the command @code{adder}, which prints the sum of
15641its three arguments. Note the arguments are text substitutions, so they may
15642reference variables, use complex expressions, or even perform inferior
15643functions calls.
104c1213
JM
15644
15645@table @code
104c1213 15646
8e04817f
AC
15647@kindex define
15648@item define @var{commandname}
15649Define a command named @var{commandname}. If there is already a command
15650by that name, you are asked to confirm that you want to redefine it.
104c1213 15651
8e04817f
AC
15652The definition of the command is made up of other @value{GDBN} command lines,
15653which are given following the @code{define} command. The end of these
15654commands is marked by a line containing @code{end}.
104c1213 15655
8e04817f
AC
15656@kindex if
15657@kindex else
15658@item if
09d4efe1 15659@itemx else
8e04817f
AC
15660Takes a single argument, which is an expression to evaluate.
15661It is followed by a series of commands that are executed
15662only if the expression is true (nonzero).
15663There can then optionally be a line @code{else}, followed
15664by a series of commands that are only executed if the expression
15665was false. The end of the list is marked by a line containing @code{end}.
104c1213 15666
8e04817f
AC
15667@kindex while
15668@item while
15669The syntax is similar to @code{if}: the command takes a single argument,
15670which is an expression to evaluate, and must be followed by the commands to
15671execute, one per line, terminated by an @code{end}.
15672The commands are executed repeatedly as long as the expression
15673evaluates to true.
104c1213 15674
8e04817f
AC
15675@kindex document
15676@item document @var{commandname}
15677Document the user-defined command @var{commandname}, so that it can be
15678accessed by @code{help}. The command @var{commandname} must already be
15679defined. This command reads lines of documentation just as @code{define}
15680reads the lines of the command definition, ending with @code{end}.
15681After the @code{document} command is finished, @code{help} on command
15682@var{commandname} displays the documentation you have written.
104c1213 15683
8e04817f
AC
15684You may use the @code{document} command again to change the
15685documentation of a command. Redefining the command with @code{define}
15686does not change the documentation.
104c1213 15687
c45da7e6
EZ
15688@kindex dont-repeat
15689@cindex don't repeat command
15690@item dont-repeat
15691Used inside a user-defined command, this tells @value{GDBN} that this
15692command should not be repeated when the user hits @key{RET}
15693(@pxref{Command Syntax, repeat last command}).
15694
8e04817f
AC
15695@kindex help user-defined
15696@item help user-defined
15697List all user-defined commands, with the first line of the documentation
15698(if any) for each.
104c1213 15699
8e04817f
AC
15700@kindex show user
15701@item show user
15702@itemx show user @var{commandname}
15703Display the @value{GDBN} commands used to define @var{commandname} (but
15704not its documentation). If no @var{commandname} is given, display the
15705definitions for all user-defined commands.
104c1213 15706
9c16f35a 15707@cindex infinite recusrion in user-defined commands
20f01a46
DH
15708@kindex show max-user-call-depth
15709@kindex set max-user-call-depth
15710@item show max-user-call-depth
5ca0cb28
DH
15711@itemx set max-user-call-depth
15712The value of @code{max-user-call-depth} controls how many recursion
15713levels are allowed in user-defined commands before GDB suspects an
15714infinite recursion and aborts the command.
20f01a46 15715
104c1213
JM
15716@end table
15717
8e04817f
AC
15718When user-defined commands are executed, the
15719commands of the definition are not printed. An error in any command
15720stops execution of the user-defined command.
104c1213 15721
8e04817f
AC
15722If used interactively, commands that would ask for confirmation proceed
15723without asking when used inside a user-defined command. Many @value{GDBN}
15724commands that normally print messages to say what they are doing omit the
15725messages when used in a user-defined command.
104c1213 15726
8e04817f
AC
15727@node Hooks
15728@section User-defined command hooks
15729@cindex command hooks
15730@cindex hooks, for commands
15731@cindex hooks, pre-command
104c1213 15732
8e04817f 15733@kindex hook
8e04817f
AC
15734You may define @dfn{hooks}, which are a special kind of user-defined
15735command. Whenever you run the command @samp{foo}, if the user-defined
15736command @samp{hook-foo} exists, it is executed (with no arguments)
15737before that command.
104c1213 15738
8e04817f
AC
15739@cindex hooks, post-command
15740@kindex hookpost
8e04817f
AC
15741A hook may also be defined which is run after the command you executed.
15742Whenever you run the command @samp{foo}, if the user-defined command
15743@samp{hookpost-foo} exists, it is executed (with no arguments) after
15744that command. Post-execution hooks may exist simultaneously with
15745pre-execution hooks, for the same command.
104c1213 15746
8e04817f 15747It is valid for a hook to call the command which it hooks. If this
9f1c6395 15748occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15749
8e04817f
AC
15750@c It would be nice if hookpost could be passed a parameter indicating
15751@c if the command it hooks executed properly or not. FIXME!
104c1213 15752
8e04817f
AC
15753@kindex stop@r{, a pseudo-command}
15754In addition, a pseudo-command, @samp{stop} exists. Defining
15755(@samp{hook-stop}) makes the associated commands execute every time
15756execution stops in your program: before breakpoint commands are run,
15757displays are printed, or the stack frame is printed.
104c1213 15758
8e04817f
AC
15759For example, to ignore @code{SIGALRM} signals while
15760single-stepping, but treat them normally during normal execution,
15761you could define:
104c1213 15762
474c8240 15763@smallexample
8e04817f
AC
15764define hook-stop
15765handle SIGALRM nopass
15766end
104c1213 15767
8e04817f
AC
15768define hook-run
15769handle SIGALRM pass
15770end
104c1213 15771
8e04817f
AC
15772define hook-continue
15773handle SIGLARM pass
15774end
474c8240 15775@end smallexample
104c1213 15776
8e04817f 15777As a further example, to hook at the begining and end of the @code{echo}
b383017d 15778command, and to add extra text to the beginning and end of the message,
8e04817f 15779you could define:
104c1213 15780
474c8240 15781@smallexample
8e04817f
AC
15782define hook-echo
15783echo <<<---
15784end
104c1213 15785
8e04817f
AC
15786define hookpost-echo
15787echo --->>>\n
15788end
104c1213 15789
8e04817f
AC
15790(@value{GDBP}) echo Hello World
15791<<<---Hello World--->>>
15792(@value{GDBP})
104c1213 15793
474c8240 15794@end smallexample
104c1213 15795
8e04817f
AC
15796You can define a hook for any single-word command in @value{GDBN}, but
15797not for command aliases; you should define a hook for the basic command
15798name, e.g. @code{backtrace} rather than @code{bt}.
15799@c FIXME! So how does Joe User discover whether a command is an alias
15800@c or not?
15801If an error occurs during the execution of your hook, execution of
15802@value{GDBN} commands stops and @value{GDBN} issues a prompt
15803(before the command that you actually typed had a chance to run).
104c1213 15804
8e04817f
AC
15805If you try to define a hook which does not match any known command, you
15806get a warning from the @code{define} command.
c906108c 15807
8e04817f
AC
15808@node Command Files
15809@section Command files
c906108c 15810
8e04817f 15811@cindex command files
6fc08d32
EZ
15812A command file for @value{GDBN} is a text file made of lines that are
15813@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15814also be included. An empty line in a command file does nothing; it
15815does not mean to repeat the last command, as it would from the
15816terminal.
c906108c 15817
6fc08d32
EZ
15818You can request the execution of a command file with the @code{source}
15819command:
c906108c 15820
8e04817f
AC
15821@table @code
15822@kindex source
15823@item source @var{filename}
15824Execute the command file @var{filename}.
c906108c
SS
15825@end table
15826
8e04817f 15827The lines in a command file are executed sequentially. They are not
a71ec265
DH
15828printed as they are executed. An error in any command terminates
15829execution of the command file and control is returned to the console.
c906108c 15830
8e04817f
AC
15831Commands that would ask for confirmation if used interactively proceed
15832without asking when used in a command file. Many @value{GDBN} commands that
15833normally print messages to say what they are doing omit the messages
15834when called from command files.
c906108c 15835
8e04817f
AC
15836@value{GDBN} also accepts command input from standard input. In this
15837mode, normal output goes to standard output and error output goes to
15838standard error. Errors in a command file supplied on standard input do
6fc08d32 15839not terminate execution of the command file---execution continues with
8e04817f 15840the next command.
c906108c 15841
474c8240 15842@smallexample
8e04817f 15843gdb < cmds > log 2>&1
474c8240 15844@end smallexample
c906108c 15845
8e04817f
AC
15846(The syntax above will vary depending on the shell used.) This example
15847will execute commands from the file @file{cmds}. All output and errors
15848would be directed to @file{log}.
c906108c 15849
8e04817f
AC
15850@node Output
15851@section Commands for controlled output
c906108c 15852
8e04817f
AC
15853During the execution of a command file or a user-defined command, normal
15854@value{GDBN} output is suppressed; the only output that appears is what is
15855explicitly printed by the commands in the definition. This section
15856describes three commands useful for generating exactly the output you
15857want.
c906108c
SS
15858
15859@table @code
8e04817f
AC
15860@kindex echo
15861@item echo @var{text}
15862@c I do not consider backslash-space a standard C escape sequence
15863@c because it is not in ANSI.
15864Print @var{text}. Nonprinting characters can be included in
15865@var{text} using C escape sequences, such as @samp{\n} to print a
15866newline. @strong{No newline is printed unless you specify one.}
15867In addition to the standard C escape sequences, a backslash followed
15868by a space stands for a space. This is useful for displaying a
15869string with spaces at the beginning or the end, since leading and
15870trailing spaces are otherwise trimmed from all arguments.
15871To print @samp{@w{ }and foo =@w{ }}, use the command
15872@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15873
8e04817f
AC
15874A backslash at the end of @var{text} can be used, as in C, to continue
15875the command onto subsequent lines. For example,
c906108c 15876
474c8240 15877@smallexample
8e04817f
AC
15878echo This is some text\n\
15879which is continued\n\
15880onto several lines.\n
474c8240 15881@end smallexample
c906108c 15882
8e04817f 15883produces the same output as
c906108c 15884
474c8240 15885@smallexample
8e04817f
AC
15886echo This is some text\n
15887echo which is continued\n
15888echo onto several lines.\n
474c8240 15889@end smallexample
c906108c 15890
8e04817f
AC
15891@kindex output
15892@item output @var{expression}
15893Print the value of @var{expression} and nothing but that value: no
15894newlines, no @samp{$@var{nn} = }. The value is not entered in the
15895value history either. @xref{Expressions, ,Expressions}, for more information
15896on expressions.
c906108c 15897
8e04817f
AC
15898@item output/@var{fmt} @var{expression}
15899Print the value of @var{expression} in format @var{fmt}. You can use
15900the same formats as for @code{print}. @xref{Output Formats,,Output
15901formats}, for more information.
c906108c 15902
8e04817f
AC
15903@kindex printf
15904@item printf @var{string}, @var{expressions}@dots{}
15905Print the values of the @var{expressions} under the control of
15906@var{string}. The @var{expressions} are separated by commas and may be
15907either numbers or pointers. Their values are printed as specified by
15908@var{string}, exactly as if your program were to execute the C
15909subroutine
15910@c FIXME: the above implies that at least all ANSI C formats are
15911@c supported, but it isn't true: %E and %G don't work (or so it seems).
15912@c Either this is a bug, or the manual should document what formats are
15913@c supported.
c906108c 15914
474c8240 15915@smallexample
8e04817f 15916printf (@var{string}, @var{expressions}@dots{});
474c8240 15917@end smallexample
c906108c 15918
8e04817f 15919For example, you can print two values in hex like this:
c906108c 15920
8e04817f
AC
15921@smallexample
15922printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15923@end smallexample
c906108c 15924
8e04817f
AC
15925The only backslash-escape sequences that you can use in the format
15926string are the simple ones that consist of backslash followed by a
15927letter.
c906108c
SS
15928@end table
15929
21c294e6
AC
15930@node Interpreters
15931@chapter Command Interpreters
15932@cindex command interpreters
15933
15934@value{GDBN} supports multiple command interpreters, and some command
15935infrastructure to allow users or user interface writers to switch
15936between interpreters or run commands in other interpreters.
15937
15938@value{GDBN} currently supports two command interpreters, the console
15939interpreter (sometimes called the command-line interpreter or @sc{cli})
15940and the machine interface interpreter (or @sc{gdb/mi}). This manual
15941describes both of these interfaces in great detail.
15942
15943By default, @value{GDBN} will start with the console interpreter.
15944However, the user may choose to start @value{GDBN} with another
15945interpreter by specifying the @option{-i} or @option{--interpreter}
15946startup options. Defined interpreters include:
15947
15948@table @code
15949@item console
15950@cindex console interpreter
15951The traditional console or command-line interpreter. This is the most often
15952used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15953@value{GDBN} will use this interpreter.
15954
15955@item mi
15956@cindex mi interpreter
15957The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15958by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15959or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15960Interface}.
15961
15962@item mi2
15963@cindex mi2 interpreter
15964The current @sc{gdb/mi} interface.
15965
15966@item mi1
15967@cindex mi1 interpreter
15968The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15969
15970@end table
15971
15972@cindex invoke another interpreter
15973The interpreter being used by @value{GDBN} may not be dynamically
15974switched at runtime. Although possible, this could lead to a very
15975precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15976enters the command "interpreter-set console" in a console view,
15977@value{GDBN} would switch to using the console interpreter, rendering
15978the IDE inoperable!
15979
15980@kindex interpreter-exec
15981Although you may only choose a single interpreter at startup, you may execute
15982commands in any interpreter from the current interpreter using the appropriate
15983command. If you are running the console interpreter, simply use the
15984@code{interpreter-exec} command:
15985
15986@smallexample
15987interpreter-exec mi "-data-list-register-names"
15988@end smallexample
15989
15990@sc{gdb/mi} has a similar command, although it is only available in versions of
15991@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15992
8e04817f
AC
15993@node TUI
15994@chapter @value{GDBN} Text User Interface
15995@cindex TUI
d0d5df6f 15996@cindex Text User Interface
c906108c 15997
8e04817f
AC
15998@menu
15999* TUI Overview:: TUI overview
16000* TUI Keys:: TUI key bindings
7cf36c78 16001* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16002* TUI Commands:: TUI specific commands
16003* TUI Configuration:: TUI configuration variables
16004@end menu
c906108c 16005
d0d5df6f
AC
16006The @value{GDBN} Text User Interface, TUI in short, is a terminal
16007interface which uses the @code{curses} library to show the source
16008file, the assembly output, the program registers and @value{GDBN}
16009commands in separate text windows.
16010
16011The TUI is enabled by invoking @value{GDBN} using either
16012@pindex gdbtui
16013@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16014
8e04817f
AC
16015@node TUI Overview
16016@section TUI overview
c906108c 16017
8e04817f
AC
16018The TUI has two display modes that can be switched while
16019@value{GDBN} runs:
c906108c 16020
8e04817f
AC
16021@itemize @bullet
16022@item
16023A curses (or TUI) mode in which it displays several text
16024windows on the terminal.
c906108c 16025
8e04817f
AC
16026@item
16027A standard mode which corresponds to the @value{GDBN} configured without
16028the TUI.
16029@end itemize
c906108c 16030
8e04817f
AC
16031In the TUI mode, @value{GDBN} can display several text window
16032on the terminal:
c906108c 16033
8e04817f
AC
16034@table @emph
16035@item command
16036This window is the @value{GDBN} command window with the @value{GDBN}
16037prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16038managed using readline but through the TUI. The @emph{command}
16039window is always visible.
c906108c 16040
8e04817f
AC
16041@item source
16042The source window shows the source file of the program. The current
16043line as well as active breakpoints are displayed in this window.
c906108c 16044
8e04817f
AC
16045@item assembly
16046The assembly window shows the disassembly output of the program.
c906108c 16047
8e04817f
AC
16048@item register
16049This window shows the processor registers. It detects when
16050a register is changed and when this is the case, registers that have
6a1b180d 16051changed are highlighted.
c906108c 16052
c906108c
SS
16053@end table
16054
269c21fe
SC
16055The source and assembly windows show the current program position
16056by highlighting the current line and marking them with the @samp{>} marker.
16057Breakpoints are also indicated with two markers. A first one
16058indicates the breakpoint type:
16059
16060@table @code
16061@item B
16062Breakpoint which was hit at least once.
16063
16064@item b
16065Breakpoint which was never hit.
16066
16067@item H
16068Hardware breakpoint which was hit at least once.
16069
16070@item h
16071Hardware breakpoint which was never hit.
16072
16073@end table
16074
16075The second marker indicates whether the breakpoint is enabled or not:
16076
16077@table @code
16078@item +
16079Breakpoint is enabled.
16080
16081@item -
16082Breakpoint is disabled.
16083
16084@end table
16085
8e04817f
AC
16086The source, assembly and register windows are attached to the thread
16087and the frame position. They are updated when the current thread
16088changes, when the frame changes or when the program counter changes.
16089These three windows are arranged by the TUI according to several
16090layouts. The layout defines which of these three windows are visible.
16091The following layouts are available:
c906108c 16092
8e04817f
AC
16093@itemize @bullet
16094@item
16095source
2df3850c 16096
8e04817f
AC
16097@item
16098assembly
16099
16100@item
16101source and assembly
16102
16103@item
16104source and registers
c906108c 16105
8e04817f
AC
16106@item
16107assembly and registers
2df3850c 16108
8e04817f 16109@end itemize
c906108c 16110
b7bb15bc
SC
16111On top of the command window a status line gives various information
16112concerning the current process begin debugged. The status line is
16113updated when the information it shows changes. The following fields
16114are displayed:
16115
16116@table @emph
16117@item target
16118Indicates the current gdb target
16119(@pxref{Targets, ,Specifying a Debugging Target}).
16120
16121@item process
16122Gives information about the current process or thread number.
16123When no process is being debugged, this field is set to @code{No process}.
16124
16125@item function
16126Gives the current function name for the selected frame.
16127The name is demangled if demangling is turned on (@pxref{Print Settings}).
16128When there is no symbol corresponding to the current program counter
16129the string @code{??} is displayed.
16130
16131@item line
16132Indicates the current line number for the selected frame.
16133When the current line number is not known the string @code{??} is displayed.
16134
16135@item pc
16136Indicates the current program counter address.
16137
16138@end table
16139
8e04817f
AC
16140@node TUI Keys
16141@section TUI Key Bindings
16142@cindex TUI key bindings
c906108c 16143
8e04817f
AC
16144The TUI installs several key bindings in the readline keymaps
16145(@pxref{Command Line Editing}).
16146They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16147directly on the TUI layout and windows. The TUI also provides
16148a @emph{SingleKey} keymap which binds several keys directly to
16149@value{GDBN} commands. The following key bindings
8e04817f 16150are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16151
8e04817f
AC
16152@table @kbd
16153@kindex C-x C-a
16154@item C-x C-a
16155@kindex C-x a
16156@itemx C-x a
16157@kindex C-x A
16158@itemx C-x A
16159Enter or leave the TUI mode. When the TUI mode is left,
16160the curses window management is left and @value{GDBN} operates using
16161its standard mode writing on the terminal directly. When the TUI
16162mode is entered, the control is given back to the curses windows.
16163The screen is then refreshed.
c906108c 16164
8e04817f
AC
16165@kindex C-x 1
16166@item C-x 1
16167Use a TUI layout with only one window. The layout will
16168either be @samp{source} or @samp{assembly}. When the TUI mode
16169is not active, it will switch to the TUI mode.
2df3850c 16170
8e04817f 16171Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16172
8e04817f
AC
16173@kindex C-x 2
16174@item C-x 2
16175Use a TUI layout with at least two windows. When the current
16176layout shows already two windows, a next layout with two windows is used.
16177When a new layout is chosen, one window will always be common to the
16178previous layout and the new one.
c906108c 16179
8e04817f 16180Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16181
72ffddc9
SC
16182@kindex C-x o
16183@item C-x o
16184Change the active window. The TUI associates several key bindings
16185(like scrolling and arrow keys) to the active window. This command
16186gives the focus to the next TUI window.
16187
16188Think of it as the Emacs @kbd{C-x o} binding.
16189
7cf36c78
SC
16190@kindex C-x s
16191@item C-x s
16192Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16193(@pxref{TUI Single Key Mode}).
16194
c906108c
SS
16195@end table
16196
8e04817f 16197The following key bindings are handled only by the TUI mode:
5d161b24 16198
8e04817f
AC
16199@table @key
16200@kindex PgUp
16201@item PgUp
16202Scroll the active window one page up.
c906108c 16203
8e04817f
AC
16204@kindex PgDn
16205@item PgDn
16206Scroll the active window one page down.
c906108c 16207
8e04817f
AC
16208@kindex Up
16209@item Up
16210Scroll the active window one line up.
c906108c 16211
8e04817f
AC
16212@kindex Down
16213@item Down
16214Scroll the active window one line down.
c906108c 16215
8e04817f
AC
16216@kindex Left
16217@item Left
16218Scroll the active window one column left.
c906108c 16219
8e04817f
AC
16220@kindex Right
16221@item Right
16222Scroll the active window one column right.
c906108c 16223
8e04817f
AC
16224@kindex C-L
16225@item C-L
16226Refresh the screen.
c906108c 16227
8e04817f 16228@end table
c906108c 16229
8e04817f 16230In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16231for scrolling. This means they are available for readline when the
16232active window is the command window. When the command window
16233does not have the focus, it is necessary to use other readline
16234key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16235
7cf36c78
SC
16236@node TUI Single Key Mode
16237@section TUI Single Key Mode
16238@cindex TUI single key mode
16239
16240The TUI provides a @emph{SingleKey} mode in which it installs a particular
16241key binding in the readline keymaps to connect single keys to
b383017d 16242some gdb commands.
7cf36c78
SC
16243
16244@table @kbd
16245@kindex c @r{(SingleKey TUI key)}
16246@item c
16247continue
16248
16249@kindex d @r{(SingleKey TUI key)}
16250@item d
16251down
16252
16253@kindex f @r{(SingleKey TUI key)}
16254@item f
16255finish
16256
16257@kindex n @r{(SingleKey TUI key)}
16258@item n
16259next
16260
16261@kindex q @r{(SingleKey TUI key)}
16262@item q
16263exit the @emph{SingleKey} mode.
16264
16265@kindex r @r{(SingleKey TUI key)}
16266@item r
16267run
16268
16269@kindex s @r{(SingleKey TUI key)}
16270@item s
16271step
16272
16273@kindex u @r{(SingleKey TUI key)}
16274@item u
16275up
16276
16277@kindex v @r{(SingleKey TUI key)}
16278@item v
16279info locals
16280
16281@kindex w @r{(SingleKey TUI key)}
16282@item w
16283where
16284
16285@end table
16286
16287Other keys temporarily switch to the @value{GDBN} command prompt.
16288The key that was pressed is inserted in the editing buffer so that
16289it is possible to type most @value{GDBN} commands without interaction
16290with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16291@emph{SingleKey} mode is restored. The only way to permanently leave
16292this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16293
16294
8e04817f
AC
16295@node TUI Commands
16296@section TUI specific commands
16297@cindex TUI commands
16298
16299The TUI has specific commands to control the text windows.
16300These commands are always available, that is they do not depend on
16301the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16302is in the standard mode, using these commands will automatically switch
16303in the TUI mode.
c906108c
SS
16304
16305@table @code
3d757584
SC
16306@item info win
16307@kindex info win
16308List and give the size of all displayed windows.
16309
8e04817f 16310@item layout next
4644b6e3 16311@kindex layout
8e04817f 16312Display the next layout.
2df3850c 16313
8e04817f 16314@item layout prev
8e04817f 16315Display the previous layout.
c906108c 16316
8e04817f 16317@item layout src
8e04817f 16318Display the source window only.
c906108c 16319
8e04817f 16320@item layout asm
8e04817f 16321Display the assembly window only.
c906108c 16322
8e04817f 16323@item layout split
8e04817f 16324Display the source and assembly window.
c906108c 16325
8e04817f 16326@item layout regs
8e04817f
AC
16327Display the register window together with the source or assembly window.
16328
16329@item focus next | prev | src | asm | regs | split
16330@kindex focus
16331Set the focus to the named window.
16332This command allows to change the active window so that scrolling keys
16333can be affected to another window.
c906108c 16334
8e04817f
AC
16335@item refresh
16336@kindex refresh
16337Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16338
6a1b180d
SC
16339@item tui reg float
16340@kindex tui reg
16341Show the floating point registers in the register window.
16342
16343@item tui reg general
16344Show the general registers in the register window.
16345
16346@item tui reg next
16347Show the next register group. The list of register groups as well as
16348their order is target specific. The predefined register groups are the
16349following: @code{general}, @code{float}, @code{system}, @code{vector},
16350@code{all}, @code{save}, @code{restore}.
16351
16352@item tui reg system
16353Show the system registers in the register window.
16354
8e04817f
AC
16355@item update
16356@kindex update
16357Update the source window and the current execution point.
c906108c 16358
8e04817f
AC
16359@item winheight @var{name} +@var{count}
16360@itemx winheight @var{name} -@var{count}
16361@kindex winheight
16362Change the height of the window @var{name} by @var{count}
16363lines. Positive counts increase the height, while negative counts
16364decrease it.
2df3850c 16365
c45da7e6
EZ
16366@item tabset
16367@kindex tabset @var{nchars}
16368Set the width of tab stops to be @var{nchars} characters.
16369
c906108c
SS
16370@end table
16371
8e04817f
AC
16372@node TUI Configuration
16373@section TUI configuration variables
16374@cindex TUI configuration variables
c906108c 16375
8e04817f
AC
16376The TUI has several configuration variables that control the
16377appearance of windows on the terminal.
c906108c 16378
8e04817f
AC
16379@table @code
16380@item set tui border-kind @var{kind}
16381@kindex set tui border-kind
16382Select the border appearance for the source, assembly and register windows.
16383The possible values are the following:
16384@table @code
16385@item space
16386Use a space character to draw the border.
c906108c 16387
8e04817f
AC
16388@item ascii
16389Use ascii characters + - and | to draw the border.
c906108c 16390
8e04817f
AC
16391@item acs
16392Use the Alternate Character Set to draw the border. The border is
16393drawn using character line graphics if the terminal supports them.
c78b4128 16394
8e04817f 16395@end table
c78b4128 16396
8e04817f
AC
16397@item set tui active-border-mode @var{mode}
16398@kindex set tui active-border-mode
16399Select the attributes to display the border of the active window.
16400The possible values are @code{normal}, @code{standout}, @code{reverse},
16401@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16402
8e04817f
AC
16403@item set tui border-mode @var{mode}
16404@kindex set tui border-mode
16405Select the attributes to display the border of other windows.
16406The @var{mode} can be one of the following:
16407@table @code
16408@item normal
16409Use normal attributes to display the border.
c906108c 16410
8e04817f
AC
16411@item standout
16412Use standout mode.
c906108c 16413
8e04817f
AC
16414@item reverse
16415Use reverse video mode.
c906108c 16416
8e04817f
AC
16417@item half
16418Use half bright mode.
c906108c 16419
8e04817f
AC
16420@item half-standout
16421Use half bright and standout mode.
c906108c 16422
8e04817f
AC
16423@item bold
16424Use extra bright or bold mode.
c78b4128 16425
8e04817f
AC
16426@item bold-standout
16427Use extra bright or bold and standout mode.
c78b4128 16428
8e04817f 16429@end table
c78b4128 16430
8e04817f 16431@end table
c78b4128 16432
8e04817f
AC
16433@node Emacs
16434@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16435
8e04817f
AC
16436@cindex Emacs
16437@cindex @sc{gnu} Emacs
16438A special interface allows you to use @sc{gnu} Emacs to view (and
16439edit) the source files for the program you are debugging with
16440@value{GDBN}.
c906108c 16441
8e04817f
AC
16442To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16443executable file you want to debug as an argument. This command starts
16444@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16445created Emacs buffer.
16446@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16447
8e04817f
AC
16448Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16449things:
c906108c 16450
8e04817f
AC
16451@itemize @bullet
16452@item
16453All ``terminal'' input and output goes through the Emacs buffer.
16454@end itemize
c906108c 16455
8e04817f
AC
16456This applies both to @value{GDBN} commands and their output, and to the input
16457and output done by the program you are debugging.
bf0184be 16458
8e04817f
AC
16459This is useful because it means that you can copy the text of previous
16460commands and input them again; you can even use parts of the output
16461in this way.
bf0184be 16462
8e04817f
AC
16463All the facilities of Emacs' Shell mode are available for interacting
16464with your program. In particular, you can send signals the usual
16465way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16466stop.
bf0184be 16467
8e04817f 16468@itemize @bullet
bf0184be 16469@item
8e04817f
AC
16470@value{GDBN} displays source code through Emacs.
16471@end itemize
bf0184be 16472
8e04817f
AC
16473Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16474source file for that frame and puts an arrow (@samp{=>}) at the
16475left margin of the current line. Emacs uses a separate buffer for
16476source display, and splits the screen to show both your @value{GDBN} session
16477and the source.
bf0184be 16478
8e04817f
AC
16479Explicit @value{GDBN} @code{list} or search commands still produce output as
16480usual, but you probably have no reason to use them from Emacs.
c906108c 16481
64fabec2
AC
16482If you specify an absolute file name when prompted for the @kbd{M-x
16483gdb} argument, then Emacs sets your current working directory to where
16484your program resides. If you only specify the file name, then Emacs
16485sets your current working directory to to the directory associated
16486with the previous buffer. In this case, @value{GDBN} may find your
16487program by searching your environment's @code{PATH} variable, but on
16488some operating systems it might not find the source. So, although the
16489@value{GDBN} input and output session proceeds normally, the auxiliary
16490buffer does not display the current source and line of execution.
16491
16492The initial working directory of @value{GDBN} is printed on the top
16493line of the @value{GDBN} I/O buffer and this serves as a default for
16494the commands that specify files for @value{GDBN} to operate
16495on. @xref{Files, ,Commands to specify files}.
16496
16497By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16498need to call @value{GDBN} by a different name (for example, if you
16499keep several configurations around, with different names) you can
16500customize the Emacs variable @code{gud-gdb-command-name} to run the
16501one you want.
8e04817f
AC
16502
16503In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16504addition to the standard Shell mode commands:
c906108c 16505
8e04817f
AC
16506@table @kbd
16507@item C-h m
16508Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16509
64fabec2 16510@item C-c C-s
8e04817f
AC
16511Execute to another source line, like the @value{GDBN} @code{step} command; also
16512update the display window to show the current file and location.
c906108c 16513
64fabec2 16514@item C-c C-n
8e04817f
AC
16515Execute to next source line in this function, skipping all function
16516calls, like the @value{GDBN} @code{next} command. Then update the display window
16517to show the current file and location.
c906108c 16518
64fabec2 16519@item C-c C-i
8e04817f
AC
16520Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16521display window accordingly.
c906108c 16522
8e04817f
AC
16523@item C-c C-f
16524Execute until exit from the selected stack frame, like the @value{GDBN}
16525@code{finish} command.
c906108c 16526
64fabec2 16527@item C-c C-r
8e04817f
AC
16528Continue execution of your program, like the @value{GDBN} @code{continue}
16529command.
b433d00b 16530
64fabec2 16531@item C-c <
8e04817f
AC
16532Go up the number of frames indicated by the numeric argument
16533(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16534like the @value{GDBN} @code{up} command.
b433d00b 16535
64fabec2 16536@item C-c >
8e04817f
AC
16537Go down the number of frames indicated by the numeric argument, like the
16538@value{GDBN} @code{down} command.
8e04817f 16539@end table
c906108c 16540
64fabec2 16541In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16542tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16543
64fabec2
AC
16544If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16545shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16546point to any frame in the stack and type @key{RET} to make it become the
16547current frame and display the associated source in the source buffer.
16548Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16549current one.
16550
8e04817f
AC
16551If you accidentally delete the source-display buffer, an easy way to get
16552it back is to type the command @code{f} in the @value{GDBN} buffer, to
16553request a frame display; when you run under Emacs, this recreates
16554the source buffer if necessary to show you the context of the current
16555frame.
c906108c 16556
8e04817f
AC
16557The source files displayed in Emacs are in ordinary Emacs buffers
16558which are visiting the source files in the usual way. You can edit
16559the files with these buffers if you wish; but keep in mind that @value{GDBN}
16560communicates with Emacs in terms of line numbers. If you add or
16561delete lines from the text, the line numbers that @value{GDBN} knows cease
16562to correspond properly with the code.
b383017d 16563
64fabec2
AC
16564The description given here is for GNU Emacs version 21.3 and a more
16565detailed description of its interaction with @value{GDBN} is given in
16566the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16567
8e04817f
AC
16568@c The following dropped because Epoch is nonstandard. Reactivate
16569@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16570@ignore
16571@kindex Emacs Epoch environment
16572@kindex Epoch
16573@kindex inspect
c906108c 16574
8e04817f
AC
16575Version 18 of @sc{gnu} Emacs has a built-in window system
16576called the @code{epoch}
16577environment. Users of this environment can use a new command,
16578@code{inspect} which performs identically to @code{print} except that
16579each value is printed in its own window.
16580@end ignore
c906108c 16581
922fbb7b
AC
16582
16583@node GDB/MI
16584@chapter The @sc{gdb/mi} Interface
16585
16586@unnumberedsec Function and Purpose
16587
16588@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16589@sc{gdb/mi} is a line based machine oriented text interface to
16590@value{GDBN} and is activated by specifying using the
16591@option{--interpreter} command line option (@pxref{Mode Options}). It
16592is specifically intended to support the development of systems which
16593use the debugger as just one small component of a larger system.
922fbb7b
AC
16594
16595This chapter is a specification of the @sc{gdb/mi} interface. It is written
16596in the form of a reference manual.
16597
16598Note that @sc{gdb/mi} is still under construction, so some of the
16599features described below are incomplete and subject to change.
16600
16601@unnumberedsec Notation and Terminology
16602
16603@cindex notational conventions, for @sc{gdb/mi}
16604This chapter uses the following notation:
16605
16606@itemize @bullet
16607@item
16608@code{|} separates two alternatives.
16609
16610@item
16611@code{[ @var{something} ]} indicates that @var{something} is optional:
16612it may or may not be given.
16613
16614@item
16615@code{( @var{group} )*} means that @var{group} inside the parentheses
16616may repeat zero or more times.
16617
16618@item
16619@code{( @var{group} )+} means that @var{group} inside the parentheses
16620may repeat one or more times.
16621
16622@item
16623@code{"@var{string}"} means a literal @var{string}.
16624@end itemize
16625
16626@ignore
16627@heading Dependencies
16628@end ignore
16629
16630@heading Acknowledgments
16631
16632In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16633Elena Zannoni.
16634
16635@menu
16636* GDB/MI Command Syntax::
16637* GDB/MI Compatibility with CLI::
16638* GDB/MI Output Records::
16639* GDB/MI Command Description Format::
16640* GDB/MI Breakpoint Table Commands::
16641* GDB/MI Data Manipulation::
16642* GDB/MI Program Control::
16643* GDB/MI Miscellaneous Commands::
16644@ignore
16645* GDB/MI Kod Commands::
16646* GDB/MI Memory Overlay Commands::
16647* GDB/MI Signal Handling Commands::
16648@end ignore
16649* GDB/MI Stack Manipulation::
16650* GDB/MI Symbol Query::
16651* GDB/MI Target Manipulation::
16652* GDB/MI Thread Commands::
16653* GDB/MI Tracepoint Commands::
16654* GDB/MI Variable Objects::
16655@end menu
16656
16657@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16658@node GDB/MI Command Syntax
16659@section @sc{gdb/mi} Command Syntax
16660
16661@menu
16662* GDB/MI Input Syntax::
16663* GDB/MI Output Syntax::
16664* GDB/MI Simple Examples::
16665@end menu
16666
16667@node GDB/MI Input Syntax
16668@subsection @sc{gdb/mi} Input Syntax
16669
16670@cindex input syntax for @sc{gdb/mi}
16671@cindex @sc{gdb/mi}, input syntax
16672@table @code
16673@item @var{command} @expansion{}
16674@code{@var{cli-command} | @var{mi-command}}
16675
16676@item @var{cli-command} @expansion{}
16677@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16678@var{cli-command} is any existing @value{GDBN} CLI command.
16679
16680@item @var{mi-command} @expansion{}
16681@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16682@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16683
16684@item @var{token} @expansion{}
16685"any sequence of digits"
16686
16687@item @var{option} @expansion{}
16688@code{"-" @var{parameter} [ " " @var{parameter} ]}
16689
16690@item @var{parameter} @expansion{}
16691@code{@var{non-blank-sequence} | @var{c-string}}
16692
16693@item @var{operation} @expansion{}
16694@emph{any of the operations described in this chapter}
16695
16696@item @var{non-blank-sequence} @expansion{}
16697@emph{anything, provided it doesn't contain special characters such as
16698"-", @var{nl}, """ and of course " "}
16699
16700@item @var{c-string} @expansion{}
16701@code{""" @var{seven-bit-iso-c-string-content} """}
16702
16703@item @var{nl} @expansion{}
16704@code{CR | CR-LF}
16705@end table
16706
16707@noindent
16708Notes:
16709
16710@itemize @bullet
16711@item
16712The CLI commands are still handled by the @sc{mi} interpreter; their
16713output is described below.
16714
16715@item
16716The @code{@var{token}}, when present, is passed back when the command
16717finishes.
16718
16719@item
16720Some @sc{mi} commands accept optional arguments as part of the parameter
16721list. Each option is identified by a leading @samp{-} (dash) and may be
16722followed by an optional argument parameter. Options occur first in the
16723parameter list and can be delimited from normal parameters using
16724@samp{--} (this is useful when some parameters begin with a dash).
16725@end itemize
16726
16727Pragmatics:
16728
16729@itemize @bullet
16730@item
16731We want easy access to the existing CLI syntax (for debugging).
16732
16733@item
16734We want it to be easy to spot a @sc{mi} operation.
16735@end itemize
16736
16737@node GDB/MI Output Syntax
16738@subsection @sc{gdb/mi} Output Syntax
16739
16740@cindex output syntax of @sc{gdb/mi}
16741@cindex @sc{gdb/mi}, output syntax
16742The output from @sc{gdb/mi} consists of zero or more out-of-band records
16743followed, optionally, by a single result record. This result record
16744is for the most recent command. The sequence of output records is
16745terminated by @samp{(@value{GDBP})}.
16746
16747If an input command was prefixed with a @code{@var{token}} then the
16748corresponding output for that command will also be prefixed by that same
16749@var{token}.
16750
16751@table @code
16752@item @var{output} @expansion{}
f7dc1244 16753@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16754
16755@item @var{result-record} @expansion{}
16756@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16757
16758@item @var{out-of-band-record} @expansion{}
16759@code{@var{async-record} | @var{stream-record}}
16760
16761@item @var{async-record} @expansion{}
16762@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16763
16764@item @var{exec-async-output} @expansion{}
16765@code{[ @var{token} ] "*" @var{async-output}}
16766
16767@item @var{status-async-output} @expansion{}
16768@code{[ @var{token} ] "+" @var{async-output}}
16769
16770@item @var{notify-async-output} @expansion{}
16771@code{[ @var{token} ] "=" @var{async-output}}
16772
16773@item @var{async-output} @expansion{}
16774@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16775
16776@item @var{result-class} @expansion{}
16777@code{"done" | "running" | "connected" | "error" | "exit"}
16778
16779@item @var{async-class} @expansion{}
16780@code{"stopped" | @var{others}} (where @var{others} will be added
16781depending on the needs---this is still in development).
16782
16783@item @var{result} @expansion{}
16784@code{ @var{variable} "=" @var{value}}
16785
16786@item @var{variable} @expansion{}
16787@code{ @var{string} }
16788
16789@item @var{value} @expansion{}
16790@code{ @var{const} | @var{tuple} | @var{list} }
16791
16792@item @var{const} @expansion{}
16793@code{@var{c-string}}
16794
16795@item @var{tuple} @expansion{}
16796@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16797
16798@item @var{list} @expansion{}
16799@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16800@var{result} ( "," @var{result} )* "]" }
16801
16802@item @var{stream-record} @expansion{}
16803@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16804
16805@item @var{console-stream-output} @expansion{}
16806@code{"~" @var{c-string}}
16807
16808@item @var{target-stream-output} @expansion{}
16809@code{"@@" @var{c-string}}
16810
16811@item @var{log-stream-output} @expansion{}
16812@code{"&" @var{c-string}}
16813
16814@item @var{nl} @expansion{}
16815@code{CR | CR-LF}
16816
16817@item @var{token} @expansion{}
16818@emph{any sequence of digits}.
16819@end table
16820
16821@noindent
16822Notes:
16823
16824@itemize @bullet
16825@item
16826All output sequences end in a single line containing a period.
16827
16828@item
16829The @code{@var{token}} is from the corresponding request. If an execution
16830command is interrupted by the @samp{-exec-interrupt} command, the
16831@var{token} associated with the @samp{*stopped} message is the one of the
16832original execution command, not the one of the interrupt command.
16833
16834@item
16835@cindex status output in @sc{gdb/mi}
16836@var{status-async-output} contains on-going status information about the
16837progress of a slow operation. It can be discarded. All status output is
16838prefixed by @samp{+}.
16839
16840@item
16841@cindex async output in @sc{gdb/mi}
16842@var{exec-async-output} contains asynchronous state change on the target
16843(stopped, started, disappeared). All async output is prefixed by
16844@samp{*}.
16845
16846@item
16847@cindex notify output in @sc{gdb/mi}
16848@var{notify-async-output} contains supplementary information that the
16849client should handle (e.g., a new breakpoint information). All notify
16850output is prefixed by @samp{=}.
16851
16852@item
16853@cindex console output in @sc{gdb/mi}
16854@var{console-stream-output} is output that should be displayed as is in the
16855console. It is the textual response to a CLI command. All the console
16856output is prefixed by @samp{~}.
16857
16858@item
16859@cindex target output in @sc{gdb/mi}
16860@var{target-stream-output} is the output produced by the target program.
16861All the target output is prefixed by @samp{@@}.
16862
16863@item
16864@cindex log output in @sc{gdb/mi}
16865@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16866instance messages that should be displayed as part of an error log. All
16867the log output is prefixed by @samp{&}.
16868
16869@item
16870@cindex list output in @sc{gdb/mi}
16871New @sc{gdb/mi} commands should only output @var{lists} containing
16872@var{values}.
16873
16874
16875@end itemize
16876
16877@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16878details about the various output records.
16879
16880@node GDB/MI Simple Examples
16881@subsection Simple Examples of @sc{gdb/mi} Interaction
16882@cindex @sc{gdb/mi}, simple examples
16883
16884This subsection presents several simple examples of interaction using
16885the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16886following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16887the output received from @sc{gdb/mi}.
16888
16889@subsubheading Target Stop
16890@c Ummm... There is no "-stop" command. This assumes async, no?
16891Here's an example of stopping the inferior process:
16892
16893@smallexample
16894-> -stop
16895<- (@value{GDBP})
16896@end smallexample
16897
16898@noindent
16899and later:
16900
16901@smallexample
16902<- *stop,reason="stop",address="0x123",source="a.c:123"
16903<- (@value{GDBP})
16904@end smallexample
16905
16906@subsubheading Simple CLI Command
16907
16908Here's an example of a simple CLI command being passed through
16909@sc{gdb/mi} and on to the CLI.
16910
16911@smallexample
16912-> print 1+2
16913<- &"print 1+2\n"
16914<- ~"$1 = 3\n"
16915<- ^done
16916<- (@value{GDBP})
16917@end smallexample
16918
16919@subsubheading Command With Side Effects
16920
16921@smallexample
16922-> -symbol-file xyz.exe
16923<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16924<- (@value{GDBP})
16925@end smallexample
16926
16927@subsubheading A Bad Command
16928
16929Here's what happens if you pass a non-existent command:
16930
16931@smallexample
16932-> -rubbish
16933<- ^error,msg="Undefined MI command: rubbish"
16934<- (@value{GDBP})
16935@end smallexample
16936
16937@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16938@node GDB/MI Compatibility with CLI
16939@section @sc{gdb/mi} Compatibility with CLI
16940
16941@cindex compatibility, @sc{gdb/mi} and CLI
16942@cindex @sc{gdb/mi}, compatibility with CLI
16943To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16944accepts existing CLI commands. As specified by the syntax, such
16945commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16946respond.
16947
16948This mechanism is provided as an aid to developers of @sc{gdb/mi}
16949clients and not as a reliable interface into the CLI. Since the command
16950is being interpreteted in an environment that assumes @sc{gdb/mi}
16951behaviour, the exact output of such commands is likely to end up being
16952an un-supported hybrid of @sc{gdb/mi} and CLI output.
16953
16954@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16955@node GDB/MI Output Records
16956@section @sc{gdb/mi} Output Records
16957
16958@menu
16959* GDB/MI Result Records::
16960* GDB/MI Stream Records::
16961* GDB/MI Out-of-band Records::
16962@end menu
16963
16964@node GDB/MI Result Records
16965@subsection @sc{gdb/mi} Result Records
16966
16967@cindex result records in @sc{gdb/mi}
16968@cindex @sc{gdb/mi}, result records
16969In addition to a number of out-of-band notifications, the response to a
16970@sc{gdb/mi} command includes one of the following result indications:
16971
16972@table @code
16973@findex ^done
16974@item "^done" [ "," @var{results} ]
16975The synchronous operation was successful, @code{@var{results}} are the return
16976values.
16977
16978@item "^running"
16979@findex ^running
16980@c Is this one correct? Should it be an out-of-band notification?
16981The asynchronous operation was successfully started. The target is
16982running.
16983
16984@item "^error" "," @var{c-string}
16985@findex ^error
16986The operation failed. The @code{@var{c-string}} contains the corresponding
16987error message.
16988@end table
16989
16990@node GDB/MI Stream Records
16991@subsection @sc{gdb/mi} Stream Records
16992
16993@cindex @sc{gdb/mi}, stream records
16994@cindex stream records in @sc{gdb/mi}
16995@value{GDBN} internally maintains a number of output streams: the console, the
16996target, and the log. The output intended for each of these streams is
16997funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16998
16999Each stream record begins with a unique @dfn{prefix character} which
17000identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17001Syntax}). In addition to the prefix, each stream record contains a
17002@code{@var{string-output}}. This is either raw text (with an implicit new
17003line) or a quoted C string (which does not contain an implicit newline).
17004
17005@table @code
17006@item "~" @var{string-output}
17007The console output stream contains text that should be displayed in the
17008CLI console window. It contains the textual responses to CLI commands.
17009
17010@item "@@" @var{string-output}
17011The target output stream contains any textual output from the running
17012target.
17013
17014@item "&" @var{string-output}
17015The log stream contains debugging messages being produced by @value{GDBN}'s
17016internals.
17017@end table
17018
17019@node GDB/MI Out-of-band Records
17020@subsection @sc{gdb/mi} Out-of-band Records
17021
17022@cindex out-of-band records in @sc{gdb/mi}
17023@cindex @sc{gdb/mi}, out-of-band records
17024@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17025additional changes that have occurred. Those changes can either be a
17026consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17027target activity (e.g., target stopped).
17028
17029The following is a preliminary list of possible out-of-band records.
034dad6f 17030In particular, the @var{exec-async-output} records.
922fbb7b
AC
17031
17032@table @code
034dad6f
BR
17033@item *stopped,reason="@var{reason}"
17034@end table
17035
17036@var{reason} can be one of the following:
17037
17038@table @code
17039@item breakpoint-hit
17040A breakpoint was reached.
17041@item watchpoint-trigger
17042A watchpoint was triggered.
17043@item read-watchpoint-trigger
17044A read watchpoint was triggered.
17045@item access-watchpoint-trigger
17046An access watchpoint was triggered.
17047@item function-finished
17048An -exec-finish or similar CLI command was accomplished.
17049@item location-reached
17050An -exec-until or similar CLI command was accomplished.
17051@item watchpoint-scope
17052A watchpoint has gone out of scope.
17053@item end-stepping-range
17054An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17055similar CLI command was accomplished.
17056@item exited-signalled
17057The inferior exited because of a signal.
17058@item exited
17059The inferior exited.
17060@item exited-normally
17061The inferior exited normally.
17062@item signal-received
17063A signal was received by the inferior.
922fbb7b
AC
17064@end table
17065
17066
17067@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17068@node GDB/MI Command Description Format
17069@section @sc{gdb/mi} Command Description Format
17070
17071The remaining sections describe blocks of commands. Each block of
17072commands is laid out in a fashion similar to this section.
17073
17074Note the the line breaks shown in the examples are here only for
17075readability. They don't appear in the real output.
17076Also note that the commands with a non-available example (N.A.@:) are
17077not yet implemented.
17078
17079@subheading Motivation
17080
17081The motivation for this collection of commands.
17082
17083@subheading Introduction
17084
17085A brief introduction to this collection of commands as a whole.
17086
17087@subheading Commands
17088
17089For each command in the block, the following is described:
17090
17091@subsubheading Synopsis
17092
17093@smallexample
17094 -command @var{args}@dots{}
17095@end smallexample
17096
17097@subsubheading @value{GDBN} Command
17098
17099The corresponding @value{GDBN} CLI command.
17100
17101@subsubheading Result
17102
17103@subsubheading Out-of-band
17104
17105@subsubheading Notes
17106
17107@subsubheading Example
17108
17109
17110@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17111@node GDB/MI Breakpoint Table Commands
17112@section @sc{gdb/mi} Breakpoint table commands
17113
17114@cindex breakpoint commands for @sc{gdb/mi}
17115@cindex @sc{gdb/mi}, breakpoint commands
17116This section documents @sc{gdb/mi} commands for manipulating
17117breakpoints.
17118
17119@subheading The @code{-break-after} Command
17120@findex -break-after
17121
17122@subsubheading Synopsis
17123
17124@smallexample
17125 -break-after @var{number} @var{count}
17126@end smallexample
17127
17128The breakpoint number @var{number} is not in effect until it has been
17129hit @var{count} times. To see how this is reflected in the output of
17130the @samp{-break-list} command, see the description of the
17131@samp{-break-list} command below.
17132
17133@subsubheading @value{GDBN} Command
17134
17135The corresponding @value{GDBN} command is @samp{ignore}.
17136
17137@subsubheading Example
17138
17139@smallexample
17140(@value{GDBP})
17141-break-insert main
17142^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17143(@value{GDBP})
17144-break-after 1 3
17145~
17146^done
17147(@value{GDBP})
17148-break-list
17149^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17150hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17151@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17152@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17153@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17154@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17155@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17156body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17157addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17158ignore="3"@}]@}
17159(@value{GDBP})
17160@end smallexample
17161
17162@ignore
17163@subheading The @code{-break-catch} Command
17164@findex -break-catch
17165
17166@subheading The @code{-break-commands} Command
17167@findex -break-commands
17168@end ignore
17169
17170
17171@subheading The @code{-break-condition} Command
17172@findex -break-condition
17173
17174@subsubheading Synopsis
17175
17176@smallexample
17177 -break-condition @var{number} @var{expr}
17178@end smallexample
17179
17180Breakpoint @var{number} will stop the program only if the condition in
17181@var{expr} is true. The condition becomes part of the
17182@samp{-break-list} output (see the description of the @samp{-break-list}
17183command below).
17184
17185@subsubheading @value{GDBN} Command
17186
17187The corresponding @value{GDBN} command is @samp{condition}.
17188
17189@subsubheading Example
17190
17191@smallexample
17192(@value{GDBP})
17193-break-condition 1 1
17194^done
17195(@value{GDBP})
17196-break-list
17197^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17198hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17199@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17200@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17201@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17202@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17203@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17204body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17205addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17206times="0",ignore="3"@}]@}
17207(@value{GDBP})
17208@end smallexample
17209
17210@subheading The @code{-break-delete} Command
17211@findex -break-delete
17212
17213@subsubheading Synopsis
17214
17215@smallexample
17216 -break-delete ( @var{breakpoint} )+
17217@end smallexample
17218
17219Delete the breakpoint(s) whose number(s) are specified in the argument
17220list. This is obviously reflected in the breakpoint list.
17221
17222@subsubheading @value{GDBN} command
17223
17224The corresponding @value{GDBN} command is @samp{delete}.
17225
17226@subsubheading Example
17227
17228@smallexample
17229(@value{GDBP})
17230-break-delete 1
17231^done
17232(@value{GDBP})
17233-break-list
17234^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17235hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17236@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17237@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17238@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17239@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17240@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17241body=[]@}
17242(@value{GDBP})
17243@end smallexample
17244
17245@subheading The @code{-break-disable} Command
17246@findex -break-disable
17247
17248@subsubheading Synopsis
17249
17250@smallexample
17251 -break-disable ( @var{breakpoint} )+
17252@end smallexample
17253
17254Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17255break list is now set to @samp{n} for the named @var{breakpoint}(s).
17256
17257@subsubheading @value{GDBN} Command
17258
17259The corresponding @value{GDBN} command is @samp{disable}.
17260
17261@subsubheading Example
17262
17263@smallexample
17264(@value{GDBP})
17265-break-disable 2
17266^done
17267(@value{GDBP})
17268-break-list
17269^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17270hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17271@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17272@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17273@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17274@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17275@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17276body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17277addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17278(@value{GDBP})
17279@end smallexample
17280
17281@subheading The @code{-break-enable} Command
17282@findex -break-enable
17283
17284@subsubheading Synopsis
17285
17286@smallexample
17287 -break-enable ( @var{breakpoint} )+
17288@end smallexample
17289
17290Enable (previously disabled) @var{breakpoint}(s).
17291
17292@subsubheading @value{GDBN} Command
17293
17294The corresponding @value{GDBN} command is @samp{enable}.
17295
17296@subsubheading Example
17297
17298@smallexample
17299(@value{GDBP})
17300-break-enable 2
17301^done
17302(@value{GDBP})
17303-break-list
17304^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17305hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17306@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17307@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17308@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17309@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17310@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17311body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17312addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17313(@value{GDBP})
17314@end smallexample
17315
17316@subheading The @code{-break-info} Command
17317@findex -break-info
17318
17319@subsubheading Synopsis
17320
17321@smallexample
17322 -break-info @var{breakpoint}
17323@end smallexample
17324
17325@c REDUNDANT???
17326Get information about a single breakpoint.
17327
17328@subsubheading @value{GDBN} command
17329
17330The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17331
17332@subsubheading Example
17333N.A.
17334
17335@subheading The @code{-break-insert} Command
17336@findex -break-insert
17337
17338@subsubheading Synopsis
17339
17340@smallexample
17341 -break-insert [ -t ] [ -h ] [ -r ]
17342 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17343 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17344@end smallexample
17345
17346@noindent
17347If specified, @var{line}, can be one of:
17348
17349@itemize @bullet
17350@item function
17351@c @item +offset
17352@c @item -offset
17353@c @item linenum
17354@item filename:linenum
17355@item filename:function
17356@item *address
17357@end itemize
17358
17359The possible optional parameters of this command are:
17360
17361@table @samp
17362@item -t
17363Insert a tempoary breakpoint.
17364@item -h
17365Insert a hardware breakpoint.
17366@item -c @var{condition}
17367Make the breakpoint conditional on @var{condition}.
17368@item -i @var{ignore-count}
17369Initialize the @var{ignore-count}.
17370@item -r
17371Insert a regular breakpoint in all the functions whose names match the
17372given regular expression. Other flags are not applicable to regular
17373expresson.
17374@end table
17375
17376@subsubheading Result
17377
17378The result is in the form:
17379
17380@smallexample
17381 ^done,bkptno="@var{number}",func="@var{funcname}",
17382 file="@var{filename}",line="@var{lineno}"
17383@end smallexample
17384
17385@noindent
17386where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17387is the name of the function where the breakpoint was inserted,
17388@var{filename} is the name of the source file which contains this
17389function, and @var{lineno} is the source line number within that file.
17390
17391Note: this format is open to change.
17392@c An out-of-band breakpoint instead of part of the result?
17393
17394@subsubheading @value{GDBN} Command
17395
17396The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17397@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17398
17399@subsubheading Example
17400
17401@smallexample
17402(@value{GDBP})
17403-break-insert main
17404^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17405(@value{GDBP})
17406-break-insert -t foo
17407^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17408(@value{GDBP})
17409-break-list
17410^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17411hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17412@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17413@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17414@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17415@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17416@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17417body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17418addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17419bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17420addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17421(@value{GDBP})
17422-break-insert -r foo.*
17423~int foo(int, int);
17424^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17425(@value{GDBP})
17426@end smallexample
17427
17428@subheading The @code{-break-list} Command
17429@findex -break-list
17430
17431@subsubheading Synopsis
17432
17433@smallexample
17434 -break-list
17435@end smallexample
17436
17437Displays the list of inserted breakpoints, showing the following fields:
17438
17439@table @samp
17440@item Number
17441number of the breakpoint
17442@item Type
17443type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17444@item Disposition
17445should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17446or @samp{nokeep}
17447@item Enabled
17448is the breakpoint enabled or no: @samp{y} or @samp{n}
17449@item Address
17450memory location at which the breakpoint is set
17451@item What
17452logical location of the breakpoint, expressed by function name, file
17453name, line number
17454@item Times
17455number of times the breakpoint has been hit
17456@end table
17457
17458If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17459@code{body} field is an empty list.
17460
17461@subsubheading @value{GDBN} Command
17462
17463The corresponding @value{GDBN} command is @samp{info break}.
17464
17465@subsubheading Example
17466
17467@smallexample
17468(@value{GDBP})
17469-break-list
17470^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17471hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17472@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17473@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17474@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17475@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17476@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17477body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17478addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17479bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17480addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17481(@value{GDBP})
17482@end smallexample
17483
17484Here's an example of the result when there are no breakpoints:
17485
17486@smallexample
17487(@value{GDBP})
17488-break-list
17489^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17490hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17491@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17492@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17493@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17494@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17495@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17496body=[]@}
17497(@value{GDBP})
17498@end smallexample
17499
17500@subheading The @code{-break-watch} Command
17501@findex -break-watch
17502
17503@subsubheading Synopsis
17504
17505@smallexample
17506 -break-watch [ -a | -r ]
17507@end smallexample
17508
17509Create a watchpoint. With the @samp{-a} option it will create an
17510@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17511read from or on a write to the memory location. With the @samp{-r}
17512option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17513trigger only when the memory location is accessed for reading. Without
17514either of the options, the watchpoint created is a regular watchpoint,
17515i.e. it will trigger when the memory location is accessed for writing.
17516@xref{Set Watchpoints, , Setting watchpoints}.
17517
17518Note that @samp{-break-list} will report a single list of watchpoints and
17519breakpoints inserted.
17520
17521@subsubheading @value{GDBN} Command
17522
17523The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17524@samp{rwatch}.
17525
17526@subsubheading Example
17527
17528Setting a watchpoint on a variable in the @code{main} function:
17529
17530@smallexample
17531(@value{GDBP})
17532-break-watch x
17533^done,wpt=@{number="2",exp="x"@}
17534(@value{GDBP})
17535-exec-continue
17536^running
17537^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17538value=@{old="-268439212",new="55"@},
76ff342d
DJ
17539frame=@{func="main",args=[],file="recursive2.c",
17540fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17541(@value{GDBP})
17542@end smallexample
17543
17544Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17545the program execution twice: first for the variable changing value, then
17546for the watchpoint going out of scope.
17547
17548@smallexample
17549(@value{GDBP})
17550-break-watch C
17551^done,wpt=@{number="5",exp="C"@}
17552(@value{GDBP})
17553-exec-continue
17554^running
17555^done,reason="watchpoint-trigger",
17556wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17557frame=@{func="callee4",args=[],
76ff342d
DJ
17558file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17559fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17560(@value{GDBP})
17561-exec-continue
17562^running
17563^done,reason="watchpoint-scope",wpnum="5",
17564frame=@{func="callee3",args=[@{name="strarg",
17565value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17566file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17567fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17568(@value{GDBP})
17569@end smallexample
17570
17571Listing breakpoints and watchpoints, at different points in the program
17572execution. Note that once the watchpoint goes out of scope, it is
17573deleted.
17574
17575@smallexample
17576(@value{GDBP})
17577-break-watch C
17578^done,wpt=@{number="2",exp="C"@}
17579(@value{GDBP})
17580-break-list
17581^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17582hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17583@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17584@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17585@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17586@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17587@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17588body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17589addr="0x00010734",func="callee4",
17590file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17591bkpt=@{number="2",type="watchpoint",disp="keep",
17592enabled="y",addr="",what="C",times="0"@}]@}
17593(@value{GDBP})
17594-exec-continue
17595^running
17596^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17597value=@{old="-276895068",new="3"@},
17598frame=@{func="callee4",args=[],
76ff342d
DJ
17599file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17600fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17601(@value{GDBP})
17602-break-list
17603^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17604hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17605@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17606@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17607@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17608@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17609@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17610body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17611addr="0x00010734",func="callee4",
17612file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17613bkpt=@{number="2",type="watchpoint",disp="keep",
17614enabled="y",addr="",what="C",times="-5"@}]@}
17615(@value{GDBP})
17616-exec-continue
17617^running
17618^done,reason="watchpoint-scope",wpnum="2",
17619frame=@{func="callee3",args=[@{name="strarg",
17620value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17621file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17622fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17623(@value{GDBP})
17624-break-list
17625^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17626hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17627@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17628@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17629@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17630@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17631@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17632body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17633addr="0x00010734",func="callee4",
17634file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17635(@value{GDBP})
17636@end smallexample
17637
17638@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17639@node GDB/MI Data Manipulation
17640@section @sc{gdb/mi} Data Manipulation
17641
17642@cindex data manipulation, in @sc{gdb/mi}
17643@cindex @sc{gdb/mi}, data manipulation
17644This section describes the @sc{gdb/mi} commands that manipulate data:
17645examine memory and registers, evaluate expressions, etc.
17646
17647@c REMOVED FROM THE INTERFACE.
17648@c @subheading -data-assign
17649@c Change the value of a program variable. Plenty of side effects.
17650@c @subsubheading GDB command
17651@c set variable
17652@c @subsubheading Example
17653@c N.A.
17654
17655@subheading The @code{-data-disassemble} Command
17656@findex -data-disassemble
17657
17658@subsubheading Synopsis
17659
17660@smallexample
17661 -data-disassemble
17662 [ -s @var{start-addr} -e @var{end-addr} ]
17663 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17664 -- @var{mode}
17665@end smallexample
17666
17667@noindent
17668Where:
17669
17670@table @samp
17671@item @var{start-addr}
17672is the beginning address (or @code{$pc})
17673@item @var{end-addr}
17674is the end address
17675@item @var{filename}
17676is the name of the file to disassemble
17677@item @var{linenum}
17678is the line number to disassemble around
17679@item @var{lines}
17680is the the number of disassembly lines to be produced. If it is -1,
17681the whole function will be disassembled, in case no @var{end-addr} is
17682specified. If @var{end-addr} is specified as a non-zero value, and
17683@var{lines} is lower than the number of disassembly lines between
17684@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17685displayed; if @var{lines} is higher than the number of lines between
17686@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17687are displayed.
17688@item @var{mode}
17689is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17690disassembly).
17691@end table
17692
17693@subsubheading Result
17694
17695The output for each instruction is composed of four fields:
17696
17697@itemize @bullet
17698@item Address
17699@item Func-name
17700@item Offset
17701@item Instruction
17702@end itemize
17703
17704Note that whatever included in the instruction field, is not manipulated
17705directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17706
17707@subsubheading @value{GDBN} Command
17708
17709There's no direct mapping from this command to the CLI.
17710
17711@subsubheading Example
17712
17713Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17714
17715@smallexample
17716(@value{GDBP})
17717-data-disassemble -s $pc -e "$pc + 20" -- 0
17718^done,
17719asm_insns=[
17720@{address="0x000107c0",func-name="main",offset="4",
17721inst="mov 2, %o0"@},
17722@{address="0x000107c4",func-name="main",offset="8",
17723inst="sethi %hi(0x11800), %o2"@},
17724@{address="0x000107c8",func-name="main",offset="12",
17725inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17726@{address="0x000107cc",func-name="main",offset="16",
17727inst="sethi %hi(0x11800), %o2"@},
17728@{address="0x000107d0",func-name="main",offset="20",
17729inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17730(@value{GDBP})
17731@end smallexample
17732
17733Disassemble the whole @code{main} function. Line 32 is part of
17734@code{main}.
17735
17736@smallexample
17737-data-disassemble -f basics.c -l 32 -- 0
17738^done,asm_insns=[
17739@{address="0x000107bc",func-name="main",offset="0",
17740inst="save %sp, -112, %sp"@},
17741@{address="0x000107c0",func-name="main",offset="4",
17742inst="mov 2, %o0"@},
17743@{address="0x000107c4",func-name="main",offset="8",
17744inst="sethi %hi(0x11800), %o2"@},
17745[@dots{}]
17746@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17747@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17748(@value{GDBP})
17749@end smallexample
17750
17751Disassemble 3 instructions from the start of @code{main}:
17752
17753@smallexample
17754(@value{GDBP})
17755-data-disassemble -f basics.c -l 32 -n 3 -- 0
17756^done,asm_insns=[
17757@{address="0x000107bc",func-name="main",offset="0",
17758inst="save %sp, -112, %sp"@},
17759@{address="0x000107c0",func-name="main",offset="4",
17760inst="mov 2, %o0"@},
17761@{address="0x000107c4",func-name="main",offset="8",
17762inst="sethi %hi(0x11800), %o2"@}]
17763(@value{GDBP})
17764@end smallexample
17765
17766Disassemble 3 instructions from the start of @code{main} in mixed mode:
17767
17768@smallexample
17769(@value{GDBP})
17770-data-disassemble -f basics.c -l 32 -n 3 -- 1
17771^done,asm_insns=[
17772src_and_asm_line=@{line="31",
17773file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17774 testsuite/gdb.mi/basics.c",line_asm_insn=[
17775@{address="0x000107bc",func-name="main",offset="0",
17776inst="save %sp, -112, %sp"@}]@},
17777src_and_asm_line=@{line="32",
17778file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17779 testsuite/gdb.mi/basics.c",line_asm_insn=[
17780@{address="0x000107c0",func-name="main",offset="4",
17781inst="mov 2, %o0"@},
17782@{address="0x000107c4",func-name="main",offset="8",
17783inst="sethi %hi(0x11800), %o2"@}]@}]
17784(@value{GDBP})
17785@end smallexample
17786
17787
17788@subheading The @code{-data-evaluate-expression} Command
17789@findex -data-evaluate-expression
17790
17791@subsubheading Synopsis
17792
17793@smallexample
17794 -data-evaluate-expression @var{expr}
17795@end smallexample
17796
17797Evaluate @var{expr} as an expression. The expression could contain an
17798inferior function call. The function call will execute synchronously.
17799If the expression contains spaces, it must be enclosed in double quotes.
17800
17801@subsubheading @value{GDBN} Command
17802
17803The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17804@samp{call}. In @code{gdbtk} only, there's a corresponding
17805@samp{gdb_eval} command.
17806
17807@subsubheading Example
17808
17809In the following example, the numbers that precede the commands are the
17810@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17811Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17812output.
17813
17814@smallexample
17815211-data-evaluate-expression A
17816211^done,value="1"
17817(@value{GDBP})
17818311-data-evaluate-expression &A
17819311^done,value="0xefffeb7c"
17820(@value{GDBP})
17821411-data-evaluate-expression A+3
17822411^done,value="4"
17823(@value{GDBP})
17824511-data-evaluate-expression "A + 3"
17825511^done,value="4"
17826(@value{GDBP})
17827@end smallexample
17828
17829
17830@subheading The @code{-data-list-changed-registers} Command
17831@findex -data-list-changed-registers
17832
17833@subsubheading Synopsis
17834
17835@smallexample
17836 -data-list-changed-registers
17837@end smallexample
17838
17839Display a list of the registers that have changed.
17840
17841@subsubheading @value{GDBN} Command
17842
17843@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17844has the corresponding command @samp{gdb_changed_register_list}.
17845
17846@subsubheading Example
17847
17848On a PPC MBX board:
17849
17850@smallexample
17851(@value{GDBP})
17852-exec-continue
17853^running
17854
17855(@value{GDBP})
17856*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17857args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17858(@value{GDBP})
17859-data-list-changed-registers
17860^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17861"10","11","13","14","15","16","17","18","19","20","21","22","23",
17862"24","25","26","27","28","30","31","64","65","66","67","69"]
17863(@value{GDBP})
17864@end smallexample
17865
17866
17867@subheading The @code{-data-list-register-names} Command
17868@findex -data-list-register-names
17869
17870@subsubheading Synopsis
17871
17872@smallexample
17873 -data-list-register-names [ ( @var{regno} )+ ]
17874@end smallexample
17875
17876Show a list of register names for the current target. If no arguments
17877are given, it shows a list of the names of all the registers. If
17878integer numbers are given as arguments, it will print a list of the
17879names of the registers corresponding to the arguments. To ensure
17880consistency between a register name and its number, the output list may
17881include empty register names.
17882
17883@subsubheading @value{GDBN} Command
17884
17885@value{GDBN} does not have a command which corresponds to
17886@samp{-data-list-register-names}. In @code{gdbtk} there is a
17887corresponding command @samp{gdb_regnames}.
17888
17889@subsubheading Example
17890
17891For the PPC MBX board:
17892@smallexample
17893(@value{GDBP})
17894-data-list-register-names
17895^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17896"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17897"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17898"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17899"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17900"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17901"", "pc","ps","cr","lr","ctr","xer"]
17902(@value{GDBP})
17903-data-list-register-names 1 2 3
17904^done,register-names=["r1","r2","r3"]
17905(@value{GDBP})
17906@end smallexample
17907
17908@subheading The @code{-data-list-register-values} Command
17909@findex -data-list-register-values
17910
17911@subsubheading Synopsis
17912
17913@smallexample
17914 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17915@end smallexample
17916
17917Display the registers' contents. @var{fmt} is the format according to
17918which the registers' contents are to be returned, followed by an optional
17919list of numbers specifying the registers to display. A missing list of
17920numbers indicates that the contents of all the registers must be returned.
17921
17922Allowed formats for @var{fmt} are:
17923
17924@table @code
17925@item x
17926Hexadecimal
17927@item o
17928Octal
17929@item t
17930Binary
17931@item d
17932Decimal
17933@item r
17934Raw
17935@item N
17936Natural
17937@end table
17938
17939@subsubheading @value{GDBN} Command
17940
17941The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17942all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17943
17944@subsubheading Example
17945
17946For a PPC MBX board (note: line breaks are for readability only, they
17947don't appear in the actual output):
17948
17949@smallexample
17950(@value{GDBP})
17951-data-list-register-values r 64 65
17952^done,register-values=[@{number="64",value="0xfe00a300"@},
17953@{number="65",value="0x00029002"@}]
17954(@value{GDBP})
17955-data-list-register-values x
17956^done,register-values=[@{number="0",value="0xfe0043c8"@},
17957@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17958@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17959@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17960@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17961@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17962@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17963@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17964@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17965@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17966@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17967@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17968@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17969@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17970@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17971@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17972@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17973@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17974@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17975@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17976@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17977@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17978@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17979@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17980@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17981@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17982@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17983@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17984@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17985@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17986@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17987@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17988@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17989@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17990@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17991@{number="69",value="0x20002b03"@}]
17992(@value{GDBP})
17993@end smallexample
17994
17995
17996@subheading The @code{-data-read-memory} Command
17997@findex -data-read-memory
17998
17999@subsubheading Synopsis
18000
18001@smallexample
18002 -data-read-memory [ -o @var{byte-offset} ]
18003 @var{address} @var{word-format} @var{word-size}
18004 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18005@end smallexample
18006
18007@noindent
18008where:
18009
18010@table @samp
18011@item @var{address}
18012An expression specifying the address of the first memory word to be
18013read. Complex expressions containing embedded white space should be
18014quoted using the C convention.
18015
18016@item @var{word-format}
18017The format to be used to print the memory words. The notation is the
18018same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18019,Output formats}).
18020
18021@item @var{word-size}
18022The size of each memory word in bytes.
18023
18024@item @var{nr-rows}
18025The number of rows in the output table.
18026
18027@item @var{nr-cols}
18028The number of columns in the output table.
18029
18030@item @var{aschar}
18031If present, indicates that each row should include an @sc{ascii} dump. The
18032value of @var{aschar} is used as a padding character when a byte is not a
18033member of the printable @sc{ascii} character set (printable @sc{ascii}
18034characters are those whose code is between 32 and 126, inclusively).
18035
18036@item @var{byte-offset}
18037An offset to add to the @var{address} before fetching memory.
18038@end table
18039
18040This command displays memory contents as a table of @var{nr-rows} by
18041@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18042@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18043(returned as @samp{total-bytes}). Should less than the requested number
18044of bytes be returned by the target, the missing words are identified
18045using @samp{N/A}. The number of bytes read from the target is returned
18046in @samp{nr-bytes} and the starting address used to read memory in
18047@samp{addr}.
18048
18049The address of the next/previous row or page is available in
18050@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18051@samp{prev-page}.
18052
18053@subsubheading @value{GDBN} Command
18054
18055The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18056@samp{gdb_get_mem} memory read command.
18057
18058@subsubheading Example
18059
18060Read six bytes of memory starting at @code{bytes+6} but then offset by
18061@code{-6} bytes. Format as three rows of two columns. One byte per
18062word. Display each word in hex.
18063
18064@smallexample
18065(@value{GDBP})
180669-data-read-memory -o -6 -- bytes+6 x 1 3 2
180679^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18068next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18069prev-page="0x0000138a",memory=[
18070@{addr="0x00001390",data=["0x00","0x01"]@},
18071@{addr="0x00001392",data=["0x02","0x03"]@},
18072@{addr="0x00001394",data=["0x04","0x05"]@}]
18073(@value{GDBP})
18074@end smallexample
18075
18076Read two bytes of memory starting at address @code{shorts + 64} and
18077display as a single word formatted in decimal.
18078
18079@smallexample
18080(@value{GDBP})
180815-data-read-memory shorts+64 d 2 1 1
180825^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18083next-row="0x00001512",prev-row="0x0000150e",
18084next-page="0x00001512",prev-page="0x0000150e",memory=[
18085@{addr="0x00001510",data=["128"]@}]
18086(@value{GDBP})
18087@end smallexample
18088
18089Read thirty two bytes of memory starting at @code{bytes+16} and format
18090as eight rows of four columns. Include a string encoding with @samp{x}
18091used as the non-printable character.
18092
18093@smallexample
18094(@value{GDBP})
180954-data-read-memory bytes+16 x 1 8 4 x
180964^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18097next-row="0x000013c0",prev-row="0x0000139c",
18098next-page="0x000013c0",prev-page="0x00001380",memory=[
18099@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18100@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18101@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18102@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18103@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18104@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18105@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18106@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18107(@value{GDBP})
18108@end smallexample
18109
18110@subheading The @code{-display-delete} Command
18111@findex -display-delete
18112
18113@subsubheading Synopsis
18114
18115@smallexample
18116 -display-delete @var{number}
18117@end smallexample
18118
18119Delete the display @var{number}.
18120
18121@subsubheading @value{GDBN} Command
18122
18123The corresponding @value{GDBN} command is @samp{delete display}.
18124
18125@subsubheading Example
18126N.A.
18127
18128
18129@subheading The @code{-display-disable} Command
18130@findex -display-disable
18131
18132@subsubheading Synopsis
18133
18134@smallexample
18135 -display-disable @var{number}
18136@end smallexample
18137
18138Disable display @var{number}.
18139
18140@subsubheading @value{GDBN} Command
18141
18142The corresponding @value{GDBN} command is @samp{disable display}.
18143
18144@subsubheading Example
18145N.A.
18146
18147
18148@subheading The @code{-display-enable} Command
18149@findex -display-enable
18150
18151@subsubheading Synopsis
18152
18153@smallexample
18154 -display-enable @var{number}
18155@end smallexample
18156
18157Enable display @var{number}.
18158
18159@subsubheading @value{GDBN} Command
18160
18161The corresponding @value{GDBN} command is @samp{enable display}.
18162
18163@subsubheading Example
18164N.A.
18165
18166
18167@subheading The @code{-display-insert} Command
18168@findex -display-insert
18169
18170@subsubheading Synopsis
18171
18172@smallexample
18173 -display-insert @var{expression}
18174@end smallexample
18175
18176Display @var{expression} every time the program stops.
18177
18178@subsubheading @value{GDBN} Command
18179
18180The corresponding @value{GDBN} command is @samp{display}.
18181
18182@subsubheading Example
18183N.A.
18184
18185
18186@subheading The @code{-display-list} Command
18187@findex -display-list
18188
18189@subsubheading Synopsis
18190
18191@smallexample
18192 -display-list
18193@end smallexample
18194
18195List the displays. Do not show the current values.
18196
18197@subsubheading @value{GDBN} Command
18198
18199The corresponding @value{GDBN} command is @samp{info display}.
18200
18201@subsubheading Example
18202N.A.
18203
18204
18205@subheading The @code{-environment-cd} Command
18206@findex -environment-cd
18207
18208@subsubheading Synopsis
18209
18210@smallexample
18211 -environment-cd @var{pathdir}
18212@end smallexample
18213
18214Set @value{GDBN}'s working directory.
18215
18216@subsubheading @value{GDBN} Command
18217
18218The corresponding @value{GDBN} command is @samp{cd}.
18219
18220@subsubheading Example
18221
18222@smallexample
18223(@value{GDBP})
18224-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18225^done
18226(@value{GDBP})
18227@end smallexample
18228
18229
18230@subheading The @code{-environment-directory} Command
18231@findex -environment-directory
18232
18233@subsubheading Synopsis
18234
18235@smallexample
18236 -environment-directory [ -r ] [ @var{pathdir} ]+
18237@end smallexample
18238
18239Add directories @var{pathdir} to beginning of search path for source files.
18240If the @samp{-r} option is used, the search path is reset to the default
b383017d 18241search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18242@samp{-r} option, the search path is first reset and then addition
18243occurs as normal.
b383017d 18244Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18245multiple directories in a single command
18246results in the directories added to the beginning of the
18247search path in the same order they were presented in the command.
18248If blanks are needed as
18249part of a directory name, double-quotes should be used around
18250the name. In the command output, the path will show up separated
b383017d 18251by the system directory-separator character. The directory-seperator
922fbb7b
AC
18252character must not be used
18253in any directory name.
18254If no directories are specified, the current search path is displayed.
18255
18256@subsubheading @value{GDBN} Command
18257
18258The corresponding @value{GDBN} command is @samp{dir}.
18259
18260@subsubheading Example
18261
18262@smallexample
18263(@value{GDBP})
18264-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18265^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18266(@value{GDBP})
18267-environment-directory ""
18268^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18269(@value{GDBP})
18270-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18271^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18272(@value{GDBP})
18273-environment-directory -r
18274^done,source-path="$cdir:$cwd"
18275(@value{GDBP})
18276@end smallexample
18277
18278
18279@subheading The @code{-environment-path} Command
18280@findex -environment-path
18281
18282@subsubheading Synopsis
18283
18284@smallexample
18285 -environment-path [ -r ] [ @var{pathdir} ]+
18286@end smallexample
18287
18288Add directories @var{pathdir} to beginning of search path for object files.
18289If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18290search path that existed at gdb start-up. If directories @var{pathdir} are
18291supplied in addition to the
922fbb7b
AC
18292@samp{-r} option, the search path is first reset and then addition
18293occurs as normal.
b383017d 18294Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18295multiple directories in a single command
18296results in the directories added to the beginning of the
18297search path in the same order they were presented in the command.
18298If blanks are needed as
18299part of a directory name, double-quotes should be used around
18300the name. In the command output, the path will show up separated
b383017d 18301by the system directory-separator character. The directory-seperator
922fbb7b
AC
18302character must not be used
18303in any directory name.
18304If no directories are specified, the current path is displayed.
18305
18306
18307@subsubheading @value{GDBN} Command
18308
18309The corresponding @value{GDBN} command is @samp{path}.
18310
18311@subsubheading Example
18312
18313@smallexample
18314(@value{GDBP})
b383017d 18315-environment-path
922fbb7b
AC
18316^done,path="/usr/bin"
18317(@value{GDBP})
18318-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18319^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18320(@value{GDBP})
18321-environment-path -r /usr/local/bin
18322^done,path="/usr/local/bin:/usr/bin"
18323(@value{GDBP})
18324@end smallexample
18325
18326
18327@subheading The @code{-environment-pwd} Command
18328@findex -environment-pwd
18329
18330@subsubheading Synopsis
18331
18332@smallexample
18333 -environment-pwd
18334@end smallexample
18335
18336Show the current working directory.
18337
18338@subsubheading @value{GDBN} command
18339
18340The corresponding @value{GDBN} command is @samp{pwd}.
18341
18342@subsubheading Example
18343
18344@smallexample
18345(@value{GDBP})
18346-environment-pwd
18347^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18348(@value{GDBP})
18349@end smallexample
18350
18351@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18352@node GDB/MI Program Control
18353@section @sc{gdb/mi} Program control
18354
18355@subsubheading Program termination
18356
18357As a result of execution, the inferior program can run to completion, if
18358it doesn't encounter any breakpoints. In this case the output will
18359include an exit code, if the program has exited exceptionally.
18360
18361@subsubheading Examples
18362
18363@noindent
18364Program exited normally:
18365
18366@smallexample
18367(@value{GDBP})
18368-exec-run
18369^running
18370(@value{GDBP})
18371x = 55
18372*stopped,reason="exited-normally"
18373(@value{GDBP})
18374@end smallexample
18375
18376@noindent
18377Program exited exceptionally:
18378
18379@smallexample
18380(@value{GDBP})
18381-exec-run
18382^running
18383(@value{GDBP})
18384x = 55
18385*stopped,reason="exited",exit-code="01"
18386(@value{GDBP})
18387@end smallexample
18388
18389Another way the program can terminate is if it receives a signal such as
18390@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18391
18392@smallexample
18393(@value{GDBP})
18394*stopped,reason="exited-signalled",signal-name="SIGINT",
18395signal-meaning="Interrupt"
18396@end smallexample
18397
18398
18399@subheading The @code{-exec-abort} Command
18400@findex -exec-abort
18401
18402@subsubheading Synopsis
18403
18404@smallexample
18405 -exec-abort
18406@end smallexample
18407
18408Kill the inferior running program.
18409
18410@subsubheading @value{GDBN} Command
18411
18412The corresponding @value{GDBN} command is @samp{kill}.
18413
18414@subsubheading Example
18415N.A.
18416
18417
18418@subheading The @code{-exec-arguments} Command
18419@findex -exec-arguments
18420
18421@subsubheading Synopsis
18422
18423@smallexample
18424 -exec-arguments @var{args}
18425@end smallexample
18426
18427Set the inferior program arguments, to be used in the next
18428@samp{-exec-run}.
18429
18430@subsubheading @value{GDBN} Command
18431
18432The corresponding @value{GDBN} command is @samp{set args}.
18433
18434@subsubheading Example
18435
18436@c FIXME!
18437Don't have one around.
18438
18439
18440@subheading The @code{-exec-continue} Command
18441@findex -exec-continue
18442
18443@subsubheading Synopsis
18444
18445@smallexample
18446 -exec-continue
18447@end smallexample
18448
18449Asynchronous command. Resumes the execution of the inferior program
18450until a breakpoint is encountered, or until the inferior exits.
18451
18452@subsubheading @value{GDBN} Command
18453
18454The corresponding @value{GDBN} corresponding is @samp{continue}.
18455
18456@subsubheading Example
18457
18458@smallexample
18459-exec-continue
18460^running
18461(@value{GDBP})
18462@@Hello world
18463*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18464file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18465(@value{GDBP})
18466@end smallexample
18467
18468
18469@subheading The @code{-exec-finish} Command
18470@findex -exec-finish
18471
18472@subsubheading Synopsis
18473
18474@smallexample
18475 -exec-finish
18476@end smallexample
18477
18478Asynchronous command. Resumes the execution of the inferior program
18479until the current function is exited. Displays the results returned by
18480the function.
18481
18482@subsubheading @value{GDBN} Command
18483
18484The corresponding @value{GDBN} command is @samp{finish}.
18485
18486@subsubheading Example
18487
18488Function returning @code{void}.
18489
18490@smallexample
18491-exec-finish
18492^running
18493(@value{GDBP})
18494@@hello from foo
18495*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18496file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18497(@value{GDBP})
18498@end smallexample
18499
18500Function returning other than @code{void}. The name of the internal
18501@value{GDBN} variable storing the result is printed, together with the
18502value itself.
18503
18504@smallexample
18505-exec-finish
18506^running
18507(@value{GDBP})
18508*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18509args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18510file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18511gdb-result-var="$1",return-value="0"
18512(@value{GDBP})
18513@end smallexample
18514
18515
18516@subheading The @code{-exec-interrupt} Command
18517@findex -exec-interrupt
18518
18519@subsubheading Synopsis
18520
18521@smallexample
18522 -exec-interrupt
18523@end smallexample
18524
18525Asynchronous command. Interrupts the background execution of the target.
18526Note how the token associated with the stop message is the one for the
18527execution command that has been interrupted. The token for the interrupt
18528itself only appears in the @samp{^done} output. If the user is trying to
18529interrupt a non-running program, an error message will be printed.
18530
18531@subsubheading @value{GDBN} Command
18532
18533The corresponding @value{GDBN} command is @samp{interrupt}.
18534
18535@subsubheading Example
18536
18537@smallexample
18538(@value{GDBP})
18539111-exec-continue
18540111^running
18541
18542(@value{GDBP})
18543222-exec-interrupt
18544222^done
18545(@value{GDBP})
18546111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18547frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18548fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18549(@value{GDBP})
18550
18551(@value{GDBP})
18552-exec-interrupt
18553^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18554(@value{GDBP})
18555@end smallexample
18556
18557
18558@subheading The @code{-exec-next} Command
18559@findex -exec-next
18560
18561@subsubheading Synopsis
18562
18563@smallexample
18564 -exec-next
18565@end smallexample
18566
18567Asynchronous command. Resumes execution of the inferior program, stopping
18568when the beginning of the next source line is reached.
18569
18570@subsubheading @value{GDBN} Command
18571
18572The corresponding @value{GDBN} command is @samp{next}.
18573
18574@subsubheading Example
18575
18576@smallexample
18577-exec-next
18578^running
18579(@value{GDBP})
18580*stopped,reason="end-stepping-range",line="8",file="hello.c"
18581(@value{GDBP})
18582@end smallexample
18583
18584
18585@subheading The @code{-exec-next-instruction} Command
18586@findex -exec-next-instruction
18587
18588@subsubheading Synopsis
18589
18590@smallexample
18591 -exec-next-instruction
18592@end smallexample
18593
18594Asynchronous command. Executes one machine instruction. If the
18595instruction is a function call continues until the function returns. If
18596the program stops at an instruction in the middle of a source line, the
18597address will be printed as well.
18598
18599@subsubheading @value{GDBN} Command
18600
18601The corresponding @value{GDBN} command is @samp{nexti}.
18602
18603@subsubheading Example
18604
18605@smallexample
18606(@value{GDBP})
18607-exec-next-instruction
18608^running
18609
18610(@value{GDBP})
18611*stopped,reason="end-stepping-range",
18612addr="0x000100d4",line="5",file="hello.c"
18613(@value{GDBP})
18614@end smallexample
18615
18616
18617@subheading The @code{-exec-return} Command
18618@findex -exec-return
18619
18620@subsubheading Synopsis
18621
18622@smallexample
18623 -exec-return
18624@end smallexample
18625
18626Makes current function return immediately. Doesn't execute the inferior.
18627Displays the new current frame.
18628
18629@subsubheading @value{GDBN} Command
18630
18631The corresponding @value{GDBN} command is @samp{return}.
18632
18633@subsubheading Example
18634
18635@smallexample
18636(@value{GDBP})
18637200-break-insert callee4
18638200^done,bkpt=@{number="1",addr="0x00010734",
18639file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18640(@value{GDBP})
18641000-exec-run
18642000^running
18643(@value{GDBP})
18644000*stopped,reason="breakpoint-hit",bkptno="1",
18645frame=@{func="callee4",args=[],
76ff342d
DJ
18646file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18647fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18648(@value{GDBP})
18649205-break-delete
18650205^done
18651(@value{GDBP})
18652111-exec-return
18653111^done,frame=@{level="0",func="callee3",
18654args=[@{name="strarg",
18655value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18656file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18657fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18658(@value{GDBP})
18659@end smallexample
18660
18661
18662@subheading The @code{-exec-run} Command
18663@findex -exec-run
18664
18665@subsubheading Synopsis
18666
18667@smallexample
18668 -exec-run
18669@end smallexample
18670
18671Asynchronous command. Starts execution of the inferior from the
18672beginning. The inferior executes until either a breakpoint is
18673encountered or the program exits.
18674
18675@subsubheading @value{GDBN} Command
18676
18677The corresponding @value{GDBN} command is @samp{run}.
18678
18679@subsubheading Example
18680
18681@smallexample
18682(@value{GDBP})
18683-break-insert main
18684^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18685(@value{GDBP})
18686-exec-run
18687^running
18688(@value{GDBP})
18689*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18690frame=@{func="main",args=[],file="recursive2.c",
18691fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18692(@value{GDBP})
18693@end smallexample
18694
18695
18696@subheading The @code{-exec-show-arguments} Command
18697@findex -exec-show-arguments
18698
18699@subsubheading Synopsis
18700
18701@smallexample
18702 -exec-show-arguments
18703@end smallexample
18704
18705Print the arguments of the program.
18706
18707@subsubheading @value{GDBN} Command
18708
18709The corresponding @value{GDBN} command is @samp{show args}.
18710
18711@subsubheading Example
18712N.A.
18713
18714@c @subheading -exec-signal
18715
18716@subheading The @code{-exec-step} Command
18717@findex -exec-step
18718
18719@subsubheading Synopsis
18720
18721@smallexample
18722 -exec-step
18723@end smallexample
18724
18725Asynchronous command. Resumes execution of the inferior program, stopping
18726when the beginning of the next source line is reached, if the next
18727source line is not a function call. If it is, stop at the first
18728instruction of the called function.
18729
18730@subsubheading @value{GDBN} Command
18731
18732The corresponding @value{GDBN} command is @samp{step}.
18733
18734@subsubheading Example
18735
18736Stepping into a function:
18737
18738@smallexample
18739-exec-step
18740^running
18741(@value{GDBP})
18742*stopped,reason="end-stepping-range",
18743frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18744@{name="b",value="0"@}],file="recursive2.c",
18745fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18746(@value{GDBP})
18747@end smallexample
18748
18749Regular stepping:
18750
18751@smallexample
18752-exec-step
18753^running
18754(@value{GDBP})
18755*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18756(@value{GDBP})
18757@end smallexample
18758
18759
18760@subheading The @code{-exec-step-instruction} Command
18761@findex -exec-step-instruction
18762
18763@subsubheading Synopsis
18764
18765@smallexample
18766 -exec-step-instruction
18767@end smallexample
18768
18769Asynchronous command. Resumes the inferior which executes one machine
18770instruction. The output, once @value{GDBN} has stopped, will vary depending on
18771whether we have stopped in the middle of a source line or not. In the
18772former case, the address at which the program stopped will be printed as
18773well.
18774
18775@subsubheading @value{GDBN} Command
18776
18777The corresponding @value{GDBN} command is @samp{stepi}.
18778
18779@subsubheading Example
18780
18781@smallexample
18782(@value{GDBP})
18783-exec-step-instruction
18784^running
18785
18786(@value{GDBP})
18787*stopped,reason="end-stepping-range",
76ff342d
DJ
18788frame=@{func="foo",args=[],file="try.c",
18789fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18790(@value{GDBP})
18791-exec-step-instruction
18792^running
18793
18794(@value{GDBP})
18795*stopped,reason="end-stepping-range",
76ff342d
DJ
18796frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18797fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18798(@value{GDBP})
18799@end smallexample
18800
18801
18802@subheading The @code{-exec-until} Command
18803@findex -exec-until
18804
18805@subsubheading Synopsis
18806
18807@smallexample
18808 -exec-until [ @var{location} ]
18809@end smallexample
18810
18811Asynchronous command. Executes the inferior until the @var{location}
18812specified in the argument is reached. If there is no argument, the inferior
18813executes until a source line greater than the current one is reached.
18814The reason for stopping in this case will be @samp{location-reached}.
18815
18816@subsubheading @value{GDBN} Command
18817
18818The corresponding @value{GDBN} command is @samp{until}.
18819
18820@subsubheading Example
18821
18822@smallexample
18823(@value{GDBP})
18824-exec-until recursive2.c:6
18825^running
18826(@value{GDBP})
18827x = 55
18828*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18829file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18830(@value{GDBP})
18831@end smallexample
18832
18833@ignore
18834@subheading -file-clear
18835Is this going away????
18836@end ignore
18837
18838
18839@subheading The @code{-file-exec-and-symbols} Command
18840@findex -file-exec-and-symbols
18841
18842@subsubheading Synopsis
18843
18844@smallexample
18845 -file-exec-and-symbols @var{file}
18846@end smallexample
18847
18848Specify the executable file to be debugged. This file is the one from
18849which the symbol table is also read. If no file is specified, the
18850command clears the executable and symbol information. If breakpoints
18851are set when using this command with no arguments, @value{GDBN} will produce
18852error messages. Otherwise, no output is produced, except a completion
18853notification.
18854
18855@subsubheading @value{GDBN} Command
18856
18857The corresponding @value{GDBN} command is @samp{file}.
18858
18859@subsubheading Example
18860
18861@smallexample
18862(@value{GDBP})
18863-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18864^done
18865(@value{GDBP})
18866@end smallexample
18867
18868
18869@subheading The @code{-file-exec-file} Command
18870@findex -file-exec-file
18871
18872@subsubheading Synopsis
18873
18874@smallexample
18875 -file-exec-file @var{file}
18876@end smallexample
18877
18878Specify the executable file to be debugged. Unlike
18879@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18880from this file. If used without argument, @value{GDBN} clears the information
18881about the executable file. No output is produced, except a completion
18882notification.
18883
18884@subsubheading @value{GDBN} Command
18885
18886The corresponding @value{GDBN} command is @samp{exec-file}.
18887
18888@subsubheading Example
18889
18890@smallexample
18891(@value{GDBP})
18892-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18893^done
18894(@value{GDBP})
18895@end smallexample
18896
18897
18898@subheading The @code{-file-list-exec-sections} Command
18899@findex -file-list-exec-sections
18900
18901@subsubheading Synopsis
18902
18903@smallexample
18904 -file-list-exec-sections
18905@end smallexample
18906
18907List the sections of the current executable file.
18908
18909@subsubheading @value{GDBN} Command
18910
18911The @value{GDBN} command @samp{info file} shows, among the rest, the same
18912information as this command. @code{gdbtk} has a corresponding command
18913@samp{gdb_load_info}.
18914
18915@subsubheading Example
18916N.A.
18917
18918
1abaf70c
BR
18919@subheading The @code{-file-list-exec-source-file} Command
18920@findex -file-list-exec-source-file
18921
18922@subsubheading Synopsis
18923
18924@smallexample
18925 -file-list-exec-source-file
18926@end smallexample
18927
b383017d 18928List the line number, the current source file, and the absolute path
1abaf70c
BR
18929to the current source file for the current executable.
18930
18931@subsubheading @value{GDBN} Command
18932
18933There's no @value{GDBN} command which directly corresponds to this one.
18934
18935@subsubheading Example
18936
18937@smallexample
18938(@value{GDBP})
18939123-file-list-exec-source-file
18940123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18941(@value{GDBP})
18942@end smallexample
18943
18944
922fbb7b
AC
18945@subheading The @code{-file-list-exec-source-files} Command
18946@findex -file-list-exec-source-files
18947
18948@subsubheading Synopsis
18949
18950@smallexample
18951 -file-list-exec-source-files
18952@end smallexample
18953
18954List the source files for the current executable.
18955
57c22c6c
BR
18956It will always output the filename, but only when GDB can find the absolute
18957file name of a source file, will it output the fullname.
18958
922fbb7b
AC
18959@subsubheading @value{GDBN} Command
18960
18961There's no @value{GDBN} command which directly corresponds to this one.
18962@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18963
18964@subsubheading Example
57c22c6c
BR
18965@smallexample
18966(@value{GDBP})
18967-file-list-exec-source-files
18968^done,files=[
18969@{file=foo.c,fullname=/home/foo.c@},
18970@{file=/home/bar.c,fullname=/home/bar.c@},
18971@{file=gdb_could_not_find_fullpath.c@}]
18972(@value{GDBP})
18973@end smallexample
922fbb7b
AC
18974
18975@subheading The @code{-file-list-shared-libraries} Command
18976@findex -file-list-shared-libraries
18977
18978@subsubheading Synopsis
18979
18980@smallexample
18981 -file-list-shared-libraries
18982@end smallexample
18983
18984List the shared libraries in the program.
18985
18986@subsubheading @value{GDBN} Command
18987
18988The corresponding @value{GDBN} command is @samp{info shared}.
18989
18990@subsubheading Example
18991N.A.
18992
18993
18994@subheading The @code{-file-list-symbol-files} Command
18995@findex -file-list-symbol-files
18996
18997@subsubheading Synopsis
18998
18999@smallexample
19000 -file-list-symbol-files
19001@end smallexample
19002
19003List symbol files.
19004
19005@subsubheading @value{GDBN} Command
19006
19007The corresponding @value{GDBN} command is @samp{info file} (part of it).
19008
19009@subsubheading Example
19010N.A.
19011
19012
19013@subheading The @code{-file-symbol-file} Command
19014@findex -file-symbol-file
19015
19016@subsubheading Synopsis
19017
19018@smallexample
19019 -file-symbol-file @var{file}
19020@end smallexample
19021
19022Read symbol table info from the specified @var{file} argument. When
19023used without arguments, clears @value{GDBN}'s symbol table info. No output is
19024produced, except for a completion notification.
19025
19026@subsubheading @value{GDBN} Command
19027
19028The corresponding @value{GDBN} command is @samp{symbol-file}.
19029
19030@subsubheading Example
19031
19032@smallexample
19033(@value{GDBP})
19034-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19035^done
19036(@value{GDBP})
19037@end smallexample
19038
19039@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19040@node GDB/MI Miscellaneous Commands
19041@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19042
19043@c @subheading -gdb-complete
19044
19045@subheading The @code{-gdb-exit} Command
19046@findex -gdb-exit
19047
19048@subsubheading Synopsis
19049
19050@smallexample
19051 -gdb-exit
19052@end smallexample
19053
19054Exit @value{GDBN} immediately.
19055
19056@subsubheading @value{GDBN} Command
19057
19058Approximately corresponds to @samp{quit}.
19059
19060@subsubheading Example
19061
19062@smallexample
19063(@value{GDBP})
19064-gdb-exit
19065@end smallexample
19066
19067@subheading The @code{-gdb-set} Command
19068@findex -gdb-set
19069
19070@subsubheading Synopsis
19071
19072@smallexample
19073 -gdb-set
19074@end smallexample
19075
19076Set an internal @value{GDBN} variable.
19077@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19078
19079@subsubheading @value{GDBN} Command
19080
19081The corresponding @value{GDBN} command is @samp{set}.
19082
19083@subsubheading Example
19084
19085@smallexample
19086(@value{GDBP})
19087-gdb-set $foo=3
19088^done
19089(@value{GDBP})
19090@end smallexample
19091
19092
19093@subheading The @code{-gdb-show} Command
19094@findex -gdb-show
19095
19096@subsubheading Synopsis
19097
19098@smallexample
19099 -gdb-show
19100@end smallexample
19101
19102Show the current value of a @value{GDBN} variable.
19103
19104@subsubheading @value{GDBN} command
19105
19106The corresponding @value{GDBN} command is @samp{show}.
19107
19108@subsubheading Example
19109
19110@smallexample
19111(@value{GDBP})
19112-gdb-show annotate
19113^done,value="0"
19114(@value{GDBP})
19115@end smallexample
19116
19117@c @subheading -gdb-source
19118
19119
19120@subheading The @code{-gdb-version} Command
19121@findex -gdb-version
19122
19123@subsubheading Synopsis
19124
19125@smallexample
19126 -gdb-version
19127@end smallexample
19128
19129Show version information for @value{GDBN}. Used mostly in testing.
19130
19131@subsubheading @value{GDBN} Command
19132
19133There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19134information when you start an interactive session.
19135
19136@subsubheading Example
19137
19138@c This example modifies the actual output from GDB to avoid overfull
19139@c box in TeX.
19140@smallexample
19141(@value{GDBP})
19142-gdb-version
19143~GNU gdb 5.2.1
19144~Copyright 2000 Free Software Foundation, Inc.
19145~GDB is free software, covered by the GNU General Public License, and
19146~you are welcome to change it and/or distribute copies of it under
19147~ certain conditions.
19148~Type "show copying" to see the conditions.
19149~There is absolutely no warranty for GDB. Type "show warranty" for
19150~ details.
b383017d 19151~This GDB was configured as
922fbb7b
AC
19152 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19153^done
19154(@value{GDBP})
19155@end smallexample
19156
19157@subheading The @code{-interpreter-exec} Command
19158@findex -interpreter-exec
19159
19160@subheading Synopsis
19161
19162@smallexample
19163-interpreter-exec @var{interpreter} @var{command}
19164@end smallexample
19165
19166Execute the specified @var{command} in the given @var{interpreter}.
19167
19168@subheading @value{GDBN} Command
19169
19170The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19171
19172@subheading Example
19173
19174@smallexample
19175(@value{GDBP})
19176-interpreter-exec console "break main"
19177&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19178&"During symbol reading, bad structure-type format.\n"
19179~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19180^done
19181(@value{GDBP})
19182@end smallexample
19183
19184@ignore
19185@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19186@node GDB/MI Kod Commands
19187@section @sc{gdb/mi} Kod Commands
19188
19189The Kod commands are not implemented.
19190
19191@c @subheading -kod-info
19192
19193@c @subheading -kod-list
19194
19195@c @subheading -kod-list-object-types
19196
19197@c @subheading -kod-show
19198
19199@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19200@node GDB/MI Memory Overlay Commands
19201@section @sc{gdb/mi} Memory Overlay Commands
19202
19203The memory overlay commands are not implemented.
19204
19205@c @subheading -overlay-auto
19206
19207@c @subheading -overlay-list-mapping-state
19208
19209@c @subheading -overlay-list-overlays
19210
19211@c @subheading -overlay-map
19212
19213@c @subheading -overlay-off
19214
19215@c @subheading -overlay-on
19216
19217@c @subheading -overlay-unmap
19218
19219@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19220@node GDB/MI Signal Handling Commands
19221@section @sc{gdb/mi} Signal Handling Commands
19222
19223Signal handling commands are not implemented.
19224
19225@c @subheading -signal-handle
19226
19227@c @subheading -signal-list-handle-actions
19228
19229@c @subheading -signal-list-signal-types
19230@end ignore
19231
19232
19233@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19234@node GDB/MI Stack Manipulation
19235@section @sc{gdb/mi} Stack Manipulation Commands
19236
dcaaae04
NR
19237
19238@subheading The @code{-stack-info-frame} Command
19239@findex -stack-info-frame
19240
19241@subsubheading Synopsis
19242
19243@smallexample
19244 -stack-info-frame
19245@end smallexample
19246
19247Get info on the selected frame.
19248
19249@subsubheading @value{GDBN} Command
19250
19251The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19252(without arguments).
19253
19254@subsubheading Example
19255
19256@smallexample
19257(@value{GDBP})
19258-stack-info-frame
19259^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19260file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19261fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19262(@value{GDBP})
19263@end smallexample
19264
922fbb7b
AC
19265@subheading The @code{-stack-info-depth} Command
19266@findex -stack-info-depth
19267
19268@subsubheading Synopsis
19269
19270@smallexample
19271 -stack-info-depth [ @var{max-depth} ]
19272@end smallexample
19273
19274Return the depth of the stack. If the integer argument @var{max-depth}
19275is specified, do not count beyond @var{max-depth} frames.
19276
19277@subsubheading @value{GDBN} Command
19278
19279There's no equivalent @value{GDBN} command.
19280
19281@subsubheading Example
19282
19283For a stack with frame levels 0 through 11:
19284
19285@smallexample
19286(@value{GDBP})
19287-stack-info-depth
19288^done,depth="12"
19289(@value{GDBP})
19290-stack-info-depth 4
19291^done,depth="4"
19292(@value{GDBP})
19293-stack-info-depth 12
19294^done,depth="12"
19295(@value{GDBP})
19296-stack-info-depth 11
19297^done,depth="11"
19298(@value{GDBP})
19299-stack-info-depth 13
19300^done,depth="12"
19301(@value{GDBP})
19302@end smallexample
19303
19304@subheading The @code{-stack-list-arguments} Command
19305@findex -stack-list-arguments
19306
19307@subsubheading Synopsis
19308
19309@smallexample
19310 -stack-list-arguments @var{show-values}
19311 [ @var{low-frame} @var{high-frame} ]
19312@end smallexample
19313
19314Display a list of the arguments for the frames between @var{low-frame}
19315and @var{high-frame} (inclusive). If @var{low-frame} and
19316@var{high-frame} are not provided, list the arguments for the whole call
19317stack.
19318
19319The @var{show-values} argument must have a value of 0 or 1. A value of
193200 means that only the names of the arguments are listed, a value of 1
19321means that both names and values of the arguments are printed.
19322
19323@subsubheading @value{GDBN} Command
19324
19325@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19326@samp{gdb_get_args} command which partially overlaps with the
19327functionality of @samp{-stack-list-arguments}.
19328
19329@subsubheading Example
19330
19331@smallexample
19332(@value{GDBP})
19333-stack-list-frames
19334^done,
19335stack=[
19336frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19337file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19338fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19339frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19340file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19341fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19342frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19343file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19344fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19345frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19346file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19347fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19348frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19349file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19350fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19351(@value{GDBP})
19352-stack-list-arguments 0
19353^done,
19354stack-args=[
19355frame=@{level="0",args=[]@},
19356frame=@{level="1",args=[name="strarg"]@},
19357frame=@{level="2",args=[name="intarg",name="strarg"]@},
19358frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19359frame=@{level="4",args=[]@}]
19360(@value{GDBP})
19361-stack-list-arguments 1
19362^done,
19363stack-args=[
19364frame=@{level="0",args=[]@},
19365frame=@{level="1",
19366 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19367frame=@{level="2",args=[
19368@{name="intarg",value="2"@},
19369@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19370@{frame=@{level="3",args=[
19371@{name="intarg",value="2"@},
19372@{name="strarg",value="0x11940 \"A string argument.\""@},
19373@{name="fltarg",value="3.5"@}]@},
19374frame=@{level="4",args=[]@}]
19375(@value{GDBP})
19376-stack-list-arguments 0 2 2
19377^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19378(@value{GDBP})
19379-stack-list-arguments 1 2 2
19380^done,stack-args=[frame=@{level="2",
19381args=[@{name="intarg",value="2"@},
19382@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19383(@value{GDBP})
19384@end smallexample
19385
19386@c @subheading -stack-list-exception-handlers
19387
19388
19389@subheading The @code{-stack-list-frames} Command
19390@findex -stack-list-frames
19391
19392@subsubheading Synopsis
19393
19394@smallexample
19395 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19396@end smallexample
19397
19398List the frames currently on the stack. For each frame it displays the
19399following info:
19400
19401@table @samp
19402@item @var{level}
19403The frame number, 0 being the topmost frame, i.e. the innermost function.
19404@item @var{addr}
19405The @code{$pc} value for that frame.
19406@item @var{func}
19407Function name.
19408@item @var{file}
19409File name of the source file where the function lives.
19410@item @var{line}
19411Line number corresponding to the @code{$pc}.
19412@end table
19413
19414If invoked without arguments, this command prints a backtrace for the
19415whole stack. If given two integer arguments, it shows the frames whose
19416levels are between the two arguments (inclusive). If the two arguments
19417are equal, it shows the single frame at the corresponding level.
19418
19419@subsubheading @value{GDBN} Command
19420
19421The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19422
19423@subsubheading Example
19424
19425Full stack backtrace:
19426
19427@smallexample
19428(@value{GDBP})
19429-stack-list-frames
19430^done,stack=
19431[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19432 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19433frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19434 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19435frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19436 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19437frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19438 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19439frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19440 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19441frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19442 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19443frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19444 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19445frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19446 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19447frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19448 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19449frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19450 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19451frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19452 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19453frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19454 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19455(@value{GDBP})
19456@end smallexample
19457
19458Show frames between @var{low_frame} and @var{high_frame}:
19459
19460@smallexample
19461(@value{GDBP})
19462-stack-list-frames 3 5
19463^done,stack=
19464[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19465 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19466frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19467 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19468frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19469 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19470(@value{GDBP})
19471@end smallexample
19472
19473Show a single frame:
19474
19475@smallexample
19476(@value{GDBP})
19477-stack-list-frames 3 3
19478^done,stack=
19479[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19480 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19481(@value{GDBP})
19482@end smallexample
19483
19484
19485@subheading The @code{-stack-list-locals} Command
19486@findex -stack-list-locals
19487
19488@subsubheading Synopsis
19489
19490@smallexample
19491 -stack-list-locals @var{print-values}
19492@end smallexample
19493
19494Display the local variable names for the current frame. With an
bc8ced35
NR
19495argument of 0 or @code{--no-values}, prints only the names of the variables.
19496With argument of 1 or @code{--all-values}, prints also their values. With
19497argument of 2 or @code{--simple-values}, prints the name, type and value for
19498simple data types and the name and type for arrays, structures and
19499unions. In this last case, the idea is that the user can see the
19500value of simple data types immediately and he can create variable
19501objects for other data types if he wishes to explore their values in
19502more detail.
922fbb7b
AC
19503
19504@subsubheading @value{GDBN} Command
19505
19506@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19507
19508@subsubheading Example
19509
19510@smallexample
19511(@value{GDBP})
19512-stack-list-locals 0
19513^done,locals=[name="A",name="B",name="C"]
19514(@value{GDBP})
bc8ced35 19515-stack-list-locals --all-values
922fbb7b 19516^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19517 @{name="C",value="@{1, 2, 3@}"@}]
19518-stack-list-locals --simple-values
19519^done,locals=[@{name="A",type="int",value="1"@},
19520 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19521(@value{GDBP})
19522@end smallexample
19523
19524
19525@subheading The @code{-stack-select-frame} Command
19526@findex -stack-select-frame
19527
19528@subsubheading Synopsis
19529
19530@smallexample
19531 -stack-select-frame @var{framenum}
19532@end smallexample
19533
19534Change the current frame. Select a different frame @var{framenum} on
19535the stack.
19536
19537@subsubheading @value{GDBN} Command
19538
19539The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19540@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19541
19542@subsubheading Example
19543
19544@smallexample
19545(@value{GDBP})
19546-stack-select-frame 2
19547^done
19548(@value{GDBP})
19549@end smallexample
19550
19551@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19552@node GDB/MI Symbol Query
19553@section @sc{gdb/mi} Symbol Query Commands
19554
19555
19556@subheading The @code{-symbol-info-address} Command
19557@findex -symbol-info-address
19558
19559@subsubheading Synopsis
19560
19561@smallexample
19562 -symbol-info-address @var{symbol}
19563@end smallexample
19564
19565Describe where @var{symbol} is stored.
19566
19567@subsubheading @value{GDBN} Command
19568
19569The corresponding @value{GDBN} command is @samp{info address}.
19570
19571@subsubheading Example
19572N.A.
19573
19574
19575@subheading The @code{-symbol-info-file} Command
19576@findex -symbol-info-file
19577
19578@subsubheading Synopsis
19579
19580@smallexample
19581 -symbol-info-file
19582@end smallexample
19583
19584Show the file for the symbol.
19585
19586@subsubheading @value{GDBN} Command
19587
19588There's no equivalent @value{GDBN} command. @code{gdbtk} has
19589@samp{gdb_find_file}.
19590
19591@subsubheading Example
19592N.A.
19593
19594
19595@subheading The @code{-symbol-info-function} Command
19596@findex -symbol-info-function
19597
19598@subsubheading Synopsis
19599
19600@smallexample
19601 -symbol-info-function
19602@end smallexample
19603
19604Show which function the symbol lives in.
19605
19606@subsubheading @value{GDBN} Command
19607
19608@samp{gdb_get_function} in @code{gdbtk}.
19609
19610@subsubheading Example
19611N.A.
19612
19613
19614@subheading The @code{-symbol-info-line} Command
19615@findex -symbol-info-line
19616
19617@subsubheading Synopsis
19618
19619@smallexample
19620 -symbol-info-line
19621@end smallexample
19622
19623Show the core addresses of the code for a source line.
19624
19625@subsubheading @value{GDBN} Command
19626
71952f4c 19627The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19628@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19629
19630@subsubheading Example
19631N.A.
19632
19633
19634@subheading The @code{-symbol-info-symbol} Command
19635@findex -symbol-info-symbol
19636
19637@subsubheading Synopsis
19638
19639@smallexample
19640 -symbol-info-symbol @var{addr}
19641@end smallexample
19642
19643Describe what symbol is at location @var{addr}.
19644
19645@subsubheading @value{GDBN} Command
19646
19647The corresponding @value{GDBN} command is @samp{info symbol}.
19648
19649@subsubheading Example
19650N.A.
19651
19652
19653@subheading The @code{-symbol-list-functions} Command
19654@findex -symbol-list-functions
19655
19656@subsubheading Synopsis
19657
19658@smallexample
19659 -symbol-list-functions
19660@end smallexample
19661
19662List the functions in the executable.
19663
19664@subsubheading @value{GDBN} Command
19665
19666@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19667@samp{gdb_search} in @code{gdbtk}.
19668
19669@subsubheading Example
19670N.A.
19671
19672
32e7087d
JB
19673@subheading The @code{-symbol-list-lines} Command
19674@findex -symbol-list-lines
19675
19676@subsubheading Synopsis
19677
19678@smallexample
19679 -symbol-list-lines @var{filename}
19680@end smallexample
19681
19682Print the list of lines that contain code and their associated program
19683addresses for the given source filename. The entries are sorted in
19684ascending PC order.
19685
19686@subsubheading @value{GDBN} Command
19687
19688There is no corresponding @value{GDBN} command.
19689
19690@subsubheading Example
19691@smallexample
19692(@value{GDBP})
19693-symbol-list-lines basics.c
54ff5908 19694^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19695(@value{GDBP})
19696@end smallexample
19697
19698
922fbb7b
AC
19699@subheading The @code{-symbol-list-types} Command
19700@findex -symbol-list-types
19701
19702@subsubheading Synopsis
19703
19704@smallexample
19705 -symbol-list-types
19706@end smallexample
19707
19708List all the type names.
19709
19710@subsubheading @value{GDBN} Command
19711
19712The corresponding commands are @samp{info types} in @value{GDBN},
19713@samp{gdb_search} in @code{gdbtk}.
19714
19715@subsubheading Example
19716N.A.
19717
19718
19719@subheading The @code{-symbol-list-variables} Command
19720@findex -symbol-list-variables
19721
19722@subsubheading Synopsis
19723
19724@smallexample
19725 -symbol-list-variables
19726@end smallexample
19727
19728List all the global and static variable names.
19729
19730@subsubheading @value{GDBN} Command
19731
19732@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19733
19734@subsubheading Example
19735N.A.
19736
19737
19738@subheading The @code{-symbol-locate} Command
19739@findex -symbol-locate
19740
19741@subsubheading Synopsis
19742
19743@smallexample
19744 -symbol-locate
19745@end smallexample
19746
19747@subsubheading @value{GDBN} Command
19748
19749@samp{gdb_loc} in @code{gdbtk}.
19750
19751@subsubheading Example
19752N.A.
19753
19754
19755@subheading The @code{-symbol-type} Command
19756@findex -symbol-type
19757
19758@subsubheading Synopsis
19759
19760@smallexample
19761 -symbol-type @var{variable}
19762@end smallexample
19763
19764Show type of @var{variable}.
19765
19766@subsubheading @value{GDBN} Command
19767
19768The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19769@samp{gdb_obj_variable}.
19770
19771@subsubheading Example
19772N.A.
19773
19774
19775@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19776@node GDB/MI Target Manipulation
19777@section @sc{gdb/mi} Target Manipulation Commands
19778
19779
19780@subheading The @code{-target-attach} Command
19781@findex -target-attach
19782
19783@subsubheading Synopsis
19784
19785@smallexample
19786 -target-attach @var{pid} | @var{file}
19787@end smallexample
19788
19789Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19790
19791@subsubheading @value{GDBN} command
19792
19793The corresponding @value{GDBN} command is @samp{attach}.
19794
19795@subsubheading Example
19796N.A.
19797
19798
19799@subheading The @code{-target-compare-sections} Command
19800@findex -target-compare-sections
19801
19802@subsubheading Synopsis
19803
19804@smallexample
19805 -target-compare-sections [ @var{section} ]
19806@end smallexample
19807
19808Compare data of section @var{section} on target to the exec file.
19809Without the argument, all sections are compared.
19810
19811@subsubheading @value{GDBN} Command
19812
19813The @value{GDBN} equivalent is @samp{compare-sections}.
19814
19815@subsubheading Example
19816N.A.
19817
19818
19819@subheading The @code{-target-detach} Command
19820@findex -target-detach
19821
19822@subsubheading Synopsis
19823
19824@smallexample
19825 -target-detach
19826@end smallexample
19827
19828Disconnect from the remote target. There's no output.
19829
19830@subsubheading @value{GDBN} command
19831
19832The corresponding @value{GDBN} command is @samp{detach}.
19833
19834@subsubheading Example
19835
19836@smallexample
19837(@value{GDBP})
19838-target-detach
19839^done
19840(@value{GDBP})
19841@end smallexample
19842
19843
07f31aa6
DJ
19844@subheading The @code{-target-disconnect} Command
19845@findex -target-disconnect
19846
19847@subsubheading Synopsis
19848
19849@example
19850 -target-disconnect
19851@end example
19852
19853Disconnect from the remote target. There's no output.
19854
19855@subsubheading @value{GDBN} command
19856
19857The corresponding @value{GDBN} command is @samp{disconnect}.
19858
19859@subsubheading Example
19860
19861@smallexample
19862(@value{GDBP})
19863-target-disconnect
19864^done
19865(@value{GDBP})
19866@end smallexample
19867
19868
922fbb7b
AC
19869@subheading The @code{-target-download} Command
19870@findex -target-download
19871
19872@subsubheading Synopsis
19873
19874@smallexample
19875 -target-download
19876@end smallexample
19877
19878Loads the executable onto the remote target.
19879It prints out an update message every half second, which includes the fields:
19880
19881@table @samp
19882@item section
19883The name of the section.
19884@item section-sent
19885The size of what has been sent so far for that section.
19886@item section-size
19887The size of the section.
19888@item total-sent
19889The total size of what was sent so far (the current and the previous sections).
19890@item total-size
19891The size of the overall executable to download.
19892@end table
19893
19894@noindent
19895Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19896@sc{gdb/mi} Output Syntax}).
19897
19898In addition, it prints the name and size of the sections, as they are
19899downloaded. These messages include the following fields:
19900
19901@table @samp
19902@item section
19903The name of the section.
19904@item section-size
19905The size of the section.
19906@item total-size
19907The size of the overall executable to download.
19908@end table
19909
19910@noindent
19911At the end, a summary is printed.
19912
19913@subsubheading @value{GDBN} Command
19914
19915The corresponding @value{GDBN} command is @samp{load}.
19916
19917@subsubheading Example
19918
19919Note: each status message appears on a single line. Here the messages
19920have been broken down so that they can fit onto a page.
19921
19922@smallexample
19923(@value{GDBP})
19924-target-download
19925+download,@{section=".text",section-size="6668",total-size="9880"@}
19926+download,@{section=".text",section-sent="512",section-size="6668",
19927total-sent="512",total-size="9880"@}
19928+download,@{section=".text",section-sent="1024",section-size="6668",
19929total-sent="1024",total-size="9880"@}
19930+download,@{section=".text",section-sent="1536",section-size="6668",
19931total-sent="1536",total-size="9880"@}
19932+download,@{section=".text",section-sent="2048",section-size="6668",
19933total-sent="2048",total-size="9880"@}
19934+download,@{section=".text",section-sent="2560",section-size="6668",
19935total-sent="2560",total-size="9880"@}
19936+download,@{section=".text",section-sent="3072",section-size="6668",
19937total-sent="3072",total-size="9880"@}
19938+download,@{section=".text",section-sent="3584",section-size="6668",
19939total-sent="3584",total-size="9880"@}
19940+download,@{section=".text",section-sent="4096",section-size="6668",
19941total-sent="4096",total-size="9880"@}
19942+download,@{section=".text",section-sent="4608",section-size="6668",
19943total-sent="4608",total-size="9880"@}
19944+download,@{section=".text",section-sent="5120",section-size="6668",
19945total-sent="5120",total-size="9880"@}
19946+download,@{section=".text",section-sent="5632",section-size="6668",
19947total-sent="5632",total-size="9880"@}
19948+download,@{section=".text",section-sent="6144",section-size="6668",
19949total-sent="6144",total-size="9880"@}
19950+download,@{section=".text",section-sent="6656",section-size="6668",
19951total-sent="6656",total-size="9880"@}
19952+download,@{section=".init",section-size="28",total-size="9880"@}
19953+download,@{section=".fini",section-size="28",total-size="9880"@}
19954+download,@{section=".data",section-size="3156",total-size="9880"@}
19955+download,@{section=".data",section-sent="512",section-size="3156",
19956total-sent="7236",total-size="9880"@}
19957+download,@{section=".data",section-sent="1024",section-size="3156",
19958total-sent="7748",total-size="9880"@}
19959+download,@{section=".data",section-sent="1536",section-size="3156",
19960total-sent="8260",total-size="9880"@}
19961+download,@{section=".data",section-sent="2048",section-size="3156",
19962total-sent="8772",total-size="9880"@}
19963+download,@{section=".data",section-sent="2560",section-size="3156",
19964total-sent="9284",total-size="9880"@}
19965+download,@{section=".data",section-sent="3072",section-size="3156",
19966total-sent="9796",total-size="9880"@}
19967^done,address="0x10004",load-size="9880",transfer-rate="6586",
19968write-rate="429"
19969(@value{GDBP})
19970@end smallexample
19971
19972
19973@subheading The @code{-target-exec-status} Command
19974@findex -target-exec-status
19975
19976@subsubheading Synopsis
19977
19978@smallexample
19979 -target-exec-status
19980@end smallexample
19981
19982Provide information on the state of the target (whether it is running or
19983not, for instance).
19984
19985@subsubheading @value{GDBN} Command
19986
19987There's no equivalent @value{GDBN} command.
19988
19989@subsubheading Example
19990N.A.
19991
19992
19993@subheading The @code{-target-list-available-targets} Command
19994@findex -target-list-available-targets
19995
19996@subsubheading Synopsis
19997
19998@smallexample
19999 -target-list-available-targets
20000@end smallexample
20001
20002List the possible targets to connect to.
20003
20004@subsubheading @value{GDBN} Command
20005
20006The corresponding @value{GDBN} command is @samp{help target}.
20007
20008@subsubheading Example
20009N.A.
20010
20011
20012@subheading The @code{-target-list-current-targets} Command
20013@findex -target-list-current-targets
20014
20015@subsubheading Synopsis
20016
20017@smallexample
20018 -target-list-current-targets
20019@end smallexample
20020
20021Describe the current target.
20022
20023@subsubheading @value{GDBN} Command
20024
20025The corresponding information is printed by @samp{info file} (among
20026other things).
20027
20028@subsubheading Example
20029N.A.
20030
20031
20032@subheading The @code{-target-list-parameters} Command
20033@findex -target-list-parameters
20034
20035@subsubheading Synopsis
20036
20037@smallexample
20038 -target-list-parameters
20039@end smallexample
20040
20041@c ????
20042
20043@subsubheading @value{GDBN} Command
20044
20045No equivalent.
20046
20047@subsubheading Example
20048N.A.
20049
20050
20051@subheading The @code{-target-select} Command
20052@findex -target-select
20053
20054@subsubheading Synopsis
20055
20056@smallexample
20057 -target-select @var{type} @var{parameters @dots{}}
20058@end smallexample
20059
20060Connect @value{GDBN} to the remote target. This command takes two args:
20061
20062@table @samp
20063@item @var{type}
20064The type of target, for instance @samp{async}, @samp{remote}, etc.
20065@item @var{parameters}
20066Device names, host names and the like. @xref{Target Commands, ,
20067Commands for managing targets}, for more details.
20068@end table
20069
20070The output is a connection notification, followed by the address at
20071which the target program is, in the following form:
20072
20073@smallexample
20074^connected,addr="@var{address}",func="@var{function name}",
20075 args=[@var{arg list}]
20076@end smallexample
20077
20078@subsubheading @value{GDBN} Command
20079
20080The corresponding @value{GDBN} command is @samp{target}.
20081
20082@subsubheading Example
20083
20084@smallexample
20085(@value{GDBP})
20086-target-select async /dev/ttya
20087^connected,addr="0xfe00a300",func="??",args=[]
20088(@value{GDBP})
20089@end smallexample
20090
20091@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20092@node GDB/MI Thread Commands
20093@section @sc{gdb/mi} Thread Commands
20094
20095
20096@subheading The @code{-thread-info} Command
20097@findex -thread-info
20098
20099@subsubheading Synopsis
20100
20101@smallexample
20102 -thread-info
20103@end smallexample
20104
20105@subsubheading @value{GDBN} command
20106
20107No equivalent.
20108
20109@subsubheading Example
20110N.A.
20111
20112
20113@subheading The @code{-thread-list-all-threads} Command
20114@findex -thread-list-all-threads
20115
20116@subsubheading Synopsis
20117
20118@smallexample
20119 -thread-list-all-threads
20120@end smallexample
20121
20122@subsubheading @value{GDBN} Command
20123
20124The equivalent @value{GDBN} command is @samp{info threads}.
20125
20126@subsubheading Example
20127N.A.
20128
20129
20130@subheading The @code{-thread-list-ids} Command
20131@findex -thread-list-ids
20132
20133@subsubheading Synopsis
20134
20135@smallexample
20136 -thread-list-ids
20137@end smallexample
20138
20139Produces a list of the currently known @value{GDBN} thread ids. At the
20140end of the list it also prints the total number of such threads.
20141
20142@subsubheading @value{GDBN} Command
20143
20144Part of @samp{info threads} supplies the same information.
20145
20146@subsubheading Example
20147
20148No threads present, besides the main process:
20149
20150@smallexample
20151(@value{GDBP})
20152-thread-list-ids
20153^done,thread-ids=@{@},number-of-threads="0"
20154(@value{GDBP})
20155@end smallexample
20156
20157
20158Several threads:
20159
20160@smallexample
20161(@value{GDBP})
20162-thread-list-ids
20163^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20164number-of-threads="3"
20165(@value{GDBP})
20166@end smallexample
20167
20168
20169@subheading The @code{-thread-select} Command
20170@findex -thread-select
20171
20172@subsubheading Synopsis
20173
20174@smallexample
20175 -thread-select @var{threadnum}
20176@end smallexample
20177
20178Make @var{threadnum} the current thread. It prints the number of the new
20179current thread, and the topmost frame for that thread.
20180
20181@subsubheading @value{GDBN} Command
20182
20183The corresponding @value{GDBN} command is @samp{thread}.
20184
20185@subsubheading Example
20186
20187@smallexample
20188(@value{GDBP})
20189-exec-next
20190^running
20191(@value{GDBP})
20192*stopped,reason="end-stepping-range",thread-id="2",line="187",
20193file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20194(@value{GDBP})
20195-thread-list-ids
20196^done,
20197thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20198number-of-threads="3"
20199(@value{GDBP})
20200-thread-select 3
20201^done,new-thread-id="3",
20202frame=@{level="0",func="vprintf",
20203args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20204@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20205(@value{GDBP})
20206@end smallexample
20207
20208@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20209@node GDB/MI Tracepoint Commands
20210@section @sc{gdb/mi} Tracepoint Commands
20211
20212The tracepoint commands are not yet implemented.
20213
20214@c @subheading -trace-actions
20215
20216@c @subheading -trace-delete
20217
20218@c @subheading -trace-disable
20219
20220@c @subheading -trace-dump
20221
20222@c @subheading -trace-enable
20223
20224@c @subheading -trace-exists
20225
20226@c @subheading -trace-find
20227
20228@c @subheading -trace-frame-number
20229
20230@c @subheading -trace-info
20231
20232@c @subheading -trace-insert
20233
20234@c @subheading -trace-list
20235
20236@c @subheading -trace-pass-count
20237
20238@c @subheading -trace-save
20239
20240@c @subheading -trace-start
20241
20242@c @subheading -trace-stop
20243
20244
20245@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20246@node GDB/MI Variable Objects
20247@section @sc{gdb/mi} Variable Objects
20248
20249
20250@subheading Motivation for Variable Objects in @sc{gdb/mi}
20251
20252For the implementation of a variable debugger window (locals, watched
20253expressions, etc.), we are proposing the adaptation of the existing code
20254used by @code{Insight}.
20255
20256The two main reasons for that are:
20257
20258@enumerate 1
20259@item
20260It has been proven in practice (it is already on its second generation).
20261
20262@item
20263It will shorten development time (needless to say how important it is
20264now).
20265@end enumerate
20266
20267The original interface was designed to be used by Tcl code, so it was
20268slightly changed so it could be used through @sc{gdb/mi}. This section
20269describes the @sc{gdb/mi} operations that will be available and gives some
20270hints about their use.
20271
20272@emph{Note}: In addition to the set of operations described here, we
20273expect the @sc{gui} implementation of a variable window to require, at
20274least, the following operations:
20275
20276@itemize @bullet
20277@item @code{-gdb-show} @code{output-radix}
20278@item @code{-stack-list-arguments}
20279@item @code{-stack-list-locals}
20280@item @code{-stack-select-frame}
20281@end itemize
20282
20283@subheading Introduction to Variable Objects in @sc{gdb/mi}
20284
20285@cindex variable objects in @sc{gdb/mi}
20286The basic idea behind variable objects is the creation of a named object
20287to represent a variable, an expression, a memory location or even a CPU
20288register. For each object created, a set of operations is available for
20289examining or changing its properties.
20290
20291Furthermore, complex data types, such as C structures, are represented
20292in a tree format. For instance, the @code{struct} type variable is the
20293root and the children will represent the struct members. If a child
20294is itself of a complex type, it will also have children of its own.
20295Appropriate language differences are handled for C, C@t{++} and Java.
20296
20297When returning the actual values of the objects, this facility allows
20298for the individual selection of the display format used in the result
20299creation. It can be chosen among: binary, decimal, hexadecimal, octal
20300and natural. Natural refers to a default format automatically
20301chosen based on the variable type (like decimal for an @code{int}, hex
20302for pointers, etc.).
20303
20304The following is the complete set of @sc{gdb/mi} operations defined to
20305access this functionality:
20306
20307@multitable @columnfractions .4 .6
20308@item @strong{Operation}
20309@tab @strong{Description}
20310
20311@item @code{-var-create}
20312@tab create a variable object
20313@item @code{-var-delete}
20314@tab delete the variable object and its children
20315@item @code{-var-set-format}
20316@tab set the display format of this variable
20317@item @code{-var-show-format}
20318@tab show the display format of this variable
20319@item @code{-var-info-num-children}
20320@tab tells how many children this object has
20321@item @code{-var-list-children}
20322@tab return a list of the object's children
20323@item @code{-var-info-type}
20324@tab show the type of this variable object
20325@item @code{-var-info-expression}
20326@tab print what this variable object represents
20327@item @code{-var-show-attributes}
20328@tab is this variable editable? does it exist here?
20329@item @code{-var-evaluate-expression}
20330@tab get the value of this variable
20331@item @code{-var-assign}
20332@tab set the value of this variable
20333@item @code{-var-update}
20334@tab update the variable and its children
20335@end multitable
20336
20337In the next subsection we describe each operation in detail and suggest
20338how it can be used.
20339
20340@subheading Description And Use of Operations on Variable Objects
20341
20342@subheading The @code{-var-create} Command
20343@findex -var-create
20344
20345@subsubheading Synopsis
20346
20347@smallexample
20348 -var-create @{@var{name} | "-"@}
20349 @{@var{frame-addr} | "*"@} @var{expression}
20350@end smallexample
20351
20352This operation creates a variable object, which allows the monitoring of
20353a variable, the result of an expression, a memory cell or a CPU
20354register.
20355
20356The @var{name} parameter is the string by which the object can be
20357referenced. It must be unique. If @samp{-} is specified, the varobj
20358system will generate a string ``varNNNNNN'' automatically. It will be
20359unique provided that one does not specify @var{name} on that format.
20360The command fails if a duplicate name is found.
20361
20362The frame under which the expression should be evaluated can be
20363specified by @var{frame-addr}. A @samp{*} indicates that the current
20364frame should be used.
20365
20366@var{expression} is any expression valid on the current language set (must not
20367begin with a @samp{*}), or one of the following:
20368
20369@itemize @bullet
20370@item
20371@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20372
20373@item
20374@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20375
20376@item
20377@samp{$@var{regname}} --- a CPU register name
20378@end itemize
20379
20380@subsubheading Result
20381
20382This operation returns the name, number of children and the type of the
20383object created. Type is returned as a string as the ones generated by
20384the @value{GDBN} CLI:
20385
20386@smallexample
20387 name="@var{name}",numchild="N",type="@var{type}"
20388@end smallexample
20389
20390
20391@subheading The @code{-var-delete} Command
20392@findex -var-delete
20393
20394@subsubheading Synopsis
20395
20396@smallexample
20397 -var-delete @var{name}
20398@end smallexample
20399
20400Deletes a previously created variable object and all of its children.
20401
20402Returns an error if the object @var{name} is not found.
20403
20404
20405@subheading The @code{-var-set-format} Command
20406@findex -var-set-format
20407
20408@subsubheading Synopsis
20409
20410@smallexample
20411 -var-set-format @var{name} @var{format-spec}
20412@end smallexample
20413
20414Sets the output format for the value of the object @var{name} to be
20415@var{format-spec}.
20416
20417The syntax for the @var{format-spec} is as follows:
20418
20419@smallexample
20420 @var{format-spec} @expansion{}
20421 @{binary | decimal | hexadecimal | octal | natural@}
20422@end smallexample
20423
20424
20425@subheading The @code{-var-show-format} Command
20426@findex -var-show-format
20427
20428@subsubheading Synopsis
20429
20430@smallexample
20431 -var-show-format @var{name}
20432@end smallexample
20433
20434Returns the format used to display the value of the object @var{name}.
20435
20436@smallexample
20437 @var{format} @expansion{}
20438 @var{format-spec}
20439@end smallexample
20440
20441
20442@subheading The @code{-var-info-num-children} Command
20443@findex -var-info-num-children
20444
20445@subsubheading Synopsis
20446
20447@smallexample
20448 -var-info-num-children @var{name}
20449@end smallexample
20450
20451Returns the number of children of a variable object @var{name}:
20452
20453@smallexample
20454 numchild=@var{n}
20455@end smallexample
20456
20457
20458@subheading The @code{-var-list-children} Command
20459@findex -var-list-children
20460
20461@subsubheading Synopsis
20462
20463@smallexample
bc8ced35 20464 -var-list-children [@var{print-values}] @var{name}
922fbb7b
AC
20465@end smallexample
20466
bc8ced35
NR
20467Returns a list of the children of the specified variable object. With
20468just the variable object name as an argument or with an optional
20469preceding argument of 0 or @code{--no-values}, prints only the names of the
20470variables. With an optional preceding argument of 1 or @code{--all-values},
20471also prints their values.
20472
20473@subsubheading Example
922fbb7b
AC
20474
20475@smallexample
bc8ced35
NR
20476(@value{GDBP})
20477 -var-list-children n
922fbb7b
AC
20478 numchild=@var{n},children=[@{name=@var{name},
20479 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20480(@value{GDBP})
20481 -var-list-children --all-values n
20482 numchild=@var{n},children=[@{name=@var{name},
20483 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20484@end smallexample
20485
20486
20487@subheading The @code{-var-info-type} Command
20488@findex -var-info-type
20489
20490@subsubheading Synopsis
20491
20492@smallexample
20493 -var-info-type @var{name}
20494@end smallexample
20495
20496Returns the type of the specified variable @var{name}. The type is
20497returned as a string in the same format as it is output by the
20498@value{GDBN} CLI:
20499
20500@smallexample
20501 type=@var{typename}
20502@end smallexample
20503
20504
20505@subheading The @code{-var-info-expression} Command
20506@findex -var-info-expression
20507
20508@subsubheading Synopsis
20509
20510@smallexample
20511 -var-info-expression @var{name}
20512@end smallexample
20513
20514Returns what is represented by the variable object @var{name}:
20515
20516@smallexample
20517 lang=@var{lang-spec},exp=@var{expression}
20518@end smallexample
20519
20520@noindent
20521where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20522
20523@subheading The @code{-var-show-attributes} Command
20524@findex -var-show-attributes
20525
20526@subsubheading Synopsis
20527
20528@smallexample
20529 -var-show-attributes @var{name}
20530@end smallexample
20531
20532List attributes of the specified variable object @var{name}:
20533
20534@smallexample
20535 status=@var{attr} [ ( ,@var{attr} )* ]
20536@end smallexample
20537
20538@noindent
20539where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20540
20541@subheading The @code{-var-evaluate-expression} Command
20542@findex -var-evaluate-expression
20543
20544@subsubheading Synopsis
20545
20546@smallexample
20547 -var-evaluate-expression @var{name}
20548@end smallexample
20549
20550Evaluates the expression that is represented by the specified variable
20551object and returns its value as a string in the current format specified
20552for the object:
20553
20554@smallexample
20555 value=@var{value}
20556@end smallexample
20557
20558Note that one must invoke @code{-var-list-children} for a variable
20559before the value of a child variable can be evaluated.
20560
20561@subheading The @code{-var-assign} Command
20562@findex -var-assign
20563
20564@subsubheading Synopsis
20565
20566@smallexample
20567 -var-assign @var{name} @var{expression}
20568@end smallexample
20569
20570Assigns the value of @var{expression} to the variable object specified
20571by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20572value is altered by the assign, the variable will show up in any
922fbb7b
AC
20573subsequent @code{-var-update} list.
20574
20575@subsubheading Example
20576
20577@smallexample
20578(@value{GDBP})
20579-var-assign var1 3
20580^done,value="3"
20581(@value{GDBP})
20582-var-update *
20583^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20584(@value{GDBP})
20585@end smallexample
20586
20587@subheading The @code{-var-update} Command
20588@findex -var-update
20589
20590@subsubheading Synopsis
20591
20592@smallexample
20593 -var-update @{@var{name} | "*"@}
20594@end smallexample
20595
20596Update the value of the variable object @var{name} by evaluating its
20597expression after fetching all the new values from memory or registers.
20598A @samp{*} causes all existing variable objects to be updated.
20599
20600
20601@node Annotations
20602@chapter @value{GDBN} Annotations
20603
086432e2
AC
20604This chapter describes annotations in @value{GDBN}. Annotations were
20605designed to interface @value{GDBN} to graphical user interfaces or other
20606similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20607relatively high level.
20608
086432e2
AC
20609The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20610(@pxref{GDB/MI}).
20611
922fbb7b
AC
20612@ignore
20613This is Edition @value{EDITION}, @value{DATE}.
20614@end ignore
20615
20616@menu
20617* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20618* Prompting:: Annotations marking @value{GDBN}'s need for input.
20619* Errors:: Annotations for error messages.
922fbb7b
AC
20620* Invalidation:: Some annotations describe things now invalid.
20621* Annotations for Running::
20622 Whether the program is running, how it stopped, etc.
20623* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20624@end menu
20625
20626@node Annotations Overview
20627@section What is an Annotation?
20628@cindex annotations
20629
922fbb7b
AC
20630Annotations start with a newline character, two @samp{control-z}
20631characters, and the name of the annotation. If there is no additional
20632information associated with this annotation, the name of the annotation
20633is followed immediately by a newline. If there is additional
20634information, the name of the annotation is followed by a space, the
20635additional information, and a newline. The additional information
20636cannot contain newline characters.
20637
20638Any output not beginning with a newline and two @samp{control-z}
20639characters denotes literal output from @value{GDBN}. Currently there is
20640no need for @value{GDBN} to output a newline followed by two
20641@samp{control-z} characters, but if there was such a need, the
20642annotations could be extended with an @samp{escape} annotation which
20643means those three characters as output.
20644
086432e2
AC
20645The annotation @var{level}, which is specified using the
20646@option{--annotate} command line option (@pxref{Mode Options}), controls
20647how much information @value{GDBN} prints together with its prompt,
20648values of expressions, source lines, and other types of output. Level 0
20649is for no anntations, level 1 is for use when @value{GDBN} is run as a
20650subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20651for programs that control @value{GDBN}, and level 2 annotations have
20652been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20653Interface, annotate, GDB's Obsolete Annotations}).
20654
20655@table @code
20656@kindex set annotate
20657@item set annotate @var{level}
e09f16f9 20658The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20659annotations to the specified @var{level}.
9c16f35a
EZ
20660
20661@item show annotate
20662@kindex show annotate
20663Show the current annotation level.
09d4efe1
EZ
20664@end table
20665
20666This chapter describes level 3 annotations.
086432e2 20667
922fbb7b
AC
20668A simple example of starting up @value{GDBN} with annotations is:
20669
20670@smallexample
086432e2
AC
20671$ @kbd{gdb --annotate=3}
20672GNU gdb 6.0
20673Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20674GDB is free software, covered by the GNU General Public License,
20675and you are welcome to change it and/or distribute copies of it
20676under certain conditions.
20677Type "show copying" to see the conditions.
20678There is absolutely no warranty for GDB. Type "show warranty"
20679for details.
086432e2 20680This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20681
20682^Z^Zpre-prompt
f7dc1244 20683(@value{GDBP})
922fbb7b 20684^Z^Zprompt
086432e2 20685@kbd{quit}
922fbb7b
AC
20686
20687^Z^Zpost-prompt
b383017d 20688$
922fbb7b
AC
20689@end smallexample
20690
20691Here @samp{quit} is input to @value{GDBN}; the rest is output from
20692@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20693denotes a @samp{control-z} character) are annotations; the rest is
20694output from @value{GDBN}.
20695
922fbb7b
AC
20696@node Prompting
20697@section Annotation for @value{GDBN} Input
20698
20699@cindex annotations for prompts
20700When @value{GDBN} prompts for input, it annotates this fact so it is possible
20701to know when to send output, when the output from a given command is
20702over, etc.
20703
20704Different kinds of input each have a different @dfn{input type}. Each
20705input type has three annotations: a @code{pre-} annotation, which
20706denotes the beginning of any prompt which is being output, a plain
20707annotation, which denotes the end of the prompt, and then a @code{post-}
20708annotation which denotes the end of any echo which may (or may not) be
20709associated with the input. For example, the @code{prompt} input type
20710features the following annotations:
20711
20712@smallexample
20713^Z^Zpre-prompt
20714^Z^Zprompt
20715^Z^Zpost-prompt
20716@end smallexample
20717
20718The input types are
20719
20720@table @code
20721@findex pre-prompt
20722@findex prompt
20723@findex post-prompt
20724@item prompt
20725When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20726
20727@findex pre-commands
20728@findex commands
20729@findex post-commands
20730@item commands
20731When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20732command. The annotations are repeated for each command which is input.
20733
20734@findex pre-overload-choice
20735@findex overload-choice
20736@findex post-overload-choice
20737@item overload-choice
20738When @value{GDBN} wants the user to select between various overloaded functions.
20739
20740@findex pre-query
20741@findex query
20742@findex post-query
20743@item query
20744When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20745
20746@findex pre-prompt-for-continue
20747@findex prompt-for-continue
20748@findex post-prompt-for-continue
20749@item prompt-for-continue
20750When @value{GDBN} is asking the user to press return to continue. Note: Don't
20751expect this to work well; instead use @code{set height 0} to disable
20752prompting. This is because the counting of lines is buggy in the
20753presence of annotations.
20754@end table
20755
20756@node Errors
20757@section Errors
20758@cindex annotations for errors, warnings and interrupts
20759
20760@findex quit
20761@smallexample
20762^Z^Zquit
20763@end smallexample
20764
20765This annotation occurs right before @value{GDBN} responds to an interrupt.
20766
20767@findex error
20768@smallexample
20769^Z^Zerror
20770@end smallexample
20771
20772This annotation occurs right before @value{GDBN} responds to an error.
20773
20774Quit and error annotations indicate that any annotations which @value{GDBN} was
20775in the middle of may end abruptly. For example, if a
20776@code{value-history-begin} annotation is followed by a @code{error}, one
20777cannot expect to receive the matching @code{value-history-end}. One
20778cannot expect not to receive it either, however; an error annotation
20779does not necessarily mean that @value{GDBN} is immediately returning all the way
20780to the top level.
20781
20782@findex error-begin
20783A quit or error annotation may be preceded by
20784
20785@smallexample
20786^Z^Zerror-begin
20787@end smallexample
20788
20789Any output between that and the quit or error annotation is the error
20790message.
20791
20792Warning messages are not yet annotated.
20793@c If we want to change that, need to fix warning(), type_error(),
20794@c range_error(), and possibly other places.
20795
922fbb7b
AC
20796@node Invalidation
20797@section Invalidation Notices
20798
20799@cindex annotations for invalidation messages
20800The following annotations say that certain pieces of state may have
20801changed.
20802
20803@table @code
20804@findex frames-invalid
20805@item ^Z^Zframes-invalid
20806
20807The frames (for example, output from the @code{backtrace} command) may
20808have changed.
20809
20810@findex breakpoints-invalid
20811@item ^Z^Zbreakpoints-invalid
20812
20813The breakpoints may have changed. For example, the user just added or
20814deleted a breakpoint.
20815@end table
20816
20817@node Annotations for Running
20818@section Running the Program
20819@cindex annotations for running programs
20820
20821@findex starting
20822@findex stopping
20823When the program starts executing due to a @value{GDBN} command such as
b383017d 20824@code{step} or @code{continue},
922fbb7b
AC
20825
20826@smallexample
20827^Z^Zstarting
20828@end smallexample
20829
b383017d 20830is output. When the program stops,
922fbb7b
AC
20831
20832@smallexample
20833^Z^Zstopped
20834@end smallexample
20835
20836is output. Before the @code{stopped} annotation, a variety of
20837annotations describe how the program stopped.
20838
20839@table @code
20840@findex exited
20841@item ^Z^Zexited @var{exit-status}
20842The program exited, and @var{exit-status} is the exit status (zero for
20843successful exit, otherwise nonzero).
20844
20845@findex signalled
20846@findex signal-name
20847@findex signal-name-end
20848@findex signal-string
20849@findex signal-string-end
20850@item ^Z^Zsignalled
20851The program exited with a signal. After the @code{^Z^Zsignalled}, the
20852annotation continues:
20853
20854@smallexample
20855@var{intro-text}
20856^Z^Zsignal-name
20857@var{name}
20858^Z^Zsignal-name-end
20859@var{middle-text}
20860^Z^Zsignal-string
20861@var{string}
20862^Z^Zsignal-string-end
20863@var{end-text}
20864@end smallexample
20865
20866@noindent
20867where @var{name} is the name of the signal, such as @code{SIGILL} or
20868@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20869as @code{Illegal Instruction} or @code{Segmentation fault}.
20870@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20871user's benefit and have no particular format.
20872
20873@findex signal
20874@item ^Z^Zsignal
20875The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20876just saying that the program received the signal, not that it was
20877terminated with it.
20878
20879@findex breakpoint
20880@item ^Z^Zbreakpoint @var{number}
20881The program hit breakpoint number @var{number}.
20882
20883@findex watchpoint
20884@item ^Z^Zwatchpoint @var{number}
20885The program hit watchpoint number @var{number}.
20886@end table
20887
20888@node Source Annotations
20889@section Displaying Source
20890@cindex annotations for source display
20891
20892@findex source
20893The following annotation is used instead of displaying source code:
20894
20895@smallexample
20896^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20897@end smallexample
20898
20899where @var{filename} is an absolute file name indicating which source
20900file, @var{line} is the line number within that file (where 1 is the
20901first line in the file), @var{character} is the character position
20902within the file (where 0 is the first character in the file) (for most
20903debug formats this will necessarily point to the beginning of a line),
20904@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20905line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20906@var{addr} is the address in the target program associated with the
20907source which is being displayed. @var{addr} is in the form @samp{0x}
20908followed by one or more lowercase hex digits (note that this does not
20909depend on the language).
20910
8e04817f
AC
20911@node GDB Bugs
20912@chapter Reporting Bugs in @value{GDBN}
20913@cindex bugs in @value{GDBN}
20914@cindex reporting bugs in @value{GDBN}
c906108c 20915
8e04817f 20916Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20917
8e04817f
AC
20918Reporting a bug may help you by bringing a solution to your problem, or it
20919may not. But in any case the principal function of a bug report is to help
20920the entire community by making the next version of @value{GDBN} work better. Bug
20921reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20922
8e04817f
AC
20923In order for a bug report to serve its purpose, you must include the
20924information that enables us to fix the bug.
c4555f82
SC
20925
20926@menu
8e04817f
AC
20927* Bug Criteria:: Have you found a bug?
20928* Bug Reporting:: How to report bugs
c4555f82
SC
20929@end menu
20930
8e04817f
AC
20931@node Bug Criteria
20932@section Have you found a bug?
20933@cindex bug criteria
c4555f82 20934
8e04817f 20935If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20936
20937@itemize @bullet
8e04817f
AC
20938@cindex fatal signal
20939@cindex debugger crash
20940@cindex crash of debugger
c4555f82 20941@item
8e04817f
AC
20942If the debugger gets a fatal signal, for any input whatever, that is a
20943@value{GDBN} bug. Reliable debuggers never crash.
20944
20945@cindex error on valid input
20946@item
20947If @value{GDBN} produces an error message for valid input, that is a
20948bug. (Note that if you're cross debugging, the problem may also be
20949somewhere in the connection to the target.)
c4555f82 20950
8e04817f 20951@cindex invalid input
c4555f82 20952@item
8e04817f
AC
20953If @value{GDBN} does not produce an error message for invalid input,
20954that is a bug. However, you should note that your idea of
20955``invalid input'' might be our idea of ``an extension'' or ``support
20956for traditional practice''.
20957
20958@item
20959If you are an experienced user of debugging tools, your suggestions
20960for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
20961@end itemize
20962
8e04817f
AC
20963@node Bug Reporting
20964@section How to report bugs
20965@cindex bug reports
20966@cindex @value{GDBN} bugs, reporting
20967
20968A number of companies and individuals offer support for @sc{gnu} products.
20969If you obtained @value{GDBN} from a support organization, we recommend you
20970contact that organization first.
20971
20972You can find contact information for many support companies and
20973individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
20974distribution.
20975@c should add a web page ref...
20976
129188f6
AC
20977In any event, we also recommend that you submit bug reports for
20978@value{GDBN}. The prefered method is to submit them directly using
20979@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
20980page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
20981be used.
8e04817f
AC
20982
20983@strong{Do not send bug reports to @samp{info-gdb}, or to
20984@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
20985not want to receive bug reports. Those that do have arranged to receive
20986@samp{bug-gdb}.
20987
20988The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
20989serves as a repeater. The mailing list and the newsgroup carry exactly
20990the same messages. Often people think of posting bug reports to the
20991newsgroup instead of mailing them. This appears to work, but it has one
20992problem which can be crucial: a newsgroup posting often lacks a mail
20993path back to the sender. Thus, if we need to ask for more information,
20994we may be unable to reach you. For this reason, it is better to send
20995bug reports to the mailing list.
c4555f82 20996
8e04817f
AC
20997The fundamental principle of reporting bugs usefully is this:
20998@strong{report all the facts}. If you are not sure whether to state a
20999fact or leave it out, state it!
c4555f82 21000
8e04817f
AC
21001Often people omit facts because they think they know what causes the
21002problem and assume that some details do not matter. Thus, you might
21003assume that the name of the variable you use in an example does not matter.
21004Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21005stray memory reference which happens to fetch from the location where that
21006name is stored in memory; perhaps, if the name were different, the contents
21007of that location would fool the debugger into doing the right thing despite
21008the bug. Play it safe and give a specific, complete example. That is the
21009easiest thing for you to do, and the most helpful.
c4555f82 21010
8e04817f
AC
21011Keep in mind that the purpose of a bug report is to enable us to fix the
21012bug. It may be that the bug has been reported previously, but neither
21013you nor we can know that unless your bug report is complete and
21014self-contained.
c4555f82 21015
8e04817f
AC
21016Sometimes people give a few sketchy facts and ask, ``Does this ring a
21017bell?'' Those bug reports are useless, and we urge everyone to
21018@emph{refuse to respond to them} except to chide the sender to report
21019bugs properly.
21020
21021To enable us to fix the bug, you should include all these things:
c4555f82
SC
21022
21023@itemize @bullet
21024@item
8e04817f
AC
21025The version of @value{GDBN}. @value{GDBN} announces it if you start
21026with no arguments; you can also print it at any time using @code{show
21027version}.
c4555f82 21028
8e04817f
AC
21029Without this, we will not know whether there is any point in looking for
21030the bug in the current version of @value{GDBN}.
c4555f82
SC
21031
21032@item
8e04817f
AC
21033The type of machine you are using, and the operating system name and
21034version number.
c4555f82
SC
21035
21036@item
8e04817f
AC
21037What compiler (and its version) was used to compile @value{GDBN}---e.g.
21038``@value{GCC}--2.8.1''.
c4555f82
SC
21039
21040@item
8e04817f
AC
21041What compiler (and its version) was used to compile the program you are
21042debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21043C Compiler''. For GCC, you can say @code{gcc --version} to get this
21044information; for other compilers, see the documentation for those
21045compilers.
c4555f82 21046
8e04817f
AC
21047@item
21048The command arguments you gave the compiler to compile your example and
21049observe the bug. For example, did you use @samp{-O}? To guarantee
21050you will not omit something important, list them all. A copy of the
21051Makefile (or the output from make) is sufficient.
c4555f82 21052
8e04817f
AC
21053If we were to try to guess the arguments, we would probably guess wrong
21054and then we might not encounter the bug.
c4555f82 21055
8e04817f
AC
21056@item
21057A complete input script, and all necessary source files, that will
21058reproduce the bug.
c4555f82 21059
8e04817f
AC
21060@item
21061A description of what behavior you observe that you believe is
21062incorrect. For example, ``It gets a fatal signal.''
c4555f82 21063
8e04817f
AC
21064Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21065will certainly notice it. But if the bug is incorrect output, we might
21066not notice unless it is glaringly wrong. You might as well not give us
21067a chance to make a mistake.
c4555f82 21068
8e04817f
AC
21069Even if the problem you experience is a fatal signal, you should still
21070say so explicitly. Suppose something strange is going on, such as, your
21071copy of @value{GDBN} is out of synch, or you have encountered a bug in
21072the C library on your system. (This has happened!) Your copy might
21073crash and ours would not. If you told us to expect a crash, then when
21074ours fails to crash, we would know that the bug was not happening for
21075us. If you had not told us to expect a crash, then we would not be able
21076to draw any conclusion from our observations.
c4555f82 21077
e0c07bf0
MC
21078@pindex script
21079@cindex recording a session script
21080To collect all this information, you can use a session recording program
21081such as @command{script}, which is available on many Unix systems.
21082Just run your @value{GDBN} session inside @command{script} and then
21083include the @file{typescript} file with your bug report.
21084
21085Another way to record a @value{GDBN} session is to run @value{GDBN}
21086inside Emacs and then save the entire buffer to a file.
21087
8e04817f
AC
21088@item
21089If you wish to suggest changes to the @value{GDBN} source, send us context
21090diffs. If you even discuss something in the @value{GDBN} source, refer to
21091it by context, not by line number.
c4555f82 21092
8e04817f
AC
21093The line numbers in our development sources will not match those in your
21094sources. Your line numbers would convey no useful information to us.
c4555f82 21095
8e04817f 21096@end itemize
c4555f82 21097
8e04817f 21098Here are some things that are not necessary:
c4555f82 21099
8e04817f
AC
21100@itemize @bullet
21101@item
21102A description of the envelope of the bug.
c4555f82 21103
8e04817f
AC
21104Often people who encounter a bug spend a lot of time investigating
21105which changes to the input file will make the bug go away and which
21106changes will not affect it.
c4555f82 21107
8e04817f
AC
21108This is often time consuming and not very useful, because the way we
21109will find the bug is by running a single example under the debugger
21110with breakpoints, not by pure deduction from a series of examples.
21111We recommend that you save your time for something else.
c4555f82 21112
8e04817f
AC
21113Of course, if you can find a simpler example to report @emph{instead}
21114of the original one, that is a convenience for us. Errors in the
21115output will be easier to spot, running under the debugger will take
21116less time, and so on.
c4555f82 21117
8e04817f
AC
21118However, simplification is not vital; if you do not want to do this,
21119report the bug anyway and send us the entire test case you used.
c4555f82 21120
8e04817f
AC
21121@item
21122A patch for the bug.
c4555f82 21123
8e04817f
AC
21124A patch for the bug does help us if it is a good one. But do not omit
21125the necessary information, such as the test case, on the assumption that
21126a patch is all we need. We might see problems with your patch and decide
21127to fix the problem another way, or we might not understand it at all.
c4555f82 21128
8e04817f
AC
21129Sometimes with a program as complicated as @value{GDBN} it is very hard to
21130construct an example that will make the program follow a certain path
21131through the code. If you do not send us the example, we will not be able
21132to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21133
8e04817f
AC
21134And if we cannot understand what bug you are trying to fix, or why your
21135patch should be an improvement, we will not install it. A test case will
21136help us to understand.
c4555f82 21137
8e04817f
AC
21138@item
21139A guess about what the bug is or what it depends on.
c4555f82 21140
8e04817f
AC
21141Such guesses are usually wrong. Even we cannot guess right about such
21142things without first using the debugger to find the facts.
21143@end itemize
c4555f82 21144
8e04817f
AC
21145@c The readline documentation is distributed with the readline code
21146@c and consists of the two following files:
21147@c rluser.texinfo
21148@c inc-hist.texinfo
21149@c Use -I with makeinfo to point to the appropriate directory,
21150@c environment var TEXINPUTS with TeX.
21151@include rluser.texinfo
21152@include inc-hist.texinfo
c4555f82 21153
c4555f82 21154
8e04817f
AC
21155@node Formatting Documentation
21156@appendix Formatting Documentation
c4555f82 21157
8e04817f
AC
21158@cindex @value{GDBN} reference card
21159@cindex reference card
21160The @value{GDBN} 4 release includes an already-formatted reference card, ready
21161for printing with PostScript or Ghostscript, in the @file{gdb}
21162subdirectory of the main source directory@footnote{In
21163@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21164release.}. If you can use PostScript or Ghostscript with your printer,
21165you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21166
8e04817f
AC
21167The release also includes the source for the reference card. You
21168can format it, using @TeX{}, by typing:
c4555f82 21169
474c8240 21170@smallexample
8e04817f 21171make refcard.dvi
474c8240 21172@end smallexample
c4555f82 21173
8e04817f
AC
21174The @value{GDBN} reference card is designed to print in @dfn{landscape}
21175mode on US ``letter'' size paper;
21176that is, on a sheet 11 inches wide by 8.5 inches
21177high. You will need to specify this form of printing as an option to
21178your @sc{dvi} output program.
c4555f82 21179
8e04817f 21180@cindex documentation
c4555f82 21181
8e04817f
AC
21182All the documentation for @value{GDBN} comes as part of the machine-readable
21183distribution. The documentation is written in Texinfo format, which is
21184a documentation system that uses a single source file to produce both
21185on-line information and a printed manual. You can use one of the Info
21186formatting commands to create the on-line version of the documentation
21187and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21188
8e04817f
AC
21189@value{GDBN} includes an already formatted copy of the on-line Info
21190version of this manual in the @file{gdb} subdirectory. The main Info
21191file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21192subordinate files matching @samp{gdb.info*} in the same directory. If
21193necessary, you can print out these files, or read them with any editor;
21194but they are easier to read using the @code{info} subsystem in @sc{gnu}
21195Emacs or the standalone @code{info} program, available as part of the
21196@sc{gnu} Texinfo distribution.
c4555f82 21197
8e04817f
AC
21198If you want to format these Info files yourself, you need one of the
21199Info formatting programs, such as @code{texinfo-format-buffer} or
21200@code{makeinfo}.
c4555f82 21201
8e04817f
AC
21202If you have @code{makeinfo} installed, and are in the top level
21203@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21204version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21205
474c8240 21206@smallexample
8e04817f
AC
21207cd gdb
21208make gdb.info
474c8240 21209@end smallexample
c4555f82 21210
8e04817f
AC
21211If you want to typeset and print copies of this manual, you need @TeX{},
21212a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21213Texinfo definitions file.
c4555f82 21214
8e04817f
AC
21215@TeX{} is a typesetting program; it does not print files directly, but
21216produces output files called @sc{dvi} files. To print a typeset
21217document, you need a program to print @sc{dvi} files. If your system
21218has @TeX{} installed, chances are it has such a program. The precise
21219command to use depends on your system; @kbd{lpr -d} is common; another
21220(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21221require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21222
8e04817f
AC
21223@TeX{} also requires a macro definitions file called
21224@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21225written in Texinfo format. On its own, @TeX{} cannot either read or
21226typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21227and is located in the @file{gdb-@var{version-number}/texinfo}
21228directory.
c4555f82 21229
8e04817f
AC
21230If you have @TeX{} and a @sc{dvi} printer program installed, you can
21231typeset and print this manual. First switch to the the @file{gdb}
21232subdirectory of the main source directory (for example, to
21233@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21234
474c8240 21235@smallexample
8e04817f 21236make gdb.dvi
474c8240 21237@end smallexample
c4555f82 21238
8e04817f 21239Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21240
8e04817f
AC
21241@node Installing GDB
21242@appendix Installing @value{GDBN}
21243@cindex configuring @value{GDBN}
21244@cindex installation
94e91d6d 21245@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21246
8e04817f
AC
21247@value{GDBN} comes with a @code{configure} script that automates the process
21248of preparing @value{GDBN} for installation; you can then use @code{make} to
21249build the @code{gdb} program.
21250@iftex
21251@c irrelevant in info file; it's as current as the code it lives with.
21252@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21253look at the @file{README} file in the sources; we may have improved the
21254installation procedures since publishing this manual.}
21255@end iftex
c4555f82 21256
8e04817f
AC
21257The @value{GDBN} distribution includes all the source code you need for
21258@value{GDBN} in a single directory, whose name is usually composed by
21259appending the version number to @samp{gdb}.
c4555f82 21260
8e04817f
AC
21261For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21262@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21263
8e04817f
AC
21264@table @code
21265@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21266script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21267
8e04817f
AC
21268@item gdb-@value{GDBVN}/gdb
21269the source specific to @value{GDBN} itself
c4555f82 21270
8e04817f
AC
21271@item gdb-@value{GDBVN}/bfd
21272source for the Binary File Descriptor library
c906108c 21273
8e04817f
AC
21274@item gdb-@value{GDBVN}/include
21275@sc{gnu} include files
c906108c 21276
8e04817f
AC
21277@item gdb-@value{GDBVN}/libiberty
21278source for the @samp{-liberty} free software library
c906108c 21279
8e04817f
AC
21280@item gdb-@value{GDBVN}/opcodes
21281source for the library of opcode tables and disassemblers
c906108c 21282
8e04817f
AC
21283@item gdb-@value{GDBVN}/readline
21284source for the @sc{gnu} command-line interface
c906108c 21285
8e04817f
AC
21286@item gdb-@value{GDBVN}/glob
21287source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21288
8e04817f
AC
21289@item gdb-@value{GDBVN}/mmalloc
21290source for the @sc{gnu} memory-mapped malloc package
21291@end table
c906108c 21292
8e04817f
AC
21293The simplest way to configure and build @value{GDBN} is to run @code{configure}
21294from the @file{gdb-@var{version-number}} source directory, which in
21295this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21296
8e04817f
AC
21297First switch to the @file{gdb-@var{version-number}} source directory
21298if you are not already in it; then run @code{configure}. Pass the
21299identifier for the platform on which @value{GDBN} will run as an
21300argument.
c906108c 21301
8e04817f 21302For example:
c906108c 21303
474c8240 21304@smallexample
8e04817f
AC
21305cd gdb-@value{GDBVN}
21306./configure @var{host}
21307make
474c8240 21308@end smallexample
c906108c 21309
8e04817f
AC
21310@noindent
21311where @var{host} is an identifier such as @samp{sun4} or
21312@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21313(You can often leave off @var{host}; @code{configure} tries to guess the
21314correct value by examining your system.)
c906108c 21315
8e04817f
AC
21316Running @samp{configure @var{host}} and then running @code{make} builds the
21317@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21318libraries, then @code{gdb} itself. The configured source files, and the
21319binaries, are left in the corresponding source directories.
c906108c 21320
8e04817f
AC
21321@need 750
21322@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21323system does not recognize this automatically when you run a different
21324shell, you may need to run @code{sh} on it explicitly:
c906108c 21325
474c8240 21326@smallexample
8e04817f 21327sh configure @var{host}
474c8240 21328@end smallexample
c906108c 21329
8e04817f
AC
21330If you run @code{configure} from a directory that contains source
21331directories for multiple libraries or programs, such as the
21332@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21333creates configuration files for every directory level underneath (unless
21334you tell it not to, with the @samp{--norecursion} option).
21335
94e91d6d
MC
21336You should run the @code{configure} script from the top directory in the
21337source tree, the @file{gdb-@var{version-number}} directory. If you run
21338@code{configure} from one of the subdirectories, you will configure only
21339that subdirectory. That is usually not what you want. In particular,
21340if you run the first @code{configure} from the @file{gdb} subdirectory
21341of the @file{gdb-@var{version-number}} directory, you will omit the
21342configuration of @file{bfd}, @file{readline}, and other sibling
21343directories of the @file{gdb} subdirectory. This leads to build errors
21344about missing include files such as @file{bfd/bfd.h}.
c906108c 21345
8e04817f
AC
21346You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21347However, you should make sure that the shell on your path (named by
21348the @samp{SHELL} environment variable) is publicly readable. Remember
21349that @value{GDBN} uses the shell to start your program---some systems refuse to
21350let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21351
8e04817f
AC
21352@menu
21353* Separate Objdir:: Compiling @value{GDBN} in another directory
21354* Config Names:: Specifying names for hosts and targets
21355* Configure Options:: Summary of options for configure
21356@end menu
c906108c 21357
8e04817f
AC
21358@node Separate Objdir
21359@section Compiling @value{GDBN} in another directory
c906108c 21360
8e04817f
AC
21361If you want to run @value{GDBN} versions for several host or target machines,
21362you need a different @code{gdb} compiled for each combination of
21363host and target. @code{configure} is designed to make this easy by
21364allowing you to generate each configuration in a separate subdirectory,
21365rather than in the source directory. If your @code{make} program
21366handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21367@code{make} in each of these directories builds the @code{gdb}
21368program specified there.
c906108c 21369
8e04817f
AC
21370To build @code{gdb} in a separate directory, run @code{configure}
21371with the @samp{--srcdir} option to specify where to find the source.
21372(You also need to specify a path to find @code{configure}
21373itself from your working directory. If the path to @code{configure}
21374would be the same as the argument to @samp{--srcdir}, you can leave out
21375the @samp{--srcdir} option; it is assumed.)
c906108c 21376
8e04817f
AC
21377For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21378separate directory for a Sun 4 like this:
c906108c 21379
474c8240 21380@smallexample
8e04817f
AC
21381@group
21382cd gdb-@value{GDBVN}
21383mkdir ../gdb-sun4
21384cd ../gdb-sun4
21385../gdb-@value{GDBVN}/configure sun4
21386make
21387@end group
474c8240 21388@end smallexample
c906108c 21389
8e04817f
AC
21390When @code{configure} builds a configuration using a remote source
21391directory, it creates a tree for the binaries with the same structure
21392(and using the same names) as the tree under the source directory. In
21393the example, you'd find the Sun 4 library @file{libiberty.a} in the
21394directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21395@file{gdb-sun4/gdb}.
c906108c 21396
94e91d6d
MC
21397Make sure that your path to the @file{configure} script has just one
21398instance of @file{gdb} in it. If your path to @file{configure} looks
21399like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21400one subdirectory of @value{GDBN}, not the whole package. This leads to
21401build errors about missing include files such as @file{bfd/bfd.h}.
21402
8e04817f
AC
21403One popular reason to build several @value{GDBN} configurations in separate
21404directories is to configure @value{GDBN} for cross-compiling (where
21405@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21406programs that run on another machine---the @dfn{target}).
21407You specify a cross-debugging target by
21408giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21409
8e04817f
AC
21410When you run @code{make} to build a program or library, you must run
21411it in a configured directory---whatever directory you were in when you
21412called @code{configure} (or one of its subdirectories).
c906108c 21413
8e04817f
AC
21414The @code{Makefile} that @code{configure} generates in each source
21415directory also runs recursively. If you type @code{make} in a source
21416directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21417directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21418will build all the required libraries, and then build GDB.
c906108c 21419
8e04817f
AC
21420When you have multiple hosts or targets configured in separate
21421directories, you can run @code{make} on them in parallel (for example,
21422if they are NFS-mounted on each of the hosts); they will not interfere
21423with each other.
c906108c 21424
8e04817f
AC
21425@node Config Names
21426@section Specifying names for hosts and targets
c906108c 21427
8e04817f
AC
21428The specifications used for hosts and targets in the @code{configure}
21429script are based on a three-part naming scheme, but some short predefined
21430aliases are also supported. The full naming scheme encodes three pieces
21431of information in the following pattern:
c906108c 21432
474c8240 21433@smallexample
8e04817f 21434@var{architecture}-@var{vendor}-@var{os}
474c8240 21435@end smallexample
c906108c 21436
8e04817f
AC
21437For example, you can use the alias @code{sun4} as a @var{host} argument,
21438or as the value for @var{target} in a @code{--target=@var{target}}
21439option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21440
8e04817f
AC
21441The @code{configure} script accompanying @value{GDBN} does not provide
21442any query facility to list all supported host and target names or
21443aliases. @code{configure} calls the Bourne shell script
21444@code{config.sub} to map abbreviations to full names; you can read the
21445script, if you wish, or you can use it to test your guesses on
21446abbreviations---for example:
c906108c 21447
8e04817f
AC
21448@smallexample
21449% sh config.sub i386-linux
21450i386-pc-linux-gnu
21451% sh config.sub alpha-linux
21452alpha-unknown-linux-gnu
21453% sh config.sub hp9k700
21454hppa1.1-hp-hpux
21455% sh config.sub sun4
21456sparc-sun-sunos4.1.1
21457% sh config.sub sun3
21458m68k-sun-sunos4.1.1
21459% sh config.sub i986v
21460Invalid configuration `i986v': machine `i986v' not recognized
21461@end smallexample
c906108c 21462
8e04817f
AC
21463@noindent
21464@code{config.sub} is also distributed in the @value{GDBN} source
21465directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21466
8e04817f
AC
21467@node Configure Options
21468@section @code{configure} options
c906108c 21469
8e04817f
AC
21470Here is a summary of the @code{configure} options and arguments that
21471are most often useful for building @value{GDBN}. @code{configure} also has
21472several other options not listed here. @inforef{What Configure
21473Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21474
474c8240 21475@smallexample
8e04817f
AC
21476configure @r{[}--help@r{]}
21477 @r{[}--prefix=@var{dir}@r{]}
21478 @r{[}--exec-prefix=@var{dir}@r{]}
21479 @r{[}--srcdir=@var{dirname}@r{]}
21480 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21481 @r{[}--target=@var{target}@r{]}
21482 @var{host}
474c8240 21483@end smallexample
c906108c 21484
8e04817f
AC
21485@noindent
21486You may introduce options with a single @samp{-} rather than
21487@samp{--} if you prefer; but you may abbreviate option names if you use
21488@samp{--}.
c906108c 21489
8e04817f
AC
21490@table @code
21491@item --help
21492Display a quick summary of how to invoke @code{configure}.
c906108c 21493
8e04817f
AC
21494@item --prefix=@var{dir}
21495Configure the source to install programs and files under directory
21496@file{@var{dir}}.
c906108c 21497
8e04817f
AC
21498@item --exec-prefix=@var{dir}
21499Configure the source to install programs under directory
21500@file{@var{dir}}.
c906108c 21501
8e04817f
AC
21502@c avoid splitting the warning from the explanation:
21503@need 2000
21504@item --srcdir=@var{dirname}
21505@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21506@code{make} that implements the @code{VPATH} feature.}@*
21507Use this option to make configurations in directories separate from the
21508@value{GDBN} source directories. Among other things, you can use this to
21509build (or maintain) several configurations simultaneously, in separate
21510directories. @code{configure} writes configuration specific files in
21511the current directory, but arranges for them to use the source in the
21512directory @var{dirname}. @code{configure} creates directories under
21513the working directory in parallel to the source directories below
21514@var{dirname}.
c906108c 21515
8e04817f
AC
21516@item --norecursion
21517Configure only the directory level where @code{configure} is executed; do not
21518propagate configuration to subdirectories.
c906108c 21519
8e04817f
AC
21520@item --target=@var{target}
21521Configure @value{GDBN} for cross-debugging programs running on the specified
21522@var{target}. Without this option, @value{GDBN} is configured to debug
21523programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21524
8e04817f 21525There is no convenient way to generate a list of all available targets.
c906108c 21526
8e04817f
AC
21527@item @var{host} @dots{}
21528Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21529
8e04817f
AC
21530There is no convenient way to generate a list of all available hosts.
21531@end table
c906108c 21532
8e04817f
AC
21533There are many other options available as well, but they are generally
21534needed for special purposes only.
c906108c 21535
8e04817f
AC
21536@node Maintenance Commands
21537@appendix Maintenance Commands
21538@cindex maintenance commands
21539@cindex internal commands
c906108c 21540
8e04817f 21541In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21542includes a number of commands intended for @value{GDBN} developers,
21543that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21544provided here for reference. (For commands that turn on debugging
21545messages, see @ref{Debugging Output}.)
c906108c 21546
8e04817f 21547@table @code
09d4efe1
EZ
21548@kindex maint agent
21549@item maint agent @var{expression}
21550Translate the given @var{expression} into remote agent bytecodes.
21551This command is useful for debugging the Agent Expression mechanism
21552(@pxref{Agent Expressions}).
21553
8e04817f
AC
21554@kindex maint info breakpoints
21555@item @anchor{maint info breakpoints}maint info breakpoints
21556Using the same format as @samp{info breakpoints}, display both the
21557breakpoints you've set explicitly, and those @value{GDBN} is using for
21558internal purposes. Internal breakpoints are shown with negative
21559breakpoint numbers. The type column identifies what kind of breakpoint
21560is shown:
c906108c 21561
8e04817f
AC
21562@table @code
21563@item breakpoint
21564Normal, explicitly set breakpoint.
c906108c 21565
8e04817f
AC
21566@item watchpoint
21567Normal, explicitly set watchpoint.
c906108c 21568
8e04817f
AC
21569@item longjmp
21570Internal breakpoint, used to handle correctly stepping through
21571@code{longjmp} calls.
c906108c 21572
8e04817f
AC
21573@item longjmp resume
21574Internal breakpoint at the target of a @code{longjmp}.
c906108c 21575
8e04817f
AC
21576@item until
21577Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21578
8e04817f
AC
21579@item finish
21580Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21581
8e04817f
AC
21582@item shlib events
21583Shared library events.
c906108c 21584
8e04817f 21585@end table
c906108c 21586
09d4efe1
EZ
21587@kindex maint check-symtabs
21588@item maint check-symtabs
21589Check the consistency of psymtabs and symtabs.
21590
21591@kindex maint cplus first_component
21592@item maint cplus first_component @var{name}
21593Print the first C@t{++} class/namespace component of @var{name}.
21594
21595@kindex maint cplus namespace
21596@item maint cplus namespace
21597Print the list of possible C@t{++} namespaces.
21598
21599@kindex maint demangle
21600@item maint demangle @var{name}
21601Demangle a C@t{++} or Objective-C manled @var{name}.
21602
21603@kindex maint deprecate
21604@kindex maint undeprecate
21605@cindex deprecated commands
21606@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21607@itemx maint undeprecate @var{command}
21608Deprecate or undeprecate the named @var{command}. Deprecated commands
21609cause @value{GDBN} to issue a warning when you use them. The optional
21610argument @var{replacement} says which newer command should be used in
21611favor of the deprecated one; if it is given, @value{GDBN} will mention
21612the replacement as part of the warning.
21613
21614@kindex maint dump-me
21615@item maint dump-me
721c2651 21616@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21617Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21618This is supported only on systems which support aborting a program
21619with the @code{SIGQUIT} signal.
09d4efe1 21620
8d30a00d
AC
21621@kindex maint internal-error
21622@kindex maint internal-warning
09d4efe1
EZ
21623@item maint internal-error @r{[}@var{message-text}@r{]}
21624@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21625Cause @value{GDBN} to call the internal function @code{internal_error}
21626or @code{internal_warning} and hence behave as though an internal error
21627or internal warning has been detected. In addition to reporting the
21628internal problem, these functions give the user the opportunity to
21629either quit @value{GDBN} or create a core file of the current
21630@value{GDBN} session.
21631
09d4efe1
EZ
21632These commands take an optional parameter @var{message-text} that is
21633used as the text of the error or warning message.
21634
21635Here's an example of using @code{indernal-error}:
21636
8d30a00d 21637@smallexample
f7dc1244 21638(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21639@dots{}/maint.c:121: internal-error: testing, 1, 2
21640A problem internal to GDB has been detected. Further
21641debugging may prove unreliable.
21642Quit this debugging session? (y or n) @kbd{n}
21643Create a core file? (y or n) @kbd{n}
f7dc1244 21644(@value{GDBP})
8d30a00d
AC
21645@end smallexample
21646
09d4efe1
EZ
21647@kindex maint packet
21648@item maint packet @var{text}
21649If @value{GDBN} is talking to an inferior via the serial protocol,
21650then this command sends the string @var{text} to the inferior, and
21651displays the response packet. @value{GDBN} supplies the initial
21652@samp{$} character, the terminating @samp{#} character, and the
21653checksum.
21654
21655@kindex maint print architecture
21656@item maint print architecture @r{[}@var{file}@r{]}
21657Print the entire architecture configuration. The optional argument
21658@var{file} names the file where the output goes.
8d30a00d 21659
00905d52
AC
21660@kindex maint print dummy-frames
21661@item maint print dummy-frames
00905d52
AC
21662Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21663
21664@smallexample
f7dc1244 21665(@value{GDBP}) @kbd{b add}
00905d52 21666@dots{}
f7dc1244 21667(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21668Breakpoint 2, add (a=2, b=3) at @dots{}
2166958 return (a + b);
21670The program being debugged stopped while in a function called from GDB.
21671@dots{}
f7dc1244 21672(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
216730x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21674 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21675 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21676(@value{GDBP})
00905d52
AC
21677@end smallexample
21678
21679Takes an optional file parameter.
21680
0680b120
AC
21681@kindex maint print registers
21682@kindex maint print raw-registers
21683@kindex maint print cooked-registers
617073a9 21684@kindex maint print register-groups
09d4efe1
EZ
21685@item maint print registers @r{[}@var{file}@r{]}
21686@itemx maint print raw-registers @r{[}@var{file}@r{]}
21687@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21688@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21689Print @value{GDBN}'s internal register data structures.
21690
617073a9
AC
21691The command @code{maint print raw-registers} includes the contents of
21692the raw register cache; the command @code{maint print cooked-registers}
21693includes the (cooked) value of all registers; and the command
21694@code{maint print register-groups} includes the groups that each
21695register is a member of. @xref{Registers,, Registers, gdbint,
21696@value{GDBN} Internals}.
0680b120 21697
09d4efe1
EZ
21698These commands take an optional parameter, a file name to which to
21699write the information.
0680b120 21700
617073a9 21701@kindex maint print reggroups
09d4efe1
EZ
21702@item maint print reggroups @r{[}@var{file}@r{]}
21703Print @value{GDBN}'s internal register group data structures. The
21704optional argument @var{file} tells to what file to write the
21705information.
617073a9 21706
09d4efe1 21707The register groups info looks like this:
617073a9
AC
21708
21709@smallexample
f7dc1244 21710(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21711 Group Type
21712 general user
21713 float user
21714 all user
21715 vector user
21716 system user
21717 save internal
21718 restore internal
617073a9
AC
21719@end smallexample
21720
09d4efe1
EZ
21721@kindex flushregs
21722@item flushregs
21723This command forces @value{GDBN} to flush its internal register cache.
21724
21725@kindex maint print objfiles
21726@cindex info for known object files
21727@item maint print objfiles
21728Print a dump of all known object files. For each object file, this
21729command prints its name, address in memory, and all of its psymtabs
21730and symtabs.
21731
21732@kindex maint print statistics
21733@cindex bcache statistics
21734@item maint print statistics
21735This command prints, for each object file in the program, various data
21736about that object file followed by the byte cache (@dfn{bcache})
21737statistics for the object file. The objfile data includes the number
21738of minimal, partical, full, and stabs symbols, the number of types
21739defined by the objfile, the number of as yet unexpanded psym tables,
21740the number of line tables and string tables, and the amount of memory
21741used by the various tables. The bcache statistics include the counts,
21742sizes, and counts of duplicates of all and unique objects, max,
21743average, and median entry size, total memory used and its overhead and
21744savings, and various measures of the hash table size and chain
21745lengths.
21746
21747@kindex maint print type
21748@cindex type chain of a data type
21749@item maint print type @var{expr}
21750Print the type chain for a type specified by @var{expr}. The argument
21751can be either a type name or a symbol. If it is a symbol, the type of
21752that symbol is described. The type chain produced by this command is
21753a recursive definition of the data type as stored in @value{GDBN}'s
21754data structures, including its flags and contained types.
21755
21756@kindex maint set dwarf2 max-cache-age
21757@kindex maint show dwarf2 max-cache-age
21758@item maint set dwarf2 max-cache-age
21759@itemx maint show dwarf2 max-cache-age
21760Control the DWARF 2 compilation unit cache.
21761
21762@cindex DWARF 2 compilation units cache
21763In object files with inter-compilation-unit references, such as those
21764produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21765reader needs to frequently refer to previously read compilation units.
21766This setting controls how long a compilation unit will remain in the
21767cache if it is not referenced. A higher limit means that cached
21768compilation units will be stored in memory longer, and more total
21769memory will be used. Setting it to zero disables caching, which will
21770slow down @value{GDBN} startup, but reduce memory consumption.
21771
e7ba9c65
DJ
21772@kindex maint set profile
21773@kindex maint show profile
21774@cindex profiling GDB
21775@item maint set profile
21776@itemx maint show profile
21777Control profiling of @value{GDBN}.
21778
21779Profiling will be disabled until you use the @samp{maint set profile}
21780command to enable it. When you enable profiling, the system will begin
21781collecting timing and execution count data; when you disable profiling or
21782exit @value{GDBN}, the results will be written to a log file. Remember that
21783if you use profiling, @value{GDBN} will overwrite the profiling log file
21784(often called @file{gmon.out}). If you have a record of important profiling
21785data in a @file{gmon.out} file, be sure to move it to a safe location.
21786
21787Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21788compiled with the @samp{-pg} compiler option.
e7ba9c65 21789
09d4efe1
EZ
21790@kindex maint show-debug-regs
21791@cindex x86 hardware debug registers
21792@item maint show-debug-regs
21793Control whether to show variables that mirror the x86 hardware debug
21794registers. Use @code{ON} to enable, @code{OFF} to disable. If
21795enabled, the debug registers values are shown when GDB inserts or
21796removes a hardware breakpoint or watchpoint, and when the inferior
21797triggers a hardware-assisted breakpoint or watchpoint.
21798
21799@kindex maint space
21800@cindex memory used by commands
21801@item maint space
21802Control whether to display memory usage for each command. If set to a
21803nonzero value, @value{GDBN} will display how much memory each command
21804took, following the command's own output. This can also be requested
21805by invoking @value{GDBN} with the @option{--statistics} command-line
21806switch (@pxref{Mode Options}).
21807
21808@kindex maint time
21809@cindex time of command execution
21810@item maint time
21811Control whether to display the execution time for each command. If
21812set to a nonzero value, @value{GDBN} will display how much time it
21813took to execute each command, following the command's own output.
21814This can also be requested by invoking @value{GDBN} with the
21815@option{--statistics} command-line switch (@pxref{Mode Options}).
21816
21817@kindex maint translate-address
21818@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21819Find the symbol stored at the location specified by the address
21820@var{addr} and an optional section name @var{section}. If found,
21821@value{GDBN} prints the name of the closest symbol and an offset from
21822the symbol's location to the specified address. This is similar to
21823the @code{info address} command (@pxref{Symbols}), except that this
21824command also allows to find symbols in other sections.
ae038cb0 21825
8e04817f 21826@end table
c906108c 21827
9c16f35a
EZ
21828The following command is useful for non-interactive invocations of
21829@value{GDBN}, such as in the test suite.
21830
21831@table @code
21832@item set watchdog @var{nsec}
21833@kindex set watchdog
21834@cindex watchdog timer
21835@cindex timeout for commands
21836Set the maximum number of seconds @value{GDBN} will wait for the
21837target operation to finish. If this time expires, @value{GDBN}
21838reports and error and the command is aborted.
21839
21840@item show watchdog
21841Show the current setting of the target wait timeout.
21842@end table
c906108c 21843
e0ce93ac 21844@node Remote Protocol
8e04817f 21845@appendix @value{GDBN} Remote Serial Protocol
c906108c 21846
ee2d5c50
AC
21847@menu
21848* Overview::
21849* Packets::
21850* Stop Reply Packets::
21851* General Query Packets::
21852* Register Packet Format::
21853* Examples::
0ce1b118 21854* File-I/O remote protocol extension::
ee2d5c50
AC
21855@end menu
21856
21857@node Overview
21858@section Overview
21859
8e04817f
AC
21860There may be occasions when you need to know something about the
21861protocol---for example, if there is only one serial port to your target
21862machine, you might want your program to do something special if it
21863recognizes a packet meant for @value{GDBN}.
c906108c 21864
d2c6833e 21865In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21866transmitted and received data respectfully.
c906108c 21867
8e04817f
AC
21868@cindex protocol, @value{GDBN} remote serial
21869@cindex serial protocol, @value{GDBN} remote
21870@cindex remote serial protocol
21871All @value{GDBN} commands and responses (other than acknowledgments) are
21872sent as a @var{packet}. A @var{packet} is introduced with the character
21873@samp{$}, the actual @var{packet-data}, and the terminating character
21874@samp{#} followed by a two-digit @var{checksum}:
c906108c 21875
474c8240 21876@smallexample
8e04817f 21877@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21878@end smallexample
8e04817f 21879@noindent
c906108c 21880
8e04817f
AC
21881@cindex checksum, for @value{GDBN} remote
21882@noindent
21883The two-digit @var{checksum} is computed as the modulo 256 sum of all
21884characters between the leading @samp{$} and the trailing @samp{#} (an
21885eight bit unsigned checksum).
c906108c 21886
8e04817f
AC
21887Implementors should note that prior to @value{GDBN} 5.0 the protocol
21888specification also included an optional two-digit @var{sequence-id}:
c906108c 21889
474c8240 21890@smallexample
8e04817f 21891@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21892@end smallexample
c906108c 21893
8e04817f
AC
21894@cindex sequence-id, for @value{GDBN} remote
21895@noindent
21896That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21897has never output @var{sequence-id}s. Stubs that handle packets added
21898since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21899
8e04817f
AC
21900@cindex acknowledgment, for @value{GDBN} remote
21901When either the host or the target machine receives a packet, the first
21902response expected is an acknowledgment: either @samp{+} (to indicate
21903the package was received correctly) or @samp{-} (to request
21904retransmission):
c906108c 21905
474c8240 21906@smallexample
d2c6833e
AC
21907-> @code{$}@var{packet-data}@code{#}@var{checksum}
21908<- @code{+}
474c8240 21909@end smallexample
8e04817f 21910@noindent
53a5351d 21911
8e04817f
AC
21912The host (@value{GDBN}) sends @var{command}s, and the target (the
21913debugging stub incorporated in your program) sends a @var{response}. In
21914the case of step and continue @var{command}s, the response is only sent
21915when the operation has completed (the target has again stopped).
c906108c 21916
8e04817f
AC
21917@var{packet-data} consists of a sequence of characters with the
21918exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21919exceptions).
c906108c 21920
8e04817f 21921Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21922@cindex remote protocol, field separator
8e04817f 21923@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21924@sc{hex} with leading zeros suppressed.
c906108c 21925
8e04817f
AC
21926Implementors should note that prior to @value{GDBN} 5.0, the character
21927@samp{:} could not appear as the third character in a packet (as it
21928would potentially conflict with the @var{sequence-id}).
c906108c 21929
8e04817f
AC
21930Response @var{data} can be run-length encoded to save space. A @samp{*}
21931means that the next character is an @sc{ascii} encoding giving a repeat count
21932which stands for that many repetitions of the character preceding the
21933@samp{*}. The encoding is @code{n+29}, yielding a printable character
21934where @code{n >=3} (which is where rle starts to win). The printable
21935characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21936value greater than 126 should not be used.
c906108c 21937
8e04817f 21938So:
474c8240 21939@smallexample
8e04817f 21940"@code{0* }"
474c8240 21941@end smallexample
8e04817f
AC
21942@noindent
21943means the same as "0000".
c906108c 21944
8e04817f
AC
21945The error response returned for some packets includes a two character
21946error number. That number is not well defined.
c906108c 21947
8e04817f
AC
21948For any @var{command} not supported by the stub, an empty response
21949(@samp{$#00}) should be returned. That way it is possible to extend the
21950protocol. A newer @value{GDBN} can tell if a packet is supported based
21951on that response.
c906108c 21952
b383017d
RM
21953A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
21954@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 21955optional.
c906108c 21956
ee2d5c50
AC
21957@node Packets
21958@section Packets
21959
21960The following table provides a complete list of all currently defined
21961@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
21962@xref{File-I/O remote protocol extension}, for details about the File
21963I/O extension of the remote protocol.
ee2d5c50
AC
21964
21965@table @r
21966
21967@item @code{!} --- extended mode
21968@cindex @code{!} packet
21969
8e04817f
AC
21970Enable extended mode. In extended mode, the remote server is made
21971persistent. The @samp{R} packet is used to restart the program being
21972debugged.
ee2d5c50
AC
21973
21974Reply:
21975@table @samp
21976@item OK
8e04817f 21977The remote target both supports and has enabled extended mode.
ee2d5c50 21978@end table
c906108c 21979
ee2d5c50
AC
21980@item @code{?} --- last signal
21981@cindex @code{?} packet
c906108c 21982
ee2d5c50
AC
21983Indicate the reason the target halted. The reply is the same as for
21984step and continue.
c906108c 21985
ee2d5c50
AC
21986Reply:
21987@xref{Stop Reply Packets}, for the reply specifications.
21988
21989@item @code{a} --- reserved
21990
21991Reserved for future use.
21992
21993@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
21994@cindex @code{A} packet
c906108c 21995
8e04817f
AC
21996Initialized @samp{argv[]} array passed into program. @var{arglen}
21997specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
21998See @code{gdbserver} for more details.
21999
22000Reply:
22001@table @samp
22002@item OK
22003@item E@var{NN}
22004@end table
22005
22006@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22007@cindex @code{b} packet
22008
22009Change the serial line speed to @var{baud}.
22010
22011JTC: @emph{When does the transport layer state change? When it's
22012received, or after the ACK is transmitted. In either case, there are
22013problems if the command or the acknowledgment packet is dropped.}
22014
22015Stan: @emph{If people really wanted to add something like this, and get
22016it working for the first time, they ought to modify ser-unix.c to send
22017some kind of out-of-band message to a specially-setup stub and have the
22018switch happen "in between" packets, so that from remote protocol's point
22019of view, nothing actually happened.}
22020
22021@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22022@cindex @code{B} packet
22023
8e04817f 22024Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22025breakpoint at @var{addr}.
22026
22027This packet has been replaced by the @samp{Z} and @samp{z} packets
22028(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22029
ee2d5c50
AC
22030@item @code{c}@var{addr} --- continue
22031@cindex @code{c} packet
22032
22033@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22034current address.
c906108c 22035
ee2d5c50
AC
22036Reply:
22037@xref{Stop Reply Packets}, for the reply specifications.
22038
22039@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22040@cindex @code{C} packet
22041
8e04817f
AC
22042Continue with signal @var{sig} (hex signal number). If
22043@code{;}@var{addr} is omitted, resume at same address.
c906108c 22044
ee2d5c50
AC
22045Reply:
22046@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22047
ee2d5c50
AC
22048@item @code{d} --- toggle debug @strong{(deprecated)}
22049@cindex @code{d} packet
22050
22051Toggle debug flag.
22052
22053@item @code{D} --- detach
22054@cindex @code{D} packet
22055
22056Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22057before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22058
22059Reply:
22060@table @samp
10fac096
NW
22061@item OK
22062for success
22063@item E@var{NN}
22064for an error
ee2d5c50 22065@end table
c906108c 22066
ee2d5c50 22067@item @code{e} --- reserved
c906108c 22068
ee2d5c50 22069Reserved for future use.
c906108c 22070
ee2d5c50 22071@item @code{E} --- reserved
c906108c 22072
ee2d5c50 22073Reserved for future use.
c906108c 22074
ee2d5c50
AC
22075@item @code{f} --- reserved
22076
22077Reserved for future use.
22078
0ce1b118
CV
22079@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22080@cindex @code{F} packet
ee2d5c50 22081
0ce1b118
CV
22082This packet is send by @value{GDBN} as reply to a @code{F} request packet
22083sent by the target. This is part of the File-I/O protocol extension.
22084@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22085
22086@item @code{g} --- read registers
22087@anchor{read registers packet}
22088@cindex @code{g} packet
22089
22090Read general registers.
22091
22092Reply:
22093@table @samp
22094@item @var{XX@dots{}}
8e04817f
AC
22095Each byte of register data is described by two hex digits. The bytes
22096with the register are transmitted in target byte order. The size of
22097each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22098determined by the @value{GDBN} internal macros
22099@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22100specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22101@item E@var{NN}
22102for an error.
22103@end table
c906108c 22104
ee2d5c50
AC
22105@item @code{G}@var{XX@dots{}} --- write regs
22106@cindex @code{G} packet
c906108c 22107
ee2d5c50
AC
22108@xref{read registers packet}, for a description of the @var{XX@dots{}}
22109data.
22110
22111Reply:
22112@table @samp
22113@item OK
22114for success
22115@item E@var{NN}
22116for an error
22117@end table
22118
22119@item @code{h} --- reserved
22120
22121Reserved for future use.
22122
b383017d 22123@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22124@cindex @code{H} packet
c906108c 22125
8e04817f 22126Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22127@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22128should be @samp{c} for step and continue operations, @samp{g} for other
22129operations. The thread designator @var{t@dots{}} may be -1, meaning all
22130the threads, a thread number, or zero which means pick any thread.
22131
22132Reply:
22133@table @samp
22134@item OK
22135for success
22136@item E@var{NN}
22137for an error
22138@end table
c906108c 22139
8e04817f
AC
22140@c FIXME: JTC:
22141@c 'H': How restrictive (or permissive) is the thread model. If a
22142@c thread is selected and stopped, are other threads allowed
22143@c to continue to execute? As I mentioned above, I think the
22144@c semantics of each command when a thread is selected must be
22145@c described. For example:
22146@c
22147@c 'g': If the stub supports threads and a specific thread is
22148@c selected, returns the register block from that thread;
22149@c otherwise returns current registers.
22150@c
22151@c 'G' If the stub supports threads and a specific thread is
22152@c selected, sets the registers of the register block of
22153@c that thread; otherwise sets current registers.
c906108c 22154
ee2d5c50
AC
22155@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22156@anchor{cycle step packet}
22157@cindex @code{i} packet
22158
8e04817f
AC
22159Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22160present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22161step starting at that address.
c906108c 22162
ee2d5c50
AC
22163@item @code{I} --- signal then cycle step @strong{(reserved)}
22164@cindex @code{I} packet
22165
22166@xref{step with signal packet}. @xref{cycle step packet}.
22167
22168@item @code{j} --- reserved
22169
22170Reserved for future use.
22171
22172@item @code{J} --- reserved
c906108c 22173
ee2d5c50 22174Reserved for future use.
c906108c 22175
ee2d5c50
AC
22176@item @code{k} --- kill request
22177@cindex @code{k} packet
c906108c 22178
ac282366 22179FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22180thread context has been selected (i.e.@: does 'k' kill only that
22181thread?)}.
c906108c 22182
ee2d5c50 22183@item @code{K} --- reserved
c906108c 22184
ee2d5c50
AC
22185Reserved for future use.
22186
22187@item @code{l} --- reserved
22188
22189Reserved for future use.
22190
22191@item @code{L} --- reserved
22192
22193Reserved for future use.
22194
22195@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22196@cindex @code{m} packet
c906108c 22197
8e04817f 22198Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22199Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22200assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22201transfer mechanism is needed.}
c906108c 22202
ee2d5c50
AC
22203Reply:
22204@table @samp
22205@item @var{XX@dots{}}
22206@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22207to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22208that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22209accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22210needed.}
22211@item E@var{NN}
22212@var{NN} is errno
22213@end table
22214
22215@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22216@cindex @code{M} packet
22217
8e04817f 22218Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22219@var{XX@dots{}} is the data.
22220
22221Reply:
22222@table @samp
22223@item OK
22224for success
22225@item E@var{NN}
8e04817f
AC
22226for an error (this includes the case where only part of the data was
22227written).
ee2d5c50 22228@end table
c906108c 22229
ee2d5c50 22230@item @code{n} --- reserved
c906108c 22231
ee2d5c50 22232Reserved for future use.
c906108c 22233
ee2d5c50 22234@item @code{N} --- reserved
c906108c 22235
ee2d5c50 22236Reserved for future use.
c906108c 22237
ee2d5c50
AC
22238@item @code{o} --- reserved
22239
22240Reserved for future use.
22241
22242@item @code{O} --- reserved
22243
2e868123 22244@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22245@cindex @code{p} packet
22246
2e868123
AC
22247@xref{read registers packet}, for a description of how the returned
22248register value is encoded.
ee2d5c50
AC
22249
22250Reply:
22251@table @samp
2e868123
AC
22252@item @var{XX@dots{}}
22253the register's value
22254@item E@var{NN}
22255for an error
22256@item
22257Indicating an unrecognized @var{query}.
ee2d5c50
AC
22258@end table
22259
22260@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22261@anchor{write register packet}
22262@cindex @code{P} packet
22263
22264Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22265digits for each byte in the register (target byte order).
c906108c 22266
ee2d5c50
AC
22267Reply:
22268@table @samp
22269@item OK
22270for success
22271@item E@var{NN}
22272for an error
22273@end table
22274
22275@item @code{q}@var{query} --- general query
22276@anchor{general query packet}
22277@cindex @code{q} packet
22278
22279Request info about @var{query}. In general @value{GDBN} queries have a
22280leading upper case letter. Custom vendor queries should use a company
22281prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22282be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22283that they match the full @var{query} name.
22284
22285Reply:
22286@table @samp
22287@item @var{XX@dots{}}
22288Hex encoded data from query. The reply can not be empty.
22289@item E@var{NN}
22290error reply
8e04817f 22291@item
ee2d5c50
AC
22292Indicating an unrecognized @var{query}.
22293@end table
22294
22295@item @code{Q}@var{var}@code{=}@var{val} --- general set
22296@cindex @code{Q} packet
22297
22298Set value of @var{var} to @var{val}.
22299
22300@xref{general query packet}, for a discussion of naming conventions.
c906108c 22301
ee2d5c50
AC
22302@item @code{r} --- reset @strong{(deprecated)}
22303@cindex @code{r} packet
c906108c 22304
8e04817f 22305Reset the entire system.
c906108c 22306
ee2d5c50
AC
22307@item @code{R}@var{XX} --- remote restart
22308@cindex @code{R} packet
22309
8e04817f
AC
22310Restart the program being debugged. @var{XX}, while needed, is ignored.
22311This packet is only available in extended mode.
ee2d5c50
AC
22312
22313Reply:
22314@table @samp
22315@item @emph{no reply}
8e04817f 22316The @samp{R} packet has no reply.
ee2d5c50
AC
22317@end table
22318
22319@item @code{s}@var{addr} --- step
22320@cindex @code{s} packet
c906108c 22321
8e04817f
AC
22322@var{addr} is address to resume. If @var{addr} is omitted, resume at
22323same address.
c906108c 22324
ee2d5c50
AC
22325Reply:
22326@xref{Stop Reply Packets}, for the reply specifications.
22327
22328@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22329@anchor{step with signal packet}
22330@cindex @code{S} packet
22331
8e04817f 22332Like @samp{C} but step not continue.
c906108c 22333
ee2d5c50
AC
22334Reply:
22335@xref{Stop Reply Packets}, for the reply specifications.
22336
b383017d 22337@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22338@cindex @code{t} packet
22339
8e04817f 22340Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22341@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22342@var{addr} must be at least 3 digits.
c906108c 22343
ee2d5c50
AC
22344@item @code{T}@var{XX} --- thread alive
22345@cindex @code{T} packet
c906108c 22346
ee2d5c50 22347Find out if the thread XX is alive.
c906108c 22348
ee2d5c50
AC
22349Reply:
22350@table @samp
22351@item OK
22352thread is still alive
22353@item E@var{NN}
22354thread is dead
22355@end table
22356
22357@item @code{u} --- reserved
22358
22359Reserved for future use.
22360
22361@item @code{U} --- reserved
22362
22363Reserved for future use.
22364
86d30acc 22365@item @code{v} --- verbose packet prefix
ee2d5c50 22366
86d30acc
DJ
22367Packets starting with @code{v} are identified by a multi-letter name,
22368up to the first @code{;} or @code{?} (or the end of the packet).
22369
22370@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22371@cindex @code{vCont} packet
22372
22373Resume the inferior. Different actions may be specified for each thread.
22374If an action is specified with no @var{tid}, then it is applied to any
22375threads that don't have a specific action specified; if no default action is
22376specified then other threads should remain stopped. Specifying multiple
22377default actions is an error; specifying no actions is also an error.
22378Thread IDs are specified in hexadecimal. Currently supported actions are:
22379
22380@table @code
22381@item c
22382Continue.
22383@item C@var{sig}
22384Continue with signal @var{sig}. @var{sig} should be two hex digits.
22385@item s
22386Step.
22387@item S@var{sig}
22388Step with signal @var{sig}. @var{sig} should be two hex digits.
22389@end table
22390
22391The optional @var{addr} argument normally associated with these packets is
22392not supported in @code{vCont}.
22393
22394Reply:
22395@xref{Stop Reply Packets}, for the reply specifications.
22396
22397@item @code{vCont?} --- extended resume query
22398@cindex @code{vCont?} packet
22399
22400Query support for the @code{vCont} packet.
22401
22402Reply:
22403@table @samp
22404@item @code{vCont}[;@var{action}]...
22405The @code{vCont} packet is supported. Each @var{action} is a supported
22406command in the @code{vCont} packet.
22407@item
22408The @code{vCont} packet is not supported.
22409@end table
ee2d5c50
AC
22410
22411@item @code{V} --- reserved
c906108c 22412
ee2d5c50 22413Reserved for future use.
c906108c 22414
ee2d5c50 22415@item @code{w} --- reserved
c906108c 22416
ee2d5c50 22417Reserved for future use.
c906108c 22418
ee2d5c50 22419@item @code{W} --- reserved
c906108c 22420
ee2d5c50 22421Reserved for future use.
c906108c 22422
ee2d5c50
AC
22423@item @code{x} --- reserved
22424
22425Reserved for future use.
22426
22427@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22428@cindex @code{X} packet
22429
22430@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22431is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22432escaped using @code{0x7d}, and then XORed with @code{0x20}.
22433For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22434
ee2d5c50
AC
22435Reply:
22436@table @samp
22437@item OK
22438for success
22439@item E@var{NN}
22440for an error
22441@end table
22442
22443@item @code{y} --- reserved
c906108c 22444
ee2d5c50 22445Reserved for future use.
c906108c 22446
ee2d5c50
AC
22447@item @code{Y} reserved
22448
22449Reserved for future use.
22450
2f870471
AC
22451@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22452@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22453@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22454@cindex @code{z} packet
2f870471 22455@cindex @code{Z} packets
ee2d5c50 22456
2f870471
AC
22457Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22458watchpoint starting at address @var{address} and covering the next
22459@var{length} bytes.
ee2d5c50 22460
2f870471
AC
22461Each breakpoint and watchpoint packet @var{type} is documented
22462separately.
22463
512217c7
AC
22464@emph{Implementation notes: A remote target shall return an empty string
22465for an unrecognized breakpoint or watchpoint packet @var{type}. A
22466remote target shall support either both or neither of a given
2f870471
AC
22467@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22468avoid potential problems with duplicate packets, the operations should
22469be implemented in an idempotent way.}
22470
22471@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22472@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22473@cindex @code{z0} packet
22474@cindex @code{Z0} packet
22475
22476Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22477@code{addr} of size @code{length}.
22478
22479A memory breakpoint is implemented by replacing the instruction at
22480@var{addr} with a software breakpoint or trap instruction. The
22481@code{length} is used by targets that indicates the size of the
22482breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22483@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22484
2f870471
AC
22485@emph{Implementation note: It is possible for a target to copy or move
22486code that contains memory breakpoints (e.g., when implementing
22487overlays). The behavior of this packet, in the presence of such a
22488target, is not defined.}
c906108c 22489
ee2d5c50
AC
22490Reply:
22491@table @samp
2f870471
AC
22492@item OK
22493success
22494@item
22495not supported
ee2d5c50
AC
22496@item E@var{NN}
22497for an error
2f870471
AC
22498@end table
22499
22500@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22501@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22502@cindex @code{z1} packet
22503@cindex @code{Z1} packet
22504
22505Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22506address @code{addr} of size @code{length}.
22507
22508A hardware breakpoint is implemented using a mechanism that is not
22509dependant on being able to modify the target's memory.
22510
22511@emph{Implementation note: A hardware breakpoint is not affected by code
22512movement.}
22513
22514Reply:
22515@table @samp
ee2d5c50 22516@item OK
2f870471
AC
22517success
22518@item
22519not supported
22520@item E@var{NN}
22521for an error
22522@end table
22523
22524@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22525@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22526@cindex @code{z2} packet
22527@cindex @code{Z2} packet
22528
22529Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22530
22531Reply:
22532@table @samp
22533@item OK
22534success
22535@item
22536not supported
22537@item E@var{NN}
22538for an error
22539@end table
22540
22541@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22542@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22543@cindex @code{z3} packet
22544@cindex @code{Z3} packet
22545
2e834e49 22546Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22547
22548Reply:
22549@table @samp
22550@item OK
22551success
22552@item
22553not supported
22554@item E@var{NN}
22555for an error
22556@end table
22557
2e834e49
HPN
22558@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22559@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22560@cindex @code{z4} packet
22561@cindex @code{Z4} packet
22562
22563Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22564
22565Reply:
22566@table @samp
22567@item OK
22568success
22569@item
22570not supported
22571@item E@var{NN}
22572for an error
ee2d5c50
AC
22573@end table
22574
22575@end table
c906108c 22576
ee2d5c50
AC
22577@node Stop Reply Packets
22578@section Stop Reply Packets
22579@cindex stop reply packets
c906108c 22580
8e04817f
AC
22581The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22582receive any of the below as a reply. In the case of the @samp{C},
22583@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22584when the target halts. In the below the exact meaning of @samp{signal
22585number} is poorly defined. In general one of the UNIX signal numbering
22586conventions is used.
c906108c 22587
ee2d5c50 22588@table @samp
c906108c 22589
ee2d5c50
AC
22590@item S@var{AA}
22591@var{AA} is the signal number
c906108c 22592
8e04817f 22593@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
22594@cindex @code{T} packet reply
22595
8e04817f
AC
22596@var{AA} = two hex digit signal number; @var{n...} = register number
22597(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22598by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22599@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22600(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22601address, this is a hex integer; @var{n...} = other string not starting
22602with valid hex digit. @value{GDBN} should ignore this @var{n...},
22603@var{r...} pair and go on to the next. This way we can extend the
22604protocol.
c906108c 22605
ee2d5c50
AC
22606@item W@var{AA}
22607
8e04817f 22608The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22609applicable to certain targets.
22610
22611@item X@var{AA}
c906108c 22612
8e04817f 22613The process terminated with signal @var{AA}.
c906108c 22614
ee2d5c50 22615@item O@var{XX@dots{}}
c906108c 22616
ee2d5c50
AC
22617@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22618any time while the program is running and the debugger should continue
22619to wait for @samp{W}, @samp{T}, etc.
22620
0ce1b118
CV
22621@item F@var{call-id}@code{,}@var{parameter@dots{}}
22622
22623@var{call-id} is the identifier which says which host system call should
22624be called. This is just the name of the function. Translation into the
22625correct system call is only applicable as it's defined in @value{GDBN}.
22626@xref{File-I/O remote protocol extension}, for a list of implemented
22627system calls.
22628
22629@var{parameter@dots{}} is a list of parameters as defined for this very
22630system call.
22631
22632The target replies with this packet when it expects @value{GDBN} to call
22633a host system call on behalf of the target. @value{GDBN} replies with
22634an appropriate @code{F} packet and keeps up waiting for the next reply
22635packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22636@samp{s} action is expected to be continued.
22637@xref{File-I/O remote protocol extension}, for more details.
22638
ee2d5c50
AC
22639@end table
22640
22641@node General Query Packets
22642@section General Query Packets
9c16f35a 22643@cindex remote query requests
c906108c 22644
8e04817f 22645The following set and query packets have already been defined.
c906108c 22646
ee2d5c50 22647@table @r
c906108c 22648
ee2d5c50 22649@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22650@cindex current thread, remote request
22651@cindex @code{qC} packet
ee2d5c50
AC
22652Return the current thread id.
22653
22654Reply:
22655@table @samp
22656@item @code{QC}@var{pid}
e1aac25b 22657Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22658@item *
22659Any other reply implies the old pid.
22660@end table
22661
22662@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22663@cindex list active threads, remote request
22664@cindex @code{qfThreadInfo} packet
ee2d5c50 22665@code{q}@code{sThreadInfo}
c906108c 22666
8e04817f
AC
22667Obtain a list of active thread ids from the target (OS). Since there
22668may be too many active threads to fit into one reply packet, this query
22669works iteratively: it may require more than one query/reply sequence to
22670obtain the entire list of threads. The first query of the sequence will
22671be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22672sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22673
22674NOTE: replaces the @code{qL} query (see below).
22675
22676Reply:
22677@table @samp
22678@item @code{m}@var{id}
22679A single thread id
22680@item @code{m}@var{id},@var{id}@dots{}
22681a comma-separated list of thread ids
22682@item @code{l}
22683(lower case 'el') denotes end of list.
22684@end table
22685
22686In response to each query, the target will reply with a list of one or
e1aac25b
JB
22687more thread ids, in big-endian unsigned hex, separated by commas.
22688@value{GDBN} will respond to each reply with a request for more thread
22689ids (using the @code{qs} form of the query), until the target responds
22690with @code{l} (lower-case el, for @code{'last'}).
c906108c 22691
ee2d5c50 22692@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22693@cindex thread attributes info, remote request
22694@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22695Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22696string description of a thread's attributes from the target OS. This
22697string may contain anything that the target OS thinks is interesting for
22698@value{GDBN} to tell the user about the thread. The string is displayed
22699in @value{GDBN}'s @samp{info threads} display. Some examples of
22700possible thread extra info strings are ``Runnable'', or ``Blocked on
22701Mutex''.
22702
22703Reply:
22704@table @samp
22705@item @var{XX@dots{}}
22706Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22707the printable string containing the extra information about the thread's
8e04817f 22708attributes.
ee2d5c50
AC
22709@end table
22710
22711@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22712
8e04817f
AC
22713Obtain thread information from RTOS. Where: @var{startflag} (one hex
22714digit) is one to indicate the first query and zero to indicate a
22715subsequent query; @var{threadcount} (two hex digits) is the maximum
22716number of threads the response packet can contain; and @var{nextthread}
22717(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22718returned in the response as @var{argthread}.
ee2d5c50
AC
22719
22720NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22721(see above).
22722
22723Reply:
22724@table @samp
22725@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22726Where: @var{count} (two hex digits) is the number of threads being
22727returned; @var{done} (one hex digit) is zero to indicate more threads
22728and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22729digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22730is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22731digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22732@end table
c906108c 22733
ee2d5c50 22734@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22735@cindex CRC of memory block, remote request
22736@cindex @code{qCRC} packet
ee2d5c50
AC
22737Reply:
22738@table @samp
22739@item @code{E}@var{NN}
22740An error (such as memory fault)
22741@item @code{C}@var{CRC32}
22742A 32 bit cyclic redundancy check of the specified memory region.
22743@end table
22744
22745@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22746@cindex section offsets, remote request
22747@cindex @code{qOffsets} packet
8e04817f
AC
22748Get section offsets that the target used when re-locating the downloaded
22749image. @emph{Note: while a @code{Bss} offset is included in the
22750response, @value{GDBN} ignores this and instead applies the @code{Data}
22751offset to the @code{Bss} section.}
c906108c 22752
ee2d5c50
AC
22753Reply:
22754@table @samp
22755@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22756@end table
22757
22758@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22759@cindex thread information, remote request
22760@cindex @code{qP} packet
8e04817f
AC
22761Returns information on @var{threadid}. Where: @var{mode} is a hex
22762encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22763
22764Reply:
22765@table @samp
22766@item *
22767@end table
22768
8e04817f 22769See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22770
ee2d5c50 22771@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22772@cindex execute remote command, remote request
22773@cindex @code{qRcmd} packet
ee2d5c50 22774@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22775execution. Invalid commands should be reported using the output string.
22776Before the final result packet, the target may also respond with a
ee2d5c50
AC
22777number of intermediate @code{O}@var{output} console output packets.
22778@emph{Implementors should note that providing access to a stubs's
22779interpreter may have security implications}.
22780
22781Reply:
22782@table @samp
22783@item OK
8e04817f 22784A command response with no output.
ee2d5c50 22785@item @var{OUTPUT}
8e04817f 22786A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22787@item @code{E}@var{NN}
8e04817f 22788Indicate a badly formed request.
ee2d5c50 22789@item @samp{}
8e04817f 22790When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22791@end table
9c16f35a 22792z
ee2d5c50 22793@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22794@cindex symbol lookup, remote request
22795@cindex @code{qSymbol} packet
8e04817f
AC
22796Notify the target that @value{GDBN} is prepared to serve symbol lookup
22797requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22798
22799Reply:
22800@table @samp
22801@item @code{OK}
8e04817f 22802The target does not need to look up any (more) symbols.
ee2d5c50
AC
22803@item @code{qSymbol:}@var{sym_name}
22804The target requests the value of symbol @var{sym_name} (hex encoded).
22805@value{GDBN} may provide the value by using the
22806@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22807@end table
22808
22809@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22810
22811Set the value of @var{sym_name} to @var{sym_value}.
22812
22813@var{sym_name} (hex encoded) is the name of a symbol whose value the
22814target has previously requested.
22815
22816@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22817@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22818will be empty.
22819
22820Reply:
22821@table @samp
22822@item @code{OK}
8e04817f 22823The target does not need to look up any (more) symbols.
ee2d5c50
AC
22824@item @code{qSymbol:}@var{sym_name}
22825The target requests the value of a new symbol @var{sym_name} (hex
22826encoded). @value{GDBN} will continue to supply the values of symbols
22827(if available), until the target ceases to request them.
22828@end table
eb12ee30 22829
649e03f6 22830@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22831@cindex read special object, remote request
22832@cindex @code{qPart} packet
649e03f6
RM
22833Read uninterpreted bytes from the target's special data area
22834identified by the keyword @code{object}.
22835Request @var{length} bytes starting at @var{offset} bytes into the data.
22836The content and encoding of @var{annex} is specific to the object;
22837it can supply additional details about what data to access.
22838
22839Here are the specific requests of this form defined so far.
22840All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22841requests use the same reply formats, listed below.
22842
22843@table @asis
22844@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22845Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22846auxiliary vector}, and see @ref{Remote configuration,
22847read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22848@end table
22849
22850Reply:
22851@table @asis
22852@item @code{OK}
22853The @var{offset} in the request is at the end of the data.
22854There is no more data to be read.
22855
22856@item @var{XX@dots{}}
22857Hex encoded data bytes read.
22858This may be fewer bytes than the @var{length} in the request.
22859
22860@item @code{E00}
22861The request was malformed, or @var{annex} was invalid.
22862
22863@item @code{E}@var{nn}
22864The offset was invalid, or there was an error encountered reading the data.
22865@var{nn} is a hex-encoded @code{errno} value.
22866
22867@item @code{""} (empty)
22868An empty reply indicates the @var{object} or @var{annex} string was not
22869recognized by the stub.
22870@end table
22871
22872@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22873@cindex write data into object, remote request
649e03f6
RM
22874Write uninterpreted bytes into the target's special data area
22875identified by the keyword @code{object},
22876starting at @var{offset} bytes into the data.
22877@var{data@dots{}} is the hex-encoded data to be written.
22878The content and encoding of @var{annex} is specific to the object;
22879it can supply additional details about what data to access.
22880
22881No requests of this form are presently in use. This specification
22882serves as a placeholder to document the common format that new
22883specific request specifications ought to use.
22884
22885Reply:
22886@table @asis
22887@item @var{nn}
22888@var{nn} (hex encoded) is the number of bytes written.
22889This may be fewer bytes than supplied in the request.
22890
22891@item @code{E00}
22892The request was malformed, or @var{annex} was invalid.
22893
22894@item @code{E}@var{nn}
22895The offset was invalid, or there was an error encountered writing the data.
22896@var{nn} is a hex-encoded @code{errno} value.
22897
22898@item @code{""} (empty)
22899An empty reply indicates the @var{object} or @var{annex} string was not
22900recognized by the stub, or that the object does not support writing.
22901@end table
22902
22903@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22904Requests of this form may be added in the future. When a stub does
22905not recognize the @var{object} keyword, or its support for
22906@var{object} does not recognize the @var{operation} keyword,
22907the stub must respond with an empty packet.
83761cbd
KB
22908
22909@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22910@cindex get thread-local storage address, remote request
22911@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22912Fetch the address associated with thread local storage specified
22913by @var{thread-id}, @var{offset}, and @var{lm}.
22914
22915@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22916thread for which to fetch the TLS address.
22917
22918@var{offset} is the (big endian, hex encoded) offset associated with the
22919thread local variable. (This offset is obtained from the debug
22920information associated with the variable.)
22921
22922@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22923the load module associated with the thread local storage. For example,
22924a @sc{gnu}/Linux system will pass the link map address of the shared
22925object associated with the thread local storage under consideration.
22926Other operating environments may choose to represent the load module
22927differently, so the precise meaning of this parameter will vary.
22928
22929Reply:
22930@table @asis
68c71a2e 22931@item @var{XX@dots{}}
83761cbd
KB
22932Hex encoded (big endian) bytes representing the address of the thread
22933local storage requested.
22934
22935@item @code{E}@var{nn} (where @var{nn} are hex digits)
22936An error occurred.
22937
22938@item @code{""} (empty)
22939An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22940@end table
22941
0abb7bc7
EZ
22942Use of this request packet is controlled by the @code{set remote
22943get-thread-local-storage-address} command (@pxref{Remote
22944configuration, set remote get-thread-local-storage-address}).
22945
ee2d5c50
AC
22946@end table
22947
22948@node Register Packet Format
22949@section Register Packet Format
eb12ee30 22950
8e04817f 22951The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
22952In the below, some thirty-two bit registers are transferred as
22953sixty-four bits. Those registers should be zero/sign extended (which?)
22954to fill the space allocated. Register bytes are transfered in target
22955byte order. The two nibbles within a register byte are transfered
22956most-significant - least-significant.
eb12ee30 22957
ee2d5c50 22958@table @r
eb12ee30 22959
8e04817f 22960@item MIPS32
ee2d5c50 22961
8e04817f
AC
22962All registers are transfered as thirty-two bit quantities in the order:
2296332 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
22964registers; fsr; fir; fp.
eb12ee30 22965
8e04817f 22966@item MIPS64
ee2d5c50 22967
8e04817f
AC
22968All registers are transfered as sixty-four bit quantities (including
22969thirty-two bit registers such as @code{sr}). The ordering is the same
22970as @code{MIPS32}.
eb12ee30 22971
ee2d5c50
AC
22972@end table
22973
22974@node Examples
22975@section Examples
eb12ee30 22976
8e04817f
AC
22977Example sequence of a target being re-started. Notice how the restart
22978does not get any direct output:
eb12ee30 22979
474c8240 22980@smallexample
d2c6833e
AC
22981-> @code{R00}
22982<- @code{+}
8e04817f 22983@emph{target restarts}
d2c6833e 22984-> @code{?}
8e04817f 22985<- @code{+}
d2c6833e
AC
22986<- @code{T001:1234123412341234}
22987-> @code{+}
474c8240 22988@end smallexample
eb12ee30 22989
8e04817f 22990Example sequence of a target being stepped by a single instruction:
eb12ee30 22991
474c8240 22992@smallexample
d2c6833e 22993-> @code{G1445@dots{}}
8e04817f 22994<- @code{+}
d2c6833e
AC
22995-> @code{s}
22996<- @code{+}
22997@emph{time passes}
22998<- @code{T001:1234123412341234}
8e04817f 22999-> @code{+}
d2c6833e 23000-> @code{g}
8e04817f 23001<- @code{+}
d2c6833e
AC
23002<- @code{1455@dots{}}
23003-> @code{+}
474c8240 23004@end smallexample
eb12ee30 23005
0ce1b118
CV
23006@node File-I/O remote protocol extension
23007@section File-I/O remote protocol extension
23008@cindex File-I/O remote protocol extension
23009
23010@menu
23011* File-I/O Overview::
23012* Protocol basics::
1d8b2f28
JB
23013* The F request packet::
23014* The F reply packet::
0ce1b118
CV
23015* Memory transfer::
23016* The Ctrl-C message::
23017* Console I/O::
23018* The isatty call::
23019* The system call::
23020* List of supported calls::
23021* Protocol specific representation of datatypes::
23022* Constants::
23023* File-I/O Examples::
23024@end menu
23025
23026@node File-I/O Overview
23027@subsection File-I/O Overview
23028@cindex file-i/o overview
23029
9c16f35a
EZ
23030The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23031target to use the host's file system and console I/O when calling various
0ce1b118
CV
23032system calls. System calls on the target system are translated into a
23033remote protocol packet to the host system which then performs the needed
23034actions and returns with an adequate response packet to the target system.
23035This simulates file system operations even on targets that lack file systems.
23036
23037The protocol is defined host- and target-system independent. It uses
9c16f35a 23038its own independent representation of datatypes and values. Both,
0ce1b118
CV
23039@value{GDBN} and the target's @value{GDBN} stub are responsible for
23040translating the system dependent values into the unified protocol values
23041when data is transmitted.
23042
23043The communication is synchronous. A system call is possible only
23044when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23045packets. While @value{GDBN} handles the request for a system call,
23046the target is stopped to allow deterministic access to the target's
23047memory. Therefore File-I/O is not interuptible by target signals. It
23048is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23049
23050The target's request to perform a host system call does not finish
23051the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23052after finishing the system call, the target returns to continuing the
23053previous activity (continue, step). No additional continue or step
23054request from @value{GDBN} is required.
23055
23056@smallexample
f7dc1244 23057(@value{GDBP}) continue
0ce1b118
CV
23058 <- target requests 'system call X'
23059 target is stopped, @value{GDBN} executes system call
23060 -> GDB returns result
23061 ... target continues, GDB returns to wait for the target
23062 <- target hits breakpoint and sends a Txx packet
23063@end smallexample
23064
23065The protocol is only used for files on the host file system and
23066for I/O on the console. Character or block special devices, pipes,
23067named pipes or sockets or any other communication method on the host
23068system are not supported by this protocol.
23069
23070@node Protocol basics
23071@subsection Protocol basics
23072@cindex protocol basics, file-i/o
23073
23074The File-I/O protocol uses the @code{F} packet, as request as well
23075as as reply packet. Since a File-I/O system call can only occur when
b383017d 23076@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23077File-I/O request is a reply that @value{GDBN} has to expect as a result
23078of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23079This @code{F} packet contains all information needed to allow @value{GDBN}
23080to call the appropriate host system call:
23081
23082@itemize @bullet
b383017d 23083@item
0ce1b118
CV
23084A unique identifier for the requested system call.
23085
23086@item
23087All parameters to the system call. Pointers are given as addresses
23088in the target memory address space. Pointers to strings are given as
b383017d 23089pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23090Numerical control values are given in a protocol specific representation.
23091
23092@end itemize
23093
23094At that point @value{GDBN} has to perform the following actions.
23095
23096@itemize @bullet
b383017d 23097@item
0ce1b118
CV
23098If parameter pointer values are given, which point to data needed as input
23099to a system call, @value{GDBN} requests this data from the target with a
23100standard @code{m} packet request. This additional communication has to be
23101expected by the target implementation and is handled as any other @code{m}
23102packet.
23103
23104@item
23105@value{GDBN} translates all value from protocol representation to host
23106representation as needed. Datatypes are coerced into the host types.
23107
23108@item
23109@value{GDBN} calls the system call
23110
23111@item
23112It then coerces datatypes back to protocol representation.
23113
23114@item
23115If pointer parameters in the request packet point to buffer space in which
23116a system call is expected to copy data to, the data is transmitted to the
23117target using a @code{M} or @code{X} packet. This packet has to be expected
23118by the target implementation and is handled as any other @code{M} or @code{X}
23119packet.
23120
23121@end itemize
23122
23123Eventually @value{GDBN} replies with another @code{F} packet which contains all
23124necessary information for the target to continue. This at least contains
23125
23126@itemize @bullet
23127@item
23128Return value.
23129
23130@item
23131@code{errno}, if has been changed by the system call.
23132
23133@item
23134``Ctrl-C'' flag.
23135
23136@end itemize
23137
23138After having done the needed type and value coercion, the target continues
23139the latest continue or step action.
23140
1d8b2f28 23141@node The F request packet
0ce1b118
CV
23142@subsection The @code{F} request packet
23143@cindex file-i/o request packet
23144@cindex @code{F} request packet
23145
23146The @code{F} request packet has the following format:
23147
23148@table @samp
23149
23150@smallexample
23151@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23152@end smallexample
23153
23154@var{call-id} is the identifier to indicate the host system call to be called.
23155This is just the name of the function.
23156
23157@var{parameter@dots{}} are the parameters to the system call.
23158
b383017d 23159@end table
0ce1b118
CV
23160
23161Parameters are hexadecimal integer values, either the real values in case
23162of scalar datatypes, as pointers to target buffer space in case of compound
23163datatypes and unspecified memory areas or as pointer/length pairs in case
23164of string parameters. These are appended to the call-id, each separated
23165from its predecessor by a comma. All values are transmitted in ASCII
23166string representation, pointer/length pairs separated by a slash.
23167
1d8b2f28 23168@node The F reply packet
0ce1b118
CV
23169@subsection The @code{F} reply packet
23170@cindex file-i/o reply packet
23171@cindex @code{F} reply packet
23172
23173The @code{F} reply packet has the following format:
23174
23175@table @samp
23176
23177@smallexample
23178@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23179@end smallexample
23180
23181@var{retcode} is the return code of the system call as hexadecimal value.
23182
23183@var{errno} is the errno set by the call, in protocol specific representation.
23184This parameter can be omitted if the call was successful.
23185
23186@var{Ctrl-C flag} is only send if the user requested a break. In this
23187case, @var{errno} must be send as well, even if the call was successful.
23188The @var{Ctrl-C flag} itself consists of the character 'C':
23189
23190@smallexample
23191F0,0,C
23192@end smallexample
23193
23194@noindent
23195or, if the call was interupted before the host call has been performed:
23196
23197@smallexample
23198F-1,4,C
23199@end smallexample
23200
23201@noindent
23202assuming 4 is the protocol specific representation of @code{EINTR}.
23203
23204@end table
23205
23206@node Memory transfer
23207@subsection Memory transfer
23208@cindex memory transfer, in file-i/o protocol
23209
23210Structured data which is transferred using a memory read or write as e.g.@:
23211a @code{struct stat} is expected to be in a protocol specific format with
23212all scalar multibyte datatypes being big endian. This should be done by
23213the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23214it transfers memory to the target. Transferred pointers to structured
23215data should point to the already coerced data at any time.
23216
23217@node The Ctrl-C message
23218@subsection The Ctrl-C message
23219@cindex ctrl-c message, in file-i/o protocol
23220
23221A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23222reply packet. In this case the target should behave, as if it had
23223gotten a break message. The meaning for the target is ``system call
23224interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23225(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23226packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23227state the system call was interrupted. Since this action is by design
23228not an atomic operation, we have to differ between two cases:
23229
23230@itemize @bullet
23231@item
23232The system call hasn't been performed on the host yet.
23233
23234@item
23235The system call on the host has been finished.
23236
23237@end itemize
23238
23239These two states can be distinguished by the target by the value of the
23240returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23241call hasn't been performed. This is equivalent to the @code{EINTR} handling
23242on POSIX systems. In any other case, the target may presume that the
23243system call has been finished --- successful or not --- and should behave
23244as if the break message arrived right after the system call.
23245
23246@value{GDBN} must behave reliable. If the system call has not been called
23247yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23248@code{errno} in the packet. If the system call on the host has been finished
23249before the user requests a break, the full action must be finshed by
23250@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23251The @code{F} packet may only be send when either nothing has happened
23252or the full action has been completed.
23253
23254@node Console I/O
23255@subsection Console I/O
23256@cindex console i/o as part of file-i/o
23257
23258By default and if not explicitely closed by the target system, the file
23259descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23260on the @value{GDBN} console is handled as any other file output operation
23261(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23262by @value{GDBN} so that after the target read request from file descriptor
232630 all following typing is buffered until either one of the following
23264conditions is met:
23265
23266@itemize @bullet
23267@item
23268The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23269@code{read}
23270system call is treated as finished.
23271
23272@item
23273The user presses @kbd{Enter}. This is treated as end of input with a trailing
23274line feed.
23275
23276@item
23277The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23278character, especially no Ctrl-D is appended to the input.
23279
23280@end itemize
23281
23282If the user has typed more characters as fit in the buffer given to
23283the read call, the trailing characters are buffered in @value{GDBN} until
23284either another @code{read(0, @dots{})} is requested by the target or debugging
23285is stopped on users request.
23286
23287@node The isatty call
2eecc4ab 23288@subsection The @samp{isatty} function call
0ce1b118
CV
23289@cindex isatty call, file-i/o protocol
23290
23291A special case in this protocol is the library call @code{isatty} which
9c16f35a 23292is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
232931 to the target if the file descriptor given as parameter is attached
23294to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23295would require implementing @code{ioctl} and would be more complex than
23296needed.
23297
23298@node The system call
2eecc4ab 23299@subsection The @samp{system} function call
0ce1b118
CV
23300@cindex system call, file-i/o protocol
23301
23302The other special case in this protocol is the @code{system} call which
9c16f35a 23303is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23304task of calling the necessary host calls to perform the @code{system}
23305call. The return value of @code{system} is simplified before it's returned
23306to the target. Basically, the only signal transmitted back is @code{EINTR}
23307in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23308entirely of the exit status of the called command.
23309
9c16f35a
EZ
23310Due to security concerns, the @code{system} call is by default refused
23311by @value{GDBN}. The user has to allow this call explicitly with the
23312@kbd{set remote system-call-allowed 1} command.
0ce1b118 23313
9c16f35a
EZ
23314@table @code
23315@item set remote system-call-allowed
23316@kindex set remote system-call-allowed
23317Control whether to allow the @code{system} calls in the File I/O
23318protocol for the remote target. The default is zero (disabled).
0ce1b118 23319
9c16f35a 23320@item show remote system-call-allowed
0ce1b118 23321@kindex show remote system-call-allowed
9c16f35a
EZ
23322Show the current setting of system calls for the remote File I/O
23323protocol.
0ce1b118
CV
23324@end table
23325
23326@node List of supported calls
23327@subsection List of supported calls
23328@cindex list of supported file-i/o calls
23329
23330@menu
23331* open::
23332* close::
23333* read::
23334* write::
23335* lseek::
23336* rename::
23337* unlink::
23338* stat/fstat::
23339* gettimeofday::
23340* isatty::
23341* system::
23342@end menu
23343
23344@node open
23345@unnumberedsubsubsec open
23346@cindex open, file-i/o system call
23347
23348@smallexample
23349@exdent Synopsis:
23350int open(const char *pathname, int flags);
23351int open(const char *pathname, int flags, mode_t mode);
23352
b383017d 23353@exdent Request:
0ce1b118
CV
23354Fopen,pathptr/len,flags,mode
23355@end smallexample
23356
23357@noindent
23358@code{flags} is the bitwise or of the following values:
23359
23360@table @code
b383017d 23361@item O_CREAT
0ce1b118
CV
23362If the file does not exist it will be created. The host
23363rules apply as far as file ownership and time stamps
23364are concerned.
23365
b383017d 23366@item O_EXCL
0ce1b118
CV
23367When used with O_CREAT, if the file already exists it is
23368an error and open() fails.
23369
b383017d 23370@item O_TRUNC
0ce1b118
CV
23371If the file already exists and the open mode allows
23372writing (O_RDWR or O_WRONLY is given) it will be
23373truncated to length 0.
23374
b383017d 23375@item O_APPEND
0ce1b118
CV
23376The file is opened in append mode.
23377
b383017d 23378@item O_RDONLY
0ce1b118
CV
23379The file is opened for reading only.
23380
b383017d 23381@item O_WRONLY
0ce1b118
CV
23382The file is opened for writing only.
23383
b383017d 23384@item O_RDWR
0ce1b118
CV
23385The file is opened for reading and writing.
23386
23387@noindent
23388Each other bit is silently ignored.
23389
23390@end table
23391
23392@noindent
23393@code{mode} is the bitwise or of the following values:
23394
23395@table @code
b383017d 23396@item S_IRUSR
0ce1b118
CV
23397User has read permission.
23398
b383017d 23399@item S_IWUSR
0ce1b118
CV
23400User has write permission.
23401
b383017d 23402@item S_IRGRP
0ce1b118
CV
23403Group has read permission.
23404
b383017d 23405@item S_IWGRP
0ce1b118
CV
23406Group has write permission.
23407
b383017d 23408@item S_IROTH
0ce1b118
CV
23409Others have read permission.
23410
b383017d 23411@item S_IWOTH
0ce1b118
CV
23412Others have write permission.
23413
23414@noindent
23415Each other bit is silently ignored.
23416
23417@end table
23418
23419@smallexample
23420@exdent Return value:
23421open returns the new file descriptor or -1 if an error
23422occured.
23423
23424@exdent Errors:
23425@end smallexample
23426
23427@table @code
b383017d 23428@item EEXIST
0ce1b118
CV
23429pathname already exists and O_CREAT and O_EXCL were used.
23430
b383017d 23431@item EISDIR
0ce1b118
CV
23432pathname refers to a directory.
23433
b383017d 23434@item EACCES
0ce1b118
CV
23435The requested access is not allowed.
23436
23437@item ENAMETOOLONG
23438pathname was too long.
23439
b383017d 23440@item ENOENT
0ce1b118
CV
23441A directory component in pathname does not exist.
23442
b383017d 23443@item ENODEV
0ce1b118
CV
23444pathname refers to a device, pipe, named pipe or socket.
23445
b383017d 23446@item EROFS
0ce1b118
CV
23447pathname refers to a file on a read-only filesystem and
23448write access was requested.
23449
b383017d 23450@item EFAULT
0ce1b118
CV
23451pathname is an invalid pointer value.
23452
b383017d 23453@item ENOSPC
0ce1b118
CV
23454No space on device to create the file.
23455
b383017d 23456@item EMFILE
0ce1b118
CV
23457The process already has the maximum number of files open.
23458
b383017d 23459@item ENFILE
0ce1b118
CV
23460The limit on the total number of files open on the system
23461has been reached.
23462
b383017d 23463@item EINTR
0ce1b118
CV
23464The call was interrupted by the user.
23465@end table
23466
23467@node close
23468@unnumberedsubsubsec close
23469@cindex close, file-i/o system call
23470
23471@smallexample
b383017d 23472@exdent Synopsis:
0ce1b118
CV
23473int close(int fd);
23474
b383017d 23475@exdent Request:
0ce1b118
CV
23476Fclose,fd
23477
23478@exdent Return value:
23479close returns zero on success, or -1 if an error occurred.
23480
23481@exdent Errors:
23482@end smallexample
23483
23484@table @code
b383017d 23485@item EBADF
0ce1b118
CV
23486fd isn't a valid open file descriptor.
23487
b383017d 23488@item EINTR
0ce1b118
CV
23489The call was interrupted by the user.
23490@end table
23491
23492@node read
23493@unnumberedsubsubsec read
23494@cindex read, file-i/o system call
23495
23496@smallexample
b383017d 23497@exdent Synopsis:
0ce1b118
CV
23498int read(int fd, void *buf, unsigned int count);
23499
b383017d 23500@exdent Request:
0ce1b118
CV
23501Fread,fd,bufptr,count
23502
23503@exdent Return value:
23504On success, the number of bytes read is returned.
23505Zero indicates end of file. If count is zero, read
b383017d 23506returns zero as well. On error, -1 is returned.
0ce1b118
CV
23507
23508@exdent Errors:
23509@end smallexample
23510
23511@table @code
b383017d 23512@item EBADF
0ce1b118
CV
23513fd is not a valid file descriptor or is not open for
23514reading.
23515
b383017d 23516@item EFAULT
0ce1b118
CV
23517buf is an invalid pointer value.
23518
b383017d 23519@item EINTR
0ce1b118
CV
23520The call was interrupted by the user.
23521@end table
23522
23523@node write
23524@unnumberedsubsubsec write
23525@cindex write, file-i/o system call
23526
23527@smallexample
b383017d 23528@exdent Synopsis:
0ce1b118
CV
23529int write(int fd, const void *buf, unsigned int count);
23530
b383017d 23531@exdent Request:
0ce1b118
CV
23532Fwrite,fd,bufptr,count
23533
23534@exdent Return value:
23535On success, the number of bytes written are returned.
23536Zero indicates nothing was written. On error, -1
23537is returned.
23538
23539@exdent Errors:
23540@end smallexample
23541
23542@table @code
b383017d 23543@item EBADF
0ce1b118
CV
23544fd is not a valid file descriptor or is not open for
23545writing.
23546
b383017d 23547@item EFAULT
0ce1b118
CV
23548buf is an invalid pointer value.
23549
b383017d 23550@item EFBIG
0ce1b118
CV
23551An attempt was made to write a file that exceeds the
23552host specific maximum file size allowed.
23553
b383017d 23554@item ENOSPC
0ce1b118
CV
23555No space on device to write the data.
23556
b383017d 23557@item EINTR
0ce1b118
CV
23558The call was interrupted by the user.
23559@end table
23560
23561@node lseek
23562@unnumberedsubsubsec lseek
23563@cindex lseek, file-i/o system call
23564
23565@smallexample
b383017d 23566@exdent Synopsis:
0ce1b118
CV
23567long lseek (int fd, long offset, int flag);
23568
b383017d 23569@exdent Request:
0ce1b118
CV
23570Flseek,fd,offset,flag
23571@end smallexample
23572
23573@code{flag} is one of:
23574
23575@table @code
b383017d 23576@item SEEK_SET
0ce1b118
CV
23577The offset is set to offset bytes.
23578
b383017d 23579@item SEEK_CUR
0ce1b118
CV
23580The offset is set to its current location plus offset
23581bytes.
23582
b383017d 23583@item SEEK_END
0ce1b118
CV
23584The offset is set to the size of the file plus offset
23585bytes.
23586@end table
23587
23588@smallexample
23589@exdent Return value:
23590On success, the resulting unsigned offset in bytes from
23591the beginning of the file is returned. Otherwise, a
23592value of -1 is returned.
23593
23594@exdent Errors:
23595@end smallexample
23596
23597@table @code
b383017d 23598@item EBADF
0ce1b118
CV
23599fd is not a valid open file descriptor.
23600
b383017d 23601@item ESPIPE
0ce1b118
CV
23602fd is associated with the @value{GDBN} console.
23603
b383017d 23604@item EINVAL
0ce1b118
CV
23605flag is not a proper value.
23606
b383017d 23607@item EINTR
0ce1b118
CV
23608The call was interrupted by the user.
23609@end table
23610
23611@node rename
23612@unnumberedsubsubsec rename
23613@cindex rename, file-i/o system call
23614
23615@smallexample
b383017d 23616@exdent Synopsis:
0ce1b118
CV
23617int rename(const char *oldpath, const char *newpath);
23618
b383017d 23619@exdent Request:
0ce1b118
CV
23620Frename,oldpathptr/len,newpathptr/len
23621
23622@exdent Return value:
23623On success, zero is returned. On error, -1 is returned.
23624
23625@exdent Errors:
23626@end smallexample
23627
23628@table @code
b383017d 23629@item EISDIR
0ce1b118
CV
23630newpath is an existing directory, but oldpath is not a
23631directory.
23632
b383017d 23633@item EEXIST
0ce1b118
CV
23634newpath is a non-empty directory.
23635
b383017d 23636@item EBUSY
0ce1b118
CV
23637oldpath or newpath is a directory that is in use by some
23638process.
23639
b383017d 23640@item EINVAL
0ce1b118
CV
23641An attempt was made to make a directory a subdirectory
23642of itself.
23643
b383017d 23644@item ENOTDIR
0ce1b118
CV
23645A component used as a directory in oldpath or new
23646path is not a directory. Or oldpath is a directory
23647and newpath exists but is not a directory.
23648
b383017d 23649@item EFAULT
0ce1b118
CV
23650oldpathptr or newpathptr are invalid pointer values.
23651
b383017d 23652@item EACCES
0ce1b118
CV
23653No access to the file or the path of the file.
23654
23655@item ENAMETOOLONG
b383017d 23656
0ce1b118
CV
23657oldpath or newpath was too long.
23658
b383017d 23659@item ENOENT
0ce1b118
CV
23660A directory component in oldpath or newpath does not exist.
23661
b383017d 23662@item EROFS
0ce1b118
CV
23663The file is on a read-only filesystem.
23664
b383017d 23665@item ENOSPC
0ce1b118
CV
23666The device containing the file has no room for the new
23667directory entry.
23668
b383017d 23669@item EINTR
0ce1b118
CV
23670The call was interrupted by the user.
23671@end table
23672
23673@node unlink
23674@unnumberedsubsubsec unlink
23675@cindex unlink, file-i/o system call
23676
23677@smallexample
b383017d 23678@exdent Synopsis:
0ce1b118
CV
23679int unlink(const char *pathname);
23680
b383017d 23681@exdent Request:
0ce1b118
CV
23682Funlink,pathnameptr/len
23683
23684@exdent Return value:
23685On success, zero is returned. On error, -1 is returned.
23686
23687@exdent Errors:
23688@end smallexample
23689
23690@table @code
b383017d 23691@item EACCES
0ce1b118
CV
23692No access to the file or the path of the file.
23693
b383017d 23694@item EPERM
0ce1b118
CV
23695The system does not allow unlinking of directories.
23696
b383017d 23697@item EBUSY
0ce1b118
CV
23698The file pathname cannot be unlinked because it's
23699being used by another process.
23700
b383017d 23701@item EFAULT
0ce1b118
CV
23702pathnameptr is an invalid pointer value.
23703
23704@item ENAMETOOLONG
23705pathname was too long.
23706
b383017d 23707@item ENOENT
0ce1b118
CV
23708A directory component in pathname does not exist.
23709
b383017d 23710@item ENOTDIR
0ce1b118
CV
23711A component of the path is not a directory.
23712
b383017d 23713@item EROFS
0ce1b118
CV
23714The file is on a read-only filesystem.
23715
b383017d 23716@item EINTR
0ce1b118
CV
23717The call was interrupted by the user.
23718@end table
23719
23720@node stat/fstat
23721@unnumberedsubsubsec stat/fstat
23722@cindex fstat, file-i/o system call
23723@cindex stat, file-i/o system call
23724
23725@smallexample
b383017d 23726@exdent Synopsis:
0ce1b118
CV
23727int stat(const char *pathname, struct stat *buf);
23728int fstat(int fd, struct stat *buf);
23729
b383017d 23730@exdent Request:
0ce1b118
CV
23731Fstat,pathnameptr/len,bufptr
23732Ffstat,fd,bufptr
23733
23734@exdent Return value:
23735On success, zero is returned. On error, -1 is returned.
23736
23737@exdent Errors:
23738@end smallexample
23739
23740@table @code
b383017d 23741@item EBADF
0ce1b118
CV
23742fd is not a valid open file.
23743
b383017d 23744@item ENOENT
0ce1b118
CV
23745A directory component in pathname does not exist or the
23746path is an empty string.
23747
b383017d 23748@item ENOTDIR
0ce1b118
CV
23749A component of the path is not a directory.
23750
b383017d 23751@item EFAULT
0ce1b118
CV
23752pathnameptr is an invalid pointer value.
23753
b383017d 23754@item EACCES
0ce1b118
CV
23755No access to the file or the path of the file.
23756
23757@item ENAMETOOLONG
23758pathname was too long.
23759
b383017d 23760@item EINTR
0ce1b118
CV
23761The call was interrupted by the user.
23762@end table
23763
23764@node gettimeofday
23765@unnumberedsubsubsec gettimeofday
23766@cindex gettimeofday, file-i/o system call
23767
23768@smallexample
b383017d 23769@exdent Synopsis:
0ce1b118
CV
23770int gettimeofday(struct timeval *tv, void *tz);
23771
b383017d 23772@exdent Request:
0ce1b118
CV
23773Fgettimeofday,tvptr,tzptr
23774
23775@exdent Return value:
23776On success, 0 is returned, -1 otherwise.
23777
23778@exdent Errors:
23779@end smallexample
23780
23781@table @code
b383017d 23782@item EINVAL
0ce1b118
CV
23783tz is a non-NULL pointer.
23784
b383017d 23785@item EFAULT
0ce1b118
CV
23786tvptr and/or tzptr is an invalid pointer value.
23787@end table
23788
23789@node isatty
23790@unnumberedsubsubsec isatty
23791@cindex isatty, file-i/o system call
23792
23793@smallexample
b383017d 23794@exdent Synopsis:
0ce1b118
CV
23795int isatty(int fd);
23796
b383017d 23797@exdent Request:
0ce1b118
CV
23798Fisatty,fd
23799
23800@exdent Return value:
23801Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23802
23803@exdent Errors:
23804@end smallexample
23805
23806@table @code
b383017d 23807@item EINTR
0ce1b118
CV
23808The call was interrupted by the user.
23809@end table
23810
23811@node system
23812@unnumberedsubsubsec system
23813@cindex system, file-i/o system call
23814
23815@smallexample
b383017d 23816@exdent Synopsis:
0ce1b118
CV
23817int system(const char *command);
23818
b383017d 23819@exdent Request:
0ce1b118
CV
23820Fsystem,commandptr/len
23821
23822@exdent Return value:
23823The value returned is -1 on error and the return status
23824of the command otherwise. Only the exit status of the
23825command is returned, which is extracted from the hosts
23826system return value by calling WEXITSTATUS(retval).
23827In case /bin/sh could not be executed, 127 is returned.
23828
23829@exdent Errors:
23830@end smallexample
23831
23832@table @code
b383017d 23833@item EINTR
0ce1b118
CV
23834The call was interrupted by the user.
23835@end table
23836
23837@node Protocol specific representation of datatypes
23838@subsection Protocol specific representation of datatypes
23839@cindex protocol specific representation of datatypes, in file-i/o protocol
23840
23841@menu
23842* Integral datatypes::
23843* Pointer values::
23844* struct stat::
23845* struct timeval::
23846@end menu
23847
23848@node Integral datatypes
23849@unnumberedsubsubsec Integral datatypes
23850@cindex integral datatypes, in file-i/o protocol
23851
23852The integral datatypes used in the system calls are
23853
23854@smallexample
23855int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23856@end smallexample
23857
23858@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23859implemented as 32 bit values in this protocol.
23860
b383017d
RM
23861@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23862
0ce1b118
CV
23863@xref{Limits}, for corresponding MIN and MAX values (similar to those
23864in @file{limits.h}) to allow range checking on host and target.
23865
23866@code{time_t} datatypes are defined as seconds since the Epoch.
23867
23868All integral datatypes transferred as part of a memory read or write of a
23869structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23870byte order.
23871
23872@node Pointer values
23873@unnumberedsubsubsec Pointer values
23874@cindex pointer values, in file-i/o protocol
23875
23876Pointers to target data are transmitted as they are. An exception
23877is made for pointers to buffers for which the length isn't
23878transmitted as part of the function call, namely strings. Strings
23879are transmitted as a pointer/length pair, both as hex values, e.g.@:
23880
23881@smallexample
23882@code{1aaf/12}
23883@end smallexample
23884
23885@noindent
23886which is a pointer to data of length 18 bytes at position 0x1aaf.
23887The length is defined as the full string length in bytes, including
23888the trailing null byte. Example:
23889
23890@smallexample
23891``hello, world'' at address 0x123456
23892@end smallexample
23893
23894@noindent
23895is transmitted as
23896
23897@smallexample
23898@code{123456/d}
23899@end smallexample
23900
23901@node struct stat
23902@unnumberedsubsubsec struct stat
23903@cindex struct stat, in file-i/o protocol
23904
23905The buffer of type struct stat used by the target and @value{GDBN} is defined
23906as follows:
23907
23908@smallexample
23909struct stat @{
23910 unsigned int st_dev; /* device */
23911 unsigned int st_ino; /* inode */
23912 mode_t st_mode; /* protection */
23913 unsigned int st_nlink; /* number of hard links */
23914 unsigned int st_uid; /* user ID of owner */
23915 unsigned int st_gid; /* group ID of owner */
23916 unsigned int st_rdev; /* device type (if inode device) */
23917 unsigned long st_size; /* total size, in bytes */
23918 unsigned long st_blksize; /* blocksize for filesystem I/O */
23919 unsigned long st_blocks; /* number of blocks allocated */
23920 time_t st_atime; /* time of last access */
23921 time_t st_mtime; /* time of last modification */
23922 time_t st_ctime; /* time of last change */
23923@};
23924@end smallexample
23925
23926The integral datatypes are conforming to the definitions given in the
23927approriate section (see @ref{Integral datatypes}, for details) so this
23928structure is of size 64 bytes.
23929
23930The values of several fields have a restricted meaning and/or
23931range of values.
23932
23933@smallexample
23934st_dev: 0 file
23935 1 console
23936
23937st_ino: No valid meaning for the target. Transmitted unchanged.
23938
23939st_mode: Valid mode bits are described in Appendix C. Any other
23940 bits have currently no meaning for the target.
23941
23942st_uid: No valid meaning for the target. Transmitted unchanged.
23943
23944st_gid: No valid meaning for the target. Transmitted unchanged.
23945
23946st_rdev: No valid meaning for the target. Transmitted unchanged.
23947
23948st_atime, st_mtime, st_ctime:
23949 These values have a host and file system dependent
23950 accuracy. Especially on Windows hosts the file systems
23951 don't support exact timing values.
23952@end smallexample
23953
23954The target gets a struct stat of the above representation and is
23955responsible to coerce it to the target representation before
23956continuing.
23957
23958Note that due to size differences between the host and target
23959representation of stat members, these members could eventually
23960get truncated on the target.
23961
23962@node struct timeval
23963@unnumberedsubsubsec struct timeval
23964@cindex struct timeval, in file-i/o protocol
23965
23966The buffer of type struct timeval used by the target and @value{GDBN}
23967is defined as follows:
23968
23969@smallexample
b383017d 23970struct timeval @{
0ce1b118
CV
23971 time_t tv_sec; /* second */
23972 long tv_usec; /* microsecond */
23973@};
23974@end smallexample
23975
23976The integral datatypes are conforming to the definitions given in the
23977approriate section (see @ref{Integral datatypes}, for details) so this
23978structure is of size 8 bytes.
23979
23980@node Constants
23981@subsection Constants
23982@cindex constants, in file-i/o protocol
23983
23984The following values are used for the constants inside of the
23985protocol. @value{GDBN} and target are resposible to translate these
23986values before and after the call as needed.
23987
23988@menu
23989* Open flags::
23990* mode_t values::
23991* Errno values::
23992* Lseek flags::
23993* Limits::
23994@end menu
23995
23996@node Open flags
23997@unnumberedsubsubsec Open flags
23998@cindex open flags, in file-i/o protocol
23999
24000All values are given in hexadecimal representation.
24001
24002@smallexample
24003 O_RDONLY 0x0
24004 O_WRONLY 0x1
24005 O_RDWR 0x2
24006 O_APPEND 0x8
24007 O_CREAT 0x200
24008 O_TRUNC 0x400
24009 O_EXCL 0x800
24010@end smallexample
24011
24012@node mode_t values
24013@unnumberedsubsubsec mode_t values
24014@cindex mode_t values, in file-i/o protocol
24015
24016All values are given in octal representation.
24017
24018@smallexample
24019 S_IFREG 0100000
24020 S_IFDIR 040000
24021 S_IRUSR 0400
24022 S_IWUSR 0200
24023 S_IXUSR 0100
24024 S_IRGRP 040
24025 S_IWGRP 020
24026 S_IXGRP 010
24027 S_IROTH 04
24028 S_IWOTH 02
24029 S_IXOTH 01
24030@end smallexample
24031
24032@node Errno values
24033@unnumberedsubsubsec Errno values
24034@cindex errno values, in file-i/o protocol
24035
24036All values are given in decimal representation.
24037
24038@smallexample
24039 EPERM 1
24040 ENOENT 2
24041 EINTR 4
24042 EBADF 9
24043 EACCES 13
24044 EFAULT 14
24045 EBUSY 16
24046 EEXIST 17
24047 ENODEV 19
24048 ENOTDIR 20
24049 EISDIR 21
24050 EINVAL 22
24051 ENFILE 23
24052 EMFILE 24
24053 EFBIG 27
24054 ENOSPC 28
24055 ESPIPE 29
24056 EROFS 30
24057 ENAMETOOLONG 91
24058 EUNKNOWN 9999
24059@end smallexample
24060
24061 EUNKNOWN is used as a fallback error value if a host system returns
24062 any error value not in the list of supported error numbers.
24063
24064@node Lseek flags
24065@unnumberedsubsubsec Lseek flags
24066@cindex lseek flags, in file-i/o protocol
24067
24068@smallexample
24069 SEEK_SET 0
24070 SEEK_CUR 1
24071 SEEK_END 2
24072@end smallexample
24073
24074@node Limits
24075@unnumberedsubsubsec Limits
24076@cindex limits, in file-i/o protocol
24077
24078All values are given in decimal representation.
24079
24080@smallexample
24081 INT_MIN -2147483648
24082 INT_MAX 2147483647
24083 UINT_MAX 4294967295
24084 LONG_MIN -9223372036854775808
24085 LONG_MAX 9223372036854775807
24086 ULONG_MAX 18446744073709551615
24087@end smallexample
24088
24089@node File-I/O Examples
24090@subsection File-I/O Examples
24091@cindex file-i/o examples
24092
24093Example sequence of a write call, file descriptor 3, buffer is at target
24094address 0x1234, 6 bytes should be written:
24095
24096@smallexample
24097<- @code{Fwrite,3,1234,6}
24098@emph{request memory read from target}
24099-> @code{m1234,6}
24100<- XXXXXX
24101@emph{return "6 bytes written"}
24102-> @code{F6}
24103@end smallexample
24104
24105Example sequence of a read call, file descriptor 3, buffer is at target
24106address 0x1234, 6 bytes should be read:
24107
24108@smallexample
24109<- @code{Fread,3,1234,6}
24110@emph{request memory write to target}
24111-> @code{X1234,6:XXXXXX}
24112@emph{return "6 bytes read"}
24113-> @code{F6}
24114@end smallexample
24115
24116Example sequence of a read call, call fails on the host due to invalid
24117file descriptor (EBADF):
24118
24119@smallexample
24120<- @code{Fread,3,1234,6}
24121-> @code{F-1,9}
24122@end smallexample
24123
24124Example sequence of a read call, user presses Ctrl-C before syscall on
24125host is called:
24126
24127@smallexample
24128<- @code{Fread,3,1234,6}
24129-> @code{F-1,4,C}
24130<- @code{T02}
24131@end smallexample
24132
24133Example sequence of a read call, user presses Ctrl-C after syscall on
24134host is called:
24135
24136@smallexample
24137<- @code{Fread,3,1234,6}
24138-> @code{X1234,6:XXXXXX}
24139<- @code{T02}
24140@end smallexample
24141
f418dd93
DJ
24142@include agentexpr.texi
24143
aab4e0ec 24144@include gpl.texi
eb12ee30 24145
2154891a 24146@raisesections
6826cf00 24147@include fdl.texi
2154891a 24148@lowersections
6826cf00 24149
6d2ebf8b 24150@node Index
c906108c
SS
24151@unnumbered Index
24152
24153@printindex cp
24154
24155@tex
24156% I think something like @colophon should be in texinfo. In the
24157% meantime:
24158\long\def\colophon{\hbox to0pt{}\vfill
24159\centerline{The body of this manual is set in}
24160\centerline{\fontname\tenrm,}
24161\centerline{with headings in {\bf\fontname\tenbf}}
24162\centerline{and examples in {\tt\fontname\tentt}.}
24163\centerline{{\it\fontname\tenit\/},}
24164\centerline{{\bf\fontname\tenbf}, and}
24165\centerline{{\sl\fontname\tensl\/}}
24166\centerline{are used for emphasis.}\vfill}
24167\page\colophon
24168% Blame: doc@cygnus.com, 1991.
24169@end tex
24170
c906108c 24171@bye