2005-11-07 Andrew Stubbs <andrew.stubbs@st.com>
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b6ba6518 2@c Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
7d51c7de 3@c 1999, 2000, 2001, 2002, 2003, 2004, 2005
c906108c
SS
4@c Free Software Foundation, Inc.
5@c
5d161b24 6@c %**start of header
c906108c
SS
7@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8@c of @set vars. However, you can override filename with makeinfo -o.
9@setfilename gdb.info
10@c
11@include gdb-cfg.texi
12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
23@syncodeindex ky cp
24
41afff9a 25@c readline appendices use @vindex, @findex and @ftable,
48e934c6 26@c annotate.texi and gdbmi use @findex.
c906108c 27@syncodeindex vr cp
41afff9a 28@syncodeindex fn cp
c906108c
SS
29
30@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 31@c This is updated by GNU Press.
e9c75b65 32@set EDITION Ninth
c906108c 33
87885426
FN
34@c !!set GDB edit command default editor
35@set EDITOR /bin/ex
c906108c 36
6c0e9fb3 37@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 38
c906108c 39@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 40@c manuals to an info tree.
03727ca6 41@dircategory Software development
96a2c332 42@direntry
03727ca6 43* Gdb: (gdb). The GNU debugger.
96a2c332
SS
44@end direntry
45
c906108c
SS
46@ifinfo
47This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
9fe8321b
AC
50This is the @value{EDITION} Edition, of @cite{Debugging with
51@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52Version @value{GDBVN}.
c906108c 53
8a037dd7 54Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
7d51c7de
BR
55 1999, 2000, 2001, 2002, 2003, 2004, 2005@*
56 Free Software Foundation, Inc.
c906108c 57
e9c75b65
EZ
58Permission is granted to copy, distribute and/or modify this document
59under the terms of the GNU Free Documentation License, Version 1.1 or
60any later version published by the Free Software Foundation; with the
959acfd1
EZ
61Invariant Sections being ``Free Software'' and ``Free Software Needs
62Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63and with the Back-Cover Texts as in (a) below.
c906108c 64
6826cf00
EZ
65(a) The Free Software Foundation's Back-Cover Text is: ``You have
66freedom to copy and modify this GNU Manual, like GNU software. Copies
67published by the Free Software Foundation raise funds for GNU
68development.''
c906108c
SS
69@end ifinfo
70
71@titlepage
72@title Debugging with @value{GDBN}
73@subtitle The @sc{gnu} Source-Level Debugger
c906108c 74@sp 1
c906108c 75@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
9e9c5ae7 76@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 77@page
c906108c
SS
78@tex
79{\parskip=0pt
53a5351d 80\hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
c906108c
SS
81\hfill {\it Debugging with @value{GDBN}}\par
82\hfill \TeX{}info \texinfoversion\par
83}
84@end tex
53a5351d 85
c906108c 86@vskip 0pt plus 1filll
8a037dd7 87Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
7d51c7de
BR
881996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
89Free Software Foundation, Inc.
c906108c 90@sp 2
c906108c
SS
91Published by the Free Software Foundation @*
9259 Temple Place - Suite 330, @*
93Boston, MA 02111-1307 USA @*
6d2ebf8b 94ISBN 1-882114-77-9 @*
e9c75b65
EZ
95
96Permission is granted to copy, distribute and/or modify this document
97under the terms of the GNU Free Documentation License, Version 1.1 or
98any later version published by the Free Software Foundation; with the
959acfd1
EZ
99Invariant Sections being ``Free Software'' and ``Free Software Needs
100Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
101and with the Back-Cover Texts as in (a) below.
e9c75b65 102
6826cf00
EZ
103(a) The Free Software Foundation's Back-Cover Text is: ``You have
104freedom to copy and modify this GNU Manual, like GNU software. Copies
105published by the Free Software Foundation raise funds for GNU
106development.''
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
9fe8321b 117This is the @value{EDITION} Edition, for @value{GDBN} Version
c906108c
SS
118@value{GDBVN}.
119
7d51c7de 120Copyright (C) 1988-2005 Free Software Foundation, Inc.
6d2ebf8b
SS
121
122@menu
123* Summary:: Summary of @value{GDBN}
124* Sample Session:: A sample @value{GDBN} session
125
126* Invocation:: Getting in and out of @value{GDBN}
127* Commands:: @value{GDBN} commands
128* Running:: Running programs under @value{GDBN}
129* Stopping:: Stopping and continuing
130* Stack:: Examining the stack
131* Source:: Examining source files
132* Data:: Examining data
e2e0bcd1 133* Macros:: Preprocessor Macros
b37052ae 134* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 135* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
136
137* Languages:: Using @value{GDBN} with different languages
138
139* Symbols:: Examining the symbol table
140* Altering:: Altering execution
141* GDB Files:: @value{GDBN} files
142* Targets:: Specifying a debugging target
6b2f586d 143* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
144* Configurations:: Configuration-specific information
145* Controlling GDB:: Controlling @value{GDBN}
146* Sequences:: Canned sequences of commands
c4555f82 147* TUI:: @value{GDBN} Text User Interface
21c294e6 148* Interpreters:: Command Interpreters
6d2ebf8b
SS
149* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
150* Annotations:: @value{GDBN}'s annotation interface.
7162c0ca 151* GDB/MI:: @value{GDBN}'s Machine Interface.
6d2ebf8b
SS
152
153* GDB Bugs:: Reporting bugs in @value{GDBN}
154* Formatting Documentation:: How to format and print @value{GDBN} documentation
155
156* Command Line Editing:: Command Line Editing
157* Using History Interactively:: Using History Interactively
158* Installing GDB:: Installing GDB
eb12ee30 159* Maintenance Commands:: Maintenance Commands
e0ce93ac 160* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 161* Agent Expressions:: The GDB Agent Expression Mechanism
aab4e0ec
AC
162* Copying:: GNU General Public License says
163 how you can copy and share GDB
6826cf00 164* GNU Free Documentation License:: The license for this documentation
6d2ebf8b
SS
165* Index:: Index
166@end menu
167
6c0e9fb3 168@end ifnottex
c906108c 169
449f3b6c 170@contents
449f3b6c 171
6d2ebf8b 172@node Summary
c906108c
SS
173@unnumbered Summary of @value{GDBN}
174
175The purpose of a debugger such as @value{GDBN} is to allow you to see what is
176going on ``inside'' another program while it executes---or what another
177program was doing at the moment it crashed.
178
179@value{GDBN} can do four main kinds of things (plus other things in support of
180these) to help you catch bugs in the act:
181
182@itemize @bullet
183@item
184Start your program, specifying anything that might affect its behavior.
185
186@item
187Make your program stop on specified conditions.
188
189@item
190Examine what has happened, when your program has stopped.
191
192@item
193Change things in your program, so you can experiment with correcting the
194effects of one bug and go on to learn about another.
195@end itemize
196
49efadf5 197You can use @value{GDBN} to debug programs written in C and C@t{++}.
9c16f35a 198For more information, see @ref{Supported languages,,Supported languages}.
c906108c
SS
199For more information, see @ref{C,,C and C++}.
200
cce74817 201@cindex Modula-2
e632838e
AC
202Support for Modula-2 is partial. For information on Modula-2, see
203@ref{Modula-2,,Modula-2}.
c906108c 204
cce74817
JM
205@cindex Pascal
206Debugging Pascal programs which use sets, subranges, file variables, or
207nested functions does not currently work. @value{GDBN} does not support
208entering expressions, printing values, or similar features using Pascal
209syntax.
c906108c 210
c906108c
SS
211@cindex Fortran
212@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 213it may be necessary to refer to some variables with a trailing
cce74817 214underscore.
c906108c 215
b37303ee
AF
216@value{GDBN} can be used to debug programs written in Objective-C,
217using either the Apple/NeXT or the GNU Objective-C runtime.
218
c906108c
SS
219@menu
220* Free Software:: Freely redistributable software
221* Contributors:: Contributors to GDB
222@end menu
223
6d2ebf8b 224@node Free Software
c906108c
SS
225@unnumberedsec Free software
226
5d161b24 227@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
228General Public License
229(GPL). The GPL gives you the freedom to copy or adapt a licensed
230program---but every person getting a copy also gets with it the
231freedom to modify that copy (which means that they must get access to
232the source code), and the freedom to distribute further copies.
233Typical software companies use copyrights to limit your freedoms; the
234Free Software Foundation uses the GPL to preserve these freedoms.
235
236Fundamentally, the General Public License is a license which says that
237you have these freedoms and that you cannot take these freedoms away
238from anyone else.
239
2666264b 240@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
241
242The biggest deficiency in the free software community today is not in
243the software---it is the lack of good free documentation that we can
244include with the free software. Many of our most important
245programs do not come with free reference manuals and free introductory
246texts. Documentation is an essential part of any software package;
247when an important free software package does not come with a free
248manual and a free tutorial, that is a major gap. We have many such
249gaps today.
250
251Consider Perl, for instance. The tutorial manuals that people
252normally use are non-free. How did this come about? Because the
253authors of those manuals published them with restrictive terms---no
254copying, no modification, source files not available---which exclude
255them from the free software world.
256
257That wasn't the first time this sort of thing happened, and it was far
258from the last. Many times we have heard a GNU user eagerly describe a
259manual that he is writing, his intended contribution to the community,
260only to learn that he had ruined everything by signing a publication
261contract to make it non-free.
262
263Free documentation, like free software, is a matter of freedom, not
264price. The problem with the non-free manual is not that publishers
265charge a price for printed copies---that in itself is fine. (The Free
266Software Foundation sells printed copies of manuals, too.) The
267problem is the restrictions on the use of the manual. Free manuals
268are available in source code form, and give you permission to copy and
269modify. Non-free manuals do not allow this.
270
271The criteria of freedom for a free manual are roughly the same as for
272free software. Redistribution (including the normal kinds of
273commercial redistribution) must be permitted, so that the manual can
274accompany every copy of the program, both on-line and on paper.
275
276Permission for modification of the technical content is crucial too.
277When people modify the software, adding or changing features, if they
278are conscientious they will change the manual too---so they can
279provide accurate and clear documentation for the modified program. A
280manual that leaves you no choice but to write a new manual to document
281a changed version of the program is not really available to our
282community.
283
284Some kinds of limits on the way modification is handled are
285acceptable. For example, requirements to preserve the original
286author's copyright notice, the distribution terms, or the list of
287authors, are ok. It is also no problem to require modified versions
288to include notice that they were modified. Even entire sections that
289may not be deleted or changed are acceptable, as long as they deal
290with nontechnical topics (like this one). These kinds of restrictions
291are acceptable because they don't obstruct the community's normal use
292of the manual.
293
294However, it must be possible to modify all the @emph{technical}
295content of the manual, and then distribute the result in all the usual
296media, through all the usual channels. Otherwise, the restrictions
297obstruct the use of the manual, it is not free, and we need another
298manual to replace it.
299
300Please spread the word about this issue. Our community continues to
301lose manuals to proprietary publishing. If we spread the word that
302free software needs free reference manuals and free tutorials, perhaps
303the next person who wants to contribute by writing documentation will
304realize, before it is too late, that only free manuals contribute to
305the free software community.
306
307If you are writing documentation, please insist on publishing it under
308the GNU Free Documentation License or another free documentation
309license. Remember that this decision requires your approval---you
310don't have to let the publisher decide. Some commercial publishers
311will use a free license if you insist, but they will not propose the
312option; it is up to you to raise the issue and say firmly that this is
313what you want. If the publisher you are dealing with refuses, please
314try other publishers. If you're not sure whether a proposed license
42584a72 315is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
316
317You can encourage commercial publishers to sell more free, copylefted
318manuals and tutorials by buying them, and particularly by buying
319copies from the publishers that paid for their writing or for major
320improvements. Meanwhile, try to avoid buying non-free documentation
321at all. Check the distribution terms of a manual before you buy it,
322and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
323Check the history of the book, and try to reward the publishers that
324have paid or pay the authors to work on it.
959acfd1
EZ
325
326The Free Software Foundation maintains a list of free documentation
327published by other publishers, at
328@url{http://www.fsf.org/doc/other-free-books.html}.
329
6d2ebf8b 330@node Contributors
96a2c332
SS
331@unnumberedsec Contributors to @value{GDBN}
332
333Richard Stallman was the original author of @value{GDBN}, and of many
334other @sc{gnu} programs. Many others have contributed to its
335development. This section attempts to credit major contributors. One
336of the virtues of free software is that everyone is free to contribute
337to it; with regret, we cannot actually acknowledge everyone here. The
338file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
339blow-by-blow account.
340
341Changes much prior to version 2.0 are lost in the mists of time.
342
343@quotation
344@emph{Plea:} Additions to this section are particularly welcome. If you
345or your friends (or enemies, to be evenhanded) have been unfairly
346omitted from this list, we would like to add your names!
347@end quotation
348
349So that they may not regard their many labors as thankless, we
350particularly thank those who shepherded @value{GDBN} through major
351releases:
7ba3cf9c 352Andrew Cagney (releases 6.3, 6.2, 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 -r
942@itemx -readnow
d700128c
EZ
943@cindex @code{--readnow}
944@cindex @code{-r}
c906108c
SS
945Read each symbol file's entire symbol table immediately, rather than
946the default, which is to read it incrementally as it is needed.
947This makes startup slower, but makes future operations faster.
53a5351d 948
c906108c
SS
949@end table
950
6d2ebf8b 951@node Mode Options
c906108c
SS
952@subsection Choosing modes
953
954You can run @value{GDBN} in various alternative modes---for example, in
955batch mode or quiet mode.
956
957@table @code
958@item -nx
959@itemx -n
d700128c
EZ
960@cindex @code{--nx}
961@cindex @code{-n}
96565e91 962Do not execute commands found in any initialization files. Normally,
2df3850c
JM
963@value{GDBN} executes the commands in these files after all the command
964options and arguments have been processed. @xref{Command Files,,Command
965files}.
c906108c
SS
966
967@item -quiet
d700128c 968@itemx -silent
c906108c 969@itemx -q
d700128c
EZ
970@cindex @code{--quiet}
971@cindex @code{--silent}
972@cindex @code{-q}
c906108c
SS
973``Quiet''. Do not print the introductory and copyright messages. These
974messages are also suppressed in batch mode.
975
976@item -batch
d700128c 977@cindex @code{--batch}
c906108c
SS
978Run in batch mode. Exit with status @code{0} after processing all the
979command files specified with @samp{-x} (and all commands from
980initialization files, if not inhibited with @samp{-n}). Exit with
981nonzero status if an error occurs in executing the @value{GDBN} commands
982in the command files.
983
2df3850c
JM
984Batch mode may be useful for running @value{GDBN} as a filter, for
985example to download and run a program on another computer; in order to
986make this more useful, the message
c906108c 987
474c8240 988@smallexample
c906108c 989Program exited normally.
474c8240 990@end smallexample
c906108c
SS
991
992@noindent
2df3850c
JM
993(which is ordinarily issued whenever a program running under
994@value{GDBN} control terminates) is not issued when running in batch
995mode.
996
1a088d06
AS
997@item -batch-silent
998@cindex @code{--batch-silent}
999Run in batch mode exactly like @samp{-batch}, but totally silently. All
1000@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1001unaffected). This is much quieter than @samp{-silent} and would be useless
1002for an interactive session.
1003
1004This is particularly useful when using targets that give @samp{Loading section}
1005messages, for example.
1006
1007Note that targets that give their output via @value{GDBN}, as opposed to
1008writing directly to @code{stdout}, will also be made silent.
1009
4b0ad762
AS
1010@item -return-child-result
1011@cindex @code{--return-child-result}
1012The return code from @value{GDBN} will be the return code from the child
1013process (the process being debugged), with the following exceptions:
1014
1015@itemize @bullet
1016@item
1017@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1018internal error. In this case the exit code is the same as it would have been
1019without @samp{-return-child-result}.
1020@item
1021The user quits with an explicit value. E.g., @samp{quit 1}.
1022@item
1023The child process never runs, or is not allowed to terminate, in which case
1024the exit code will be -1.
1025@end itemize
1026
1027This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1028when @value{GDBN} is being used as a remote program loader or simulator
1029interface.
1030
2df3850c
JM
1031@item -nowindows
1032@itemx -nw
d700128c
EZ
1033@cindex @code{--nowindows}
1034@cindex @code{-nw}
2df3850c 1035``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1036(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1037interface. If no GUI is available, this option has no effect.
1038
1039@item -windows
1040@itemx -w
d700128c
EZ
1041@cindex @code{--windows}
1042@cindex @code{-w}
2df3850c
JM
1043If @value{GDBN} includes a GUI, then this option requires it to be
1044used if possible.
c906108c
SS
1045
1046@item -cd @var{directory}
d700128c 1047@cindex @code{--cd}
c906108c
SS
1048Run @value{GDBN} using @var{directory} as its working directory,
1049instead of the current directory.
1050
c906108c
SS
1051@item -fullname
1052@itemx -f
d700128c
EZ
1053@cindex @code{--fullname}
1054@cindex @code{-f}
7a292a7a
SS
1055@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1056subprocess. It tells @value{GDBN} to output the full file name and line
1057number in a standard, recognizable fashion each time a stack frame is
1058displayed (which includes each time your program stops). This
1059recognizable format looks like two @samp{\032} characters, followed by
1060the file name, line number and character position separated by colons,
1061and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1062@samp{\032} characters as a signal to display the source code for the
1063frame.
c906108c 1064
d700128c
EZ
1065@item -epoch
1066@cindex @code{--epoch}
1067The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1068@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1069routines so as to allow Epoch to display values of expressions in a
1070separate window.
1071
1072@item -annotate @var{level}
1073@cindex @code{--annotate}
1074This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1075effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1076(@pxref{Annotations}). The annotation @var{level} controls how much
1077information @value{GDBN} prints together with its prompt, values of
1078expressions, source lines, and other types of output. Level 0 is the
1079normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1080@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1081that control @value{GDBN}, and level 2 has been deprecated.
1082
265eeb58 1083The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1084(@pxref{GDB/MI}).
d700128c 1085
aa26fa3a
TT
1086@item --args
1087@cindex @code{--args}
1088Change interpretation of command line so that arguments following the
1089executable file are passed as command line arguments to the inferior.
1090This option stops option processing.
1091
2df3850c
JM
1092@item -baud @var{bps}
1093@itemx -b @var{bps}
d700128c
EZ
1094@cindex @code{--baud}
1095@cindex @code{-b}
c906108c
SS
1096Set the line speed (baud rate or bits per second) of any serial
1097interface used by @value{GDBN} for remote debugging.
c906108c 1098
f47b1503
AS
1099@item -l @var{timeout}
1100@cindex @code{-l}
1101Set the timeout (in seconds) of any communication used by @value{GDBN}
1102for remote debugging.
1103
c906108c 1104@item -tty @var{device}
d700128c
EZ
1105@itemx -t @var{device}
1106@cindex @code{--tty}
1107@cindex @code{-t}
c906108c
SS
1108Run using @var{device} for your program's standard input and output.
1109@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1110
53a5351d 1111@c resolve the situation of these eventually
c4555f82
SC
1112@item -tui
1113@cindex @code{--tui}
d0d5df6f
AC
1114Activate the @dfn{Text User Interface} when starting. The Text User
1115Interface manages several text windows on the terminal, showing
1116source, assembly, registers and @value{GDBN} command outputs
1117(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1118Text User Interface can be enabled by invoking the program
1119@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1120Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1121
1122@c @item -xdb
d700128c 1123@c @cindex @code{--xdb}
53a5351d
JM
1124@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1125@c For information, see the file @file{xdb_trans.html}, which is usually
1126@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1127@c systems.
1128
d700128c
EZ
1129@item -interpreter @var{interp}
1130@cindex @code{--interpreter}
1131Use the interpreter @var{interp} for interface with the controlling
1132program or device. This option is meant to be set by programs which
94bbb2c0 1133communicate with @value{GDBN} using it as a back end.
21c294e6 1134@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1135
da0f9dcd 1136@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1137@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1138The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1139previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1140selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1141@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1142
1143@item -write
1144@cindex @code{--write}
1145Open the executable and core files for both reading and writing. This
1146is equivalent to the @samp{set write on} command inside @value{GDBN}
1147(@pxref{Patching}).
1148
1149@item -statistics
1150@cindex @code{--statistics}
1151This option causes @value{GDBN} to print statistics about time and
1152memory usage after it completes each command and returns to the prompt.
1153
1154@item -version
1155@cindex @code{--version}
1156This option causes @value{GDBN} to print its version number and
1157no-warranty blurb, and exit.
1158
c906108c
SS
1159@end table
1160
6fc08d32
EZ
1161@node Startup
1162@subsection What @value{GDBN} does during startup
1163@cindex @value{GDBN} startup
1164
1165Here's the description of what @value{GDBN} does during session startup:
1166
1167@enumerate
1168@item
1169Sets up the command interpreter as specified by the command line
1170(@pxref{Mode Options, interpreter}).
1171
1172@item
1173@cindex init file
1174Reads the @dfn{init file} (if any) in your home directory@footnote{On
1175DOS/Windows systems, the home directory is the one pointed to by the
1176@code{HOME} environment variable.} and executes all the commands in
1177that file.
1178
1179@item
1180Processes command line options and operands.
1181
1182@item
1183Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1184working directory. This is only done if the current directory is
1185different from your home directory. Thus, you can have more than one
1186init file, one generic in your home directory, and another, specific
1187to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1188@value{GDBN}.
1189
1190@item
1191Reads command files specified by the @samp{-x} option. @xref{Command
1192Files}, for more details about @value{GDBN} command files.
1193
1194@item
1195Reads the command history recorded in the @dfn{history file}.
d620b259 1196@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1197files where @value{GDBN} records it.
1198@end enumerate
1199
1200Init files use the same syntax as @dfn{command files} (@pxref{Command
1201Files}) and are processed by @value{GDBN} in the same way. The init
1202file in your home directory can set options (such as @samp{set
1203complaints}) that affect subsequent processing of command line options
1204and operands. Init files are not executed if you use the @samp{-nx}
1205option (@pxref{Mode Options, ,Choosing modes}).
1206
1207@cindex init file name
1208@cindex @file{.gdbinit}
119b882a 1209The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1210On some configurations of @value{GDBN}, the init file is known by a
1211different name (these are typically environments where a specialized
1212form of @value{GDBN} may need to coexist with other forms, hence a
1213different name for the specialized version's init file). These are the
1214environments with special init file names:
1215
6fc08d32 1216@itemize @bullet
119b882a
EZ
1217@cindex @file{gdb.ini}
1218@item
1219The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1220the limitations of file names imposed by DOS filesystems. The Windows
1221ports of @value{GDBN} use the standard name, but if they find a
1222@file{gdb.ini} file, they warn you about that and suggest to rename
1223the file to the standard name.
1224
1225@cindex @file{.vxgdbinit}
6fc08d32
EZ
1226@item
1227VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1228
1229@cindex @file{.os68gdbinit}
1230@item
1231OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1232
1233@cindex @file{.esgdbinit}
1234@item
1235ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1236
1237@item
1238CISCO 68k: @file{.cisco-gdbinit}
1239@end itemize
1240
1241
6d2ebf8b 1242@node Quitting GDB
c906108c
SS
1243@section Quitting @value{GDBN}
1244@cindex exiting @value{GDBN}
1245@cindex leaving @value{GDBN}
1246
1247@table @code
1248@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1249@kindex q @r{(@code{quit})}
96a2c332
SS
1250@item quit @r{[}@var{expression}@r{]}
1251@itemx q
1252To exit @value{GDBN}, use the @code{quit} command (abbreviated
1253@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1254do not supply @var{expression}, @value{GDBN} will terminate normally;
1255otherwise it will terminate using the result of @var{expression} as the
1256error code.
c906108c
SS
1257@end table
1258
1259@cindex interrupt
1260An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1261terminates the action of any @value{GDBN} command that is in progress and
1262returns to @value{GDBN} command level. It is safe to type the interrupt
1263character at any time because @value{GDBN} does not allow it to take effect
1264until a time when it is safe.
1265
c906108c
SS
1266If you have been using @value{GDBN} to control an attached process or
1267device, you can release it with the @code{detach} command
1268(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1269
6d2ebf8b 1270@node Shell Commands
c906108c
SS
1271@section Shell commands
1272
1273If you need to execute occasional shell commands during your
1274debugging session, there is no need to leave or suspend @value{GDBN}; you can
1275just use the @code{shell} command.
1276
1277@table @code
1278@kindex shell
1279@cindex shell escape
1280@item shell @var{command string}
1281Invoke a standard shell to execute @var{command string}.
c906108c 1282If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1283shell to run. Otherwise @value{GDBN} uses the default shell
1284(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1285@end table
1286
1287The utility @code{make} is often needed in development environments.
1288You do not have to use the @code{shell} command for this purpose in
1289@value{GDBN}:
1290
1291@table @code
1292@kindex make
1293@cindex calling make
1294@item make @var{make-args}
1295Execute the @code{make} program with the specified
1296arguments. This is equivalent to @samp{shell make @var{make-args}}.
1297@end table
1298
0fac0b41
DJ
1299@node Logging output
1300@section Logging output
1301@cindex logging @value{GDBN} output
9c16f35a 1302@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1303
1304You may want to save the output of @value{GDBN} commands to a file.
1305There are several commands to control @value{GDBN}'s logging.
1306
1307@table @code
1308@kindex set logging
1309@item set logging on
1310Enable logging.
1311@item set logging off
1312Disable logging.
9c16f35a 1313@cindex logging file name
0fac0b41
DJ
1314@item set logging file @var{file}
1315Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1316@item set logging overwrite [on|off]
1317By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1318you want @code{set logging on} to overwrite the logfile instead.
1319@item set logging redirect [on|off]
1320By default, @value{GDBN} output will go to both the terminal and the logfile.
1321Set @code{redirect} if you want output to go only to the log file.
1322@kindex show logging
1323@item show logging
1324Show the current values of the logging settings.
1325@end table
1326
6d2ebf8b 1327@node Commands
c906108c
SS
1328@chapter @value{GDBN} Commands
1329
1330You can abbreviate a @value{GDBN} command to the first few letters of the command
1331name, if that abbreviation is unambiguous; and you can repeat certain
1332@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1333key to get @value{GDBN} to fill out the rest of a word in a command (or to
1334show you the alternatives available, if there is more than one possibility).
1335
1336@menu
1337* Command Syntax:: How to give commands to @value{GDBN}
1338* Completion:: Command completion
1339* Help:: How to ask @value{GDBN} for help
1340@end menu
1341
6d2ebf8b 1342@node Command Syntax
c906108c
SS
1343@section Command syntax
1344
1345A @value{GDBN} command is a single line of input. There is no limit on
1346how long it can be. It starts with a command name, which is followed by
1347arguments whose meaning depends on the command name. For example, the
1348command @code{step} accepts an argument which is the number of times to
1349step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1350with no arguments. Some commands do not allow any arguments.
c906108c
SS
1351
1352@cindex abbreviation
1353@value{GDBN} command names may always be truncated if that abbreviation is
1354unambiguous. Other possible command abbreviations are listed in the
1355documentation for individual commands. In some cases, even ambiguous
1356abbreviations are allowed; for example, @code{s} is specially defined as
1357equivalent to @code{step} even though there are other commands whose
1358names start with @code{s}. You can test abbreviations by using them as
1359arguments to the @code{help} command.
1360
1361@cindex repeating commands
41afff9a 1362@kindex RET @r{(repeat last command)}
c906108c 1363A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1364repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1365will not repeat this way; these are commands whose unintentional
1366repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1367repeat. User-defined commands can disable this feature; see
1368@ref{Define, dont-repeat}.
c906108c
SS
1369
1370The @code{list} and @code{x} commands, when you repeat them with
1371@key{RET}, construct new arguments rather than repeating
1372exactly as typed. This permits easy scanning of source or memory.
1373
1374@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1375output, in a way similar to the common utility @code{more}
1376(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1377@key{RET} too many in this situation, @value{GDBN} disables command
1378repetition after any command that generates this sort of display.
1379
41afff9a 1380@kindex # @r{(a comment)}
c906108c
SS
1381@cindex comment
1382Any text from a @kbd{#} to the end of the line is a comment; it does
1383nothing. This is useful mainly in command files (@pxref{Command
1384Files,,Command files}).
1385
88118b3a
TT
1386@cindex repeating command sequences
1387@kindex C-o @r{(operate-and-get-next)}
1388The @kbd{C-o} binding is useful for repeating a complex sequence of
1389commands. This command accepts the current line, like @kbd{RET}, and
1390then fetches the next line relative to the current line from the history
1391for editing.
1392
6d2ebf8b 1393@node Completion
c906108c
SS
1394@section Command completion
1395
1396@cindex completion
1397@cindex word completion
1398@value{GDBN} can fill in the rest of a word in a command for you, if there is
1399only one possibility; it can also show you what the valid possibilities
1400are for the next word in a command, at any time. This works for @value{GDBN}
1401commands, @value{GDBN} subcommands, and the names of symbols in your program.
1402
1403Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1404of a word. If there is only one possibility, @value{GDBN} fills in the
1405word, and waits for you to finish the command (or press @key{RET} to
1406enter it). For example, if you type
1407
1408@c FIXME "@key" does not distinguish its argument sufficiently to permit
1409@c complete accuracy in these examples; space introduced for clarity.
1410@c If texinfo enhancements make it unnecessary, it would be nice to
1411@c replace " @key" by "@key" in the following...
474c8240 1412@smallexample
c906108c 1413(@value{GDBP}) info bre @key{TAB}
474c8240 1414@end smallexample
c906108c
SS
1415
1416@noindent
1417@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1418the only @code{info} subcommand beginning with @samp{bre}:
1419
474c8240 1420@smallexample
c906108c 1421(@value{GDBP}) info breakpoints
474c8240 1422@end smallexample
c906108c
SS
1423
1424@noindent
1425You can either press @key{RET} at this point, to run the @code{info
1426breakpoints} command, or backspace and enter something else, if
1427@samp{breakpoints} does not look like the command you expected. (If you
1428were sure you wanted @code{info breakpoints} in the first place, you
1429might as well just type @key{RET} immediately after @samp{info bre},
1430to exploit command abbreviations rather than command completion).
1431
1432If there is more than one possibility for the next word when you press
1433@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1434characters and try again, or just press @key{TAB} a second time;
1435@value{GDBN} displays all the possible completions for that word. For
1436example, you might want to set a breakpoint on a subroutine whose name
1437begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1438just sounds the bell. Typing @key{TAB} again displays all the
1439function names in your program that begin with those characters, for
1440example:
1441
474c8240 1442@smallexample
c906108c
SS
1443(@value{GDBP}) b make_ @key{TAB}
1444@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1445make_a_section_from_file make_environ
1446make_abs_section make_function_type
1447make_blockvector make_pointer_type
1448make_cleanup make_reference_type
c906108c
SS
1449make_command make_symbol_completion_list
1450(@value{GDBP}) b make_
474c8240 1451@end smallexample
c906108c
SS
1452
1453@noindent
1454After displaying the available possibilities, @value{GDBN} copies your
1455partial input (@samp{b make_} in the example) so you can finish the
1456command.
1457
1458If you just want to see the list of alternatives in the first place, you
b37052ae 1459can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1460means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1461key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1462one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1463
1464@cindex quotes in commands
1465@cindex completion of quoted strings
1466Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1467parentheses or other characters that @value{GDBN} normally excludes from
1468its notion of a word. To permit word completion to work in this
1469situation, you may enclose words in @code{'} (single quote marks) in
1470@value{GDBN} commands.
c906108c 1471
c906108c 1472The most likely situation where you might need this is in typing the
b37052ae
EZ
1473name of a C@t{++} function. This is because C@t{++} allows function
1474overloading (multiple definitions of the same function, distinguished
1475by argument type). For example, when you want to set a breakpoint you
1476may need to distinguish whether you mean the version of @code{name}
1477that takes an @code{int} parameter, @code{name(int)}, or the version
1478that takes a @code{float} parameter, @code{name(float)}. To use the
1479word-completion facilities in this situation, type a single quote
1480@code{'} at the beginning of the function name. This alerts
1481@value{GDBN} that it may need to consider more information than usual
1482when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1483
474c8240 1484@smallexample
96a2c332 1485(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1486bubble(double,double) bubble(int,int)
1487(@value{GDBP}) b 'bubble(
474c8240 1488@end smallexample
c906108c
SS
1489
1490In some cases, @value{GDBN} can tell that completing a name requires using
1491quotes. When this happens, @value{GDBN} inserts the quote for you (while
1492completing as much as it can) if you do not type the quote in the first
1493place:
1494
474c8240 1495@smallexample
c906108c
SS
1496(@value{GDBP}) b bub @key{TAB}
1497@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1498(@value{GDBP}) b 'bubble(
474c8240 1499@end smallexample
c906108c
SS
1500
1501@noindent
1502In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1503you have not yet started typing the argument list when you ask for
1504completion on an overloaded symbol.
1505
d4f3574e 1506For more information about overloaded functions, see @ref{C plus plus
b37052ae 1507expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1508overload-resolution off} to disable overload resolution;
b37052ae 1509see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1510
1511
6d2ebf8b 1512@node Help
c906108c
SS
1513@section Getting help
1514@cindex online documentation
1515@kindex help
1516
5d161b24 1517You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1518using the command @code{help}.
1519
1520@table @code
41afff9a 1521@kindex h @r{(@code{help})}
c906108c
SS
1522@item help
1523@itemx h
1524You can use @code{help} (abbreviated @code{h}) with no arguments to
1525display a short list of named classes of commands:
1526
1527@smallexample
1528(@value{GDBP}) help
1529List of classes of commands:
1530
2df3850c 1531aliases -- Aliases of other commands
c906108c 1532breakpoints -- Making program stop at certain points
2df3850c 1533data -- Examining data
c906108c 1534files -- Specifying and examining files
2df3850c
JM
1535internals -- Maintenance commands
1536obscure -- Obscure features
1537running -- Running the program
1538stack -- Examining the stack
c906108c
SS
1539status -- Status inquiries
1540support -- Support facilities
96a2c332
SS
1541tracepoints -- Tracing of program execution without@*
1542 stopping the program
c906108c 1543user-defined -- User-defined commands
c906108c 1544
5d161b24 1545Type "help" followed by a class name for a list of
c906108c 1546commands in that class.
5d161b24 1547Type "help" followed by command name for full
c906108c
SS
1548documentation.
1549Command name abbreviations are allowed if unambiguous.
1550(@value{GDBP})
1551@end smallexample
96a2c332 1552@c the above line break eliminates huge line overfull...
c906108c
SS
1553
1554@item help @var{class}
1555Using one of the general help classes as an argument, you can get a
1556list of the individual commands in that class. For example, here is the
1557help display for the class @code{status}:
1558
1559@smallexample
1560(@value{GDBP}) help status
1561Status inquiries.
1562
1563List of commands:
1564
1565@c Line break in "show" line falsifies real output, but needed
1566@c to fit in smallbook page size.
2df3850c
JM
1567info -- Generic command for showing things
1568 about the program being debugged
1569show -- Generic command for showing things
1570 about the debugger
c906108c 1571
5d161b24 1572Type "help" followed by command name for full
c906108c
SS
1573documentation.
1574Command name abbreviations are allowed if unambiguous.
1575(@value{GDBP})
1576@end smallexample
1577
1578@item help @var{command}
1579With a command name as @code{help} argument, @value{GDBN} displays a
1580short paragraph on how to use that command.
1581
6837a0a2
DB
1582@kindex apropos
1583@item apropos @var{args}
09d4efe1 1584The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1585commands, and their documentation, for the regular expression specified in
1586@var{args}. It prints out all matches found. For example:
1587
1588@smallexample
1589apropos reload
1590@end smallexample
1591
b37052ae
EZ
1592@noindent
1593results in:
6837a0a2
DB
1594
1595@smallexample
6d2ebf8b
SS
1596@c @group
1597set symbol-reloading -- Set dynamic symbol table reloading
1598 multiple times in one run
1599show symbol-reloading -- Show dynamic symbol table reloading
1600 multiple times in one run
1601@c @end group
6837a0a2
DB
1602@end smallexample
1603
c906108c
SS
1604@kindex complete
1605@item complete @var{args}
1606The @code{complete @var{args}} command lists all the possible completions
1607for the beginning of a command. Use @var{args} to specify the beginning of the
1608command you want completed. For example:
1609
1610@smallexample
1611complete i
1612@end smallexample
1613
1614@noindent results in:
1615
1616@smallexample
1617@group
2df3850c
JM
1618if
1619ignore
c906108c
SS
1620info
1621inspect
c906108c
SS
1622@end group
1623@end smallexample
1624
1625@noindent This is intended for use by @sc{gnu} Emacs.
1626@end table
1627
1628In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1629and @code{show} to inquire about the state of your program, or the state
1630of @value{GDBN} itself. Each command supports many topics of inquiry; this
1631manual introduces each of them in the appropriate context. The listings
1632under @code{info} and under @code{show} in the Index point to
1633all the sub-commands. @xref{Index}.
1634
1635@c @group
1636@table @code
1637@kindex info
41afff9a 1638@kindex i @r{(@code{info})}
c906108c
SS
1639@item info
1640This command (abbreviated @code{i}) is for describing the state of your
1641program. For example, you can list the arguments given to your program
1642with @code{info args}, list the registers currently in use with @code{info
1643registers}, or list the breakpoints you have set with @code{info breakpoints}.
1644You can get a complete list of the @code{info} sub-commands with
1645@w{@code{help info}}.
1646
1647@kindex set
1648@item set
5d161b24 1649You can assign the result of an expression to an environment variable with
c906108c
SS
1650@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1651@code{set prompt $}.
1652
1653@kindex show
1654@item show
5d161b24 1655In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1656@value{GDBN} itself.
1657You can change most of the things you can @code{show}, by using the
1658related command @code{set}; for example, you can control what number
1659system is used for displays with @code{set radix}, or simply inquire
1660which is currently in use with @code{show radix}.
1661
1662@kindex info set
1663To display all the settable parameters and their current
1664values, you can use @code{show} with no arguments; you may also use
1665@code{info set}. Both commands produce the same display.
1666@c FIXME: "info set" violates the rule that "info" is for state of
1667@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1668@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1669@end table
1670@c @end group
1671
1672Here are three miscellaneous @code{show} subcommands, all of which are
1673exceptional in lacking corresponding @code{set} commands:
1674
1675@table @code
1676@kindex show version
9c16f35a 1677@cindex @value{GDBN} version number
c906108c
SS
1678@item show version
1679Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1680information in @value{GDBN} bug-reports. If multiple versions of
1681@value{GDBN} are in use at your site, you may need to determine which
1682version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1683commands are introduced, and old ones may wither away. Also, many
1684system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1685variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1686The version number is the same as the one announced when you start
1687@value{GDBN}.
c906108c
SS
1688
1689@kindex show copying
09d4efe1 1690@kindex info copying
9c16f35a 1691@cindex display @value{GDBN} copyright
c906108c 1692@item show copying
09d4efe1 1693@itemx info copying
c906108c
SS
1694Display information about permission for copying @value{GDBN}.
1695
1696@kindex show warranty
09d4efe1 1697@kindex info warranty
c906108c 1698@item show warranty
09d4efe1 1699@itemx info warranty
2df3850c 1700Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1701if your version of @value{GDBN} comes with one.
2df3850c 1702
c906108c
SS
1703@end table
1704
6d2ebf8b 1705@node Running
c906108c
SS
1706@chapter Running Programs Under @value{GDBN}
1707
1708When you run a program under @value{GDBN}, you must first generate
1709debugging information when you compile it.
7a292a7a
SS
1710
1711You may start @value{GDBN} with its arguments, if any, in an environment
1712of your choice. If you are doing native debugging, you may redirect
1713your program's input and output, debug an already running process, or
1714kill a child process.
c906108c
SS
1715
1716@menu
1717* Compilation:: Compiling for debugging
1718* Starting:: Starting your program
c906108c
SS
1719* Arguments:: Your program's arguments
1720* Environment:: Your program's environment
c906108c
SS
1721
1722* Working Directory:: Your program's working directory
1723* Input/Output:: Your program's input and output
1724* Attach:: Debugging an already-running process
1725* Kill Process:: Killing the child process
c906108c
SS
1726
1727* Threads:: Debugging programs with multiple threads
1728* Processes:: Debugging programs with multiple processes
1729@end menu
1730
6d2ebf8b 1731@node Compilation
c906108c
SS
1732@section Compiling for debugging
1733
1734In order to debug a program effectively, you need to generate
1735debugging information when you compile it. This debugging information
1736is stored in the object file; it describes the data type of each
1737variable or function and the correspondence between source line numbers
1738and addresses in the executable code.
1739
1740To request debugging information, specify the @samp{-g} option when you run
1741the compiler.
1742
514c4d71
EZ
1743Programs that are to be shipped to your customers are compiled with
1744optimizations, using the @samp{-O} compiler option. However, many
1745compilers are unable to handle the @samp{-g} and @samp{-O} options
1746together. Using those compilers, you cannot generate optimized
c906108c
SS
1747executables containing debugging information.
1748
514c4d71 1749@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1750without @samp{-O}, making it possible to debug optimized code. We
1751recommend that you @emph{always} use @samp{-g} whenever you compile a
1752program. You may think your program is correct, but there is no sense
1753in pushing your luck.
c906108c
SS
1754
1755@cindex optimized code, debugging
1756@cindex debugging optimized code
1757When you debug a program compiled with @samp{-g -O}, remember that the
1758optimizer is rearranging your code; the debugger shows you what is
1759really there. Do not be too surprised when the execution path does not
1760exactly match your source file! An extreme example: if you define a
1761variable, but never use it, @value{GDBN} never sees that
1762variable---because the compiler optimizes it out of existence.
1763
1764Some things do not work as well with @samp{-g -O} as with just
1765@samp{-g}, particularly on machines with instruction scheduling. If in
1766doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1767please report it to us as a bug (including a test case!).
15387254 1768@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1769
1770Older versions of the @sc{gnu} C compiler permitted a variant option
1771@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1772format; if your @sc{gnu} C compiler has this option, do not use it.
1773
514c4d71
EZ
1774@value{GDBN} knows about preprocessor macros and can show you their
1775expansion (@pxref{Macros}). Most compilers do not include information
1776about preprocessor macros in the debugging information if you specify
1777the @option{-g} flag alone, because this information is rather large.
1778Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1779provides macro information if you specify the options
1780@option{-gdwarf-2} and @option{-g3}; the former option requests
1781debugging information in the Dwarf 2 format, and the latter requests
1782``extra information''. In the future, we hope to find more compact
1783ways to represent macro information, so that it can be included with
1784@option{-g} alone.
1785
c906108c 1786@need 2000
6d2ebf8b 1787@node Starting
c906108c
SS
1788@section Starting your program
1789@cindex starting
1790@cindex running
1791
1792@table @code
1793@kindex run
41afff9a 1794@kindex r @r{(@code{run})}
c906108c
SS
1795@item run
1796@itemx r
7a292a7a
SS
1797Use the @code{run} command to start your program under @value{GDBN}.
1798You must first specify the program name (except on VxWorks) with an
1799argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1800@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1801(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1802
1803@end table
1804
c906108c
SS
1805If you are running your program in an execution environment that
1806supports processes, @code{run} creates an inferior process and makes
1807that process run your program. (In environments without processes,
1808@code{run} jumps to the start of your program.)
1809
1810The execution of a program is affected by certain information it
1811receives from its superior. @value{GDBN} provides ways to specify this
1812information, which you must do @emph{before} starting your program. (You
1813can change it after starting your program, but such changes only affect
1814your program the next time you start it.) This information may be
1815divided into four categories:
1816
1817@table @asis
1818@item The @emph{arguments.}
1819Specify the arguments to give your program as the arguments of the
1820@code{run} command. If a shell is available on your target, the shell
1821is used to pass the arguments, so that you may use normal conventions
1822(such as wildcard expansion or variable substitution) in describing
1823the arguments.
1824In Unix systems, you can control which shell is used with the
1825@code{SHELL} environment variable.
1826@xref{Arguments, ,Your program's arguments}.
1827
1828@item The @emph{environment.}
1829Your program normally inherits its environment from @value{GDBN}, but you can
1830use the @value{GDBN} commands @code{set environment} and @code{unset
1831environment} to change parts of the environment that affect
1832your program. @xref{Environment, ,Your program's environment}.
1833
1834@item The @emph{working directory.}
1835Your program inherits its working directory from @value{GDBN}. You can set
1836the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1837@xref{Working Directory, ,Your program's working directory}.
1838
1839@item The @emph{standard input and output.}
1840Your program normally uses the same device for standard input and
1841standard output as @value{GDBN} is using. You can redirect input and output
1842in the @code{run} command line, or you can use the @code{tty} command to
1843set a different device for your program.
1844@xref{Input/Output, ,Your program's input and output}.
1845
1846@cindex pipes
1847@emph{Warning:} While input and output redirection work, you cannot use
1848pipes to pass the output of the program you are debugging to another
1849program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1850wrong program.
1851@end table
c906108c
SS
1852
1853When you issue the @code{run} command, your program begins to execute
1854immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1855of how to arrange for your program to stop. Once your program has
1856stopped, you may call functions in your program, using the @code{print}
1857or @code{call} commands. @xref{Data, ,Examining Data}.
1858
1859If the modification time of your symbol file has changed since the last
1860time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1861table, and reads it again. When it does this, @value{GDBN} tries to retain
1862your current breakpoints.
1863
4e8b0763
JB
1864@table @code
1865@kindex start
1866@item start
1867@cindex run to main procedure
1868The name of the main procedure can vary from language to language.
1869With C or C@t{++}, the main procedure name is always @code{main}, but
1870other languages such as Ada do not require a specific name for their
1871main procedure. The debugger provides a convenient way to start the
1872execution of the program and to stop at the beginning of the main
1873procedure, depending on the language used.
1874
1875The @samp{start} command does the equivalent of setting a temporary
1876breakpoint at the beginning of the main procedure and then invoking
1877the @samp{run} command.
1878
f018e82f
EZ
1879@cindex elaboration phase
1880Some programs contain an @dfn{elaboration} phase where some startup code is
1881executed before the main procedure is called. This depends on the
1882languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1883constructors for static and global objects are executed before
1884@code{main} is called. It is therefore possible that the debugger stops
1885before reaching the main procedure. However, the temporary breakpoint
1886will remain to halt execution.
1887
1888Specify the arguments to give to your program as arguments to the
1889@samp{start} command. These arguments will be given verbatim to the
1890underlying @samp{run} command. Note that the same arguments will be
1891reused if no argument is provided during subsequent calls to
1892@samp{start} or @samp{run}.
1893
1894It is sometimes necessary to debug the program during elaboration. In
1895these cases, using the @code{start} command would stop the execution of
1896your program too late, as the program would have already completed the
1897elaboration phase. Under these circumstances, insert breakpoints in your
1898elaboration code before running your program.
1899@end table
1900
6d2ebf8b 1901@node Arguments
c906108c
SS
1902@section Your program's arguments
1903
1904@cindex arguments (to your program)
1905The arguments to your program can be specified by the arguments of the
5d161b24 1906@code{run} command.
c906108c
SS
1907They are passed to a shell, which expands wildcard characters and
1908performs redirection of I/O, and thence to your program. Your
1909@code{SHELL} environment variable (if it exists) specifies what shell
1910@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1911the default shell (@file{/bin/sh} on Unix).
1912
1913On non-Unix systems, the program is usually invoked directly by
1914@value{GDBN}, which emulates I/O redirection via the appropriate system
1915calls, and the wildcard characters are expanded by the startup code of
1916the program, not by the shell.
c906108c
SS
1917
1918@code{run} with no arguments uses the same arguments used by the previous
1919@code{run}, or those set by the @code{set args} command.
1920
c906108c 1921@table @code
41afff9a 1922@kindex set args
c906108c
SS
1923@item set args
1924Specify the arguments to be used the next time your program is run. If
1925@code{set args} has no arguments, @code{run} executes your program
1926with no arguments. Once you have run your program with arguments,
1927using @code{set args} before the next @code{run} is the only way to run
1928it again without arguments.
1929
1930@kindex show args
1931@item show args
1932Show the arguments to give your program when it is started.
1933@end table
1934
6d2ebf8b 1935@node Environment
c906108c
SS
1936@section Your program's environment
1937
1938@cindex environment (of your program)
1939The @dfn{environment} consists of a set of environment variables and
1940their values. Environment variables conventionally record such things as
1941your user name, your home directory, your terminal type, and your search
1942path for programs to run. Usually you set up environment variables with
1943the shell and they are inherited by all the other programs you run. When
1944debugging, it can be useful to try running your program with a modified
1945environment without having to start @value{GDBN} over again.
1946
1947@table @code
1948@kindex path
1949@item path @var{directory}
1950Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1951(the search path for executables) that will be passed to your program.
1952The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1953You may specify several directory names, separated by whitespace or by a
1954system-dependent separator character (@samp{:} on Unix, @samp{;} on
1955MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1956is moved to the front, so it is searched sooner.
c906108c
SS
1957
1958You can use the string @samp{$cwd} to refer to whatever is the current
1959working directory at the time @value{GDBN} searches the path. If you
1960use @samp{.} instead, it refers to the directory where you executed the
1961@code{path} command. @value{GDBN} replaces @samp{.} in the
1962@var{directory} argument (with the current path) before adding
1963@var{directory} to the search path.
1964@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1965@c document that, since repeating it would be a no-op.
1966
1967@kindex show paths
1968@item show paths
1969Display the list of search paths for executables (the @code{PATH}
1970environment variable).
1971
1972@kindex show environment
1973@item show environment @r{[}@var{varname}@r{]}
1974Print the value of environment variable @var{varname} to be given to
1975your program when it starts. If you do not supply @var{varname},
1976print the names and values of all environment variables to be given to
1977your program. You can abbreviate @code{environment} as @code{env}.
1978
1979@kindex set environment
53a5351d 1980@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1981Set environment variable @var{varname} to @var{value}. The value
1982changes for your program only, not for @value{GDBN} itself. @var{value} may
1983be any string; the values of environment variables are just strings, and
1984any interpretation is supplied by your program itself. The @var{value}
1985parameter is optional; if it is eliminated, the variable is set to a
1986null value.
1987@c "any string" here does not include leading, trailing
1988@c blanks. Gnu asks: does anyone care?
1989
1990For example, this command:
1991
474c8240 1992@smallexample
c906108c 1993set env USER = foo
474c8240 1994@end smallexample
c906108c
SS
1995
1996@noindent
d4f3574e 1997tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1998@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1999are not actually required.)
2000
2001@kindex unset environment
2002@item unset environment @var{varname}
2003Remove variable @var{varname} from the environment to be passed to your
2004program. This is different from @samp{set env @var{varname} =};
2005@code{unset environment} removes the variable from the environment,
2006rather than assigning it an empty value.
2007@end table
2008
d4f3574e
SS
2009@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2010the shell indicated
c906108c
SS
2011by your @code{SHELL} environment variable if it exists (or
2012@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2013that runs an initialization file---such as @file{.cshrc} for C-shell, or
2014@file{.bashrc} for BASH---any variables you set in that file affect
2015your program. You may wish to move setting of environment variables to
2016files that are only run when you sign on, such as @file{.login} or
2017@file{.profile}.
2018
6d2ebf8b 2019@node Working Directory
c906108c
SS
2020@section Your program's working directory
2021
2022@cindex working directory (of your program)
2023Each time you start your program with @code{run}, it inherits its
2024working directory from the current working directory of @value{GDBN}.
2025The @value{GDBN} working directory is initially whatever it inherited
2026from its parent process (typically the shell), but you can specify a new
2027working directory in @value{GDBN} with the @code{cd} command.
2028
2029The @value{GDBN} working directory also serves as a default for the commands
2030that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2031specify files}.
2032
2033@table @code
2034@kindex cd
721c2651 2035@cindex change working directory
c906108c
SS
2036@item cd @var{directory}
2037Set the @value{GDBN} working directory to @var{directory}.
2038
2039@kindex pwd
2040@item pwd
2041Print the @value{GDBN} working directory.
2042@end table
2043
60bf7e09
EZ
2044It is generally impossible to find the current working directory of
2045the process being debugged (since a program can change its directory
2046during its run). If you work on a system where @value{GDBN} is
2047configured with the @file{/proc} support, you can use the @code{info
2048proc} command (@pxref{SVR4 Process Information}) to find out the
2049current working directory of the debuggee.
2050
6d2ebf8b 2051@node Input/Output
c906108c
SS
2052@section Your program's input and output
2053
2054@cindex redirection
2055@cindex i/o
2056@cindex terminal
2057By default, the program you run under @value{GDBN} does input and output to
5d161b24 2058the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2059to its own terminal modes to interact with you, but it records the terminal
2060modes your program was using and switches back to them when you continue
2061running your program.
2062
2063@table @code
2064@kindex info terminal
2065@item info terminal
2066Displays information recorded by @value{GDBN} about the terminal modes your
2067program is using.
2068@end table
2069
2070You can redirect your program's input and/or output using shell
2071redirection with the @code{run} command. For example,
2072
474c8240 2073@smallexample
c906108c 2074run > outfile
474c8240 2075@end smallexample
c906108c
SS
2076
2077@noindent
2078starts your program, diverting its output to the file @file{outfile}.
2079
2080@kindex tty
2081@cindex controlling terminal
2082Another way to specify where your program should do input and output is
2083with the @code{tty} command. This command accepts a file name as
2084argument, and causes this file to be the default for future @code{run}
2085commands. It also resets the controlling terminal for the child
2086process, for future @code{run} commands. For example,
2087
474c8240 2088@smallexample
c906108c 2089tty /dev/ttyb
474c8240 2090@end smallexample
c906108c
SS
2091
2092@noindent
2093directs that processes started with subsequent @code{run} commands
2094default to do input and output on the terminal @file{/dev/ttyb} and have
2095that as their controlling terminal.
2096
2097An explicit redirection in @code{run} overrides the @code{tty} command's
2098effect on the input/output device, but not its effect on the controlling
2099terminal.
2100
2101When you use the @code{tty} command or redirect input in the @code{run}
2102command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2103for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2104for @code{set inferior-tty}.
2105
2106@cindex inferior tty
2107@cindex set inferior controlling terminal
2108You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2109display the name of the terminal that will be used for future runs of your
2110program.
2111
2112@table @code
2113@item set inferior-tty /dev/ttyb
2114@kindex set inferior-tty
2115Set the tty for the program being debugged to /dev/ttyb.
2116
2117@item show inferior-tty
2118@kindex show inferior-tty
2119Show the current tty for the program being debugged.
2120@end table
c906108c 2121
6d2ebf8b 2122@node Attach
c906108c
SS
2123@section Debugging an already-running process
2124@kindex attach
2125@cindex attach
2126
2127@table @code
2128@item attach @var{process-id}
2129This command attaches to a running process---one that was started
2130outside @value{GDBN}. (@code{info files} shows your active
2131targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2132find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2133or with the @samp{jobs -l} shell command.
2134
2135@code{attach} does not repeat if you press @key{RET} a second time after
2136executing the command.
2137@end table
2138
2139To use @code{attach}, your program must be running in an environment
2140which supports processes; for example, @code{attach} does not work for
2141programs on bare-board targets that lack an operating system. You must
2142also have permission to send the process a signal.
2143
2144When you use @code{attach}, the debugger finds the program running in
2145the process first by looking in the current working directory, then (if
2146the program is not found) by using the source file search path
2147(@pxref{Source Path, ,Specifying source directories}). You can also use
2148the @code{file} command to load the program. @xref{Files, ,Commands to
2149Specify Files}.
2150
2151The first thing @value{GDBN} does after arranging to debug the specified
2152process is to stop it. You can examine and modify an attached process
53a5351d
JM
2153with all the @value{GDBN} commands that are ordinarily available when
2154you start processes with @code{run}. You can insert breakpoints; you
2155can step and continue; you can modify storage. If you would rather the
2156process continue running, you may use the @code{continue} command after
c906108c
SS
2157attaching @value{GDBN} to the process.
2158
2159@table @code
2160@kindex detach
2161@item detach
2162When you have finished debugging the attached process, you can use the
2163@code{detach} command to release it from @value{GDBN} control. Detaching
2164the process continues its execution. After the @code{detach} command,
2165that process and @value{GDBN} become completely independent once more, and you
2166are ready to @code{attach} another process or start one with @code{run}.
2167@code{detach} does not repeat if you press @key{RET} again after
2168executing the command.
2169@end table
2170
2171If you exit @value{GDBN} or use the @code{run} command while you have an
2172attached process, you kill that process. By default, @value{GDBN} asks
2173for confirmation if you try to do either of these things; you can
2174control whether or not you need to confirm by using the @code{set
2175confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2176messages}).
2177
6d2ebf8b 2178@node Kill Process
c906108c 2179@section Killing the child process
c906108c
SS
2180
2181@table @code
2182@kindex kill
2183@item kill
2184Kill the child process in which your program is running under @value{GDBN}.
2185@end table
2186
2187This command is useful if you wish to debug a core dump instead of a
2188running process. @value{GDBN} ignores any core dump file while your program
2189is running.
2190
2191On some operating systems, a program cannot be executed outside @value{GDBN}
2192while you have breakpoints set on it inside @value{GDBN}. You can use the
2193@code{kill} command in this situation to permit running your program
2194outside the debugger.
2195
2196The @code{kill} command is also useful if you wish to recompile and
2197relink your program, since on many systems it is impossible to modify an
2198executable file while it is running in a process. In this case, when you
2199next type @code{run}, @value{GDBN} notices that the file has changed, and
2200reads the symbol table again (while trying to preserve your current
2201breakpoint settings).
2202
6d2ebf8b 2203@node Threads
c906108c 2204@section Debugging programs with multiple threads
c906108c
SS
2205
2206@cindex threads of execution
2207@cindex multiple threads
2208@cindex switching threads
2209In some operating systems, such as HP-UX and Solaris, a single program
2210may have more than one @dfn{thread} of execution. The precise semantics
2211of threads differ from one operating system to another, but in general
2212the threads of a single program are akin to multiple processes---except
2213that they share one address space (that is, they can all examine and
2214modify the same variables). On the other hand, each thread has its own
2215registers and execution stack, and perhaps private memory.
2216
2217@value{GDBN} provides these facilities for debugging multi-thread
2218programs:
2219
2220@itemize @bullet
2221@item automatic notification of new threads
2222@item @samp{thread @var{threadno}}, a command to switch among threads
2223@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2224@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2225a command to apply a command to a list of threads
2226@item thread-specific breakpoints
2227@end itemize
2228
c906108c
SS
2229@quotation
2230@emph{Warning:} These facilities are not yet available on every
2231@value{GDBN} configuration where the operating system supports threads.
2232If your @value{GDBN} does not support threads, these commands have no
2233effect. For example, a system without thread support shows no output
2234from @samp{info threads}, and always rejects the @code{thread} command,
2235like this:
2236
2237@smallexample
2238(@value{GDBP}) info threads
2239(@value{GDBP}) thread 1
2240Thread ID 1 not known. Use the "info threads" command to
2241see the IDs of currently known threads.
2242@end smallexample
2243@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2244@c doesn't support threads"?
2245@end quotation
c906108c
SS
2246
2247@cindex focus of debugging
2248@cindex current thread
2249The @value{GDBN} thread debugging facility allows you to observe all
2250threads while your program runs---but whenever @value{GDBN} takes
2251control, one thread in particular is always the focus of debugging.
2252This thread is called the @dfn{current thread}. Debugging commands show
2253program information from the perspective of the current thread.
2254
41afff9a 2255@cindex @code{New} @var{systag} message
c906108c
SS
2256@cindex thread identifier (system)
2257@c FIXME-implementors!! It would be more helpful if the [New...] message
2258@c included GDB's numeric thread handle, so you could just go to that
2259@c thread without first checking `info threads'.
2260Whenever @value{GDBN} detects a new thread in your program, it displays
2261the target system's identification for the thread with a message in the
2262form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2263whose form varies depending on the particular system. For example, on
2264LynxOS, you might see
2265
474c8240 2266@smallexample
c906108c 2267[New process 35 thread 27]
474c8240 2268@end smallexample
c906108c
SS
2269
2270@noindent
2271when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2272the @var{systag} is simply something like @samp{process 368}, with no
2273further qualifier.
2274
2275@c FIXME!! (1) Does the [New...] message appear even for the very first
2276@c thread of a program, or does it only appear for the
6ca652b0 2277@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2278@c program?
2279@c (2) *Is* there necessarily a first thread always? Or do some
2280@c multithread systems permit starting a program with multiple
5d161b24 2281@c threads ab initio?
c906108c
SS
2282
2283@cindex thread number
2284@cindex thread identifier (GDB)
2285For debugging purposes, @value{GDBN} associates its own thread
2286number---always a single integer---with each thread in your program.
2287
2288@table @code
2289@kindex info threads
2290@item info threads
2291Display a summary of all threads currently in your
2292program. @value{GDBN} displays for each thread (in this order):
2293
2294@enumerate
09d4efe1
EZ
2295@item
2296the thread number assigned by @value{GDBN}
c906108c 2297
09d4efe1
EZ
2298@item
2299the target system's thread identifier (@var{systag})
c906108c 2300
09d4efe1
EZ
2301@item
2302the current stack frame summary for that thread
c906108c
SS
2303@end enumerate
2304
2305@noindent
2306An asterisk @samp{*} to the left of the @value{GDBN} thread number
2307indicates the current thread.
2308
5d161b24 2309For example,
c906108c
SS
2310@end table
2311@c end table here to get a little more width for example
2312
2313@smallexample
2314(@value{GDBP}) info threads
2315 3 process 35 thread 27 0x34e5 in sigpause ()
2316 2 process 35 thread 23 0x34e5 in sigpause ()
2317* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2318 at threadtest.c:68
2319@end smallexample
53a5351d
JM
2320
2321On HP-UX systems:
c906108c 2322
4644b6e3
EZ
2323@cindex debugging multithreaded programs (on HP-UX)
2324@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2325For debugging purposes, @value{GDBN} associates its own thread
2326number---a small integer assigned in thread-creation order---with each
2327thread in your program.
2328
41afff9a
EZ
2329@cindex @code{New} @var{systag} message, on HP-UX
2330@cindex thread identifier (system), on HP-UX
c906108c
SS
2331@c FIXME-implementors!! It would be more helpful if the [New...] message
2332@c included GDB's numeric thread handle, so you could just go to that
2333@c thread without first checking `info threads'.
2334Whenever @value{GDBN} detects a new thread in your program, it displays
2335both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2336form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2337whose form varies depending on the particular system. For example, on
2338HP-UX, you see
2339
474c8240 2340@smallexample
c906108c 2341[New thread 2 (system thread 26594)]
474c8240 2342@end smallexample
c906108c
SS
2343
2344@noindent
5d161b24 2345when @value{GDBN} notices a new thread.
c906108c
SS
2346
2347@table @code
4644b6e3 2348@kindex info threads (HP-UX)
c906108c
SS
2349@item info threads
2350Display a summary of all threads currently in your
2351program. @value{GDBN} displays for each thread (in this order):
2352
2353@enumerate
2354@item the thread number assigned by @value{GDBN}
2355
2356@item the target system's thread identifier (@var{systag})
2357
2358@item the current stack frame summary for that thread
2359@end enumerate
2360
2361@noindent
2362An asterisk @samp{*} to the left of the @value{GDBN} thread number
2363indicates the current thread.
2364
5d161b24 2365For example,
c906108c
SS
2366@end table
2367@c end table here to get a little more width for example
2368
474c8240 2369@smallexample
c906108c 2370(@value{GDBP}) info threads
6d2ebf8b
SS
2371 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2372 at quicksort.c:137
2373 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2374 from /usr/lib/libc.2
2375 1 system thread 27905 0x7b003498 in _brk () \@*
2376 from /usr/lib/libc.2
474c8240 2377@end smallexample
c906108c 2378
c45da7e6
EZ
2379On Solaris, you can display more information about user threads with a
2380Solaris-specific command:
2381
2382@table @code
2383@item maint info sol-threads
2384@kindex maint info sol-threads
2385@cindex thread info (Solaris)
2386Display info on Solaris user threads.
2387@end table
2388
c906108c
SS
2389@table @code
2390@kindex thread @var{threadno}
2391@item thread @var{threadno}
2392Make thread number @var{threadno} the current thread. The command
2393argument @var{threadno} is the internal @value{GDBN} thread number, as
2394shown in the first field of the @samp{info threads} display.
2395@value{GDBN} responds by displaying the system identifier of the thread
2396you selected, and its current stack frame summary:
2397
2398@smallexample
2399@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2400(@value{GDBP}) thread 2
c906108c 2401[Switching to process 35 thread 23]
c906108c
SS
24020x34e5 in sigpause ()
2403@end smallexample
2404
2405@noindent
2406As with the @samp{[New @dots{}]} message, the form of the text after
2407@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2408threads.
c906108c 2409
9c16f35a 2410@kindex thread apply
638ac427 2411@cindex apply command to several threads
c906108c
SS
2412@item thread apply [@var{threadno}] [@var{all}] @var{args}
2413The @code{thread apply} command allows you to apply a command to one or
2414more threads. Specify the numbers of the threads that you want affected
2415with the command argument @var{threadno}. @var{threadno} is the internal
2416@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2417threads} display. To apply a command to all threads, use
2418@code{thread apply all} @var{args}.
c906108c
SS
2419@end table
2420
2421@cindex automatic thread selection
2422@cindex switching threads automatically
2423@cindex threads, automatic switching
2424Whenever @value{GDBN} stops your program, due to a breakpoint or a
2425signal, it automatically selects the thread where that breakpoint or
2426signal happened. @value{GDBN} alerts you to the context switch with a
2427message of the form @samp{[Switching to @var{systag}]} to identify the
2428thread.
2429
2430@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2431more information about how @value{GDBN} behaves when you stop and start
2432programs with multiple threads.
2433
2434@xref{Set Watchpoints,,Setting watchpoints}, for information about
2435watchpoints in programs with multiple threads.
c906108c 2436
6d2ebf8b 2437@node Processes
c906108c
SS
2438@section Debugging programs with multiple processes
2439
2440@cindex fork, debugging programs which call
2441@cindex multiple processes
2442@cindex processes, multiple
53a5351d
JM
2443On most systems, @value{GDBN} has no special support for debugging
2444programs which create additional processes using the @code{fork}
2445function. When a program forks, @value{GDBN} will continue to debug the
2446parent process and the child process will run unimpeded. If you have
2447set a breakpoint in any code which the child then executes, the child
2448will get a @code{SIGTRAP} signal which (unless it catches the signal)
2449will cause it to terminate.
c906108c
SS
2450
2451However, if you want to debug the child process there is a workaround
2452which isn't too painful. Put a call to @code{sleep} in the code which
2453the child process executes after the fork. It may be useful to sleep
2454only if a certain environment variable is set, or a certain file exists,
2455so that the delay need not occur when you don't want to run @value{GDBN}
2456on the child. While the child is sleeping, use the @code{ps} program to
2457get its process ID. Then tell @value{GDBN} (a new invocation of
2458@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2459the child process (@pxref{Attach}). From that point on you can debug
c906108c 2460the child process just like any other process which you attached to.
c906108c 2461
b51970ac
DJ
2462On some systems, @value{GDBN} provides support for debugging programs that
2463create additional processes using the @code{fork} or @code{vfork} functions.
2464Currently, the only platforms with this feature are HP-UX (11.x and later
2465only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2466
2467By default, when a program forks, @value{GDBN} will continue to debug
2468the parent process and the child process will run unimpeded.
2469
2470If you want to follow the child process instead of the parent process,
2471use the command @w{@code{set follow-fork-mode}}.
2472
2473@table @code
2474@kindex set follow-fork-mode
2475@item set follow-fork-mode @var{mode}
2476Set the debugger response to a program call of @code{fork} or
2477@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2478process. The @var{mode} argument can be:
c906108c
SS
2479
2480@table @code
2481@item parent
2482The original process is debugged after a fork. The child process runs
2df3850c 2483unimpeded. This is the default.
c906108c
SS
2484
2485@item child
2486The new process is debugged after a fork. The parent process runs
2487unimpeded.
2488
c906108c
SS
2489@end table
2490
9c16f35a 2491@kindex show follow-fork-mode
c906108c 2492@item show follow-fork-mode
2df3850c 2493Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2494@end table
2495
2496If you ask to debug a child process and a @code{vfork} is followed by an
2497@code{exec}, @value{GDBN} executes the new target up to the first
2498breakpoint in the new target. If you have a breakpoint set on
2499@code{main} in your original program, the breakpoint will also be set on
2500the child process's @code{main}.
2501
2502When a child process is spawned by @code{vfork}, you cannot debug the
2503child or parent until an @code{exec} call completes.
2504
2505If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2506call executes, the new target restarts. To restart the parent process,
2507use the @code{file} command with the parent executable name as its
2508argument.
2509
2510You can use the @code{catch} command to make @value{GDBN} stop whenever
2511a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2512Catchpoints, ,Setting catchpoints}.
c906108c 2513
6d2ebf8b 2514@node Stopping
c906108c
SS
2515@chapter Stopping and Continuing
2516
2517The principal purposes of using a debugger are so that you can stop your
2518program before it terminates; or so that, if your program runs into
2519trouble, you can investigate and find out why.
2520
7a292a7a
SS
2521Inside @value{GDBN}, your program may stop for any of several reasons,
2522such as a signal, a breakpoint, or reaching a new line after a
2523@value{GDBN} command such as @code{step}. You may then examine and
2524change variables, set new breakpoints or remove old ones, and then
2525continue execution. Usually, the messages shown by @value{GDBN} provide
2526ample explanation of the status of your program---but you can also
2527explicitly request this information at any time.
c906108c
SS
2528
2529@table @code
2530@kindex info program
2531@item info program
2532Display information about the status of your program: whether it is
7a292a7a 2533running or not, what process it is, and why it stopped.
c906108c
SS
2534@end table
2535
2536@menu
2537* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2538* Continuing and Stepping:: Resuming execution
c906108c 2539* Signals:: Signals
c906108c 2540* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2541@end menu
2542
6d2ebf8b 2543@node Breakpoints
c906108c
SS
2544@section Breakpoints, watchpoints, and catchpoints
2545
2546@cindex breakpoints
2547A @dfn{breakpoint} makes your program stop whenever a certain point in
2548the program is reached. For each breakpoint, you can add conditions to
2549control in finer detail whether your program stops. You can set
2550breakpoints with the @code{break} command and its variants (@pxref{Set
2551Breaks, ,Setting breakpoints}), to specify the place where your program
2552should stop by line number, function name or exact address in the
2553program.
2554
09d4efe1
EZ
2555On some systems, you can set breakpoints in shared libraries before
2556the executable is run. There is a minor limitation on HP-UX systems:
2557you must wait until the executable is run in order to set breakpoints
2558in shared library routines that are not called directly by the program
2559(for example, routines that are arguments in a @code{pthread_create}
2560call).
c906108c
SS
2561
2562@cindex watchpoints
2563@cindex memory tracing
2564@cindex breakpoint on memory address
2565@cindex breakpoint on variable modification
2566A @dfn{watchpoint} is a special breakpoint that stops your program
2567when the value of an expression changes. You must use a different
2568command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2569watchpoints}), but aside from that, you can manage a watchpoint like
2570any other breakpoint: you enable, disable, and delete both breakpoints
2571and watchpoints using the same commands.
2572
2573You can arrange to have values from your program displayed automatically
2574whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2575Automatic display}.
2576
2577@cindex catchpoints
2578@cindex breakpoint on events
2579A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2580when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2581exception or the loading of a library. As with watchpoints, you use a
2582different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2583catchpoints}), but aside from that, you can manage a catchpoint like any
2584other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2585@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2586
2587@cindex breakpoint numbers
2588@cindex numbers for breakpoints
2589@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2590catchpoint when you create it; these numbers are successive integers
2591starting with one. In many of the commands for controlling various
2592features of breakpoints you use the breakpoint number to say which
2593breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2594@dfn{disabled}; if disabled, it has no effect on your program until you
2595enable it again.
2596
c5394b80
JM
2597@cindex breakpoint ranges
2598@cindex ranges of breakpoints
2599Some @value{GDBN} commands accept a range of breakpoints on which to
2600operate. A breakpoint range is either a single breakpoint number, like
2601@samp{5}, or two such numbers, in increasing order, separated by a
2602hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2603all breakpoint in that range are operated on.
2604
c906108c
SS
2605@menu
2606* Set Breaks:: Setting breakpoints
2607* Set Watchpoints:: Setting watchpoints
2608* Set Catchpoints:: Setting catchpoints
2609* Delete Breaks:: Deleting breakpoints
2610* Disabling:: Disabling breakpoints
2611* Conditions:: Break conditions
2612* Break Commands:: Breakpoint command lists
c906108c 2613* Breakpoint Menus:: Breakpoint menus
d4f3574e 2614* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2615* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2616@end menu
2617
6d2ebf8b 2618@node Set Breaks
c906108c
SS
2619@subsection Setting breakpoints
2620
5d161b24 2621@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2622@c consider in particular declaration with/without initialization.
2623@c
2624@c FIXME 2 is there stuff on this already? break at fun start, already init?
2625
2626@kindex break
41afff9a
EZ
2627@kindex b @r{(@code{break})}
2628@vindex $bpnum@r{, convenience variable}
c906108c
SS
2629@cindex latest breakpoint
2630Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2631@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2632number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2633Vars,, Convenience variables}, for a discussion of what you can do with
2634convenience variables.
2635
2636You have several ways to say where the breakpoint should go.
2637
2638@table @code
2639@item break @var{function}
5d161b24 2640Set a breakpoint at entry to function @var{function}.
c906108c 2641When using source languages that permit overloading of symbols, such as
b37052ae 2642C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2643@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2644
2645@item break +@var{offset}
2646@itemx break -@var{offset}
2647Set a breakpoint some number of lines forward or back from the position
d4f3574e 2648at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2649(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2650
2651@item break @var{linenum}
2652Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2653The current source file is the last file whose source text was printed.
2654The breakpoint will stop your program just before it executes any of the
c906108c
SS
2655code on that line.
2656
2657@item break @var{filename}:@var{linenum}
2658Set a breakpoint at line @var{linenum} in source file @var{filename}.
2659
2660@item break @var{filename}:@var{function}
2661Set a breakpoint at entry to function @var{function} found in file
2662@var{filename}. Specifying a file name as well as a function name is
2663superfluous except when multiple files contain similarly named
2664functions.
2665
2666@item break *@var{address}
2667Set a breakpoint at address @var{address}. You can use this to set
2668breakpoints in parts of your program which do not have debugging
2669information or source files.
2670
2671@item break
2672When called without any arguments, @code{break} sets a breakpoint at
2673the next instruction to be executed in the selected stack frame
2674(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2675innermost, this makes your program stop as soon as control
2676returns to that frame. This is similar to the effect of a
2677@code{finish} command in the frame inside the selected frame---except
2678that @code{finish} does not leave an active breakpoint. If you use
2679@code{break} without an argument in the innermost frame, @value{GDBN} stops
2680the next time it reaches the current location; this may be useful
2681inside loops.
2682
2683@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2684least one instruction has been executed. If it did not do this, you
2685would be unable to proceed past a breakpoint without first disabling the
2686breakpoint. This rule applies whether or not the breakpoint already
2687existed when your program stopped.
2688
2689@item break @dots{} if @var{cond}
2690Set a breakpoint with condition @var{cond}; evaluate the expression
2691@var{cond} each time the breakpoint is reached, and stop only if the
2692value is nonzero---that is, if @var{cond} evaluates as true.
2693@samp{@dots{}} stands for one of the possible arguments described
2694above (or no argument) specifying where to break. @xref{Conditions,
2695,Break conditions}, for more information on breakpoint conditions.
2696
2697@kindex tbreak
2698@item tbreak @var{args}
2699Set a breakpoint enabled only for one stop. @var{args} are the
2700same as for the @code{break} command, and the breakpoint is set in the same
2701way, but the breakpoint is automatically deleted after the first time your
2702program stops there. @xref{Disabling, ,Disabling breakpoints}.
2703
c906108c 2704@kindex hbreak
ba04e063 2705@cindex hardware breakpoints
c906108c 2706@item hbreak @var{args}
d4f3574e
SS
2707Set a hardware-assisted breakpoint. @var{args} are the same as for the
2708@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2709breakpoint requires hardware support and some target hardware may not
2710have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2711debugging, so you can set a breakpoint at an instruction without
2712changing the instruction. This can be used with the new trap-generation
09d4efe1 2713provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2714will generate traps when a program accesses some data or instruction
2715address that is assigned to the debug registers. However the hardware
2716breakpoint registers can take a limited number of breakpoints. For
2717example, on the DSU, only two data breakpoints can be set at a time, and
2718@value{GDBN} will reject this command if more than two are used. Delete
2719or disable unused hardware breakpoints before setting new ones
2720(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2721For remote targets, you can restrict the number of hardware
2722breakpoints @value{GDBN} will use, see @ref{set remote
2723hardware-breakpoint-limit}.
501eef12 2724
c906108c
SS
2725
2726@kindex thbreak
2727@item thbreak @var{args}
2728Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2729are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2730the same way. However, like the @code{tbreak} command,
c906108c
SS
2731the breakpoint is automatically deleted after the
2732first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2733command, the breakpoint requires hardware support and some target hardware
2734may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2735See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2736
2737@kindex rbreak
2738@cindex regular expression
c45da7e6
EZ
2739@cindex breakpoints in functions matching a regexp
2740@cindex set breakpoints in many functions
c906108c 2741@item rbreak @var{regex}
c906108c 2742Set breakpoints on all functions matching the regular expression
11cf8741
JM
2743@var{regex}. This command sets an unconditional breakpoint on all
2744matches, printing a list of all breakpoints it set. Once these
2745breakpoints are set, they are treated just like the breakpoints set with
2746the @code{break} command. You can delete them, disable them, or make
2747them conditional the same way as any other breakpoint.
2748
2749The syntax of the regular expression is the standard one used with tools
2750like @file{grep}. Note that this is different from the syntax used by
2751shells, so for instance @code{foo*} matches all functions that include
2752an @code{fo} followed by zero or more @code{o}s. There is an implicit
2753@code{.*} leading and trailing the regular expression you supply, so to
2754match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2755
f7dc1244 2756@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2757When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2758breakpoints on overloaded functions that are not members of any special
2759classes.
c906108c 2760
f7dc1244
EZ
2761@cindex set breakpoints on all functions
2762The @code{rbreak} command can be used to set breakpoints in
2763@strong{all} the functions in a program, like this:
2764
2765@smallexample
2766(@value{GDBP}) rbreak .
2767@end smallexample
2768
c906108c
SS
2769@kindex info breakpoints
2770@cindex @code{$_} and @code{info breakpoints}
2771@item info breakpoints @r{[}@var{n}@r{]}
2772@itemx info break @r{[}@var{n}@r{]}
2773@itemx info watchpoints @r{[}@var{n}@r{]}
2774Print a table of all breakpoints, watchpoints, and catchpoints set and
2775not deleted, with the following columns for each breakpoint:
2776
2777@table @emph
2778@item Breakpoint Numbers
2779@item Type
2780Breakpoint, watchpoint, or catchpoint.
2781@item Disposition
2782Whether the breakpoint is marked to be disabled or deleted when hit.
2783@item Enabled or Disabled
2784Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2785that are not enabled.
2786@item Address
2650777c
JJ
2787Where the breakpoint is in your program, as a memory address. If the
2788breakpoint is pending (see below for details) on a future load of a shared library, the address
2789will be listed as @samp{<PENDING>}.
c906108c
SS
2790@item What
2791Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2792line number. For a pending breakpoint, the original string passed to
2793the breakpoint command will be listed as it cannot be resolved until
2794the appropriate shared library is loaded in the future.
c906108c
SS
2795@end table
2796
2797@noindent
2798If a breakpoint is conditional, @code{info break} shows the condition on
2799the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2800are listed after that. A pending breakpoint is allowed to have a condition
2801specified for it. The condition is not parsed for validity until a shared
2802library is loaded that allows the pending breakpoint to resolve to a
2803valid location.
c906108c
SS
2804
2805@noindent
2806@code{info break} with a breakpoint
2807number @var{n} as argument lists only that breakpoint. The
2808convenience variable @code{$_} and the default examining-address for
2809the @code{x} command are set to the address of the last breakpoint
5d161b24 2810listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2811
2812@noindent
2813@code{info break} displays a count of the number of times the breakpoint
2814has been hit. This is especially useful in conjunction with the
2815@code{ignore} command. You can ignore a large number of breakpoint
2816hits, look at the breakpoint info to see how many times the breakpoint
2817was hit, and then run again, ignoring one less than that number. This
2818will get you quickly to the last hit of that breakpoint.
2819@end table
2820
2821@value{GDBN} allows you to set any number of breakpoints at the same place in
2822your program. There is nothing silly or meaningless about this. When
2823the breakpoints are conditional, this is even useful
2824(@pxref{Conditions, ,Break conditions}).
2825
2650777c 2826@cindex pending breakpoints
dd79a6cf
JJ
2827If a specified breakpoint location cannot be found, it may be due to the fact
2828that the location is in a shared library that is yet to be loaded. In such
2829a case, you may want @value{GDBN} to create a special breakpoint (known as
2830a @dfn{pending breakpoint}) that
2831attempts to resolve itself in the future when an appropriate shared library
2832gets loaded.
2833
2834Pending breakpoints are useful to set at the start of your
2650777c
JJ
2835@value{GDBN} session for locations that you know will be dynamically loaded
2836later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2837a check is made to see if the load resolves any pending breakpoint locations.
2838If a pending breakpoint location gets resolved,
2839a regular breakpoint is created and the original pending breakpoint is removed.
2840
2841@value{GDBN} provides some additional commands for controlling pending
2842breakpoint support:
2843
2844@kindex set breakpoint pending
2845@kindex show breakpoint pending
2846@table @code
2847@item set breakpoint pending auto
2848This is the default behavior. When @value{GDBN} cannot find the breakpoint
2849location, it queries you whether a pending breakpoint should be created.
2850
2851@item set breakpoint pending on
2852This indicates that an unrecognized breakpoint location should automatically
2853result in a pending breakpoint being created.
2854
2855@item set breakpoint pending off
2856This indicates that pending breakpoints are not to be created. Any
2857unrecognized breakpoint location results in an error. This setting does
2858not affect any pending breakpoints previously created.
2859
2860@item show breakpoint pending
2861Show the current behavior setting for creating pending breakpoints.
2862@end table
2650777c 2863
649e03f6
RM
2864@cindex operations allowed on pending breakpoints
2865Normal breakpoint operations apply to pending breakpoints as well. You may
2866specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2867breakpoint is reached. You can also enable or disable
2868the pending breakpoint. When you specify a condition for a pending breakpoint,
2869the parsing of the condition will be deferred until the point where the
2870pending breakpoint location is resolved. Disabling a pending breakpoint
2871tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2872shared library load. When a pending breakpoint is re-enabled,
649e03f6 2873@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2874This is done because any number of shared library loads could have
2875occurred since the time the breakpoint was disabled and one or more
2876of these loads could resolve the location.
2877
c906108c
SS
2878@cindex negative breakpoint numbers
2879@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2880@value{GDBN} itself sometimes sets breakpoints in your program for
2881special purposes, such as proper handling of @code{longjmp} (in C
2882programs). These internal breakpoints are assigned negative numbers,
2883starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2884You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2885@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2886
2887
6d2ebf8b 2888@node Set Watchpoints
c906108c
SS
2889@subsection Setting watchpoints
2890
2891@cindex setting watchpoints
c906108c
SS
2892You can use a watchpoint to stop execution whenever the value of an
2893expression changes, without having to predict a particular place where
2894this may happen.
2895
82f2d802
EZ
2896@cindex software watchpoints
2897@cindex hardware watchpoints
c906108c 2898Depending on your system, watchpoints may be implemented in software or
2df3850c 2899hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2900program and testing the variable's value each time, which is hundreds of
2901times slower than normal execution. (But this may still be worth it, to
2902catch errors where you have no clue what part of your program is the
2903culprit.)
2904
82f2d802
EZ
2905On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2906x86-based targets, @value{GDBN} includes support for hardware
2907watchpoints, which do not slow down the running of your program.
c906108c
SS
2908
2909@table @code
2910@kindex watch
2911@item watch @var{expr}
2912Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2913is written into by the program and its value changes.
2914
2915@kindex rwatch
2916@item rwatch @var{expr}
09d4efe1
EZ
2917Set a watchpoint that will break when the value of @var{expr} is read
2918by the program.
c906108c
SS
2919
2920@kindex awatch
2921@item awatch @var{expr}
09d4efe1
EZ
2922Set a watchpoint that will break when @var{expr} is either read from
2923or written into by the program.
c906108c
SS
2924
2925@kindex info watchpoints
2926@item info watchpoints
2927This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2928it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2929@end table
2930
2931@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2932watchpoints execute very quickly, and the debugger reports a change in
2933value at the exact instruction where the change occurs. If @value{GDBN}
2934cannot set a hardware watchpoint, it sets a software watchpoint, which
2935executes more slowly and reports the change in value at the next
82f2d802
EZ
2936@emph{statement}, not the instruction, after the change occurs.
2937
82f2d802
EZ
2938@cindex use only software watchpoints
2939You can force @value{GDBN} to use only software watchpoints with the
2940@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2941zero, @value{GDBN} will never try to use hardware watchpoints, even if
2942the underlying system supports them. (Note that hardware-assisted
2943watchpoints that were set @emph{before} setting
2944@code{can-use-hw-watchpoints} to zero will still use the hardware
2945mechanism of watching expressiion values.)
c906108c 2946
9c16f35a
EZ
2947@table @code
2948@item set can-use-hw-watchpoints
2949@kindex set can-use-hw-watchpoints
2950Set whether or not to use hardware watchpoints.
2951
2952@item show can-use-hw-watchpoints
2953@kindex show can-use-hw-watchpoints
2954Show the current mode of using hardware watchpoints.
2955@end table
2956
2957For remote targets, you can restrict the number of hardware
2958watchpoints @value{GDBN} will use, see @ref{set remote
2959hardware-breakpoint-limit}.
2960
c906108c
SS
2961When you issue the @code{watch} command, @value{GDBN} reports
2962
474c8240 2963@smallexample
c906108c 2964Hardware watchpoint @var{num}: @var{expr}
474c8240 2965@end smallexample
c906108c
SS
2966
2967@noindent
2968if it was able to set a hardware watchpoint.
2969
7be570e7
JM
2970Currently, the @code{awatch} and @code{rwatch} commands can only set
2971hardware watchpoints, because accesses to data that don't change the
2972value of the watched expression cannot be detected without examining
2973every instruction as it is being executed, and @value{GDBN} does not do
2974that currently. If @value{GDBN} finds that it is unable to set a
2975hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2976will print a message like this:
2977
2978@smallexample
2979Expression cannot be implemented with read/access watchpoint.
2980@end smallexample
2981
2982Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2983data type of the watched expression is wider than what a hardware
2984watchpoint on the target machine can handle. For example, some systems
2985can only watch regions that are up to 4 bytes wide; on such systems you
2986cannot set hardware watchpoints for an expression that yields a
2987double-precision floating-point number (which is typically 8 bytes
2988wide). As a work-around, it might be possible to break the large region
2989into a series of smaller ones and watch them with separate watchpoints.
2990
2991If you set too many hardware watchpoints, @value{GDBN} might be unable
2992to insert all of them when you resume the execution of your program.
2993Since the precise number of active watchpoints is unknown until such
2994time as the program is about to be resumed, @value{GDBN} might not be
2995able to warn you about this when you set the watchpoints, and the
2996warning will be printed only when the program is resumed:
2997
2998@smallexample
2999Hardware watchpoint @var{num}: Could not insert watchpoint
3000@end smallexample
3001
3002@noindent
3003If this happens, delete or disable some of the watchpoints.
3004
3005The SPARClite DSU will generate traps when a program accesses some data
3006or instruction address that is assigned to the debug registers. For the
3007data addresses, DSU facilitates the @code{watch} command. However the
3008hardware breakpoint registers can only take two data watchpoints, and
3009both watchpoints must be the same kind. For example, you can set two
3010watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3011@strong{or} two with @code{awatch} commands, but you cannot set one
3012watchpoint with one command and the other with a different command.
c906108c
SS
3013@value{GDBN} will reject the command if you try to mix watchpoints.
3014Delete or disable unused watchpoint commands before setting new ones.
3015
3016If you call a function interactively using @code{print} or @code{call},
2df3850c 3017any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
3018kind of breakpoint or the call completes.
3019
7be570e7
JM
3020@value{GDBN} automatically deletes watchpoints that watch local
3021(automatic) variables, or expressions that involve such variables, when
3022they go out of scope, that is, when the execution leaves the block in
3023which these variables were defined. In particular, when the program
3024being debugged terminates, @emph{all} local variables go out of scope,
3025and so only watchpoints that watch global variables remain set. If you
3026rerun the program, you will need to set all such watchpoints again. One
3027way of doing that would be to set a code breakpoint at the entry to the
3028@code{main} function and when it breaks, set all the watchpoints.
3029
c906108c
SS
3030@quotation
3031@cindex watchpoints and threads
3032@cindex threads and watchpoints
c906108c
SS
3033@emph{Warning:} In multi-thread programs, watchpoints have only limited
3034usefulness. With the current watchpoint implementation, @value{GDBN}
3035can only watch the value of an expression @emph{in a single thread}. If
3036you are confident that the expression can only change due to the current
3037thread's activity (and if you are also confident that no other thread
3038can become current), then you can use watchpoints as usual. However,
3039@value{GDBN} may not notice when a non-current thread's activity changes
3040the expression.
53a5351d 3041
d4f3574e 3042@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3043@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3044have only limited usefulness. If @value{GDBN} creates a software
3045watchpoint, it can only watch the value of an expression @emph{in a
3046single thread}. If you are confident that the expression can only
3047change due to the current thread's activity (and if you are also
3048confident that no other thread can become current), then you can use
3049software watchpoints as usual. However, @value{GDBN} may not notice
3050when a non-current thread's activity changes the expression. (Hardware
3051watchpoints, in contrast, watch an expression in all threads.)
c906108c 3052@end quotation
c906108c 3053
501eef12
AC
3054@xref{set remote hardware-watchpoint-limit}.
3055
6d2ebf8b 3056@node Set Catchpoints
c906108c 3057@subsection Setting catchpoints
d4f3574e 3058@cindex catchpoints, setting
c906108c
SS
3059@cindex exception handlers
3060@cindex event handling
3061
3062You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3063kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3064shared library. Use the @code{catch} command to set a catchpoint.
3065
3066@table @code
3067@kindex catch
3068@item catch @var{event}
3069Stop when @var{event} occurs. @var{event} can be any of the following:
3070@table @code
3071@item throw
4644b6e3 3072@cindex stop on C@t{++} exceptions
b37052ae 3073The throwing of a C@t{++} exception.
c906108c
SS
3074
3075@item catch
b37052ae 3076The catching of a C@t{++} exception.
c906108c
SS
3077
3078@item exec
4644b6e3 3079@cindex break on fork/exec
c906108c
SS
3080A call to @code{exec}. This is currently only available for HP-UX.
3081
3082@item fork
c906108c
SS
3083A call to @code{fork}. This is currently only available for HP-UX.
3084
3085@item vfork
c906108c
SS
3086A call to @code{vfork}. This is currently only available for HP-UX.
3087
3088@item load
3089@itemx load @var{libname}
4644b6e3 3090@cindex break on load/unload of shared library
c906108c
SS
3091The dynamic loading of any shared library, or the loading of the library
3092@var{libname}. This is currently only available for HP-UX.
3093
3094@item unload
3095@itemx unload @var{libname}
c906108c
SS
3096The unloading of any dynamically loaded shared library, or the unloading
3097of the library @var{libname}. This is currently only available for HP-UX.
3098@end table
3099
3100@item tcatch @var{event}
3101Set a catchpoint that is enabled only for one stop. The catchpoint is
3102automatically deleted after the first time the event is caught.
3103
3104@end table
3105
3106Use the @code{info break} command to list the current catchpoints.
3107
b37052ae 3108There are currently some limitations to C@t{++} exception handling
c906108c
SS
3109(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3110
3111@itemize @bullet
3112@item
3113If you call a function interactively, @value{GDBN} normally returns
3114control to you when the function has finished executing. If the call
3115raises an exception, however, the call may bypass the mechanism that
3116returns control to you and cause your program either to abort or to
3117simply continue running until it hits a breakpoint, catches a signal
3118that @value{GDBN} is listening for, or exits. This is the case even if
3119you set a catchpoint for the exception; catchpoints on exceptions are
3120disabled within interactive calls.
3121
3122@item
3123You cannot raise an exception interactively.
3124
3125@item
3126You cannot install an exception handler interactively.
3127@end itemize
3128
3129@cindex raise exceptions
3130Sometimes @code{catch} is not the best way to debug exception handling:
3131if you need to know exactly where an exception is raised, it is better to
3132stop @emph{before} the exception handler is called, since that way you
3133can see the stack before any unwinding takes place. If you set a
3134breakpoint in an exception handler instead, it may not be easy to find
3135out where the exception was raised.
3136
3137To stop just before an exception handler is called, you need some
b37052ae 3138knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3139raised by calling a library function named @code{__raise_exception}
3140which has the following ANSI C interface:
3141
474c8240 3142@smallexample
c906108c 3143 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3144 @var{id} is the exception identifier. */
3145 void __raise_exception (void **addr, void *id);
474c8240 3146@end smallexample
c906108c
SS
3147
3148@noindent
3149To make the debugger catch all exceptions before any stack
3150unwinding takes place, set a breakpoint on @code{__raise_exception}
3151(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3152
3153With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3154that depends on the value of @var{id}, you can stop your program when
3155a specific exception is raised. You can use multiple conditional
3156breakpoints to stop your program when any of a number of exceptions are
3157raised.
3158
3159
6d2ebf8b 3160@node Delete Breaks
c906108c
SS
3161@subsection Deleting breakpoints
3162
3163@cindex clearing breakpoints, watchpoints, catchpoints
3164@cindex deleting breakpoints, watchpoints, catchpoints
3165It is often necessary to eliminate a breakpoint, watchpoint, or
3166catchpoint once it has done its job and you no longer want your program
3167to stop there. This is called @dfn{deleting} the breakpoint. A
3168breakpoint that has been deleted no longer exists; it is forgotten.
3169
3170With the @code{clear} command you can delete breakpoints according to
3171where they are in your program. With the @code{delete} command you can
3172delete individual breakpoints, watchpoints, or catchpoints by specifying
3173their breakpoint numbers.
3174
3175It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3176automatically ignores breakpoints on the first instruction to be executed
3177when you continue execution without changing the execution address.
3178
3179@table @code
3180@kindex clear
3181@item clear
3182Delete any breakpoints at the next instruction to be executed in the
3183selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3184the innermost frame is selected, this is a good way to delete a
3185breakpoint where your program just stopped.
3186
3187@item clear @var{function}
3188@itemx clear @var{filename}:@var{function}
09d4efe1 3189Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3190
3191@item clear @var{linenum}
3192@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3193Delete any breakpoints set at or within the code of the specified
3194@var{linenum} of the specified @var{filename}.
c906108c
SS
3195
3196@cindex delete breakpoints
3197@kindex delete
41afff9a 3198@kindex d @r{(@code{delete})}
c5394b80
JM
3199@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3200Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3201ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3202breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3203confirm off}). You can abbreviate this command as @code{d}.
3204@end table
3205
6d2ebf8b 3206@node Disabling
c906108c
SS
3207@subsection Disabling breakpoints
3208
4644b6e3 3209@cindex enable/disable a breakpoint
c906108c
SS
3210Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3211prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3212it had been deleted, but remembers the information on the breakpoint so
3213that you can @dfn{enable} it again later.
3214
3215You disable and enable breakpoints, watchpoints, and catchpoints with
3216the @code{enable} and @code{disable} commands, optionally specifying one
3217or more breakpoint numbers as arguments. Use @code{info break} or
3218@code{info watch} to print a list of breakpoints, watchpoints, and
3219catchpoints if you do not know which numbers to use.
3220
3221A breakpoint, watchpoint, or catchpoint can have any of four different
3222states of enablement:
3223
3224@itemize @bullet
3225@item
3226Enabled. The breakpoint stops your program. A breakpoint set
3227with the @code{break} command starts out in this state.
3228@item
3229Disabled. The breakpoint has no effect on your program.
3230@item
3231Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3232disabled.
c906108c
SS
3233@item
3234Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3235immediately after it does so it is deleted permanently. A breakpoint
3236set with the @code{tbreak} command starts out in this state.
c906108c
SS
3237@end itemize
3238
3239You can use the following commands to enable or disable breakpoints,
3240watchpoints, and catchpoints:
3241
3242@table @code
c906108c 3243@kindex disable
41afff9a 3244@kindex dis @r{(@code{disable})}
c5394b80 3245@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3246Disable the specified breakpoints---or all breakpoints, if none are
3247listed. A disabled breakpoint has no effect but is not forgotten. All
3248options such as ignore-counts, conditions and commands are remembered in
3249case the breakpoint is enabled again later. You may abbreviate
3250@code{disable} as @code{dis}.
3251
c906108c 3252@kindex enable
c5394b80 3253@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3254Enable the specified breakpoints (or all defined breakpoints). They
3255become effective once again in stopping your program.
3256
c5394b80 3257@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3258Enable the specified breakpoints temporarily. @value{GDBN} disables any
3259of these breakpoints immediately after stopping your program.
3260
c5394b80 3261@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3262Enable the specified breakpoints to work once, then die. @value{GDBN}
3263deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3264Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3265@end table
3266
d4f3574e
SS
3267@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3268@c confusing: tbreak is also initially enabled.
c906108c
SS
3269Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3270,Setting breakpoints}), breakpoints that you set are initially enabled;
3271subsequently, they become disabled or enabled only when you use one of
3272the commands above. (The command @code{until} can set and delete a
3273breakpoint of its own, but it does not change the state of your other
3274breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3275stepping}.)
3276
6d2ebf8b 3277@node Conditions
c906108c
SS
3278@subsection Break conditions
3279@cindex conditional breakpoints
3280@cindex breakpoint conditions
3281
3282@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3283@c in particular for a watchpoint?
c906108c
SS
3284The simplest sort of breakpoint breaks every time your program reaches a
3285specified place. You can also specify a @dfn{condition} for a
3286breakpoint. A condition is just a Boolean expression in your
3287programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3288a condition evaluates the expression each time your program reaches it,
3289and your program stops only if the condition is @emph{true}.
3290
3291This is the converse of using assertions for program validation; in that
3292situation, you want to stop when the assertion is violated---that is,
3293when the condition is false. In C, if you want to test an assertion expressed
3294by the condition @var{assert}, you should set the condition
3295@samp{! @var{assert}} on the appropriate breakpoint.
3296
3297Conditions are also accepted for watchpoints; you may not need them,
3298since a watchpoint is inspecting the value of an expression anyhow---but
3299it might be simpler, say, to just set a watchpoint on a variable name,
3300and specify a condition that tests whether the new value is an interesting
3301one.
3302
3303Break conditions can have side effects, and may even call functions in
3304your program. This can be useful, for example, to activate functions
3305that log program progress, or to use your own print functions to
3306format special data structures. The effects are completely predictable
3307unless there is another enabled breakpoint at the same address. (In
3308that case, @value{GDBN} might see the other breakpoint first and stop your
3309program without checking the condition of this one.) Note that
d4f3574e
SS
3310breakpoint commands are usually more convenient and flexible than break
3311conditions for the
c906108c
SS
3312purpose of performing side effects when a breakpoint is reached
3313(@pxref{Break Commands, ,Breakpoint command lists}).
3314
3315Break conditions can be specified when a breakpoint is set, by using
3316@samp{if} in the arguments to the @code{break} command. @xref{Set
3317Breaks, ,Setting breakpoints}. They can also be changed at any time
3318with the @code{condition} command.
53a5351d 3319
c906108c
SS
3320You can also use the @code{if} keyword with the @code{watch} command.
3321The @code{catch} command does not recognize the @code{if} keyword;
3322@code{condition} is the only way to impose a further condition on a
3323catchpoint.
c906108c
SS
3324
3325@table @code
3326@kindex condition
3327@item condition @var{bnum} @var{expression}
3328Specify @var{expression} as the break condition for breakpoint,
3329watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3330breakpoint @var{bnum} stops your program only if the value of
3331@var{expression} is true (nonzero, in C). When you use
3332@code{condition}, @value{GDBN} checks @var{expression} immediately for
3333syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3334referents in the context of your breakpoint. If @var{expression} uses
3335symbols not referenced in the context of the breakpoint, @value{GDBN}
3336prints an error message:
3337
474c8240 3338@smallexample
d4f3574e 3339No symbol "foo" in current context.
474c8240 3340@end smallexample
d4f3574e
SS
3341
3342@noindent
c906108c
SS
3343@value{GDBN} does
3344not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3345command (or a command that sets a breakpoint with a condition, like
3346@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3347
3348@item condition @var{bnum}
3349Remove the condition from breakpoint number @var{bnum}. It becomes
3350an ordinary unconditional breakpoint.
3351@end table
3352
3353@cindex ignore count (of breakpoint)
3354A special case of a breakpoint condition is to stop only when the
3355breakpoint has been reached a certain number of times. This is so
3356useful that there is a special way to do it, using the @dfn{ignore
3357count} of the breakpoint. Every breakpoint has an ignore count, which
3358is an integer. Most of the time, the ignore count is zero, and
3359therefore has no effect. But if your program reaches a breakpoint whose
3360ignore count is positive, then instead of stopping, it just decrements
3361the ignore count by one and continues. As a result, if the ignore count
3362value is @var{n}, the breakpoint does not stop the next @var{n} times
3363your program reaches it.
3364
3365@table @code
3366@kindex ignore
3367@item ignore @var{bnum} @var{count}
3368Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3369The next @var{count} times the breakpoint is reached, your program's
3370execution does not stop; other than to decrement the ignore count, @value{GDBN}
3371takes no action.
3372
3373To make the breakpoint stop the next time it is reached, specify
3374a count of zero.
3375
3376When you use @code{continue} to resume execution of your program from a
3377breakpoint, you can specify an ignore count directly as an argument to
3378@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3379Stepping,,Continuing and stepping}.
3380
3381If a breakpoint has a positive ignore count and a condition, the
3382condition is not checked. Once the ignore count reaches zero,
3383@value{GDBN} resumes checking the condition.
3384
3385You could achieve the effect of the ignore count with a condition such
3386as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3387is decremented each time. @xref{Convenience Vars, ,Convenience
3388variables}.
3389@end table
3390
3391Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3392
3393
6d2ebf8b 3394@node Break Commands
c906108c
SS
3395@subsection Breakpoint command lists
3396
3397@cindex breakpoint commands
3398You can give any breakpoint (or watchpoint or catchpoint) a series of
3399commands to execute when your program stops due to that breakpoint. For
3400example, you might want to print the values of certain expressions, or
3401enable other breakpoints.
3402
3403@table @code
3404@kindex commands
3405@kindex end
3406@item commands @r{[}@var{bnum}@r{]}
3407@itemx @dots{} @var{command-list} @dots{}
3408@itemx end
3409Specify a list of commands for breakpoint number @var{bnum}. The commands
3410themselves appear on the following lines. Type a line containing just
3411@code{end} to terminate the commands.
3412
3413To remove all commands from a breakpoint, type @code{commands} and
3414follow it immediately with @code{end}; that is, give no commands.
3415
3416With no @var{bnum} argument, @code{commands} refers to the last
3417breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3418recently encountered).
3419@end table
3420
3421Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3422disabled within a @var{command-list}.
3423
3424You can use breakpoint commands to start your program up again. Simply
3425use the @code{continue} command, or @code{step}, or any other command
3426that resumes execution.
3427
3428Any other commands in the command list, after a command that resumes
3429execution, are ignored. This is because any time you resume execution
3430(even with a simple @code{next} or @code{step}), you may encounter
3431another breakpoint---which could have its own command list, leading to
3432ambiguities about which list to execute.
3433
3434@kindex silent
3435If the first command you specify in a command list is @code{silent}, the
3436usual message about stopping at a breakpoint is not printed. This may
3437be desirable for breakpoints that are to print a specific message and
3438then continue. If none of the remaining commands print anything, you
3439see no sign that the breakpoint was reached. @code{silent} is
3440meaningful only at the beginning of a breakpoint command list.
3441
3442The commands @code{echo}, @code{output}, and @code{printf} allow you to
3443print precisely controlled output, and are often useful in silent
3444breakpoints. @xref{Output, ,Commands for controlled output}.
3445
3446For example, here is how you could use breakpoint commands to print the
3447value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3448
474c8240 3449@smallexample
c906108c
SS
3450break foo if x>0
3451commands
3452silent
3453printf "x is %d\n",x
3454cont
3455end
474c8240 3456@end smallexample
c906108c
SS
3457
3458One application for breakpoint commands is to compensate for one bug so
3459you can test for another. Put a breakpoint just after the erroneous line
3460of code, give it a condition to detect the case in which something
3461erroneous has been done, and give it commands to assign correct values
3462to any variables that need them. End with the @code{continue} command
3463so that your program does not stop, and start with the @code{silent}
3464command so that no output is produced. Here is an example:
3465
474c8240 3466@smallexample
c906108c
SS
3467break 403
3468commands
3469silent
3470set x = y + 4
3471cont
3472end
474c8240 3473@end smallexample
c906108c 3474
6d2ebf8b 3475@node Breakpoint Menus
c906108c
SS
3476@subsection Breakpoint menus
3477@cindex overloading
3478@cindex symbol overloading
3479
b383017d 3480Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3481single function name
c906108c
SS
3482to be defined several times, for application in different contexts.
3483This is called @dfn{overloading}. When a function name is overloaded,
3484@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3485a breakpoint. If you realize this is a problem, you can use
3486something like @samp{break @var{function}(@var{types})} to specify which
3487particular version of the function you want. Otherwise, @value{GDBN} offers
3488you a menu of numbered choices for different possible breakpoints, and
3489waits for your selection with the prompt @samp{>}. The first two
3490options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3491sets a breakpoint at each definition of @var{function}, and typing
3492@kbd{0} aborts the @code{break} command without setting any new
3493breakpoints.
3494
3495For example, the following session excerpt shows an attempt to set a
3496breakpoint at the overloaded symbol @code{String::after}.
3497We choose three particular definitions of that function name:
3498
3499@c FIXME! This is likely to change to show arg type lists, at least
3500@smallexample
3501@group
3502(@value{GDBP}) b String::after
3503[0] cancel
3504[1] all
3505[2] file:String.cc; line number:867
3506[3] file:String.cc; line number:860
3507[4] file:String.cc; line number:875
3508[5] file:String.cc; line number:853
3509[6] file:String.cc; line number:846
3510[7] file:String.cc; line number:735
3511> 2 4 6
3512Breakpoint 1 at 0xb26c: file String.cc, line 867.
3513Breakpoint 2 at 0xb344: file String.cc, line 875.
3514Breakpoint 3 at 0xafcc: file String.cc, line 846.
3515Multiple breakpoints were set.
3516Use the "delete" command to delete unwanted
3517 breakpoints.
3518(@value{GDBP})
3519@end group
3520@end smallexample
c906108c
SS
3521
3522@c @ifclear BARETARGET
6d2ebf8b 3523@node Error in Breakpoints
d4f3574e 3524@subsection ``Cannot insert breakpoints''
c906108c
SS
3525@c
3526@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3527@c
d4f3574e
SS
3528Under some operating systems, breakpoints cannot be used in a program if
3529any other process is running that program. In this situation,
5d161b24 3530attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3531@value{GDBN} to print an error message:
3532
474c8240 3533@smallexample
d4f3574e
SS
3534Cannot insert breakpoints.
3535The same program may be running in another process.
474c8240 3536@end smallexample
d4f3574e
SS
3537
3538When this happens, you have three ways to proceed:
3539
3540@enumerate
3541@item
3542Remove or disable the breakpoints, then continue.
3543
3544@item
5d161b24 3545Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3546name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3547that @value{GDBN} should run your program under that name.
d4f3574e
SS
3548Then start your program again.
3549
3550@item
3551Relink your program so that the text segment is nonsharable, using the
3552linker option @samp{-N}. The operating system limitation may not apply
3553to nonsharable executables.
3554@end enumerate
c906108c
SS
3555@c @end ifclear
3556
d4f3574e
SS
3557A similar message can be printed if you request too many active
3558hardware-assisted breakpoints and watchpoints:
3559
3560@c FIXME: the precise wording of this message may change; the relevant
3561@c source change is not committed yet (Sep 3, 1999).
3562@smallexample
3563Stopped; cannot insert breakpoints.
3564You may have requested too many hardware breakpoints and watchpoints.
3565@end smallexample
3566
3567@noindent
3568This message is printed when you attempt to resume the program, since
3569only then @value{GDBN} knows exactly how many hardware breakpoints and
3570watchpoints it needs to insert.
3571
3572When this message is printed, you need to disable or remove some of the
3573hardware-assisted breakpoints and watchpoints, and then continue.
3574
1485d690
KB
3575@node Breakpoint related warnings
3576@subsection ``Breakpoint address adjusted...''
3577@cindex breakpoint address adjusted
3578
3579Some processor architectures place constraints on the addresses at
3580which breakpoints may be placed. For architectures thus constrained,
3581@value{GDBN} will attempt to adjust the breakpoint's address to comply
3582with the constraints dictated by the architecture.
3583
3584One example of such an architecture is the Fujitsu FR-V. The FR-V is
3585a VLIW architecture in which a number of RISC-like instructions may be
3586bundled together for parallel execution. The FR-V architecture
3587constrains the location of a breakpoint instruction within such a
3588bundle to the instruction with the lowest address. @value{GDBN}
3589honors this constraint by adjusting a breakpoint's address to the
3590first in the bundle.
3591
3592It is not uncommon for optimized code to have bundles which contain
3593instructions from different source statements, thus it may happen that
3594a breakpoint's address will be adjusted from one source statement to
3595another. Since this adjustment may significantly alter @value{GDBN}'s
3596breakpoint related behavior from what the user expects, a warning is
3597printed when the breakpoint is first set and also when the breakpoint
3598is hit.
3599
3600A warning like the one below is printed when setting a breakpoint
3601that's been subject to address adjustment:
3602
3603@smallexample
3604warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3605@end smallexample
3606
3607Such warnings are printed both for user settable and @value{GDBN}'s
3608internal breakpoints. If you see one of these warnings, you should
3609verify that a breakpoint set at the adjusted address will have the
3610desired affect. If not, the breakpoint in question may be removed and
b383017d 3611other breakpoints may be set which will have the desired behavior.
1485d690
KB
3612E.g., it may be sufficient to place the breakpoint at a later
3613instruction. A conditional breakpoint may also be useful in some
3614cases to prevent the breakpoint from triggering too often.
3615
3616@value{GDBN} will also issue a warning when stopping at one of these
3617adjusted breakpoints:
3618
3619@smallexample
3620warning: Breakpoint 1 address previously adjusted from 0x00010414
3621to 0x00010410.
3622@end smallexample
3623
3624When this warning is encountered, it may be too late to take remedial
3625action except in cases where the breakpoint is hit earlier or more
3626frequently than expected.
d4f3574e 3627
6d2ebf8b 3628@node Continuing and Stepping
c906108c
SS
3629@section Continuing and stepping
3630
3631@cindex stepping
3632@cindex continuing
3633@cindex resuming execution
3634@dfn{Continuing} means resuming program execution until your program
3635completes normally. In contrast, @dfn{stepping} means executing just
3636one more ``step'' of your program, where ``step'' may mean either one
3637line of source code, or one machine instruction (depending on what
7a292a7a
SS
3638particular command you use). Either when continuing or when stepping,
3639your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3640it stops due to a signal, you may want to use @code{handle}, or use
3641@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3642
3643@table @code
3644@kindex continue
41afff9a
EZ
3645@kindex c @r{(@code{continue})}
3646@kindex fg @r{(resume foreground execution)}
c906108c
SS
3647@item continue @r{[}@var{ignore-count}@r{]}
3648@itemx c @r{[}@var{ignore-count}@r{]}
3649@itemx fg @r{[}@var{ignore-count}@r{]}
3650Resume program execution, at the address where your program last stopped;
3651any breakpoints set at that address are bypassed. The optional argument
3652@var{ignore-count} allows you to specify a further number of times to
3653ignore a breakpoint at this location; its effect is like that of
3654@code{ignore} (@pxref{Conditions, ,Break conditions}).
3655
3656The argument @var{ignore-count} is meaningful only when your program
3657stopped due to a breakpoint. At other times, the argument to
3658@code{continue} is ignored.
3659
d4f3574e
SS
3660The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3661debugged program is deemed to be the foreground program) are provided
3662purely for convenience, and have exactly the same behavior as
3663@code{continue}.
c906108c
SS
3664@end table
3665
3666To resume execution at a different place, you can use @code{return}
3667(@pxref{Returning, ,Returning from a function}) to go back to the
3668calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3669different address}) to go to an arbitrary location in your program.
3670
3671A typical technique for using stepping is to set a breakpoint
3672(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3673beginning of the function or the section of your program where a problem
3674is believed to lie, run your program until it stops at that breakpoint,
3675and then step through the suspect area, examining the variables that are
3676interesting, until you see the problem happen.
3677
3678@table @code
3679@kindex step
41afff9a 3680@kindex s @r{(@code{step})}
c906108c
SS
3681@item step
3682Continue running your program until control reaches a different source
3683line, then stop it and return control to @value{GDBN}. This command is
3684abbreviated @code{s}.
3685
3686@quotation
3687@c "without debugging information" is imprecise; actually "without line
3688@c numbers in the debugging information". (gcc -g1 has debugging info but
3689@c not line numbers). But it seems complex to try to make that
3690@c distinction here.
3691@emph{Warning:} If you use the @code{step} command while control is
3692within a function that was compiled without debugging information,
3693execution proceeds until control reaches a function that does have
3694debugging information. Likewise, it will not step into a function which
3695is compiled without debugging information. To step through functions
3696without debugging information, use the @code{stepi} command, described
3697below.
3698@end quotation
3699
4a92d011
EZ
3700The @code{step} command only stops at the first instruction of a source
3701line. This prevents the multiple stops that could otherwise occur in
3702@code{switch} statements, @code{for} loops, etc. @code{step} continues
3703to stop if a function that has debugging information is called within
3704the line. In other words, @code{step} @emph{steps inside} any functions
3705called within the line.
c906108c 3706
d4f3574e
SS
3707Also, the @code{step} command only enters a function if there is line
3708number information for the function. Otherwise it acts like the
5d161b24 3709@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3710on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3711was any debugging information about the routine.
c906108c
SS
3712
3713@item step @var{count}
3714Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3715breakpoint is reached, or a signal not related to stepping occurs before
3716@var{count} steps, stepping stops right away.
c906108c
SS
3717
3718@kindex next
41afff9a 3719@kindex n @r{(@code{next})}
c906108c
SS
3720@item next @r{[}@var{count}@r{]}
3721Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3722This is similar to @code{step}, but function calls that appear within
3723the line of code are executed without stopping. Execution stops when
3724control reaches a different line of code at the original stack level
3725that was executing when you gave the @code{next} command. This command
3726is abbreviated @code{n}.
c906108c
SS
3727
3728An argument @var{count} is a repeat count, as for @code{step}.
3729
3730
3731@c FIX ME!! Do we delete this, or is there a way it fits in with
3732@c the following paragraph? --- Vctoria
3733@c
3734@c @code{next} within a function that lacks debugging information acts like
3735@c @code{step}, but any function calls appearing within the code of the
3736@c function are executed without stopping.
3737
d4f3574e
SS
3738The @code{next} command only stops at the first instruction of a
3739source line. This prevents multiple stops that could otherwise occur in
4a92d011 3740@code{switch} statements, @code{for} loops, etc.
c906108c 3741
b90a5f51
CF
3742@kindex set step-mode
3743@item set step-mode
3744@cindex functions without line info, and stepping
3745@cindex stepping into functions with no line info
3746@itemx set step-mode on
4a92d011 3747The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3748stop at the first instruction of a function which contains no debug line
3749information rather than stepping over it.
3750
4a92d011
EZ
3751This is useful in cases where you may be interested in inspecting the
3752machine instructions of a function which has no symbolic info and do not
3753want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3754
3755@item set step-mode off
4a92d011 3756Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3757debug information. This is the default.
3758
9c16f35a
EZ
3759@item show step-mode
3760Show whether @value{GDBN} will stop in or step over functions without
3761source line debug information.
3762
c906108c
SS
3763@kindex finish
3764@item finish
3765Continue running until just after function in the selected stack frame
3766returns. Print the returned value (if any).
3767
3768Contrast this with the @code{return} command (@pxref{Returning,
3769,Returning from a function}).
3770
3771@kindex until
41afff9a 3772@kindex u @r{(@code{until})}
09d4efe1 3773@cindex run until specified location
c906108c
SS
3774@item until
3775@itemx u
3776Continue running until a source line past the current line, in the
3777current stack frame, is reached. This command is used to avoid single
3778stepping through a loop more than once. It is like the @code{next}
3779command, except that when @code{until} encounters a jump, it
3780automatically continues execution until the program counter is greater
3781than the address of the jump.
3782
3783This means that when you reach the end of a loop after single stepping
3784though it, @code{until} makes your program continue execution until it
3785exits the loop. In contrast, a @code{next} command at the end of a loop
3786simply steps back to the beginning of the loop, which forces you to step
3787through the next iteration.
3788
3789@code{until} always stops your program if it attempts to exit the current
3790stack frame.
3791
3792@code{until} may produce somewhat counterintuitive results if the order
3793of machine code does not match the order of the source lines. For
3794example, in the following excerpt from a debugging session, the @code{f}
3795(@code{frame}) command shows that execution is stopped at line
3796@code{206}; yet when we use @code{until}, we get to line @code{195}:
3797
474c8240 3798@smallexample
c906108c
SS
3799(@value{GDBP}) f
3800#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3801206 expand_input();
3802(@value{GDBP}) until
3803195 for ( ; argc > 0; NEXTARG) @{
474c8240 3804@end smallexample
c906108c
SS
3805
3806This happened because, for execution efficiency, the compiler had
3807generated code for the loop closure test at the end, rather than the
3808start, of the loop---even though the test in a C @code{for}-loop is
3809written before the body of the loop. The @code{until} command appeared
3810to step back to the beginning of the loop when it advanced to this
3811expression; however, it has not really gone to an earlier
3812statement---not in terms of the actual machine code.
3813
3814@code{until} with no argument works by means of single
3815instruction stepping, and hence is slower than @code{until} with an
3816argument.
3817
3818@item until @var{location}
3819@itemx u @var{location}
3820Continue running your program until either the specified location is
3821reached, or the current stack frame returns. @var{location} is any of
3822the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3823,Setting breakpoints}). This form of the command uses breakpoints, and
3824hence is quicker than @code{until} without an argument. The specified
3825location is actually reached only if it is in the current frame. This
3826implies that @code{until} can be used to skip over recursive function
3827invocations. For instance in the code below, if the current location is
3828line @code{96}, issuing @code{until 99} will execute the program up to
3829line @code{99} in the same invocation of factorial, i.e. after the inner
3830invocations have returned.
3831
3832@smallexample
383394 int factorial (int value)
383495 @{
383596 if (value > 1) @{
383697 value *= factorial (value - 1);
383798 @}
383899 return (value);
3839100 @}
3840@end smallexample
3841
3842
3843@kindex advance @var{location}
3844@itemx advance @var{location}
09d4efe1
EZ
3845Continue running the program up to the given @var{location}. An argument is
3846required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3847command. Execution will also stop upon exit from the current stack
3848frame. This command is similar to @code{until}, but @code{advance} will
3849not skip over recursive function calls, and the target location doesn't
3850have to be in the same frame as the current one.
3851
c906108c
SS
3852
3853@kindex stepi
41afff9a 3854@kindex si @r{(@code{stepi})}
c906108c 3855@item stepi
96a2c332 3856@itemx stepi @var{arg}
c906108c
SS
3857@itemx si
3858Execute one machine instruction, then stop and return to the debugger.
3859
3860It is often useful to do @samp{display/i $pc} when stepping by machine
3861instructions. This makes @value{GDBN} automatically display the next
3862instruction to be executed, each time your program stops. @xref{Auto
3863Display,, Automatic display}.
3864
3865An argument is a repeat count, as in @code{step}.
3866
3867@need 750
3868@kindex nexti
41afff9a 3869@kindex ni @r{(@code{nexti})}
c906108c 3870@item nexti
96a2c332 3871@itemx nexti @var{arg}
c906108c
SS
3872@itemx ni
3873Execute one machine instruction, but if it is a function call,
3874proceed until the function returns.
3875
3876An argument is a repeat count, as in @code{next}.
3877@end table
3878
6d2ebf8b 3879@node Signals
c906108c
SS
3880@section Signals
3881@cindex signals
3882
3883A signal is an asynchronous event that can happen in a program. The
3884operating system defines the possible kinds of signals, and gives each
3885kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3886signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3887@code{SIGSEGV} is the signal a program gets from referencing a place in
3888memory far away from all the areas in use; @code{SIGALRM} occurs when
3889the alarm clock timer goes off (which happens only if your program has
3890requested an alarm).
3891
3892@cindex fatal signals
3893Some signals, including @code{SIGALRM}, are a normal part of the
3894functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3895errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3896program has not specified in advance some other way to handle the signal.
3897@code{SIGINT} does not indicate an error in your program, but it is normally
3898fatal so it can carry out the purpose of the interrupt: to kill the program.
3899
3900@value{GDBN} has the ability to detect any occurrence of a signal in your
3901program. You can tell @value{GDBN} in advance what to do for each kind of
3902signal.
3903
3904@cindex handling signals
24f93129
EZ
3905Normally, @value{GDBN} is set up to let the non-erroneous signals like
3906@code{SIGALRM} be silently passed to your program
3907(so as not to interfere with their role in the program's functioning)
c906108c
SS
3908but to stop your program immediately whenever an error signal happens.
3909You can change these settings with the @code{handle} command.
3910
3911@table @code
3912@kindex info signals
09d4efe1 3913@kindex info handle
c906108c 3914@item info signals
96a2c332 3915@itemx info handle
c906108c
SS
3916Print a table of all the kinds of signals and how @value{GDBN} has been told to
3917handle each one. You can use this to see the signal numbers of all
3918the defined types of signals.
3919
d4f3574e 3920@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3921
3922@kindex handle
3923@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3924Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3925can be the number of a signal or its name (with or without the
24f93129 3926@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3927@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3928known signals. The @var{keywords} say what change to make.
c906108c
SS
3929@end table
3930
3931@c @group
3932The keywords allowed by the @code{handle} command can be abbreviated.
3933Their full names are:
3934
3935@table @code
3936@item nostop
3937@value{GDBN} should not stop your program when this signal happens. It may
3938still print a message telling you that the signal has come in.
3939
3940@item stop
3941@value{GDBN} should stop your program when this signal happens. This implies
3942the @code{print} keyword as well.
3943
3944@item print
3945@value{GDBN} should print a message when this signal happens.
3946
3947@item noprint
3948@value{GDBN} should not mention the occurrence of the signal at all. This
3949implies the @code{nostop} keyword as well.
3950
3951@item pass
5ece1a18 3952@itemx noignore
c906108c
SS
3953@value{GDBN} should allow your program to see this signal; your program
3954can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3955and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3956
3957@item nopass
5ece1a18 3958@itemx ignore
c906108c 3959@value{GDBN} should not allow your program to see this signal.
5ece1a18 3960@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3961@end table
3962@c @end group
3963
d4f3574e
SS
3964When a signal stops your program, the signal is not visible to the
3965program until you
c906108c
SS
3966continue. Your program sees the signal then, if @code{pass} is in
3967effect for the signal in question @emph{at that time}. In other words,
3968after @value{GDBN} reports a signal, you can use the @code{handle}
3969command with @code{pass} or @code{nopass} to control whether your
3970program sees that signal when you continue.
3971
24f93129
EZ
3972The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3973non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3974@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3975erroneous signals.
3976
c906108c
SS
3977You can also use the @code{signal} command to prevent your program from
3978seeing a signal, or cause it to see a signal it normally would not see,
3979or to give it any signal at any time. For example, if your program stopped
3980due to some sort of memory reference error, you might store correct
3981values into the erroneous variables and continue, hoping to see more
3982execution; but your program would probably terminate immediately as
3983a result of the fatal signal once it saw the signal. To prevent this,
3984you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3985program a signal}.
c906108c 3986
6d2ebf8b 3987@node Thread Stops
c906108c
SS
3988@section Stopping and starting multi-thread programs
3989
3990When your program has multiple threads (@pxref{Threads,, Debugging
3991programs with multiple threads}), you can choose whether to set
3992breakpoints on all threads, or on a particular thread.
3993
3994@table @code
3995@cindex breakpoints and threads
3996@cindex thread breakpoints
3997@kindex break @dots{} thread @var{threadno}
3998@item break @var{linespec} thread @var{threadno}
3999@itemx break @var{linespec} thread @var{threadno} if @dots{}
4000@var{linespec} specifies source lines; there are several ways of
4001writing them, but the effect is always to specify some source line.
4002
4003Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4004to specify that you only want @value{GDBN} to stop the program when a
4005particular thread reaches this breakpoint. @var{threadno} is one of the
4006numeric thread identifiers assigned by @value{GDBN}, shown in the first
4007column of the @samp{info threads} display.
4008
4009If you do not specify @samp{thread @var{threadno}} when you set a
4010breakpoint, the breakpoint applies to @emph{all} threads of your
4011program.
4012
4013You can use the @code{thread} qualifier on conditional breakpoints as
4014well; in this case, place @samp{thread @var{threadno}} before the
4015breakpoint condition, like this:
4016
4017@smallexample
2df3850c 4018(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
4019@end smallexample
4020
4021@end table
4022
4023@cindex stopped threads
4024@cindex threads, stopped
4025Whenever your program stops under @value{GDBN} for any reason,
4026@emph{all} threads of execution stop, not just the current thread. This
4027allows you to examine the overall state of the program, including
4028switching between threads, without worrying that things may change
4029underfoot.
4030
36d86913
MC
4031@cindex thread breakpoints and system calls
4032@cindex system calls and thread breakpoints
4033@cindex premature return from system calls
4034There is an unfortunate side effect. If one thread stops for a
4035breakpoint, or for some other reason, and another thread is blocked in a
4036system call, then the system call may return prematurely. This is a
4037consequence of the interaction between multiple threads and the signals
4038that @value{GDBN} uses to implement breakpoints and other events that
4039stop execution.
4040
4041To handle this problem, your program should check the return value of
4042each system call and react appropriately. This is good programming
4043style anyways.
4044
4045For example, do not write code like this:
4046
4047@smallexample
4048 sleep (10);
4049@end smallexample
4050
4051The call to @code{sleep} will return early if a different thread stops
4052at a breakpoint or for some other reason.
4053
4054Instead, write this:
4055
4056@smallexample
4057 int unslept = 10;
4058 while (unslept > 0)
4059 unslept = sleep (unslept);
4060@end smallexample
4061
4062A system call is allowed to return early, so the system is still
4063conforming to its specification. But @value{GDBN} does cause your
4064multi-threaded program to behave differently than it would without
4065@value{GDBN}.
4066
4067Also, @value{GDBN} uses internal breakpoints in the thread library to
4068monitor certain events such as thread creation and thread destruction.
4069When such an event happens, a system call in another thread may return
4070prematurely, even though your program does not appear to stop.
4071
c906108c
SS
4072@cindex continuing threads
4073@cindex threads, continuing
4074Conversely, whenever you restart the program, @emph{all} threads start
4075executing. @emph{This is true even when single-stepping} with commands
5d161b24 4076like @code{step} or @code{next}.
c906108c
SS
4077
4078In particular, @value{GDBN} cannot single-step all threads in lockstep.
4079Since thread scheduling is up to your debugging target's operating
4080system (not controlled by @value{GDBN}), other threads may
4081execute more than one statement while the current thread completes a
4082single step. Moreover, in general other threads stop in the middle of a
4083statement, rather than at a clean statement boundary, when the program
4084stops.
4085
4086You might even find your program stopped in another thread after
4087continuing or even single-stepping. This happens whenever some other
4088thread runs into a breakpoint, a signal, or an exception before the
4089first thread completes whatever you requested.
4090
4091On some OSes, you can lock the OS scheduler and thus allow only a single
4092thread to run.
4093
4094@table @code
4095@item set scheduler-locking @var{mode}
9c16f35a
EZ
4096@cindex scheduler locking mode
4097@cindex lock scheduler
c906108c
SS
4098Set the scheduler locking mode. If it is @code{off}, then there is no
4099locking and any thread may run at any time. If @code{on}, then only the
4100current thread may run when the inferior is resumed. The @code{step}
4101mode optimizes for single-stepping. It stops other threads from
4102``seizing the prompt'' by preempting the current thread while you are
4103stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4104when you step. They are more likely to run when you @samp{next} over a
c906108c 4105function call, and they are completely free to run when you use commands
d4f3574e 4106like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4107thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4108@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4109
4110@item show scheduler-locking
4111Display the current scheduler locking mode.
4112@end table
4113
c906108c 4114
6d2ebf8b 4115@node Stack
c906108c
SS
4116@chapter Examining the Stack
4117
4118When your program has stopped, the first thing you need to know is where it
4119stopped and how it got there.
4120
4121@cindex call stack
5d161b24
DB
4122Each time your program performs a function call, information about the call
4123is generated.
4124That information includes the location of the call in your program,
4125the arguments of the call,
c906108c 4126and the local variables of the function being called.
5d161b24 4127The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4128The stack frames are allocated in a region of memory called the @dfn{call
4129stack}.
4130
4131When your program stops, the @value{GDBN} commands for examining the
4132stack allow you to see all of this information.
4133
4134@cindex selected frame
4135One of the stack frames is @dfn{selected} by @value{GDBN} and many
4136@value{GDBN} commands refer implicitly to the selected frame. In
4137particular, whenever you ask @value{GDBN} for the value of a variable in
4138your program, the value is found in the selected frame. There are
4139special @value{GDBN} commands to select whichever frame you are
4140interested in. @xref{Selection, ,Selecting a frame}.
4141
4142When your program stops, @value{GDBN} automatically selects the
5d161b24 4143currently executing frame and describes it briefly, similar to the
c906108c
SS
4144@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4145
4146@menu
4147* Frames:: Stack frames
4148* Backtrace:: Backtraces
4149* Selection:: Selecting a frame
4150* Frame Info:: Information on a frame
c906108c
SS
4151
4152@end menu
4153
6d2ebf8b 4154@node Frames
c906108c
SS
4155@section Stack frames
4156
d4f3574e 4157@cindex frame, definition
c906108c
SS
4158@cindex stack frame
4159The call stack is divided up into contiguous pieces called @dfn{stack
4160frames}, or @dfn{frames} for short; each frame is the data associated
4161with one call to one function. The frame contains the arguments given
4162to the function, the function's local variables, and the address at
4163which the function is executing.
4164
4165@cindex initial frame
4166@cindex outermost frame
4167@cindex innermost frame
4168When your program is started, the stack has only one frame, that of the
4169function @code{main}. This is called the @dfn{initial} frame or the
4170@dfn{outermost} frame. Each time a function is called, a new frame is
4171made. Each time a function returns, the frame for that function invocation
4172is eliminated. If a function is recursive, there can be many frames for
4173the same function. The frame for the function in which execution is
4174actually occurring is called the @dfn{innermost} frame. This is the most
4175recently created of all the stack frames that still exist.
4176
4177@cindex frame pointer
4178Inside your program, stack frames are identified by their addresses. A
4179stack frame consists of many bytes, each of which has its own address; each
4180kind of computer has a convention for choosing one byte whose
4181address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4182in a register called the @dfn{frame pointer register}
4183(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4184
4185@cindex frame number
4186@value{GDBN} assigns numbers to all existing stack frames, starting with
4187zero for the innermost frame, one for the frame that called it,
4188and so on upward. These numbers do not really exist in your program;
4189they are assigned by @value{GDBN} to give you a way of designating stack
4190frames in @value{GDBN} commands.
4191
6d2ebf8b
SS
4192@c The -fomit-frame-pointer below perennially causes hbox overflow
4193@c underflow problems.
c906108c
SS
4194@cindex frameless execution
4195Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4196without stack frames. (For example, the @value{GCC} option
474c8240 4197@smallexample
6d2ebf8b 4198@samp{-fomit-frame-pointer}
474c8240 4199@end smallexample
6d2ebf8b 4200generates functions without a frame.)
c906108c
SS
4201This is occasionally done with heavily used library functions to save
4202the frame setup time. @value{GDBN} has limited facilities for dealing
4203with these function invocations. If the innermost function invocation
4204has no stack frame, @value{GDBN} nevertheless regards it as though
4205it had a separate frame, which is numbered zero as usual, allowing
4206correct tracing of the function call chain. However, @value{GDBN} has
4207no provision for frameless functions elsewhere in the stack.
4208
4209@table @code
d4f3574e 4210@kindex frame@r{, command}
41afff9a 4211@cindex current stack frame
c906108c 4212@item frame @var{args}
5d161b24 4213The @code{frame} command allows you to move from one stack frame to another,
c906108c 4214and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4215address of the frame or the stack frame number. Without an argument,
4216@code{frame} prints the current stack frame.
c906108c
SS
4217
4218@kindex select-frame
41afff9a 4219@cindex selecting frame silently
c906108c
SS
4220@item select-frame
4221The @code{select-frame} command allows you to move from one stack frame
4222to another without printing the frame. This is the silent version of
4223@code{frame}.
4224@end table
4225
6d2ebf8b 4226@node Backtrace
c906108c
SS
4227@section Backtraces
4228
09d4efe1
EZ
4229@cindex traceback
4230@cindex call stack traces
c906108c
SS
4231A backtrace is a summary of how your program got where it is. It shows one
4232line per frame, for many frames, starting with the currently executing
4233frame (frame zero), followed by its caller (frame one), and on up the
4234stack.
4235
4236@table @code
4237@kindex backtrace
41afff9a 4238@kindex bt @r{(@code{backtrace})}
c906108c
SS
4239@item backtrace
4240@itemx bt
4241Print a backtrace of the entire stack: one line per frame for all
4242frames in the stack.
4243
4244You can stop the backtrace at any time by typing the system interrupt
4245character, normally @kbd{C-c}.
4246
4247@item backtrace @var{n}
4248@itemx bt @var{n}
4249Similar, but print only the innermost @var{n} frames.
4250
4251@item backtrace -@var{n}
4252@itemx bt -@var{n}
4253Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4254
4255@item backtrace full
4256Print the values of the local variables also.
4257@itemx bt full
c906108c
SS
4258@end table
4259
4260@kindex where
4261@kindex info stack
c906108c
SS
4262The names @code{where} and @code{info stack} (abbreviated @code{info s})
4263are additional aliases for @code{backtrace}.
4264
4265Each line in the backtrace shows the frame number and the function name.
4266The program counter value is also shown---unless you use @code{set
4267print address off}. The backtrace also shows the source file name and
4268line number, as well as the arguments to the function. The program
4269counter value is omitted if it is at the beginning of the code for that
4270line number.
4271
4272Here is an example of a backtrace. It was made with the command
4273@samp{bt 3}, so it shows the innermost three frames.
4274
4275@smallexample
4276@group
5d161b24 4277#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4278 at builtin.c:993
4279#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4280#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4281 at macro.c:71
4282(More stack frames follow...)
4283@end group
4284@end smallexample
4285
4286@noindent
4287The display for frame zero does not begin with a program counter
4288value, indicating that your program has stopped at the beginning of the
4289code for line @code{993} of @code{builtin.c}.
4290
18999be5
EZ
4291@cindex value optimized out, in backtrace
4292@cindex function call arguments, optimized out
4293If your program was compiled with optimizations, some compilers will
4294optimize away arguments passed to functions if those arguments are
4295never used after the call. Such optimizations generate code that
4296passes arguments through registers, but doesn't store those arguments
4297in the stack frame. @value{GDBN} has no way of displaying such
4298arguments in stack frames other than the innermost one. Here's what
4299such a backtrace might look like:
4300
4301@smallexample
4302@group
4303#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4304 at builtin.c:993
4305#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4306#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4307 at macro.c:71
4308(More stack frames follow...)
4309@end group
4310@end smallexample
4311
4312@noindent
4313The values of arguments that were not saved in their stack frames are
4314shown as @samp{<value optimized out>}.
4315
4316If you need to display the values of such optimized-out arguments,
4317either deduce that from other variables whose values depend on the one
4318you are interested in, or recompile without optimizations.
4319
a8f24a35
EZ
4320@cindex backtrace beyond @code{main} function
4321@cindex program entry point
4322@cindex startup code, and backtrace
25d29d70
AC
4323Most programs have a standard user entry point---a place where system
4324libraries and startup code transition into user code. For C this is
d416eeec
EZ
4325@code{main}@footnote{
4326Note that embedded programs (the so-called ``free-standing''
4327environment) are not required to have a @code{main} function as the
4328entry point. They could even have multiple entry points.}.
4329When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4330it will terminate the backtrace, to avoid tracing into highly
4331system-specific (and generally uninteresting) code.
4332
4333If you need to examine the startup code, or limit the number of levels
4334in a backtrace, you can change this behavior:
95f90d25
DJ
4335
4336@table @code
25d29d70
AC
4337@item set backtrace past-main
4338@itemx set backtrace past-main on
4644b6e3 4339@kindex set backtrace
25d29d70
AC
4340Backtraces will continue past the user entry point.
4341
4342@item set backtrace past-main off
95f90d25
DJ
4343Backtraces will stop when they encounter the user entry point. This is the
4344default.
4345
25d29d70 4346@item show backtrace past-main
4644b6e3 4347@kindex show backtrace
25d29d70
AC
4348Display the current user entry point backtrace policy.
4349
2315ffec
RC
4350@item set backtrace past-entry
4351@itemx set backtrace past-entry on
a8f24a35 4352Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4353This entry point is encoded by the linker when the application is built,
4354and is likely before the user entry point @code{main} (or equivalent) is called.
4355
4356@item set backtrace past-entry off
4357Backtraces will stop when they encouter the internal entry point of an
4358application. This is the default.
4359
4360@item show backtrace past-entry
4361Display the current internal entry point backtrace policy.
4362
25d29d70
AC
4363@item set backtrace limit @var{n}
4364@itemx set backtrace limit 0
4365@cindex backtrace limit
4366Limit the backtrace to @var{n} levels. A value of zero means
4367unlimited.
95f90d25 4368
25d29d70
AC
4369@item show backtrace limit
4370Display the current limit on backtrace levels.
95f90d25
DJ
4371@end table
4372
6d2ebf8b 4373@node Selection
c906108c
SS
4374@section Selecting a frame
4375
4376Most commands for examining the stack and other data in your program work on
4377whichever stack frame is selected at the moment. Here are the commands for
4378selecting a stack frame; all of them finish by printing a brief description
4379of the stack frame just selected.
4380
4381@table @code
d4f3574e 4382@kindex frame@r{, selecting}
41afff9a 4383@kindex f @r{(@code{frame})}
c906108c
SS
4384@item frame @var{n}
4385@itemx f @var{n}
4386Select frame number @var{n}. Recall that frame zero is the innermost
4387(currently executing) frame, frame one is the frame that called the
4388innermost one, and so on. The highest-numbered frame is the one for
4389@code{main}.
4390
4391@item frame @var{addr}
4392@itemx f @var{addr}
4393Select the frame at address @var{addr}. This is useful mainly if the
4394chaining of stack frames has been damaged by a bug, making it
4395impossible for @value{GDBN} to assign numbers properly to all frames. In
4396addition, this can be useful when your program has multiple stacks and
4397switches between them.
4398
c906108c
SS
4399On the SPARC architecture, @code{frame} needs two addresses to
4400select an arbitrary frame: a frame pointer and a stack pointer.
4401
4402On the MIPS and Alpha architecture, it needs two addresses: a stack
4403pointer and a program counter.
4404
4405On the 29k architecture, it needs three addresses: a register stack
4406pointer, a program counter, and a memory stack pointer.
c906108c
SS
4407
4408@kindex up
4409@item up @var{n}
4410Move @var{n} frames up the stack. For positive numbers @var{n}, this
4411advances toward the outermost frame, to higher frame numbers, to frames
4412that have existed longer. @var{n} defaults to one.
4413
4414@kindex down
41afff9a 4415@kindex do @r{(@code{down})}
c906108c
SS
4416@item down @var{n}
4417Move @var{n} frames down the stack. For positive numbers @var{n}, this
4418advances toward the innermost frame, to lower frame numbers, to frames
4419that were created more recently. @var{n} defaults to one. You may
4420abbreviate @code{down} as @code{do}.
4421@end table
4422
4423All of these commands end by printing two lines of output describing the
4424frame. The first line shows the frame number, the function name, the
4425arguments, and the source file and line number of execution in that
5d161b24 4426frame. The second line shows the text of that source line.
c906108c
SS
4427
4428@need 1000
4429For example:
4430
4431@smallexample
4432@group
4433(@value{GDBP}) up
4434#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4435 at env.c:10
443610 read_input_file (argv[i]);
4437@end group
4438@end smallexample
4439
4440After such a printout, the @code{list} command with no arguments
4441prints ten lines centered on the point of execution in the frame.
87885426
FN
4442You can also edit the program at the point of execution with your favorite
4443editing program by typing @code{edit}.
4444@xref{List, ,Printing source lines},
4445for details.
c906108c
SS
4446
4447@table @code
4448@kindex down-silently
4449@kindex up-silently
4450@item up-silently @var{n}
4451@itemx down-silently @var{n}
4452These two commands are variants of @code{up} and @code{down},
4453respectively; they differ in that they do their work silently, without
4454causing display of the new frame. They are intended primarily for use
4455in @value{GDBN} command scripts, where the output might be unnecessary and
4456distracting.
4457@end table
4458
6d2ebf8b 4459@node Frame Info
c906108c
SS
4460@section Information about a frame
4461
4462There are several other commands to print information about the selected
4463stack frame.
4464
4465@table @code
4466@item frame
4467@itemx f
4468When used without any argument, this command does not change which
4469frame is selected, but prints a brief description of the currently
4470selected stack frame. It can be abbreviated @code{f}. With an
4471argument, this command is used to select a stack frame.
4472@xref{Selection, ,Selecting a frame}.
4473
4474@kindex info frame
41afff9a 4475@kindex info f @r{(@code{info frame})}
c906108c
SS
4476@item info frame
4477@itemx info f
4478This command prints a verbose description of the selected stack frame,
4479including:
4480
4481@itemize @bullet
5d161b24
DB
4482@item
4483the address of the frame
c906108c
SS
4484@item
4485the address of the next frame down (called by this frame)
4486@item
4487the address of the next frame up (caller of this frame)
4488@item
4489the language in which the source code corresponding to this frame is written
4490@item
4491the address of the frame's arguments
4492@item
d4f3574e
SS
4493the address of the frame's local variables
4494@item
c906108c
SS
4495the program counter saved in it (the address of execution in the caller frame)
4496@item
4497which registers were saved in the frame
4498@end itemize
4499
4500@noindent The verbose description is useful when
4501something has gone wrong that has made the stack format fail to fit
4502the usual conventions.
4503
4504@item info frame @var{addr}
4505@itemx info f @var{addr}
4506Print a verbose description of the frame at address @var{addr}, without
4507selecting that frame. The selected frame remains unchanged by this
4508command. This requires the same kind of address (more than one for some
4509architectures) that you specify in the @code{frame} command.
4510@xref{Selection, ,Selecting a frame}.
4511
4512@kindex info args
4513@item info args
4514Print the arguments of the selected frame, each on a separate line.
4515
4516@item info locals
4517@kindex info locals
4518Print the local variables of the selected frame, each on a separate
4519line. These are all variables (declared either static or automatic)
4520accessible at the point of execution of the selected frame.
4521
c906108c 4522@kindex info catch
d4f3574e
SS
4523@cindex catch exceptions, list active handlers
4524@cindex exception handlers, how to list
c906108c
SS
4525@item info catch
4526Print a list of all the exception handlers that are active in the
4527current stack frame at the current point of execution. To see other
4528exception handlers, visit the associated frame (using the @code{up},
4529@code{down}, or @code{frame} commands); then type @code{info catch}.
4530@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4531
c906108c
SS
4532@end table
4533
c906108c 4534
6d2ebf8b 4535@node Source
c906108c
SS
4536@chapter Examining Source Files
4537
4538@value{GDBN} can print parts of your program's source, since the debugging
4539information recorded in the program tells @value{GDBN} what source files were
4540used to build it. When your program stops, @value{GDBN} spontaneously prints
4541the line where it stopped. Likewise, when you select a stack frame
4542(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4543execution in that frame has stopped. You can print other portions of
4544source files by explicit command.
4545
7a292a7a 4546If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4547prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4548@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4549
4550@menu
4551* List:: Printing source lines
87885426 4552* Edit:: Editing source files
c906108c 4553* Search:: Searching source files
c906108c
SS
4554* Source Path:: Specifying source directories
4555* Machine Code:: Source and machine code
4556@end menu
4557
6d2ebf8b 4558@node List
c906108c
SS
4559@section Printing source lines
4560
4561@kindex list
41afff9a 4562@kindex l @r{(@code{list})}
c906108c 4563To print lines from a source file, use the @code{list} command
5d161b24 4564(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4565There are several ways to specify what part of the file you want to print.
4566
4567Here are the forms of the @code{list} command most commonly used:
4568
4569@table @code
4570@item list @var{linenum}
4571Print lines centered around line number @var{linenum} in the
4572current source file.
4573
4574@item list @var{function}
4575Print lines centered around the beginning of function
4576@var{function}.
4577
4578@item list
4579Print more lines. If the last lines printed were printed with a
4580@code{list} command, this prints lines following the last lines
4581printed; however, if the last line printed was a solitary line printed
4582as part of displaying a stack frame (@pxref{Stack, ,Examining the
4583Stack}), this prints lines centered around that line.
4584
4585@item list -
4586Print lines just before the lines last printed.
4587@end table
4588
9c16f35a 4589@cindex @code{list}, how many lines to display
c906108c
SS
4590By default, @value{GDBN} prints ten source lines with any of these forms of
4591the @code{list} command. You can change this using @code{set listsize}:
4592
4593@table @code
4594@kindex set listsize
4595@item set listsize @var{count}
4596Make the @code{list} command display @var{count} source lines (unless
4597the @code{list} argument explicitly specifies some other number).
4598
4599@kindex show listsize
4600@item show listsize
4601Display the number of lines that @code{list} prints.
4602@end table
4603
4604Repeating a @code{list} command with @key{RET} discards the argument,
4605so it is equivalent to typing just @code{list}. This is more useful
4606than listing the same lines again. An exception is made for an
4607argument of @samp{-}; that argument is preserved in repetition so that
4608each repetition moves up in the source file.
4609
4610@cindex linespec
4611In general, the @code{list} command expects you to supply zero, one or two
4612@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4613of writing them, but the effect is always to specify some source line.
c906108c
SS
4614Here is a complete description of the possible arguments for @code{list}:
4615
4616@table @code
4617@item list @var{linespec}
4618Print lines centered around the line specified by @var{linespec}.
4619
4620@item list @var{first},@var{last}
4621Print lines from @var{first} to @var{last}. Both arguments are
4622linespecs.
4623
4624@item list ,@var{last}
4625Print lines ending with @var{last}.
4626
4627@item list @var{first},
4628Print lines starting with @var{first}.
4629
4630@item list +
4631Print lines just after the lines last printed.
4632
4633@item list -
4634Print lines just before the lines last printed.
4635
4636@item list
4637As described in the preceding table.
4638@end table
4639
4640Here are the ways of specifying a single source line---all the
4641kinds of linespec.
4642
4643@table @code
4644@item @var{number}
4645Specifies line @var{number} of the current source file.
4646When a @code{list} command has two linespecs, this refers to
4647the same source file as the first linespec.
4648
4649@item +@var{offset}
4650Specifies the line @var{offset} lines after the last line printed.
4651When used as the second linespec in a @code{list} command that has
4652two, this specifies the line @var{offset} lines down from the
4653first linespec.
4654
4655@item -@var{offset}
4656Specifies the line @var{offset} lines before the last line printed.
4657
4658@item @var{filename}:@var{number}
4659Specifies line @var{number} in the source file @var{filename}.
4660
4661@item @var{function}
4662Specifies the line that begins the body of the function @var{function}.
4663For example: in C, this is the line with the open brace.
4664
4665@item @var{filename}:@var{function}
4666Specifies the line of the open-brace that begins the body of the
4667function @var{function} in the file @var{filename}. You only need the
4668file name with a function name to avoid ambiguity when there are
4669identically named functions in different source files.
4670
4671@item *@var{address}
4672Specifies the line containing the program address @var{address}.
4673@var{address} may be any expression.
4674@end table
4675
87885426
FN
4676@node Edit
4677@section Editing source files
4678@cindex editing source files
4679
4680@kindex edit
4681@kindex e @r{(@code{edit})}
4682To edit the lines in a source file, use the @code{edit} command.
4683The editing program of your choice
4684is invoked with the current line set to
4685the active line in the program.
4686Alternatively, there are several ways to specify what part of the file you
4687want to print if you want to see other parts of the program.
4688
4689Here are the forms of the @code{edit} command most commonly used:
4690
4691@table @code
4692@item edit
4693Edit the current source file at the active line number in the program.
4694
4695@item edit @var{number}
4696Edit the current source file with @var{number} as the active line number.
4697
4698@item edit @var{function}
4699Edit the file containing @var{function} at the beginning of its definition.
4700
4701@item edit @var{filename}:@var{number}
4702Specifies line @var{number} in the source file @var{filename}.
4703
4704@item edit @var{filename}:@var{function}
4705Specifies the line that begins the body of the
4706function @var{function} in the file @var{filename}. You only need the
4707file name with a function name to avoid ambiguity when there are
4708identically named functions in different source files.
4709
4710@item edit *@var{address}
4711Specifies the line containing the program address @var{address}.
4712@var{address} may be any expression.
4713@end table
4714
4715@subsection Choosing your editor
4716You can customize @value{GDBN} to use any editor you want
4717@footnote{
4718The only restriction is that your editor (say @code{ex}), recognizes the
4719following command-line syntax:
10998722 4720@smallexample
87885426 4721ex +@var{number} file
10998722 4722@end smallexample
15387254
EZ
4723The optional numeric value +@var{number} specifies the number of the line in
4724the file where to start editing.}.
4725By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4726by setting the environment variable @code{EDITOR} before using
4727@value{GDBN}. For example, to configure @value{GDBN} to use the
4728@code{vi} editor, you could use these commands with the @code{sh} shell:
4729@smallexample
87885426
FN
4730EDITOR=/usr/bin/vi
4731export EDITOR
15387254 4732gdb @dots{}
10998722 4733@end smallexample
87885426 4734or in the @code{csh} shell,
10998722 4735@smallexample
87885426 4736setenv EDITOR /usr/bin/vi
15387254 4737gdb @dots{}
10998722 4738@end smallexample
87885426 4739
6d2ebf8b 4740@node Search
c906108c 4741@section Searching source files
15387254 4742@cindex searching source files
c906108c
SS
4743
4744There are two commands for searching through the current source file for a
4745regular expression.
4746
4747@table @code
4748@kindex search
4749@kindex forward-search
4750@item forward-search @var{regexp}
4751@itemx search @var{regexp}
4752The command @samp{forward-search @var{regexp}} checks each line,
4753starting with the one following the last line listed, for a match for
5d161b24 4754@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4755synonym @samp{search @var{regexp}} or abbreviate the command name as
4756@code{fo}.
4757
09d4efe1 4758@kindex reverse-search
c906108c
SS
4759@item reverse-search @var{regexp}
4760The command @samp{reverse-search @var{regexp}} checks each line, starting
4761with the one before the last line listed and going backward, for a match
4762for @var{regexp}. It lists the line that is found. You can abbreviate
4763this command as @code{rev}.
4764@end table
c906108c 4765
6d2ebf8b 4766@node Source Path
c906108c
SS
4767@section Specifying source directories
4768
4769@cindex source path
4770@cindex directories for source files
4771Executable programs sometimes do not record the directories of the source
4772files from which they were compiled, just the names. Even when they do,
4773the directories could be moved between the compilation and your debugging
4774session. @value{GDBN} has a list of directories to search for source files;
4775this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4776it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4777in the list, until it finds a file with the desired name.
4778
4779For example, suppose an executable references the file
4780@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4781@file{/mnt/cross}. The file is first looked up literally; if this
4782fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4783fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4784message is printed. @value{GDBN} does not look up the parts of the
4785source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4786Likewise, the subdirectories of the source path are not searched: if
4787the source path is @file{/mnt/cross}, and the binary refers to
4788@file{foo.c}, @value{GDBN} would not find it under
4789@file{/mnt/cross/usr/src/foo-1.0/lib}.
4790
4791Plain file names, relative file names with leading directories, file
4792names containing dots, etc.@: are all treated as described above; for
4793instance, if the source path is @file{/mnt/cross}, and the source file
4794is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4795@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4796that---@file{/mnt/cross/foo.c}.
4797
4798Note that the executable search path is @emph{not} used to locate the
4799source files. Neither is the current working directory, unless it
4800happens to be in the source path.
c906108c
SS
4801
4802Whenever you reset or rearrange the source path, @value{GDBN} clears out
4803any information it has cached about where source files are found and where
4804each line is in the file.
4805
4806@kindex directory
4807@kindex dir
d4f3574e
SS
4808When you start @value{GDBN}, its source path includes only @samp{cdir}
4809and @samp{cwd}, in that order.
c906108c
SS
4810To add other directories, use the @code{directory} command.
4811
4812@table @code
4813@item directory @var{dirname} @dots{}
4814@item dir @var{dirname} @dots{}
4815Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4816directory names may be given to this command, separated by @samp{:}
4817(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4818part of absolute file names) or
c906108c
SS
4819whitespace. You may specify a directory that is already in the source
4820path; this moves it forward, so @value{GDBN} searches it sooner.
4821
4822@kindex cdir
4823@kindex cwd
41afff9a
EZ
4824@vindex $cdir@r{, convenience variable}
4825@vindex $cwdr@r{, convenience variable}
c906108c
SS
4826@cindex compilation directory
4827@cindex current directory
4828@cindex working directory
4829@cindex directory, current
4830@cindex directory, compilation
4831You can use the string @samp{$cdir} to refer to the compilation
4832directory (if one is recorded), and @samp{$cwd} to refer to the current
4833working directory. @samp{$cwd} is not the same as @samp{.}---the former
4834tracks the current working directory as it changes during your @value{GDBN}
4835session, while the latter is immediately expanded to the current
4836directory at the time you add an entry to the source path.
4837
4838@item directory
4839Reset the source path to empty again. This requires confirmation.
4840
4841@c RET-repeat for @code{directory} is explicitly disabled, but since
4842@c repeating it would be a no-op we do not say that. (thanks to RMS)
4843
4844@item show directories
4845@kindex show directories
4846Print the source path: show which directories it contains.
4847@end table
4848
4849If your source path is cluttered with directories that are no longer of
4850interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4851versions of source. You can correct the situation as follows:
4852
4853@enumerate
4854@item
4855Use @code{directory} with no argument to reset the source path to empty.
4856
4857@item
4858Use @code{directory} with suitable arguments to reinstall the
4859directories you want in the source path. You can add all the
4860directories in one command.
4861@end enumerate
4862
6d2ebf8b 4863@node Machine Code
c906108c 4864@section Source and machine code
15387254 4865@cindex source line and its code address
c906108c
SS
4866
4867You can use the command @code{info line} to map source lines to program
4868addresses (and vice versa), and the command @code{disassemble} to display
4869a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4870mode, the @code{info line} command causes the arrow to point to the
5d161b24 4871line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4872well as hex.
4873
4874@table @code
4875@kindex info line
4876@item info line @var{linespec}
4877Print the starting and ending addresses of the compiled code for
4878source line @var{linespec}. You can specify source lines in any of
4879the ways understood by the @code{list} command (@pxref{List, ,Printing
4880source lines}).
4881@end table
4882
4883For example, we can use @code{info line} to discover the location of
4884the object code for the first line of function
4885@code{m4_changequote}:
4886
d4f3574e
SS
4887@c FIXME: I think this example should also show the addresses in
4888@c symbolic form, as they usually would be displayed.
c906108c 4889@smallexample
96a2c332 4890(@value{GDBP}) info line m4_changequote
c906108c
SS
4891Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4892@end smallexample
4893
4894@noindent
15387254 4895@cindex code address and its source line
c906108c
SS
4896We can also inquire (using @code{*@var{addr}} as the form for
4897@var{linespec}) what source line covers a particular address:
4898@smallexample
4899(@value{GDBP}) info line *0x63ff
4900Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4901@end smallexample
4902
4903@cindex @code{$_} and @code{info line}
15387254 4904@cindex @code{x} command, default address
41afff9a 4905@kindex x@r{(examine), and} info line
c906108c
SS
4906After @code{info line}, the default address for the @code{x} command
4907is changed to the starting address of the line, so that @samp{x/i} is
4908sufficient to begin examining the machine code (@pxref{Memory,
4909,Examining memory}). Also, this address is saved as the value of the
4910convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4911variables}).
4912
4913@table @code
4914@kindex disassemble
4915@cindex assembly instructions
4916@cindex instructions, assembly
4917@cindex machine instructions
4918@cindex listing machine instructions
4919@item disassemble
4920This specialized command dumps a range of memory as machine
4921instructions. The default memory range is the function surrounding the
4922program counter of the selected frame. A single argument to this
4923command is a program counter value; @value{GDBN} dumps the function
4924surrounding this value. Two arguments specify a range of addresses
4925(first inclusive, second exclusive) to dump.
4926@end table
4927
c906108c
SS
4928The following example shows the disassembly of a range of addresses of
4929HP PA-RISC 2.0 code:
4930
4931@smallexample
4932(@value{GDBP}) disas 0x32c4 0x32e4
4933Dump of assembler code from 0x32c4 to 0x32e4:
49340x32c4 <main+204>: addil 0,dp
49350x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49360x32cc <main+212>: ldil 0x3000,r31
49370x32d0 <main+216>: ble 0x3f8(sr4,r31)
49380x32d4 <main+220>: ldo 0(r31),rp
49390x32d8 <main+224>: addil -0x800,dp
49400x32dc <main+228>: ldo 0x588(r1),r26
49410x32e0 <main+232>: ldil 0x3000,r31
4942End of assembler dump.
4943@end smallexample
c906108c
SS
4944
4945Some architectures have more than one commonly-used set of instruction
4946mnemonics or other syntax.
4947
76d17f34
EZ
4948For programs that were dynamically linked and use shared libraries,
4949instructions that call functions or branch to locations in the shared
4950libraries might show a seemingly bogus location---it's actually a
4951location of the relocation table. On some architectures, @value{GDBN}
4952might be able to resolve these to actual function names.
4953
c906108c 4954@table @code
d4f3574e 4955@kindex set disassembly-flavor
d4f3574e
SS
4956@cindex Intel disassembly flavor
4957@cindex AT&T disassembly flavor
4958@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4959Select the instruction set to use when disassembling the
4960program via the @code{disassemble} or @code{x/i} commands.
4961
4962Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4963can set @var{instruction-set} to either @code{intel} or @code{att}.
4964The default is @code{att}, the AT&T flavor used by default by Unix
4965assemblers for x86-based targets.
9c16f35a
EZ
4966
4967@kindex show disassembly-flavor
4968@item show disassembly-flavor
4969Show the current setting of the disassembly flavor.
c906108c
SS
4970@end table
4971
4972
6d2ebf8b 4973@node Data
c906108c
SS
4974@chapter Examining Data
4975
4976@cindex printing data
4977@cindex examining data
4978@kindex print
4979@kindex inspect
4980@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4981@c document because it is nonstandard... Under Epoch it displays in a
4982@c different window or something like that.
4983The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4984command (abbreviated @code{p}), or its synonym @code{inspect}. It
4985evaluates and prints the value of an expression of the language your
4986program is written in (@pxref{Languages, ,Using @value{GDBN} with
4987Different Languages}).
c906108c
SS
4988
4989@table @code
d4f3574e
SS
4990@item print @var{expr}
4991@itemx print /@var{f} @var{expr}
4992@var{expr} is an expression (in the source language). By default the
4993value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4994you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4995@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4996formats}.
4997
4998@item print
4999@itemx print /@var{f}
15387254 5000@cindex reprint the last value
d4f3574e 5001If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
5002@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
5003conveniently inspect the same value in an alternative format.
5004@end table
5005
5006A more low-level way of examining data is with the @code{x} command.
5007It examines data in memory at a specified address and prints it in a
5008specified format. @xref{Memory, ,Examining memory}.
5009
7a292a7a 5010If you are interested in information about types, or about how the
d4f3574e
SS
5011fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5012command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 5013Table}.
c906108c
SS
5014
5015@menu
5016* Expressions:: Expressions
5017* Variables:: Program variables
5018* Arrays:: Artificial arrays
5019* Output Formats:: Output formats
5020* Memory:: Examining memory
5021* Auto Display:: Automatic display
5022* Print Settings:: Print settings
5023* Value History:: Value history
5024* Convenience Vars:: Convenience variables
5025* Registers:: Registers
c906108c 5026* Floating Point Hardware:: Floating point hardware
53c69bd7 5027* Vector Unit:: Vector Unit
721c2651 5028* OS Information:: Auxiliary data provided by operating system
29e57380 5029* Memory Region Attributes:: Memory region attributes
16d9dec6 5030* Dump/Restore Files:: Copy between memory and a file
384ee23f 5031* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
5032* Character Sets:: Debugging programs that use a different
5033 character set than GDB does
09d4efe1 5034* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5035@end menu
5036
6d2ebf8b 5037@node Expressions
c906108c
SS
5038@section Expressions
5039
5040@cindex expressions
5041@code{print} and many other @value{GDBN} commands accept an expression and
5042compute its value. Any kind of constant, variable or operator defined
5043by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5044@value{GDBN}. This includes conditional expressions, function calls,
5045casts, and string constants. It also includes preprocessor macros, if
5046you compiled your program to include this information; see
5047@ref{Compilation}.
c906108c 5048
15387254 5049@cindex arrays in expressions
d4f3574e
SS
5050@value{GDBN} supports array constants in expressions input by
5051the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5052you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5053memory that is @code{malloc}ed in the target program.
c906108c 5054
c906108c
SS
5055Because C is so widespread, most of the expressions shown in examples in
5056this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5057Languages}, for information on how to use expressions in other
5058languages.
5059
5060In this section, we discuss operators that you can use in @value{GDBN}
5061expressions regardless of your programming language.
5062
15387254 5063@cindex casts, in expressions
c906108c
SS
5064Casts are supported in all languages, not just in C, because it is so
5065useful to cast a number into a pointer in order to examine a structure
5066at that address in memory.
5067@c FIXME: casts supported---Mod2 true?
c906108c
SS
5068
5069@value{GDBN} supports these operators, in addition to those common
5070to programming languages:
5071
5072@table @code
5073@item @@
5074@samp{@@} is a binary operator for treating parts of memory as arrays.
5075@xref{Arrays, ,Artificial arrays}, for more information.
5076
5077@item ::
5078@samp{::} allows you to specify a variable in terms of the file or
5079function where it is defined. @xref{Variables, ,Program variables}.
5080
5081@cindex @{@var{type}@}
5082@cindex type casting memory
5083@cindex memory, viewing as typed object
5084@cindex casts, to view memory
5085@item @{@var{type}@} @var{addr}
5086Refers to an object of type @var{type} stored at address @var{addr} in
5087memory. @var{addr} may be any expression whose value is an integer or
5088pointer (but parentheses are required around binary operators, just as in
5089a cast). This construct is allowed regardless of what kind of data is
5090normally supposed to reside at @var{addr}.
5091@end table
5092
6d2ebf8b 5093@node Variables
c906108c
SS
5094@section Program variables
5095
5096The most common kind of expression to use is the name of a variable
5097in your program.
5098
5099Variables in expressions are understood in the selected stack frame
5100(@pxref{Selection, ,Selecting a frame}); they must be either:
5101
5102@itemize @bullet
5103@item
5104global (or file-static)
5105@end itemize
5106
5d161b24 5107@noindent or
c906108c
SS
5108
5109@itemize @bullet
5110@item
5111visible according to the scope rules of the
5112programming language from the point of execution in that frame
5d161b24 5113@end itemize
c906108c
SS
5114
5115@noindent This means that in the function
5116
474c8240 5117@smallexample
c906108c
SS
5118foo (a)
5119 int a;
5120@{
5121 bar (a);
5122 @{
5123 int b = test ();
5124 bar (b);
5125 @}
5126@}
474c8240 5127@end smallexample
c906108c
SS
5128
5129@noindent
5130you can examine and use the variable @code{a} whenever your program is
5131executing within the function @code{foo}, but you can only use or
5132examine the variable @code{b} while your program is executing inside
5133the block where @code{b} is declared.
5134
5135@cindex variable name conflict
5136There is an exception: you can refer to a variable or function whose
5137scope is a single source file even if the current execution point is not
5138in this file. But it is possible to have more than one such variable or
5139function with the same name (in different source files). If that
5140happens, referring to that name has unpredictable effects. If you wish,
5141you can specify a static variable in a particular function or file,
15387254 5142using the colon-colon (@code{::}) notation:
c906108c 5143
d4f3574e 5144@cindex colon-colon, context for variables/functions
c906108c
SS
5145@iftex
5146@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5147@cindex @code{::}, context for variables/functions
c906108c 5148@end iftex
474c8240 5149@smallexample
c906108c
SS
5150@var{file}::@var{variable}
5151@var{function}::@var{variable}
474c8240 5152@end smallexample
c906108c
SS
5153
5154@noindent
5155Here @var{file} or @var{function} is the name of the context for the
5156static @var{variable}. In the case of file names, you can use quotes to
5157make sure @value{GDBN} parses the file name as a single word---for example,
5158to print a global value of @code{x} defined in @file{f2.c}:
5159
474c8240 5160@smallexample
c906108c 5161(@value{GDBP}) p 'f2.c'::x
474c8240 5162@end smallexample
c906108c 5163
b37052ae 5164@cindex C@t{++} scope resolution
c906108c 5165This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5166use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5167scope resolution operator in @value{GDBN} expressions.
5168@c FIXME: Um, so what happens in one of those rare cases where it's in
5169@c conflict?? --mew
c906108c
SS
5170
5171@cindex wrong values
5172@cindex variable values, wrong
15387254
EZ
5173@cindex function entry/exit, wrong values of variables
5174@cindex optimized code, wrong values of variables
c906108c
SS
5175@quotation
5176@emph{Warning:} Occasionally, a local variable may appear to have the
5177wrong value at certain points in a function---just after entry to a new
5178scope, and just before exit.
5179@end quotation
5180You may see this problem when you are stepping by machine instructions.
5181This is because, on most machines, it takes more than one instruction to
5182set up a stack frame (including local variable definitions); if you are
5183stepping by machine instructions, variables may appear to have the wrong
5184values until the stack frame is completely built. On exit, it usually
5185also takes more than one machine instruction to destroy a stack frame;
5186after you begin stepping through that group of instructions, local
5187variable definitions may be gone.
5188
5189This may also happen when the compiler does significant optimizations.
5190To be sure of always seeing accurate values, turn off all optimization
5191when compiling.
5192
d4f3574e
SS
5193@cindex ``No symbol "foo" in current context''
5194Another possible effect of compiler optimizations is to optimize
5195unused variables out of existence, or assign variables to registers (as
5196opposed to memory addresses). Depending on the support for such cases
5197offered by the debug info format used by the compiler, @value{GDBN}
5198might not be able to display values for such local variables. If that
5199happens, @value{GDBN} will print a message like this:
5200
474c8240 5201@smallexample
d4f3574e 5202No symbol "foo" in current context.
474c8240 5203@end smallexample
d4f3574e
SS
5204
5205To solve such problems, either recompile without optimizations, or use a
5206different debug info format, if the compiler supports several such
15387254 5207formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5208usually supports the @option{-gstabs+} option. @option{-gstabs+}
5209produces debug info in a format that is superior to formats such as
5210COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5211an effective form for debug info. @xref{Debugging Options,,Options
5212for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5213@xref{C, , Debugging C++}, for more info about debug info formats
5214that are best suited to C@t{++} programs.
d4f3574e 5215
ab1adacd
EZ
5216If you ask to print an object whose contents are unknown to
5217@value{GDBN}, e.g., because its data type is not completely specified
5218by the debug information, @value{GDBN} will say @samp{<incomplete
5219type>}. @xref{Symbols, incomplete type}, for more about this.
5220
6d2ebf8b 5221@node Arrays
c906108c
SS
5222@section Artificial arrays
5223
5224@cindex artificial array
15387254 5225@cindex arrays
41afff9a 5226@kindex @@@r{, referencing memory as an array}
c906108c
SS
5227It is often useful to print out several successive objects of the
5228same type in memory; a section of an array, or an array of
5229dynamically determined size for which only a pointer exists in the
5230program.
5231
5232You can do this by referring to a contiguous span of memory as an
5233@dfn{artificial array}, using the binary operator @samp{@@}. The left
5234operand of @samp{@@} should be the first element of the desired array
5235and be an individual object. The right operand should be the desired length
5236of the array. The result is an array value whose elements are all of
5237the type of the left argument. The first element is actually the left
5238argument; the second element comes from bytes of memory immediately
5239following those that hold the first element, and so on. Here is an
5240example. If a program says
5241
474c8240 5242@smallexample
c906108c 5243int *array = (int *) malloc (len * sizeof (int));
474c8240 5244@end smallexample
c906108c
SS
5245
5246@noindent
5247you can print the contents of @code{array} with
5248
474c8240 5249@smallexample
c906108c 5250p *array@@len
474c8240 5251@end smallexample
c906108c
SS
5252
5253The left operand of @samp{@@} must reside in memory. Array values made
5254with @samp{@@} in this way behave just like other arrays in terms of
5255subscripting, and are coerced to pointers when used in expressions.
5256Artificial arrays most often appear in expressions via the value history
5257(@pxref{Value History, ,Value history}), after printing one out.
5258
5259Another way to create an artificial array is to use a cast.
5260This re-interprets a value as if it were an array.
5261The value need not be in memory:
474c8240 5262@smallexample
c906108c
SS
5263(@value{GDBP}) p/x (short[2])0x12345678
5264$1 = @{0x1234, 0x5678@}
474c8240 5265@end smallexample
c906108c
SS
5266
5267As a convenience, if you leave the array length out (as in
c3f6f71d 5268@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5269the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5270@smallexample
c906108c
SS
5271(@value{GDBP}) p/x (short[])0x12345678
5272$2 = @{0x1234, 0x5678@}
474c8240 5273@end smallexample
c906108c
SS
5274
5275Sometimes the artificial array mechanism is not quite enough; in
5276moderately complex data structures, the elements of interest may not
5277actually be adjacent---for example, if you are interested in the values
5278of pointers in an array. One useful work-around in this situation is
5279to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5280variables}) as a counter in an expression that prints the first
5281interesting value, and then repeat that expression via @key{RET}. For
5282instance, suppose you have an array @code{dtab} of pointers to
5283structures, and you are interested in the values of a field @code{fv}
5284in each structure. Here is an example of what you might type:
5285
474c8240 5286@smallexample
c906108c
SS
5287set $i = 0
5288p dtab[$i++]->fv
5289@key{RET}
5290@key{RET}
5291@dots{}
474c8240 5292@end smallexample
c906108c 5293
6d2ebf8b 5294@node Output Formats
c906108c
SS
5295@section Output formats
5296
5297@cindex formatted output
5298@cindex output formats
5299By default, @value{GDBN} prints a value according to its data type. Sometimes
5300this is not what you want. For example, you might want to print a number
5301in hex, or a pointer in decimal. Or you might want to view data in memory
5302at a certain address as a character string or as an instruction. To do
5303these things, specify an @dfn{output format} when you print a value.
5304
5305The simplest use of output formats is to say how to print a value
5306already computed. This is done by starting the arguments of the
5307@code{print} command with a slash and a format letter. The format
5308letters supported are:
5309
5310@table @code
5311@item x
5312Regard the bits of the value as an integer, and print the integer in
5313hexadecimal.
5314
5315@item d
5316Print as integer in signed decimal.
5317
5318@item u
5319Print as integer in unsigned decimal.
5320
5321@item o
5322Print as integer in octal.
5323
5324@item t
5325Print as integer in binary. The letter @samp{t} stands for ``two''.
5326@footnote{@samp{b} cannot be used because these format letters are also
5327used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5328see @ref{Memory,,Examining memory}.}
c906108c
SS
5329
5330@item a
5331@cindex unknown address, locating
3d67e040 5332@cindex locate address
c906108c
SS
5333Print as an address, both absolute in hexadecimal and as an offset from
5334the nearest preceding symbol. You can use this format used to discover
5335where (in what function) an unknown address is located:
5336
474c8240 5337@smallexample
c906108c
SS
5338(@value{GDBP}) p/a 0x54320
5339$3 = 0x54320 <_initialize_vx+396>
474c8240 5340@end smallexample
c906108c 5341
3d67e040
EZ
5342@noindent
5343The command @code{info symbol 0x54320} yields similar results.
5344@xref{Symbols, info symbol}.
5345
c906108c 5346@item c
51274035
EZ
5347Regard as an integer and print it as a character constant. This
5348prints both the numerical value and its character representation. The
5349character representation is replaced with the octal escape @samp{\nnn}
5350for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5351
5352@item f
5353Regard the bits of the value as a floating point number and print
5354using typical floating point syntax.
5355@end table
5356
5357For example, to print the program counter in hex (@pxref{Registers}), type
5358
474c8240 5359@smallexample
c906108c 5360p/x $pc
474c8240 5361@end smallexample
c906108c
SS
5362
5363@noindent
5364Note that no space is required before the slash; this is because command
5365names in @value{GDBN} cannot contain a slash.
5366
5367To reprint the last value in the value history with a different format,
5368you can use the @code{print} command with just a format and no
5369expression. For example, @samp{p/x} reprints the last value in hex.
5370
6d2ebf8b 5371@node Memory
c906108c
SS
5372@section Examining memory
5373
5374You can use the command @code{x} (for ``examine'') to examine memory in
5375any of several formats, independently of your program's data types.
5376
5377@cindex examining memory
5378@table @code
41afff9a 5379@kindex x @r{(examine memory)}
c906108c
SS
5380@item x/@var{nfu} @var{addr}
5381@itemx x @var{addr}
5382@itemx x
5383Use the @code{x} command to examine memory.
5384@end table
5385
5386@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5387much memory to display and how to format it; @var{addr} is an
5388expression giving the address where you want to start displaying memory.
5389If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5390Several commands set convenient defaults for @var{addr}.
5391
5392@table @r
5393@item @var{n}, the repeat count
5394The repeat count is a decimal integer; the default is 1. It specifies
5395how much memory (counting by units @var{u}) to display.
5396@c This really is **decimal**; unaffected by 'set radix' as of GDB
5397@c 4.1.2.
5398
5399@item @var{f}, the display format
51274035
EZ
5400The display format is one of the formats used by @code{print}
5401(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5402@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5403@samp{i} (for machine instructions). The default is @samp{x}
5404(hexadecimal) initially. The default changes each time you use either
5405@code{x} or @code{print}.
c906108c
SS
5406
5407@item @var{u}, the unit size
5408The unit size is any of
5409
5410@table @code
5411@item b
5412Bytes.
5413@item h
5414Halfwords (two bytes).
5415@item w
5416Words (four bytes). This is the initial default.
5417@item g
5418Giant words (eight bytes).
5419@end table
5420
5421Each time you specify a unit size with @code{x}, that size becomes the
5422default unit the next time you use @code{x}. (For the @samp{s} and
5423@samp{i} formats, the unit size is ignored and is normally not written.)
5424
5425@item @var{addr}, starting display address
5426@var{addr} is the address where you want @value{GDBN} to begin displaying
5427memory. The expression need not have a pointer value (though it may);
5428it is always interpreted as an integer address of a byte of memory.
5429@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5430@var{addr} is usually just after the last address examined---but several
5431other commands also set the default address: @code{info breakpoints} (to
5432the address of the last breakpoint listed), @code{info line} (to the
5433starting address of a line), and @code{print} (if you use it to display
5434a value from memory).
5435@end table
5436
5437For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5438(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5439starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5440words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5441@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5442
5443Since the letters indicating unit sizes are all distinct from the
5444letters specifying output formats, you do not have to remember whether
5445unit size or format comes first; either order works. The output
5446specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5447(However, the count @var{n} must come first; @samp{wx4} does not work.)
5448
5449Even though the unit size @var{u} is ignored for the formats @samp{s}
5450and @samp{i}, you might still want to use a count @var{n}; for example,
5451@samp{3i} specifies that you want to see three machine instructions,
5452including any operands. The command @code{disassemble} gives an
d4f3574e 5453alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5454Code,,Source and machine code}.
5455
5456All the defaults for the arguments to @code{x} are designed to make it
5457easy to continue scanning memory with minimal specifications each time
5458you use @code{x}. For example, after you have inspected three machine
5459instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5460with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5461the repeat count @var{n} is used again; the other arguments default as
5462for successive uses of @code{x}.
5463
5464@cindex @code{$_}, @code{$__}, and value history
5465The addresses and contents printed by the @code{x} command are not saved
5466in the value history because there is often too much of them and they
5467would get in the way. Instead, @value{GDBN} makes these values available for
5468subsequent use in expressions as values of the convenience variables
5469@code{$_} and @code{$__}. After an @code{x} command, the last address
5470examined is available for use in expressions in the convenience variable
5471@code{$_}. The contents of that address, as examined, are available in
5472the convenience variable @code{$__}.
5473
5474If the @code{x} command has a repeat count, the address and contents saved
5475are from the last memory unit printed; this is not the same as the last
5476address printed if several units were printed on the last line of output.
5477
09d4efe1
EZ
5478@cindex remote memory comparison
5479@cindex verify remote memory image
5480When you are debugging a program running on a remote target machine
5481(@pxref{Remote}), you may wish to verify the program's image in the
5482remote machine's memory against the executable file you downloaded to
5483the target. The @code{compare-sections} command is provided for such
5484situations.
5485
5486@table @code
5487@kindex compare-sections
5488@item compare-sections @r{[}@var{section-name}@r{]}
5489Compare the data of a loadable section @var{section-name} in the
5490executable file of the program being debugged with the same section in
5491the remote machine's memory, and report any mismatches. With no
5492arguments, compares all loadable sections. This command's
5493availability depends on the target's support for the @code{"qCRC"}
5494remote request.
5495@end table
5496
6d2ebf8b 5497@node Auto Display
c906108c
SS
5498@section Automatic display
5499@cindex automatic display
5500@cindex display of expressions
5501
5502If you find that you want to print the value of an expression frequently
5503(to see how it changes), you might want to add it to the @dfn{automatic
5504display list} so that @value{GDBN} prints its value each time your program stops.
5505Each expression added to the list is given a number to identify it;
5506to remove an expression from the list, you specify that number.
5507The automatic display looks like this:
5508
474c8240 5509@smallexample
c906108c
SS
55102: foo = 38
55113: bar[5] = (struct hack *) 0x3804
474c8240 5512@end smallexample
c906108c
SS
5513
5514@noindent
5515This display shows item numbers, expressions and their current values. As with
5516displays you request manually using @code{x} or @code{print}, you can
5517specify the output format you prefer; in fact, @code{display} decides
5518whether to use @code{print} or @code{x} depending on how elaborate your
5519format specification is---it uses @code{x} if you specify a unit size,
5520or one of the two formats (@samp{i} and @samp{s}) that are only
5521supported by @code{x}; otherwise it uses @code{print}.
5522
5523@table @code
5524@kindex display
d4f3574e
SS
5525@item display @var{expr}
5526Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5527each time your program stops. @xref{Expressions, ,Expressions}.
5528
5529@code{display} does not repeat if you press @key{RET} again after using it.
5530
d4f3574e 5531@item display/@var{fmt} @var{expr}
c906108c 5532For @var{fmt} specifying only a display format and not a size or
d4f3574e 5533count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5534arrange to display it each time in the specified format @var{fmt}.
5535@xref{Output Formats,,Output formats}.
5536
5537@item display/@var{fmt} @var{addr}
5538For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5539number of units, add the expression @var{addr} as a memory address to
5540be examined each time your program stops. Examining means in effect
5541doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5542@end table
5543
5544For example, @samp{display/i $pc} can be helpful, to see the machine
5545instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5546is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5547
5548@table @code
5549@kindex delete display
5550@kindex undisplay
5551@item undisplay @var{dnums}@dots{}
5552@itemx delete display @var{dnums}@dots{}
5553Remove item numbers @var{dnums} from the list of expressions to display.
5554
5555@code{undisplay} does not repeat if you press @key{RET} after using it.
5556(Otherwise you would just get the error @samp{No display number @dots{}}.)
5557
5558@kindex disable display
5559@item disable display @var{dnums}@dots{}
5560Disable the display of item numbers @var{dnums}. A disabled display
5561item is not printed automatically, but is not forgotten. It may be
5562enabled again later.
5563
5564@kindex enable display
5565@item enable display @var{dnums}@dots{}
5566Enable display of item numbers @var{dnums}. It becomes effective once
5567again in auto display of its expression, until you specify otherwise.
5568
5569@item display
5570Display the current values of the expressions on the list, just as is
5571done when your program stops.
5572
5573@kindex info display
5574@item info display
5575Print the list of expressions previously set up to display
5576automatically, each one with its item number, but without showing the
5577values. This includes disabled expressions, which are marked as such.
5578It also includes expressions which would not be displayed right now
5579because they refer to automatic variables not currently available.
5580@end table
5581
15387254 5582@cindex display disabled out of scope
c906108c
SS
5583If a display expression refers to local variables, then it does not make
5584sense outside the lexical context for which it was set up. Such an
5585expression is disabled when execution enters a context where one of its
5586variables is not defined. For example, if you give the command
5587@code{display last_char} while inside a function with an argument
5588@code{last_char}, @value{GDBN} displays this argument while your program
5589continues to stop inside that function. When it stops elsewhere---where
5590there is no variable @code{last_char}---the display is disabled
5591automatically. The next time your program stops where @code{last_char}
5592is meaningful, you can enable the display expression once again.
5593
6d2ebf8b 5594@node Print Settings
c906108c
SS
5595@section Print settings
5596
5597@cindex format options
5598@cindex print settings
5599@value{GDBN} provides the following ways to control how arrays, structures,
5600and symbols are printed.
5601
5602@noindent
5603These settings are useful for debugging programs in any language:
5604
5605@table @code
4644b6e3 5606@kindex set print
c906108c
SS
5607@item set print address
5608@itemx set print address on
4644b6e3 5609@cindex print/don't print memory addresses
c906108c
SS
5610@value{GDBN} prints memory addresses showing the location of stack
5611traces, structure values, pointer values, breakpoints, and so forth,
5612even when it also displays the contents of those addresses. The default
5613is @code{on}. For example, this is what a stack frame display looks like with
5614@code{set print address on}:
5615
5616@smallexample
5617@group
5618(@value{GDBP}) f
5619#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5620 at input.c:530
5621530 if (lquote != def_lquote)
5622@end group
5623@end smallexample
5624
5625@item set print address off
5626Do not print addresses when displaying their contents. For example,
5627this is the same stack frame displayed with @code{set print address off}:
5628
5629@smallexample
5630@group
5631(@value{GDBP}) set print addr off
5632(@value{GDBP}) f
5633#0 set_quotes (lq="<<", rq=">>") at input.c:530
5634530 if (lquote != def_lquote)
5635@end group
5636@end smallexample
5637
5638You can use @samp{set print address off} to eliminate all machine
5639dependent displays from the @value{GDBN} interface. For example, with
5640@code{print address off}, you should get the same text for backtraces on
5641all machines---whether or not they involve pointer arguments.
5642
4644b6e3 5643@kindex show print
c906108c
SS
5644@item show print address
5645Show whether or not addresses are to be printed.
5646@end table
5647
5648When @value{GDBN} prints a symbolic address, it normally prints the
5649closest earlier symbol plus an offset. If that symbol does not uniquely
5650identify the address (for example, it is a name whose scope is a single
5651source file), you may need to clarify. One way to do this is with
5652@code{info line}, for example @samp{info line *0x4537}. Alternately,
5653you can set @value{GDBN} to print the source file and line number when
5654it prints a symbolic address:
5655
5656@table @code
c906108c 5657@item set print symbol-filename on
9c16f35a
EZ
5658@cindex source file and line of a symbol
5659@cindex symbol, source file and line
c906108c
SS
5660Tell @value{GDBN} to print the source file name and line number of a
5661symbol in the symbolic form of an address.
5662
5663@item set print symbol-filename off
5664Do not print source file name and line number of a symbol. This is the
5665default.
5666
c906108c
SS
5667@item show print symbol-filename
5668Show whether or not @value{GDBN} will print the source file name and
5669line number of a symbol in the symbolic form of an address.
5670@end table
5671
5672Another situation where it is helpful to show symbol filenames and line
5673numbers is when disassembling code; @value{GDBN} shows you the line
5674number and source file that corresponds to each instruction.
5675
5676Also, you may wish to see the symbolic form only if the address being
5677printed is reasonably close to the closest earlier symbol:
5678
5679@table @code
c906108c 5680@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5681@cindex maximum value for offset of closest symbol
c906108c
SS
5682Tell @value{GDBN} to only display the symbolic form of an address if the
5683offset between the closest earlier symbol and the address is less than
5d161b24 5684@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5685to always print the symbolic form of an address if any symbol precedes it.
5686
c906108c
SS
5687@item show print max-symbolic-offset
5688Ask how large the maximum offset is that @value{GDBN} prints in a
5689symbolic address.
5690@end table
5691
5692@cindex wild pointer, interpreting
5693@cindex pointer, finding referent
5694If you have a pointer and you are not sure where it points, try
5695@samp{set print symbol-filename on}. Then you can determine the name
5696and source file location of the variable where it points, using
5697@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5698For example, here @value{GDBN} shows that a variable @code{ptt} points
5699at another variable @code{t}, defined in @file{hi2.c}:
5700
474c8240 5701@smallexample
c906108c
SS
5702(@value{GDBP}) set print symbol-filename on
5703(@value{GDBP}) p/a ptt
5704$4 = 0xe008 <t in hi2.c>
474c8240 5705@end smallexample
c906108c
SS
5706
5707@quotation
5708@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5709does not show the symbol name and filename of the referent, even with
5710the appropriate @code{set print} options turned on.
5711@end quotation
5712
5713Other settings control how different kinds of objects are printed:
5714
5715@table @code
c906108c
SS
5716@item set print array
5717@itemx set print array on
4644b6e3 5718@cindex pretty print arrays
c906108c
SS
5719Pretty print arrays. This format is more convenient to read,
5720but uses more space. The default is off.
5721
5722@item set print array off
5723Return to compressed format for arrays.
5724
c906108c
SS
5725@item show print array
5726Show whether compressed or pretty format is selected for displaying
5727arrays.
5728
3c9c013a
JB
5729@cindex print array indexes
5730@item set print array-indexes
5731@itemx set print array-indexes on
5732Print the index of each element when displaying arrays. May be more
5733convenient to locate a given element in the array or quickly find the
5734index of a given element in that printed array. The default is off.
5735
5736@item set print array-indexes off
5737Stop printing element indexes when displaying arrays.
5738
5739@item show print array-indexes
5740Show whether the index of each element is printed when displaying
5741arrays.
5742
c906108c 5743@item set print elements @var{number-of-elements}
4644b6e3 5744@cindex number of array elements to print
9c16f35a 5745@cindex limit on number of printed array elements
c906108c
SS
5746Set a limit on how many elements of an array @value{GDBN} will print.
5747If @value{GDBN} is printing a large array, it stops printing after it has
5748printed the number of elements set by the @code{set print elements} command.
5749This limit also applies to the display of strings.
d4f3574e 5750When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5751Setting @var{number-of-elements} to zero means that the printing is unlimited.
5752
c906108c
SS
5753@item show print elements
5754Display the number of elements of a large array that @value{GDBN} will print.
5755If the number is 0, then the printing is unlimited.
5756
9c16f35a
EZ
5757@item set print repeats
5758@cindex repeated array elements
5759Set the threshold for suppressing display of repeated array
5760elelments. When the number of consecutive identical elements of an
5761array exceeds the threshold, @value{GDBN} prints the string
5762@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5763identical repetitions, instead of displaying the identical elements
5764themselves. Setting the threshold to zero will cause all elements to
5765be individually printed. The default threshold is 10.
5766
5767@item show print repeats
5768Display the current threshold for printing repeated identical
5769elements.
5770
c906108c 5771@item set print null-stop
4644b6e3 5772@cindex @sc{null} elements in arrays
c906108c 5773Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5774@sc{null} is encountered. This is useful when large arrays actually
c906108c 5775contain only short strings.
d4f3574e 5776The default is off.
c906108c 5777
9c16f35a
EZ
5778@item show print null-stop
5779Show whether @value{GDBN} stops printing an array on the first
5780@sc{null} character.
5781
c906108c 5782@item set print pretty on
9c16f35a
EZ
5783@cindex print structures in indented form
5784@cindex indentation in structure display
5d161b24 5785Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5786per line, like this:
5787
5788@smallexample
5789@group
5790$1 = @{
5791 next = 0x0,
5792 flags = @{
5793 sweet = 1,
5794 sour = 1
5795 @},
5796 meat = 0x54 "Pork"
5797@}
5798@end group
5799@end smallexample
5800
5801@item set print pretty off
5802Cause @value{GDBN} to print structures in a compact format, like this:
5803
5804@smallexample
5805@group
5806$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5807meat = 0x54 "Pork"@}
5808@end group
5809@end smallexample
5810
5811@noindent
5812This is the default format.
5813
c906108c
SS
5814@item show print pretty
5815Show which format @value{GDBN} is using to print structures.
5816
c906108c 5817@item set print sevenbit-strings on
4644b6e3
EZ
5818@cindex eight-bit characters in strings
5819@cindex octal escapes in strings
c906108c
SS
5820Print using only seven-bit characters; if this option is set,
5821@value{GDBN} displays any eight-bit characters (in strings or
5822character values) using the notation @code{\}@var{nnn}. This setting is
5823best if you are working in English (@sc{ascii}) and you use the
5824high-order bit of characters as a marker or ``meta'' bit.
5825
5826@item set print sevenbit-strings off
5827Print full eight-bit characters. This allows the use of more
5828international character sets, and is the default.
5829
c906108c
SS
5830@item show print sevenbit-strings
5831Show whether or not @value{GDBN} is printing only seven-bit characters.
5832
c906108c 5833@item set print union on
4644b6e3 5834@cindex unions in structures, printing
9c16f35a
EZ
5835Tell @value{GDBN} to print unions which are contained in structures
5836and other unions. This is the default setting.
c906108c
SS
5837
5838@item set print union off
9c16f35a
EZ
5839Tell @value{GDBN} not to print unions which are contained in
5840structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5841instead.
c906108c 5842
c906108c
SS
5843@item show print union
5844Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5845structures and other unions.
c906108c
SS
5846
5847For example, given the declarations
5848
5849@smallexample
5850typedef enum @{Tree, Bug@} Species;
5851typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5852typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5853 Bug_forms;
5854
5855struct thing @{
5856 Species it;
5857 union @{
5858 Tree_forms tree;
5859 Bug_forms bug;
5860 @} form;
5861@};
5862
5863struct thing foo = @{Tree, @{Acorn@}@};
5864@end smallexample
5865
5866@noindent
5867with @code{set print union on} in effect @samp{p foo} would print
5868
5869@smallexample
5870$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5871@end smallexample
5872
5873@noindent
5874and with @code{set print union off} in effect it would print
5875
5876@smallexample
5877$1 = @{it = Tree, form = @{...@}@}
5878@end smallexample
9c16f35a
EZ
5879
5880@noindent
5881@code{set print union} affects programs written in C-like languages
5882and in Pascal.
c906108c
SS
5883@end table
5884
c906108c
SS
5885@need 1000
5886@noindent
b37052ae 5887These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5888
5889@table @code
4644b6e3 5890@cindex demangling C@t{++} names
c906108c
SS
5891@item set print demangle
5892@itemx set print demangle on
b37052ae 5893Print C@t{++} names in their source form rather than in the encoded
c906108c 5894(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5895linkage. The default is on.
c906108c 5896
c906108c 5897@item show print demangle
b37052ae 5898Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5899
c906108c
SS
5900@item set print asm-demangle
5901@itemx set print asm-demangle on
b37052ae 5902Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5903in assembler code printouts such as instruction disassemblies.
5904The default is off.
5905
c906108c 5906@item show print asm-demangle
b37052ae 5907Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5908or demangled form.
5909
b37052ae
EZ
5910@cindex C@t{++} symbol decoding style
5911@cindex symbol decoding style, C@t{++}
a8f24a35 5912@kindex set demangle-style
c906108c
SS
5913@item set demangle-style @var{style}
5914Choose among several encoding schemes used by different compilers to
b37052ae 5915represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5916
5917@table @code
5918@item auto
5919Allow @value{GDBN} to choose a decoding style by inspecting your program.
5920
5921@item gnu
b37052ae 5922Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5923This is the default.
c906108c
SS
5924
5925@item hp
b37052ae 5926Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5927
5928@item lucid
b37052ae 5929Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5930
5931@item arm
b37052ae 5932Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5933@strong{Warning:} this setting alone is not sufficient to allow
5934debugging @code{cfront}-generated executables. @value{GDBN} would
5935require further enhancement to permit that.
5936
5937@end table
5938If you omit @var{style}, you will see a list of possible formats.
5939
c906108c 5940@item show demangle-style
b37052ae 5941Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5942
c906108c
SS
5943@item set print object
5944@itemx set print object on
4644b6e3 5945@cindex derived type of an object, printing
9c16f35a 5946@cindex display derived types
c906108c
SS
5947When displaying a pointer to an object, identify the @emph{actual}
5948(derived) type of the object rather than the @emph{declared} type, using
5949the virtual function table.
5950
5951@item set print object off
5952Display only the declared type of objects, without reference to the
5953virtual function table. This is the default setting.
5954
c906108c
SS
5955@item show print object
5956Show whether actual, or declared, object types are displayed.
5957
c906108c
SS
5958@item set print static-members
5959@itemx set print static-members on
4644b6e3 5960@cindex static members of C@t{++} objects
b37052ae 5961Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5962
5963@item set print static-members off
b37052ae 5964Do not print static members when displaying a C@t{++} object.
c906108c 5965
c906108c 5966@item show print static-members
9c16f35a
EZ
5967Show whether C@t{++} static members are printed or not.
5968
5969@item set print pascal_static-members
5970@itemx set print pascal_static-members on
5971@cindex static members of Pacal objects
5972@cindex Pacal objects, static members display
5973Print static members when displaying a Pascal object. The default is on.
5974
5975@item set print pascal_static-members off
5976Do not print static members when displaying a Pascal object.
5977
5978@item show print pascal_static-members
5979Show whether Pascal static members are printed or not.
c906108c
SS
5980
5981@c These don't work with HP ANSI C++ yet.
c906108c
SS
5982@item set print vtbl
5983@itemx set print vtbl on
4644b6e3 5984@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5985@cindex virtual functions (C@t{++}) display
5986@cindex VTBL display
b37052ae 5987Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5988(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5989ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5990
5991@item set print vtbl off
b37052ae 5992Do not pretty print C@t{++} virtual function tables.
c906108c 5993
c906108c 5994@item show print vtbl
b37052ae 5995Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5996@end table
c906108c 5997
6d2ebf8b 5998@node Value History
c906108c
SS
5999@section Value history
6000
6001@cindex value history
9c16f35a 6002@cindex history of values printed by @value{GDBN}
5d161b24
DB
6003Values printed by the @code{print} command are saved in the @value{GDBN}
6004@dfn{value history}. This allows you to refer to them in other expressions.
6005Values are kept until the symbol table is re-read or discarded
6006(for example with the @code{file} or @code{symbol-file} commands).
6007When the symbol table changes, the value history is discarded,
6008since the values may contain pointers back to the types defined in the
c906108c
SS
6009symbol table.
6010
6011@cindex @code{$}
6012@cindex @code{$$}
6013@cindex history number
6014The values printed are given @dfn{history numbers} by which you can
6015refer to them. These are successive integers starting with one.
6016@code{print} shows you the history number assigned to a value by
6017printing @samp{$@var{num} = } before the value; here @var{num} is the
6018history number.
6019
6020To refer to any previous value, use @samp{$} followed by the value's
6021history number. The way @code{print} labels its output is designed to
6022remind you of this. Just @code{$} refers to the most recent value in
6023the history, and @code{$$} refers to the value before that.
6024@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6025is the value just prior to @code{$$}, @code{$$1} is equivalent to
6026@code{$$}, and @code{$$0} is equivalent to @code{$}.
6027
6028For example, suppose you have just printed a pointer to a structure and
6029want to see the contents of the structure. It suffices to type
6030
474c8240 6031@smallexample
c906108c 6032p *$
474c8240 6033@end smallexample
c906108c
SS
6034
6035If you have a chain of structures where the component @code{next} points
6036to the next one, you can print the contents of the next one with this:
6037
474c8240 6038@smallexample
c906108c 6039p *$.next
474c8240 6040@end smallexample
c906108c
SS
6041
6042@noindent
6043You can print successive links in the chain by repeating this
6044command---which you can do by just typing @key{RET}.
6045
6046Note that the history records values, not expressions. If the value of
6047@code{x} is 4 and you type these commands:
6048
474c8240 6049@smallexample
c906108c
SS
6050print x
6051set x=5
474c8240 6052@end smallexample
c906108c
SS
6053
6054@noindent
6055then the value recorded in the value history by the @code{print} command
6056remains 4 even though the value of @code{x} has changed.
6057
6058@table @code
6059@kindex show values
6060@item show values
6061Print the last ten values in the value history, with their item numbers.
6062This is like @samp{p@ $$9} repeated ten times, except that @code{show
6063values} does not change the history.
6064
6065@item show values @var{n}
6066Print ten history values centered on history item number @var{n}.
6067
6068@item show values +
6069Print ten history values just after the values last printed. If no more
6070values are available, @code{show values +} produces no display.
6071@end table
6072
6073Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6074same effect as @samp{show values +}.
6075
6d2ebf8b 6076@node Convenience Vars
c906108c
SS
6077@section Convenience variables
6078
6079@cindex convenience variables
9c16f35a 6080@cindex user-defined variables
c906108c
SS
6081@value{GDBN} provides @dfn{convenience variables} that you can use within
6082@value{GDBN} to hold on to a value and refer to it later. These variables
6083exist entirely within @value{GDBN}; they are not part of your program, and
6084setting a convenience variable has no direct effect on further execution
6085of your program. That is why you can use them freely.
6086
6087Convenience variables are prefixed with @samp{$}. Any name preceded by
6088@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6089the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6090(Value history references, in contrast, are @emph{numbers} preceded
6091by @samp{$}. @xref{Value History, ,Value history}.)
6092
6093You can save a value in a convenience variable with an assignment
6094expression, just as you would set a variable in your program.
6095For example:
6096
474c8240 6097@smallexample
c906108c 6098set $foo = *object_ptr
474c8240 6099@end smallexample
c906108c
SS
6100
6101@noindent
6102would save in @code{$foo} the value contained in the object pointed to by
6103@code{object_ptr}.
6104
6105Using a convenience variable for the first time creates it, but its
6106value is @code{void} until you assign a new value. You can alter the
6107value with another assignment at any time.
6108
6109Convenience variables have no fixed types. You can assign a convenience
6110variable any type of value, including structures and arrays, even if
6111that variable already has a value of a different type. The convenience
6112variable, when used as an expression, has the type of its current value.
6113
6114@table @code
6115@kindex show convenience
9c16f35a 6116@cindex show all user variables
c906108c
SS
6117@item show convenience
6118Print a list of convenience variables used so far, and their values.
d4f3574e 6119Abbreviated @code{show conv}.
c906108c
SS
6120@end table
6121
6122One of the ways to use a convenience variable is as a counter to be
6123incremented or a pointer to be advanced. For example, to print
6124a field from successive elements of an array of structures:
6125
474c8240 6126@smallexample
c906108c
SS
6127set $i = 0
6128print bar[$i++]->contents
474c8240 6129@end smallexample
c906108c 6130
d4f3574e
SS
6131@noindent
6132Repeat that command by typing @key{RET}.
c906108c
SS
6133
6134Some convenience variables are created automatically by @value{GDBN} and given
6135values likely to be useful.
6136
6137@table @code
41afff9a 6138@vindex $_@r{, convenience variable}
c906108c
SS
6139@item $_
6140The variable @code{$_} is automatically set by the @code{x} command to
6141the last address examined (@pxref{Memory, ,Examining memory}). Other
6142commands which provide a default address for @code{x} to examine also
6143set @code{$_} to that address; these commands include @code{info line}
6144and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6145except when set by the @code{x} command, in which case it is a pointer
6146to the type of @code{$__}.
6147
41afff9a 6148@vindex $__@r{, convenience variable}
c906108c
SS
6149@item $__
6150The variable @code{$__} is automatically set by the @code{x} command
6151to the value found in the last address examined. Its type is chosen
6152to match the format in which the data was printed.
6153
6154@item $_exitcode
41afff9a 6155@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6156The variable @code{$_exitcode} is automatically set to the exit code when
6157the program being debugged terminates.
6158@end table
6159
53a5351d
JM
6160On HP-UX systems, if you refer to a function or variable name that
6161begins with a dollar sign, @value{GDBN} searches for a user or system
6162name first, before it searches for a convenience variable.
c906108c 6163
6d2ebf8b 6164@node Registers
c906108c
SS
6165@section Registers
6166
6167@cindex registers
6168You can refer to machine register contents, in expressions, as variables
6169with names starting with @samp{$}. The names of registers are different
6170for each machine; use @code{info registers} to see the names used on
6171your machine.
6172
6173@table @code
6174@kindex info registers
6175@item info registers
6176Print the names and values of all registers except floating-point
c85508ee 6177and vector registers (in the selected stack frame).
c906108c
SS
6178
6179@kindex info all-registers
6180@cindex floating point registers
6181@item info all-registers
6182Print the names and values of all registers, including floating-point
c85508ee 6183and vector registers (in the selected stack frame).
c906108c
SS
6184
6185@item info registers @var{regname} @dots{}
6186Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6187As discussed in detail below, register values are normally relative to
6188the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6189the machine you are using, with or without the initial @samp{$}.
6190@end table
6191
e09f16f9
EZ
6192@cindex stack pointer register
6193@cindex program counter register
6194@cindex process status register
6195@cindex frame pointer register
6196@cindex standard registers
c906108c
SS
6197@value{GDBN} has four ``standard'' register names that are available (in
6198expressions) on most machines---whenever they do not conflict with an
6199architecture's canonical mnemonics for registers. The register names
6200@code{$pc} and @code{$sp} are used for the program counter register and
6201the stack pointer. @code{$fp} is used for a register that contains a
6202pointer to the current stack frame, and @code{$ps} is used for a
6203register that contains the processor status. For example,
6204you could print the program counter in hex with
6205
474c8240 6206@smallexample
c906108c 6207p/x $pc
474c8240 6208@end smallexample
c906108c
SS
6209
6210@noindent
6211or print the instruction to be executed next with
6212
474c8240 6213@smallexample
c906108c 6214x/i $pc
474c8240 6215@end smallexample
c906108c
SS
6216
6217@noindent
6218or add four to the stack pointer@footnote{This is a way of removing
6219one word from the stack, on machines where stacks grow downward in
6220memory (most machines, nowadays). This assumes that the innermost
6221stack frame is selected; setting @code{$sp} is not allowed when other
6222stack frames are selected. To pop entire frames off the stack,
6223regardless of machine architecture, use @code{return};
d4f3574e 6224see @ref{Returning, ,Returning from a function}.} with
c906108c 6225
474c8240 6226@smallexample
c906108c 6227set $sp += 4
474c8240 6228@end smallexample
c906108c
SS
6229
6230Whenever possible, these four standard register names are available on
6231your machine even though the machine has different canonical mnemonics,
6232so long as there is no conflict. The @code{info registers} command
6233shows the canonical names. For example, on the SPARC, @code{info
6234registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6235can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6236is an alias for the @sc{eflags} register.
c906108c
SS
6237
6238@value{GDBN} always considers the contents of an ordinary register as an
6239integer when the register is examined in this way. Some machines have
6240special registers which can hold nothing but floating point; these
6241registers are considered to have floating point values. There is no way
6242to refer to the contents of an ordinary register as floating point value
6243(although you can @emph{print} it as a floating point value with
6244@samp{print/f $@var{regname}}).
6245
6246Some registers have distinct ``raw'' and ``virtual'' data formats. This
6247means that the data format in which the register contents are saved by
6248the operating system is not the same one that your program normally
6249sees. For example, the registers of the 68881 floating point
6250coprocessor are always saved in ``extended'' (raw) format, but all C
6251programs expect to work with ``double'' (virtual) format. In such
5d161b24 6252cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6253that makes sense for your program), but the @code{info registers} command
6254prints the data in both formats.
6255
6256Normally, register values are relative to the selected stack frame
6257(@pxref{Selection, ,Selecting a frame}). This means that you get the
6258value that the register would contain if all stack frames farther in
6259were exited and their saved registers restored. In order to see the
6260true contents of hardware registers, you must select the innermost
6261frame (with @samp{frame 0}).
6262
6263However, @value{GDBN} must deduce where registers are saved, from the machine
6264code generated by your compiler. If some registers are not saved, or if
6265@value{GDBN} is unable to locate the saved registers, the selected stack
6266frame makes no difference.
6267
6d2ebf8b 6268@node Floating Point Hardware
c906108c
SS
6269@section Floating point hardware
6270@cindex floating point
6271
6272Depending on the configuration, @value{GDBN} may be able to give
6273you more information about the status of the floating point hardware.
6274
6275@table @code
6276@kindex info float
6277@item info float
6278Display hardware-dependent information about the floating
6279point unit. The exact contents and layout vary depending on the
6280floating point chip. Currently, @samp{info float} is supported on
6281the ARM and x86 machines.
6282@end table
c906108c 6283
e76f1f2e
AC
6284@node Vector Unit
6285@section Vector Unit
6286@cindex vector unit
6287
6288Depending on the configuration, @value{GDBN} may be able to give you
6289more information about the status of the vector unit.
6290
6291@table @code
6292@kindex info vector
6293@item info vector
6294Display information about the vector unit. The exact contents and
6295layout vary depending on the hardware.
6296@end table
6297
721c2651
EZ
6298@node OS Information
6299@section Operating system auxiliary information
6300@cindex OS information
6301
6302@value{GDBN} provides interfaces to useful OS facilities that can help
6303you debug your program.
6304
6305@cindex @code{ptrace} system call
6306@cindex @code{struct user} contents
6307When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6308machines), it interfaces with the inferior via the @code{ptrace}
6309system call. The operating system creates a special sata structure,
6310called @code{struct user}, for this interface. You can use the
6311command @code{info udot} to display the contents of this data
6312structure.
6313
6314@table @code
6315@item info udot
6316@kindex info udot
6317Display the contents of the @code{struct user} maintained by the OS
6318kernel for the program being debugged. @value{GDBN} displays the
6319contents of @code{struct user} as a list of hex numbers, similar to
6320the @code{examine} command.
6321@end table
6322
b383017d
RM
6323@cindex auxiliary vector
6324@cindex vector, auxiliary
b383017d
RM
6325Some operating systems supply an @dfn{auxiliary vector} to programs at
6326startup. This is akin to the arguments and environment that you
6327specify for a program, but contains a system-dependent variety of
6328binary values that tell system libraries important details about the
6329hardware, operating system, and process. Each value's purpose is
6330identified by an integer tag; the meanings are well-known but system-specific.
6331Depending on the configuration and operating system facilities,
9c16f35a
EZ
6332@value{GDBN} may be able to show you this information. For remote
6333targets, this functionality may further depend on the remote stub's
6334support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6335configuration, auxiliary vector}.
b383017d
RM
6336
6337@table @code
6338@kindex info auxv
6339@item info auxv
6340Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6341live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6342numerically, and also shows names and text descriptions for recognized
6343tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6344pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6345most appropriate form for a recognized tag, and in hexadecimal for
6346an unrecognized tag.
6347@end table
6348
721c2651 6349
29e57380 6350@node Memory Region Attributes
b383017d 6351@section Memory region attributes
29e57380
C
6352@cindex memory region attributes
6353
b383017d
RM
6354@dfn{Memory region attributes} allow you to describe special handling
6355required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6356to determine whether to allow certain types of memory accesses; whether to
6357use specific width accesses; and whether to cache target memory.
6358
6359Defined memory regions can be individually enabled and disabled. When a
6360memory region is disabled, @value{GDBN} uses the default attributes when
6361accessing memory in that region. Similarly, if no memory regions have
6362been defined, @value{GDBN} uses the default attributes when accessing
6363all memory.
6364
b383017d 6365When a memory region is defined, it is given a number to identify it;
29e57380
C
6366to enable, disable, or remove a memory region, you specify that number.
6367
6368@table @code
6369@kindex mem
bfac230e 6370@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6371Define a memory region bounded by @var{lower} and @var{upper} with
6372attributes @var{attributes}@dots{}, and add it to the list of regions
6373monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6374case: it is treated as the the target's maximum memory address.
bfac230e 6375(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6376
6377@kindex delete mem
6378@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6379Remove memory regions @var{nums}@dots{} from the list of regions
6380monitored by @value{GDBN}.
29e57380
C
6381
6382@kindex disable mem
6383@item disable mem @var{nums}@dots{}
09d4efe1 6384Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6385A disabled memory region is not forgotten.
29e57380
C
6386It may be enabled again later.
6387
6388@kindex enable mem
6389@item enable mem @var{nums}@dots{}
09d4efe1 6390Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6391
6392@kindex info mem
6393@item info mem
6394Print a table of all defined memory regions, with the following columns
09d4efe1 6395for each region:
29e57380
C
6396
6397@table @emph
6398@item Memory Region Number
6399@item Enabled or Disabled.
b383017d 6400Enabled memory regions are marked with @samp{y}.
29e57380
C
6401Disabled memory regions are marked with @samp{n}.
6402
6403@item Lo Address
6404The address defining the inclusive lower bound of the memory region.
6405
6406@item Hi Address
6407The address defining the exclusive upper bound of the memory region.
6408
6409@item Attributes
6410The list of attributes set for this memory region.
6411@end table
6412@end table
6413
6414
6415@subsection Attributes
6416
b383017d 6417@subsubsection Memory Access Mode
29e57380
C
6418The access mode attributes set whether @value{GDBN} may make read or
6419write accesses to a memory region.
6420
6421While these attributes prevent @value{GDBN} from performing invalid
6422memory accesses, they do nothing to prevent the target system, I/O DMA,
6423etc. from accessing memory.
6424
6425@table @code
6426@item ro
6427Memory is read only.
6428@item wo
6429Memory is write only.
6430@item rw
6ca652b0 6431Memory is read/write. This is the default.
29e57380
C
6432@end table
6433
6434@subsubsection Memory Access Size
6435The acccess size attributes tells @value{GDBN} to use specific sized
6436accesses in the memory region. Often memory mapped device registers
6437require specific sized accesses. If no access size attribute is
6438specified, @value{GDBN} may use accesses of any size.
6439
6440@table @code
6441@item 8
6442Use 8 bit memory accesses.
6443@item 16
6444Use 16 bit memory accesses.
6445@item 32
6446Use 32 bit memory accesses.
6447@item 64
6448Use 64 bit memory accesses.
6449@end table
6450
6451@c @subsubsection Hardware/Software Breakpoints
6452@c The hardware/software breakpoint attributes set whether @value{GDBN}
6453@c will use hardware or software breakpoints for the internal breakpoints
6454@c used by the step, next, finish, until, etc. commands.
6455@c
6456@c @table @code
6457@c @item hwbreak
b383017d 6458@c Always use hardware breakpoints
29e57380
C
6459@c @item swbreak (default)
6460@c @end table
6461
6462@subsubsection Data Cache
6463The data cache attributes set whether @value{GDBN} will cache target
6464memory. While this generally improves performance by reducing debug
6465protocol overhead, it can lead to incorrect results because @value{GDBN}
6466does not know about volatile variables or memory mapped device
6467registers.
6468
6469@table @code
6470@item cache
b383017d 6471Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6472@item nocache
6473Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6474@end table
6475
6476@c @subsubsection Memory Write Verification
b383017d 6477@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6478@c will re-reads data after each write to verify the write was successful.
6479@c
6480@c @table @code
6481@c @item verify
6482@c @item noverify (default)
6483@c @end table
6484
16d9dec6
MS
6485@node Dump/Restore Files
6486@section Copy between memory and a file
6487@cindex dump/restore files
6488@cindex append data to a file
6489@cindex dump data to a file
6490@cindex restore data from a file
16d9dec6 6491
df5215a6
JB
6492You can use the commands @code{dump}, @code{append}, and
6493@code{restore} to copy data between target memory and a file. The
6494@code{dump} and @code{append} commands write data to a file, and the
6495@code{restore} command reads data from a file back into the inferior's
6496memory. Files may be in binary, Motorola S-record, Intel hex, or
6497Tektronix Hex format; however, @value{GDBN} can only append to binary
6498files.
6499
6500@table @code
6501
6502@kindex dump
6503@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6504@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6505Dump the contents of memory from @var{start_addr} to @var{end_addr},
6506or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6507
df5215a6 6508The @var{format} parameter may be any one of:
16d9dec6 6509@table @code
df5215a6
JB
6510@item binary
6511Raw binary form.
6512@item ihex
6513Intel hex format.
6514@item srec
6515Motorola S-record format.
6516@item tekhex
6517Tektronix Hex format.
6518@end table
6519
6520@value{GDBN} uses the same definitions of these formats as the
6521@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6522@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6523form.
6524
6525@kindex append
6526@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6527@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6528Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6529or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6530(@value{GDBN} can only append data to files in raw binary form.)
6531
6532@kindex restore
6533@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6534Restore the contents of file @var{filename} into memory. The
6535@code{restore} command can automatically recognize any known @sc{bfd}
6536file format, except for raw binary. To restore a raw binary file you
6537must specify the optional keyword @code{binary} after the filename.
16d9dec6 6538
b383017d 6539If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6540contained in the file. Binary files always start at address zero, so
6541they will be restored at address @var{bias}. Other bfd files have
6542a built-in location; they will be restored at offset @var{bias}
6543from that location.
6544
6545If @var{start} and/or @var{end} are non-zero, then only data between
6546file offset @var{start} and file offset @var{end} will be restored.
b383017d 6547These offsets are relative to the addresses in the file, before
16d9dec6
MS
6548the @var{bias} argument is applied.
6549
6550@end table
6551
384ee23f
EZ
6552@node Core File Generation
6553@section How to Produce a Core File from Your Program
6554@cindex dump core from inferior
6555
6556A @dfn{core file} or @dfn{core dump} is a file that records the memory
6557image of a running process and its process status (register values
6558etc.). Its primary use is post-mortem debugging of a program that
6559crashed while it ran outside a debugger. A program that crashes
6560automatically produces a core file, unless this feature is disabled by
6561the user. @xref{Files}, for information on invoking @value{GDBN} in
6562the post-mortem debugging mode.
6563
6564Occasionally, you may wish to produce a core file of the program you
6565are debugging in order to preserve a snapshot of its state.
6566@value{GDBN} has a special command for that.
6567
6568@table @code
6569@kindex gcore
6570@kindex generate-core-file
6571@item generate-core-file [@var{file}]
6572@itemx gcore [@var{file}]
6573Produce a core dump of the inferior process. The optional argument
6574@var{file} specifies the file name where to put the core dump. If not
6575specified, the file name defaults to @file{core.@var{pid}}, where
6576@var{pid} is the inferior process ID.
6577
6578Note that this command is implemented only for some systems (as of
6579this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6580@end table
6581
a0eb71c5
KB
6582@node Character Sets
6583@section Character Sets
6584@cindex character sets
6585@cindex charset
6586@cindex translating between character sets
6587@cindex host character set
6588@cindex target character set
6589
6590If the program you are debugging uses a different character set to
6591represent characters and strings than the one @value{GDBN} uses itself,
6592@value{GDBN} can automatically translate between the character sets for
6593you. The character set @value{GDBN} uses we call the @dfn{host
6594character set}; the one the inferior program uses we call the
6595@dfn{target character set}.
6596
6597For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6598uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6599remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6600running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6601then the host character set is Latin-1, and the target character set is
6602@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6603target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6604@sc{ebcdic} and Latin 1 as you print character or string values, or use
6605character and string literals in expressions.
6606
6607@value{GDBN} has no way to automatically recognize which character set
6608the inferior program uses; you must tell it, using the @code{set
6609target-charset} command, described below.
6610
6611Here are the commands for controlling @value{GDBN}'s character set
6612support:
6613
6614@table @code
6615@item set target-charset @var{charset}
6616@kindex set target-charset
6617Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6618character set names @value{GDBN} recognizes below, but if you type
6619@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6620list the target character sets it supports.
a0eb71c5
KB
6621@end table
6622
6623@table @code
6624@item set host-charset @var{charset}
6625@kindex set host-charset
6626Set the current host character set to @var{charset}.
6627
6628By default, @value{GDBN} uses a host character set appropriate to the
6629system it is running on; you can override that default using the
6630@code{set host-charset} command.
6631
6632@value{GDBN} can only use certain character sets as its host character
6633set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6634indicate which can be host character sets, but if you type
6635@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6636list the host character sets it supports.
a0eb71c5
KB
6637
6638@item set charset @var{charset}
6639@kindex set charset
e33d66ec
EZ
6640Set the current host and target character sets to @var{charset}. As
6641above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6642@value{GDBN} will list the name of the character sets that can be used
6643for both host and target.
6644
a0eb71c5
KB
6645
6646@item show charset
a0eb71c5 6647@kindex show charset
b383017d 6648Show the names of the current host and target charsets.
e33d66ec
EZ
6649
6650@itemx show host-charset
a0eb71c5 6651@kindex show host-charset
b383017d 6652Show the name of the current host charset.
e33d66ec
EZ
6653
6654@itemx show target-charset
a0eb71c5 6655@kindex show target-charset
b383017d 6656Show the name of the current target charset.
a0eb71c5
KB
6657
6658@end table
6659
6660@value{GDBN} currently includes support for the following character
6661sets:
6662
6663@table @code
6664
6665@item ASCII
6666@cindex ASCII character set
6667Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6668character set.
6669
6670@item ISO-8859-1
6671@cindex ISO 8859-1 character set
6672@cindex ISO Latin 1 character set
e33d66ec 6673The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6674characters needed for French, German, and Spanish. @value{GDBN} can use
6675this as its host character set.
6676
6677@item EBCDIC-US
6678@itemx IBM1047
6679@cindex EBCDIC character set
6680@cindex IBM1047 character set
6681Variants of the @sc{ebcdic} character set, used on some of IBM's
6682mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6683@value{GDBN} cannot use these as its host character set.
6684
6685@end table
6686
6687Note that these are all single-byte character sets. More work inside
6688GDB is needed to support multi-byte or variable-width character
6689encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6690
6691Here is an example of @value{GDBN}'s character set support in action.
6692Assume that the following source code has been placed in the file
6693@file{charset-test.c}:
6694
6695@smallexample
6696#include <stdio.h>
6697
6698char ascii_hello[]
6699 = @{72, 101, 108, 108, 111, 44, 32, 119,
6700 111, 114, 108, 100, 33, 10, 0@};
6701char ibm1047_hello[]
6702 = @{200, 133, 147, 147, 150, 107, 64, 166,
6703 150, 153, 147, 132, 90, 37, 0@};
6704
6705main ()
6706@{
6707 printf ("Hello, world!\n");
6708@}
10998722 6709@end smallexample
a0eb71c5
KB
6710
6711In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6712containing the string @samp{Hello, world!} followed by a newline,
6713encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6714
6715We compile the program, and invoke the debugger on it:
6716
6717@smallexample
6718$ gcc -g charset-test.c -o charset-test
6719$ gdb -nw charset-test
6720GNU gdb 2001-12-19-cvs
6721Copyright 2001 Free Software Foundation, Inc.
6722@dots{}
f7dc1244 6723(@value{GDBP})
10998722 6724@end smallexample
a0eb71c5
KB
6725
6726We can use the @code{show charset} command to see what character sets
6727@value{GDBN} is currently using to interpret and display characters and
6728strings:
6729
6730@smallexample
f7dc1244 6731(@value{GDBP}) show charset
e33d66ec 6732The current host and target character set is `ISO-8859-1'.
f7dc1244 6733(@value{GDBP})
10998722 6734@end smallexample
a0eb71c5
KB
6735
6736For the sake of printing this manual, let's use @sc{ascii} as our
6737initial character set:
6738@smallexample
f7dc1244
EZ
6739(@value{GDBP}) set charset ASCII
6740(@value{GDBP}) show charset
e33d66ec 6741The current host and target character set is `ASCII'.
f7dc1244 6742(@value{GDBP})
10998722 6743@end smallexample
a0eb71c5
KB
6744
6745Let's assume that @sc{ascii} is indeed the correct character set for our
6746host system --- in other words, let's assume that if @value{GDBN} prints
6747characters using the @sc{ascii} character set, our terminal will display
6748them properly. Since our current target character set is also
6749@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6750
6751@smallexample
f7dc1244 6752(@value{GDBP}) print ascii_hello
a0eb71c5 6753$1 = 0x401698 "Hello, world!\n"
f7dc1244 6754(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6755$2 = 72 'H'
f7dc1244 6756(@value{GDBP})
10998722 6757@end smallexample
a0eb71c5
KB
6758
6759@value{GDBN} uses the target character set for character and string
6760literals you use in expressions:
6761
6762@smallexample
f7dc1244 6763(@value{GDBP}) print '+'
a0eb71c5 6764$3 = 43 '+'
f7dc1244 6765(@value{GDBP})
10998722 6766@end smallexample
a0eb71c5
KB
6767
6768The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6769character.
6770
6771@value{GDBN} relies on the user to tell it which character set the
6772target program uses. If we print @code{ibm1047_hello} while our target
6773character set is still @sc{ascii}, we get jibberish:
6774
6775@smallexample
f7dc1244 6776(@value{GDBP}) print ibm1047_hello
a0eb71c5 6777$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6778(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6779$5 = 200 '\310'
f7dc1244 6780(@value{GDBP})
10998722 6781@end smallexample
a0eb71c5 6782
e33d66ec 6783If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6784@value{GDBN} tells us the character sets it supports:
6785
6786@smallexample
f7dc1244 6787(@value{GDBP}) set target-charset
b383017d 6788ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6789(@value{GDBP}) set target-charset
10998722 6790@end smallexample
a0eb71c5
KB
6791
6792We can select @sc{ibm1047} as our target character set, and examine the
6793program's strings again. Now the @sc{ascii} string is wrong, but
6794@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6795target character set, @sc{ibm1047}, to the host character set,
6796@sc{ascii}, and they display correctly:
6797
6798@smallexample
f7dc1244
EZ
6799(@value{GDBP}) set target-charset IBM1047
6800(@value{GDBP}) show charset
e33d66ec
EZ
6801The current host character set is `ASCII'.
6802The current target character set is `IBM1047'.
f7dc1244 6803(@value{GDBP}) print ascii_hello
a0eb71c5 6804$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6805(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6806$7 = 72 '\110'
f7dc1244 6807(@value{GDBP}) print ibm1047_hello
a0eb71c5 6808$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6809(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6810$9 = 200 'H'
f7dc1244 6811(@value{GDBP})
10998722 6812@end smallexample
a0eb71c5
KB
6813
6814As above, @value{GDBN} uses the target character set for character and
6815string literals you use in expressions:
6816
6817@smallexample
f7dc1244 6818(@value{GDBP}) print '+'
a0eb71c5 6819$10 = 78 '+'
f7dc1244 6820(@value{GDBP})
10998722 6821@end smallexample
a0eb71c5 6822
e33d66ec 6823The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6824character.
6825
09d4efe1
EZ
6826@node Caching Remote Data
6827@section Caching Data of Remote Targets
6828@cindex caching data of remote targets
6829
6830@value{GDBN} can cache data exchanged between the debugger and a
6831remote target (@pxref{Remote}). Such caching generally improves
6832performance, because it reduces the overhead of the remote protocol by
6833bundling memory reads and writes into large chunks. Unfortunately,
6834@value{GDBN} does not currently know anything about volatile
6835registers, and thus data caching will produce incorrect results when
6836volatile registers are in use.
6837
6838@table @code
6839@kindex set remotecache
6840@item set remotecache on
6841@itemx set remotecache off
6842Set caching state for remote targets. When @code{ON}, use data
6843caching. By default, this option is @code{OFF}.
6844
6845@kindex show remotecache
6846@item show remotecache
6847Show the current state of data caching for remote targets.
6848
6849@kindex info dcache
6850@item info dcache
6851Print the information about the data cache performance. The
6852information displayed includes: the dcache width and depth; and for
6853each cache line, how many times it was referenced, and its data and
6854state (dirty, bad, ok, etc.). This command is useful for debugging
6855the data cache operation.
6856@end table
6857
a0eb71c5 6858
e2e0bcd1
JB
6859@node Macros
6860@chapter C Preprocessor Macros
6861
49efadf5 6862Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6863``preprocessor macros'' which expand into strings of tokens.
6864@value{GDBN} can evaluate expressions containing macro invocations, show
6865the result of macro expansion, and show a macro's definition, including
6866where it was defined.
6867
6868You may need to compile your program specially to provide @value{GDBN}
6869with information about preprocessor macros. Most compilers do not
6870include macros in their debugging information, even when you compile
6871with the @option{-g} flag. @xref{Compilation}.
6872
6873A program may define a macro at one point, remove that definition later,
6874and then provide a different definition after that. Thus, at different
6875points in the program, a macro may have different definitions, or have
6876no definition at all. If there is a current stack frame, @value{GDBN}
6877uses the macros in scope at that frame's source code line. Otherwise,
6878@value{GDBN} uses the macros in scope at the current listing location;
6879see @ref{List}.
6880
6881At the moment, @value{GDBN} does not support the @code{##}
6882token-splicing operator, the @code{#} stringification operator, or
6883variable-arity macros.
6884
6885Whenever @value{GDBN} evaluates an expression, it always expands any
6886macro invocations present in the expression. @value{GDBN} also provides
6887the following commands for working with macros explicitly.
6888
6889@table @code
6890
6891@kindex macro expand
6892@cindex macro expansion, showing the results of preprocessor
6893@cindex preprocessor macro expansion, showing the results of
6894@cindex expanding preprocessor macros
6895@item macro expand @var{expression}
6896@itemx macro exp @var{expression}
6897Show the results of expanding all preprocessor macro invocations in
6898@var{expression}. Since @value{GDBN} simply expands macros, but does
6899not parse the result, @var{expression} need not be a valid expression;
6900it can be any string of tokens.
6901
09d4efe1 6902@kindex macro exp1
e2e0bcd1
JB
6903@item macro expand-once @var{expression}
6904@itemx macro exp1 @var{expression}
4644b6e3 6905@cindex expand macro once
e2e0bcd1
JB
6906@i{(This command is not yet implemented.)} Show the results of
6907expanding those preprocessor macro invocations that appear explicitly in
6908@var{expression}. Macro invocations appearing in that expansion are
6909left unchanged. This command allows you to see the effect of a
6910particular macro more clearly, without being confused by further
6911expansions. Since @value{GDBN} simply expands macros, but does not
6912parse the result, @var{expression} need not be a valid expression; it
6913can be any string of tokens.
6914
475b0867 6915@kindex info macro
e2e0bcd1
JB
6916@cindex macro definition, showing
6917@cindex definition, showing a macro's
475b0867 6918@item info macro @var{macro}
e2e0bcd1
JB
6919Show the definition of the macro named @var{macro}, and describe the
6920source location where that definition was established.
6921
6922@kindex macro define
6923@cindex user-defined macros
6924@cindex defining macros interactively
6925@cindex macros, user-defined
6926@item macro define @var{macro} @var{replacement-list}
6927@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6928@i{(This command is not yet implemented.)} Introduce a definition for a
6929preprocessor macro named @var{macro}, invocations of which are replaced
6930by the tokens given in @var{replacement-list}. The first form of this
6931command defines an ``object-like'' macro, which takes no arguments; the
6932second form defines a ``function-like'' macro, which takes the arguments
6933given in @var{arglist}.
6934
6935A definition introduced by this command is in scope in every expression
6936evaluated in @value{GDBN}, until it is removed with the @command{macro
6937undef} command, described below. The definition overrides all
6938definitions for @var{macro} present in the program being debugged, as
6939well as any previous user-supplied definition.
6940
6941@kindex macro undef
6942@item macro undef @var{macro}
6943@i{(This command is not yet implemented.)} Remove any user-supplied
6944definition for the macro named @var{macro}. This command only affects
6945definitions provided with the @command{macro define} command, described
6946above; it cannot remove definitions present in the program being
6947debugged.
6948
09d4efe1
EZ
6949@kindex macro list
6950@item macro list
6951@i{(This command is not yet implemented.)} List all the macros
6952defined using the @code{macro define} command.
e2e0bcd1
JB
6953@end table
6954
6955@cindex macros, example of debugging with
6956Here is a transcript showing the above commands in action. First, we
6957show our source files:
6958
6959@smallexample
6960$ cat sample.c
6961#include <stdio.h>
6962#include "sample.h"
6963
6964#define M 42
6965#define ADD(x) (M + x)
6966
6967main ()
6968@{
6969#define N 28
6970 printf ("Hello, world!\n");
6971#undef N
6972 printf ("We're so creative.\n");
6973#define N 1729
6974 printf ("Goodbye, world!\n");
6975@}
6976$ cat sample.h
6977#define Q <
6978$
6979@end smallexample
6980
6981Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6982We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6983compiler includes information about preprocessor macros in the debugging
6984information.
6985
6986@smallexample
6987$ gcc -gdwarf-2 -g3 sample.c -o sample
6988$
6989@end smallexample
6990
6991Now, we start @value{GDBN} on our sample program:
6992
6993@smallexample
6994$ gdb -nw sample
6995GNU gdb 2002-05-06-cvs
6996Copyright 2002 Free Software Foundation, Inc.
6997GDB is free software, @dots{}
f7dc1244 6998(@value{GDBP})
e2e0bcd1
JB
6999@end smallexample
7000
7001We can expand macros and examine their definitions, even when the
7002program is not running. @value{GDBN} uses the current listing position
7003to decide which macro definitions are in scope:
7004
7005@smallexample
f7dc1244 7006(@value{GDBP}) list main
e2e0bcd1
JB
70073
70084 #define M 42
70095 #define ADD(x) (M + x)
70106
70117 main ()
70128 @{
70139 #define N 28
701410 printf ("Hello, world!\n");
701511 #undef N
701612 printf ("We're so creative.\n");
f7dc1244 7017(@value{GDBP}) info macro ADD
e2e0bcd1
JB
7018Defined at /home/jimb/gdb/macros/play/sample.c:5
7019#define ADD(x) (M + x)
f7dc1244 7020(@value{GDBP}) info macro Q
e2e0bcd1
JB
7021Defined at /home/jimb/gdb/macros/play/sample.h:1
7022 included at /home/jimb/gdb/macros/play/sample.c:2
7023#define Q <
f7dc1244 7024(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 7025expands to: (42 + 1)
f7dc1244 7026(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 7027expands to: once (M + 1)
f7dc1244 7028(@value{GDBP})
e2e0bcd1
JB
7029@end smallexample
7030
7031In the example above, note that @command{macro expand-once} expands only
7032the macro invocation explicit in the original text --- the invocation of
7033@code{ADD} --- but does not expand the invocation of the macro @code{M},
7034which was introduced by @code{ADD}.
7035
7036Once the program is running, GDB uses the macro definitions in force at
7037the source line of the current stack frame:
7038
7039@smallexample
f7dc1244 7040(@value{GDBP}) break main
e2e0bcd1 7041Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7042(@value{GDBP}) run
b383017d 7043Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7044
7045Breakpoint 1, main () at sample.c:10
704610 printf ("Hello, world!\n");
f7dc1244 7047(@value{GDBP})
e2e0bcd1
JB
7048@end smallexample
7049
7050At line 10, the definition of the macro @code{N} at line 9 is in force:
7051
7052@smallexample
f7dc1244 7053(@value{GDBP}) info macro N
e2e0bcd1
JB
7054Defined at /home/jimb/gdb/macros/play/sample.c:9
7055#define N 28
f7dc1244 7056(@value{GDBP}) macro expand N Q M
e2e0bcd1 7057expands to: 28 < 42
f7dc1244 7058(@value{GDBP}) print N Q M
e2e0bcd1 7059$1 = 1
f7dc1244 7060(@value{GDBP})
e2e0bcd1
JB
7061@end smallexample
7062
7063As we step over directives that remove @code{N}'s definition, and then
7064give it a new definition, @value{GDBN} finds the definition (or lack
7065thereof) in force at each point:
7066
7067@smallexample
f7dc1244 7068(@value{GDBP}) next
e2e0bcd1
JB
7069Hello, world!
707012 printf ("We're so creative.\n");
f7dc1244 7071(@value{GDBP}) info macro N
e2e0bcd1
JB
7072The symbol `N' has no definition as a C/C++ preprocessor macro
7073at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7074(@value{GDBP}) next
e2e0bcd1
JB
7075We're so creative.
707614 printf ("Goodbye, world!\n");
f7dc1244 7077(@value{GDBP}) info macro N
e2e0bcd1
JB
7078Defined at /home/jimb/gdb/macros/play/sample.c:13
7079#define N 1729
f7dc1244 7080(@value{GDBP}) macro expand N Q M
e2e0bcd1 7081expands to: 1729 < 42
f7dc1244 7082(@value{GDBP}) print N Q M
e2e0bcd1 7083$2 = 0
f7dc1244 7084(@value{GDBP})
e2e0bcd1
JB
7085@end smallexample
7086
7087
b37052ae
EZ
7088@node Tracepoints
7089@chapter Tracepoints
7090@c This chapter is based on the documentation written by Michael
7091@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7092
7093@cindex tracepoints
7094In some applications, it is not feasible for the debugger to interrupt
7095the program's execution long enough for the developer to learn
7096anything helpful about its behavior. If the program's correctness
7097depends on its real-time behavior, delays introduced by a debugger
7098might cause the program to change its behavior drastically, or perhaps
7099fail, even when the code itself is correct. It is useful to be able
7100to observe the program's behavior without interrupting it.
7101
7102Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7103specify locations in the program, called @dfn{tracepoints}, and
7104arbitrary expressions to evaluate when those tracepoints are reached.
7105Later, using the @code{tfind} command, you can examine the values
7106those expressions had when the program hit the tracepoints. The
7107expressions may also denote objects in memory---structures or arrays,
7108for example---whose values @value{GDBN} should record; while visiting
7109a particular tracepoint, you may inspect those objects as if they were
7110in memory at that moment. However, because @value{GDBN} records these
7111values without interacting with you, it can do so quickly and
7112unobtrusively, hopefully not disturbing the program's behavior.
7113
7114The tracepoint facility is currently available only for remote
2c0069bb
EZ
7115targets. @xref{Targets}. In addition, your remote target must know how
7116to collect trace data. This functionality is implemented in the remote
7117stub; however, none of the stubs distributed with @value{GDBN} support
7118tracepoints as of this writing.
b37052ae
EZ
7119
7120This chapter describes the tracepoint commands and features.
7121
7122@menu
b383017d
RM
7123* Set Tracepoints::
7124* Analyze Collected Data::
7125* Tracepoint Variables::
b37052ae
EZ
7126@end menu
7127
7128@node Set Tracepoints
7129@section Commands to Set Tracepoints
7130
7131Before running such a @dfn{trace experiment}, an arbitrary number of
7132tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7133tracepoint has a number assigned to it by @value{GDBN}. Like with
7134breakpoints, tracepoint numbers are successive integers starting from
7135one. Many of the commands associated with tracepoints take the
7136tracepoint number as their argument, to identify which tracepoint to
7137work on.
7138
7139For each tracepoint, you can specify, in advance, some arbitrary set
7140of data that you want the target to collect in the trace buffer when
7141it hits that tracepoint. The collected data can include registers,
7142local variables, or global data. Later, you can use @value{GDBN}
7143commands to examine the values these data had at the time the
7144tracepoint was hit.
7145
7146This section describes commands to set tracepoints and associated
7147conditions and actions.
7148
7149@menu
b383017d
RM
7150* Create and Delete Tracepoints::
7151* Enable and Disable Tracepoints::
7152* Tracepoint Passcounts::
7153* Tracepoint Actions::
7154* Listing Tracepoints::
7155* Starting and Stopping Trace Experiment::
b37052ae
EZ
7156@end menu
7157
7158@node Create and Delete Tracepoints
7159@subsection Create and Delete Tracepoints
7160
7161@table @code
7162@cindex set tracepoint
7163@kindex trace
7164@item trace
7165The @code{trace} command is very similar to the @code{break} command.
7166Its argument can be a source line, a function name, or an address in
7167the target program. @xref{Set Breaks}. The @code{trace} command
7168defines a tracepoint, which is a point in the target program where the
7169debugger will briefly stop, collect some data, and then allow the
7170program to continue. Setting a tracepoint or changing its commands
7171doesn't take effect until the next @code{tstart} command; thus, you
7172cannot change the tracepoint attributes once a trace experiment is
7173running.
7174
7175Here are some examples of using the @code{trace} command:
7176
7177@smallexample
7178(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7179
7180(@value{GDBP}) @b{trace +2} // 2 lines forward
7181
7182(@value{GDBP}) @b{trace my_function} // first source line of function
7183
7184(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7185
7186(@value{GDBP}) @b{trace *0x2117c4} // an address
7187@end smallexample
7188
7189@noindent
7190You can abbreviate @code{trace} as @code{tr}.
7191
7192@vindex $tpnum
7193@cindex last tracepoint number
7194@cindex recent tracepoint number
7195@cindex tracepoint number
7196The convenience variable @code{$tpnum} records the tracepoint number
7197of the most recently set tracepoint.
7198
7199@kindex delete tracepoint
7200@cindex tracepoint deletion
7201@item delete tracepoint @r{[}@var{num}@r{]}
7202Permanently delete one or more tracepoints. With no argument, the
7203default is to delete all tracepoints.
7204
7205Examples:
7206
7207@smallexample
7208(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7209
7210(@value{GDBP}) @b{delete trace} // remove all tracepoints
7211@end smallexample
7212
7213@noindent
7214You can abbreviate this command as @code{del tr}.
7215@end table
7216
7217@node Enable and Disable Tracepoints
7218@subsection Enable and Disable Tracepoints
7219
7220@table @code
7221@kindex disable tracepoint
7222@item disable tracepoint @r{[}@var{num}@r{]}
7223Disable tracepoint @var{num}, or all tracepoints if no argument
7224@var{num} is given. A disabled tracepoint will have no effect during
7225the next trace experiment, but it is not forgotten. You can re-enable
7226a disabled tracepoint using the @code{enable tracepoint} command.
7227
7228@kindex enable tracepoint
7229@item enable tracepoint @r{[}@var{num}@r{]}
7230Enable tracepoint @var{num}, or all tracepoints. The enabled
7231tracepoints will become effective the next time a trace experiment is
7232run.
7233@end table
7234
7235@node Tracepoint Passcounts
7236@subsection Tracepoint Passcounts
7237
7238@table @code
7239@kindex passcount
7240@cindex tracepoint pass count
7241@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7242Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7243automatically stop a trace experiment. If a tracepoint's passcount is
7244@var{n}, then the trace experiment will be automatically stopped on
7245the @var{n}'th time that tracepoint is hit. If the tracepoint number
7246@var{num} is not specified, the @code{passcount} command sets the
7247passcount of the most recently defined tracepoint. If no passcount is
7248given, the trace experiment will run until stopped explicitly by the
7249user.
7250
7251Examples:
7252
7253@smallexample
b383017d 7254(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7255@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7256
7257(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7258@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7259(@value{GDBP}) @b{trace foo}
7260(@value{GDBP}) @b{pass 3}
7261(@value{GDBP}) @b{trace bar}
7262(@value{GDBP}) @b{pass 2}
7263(@value{GDBP}) @b{trace baz}
7264(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7265@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7266@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7267@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7268@end smallexample
7269@end table
7270
7271@node Tracepoint Actions
7272@subsection Tracepoint Action Lists
7273
7274@table @code
7275@kindex actions
7276@cindex tracepoint actions
7277@item actions @r{[}@var{num}@r{]}
7278This command will prompt for a list of actions to be taken when the
7279tracepoint is hit. If the tracepoint number @var{num} is not
7280specified, this command sets the actions for the one that was most
7281recently defined (so that you can define a tracepoint and then say
7282@code{actions} without bothering about its number). You specify the
7283actions themselves on the following lines, one action at a time, and
7284terminate the actions list with a line containing just @code{end}. So
7285far, the only defined actions are @code{collect} and
7286@code{while-stepping}.
7287
7288@cindex remove actions from a tracepoint
7289To remove all actions from a tracepoint, type @samp{actions @var{num}}
7290and follow it immediately with @samp{end}.
7291
7292@smallexample
7293(@value{GDBP}) @b{collect @var{data}} // collect some data
7294
6826cf00 7295(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7296
6826cf00 7297(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7298@end smallexample
7299
7300In the following example, the action list begins with @code{collect}
7301commands indicating the things to be collected when the tracepoint is
7302hit. Then, in order to single-step and collect additional data
7303following the tracepoint, a @code{while-stepping} command is used,
7304followed by the list of things to be collected while stepping. The
7305@code{while-stepping} command is terminated by its own separate
7306@code{end} command. Lastly, the action list is terminated by an
7307@code{end} command.
7308
7309@smallexample
7310(@value{GDBP}) @b{trace foo}
7311(@value{GDBP}) @b{actions}
7312Enter actions for tracepoint 1, one per line:
7313> collect bar,baz
7314> collect $regs
7315> while-stepping 12
7316 > collect $fp, $sp
7317 > end
7318end
7319@end smallexample
7320
7321@kindex collect @r{(tracepoints)}
7322@item collect @var{expr1}, @var{expr2}, @dots{}
7323Collect values of the given expressions when the tracepoint is hit.
7324This command accepts a comma-separated list of any valid expressions.
7325In addition to global, static, or local variables, the following
7326special arguments are supported:
7327
7328@table @code
7329@item $regs
7330collect all registers
7331
7332@item $args
7333collect all function arguments
7334
7335@item $locals
7336collect all local variables.
7337@end table
7338
7339You can give several consecutive @code{collect} commands, each one
7340with a single argument, or one @code{collect} command with several
7341arguments separated by commas: the effect is the same.
7342
f5c37c66
EZ
7343The command @code{info scope} (@pxref{Symbols, info scope}) is
7344particularly useful for figuring out what data to collect.
7345
b37052ae
EZ
7346@kindex while-stepping @r{(tracepoints)}
7347@item while-stepping @var{n}
7348Perform @var{n} single-step traces after the tracepoint, collecting
7349new data at each step. The @code{while-stepping} command is
7350followed by the list of what to collect while stepping (followed by
7351its own @code{end} command):
7352
7353@smallexample
7354> while-stepping 12
7355 > collect $regs, myglobal
7356 > end
7357>
7358@end smallexample
7359
7360@noindent
7361You may abbreviate @code{while-stepping} as @code{ws} or
7362@code{stepping}.
7363@end table
7364
7365@node Listing Tracepoints
7366@subsection Listing Tracepoints
7367
7368@table @code
7369@kindex info tracepoints
09d4efe1 7370@kindex info tp
b37052ae
EZ
7371@cindex information about tracepoints
7372@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7373Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7374a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7375defined so far. For each tracepoint, the following information is
7376shown:
7377
7378@itemize @bullet
7379@item
7380its number
7381@item
7382whether it is enabled or disabled
7383@item
7384its address
7385@item
7386its passcount as given by the @code{passcount @var{n}} command
7387@item
7388its step count as given by the @code{while-stepping @var{n}} command
7389@item
7390where in the source files is the tracepoint set
7391@item
7392its action list as given by the @code{actions} command
7393@end itemize
7394
7395@smallexample
7396(@value{GDBP}) @b{info trace}
7397Num Enb Address PassC StepC What
73981 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73992 y 0x0020dc64 0 0 in g_test at g_test.c:1375
74003 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7401(@value{GDBP})
7402@end smallexample
7403
7404@noindent
7405This command can be abbreviated @code{info tp}.
7406@end table
7407
7408@node Starting and Stopping Trace Experiment
7409@subsection Starting and Stopping Trace Experiment
7410
7411@table @code
7412@kindex tstart
7413@cindex start a new trace experiment
7414@cindex collected data discarded
7415@item tstart
7416This command takes no arguments. It starts the trace experiment, and
7417begins collecting data. This has the side effect of discarding all
7418the data collected in the trace buffer during the previous trace
7419experiment.
7420
7421@kindex tstop
7422@cindex stop a running trace experiment
7423@item tstop
7424This command takes no arguments. It ends the trace experiment, and
7425stops collecting data.
7426
68c71a2e 7427@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7428automatically if any tracepoint's passcount is reached
7429(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7430
7431@kindex tstatus
7432@cindex status of trace data collection
7433@cindex trace experiment, status of
7434@item tstatus
7435This command displays the status of the current trace data
7436collection.
7437@end table
7438
7439Here is an example of the commands we described so far:
7440
7441@smallexample
7442(@value{GDBP}) @b{trace gdb_c_test}
7443(@value{GDBP}) @b{actions}
7444Enter actions for tracepoint #1, one per line.
7445> collect $regs,$locals,$args
7446> while-stepping 11
7447 > collect $regs
7448 > end
7449> end
7450(@value{GDBP}) @b{tstart}
7451 [time passes @dots{}]
7452(@value{GDBP}) @b{tstop}
7453@end smallexample
7454
7455
7456@node Analyze Collected Data
7457@section Using the collected data
7458
7459After the tracepoint experiment ends, you use @value{GDBN} commands
7460for examining the trace data. The basic idea is that each tracepoint
7461collects a trace @dfn{snapshot} every time it is hit and another
7462snapshot every time it single-steps. All these snapshots are
7463consecutively numbered from zero and go into a buffer, and you can
7464examine them later. The way you examine them is to @dfn{focus} on a
7465specific trace snapshot. When the remote stub is focused on a trace
7466snapshot, it will respond to all @value{GDBN} requests for memory and
7467registers by reading from the buffer which belongs to that snapshot,
7468rather than from @emph{real} memory or registers of the program being
7469debugged. This means that @strong{all} @value{GDBN} commands
7470(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7471behave as if we were currently debugging the program state as it was
7472when the tracepoint occurred. Any requests for data that are not in
7473the buffer will fail.
7474
7475@menu
7476* tfind:: How to select a trace snapshot
7477* tdump:: How to display all data for a snapshot
7478* save-tracepoints:: How to save tracepoints for a future run
7479@end menu
7480
7481@node tfind
7482@subsection @code{tfind @var{n}}
7483
7484@kindex tfind
7485@cindex select trace snapshot
7486@cindex find trace snapshot
7487The basic command for selecting a trace snapshot from the buffer is
7488@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7489counting from zero. If no argument @var{n} is given, the next
7490snapshot is selected.
7491
7492Here are the various forms of using the @code{tfind} command.
7493
7494@table @code
7495@item tfind start
7496Find the first snapshot in the buffer. This is a synonym for
7497@code{tfind 0} (since 0 is the number of the first snapshot).
7498
7499@item tfind none
7500Stop debugging trace snapshots, resume @emph{live} debugging.
7501
7502@item tfind end
7503Same as @samp{tfind none}.
7504
7505@item tfind
7506No argument means find the next trace snapshot.
7507
7508@item tfind -
7509Find the previous trace snapshot before the current one. This permits
7510retracing earlier steps.
7511
7512@item tfind tracepoint @var{num}
7513Find the next snapshot associated with tracepoint @var{num}. Search
7514proceeds forward from the last examined trace snapshot. If no
7515argument @var{num} is given, it means find the next snapshot collected
7516for the same tracepoint as the current snapshot.
7517
7518@item tfind pc @var{addr}
7519Find the next snapshot associated with the value @var{addr} of the
7520program counter. Search proceeds forward from the last examined trace
7521snapshot. If no argument @var{addr} is given, it means find the next
7522snapshot with the same value of PC as the current snapshot.
7523
7524@item tfind outside @var{addr1}, @var{addr2}
7525Find the next snapshot whose PC is outside the given range of
7526addresses.
7527
7528@item tfind range @var{addr1}, @var{addr2}
7529Find the next snapshot whose PC is between @var{addr1} and
7530@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7531
7532@item tfind line @r{[}@var{file}:@r{]}@var{n}
7533Find the next snapshot associated with the source line @var{n}. If
7534the optional argument @var{file} is given, refer to line @var{n} in
7535that source file. Search proceeds forward from the last examined
7536trace snapshot. If no argument @var{n} is given, it means find the
7537next line other than the one currently being examined; thus saying
7538@code{tfind line} repeatedly can appear to have the same effect as
7539stepping from line to line in a @emph{live} debugging session.
7540@end table
7541
7542The default arguments for the @code{tfind} commands are specifically
7543designed to make it easy to scan through the trace buffer. For
7544instance, @code{tfind} with no argument selects the next trace
7545snapshot, and @code{tfind -} with no argument selects the previous
7546trace snapshot. So, by giving one @code{tfind} command, and then
7547simply hitting @key{RET} repeatedly you can examine all the trace
7548snapshots in order. Or, by saying @code{tfind -} and then hitting
7549@key{RET} repeatedly you can examine the snapshots in reverse order.
7550The @code{tfind line} command with no argument selects the snapshot
7551for the next source line executed. The @code{tfind pc} command with
7552no argument selects the next snapshot with the same program counter
7553(PC) as the current frame. The @code{tfind tracepoint} command with
7554no argument selects the next trace snapshot collected by the same
7555tracepoint as the current one.
7556
7557In addition to letting you scan through the trace buffer manually,
7558these commands make it easy to construct @value{GDBN} scripts that
7559scan through the trace buffer and print out whatever collected data
7560you are interested in. Thus, if we want to examine the PC, FP, and SP
7561registers from each trace frame in the buffer, we can say this:
7562
7563@smallexample
7564(@value{GDBP}) @b{tfind start}
7565(@value{GDBP}) @b{while ($trace_frame != -1)}
7566> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7567 $trace_frame, $pc, $sp, $fp
7568> tfind
7569> end
7570
7571Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7572Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7573Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7574Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7575Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7576Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7577Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7578Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7579Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7580Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7581Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7582@end smallexample
7583
7584Or, if we want to examine the variable @code{X} at each source line in
7585the buffer:
7586
7587@smallexample
7588(@value{GDBP}) @b{tfind start}
7589(@value{GDBP}) @b{while ($trace_frame != -1)}
7590> printf "Frame %d, X == %d\n", $trace_frame, X
7591> tfind line
7592> end
7593
7594Frame 0, X = 1
7595Frame 7, X = 2
7596Frame 13, X = 255
7597@end smallexample
7598
7599@node tdump
7600@subsection @code{tdump}
7601@kindex tdump
7602@cindex dump all data collected at tracepoint
7603@cindex tracepoint data, display
7604
7605This command takes no arguments. It prints all the data collected at
7606the current trace snapshot.
7607
7608@smallexample
7609(@value{GDBP}) @b{trace 444}
7610(@value{GDBP}) @b{actions}
7611Enter actions for tracepoint #2, one per line:
7612> collect $regs, $locals, $args, gdb_long_test
7613> end
7614
7615(@value{GDBP}) @b{tstart}
7616
7617(@value{GDBP}) @b{tfind line 444}
7618#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7619at gdb_test.c:444
7620444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7621
7622(@value{GDBP}) @b{tdump}
7623Data collected at tracepoint 2, trace frame 1:
7624d0 0xc4aa0085 -995491707
7625d1 0x18 24
7626d2 0x80 128
7627d3 0x33 51
7628d4 0x71aea3d 119204413
7629d5 0x22 34
7630d6 0xe0 224
7631d7 0x380035 3670069
7632a0 0x19e24a 1696330
7633a1 0x3000668 50333288
7634a2 0x100 256
7635a3 0x322000 3284992
7636a4 0x3000698 50333336
7637a5 0x1ad3cc 1758156
7638fp 0x30bf3c 0x30bf3c
7639sp 0x30bf34 0x30bf34
7640ps 0x0 0
7641pc 0x20b2c8 0x20b2c8
7642fpcontrol 0x0 0
7643fpstatus 0x0 0
7644fpiaddr 0x0 0
7645p = 0x20e5b4 "gdb-test"
7646p1 = (void *) 0x11
7647p2 = (void *) 0x22
7648p3 = (void *) 0x33
7649p4 = (void *) 0x44
7650p5 = (void *) 0x55
7651p6 = (void *) 0x66
7652gdb_long_test = 17 '\021'
7653
7654(@value{GDBP})
7655@end smallexample
7656
7657@node save-tracepoints
7658@subsection @code{save-tracepoints @var{filename}}
7659@kindex save-tracepoints
7660@cindex save tracepoints for future sessions
7661
7662This command saves all current tracepoint definitions together with
7663their actions and passcounts, into a file @file{@var{filename}}
7664suitable for use in a later debugging session. To read the saved
7665tracepoint definitions, use the @code{source} command (@pxref{Command
7666Files}).
7667
7668@node Tracepoint Variables
7669@section Convenience Variables for Tracepoints
7670@cindex tracepoint variables
7671@cindex convenience variables for tracepoints
7672
7673@table @code
7674@vindex $trace_frame
7675@item (int) $trace_frame
7676The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7677snapshot is selected.
7678
7679@vindex $tracepoint
7680@item (int) $tracepoint
7681The tracepoint for the current trace snapshot.
7682
7683@vindex $trace_line
7684@item (int) $trace_line
7685The line number for the current trace snapshot.
7686
7687@vindex $trace_file
7688@item (char []) $trace_file
7689The source file for the current trace snapshot.
7690
7691@vindex $trace_func
7692@item (char []) $trace_func
7693The name of the function containing @code{$tracepoint}.
7694@end table
7695
7696Note: @code{$trace_file} is not suitable for use in @code{printf},
7697use @code{output} instead.
7698
7699Here's a simple example of using these convenience variables for
7700stepping through all the trace snapshots and printing some of their
7701data.
7702
7703@smallexample
7704(@value{GDBP}) @b{tfind start}
7705
7706(@value{GDBP}) @b{while $trace_frame != -1}
7707> output $trace_file
7708> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7709> tfind
7710> end
7711@end smallexample
7712
df0cd8c5
JB
7713@node Overlays
7714@chapter Debugging Programs That Use Overlays
7715@cindex overlays
7716
7717If your program is too large to fit completely in your target system's
7718memory, you can sometimes use @dfn{overlays} to work around this
7719problem. @value{GDBN} provides some support for debugging programs that
7720use overlays.
7721
7722@menu
7723* How Overlays Work:: A general explanation of overlays.
7724* Overlay Commands:: Managing overlays in @value{GDBN}.
7725* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7726 mapped by asking the inferior.
7727* Overlay Sample Program:: A sample program using overlays.
7728@end menu
7729
7730@node How Overlays Work
7731@section How Overlays Work
7732@cindex mapped overlays
7733@cindex unmapped overlays
7734@cindex load address, overlay's
7735@cindex mapped address
7736@cindex overlay area
7737
7738Suppose you have a computer whose instruction address space is only 64
7739kilobytes long, but which has much more memory which can be accessed by
7740other means: special instructions, segment registers, or memory
7741management hardware, for example. Suppose further that you want to
7742adapt a program which is larger than 64 kilobytes to run on this system.
7743
7744One solution is to identify modules of your program which are relatively
7745independent, and need not call each other directly; call these modules
7746@dfn{overlays}. Separate the overlays from the main program, and place
7747their machine code in the larger memory. Place your main program in
7748instruction memory, but leave at least enough space there to hold the
7749largest overlay as well.
7750
7751Now, to call a function located in an overlay, you must first copy that
7752overlay's machine code from the large memory into the space set aside
7753for it in the instruction memory, and then jump to its entry point
7754there.
7755
c928edc0
AC
7756@c NB: In the below the mapped area's size is greater or equal to the
7757@c size of all overlays. This is intentional to remind the developer
7758@c that overlays don't necessarily need to be the same size.
7759
474c8240 7760@smallexample
df0cd8c5 7761@group
c928edc0
AC
7762 Data Instruction Larger
7763Address Space Address Space Address Space
7764+-----------+ +-----------+ +-----------+
7765| | | | | |
7766+-----------+ +-----------+ +-----------+<-- overlay 1
7767| program | | main | .----| overlay 1 | load address
7768| variables | | program | | +-----------+
7769| and heap | | | | | |
7770+-----------+ | | | +-----------+<-- overlay 2
7771| | +-----------+ | | | load address
7772+-----------+ | | | .-| overlay 2 |
7773 | | | | | |
7774 mapped --->+-----------+ | | +-----------+
7775 address | | | | | |
7776 | overlay | <-' | | |
7777 | area | <---' +-----------+<-- overlay 3
7778 | | <---. | | load address
7779 +-----------+ `--| overlay 3 |
7780 | | | |
7781 +-----------+ | |
7782 +-----------+
7783 | |
7784 +-----------+
7785
7786 @anchor{A code overlay}A code overlay
df0cd8c5 7787@end group
474c8240 7788@end smallexample
df0cd8c5 7789
c928edc0
AC
7790The diagram (@pxref{A code overlay}) shows a system with separate data
7791and instruction address spaces. To map an overlay, the program copies
7792its code from the larger address space to the instruction address space.
7793Since the overlays shown here all use the same mapped address, only one
7794may be mapped at a time. For a system with a single address space for
7795data and instructions, the diagram would be similar, except that the
7796program variables and heap would share an address space with the main
7797program and the overlay area.
df0cd8c5
JB
7798
7799An overlay loaded into instruction memory and ready for use is called a
7800@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7801instruction memory. An overlay not present (or only partially present)
7802in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7803is its address in the larger memory. The mapped address is also called
7804the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7805called the @dfn{load memory address}, or @dfn{LMA}.
7806
7807Unfortunately, overlays are not a completely transparent way to adapt a
7808program to limited instruction memory. They introduce a new set of
7809global constraints you must keep in mind as you design your program:
7810
7811@itemize @bullet
7812
7813@item
7814Before calling or returning to a function in an overlay, your program
7815must make sure that overlay is actually mapped. Otherwise, the call or
7816return will transfer control to the right address, but in the wrong
7817overlay, and your program will probably crash.
7818
7819@item
7820If the process of mapping an overlay is expensive on your system, you
7821will need to choose your overlays carefully to minimize their effect on
7822your program's performance.
7823
7824@item
7825The executable file you load onto your system must contain each
7826overlay's instructions, appearing at the overlay's load address, not its
7827mapped address. However, each overlay's instructions must be relocated
7828and its symbols defined as if the overlay were at its mapped address.
7829You can use GNU linker scripts to specify different load and relocation
7830addresses for pieces of your program; see @ref{Overlay Description,,,
7831ld.info, Using ld: the GNU linker}.
7832
7833@item
7834The procedure for loading executable files onto your system must be able
7835to load their contents into the larger address space as well as the
7836instruction and data spaces.
7837
7838@end itemize
7839
7840The overlay system described above is rather simple, and could be
7841improved in many ways:
7842
7843@itemize @bullet
7844
7845@item
7846If your system has suitable bank switch registers or memory management
7847hardware, you could use those facilities to make an overlay's load area
7848contents simply appear at their mapped address in instruction space.
7849This would probably be faster than copying the overlay to its mapped
7850area in the usual way.
7851
7852@item
7853If your overlays are small enough, you could set aside more than one
7854overlay area, and have more than one overlay mapped at a time.
7855
7856@item
7857You can use overlays to manage data, as well as instructions. In
7858general, data overlays are even less transparent to your design than
7859code overlays: whereas code overlays only require care when you call or
7860return to functions, data overlays require care every time you access
7861the data. Also, if you change the contents of a data overlay, you
7862must copy its contents back out to its load address before you can copy a
7863different data overlay into the same mapped area.
7864
7865@end itemize
7866
7867
7868@node Overlay Commands
7869@section Overlay Commands
7870
7871To use @value{GDBN}'s overlay support, each overlay in your program must
7872correspond to a separate section of the executable file. The section's
7873virtual memory address and load memory address must be the overlay's
7874mapped and load addresses. Identifying overlays with sections allows
7875@value{GDBN} to determine the appropriate address of a function or
7876variable, depending on whether the overlay is mapped or not.
7877
7878@value{GDBN}'s overlay commands all start with the word @code{overlay};
7879you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7880
7881@table @code
7882@item overlay off
4644b6e3 7883@kindex overlay
df0cd8c5
JB
7884Disable @value{GDBN}'s overlay support. When overlay support is
7885disabled, @value{GDBN} assumes that all functions and variables are
7886always present at their mapped addresses. By default, @value{GDBN}'s
7887overlay support is disabled.
7888
7889@item overlay manual
df0cd8c5
JB
7890@cindex manual overlay debugging
7891Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7892relies on you to tell it which overlays are mapped, and which are not,
7893using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7894commands described below.
7895
7896@item overlay map-overlay @var{overlay}
7897@itemx overlay map @var{overlay}
df0cd8c5
JB
7898@cindex map an overlay
7899Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7900be the name of the object file section containing the overlay. When an
7901overlay is mapped, @value{GDBN} assumes it can find the overlay's
7902functions and variables at their mapped addresses. @value{GDBN} assumes
7903that any other overlays whose mapped ranges overlap that of
7904@var{overlay} are now unmapped.
7905
7906@item overlay unmap-overlay @var{overlay}
7907@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7908@cindex unmap an overlay
7909Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7910must be the name of the object file section containing the overlay.
7911When an overlay is unmapped, @value{GDBN} assumes it can find the
7912overlay's functions and variables at their load addresses.
7913
7914@item overlay auto
df0cd8c5
JB
7915Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7916consults a data structure the overlay manager maintains in the inferior
7917to see which overlays are mapped. For details, see @ref{Automatic
7918Overlay Debugging}.
7919
7920@item overlay load-target
7921@itemx overlay load
df0cd8c5
JB
7922@cindex reloading the overlay table
7923Re-read the overlay table from the inferior. Normally, @value{GDBN}
7924re-reads the table @value{GDBN} automatically each time the inferior
7925stops, so this command should only be necessary if you have changed the
7926overlay mapping yourself using @value{GDBN}. This command is only
7927useful when using automatic overlay debugging.
7928
7929@item overlay list-overlays
7930@itemx overlay list
7931@cindex listing mapped overlays
7932Display a list of the overlays currently mapped, along with their mapped
7933addresses, load addresses, and sizes.
7934
7935@end table
7936
7937Normally, when @value{GDBN} prints a code address, it includes the name
7938of the function the address falls in:
7939
474c8240 7940@smallexample
f7dc1244 7941(@value{GDBP}) print main
df0cd8c5 7942$3 = @{int ()@} 0x11a0 <main>
474c8240 7943@end smallexample
df0cd8c5
JB
7944@noindent
7945When overlay debugging is enabled, @value{GDBN} recognizes code in
7946unmapped overlays, and prints the names of unmapped functions with
7947asterisks around them. For example, if @code{foo} is a function in an
7948unmapped overlay, @value{GDBN} prints it this way:
7949
474c8240 7950@smallexample
f7dc1244 7951(@value{GDBP}) overlay list
df0cd8c5 7952No sections are mapped.
f7dc1244 7953(@value{GDBP}) print foo
df0cd8c5 7954$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7955@end smallexample
df0cd8c5
JB
7956@noindent
7957When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7958name normally:
7959
474c8240 7960@smallexample
f7dc1244 7961(@value{GDBP}) overlay list
b383017d 7962Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7963 mapped at 0x1016 - 0x104a
f7dc1244 7964(@value{GDBP}) print foo
df0cd8c5 7965$6 = @{int (int)@} 0x1016 <foo>
474c8240 7966@end smallexample
df0cd8c5
JB
7967
7968When overlay debugging is enabled, @value{GDBN} can find the correct
7969address for functions and variables in an overlay, whether or not the
7970overlay is mapped. This allows most @value{GDBN} commands, like
7971@code{break} and @code{disassemble}, to work normally, even on unmapped
7972code. However, @value{GDBN}'s breakpoint support has some limitations:
7973
7974@itemize @bullet
7975@item
7976@cindex breakpoints in overlays
7977@cindex overlays, setting breakpoints in
7978You can set breakpoints in functions in unmapped overlays, as long as
7979@value{GDBN} can write to the overlay at its load address.
7980@item
7981@value{GDBN} can not set hardware or simulator-based breakpoints in
7982unmapped overlays. However, if you set a breakpoint at the end of your
7983overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7984you are using manual overlay management), @value{GDBN} will re-set its
7985breakpoints properly.
7986@end itemize
7987
7988
7989@node Automatic Overlay Debugging
7990@section Automatic Overlay Debugging
7991@cindex automatic overlay debugging
7992
7993@value{GDBN} can automatically track which overlays are mapped and which
7994are not, given some simple co-operation from the overlay manager in the
7995inferior. If you enable automatic overlay debugging with the
7996@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7997looks in the inferior's memory for certain variables describing the
7998current state of the overlays.
7999
8000Here are the variables your overlay manager must define to support
8001@value{GDBN}'s automatic overlay debugging:
8002
8003@table @asis
8004
8005@item @code{_ovly_table}:
8006This variable must be an array of the following structures:
8007
474c8240 8008@smallexample
df0cd8c5
JB
8009struct
8010@{
8011 /* The overlay's mapped address. */
8012 unsigned long vma;
8013
8014 /* The size of the overlay, in bytes. */
8015 unsigned long size;
8016
8017 /* The overlay's load address. */
8018 unsigned long lma;
8019
8020 /* Non-zero if the overlay is currently mapped;
8021 zero otherwise. */
8022 unsigned long mapped;
8023@}
474c8240 8024@end smallexample
df0cd8c5
JB
8025
8026@item @code{_novlys}:
8027This variable must be a four-byte signed integer, holding the total
8028number of elements in @code{_ovly_table}.
8029
8030@end table
8031
8032To decide whether a particular overlay is mapped or not, @value{GDBN}
8033looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8034@code{lma} members equal the VMA and LMA of the overlay's section in the
8035executable file. When @value{GDBN} finds a matching entry, it consults
8036the entry's @code{mapped} member to determine whether the overlay is
8037currently mapped.
8038
81d46470 8039In addition, your overlay manager may define a function called
def71bfa 8040@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8041will silently set a breakpoint there. If the overlay manager then
8042calls this function whenever it has changed the overlay table, this
8043will enable @value{GDBN} to accurately keep track of which overlays
8044are in program memory, and update any breakpoints that may be set
b383017d 8045in overlays. This will allow breakpoints to work even if the
81d46470
MS
8046overlays are kept in ROM or other non-writable memory while they
8047are not being executed.
df0cd8c5
JB
8048
8049@node Overlay Sample Program
8050@section Overlay Sample Program
8051@cindex overlay example program
8052
8053When linking a program which uses overlays, you must place the overlays
8054at their load addresses, while relocating them to run at their mapped
8055addresses. To do this, you must write a linker script (@pxref{Overlay
8056Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8057since linker scripts are specific to a particular host system, target
8058architecture, and target memory layout, this manual cannot provide
8059portable sample code demonstrating @value{GDBN}'s overlay support.
8060
8061However, the @value{GDBN} source distribution does contain an overlaid
8062program, with linker scripts for a few systems, as part of its test
8063suite. The program consists of the following files from
8064@file{gdb/testsuite/gdb.base}:
8065
8066@table @file
8067@item overlays.c
8068The main program file.
8069@item ovlymgr.c
8070A simple overlay manager, used by @file{overlays.c}.
8071@item foo.c
8072@itemx bar.c
8073@itemx baz.c
8074@itemx grbx.c
8075Overlay modules, loaded and used by @file{overlays.c}.
8076@item d10v.ld
8077@itemx m32r.ld
8078Linker scripts for linking the test program on the @code{d10v-elf}
8079and @code{m32r-elf} targets.
8080@end table
8081
8082You can build the test program using the @code{d10v-elf} GCC
8083cross-compiler like this:
8084
474c8240 8085@smallexample
df0cd8c5
JB
8086$ d10v-elf-gcc -g -c overlays.c
8087$ d10v-elf-gcc -g -c ovlymgr.c
8088$ d10v-elf-gcc -g -c foo.c
8089$ d10v-elf-gcc -g -c bar.c
8090$ d10v-elf-gcc -g -c baz.c
8091$ d10v-elf-gcc -g -c grbx.c
8092$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8093 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8094@end smallexample
df0cd8c5
JB
8095
8096The build process is identical for any other architecture, except that
8097you must substitute the appropriate compiler and linker script for the
8098target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8099
8100
6d2ebf8b 8101@node Languages
c906108c
SS
8102@chapter Using @value{GDBN} with Different Languages
8103@cindex languages
8104
c906108c
SS
8105Although programming languages generally have common aspects, they are
8106rarely expressed in the same manner. For instance, in ANSI C,
8107dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8108Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8109represented (and displayed) differently. Hex numbers in C appear as
c906108c 8110@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8111
8112@cindex working language
8113Language-specific information is built into @value{GDBN} for some languages,
8114allowing you to express operations like the above in your program's
8115native language, and allowing @value{GDBN} to output values in a manner
8116consistent with the syntax of your program's native language. The
8117language you use to build expressions is called the @dfn{working
8118language}.
8119
8120@menu
8121* Setting:: Switching between source languages
8122* Show:: Displaying the language
c906108c 8123* Checks:: Type and range checks
9c16f35a 8124* Supported languages:: Supported languages
4e562065 8125* Unsupported languages:: Unsupported languages
c906108c
SS
8126@end menu
8127
6d2ebf8b 8128@node Setting
c906108c
SS
8129@section Switching between source languages
8130
8131There are two ways to control the working language---either have @value{GDBN}
8132set it automatically, or select it manually yourself. You can use the
8133@code{set language} command for either purpose. On startup, @value{GDBN}
8134defaults to setting the language automatically. The working language is
8135used to determine how expressions you type are interpreted, how values
8136are printed, etc.
8137
8138In addition to the working language, every source file that
8139@value{GDBN} knows about has its own working language. For some object
8140file formats, the compiler might indicate which language a particular
8141source file is in. However, most of the time @value{GDBN} infers the
8142language from the name of the file. The language of a source file
b37052ae 8143controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8144show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8145set the language of a source file from within @value{GDBN}, but you can
8146set the language associated with a filename extension. @xref{Show, ,
8147Displaying the language}.
c906108c
SS
8148
8149This is most commonly a problem when you use a program, such
5d161b24 8150as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8151another language. In that case, make the
8152program use @code{#line} directives in its C output; that way
8153@value{GDBN} will know the correct language of the source code of the original
8154program, and will display that source code, not the generated C code.
8155
8156@menu
8157* Filenames:: Filename extensions and languages.
8158* Manually:: Setting the working language manually
8159* Automatically:: Having @value{GDBN} infer the source language
8160@end menu
8161
6d2ebf8b 8162@node Filenames
c906108c
SS
8163@subsection List of filename extensions and languages
8164
8165If a source file name ends in one of the following extensions, then
8166@value{GDBN} infers that its language is the one indicated.
8167
8168@table @file
e07c999f
PH
8169@item .ada
8170@itemx .ads
8171@itemx .adb
8172@itemx .a
8173Ada source file.
c906108c
SS
8174
8175@item .c
8176C source file
8177
8178@item .C
8179@itemx .cc
8180@itemx .cp
8181@itemx .cpp
8182@itemx .cxx
8183@itemx .c++
b37052ae 8184C@t{++} source file
c906108c 8185
b37303ee
AF
8186@item .m
8187Objective-C source file
8188
c906108c
SS
8189@item .f
8190@itemx .F
8191Fortran source file
8192
c906108c
SS
8193@item .mod
8194Modula-2 source file
c906108c
SS
8195
8196@item .s
8197@itemx .S
8198Assembler source file. This actually behaves almost like C, but
8199@value{GDBN} does not skip over function prologues when stepping.
8200@end table
8201
8202In addition, you may set the language associated with a filename
8203extension. @xref{Show, , Displaying the language}.
8204
6d2ebf8b 8205@node Manually
c906108c
SS
8206@subsection Setting the working language
8207
8208If you allow @value{GDBN} to set the language automatically,
8209expressions are interpreted the same way in your debugging session and
8210your program.
8211
8212@kindex set language
8213If you wish, you may set the language manually. To do this, issue the
8214command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8215a language, such as
c906108c 8216@code{c} or @code{modula-2}.
c906108c
SS
8217For a list of the supported languages, type @samp{set language}.
8218
c906108c
SS
8219Setting the language manually prevents @value{GDBN} from updating the working
8220language automatically. This can lead to confusion if you try
8221to debug a program when the working language is not the same as the
8222source language, when an expression is acceptable to both
8223languages---but means different things. For instance, if the current
8224source file were written in C, and @value{GDBN} was parsing Modula-2, a
8225command such as:
8226
474c8240 8227@smallexample
c906108c 8228print a = b + c
474c8240 8229@end smallexample
c906108c
SS
8230
8231@noindent
8232might not have the effect you intended. In C, this means to add
8233@code{b} and @code{c} and place the result in @code{a}. The result
8234printed would be the value of @code{a}. In Modula-2, this means to compare
8235@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8236
6d2ebf8b 8237@node Automatically
c906108c
SS
8238@subsection Having @value{GDBN} infer the source language
8239
8240To have @value{GDBN} set the working language automatically, use
8241@samp{set language local} or @samp{set language auto}. @value{GDBN}
8242then infers the working language. That is, when your program stops in a
8243frame (usually by encountering a breakpoint), @value{GDBN} sets the
8244working language to the language recorded for the function in that
8245frame. If the language for a frame is unknown (that is, if the function
8246or block corresponding to the frame was defined in a source file that
8247does not have a recognized extension), the current working language is
8248not changed, and @value{GDBN} issues a warning.
8249
8250This may not seem necessary for most programs, which are written
8251entirely in one source language. However, program modules and libraries
8252written in one source language can be used by a main program written in
8253a different source language. Using @samp{set language auto} in this
8254case frees you from having to set the working language manually.
8255
6d2ebf8b 8256@node Show
c906108c 8257@section Displaying the language
c906108c
SS
8258
8259The following commands help you find out which language is the
8260working language, and also what language source files were written in.
8261
c906108c
SS
8262@table @code
8263@item show language
9c16f35a 8264@kindex show language
c906108c
SS
8265Display the current working language. This is the
8266language you can use with commands such as @code{print} to
8267build and compute expressions that may involve variables in your program.
8268
8269@item info frame
4644b6e3 8270@kindex info frame@r{, show the source language}
5d161b24 8271Display the source language for this frame. This language becomes the
c906108c 8272working language if you use an identifier from this frame.
5d161b24 8273@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8274information listed here.
8275
8276@item info source
4644b6e3 8277@kindex info source@r{, show the source language}
c906108c 8278Display the source language of this source file.
5d161b24 8279@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8280information listed here.
8281@end table
8282
8283In unusual circumstances, you may have source files with extensions
8284not in the standard list. You can then set the extension associated
8285with a language explicitly:
8286
c906108c 8287@table @code
09d4efe1 8288@item set extension-language @var{ext} @var{language}
9c16f35a 8289@kindex set extension-language
09d4efe1
EZ
8290Tell @value{GDBN} that source files with extension @var{ext} are to be
8291assumed as written in the source language @var{language}.
c906108c
SS
8292
8293@item info extensions
9c16f35a 8294@kindex info extensions
c906108c
SS
8295List all the filename extensions and the associated languages.
8296@end table
8297
6d2ebf8b 8298@node Checks
c906108c
SS
8299@section Type and range checking
8300
8301@quotation
8302@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8303checking are included, but they do not yet have any effect. This
8304section documents the intended facilities.
8305@end quotation
8306@c FIXME remove warning when type/range code added
8307
8308Some languages are designed to guard you against making seemingly common
8309errors through a series of compile- and run-time checks. These include
8310checking the type of arguments to functions and operators, and making
8311sure mathematical overflows are caught at run time. Checks such as
8312these help to ensure a program's correctness once it has been compiled
8313by eliminating type mismatches, and providing active checks for range
8314errors when your program is running.
8315
8316@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8317Although @value{GDBN} does not check the statements in your program,
8318it can check expressions entered directly into @value{GDBN} for
8319evaluation via the @code{print} command, for example. As with the
8320working language, @value{GDBN} can also decide whether or not to check
8321automatically based on your program's source language.
8322@xref{Supported languages, ,Supported languages}, for the default
8323settings of supported languages.
c906108c
SS
8324
8325@menu
8326* Type Checking:: An overview of type checking
8327* Range Checking:: An overview of range checking
8328@end menu
8329
8330@cindex type checking
8331@cindex checks, type
6d2ebf8b 8332@node Type Checking
c906108c
SS
8333@subsection An overview of type checking
8334
8335Some languages, such as Modula-2, are strongly typed, meaning that the
8336arguments to operators and functions have to be of the correct type,
8337otherwise an error occurs. These checks prevent type mismatch
8338errors from ever causing any run-time problems. For example,
8339
8340@smallexample
83411 + 2 @result{} 3
8342@exdent but
8343@error{} 1 + 2.3
8344@end smallexample
8345
8346The second example fails because the @code{CARDINAL} 1 is not
8347type-compatible with the @code{REAL} 2.3.
8348
5d161b24
DB
8349For the expressions you use in @value{GDBN} commands, you can tell the
8350@value{GDBN} type checker to skip checking;
8351to treat any mismatches as errors and abandon the expression;
8352or to only issue warnings when type mismatches occur,
c906108c
SS
8353but evaluate the expression anyway. When you choose the last of
8354these, @value{GDBN} evaluates expressions like the second example above, but
8355also issues a warning.
8356
5d161b24
DB
8357Even if you turn type checking off, there may be other reasons
8358related to type that prevent @value{GDBN} from evaluating an expression.
8359For instance, @value{GDBN} does not know how to add an @code{int} and
8360a @code{struct foo}. These particular type errors have nothing to do
8361with the language in use, and usually arise from expressions, such as
c906108c
SS
8362the one described above, which make little sense to evaluate anyway.
8363
8364Each language defines to what degree it is strict about type. For
8365instance, both Modula-2 and C require the arguments to arithmetical
8366operators to be numbers. In C, enumerated types and pointers can be
8367represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8368operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8369details on specific languages.
8370
8371@value{GDBN} provides some additional commands for controlling the type checker:
8372
c906108c
SS
8373@kindex set check type
8374@kindex show check type
8375@table @code
8376@item set check type auto
8377Set type checking on or off based on the current working language.
9c16f35a 8378@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8379each language.
8380
8381@item set check type on
8382@itemx set check type off
8383Set type checking on or off, overriding the default setting for the
8384current working language. Issue a warning if the setting does not
8385match the language default. If any type mismatches occur in
d4f3574e 8386evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8387message and aborts evaluation of the expression.
8388
8389@item set check type warn
8390Cause the type checker to issue warnings, but to always attempt to
8391evaluate the expression. Evaluating the expression may still
8392be impossible for other reasons. For example, @value{GDBN} cannot add
8393numbers and structures.
8394
8395@item show type
5d161b24 8396Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8397is setting it automatically.
8398@end table
8399
8400@cindex range checking
8401@cindex checks, range
6d2ebf8b 8402@node Range Checking
c906108c
SS
8403@subsection An overview of range checking
8404
8405In some languages (such as Modula-2), it is an error to exceed the
8406bounds of a type; this is enforced with run-time checks. Such range
8407checking is meant to ensure program correctness by making sure
8408computations do not overflow, or indices on an array element access do
8409not exceed the bounds of the array.
8410
8411For expressions you use in @value{GDBN} commands, you can tell
8412@value{GDBN} to treat range errors in one of three ways: ignore them,
8413always treat them as errors and abandon the expression, or issue
8414warnings but evaluate the expression anyway.
8415
8416A range error can result from numerical overflow, from exceeding an
8417array index bound, or when you type a constant that is not a member
8418of any type. Some languages, however, do not treat overflows as an
8419error. In many implementations of C, mathematical overflow causes the
8420result to ``wrap around'' to lower values---for example, if @var{m} is
8421the largest integer value, and @var{s} is the smallest, then
8422
474c8240 8423@smallexample
c906108c 8424@var{m} + 1 @result{} @var{s}
474c8240 8425@end smallexample
c906108c
SS
8426
8427This, too, is specific to individual languages, and in some cases
9c16f35a 8428specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8429Supported languages}, for further details on specific languages.
8430
8431@value{GDBN} provides some additional commands for controlling the range checker:
8432
c906108c
SS
8433@kindex set check range
8434@kindex show check range
8435@table @code
8436@item set check range auto
8437Set range checking on or off based on the current working language.
9c16f35a 8438@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8439each language.
8440
8441@item set check range on
8442@itemx set check range off
8443Set range checking on or off, overriding the default setting for the
8444current working language. A warning is issued if the setting does not
c3f6f71d
JM
8445match the language default. If a range error occurs and range checking is on,
8446then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8447
8448@item set check range warn
8449Output messages when the @value{GDBN} range checker detects a range error,
8450but attempt to evaluate the expression anyway. Evaluating the
8451expression may still be impossible for other reasons, such as accessing
8452memory that the process does not own (a typical example from many Unix
8453systems).
8454
8455@item show range
8456Show the current setting of the range checker, and whether or not it is
8457being set automatically by @value{GDBN}.
8458@end table
c906108c 8459
9c16f35a 8460@node Supported languages
c906108c 8461@section Supported languages
c906108c 8462
9c16f35a
EZ
8463@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8464assembly, Modula-2, and Ada.
cce74817 8465@c This is false ...
c906108c
SS
8466Some @value{GDBN} features may be used in expressions regardless of the
8467language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8468and the @samp{@{type@}addr} construct (@pxref{Expressions,
8469,Expressions}) can be used with the constructs of any supported
8470language.
8471
8472The following sections detail to what degree each source language is
8473supported by @value{GDBN}. These sections are not meant to be language
8474tutorials or references, but serve only as a reference guide to what the
8475@value{GDBN} expression parser accepts, and what input and output
8476formats should look like for different languages. There are many good
8477books written on each of these languages; please look to these for a
8478language reference or tutorial.
8479
c906108c 8480@menu
b37303ee 8481* C:: C and C@t{++}
b383017d 8482* Objective-C:: Objective-C
09d4efe1 8483* Fortran:: Fortran
9c16f35a 8484* Pascal:: Pascal
b37303ee 8485* Modula-2:: Modula-2
e07c999f 8486* Ada:: Ada
c906108c
SS
8487@end menu
8488
6d2ebf8b 8489@node C
b37052ae 8490@subsection C and C@t{++}
7a292a7a 8491
b37052ae
EZ
8492@cindex C and C@t{++}
8493@cindex expressions in C or C@t{++}
c906108c 8494
b37052ae 8495Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8496to both languages. Whenever this is the case, we discuss those languages
8497together.
8498
41afff9a
EZ
8499@cindex C@t{++}
8500@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8501@cindex @sc{gnu} C@t{++}
8502The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8503compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8504effectively, you must compile your C@t{++} programs with a supported
8505C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8506compiler (@code{aCC}).
8507
0179ffac
DC
8508For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8509format; if it doesn't work on your system, try the stabs+ debugging
8510format. You can select those formats explicitly with the @code{g++}
8511command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8512@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8513CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8514
c906108c 8515@menu
b37052ae
EZ
8516* C Operators:: C and C@t{++} operators
8517* C Constants:: C and C@t{++} constants
8518* C plus plus expressions:: C@t{++} expressions
8519* C Defaults:: Default settings for C and C@t{++}
8520* C Checks:: C and C@t{++} type and range checks
c906108c 8521* Debugging C:: @value{GDBN} and C
b37052ae 8522* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8523@end menu
c906108c 8524
6d2ebf8b 8525@node C Operators
b37052ae 8526@subsubsection C and C@t{++} operators
7a292a7a 8527
b37052ae 8528@cindex C and C@t{++} operators
c906108c
SS
8529
8530Operators must be defined on values of specific types. For instance,
8531@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8532often defined on groups of types.
c906108c 8533
b37052ae 8534For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8535
8536@itemize @bullet
53a5351d 8537
c906108c 8538@item
c906108c 8539@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8540specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8541
8542@item
d4f3574e
SS
8543@emph{Floating-point types} include @code{float}, @code{double}, and
8544@code{long double} (if supported by the target platform).
c906108c
SS
8545
8546@item
53a5351d 8547@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8548
8549@item
8550@emph{Scalar types} include all of the above.
53a5351d 8551
c906108c
SS
8552@end itemize
8553
8554@noindent
8555The following operators are supported. They are listed here
8556in order of increasing precedence:
8557
8558@table @code
8559@item ,
8560The comma or sequencing operator. Expressions in a comma-separated list
8561are evaluated from left to right, with the result of the entire
8562expression being the last expression evaluated.
8563
8564@item =
8565Assignment. The value of an assignment expression is the value
8566assigned. Defined on scalar types.
8567
8568@item @var{op}=
8569Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8570and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8571@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8572@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8573@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8574
8575@item ?:
8576The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8577of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8578integral type.
8579
8580@item ||
8581Logical @sc{or}. Defined on integral types.
8582
8583@item &&
8584Logical @sc{and}. Defined on integral types.
8585
8586@item |
8587Bitwise @sc{or}. Defined on integral types.
8588
8589@item ^
8590Bitwise exclusive-@sc{or}. Defined on integral types.
8591
8592@item &
8593Bitwise @sc{and}. Defined on integral types.
8594
8595@item ==@r{, }!=
8596Equality and inequality. Defined on scalar types. The value of these
8597expressions is 0 for false and non-zero for true.
8598
8599@item <@r{, }>@r{, }<=@r{, }>=
8600Less than, greater than, less than or equal, greater than or equal.
8601Defined on scalar types. The value of these expressions is 0 for false
8602and non-zero for true.
8603
8604@item <<@r{, }>>
8605left shift, and right shift. Defined on integral types.
8606
8607@item @@
8608The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8609
8610@item +@r{, }-
8611Addition and subtraction. Defined on integral types, floating-point types and
8612pointer types.
8613
8614@item *@r{, }/@r{, }%
8615Multiplication, division, and modulus. Multiplication and division are
8616defined on integral and floating-point types. Modulus is defined on
8617integral types.
8618
8619@item ++@r{, }--
8620Increment and decrement. When appearing before a variable, the
8621operation is performed before the variable is used in an expression;
8622when appearing after it, the variable's value is used before the
8623operation takes place.
8624
8625@item *
8626Pointer dereferencing. Defined on pointer types. Same precedence as
8627@code{++}.
8628
8629@item &
8630Address operator. Defined on variables. Same precedence as @code{++}.
8631
b37052ae
EZ
8632For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8633allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8634(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8635where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8636stored.
c906108c
SS
8637
8638@item -
8639Negative. Defined on integral and floating-point types. Same
8640precedence as @code{++}.
8641
8642@item !
8643Logical negation. Defined on integral types. Same precedence as
8644@code{++}.
8645
8646@item ~
8647Bitwise complement operator. Defined on integral types. Same precedence as
8648@code{++}.
8649
8650
8651@item .@r{, }->
8652Structure member, and pointer-to-structure member. For convenience,
8653@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8654pointer based on the stored type information.
8655Defined on @code{struct} and @code{union} data.
8656
c906108c
SS
8657@item .*@r{, }->*
8658Dereferences of pointers to members.
c906108c
SS
8659
8660@item []
8661Array indexing. @code{@var{a}[@var{i}]} is defined as
8662@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8663
8664@item ()
8665Function parameter list. Same precedence as @code{->}.
8666
c906108c 8667@item ::
b37052ae 8668C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8669and @code{class} types.
c906108c
SS
8670
8671@item ::
7a292a7a
SS
8672Doubled colons also represent the @value{GDBN} scope operator
8673(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8674above.
c906108c
SS
8675@end table
8676
c906108c
SS
8677If an operator is redefined in the user code, @value{GDBN} usually
8678attempts to invoke the redefined version instead of using the operator's
8679predefined meaning.
c906108c 8680
c906108c 8681@menu
5d161b24 8682* C Constants::
c906108c
SS
8683@end menu
8684
6d2ebf8b 8685@node C Constants
b37052ae 8686@subsubsection C and C@t{++} constants
c906108c 8687
b37052ae 8688@cindex C and C@t{++} constants
c906108c 8689
b37052ae 8690@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8691following ways:
c906108c
SS
8692
8693@itemize @bullet
8694@item
8695Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8696specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8697by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8698@samp{l}, specifying that the constant should be treated as a
8699@code{long} value.
8700
8701@item
8702Floating point constants are a sequence of digits, followed by a decimal
8703point, followed by a sequence of digits, and optionally followed by an
8704exponent. An exponent is of the form:
8705@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8706sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8707A floating-point constant may also end with a letter @samp{f} or
8708@samp{F}, specifying that the constant should be treated as being of
8709the @code{float} (as opposed to the default @code{double}) type; or with
8710a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8711constant.
c906108c
SS
8712
8713@item
8714Enumerated constants consist of enumerated identifiers, or their
8715integral equivalents.
8716
8717@item
8718Character constants are a single character surrounded by single quotes
8719(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8720(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8721be represented by a letter or by @dfn{escape sequences}, which are of
8722the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8723of the character's ordinal value; or of the form @samp{\@var{x}}, where
8724@samp{@var{x}} is a predefined special character---for example,
8725@samp{\n} for newline.
8726
8727@item
96a2c332
SS
8728String constants are a sequence of character constants surrounded by
8729double quotes (@code{"}). Any valid character constant (as described
8730above) may appear. Double quotes within the string must be preceded by
8731a backslash, so for instance @samp{"a\"b'c"} is a string of five
8732characters.
c906108c
SS
8733
8734@item
8735Pointer constants are an integral value. You can also write pointers
8736to constants using the C operator @samp{&}.
8737
8738@item
8739Array constants are comma-separated lists surrounded by braces @samp{@{}
8740and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8741integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8742and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8743@end itemize
8744
c906108c 8745@menu
5d161b24
DB
8746* C plus plus expressions::
8747* C Defaults::
8748* C Checks::
c906108c 8749
5d161b24 8750* Debugging C::
c906108c
SS
8751@end menu
8752
6d2ebf8b 8753@node C plus plus expressions
b37052ae
EZ
8754@subsubsection C@t{++} expressions
8755
8756@cindex expressions in C@t{++}
8757@value{GDBN} expression handling can interpret most C@t{++} expressions.
8758
0179ffac
DC
8759@cindex debugging C@t{++} programs
8760@cindex C@t{++} compilers
8761@cindex debug formats and C@t{++}
8762@cindex @value{NGCC} and C@t{++}
c906108c 8763@quotation
b37052ae 8764@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8765proper compiler and the proper debug format. Currently, @value{GDBN}
8766works best when debugging C@t{++} code that is compiled with
8767@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8768@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8769stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8770stabs+ as their default debug format, so you usually don't need to
8771specify a debug format explicitly. Other compilers and/or debug formats
8772are likely to work badly or not at all when using @value{GDBN} to debug
8773C@t{++} code.
c906108c 8774@end quotation
c906108c
SS
8775
8776@enumerate
8777
8778@cindex member functions
8779@item
8780Member function calls are allowed; you can use expressions like
8781
474c8240 8782@smallexample
c906108c 8783count = aml->GetOriginal(x, y)
474c8240 8784@end smallexample
c906108c 8785
41afff9a 8786@vindex this@r{, inside C@t{++} member functions}
b37052ae 8787@cindex namespace in C@t{++}
c906108c
SS
8788@item
8789While a member function is active (in the selected stack frame), your
8790expressions have the same namespace available as the member function;
8791that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8792pointer @code{this} following the same rules as C@t{++}.
c906108c 8793
c906108c 8794@cindex call overloaded functions
d4f3574e 8795@cindex overloaded functions, calling
b37052ae 8796@cindex type conversions in C@t{++}
c906108c
SS
8797@item
8798You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8799call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8800perform overload resolution involving user-defined type conversions,
8801calls to constructors, or instantiations of templates that do not exist
8802in the program. It also cannot handle ellipsis argument lists or
8803default arguments.
8804
8805It does perform integral conversions and promotions, floating-point
8806promotions, arithmetic conversions, pointer conversions, conversions of
8807class objects to base classes, and standard conversions such as those of
8808functions or arrays to pointers; it requires an exact match on the
8809number of function arguments.
8810
8811Overload resolution is always performed, unless you have specified
8812@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8813,@value{GDBN} features for C@t{++}}.
c906108c 8814
d4f3574e 8815You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8816explicit function signature to call an overloaded function, as in
8817@smallexample
8818p 'foo(char,int)'('x', 13)
8819@end smallexample
d4f3574e 8820
c906108c 8821The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8822see @ref{Completion, ,Command completion}.
c906108c 8823
c906108c
SS
8824@cindex reference declarations
8825@item
b37052ae
EZ
8826@value{GDBN} understands variables declared as C@t{++} references; you can use
8827them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8828dereferenced.
8829
8830In the parameter list shown when @value{GDBN} displays a frame, the values of
8831reference variables are not displayed (unlike other variables); this
8832avoids clutter, since references are often used for large structures.
8833The @emph{address} of a reference variable is always shown, unless
8834you have specified @samp{set print address off}.
8835
8836@item
b37052ae 8837@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8838expressions can use it just as expressions in your program do. Since
8839one scope may be defined in another, you can use @code{::} repeatedly if
8840necessary, for example in an expression like
8841@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8842resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8843debugging (@pxref{Variables, ,Program variables}).
8844@end enumerate
8845
b37052ae 8846In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8847calling virtual functions correctly, printing out virtual bases of
8848objects, calling functions in a base subobject, casting objects, and
8849invoking user-defined operators.
c906108c 8850
6d2ebf8b 8851@node C Defaults
b37052ae 8852@subsubsection C and C@t{++} defaults
7a292a7a 8853
b37052ae 8854@cindex C and C@t{++} defaults
c906108c 8855
c906108c
SS
8856If you allow @value{GDBN} to set type and range checking automatically, they
8857both default to @code{off} whenever the working language changes to
b37052ae 8858C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8859selects the working language.
c906108c
SS
8860
8861If you allow @value{GDBN} to set the language automatically, it
8862recognizes source files whose names end with @file{.c}, @file{.C}, or
8863@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8864these files, it sets the working language to C or C@t{++}.
c906108c
SS
8865@xref{Automatically, ,Having @value{GDBN} infer the source language},
8866for further details.
8867
c906108c
SS
8868@c Type checking is (a) primarily motivated by Modula-2, and (b)
8869@c unimplemented. If (b) changes, it might make sense to let this node
8870@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8871
6d2ebf8b 8872@node C Checks
b37052ae 8873@subsubsection C and C@t{++} type and range checks
7a292a7a 8874
b37052ae 8875@cindex C and C@t{++} checks
c906108c 8876
b37052ae 8877By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8878is not used. However, if you turn type checking on, @value{GDBN}
8879considers two variables type equivalent if:
8880
8881@itemize @bullet
8882@item
8883The two variables are structured and have the same structure, union, or
8884enumerated tag.
8885
8886@item
8887The two variables have the same type name, or types that have been
8888declared equivalent through @code{typedef}.
8889
8890@ignore
8891@c leaving this out because neither J Gilmore nor R Pesch understand it.
8892@c FIXME--beers?
8893@item
8894The two @code{struct}, @code{union}, or @code{enum} variables are
8895declared in the same declaration. (Note: this may not be true for all C
8896compilers.)
8897@end ignore
8898@end itemize
8899
8900Range checking, if turned on, is done on mathematical operations. Array
8901indices are not checked, since they are often used to index a pointer
8902that is not itself an array.
c906108c 8903
6d2ebf8b 8904@node Debugging C
c906108c 8905@subsubsection @value{GDBN} and C
c906108c
SS
8906
8907The @code{set print union} and @code{show print union} commands apply to
8908the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8909inside a @code{struct} or @code{class} is also printed. Otherwise, it
8910appears as @samp{@{...@}}.
c906108c
SS
8911
8912The @code{@@} operator aids in the debugging of dynamic arrays, formed
8913with pointers and a memory allocation function. @xref{Expressions,
8914,Expressions}.
8915
c906108c 8916@menu
5d161b24 8917* Debugging C plus plus::
c906108c
SS
8918@end menu
8919
6d2ebf8b 8920@node Debugging C plus plus
b37052ae 8921@subsubsection @value{GDBN} features for C@t{++}
c906108c 8922
b37052ae 8923@cindex commands for C@t{++}
7a292a7a 8924
b37052ae
EZ
8925Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8926designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8927
8928@table @code
8929@cindex break in overloaded functions
8930@item @r{breakpoint menus}
8931When you want a breakpoint in a function whose name is overloaded,
8932@value{GDBN} breakpoint menus help you specify which function definition
8933you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8934
b37052ae 8935@cindex overloading in C@t{++}
c906108c
SS
8936@item rbreak @var{regex}
8937Setting breakpoints using regular expressions is helpful for setting
8938breakpoints on overloaded functions that are not members of any special
8939classes.
8940@xref{Set Breaks, ,Setting breakpoints}.
8941
b37052ae 8942@cindex C@t{++} exception handling
c906108c
SS
8943@item catch throw
8944@itemx catch catch
b37052ae 8945Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8946Catchpoints, , Setting catchpoints}.
8947
8948@cindex inheritance
8949@item ptype @var{typename}
8950Print inheritance relationships as well as other information for type
8951@var{typename}.
8952@xref{Symbols, ,Examining the Symbol Table}.
8953
b37052ae 8954@cindex C@t{++} symbol display
c906108c
SS
8955@item set print demangle
8956@itemx show print demangle
8957@itemx set print asm-demangle
8958@itemx show print asm-demangle
b37052ae
EZ
8959Control whether C@t{++} symbols display in their source form, both when
8960displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8961@xref{Print Settings, ,Print settings}.
8962
8963@item set print object
8964@itemx show print object
8965Choose whether to print derived (actual) or declared types of objects.
8966@xref{Print Settings, ,Print settings}.
8967
8968@item set print vtbl
8969@itemx show print vtbl
8970Control the format for printing virtual function tables.
8971@xref{Print Settings, ,Print settings}.
c906108c 8972(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8973ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8974
8975@kindex set overload-resolution
d4f3574e 8976@cindex overloaded functions, overload resolution
c906108c 8977@item set overload-resolution on
b37052ae 8978Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8979is on. For overloaded functions, @value{GDBN} evaluates the arguments
8980and searches for a function whose signature matches the argument types,
b37052ae 8981using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8982expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8983message.
8984
8985@item set overload-resolution off
b37052ae 8986Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8987overloaded functions that are not class member functions, @value{GDBN}
8988chooses the first function of the specified name that it finds in the
8989symbol table, whether or not its arguments are of the correct type. For
8990overloaded functions that are class member functions, @value{GDBN}
8991searches for a function whose signature @emph{exactly} matches the
8992argument types.
c906108c 8993
9c16f35a
EZ
8994@kindex show overload-resolution
8995@item show overload-resolution
8996Show the current setting of overload resolution.
8997
c906108c
SS
8998@item @r{Overloaded symbol names}
8999You can specify a particular definition of an overloaded symbol, using
b37052ae 9000the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
9001@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9002also use the @value{GDBN} command-line word completion facilities to list the
9003available choices, or to finish the type list for you.
9004@xref{Completion,, Command completion}, for details on how to do this.
9005@end table
c906108c 9006
b37303ee
AF
9007@node Objective-C
9008@subsection Objective-C
9009
9010@cindex Objective-C
9011This section provides information about some commands and command
721c2651
EZ
9012options that are useful for debugging Objective-C code. See also
9013@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9014few more commands specific to Objective-C support.
b37303ee
AF
9015
9016@menu
b383017d
RM
9017* Method Names in Commands::
9018* The Print Command with Objective-C::
b37303ee
AF
9019@end menu
9020
9021@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
9022@subsubsection Method Names in Commands
9023
9024The following commands have been extended to accept Objective-C method
9025names as line specifications:
9026
9027@kindex clear@r{, and Objective-C}
9028@kindex break@r{, and Objective-C}
9029@kindex info line@r{, and Objective-C}
9030@kindex jump@r{, and Objective-C}
9031@kindex list@r{, and Objective-C}
9032@itemize
9033@item @code{clear}
9034@item @code{break}
9035@item @code{info line}
9036@item @code{jump}
9037@item @code{list}
9038@end itemize
9039
9040A fully qualified Objective-C method name is specified as
9041
9042@smallexample
9043-[@var{Class} @var{methodName}]
9044@end smallexample
9045
c552b3bb
JM
9046where the minus sign is used to indicate an instance method and a
9047plus sign (not shown) is used to indicate a class method. The class
9048name @var{Class} and method name @var{methodName} are enclosed in
9049brackets, similar to the way messages are specified in Objective-C
9050source code. For example, to set a breakpoint at the @code{create}
9051instance method of class @code{Fruit} in the program currently being
9052debugged, enter:
b37303ee
AF
9053
9054@smallexample
9055break -[Fruit create]
9056@end smallexample
9057
9058To list ten program lines around the @code{initialize} class method,
9059enter:
9060
9061@smallexample
9062list +[NSText initialize]
9063@end smallexample
9064
c552b3bb
JM
9065In the current version of @value{GDBN}, the plus or minus sign is
9066required. In future versions of @value{GDBN}, the plus or minus
9067sign will be optional, but you can use it to narrow the search. It
9068is also possible to specify just a method name:
b37303ee
AF
9069
9070@smallexample
9071break create
9072@end smallexample
9073
9074You must specify the complete method name, including any colons. If
9075your program's source files contain more than one @code{create} method,
9076you'll be presented with a numbered list of classes that implement that
9077method. Indicate your choice by number, or type @samp{0} to exit if
9078none apply.
9079
9080As another example, to clear a breakpoint established at the
9081@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9082
9083@smallexample
9084clear -[NSWindow makeKeyAndOrderFront:]
9085@end smallexample
9086
9087@node The Print Command with Objective-C
9088@subsubsection The Print Command With Objective-C
721c2651 9089@cindex Objective-C, print objects
c552b3bb
JM
9090@kindex print-object
9091@kindex po @r{(@code{print-object})}
b37303ee 9092
c552b3bb 9093The print command has also been extended to accept methods. For example:
b37303ee
AF
9094
9095@smallexample
c552b3bb 9096print -[@var{object} hash]
b37303ee
AF
9097@end smallexample
9098
9099@cindex print an Objective-C object description
c552b3bb
JM
9100@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9101@noindent
9102will tell @value{GDBN} to send the @code{hash} message to @var{object}
9103and print the result. Also, an additional command has been added,
9104@code{print-object} or @code{po} for short, which is meant to print
9105the description of an object. However, this command may only work
9106with certain Objective-C libraries that have a particular hook
9107function, @code{_NSPrintForDebugger}, defined.
b37303ee 9108
09d4efe1
EZ
9109@node Fortran
9110@subsection Fortran
9111@cindex Fortran-specific support in @value{GDBN}
9112
9113@table @code
9114@cindex @code{COMMON} blocks, Fortran
9115@kindex info common
9116@item info common @r{[}@var{common-name}@r{]}
9117This command prints the values contained in the Fortran @code{COMMON}
9118block whose name is @var{common-name}. With no argument, the names of
9119all @code{COMMON} blocks visible at current program location are
9120printed.
9121@end table
9122
a8f24a35
EZ
9123Fortran symbols are usually case-insensitive, so @value{GDBN} by
9124default uses case-insensitive matches for Fortran symbols. You can
9125change that with the @samp{set case-insensitive} command, see
9126@ref{Symbols}, for the details.
9127
9c16f35a
EZ
9128@node Pascal
9129@subsection Pascal
9130
9131@cindex Pascal support in @value{GDBN}, limitations
9132Debugging Pascal programs which use sets, subranges, file variables, or
9133nested functions does not currently work. @value{GDBN} does not support
9134entering expressions, printing values, or similar features using Pascal
9135syntax.
9136
9137The Pascal-specific command @code{set print pascal_static-members}
9138controls whether static members of Pascal objects are displayed.
9139@xref{Print Settings, pascal_static-members}.
9140
09d4efe1 9141@node Modula-2
c906108c 9142@subsection Modula-2
7a292a7a 9143
d4f3574e 9144@cindex Modula-2, @value{GDBN} support
c906108c
SS
9145
9146The extensions made to @value{GDBN} to support Modula-2 only support
9147output from the @sc{gnu} Modula-2 compiler (which is currently being
9148developed). Other Modula-2 compilers are not currently supported, and
9149attempting to debug executables produced by them is most likely
9150to give an error as @value{GDBN} reads in the executable's symbol
9151table.
9152
9153@cindex expressions in Modula-2
9154@menu
9155* M2 Operators:: Built-in operators
9156* Built-In Func/Proc:: Built-in functions and procedures
9157* M2 Constants:: Modula-2 constants
9158* M2 Defaults:: Default settings for Modula-2
9159* Deviations:: Deviations from standard Modula-2
9160* M2 Checks:: Modula-2 type and range checks
9161* M2 Scope:: The scope operators @code{::} and @code{.}
9162* GDB/M2:: @value{GDBN} and Modula-2
9163@end menu
9164
6d2ebf8b 9165@node M2 Operators
c906108c
SS
9166@subsubsection Operators
9167@cindex Modula-2 operators
9168
9169Operators must be defined on values of specific types. For instance,
9170@code{+} is defined on numbers, but not on structures. Operators are
9171often defined on groups of types. For the purposes of Modula-2, the
9172following definitions hold:
9173
9174@itemize @bullet
9175
9176@item
9177@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9178their subranges.
9179
9180@item
9181@emph{Character types} consist of @code{CHAR} and its subranges.
9182
9183@item
9184@emph{Floating-point types} consist of @code{REAL}.
9185
9186@item
9187@emph{Pointer types} consist of anything declared as @code{POINTER TO
9188@var{type}}.
9189
9190@item
9191@emph{Scalar types} consist of all of the above.
9192
9193@item
9194@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9195
9196@item
9197@emph{Boolean types} consist of @code{BOOLEAN}.
9198@end itemize
9199
9200@noindent
9201The following operators are supported, and appear in order of
9202increasing precedence:
9203
9204@table @code
9205@item ,
9206Function argument or array index separator.
9207
9208@item :=
9209Assignment. The value of @var{var} @code{:=} @var{value} is
9210@var{value}.
9211
9212@item <@r{, }>
9213Less than, greater than on integral, floating-point, or enumerated
9214types.
9215
9216@item <=@r{, }>=
96a2c332 9217Less than or equal to, greater than or equal to
c906108c
SS
9218on integral, floating-point and enumerated types, or set inclusion on
9219set types. Same precedence as @code{<}.
9220
9221@item =@r{, }<>@r{, }#
9222Equality and two ways of expressing inequality, valid on scalar types.
9223Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9224available for inequality, since @code{#} conflicts with the script
9225comment character.
9226
9227@item IN
9228Set membership. Defined on set types and the types of their members.
9229Same precedence as @code{<}.
9230
9231@item OR
9232Boolean disjunction. Defined on boolean types.
9233
9234@item AND@r{, }&
d4f3574e 9235Boolean conjunction. Defined on boolean types.
c906108c
SS
9236
9237@item @@
9238The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9239
9240@item +@r{, }-
9241Addition and subtraction on integral and floating-point types, or union
9242and difference on set types.
9243
9244@item *
9245Multiplication on integral and floating-point types, or set intersection
9246on set types.
9247
9248@item /
9249Division on floating-point types, or symmetric set difference on set
9250types. Same precedence as @code{*}.
9251
9252@item DIV@r{, }MOD
9253Integer division and remainder. Defined on integral types. Same
9254precedence as @code{*}.
9255
9256@item -
9257Negative. Defined on @code{INTEGER} and @code{REAL} data.
9258
9259@item ^
9260Pointer dereferencing. Defined on pointer types.
9261
9262@item NOT
9263Boolean negation. Defined on boolean types. Same precedence as
9264@code{^}.
9265
9266@item .
9267@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9268precedence as @code{^}.
9269
9270@item []
9271Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9272
9273@item ()
9274Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9275as @code{^}.
9276
9277@item ::@r{, }.
9278@value{GDBN} and Modula-2 scope operators.
9279@end table
9280
9281@quotation
9282@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9283treats the use of the operator @code{IN}, or the use of operators
9284@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9285@code{<=}, and @code{>=} on sets as an error.
9286@end quotation
9287
cb51c4e0 9288
6d2ebf8b 9289@node Built-In Func/Proc
c906108c 9290@subsubsection Built-in functions and procedures
cb51c4e0 9291@cindex Modula-2 built-ins
c906108c
SS
9292
9293Modula-2 also makes available several built-in procedures and functions.
9294In describing these, the following metavariables are used:
9295
9296@table @var
9297
9298@item a
9299represents an @code{ARRAY} variable.
9300
9301@item c
9302represents a @code{CHAR} constant or variable.
9303
9304@item i
9305represents a variable or constant of integral type.
9306
9307@item m
9308represents an identifier that belongs to a set. Generally used in the
9309same function with the metavariable @var{s}. The type of @var{s} should
9310be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9311
9312@item n
9313represents a variable or constant of integral or floating-point type.
9314
9315@item r
9316represents a variable or constant of floating-point type.
9317
9318@item t
9319represents a type.
9320
9321@item v
9322represents a variable.
9323
9324@item x
9325represents a variable or constant of one of many types. See the
9326explanation of the function for details.
9327@end table
9328
9329All Modula-2 built-in procedures also return a result, described below.
9330
9331@table @code
9332@item ABS(@var{n})
9333Returns the absolute value of @var{n}.
9334
9335@item CAP(@var{c})
9336If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9337equivalent, otherwise it returns its argument.
c906108c
SS
9338
9339@item CHR(@var{i})
9340Returns the character whose ordinal value is @var{i}.
9341
9342@item DEC(@var{v})
c3f6f71d 9343Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9344
9345@item DEC(@var{v},@var{i})
9346Decrements the value in the variable @var{v} by @var{i}. Returns the
9347new value.
9348
9349@item EXCL(@var{m},@var{s})
9350Removes the element @var{m} from the set @var{s}. Returns the new
9351set.
9352
9353@item FLOAT(@var{i})
9354Returns the floating point equivalent of the integer @var{i}.
9355
9356@item HIGH(@var{a})
9357Returns the index of the last member of @var{a}.
9358
9359@item INC(@var{v})
c3f6f71d 9360Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9361
9362@item INC(@var{v},@var{i})
9363Increments the value in the variable @var{v} by @var{i}. Returns the
9364new value.
9365
9366@item INCL(@var{m},@var{s})
9367Adds the element @var{m} to the set @var{s} if it is not already
9368there. Returns the new set.
9369
9370@item MAX(@var{t})
9371Returns the maximum value of the type @var{t}.
9372
9373@item MIN(@var{t})
9374Returns the minimum value of the type @var{t}.
9375
9376@item ODD(@var{i})
9377Returns boolean TRUE if @var{i} is an odd number.
9378
9379@item ORD(@var{x})
9380Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9381value of a character is its @sc{ascii} value (on machines supporting the
9382@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9383integral, character and enumerated types.
9384
9385@item SIZE(@var{x})
9386Returns the size of its argument. @var{x} can be a variable or a type.
9387
9388@item TRUNC(@var{r})
9389Returns the integral part of @var{r}.
9390
9391@item VAL(@var{t},@var{i})
9392Returns the member of the type @var{t} whose ordinal value is @var{i}.
9393@end table
9394
9395@quotation
9396@emph{Warning:} Sets and their operations are not yet supported, so
9397@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9398an error.
9399@end quotation
9400
9401@cindex Modula-2 constants
6d2ebf8b 9402@node M2 Constants
c906108c
SS
9403@subsubsection Constants
9404
9405@value{GDBN} allows you to express the constants of Modula-2 in the following
9406ways:
9407
9408@itemize @bullet
9409
9410@item
9411Integer constants are simply a sequence of digits. When used in an
9412expression, a constant is interpreted to be type-compatible with the
9413rest of the expression. Hexadecimal integers are specified by a
9414trailing @samp{H}, and octal integers by a trailing @samp{B}.
9415
9416@item
9417Floating point constants appear as a sequence of digits, followed by a
9418decimal point and another sequence of digits. An optional exponent can
9419then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9420@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9421digits of the floating point constant must be valid decimal (base 10)
9422digits.
9423
9424@item
9425Character constants consist of a single character enclosed by a pair of
9426like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9427also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9428followed by a @samp{C}.
9429
9430@item
9431String constants consist of a sequence of characters enclosed by a
9432pair of like quotes, either single (@code{'}) or double (@code{"}).
9433Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9434Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9435sequences.
9436
9437@item
9438Enumerated constants consist of an enumerated identifier.
9439
9440@item
9441Boolean constants consist of the identifiers @code{TRUE} and
9442@code{FALSE}.
9443
9444@item
9445Pointer constants consist of integral values only.
9446
9447@item
9448Set constants are not yet supported.
9449@end itemize
9450
6d2ebf8b 9451@node M2 Defaults
c906108c
SS
9452@subsubsection Modula-2 defaults
9453@cindex Modula-2 defaults
9454
9455If type and range checking are set automatically by @value{GDBN}, they
9456both default to @code{on} whenever the working language changes to
d4f3574e 9457Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9458selected the working language.
9459
9460If you allow @value{GDBN} to set the language automatically, then entering
9461code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9462working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9463the language automatically}, for further details.
9464
6d2ebf8b 9465@node Deviations
c906108c
SS
9466@subsubsection Deviations from standard Modula-2
9467@cindex Modula-2, deviations from
9468
9469A few changes have been made to make Modula-2 programs easier to debug.
9470This is done primarily via loosening its type strictness:
9471
9472@itemize @bullet
9473@item
9474Unlike in standard Modula-2, pointer constants can be formed by
9475integers. This allows you to modify pointer variables during
9476debugging. (In standard Modula-2, the actual address contained in a
9477pointer variable is hidden from you; it can only be modified
9478through direct assignment to another pointer variable or expression that
9479returned a pointer.)
9480
9481@item
9482C escape sequences can be used in strings and characters to represent
9483non-printable characters. @value{GDBN} prints out strings with these
9484escape sequences embedded. Single non-printable characters are
9485printed using the @samp{CHR(@var{nnn})} format.
9486
9487@item
9488The assignment operator (@code{:=}) returns the value of its right-hand
9489argument.
9490
9491@item
9492All built-in procedures both modify @emph{and} return their argument.
9493@end itemize
9494
6d2ebf8b 9495@node M2 Checks
c906108c
SS
9496@subsubsection Modula-2 type and range checks
9497@cindex Modula-2 checks
9498
9499@quotation
9500@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9501range checking.
9502@end quotation
9503@c FIXME remove warning when type/range checks added
9504
9505@value{GDBN} considers two Modula-2 variables type equivalent if:
9506
9507@itemize @bullet
9508@item
9509They are of types that have been declared equivalent via a @code{TYPE
9510@var{t1} = @var{t2}} statement
9511
9512@item
9513They have been declared on the same line. (Note: This is true of the
9514@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9515@end itemize
9516
9517As long as type checking is enabled, any attempt to combine variables
9518whose types are not equivalent is an error.
9519
9520Range checking is done on all mathematical operations, assignment, array
9521index bounds, and all built-in functions and procedures.
9522
6d2ebf8b 9523@node M2 Scope
c906108c
SS
9524@subsubsection The scope operators @code{::} and @code{.}
9525@cindex scope
41afff9a 9526@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9527@cindex colon, doubled as scope operator
9528@ifinfo
41afff9a 9529@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9530@c Info cannot handle :: but TeX can.
9531@end ifinfo
9532@iftex
41afff9a 9533@vindex ::@r{, in Modula-2}
c906108c
SS
9534@end iftex
9535
9536There are a few subtle differences between the Modula-2 scope operator
9537(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9538similar syntax:
9539
474c8240 9540@smallexample
c906108c
SS
9541
9542@var{module} . @var{id}
9543@var{scope} :: @var{id}
474c8240 9544@end smallexample
c906108c
SS
9545
9546@noindent
9547where @var{scope} is the name of a module or a procedure,
9548@var{module} the name of a module, and @var{id} is any declared
9549identifier within your program, except another module.
9550
9551Using the @code{::} operator makes @value{GDBN} search the scope
9552specified by @var{scope} for the identifier @var{id}. If it is not
9553found in the specified scope, then @value{GDBN} searches all scopes
9554enclosing the one specified by @var{scope}.
9555
9556Using the @code{.} operator makes @value{GDBN} search the current scope for
9557the identifier specified by @var{id} that was imported from the
9558definition module specified by @var{module}. With this operator, it is
9559an error if the identifier @var{id} was not imported from definition
9560module @var{module}, or if @var{id} is not an identifier in
9561@var{module}.
9562
6d2ebf8b 9563@node GDB/M2
c906108c
SS
9564@subsubsection @value{GDBN} and Modula-2
9565
9566Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9567Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9568specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9569@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9570apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9571analogue in Modula-2.
9572
9573The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9574with any language, is not useful with Modula-2. Its
c906108c 9575intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9576created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9577address can be specified by an integral constant, the construct
d4f3574e 9578@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9579
9580@cindex @code{#} in Modula-2
9581In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9582interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9583
e07c999f
PH
9584@node Ada
9585@subsection Ada
9586@cindex Ada
9587
9588The extensions made to @value{GDBN} for Ada only support
9589output from the @sc{gnu} Ada (GNAT) compiler.
9590Other Ada compilers are not currently supported, and
9591attempting to debug executables produced by them is most likely
9592to be difficult.
9593
9594
9595@cindex expressions in Ada
9596@menu
9597* Ada Mode Intro:: General remarks on the Ada syntax
9598 and semantics supported by Ada mode
9599 in @value{GDBN}.
9600* Omissions from Ada:: Restrictions on the Ada expression syntax.
9601* Additions to Ada:: Extensions of the Ada expression syntax.
9602* Stopping Before Main Program:: Debugging the program during elaboration.
9603* Ada Glitches:: Known peculiarities of Ada mode.
9604@end menu
9605
9606@node Ada Mode Intro
9607@subsubsection Introduction
9608@cindex Ada mode, general
9609
9610The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9611syntax, with some extensions.
9612The philosophy behind the design of this subset is
9613
9614@itemize @bullet
9615@item
9616That @value{GDBN} should provide basic literals and access to operations for
9617arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9618leaving more sophisticated computations to subprograms written into the
9619program (which therefore may be called from @value{GDBN}).
9620
9621@item
9622That type safety and strict adherence to Ada language restrictions
9623are not particularly important to the @value{GDBN} user.
9624
9625@item
9626That brevity is important to the @value{GDBN} user.
9627@end itemize
9628
9629Thus, for brevity, the debugger acts as if there were
9630implicit @code{with} and @code{use} clauses in effect for all user-written
9631packages, making it unnecessary to fully qualify most names with
9632their packages, regardless of context. Where this causes ambiguity,
9633@value{GDBN} asks the user's intent.
9634
9635The debugger will start in Ada mode if it detects an Ada main program.
9636As for other languages, it will enter Ada mode when stopped in a program that
9637was translated from an Ada source file.
9638
9639While in Ada mode, you may use `@t{--}' for comments. This is useful
9640mostly for documenting command files. The standard @value{GDBN} comment
9641(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9642middle (to allow based literals).
9643
9644The debugger supports limited overloading. Given a subprogram call in which
9645the function symbol has multiple definitions, it will use the number of
9646actual parameters and some information about their types to attempt to narrow
9647the set of definitions. It also makes very limited use of context, preferring
9648procedures to functions in the context of the @code{call} command, and
9649functions to procedures elsewhere.
9650
9651@node Omissions from Ada
9652@subsubsection Omissions from Ada
9653@cindex Ada, omissions from
9654
9655Here are the notable omissions from the subset:
9656
9657@itemize @bullet
9658@item
9659Only a subset of the attributes are supported:
9660
9661@itemize @minus
9662@item
9663@t{'First}, @t{'Last}, and @t{'Length}
9664 on array objects (not on types and subtypes).
9665
9666@item
9667@t{'Min} and @t{'Max}.
9668
9669@item
9670@t{'Pos} and @t{'Val}.
9671
9672@item
9673@t{'Tag}.
9674
9675@item
9676@t{'Range} on array objects (not subtypes), but only as the right
9677operand of the membership (@code{in}) operator.
9678
9679@item
9680@t{'Access}, @t{'Unchecked_Access}, and
9681@t{'Unrestricted_Access} (a GNAT extension).
9682
9683@item
9684@t{'Address}.
9685@end itemize
9686
9687@item
9688The names in
9689@code{Characters.Latin_1} are not available and
9690concatenation is not implemented. Thus, escape characters in strings are
9691not currently available.
9692
9693@item
9694Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9695equality of representations. They will generally work correctly
9696for strings and arrays whose elements have integer or enumeration types.
9697They may not work correctly for arrays whose element
9698types have user-defined equality, for arrays of real values
9699(in particular, IEEE-conformant floating point, because of negative
9700zeroes and NaNs), and for arrays whose elements contain unused bits with
9701indeterminate values.
9702
9703@item
9704The other component-by-component array operations (@code{and}, @code{or},
9705@code{xor}, @code{not}, and relational tests other than equality)
9706are not implemented.
9707
9708@item
9709There are no record or array aggregates.
9710
9711@item
9712Calls to dispatching subprograms are not implemented.
9713
9714@item
9715The overloading algorithm is much more limited (i.e., less selective)
9716than that of real Ada. It makes only limited use of the context in which a subexpression
9717appears to resolve its meaning, and it is much looser in its rules for allowing
9718type matches. As a result, some function calls will be ambiguous, and the user
9719will be asked to choose the proper resolution.
9720
9721@item
9722The @code{new} operator is not implemented.
9723
9724@item
9725Entry calls are not implemented.
9726
9727@item
9728Aside from printing, arithmetic operations on the native VAX floating-point
9729formats are not supported.
9730
9731@item
9732It is not possible to slice a packed array.
9733@end itemize
9734
9735@node Additions to Ada
9736@subsubsection Additions to Ada
9737@cindex Ada, deviations from
9738
9739As it does for other languages, @value{GDBN} makes certain generic
9740extensions to Ada (@pxref{Expressions}):
9741
9742@itemize @bullet
9743@item
9744If the expression @var{E} is a variable residing in memory
9745(typically a local variable or array element) and @var{N} is
9746a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9747@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9748In Ada, this operator is generally not necessary, since its prime use
9749is in displaying parts of an array, and slicing will usually do this in Ada.
9750However, there are occasional uses when debugging programs
9751in which certain debugging information has been optimized away.
9752
9753@item
9754@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9755in function or file @var{B}.'' When @var{B} is a file name, you must typically
9756surround it in single quotes.
9757
9758@item
9759The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9760@var{type} that appears at address @var{addr}.''
9761
9762@item
9763A name starting with @samp{$} is a convenience variable
9764(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9765@end itemize
9766
9767In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9768to Ada:
9769
9770@itemize @bullet
9771@item
9772The assignment statement is allowed as an expression, returning
9773its right-hand operand as its value. Thus, you may enter
9774
9775@smallexample
9776set x := y + 3
9777print A(tmp := y + 1)
9778@end smallexample
9779
9780@item
9781The semicolon is allowed as an ``operator,'' returning as its value
9782the value of its right-hand operand.
9783This allows, for example,
9784complex conditional breaks:
9785
9786@smallexample
9787break f
9788condition 1 (report(i); k += 1; A(k) > 100)
9789@end smallexample
9790
9791@item
9792Rather than use catenation and symbolic character names to introduce special
9793characters into strings, one may instead use a special bracket notation,
9794which is also used to print strings. A sequence of characters of the form
9795@samp{["@var{XX}"]} within a string or character literal denotes the
9796(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9797sequence of characters @samp{["""]} also denotes a single quotation mark
9798in strings. For example,
9799@smallexample
9800 "One line.["0a"]Next line.["0a"]"
9801@end smallexample
9802@noindent
9803contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9804period.
9805
9806@item
9807The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9808@t{'Max} is optional (and is ignored in any case). For example, it is valid
9809to write
9810
9811@smallexample
9812print 'max(x, y)
9813@end smallexample
9814
9815@item
9816When printing arrays, @value{GDBN} uses positional notation when the
9817array has a lower bound of 1, and uses a modified named notation otherwise.
9818For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9819
9820@smallexample
9821(3 => 10, 17, 1)
9822@end smallexample
9823
9824@noindent
9825That is, in contrast to valid Ada, only the first component has a @code{=>}
9826clause.
9827
9828@item
9829You may abbreviate attributes in expressions with any unique,
9830multi-character subsequence of
9831their names (an exact match gets preference).
9832For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9833in place of @t{a'length}.
9834
9835@item
9836@cindex quoting Ada internal identifiers
9837Since Ada is case-insensitive, the debugger normally maps identifiers you type
9838to lower case. The GNAT compiler uses upper-case characters for
9839some of its internal identifiers, which are normally of no interest to users.
9840For the rare occasions when you actually have to look at them,
9841enclose them in angle brackets to avoid the lower-case mapping.
9842For example,
9843@smallexample
9844@value{GDBP} print <JMPBUF_SAVE>[0]
9845@end smallexample
9846
9847@item
9848Printing an object of class-wide type or dereferencing an
9849access-to-class-wide value will display all the components of the object's
9850specific type (as indicated by its run-time tag). Likewise, component
9851selection on such a value will operate on the specific type of the
9852object.
9853
9854@end itemize
9855
9856@node Stopping Before Main Program
9857@subsubsection Stopping at the Very Beginning
9858
9859@cindex breakpointing Ada elaboration code
9860It is sometimes necessary to debug the program during elaboration, and
9861before reaching the main procedure.
9862As defined in the Ada Reference
9863Manual, the elaboration code is invoked from a procedure called
9864@code{adainit}. To run your program up to the beginning of
9865elaboration, simply use the following two commands:
9866@code{tbreak adainit} and @code{run}.
9867
9868@node Ada Glitches
9869@subsubsection Known Peculiarities of Ada Mode
9870@cindex Ada, problems
9871
9872Besides the omissions listed previously (@pxref{Omissions from Ada}),
9873we know of several problems with and limitations of Ada mode in
9874@value{GDBN},
9875some of which will be fixed with planned future releases of the debugger
9876and the GNU Ada compiler.
9877
9878@itemize @bullet
9879@item
9880Currently, the debugger
9881has insufficient information to determine whether certain pointers represent
9882pointers to objects or the objects themselves.
9883Thus, the user may have to tack an extra @code{.all} after an expression
9884to get it printed properly.
9885
9886@item
9887Static constants that the compiler chooses not to materialize as objects in
9888storage are invisible to the debugger.
9889
9890@item
9891Named parameter associations in function argument lists are ignored (the
9892argument lists are treated as positional).
9893
9894@item
9895Many useful library packages are currently invisible to the debugger.
9896
9897@item
9898Fixed-point arithmetic, conversions, input, and output is carried out using
9899floating-point arithmetic, and may give results that only approximate those on
9900the host machine.
9901
9902@item
9903The type of the @t{'Address} attribute may not be @code{System.Address}.
9904
9905@item
9906The GNAT compiler never generates the prefix @code{Standard} for any of
9907the standard symbols defined by the Ada language. @value{GDBN} knows about
9908this: it will strip the prefix from names when you use it, and will never
9909look for a name you have so qualified among local symbols, nor match against
9910symbols in other packages or subprograms. If you have
9911defined entities anywhere in your program other than parameters and
9912local variables whose simple names match names in @code{Standard},
9913GNAT's lack of qualification here can cause confusion. When this happens,
9914you can usually resolve the confusion
9915by qualifying the problematic names with package
9916@code{Standard} explicitly.
9917@end itemize
9918
4e562065
JB
9919@node Unsupported languages
9920@section Unsupported languages
9921
9922@cindex unsupported languages
9923@cindex minimal language
9924In addition to the other fully-supported programming languages,
9925@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9926It does not represent a real programming language, but provides a set
9927of capabilities close to what the C or assembly languages provide.
9928This should allow most simple operations to be performed while debugging
9929an application that uses a language currently not supported by @value{GDBN}.
9930
9931If the language is set to @code{auto}, @value{GDBN} will automatically
9932select this language if the current frame corresponds to an unsupported
9933language.
9934
6d2ebf8b 9935@node Symbols
c906108c
SS
9936@chapter Examining the Symbol Table
9937
d4f3574e 9938The commands described in this chapter allow you to inquire about the
c906108c
SS
9939symbols (names of variables, functions and types) defined in your
9940program. This information is inherent in the text of your program and
9941does not change as your program executes. @value{GDBN} finds it in your
9942program's symbol table, in the file indicated when you started @value{GDBN}
9943(@pxref{File Options, ,Choosing files}), or by one of the
9944file-management commands (@pxref{Files, ,Commands to specify files}).
9945
9946@cindex symbol names
9947@cindex names of symbols
9948@cindex quoting names
9949Occasionally, you may need to refer to symbols that contain unusual
9950characters, which @value{GDBN} ordinarily treats as word delimiters. The
9951most frequent case is in referring to static variables in other
9952source files (@pxref{Variables,,Program variables}). File names
9953are recorded in object files as debugging symbols, but @value{GDBN} would
9954ordinarily parse a typical file name, like @file{foo.c}, as the three words
9955@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9956@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9957
474c8240 9958@smallexample
c906108c 9959p 'foo.c'::x
474c8240 9960@end smallexample
c906108c
SS
9961
9962@noindent
9963looks up the value of @code{x} in the scope of the file @file{foo.c}.
9964
9965@table @code
a8f24a35
EZ
9966@cindex case-insensitive symbol names
9967@cindex case sensitivity in symbol names
9968@kindex set case-sensitive
9969@item set case-sensitive on
9970@itemx set case-sensitive off
9971@itemx set case-sensitive auto
9972Normally, when @value{GDBN} looks up symbols, it matches their names
9973with case sensitivity determined by the current source language.
9974Occasionally, you may wish to control that. The command @code{set
9975case-sensitive} lets you do that by specifying @code{on} for
9976case-sensitive matches or @code{off} for case-insensitive ones. If
9977you specify @code{auto}, case sensitivity is reset to the default
9978suitable for the source language. The default is case-sensitive
9979matches for all languages except for Fortran, for which the default is
9980case-insensitive matches.
9981
9c16f35a
EZ
9982@kindex show case-sensitive
9983@item show case-sensitive
a8f24a35
EZ
9984This command shows the current setting of case sensitivity for symbols
9985lookups.
9986
c906108c 9987@kindex info address
b37052ae 9988@cindex address of a symbol
c906108c
SS
9989@item info address @var{symbol}
9990Describe where the data for @var{symbol} is stored. For a register
9991variable, this says which register it is kept in. For a non-register
9992local variable, this prints the stack-frame offset at which the variable
9993is always stored.
9994
9995Note the contrast with @samp{print &@var{symbol}}, which does not work
9996at all for a register variable, and for a stack local variable prints
9997the exact address of the current instantiation of the variable.
9998
3d67e040 9999@kindex info symbol
b37052ae 10000@cindex symbol from address
9c16f35a 10001@cindex closest symbol and offset for an address
3d67e040
EZ
10002@item info symbol @var{addr}
10003Print the name of a symbol which is stored at the address @var{addr}.
10004If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10005nearest symbol and an offset from it:
10006
474c8240 10007@smallexample
3d67e040
EZ
10008(@value{GDBP}) info symbol 0x54320
10009_initialize_vx + 396 in section .text
474c8240 10010@end smallexample
3d67e040
EZ
10011
10012@noindent
10013This is the opposite of the @code{info address} command. You can use
10014it to find out the name of a variable or a function given its address.
10015
c906108c 10016@kindex whatis
d4f3574e
SS
10017@item whatis @var{expr}
10018Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
10019actually evaluated, and any side-effecting operations (such as
10020assignments or function calls) inside it do not take place.
10021@xref{Expressions, ,Expressions}.
10022
10023@item whatis
10024Print the data type of @code{$}, the last value in the value history.
10025
10026@kindex ptype
10027@item ptype @var{typename}
10028Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
10029the name of a type, or for C code it may have the form @samp{class
10030@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
10031@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 10032
d4f3574e 10033@item ptype @var{expr}
c906108c 10034@itemx ptype
d4f3574e 10035Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10036differs from @code{whatis} by printing a detailed description, instead
10037of just the name of the type.
10038
10039For example, for this variable declaration:
10040
474c8240 10041@smallexample
c906108c 10042struct complex @{double real; double imag;@} v;
474c8240 10043@end smallexample
c906108c
SS
10044
10045@noindent
10046the two commands give this output:
10047
474c8240 10048@smallexample
c906108c
SS
10049@group
10050(@value{GDBP}) whatis v
10051type = struct complex
10052(@value{GDBP}) ptype v
10053type = struct complex @{
10054 double real;
10055 double imag;
10056@}
10057@end group
474c8240 10058@end smallexample
c906108c
SS
10059
10060@noindent
10061As with @code{whatis}, using @code{ptype} without an argument refers to
10062the type of @code{$}, the last value in the value history.
10063
ab1adacd
EZ
10064@cindex incomplete type
10065Sometimes, programs use opaque data types or incomplete specifications
10066of complex data structure. If the debug information included in the
10067program does not allow @value{GDBN} to display a full declaration of
10068the data type, it will say @samp{<incomplete type>}. For example,
10069given these declarations:
10070
10071@smallexample
10072 struct foo;
10073 struct foo *fooptr;
10074@end smallexample
10075
10076@noindent
10077but no definition for @code{struct foo} itself, @value{GDBN} will say:
10078
10079@smallexample
10080 (gdb) ptype foo
10081 $1 = <incomplete type>
10082@end smallexample
10083
10084@noindent
10085``Incomplete type'' is C terminology for data types that are not
10086completely specified.
10087
c906108c
SS
10088@kindex info types
10089@item info types @var{regexp}
10090@itemx info types
09d4efe1
EZ
10091Print a brief description of all types whose names match the regular
10092expression @var{regexp} (or all types in your program, if you supply
10093no argument). Each complete typename is matched as though it were a
10094complete line; thus, @samp{i type value} gives information on all
10095types in your program whose names include the string @code{value}, but
10096@samp{i type ^value$} gives information only on types whose complete
10097name is @code{value}.
c906108c
SS
10098
10099This command differs from @code{ptype} in two ways: first, like
10100@code{whatis}, it does not print a detailed description; second, it
10101lists all source files where a type is defined.
10102
b37052ae
EZ
10103@kindex info scope
10104@cindex local variables
09d4efe1 10105@item info scope @var{location}
b37052ae 10106List all the variables local to a particular scope. This command
09d4efe1
EZ
10107accepts a @var{location} argument---a function name, a source line, or
10108an address preceded by a @samp{*}, and prints all the variables local
10109to the scope defined by that location. For example:
b37052ae
EZ
10110
10111@smallexample
10112(@value{GDBP}) @b{info scope command_line_handler}
10113Scope for command_line_handler:
10114Symbol rl is an argument at stack/frame offset 8, length 4.
10115Symbol linebuffer is in static storage at address 0x150a18, length 4.
10116Symbol linelength is in static storage at address 0x150a1c, length 4.
10117Symbol p is a local variable in register $esi, length 4.
10118Symbol p1 is a local variable in register $ebx, length 4.
10119Symbol nline is a local variable in register $edx, length 4.
10120Symbol repeat is a local variable at frame offset -8, length 4.
10121@end smallexample
10122
f5c37c66
EZ
10123@noindent
10124This command is especially useful for determining what data to collect
10125during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10126collect}.
10127
c906108c
SS
10128@kindex info source
10129@item info source
919d772c
JB
10130Show information about the current source file---that is, the source file for
10131the function containing the current point of execution:
10132@itemize @bullet
10133@item
10134the name of the source file, and the directory containing it,
10135@item
10136the directory it was compiled in,
10137@item
10138its length, in lines,
10139@item
10140which programming language it is written in,
10141@item
10142whether the executable includes debugging information for that file, and
10143if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10144@item
10145whether the debugging information includes information about
10146preprocessor macros.
10147@end itemize
10148
c906108c
SS
10149
10150@kindex info sources
10151@item info sources
10152Print the names of all source files in your program for which there is
10153debugging information, organized into two lists: files whose symbols
10154have already been read, and files whose symbols will be read when needed.
10155
10156@kindex info functions
10157@item info functions
10158Print the names and data types of all defined functions.
10159
10160@item info functions @var{regexp}
10161Print the names and data types of all defined functions
10162whose names contain a match for regular expression @var{regexp}.
10163Thus, @samp{info fun step} finds all functions whose names
10164include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10165start with @code{step}. If a function name contains characters
10166that conflict with the regular expression language (eg.
1c5dfdad 10167@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10168
10169@kindex info variables
10170@item info variables
10171Print the names and data types of all variables that are declared
6ca652b0 10172outside of functions (i.e.@: excluding local variables).
c906108c
SS
10173
10174@item info variables @var{regexp}
10175Print the names and data types of all variables (except for local
10176variables) whose names contain a match for regular expression
10177@var{regexp}.
10178
b37303ee 10179@kindex info classes
721c2651 10180@cindex Objective-C, classes and selectors
b37303ee
AF
10181@item info classes
10182@itemx info classes @var{regexp}
10183Display all Objective-C classes in your program, or
10184(with the @var{regexp} argument) all those matching a particular regular
10185expression.
10186
10187@kindex info selectors
10188@item info selectors
10189@itemx info selectors @var{regexp}
10190Display all Objective-C selectors in your program, or
10191(with the @var{regexp} argument) all those matching a particular regular
10192expression.
10193
c906108c
SS
10194@ignore
10195This was never implemented.
10196@kindex info methods
10197@item info methods
10198@itemx info methods @var{regexp}
10199The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10200methods within C@t{++} program, or (with the @var{regexp} argument) a
10201specific set of methods found in the various C@t{++} classes. Many
10202C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10203from the @code{ptype} command can be overwhelming and hard to use. The
10204@code{info-methods} command filters the methods, printing only those
10205which match the regular-expression @var{regexp}.
10206@end ignore
10207
c906108c
SS
10208@cindex reloading symbols
10209Some systems allow individual object files that make up your program to
7a292a7a
SS
10210be replaced without stopping and restarting your program. For example,
10211in VxWorks you can simply recompile a defective object file and keep on
10212running. If you are running on one of these systems, you can allow
10213@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10214
10215@table @code
10216@kindex set symbol-reloading
10217@item set symbol-reloading on
10218Replace symbol definitions for the corresponding source file when an
10219object file with a particular name is seen again.
10220
10221@item set symbol-reloading off
6d2ebf8b
SS
10222Do not replace symbol definitions when encountering object files of the
10223same name more than once. This is the default state; if you are not
10224running on a system that permits automatic relinking of modules, you
10225should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10226may discard symbols when linking large programs, that may contain
10227several modules (from different directories or libraries) with the same
10228name.
c906108c
SS
10229
10230@kindex show symbol-reloading
10231@item show symbol-reloading
10232Show the current @code{on} or @code{off} setting.
10233@end table
c906108c 10234
9c16f35a 10235@cindex opaque data types
c906108c
SS
10236@kindex set opaque-type-resolution
10237@item set opaque-type-resolution on
10238Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10239declared as a pointer to a @code{struct}, @code{class}, or
10240@code{union}---for example, @code{struct MyType *}---that is used in one
10241source file although the full declaration of @code{struct MyType} is in
10242another source file. The default is on.
10243
10244A change in the setting of this subcommand will not take effect until
10245the next time symbols for a file are loaded.
10246
10247@item set opaque-type-resolution off
10248Tell @value{GDBN} not to resolve opaque types. In this case, the type
10249is printed as follows:
10250@smallexample
10251@{<no data fields>@}
10252@end smallexample
10253
10254@kindex show opaque-type-resolution
10255@item show opaque-type-resolution
10256Show whether opaque types are resolved or not.
c906108c
SS
10257
10258@kindex maint print symbols
10259@cindex symbol dump
10260@kindex maint print psymbols
10261@cindex partial symbol dump
10262@item maint print symbols @var{filename}
10263@itemx maint print psymbols @var{filename}
10264@itemx maint print msymbols @var{filename}
10265Write a dump of debugging symbol data into the file @var{filename}.
10266These commands are used to debug the @value{GDBN} symbol-reading code. Only
10267symbols with debugging data are included. If you use @samp{maint print
10268symbols}, @value{GDBN} includes all the symbols for which it has already
10269collected full details: that is, @var{filename} reflects symbols for
10270only those files whose symbols @value{GDBN} has read. You can use the
10271command @code{info sources} to find out which files these are. If you
10272use @samp{maint print psymbols} instead, the dump shows information about
10273symbols that @value{GDBN} only knows partially---that is, symbols defined in
10274files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10275@samp{maint print msymbols} dumps just the minimal symbol information
10276required for each object file from which @value{GDBN} has read some symbols.
10277@xref{Files, ,Commands to specify files}, for a discussion of how
10278@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10279
5e7b2f39
JB
10280@kindex maint info symtabs
10281@kindex maint info psymtabs
44ea7b70
JB
10282@cindex listing @value{GDBN}'s internal symbol tables
10283@cindex symbol tables, listing @value{GDBN}'s internal
10284@cindex full symbol tables, listing @value{GDBN}'s internal
10285@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10286@item maint info symtabs @r{[} @var{regexp} @r{]}
10287@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10288
10289List the @code{struct symtab} or @code{struct partial_symtab}
10290structures whose names match @var{regexp}. If @var{regexp} is not
10291given, list them all. The output includes expressions which you can
10292copy into a @value{GDBN} debugging this one to examine a particular
10293structure in more detail. For example:
10294
10295@smallexample
5e7b2f39 10296(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10297@{ objfile /home/gnu/build/gdb/gdb
10298 ((struct objfile *) 0x82e69d0)
b383017d 10299 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10300 ((struct partial_symtab *) 0x8474b10)
10301 readin no
10302 fullname (null)
10303 text addresses 0x814d3c8 -- 0x8158074
10304 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10305 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10306 dependencies (none)
10307 @}
10308@}
5e7b2f39 10309(@value{GDBP}) maint info symtabs
44ea7b70
JB
10310(@value{GDBP})
10311@end smallexample
10312@noindent
10313We see that there is one partial symbol table whose filename contains
10314the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10315and we see that @value{GDBN} has not read in any symtabs yet at all.
10316If we set a breakpoint on a function, that will cause @value{GDBN} to
10317read the symtab for the compilation unit containing that function:
10318
10319@smallexample
10320(@value{GDBP}) break dwarf2_psymtab_to_symtab
10321Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10322line 1574.
5e7b2f39 10323(@value{GDBP}) maint info symtabs
b383017d 10324@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10325 ((struct objfile *) 0x82e69d0)
b383017d 10326 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10327 ((struct symtab *) 0x86c1f38)
10328 dirname (null)
10329 fullname (null)
10330 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10331 debugformat DWARF 2
10332 @}
10333@}
b383017d 10334(@value{GDBP})
44ea7b70 10335@end smallexample
c906108c
SS
10336@end table
10337
44ea7b70 10338
6d2ebf8b 10339@node Altering
c906108c
SS
10340@chapter Altering Execution
10341
10342Once you think you have found an error in your program, you might want to
10343find out for certain whether correcting the apparent error would lead to
10344correct results in the rest of the run. You can find the answer by
10345experiment, using the @value{GDBN} features for altering execution of the
10346program.
10347
10348For example, you can store new values into variables or memory
7a292a7a
SS
10349locations, give your program a signal, restart it at a different
10350address, or even return prematurely from a function.
c906108c
SS
10351
10352@menu
10353* Assignment:: Assignment to variables
10354* Jumping:: Continuing at a different address
c906108c 10355* Signaling:: Giving your program a signal
c906108c
SS
10356* Returning:: Returning from a function
10357* Calling:: Calling your program's functions
10358* Patching:: Patching your program
10359@end menu
10360
6d2ebf8b 10361@node Assignment
c906108c
SS
10362@section Assignment to variables
10363
10364@cindex assignment
10365@cindex setting variables
10366To alter the value of a variable, evaluate an assignment expression.
10367@xref{Expressions, ,Expressions}. For example,
10368
474c8240 10369@smallexample
c906108c 10370print x=4
474c8240 10371@end smallexample
c906108c
SS
10372
10373@noindent
10374stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10375value of the assignment expression (which is 4).
c906108c
SS
10376@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10377information on operators in supported languages.
c906108c
SS
10378
10379@kindex set variable
10380@cindex variables, setting
10381If you are not interested in seeing the value of the assignment, use the
10382@code{set} command instead of the @code{print} command. @code{set} is
10383really the same as @code{print} except that the expression's value is
10384not printed and is not put in the value history (@pxref{Value History,
10385,Value history}). The expression is evaluated only for its effects.
10386
c906108c
SS
10387If the beginning of the argument string of the @code{set} command
10388appears identical to a @code{set} subcommand, use the @code{set
10389variable} command instead of just @code{set}. This command is identical
10390to @code{set} except for its lack of subcommands. For example, if your
10391program has a variable @code{width}, you get an error if you try to set
10392a new value with just @samp{set width=13}, because @value{GDBN} has the
10393command @code{set width}:
10394
474c8240 10395@smallexample
c906108c
SS
10396(@value{GDBP}) whatis width
10397type = double
10398(@value{GDBP}) p width
10399$4 = 13
10400(@value{GDBP}) set width=47
10401Invalid syntax in expression.
474c8240 10402@end smallexample
c906108c
SS
10403
10404@noindent
10405The invalid expression, of course, is @samp{=47}. In
10406order to actually set the program's variable @code{width}, use
10407
474c8240 10408@smallexample
c906108c 10409(@value{GDBP}) set var width=47
474c8240 10410@end smallexample
53a5351d 10411
c906108c
SS
10412Because the @code{set} command has many subcommands that can conflict
10413with the names of program variables, it is a good idea to use the
10414@code{set variable} command instead of just @code{set}. For example, if
10415your program has a variable @code{g}, you run into problems if you try
10416to set a new value with just @samp{set g=4}, because @value{GDBN} has
10417the command @code{set gnutarget}, abbreviated @code{set g}:
10418
474c8240 10419@smallexample
c906108c
SS
10420@group
10421(@value{GDBP}) whatis g
10422type = double
10423(@value{GDBP}) p g
10424$1 = 1
10425(@value{GDBP}) set g=4
2df3850c 10426(@value{GDBP}) p g
c906108c
SS
10427$2 = 1
10428(@value{GDBP}) r
10429The program being debugged has been started already.
10430Start it from the beginning? (y or n) y
10431Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10432"/home/smith/cc_progs/a.out": can't open to read symbols:
10433 Invalid bfd target.
c906108c
SS
10434(@value{GDBP}) show g
10435The current BFD target is "=4".
10436@end group
474c8240 10437@end smallexample
c906108c
SS
10438
10439@noindent
10440The program variable @code{g} did not change, and you silently set the
10441@code{gnutarget} to an invalid value. In order to set the variable
10442@code{g}, use
10443
474c8240 10444@smallexample
c906108c 10445(@value{GDBP}) set var g=4
474c8240 10446@end smallexample
c906108c
SS
10447
10448@value{GDBN} allows more implicit conversions in assignments than C; you can
10449freely store an integer value into a pointer variable or vice versa,
10450and you can convert any structure to any other structure that is the
10451same length or shorter.
10452@comment FIXME: how do structs align/pad in these conversions?
10453@comment /doc@cygnus.com 18dec1990
10454
10455To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10456construct to generate a value of specified type at a specified address
10457(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10458to memory location @code{0x83040} as an integer (which implies a certain size
10459and representation in memory), and
10460
474c8240 10461@smallexample
c906108c 10462set @{int@}0x83040 = 4
474c8240 10463@end smallexample
c906108c
SS
10464
10465@noindent
10466stores the value 4 into that memory location.
10467
6d2ebf8b 10468@node Jumping
c906108c
SS
10469@section Continuing at a different address
10470
10471Ordinarily, when you continue your program, you do so at the place where
10472it stopped, with the @code{continue} command. You can instead continue at
10473an address of your own choosing, with the following commands:
10474
10475@table @code
10476@kindex jump
10477@item jump @var{linespec}
10478Resume execution at line @var{linespec}. Execution stops again
10479immediately if there is a breakpoint there. @xref{List, ,Printing
10480source lines}, for a description of the different forms of
10481@var{linespec}. It is common practice to use the @code{tbreak} command
10482in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10483breakpoints}.
10484
10485The @code{jump} command does not change the current stack frame, or
10486the stack pointer, or the contents of any memory location or any
10487register other than the program counter. If line @var{linespec} is in
10488a different function from the one currently executing, the results may
10489be bizarre if the two functions expect different patterns of arguments or
10490of local variables. For this reason, the @code{jump} command requests
10491confirmation if the specified line is not in the function currently
10492executing. However, even bizarre results are predictable if you are
10493well acquainted with the machine-language code of your program.
10494
10495@item jump *@var{address}
10496Resume execution at the instruction at address @var{address}.
10497@end table
10498
c906108c 10499@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10500On many systems, you can get much the same effect as the @code{jump}
10501command by storing a new value into the register @code{$pc}. The
10502difference is that this does not start your program running; it only
10503changes the address of where it @emph{will} run when you continue. For
10504example,
c906108c 10505
474c8240 10506@smallexample
c906108c 10507set $pc = 0x485
474c8240 10508@end smallexample
c906108c
SS
10509
10510@noindent
10511makes the next @code{continue} command or stepping command execute at
10512address @code{0x485}, rather than at the address where your program stopped.
10513@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10514
10515The most common occasion to use the @code{jump} command is to back
10516up---perhaps with more breakpoints set---over a portion of a program
10517that has already executed, in order to examine its execution in more
10518detail.
10519
c906108c 10520@c @group
6d2ebf8b 10521@node Signaling
c906108c 10522@section Giving your program a signal
9c16f35a 10523@cindex deliver a signal to a program
c906108c
SS
10524
10525@table @code
10526@kindex signal
10527@item signal @var{signal}
10528Resume execution where your program stopped, but immediately give it the
10529signal @var{signal}. @var{signal} can be the name or the number of a
10530signal. For example, on many systems @code{signal 2} and @code{signal
10531SIGINT} are both ways of sending an interrupt signal.
10532
10533Alternatively, if @var{signal} is zero, continue execution without
10534giving a signal. This is useful when your program stopped on account of
10535a signal and would ordinary see the signal when resumed with the
10536@code{continue} command; @samp{signal 0} causes it to resume without a
10537signal.
10538
10539@code{signal} does not repeat when you press @key{RET} a second time
10540after executing the command.
10541@end table
10542@c @end group
10543
10544Invoking the @code{signal} command is not the same as invoking the
10545@code{kill} utility from the shell. Sending a signal with @code{kill}
10546causes @value{GDBN} to decide what to do with the signal depending on
10547the signal handling tables (@pxref{Signals}). The @code{signal} command
10548passes the signal directly to your program.
10549
c906108c 10550
6d2ebf8b 10551@node Returning
c906108c
SS
10552@section Returning from a function
10553
10554@table @code
10555@cindex returning from a function
10556@kindex return
10557@item return
10558@itemx return @var{expression}
10559You can cancel execution of a function call with the @code{return}
10560command. If you give an
10561@var{expression} argument, its value is used as the function's return
10562value.
10563@end table
10564
10565When you use @code{return}, @value{GDBN} discards the selected stack frame
10566(and all frames within it). You can think of this as making the
10567discarded frame return prematurely. If you wish to specify a value to
10568be returned, give that value as the argument to @code{return}.
10569
10570This pops the selected stack frame (@pxref{Selection, ,Selecting a
10571frame}), and any other frames inside of it, leaving its caller as the
10572innermost remaining frame. That frame becomes selected. The
10573specified value is stored in the registers used for returning values
10574of functions.
10575
10576The @code{return} command does not resume execution; it leaves the
10577program stopped in the state that would exist if the function had just
10578returned. In contrast, the @code{finish} command (@pxref{Continuing
10579and Stepping, ,Continuing and stepping}) resumes execution until the
10580selected stack frame returns naturally.
10581
6d2ebf8b 10582@node Calling
c906108c
SS
10583@section Calling program functions
10584
f8568604 10585@table @code
c906108c 10586@cindex calling functions
f8568604
EZ
10587@cindex inferior functions, calling
10588@item print @var{expr}
9c16f35a 10589Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10590@var{expr} may include calls to functions in the program being
10591debugged.
10592
c906108c 10593@kindex call
c906108c
SS
10594@item call @var{expr}
10595Evaluate the expression @var{expr} without displaying @code{void}
10596returned values.
c906108c
SS
10597
10598You can use this variant of the @code{print} command if you want to
f8568604
EZ
10599execute a function from your program that does not return anything
10600(a.k.a.@: @dfn{a void function}), but without cluttering the output
10601with @code{void} returned values that @value{GDBN} will otherwise
10602print. If the result is not void, it is printed and saved in the
10603value history.
10604@end table
10605
9c16f35a
EZ
10606It is possible for the function you call via the @code{print} or
10607@code{call} command to generate a signal (e.g., if there's a bug in
10608the function, or if you passed it incorrect arguments). What happens
10609in that case is controlled by the @code{set unwindonsignal} command.
10610
10611@table @code
10612@item set unwindonsignal
10613@kindex set unwindonsignal
10614@cindex unwind stack in called functions
10615@cindex call dummy stack unwinding
10616Set unwinding of the stack if a signal is received while in a function
10617that @value{GDBN} called in the program being debugged. If set to on,
10618@value{GDBN} unwinds the stack it created for the call and restores
10619the context to what it was before the call. If set to off (the
10620default), @value{GDBN} stops in the frame where the signal was
10621received.
10622
10623@item show unwindonsignal
10624@kindex show unwindonsignal
10625Show the current setting of stack unwinding in the functions called by
10626@value{GDBN}.
10627@end table
10628
f8568604
EZ
10629@cindex weak alias functions
10630Sometimes, a function you wish to call is actually a @dfn{weak alias}
10631for another function. In such case, @value{GDBN} might not pick up
10632the type information, including the types of the function arguments,
10633which causes @value{GDBN} to call the inferior function incorrectly.
10634As a result, the called function will function erroneously and may
10635even crash. A solution to that is to use the name of the aliased
10636function instead.
c906108c 10637
6d2ebf8b 10638@node Patching
c906108c 10639@section Patching programs
7a292a7a 10640
c906108c
SS
10641@cindex patching binaries
10642@cindex writing into executables
c906108c 10643@cindex writing into corefiles
c906108c 10644
7a292a7a
SS
10645By default, @value{GDBN} opens the file containing your program's
10646executable code (or the corefile) read-only. This prevents accidental
10647alterations to machine code; but it also prevents you from intentionally
10648patching your program's binary.
c906108c
SS
10649
10650If you'd like to be able to patch the binary, you can specify that
10651explicitly with the @code{set write} command. For example, you might
10652want to turn on internal debugging flags, or even to make emergency
10653repairs.
10654
10655@table @code
10656@kindex set write
10657@item set write on
10658@itemx set write off
7a292a7a
SS
10659If you specify @samp{set write on}, @value{GDBN} opens executable and
10660core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10661off} (the default), @value{GDBN} opens them read-only.
10662
10663If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10664@code{exec-file} or @code{core-file} command) after changing @code{set
10665write}, for your new setting to take effect.
c906108c
SS
10666
10667@item show write
10668@kindex show write
7a292a7a
SS
10669Display whether executable files and core files are opened for writing
10670as well as reading.
c906108c
SS
10671@end table
10672
6d2ebf8b 10673@node GDB Files
c906108c
SS
10674@chapter @value{GDBN} Files
10675
7a292a7a
SS
10676@value{GDBN} needs to know the file name of the program to be debugged,
10677both in order to read its symbol table and in order to start your
10678program. To debug a core dump of a previous run, you must also tell
10679@value{GDBN} the name of the core dump file.
c906108c
SS
10680
10681@menu
10682* Files:: Commands to specify files
5b5d99cf 10683* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10684* Symbol Errors:: Errors reading symbol files
10685@end menu
10686
6d2ebf8b 10687@node Files
c906108c 10688@section Commands to specify files
c906108c 10689
7a292a7a 10690@cindex symbol table
c906108c 10691@cindex core dump file
7a292a7a
SS
10692
10693You may want to specify executable and core dump file names. The usual
10694way to do this is at start-up time, using the arguments to
10695@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10696Out of @value{GDBN}}).
c906108c
SS
10697
10698Occasionally it is necessary to change to a different file during a
397ca115
EZ
10699@value{GDBN} session. Or you may run @value{GDBN} and forget to
10700specify a file you want to use. Or you are debugging a remote target
10701via @code{gdbserver} (@pxref{Server, file}). In these situations the
10702@value{GDBN} commands to specify new files are useful.
c906108c
SS
10703
10704@table @code
10705@cindex executable file
10706@kindex file
10707@item file @var{filename}
10708Use @var{filename} as the program to be debugged. It is read for its
10709symbols and for the contents of pure memory. It is also the program
10710executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10711directory and the file is not found in the @value{GDBN} working directory,
10712@value{GDBN} uses the environment variable @code{PATH} as a list of
10713directories to search, just as the shell does when looking for a program
10714to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10715and your program, using the @code{path} command.
10716
fc8be69e
EZ
10717@cindex unlinked object files
10718@cindex patching object files
10719You can load unlinked object @file{.o} files into @value{GDBN} using
10720the @code{file} command. You will not be able to ``run'' an object
10721file, but you can disassemble functions and inspect variables. Also,
10722if the underlying BFD functionality supports it, you could use
10723@kbd{gdb -write} to patch object files using this technique. Note
10724that @value{GDBN} can neither interpret nor modify relocations in this
10725case, so branches and some initialized variables will appear to go to
10726the wrong place. But this feature is still handy from time to time.
10727
c906108c
SS
10728@item file
10729@code{file} with no argument makes @value{GDBN} discard any information it
10730has on both executable file and the symbol table.
10731
10732@kindex exec-file
10733@item exec-file @r{[} @var{filename} @r{]}
10734Specify that the program to be run (but not the symbol table) is found
10735in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10736if necessary to locate your program. Omitting @var{filename} means to
10737discard information on the executable file.
10738
10739@kindex symbol-file
10740@item symbol-file @r{[} @var{filename} @r{]}
10741Read symbol table information from file @var{filename}. @code{PATH} is
10742searched when necessary. Use the @code{file} command to get both symbol
10743table and program to run from the same file.
10744
10745@code{symbol-file} with no argument clears out @value{GDBN} information on your
10746program's symbol table.
10747
5d161b24 10748The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10749of its convenience variables, the value history, and all breakpoints and
10750auto-display expressions. This is because they may contain pointers to
10751the internal data recording symbols and data types, which are part of
10752the old symbol table data being discarded inside @value{GDBN}.
10753
10754@code{symbol-file} does not repeat if you press @key{RET} again after
10755executing it once.
10756
10757When @value{GDBN} is configured for a particular environment, it
10758understands debugging information in whatever format is the standard
10759generated for that environment; you may use either a @sc{gnu} compiler, or
10760other compilers that adhere to the local conventions.
c906108c
SS
10761Best results are usually obtained from @sc{gnu} compilers; for example,
10762using @code{@value{GCC}} you can generate debugging information for
10763optimized code.
c906108c
SS
10764
10765For most kinds of object files, with the exception of old SVR3 systems
10766using COFF, the @code{symbol-file} command does not normally read the
10767symbol table in full right away. Instead, it scans the symbol table
10768quickly to find which source files and which symbols are present. The
10769details are read later, one source file at a time, as they are needed.
10770
10771The purpose of this two-stage reading strategy is to make @value{GDBN}
10772start up faster. For the most part, it is invisible except for
10773occasional pauses while the symbol table details for a particular source
10774file are being read. (The @code{set verbose} command can turn these
10775pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10776warnings and messages}.)
10777
c906108c
SS
10778We have not implemented the two-stage strategy for COFF yet. When the
10779symbol table is stored in COFF format, @code{symbol-file} reads the
10780symbol table data in full right away. Note that ``stabs-in-COFF''
10781still does the two-stage strategy, since the debug info is actually
10782in stabs format.
10783
10784@kindex readnow
10785@cindex reading symbols immediately
10786@cindex symbols, reading immediately
a94ab193
EZ
10787@item symbol-file @var{filename} @r{[} -readnow @r{]}
10788@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
10789You can override the @value{GDBN} two-stage strategy for reading symbol
10790tables by using the @samp{-readnow} option with any of the commands that
10791load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10792entire symbol table available.
c906108c 10793
c906108c
SS
10794@c FIXME: for now no mention of directories, since this seems to be in
10795@c flux. 13mar1992 status is that in theory GDB would look either in
10796@c current dir or in same dir as myprog; but issues like competing
10797@c GDB's, or clutter in system dirs, mean that in practice right now
10798@c only current dir is used. FFish says maybe a special GDB hierarchy
10799@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10800@c files.
10801
c906108c 10802@kindex core-file
09d4efe1 10803@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10804@itemx core
c906108c
SS
10805Specify the whereabouts of a core dump file to be used as the ``contents
10806of memory''. Traditionally, core files contain only some parts of the
10807address space of the process that generated them; @value{GDBN} can access the
10808executable file itself for other parts.
10809
10810@code{core-file} with no argument specifies that no core file is
10811to be used.
10812
10813Note that the core file is ignored when your program is actually running
7a292a7a
SS
10814under @value{GDBN}. So, if you have been running your program and you
10815wish to debug a core file instead, you must kill the subprocess in which
10816the program is running. To do this, use the @code{kill} command
c906108c 10817(@pxref{Kill Process, ,Killing the child process}).
c906108c 10818
c906108c
SS
10819@kindex add-symbol-file
10820@cindex dynamic linking
10821@item add-symbol-file @var{filename} @var{address}
a94ab193 10822@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 10823@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10824The @code{add-symbol-file} command reads additional symbol table
10825information from the file @var{filename}. You would use this command
10826when @var{filename} has been dynamically loaded (by some other means)
10827into the program that is running. @var{address} should be the memory
10828address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10829this out for itself. You can additionally specify an arbitrary number
10830of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10831section name and base address for that section. You can specify any
10832@var{address} as an expression.
c906108c
SS
10833
10834The symbol table of the file @var{filename} is added to the symbol table
10835originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10836@code{add-symbol-file} command any number of times; the new symbol data
10837thus read keeps adding to the old. To discard all old symbol data
10838instead, use the @code{symbol-file} command without any arguments.
c906108c 10839
17d9d558
JB
10840@cindex relocatable object files, reading symbols from
10841@cindex object files, relocatable, reading symbols from
10842@cindex reading symbols from relocatable object files
10843@cindex symbols, reading from relocatable object files
10844@cindex @file{.o} files, reading symbols from
10845Although @var{filename} is typically a shared library file, an
10846executable file, or some other object file which has been fully
10847relocated for loading into a process, you can also load symbolic
10848information from relocatable @file{.o} files, as long as:
10849
10850@itemize @bullet
10851@item
10852the file's symbolic information refers only to linker symbols defined in
10853that file, not to symbols defined by other object files,
10854@item
10855every section the file's symbolic information refers to has actually
10856been loaded into the inferior, as it appears in the file, and
10857@item
10858you can determine the address at which every section was loaded, and
10859provide these to the @code{add-symbol-file} command.
10860@end itemize
10861
10862@noindent
10863Some embedded operating systems, like Sun Chorus and VxWorks, can load
10864relocatable files into an already running program; such systems
10865typically make the requirements above easy to meet. However, it's
10866important to recognize that many native systems use complex link
49efadf5 10867procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10868assembly, for example) that make the requirements difficult to meet. In
10869general, one cannot assume that using @code{add-symbol-file} to read a
10870relocatable object file's symbolic information will have the same effect
10871as linking the relocatable object file into the program in the normal
10872way.
10873
c906108c
SS
10874@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10875
c45da7e6
EZ
10876@kindex add-symbol-file-from-memory
10877@cindex @code{syscall DSO}
10878@cindex load symbols from memory
10879@item add-symbol-file-from-memory @var{address}
10880Load symbols from the given @var{address} in a dynamically loaded
10881object file whose image is mapped directly into the inferior's memory.
10882For example, the Linux kernel maps a @code{syscall DSO} into each
10883process's address space; this DSO provides kernel-specific code for
10884some system calls. The argument can be any expression whose
10885evaluation yields the address of the file's shared object file header.
10886For this command to work, you must have used @code{symbol-file} or
10887@code{exec-file} commands in advance.
10888
09d4efe1
EZ
10889@kindex add-shared-symbol-files
10890@kindex assf
10891@item add-shared-symbol-files @var{library-file}
10892@itemx assf @var{library-file}
10893The @code{add-shared-symbol-files} command can currently be used only
10894in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10895alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10896@value{GDBN} automatically looks for shared libraries, however if
10897@value{GDBN} does not find yours, you can invoke
10898@code{add-shared-symbol-files}. It takes one argument: the shared
10899library's file name. @code{assf} is a shorthand alias for
10900@code{add-shared-symbol-files}.
c906108c 10901
c906108c 10902@kindex section
09d4efe1
EZ
10903@item section @var{section} @var{addr}
10904The @code{section} command changes the base address of the named
10905@var{section} of the exec file to @var{addr}. This can be used if the
10906exec file does not contain section addresses, (such as in the
10907@code{a.out} format), or when the addresses specified in the file
10908itself are wrong. Each section must be changed separately. The
10909@code{info files} command, described below, lists all the sections and
10910their addresses.
c906108c
SS
10911
10912@kindex info files
10913@kindex info target
10914@item info files
10915@itemx info target
7a292a7a
SS
10916@code{info files} and @code{info target} are synonymous; both print the
10917current target (@pxref{Targets, ,Specifying a Debugging Target}),
10918including the names of the executable and core dump files currently in
10919use by @value{GDBN}, and the files from which symbols were loaded. The
10920command @code{help target} lists all possible targets rather than
10921current ones.
10922
fe95c787
MS
10923@kindex maint info sections
10924@item maint info sections
10925Another command that can give you extra information about program sections
10926is @code{maint info sections}. In addition to the section information
10927displayed by @code{info files}, this command displays the flags and file
10928offset of each section in the executable and core dump files. In addition,
10929@code{maint info sections} provides the following command options (which
10930may be arbitrarily combined):
10931
10932@table @code
10933@item ALLOBJ
10934Display sections for all loaded object files, including shared libraries.
10935@item @var{sections}
6600abed 10936Display info only for named @var{sections}.
fe95c787
MS
10937@item @var{section-flags}
10938Display info only for sections for which @var{section-flags} are true.
10939The section flags that @value{GDBN} currently knows about are:
10940@table @code
10941@item ALLOC
10942Section will have space allocated in the process when loaded.
10943Set for all sections except those containing debug information.
10944@item LOAD
10945Section will be loaded from the file into the child process memory.
10946Set for pre-initialized code and data, clear for @code{.bss} sections.
10947@item RELOC
10948Section needs to be relocated before loading.
10949@item READONLY
10950Section cannot be modified by the child process.
10951@item CODE
10952Section contains executable code only.
6600abed 10953@item DATA
fe95c787
MS
10954Section contains data only (no executable code).
10955@item ROM
10956Section will reside in ROM.
10957@item CONSTRUCTOR
10958Section contains data for constructor/destructor lists.
10959@item HAS_CONTENTS
10960Section is not empty.
10961@item NEVER_LOAD
10962An instruction to the linker to not output the section.
10963@item COFF_SHARED_LIBRARY
10964A notification to the linker that the section contains
10965COFF shared library information.
10966@item IS_COMMON
10967Section contains common symbols.
10968@end table
10969@end table
6763aef9 10970@kindex set trust-readonly-sections
9c16f35a 10971@cindex read-only sections
6763aef9
MS
10972@item set trust-readonly-sections on
10973Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10974really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10975In that case, @value{GDBN} can fetch values from these sections
10976out of the object file, rather than from the target program.
10977For some targets (notably embedded ones), this can be a significant
10978enhancement to debugging performance.
10979
10980The default is off.
10981
10982@item set trust-readonly-sections off
15110bc3 10983Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10984the contents of the section might change while the program is running,
10985and must therefore be fetched from the target when needed.
9c16f35a
EZ
10986
10987@item show trust-readonly-sections
10988Show the current setting of trusting readonly sections.
c906108c
SS
10989@end table
10990
10991All file-specifying commands allow both absolute and relative file names
10992as arguments. @value{GDBN} always converts the file name to an absolute file
10993name and remembers it that way.
10994
c906108c 10995@cindex shared libraries
9c16f35a
EZ
10996@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10997and IBM RS/6000 AIX shared libraries.
53a5351d 10998
c906108c
SS
10999@value{GDBN} automatically loads symbol definitions from shared libraries
11000when you use the @code{run} command, or when you examine a core file.
11001(Before you issue the @code{run} command, @value{GDBN} does not understand
11002references to a function in a shared library, however---unless you are
11003debugging a core file).
53a5351d
JM
11004
11005On HP-UX, if the program loads a library explicitly, @value{GDBN}
11006automatically loads the symbols at the time of the @code{shl_load} call.
11007
c906108c
SS
11008@c FIXME: some @value{GDBN} release may permit some refs to undef
11009@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11010@c FIXME...lib; check this from time to time when updating manual
11011
b7209cb4
FF
11012There are times, however, when you may wish to not automatically load
11013symbol definitions from shared libraries, such as when they are
11014particularly large or there are many of them.
11015
11016To control the automatic loading of shared library symbols, use the
11017commands:
11018
11019@table @code
11020@kindex set auto-solib-add
11021@item set auto-solib-add @var{mode}
11022If @var{mode} is @code{on}, symbols from all shared object libraries
11023will be loaded automatically when the inferior begins execution, you
11024attach to an independently started inferior, or when the dynamic linker
11025informs @value{GDBN} that a new library has been loaded. If @var{mode}
11026is @code{off}, symbols must be loaded manually, using the
11027@code{sharedlibrary} command. The default value is @code{on}.
11028
dcaf7c2c
EZ
11029@cindex memory used for symbol tables
11030If your program uses lots of shared libraries with debug info that
11031takes large amounts of memory, you can decrease the @value{GDBN}
11032memory footprint by preventing it from automatically loading the
11033symbols from shared libraries. To that end, type @kbd{set
11034auto-solib-add off} before running the inferior, then load each
11035library whose debug symbols you do need with @kbd{sharedlibrary
11036@var{regexp}}, where @var{regexp} is a regular expresion that matches
11037the libraries whose symbols you want to be loaded.
11038
b7209cb4
FF
11039@kindex show auto-solib-add
11040@item show auto-solib-add
11041Display the current autoloading mode.
11042@end table
11043
c45da7e6 11044@cindex load shared library
b7209cb4
FF
11045To explicitly load shared library symbols, use the @code{sharedlibrary}
11046command:
11047
c906108c
SS
11048@table @code
11049@kindex info sharedlibrary
11050@kindex info share
11051@item info share
11052@itemx info sharedlibrary
11053Print the names of the shared libraries which are currently loaded.
11054
11055@kindex sharedlibrary
11056@kindex share
11057@item sharedlibrary @var{regex}
11058@itemx share @var{regex}
c906108c
SS
11059Load shared object library symbols for files matching a
11060Unix regular expression.
11061As with files loaded automatically, it only loads shared libraries
11062required by your program for a core file or after typing @code{run}. If
11063@var{regex} is omitted all shared libraries required by your program are
11064loaded.
c45da7e6
EZ
11065
11066@item nosharedlibrary
11067@kindex nosharedlibrary
11068@cindex unload symbols from shared libraries
11069Unload all shared object library symbols. This discards all symbols
11070that have been loaded from all shared libraries. Symbols from shared
11071libraries that were loaded by explicit user requests are not
11072discarded.
c906108c
SS
11073@end table
11074
721c2651
EZ
11075Sometimes you may wish that @value{GDBN} stops and gives you control
11076when any of shared library events happen. Use the @code{set
11077stop-on-solib-events} command for this:
11078
11079@table @code
11080@item set stop-on-solib-events
11081@kindex set stop-on-solib-events
11082This command controls whether @value{GDBN} should give you control
11083when the dynamic linker notifies it about some shared library event.
11084The most common event of interest is loading or unloading of a new
11085shared library.
11086
11087@item show stop-on-solib-events
11088@kindex show stop-on-solib-events
11089Show whether @value{GDBN} stops and gives you control when shared
11090library events happen.
11091@end table
11092
f5ebfba0
DJ
11093Shared libraries are also supported in many cross or remote debugging
11094configurations. A copy of the target's libraries need to be present on the
11095host system; they need to be the same as the target libraries, although the
11096copies on the target can be stripped as long as the copies on the host are
11097not.
11098
59b7b46f
EZ
11099@cindex where to look for shared libraries
11100For remote debugging, you need to tell @value{GDBN} where the target
11101libraries are, so that it can load the correct copies---otherwise, it
11102may try to load the host's libraries. @value{GDBN} has two variables
11103to specify the search directories for target libraries.
f5ebfba0
DJ
11104
11105@table @code
59b7b46f 11106@cindex prefix for shared library file names
f5ebfba0
DJ
11107@kindex set solib-absolute-prefix
11108@item set solib-absolute-prefix @var{path}
11109If this variable is set, @var{path} will be used as a prefix for any
11110absolute shared library paths; many runtime loaders store the absolute
11111paths to the shared library in the target program's memory. If you use
11112@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11113out in the same way that they are on the target, with e.g.@: a
11114@file{/usr/lib} hierarchy under @var{path}.
11115
59b7b46f
EZ
11116@cindex default value of @samp{solib-absolute-prefix}
11117@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11118You can set the default value of @samp{solib-absolute-prefix} by using the
11119configure-time @samp{--with-sysroot} option.
11120
11121@kindex show solib-absolute-prefix
11122@item show solib-absolute-prefix
11123Display the current shared library prefix.
11124
11125@kindex set solib-search-path
11126@item set solib-search-path @var{path}
11127If this variable is set, @var{path} is a colon-separated list of directories
11128to search for shared libraries. @samp{solib-search-path} is used after
11129@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11130the library is relative instead of absolute. If you want to use
11131@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11132set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11133@value{GDBN} from finding your host's libraries.
11134
11135@kindex show solib-search-path
11136@item show solib-search-path
11137Display the current shared library search path.
11138@end table
11139
5b5d99cf
JB
11140
11141@node Separate Debug Files
11142@section Debugging Information in Separate Files
11143@cindex separate debugging information files
11144@cindex debugging information in separate files
11145@cindex @file{.debug} subdirectories
11146@cindex debugging information directory, global
11147@cindex global debugging information directory
11148
11149@value{GDBN} allows you to put a program's debugging information in a
11150file separate from the executable itself, in a way that allows
11151@value{GDBN} to find and load the debugging information automatically.
11152Since debugging information can be very large --- sometimes larger
11153than the executable code itself --- some systems distribute debugging
11154information for their executables in separate files, which users can
11155install only when they need to debug a problem.
11156
11157If an executable's debugging information has been extracted to a
11158separate file, the executable should contain a @dfn{debug link} giving
11159the name of the debugging information file (with no directory
11160components), and a checksum of its contents. (The exact form of a
11161debug link is described below.) If the full name of the directory
11162containing the executable is @var{execdir}, and the executable has a
11163debug link that specifies the name @var{debugfile}, then @value{GDBN}
11164will automatically search for the debugging information file in three
11165places:
11166
11167@itemize @bullet
11168@item
11169the directory containing the executable file (that is, it will look
11170for a file named @file{@var{execdir}/@var{debugfile}},
11171@item
11172a subdirectory of that directory named @file{.debug} (that is, the
11173file @file{@var{execdir}/.debug/@var{debugfile}}, and
11174@item
11175a subdirectory of the global debug file directory that includes the
11176executable's full path, and the name from the link (that is, the file
11177@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11178@var{globaldebugdir} is the global debug file directory, and
11179@var{execdir} has been turned into a relative path).
11180@end itemize
11181@noindent
11182@value{GDBN} checks under each of these names for a debugging
11183information file whose checksum matches that given in the link, and
11184reads the debugging information from the first one it finds.
11185
11186So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11187which has a link containing the name @file{ls.debug}, and the global
11188debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11189for debug information in @file{/usr/bin/ls.debug},
11190@file{/usr/bin/.debug/ls.debug}, and
11191@file{/usr/lib/debug/usr/bin/ls.debug}.
11192
11193You can set the global debugging info directory's name, and view the
11194name @value{GDBN} is currently using.
11195
11196@table @code
11197
11198@kindex set debug-file-directory
11199@item set debug-file-directory @var{directory}
11200Set the directory which @value{GDBN} searches for separate debugging
11201information files to @var{directory}.
11202
11203@kindex show debug-file-directory
11204@item show debug-file-directory
11205Show the directory @value{GDBN} searches for separate debugging
11206information files.
11207
11208@end table
11209
11210@cindex @code{.gnu_debuglink} sections
11211@cindex debug links
11212A debug link is a special section of the executable file named
11213@code{.gnu_debuglink}. The section must contain:
11214
11215@itemize
11216@item
11217A filename, with any leading directory components removed, followed by
11218a zero byte,
11219@item
11220zero to three bytes of padding, as needed to reach the next four-byte
11221boundary within the section, and
11222@item
11223a four-byte CRC checksum, stored in the same endianness used for the
11224executable file itself. The checksum is computed on the debugging
11225information file's full contents by the function given below, passing
11226zero as the @var{crc} argument.
11227@end itemize
11228
11229Any executable file format can carry a debug link, as long as it can
11230contain a section named @code{.gnu_debuglink} with the contents
11231described above.
11232
11233The debugging information file itself should be an ordinary
11234executable, containing a full set of linker symbols, sections, and
11235debugging information. The sections of the debugging information file
11236should have the same names, addresses and sizes as the original file,
11237but they need not contain any data --- much like a @code{.bss} section
11238in an ordinary executable.
11239
11240As of December 2002, there is no standard GNU utility to produce
11241separated executable / debugging information file pairs. Ulrich
11242Drepper's @file{elfutils} package, starting with version 0.53,
11243contains a version of the @code{strip} command such that the command
11244@kbd{strip foo -f foo.debug} removes the debugging information from
11245the executable file @file{foo}, places it in the file
11246@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11247
11248Since there are many different ways to compute CRC's (different
11249polynomials, reversals, byte ordering, etc.), the simplest way to
11250describe the CRC used in @code{.gnu_debuglink} sections is to give the
11251complete code for a function that computes it:
11252
4644b6e3 11253@kindex gnu_debuglink_crc32
5b5d99cf
JB
11254@smallexample
11255unsigned long
11256gnu_debuglink_crc32 (unsigned long crc,
11257 unsigned char *buf, size_t len)
11258@{
11259 static const unsigned long crc32_table[256] =
11260 @{
11261 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11262 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11263 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11264 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11265 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11266 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11267 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11268 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11269 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11270 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11271 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11272 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11273 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11274 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11275 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11276 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11277 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11278 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11279 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11280 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11281 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11282 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11283 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11284 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11285 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11286 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11287 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11288 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11289 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11290 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11291 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11292 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11293 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11294 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11295 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11296 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11297 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11298 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11299 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11300 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11301 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11302 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11303 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11304 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11305 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11306 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11307 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11308 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11309 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11310 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11311 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11312 0x2d02ef8d
11313 @};
11314 unsigned char *end;
11315
11316 crc = ~crc & 0xffffffff;
11317 for (end = buf + len; buf < end; ++buf)
11318 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11319 return ~crc & 0xffffffff;
5b5d99cf
JB
11320@}
11321@end smallexample
11322
11323
6d2ebf8b 11324@node Symbol Errors
c906108c
SS
11325@section Errors reading symbol files
11326
11327While reading a symbol file, @value{GDBN} occasionally encounters problems,
11328such as symbol types it does not recognize, or known bugs in compiler
11329output. By default, @value{GDBN} does not notify you of such problems, since
11330they are relatively common and primarily of interest to people
11331debugging compilers. If you are interested in seeing information
11332about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11333only one message about each such type of problem, no matter how many
11334times the problem occurs; or you can ask @value{GDBN} to print more messages,
11335to see how many times the problems occur, with the @code{set
11336complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11337messages}).
11338
11339The messages currently printed, and their meanings, include:
11340
11341@table @code
11342@item inner block not inside outer block in @var{symbol}
11343
11344The symbol information shows where symbol scopes begin and end
11345(such as at the start of a function or a block of statements). This
11346error indicates that an inner scope block is not fully contained
11347in its outer scope blocks.
11348
11349@value{GDBN} circumvents the problem by treating the inner block as if it had
11350the same scope as the outer block. In the error message, @var{symbol}
11351may be shown as ``@code{(don't know)}'' if the outer block is not a
11352function.
11353
11354@item block at @var{address} out of order
11355
11356The symbol information for symbol scope blocks should occur in
11357order of increasing addresses. This error indicates that it does not
11358do so.
11359
11360@value{GDBN} does not circumvent this problem, and has trouble
11361locating symbols in the source file whose symbols it is reading. (You
11362can often determine what source file is affected by specifying
11363@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11364messages}.)
11365
11366@item bad block start address patched
11367
11368The symbol information for a symbol scope block has a start address
11369smaller than the address of the preceding source line. This is known
11370to occur in the SunOS 4.1.1 (and earlier) C compiler.
11371
11372@value{GDBN} circumvents the problem by treating the symbol scope block as
11373starting on the previous source line.
11374
11375@item bad string table offset in symbol @var{n}
11376
11377@cindex foo
11378Symbol number @var{n} contains a pointer into the string table which is
11379larger than the size of the string table.
11380
11381@value{GDBN} circumvents the problem by considering the symbol to have the
11382name @code{foo}, which may cause other problems if many symbols end up
11383with this name.
11384
11385@item unknown symbol type @code{0x@var{nn}}
11386
7a292a7a
SS
11387The symbol information contains new data types that @value{GDBN} does
11388not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11389uncomprehended information, in hexadecimal.
c906108c 11390
7a292a7a
SS
11391@value{GDBN} circumvents the error by ignoring this symbol information.
11392This usually allows you to debug your program, though certain symbols
c906108c 11393are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11394debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11395on @code{complain}, then go up to the function @code{read_dbx_symtab}
11396and examine @code{*bufp} to see the symbol.
c906108c
SS
11397
11398@item stub type has NULL name
c906108c 11399
7a292a7a 11400@value{GDBN} could not find the full definition for a struct or class.
c906108c 11401
7a292a7a 11402@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11403The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11404information that recent versions of the compiler should have output for
11405it.
c906108c
SS
11406
11407@item info mismatch between compiler and debugger
11408
11409@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11410
c906108c
SS
11411@end table
11412
6d2ebf8b 11413@node Targets
c906108c 11414@chapter Specifying a Debugging Target
7a292a7a 11415
c906108c 11416@cindex debugging target
c906108c 11417A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11418
11419Often, @value{GDBN} runs in the same host environment as your program;
11420in that case, the debugging target is specified as a side effect when
11421you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11422flexibility---for example, running @value{GDBN} on a physically separate
11423host, or controlling a standalone system over a serial port or a
53a5351d
JM
11424realtime system over a TCP/IP connection---you can use the @code{target}
11425command to specify one of the target types configured for @value{GDBN}
11426(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11427
a8f24a35
EZ
11428@cindex target architecture
11429It is possible to build @value{GDBN} for several different @dfn{target
11430architectures}. When @value{GDBN} is built like that, you can choose
11431one of the available architectures with the @kbd{set architecture}
11432command.
11433
11434@table @code
11435@kindex set architecture
11436@kindex show architecture
11437@item set architecture @var{arch}
11438This command sets the current target architecture to @var{arch}. The
11439value of @var{arch} can be @code{"auto"}, in addition to one of the
11440supported architectures.
11441
11442@item show architecture
11443Show the current target architecture.
9c16f35a
EZ
11444
11445@item set processor
11446@itemx processor
11447@kindex set processor
11448@kindex show processor
11449These are alias commands for, respectively, @code{set architecture}
11450and @code{show architecture}.
a8f24a35
EZ
11451@end table
11452
c906108c
SS
11453@menu
11454* Active Targets:: Active targets
11455* Target Commands:: Commands for managing targets
c906108c
SS
11456* Byte Order:: Choosing target byte order
11457* Remote:: Remote debugging
96baa820 11458* KOD:: Kernel Object Display
c906108c
SS
11459
11460@end menu
11461
6d2ebf8b 11462@node Active Targets
c906108c 11463@section Active targets
7a292a7a 11464
c906108c
SS
11465@cindex stacking targets
11466@cindex active targets
11467@cindex multiple targets
11468
c906108c 11469There are three classes of targets: processes, core files, and
7a292a7a
SS
11470executable files. @value{GDBN} can work concurrently on up to three
11471active targets, one in each class. This allows you to (for example)
11472start a process and inspect its activity without abandoning your work on
11473a core file.
c906108c
SS
11474
11475For example, if you execute @samp{gdb a.out}, then the executable file
11476@code{a.out} is the only active target. If you designate a core file as
11477well---presumably from a prior run that crashed and coredumped---then
11478@value{GDBN} has two active targets and uses them in tandem, looking
11479first in the corefile target, then in the executable file, to satisfy
11480requests for memory addresses. (Typically, these two classes of target
11481are complementary, since core files contain only a program's
11482read-write memory---variables and so on---plus machine status, while
11483executable files contain only the program text and initialized data.)
c906108c
SS
11484
11485When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11486target as well. When a process target is active, all @value{GDBN}
11487commands requesting memory addresses refer to that target; addresses in
11488an active core file or executable file target are obscured while the
11489process target is active.
c906108c 11490
7a292a7a
SS
11491Use the @code{core-file} and @code{exec-file} commands to select a new
11492core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11493files}). To specify as a target a process that is already running, use
7a292a7a
SS
11494the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11495process}).
c906108c 11496
6d2ebf8b 11497@node Target Commands
c906108c
SS
11498@section Commands for managing targets
11499
11500@table @code
11501@item target @var{type} @var{parameters}
7a292a7a
SS
11502Connects the @value{GDBN} host environment to a target machine or
11503process. A target is typically a protocol for talking to debugging
11504facilities. You use the argument @var{type} to specify the type or
11505protocol of the target machine.
c906108c
SS
11506
11507Further @var{parameters} are interpreted by the target protocol, but
11508typically include things like device names or host names to connect
11509with, process numbers, and baud rates.
c906108c
SS
11510
11511The @code{target} command does not repeat if you press @key{RET} again
11512after executing the command.
11513
11514@kindex help target
11515@item help target
11516Displays the names of all targets available. To display targets
11517currently selected, use either @code{info target} or @code{info files}
11518(@pxref{Files, ,Commands to specify files}).
11519
11520@item help target @var{name}
11521Describe a particular target, including any parameters necessary to
11522select it.
11523
11524@kindex set gnutarget
11525@item set gnutarget @var{args}
5d161b24 11526@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11527knows whether it is reading an @dfn{executable},
5d161b24
DB
11528a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11529with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11530with @code{gnutarget} the @code{target} refers to a program, not a machine.
11531
d4f3574e 11532@quotation
c906108c
SS
11533@emph{Warning:} To specify a file format with @code{set gnutarget},
11534you must know the actual BFD name.
d4f3574e 11535@end quotation
c906108c 11536
d4f3574e
SS
11537@noindent
11538@xref{Files, , Commands to specify files}.
c906108c 11539
5d161b24 11540@kindex show gnutarget
c906108c
SS
11541@item show gnutarget
11542Use the @code{show gnutarget} command to display what file format
11543@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11544@value{GDBN} will determine the file format for each file automatically,
11545and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11546@end table
11547
4644b6e3 11548@cindex common targets
c906108c
SS
11549Here are some common targets (available, or not, depending on the GDB
11550configuration):
c906108c
SS
11551
11552@table @code
4644b6e3 11553@kindex target
c906108c 11554@item target exec @var{program}
4644b6e3 11555@cindex executable file target
c906108c
SS
11556An executable file. @samp{target exec @var{program}} is the same as
11557@samp{exec-file @var{program}}.
11558
c906108c 11559@item target core @var{filename}
4644b6e3 11560@cindex core dump file target
c906108c
SS
11561A core dump file. @samp{target core @var{filename}} is the same as
11562@samp{core-file @var{filename}}.
c906108c 11563
c906108c 11564@item target remote @var{dev}
4644b6e3 11565@cindex remote target
c906108c
SS
11566Remote serial target in GDB-specific protocol. The argument @var{dev}
11567specifies what serial device to use for the connection (e.g.
11568@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11569supports the @code{load} command. This is only useful if you have
c906108c
SS
11570some other way of getting the stub to the target system, and you can put
11571it somewhere in memory where it won't get clobbered by the download.
11572
c906108c 11573@item target sim
4644b6e3 11574@cindex built-in simulator target
2df3850c 11575Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11576In general,
474c8240 11577@smallexample
104c1213
JM
11578 target sim
11579 load
11580 run
474c8240 11581@end smallexample
d4f3574e 11582@noindent
104c1213 11583works; however, you cannot assume that a specific memory map, device
d4f3574e 11584drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11585provide these. For info about any processor-specific simulator details,
11586see the appropriate section in @ref{Embedded Processors, ,Embedded
11587Processors}.
11588
c906108c
SS
11589@end table
11590
104c1213 11591Some configurations may include these targets as well:
c906108c
SS
11592
11593@table @code
11594
c906108c 11595@item target nrom @var{dev}
4644b6e3 11596@cindex NetROM ROM emulator target
c906108c
SS
11597NetROM ROM emulator. This target only supports downloading.
11598
c906108c
SS
11599@end table
11600
5d161b24 11601Different targets are available on different configurations of @value{GDBN};
c906108c 11602your configuration may have more or fewer targets.
c906108c 11603
721c2651
EZ
11604Many remote targets require you to download the executable's code once
11605you've successfully established a connection. You may wish to control
11606various aspects of this process, such as the size of the data chunks
11607used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11608
11609@table @code
11610@kindex set download-write-size
11611@item set download-write-size @var{size}
11612Set the write size used when downloading a program. Only used when
11613downloading a program onto a remote target. Specify zero or a
11614negative value to disable blocked writes. The actual size of each
11615transfer is also limited by the size of the target packet and the
11616memory cache.
11617
11618@kindex show download-write-size
11619@item show download-write-size
721c2651 11620@kindex show download-write-size
a8f24a35 11621Show the current value of the write size.
721c2651
EZ
11622
11623@item set hash
11624@kindex set hash@r{, for remote monitors}
11625@cindex hash mark while downloading
11626This command controls whether a hash mark @samp{#} is displayed while
11627downloading a file to the remote monitor. If on, a hash mark is
11628displayed after each S-record is successfully downloaded to the
11629monitor.
11630
11631@item show hash
11632@kindex show hash@r{, for remote monitors}
11633Show the current status of displaying the hash mark.
11634
11635@item set debug monitor
11636@kindex set debug monitor
11637@cindex display remote monitor communications
11638Enable or disable display of communications messages between
11639@value{GDBN} and the remote monitor.
11640
11641@item show debug monitor
11642@kindex show debug monitor
11643Show the current status of displaying communications between
11644@value{GDBN} and the remote monitor.
a8f24a35 11645@end table
c906108c
SS
11646
11647@table @code
11648
11649@kindex load @var{filename}
11650@item load @var{filename}
c906108c
SS
11651Depending on what remote debugging facilities are configured into
11652@value{GDBN}, the @code{load} command may be available. Where it exists, it
11653is meant to make @var{filename} (an executable) available for debugging
11654on the remote system---by downloading, or dynamic linking, for example.
11655@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11656the @code{add-symbol-file} command.
11657
11658If your @value{GDBN} does not have a @code{load} command, attempting to
11659execute it gets the error message ``@code{You can't do that when your
11660target is @dots{}}''
c906108c
SS
11661
11662The file is loaded at whatever address is specified in the executable.
11663For some object file formats, you can specify the load address when you
11664link the program; for other formats, like a.out, the object file format
11665specifies a fixed address.
11666@c FIXME! This would be a good place for an xref to the GNU linker doc.
11667
c906108c
SS
11668@code{load} does not repeat if you press @key{RET} again after using it.
11669@end table
11670
6d2ebf8b 11671@node Byte Order
c906108c 11672@section Choosing target byte order
7a292a7a 11673
c906108c
SS
11674@cindex choosing target byte order
11675@cindex target byte order
c906108c 11676
172c2a43 11677Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11678offer the ability to run either big-endian or little-endian byte
11679orders. Usually the executable or symbol will include a bit to
11680designate the endian-ness, and you will not need to worry about
11681which to use. However, you may still find it useful to adjust
d4f3574e 11682@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11683
11684@table @code
4644b6e3 11685@kindex set endian
c906108c
SS
11686@item set endian big
11687Instruct @value{GDBN} to assume the target is big-endian.
11688
c906108c
SS
11689@item set endian little
11690Instruct @value{GDBN} to assume the target is little-endian.
11691
c906108c
SS
11692@item set endian auto
11693Instruct @value{GDBN} to use the byte order associated with the
11694executable.
11695
11696@item show endian
11697Display @value{GDBN}'s current idea of the target byte order.
11698
11699@end table
11700
11701Note that these commands merely adjust interpretation of symbolic
11702data on the host, and that they have absolutely no effect on the
11703target system.
11704
6d2ebf8b 11705@node Remote
c906108c
SS
11706@section Remote debugging
11707@cindex remote debugging
11708
11709If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11710@value{GDBN} in the usual way, it is often useful to use remote debugging.
11711For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11712or on a small system which does not have a general purpose operating system
11713powerful enough to run a full-featured debugger.
11714
11715Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11716to make this work with particular debugging targets. In addition,
5d161b24 11717@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11718but not specific to any particular target system) which you can use if you
11719write the remote stubs---the code that runs on the remote system to
11720communicate with @value{GDBN}.
11721
11722Other remote targets may be available in your
11723configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11724
c45da7e6
EZ
11725Once you've connected to the remote target, @value{GDBN} allows you to
11726send arbitrary commands to the remote monitor:
11727
11728@table @code
11729@item remote @var{command}
11730@kindex remote@r{, a command}
11731@cindex send command to remote monitor
11732Send an arbitrary @var{command} string to the remote monitor.
11733@end table
11734
11735
6f05cf9f
AC
11736@node KOD
11737@section Kernel Object Display
6f05cf9f 11738@cindex kernel object display
6f05cf9f
AC
11739@cindex KOD
11740
11741Some targets support kernel object display. Using this facility,
11742@value{GDBN} communicates specially with the underlying operating system
11743and can display information about operating system-level objects such as
11744mutexes and other synchronization objects. Exactly which objects can be
11745displayed is determined on a per-OS basis.
11746
3bbe9696 11747@kindex set os
6f05cf9f
AC
11748Use the @code{set os} command to set the operating system. This tells
11749@value{GDBN} which kernel object display module to initialize:
11750
474c8240 11751@smallexample
6f05cf9f 11752(@value{GDBP}) set os cisco
474c8240 11753@end smallexample
6f05cf9f 11754
3bbe9696
EZ
11755@kindex show os
11756The associated command @code{show os} displays the operating system
11757set with the @code{set os} command; if no operating system has been
11758set, @code{show os} will display an empty string @samp{""}.
11759
6f05cf9f
AC
11760If @code{set os} succeeds, @value{GDBN} will display some information
11761about the operating system, and will create a new @code{info} command
11762which can be used to query the target. The @code{info} command is named
11763after the operating system:
c906108c 11764
3bbe9696 11765@kindex info cisco
474c8240 11766@smallexample
6f05cf9f
AC
11767(@value{GDBP}) info cisco
11768List of Cisco Kernel Objects
11769Object Description
11770any Any and all objects
474c8240 11771@end smallexample
6f05cf9f
AC
11772
11773Further subcommands can be used to query about particular objects known
11774by the kernel.
11775
3bbe9696
EZ
11776There is currently no way to determine whether a given operating
11777system is supported other than to try setting it with @kbd{set os
11778@var{name}}, where @var{name} is the name of the operating system you
11779want to try.
6f05cf9f
AC
11780
11781
11782@node Remote Debugging
11783@chapter Debugging remote programs
11784
6b2f586d 11785@menu
07f31aa6 11786* Connecting:: Connecting to a remote target
6b2f586d
AC
11787* Server:: Using the gdbserver program
11788* NetWare:: Using the gdbserve.nlm program
501eef12 11789* Remote configuration:: Remote configuration
6b2f586d 11790* remote stub:: Implementing a remote stub
6b2f586d
AC
11791@end menu
11792
07f31aa6
DJ
11793@node Connecting
11794@section Connecting to a remote target
11795
11796On the @value{GDBN} host machine, you will need an unstripped copy of
11797your program, since @value{GDBN} needs symobl and debugging information.
11798Start up @value{GDBN} as usual, using the name of the local copy of your
11799program as the first argument.
11800
11801@cindex serial line, @code{target remote}
11802If you're using a serial line, you may want to give @value{GDBN} the
11803@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11804(@pxref{Remote configuration, set remotebaud}) before the
11805@code{target} command.
07f31aa6
DJ
11806
11807After that, use @code{target remote} to establish communications with
11808the target machine. Its argument specifies how to communicate---either
11809via a devicename attached to a direct serial line, or a TCP or UDP port
11810(possibly to a terminal server which in turn has a serial line to the
11811target). For example, to use a serial line connected to the device
11812named @file{/dev/ttyb}:
11813
11814@smallexample
11815target remote /dev/ttyb
11816@end smallexample
11817
11818@cindex TCP port, @code{target remote}
11819To use a TCP connection, use an argument of the form
11820@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11821For example, to connect to port 2828 on a
11822terminal server named @code{manyfarms}:
11823
11824@smallexample
11825target remote manyfarms:2828
11826@end smallexample
11827
11828If your remote target is actually running on the same machine as
11829your debugger session (e.g.@: a simulator of your target running on
11830the same host), you can omit the hostname. For example, to connect
11831to port 1234 on your local machine:
11832
11833@smallexample
11834target remote :1234
11835@end smallexample
11836@noindent
11837
11838Note that the colon is still required here.
11839
11840@cindex UDP port, @code{target remote}
11841To use a UDP connection, use an argument of the form
11842@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11843on a terminal server named @code{manyfarms}:
11844
11845@smallexample
11846target remote udp:manyfarms:2828
11847@end smallexample
11848
11849When using a UDP connection for remote debugging, you should keep in mind
11850that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11851busy or unreliable networks, which will cause havoc with your debugging
11852session.
11853
11854Now you can use all the usual commands to examine and change data and to
11855step and continue the remote program.
11856
11857@cindex interrupting remote programs
11858@cindex remote programs, interrupting
11859Whenever @value{GDBN} is waiting for the remote program, if you type the
11860interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11861program. This may or may not succeed, depending in part on the hardware
11862and the serial drivers the remote system uses. If you type the
11863interrupt character once again, @value{GDBN} displays this prompt:
11864
11865@smallexample
11866Interrupted while waiting for the program.
11867Give up (and stop debugging it)? (y or n)
11868@end smallexample
11869
11870If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11871(If you decide you want to try again later, you can use @samp{target
11872remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11873goes back to waiting.
11874
11875@table @code
11876@kindex detach (remote)
11877@item detach
11878When you have finished debugging the remote program, you can use the
11879@code{detach} command to release it from @value{GDBN} control.
11880Detaching from the target normally resumes its execution, but the results
11881will depend on your particular remote stub. After the @code{detach}
11882command, @value{GDBN} is free to connect to another target.
11883
11884@kindex disconnect
11885@item disconnect
11886The @code{disconnect} command behaves like @code{detach}, except that
11887the target is generally not resumed. It will wait for @value{GDBN}
11888(this instance or another one) to connect and continue debugging. After
11889the @code{disconnect} command, @value{GDBN} is again free to connect to
11890another target.
09d4efe1
EZ
11891
11892@cindex send command to remote monitor
11893@kindex monitor
11894@item monitor @var{cmd}
11895This command allows you to send commands directly to the remote
11896monitor.
07f31aa6
DJ
11897@end table
11898
6f05cf9f
AC
11899@node Server
11900@section Using the @code{gdbserver} program
11901
11902@kindex gdbserver
11903@cindex remote connection without stubs
11904@code{gdbserver} is a control program for Unix-like systems, which
11905allows you to connect your program with a remote @value{GDBN} via
11906@code{target remote}---but without linking in the usual debugging stub.
11907
11908@code{gdbserver} is not a complete replacement for the debugging stubs,
11909because it requires essentially the same operating-system facilities
11910that @value{GDBN} itself does. In fact, a system that can run
11911@code{gdbserver} to connect to a remote @value{GDBN} could also run
11912@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11913because it is a much smaller program than @value{GDBN} itself. It is
11914also easier to port than all of @value{GDBN}, so you may be able to get
11915started more quickly on a new system by using @code{gdbserver}.
11916Finally, if you develop code for real-time systems, you may find that
11917the tradeoffs involved in real-time operation make it more convenient to
11918do as much development work as possible on another system, for example
11919by cross-compiling. You can use @code{gdbserver} to make a similar
11920choice for debugging.
11921
11922@value{GDBN} and @code{gdbserver} communicate via either a serial line
11923or a TCP connection, using the standard @value{GDBN} remote serial
11924protocol.
11925
11926@table @emph
11927@item On the target machine,
11928you need to have a copy of the program you want to debug.
11929@code{gdbserver} does not need your program's symbol table, so you can
11930strip the program if necessary to save space. @value{GDBN} on the host
11931system does all the symbol handling.
11932
11933To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11934the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11935syntax is:
11936
11937@smallexample
11938target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11939@end smallexample
11940
11941@var{comm} is either a device name (to use a serial line) or a TCP
11942hostname and portnumber. For example, to debug Emacs with the argument
11943@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11944@file{/dev/com1}:
11945
11946@smallexample
11947target> gdbserver /dev/com1 emacs foo.txt
11948@end smallexample
11949
11950@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11951with it.
11952
11953To use a TCP connection instead of a serial line:
11954
11955@smallexample
11956target> gdbserver host:2345 emacs foo.txt
11957@end smallexample
11958
11959The only difference from the previous example is the first argument,
11960specifying that you are communicating with the host @value{GDBN} via
11961TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11962expect a TCP connection from machine @samp{host} to local TCP port 2345.
11963(Currently, the @samp{host} part is ignored.) You can choose any number
11964you want for the port number as long as it does not conflict with any
11965TCP ports already in use on the target system (for example, @code{23} is
11966reserved for @code{telnet}).@footnote{If you choose a port number that
11967conflicts with another service, @code{gdbserver} prints an error message
11968and exits.} You must use the same port number with the host @value{GDBN}
11969@code{target remote} command.
11970
56460a61
DJ
11971On some targets, @code{gdbserver} can also attach to running programs.
11972This is accomplished via the @code{--attach} argument. The syntax is:
11973
11974@smallexample
11975target> gdbserver @var{comm} --attach @var{pid}
11976@end smallexample
11977
11978@var{pid} is the process ID of a currently running process. It isn't necessary
11979to point @code{gdbserver} at a binary for the running process.
11980
b1fe9455
DJ
11981@pindex pidof
11982@cindex attach to a program by name
11983You can debug processes by name instead of process ID if your target has the
11984@code{pidof} utility:
11985
11986@smallexample
11987target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11988@end smallexample
11989
11990In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11991has multiple threads, most versions of @code{pidof} support the
11992@code{-s} option to only return the first process ID.
11993
07f31aa6
DJ
11994@item On the host machine,
11995connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11996For TCP connections, you must start up @code{gdbserver} prior to using
11997the @code{target remote} command. Otherwise you may get an error whose
11998text depends on the host system, but which usually looks something like
07f31aa6 11999@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
12000command in @value{GDBN} when using @code{gdbserver}, since the program is
12001already on the target. However, if you want to load the symbols (as
12002you normally would), do that with the @code{file} command, and issue
12003it @emph{before} connecting to the server; otherwise, you will get an
12004error message saying @code{"Program is already running"}, since the
12005program is considered running after the connection.
07f31aa6 12006
6f05cf9f
AC
12007@end table
12008
12009@node NetWare
12010@section Using the @code{gdbserve.nlm} program
12011
12012@kindex gdbserve.nlm
12013@code{gdbserve.nlm} is a control program for NetWare systems, which
12014allows you to connect your program with a remote @value{GDBN} via
12015@code{target remote}.
12016
12017@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
12018using the standard @value{GDBN} remote serial protocol.
12019
12020@table @emph
12021@item On the target machine,
12022you need to have a copy of the program you want to debug.
12023@code{gdbserve.nlm} does not need your program's symbol table, so you
12024can strip the program if necessary to save space. @value{GDBN} on the
12025host system does all the symbol handling.
12026
12027To use the server, you must tell it how to communicate with
12028@value{GDBN}; the name of your program; and the arguments for your
12029program. The syntax is:
12030
12031@smallexample
12032load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
12033 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12034@end smallexample
12035
12036@var{board} and @var{port} specify the serial line; @var{baud} specifies
12037the baud rate used by the connection. @var{port} and @var{node} default
12038to 0, @var{baud} defaults to 9600@dmn{bps}.
12039
12040For example, to debug Emacs with the argument @samp{foo.txt}and
12041communicate with @value{GDBN} over serial port number 2 or board 1
12042using a 19200@dmn{bps} connection:
12043
12044@smallexample
12045load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12046@end smallexample
12047
07f31aa6
DJ
12048@item
12049On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12050Connecting to a remote target}).
6f05cf9f 12051
6f05cf9f
AC
12052@end table
12053
501eef12
AC
12054@node Remote configuration
12055@section Remote configuration
12056
9c16f35a
EZ
12057@kindex set remote
12058@kindex show remote
12059This section documents the configuration options available when
12060debugging remote programs. For the options related to the File I/O
12061extensions of the remote protocol, see @ref{The system call,
12062system-call-allowed}.
501eef12
AC
12063
12064@table @code
9c16f35a
EZ
12065@item set remoteaddresssize @var{bits}
12066@cindex adress size for remote targets
12067@cindex bits in remote address
12068Set the maximum size of address in a memory packet to the specified
12069number of bits. @value{GDBN} will mask off the address bits above
12070that number, when it passes addresses to the remote target. The
12071default value is the number of bits in the target's address.
12072
12073@item show remoteaddresssize
12074Show the current value of remote address size in bits.
12075
12076@item set remotebaud @var{n}
12077@cindex baud rate for remote targets
12078Set the baud rate for the remote serial I/O to @var{n} baud. The
12079value is used to set the speed of the serial port used for debugging
12080remote targets.
12081
12082@item show remotebaud
12083Show the current speed of the remote connection.
12084
12085@item set remotebreak
12086@cindex interrupt remote programs
12087@cindex BREAK signal instead of Ctrl-C
12088If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12089when you press the @key{Ctrl-C} key to interrupt the program running
12090on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12091character instead. The default is off, since most remote systems
12092expect to see @samp{Ctrl-C} as the interrupt signal.
12093
12094@item show remotebreak
12095Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12096interrupt the remote program.
12097
12098@item set remotedebug
12099@cindex debug remote protocol
12100@cindex remote protocol debugging
12101@cindex display remote packets
12102Control the debugging of the remote protocol. When enabled, each
12103packet sent to or received from the remote target is displayed. The
12104defaults is off.
12105
12106@item show remotedebug
12107Show the current setting of the remote protocol debugging.
12108
12109@item set remotedevice @var{device}
12110@cindex serial port name
12111Set the name of the serial port through which to communicate to the
12112remote target to @var{device}. This is the device used by
12113@value{GDBN} to open the serial communications line to the remote
12114target. There's no default, so you must set a valid port name for the
12115remote serial communications to work. (Some varieties of the
12116@code{target} command accept the port name as part of their
12117arguments.)
12118
12119@item show remotedevice
12120Show the current name of the serial port.
12121
12122@item set remotelogbase @var{base}
12123Set the base (a.k.a.@: radix) of logging serial protocol
12124communications to @var{base}. Supported values of @var{base} are:
12125@code{ascii}, @code{octal}, and @code{hex}. The default is
12126@code{ascii}.
12127
12128@item show remotelogbase
12129Show the current setting of the radix for logging remote serial
12130protocol.
12131
12132@item set remotelogfile @var{file}
12133@cindex record serial communications on file
12134Record remote serial communications on the named @var{file}. The
12135default is not to record at all.
12136
12137@item show remotelogfile.
12138Show the current setting of the file name on which to record the
12139serial communications.
12140
12141@item set remotetimeout @var{num}
12142@cindex timeout for serial communications
12143@cindex remote timeout
12144Set the timeout limit to wait for the remote target to respond to
12145@var{num} seconds. The default is 2 seconds.
12146
12147@item show remotetimeout
12148Show the current number of seconds to wait for the remote target
12149responses.
12150
12151@cindex limit hardware breakpoints and watchpoints
12152@cindex remote target, limit break- and watchpoints
501eef12
AC
12153@anchor{set remote hardware-watchpoint-limit}
12154@anchor{set remote hardware-breakpoint-limit}
12155@item set remote hardware-watchpoint-limit @var{limit}
12156@itemx set remote hardware-breakpoint-limit @var{limit}
12157Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12158watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12159
12160@item set remote fetch-register-packet
12161@itemx set remote set-register-packet
12162@itemx set remote P-packet
12163@itemx set remote p-packet
12164@cindex P-packet
12165@cindex fetch registers from remote targets
12166@cindex set registers in remote targets
12167Determine whether @value{GDBN} can set and fetch registers from the
12168remote target using the @samp{P} packets. The default depends on the
12169remote stub's support of the @samp{P} packets (@value{GDBN} queries
12170the stub when this packet is first required).
12171
12172@item show remote fetch-register-packet
12173@itemx show remote set-register-packet
12174@itemx show remote P-packet
12175@itemx show remote p-packet
12176Show the current setting of using the @samp{P} packets for setting and
12177fetching registers from the remote target.
12178
12179@cindex binary downloads
12180@cindex X-packet
12181@item set remote binary-download-packet
12182@itemx set remote X-packet
12183Determine whether @value{GDBN} sends downloads in binary mode using
12184the @samp{X} packets. The default is on.
12185
12186@item show remote binary-download-packet
12187@itemx show remote X-packet
12188Show the current setting of using the @samp{X} packets for binary
12189downloads.
12190
12191@item set remote read-aux-vector-packet
12192@cindex auxiliary vector of remote target
12193@cindex @code{auxv}, and remote targets
12194Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12195auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12196remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12197Auxiliary Vector}. The default setting depends on the remote stub's
12198support of this request (@value{GDBN} queries the stub when this
12199request is first required). @xref{General Query Packets, qPart}, for
12200more information about this request.
9c16f35a
EZ
12201
12202@item show remote read-aux-vector-packet
12203Show the current setting of use of the @samp{qPart:auxv:read} request.
12204
12205@item set remote symbol-lookup-packet
12206@cindex remote symbol lookup request
12207Set the use of the remote protocol's @samp{qSymbol} (target symbol
12208lookup) request. This request is used to communicate symbol
12209information to the remote target, e.g., whenever a new shared library
12210is loaded by the remote (@pxref{Files, shared libraries}). The
12211default setting depends on the remote stub's support of this request
12212(@value{GDBN} queries the stub when this request is first required).
12213@xref{General Query Packets, qSymbol}, for more information about this
12214request.
12215
12216@item show remote symbol-lookup-packet
12217Show the current setting of use of the @samp{qSymbol} request.
12218
12219@item set remote verbose-resume-packet
12220@cindex resume remote target
12221@cindex signal thread, and remote targets
12222@cindex single-step thread, and remote targets
12223@cindex thread-specific operations on remote targets
12224Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12225request. This request is used to resume specific threads in the
12226remote target, and to single-step or signal them. The default setting
12227depends on the remote stub's support of this request (@value{GDBN}
12228queries the stub when this request is first required). This setting
12229affects debugging of multithreaded programs: if @samp{vCont} cannot be
12230used, @value{GDBN} might be unable to single-step a specific thread,
12231especially under @code{set scheduler-locking off}; it is also
12232impossible to pause a specific thread. @xref{Packets, vCont}, for
12233more details.
12234
12235@item show remote verbose-resume-packet
12236Show the current setting of use of the @samp{vCont} request
12237
12238@item set remote software-breakpoint-packet
12239@itemx set remote hardware-breakpoint-packet
12240@itemx set remote write-watchpoint-packet
12241@itemx set remote read-watchpoint-packet
12242@itemx set remote access-watchpoint-packet
12243@itemx set remote Z-packet
12244@cindex Z-packet
12245@cindex remote hardware breakpoints and watchpoints
12246These commands enable or disable the use of @samp{Z} packets for
12247setting breakpoints and watchpoints in the remote target. The default
12248depends on the remote stub's support of the @samp{Z} packets
12249(@value{GDBN} queries the stub when each packet is first required).
12250The command @code{set remote Z-packet}, kept for back-compatibility,
12251turns on or off all the features that require the use of @samp{Z}
12252packets.
12253
12254@item show remote software-breakpoint-packet
12255@itemx show remote hardware-breakpoint-packet
12256@itemx show remote write-watchpoint-packet
12257@itemx show remote read-watchpoint-packet
12258@itemx show remote access-watchpoint-packet
12259@itemx show remote Z-packet
12260Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12261
12262@item set remote get-thread-local-storage-address
12263@kindex set remote get-thread-local-storage-address
12264@cindex thread local storage of remote targets
12265This command enables or disables the use of the @samp{qGetTLSAddr}
12266(Get Thread Local Storage Address) request packet. The default
12267depends on whether the remote stub supports this request.
12268@xref{General Query Packets, qGetTLSAddr}, for more details about this
12269packet.
12270
12271@item show remote get-thread-local-storage-address
12272@kindex show remote get-thread-local-storage-address
12273Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12274@end table
12275
6f05cf9f
AC
12276@node remote stub
12277@section Implementing a remote stub
7a292a7a 12278
8e04817f
AC
12279@cindex debugging stub, example
12280@cindex remote stub, example
12281@cindex stub example, remote debugging
12282The stub files provided with @value{GDBN} implement the target side of the
12283communication protocol, and the @value{GDBN} side is implemented in the
12284@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12285these subroutines to communicate, and ignore the details. (If you're
12286implementing your own stub file, you can still ignore the details: start
12287with one of the existing stub files. @file{sparc-stub.c} is the best
12288organized, and therefore the easiest to read.)
12289
104c1213
JM
12290@cindex remote serial debugging, overview
12291To debug a program running on another machine (the debugging
12292@dfn{target} machine), you must first arrange for all the usual
12293prerequisites for the program to run by itself. For example, for a C
12294program, you need:
c906108c 12295
104c1213
JM
12296@enumerate
12297@item
12298A startup routine to set up the C runtime environment; these usually
12299have a name like @file{crt0}. The startup routine may be supplied by
12300your hardware supplier, or you may have to write your own.
96baa820 12301
5d161b24 12302@item
d4f3574e 12303A C subroutine library to support your program's
104c1213 12304subroutine calls, notably managing input and output.
96baa820 12305
104c1213
JM
12306@item
12307A way of getting your program to the other machine---for example, a
12308download program. These are often supplied by the hardware
12309manufacturer, but you may have to write your own from hardware
12310documentation.
12311@end enumerate
96baa820 12312
104c1213
JM
12313The next step is to arrange for your program to use a serial port to
12314communicate with the machine where @value{GDBN} is running (the @dfn{host}
12315machine). In general terms, the scheme looks like this:
96baa820 12316
104c1213
JM
12317@table @emph
12318@item On the host,
12319@value{GDBN} already understands how to use this protocol; when everything
12320else is set up, you can simply use the @samp{target remote} command
12321(@pxref{Targets,,Specifying a Debugging Target}).
12322
12323@item On the target,
12324you must link with your program a few special-purpose subroutines that
12325implement the @value{GDBN} remote serial protocol. The file containing these
12326subroutines is called a @dfn{debugging stub}.
12327
12328On certain remote targets, you can use an auxiliary program
12329@code{gdbserver} instead of linking a stub into your program.
12330@xref{Server,,Using the @code{gdbserver} program}, for details.
12331@end table
96baa820 12332
104c1213
JM
12333The debugging stub is specific to the architecture of the remote
12334machine; for example, use @file{sparc-stub.c} to debug programs on
12335@sc{sparc} boards.
96baa820 12336
104c1213
JM
12337@cindex remote serial stub list
12338These working remote stubs are distributed with @value{GDBN}:
96baa820 12339
104c1213
JM
12340@table @code
12341
12342@item i386-stub.c
41afff9a 12343@cindex @file{i386-stub.c}
104c1213
JM
12344@cindex Intel
12345@cindex i386
12346For Intel 386 and compatible architectures.
12347
12348@item m68k-stub.c
41afff9a 12349@cindex @file{m68k-stub.c}
104c1213
JM
12350@cindex Motorola 680x0
12351@cindex m680x0
12352For Motorola 680x0 architectures.
12353
12354@item sh-stub.c
41afff9a 12355@cindex @file{sh-stub.c}
172c2a43 12356@cindex Renesas
104c1213 12357@cindex SH
172c2a43 12358For Renesas SH architectures.
104c1213
JM
12359
12360@item sparc-stub.c
41afff9a 12361@cindex @file{sparc-stub.c}
104c1213
JM
12362@cindex Sparc
12363For @sc{sparc} architectures.
12364
12365@item sparcl-stub.c
41afff9a 12366@cindex @file{sparcl-stub.c}
104c1213
JM
12367@cindex Fujitsu
12368@cindex SparcLite
12369For Fujitsu @sc{sparclite} architectures.
12370
12371@end table
12372
12373The @file{README} file in the @value{GDBN} distribution may list other
12374recently added stubs.
12375
12376@menu
12377* Stub Contents:: What the stub can do for you
12378* Bootstrapping:: What you must do for the stub
12379* Debug Session:: Putting it all together
104c1213
JM
12380@end menu
12381
6d2ebf8b 12382@node Stub Contents
6f05cf9f 12383@subsection What the stub can do for you
104c1213
JM
12384
12385@cindex remote serial stub
12386The debugging stub for your architecture supplies these three
12387subroutines:
12388
12389@table @code
12390@item set_debug_traps
4644b6e3 12391@findex set_debug_traps
104c1213
JM
12392@cindex remote serial stub, initialization
12393This routine arranges for @code{handle_exception} to run when your
12394program stops. You must call this subroutine explicitly near the
12395beginning of your program.
12396
12397@item handle_exception
4644b6e3 12398@findex handle_exception
104c1213
JM
12399@cindex remote serial stub, main routine
12400This is the central workhorse, but your program never calls it
12401explicitly---the setup code arranges for @code{handle_exception} to
12402run when a trap is triggered.
12403
12404@code{handle_exception} takes control when your program stops during
12405execution (for example, on a breakpoint), and mediates communications
12406with @value{GDBN} on the host machine. This is where the communications
12407protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12408representative on the target machine. It begins by sending summary
104c1213
JM
12409information on the state of your program, then continues to execute,
12410retrieving and transmitting any information @value{GDBN} needs, until you
12411execute a @value{GDBN} command that makes your program resume; at that point,
12412@code{handle_exception} returns control to your own code on the target
5d161b24 12413machine.
104c1213
JM
12414
12415@item breakpoint
12416@cindex @code{breakpoint} subroutine, remote
12417Use this auxiliary subroutine to make your program contain a
12418breakpoint. Depending on the particular situation, this may be the only
12419way for @value{GDBN} to get control. For instance, if your target
12420machine has some sort of interrupt button, you won't need to call this;
12421pressing the interrupt button transfers control to
12422@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12423simply receiving characters on the serial port may also trigger a trap;
12424again, in that situation, you don't need to call @code{breakpoint} from
12425your own program---simply running @samp{target remote} from the host
5d161b24 12426@value{GDBN} session gets control.
104c1213
JM
12427
12428Call @code{breakpoint} if none of these is true, or if you simply want
12429to make certain your program stops at a predetermined point for the
12430start of your debugging session.
12431@end table
12432
6d2ebf8b 12433@node Bootstrapping
6f05cf9f 12434@subsection What you must do for the stub
104c1213
JM
12435
12436@cindex remote stub, support routines
12437The debugging stubs that come with @value{GDBN} are set up for a particular
12438chip architecture, but they have no information about the rest of your
12439debugging target machine.
12440
12441First of all you need to tell the stub how to communicate with the
12442serial port.
12443
12444@table @code
12445@item int getDebugChar()
4644b6e3 12446@findex getDebugChar
104c1213
JM
12447Write this subroutine to read a single character from the serial port.
12448It may be identical to @code{getchar} for your target system; a
12449different name is used to allow you to distinguish the two if you wish.
12450
12451@item void putDebugChar(int)
4644b6e3 12452@findex putDebugChar
104c1213 12453Write this subroutine to write a single character to the serial port.
5d161b24 12454It may be identical to @code{putchar} for your target system; a
104c1213
JM
12455different name is used to allow you to distinguish the two if you wish.
12456@end table
12457
12458@cindex control C, and remote debugging
12459@cindex interrupting remote targets
12460If you want @value{GDBN} to be able to stop your program while it is
12461running, you need to use an interrupt-driven serial driver, and arrange
12462for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12463character). That is the character which @value{GDBN} uses to tell the
12464remote system to stop.
12465
12466Getting the debugging target to return the proper status to @value{GDBN}
12467probably requires changes to the standard stub; one quick and dirty way
12468is to just execute a breakpoint instruction (the ``dirty'' part is that
12469@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12470
12471Other routines you need to supply are:
12472
12473@table @code
12474@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12475@findex exceptionHandler
104c1213
JM
12476Write this function to install @var{exception_address} in the exception
12477handling tables. You need to do this because the stub does not have any
12478way of knowing what the exception handling tables on your target system
12479are like (for example, the processor's table might be in @sc{rom},
12480containing entries which point to a table in @sc{ram}).
12481@var{exception_number} is the exception number which should be changed;
12482its meaning is architecture-dependent (for example, different numbers
12483might represent divide by zero, misaligned access, etc). When this
12484exception occurs, control should be transferred directly to
12485@var{exception_address}, and the processor state (stack, registers,
12486and so on) should be just as it is when a processor exception occurs. So if
12487you want to use a jump instruction to reach @var{exception_address}, it
12488should be a simple jump, not a jump to subroutine.
12489
12490For the 386, @var{exception_address} should be installed as an interrupt
12491gate so that interrupts are masked while the handler runs. The gate
12492should be at privilege level 0 (the most privileged level). The
12493@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12494help from @code{exceptionHandler}.
12495
12496@item void flush_i_cache()
4644b6e3 12497@findex flush_i_cache
d4f3574e 12498On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12499instruction cache, if any, on your target machine. If there is no
12500instruction cache, this subroutine may be a no-op.
12501
12502On target machines that have instruction caches, @value{GDBN} requires this
12503function to make certain that the state of your program is stable.
12504@end table
12505
12506@noindent
12507You must also make sure this library routine is available:
12508
12509@table @code
12510@item void *memset(void *, int, int)
4644b6e3 12511@findex memset
104c1213
JM
12512This is the standard library function @code{memset} that sets an area of
12513memory to a known value. If you have one of the free versions of
12514@code{libc.a}, @code{memset} can be found there; otherwise, you must
12515either obtain it from your hardware manufacturer, or write your own.
12516@end table
12517
12518If you do not use the GNU C compiler, you may need other standard
12519library subroutines as well; this varies from one stub to another,
12520but in general the stubs are likely to use any of the common library
d4f3574e 12521subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12522
12523
6d2ebf8b 12524@node Debug Session
6f05cf9f 12525@subsection Putting it all together
104c1213
JM
12526
12527@cindex remote serial debugging summary
12528In summary, when your program is ready to debug, you must follow these
12529steps.
12530
12531@enumerate
12532@item
6d2ebf8b 12533Make sure you have defined the supporting low-level routines
104c1213
JM
12534(@pxref{Bootstrapping,,What you must do for the stub}):
12535@display
12536@code{getDebugChar}, @code{putDebugChar},
12537@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12538@end display
12539
12540@item
12541Insert these lines near the top of your program:
12542
474c8240 12543@smallexample
104c1213
JM
12544set_debug_traps();
12545breakpoint();
474c8240 12546@end smallexample
104c1213
JM
12547
12548@item
12549For the 680x0 stub only, you need to provide a variable called
12550@code{exceptionHook}. Normally you just use:
12551
474c8240 12552@smallexample
104c1213 12553void (*exceptionHook)() = 0;
474c8240 12554@end smallexample
104c1213 12555
d4f3574e 12556@noindent
104c1213 12557but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12558function in your program, that function is called when
104c1213
JM
12559@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12560error). The function indicated by @code{exceptionHook} is called with
12561one parameter: an @code{int} which is the exception number.
12562
12563@item
12564Compile and link together: your program, the @value{GDBN} debugging stub for
12565your target architecture, and the supporting subroutines.
12566
12567@item
12568Make sure you have a serial connection between your target machine and
12569the @value{GDBN} host, and identify the serial port on the host.
12570
12571@item
12572@c The "remote" target now provides a `load' command, so we should
12573@c document that. FIXME.
12574Download your program to your target machine (or get it there by
12575whatever means the manufacturer provides), and start it.
12576
12577@item
07f31aa6
DJ
12578Start @value{GDBN} on the host, and connect to the target
12579(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12580
104c1213
JM
12581@end enumerate
12582
8e04817f
AC
12583@node Configurations
12584@chapter Configuration-Specific Information
104c1213 12585
8e04817f
AC
12586While nearly all @value{GDBN} commands are available for all native and
12587cross versions of the debugger, there are some exceptions. This chapter
12588describes things that are only available in certain configurations.
104c1213 12589
8e04817f
AC
12590There are three major categories of configurations: native
12591configurations, where the host and target are the same, embedded
12592operating system configurations, which are usually the same for several
12593different processor architectures, and bare embedded processors, which
12594are quite different from each other.
104c1213 12595
8e04817f
AC
12596@menu
12597* Native::
12598* Embedded OS::
12599* Embedded Processors::
12600* Architectures::
12601@end menu
104c1213 12602
8e04817f
AC
12603@node Native
12604@section Native
104c1213 12605
8e04817f
AC
12606This section describes details specific to particular native
12607configurations.
6cf7e474 12608
8e04817f
AC
12609@menu
12610* HP-UX:: HP-UX
7561d450 12611* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12612* SVR4 Process Information:: SVR4 process information
12613* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12614* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12615* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12616* Neutrino:: Features specific to QNX Neutrino
8e04817f 12617@end menu
6cf7e474 12618
8e04817f
AC
12619@node HP-UX
12620@subsection HP-UX
104c1213 12621
8e04817f
AC
12622On HP-UX systems, if you refer to a function or variable name that
12623begins with a dollar sign, @value{GDBN} searches for a user or system
12624name first, before it searches for a convenience variable.
104c1213 12625
9c16f35a 12626
7561d450
MK
12627@node BSD libkvm Interface
12628@subsection BSD libkvm Interface
12629
12630@cindex libkvm
12631@cindex kernel memory image
12632@cindex kernel crash dump
12633
12634BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12635interface that provides a uniform interface for accessing kernel virtual
12636memory images, including live systems and crash dumps. @value{GDBN}
12637uses this interface to allow you to debug live kernels and kernel crash
12638dumps on many native BSD configurations. This is implemented as a
12639special @code{kvm} debugging target. For debugging a live system, load
12640the currently running kernel into @value{GDBN} and connect to the
12641@code{kvm} target:
12642
12643@smallexample
12644(@value{GDBP}) @b{target kvm}
12645@end smallexample
12646
12647For debugging crash dumps, provide the file name of the crash dump as an
12648argument:
12649
12650@smallexample
12651(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12652@end smallexample
12653
12654Once connected to the @code{kvm} target, the following commands are
12655available:
12656
12657@table @code
12658@kindex kvm
12659@item kvm pcb
721c2651 12660Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12661
12662@item kvm proc
12663Set current context from proc address. This command isn't available on
12664modern FreeBSD systems.
12665@end table
12666
8e04817f
AC
12667@node SVR4 Process Information
12668@subsection SVR4 process information
60bf7e09
EZ
12669@cindex /proc
12670@cindex examine process image
12671@cindex process info via @file{/proc}
104c1213 12672
60bf7e09
EZ
12673Many versions of SVR4 and compatible systems provide a facility called
12674@samp{/proc} that can be used to examine the image of a running
12675process using file-system subroutines. If @value{GDBN} is configured
12676for an operating system with this facility, the command @code{info
12677proc} is available to report information about the process running
12678your program, or about any process running on your system. @code{info
12679proc} works only on SVR4 systems that include the @code{procfs} code.
12680This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12681Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12682
8e04817f
AC
12683@table @code
12684@kindex info proc
60bf7e09 12685@cindex process ID
8e04817f 12686@item info proc
60bf7e09
EZ
12687@itemx info proc @var{process-id}
12688Summarize available information about any running process. If a
12689process ID is specified by @var{process-id}, display information about
12690that process; otherwise display information about the program being
12691debugged. The summary includes the debugged process ID, the command
12692line used to invoke it, its current working directory, and its
12693executable file's absolute file name.
12694
12695On some systems, @var{process-id} can be of the form
12696@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12697within a process. If the optional @var{pid} part is missing, it means
12698a thread from the process being debugged (the leading @samp{/} still
12699needs to be present, or else @value{GDBN} will interpret the number as
12700a process ID rather than a thread ID).
6cf7e474 12701
8e04817f 12702@item info proc mappings
60bf7e09
EZ
12703@cindex memory address space mappings
12704Report the memory address space ranges accessible in the program, with
12705information on whether the process has read, write, or execute access
12706rights to each range. On @sc{gnu}/Linux systems, each memory range
12707includes the object file which is mapped to that range, instead of the
12708memory access rights to that range.
12709
12710@item info proc stat
12711@itemx info proc status
12712@cindex process detailed status information
12713These subcommands are specific to @sc{gnu}/Linux systems. They show
12714the process-related information, including the user ID and group ID;
12715how many threads are there in the process; its virtual memory usage;
12716the signals that are pending, blocked, and ignored; its TTY; its
12717consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12718value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12719(type @kbd{man 5 proc} from your shell prompt).
12720
12721@item info proc all
12722Show all the information about the process described under all of the
12723above @code{info proc} subcommands.
12724
8e04817f
AC
12725@ignore
12726@comment These sub-options of 'info proc' were not included when
12727@comment procfs.c was re-written. Keep their descriptions around
12728@comment against the day when someone finds the time to put them back in.
12729@kindex info proc times
12730@item info proc times
12731Starting time, user CPU time, and system CPU time for your program and
12732its children.
6cf7e474 12733
8e04817f
AC
12734@kindex info proc id
12735@item info proc id
12736Report on the process IDs related to your program: its own process ID,
12737the ID of its parent, the process group ID, and the session ID.
8e04817f 12738@end ignore
721c2651
EZ
12739
12740@item set procfs-trace
12741@kindex set procfs-trace
12742@cindex @code{procfs} API calls
12743This command enables and disables tracing of @code{procfs} API calls.
12744
12745@item show procfs-trace
12746@kindex show procfs-trace
12747Show the current state of @code{procfs} API call tracing.
12748
12749@item set procfs-file @var{file}
12750@kindex set procfs-file
12751Tell @value{GDBN} to write @code{procfs} API trace to the named
12752@var{file}. @value{GDBN} appends the trace info to the previous
12753contents of the file. The default is to display the trace on the
12754standard output.
12755
12756@item show procfs-file
12757@kindex show procfs-file
12758Show the file to which @code{procfs} API trace is written.
12759
12760@item proc-trace-entry
12761@itemx proc-trace-exit
12762@itemx proc-untrace-entry
12763@itemx proc-untrace-exit
12764@kindex proc-trace-entry
12765@kindex proc-trace-exit
12766@kindex proc-untrace-entry
12767@kindex proc-untrace-exit
12768These commands enable and disable tracing of entries into and exits
12769from the @code{syscall} interface.
12770
12771@item info pidlist
12772@kindex info pidlist
12773@cindex process list, QNX Neutrino
12774For QNX Neutrino only, this command displays the list of all the
12775processes and all the threads within each process.
12776
12777@item info meminfo
12778@kindex info meminfo
12779@cindex mapinfo list, QNX Neutrino
12780For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12781@end table
104c1213 12782
8e04817f
AC
12783@node DJGPP Native
12784@subsection Features for Debugging @sc{djgpp} Programs
12785@cindex @sc{djgpp} debugging
12786@cindex native @sc{djgpp} debugging
12787@cindex MS-DOS-specific commands
104c1213 12788
514c4d71
EZ
12789@cindex DPMI
12790@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12791MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12792that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12793top of real-mode DOS systems and their emulations.
104c1213 12794
8e04817f
AC
12795@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12796defines a few commands specific to the @sc{djgpp} port. This
12797subsection describes those commands.
104c1213 12798
8e04817f
AC
12799@table @code
12800@kindex info dos
12801@item info dos
12802This is a prefix of @sc{djgpp}-specific commands which print
12803information about the target system and important OS structures.
f1251bdd 12804
8e04817f
AC
12805@kindex sysinfo
12806@cindex MS-DOS system info
12807@cindex free memory information (MS-DOS)
12808@item info dos sysinfo
12809This command displays assorted information about the underlying
12810platform: the CPU type and features, the OS version and flavor, the
12811DPMI version, and the available conventional and DPMI memory.
104c1213 12812
8e04817f
AC
12813@cindex GDT
12814@cindex LDT
12815@cindex IDT
12816@cindex segment descriptor tables
12817@cindex descriptor tables display
12818@item info dos gdt
12819@itemx info dos ldt
12820@itemx info dos idt
12821These 3 commands display entries from, respectively, Global, Local,
12822and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12823tables are data structures which store a descriptor for each segment
12824that is currently in use. The segment's selector is an index into a
12825descriptor table; the table entry for that index holds the
12826descriptor's base address and limit, and its attributes and access
12827rights.
104c1213 12828
8e04817f
AC
12829A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12830segment (used for both data and the stack), and a DOS segment (which
12831allows access to DOS/BIOS data structures and absolute addresses in
12832conventional memory). However, the DPMI host will usually define
12833additional segments in order to support the DPMI environment.
d4f3574e 12834
8e04817f
AC
12835@cindex garbled pointers
12836These commands allow to display entries from the descriptor tables.
12837Without an argument, all entries from the specified table are
12838displayed. An argument, which should be an integer expression, means
12839display a single entry whose index is given by the argument. For
12840example, here's a convenient way to display information about the
12841debugged program's data segment:
104c1213 12842
8e04817f
AC
12843@smallexample
12844@exdent @code{(@value{GDBP}) info dos ldt $ds}
12845@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12846@end smallexample
104c1213 12847
8e04817f
AC
12848@noindent
12849This comes in handy when you want to see whether a pointer is outside
12850the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12851
8e04817f
AC
12852@cindex page tables display (MS-DOS)
12853@item info dos pde
12854@itemx info dos pte
12855These two commands display entries from, respectively, the Page
12856Directory and the Page Tables. Page Directories and Page Tables are
12857data structures which control how virtual memory addresses are mapped
12858into physical addresses. A Page Table includes an entry for every
12859page of memory that is mapped into the program's address space; there
12860may be several Page Tables, each one holding up to 4096 entries. A
12861Page Directory has up to 4096 entries, one each for every Page Table
12862that is currently in use.
104c1213 12863
8e04817f
AC
12864Without an argument, @kbd{info dos pde} displays the entire Page
12865Directory, and @kbd{info dos pte} displays all the entries in all of
12866the Page Tables. An argument, an integer expression, given to the
12867@kbd{info dos pde} command means display only that entry from the Page
12868Directory table. An argument given to the @kbd{info dos pte} command
12869means display entries from a single Page Table, the one pointed to by
12870the specified entry in the Page Directory.
104c1213 12871
8e04817f
AC
12872@cindex direct memory access (DMA) on MS-DOS
12873These commands are useful when your program uses @dfn{DMA} (Direct
12874Memory Access), which needs physical addresses to program the DMA
12875controller.
104c1213 12876
8e04817f 12877These commands are supported only with some DPMI servers.
104c1213 12878
8e04817f
AC
12879@cindex physical address from linear address
12880@item info dos address-pte @var{addr}
12881This command displays the Page Table entry for a specified linear
514c4d71
EZ
12882address. The argument @var{addr} is a linear address which should
12883already have the appropriate segment's base address added to it,
12884because this command accepts addresses which may belong to @emph{any}
12885segment. For example, here's how to display the Page Table entry for
12886the page where a variable @code{i} is stored:
104c1213 12887
b383017d 12888@smallexample
8e04817f
AC
12889@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12890@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12891@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12892@end smallexample
104c1213 12893
8e04817f
AC
12894@noindent
12895This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12896whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12897attributes of that page.
104c1213 12898
8e04817f
AC
12899Note that you must cast the addresses of variables to a @code{char *},
12900since otherwise the value of @code{__djgpp_base_address}, the base
12901address of all variables and functions in a @sc{djgpp} program, will
12902be added using the rules of C pointer arithmetics: if @code{i} is
12903declared an @code{int}, @value{GDBN} will add 4 times the value of
12904@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12905
8e04817f
AC
12906Here's another example, it displays the Page Table entry for the
12907transfer buffer:
104c1213 12908
8e04817f
AC
12909@smallexample
12910@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12911@exdent @code{Page Table entry for address 0x29110:}
12912@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12913@end smallexample
104c1213 12914
8e04817f
AC
12915@noindent
12916(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
129173rd member of the @code{_go32_info_block} structure.) The output
12918clearly shows that this DPMI server maps the addresses in conventional
12919memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12920linear (@code{0x29110}) addresses are identical.
104c1213 12921
8e04817f
AC
12922This command is supported only with some DPMI servers.
12923@end table
104c1213 12924
c45da7e6 12925@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12926In addition to native debugging, the DJGPP port supports remote
12927debugging via a serial data link. The following commands are specific
12928to remote serial debugging in the DJGPP port of @value{GDBN}.
12929
12930@table @code
12931@kindex set com1base
12932@kindex set com1irq
12933@kindex set com2base
12934@kindex set com2irq
12935@kindex set com3base
12936@kindex set com3irq
12937@kindex set com4base
12938@kindex set com4irq
12939@item set com1base @var{addr}
12940This command sets the base I/O port address of the @file{COM1} serial
12941port.
12942
12943@item set com1irq @var{irq}
12944This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12945for the @file{COM1} serial port.
12946
12947There are similar commands @samp{set com2base}, @samp{set com3irq},
12948etc.@: for setting the port address and the @code{IRQ} lines for the
12949other 3 COM ports.
12950
12951@kindex show com1base
12952@kindex show com1irq
12953@kindex show com2base
12954@kindex show com2irq
12955@kindex show com3base
12956@kindex show com3irq
12957@kindex show com4base
12958@kindex show com4irq
12959The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12960display the current settings of the base address and the @code{IRQ}
12961lines used by the COM ports.
c45da7e6
EZ
12962
12963@item info serial
12964@kindex info serial
12965@cindex DOS serial port status
12966This command prints the status of the 4 DOS serial ports. For each
12967port, it prints whether it's active or not, its I/O base address and
12968IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12969counts of various errors encountered so far.
a8f24a35
EZ
12970@end table
12971
12972
78c47bea
PM
12973@node Cygwin Native
12974@subsection Features for Debugging MS Windows PE executables
12975@cindex MS Windows debugging
12976@cindex native Cygwin debugging
12977@cindex Cygwin-specific commands
12978
be448670
CF
12979@value{GDBN} supports native debugging of MS Windows programs, including
12980DLLs with and without symbolic debugging information. There are various
12981additional Cygwin-specific commands, described in this subsection. The
12982subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12983that have no debugging symbols.
12984
78c47bea
PM
12985
12986@table @code
12987@kindex info w32
12988@item info w32
12989This is a prefix of MS Windows specific commands which print
12990information about the target system and important OS structures.
12991
12992@item info w32 selector
12993This command displays information returned by
12994the Win32 API @code{GetThreadSelectorEntry} function.
12995It takes an optional argument that is evaluated to
12996a long value to give the information about this given selector.
12997Without argument, this command displays information
12998about the the six segment registers.
12999
13000@kindex info dll
13001@item info dll
13002This is a Cygwin specific alias of info shared.
13003
13004@kindex dll-symbols
13005@item dll-symbols
13006This command loads symbols from a dll similarly to
13007add-sym command but without the need to specify a base address.
13008
b383017d 13009@kindex set new-console
78c47bea 13010@item set new-console @var{mode}
b383017d 13011If @var{mode} is @code{on} the debuggee will
78c47bea
PM
13012be started in a new console on next start.
13013If @var{mode} is @code{off}i, the debuggee will
13014be started in the same console as the debugger.
13015
13016@kindex show new-console
13017@item show new-console
13018Displays whether a new console is used
13019when the debuggee is started.
13020
13021@kindex set new-group
13022@item set new-group @var{mode}
13023This boolean value controls whether the debuggee should
13024start a new group or stay in the same group as the debugger.
13025This affects the way the Windows OS handles
13026Ctrl-C.
13027
13028@kindex show new-group
13029@item show new-group
13030Displays current value of new-group boolean.
13031
13032@kindex set debugevents
13033@item set debugevents
13034This boolean value adds debug output concerning events seen by the debugger.
13035
13036@kindex set debugexec
13037@item set debugexec
b383017d 13038This boolean value adds debug output concerning execute events
78c47bea
PM
13039seen by the debugger.
13040
13041@kindex set debugexceptions
13042@item set debugexceptions
b383017d 13043This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13044seen by the debugger.
13045
13046@kindex set debugmemory
13047@item set debugmemory
b383017d 13048This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13049seen by the debugger.
13050
13051@kindex set shell
13052@item set shell
13053This boolean values specifies whether the debuggee is called
13054via a shell or directly (default value is on).
13055
13056@kindex show shell
13057@item show shell
13058Displays if the debuggee will be started with a shell.
13059
13060@end table
13061
be448670
CF
13062@menu
13063* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13064@end menu
13065
13066@node Non-debug DLL symbols
13067@subsubsection Support for DLLs without debugging symbols
13068@cindex DLLs with no debugging symbols
13069@cindex Minimal symbols and DLLs
13070
13071Very often on windows, some of the DLLs that your program relies on do
13072not include symbolic debugging information (for example,
13073@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13074symbols in a DLL, it relies on the minimal amount of symbolic
13075information contained in the DLL's export table. This subsubsection
13076describes working with such symbols, known internally to @value{GDBN} as
13077``minimal symbols''.
13078
13079Note that before the debugged program has started execution, no DLLs
13080will have been loaded. The easiest way around this problem is simply to
13081start the program --- either by setting a breakpoint or letting the
13082program run once to completion. It is also possible to force
13083@value{GDBN} to load a particular DLL before starting the executable ---
13084see the shared library information in @pxref{Files} or the
13085@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13086explicitly loading symbols from a DLL with no debugging information will
13087cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13088which may adversely affect symbol lookup performance.
13089
13090@subsubsection DLL name prefixes
13091
13092In keeping with the naming conventions used by the Microsoft debugging
13093tools, DLL export symbols are made available with a prefix based on the
13094DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13095also entered into the symbol table, so @code{CreateFileA} is often
13096sufficient. In some cases there will be name clashes within a program
13097(particularly if the executable itself includes full debugging symbols)
13098necessitating the use of the fully qualified name when referring to the
13099contents of the DLL. Use single-quotes around the name to avoid the
13100exclamation mark (``!'') being interpreted as a language operator.
13101
13102Note that the internal name of the DLL may be all upper-case, even
13103though the file name of the DLL is lower-case, or vice-versa. Since
13104symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13105some confusion. If in doubt, try the @code{info functions} and
13106@code{info variables} commands or even @code{maint print msymbols} (see
13107@pxref{Symbols}). Here's an example:
13108
13109@smallexample
f7dc1244 13110(@value{GDBP}) info function CreateFileA
be448670
CF
13111All functions matching regular expression "CreateFileA":
13112
13113Non-debugging symbols:
131140x77e885f4 CreateFileA
131150x77e885f4 KERNEL32!CreateFileA
13116@end smallexample
13117
13118@smallexample
f7dc1244 13119(@value{GDBP}) info function !
be448670
CF
13120All functions matching regular expression "!":
13121
13122Non-debugging symbols:
131230x6100114c cygwin1!__assert
131240x61004034 cygwin1!_dll_crt0@@0
131250x61004240 cygwin1!dll_crt0(per_process *)
13126[etc...]
13127@end smallexample
13128
13129@subsubsection Working with minimal symbols
13130
13131Symbols extracted from a DLL's export table do not contain very much
13132type information. All that @value{GDBN} can do is guess whether a symbol
13133refers to a function or variable depending on the linker section that
13134contains the symbol. Also note that the actual contents of the memory
13135contained in a DLL are not available unless the program is running. This
13136means that you cannot examine the contents of a variable or disassemble
13137a function within a DLL without a running program.
13138
13139Variables are generally treated as pointers and dereferenced
13140automatically. For this reason, it is often necessary to prefix a
13141variable name with the address-of operator (``&'') and provide explicit
13142type information in the command. Here's an example of the type of
13143problem:
13144
13145@smallexample
f7dc1244 13146(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13147$1 = 268572168
13148@end smallexample
13149
13150@smallexample
f7dc1244 13151(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131520x10021610: "\230y\""
13153@end smallexample
13154
13155And two possible solutions:
13156
13157@smallexample
f7dc1244 13158(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13159$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13160@end smallexample
13161
13162@smallexample
f7dc1244 13163(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131640x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13165(@value{GDBP}) x/x 0x10021608
be448670 131660x10021608: 0x0022fd98
f7dc1244 13167(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131680x22fd98: "/cygdrive/c/mydirectory/myprogram"
13169@end smallexample
13170
13171Setting a break point within a DLL is possible even before the program
13172starts execution. However, under these circumstances, @value{GDBN} can't
13173examine the initial instructions of the function in order to skip the
13174function's frame set-up code. You can work around this by using ``*&''
13175to set the breakpoint at a raw memory address:
13176
13177@smallexample
f7dc1244 13178(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13179Breakpoint 1 at 0x1e04eff0
13180@end smallexample
13181
13182The author of these extensions is not entirely convinced that setting a
13183break point within a shared DLL like @file{kernel32.dll} is completely
13184safe.
13185
14d6dd68
EZ
13186@node Hurd Native
13187@subsection Commands specific to @sc{gnu} Hurd systems
13188@cindex @sc{gnu} Hurd debugging
13189
13190This subsection describes @value{GDBN} commands specific to the
13191@sc{gnu} Hurd native debugging.
13192
13193@table @code
13194@item set signals
13195@itemx set sigs
13196@kindex set signals@r{, Hurd command}
13197@kindex set sigs@r{, Hurd command}
13198This command toggles the state of inferior signal interception by
13199@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13200affected by this command. @code{sigs} is a shorthand alias for
13201@code{signals}.
13202
13203@item show signals
13204@itemx show sigs
13205@kindex show signals@r{, Hurd command}
13206@kindex show sigs@r{, Hurd command}
13207Show the current state of intercepting inferior's signals.
13208
13209@item set signal-thread
13210@itemx set sigthread
13211@kindex set signal-thread
13212@kindex set sigthread
13213This command tells @value{GDBN} which thread is the @code{libc} signal
13214thread. That thread is run when a signal is delivered to a running
13215process. @code{set sigthread} is the shorthand alias of @code{set
13216signal-thread}.
13217
13218@item show signal-thread
13219@itemx show sigthread
13220@kindex show signal-thread
13221@kindex show sigthread
13222These two commands show which thread will run when the inferior is
13223delivered a signal.
13224
13225@item set stopped
13226@kindex set stopped@r{, Hurd command}
13227This commands tells @value{GDBN} that the inferior process is stopped,
13228as with the @code{SIGSTOP} signal. The stopped process can be
13229continued by delivering a signal to it.
13230
13231@item show stopped
13232@kindex show stopped@r{, Hurd command}
13233This command shows whether @value{GDBN} thinks the debuggee is
13234stopped.
13235
13236@item set exceptions
13237@kindex set exceptions@r{, Hurd command}
13238Use this command to turn off trapping of exceptions in the inferior.
13239When exception trapping is off, neither breakpoints nor
13240single-stepping will work. To restore the default, set exception
13241trapping on.
13242
13243@item show exceptions
13244@kindex show exceptions@r{, Hurd command}
13245Show the current state of trapping exceptions in the inferior.
13246
13247@item set task pause
13248@kindex set task@r{, Hurd commands}
13249@cindex task attributes (@sc{gnu} Hurd)
13250@cindex pause current task (@sc{gnu} Hurd)
13251This command toggles task suspension when @value{GDBN} has control.
13252Setting it to on takes effect immediately, and the task is suspended
13253whenever @value{GDBN} gets control. Setting it to off will take
13254effect the next time the inferior is continued. If this option is set
13255to off, you can use @code{set thread default pause on} or @code{set
13256thread pause on} (see below) to pause individual threads.
13257
13258@item show task pause
13259@kindex show task@r{, Hurd commands}
13260Show the current state of task suspension.
13261
13262@item set task detach-suspend-count
13263@cindex task suspend count
13264@cindex detach from task, @sc{gnu} Hurd
13265This command sets the suspend count the task will be left with when
13266@value{GDBN} detaches from it.
13267
13268@item show task detach-suspend-count
13269Show the suspend count the task will be left with when detaching.
13270
13271@item set task exception-port
13272@itemx set task excp
13273@cindex task exception port, @sc{gnu} Hurd
13274This command sets the task exception port to which @value{GDBN} will
13275forward exceptions. The argument should be the value of the @dfn{send
13276rights} of the task. @code{set task excp} is a shorthand alias.
13277
13278@item set noninvasive
13279@cindex noninvasive task options
13280This command switches @value{GDBN} to a mode that is the least
13281invasive as far as interfering with the inferior is concerned. This
13282is the same as using @code{set task pause}, @code{set exceptions}, and
13283@code{set signals} to values opposite to the defaults.
13284
13285@item info send-rights
13286@itemx info receive-rights
13287@itemx info port-rights
13288@itemx info port-sets
13289@itemx info dead-names
13290@itemx info ports
13291@itemx info psets
13292@cindex send rights, @sc{gnu} Hurd
13293@cindex receive rights, @sc{gnu} Hurd
13294@cindex port rights, @sc{gnu} Hurd
13295@cindex port sets, @sc{gnu} Hurd
13296@cindex dead names, @sc{gnu} Hurd
13297These commands display information about, respectively, send rights,
13298receive rights, port rights, port sets, and dead names of a task.
13299There are also shorthand aliases: @code{info ports} for @code{info
13300port-rights} and @code{info psets} for @code{info port-sets}.
13301
13302@item set thread pause
13303@kindex set thread@r{, Hurd command}
13304@cindex thread properties, @sc{gnu} Hurd
13305@cindex pause current thread (@sc{gnu} Hurd)
13306This command toggles current thread suspension when @value{GDBN} has
13307control. Setting it to on takes effect immediately, and the current
13308thread is suspended whenever @value{GDBN} gets control. Setting it to
13309off will take effect the next time the inferior is continued.
13310Normally, this command has no effect, since when @value{GDBN} has
13311control, the whole task is suspended. However, if you used @code{set
13312task pause off} (see above), this command comes in handy to suspend
13313only the current thread.
13314
13315@item show thread pause
13316@kindex show thread@r{, Hurd command}
13317This command shows the state of current thread suspension.
13318
13319@item set thread run
13320This comamnd sets whether the current thread is allowed to run.
13321
13322@item show thread run
13323Show whether the current thread is allowed to run.
13324
13325@item set thread detach-suspend-count
13326@cindex thread suspend count, @sc{gnu} Hurd
13327@cindex detach from thread, @sc{gnu} Hurd
13328This command sets the suspend count @value{GDBN} will leave on a
13329thread when detaching. This number is relative to the suspend count
13330found by @value{GDBN} when it notices the thread; use @code{set thread
13331takeover-suspend-count} to force it to an absolute value.
13332
13333@item show thread detach-suspend-count
13334Show the suspend count @value{GDBN} will leave on the thread when
13335detaching.
13336
13337@item set thread exception-port
13338@itemx set thread excp
13339Set the thread exception port to which to forward exceptions. This
13340overrides the port set by @code{set task exception-port} (see above).
13341@code{set thread excp} is the shorthand alias.
13342
13343@item set thread takeover-suspend-count
13344Normally, @value{GDBN}'s thread suspend counts are relative to the
13345value @value{GDBN} finds when it notices each thread. This command
13346changes the suspend counts to be absolute instead.
13347
13348@item set thread default
13349@itemx show thread default
13350@cindex thread default settings, @sc{gnu} Hurd
13351Each of the above @code{set thread} commands has a @code{set thread
13352default} counterpart (e.g., @code{set thread default pause}, @code{set
13353thread default exception-port}, etc.). The @code{thread default}
13354variety of commands sets the default thread properties for all
13355threads; you can then change the properties of individual threads with
13356the non-default commands.
13357@end table
13358
13359
a64548ea
EZ
13360@node Neutrino
13361@subsection QNX Neutrino
13362@cindex QNX Neutrino
13363
13364@value{GDBN} provides the following commands specific to the QNX
13365Neutrino target:
13366
13367@table @code
13368@item set debug nto-debug
13369@kindex set debug nto-debug
13370When set to on, enables debugging messages specific to the QNX
13371Neutrino support.
13372
13373@item show debug nto-debug
13374@kindex show debug nto-debug
13375Show the current state of QNX Neutrino messages.
13376@end table
13377
13378
8e04817f
AC
13379@node Embedded OS
13380@section Embedded Operating Systems
104c1213 13381
8e04817f
AC
13382This section describes configurations involving the debugging of
13383embedded operating systems that are available for several different
13384architectures.
d4f3574e 13385
8e04817f
AC
13386@menu
13387* VxWorks:: Using @value{GDBN} with VxWorks
13388@end menu
104c1213 13389
8e04817f
AC
13390@value{GDBN} includes the ability to debug programs running on
13391various real-time operating systems.
104c1213 13392
8e04817f
AC
13393@node VxWorks
13394@subsection Using @value{GDBN} with VxWorks
104c1213 13395
8e04817f 13396@cindex VxWorks
104c1213 13397
8e04817f 13398@table @code
104c1213 13399
8e04817f
AC
13400@kindex target vxworks
13401@item target vxworks @var{machinename}
13402A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13403is the target system's machine name or IP address.
104c1213 13404
8e04817f 13405@end table
104c1213 13406
8e04817f
AC
13407On VxWorks, @code{load} links @var{filename} dynamically on the
13408current target system as well as adding its symbols in @value{GDBN}.
104c1213 13409
8e04817f
AC
13410@value{GDBN} enables developers to spawn and debug tasks running on networked
13411VxWorks targets from a Unix host. Already-running tasks spawned from
13412the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13413both the Unix host and on the VxWorks target. The program
13414@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13415installed with the name @code{vxgdb}, to distinguish it from a
13416@value{GDBN} for debugging programs on the host itself.)
104c1213 13417
8e04817f
AC
13418@table @code
13419@item VxWorks-timeout @var{args}
13420@kindex vxworks-timeout
13421All VxWorks-based targets now support the option @code{vxworks-timeout}.
13422This option is set by the user, and @var{args} represents the number of
13423seconds @value{GDBN} waits for responses to rpc's. You might use this if
13424your VxWorks target is a slow software simulator or is on the far side
13425of a thin network line.
13426@end table
104c1213 13427
8e04817f
AC
13428The following information on connecting to VxWorks was current when
13429this manual was produced; newer releases of VxWorks may use revised
13430procedures.
104c1213 13431
4644b6e3 13432@findex INCLUDE_RDB
8e04817f
AC
13433To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13434to include the remote debugging interface routines in the VxWorks
13435library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13436VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13437kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13438source debugging task @code{tRdbTask} when VxWorks is booted. For more
13439information on configuring and remaking VxWorks, see the manufacturer's
13440manual.
13441@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13442
8e04817f
AC
13443Once you have included @file{rdb.a} in your VxWorks system image and set
13444your Unix execution search path to find @value{GDBN}, you are ready to
13445run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13446@code{vxgdb}, depending on your installation).
104c1213 13447
8e04817f 13448@value{GDBN} comes up showing the prompt:
104c1213 13449
474c8240 13450@smallexample
8e04817f 13451(vxgdb)
474c8240 13452@end smallexample
104c1213 13453
8e04817f
AC
13454@menu
13455* VxWorks Connection:: Connecting to VxWorks
13456* VxWorks Download:: VxWorks download
13457* VxWorks Attach:: Running tasks
13458@end menu
104c1213 13459
8e04817f
AC
13460@node VxWorks Connection
13461@subsubsection Connecting to VxWorks
104c1213 13462
8e04817f
AC
13463The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13464network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13465
474c8240 13466@smallexample
8e04817f 13467(vxgdb) target vxworks tt
474c8240 13468@end smallexample
104c1213 13469
8e04817f
AC
13470@need 750
13471@value{GDBN} displays messages like these:
104c1213 13472
8e04817f
AC
13473@smallexample
13474Attaching remote machine across net...
13475Connected to tt.
13476@end smallexample
104c1213 13477
8e04817f
AC
13478@need 1000
13479@value{GDBN} then attempts to read the symbol tables of any object modules
13480loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13481these files by searching the directories listed in the command search
13482path (@pxref{Environment, ,Your program's environment}); if it fails
13483to find an object file, it displays a message such as:
5d161b24 13484
474c8240 13485@smallexample
8e04817f 13486prog.o: No such file or directory.
474c8240 13487@end smallexample
104c1213 13488
8e04817f
AC
13489When this happens, add the appropriate directory to the search path with
13490the @value{GDBN} command @code{path}, and execute the @code{target}
13491command again.
104c1213 13492
8e04817f
AC
13493@node VxWorks Download
13494@subsubsection VxWorks download
104c1213 13495
8e04817f
AC
13496@cindex download to VxWorks
13497If you have connected to the VxWorks target and you want to debug an
13498object that has not yet been loaded, you can use the @value{GDBN}
13499@code{load} command to download a file from Unix to VxWorks
13500incrementally. The object file given as an argument to the @code{load}
13501command is actually opened twice: first by the VxWorks target in order
13502to download the code, then by @value{GDBN} in order to read the symbol
13503table. This can lead to problems if the current working directories on
13504the two systems differ. If both systems have NFS mounted the same
13505filesystems, you can avoid these problems by using absolute paths.
13506Otherwise, it is simplest to set the working directory on both systems
13507to the directory in which the object file resides, and then to reference
13508the file by its name, without any path. For instance, a program
13509@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13510and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13511program, type this on VxWorks:
104c1213 13512
474c8240 13513@smallexample
8e04817f 13514-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13515@end smallexample
104c1213 13516
8e04817f
AC
13517@noindent
13518Then, in @value{GDBN}, type:
104c1213 13519
474c8240 13520@smallexample
8e04817f
AC
13521(vxgdb) cd @var{hostpath}/vw/demo/rdb
13522(vxgdb) load prog.o
474c8240 13523@end smallexample
104c1213 13524
8e04817f 13525@value{GDBN} displays a response similar to this:
104c1213 13526
8e04817f
AC
13527@smallexample
13528Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13529@end smallexample
104c1213 13530
8e04817f
AC
13531You can also use the @code{load} command to reload an object module
13532after editing and recompiling the corresponding source file. Note that
13533this makes @value{GDBN} delete all currently-defined breakpoints,
13534auto-displays, and convenience variables, and to clear the value
13535history. (This is necessary in order to preserve the integrity of
13536debugger's data structures that reference the target system's symbol
13537table.)
104c1213 13538
8e04817f
AC
13539@node VxWorks Attach
13540@subsubsection Running tasks
104c1213
JM
13541
13542@cindex running VxWorks tasks
13543You can also attach to an existing task using the @code{attach} command as
13544follows:
13545
474c8240 13546@smallexample
104c1213 13547(vxgdb) attach @var{task}
474c8240 13548@end smallexample
104c1213
JM
13549
13550@noindent
13551where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13552or suspended when you attach to it. Running tasks are suspended at
13553the time of attachment.
13554
6d2ebf8b 13555@node Embedded Processors
104c1213
JM
13556@section Embedded Processors
13557
13558This section goes into details specific to particular embedded
13559configurations.
13560
c45da7e6
EZ
13561@cindex send command to simulator
13562Whenever a specific embedded processor has a simulator, @value{GDBN}
13563allows to send an arbitrary command to the simulator.
13564
13565@table @code
13566@item sim @var{command}
13567@kindex sim@r{, a command}
13568Send an arbitrary @var{command} string to the simulator. Consult the
13569documentation for the specific simulator in use for information about
13570acceptable commands.
13571@end table
13572
7d86b5d5 13573
104c1213 13574@menu
c45da7e6 13575* ARM:: ARM RDI
172c2a43
KI
13576* H8/300:: Renesas H8/300
13577* H8/500:: Renesas H8/500
13578* M32R/D:: Renesas M32R/D
104c1213 13579* M68K:: Motorola M68K
104c1213 13580* MIPS Embedded:: MIPS Embedded
a37295f9 13581* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13582* PA:: HP PA Embedded
13583* PowerPC: PowerPC
172c2a43 13584* SH:: Renesas SH
104c1213
JM
13585* Sparclet:: Tsqware Sparclet
13586* Sparclite:: Fujitsu Sparclite
13587* ST2000:: Tandem ST2000
13588* Z8000:: Zilog Z8000
a64548ea
EZ
13589* AVR:: Atmel AVR
13590* CRIS:: CRIS
13591* Super-H:: Renesas Super-H
c45da7e6 13592* WinCE:: Windows CE child processes
104c1213
JM
13593@end menu
13594
6d2ebf8b 13595@node ARM
104c1213 13596@subsection ARM
c45da7e6 13597@cindex ARM RDI
104c1213
JM
13598
13599@table @code
8e04817f
AC
13600@kindex target rdi
13601@item target rdi @var{dev}
13602ARM Angel monitor, via RDI library interface to ADP protocol. You may
13603use this target to communicate with both boards running the Angel
13604monitor, or with the EmbeddedICE JTAG debug device.
13605
13606@kindex target rdp
13607@item target rdp @var{dev}
13608ARM Demon monitor.
13609
13610@end table
13611
e2f4edfd
EZ
13612@value{GDBN} provides the following ARM-specific commands:
13613
13614@table @code
13615@item set arm disassembler
13616@kindex set arm
13617This commands selects from a list of disassembly styles. The
13618@code{"std"} style is the standard style.
13619
13620@item show arm disassembler
13621@kindex show arm
13622Show the current disassembly style.
13623
13624@item set arm apcs32
13625@cindex ARM 32-bit mode
13626This command toggles ARM operation mode between 32-bit and 26-bit.
13627
13628@item show arm apcs32
13629Display the current usage of the ARM 32-bit mode.
13630
13631@item set arm fpu @var{fputype}
13632This command sets the ARM floating-point unit (FPU) type. The
13633argument @var{fputype} can be one of these:
13634
13635@table @code
13636@item auto
13637Determine the FPU type by querying the OS ABI.
13638@item softfpa
13639Software FPU, with mixed-endian doubles on little-endian ARM
13640processors.
13641@item fpa
13642GCC-compiled FPA co-processor.
13643@item softvfp
13644Software FPU with pure-endian doubles.
13645@item vfp
13646VFP co-processor.
13647@end table
13648
13649@item show arm fpu
13650Show the current type of the FPU.
13651
13652@item set arm abi
13653This command forces @value{GDBN} to use the specified ABI.
13654
13655@item show arm abi
13656Show the currently used ABI.
13657
13658@item set debug arm
13659Toggle whether to display ARM-specific debugging messages from the ARM
13660target support subsystem.
13661
13662@item show debug arm
13663Show whether ARM-specific debugging messages are enabled.
13664@end table
13665
c45da7e6
EZ
13666The following commands are available when an ARM target is debugged
13667using the RDI interface:
13668
13669@table @code
13670@item rdilogfile @r{[}@var{file}@r{]}
13671@kindex rdilogfile
13672@cindex ADP (Angel Debugger Protocol) logging
13673Set the filename for the ADP (Angel Debugger Protocol) packet log.
13674With an argument, sets the log file to the specified @var{file}. With
13675no argument, show the current log file name. The default log file is
13676@file{rdi.log}.
13677
13678@item rdilogenable @r{[}@var{arg}@r{]}
13679@kindex rdilogenable
13680Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13681enables logging, with an argument 0 or @code{"no"} disables it. With
13682no arguments displays the current setting. When logging is enabled,
13683ADP packets exchanged between @value{GDBN} and the RDI target device
13684are logged to a file.
13685
13686@item set rdiromatzero
13687@kindex set rdiromatzero
13688@cindex ROM at zero address, RDI
13689Tell @value{GDBN} whether the target has ROM at address 0. If on,
13690vector catching is disabled, so that zero address can be used. If off
13691(the default), vector catching is enabled. For this command to take
13692effect, it needs to be invoked prior to the @code{target rdi} command.
13693
13694@item show rdiromatzero
13695@kindex show rdiromatzero
13696Show the current setting of ROM at zero address.
13697
13698@item set rdiheartbeat
13699@kindex set rdiheartbeat
13700@cindex RDI heartbeat
13701Enable or disable RDI heartbeat packets. It is not recommended to
13702turn on this option, since it confuses ARM and EPI JTAG interface, as
13703well as the Angel monitor.
13704
13705@item show rdiheartbeat
13706@kindex show rdiheartbeat
13707Show the setting of RDI heartbeat packets.
13708@end table
13709
e2f4edfd 13710
8e04817f 13711@node H8/300
172c2a43 13712@subsection Renesas H8/300
8e04817f
AC
13713
13714@table @code
13715
13716@kindex target hms@r{, with H8/300}
13717@item target hms @var{dev}
172c2a43 13718A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13719Use special commands @code{device} and @code{speed} to control the serial
13720line and the communications speed used.
13721
13722@kindex target e7000@r{, with H8/300}
13723@item target e7000 @var{dev}
172c2a43 13724E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13725
13726@kindex target sh3@r{, with H8/300}
13727@kindex target sh3e@r{, with H8/300}
13728@item target sh3 @var{dev}
13729@itemx target sh3e @var{dev}
172c2a43 13730Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13731
13732@end table
13733
13734@cindex download to H8/300 or H8/500
13735@cindex H8/300 or H8/500 download
172c2a43
KI
13736@cindex download to Renesas SH
13737@cindex Renesas SH download
13738When you select remote debugging to a Renesas SH, H8/300, or H8/500
13739board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13740board and also opens it as the current executable target for
13741@value{GDBN} on your host (like the @code{file} command).
13742
13743@value{GDBN} needs to know these things to talk to your
172c2a43 13744Renesas SH, H8/300, or H8/500:
8e04817f
AC
13745
13746@enumerate
13747@item
13748that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13749for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13750emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13751the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13752H8/300, or H8/500.)
13753
13754@item
172c2a43 13755what serial device connects your host to your Renesas board (the first
8e04817f
AC
13756serial device available on your host is the default).
13757
13758@item
13759what speed to use over the serial device.
13760@end enumerate
13761
13762@menu
172c2a43
KI
13763* Renesas Boards:: Connecting to Renesas boards.
13764* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13765* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13766@end menu
13767
172c2a43
KI
13768@node Renesas Boards
13769@subsubsection Connecting to Renesas boards
8e04817f
AC
13770
13771@c only for Unix hosts
13772@kindex device
172c2a43 13773@cindex serial device, Renesas micros
8e04817f
AC
13774Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13775need to explicitly set the serial device. The default @var{port} is the
13776first available port on your host. This is only necessary on Unix
13777hosts, where it is typically something like @file{/dev/ttya}.
13778
13779@kindex speed
172c2a43 13780@cindex serial line speed, Renesas micros
8e04817f
AC
13781@code{@value{GDBN}} has another special command to set the communications
13782speed: @samp{speed @var{bps}}. This command also is only used from Unix
13783hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13784the DOS @code{mode} command (for instance,
13785@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13786
13787The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13788use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13789use a DOS host,
13790@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13791called @code{asynctsr} to communicate with the development board
13792through a PC serial port. You must also use the DOS @code{mode} command
13793to set up the serial port on the DOS side.
13794
13795The following sample session illustrates the steps needed to start a
13796program under @value{GDBN} control on an H8/300. The example uses a
13797sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13798the Renesas SH and the H8/500.
8e04817f
AC
13799
13800First hook up your development board. In this example, we use a
13801board attached to serial port @code{COM2}; if you use a different serial
13802port, substitute its name in the argument of the @code{mode} command.
13803When you call @code{asynctsr}, the auxiliary comms program used by the
13804debugger, you give it just the numeric part of the serial port's name;
13805for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13806@code{COM2}.
13807
474c8240 13808@smallexample
8e04817f
AC
13809C:\H8300\TEST> asynctsr 2
13810C:\H8300\TEST> mode com2:9600,n,8,1,p
13811
13812Resident portion of MODE loaded
13813
13814COM2: 9600, n, 8, 1, p
13815
474c8240 13816@end smallexample
8e04817f
AC
13817
13818@quotation
13819@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13820@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13821disable it, or even boot without it, to use @code{asynctsr} to control
13822your development board.
13823@end quotation
13824
13825@kindex target hms@r{, and serial protocol}
13826Now that serial communications are set up, and the development board is
9c16f35a 13827connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13828the name of your program as the argument. @code{@value{GDBN}} prompts
13829you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13830commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13831cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13832download your program to the board. @code{load} displays the names of
13833the program's sections, and a @samp{*} for each 2K of data downloaded.
13834(If you want to refresh @value{GDBN} data on symbols or on the
13835executable file without downloading, use the @value{GDBN} commands
13836@code{file} or @code{symbol-file}. These commands, and @code{load}
13837itself, are described in @ref{Files,,Commands to specify files}.)
13838
13839@smallexample
13840(eg-C:\H8300\TEST) @value{GDBP} t.x
13841@value{GDBN} is free software and you are welcome to distribute copies
13842 of it under certain conditions; type "show copying" to see
13843 the conditions.
13844There is absolutely no warranty for @value{GDBN}; type "show warranty"
13845for details.
13846@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13847(@value{GDBP}) target hms
13848Connected to remote H8/300 HMS system.
13849(@value{GDBP}) load t.x
13850.text : 0x8000 .. 0xabde ***********
13851.data : 0xabde .. 0xad30 *
13852.stack : 0xf000 .. 0xf014 *
13853@end smallexample
13854
13855At this point, you're ready to run or debug your program. From here on,
13856you can use all the usual @value{GDBN} commands. The @code{break} command
13857sets breakpoints; the @code{run} command starts your program;
13858@code{print} or @code{x} display data; the @code{continue} command
13859resumes execution after stopping at a breakpoint. You can use the
13860@code{help} command at any time to find out more about @value{GDBN} commands.
13861
13862Remember, however, that @emph{operating system} facilities aren't
13863available on your development board; for example, if your program hangs,
13864you can't send an interrupt---but you can press the @sc{reset} switch!
13865
13866Use the @sc{reset} button on the development board
13867@itemize @bullet
13868@item
13869to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13870no way to pass an interrupt signal to the development board); and
13871
13872@item
13873to return to the @value{GDBN} command prompt after your program finishes
13874normally. The communications protocol provides no other way for @value{GDBN}
13875to detect program completion.
13876@end itemize
13877
13878In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13879development board as a ``normal exit'' of your program.
13880
172c2a43 13881@node Renesas ICE
8e04817f
AC
13882@subsubsection Using the E7000 in-circuit emulator
13883
172c2a43 13884@kindex target e7000@r{, with Renesas ICE}
8e04817f 13885You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13886Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13887e7000} command to connect @value{GDBN} to your E7000:
13888
13889@table @code
13890@item target e7000 @var{port} @var{speed}
13891Use this form if your E7000 is connected to a serial port. The
13892@var{port} argument identifies what serial port to use (for example,
13893@samp{com2}). The third argument is the line speed in bits per second
13894(for example, @samp{9600}).
13895
13896@item target e7000 @var{hostname}
13897If your E7000 is installed as a host on a TCP/IP network, you can just
13898specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13899@end table
13900
ba04e063
EZ
13901The following special commands are available when debugging with the
13902Renesas E7000 ICE:
13903
13904@table @code
13905@item e7000 @var{command}
13906@kindex e7000
13907@cindex send command to E7000 monitor
13908This sends the specified @var{command} to the E7000 monitor.
13909
13910@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13911@kindex ftplogin@r{, E7000}
13912This command records information for subsequent interface with the
13913E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13914named @var{machine} using specified @var{username} and @var{password},
13915and then chdir to the named directory @var{dir}.
13916
13917@item ftpload @var{file}
13918@kindex ftpload@r{, E7000}
13919This command uses credentials recorded by @code{ftplogin} to fetch and
13920load the named @var{file} from the E7000 monitor.
13921
13922@item drain
13923@kindex drain@r{, E7000}
13924This command drains any pending text buffers stored on the E7000.
13925
13926@item set usehardbreakpoints
13927@itemx show usehardbreakpoints
13928@kindex set usehardbreakpoints@r{, E7000}
13929@kindex show usehardbreakpoints@r{, E7000}
13930@cindex hardware breakpoints, and E7000
13931These commands set and show the use of hardware breakpoints for all
13932breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13933more information about using hardware breakpoints selectively.
13934@end table
13935
172c2a43
KI
13936@node Renesas Special
13937@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13938
13939Some @value{GDBN} commands are available only for the H8/300:
13940
13941@table @code
13942
13943@kindex set machine
13944@kindex show machine
13945@item set machine h8300
13946@itemx set machine h8300h
13947Condition @value{GDBN} for one of the two variants of the H8/300
13948architecture with @samp{set machine}. You can use @samp{show machine}
13949to check which variant is currently in effect.
104c1213
JM
13950
13951@end table
13952
8e04817f
AC
13953@node H8/500
13954@subsection H8/500
104c1213
JM
13955
13956@table @code
13957
8e04817f
AC
13958@kindex set memory @var{mod}
13959@cindex memory models, H8/500
13960@item set memory @var{mod}
13961@itemx show memory
13962Specify which H8/500 memory model (@var{mod}) you are using with
13963@samp{set memory}; check which memory model is in effect with @samp{show
13964memory}. The accepted values for @var{mod} are @code{small},
13965@code{big}, @code{medium}, and @code{compact}.
104c1213 13966
8e04817f 13967@end table
104c1213 13968
8e04817f 13969@node M32R/D
ba04e063 13970@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13971
13972@table @code
8e04817f
AC
13973@kindex target m32r
13974@item target m32r @var{dev}
172c2a43 13975Renesas M32R/D ROM monitor.
8e04817f 13976
fb3e19c0
KI
13977@kindex target m32rsdi
13978@item target m32rsdi @var{dev}
13979Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13980@end table
13981
13982The following @value{GDBN} commands are specific to the M32R monitor:
13983
13984@table @code
13985@item set download-path @var{path}
13986@kindex set download-path
13987@cindex find downloadable @sc{srec} files (M32R)
13988Set the default path for finding donwloadable @sc{srec} files.
13989
13990@item show download-path
13991@kindex show download-path
13992Show the default path for downloadable @sc{srec} files.
fb3e19c0 13993
721c2651
EZ
13994@item set board-address @var{addr}
13995@kindex set board-address
13996@cindex M32-EVA target board address
13997Set the IP address for the M32R-EVA target board.
13998
13999@item show board-address
14000@kindex show board-address
14001Show the current IP address of the target board.
14002
14003@item set server-address @var{addr}
14004@kindex set server-address
14005@cindex download server address (M32R)
14006Set the IP address for the download server, which is the @value{GDBN}'s
14007host machine.
14008
14009@item show server-address
14010@kindex show server-address
14011Display the IP address of the download server.
14012
14013@item upload @r{[}@var{file}@r{]}
14014@kindex upload@r{, M32R}
14015Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14016upload capability. If no @var{file} argument is given, the current
14017executable file is uploaded.
14018
14019@item tload @r{[}@var{file}@r{]}
14020@kindex tload@r{, M32R}
14021Test the @code{upload} command.
8e04817f
AC
14022@end table
14023
ba04e063
EZ
14024The following commands are available for M32R/SDI:
14025
14026@table @code
14027@item sdireset
14028@kindex sdireset
14029@cindex reset SDI connection, M32R
14030This command resets the SDI connection.
14031
14032@item sdistatus
14033@kindex sdistatus
14034This command shows the SDI connection status.
14035
14036@item debug_chaos
14037@kindex debug_chaos
14038@cindex M32R/Chaos debugging
14039Instructs the remote that M32R/Chaos debugging is to be used.
14040
14041@item use_debug_dma
14042@kindex use_debug_dma
14043Instructs the remote to use the DEBUG_DMA method of accessing memory.
14044
14045@item use_mon_code
14046@kindex use_mon_code
14047Instructs the remote to use the MON_CODE method of accessing memory.
14048
14049@item use_ib_break
14050@kindex use_ib_break
14051Instructs the remote to set breakpoints by IB break.
14052
14053@item use_dbt_break
14054@kindex use_dbt_break
14055Instructs the remote to set breakpoints by DBT.
14056@end table
14057
8e04817f
AC
14058@node M68K
14059@subsection M68k
14060
14061The Motorola m68k configuration includes ColdFire support, and
14062target command for the following ROM monitors.
14063
14064@table @code
14065
14066@kindex target abug
14067@item target abug @var{dev}
14068ABug ROM monitor for M68K.
14069
14070@kindex target cpu32bug
14071@item target cpu32bug @var{dev}
14072CPU32BUG monitor, running on a CPU32 (M68K) board.
14073
14074@kindex target dbug
14075@item target dbug @var{dev}
14076dBUG ROM monitor for Motorola ColdFire.
14077
14078@kindex target est
14079@item target est @var{dev}
14080EST-300 ICE monitor, running on a CPU32 (M68K) board.
14081
14082@kindex target rom68k
14083@item target rom68k @var{dev}
14084ROM 68K monitor, running on an M68K IDP board.
14085
14086@end table
14087
8e04817f
AC
14088@table @code
14089
14090@kindex target rombug
14091@item target rombug @var{dev}
14092ROMBUG ROM monitor for OS/9000.
14093
14094@end table
14095
8e04817f
AC
14096@node MIPS Embedded
14097@subsection MIPS Embedded
14098
14099@cindex MIPS boards
14100@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14101MIPS board attached to a serial line. This is available when
14102you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14103
8e04817f
AC
14104@need 1000
14105Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14106
8e04817f
AC
14107@table @code
14108@item target mips @var{port}
14109@kindex target mips @var{port}
14110To run a program on the board, start up @code{@value{GDBP}} with the
14111name of your program as the argument. To connect to the board, use the
14112command @samp{target mips @var{port}}, where @var{port} is the name of
14113the serial port connected to the board. If the program has not already
14114been downloaded to the board, you may use the @code{load} command to
14115download it. You can then use all the usual @value{GDBN} commands.
104c1213 14116
8e04817f
AC
14117For example, this sequence connects to the target board through a serial
14118port, and loads and runs a program called @var{prog} through the
14119debugger:
104c1213 14120
474c8240 14121@smallexample
8e04817f
AC
14122host$ @value{GDBP} @var{prog}
14123@value{GDBN} is free software and @dots{}
14124(@value{GDBP}) target mips /dev/ttyb
14125(@value{GDBP}) load @var{prog}
14126(@value{GDBP}) run
474c8240 14127@end smallexample
104c1213 14128
8e04817f
AC
14129@item target mips @var{hostname}:@var{portnumber}
14130On some @value{GDBN} host configurations, you can specify a TCP
14131connection (for instance, to a serial line managed by a terminal
14132concentrator) instead of a serial port, using the syntax
14133@samp{@var{hostname}:@var{portnumber}}.
104c1213 14134
8e04817f
AC
14135@item target pmon @var{port}
14136@kindex target pmon @var{port}
14137PMON ROM monitor.
104c1213 14138
8e04817f
AC
14139@item target ddb @var{port}
14140@kindex target ddb @var{port}
14141NEC's DDB variant of PMON for Vr4300.
104c1213 14142
8e04817f
AC
14143@item target lsi @var{port}
14144@kindex target lsi @var{port}
14145LSI variant of PMON.
104c1213 14146
8e04817f
AC
14147@kindex target r3900
14148@item target r3900 @var{dev}
14149Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14150
8e04817f
AC
14151@kindex target array
14152@item target array @var{dev}
14153Array Tech LSI33K RAID controller board.
104c1213 14154
8e04817f 14155@end table
104c1213 14156
104c1213 14157
8e04817f
AC
14158@noindent
14159@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14160
8e04817f 14161@table @code
8e04817f
AC
14162@item set mipsfpu double
14163@itemx set mipsfpu single
14164@itemx set mipsfpu none
a64548ea 14165@itemx set mipsfpu auto
8e04817f
AC
14166@itemx show mipsfpu
14167@kindex set mipsfpu
14168@kindex show mipsfpu
14169@cindex MIPS remote floating point
14170@cindex floating point, MIPS remote
14171If your target board does not support the MIPS floating point
14172coprocessor, you should use the command @samp{set mipsfpu none} (if you
14173need this, you may wish to put the command in your @value{GDBN} init
14174file). This tells @value{GDBN} how to find the return value of
14175functions which return floating point values. It also allows
14176@value{GDBN} to avoid saving the floating point registers when calling
14177functions on the board. If you are using a floating point coprocessor
14178with only single precision floating point support, as on the @sc{r4650}
14179processor, use the command @samp{set mipsfpu single}. The default
14180double precision floating point coprocessor may be selected using
14181@samp{set mipsfpu double}.
104c1213 14182
8e04817f
AC
14183In previous versions the only choices were double precision or no
14184floating point, so @samp{set mipsfpu on} will select double precision
14185and @samp{set mipsfpu off} will select no floating point.
104c1213 14186
8e04817f
AC
14187As usual, you can inquire about the @code{mipsfpu} variable with
14188@samp{show mipsfpu}.
104c1213 14189
8e04817f
AC
14190@item set timeout @var{seconds}
14191@itemx set retransmit-timeout @var{seconds}
14192@itemx show timeout
14193@itemx show retransmit-timeout
14194@cindex @code{timeout}, MIPS protocol
14195@cindex @code{retransmit-timeout}, MIPS protocol
14196@kindex set timeout
14197@kindex show timeout
14198@kindex set retransmit-timeout
14199@kindex show retransmit-timeout
14200You can control the timeout used while waiting for a packet, in the MIPS
14201remote protocol, with the @code{set timeout @var{seconds}} command. The
14202default is 5 seconds. Similarly, you can control the timeout used while
14203waiting for an acknowledgement of a packet with the @code{set
14204retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14205You can inspect both values with @code{show timeout} and @code{show
14206retransmit-timeout}. (These commands are @emph{only} available when
14207@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14208
8e04817f
AC
14209The timeout set by @code{set timeout} does not apply when @value{GDBN}
14210is waiting for your program to stop. In that case, @value{GDBN} waits
14211forever because it has no way of knowing how long the program is going
14212to run before stopping.
ba04e063
EZ
14213
14214@item set syn-garbage-limit @var{num}
14215@kindex set syn-garbage-limit@r{, MIPS remote}
14216@cindex synchronize with remote MIPS target
14217Limit the maximum number of characters @value{GDBN} should ignore when
14218it tries to synchronize with the remote target. The default is 10
14219characters. Setting the limit to -1 means there's no limit.
14220
14221@item show syn-garbage-limit
14222@kindex show syn-garbage-limit@r{, MIPS remote}
14223Show the current limit on the number of characters to ignore when
14224trying to synchronize with the remote system.
14225
14226@item set monitor-prompt @var{prompt}
14227@kindex set monitor-prompt@r{, MIPS remote}
14228@cindex remote monitor prompt
14229Tell @value{GDBN} to expect the specified @var{prompt} string from the
14230remote monitor. The default depends on the target:
14231@table @asis
14232@item pmon target
14233@samp{PMON}
14234@item ddb target
14235@samp{NEC010}
14236@item lsi target
14237@samp{PMON>}
14238@end table
14239
14240@item show monitor-prompt
14241@kindex show monitor-prompt@r{, MIPS remote}
14242Show the current strings @value{GDBN} expects as the prompt from the
14243remote monitor.
14244
14245@item set monitor-warnings
14246@kindex set monitor-warnings@r{, MIPS remote}
14247Enable or disable monitor warnings about hardware breakpoints. This
14248has effect only for the @code{lsi} target. When on, @value{GDBN} will
14249display warning messages whose codes are returned by the @code{lsi}
14250PMON monitor for breakpoint commands.
14251
14252@item show monitor-warnings
14253@kindex show monitor-warnings@r{, MIPS remote}
14254Show the current setting of printing monitor warnings.
14255
14256@item pmon @var{command}
14257@kindex pmon@r{, MIPS remote}
14258@cindex send PMON command
14259This command allows sending an arbitrary @var{command} string to the
14260monitor. The monitor must be in debug mode for this to work.
8e04817f 14261@end table
104c1213 14262
a37295f9
MM
14263@node OpenRISC 1000
14264@subsection OpenRISC 1000
14265@cindex OpenRISC 1000
14266
14267@cindex or1k boards
14268See OR1k Architecture document (@uref{www.opencores.org}) for more information
14269about platform and commands.
14270
14271@table @code
14272
14273@kindex target jtag
14274@item target jtag jtag://@var{host}:@var{port}
14275
14276Connects to remote JTAG server.
14277JTAG remote server can be either an or1ksim or JTAG server,
14278connected via parallel port to the board.
14279
14280Example: @code{target jtag jtag://localhost:9999}
14281
14282@kindex or1ksim
14283@item or1ksim @var{command}
14284If connected to @code{or1ksim} OpenRISC 1000 Architectural
14285Simulator, proprietary commands can be executed.
14286
14287@kindex info or1k spr
14288@item info or1k spr
14289Displays spr groups.
14290
14291@item info or1k spr @var{group}
14292@itemx info or1k spr @var{groupno}
14293Displays register names in selected group.
14294
14295@item info or1k spr @var{group} @var{register}
14296@itemx info or1k spr @var{register}
14297@itemx info or1k spr @var{groupno} @var{registerno}
14298@itemx info or1k spr @var{registerno}
14299Shows information about specified spr register.
14300
14301@kindex spr
14302@item spr @var{group} @var{register} @var{value}
14303@itemx spr @var{register @var{value}}
14304@itemx spr @var{groupno} @var{registerno @var{value}}
14305@itemx spr @var{registerno @var{value}}
14306Writes @var{value} to specified spr register.
14307@end table
14308
14309Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14310It is very similar to @value{GDBN} trace, except it does not interfere with normal
14311program execution and is thus much faster. Hardware breakpoints/watchpoint
14312triggers can be set using:
14313@table @code
14314@item $LEA/$LDATA
14315Load effective address/data
14316@item $SEA/$SDATA
14317Store effective address/data
14318@item $AEA/$ADATA
14319Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14320@item $FETCH
14321Fetch data
14322@end table
14323
14324When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14325@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14326
14327@code{htrace} commands:
14328@cindex OpenRISC 1000 htrace
14329@table @code
14330@kindex hwatch
14331@item hwatch @var{conditional}
14332Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14333or Data. For example:
14334
14335@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14336
14337@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14338
4644b6e3 14339@kindex htrace
a37295f9
MM
14340@item htrace info
14341Display information about current HW trace configuration.
14342
a37295f9
MM
14343@item htrace trigger @var{conditional}
14344Set starting criteria for HW trace.
14345
a37295f9
MM
14346@item htrace qualifier @var{conditional}
14347Set acquisition qualifier for HW trace.
14348
a37295f9
MM
14349@item htrace stop @var{conditional}
14350Set HW trace stopping criteria.
14351
f153cc92 14352@item htrace record [@var{data}]*
a37295f9
MM
14353Selects the data to be recorded, when qualifier is met and HW trace was
14354triggered.
14355
a37295f9 14356@item htrace enable
a37295f9
MM
14357@itemx htrace disable
14358Enables/disables the HW trace.
14359
f153cc92 14360@item htrace rewind [@var{filename}]
a37295f9
MM
14361Clears currently recorded trace data.
14362
14363If filename is specified, new trace file is made and any newly collected data
14364will be written there.
14365
f153cc92 14366@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14367Prints trace buffer, using current record configuration.
14368
a37295f9
MM
14369@item htrace mode continuous
14370Set continuous trace mode.
14371
a37295f9
MM
14372@item htrace mode suspend
14373Set suspend trace mode.
14374
14375@end table
14376
8e04817f
AC
14377@node PowerPC
14378@subsection PowerPC
104c1213
JM
14379
14380@table @code
8e04817f
AC
14381@kindex target dink32
14382@item target dink32 @var{dev}
14383DINK32 ROM monitor.
104c1213 14384
8e04817f
AC
14385@kindex target ppcbug
14386@item target ppcbug @var{dev}
14387@kindex target ppcbug1
14388@item target ppcbug1 @var{dev}
14389PPCBUG ROM monitor for PowerPC.
104c1213 14390
8e04817f
AC
14391@kindex target sds
14392@item target sds @var{dev}
14393SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14394@end table
8e04817f 14395
c45da7e6
EZ
14396@cindex SDS protocol
14397The following commands specifi to the SDS protocol are supported
14398by@value{GDBN}:
14399
14400@table @code
14401@item set sdstimeout @var{nsec}
14402@kindex set sdstimeout
14403Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14404default is 2 seconds.
14405
14406@item show sdstimeout
14407@kindex show sdstimeout
14408Show the current value of the SDS timeout.
14409
14410@item sds @var{command}
14411@kindex sds@r{, a command}
14412Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14413@end table
14414
c45da7e6 14415
8e04817f
AC
14416@node PA
14417@subsection HP PA Embedded
104c1213
JM
14418
14419@table @code
14420
8e04817f
AC
14421@kindex target op50n
14422@item target op50n @var{dev}
14423OP50N monitor, running on an OKI HPPA board.
14424
14425@kindex target w89k
14426@item target w89k @var{dev}
14427W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14428
14429@end table
14430
8e04817f 14431@node SH
172c2a43 14432@subsection Renesas SH
104c1213
JM
14433
14434@table @code
14435
172c2a43 14436@kindex target hms@r{, with Renesas SH}
8e04817f 14437@item target hms @var{dev}
172c2a43 14438A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14439commands @code{device} and @code{speed} to control the serial line and
14440the communications speed used.
104c1213 14441
172c2a43 14442@kindex target e7000@r{, with Renesas SH}
8e04817f 14443@item target e7000 @var{dev}
172c2a43 14444E7000 emulator for Renesas SH.
104c1213 14445
8e04817f
AC
14446@kindex target sh3@r{, with SH}
14447@kindex target sh3e@r{, with SH}
14448@item target sh3 @var{dev}
14449@item target sh3e @var{dev}
172c2a43 14450Renesas SH-3 and SH-3E target systems.
104c1213 14451
8e04817f 14452@end table
104c1213 14453
8e04817f
AC
14454@node Sparclet
14455@subsection Tsqware Sparclet
104c1213 14456
8e04817f
AC
14457@cindex Sparclet
14458
14459@value{GDBN} enables developers to debug tasks running on
14460Sparclet targets from a Unix host.
14461@value{GDBN} uses code that runs on
14462both the Unix host and on the Sparclet target. The program
14463@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14464
8e04817f
AC
14465@table @code
14466@item remotetimeout @var{args}
14467@kindex remotetimeout
14468@value{GDBN} supports the option @code{remotetimeout}.
14469This option is set by the user, and @var{args} represents the number of
14470seconds @value{GDBN} waits for responses.
104c1213
JM
14471@end table
14472
8e04817f
AC
14473@cindex compiling, on Sparclet
14474When compiling for debugging, include the options @samp{-g} to get debug
14475information and @samp{-Ttext} to relocate the program to where you wish to
14476load it on the target. You may also want to add the options @samp{-n} or
14477@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14478
474c8240 14479@smallexample
8e04817f 14480sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14481@end smallexample
104c1213 14482
8e04817f 14483You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14484
474c8240 14485@smallexample
8e04817f 14486sparclet-aout-objdump --headers --syms prog
474c8240 14487@end smallexample
104c1213 14488
8e04817f
AC
14489@cindex running, on Sparclet
14490Once you have set
14491your Unix execution search path to find @value{GDBN}, you are ready to
14492run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14493(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14494
8e04817f
AC
14495@value{GDBN} comes up showing the prompt:
14496
474c8240 14497@smallexample
8e04817f 14498(gdbslet)
474c8240 14499@end smallexample
104c1213
JM
14500
14501@menu
8e04817f
AC
14502* Sparclet File:: Setting the file to debug
14503* Sparclet Connection:: Connecting to Sparclet
14504* Sparclet Download:: Sparclet download
14505* Sparclet Execution:: Running and debugging
104c1213
JM
14506@end menu
14507
8e04817f
AC
14508@node Sparclet File
14509@subsubsection Setting file to debug
104c1213 14510
8e04817f 14511The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14512
474c8240 14513@smallexample
8e04817f 14514(gdbslet) file prog
474c8240 14515@end smallexample
104c1213 14516
8e04817f
AC
14517@need 1000
14518@value{GDBN} then attempts to read the symbol table of @file{prog}.
14519@value{GDBN} locates
14520the file by searching the directories listed in the command search
14521path.
14522If the file was compiled with debug information (option "-g"), source
14523files will be searched as well.
14524@value{GDBN} locates
14525the source files by searching the directories listed in the directory search
14526path (@pxref{Environment, ,Your program's environment}).
14527If it fails
14528to find a file, it displays a message such as:
104c1213 14529
474c8240 14530@smallexample
8e04817f 14531prog: No such file or directory.
474c8240 14532@end smallexample
104c1213 14533
8e04817f
AC
14534When this happens, add the appropriate directories to the search paths with
14535the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14536@code{target} command again.
104c1213 14537
8e04817f
AC
14538@node Sparclet Connection
14539@subsubsection Connecting to Sparclet
104c1213 14540
8e04817f
AC
14541The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14542To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14543
474c8240 14544@smallexample
8e04817f
AC
14545(gdbslet) target sparclet /dev/ttya
14546Remote target sparclet connected to /dev/ttya
14547main () at ../prog.c:3
474c8240 14548@end smallexample
104c1213 14549
8e04817f
AC
14550@need 750
14551@value{GDBN} displays messages like these:
104c1213 14552
474c8240 14553@smallexample
8e04817f 14554Connected to ttya.
474c8240 14555@end smallexample
104c1213 14556
8e04817f
AC
14557@node Sparclet Download
14558@subsubsection Sparclet download
104c1213 14559
8e04817f
AC
14560@cindex download to Sparclet
14561Once connected to the Sparclet target,
14562you can use the @value{GDBN}
14563@code{load} command to download the file from the host to the target.
14564The file name and load offset should be given as arguments to the @code{load}
14565command.
14566Since the file format is aout, the program must be loaded to the starting
14567address. You can use @code{objdump} to find out what this value is. The load
14568offset is an offset which is added to the VMA (virtual memory address)
14569of each of the file's sections.
14570For instance, if the program
14571@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14572and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14573
474c8240 14574@smallexample
8e04817f
AC
14575(gdbslet) load prog 0x12010000
14576Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14577@end smallexample
104c1213 14578
8e04817f
AC
14579If the code is loaded at a different address then what the program was linked
14580to, you may need to use the @code{section} and @code{add-symbol-file} commands
14581to tell @value{GDBN} where to map the symbol table.
14582
14583@node Sparclet Execution
14584@subsubsection Running and debugging
14585
14586@cindex running and debugging Sparclet programs
14587You can now begin debugging the task using @value{GDBN}'s execution control
14588commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14589manual for the list of commands.
14590
474c8240 14591@smallexample
8e04817f
AC
14592(gdbslet) b main
14593Breakpoint 1 at 0x12010000: file prog.c, line 3.
14594(gdbslet) run
14595Starting program: prog
14596Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145973 char *symarg = 0;
14598(gdbslet) step
145994 char *execarg = "hello!";
14600(gdbslet)
474c8240 14601@end smallexample
8e04817f
AC
14602
14603@node Sparclite
14604@subsection Fujitsu Sparclite
104c1213
JM
14605
14606@table @code
14607
8e04817f
AC
14608@kindex target sparclite
14609@item target sparclite @var{dev}
14610Fujitsu sparclite boards, used only for the purpose of loading.
14611You must use an additional command to debug the program.
14612For example: target remote @var{dev} using @value{GDBN} standard
14613remote protocol.
104c1213
JM
14614
14615@end table
14616
8e04817f
AC
14617@node ST2000
14618@subsection Tandem ST2000
104c1213 14619
8e04817f
AC
14620@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14621STDBUG protocol.
104c1213 14622
8e04817f
AC
14623To connect your ST2000 to the host system, see the manufacturer's
14624manual. Once the ST2000 is physically attached, you can run:
104c1213 14625
474c8240 14626@smallexample
8e04817f 14627target st2000 @var{dev} @var{speed}
474c8240 14628@end smallexample
104c1213 14629
8e04817f
AC
14630@noindent
14631to establish it as your debugging environment. @var{dev} is normally
14632the name of a serial device, such as @file{/dev/ttya}, connected to the
14633ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14634connection (for example, to a serial line attached via a terminal
14635concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14636
8e04817f
AC
14637The @code{load} and @code{attach} commands are @emph{not} defined for
14638this target; you must load your program into the ST2000 as you normally
14639would for standalone operation. @value{GDBN} reads debugging information
14640(such as symbols) from a separate, debugging version of the program
14641available on your host computer.
14642@c FIXME!! This is terribly vague; what little content is here is
14643@c basically hearsay.
104c1213 14644
8e04817f
AC
14645@cindex ST2000 auxiliary commands
14646These auxiliary @value{GDBN} commands are available to help you with the ST2000
14647environment:
104c1213 14648
8e04817f
AC
14649@table @code
14650@item st2000 @var{command}
14651@kindex st2000 @var{cmd}
14652@cindex STDBUG commands (ST2000)
14653@cindex commands to STDBUG (ST2000)
14654Send a @var{command} to the STDBUG monitor. See the manufacturer's
14655manual for available commands.
104c1213 14656
8e04817f
AC
14657@item connect
14658@cindex connect (to STDBUG)
14659Connect the controlling terminal to the STDBUG command monitor. When
14660you are done interacting with STDBUG, typing either of two character
14661sequences gets you back to the @value{GDBN} command prompt:
14662@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14663@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14664@end table
14665
8e04817f
AC
14666@node Z8000
14667@subsection Zilog Z8000
104c1213 14668
8e04817f
AC
14669@cindex Z8000
14670@cindex simulator, Z8000
14671@cindex Zilog Z8000 simulator
104c1213 14672
8e04817f
AC
14673When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14674a Z8000 simulator.
14675
14676For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14677unsegmented variant of the Z8000 architecture) or the Z8001 (the
14678segmented variant). The simulator recognizes which architecture is
14679appropriate by inspecting the object code.
104c1213 14680
8e04817f
AC
14681@table @code
14682@item target sim @var{args}
14683@kindex sim
14684@kindex target sim@r{, with Z8000}
14685Debug programs on a simulated CPU. If the simulator supports setup
14686options, specify them via @var{args}.
104c1213
JM
14687@end table
14688
8e04817f
AC
14689@noindent
14690After specifying this target, you can debug programs for the simulated
14691CPU in the same style as programs for your host computer; use the
14692@code{file} command to load a new program image, the @code{run} command
14693to run your program, and so on.
14694
14695As well as making available all the usual machine registers
14696(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14697additional items of information as specially named registers:
104c1213
JM
14698
14699@table @code
14700
8e04817f
AC
14701@item cycles
14702Counts clock-ticks in the simulator.
104c1213 14703
8e04817f
AC
14704@item insts
14705Counts instructions run in the simulator.
104c1213 14706
8e04817f
AC
14707@item time
14708Execution time in 60ths of a second.
104c1213 14709
8e04817f 14710@end table
104c1213 14711
8e04817f
AC
14712You can refer to these values in @value{GDBN} expressions with the usual
14713conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14714conditional breakpoint that suspends only after at least 5000
14715simulated clock ticks.
104c1213 14716
a64548ea
EZ
14717@node AVR
14718@subsection Atmel AVR
14719@cindex AVR
14720
14721When configured for debugging the Atmel AVR, @value{GDBN} supports the
14722following AVR-specific commands:
14723
14724@table @code
14725@item info io_registers
14726@kindex info io_registers@r{, AVR}
14727@cindex I/O registers (Atmel AVR)
14728This command displays information about the AVR I/O registers. For
14729each register, @value{GDBN} prints its number and value.
14730@end table
14731
14732@node CRIS
14733@subsection CRIS
14734@cindex CRIS
14735
14736When configured for debugging CRIS, @value{GDBN} provides the
14737following CRIS-specific commands:
14738
14739@table @code
14740@item set cris-version @var{ver}
14741@cindex CRIS version
e22e55c9
OF
14742Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14743The CRIS version affects register names and sizes. This command is useful in
14744case autodetection of the CRIS version fails.
a64548ea
EZ
14745
14746@item show cris-version
14747Show the current CRIS version.
14748
14749@item set cris-dwarf2-cfi
14750@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14751Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14752Change to @samp{off} when using @code{gcc-cris} whose version is below
14753@code{R59}.
a64548ea
EZ
14754
14755@item show cris-dwarf2-cfi
14756Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14757
14758@item set cris-mode @var{mode}
14759@cindex CRIS mode
14760Set the current CRIS mode to @var{mode}. It should only be changed when
14761debugging in guru mode, in which case it should be set to
14762@samp{guru} (the default is @samp{normal}).
14763
14764@item show cris-mode
14765Show the current CRIS mode.
a64548ea
EZ
14766@end table
14767
14768@node Super-H
14769@subsection Renesas Super-H
14770@cindex Super-H
14771
14772For the Renesas Super-H processor, @value{GDBN} provides these
14773commands:
14774
14775@table @code
14776@item regs
14777@kindex regs@r{, Super-H}
14778Show the values of all Super-H registers.
14779@end table
14780
c45da7e6
EZ
14781@node WinCE
14782@subsection Windows CE
14783@cindex Windows CE
14784
14785The following commands are available for Windows CE:
14786
14787@table @code
14788@item set remotedirectory @var{dir}
14789@kindex set remotedirectory
14790Tell @value{GDBN} to upload files from the named directory @var{dir}.
14791The default is @file{/gdb}, i.e.@: the root directory on the current
14792drive.
14793
14794@item show remotedirectory
14795@kindex show remotedirectory
14796Show the current value of the upload directory.
14797
14798@item set remoteupload @var{method}
14799@kindex set remoteupload
14800Set the method used to upload files to remote device. Valid values
14801for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14802The default is @samp{newer}.
14803
14804@item show remoteupload
14805@kindex show remoteupload
14806Show the current setting of the upload method.
14807
14808@item set remoteaddhost
14809@kindex set remoteaddhost
14810Tell @value{GDBN} whether to add this host to the remote stub's
14811arguments when you debug over a network.
14812
14813@item show remoteaddhost
14814@kindex show remoteaddhost
14815Show whether to add this host to remote stub's arguments when
14816debugging over a network.
14817@end table
14818
a64548ea 14819
8e04817f
AC
14820@node Architectures
14821@section Architectures
104c1213 14822
8e04817f
AC
14823This section describes characteristics of architectures that affect
14824all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14825
8e04817f 14826@menu
9c16f35a 14827* i386::
8e04817f
AC
14828* A29K::
14829* Alpha::
14830* MIPS::
a64548ea 14831* HPPA:: HP PA architecture
8e04817f 14832@end menu
104c1213 14833
9c16f35a
EZ
14834@node i386
14835@subsection x86 Architecture-specific issues.
14836
14837@table @code
14838@item set struct-convention @var{mode}
14839@kindex set struct-convention
14840@cindex struct return convention
14841@cindex struct/union returned in registers
14842Set the convention used by the inferior to return @code{struct}s and
14843@code{union}s from functions to @var{mode}. Possible values of
14844@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14845default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14846are returned on the stack, while @code{"reg"} means that a
14847@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14848be returned in a register.
14849
14850@item show struct-convention
14851@kindex show struct-convention
14852Show the current setting of the convention to return @code{struct}s
14853from functions.
14854@end table
14855
8e04817f
AC
14856@node A29K
14857@subsection A29K
104c1213
JM
14858
14859@table @code
104c1213 14860
8e04817f
AC
14861@kindex set rstack_high_address
14862@cindex AMD 29K register stack
14863@cindex register stack, AMD29K
14864@item set rstack_high_address @var{address}
14865On AMD 29000 family processors, registers are saved in a separate
14866@dfn{register stack}. There is no way for @value{GDBN} to determine the
14867extent of this stack. Normally, @value{GDBN} just assumes that the
14868stack is ``large enough''. This may result in @value{GDBN} referencing
14869memory locations that do not exist. If necessary, you can get around
14870this problem by specifying the ending address of the register stack with
14871the @code{set rstack_high_address} command. The argument should be an
14872address, which you probably want to precede with @samp{0x} to specify in
14873hexadecimal.
104c1213 14874
8e04817f
AC
14875@kindex show rstack_high_address
14876@item show rstack_high_address
14877Display the current limit of the register stack, on AMD 29000 family
14878processors.
104c1213 14879
8e04817f 14880@end table
104c1213 14881
8e04817f
AC
14882@node Alpha
14883@subsection Alpha
104c1213 14884
8e04817f 14885See the following section.
104c1213 14886
8e04817f
AC
14887@node MIPS
14888@subsection MIPS
104c1213 14889
8e04817f
AC
14890@cindex stack on Alpha
14891@cindex stack on MIPS
14892@cindex Alpha stack
14893@cindex MIPS stack
14894Alpha- and MIPS-based computers use an unusual stack frame, which
14895sometimes requires @value{GDBN} to search backward in the object code to
14896find the beginning of a function.
104c1213 14897
8e04817f
AC
14898@cindex response time, MIPS debugging
14899To improve response time (especially for embedded applications, where
14900@value{GDBN} may be restricted to a slow serial line for this search)
14901you may want to limit the size of this search, using one of these
14902commands:
104c1213 14903
8e04817f
AC
14904@table @code
14905@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14906@item set heuristic-fence-post @var{limit}
14907Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14908search for the beginning of a function. A value of @var{0} (the
14909default) means there is no limit. However, except for @var{0}, the
14910larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14911and therefore the longer it takes to run. You should only need to use
14912this command when debugging a stripped executable.
104c1213 14913
8e04817f
AC
14914@item show heuristic-fence-post
14915Display the current limit.
14916@end table
104c1213
JM
14917
14918@noindent
8e04817f
AC
14919These commands are available @emph{only} when @value{GDBN} is configured
14920for debugging programs on Alpha or MIPS processors.
104c1213 14921
a64548ea
EZ
14922Several MIPS-specific commands are available when debugging MIPS
14923programs:
14924
14925@table @code
14926@item set mips saved-gpreg-size @var{size}
14927@kindex set mips saved-gpreg-size
14928@cindex MIPS GP register size on stack
14929Set the size of MIPS general-purpose registers saved on the stack.
14930The argument @var{size} can be one of the following:
14931
14932@table @samp
14933@item 32
1493432-bit GP registers
14935@item 64
1493664-bit GP registers
14937@item auto
14938Use the target's default setting or autodetect the saved size from the
14939information contained in the executable. This is the default
14940@end table
14941
14942@item show mips saved-gpreg-size
14943@kindex show mips saved-gpreg-size
14944Show the current size of MIPS GP registers on the stack.
14945
14946@item set mips stack-arg-size @var{size}
14947@kindex set mips stack-arg-size
14948@cindex MIPS stack space for arguments
14949Set the amount of stack space reserved for arguments to functions.
14950The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14951(the default).
14952
14953@item set mips abi @var{arg}
14954@kindex set mips abi
14955@cindex set ABI for MIPS
14956Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14957values of @var{arg} are:
14958
14959@table @samp
14960@item auto
14961The default ABI associated with the current binary (this is the
14962default).
14963@item o32
14964@item o64
14965@item n32
14966@item n64
14967@item eabi32
14968@item eabi64
14969@item auto
14970@end table
14971
14972@item show mips abi
14973@kindex show mips abi
14974Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14975
14976@item set mipsfpu
14977@itemx show mipsfpu
14978@xref{MIPS Embedded, set mipsfpu}.
14979
14980@item set mips mask-address @var{arg}
14981@kindex set mips mask-address
14982@cindex MIPS addresses, masking
14983This command determines whether the most-significant 32 bits of 64-bit
14984MIPS addresses are masked off. The argument @var{arg} can be
14985@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14986setting, which lets @value{GDBN} determine the correct value.
14987
14988@item show mips mask-address
14989@kindex show mips mask-address
14990Show whether the upper 32 bits of MIPS addresses are masked off or
14991not.
14992
14993@item set remote-mips64-transfers-32bit-regs
14994@kindex set remote-mips64-transfers-32bit-regs
14995This command controls compatibility with 64-bit MIPS targets that
14996transfer data in 32-bit quantities. If you have an old MIPS 64 target
14997that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14998and 64 bits for other registers, set this option to @samp{on}.
14999
15000@item show remote-mips64-transfers-32bit-regs
15001@kindex show remote-mips64-transfers-32bit-regs
15002Show the current setting of compatibility with older MIPS 64 targets.
15003
15004@item set debug mips
15005@kindex set debug mips
15006This command turns on and off debugging messages for the MIPS-specific
15007target code in @value{GDBN}.
15008
15009@item show debug mips
15010@kindex show debug mips
15011Show the current setting of MIPS debugging messages.
15012@end table
15013
15014
15015@node HPPA
15016@subsection HPPA
15017@cindex HPPA support
15018
15019When @value{GDBN} is debugging te HP PA architecture, it provides the
15020following special commands:
15021
15022@table @code
15023@item set debug hppa
15024@kindex set debug hppa
15025THis command determines whether HPPA architecture specific debugging
15026messages are to be displayed.
15027
15028@item show debug hppa
15029Show whether HPPA debugging messages are displayed.
15030
15031@item maint print unwind @var{address}
15032@kindex maint print unwind@r{, HPPA}
15033This command displays the contents of the unwind table entry at the
15034given @var{address}.
15035
15036@end table
15037
104c1213 15038
8e04817f
AC
15039@node Controlling GDB
15040@chapter Controlling @value{GDBN}
15041
15042You can alter the way @value{GDBN} interacts with you by using the
15043@code{set} command. For commands controlling how @value{GDBN} displays
15044data, see @ref{Print Settings, ,Print settings}. Other settings are
15045described here.
15046
15047@menu
15048* Prompt:: Prompt
15049* Editing:: Command editing
d620b259 15050* Command History:: Command history
8e04817f
AC
15051* Screen Size:: Screen size
15052* Numbers:: Numbers
1e698235 15053* ABI:: Configuring the current ABI
8e04817f
AC
15054* Messages/Warnings:: Optional warnings and messages
15055* Debugging Output:: Optional messages about internal happenings
15056@end menu
15057
15058@node Prompt
15059@section Prompt
104c1213 15060
8e04817f 15061@cindex prompt
104c1213 15062
8e04817f
AC
15063@value{GDBN} indicates its readiness to read a command by printing a string
15064called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15065can change the prompt string with the @code{set prompt} command. For
15066instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15067the prompt in one of the @value{GDBN} sessions so that you can always tell
15068which one you are talking to.
104c1213 15069
8e04817f
AC
15070@emph{Note:} @code{set prompt} does not add a space for you after the
15071prompt you set. This allows you to set a prompt which ends in a space
15072or a prompt that does not.
104c1213 15073
8e04817f
AC
15074@table @code
15075@kindex set prompt
15076@item set prompt @var{newprompt}
15077Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15078
8e04817f
AC
15079@kindex show prompt
15080@item show prompt
15081Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15082@end table
15083
8e04817f
AC
15084@node Editing
15085@section Command editing
15086@cindex readline
15087@cindex command line editing
104c1213 15088
703663ab 15089@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15090@sc{gnu} library provides consistent behavior for programs which provide a
15091command line interface to the user. Advantages are @sc{gnu} Emacs-style
15092or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15093substitution, and a storage and recall of command history across
15094debugging sessions.
104c1213 15095
8e04817f
AC
15096You may control the behavior of command line editing in @value{GDBN} with the
15097command @code{set}.
104c1213 15098
8e04817f
AC
15099@table @code
15100@kindex set editing
15101@cindex editing
15102@item set editing
15103@itemx set editing on
15104Enable command line editing (enabled by default).
104c1213 15105
8e04817f
AC
15106@item set editing off
15107Disable command line editing.
104c1213 15108
8e04817f
AC
15109@kindex show editing
15110@item show editing
15111Show whether command line editing is enabled.
104c1213
JM
15112@end table
15113
703663ab
EZ
15114@xref{Command Line Editing}, for more details about the Readline
15115interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15116encouraged to read that chapter.
15117
d620b259 15118@node Command History
8e04817f 15119@section Command history
703663ab 15120@cindex command history
8e04817f
AC
15121
15122@value{GDBN} can keep track of the commands you type during your
15123debugging sessions, so that you can be certain of precisely what
15124happened. Use these commands to manage the @value{GDBN} command
15125history facility.
104c1213 15126
703663ab
EZ
15127@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15128package, to provide the history facility. @xref{Using History
15129Interactively}, for the detailed description of the History library.
15130
d620b259
NR
15131To issue a command to @value{GDBN} without affecting certain aspects of
15132the state which is seen by users, prefix it with @samp{server }. This
15133means that this command will not affect the command history, nor will it
15134affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15135pressed on a line by itself.
15136
15137@cindex @code{server}, command prefix
15138The server prefix does not affect the recording of values into the value
15139history; to print a value without recording it into the value history,
15140use the @code{output} command instead of the @code{print} command.
15141
703663ab
EZ
15142Here is the description of @value{GDBN} commands related to command
15143history.
15144
104c1213 15145@table @code
8e04817f
AC
15146@cindex history substitution
15147@cindex history file
15148@kindex set history filename
4644b6e3 15149@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15150@item set history filename @var{fname}
15151Set the name of the @value{GDBN} command history file to @var{fname}.
15152This is the file where @value{GDBN} reads an initial command history
15153list, and where it writes the command history from this session when it
15154exits. You can access this list through history expansion or through
15155the history command editing characters listed below. This file defaults
15156to the value of the environment variable @code{GDBHISTFILE}, or to
15157@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15158is not set.
104c1213 15159
9c16f35a
EZ
15160@cindex save command history
15161@kindex set history save
8e04817f
AC
15162@item set history save
15163@itemx set history save on
15164Record command history in a file, whose name may be specified with the
15165@code{set history filename} command. By default, this option is disabled.
104c1213 15166
8e04817f
AC
15167@item set history save off
15168Stop recording command history in a file.
104c1213 15169
8e04817f 15170@cindex history size
9c16f35a 15171@kindex set history size
6fc08d32 15172@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15173@item set history size @var{size}
15174Set the number of commands which @value{GDBN} keeps in its history list.
15175This defaults to the value of the environment variable
15176@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15177@end table
15178
8e04817f 15179History expansion assigns special meaning to the character @kbd{!}.
703663ab 15180@xref{Event Designators}, for more details.
8e04817f 15181
703663ab 15182@cindex history expansion, turn on/off
8e04817f
AC
15183Since @kbd{!} is also the logical not operator in C, history expansion
15184is off by default. If you decide to enable history expansion with the
15185@code{set history expansion on} command, you may sometimes need to
15186follow @kbd{!} (when it is used as logical not, in an expression) with
15187a space or a tab to prevent it from being expanded. The readline
15188history facilities do not attempt substitution on the strings
15189@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15190
15191The commands to control history expansion are:
104c1213
JM
15192
15193@table @code
8e04817f
AC
15194@item set history expansion on
15195@itemx set history expansion
703663ab 15196@kindex set history expansion
8e04817f 15197Enable history expansion. History expansion is off by default.
104c1213 15198
8e04817f
AC
15199@item set history expansion off
15200Disable history expansion.
104c1213 15201
8e04817f
AC
15202@c @group
15203@kindex show history
15204@item show history
15205@itemx show history filename
15206@itemx show history save
15207@itemx show history size
15208@itemx show history expansion
15209These commands display the state of the @value{GDBN} history parameters.
15210@code{show history} by itself displays all four states.
15211@c @end group
15212@end table
15213
15214@table @code
9c16f35a
EZ
15215@kindex show commands
15216@cindex show last commands
15217@cindex display command history
8e04817f
AC
15218@item show commands
15219Display the last ten commands in the command history.
104c1213 15220
8e04817f
AC
15221@item show commands @var{n}
15222Print ten commands centered on command number @var{n}.
15223
15224@item show commands +
15225Print ten commands just after the commands last printed.
104c1213
JM
15226@end table
15227
8e04817f
AC
15228@node Screen Size
15229@section Screen size
15230@cindex size of screen
15231@cindex pauses in output
104c1213 15232
8e04817f
AC
15233Certain commands to @value{GDBN} may produce large amounts of
15234information output to the screen. To help you read all of it,
15235@value{GDBN} pauses and asks you for input at the end of each page of
15236output. Type @key{RET} when you want to continue the output, or @kbd{q}
15237to discard the remaining output. Also, the screen width setting
15238determines when to wrap lines of output. Depending on what is being
15239printed, @value{GDBN} tries to break the line at a readable place,
15240rather than simply letting it overflow onto the following line.
15241
15242Normally @value{GDBN} knows the size of the screen from the terminal
15243driver software. For example, on Unix @value{GDBN} uses the termcap data base
15244together with the value of the @code{TERM} environment variable and the
15245@code{stty rows} and @code{stty cols} settings. If this is not correct,
15246you can override it with the @code{set height} and @code{set
15247width} commands:
15248
15249@table @code
15250@kindex set height
15251@kindex set width
15252@kindex show width
15253@kindex show height
15254@item set height @var{lpp}
15255@itemx show height
15256@itemx set width @var{cpl}
15257@itemx show width
15258These @code{set} commands specify a screen height of @var{lpp} lines and
15259a screen width of @var{cpl} characters. The associated @code{show}
15260commands display the current settings.
104c1213 15261
8e04817f
AC
15262If you specify a height of zero lines, @value{GDBN} does not pause during
15263output no matter how long the output is. This is useful if output is to a
15264file or to an editor buffer.
104c1213 15265
8e04817f
AC
15266Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15267from wrapping its output.
9c16f35a
EZ
15268
15269@item set pagination on
15270@itemx set pagination off
15271@kindex set pagination
15272Turn the output pagination on or off; the default is on. Turning
15273pagination off is the alternative to @code{set height 0}.
15274
15275@item show pagination
15276@kindex show pagination
15277Show the current pagination mode.
104c1213
JM
15278@end table
15279
8e04817f
AC
15280@node Numbers
15281@section Numbers
15282@cindex number representation
15283@cindex entering numbers
104c1213 15284
8e04817f
AC
15285You can always enter numbers in octal, decimal, or hexadecimal in
15286@value{GDBN} by the usual conventions: octal numbers begin with
15287@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15288begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15289@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1529010; likewise, the default display for numbers---when no particular
15291format is specified---is base 10. You can change the default base for
15292both input and output with the commands described below.
104c1213 15293
8e04817f
AC
15294@table @code
15295@kindex set input-radix
15296@item set input-radix @var{base}
15297Set the default base for numeric input. Supported choices
15298for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15299specified either unambiguously or using the current input radix; for
8e04817f 15300example, any of
104c1213 15301
8e04817f 15302@smallexample
9c16f35a
EZ
15303set input-radix 012
15304set input-radix 10.
15305set input-radix 0xa
8e04817f 15306@end smallexample
104c1213 15307
8e04817f 15308@noindent
9c16f35a 15309sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15310leaves the input radix unchanged, no matter what it was, since
15311@samp{10}, being without any leading or trailing signs of its base, is
15312interpreted in the current radix. Thus, if the current radix is 16,
15313@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15314change the radix.
104c1213 15315
8e04817f
AC
15316@kindex set output-radix
15317@item set output-radix @var{base}
15318Set the default base for numeric display. Supported choices
15319for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15320specified either unambiguously or using the current input radix.
104c1213 15321
8e04817f
AC
15322@kindex show input-radix
15323@item show input-radix
15324Display the current default base for numeric input.
104c1213 15325
8e04817f
AC
15326@kindex show output-radix
15327@item show output-radix
15328Display the current default base for numeric display.
9c16f35a
EZ
15329
15330@item set radix @r{[}@var{base}@r{]}
15331@itemx show radix
15332@kindex set radix
15333@kindex show radix
15334These commands set and show the default base for both input and output
15335of numbers. @code{set radix} sets the radix of input and output to
15336the same base; without an argument, it resets the radix back to its
15337default value of 10.
15338
8e04817f 15339@end table
104c1213 15340
1e698235
DJ
15341@node ABI
15342@section Configuring the current ABI
15343
15344@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15345application automatically. However, sometimes you need to override its
15346conclusions. Use these commands to manage @value{GDBN}'s view of the
15347current ABI.
15348
98b45e30
DJ
15349@cindex OS ABI
15350@kindex set osabi
b4e9345d 15351@kindex show osabi
98b45e30
DJ
15352
15353One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15354system targets, either via remote debugging or native emulation.
98b45e30
DJ
15355@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15356but you can override its conclusion using the @code{set osabi} command.
15357One example where this is useful is in debugging of binaries which use
15358an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15359not have the same identifying marks that the standard C library for your
15360platform provides.
15361
15362@table @code
15363@item show osabi
15364Show the OS ABI currently in use.
15365
15366@item set osabi
15367With no argument, show the list of registered available OS ABI's.
15368
15369@item set osabi @var{abi}
15370Set the current OS ABI to @var{abi}.
15371@end table
15372
1e698235 15373@cindex float promotion
1e698235
DJ
15374
15375Generally, the way that an argument of type @code{float} is passed to a
15376function depends on whether the function is prototyped. For a prototyped
15377(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15378according to the architecture's convention for @code{float}. For unprototyped
15379(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15380@code{double} and then passed.
15381
15382Unfortunately, some forms of debug information do not reliably indicate whether
15383a function is prototyped. If @value{GDBN} calls a function that is not marked
15384as prototyped, it consults @kbd{set coerce-float-to-double}.
15385
15386@table @code
a8f24a35 15387@kindex set coerce-float-to-double
1e698235
DJ
15388@item set coerce-float-to-double
15389@itemx set coerce-float-to-double on
15390Arguments of type @code{float} will be promoted to @code{double} when passed
15391to an unprototyped function. This is the default setting.
15392
15393@item set coerce-float-to-double off
15394Arguments of type @code{float} will be passed directly to unprototyped
15395functions.
9c16f35a
EZ
15396
15397@kindex show coerce-float-to-double
15398@item show coerce-float-to-double
15399Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15400@end table
15401
f1212245
DJ
15402@kindex set cp-abi
15403@kindex show cp-abi
15404@value{GDBN} needs to know the ABI used for your program's C@t{++}
15405objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15406used to build your application. @value{GDBN} only fully supports
15407programs with a single C@t{++} ABI; if your program contains code using
15408multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15409program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15410Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15411before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15412``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15413use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15414``auto''.
15415
15416@table @code
15417@item show cp-abi
15418Show the C@t{++} ABI currently in use.
15419
15420@item set cp-abi
15421With no argument, show the list of supported C@t{++} ABI's.
15422
15423@item set cp-abi @var{abi}
15424@itemx set cp-abi auto
15425Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15426@end table
15427
8e04817f
AC
15428@node Messages/Warnings
15429@section Optional warnings and messages
104c1213 15430
9c16f35a
EZ
15431@cindex verbose operation
15432@cindex optional warnings
8e04817f
AC
15433By default, @value{GDBN} is silent about its inner workings. If you are
15434running on a slow machine, you may want to use the @code{set verbose}
15435command. This makes @value{GDBN} tell you when it does a lengthy
15436internal operation, so you will not think it has crashed.
104c1213 15437
8e04817f
AC
15438Currently, the messages controlled by @code{set verbose} are those
15439which announce that the symbol table for a source file is being read;
15440see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15441
8e04817f
AC
15442@table @code
15443@kindex set verbose
15444@item set verbose on
15445Enables @value{GDBN} output of certain informational messages.
104c1213 15446
8e04817f
AC
15447@item set verbose off
15448Disables @value{GDBN} output of certain informational messages.
104c1213 15449
8e04817f
AC
15450@kindex show verbose
15451@item show verbose
15452Displays whether @code{set verbose} is on or off.
15453@end table
104c1213 15454
8e04817f
AC
15455By default, if @value{GDBN} encounters bugs in the symbol table of an
15456object file, it is silent; but if you are debugging a compiler, you may
15457find this information useful (@pxref{Symbol Errors, ,Errors reading
15458symbol files}).
104c1213 15459
8e04817f 15460@table @code
104c1213 15461
8e04817f
AC
15462@kindex set complaints
15463@item set complaints @var{limit}
15464Permits @value{GDBN} to output @var{limit} complaints about each type of
15465unusual symbols before becoming silent about the problem. Set
15466@var{limit} to zero to suppress all complaints; set it to a large number
15467to prevent complaints from being suppressed.
104c1213 15468
8e04817f
AC
15469@kindex show complaints
15470@item show complaints
15471Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15472
8e04817f 15473@end table
104c1213 15474
8e04817f
AC
15475By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15476lot of stupid questions to confirm certain commands. For example, if
15477you try to run a program which is already running:
104c1213 15478
474c8240 15479@smallexample
8e04817f
AC
15480(@value{GDBP}) run
15481The program being debugged has been started already.
15482Start it from the beginning? (y or n)
474c8240 15483@end smallexample
104c1213 15484
8e04817f
AC
15485If you are willing to unflinchingly face the consequences of your own
15486commands, you can disable this ``feature'':
104c1213 15487
8e04817f 15488@table @code
104c1213 15489
8e04817f
AC
15490@kindex set confirm
15491@cindex flinching
15492@cindex confirmation
15493@cindex stupid questions
15494@item set confirm off
15495Disables confirmation requests.
104c1213 15496
8e04817f
AC
15497@item set confirm on
15498Enables confirmation requests (the default).
104c1213 15499
8e04817f
AC
15500@kindex show confirm
15501@item show confirm
15502Displays state of confirmation requests.
15503
15504@end table
104c1213 15505
8e04817f
AC
15506@node Debugging Output
15507@section Optional messages about internal happenings
4644b6e3
EZ
15508@cindex optional debugging messages
15509
da316a69
EZ
15510@value{GDBN} has commands that enable optional debugging messages from
15511various @value{GDBN} subsystems; normally these commands are of
15512interest to @value{GDBN} maintainers, or when reporting a bug. This
15513section documents those commands.
15514
104c1213 15515@table @code
a8f24a35
EZ
15516@kindex set exec-done-display
15517@item set exec-done-display
15518Turns on or off the notification of asynchronous commands'
15519completion. When on, @value{GDBN} will print a message when an
15520asynchronous command finishes its execution. The default is off.
15521@kindex show exec-done-display
15522@item show exec-done-display
15523Displays the current setting of asynchronous command completion
15524notification.
4644b6e3
EZ
15525@kindex set debug
15526@cindex gdbarch debugging info
a8f24a35 15527@cindex architecture debugging info
8e04817f 15528@item set debug arch
a8f24a35 15529Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15530@kindex show debug
8e04817f
AC
15531@item show debug arch
15532Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15533@item set debug aix-thread
15534@cindex AIX threads
15535Display debugging messages about inner workings of the AIX thread
15536module.
15537@item show debug aix-thread
15538Show the current state of AIX thread debugging info display.
8e04817f 15539@item set debug event
4644b6e3 15540@cindex event debugging info
a8f24a35 15541Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15542default is off.
8e04817f
AC
15543@item show debug event
15544Displays the current state of displaying @value{GDBN} event debugging
15545info.
8e04817f 15546@item set debug expression
4644b6e3 15547@cindex expression debugging info
721c2651
EZ
15548Turns on or off display of debugging info about @value{GDBN}
15549expression parsing. The default is off.
8e04817f 15550@item show debug expression
721c2651
EZ
15551Displays the current state of displaying debugging info about
15552@value{GDBN} expression parsing.
7453dc06 15553@item set debug frame
4644b6e3 15554@cindex frame debugging info
7453dc06
AC
15555Turns on or off display of @value{GDBN} frame debugging info. The
15556default is off.
7453dc06
AC
15557@item show debug frame
15558Displays the current state of displaying @value{GDBN} frame debugging
15559info.
30e91e0b
RC
15560@item set debug infrun
15561@cindex inferior debugging info
15562Turns on or off display of @value{GDBN} debugging info for running the inferior.
15563The default is off. @file{infrun.c} contains GDB's runtime state machine used
15564for implementing operations such as single-stepping the inferior.
15565@item show debug infrun
15566Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15567@item set debug lin-lwp
15568@cindex @sc{gnu}/Linux LWP debug messages
15569@cindex Linux lightweight processes
721c2651 15570Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15571@item show debug lin-lwp
15572Show the current state of Linux LWP debugging messages.
2b4855ab 15573@item set debug observer
4644b6e3 15574@cindex observer debugging info
2b4855ab
AC
15575Turns on or off display of @value{GDBN} observer debugging. This
15576includes info such as the notification of observable events.
2b4855ab
AC
15577@item show debug observer
15578Displays the current state of observer debugging.
8e04817f 15579@item set debug overload
4644b6e3 15580@cindex C@t{++} overload debugging info
8e04817f
AC
15581Turns on or off display of @value{GDBN} C@t{++} overload debugging
15582info. This includes info such as ranking of functions, etc. The default
15583is off.
8e04817f
AC
15584@item show debug overload
15585Displays the current state of displaying @value{GDBN} C@t{++} overload
15586debugging info.
8e04817f
AC
15587@cindex packets, reporting on stdout
15588@cindex serial connections, debugging
15589@item set debug remote
15590Turns on or off display of reports on all packets sent back and forth across
15591the serial line to the remote machine. The info is printed on the
15592@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15593@item show debug remote
15594Displays the state of display of remote packets.
8e04817f
AC
15595@item set debug serial
15596Turns on or off display of @value{GDBN} serial debugging info. The
15597default is off.
8e04817f
AC
15598@item show debug serial
15599Displays the current state of displaying @value{GDBN} serial debugging
15600info.
c45da7e6
EZ
15601@item set debug solib-frv
15602@cindex FR-V shared-library debugging
15603Turns on or off debugging messages for FR-V shared-library code.
15604@item show debug solib-frv
15605Display the current state of FR-V shared-library code debugging
15606messages.
8e04817f 15607@item set debug target
4644b6e3 15608@cindex target debugging info
8e04817f
AC
15609Turns on or off display of @value{GDBN} target debugging info. This info
15610includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15611default is 0. Set it to 1 to track events, and to 2 to also track the
15612value of large memory transfers. Changes to this flag do not take effect
15613until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15614@item show debug target
15615Displays the current state of displaying @value{GDBN} target debugging
15616info.
c45da7e6 15617@item set debugvarobj
4644b6e3 15618@cindex variable object debugging info
8e04817f
AC
15619Turns on or off display of @value{GDBN} variable object debugging
15620info. The default is off.
c45da7e6 15621@item show debugvarobj
8e04817f
AC
15622Displays the current state of displaying @value{GDBN} variable object
15623debugging info.
15624@end table
104c1213 15625
8e04817f
AC
15626@node Sequences
15627@chapter Canned Sequences of Commands
104c1213 15628
8e04817f
AC
15629Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15630command lists}), @value{GDBN} provides two ways to store sequences of
15631commands for execution as a unit: user-defined commands and command
15632files.
104c1213 15633
8e04817f
AC
15634@menu
15635* Define:: User-defined commands
15636* Hooks:: User-defined command hooks
15637* Command Files:: Command files
15638* Output:: Commands for controlled output
15639@end menu
104c1213 15640
8e04817f
AC
15641@node Define
15642@section User-defined commands
104c1213 15643
8e04817f
AC
15644@cindex user-defined command
15645A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15646which you assign a new name as a command. This is done with the
15647@code{define} command. User commands may accept up to 10 arguments
15648separated by whitespace. Arguments are accessed within the user command
15649via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15650
8e04817f
AC
15651@smallexample
15652define adder
15653 print $arg0 + $arg1 + $arg2
15654@end smallexample
104c1213
JM
15655
15656@noindent
8e04817f 15657To execute the command use:
104c1213 15658
8e04817f
AC
15659@smallexample
15660adder 1 2 3
15661@end smallexample
104c1213 15662
8e04817f
AC
15663@noindent
15664This defines the command @code{adder}, which prints the sum of
15665its three arguments. Note the arguments are text substitutions, so they may
15666reference variables, use complex expressions, or even perform inferior
15667functions calls.
104c1213
JM
15668
15669@table @code
104c1213 15670
8e04817f
AC
15671@kindex define
15672@item define @var{commandname}
15673Define a command named @var{commandname}. If there is already a command
15674by that name, you are asked to confirm that you want to redefine it.
104c1213 15675
8e04817f
AC
15676The definition of the command is made up of other @value{GDBN} command lines,
15677which are given following the @code{define} command. The end of these
15678commands is marked by a line containing @code{end}.
104c1213 15679
8e04817f
AC
15680@kindex if
15681@kindex else
15682@item if
09d4efe1 15683@itemx else
8e04817f
AC
15684Takes a single argument, which is an expression to evaluate.
15685It is followed by a series of commands that are executed
15686only if the expression is true (nonzero).
15687There can then optionally be a line @code{else}, followed
15688by a series of commands that are only executed if the expression
15689was false. The end of the list is marked by a line containing @code{end}.
104c1213 15690
8e04817f
AC
15691@kindex while
15692@item while
15693The syntax is similar to @code{if}: the command takes a single argument,
15694which is an expression to evaluate, and must be followed by the commands to
15695execute, one per line, terminated by an @code{end}.
15696The commands are executed repeatedly as long as the expression
15697evaluates to true.
104c1213 15698
8e04817f
AC
15699@kindex document
15700@item document @var{commandname}
15701Document the user-defined command @var{commandname}, so that it can be
15702accessed by @code{help}. The command @var{commandname} must already be
15703defined. This command reads lines of documentation just as @code{define}
15704reads the lines of the command definition, ending with @code{end}.
15705After the @code{document} command is finished, @code{help} on command
15706@var{commandname} displays the documentation you have written.
104c1213 15707
8e04817f
AC
15708You may use the @code{document} command again to change the
15709documentation of a command. Redefining the command with @code{define}
15710does not change the documentation.
104c1213 15711
c45da7e6
EZ
15712@kindex dont-repeat
15713@cindex don't repeat command
15714@item dont-repeat
15715Used inside a user-defined command, this tells @value{GDBN} that this
15716command should not be repeated when the user hits @key{RET}
15717(@pxref{Command Syntax, repeat last command}).
15718
8e04817f
AC
15719@kindex help user-defined
15720@item help user-defined
15721List all user-defined commands, with the first line of the documentation
15722(if any) for each.
104c1213 15723
8e04817f
AC
15724@kindex show user
15725@item show user
15726@itemx show user @var{commandname}
15727Display the @value{GDBN} commands used to define @var{commandname} (but
15728not its documentation). If no @var{commandname} is given, display the
15729definitions for all user-defined commands.
104c1213 15730
9c16f35a 15731@cindex infinite recusrion in user-defined commands
20f01a46
DH
15732@kindex show max-user-call-depth
15733@kindex set max-user-call-depth
15734@item show max-user-call-depth
5ca0cb28
DH
15735@itemx set max-user-call-depth
15736The value of @code{max-user-call-depth} controls how many recursion
15737levels are allowed in user-defined commands before GDB suspects an
15738infinite recursion and aborts the command.
20f01a46 15739
104c1213
JM
15740@end table
15741
8e04817f
AC
15742When user-defined commands are executed, the
15743commands of the definition are not printed. An error in any command
15744stops execution of the user-defined command.
104c1213 15745
8e04817f
AC
15746If used interactively, commands that would ask for confirmation proceed
15747without asking when used inside a user-defined command. Many @value{GDBN}
15748commands that normally print messages to say what they are doing omit the
15749messages when used in a user-defined command.
104c1213 15750
8e04817f
AC
15751@node Hooks
15752@section User-defined command hooks
15753@cindex command hooks
15754@cindex hooks, for commands
15755@cindex hooks, pre-command
104c1213 15756
8e04817f 15757@kindex hook
8e04817f
AC
15758You may define @dfn{hooks}, which are a special kind of user-defined
15759command. Whenever you run the command @samp{foo}, if the user-defined
15760command @samp{hook-foo} exists, it is executed (with no arguments)
15761before that command.
104c1213 15762
8e04817f
AC
15763@cindex hooks, post-command
15764@kindex hookpost
8e04817f
AC
15765A hook may also be defined which is run after the command you executed.
15766Whenever you run the command @samp{foo}, if the user-defined command
15767@samp{hookpost-foo} exists, it is executed (with no arguments) after
15768that command. Post-execution hooks may exist simultaneously with
15769pre-execution hooks, for the same command.
104c1213 15770
8e04817f 15771It is valid for a hook to call the command which it hooks. If this
9f1c6395 15772occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15773
8e04817f
AC
15774@c It would be nice if hookpost could be passed a parameter indicating
15775@c if the command it hooks executed properly or not. FIXME!
104c1213 15776
8e04817f
AC
15777@kindex stop@r{, a pseudo-command}
15778In addition, a pseudo-command, @samp{stop} exists. Defining
15779(@samp{hook-stop}) makes the associated commands execute every time
15780execution stops in your program: before breakpoint commands are run,
15781displays are printed, or the stack frame is printed.
104c1213 15782
8e04817f
AC
15783For example, to ignore @code{SIGALRM} signals while
15784single-stepping, but treat them normally during normal execution,
15785you could define:
104c1213 15786
474c8240 15787@smallexample
8e04817f
AC
15788define hook-stop
15789handle SIGALRM nopass
15790end
104c1213 15791
8e04817f
AC
15792define hook-run
15793handle SIGALRM pass
15794end
104c1213 15795
8e04817f
AC
15796define hook-continue
15797handle SIGLARM pass
15798end
474c8240 15799@end smallexample
104c1213 15800
8e04817f 15801As a further example, to hook at the begining and end of the @code{echo}
b383017d 15802command, and to add extra text to the beginning and end of the message,
8e04817f 15803you could define:
104c1213 15804
474c8240 15805@smallexample
8e04817f
AC
15806define hook-echo
15807echo <<<---
15808end
104c1213 15809
8e04817f
AC
15810define hookpost-echo
15811echo --->>>\n
15812end
104c1213 15813
8e04817f
AC
15814(@value{GDBP}) echo Hello World
15815<<<---Hello World--->>>
15816(@value{GDBP})
104c1213 15817
474c8240 15818@end smallexample
104c1213 15819
8e04817f
AC
15820You can define a hook for any single-word command in @value{GDBN}, but
15821not for command aliases; you should define a hook for the basic command
15822name, e.g. @code{backtrace} rather than @code{bt}.
15823@c FIXME! So how does Joe User discover whether a command is an alias
15824@c or not?
15825If an error occurs during the execution of your hook, execution of
15826@value{GDBN} commands stops and @value{GDBN} issues a prompt
15827(before the command that you actually typed had a chance to run).
104c1213 15828
8e04817f
AC
15829If you try to define a hook which does not match any known command, you
15830get a warning from the @code{define} command.
c906108c 15831
8e04817f
AC
15832@node Command Files
15833@section Command files
c906108c 15834
8e04817f 15835@cindex command files
6fc08d32
EZ
15836A command file for @value{GDBN} is a text file made of lines that are
15837@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15838also be included. An empty line in a command file does nothing; it
15839does not mean to repeat the last command, as it would from the
15840terminal.
c906108c 15841
6fc08d32
EZ
15842You can request the execution of a command file with the @code{source}
15843command:
c906108c 15844
8e04817f
AC
15845@table @code
15846@kindex source
15847@item source @var{filename}
15848Execute the command file @var{filename}.
c906108c
SS
15849@end table
15850
8e04817f 15851The lines in a command file are executed sequentially. They are not
a71ec265
DH
15852printed as they are executed. An error in any command terminates
15853execution of the command file and control is returned to the console.
c906108c 15854
8e04817f
AC
15855Commands that would ask for confirmation if used interactively proceed
15856without asking when used in a command file. Many @value{GDBN} commands that
15857normally print messages to say what they are doing omit the messages
15858when called from command files.
c906108c 15859
8e04817f
AC
15860@value{GDBN} also accepts command input from standard input. In this
15861mode, normal output goes to standard output and error output goes to
15862standard error. Errors in a command file supplied on standard input do
6fc08d32 15863not terminate execution of the command file---execution continues with
8e04817f 15864the next command.
c906108c 15865
474c8240 15866@smallexample
8e04817f 15867gdb < cmds > log 2>&1
474c8240 15868@end smallexample
c906108c 15869
8e04817f
AC
15870(The syntax above will vary depending on the shell used.) This example
15871will execute commands from the file @file{cmds}. All output and errors
15872would be directed to @file{log}.
c906108c 15873
8e04817f
AC
15874@node Output
15875@section Commands for controlled output
c906108c 15876
8e04817f
AC
15877During the execution of a command file or a user-defined command, normal
15878@value{GDBN} output is suppressed; the only output that appears is what is
15879explicitly printed by the commands in the definition. This section
15880describes three commands useful for generating exactly the output you
15881want.
c906108c
SS
15882
15883@table @code
8e04817f
AC
15884@kindex echo
15885@item echo @var{text}
15886@c I do not consider backslash-space a standard C escape sequence
15887@c because it is not in ANSI.
15888Print @var{text}. Nonprinting characters can be included in
15889@var{text} using C escape sequences, such as @samp{\n} to print a
15890newline. @strong{No newline is printed unless you specify one.}
15891In addition to the standard C escape sequences, a backslash followed
15892by a space stands for a space. This is useful for displaying a
15893string with spaces at the beginning or the end, since leading and
15894trailing spaces are otherwise trimmed from all arguments.
15895To print @samp{@w{ }and foo =@w{ }}, use the command
15896@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15897
8e04817f
AC
15898A backslash at the end of @var{text} can be used, as in C, to continue
15899the command onto subsequent lines. For example,
c906108c 15900
474c8240 15901@smallexample
8e04817f
AC
15902echo This is some text\n\
15903which is continued\n\
15904onto several lines.\n
474c8240 15905@end smallexample
c906108c 15906
8e04817f 15907produces the same output as
c906108c 15908
474c8240 15909@smallexample
8e04817f
AC
15910echo This is some text\n
15911echo which is continued\n
15912echo onto several lines.\n
474c8240 15913@end smallexample
c906108c 15914
8e04817f
AC
15915@kindex output
15916@item output @var{expression}
15917Print the value of @var{expression} and nothing but that value: no
15918newlines, no @samp{$@var{nn} = }. The value is not entered in the
15919value history either. @xref{Expressions, ,Expressions}, for more information
15920on expressions.
c906108c 15921
8e04817f
AC
15922@item output/@var{fmt} @var{expression}
15923Print the value of @var{expression} in format @var{fmt}. You can use
15924the same formats as for @code{print}. @xref{Output Formats,,Output
15925formats}, for more information.
c906108c 15926
8e04817f
AC
15927@kindex printf
15928@item printf @var{string}, @var{expressions}@dots{}
15929Print the values of the @var{expressions} under the control of
15930@var{string}. The @var{expressions} are separated by commas and may be
15931either numbers or pointers. Their values are printed as specified by
15932@var{string}, exactly as if your program were to execute the C
15933subroutine
15934@c FIXME: the above implies that at least all ANSI C formats are
15935@c supported, but it isn't true: %E and %G don't work (or so it seems).
15936@c Either this is a bug, or the manual should document what formats are
15937@c supported.
c906108c 15938
474c8240 15939@smallexample
8e04817f 15940printf (@var{string}, @var{expressions}@dots{});
474c8240 15941@end smallexample
c906108c 15942
8e04817f 15943For example, you can print two values in hex like this:
c906108c 15944
8e04817f
AC
15945@smallexample
15946printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15947@end smallexample
c906108c 15948
8e04817f
AC
15949The only backslash-escape sequences that you can use in the format
15950string are the simple ones that consist of backslash followed by a
15951letter.
c906108c
SS
15952@end table
15953
21c294e6
AC
15954@node Interpreters
15955@chapter Command Interpreters
15956@cindex command interpreters
15957
15958@value{GDBN} supports multiple command interpreters, and some command
15959infrastructure to allow users or user interface writers to switch
15960between interpreters or run commands in other interpreters.
15961
15962@value{GDBN} currently supports two command interpreters, the console
15963interpreter (sometimes called the command-line interpreter or @sc{cli})
15964and the machine interface interpreter (or @sc{gdb/mi}). This manual
15965describes both of these interfaces in great detail.
15966
15967By default, @value{GDBN} will start with the console interpreter.
15968However, the user may choose to start @value{GDBN} with another
15969interpreter by specifying the @option{-i} or @option{--interpreter}
15970startup options. Defined interpreters include:
15971
15972@table @code
15973@item console
15974@cindex console interpreter
15975The traditional console or command-line interpreter. This is the most often
15976used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15977@value{GDBN} will use this interpreter.
15978
15979@item mi
15980@cindex mi interpreter
15981The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15982by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15983or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15984Interface}.
15985
15986@item mi2
15987@cindex mi2 interpreter
15988The current @sc{gdb/mi} interface.
15989
15990@item mi1
15991@cindex mi1 interpreter
15992The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15993
15994@end table
15995
15996@cindex invoke another interpreter
15997The interpreter being used by @value{GDBN} may not be dynamically
15998switched at runtime. Although possible, this could lead to a very
15999precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16000enters the command "interpreter-set console" in a console view,
16001@value{GDBN} would switch to using the console interpreter, rendering
16002the IDE inoperable!
16003
16004@kindex interpreter-exec
16005Although you may only choose a single interpreter at startup, you may execute
16006commands in any interpreter from the current interpreter using the appropriate
16007command. If you are running the console interpreter, simply use the
16008@code{interpreter-exec} command:
16009
16010@smallexample
16011interpreter-exec mi "-data-list-register-names"
16012@end smallexample
16013
16014@sc{gdb/mi} has a similar command, although it is only available in versions of
16015@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16016
8e04817f
AC
16017@node TUI
16018@chapter @value{GDBN} Text User Interface
16019@cindex TUI
d0d5df6f 16020@cindex Text User Interface
c906108c 16021
8e04817f
AC
16022@menu
16023* TUI Overview:: TUI overview
16024* TUI Keys:: TUI key bindings
7cf36c78 16025* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
16026* TUI Commands:: TUI specific commands
16027* TUI Configuration:: TUI configuration variables
16028@end menu
c906108c 16029
d0d5df6f
AC
16030The @value{GDBN} Text User Interface, TUI in short, is a terminal
16031interface which uses the @code{curses} library to show the source
16032file, the assembly output, the program registers and @value{GDBN}
16033commands in separate text windows.
16034
16035The TUI is enabled by invoking @value{GDBN} using either
16036@pindex gdbtui
16037@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16038
8e04817f
AC
16039@node TUI Overview
16040@section TUI overview
c906108c 16041
8e04817f
AC
16042The TUI has two display modes that can be switched while
16043@value{GDBN} runs:
c906108c 16044
8e04817f
AC
16045@itemize @bullet
16046@item
16047A curses (or TUI) mode in which it displays several text
16048windows on the terminal.
c906108c 16049
8e04817f
AC
16050@item
16051A standard mode which corresponds to the @value{GDBN} configured without
16052the TUI.
16053@end itemize
c906108c 16054
8e04817f
AC
16055In the TUI mode, @value{GDBN} can display several text window
16056on the terminal:
c906108c 16057
8e04817f
AC
16058@table @emph
16059@item command
16060This window is the @value{GDBN} command window with the @value{GDBN}
16061prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16062managed using readline but through the TUI. The @emph{command}
16063window is always visible.
c906108c 16064
8e04817f
AC
16065@item source
16066The source window shows the source file of the program. The current
16067line as well as active breakpoints are displayed in this window.
c906108c 16068
8e04817f
AC
16069@item assembly
16070The assembly window shows the disassembly output of the program.
c906108c 16071
8e04817f
AC
16072@item register
16073This window shows the processor registers. It detects when
16074a register is changed and when this is the case, registers that have
6a1b180d 16075changed are highlighted.
c906108c 16076
c906108c
SS
16077@end table
16078
269c21fe
SC
16079The source and assembly windows show the current program position
16080by highlighting the current line and marking them with the @samp{>} marker.
16081Breakpoints are also indicated with two markers. A first one
16082indicates the breakpoint type:
16083
16084@table @code
16085@item B
16086Breakpoint which was hit at least once.
16087
16088@item b
16089Breakpoint which was never hit.
16090
16091@item H
16092Hardware breakpoint which was hit at least once.
16093
16094@item h
16095Hardware breakpoint which was never hit.
16096
16097@end table
16098
16099The second marker indicates whether the breakpoint is enabled or not:
16100
16101@table @code
16102@item +
16103Breakpoint is enabled.
16104
16105@item -
16106Breakpoint is disabled.
16107
16108@end table
16109
8e04817f
AC
16110The source, assembly and register windows are attached to the thread
16111and the frame position. They are updated when the current thread
16112changes, when the frame changes or when the program counter changes.
16113These three windows are arranged by the TUI according to several
16114layouts. The layout defines which of these three windows are visible.
16115The following layouts are available:
c906108c 16116
8e04817f
AC
16117@itemize @bullet
16118@item
16119source
2df3850c 16120
8e04817f
AC
16121@item
16122assembly
16123
16124@item
16125source and assembly
16126
16127@item
16128source and registers
c906108c 16129
8e04817f
AC
16130@item
16131assembly and registers
2df3850c 16132
8e04817f 16133@end itemize
c906108c 16134
b7bb15bc
SC
16135On top of the command window a status line gives various information
16136concerning the current process begin debugged. The status line is
16137updated when the information it shows changes. The following fields
16138are displayed:
16139
16140@table @emph
16141@item target
16142Indicates the current gdb target
16143(@pxref{Targets, ,Specifying a Debugging Target}).
16144
16145@item process
16146Gives information about the current process or thread number.
16147When no process is being debugged, this field is set to @code{No process}.
16148
16149@item function
16150Gives the current function name for the selected frame.
16151The name is demangled if demangling is turned on (@pxref{Print Settings}).
16152When there is no symbol corresponding to the current program counter
16153the string @code{??} is displayed.
16154
16155@item line
16156Indicates the current line number for the selected frame.
16157When the current line number is not known the string @code{??} is displayed.
16158
16159@item pc
16160Indicates the current program counter address.
16161
16162@end table
16163
8e04817f
AC
16164@node TUI Keys
16165@section TUI Key Bindings
16166@cindex TUI key bindings
c906108c 16167
8e04817f
AC
16168The TUI installs several key bindings in the readline keymaps
16169(@pxref{Command Line Editing}).
16170They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16171directly on the TUI layout and windows. The TUI also provides
16172a @emph{SingleKey} keymap which binds several keys directly to
16173@value{GDBN} commands. The following key bindings
8e04817f 16174are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16175
8e04817f
AC
16176@table @kbd
16177@kindex C-x C-a
16178@item C-x C-a
16179@kindex C-x a
16180@itemx C-x a
16181@kindex C-x A
16182@itemx C-x A
16183Enter or leave the TUI mode. When the TUI mode is left,
16184the curses window management is left and @value{GDBN} operates using
16185its standard mode writing on the terminal directly. When the TUI
16186mode is entered, the control is given back to the curses windows.
16187The screen is then refreshed.
c906108c 16188
8e04817f
AC
16189@kindex C-x 1
16190@item C-x 1
16191Use a TUI layout with only one window. The layout will
16192either be @samp{source} or @samp{assembly}. When the TUI mode
16193is not active, it will switch to the TUI mode.
2df3850c 16194
8e04817f 16195Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16196
8e04817f
AC
16197@kindex C-x 2
16198@item C-x 2
16199Use a TUI layout with at least two windows. When the current
16200layout shows already two windows, a next layout with two windows is used.
16201When a new layout is chosen, one window will always be common to the
16202previous layout and the new one.
c906108c 16203
8e04817f 16204Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16205
72ffddc9
SC
16206@kindex C-x o
16207@item C-x o
16208Change the active window. The TUI associates several key bindings
16209(like scrolling and arrow keys) to the active window. This command
16210gives the focus to the next TUI window.
16211
16212Think of it as the Emacs @kbd{C-x o} binding.
16213
7cf36c78
SC
16214@kindex C-x s
16215@item C-x s
16216Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16217(@pxref{TUI Single Key Mode}).
16218
c906108c
SS
16219@end table
16220
8e04817f 16221The following key bindings are handled only by the TUI mode:
5d161b24 16222
8e04817f
AC
16223@table @key
16224@kindex PgUp
16225@item PgUp
16226Scroll the active window one page up.
c906108c 16227
8e04817f
AC
16228@kindex PgDn
16229@item PgDn
16230Scroll the active window one page down.
c906108c 16231
8e04817f
AC
16232@kindex Up
16233@item Up
16234Scroll the active window one line up.
c906108c 16235
8e04817f
AC
16236@kindex Down
16237@item Down
16238Scroll the active window one line down.
c906108c 16239
8e04817f
AC
16240@kindex Left
16241@item Left
16242Scroll the active window one column left.
c906108c 16243
8e04817f
AC
16244@kindex Right
16245@item Right
16246Scroll the active window one column right.
c906108c 16247
8e04817f
AC
16248@kindex C-L
16249@item C-L
16250Refresh the screen.
c906108c 16251
8e04817f 16252@end table
c906108c 16253
8e04817f 16254In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16255for scrolling. This means they are available for readline when the
16256active window is the command window. When the command window
16257does not have the focus, it is necessary to use other readline
16258key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16259
7cf36c78
SC
16260@node TUI Single Key Mode
16261@section TUI Single Key Mode
16262@cindex TUI single key mode
16263
16264The TUI provides a @emph{SingleKey} mode in which it installs a particular
16265key binding in the readline keymaps to connect single keys to
b383017d 16266some gdb commands.
7cf36c78
SC
16267
16268@table @kbd
16269@kindex c @r{(SingleKey TUI key)}
16270@item c
16271continue
16272
16273@kindex d @r{(SingleKey TUI key)}
16274@item d
16275down
16276
16277@kindex f @r{(SingleKey TUI key)}
16278@item f
16279finish
16280
16281@kindex n @r{(SingleKey TUI key)}
16282@item n
16283next
16284
16285@kindex q @r{(SingleKey TUI key)}
16286@item q
16287exit the @emph{SingleKey} mode.
16288
16289@kindex r @r{(SingleKey TUI key)}
16290@item r
16291run
16292
16293@kindex s @r{(SingleKey TUI key)}
16294@item s
16295step
16296
16297@kindex u @r{(SingleKey TUI key)}
16298@item u
16299up
16300
16301@kindex v @r{(SingleKey TUI key)}
16302@item v
16303info locals
16304
16305@kindex w @r{(SingleKey TUI key)}
16306@item w
16307where
16308
16309@end table
16310
16311Other keys temporarily switch to the @value{GDBN} command prompt.
16312The key that was pressed is inserted in the editing buffer so that
16313it is possible to type most @value{GDBN} commands without interaction
16314with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16315@emph{SingleKey} mode is restored. The only way to permanently leave
16316this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16317
16318
8e04817f
AC
16319@node TUI Commands
16320@section TUI specific commands
16321@cindex TUI commands
16322
16323The TUI has specific commands to control the text windows.
16324These commands are always available, that is they do not depend on
16325the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16326is in the standard mode, using these commands will automatically switch
16327in the TUI mode.
c906108c
SS
16328
16329@table @code
3d757584
SC
16330@item info win
16331@kindex info win
16332List and give the size of all displayed windows.
16333
8e04817f 16334@item layout next
4644b6e3 16335@kindex layout
8e04817f 16336Display the next layout.
2df3850c 16337
8e04817f 16338@item layout prev
8e04817f 16339Display the previous layout.
c906108c 16340
8e04817f 16341@item layout src
8e04817f 16342Display the source window only.
c906108c 16343
8e04817f 16344@item layout asm
8e04817f 16345Display the assembly window only.
c906108c 16346
8e04817f 16347@item layout split
8e04817f 16348Display the source and assembly window.
c906108c 16349
8e04817f 16350@item layout regs
8e04817f
AC
16351Display the register window together with the source or assembly window.
16352
16353@item focus next | prev | src | asm | regs | split
16354@kindex focus
16355Set the focus to the named window.
16356This command allows to change the active window so that scrolling keys
16357can be affected to another window.
c906108c 16358
8e04817f
AC
16359@item refresh
16360@kindex refresh
16361Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16362
6a1b180d
SC
16363@item tui reg float
16364@kindex tui reg
16365Show the floating point registers in the register window.
16366
16367@item tui reg general
16368Show the general registers in the register window.
16369
16370@item tui reg next
16371Show the next register group. The list of register groups as well as
16372their order is target specific. The predefined register groups are the
16373following: @code{general}, @code{float}, @code{system}, @code{vector},
16374@code{all}, @code{save}, @code{restore}.
16375
16376@item tui reg system
16377Show the system registers in the register window.
16378
8e04817f
AC
16379@item update
16380@kindex update
16381Update the source window and the current execution point.
c906108c 16382
8e04817f
AC
16383@item winheight @var{name} +@var{count}
16384@itemx winheight @var{name} -@var{count}
16385@kindex winheight
16386Change the height of the window @var{name} by @var{count}
16387lines. Positive counts increase the height, while negative counts
16388decrease it.
2df3850c 16389
c45da7e6
EZ
16390@item tabset
16391@kindex tabset @var{nchars}
16392Set the width of tab stops to be @var{nchars} characters.
16393
c906108c
SS
16394@end table
16395
8e04817f
AC
16396@node TUI Configuration
16397@section TUI configuration variables
16398@cindex TUI configuration variables
c906108c 16399
8e04817f
AC
16400The TUI has several configuration variables that control the
16401appearance of windows on the terminal.
c906108c 16402
8e04817f
AC
16403@table @code
16404@item set tui border-kind @var{kind}
16405@kindex set tui border-kind
16406Select the border appearance for the source, assembly and register windows.
16407The possible values are the following:
16408@table @code
16409@item space
16410Use a space character to draw the border.
c906108c 16411
8e04817f
AC
16412@item ascii
16413Use ascii characters + - and | to draw the border.
c906108c 16414
8e04817f
AC
16415@item acs
16416Use the Alternate Character Set to draw the border. The border is
16417drawn using character line graphics if the terminal supports them.
c78b4128 16418
8e04817f 16419@end table
c78b4128 16420
8e04817f
AC
16421@item set tui active-border-mode @var{mode}
16422@kindex set tui active-border-mode
16423Select the attributes to display the border of the active window.
16424The possible values are @code{normal}, @code{standout}, @code{reverse},
16425@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16426
8e04817f
AC
16427@item set tui border-mode @var{mode}
16428@kindex set tui border-mode
16429Select the attributes to display the border of other windows.
16430The @var{mode} can be one of the following:
16431@table @code
16432@item normal
16433Use normal attributes to display the border.
c906108c 16434
8e04817f
AC
16435@item standout
16436Use standout mode.
c906108c 16437
8e04817f
AC
16438@item reverse
16439Use reverse video mode.
c906108c 16440
8e04817f
AC
16441@item half
16442Use half bright mode.
c906108c 16443
8e04817f
AC
16444@item half-standout
16445Use half bright and standout mode.
c906108c 16446
8e04817f
AC
16447@item bold
16448Use extra bright or bold mode.
c78b4128 16449
8e04817f
AC
16450@item bold-standout
16451Use extra bright or bold and standout mode.
c78b4128 16452
8e04817f 16453@end table
c78b4128 16454
8e04817f 16455@end table
c78b4128 16456
8e04817f
AC
16457@node Emacs
16458@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16459
8e04817f
AC
16460@cindex Emacs
16461@cindex @sc{gnu} Emacs
16462A special interface allows you to use @sc{gnu} Emacs to view (and
16463edit) the source files for the program you are debugging with
16464@value{GDBN}.
c906108c 16465
8e04817f
AC
16466To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16467executable file you want to debug as an argument. This command starts
16468@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16469created Emacs buffer.
16470@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16471
8e04817f
AC
16472Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16473things:
c906108c 16474
8e04817f
AC
16475@itemize @bullet
16476@item
16477All ``terminal'' input and output goes through the Emacs buffer.
16478@end itemize
c906108c 16479
8e04817f
AC
16480This applies both to @value{GDBN} commands and their output, and to the input
16481and output done by the program you are debugging.
bf0184be 16482
8e04817f
AC
16483This is useful because it means that you can copy the text of previous
16484commands and input them again; you can even use parts of the output
16485in this way.
bf0184be 16486
8e04817f
AC
16487All the facilities of Emacs' Shell mode are available for interacting
16488with your program. In particular, you can send signals the usual
16489way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16490stop.
bf0184be 16491
8e04817f 16492@itemize @bullet
bf0184be 16493@item
8e04817f
AC
16494@value{GDBN} displays source code through Emacs.
16495@end itemize
bf0184be 16496
8e04817f
AC
16497Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16498source file for that frame and puts an arrow (@samp{=>}) at the
16499left margin of the current line. Emacs uses a separate buffer for
16500source display, and splits the screen to show both your @value{GDBN} session
16501and the source.
bf0184be 16502
8e04817f
AC
16503Explicit @value{GDBN} @code{list} or search commands still produce output as
16504usual, but you probably have no reason to use them from Emacs.
c906108c 16505
64fabec2
AC
16506If you specify an absolute file name when prompted for the @kbd{M-x
16507gdb} argument, then Emacs sets your current working directory to where
16508your program resides. If you only specify the file name, then Emacs
16509sets your current working directory to to the directory associated
16510with the previous buffer. In this case, @value{GDBN} may find your
16511program by searching your environment's @code{PATH} variable, but on
16512some operating systems it might not find the source. So, although the
16513@value{GDBN} input and output session proceeds normally, the auxiliary
16514buffer does not display the current source and line of execution.
16515
16516The initial working directory of @value{GDBN} is printed on the top
16517line of the @value{GDBN} I/O buffer and this serves as a default for
16518the commands that specify files for @value{GDBN} to operate
16519on. @xref{Files, ,Commands to specify files}.
16520
16521By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16522need to call @value{GDBN} by a different name (for example, if you
16523keep several configurations around, with different names) you can
16524customize the Emacs variable @code{gud-gdb-command-name} to run the
16525one you want.
8e04817f
AC
16526
16527In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16528addition to the standard Shell mode commands:
c906108c 16529
8e04817f
AC
16530@table @kbd
16531@item C-h m
16532Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16533
64fabec2 16534@item C-c C-s
8e04817f
AC
16535Execute to another source line, like the @value{GDBN} @code{step} command; also
16536update the display window to show the current file and location.
c906108c 16537
64fabec2 16538@item C-c C-n
8e04817f
AC
16539Execute to next source line in this function, skipping all function
16540calls, like the @value{GDBN} @code{next} command. Then update the display window
16541to show the current file and location.
c906108c 16542
64fabec2 16543@item C-c C-i
8e04817f
AC
16544Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16545display window accordingly.
c906108c 16546
8e04817f
AC
16547@item C-c C-f
16548Execute until exit from the selected stack frame, like the @value{GDBN}
16549@code{finish} command.
c906108c 16550
64fabec2 16551@item C-c C-r
8e04817f
AC
16552Continue execution of your program, like the @value{GDBN} @code{continue}
16553command.
b433d00b 16554
64fabec2 16555@item C-c <
8e04817f
AC
16556Go up the number of frames indicated by the numeric argument
16557(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16558like the @value{GDBN} @code{up} command.
b433d00b 16559
64fabec2 16560@item C-c >
8e04817f
AC
16561Go down the number of frames indicated by the numeric argument, like the
16562@value{GDBN} @code{down} command.
8e04817f 16563@end table
c906108c 16564
64fabec2 16565In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16566tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16567
64fabec2
AC
16568If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16569shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16570point to any frame in the stack and type @key{RET} to make it become the
16571current frame and display the associated source in the source buffer.
16572Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16573current one.
16574
8e04817f
AC
16575If you accidentally delete the source-display buffer, an easy way to get
16576it back is to type the command @code{f} in the @value{GDBN} buffer, to
16577request a frame display; when you run under Emacs, this recreates
16578the source buffer if necessary to show you the context of the current
16579frame.
c906108c 16580
8e04817f
AC
16581The source files displayed in Emacs are in ordinary Emacs buffers
16582which are visiting the source files in the usual way. You can edit
16583the files with these buffers if you wish; but keep in mind that @value{GDBN}
16584communicates with Emacs in terms of line numbers. If you add or
16585delete lines from the text, the line numbers that @value{GDBN} knows cease
16586to correspond properly with the code.
b383017d 16587
64fabec2
AC
16588The description given here is for GNU Emacs version 21.3 and a more
16589detailed description of its interaction with @value{GDBN} is given in
16590the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16591
8e04817f
AC
16592@c The following dropped because Epoch is nonstandard. Reactivate
16593@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16594@ignore
16595@kindex Emacs Epoch environment
16596@kindex Epoch
16597@kindex inspect
c906108c 16598
8e04817f
AC
16599Version 18 of @sc{gnu} Emacs has a built-in window system
16600called the @code{epoch}
16601environment. Users of this environment can use a new command,
16602@code{inspect} which performs identically to @code{print} except that
16603each value is printed in its own window.
16604@end ignore
c906108c 16605
922fbb7b
AC
16606
16607@node GDB/MI
16608@chapter The @sc{gdb/mi} Interface
16609
16610@unnumberedsec Function and Purpose
16611
16612@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16613@sc{gdb/mi} is a line based machine oriented text interface to
16614@value{GDBN} and is activated by specifying using the
16615@option{--interpreter} command line option (@pxref{Mode Options}). It
16616is specifically intended to support the development of systems which
16617use the debugger as just one small component of a larger system.
922fbb7b
AC
16618
16619This chapter is a specification of the @sc{gdb/mi} interface. It is written
16620in the form of a reference manual.
16621
16622Note that @sc{gdb/mi} is still under construction, so some of the
16623features described below are incomplete and subject to change.
16624
16625@unnumberedsec Notation and Terminology
16626
16627@cindex notational conventions, for @sc{gdb/mi}
16628This chapter uses the following notation:
16629
16630@itemize @bullet
16631@item
16632@code{|} separates two alternatives.
16633
16634@item
16635@code{[ @var{something} ]} indicates that @var{something} is optional:
16636it may or may not be given.
16637
16638@item
16639@code{( @var{group} )*} means that @var{group} inside the parentheses
16640may repeat zero or more times.
16641
16642@item
16643@code{( @var{group} )+} means that @var{group} inside the parentheses
16644may repeat one or more times.
16645
16646@item
16647@code{"@var{string}"} means a literal @var{string}.
16648@end itemize
16649
16650@ignore
16651@heading Dependencies
16652@end ignore
16653
16654@heading Acknowledgments
16655
16656In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16657Elena Zannoni.
16658
16659@menu
16660* GDB/MI Command Syntax::
16661* GDB/MI Compatibility with CLI::
16662* GDB/MI Output Records::
16663* GDB/MI Command Description Format::
16664* GDB/MI Breakpoint Table Commands::
16665* GDB/MI Data Manipulation::
16666* GDB/MI Program Control::
16667* GDB/MI Miscellaneous Commands::
16668@ignore
16669* GDB/MI Kod Commands::
16670* GDB/MI Memory Overlay Commands::
16671* GDB/MI Signal Handling Commands::
16672@end ignore
16673* GDB/MI Stack Manipulation::
16674* GDB/MI Symbol Query::
16675* GDB/MI Target Manipulation::
16676* GDB/MI Thread Commands::
16677* GDB/MI Tracepoint Commands::
16678* GDB/MI Variable Objects::
16679@end menu
16680
16681@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16682@node GDB/MI Command Syntax
16683@section @sc{gdb/mi} Command Syntax
16684
16685@menu
16686* GDB/MI Input Syntax::
16687* GDB/MI Output Syntax::
16688* GDB/MI Simple Examples::
16689@end menu
16690
16691@node GDB/MI Input Syntax
16692@subsection @sc{gdb/mi} Input Syntax
16693
16694@cindex input syntax for @sc{gdb/mi}
16695@cindex @sc{gdb/mi}, input syntax
16696@table @code
16697@item @var{command} @expansion{}
16698@code{@var{cli-command} | @var{mi-command}}
16699
16700@item @var{cli-command} @expansion{}
16701@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16702@var{cli-command} is any existing @value{GDBN} CLI command.
16703
16704@item @var{mi-command} @expansion{}
16705@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16706@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16707
16708@item @var{token} @expansion{}
16709"any sequence of digits"
16710
16711@item @var{option} @expansion{}
16712@code{"-" @var{parameter} [ " " @var{parameter} ]}
16713
16714@item @var{parameter} @expansion{}
16715@code{@var{non-blank-sequence} | @var{c-string}}
16716
16717@item @var{operation} @expansion{}
16718@emph{any of the operations described in this chapter}
16719
16720@item @var{non-blank-sequence} @expansion{}
16721@emph{anything, provided it doesn't contain special characters such as
16722"-", @var{nl}, """ and of course " "}
16723
16724@item @var{c-string} @expansion{}
16725@code{""" @var{seven-bit-iso-c-string-content} """}
16726
16727@item @var{nl} @expansion{}
16728@code{CR | CR-LF}
16729@end table
16730
16731@noindent
16732Notes:
16733
16734@itemize @bullet
16735@item
16736The CLI commands are still handled by the @sc{mi} interpreter; their
16737output is described below.
16738
16739@item
16740The @code{@var{token}}, when present, is passed back when the command
16741finishes.
16742
16743@item
16744Some @sc{mi} commands accept optional arguments as part of the parameter
16745list. Each option is identified by a leading @samp{-} (dash) and may be
16746followed by an optional argument parameter. Options occur first in the
16747parameter list and can be delimited from normal parameters using
16748@samp{--} (this is useful when some parameters begin with a dash).
16749@end itemize
16750
16751Pragmatics:
16752
16753@itemize @bullet
16754@item
16755We want easy access to the existing CLI syntax (for debugging).
16756
16757@item
16758We want it to be easy to spot a @sc{mi} operation.
16759@end itemize
16760
16761@node GDB/MI Output Syntax
16762@subsection @sc{gdb/mi} Output Syntax
16763
16764@cindex output syntax of @sc{gdb/mi}
16765@cindex @sc{gdb/mi}, output syntax
16766The output from @sc{gdb/mi} consists of zero or more out-of-band records
16767followed, optionally, by a single result record. This result record
16768is for the most recent command. The sequence of output records is
16769terminated by @samp{(@value{GDBP})}.
16770
16771If an input command was prefixed with a @code{@var{token}} then the
16772corresponding output for that command will also be prefixed by that same
16773@var{token}.
16774
16775@table @code
16776@item @var{output} @expansion{}
f7dc1244 16777@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16778
16779@item @var{result-record} @expansion{}
16780@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16781
16782@item @var{out-of-band-record} @expansion{}
16783@code{@var{async-record} | @var{stream-record}}
16784
16785@item @var{async-record} @expansion{}
16786@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16787
16788@item @var{exec-async-output} @expansion{}
16789@code{[ @var{token} ] "*" @var{async-output}}
16790
16791@item @var{status-async-output} @expansion{}
16792@code{[ @var{token} ] "+" @var{async-output}}
16793
16794@item @var{notify-async-output} @expansion{}
16795@code{[ @var{token} ] "=" @var{async-output}}
16796
16797@item @var{async-output} @expansion{}
16798@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16799
16800@item @var{result-class} @expansion{}
16801@code{"done" | "running" | "connected" | "error" | "exit"}
16802
16803@item @var{async-class} @expansion{}
16804@code{"stopped" | @var{others}} (where @var{others} will be added
16805depending on the needs---this is still in development).
16806
16807@item @var{result} @expansion{}
16808@code{ @var{variable} "=" @var{value}}
16809
16810@item @var{variable} @expansion{}
16811@code{ @var{string} }
16812
16813@item @var{value} @expansion{}
16814@code{ @var{const} | @var{tuple} | @var{list} }
16815
16816@item @var{const} @expansion{}
16817@code{@var{c-string}}
16818
16819@item @var{tuple} @expansion{}
16820@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16821
16822@item @var{list} @expansion{}
16823@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16824@var{result} ( "," @var{result} )* "]" }
16825
16826@item @var{stream-record} @expansion{}
16827@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16828
16829@item @var{console-stream-output} @expansion{}
16830@code{"~" @var{c-string}}
16831
16832@item @var{target-stream-output} @expansion{}
16833@code{"@@" @var{c-string}}
16834
16835@item @var{log-stream-output} @expansion{}
16836@code{"&" @var{c-string}}
16837
16838@item @var{nl} @expansion{}
16839@code{CR | CR-LF}
16840
16841@item @var{token} @expansion{}
16842@emph{any sequence of digits}.
16843@end table
16844
16845@noindent
16846Notes:
16847
16848@itemize @bullet
16849@item
16850All output sequences end in a single line containing a period.
16851
16852@item
16853The @code{@var{token}} is from the corresponding request. If an execution
16854command is interrupted by the @samp{-exec-interrupt} command, the
16855@var{token} associated with the @samp{*stopped} message is the one of the
16856original execution command, not the one of the interrupt command.
16857
16858@item
16859@cindex status output in @sc{gdb/mi}
16860@var{status-async-output} contains on-going status information about the
16861progress of a slow operation. It can be discarded. All status output is
16862prefixed by @samp{+}.
16863
16864@item
16865@cindex async output in @sc{gdb/mi}
16866@var{exec-async-output} contains asynchronous state change on the target
16867(stopped, started, disappeared). All async output is prefixed by
16868@samp{*}.
16869
16870@item
16871@cindex notify output in @sc{gdb/mi}
16872@var{notify-async-output} contains supplementary information that the
16873client should handle (e.g., a new breakpoint information). All notify
16874output is prefixed by @samp{=}.
16875
16876@item
16877@cindex console output in @sc{gdb/mi}
16878@var{console-stream-output} is output that should be displayed as is in the
16879console. It is the textual response to a CLI command. All the console
16880output is prefixed by @samp{~}.
16881
16882@item
16883@cindex target output in @sc{gdb/mi}
16884@var{target-stream-output} is the output produced by the target program.
16885All the target output is prefixed by @samp{@@}.
16886
16887@item
16888@cindex log output in @sc{gdb/mi}
16889@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16890instance messages that should be displayed as part of an error log. All
16891the log output is prefixed by @samp{&}.
16892
16893@item
16894@cindex list output in @sc{gdb/mi}
16895New @sc{gdb/mi} commands should only output @var{lists} containing
16896@var{values}.
16897
16898
16899@end itemize
16900
16901@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16902details about the various output records.
16903
16904@node GDB/MI Simple Examples
16905@subsection Simple Examples of @sc{gdb/mi} Interaction
16906@cindex @sc{gdb/mi}, simple examples
16907
16908This subsection presents several simple examples of interaction using
16909the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16910following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16911the output received from @sc{gdb/mi}.
16912
16913@subsubheading Target Stop
16914@c Ummm... There is no "-stop" command. This assumes async, no?
16915Here's an example of stopping the inferior process:
16916
16917@smallexample
16918-> -stop
16919<- (@value{GDBP})
16920@end smallexample
16921
16922@noindent
16923and later:
16924
16925@smallexample
16926<- *stop,reason="stop",address="0x123",source="a.c:123"
16927<- (@value{GDBP})
16928@end smallexample
16929
16930@subsubheading Simple CLI Command
16931
16932Here's an example of a simple CLI command being passed through
16933@sc{gdb/mi} and on to the CLI.
16934
16935@smallexample
16936-> print 1+2
16937<- &"print 1+2\n"
16938<- ~"$1 = 3\n"
16939<- ^done
16940<- (@value{GDBP})
16941@end smallexample
16942
16943@subsubheading Command With Side Effects
16944
16945@smallexample
16946-> -symbol-file xyz.exe
16947<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16948<- (@value{GDBP})
16949@end smallexample
16950
16951@subsubheading A Bad Command
16952
16953Here's what happens if you pass a non-existent command:
16954
16955@smallexample
16956-> -rubbish
16957<- ^error,msg="Undefined MI command: rubbish"
16958<- (@value{GDBP})
16959@end smallexample
16960
16961@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16962@node GDB/MI Compatibility with CLI
16963@section @sc{gdb/mi} Compatibility with CLI
16964
16965@cindex compatibility, @sc{gdb/mi} and CLI
16966@cindex @sc{gdb/mi}, compatibility with CLI
16967To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16968accepts existing CLI commands. As specified by the syntax, such
16969commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16970respond.
16971
16972This mechanism is provided as an aid to developers of @sc{gdb/mi}
16973clients and not as a reliable interface into the CLI. Since the command
16974is being interpreteted in an environment that assumes @sc{gdb/mi}
16975behaviour, the exact output of such commands is likely to end up being
16976an un-supported hybrid of @sc{gdb/mi} and CLI output.
16977
16978@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16979@node GDB/MI Output Records
16980@section @sc{gdb/mi} Output Records
16981
16982@menu
16983* GDB/MI Result Records::
16984* GDB/MI Stream Records::
16985* GDB/MI Out-of-band Records::
16986@end menu
16987
16988@node GDB/MI Result Records
16989@subsection @sc{gdb/mi} Result Records
16990
16991@cindex result records in @sc{gdb/mi}
16992@cindex @sc{gdb/mi}, result records
16993In addition to a number of out-of-band notifications, the response to a
16994@sc{gdb/mi} command includes one of the following result indications:
16995
16996@table @code
16997@findex ^done
16998@item "^done" [ "," @var{results} ]
16999The synchronous operation was successful, @code{@var{results}} are the return
17000values.
17001
17002@item "^running"
17003@findex ^running
17004@c Is this one correct? Should it be an out-of-band notification?
17005The asynchronous operation was successfully started. The target is
17006running.
17007
17008@item "^error" "," @var{c-string}
17009@findex ^error
17010The operation failed. The @code{@var{c-string}} contains the corresponding
17011error message.
17012@end table
17013
17014@node GDB/MI Stream Records
17015@subsection @sc{gdb/mi} Stream Records
17016
17017@cindex @sc{gdb/mi}, stream records
17018@cindex stream records in @sc{gdb/mi}
17019@value{GDBN} internally maintains a number of output streams: the console, the
17020target, and the log. The output intended for each of these streams is
17021funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17022
17023Each stream record begins with a unique @dfn{prefix character} which
17024identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17025Syntax}). In addition to the prefix, each stream record contains a
17026@code{@var{string-output}}. This is either raw text (with an implicit new
17027line) or a quoted C string (which does not contain an implicit newline).
17028
17029@table @code
17030@item "~" @var{string-output}
17031The console output stream contains text that should be displayed in the
17032CLI console window. It contains the textual responses to CLI commands.
17033
17034@item "@@" @var{string-output}
17035The target output stream contains any textual output from the running
17036target.
17037
17038@item "&" @var{string-output}
17039The log stream contains debugging messages being produced by @value{GDBN}'s
17040internals.
17041@end table
17042
17043@node GDB/MI Out-of-band Records
17044@subsection @sc{gdb/mi} Out-of-band Records
17045
17046@cindex out-of-band records in @sc{gdb/mi}
17047@cindex @sc{gdb/mi}, out-of-band records
17048@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17049additional changes that have occurred. Those changes can either be a
17050consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17051target activity (e.g., target stopped).
17052
17053The following is a preliminary list of possible out-of-band records.
034dad6f 17054In particular, the @var{exec-async-output} records.
922fbb7b
AC
17055
17056@table @code
034dad6f
BR
17057@item *stopped,reason="@var{reason}"
17058@end table
17059
17060@var{reason} can be one of the following:
17061
17062@table @code
17063@item breakpoint-hit
17064A breakpoint was reached.
17065@item watchpoint-trigger
17066A watchpoint was triggered.
17067@item read-watchpoint-trigger
17068A read watchpoint was triggered.
17069@item access-watchpoint-trigger
17070An access watchpoint was triggered.
17071@item function-finished
17072An -exec-finish or similar CLI command was accomplished.
17073@item location-reached
17074An -exec-until or similar CLI command was accomplished.
17075@item watchpoint-scope
17076A watchpoint has gone out of scope.
17077@item end-stepping-range
17078An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17079similar CLI command was accomplished.
17080@item exited-signalled
17081The inferior exited because of a signal.
17082@item exited
17083The inferior exited.
17084@item exited-normally
17085The inferior exited normally.
17086@item signal-received
17087A signal was received by the inferior.
922fbb7b
AC
17088@end table
17089
17090
17091@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17092@node GDB/MI Command Description Format
17093@section @sc{gdb/mi} Command Description Format
17094
17095The remaining sections describe blocks of commands. Each block of
17096commands is laid out in a fashion similar to this section.
17097
17098Note the the line breaks shown in the examples are here only for
17099readability. They don't appear in the real output.
17100Also note that the commands with a non-available example (N.A.@:) are
17101not yet implemented.
17102
17103@subheading Motivation
17104
17105The motivation for this collection of commands.
17106
17107@subheading Introduction
17108
17109A brief introduction to this collection of commands as a whole.
17110
17111@subheading Commands
17112
17113For each command in the block, the following is described:
17114
17115@subsubheading Synopsis
17116
17117@smallexample
17118 -command @var{args}@dots{}
17119@end smallexample
17120
922fbb7b
AC
17121@subsubheading Result
17122
265eeb58 17123@subsubheading @value{GDBN} Command
922fbb7b 17124
265eeb58 17125The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17126
17127@subsubheading Example
17128
922fbb7b
AC
17129@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17130@node GDB/MI Breakpoint Table Commands
17131@section @sc{gdb/mi} Breakpoint table commands
17132
17133@cindex breakpoint commands for @sc{gdb/mi}
17134@cindex @sc{gdb/mi}, breakpoint commands
17135This section documents @sc{gdb/mi} commands for manipulating
17136breakpoints.
17137
17138@subheading The @code{-break-after} Command
17139@findex -break-after
17140
17141@subsubheading Synopsis
17142
17143@smallexample
17144 -break-after @var{number} @var{count}
17145@end smallexample
17146
17147The breakpoint number @var{number} is not in effect until it has been
17148hit @var{count} times. To see how this is reflected in the output of
17149the @samp{-break-list} command, see the description of the
17150@samp{-break-list} command below.
17151
17152@subsubheading @value{GDBN} Command
17153
17154The corresponding @value{GDBN} command is @samp{ignore}.
17155
17156@subsubheading Example
17157
17158@smallexample
17159(@value{GDBP})
17160-break-insert main
17161^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17162(@value{GDBP})
17163-break-after 1 3
17164~
17165^done
17166(@value{GDBP})
17167-break-list
17168^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17169hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17170@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17171@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17172@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17173@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17174@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17175body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17176addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17177ignore="3"@}]@}
17178(@value{GDBP})
17179@end smallexample
17180
17181@ignore
17182@subheading The @code{-break-catch} Command
17183@findex -break-catch
17184
17185@subheading The @code{-break-commands} Command
17186@findex -break-commands
17187@end ignore
17188
17189
17190@subheading The @code{-break-condition} Command
17191@findex -break-condition
17192
17193@subsubheading Synopsis
17194
17195@smallexample
17196 -break-condition @var{number} @var{expr}
17197@end smallexample
17198
17199Breakpoint @var{number} will stop the program only if the condition in
17200@var{expr} is true. The condition becomes part of the
17201@samp{-break-list} output (see the description of the @samp{-break-list}
17202command below).
17203
17204@subsubheading @value{GDBN} Command
17205
17206The corresponding @value{GDBN} command is @samp{condition}.
17207
17208@subsubheading Example
17209
17210@smallexample
17211(@value{GDBP})
17212-break-condition 1 1
17213^done
17214(@value{GDBP})
17215-break-list
17216^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17217hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17218@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17219@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17220@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17221@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17222@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17223body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17224addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17225times="0",ignore="3"@}]@}
17226(@value{GDBP})
17227@end smallexample
17228
17229@subheading The @code{-break-delete} Command
17230@findex -break-delete
17231
17232@subsubheading Synopsis
17233
17234@smallexample
17235 -break-delete ( @var{breakpoint} )+
17236@end smallexample
17237
17238Delete the breakpoint(s) whose number(s) are specified in the argument
17239list. This is obviously reflected in the breakpoint list.
17240
17241@subsubheading @value{GDBN} command
17242
17243The corresponding @value{GDBN} command is @samp{delete}.
17244
17245@subsubheading Example
17246
17247@smallexample
17248(@value{GDBP})
17249-break-delete 1
17250^done
17251(@value{GDBP})
17252-break-list
17253^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17254hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17255@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17256@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17257@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17258@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17259@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17260body=[]@}
17261(@value{GDBP})
17262@end smallexample
17263
17264@subheading The @code{-break-disable} Command
17265@findex -break-disable
17266
17267@subsubheading Synopsis
17268
17269@smallexample
17270 -break-disable ( @var{breakpoint} )+
17271@end smallexample
17272
17273Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17274break list is now set to @samp{n} for the named @var{breakpoint}(s).
17275
17276@subsubheading @value{GDBN} Command
17277
17278The corresponding @value{GDBN} command is @samp{disable}.
17279
17280@subsubheading Example
17281
17282@smallexample
17283(@value{GDBP})
17284-break-disable 2
17285^done
17286(@value{GDBP})
17287-break-list
17288^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17289hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17290@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17291@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17292@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17293@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17294@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17295body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17296addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17297(@value{GDBP})
17298@end smallexample
17299
17300@subheading The @code{-break-enable} Command
17301@findex -break-enable
17302
17303@subsubheading Synopsis
17304
17305@smallexample
17306 -break-enable ( @var{breakpoint} )+
17307@end smallexample
17308
17309Enable (previously disabled) @var{breakpoint}(s).
17310
17311@subsubheading @value{GDBN} Command
17312
17313The corresponding @value{GDBN} command is @samp{enable}.
17314
17315@subsubheading Example
17316
17317@smallexample
17318(@value{GDBP})
17319-break-enable 2
17320^done
17321(@value{GDBP})
17322-break-list
17323^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17324hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17325@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17326@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17327@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17328@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17329@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17330body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17331addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17332(@value{GDBP})
17333@end smallexample
17334
17335@subheading The @code{-break-info} Command
17336@findex -break-info
17337
17338@subsubheading Synopsis
17339
17340@smallexample
17341 -break-info @var{breakpoint}
17342@end smallexample
17343
17344@c REDUNDANT???
17345Get information about a single breakpoint.
17346
17347@subsubheading @value{GDBN} command
17348
17349The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17350
17351@subsubheading Example
17352N.A.
17353
17354@subheading The @code{-break-insert} Command
17355@findex -break-insert
17356
17357@subsubheading Synopsis
17358
17359@smallexample
17360 -break-insert [ -t ] [ -h ] [ -r ]
17361 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17362 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17363@end smallexample
17364
17365@noindent
17366If specified, @var{line}, can be one of:
17367
17368@itemize @bullet
17369@item function
17370@c @item +offset
17371@c @item -offset
17372@c @item linenum
17373@item filename:linenum
17374@item filename:function
17375@item *address
17376@end itemize
17377
17378The possible optional parameters of this command are:
17379
17380@table @samp
17381@item -t
17382Insert a tempoary breakpoint.
17383@item -h
17384Insert a hardware breakpoint.
17385@item -c @var{condition}
17386Make the breakpoint conditional on @var{condition}.
17387@item -i @var{ignore-count}
17388Initialize the @var{ignore-count}.
17389@item -r
17390Insert a regular breakpoint in all the functions whose names match the
17391given regular expression. Other flags are not applicable to regular
17392expresson.
17393@end table
17394
17395@subsubheading Result
17396
17397The result is in the form:
17398
17399@smallexample
17400 ^done,bkptno="@var{number}",func="@var{funcname}",
17401 file="@var{filename}",line="@var{lineno}"
17402@end smallexample
17403
17404@noindent
17405where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17406is the name of the function where the breakpoint was inserted,
17407@var{filename} is the name of the source file which contains this
17408function, and @var{lineno} is the source line number within that file.
17409
17410Note: this format is open to change.
17411@c An out-of-band breakpoint instead of part of the result?
17412
17413@subsubheading @value{GDBN} Command
17414
17415The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17416@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17417
17418@subsubheading Example
17419
17420@smallexample
17421(@value{GDBP})
17422-break-insert main
17423^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17424(@value{GDBP})
17425-break-insert -t foo
17426^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17427(@value{GDBP})
17428-break-list
17429^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17430hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17431@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17432@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17433@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17434@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17435@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17436body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17437addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17438bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17439addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17440(@value{GDBP})
17441-break-insert -r foo.*
17442~int foo(int, int);
17443^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17444(@value{GDBP})
17445@end smallexample
17446
17447@subheading The @code{-break-list} Command
17448@findex -break-list
17449
17450@subsubheading Synopsis
17451
17452@smallexample
17453 -break-list
17454@end smallexample
17455
17456Displays the list of inserted breakpoints, showing the following fields:
17457
17458@table @samp
17459@item Number
17460number of the breakpoint
17461@item Type
17462type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17463@item Disposition
17464should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17465or @samp{nokeep}
17466@item Enabled
17467is the breakpoint enabled or no: @samp{y} or @samp{n}
17468@item Address
17469memory location at which the breakpoint is set
17470@item What
17471logical location of the breakpoint, expressed by function name, file
17472name, line number
17473@item Times
17474number of times the breakpoint has been hit
17475@end table
17476
17477If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17478@code{body} field is an empty list.
17479
17480@subsubheading @value{GDBN} Command
17481
17482The corresponding @value{GDBN} command is @samp{info break}.
17483
17484@subsubheading Example
17485
17486@smallexample
17487(@value{GDBP})
17488-break-list
17489^done,BreakpointTable=@{nr_rows="2",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=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17497addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17498bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17499addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17500(@value{GDBP})
17501@end smallexample
17502
17503Here's an example of the result when there are no breakpoints:
17504
17505@smallexample
17506(@value{GDBP})
17507-break-list
17508^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17509hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17510@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17511@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17512@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17513@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17514@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17515body=[]@}
17516(@value{GDBP})
17517@end smallexample
17518
17519@subheading The @code{-break-watch} Command
17520@findex -break-watch
17521
17522@subsubheading Synopsis
17523
17524@smallexample
17525 -break-watch [ -a | -r ]
17526@end smallexample
17527
17528Create a watchpoint. With the @samp{-a} option it will create an
17529@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17530read from or on a write to the memory location. With the @samp{-r}
17531option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17532trigger only when the memory location is accessed for reading. Without
17533either of the options, the watchpoint created is a regular watchpoint,
17534i.e. it will trigger when the memory location is accessed for writing.
17535@xref{Set Watchpoints, , Setting watchpoints}.
17536
17537Note that @samp{-break-list} will report a single list of watchpoints and
17538breakpoints inserted.
17539
17540@subsubheading @value{GDBN} Command
17541
17542The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17543@samp{rwatch}.
17544
17545@subsubheading Example
17546
17547Setting a watchpoint on a variable in the @code{main} function:
17548
17549@smallexample
17550(@value{GDBP})
17551-break-watch x
17552^done,wpt=@{number="2",exp="x"@}
17553(@value{GDBP})
17554-exec-continue
17555^running
17556^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17557value=@{old="-268439212",new="55"@},
76ff342d
DJ
17558frame=@{func="main",args=[],file="recursive2.c",
17559fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17560(@value{GDBP})
17561@end smallexample
17562
17563Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17564the program execution twice: first for the variable changing value, then
17565for the watchpoint going out of scope.
17566
17567@smallexample
17568(@value{GDBP})
17569-break-watch C
17570^done,wpt=@{number="5",exp="C"@}
17571(@value{GDBP})
17572-exec-continue
17573^running
17574^done,reason="watchpoint-trigger",
17575wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17576frame=@{func="callee4",args=[],
76ff342d
DJ
17577file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17578fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17579(@value{GDBP})
17580-exec-continue
17581^running
17582^done,reason="watchpoint-scope",wpnum="5",
17583frame=@{func="callee3",args=[@{name="strarg",
17584value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17585file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17586fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17587(@value{GDBP})
17588@end smallexample
17589
17590Listing breakpoints and watchpoints, at different points in the program
17591execution. Note that once the watchpoint goes out of scope, it is
17592deleted.
17593
17594@smallexample
17595(@value{GDBP})
17596-break-watch C
17597^done,wpt=@{number="2",exp="C"@}
17598(@value{GDBP})
17599-break-list
17600^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17601hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17602@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17603@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17604@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17605@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17606@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17607body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17608addr="0x00010734",func="callee4",
17609file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17610bkpt=@{number="2",type="watchpoint",disp="keep",
17611enabled="y",addr="",what="C",times="0"@}]@}
17612(@value{GDBP})
17613-exec-continue
17614^running
17615^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17616value=@{old="-276895068",new="3"@},
17617frame=@{func="callee4",args=[],
76ff342d
DJ
17618file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17619fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17620(@value{GDBP})
17621-break-list
17622^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17623hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17624@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17625@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17626@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17627@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17628@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17629body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17630addr="0x00010734",func="callee4",
17631file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17632bkpt=@{number="2",type="watchpoint",disp="keep",
17633enabled="y",addr="",what="C",times="-5"@}]@}
17634(@value{GDBP})
17635-exec-continue
17636^running
17637^done,reason="watchpoint-scope",wpnum="2",
17638frame=@{func="callee3",args=[@{name="strarg",
17639value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17640file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17641fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17642(@value{GDBP})
17643-break-list
17644^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17645hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17646@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17647@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17648@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17649@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17650@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17651body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17652addr="0x00010734",func="callee4",
17653file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17654(@value{GDBP})
17655@end smallexample
17656
17657@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17658@node GDB/MI Data Manipulation
17659@section @sc{gdb/mi} Data Manipulation
17660
17661@cindex data manipulation, in @sc{gdb/mi}
17662@cindex @sc{gdb/mi}, data manipulation
17663This section describes the @sc{gdb/mi} commands that manipulate data:
17664examine memory and registers, evaluate expressions, etc.
17665
17666@c REMOVED FROM THE INTERFACE.
17667@c @subheading -data-assign
17668@c Change the value of a program variable. Plenty of side effects.
17669@c @subsubheading GDB command
17670@c set variable
17671@c @subsubheading Example
17672@c N.A.
17673
17674@subheading The @code{-data-disassemble} Command
17675@findex -data-disassemble
17676
17677@subsubheading Synopsis
17678
17679@smallexample
17680 -data-disassemble
17681 [ -s @var{start-addr} -e @var{end-addr} ]
17682 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17683 -- @var{mode}
17684@end smallexample
17685
17686@noindent
17687Where:
17688
17689@table @samp
17690@item @var{start-addr}
17691is the beginning address (or @code{$pc})
17692@item @var{end-addr}
17693is the end address
17694@item @var{filename}
17695is the name of the file to disassemble
17696@item @var{linenum}
17697is the line number to disassemble around
17698@item @var{lines}
17699is the the number of disassembly lines to be produced. If it is -1,
17700the whole function will be disassembled, in case no @var{end-addr} is
17701specified. If @var{end-addr} is specified as a non-zero value, and
17702@var{lines} is lower than the number of disassembly lines between
17703@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17704displayed; if @var{lines} is higher than the number of lines between
17705@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17706are displayed.
17707@item @var{mode}
17708is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17709disassembly).
17710@end table
17711
17712@subsubheading Result
17713
17714The output for each instruction is composed of four fields:
17715
17716@itemize @bullet
17717@item Address
17718@item Func-name
17719@item Offset
17720@item Instruction
17721@end itemize
17722
17723Note that whatever included in the instruction field, is not manipulated
17724directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17725
17726@subsubheading @value{GDBN} Command
17727
17728There's no direct mapping from this command to the CLI.
17729
17730@subsubheading Example
17731
17732Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17733
17734@smallexample
17735(@value{GDBP})
17736-data-disassemble -s $pc -e "$pc + 20" -- 0
17737^done,
17738asm_insns=[
17739@{address="0x000107c0",func-name="main",offset="4",
17740inst="mov 2, %o0"@},
17741@{address="0x000107c4",func-name="main",offset="8",
17742inst="sethi %hi(0x11800), %o2"@},
17743@{address="0x000107c8",func-name="main",offset="12",
17744inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17745@{address="0x000107cc",func-name="main",offset="16",
17746inst="sethi %hi(0x11800), %o2"@},
17747@{address="0x000107d0",func-name="main",offset="20",
17748inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17749(@value{GDBP})
17750@end smallexample
17751
17752Disassemble the whole @code{main} function. Line 32 is part of
17753@code{main}.
17754
17755@smallexample
17756-data-disassemble -f basics.c -l 32 -- 0
17757^done,asm_insns=[
17758@{address="0x000107bc",func-name="main",offset="0",
17759inst="save %sp, -112, %sp"@},
17760@{address="0x000107c0",func-name="main",offset="4",
17761inst="mov 2, %o0"@},
17762@{address="0x000107c4",func-name="main",offset="8",
17763inst="sethi %hi(0x11800), %o2"@},
17764[@dots{}]
17765@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17766@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17767(@value{GDBP})
17768@end smallexample
17769
17770Disassemble 3 instructions from the start of @code{main}:
17771
17772@smallexample
17773(@value{GDBP})
17774-data-disassemble -f basics.c -l 32 -n 3 -- 0
17775^done,asm_insns=[
17776@{address="0x000107bc",func-name="main",offset="0",
17777inst="save %sp, -112, %sp"@},
17778@{address="0x000107c0",func-name="main",offset="4",
17779inst="mov 2, %o0"@},
17780@{address="0x000107c4",func-name="main",offset="8",
17781inst="sethi %hi(0x11800), %o2"@}]
17782(@value{GDBP})
17783@end smallexample
17784
17785Disassemble 3 instructions from the start of @code{main} in mixed mode:
17786
17787@smallexample
17788(@value{GDBP})
17789-data-disassemble -f basics.c -l 32 -n 3 -- 1
17790^done,asm_insns=[
17791src_and_asm_line=@{line="31",
17792file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17793 testsuite/gdb.mi/basics.c",line_asm_insn=[
17794@{address="0x000107bc",func-name="main",offset="0",
17795inst="save %sp, -112, %sp"@}]@},
17796src_and_asm_line=@{line="32",
17797file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17798 testsuite/gdb.mi/basics.c",line_asm_insn=[
17799@{address="0x000107c0",func-name="main",offset="4",
17800inst="mov 2, %o0"@},
17801@{address="0x000107c4",func-name="main",offset="8",
17802inst="sethi %hi(0x11800), %o2"@}]@}]
17803(@value{GDBP})
17804@end smallexample
17805
17806
17807@subheading The @code{-data-evaluate-expression} Command
17808@findex -data-evaluate-expression
17809
17810@subsubheading Synopsis
17811
17812@smallexample
17813 -data-evaluate-expression @var{expr}
17814@end smallexample
17815
17816Evaluate @var{expr} as an expression. The expression could contain an
17817inferior function call. The function call will execute synchronously.
17818If the expression contains spaces, it must be enclosed in double quotes.
17819
17820@subsubheading @value{GDBN} Command
17821
17822The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17823@samp{call}. In @code{gdbtk} only, there's a corresponding
17824@samp{gdb_eval} command.
17825
17826@subsubheading Example
17827
17828In the following example, the numbers that precede the commands are the
17829@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17830Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17831output.
17832
17833@smallexample
17834211-data-evaluate-expression A
17835211^done,value="1"
17836(@value{GDBP})
17837311-data-evaluate-expression &A
17838311^done,value="0xefffeb7c"
17839(@value{GDBP})
17840411-data-evaluate-expression A+3
17841411^done,value="4"
17842(@value{GDBP})
17843511-data-evaluate-expression "A + 3"
17844511^done,value="4"
17845(@value{GDBP})
17846@end smallexample
17847
17848
17849@subheading The @code{-data-list-changed-registers} Command
17850@findex -data-list-changed-registers
17851
17852@subsubheading Synopsis
17853
17854@smallexample
17855 -data-list-changed-registers
17856@end smallexample
17857
17858Display a list of the registers that have changed.
17859
17860@subsubheading @value{GDBN} Command
17861
17862@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17863has the corresponding command @samp{gdb_changed_register_list}.
17864
17865@subsubheading Example
17866
17867On a PPC MBX board:
17868
17869@smallexample
17870(@value{GDBP})
17871-exec-continue
17872^running
17873
17874(@value{GDBP})
17875*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17876args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17877(@value{GDBP})
17878-data-list-changed-registers
17879^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17880"10","11","13","14","15","16","17","18","19","20","21","22","23",
17881"24","25","26","27","28","30","31","64","65","66","67","69"]
17882(@value{GDBP})
17883@end smallexample
17884
17885
17886@subheading The @code{-data-list-register-names} Command
17887@findex -data-list-register-names
17888
17889@subsubheading Synopsis
17890
17891@smallexample
17892 -data-list-register-names [ ( @var{regno} )+ ]
17893@end smallexample
17894
17895Show a list of register names for the current target. If no arguments
17896are given, it shows a list of the names of all the registers. If
17897integer numbers are given as arguments, it will print a list of the
17898names of the registers corresponding to the arguments. To ensure
17899consistency between a register name and its number, the output list may
17900include empty register names.
17901
17902@subsubheading @value{GDBN} Command
17903
17904@value{GDBN} does not have a command which corresponds to
17905@samp{-data-list-register-names}. In @code{gdbtk} there is a
17906corresponding command @samp{gdb_regnames}.
17907
17908@subsubheading Example
17909
17910For the PPC MBX board:
17911@smallexample
17912(@value{GDBP})
17913-data-list-register-names
17914^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17915"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17916"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17917"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17918"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17919"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17920"", "pc","ps","cr","lr","ctr","xer"]
17921(@value{GDBP})
17922-data-list-register-names 1 2 3
17923^done,register-names=["r1","r2","r3"]
17924(@value{GDBP})
17925@end smallexample
17926
17927@subheading The @code{-data-list-register-values} Command
17928@findex -data-list-register-values
17929
17930@subsubheading Synopsis
17931
17932@smallexample
17933 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17934@end smallexample
17935
17936Display the registers' contents. @var{fmt} is the format according to
17937which the registers' contents are to be returned, followed by an optional
17938list of numbers specifying the registers to display. A missing list of
17939numbers indicates that the contents of all the registers must be returned.
17940
17941Allowed formats for @var{fmt} are:
17942
17943@table @code
17944@item x
17945Hexadecimal
17946@item o
17947Octal
17948@item t
17949Binary
17950@item d
17951Decimal
17952@item r
17953Raw
17954@item N
17955Natural
17956@end table
17957
17958@subsubheading @value{GDBN} Command
17959
17960The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17961all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17962
17963@subsubheading Example
17964
17965For a PPC MBX board (note: line breaks are for readability only, they
17966don't appear in the actual output):
17967
17968@smallexample
17969(@value{GDBP})
17970-data-list-register-values r 64 65
17971^done,register-values=[@{number="64",value="0xfe00a300"@},
17972@{number="65",value="0x00029002"@}]
17973(@value{GDBP})
17974-data-list-register-values x
17975^done,register-values=[@{number="0",value="0xfe0043c8"@},
17976@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17977@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17978@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17979@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17980@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17981@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17982@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17983@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17984@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17985@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17986@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17987@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17988@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17989@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17990@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17991@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17992@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17993@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17994@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17995@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17996@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17997@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17998@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17999@{number="47",value="0x0"@},@{number="48",value="0x0"@},
18000@{number="49",value="0x0"@},@{number="50",value="0x0"@},
18001@{number="51",value="0x0"@},@{number="52",value="0x0"@},
18002@{number="53",value="0x0"@},@{number="54",value="0x0"@},
18003@{number="55",value="0x0"@},@{number="56",value="0x0"@},
18004@{number="57",value="0x0"@},@{number="58",value="0x0"@},
18005@{number="59",value="0x0"@},@{number="60",value="0x0"@},
18006@{number="61",value="0x0"@},@{number="62",value="0x0"@},
18007@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
18008@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
18009@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
18010@{number="69",value="0x20002b03"@}]
18011(@value{GDBP})
18012@end smallexample
18013
18014
18015@subheading The @code{-data-read-memory} Command
18016@findex -data-read-memory
18017
18018@subsubheading Synopsis
18019
18020@smallexample
18021 -data-read-memory [ -o @var{byte-offset} ]
18022 @var{address} @var{word-format} @var{word-size}
18023 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
18024@end smallexample
18025
18026@noindent
18027where:
18028
18029@table @samp
18030@item @var{address}
18031An expression specifying the address of the first memory word to be
18032read. Complex expressions containing embedded white space should be
18033quoted using the C convention.
18034
18035@item @var{word-format}
18036The format to be used to print the memory words. The notation is the
18037same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18038,Output formats}).
18039
18040@item @var{word-size}
18041The size of each memory word in bytes.
18042
18043@item @var{nr-rows}
18044The number of rows in the output table.
18045
18046@item @var{nr-cols}
18047The number of columns in the output table.
18048
18049@item @var{aschar}
18050If present, indicates that each row should include an @sc{ascii} dump. The
18051value of @var{aschar} is used as a padding character when a byte is not a
18052member of the printable @sc{ascii} character set (printable @sc{ascii}
18053characters are those whose code is between 32 and 126, inclusively).
18054
18055@item @var{byte-offset}
18056An offset to add to the @var{address} before fetching memory.
18057@end table
18058
18059This command displays memory contents as a table of @var{nr-rows} by
18060@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18061@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18062(returned as @samp{total-bytes}). Should less than the requested number
18063of bytes be returned by the target, the missing words are identified
18064using @samp{N/A}. The number of bytes read from the target is returned
18065in @samp{nr-bytes} and the starting address used to read memory in
18066@samp{addr}.
18067
18068The address of the next/previous row or page is available in
18069@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18070@samp{prev-page}.
18071
18072@subsubheading @value{GDBN} Command
18073
18074The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18075@samp{gdb_get_mem} memory read command.
18076
18077@subsubheading Example
18078
18079Read six bytes of memory starting at @code{bytes+6} but then offset by
18080@code{-6} bytes. Format as three rows of two columns. One byte per
18081word. Display each word in hex.
18082
18083@smallexample
18084(@value{GDBP})
180859-data-read-memory -o -6 -- bytes+6 x 1 3 2
180869^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18087next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18088prev-page="0x0000138a",memory=[
18089@{addr="0x00001390",data=["0x00","0x01"]@},
18090@{addr="0x00001392",data=["0x02","0x03"]@},
18091@{addr="0x00001394",data=["0x04","0x05"]@}]
18092(@value{GDBP})
18093@end smallexample
18094
18095Read two bytes of memory starting at address @code{shorts + 64} and
18096display as a single word formatted in decimal.
18097
18098@smallexample
18099(@value{GDBP})
181005-data-read-memory shorts+64 d 2 1 1
181015^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18102next-row="0x00001512",prev-row="0x0000150e",
18103next-page="0x00001512",prev-page="0x0000150e",memory=[
18104@{addr="0x00001510",data=["128"]@}]
18105(@value{GDBP})
18106@end smallexample
18107
18108Read thirty two bytes of memory starting at @code{bytes+16} and format
18109as eight rows of four columns. Include a string encoding with @samp{x}
18110used as the non-printable character.
18111
18112@smallexample
18113(@value{GDBP})
181144-data-read-memory bytes+16 x 1 8 4 x
181154^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18116next-row="0x000013c0",prev-row="0x0000139c",
18117next-page="0x000013c0",prev-page="0x00001380",memory=[
18118@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18119@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18120@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18121@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18122@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18123@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18124@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18125@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18126(@value{GDBP})
18127@end smallexample
18128
18129@subheading The @code{-display-delete} Command
18130@findex -display-delete
18131
18132@subsubheading Synopsis
18133
18134@smallexample
18135 -display-delete @var{number}
18136@end smallexample
18137
18138Delete the display @var{number}.
18139
18140@subsubheading @value{GDBN} Command
18141
18142The corresponding @value{GDBN} command is @samp{delete display}.
18143
18144@subsubheading Example
18145N.A.
18146
18147
18148@subheading The @code{-display-disable} Command
18149@findex -display-disable
18150
18151@subsubheading Synopsis
18152
18153@smallexample
18154 -display-disable @var{number}
18155@end smallexample
18156
18157Disable display @var{number}.
18158
18159@subsubheading @value{GDBN} Command
18160
18161The corresponding @value{GDBN} command is @samp{disable display}.
18162
18163@subsubheading Example
18164N.A.
18165
18166
18167@subheading The @code{-display-enable} Command
18168@findex -display-enable
18169
18170@subsubheading Synopsis
18171
18172@smallexample
18173 -display-enable @var{number}
18174@end smallexample
18175
18176Enable display @var{number}.
18177
18178@subsubheading @value{GDBN} Command
18179
18180The corresponding @value{GDBN} command is @samp{enable display}.
18181
18182@subsubheading Example
18183N.A.
18184
18185
18186@subheading The @code{-display-insert} Command
18187@findex -display-insert
18188
18189@subsubheading Synopsis
18190
18191@smallexample
18192 -display-insert @var{expression}
18193@end smallexample
18194
18195Display @var{expression} every time the program stops.
18196
18197@subsubheading @value{GDBN} Command
18198
18199The corresponding @value{GDBN} command is @samp{display}.
18200
18201@subsubheading Example
18202N.A.
18203
18204
18205@subheading The @code{-display-list} Command
18206@findex -display-list
18207
18208@subsubheading Synopsis
18209
18210@smallexample
18211 -display-list
18212@end smallexample
18213
18214List the displays. Do not show the current values.
18215
18216@subsubheading @value{GDBN} Command
18217
18218The corresponding @value{GDBN} command is @samp{info display}.
18219
18220@subsubheading Example
18221N.A.
18222
18223
18224@subheading The @code{-environment-cd} Command
18225@findex -environment-cd
18226
18227@subsubheading Synopsis
18228
18229@smallexample
18230 -environment-cd @var{pathdir}
18231@end smallexample
18232
18233Set @value{GDBN}'s working directory.
18234
18235@subsubheading @value{GDBN} Command
18236
18237The corresponding @value{GDBN} command is @samp{cd}.
18238
18239@subsubheading Example
18240
18241@smallexample
18242(@value{GDBP})
18243-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18244^done
18245(@value{GDBP})
18246@end smallexample
18247
18248
18249@subheading The @code{-environment-directory} Command
18250@findex -environment-directory
18251
18252@subsubheading Synopsis
18253
18254@smallexample
18255 -environment-directory [ -r ] [ @var{pathdir} ]+
18256@end smallexample
18257
18258Add directories @var{pathdir} to beginning of search path for source files.
18259If the @samp{-r} option is used, the search path is reset to the default
b383017d 18260search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18261@samp{-r} option, the search path is first reset and then addition
18262occurs as normal.
b383017d 18263Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18264multiple directories in a single command
18265results in the directories added to the beginning of the
18266search path in the same order they were presented in the command.
18267If blanks are needed as
18268part of a directory name, double-quotes should be used around
18269the name. In the command output, the path will show up separated
b383017d 18270by the system directory-separator character. The directory-seperator
922fbb7b
AC
18271character must not be used
18272in any directory name.
18273If no directories are specified, the current search path is displayed.
18274
18275@subsubheading @value{GDBN} Command
18276
18277The corresponding @value{GDBN} command is @samp{dir}.
18278
18279@subsubheading Example
18280
18281@smallexample
18282(@value{GDBP})
18283-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18284^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18285(@value{GDBP})
18286-environment-directory ""
18287^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18288(@value{GDBP})
18289-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18290^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18291(@value{GDBP})
18292-environment-directory -r
18293^done,source-path="$cdir:$cwd"
18294(@value{GDBP})
18295@end smallexample
18296
18297
18298@subheading The @code{-environment-path} Command
18299@findex -environment-path
18300
18301@subsubheading Synopsis
18302
18303@smallexample
18304 -environment-path [ -r ] [ @var{pathdir} ]+
18305@end smallexample
18306
18307Add directories @var{pathdir} to beginning of search path for object files.
18308If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18309search path that existed at gdb start-up. If directories @var{pathdir} are
18310supplied in addition to the
922fbb7b
AC
18311@samp{-r} option, the search path is first reset and then addition
18312occurs as normal.
b383017d 18313Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18314multiple directories in a single command
18315results in the directories added to the beginning of the
18316search path in the same order they were presented in the command.
18317If blanks are needed as
18318part of a directory name, double-quotes should be used around
18319the name. In the command output, the path will show up separated
b383017d 18320by the system directory-separator character. The directory-seperator
922fbb7b
AC
18321character must not be used
18322in any directory name.
18323If no directories are specified, the current path is displayed.
18324
18325
18326@subsubheading @value{GDBN} Command
18327
18328The corresponding @value{GDBN} command is @samp{path}.
18329
18330@subsubheading Example
18331
18332@smallexample
18333(@value{GDBP})
b383017d 18334-environment-path
922fbb7b
AC
18335^done,path="/usr/bin"
18336(@value{GDBP})
18337-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18338^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18339(@value{GDBP})
18340-environment-path -r /usr/local/bin
18341^done,path="/usr/local/bin:/usr/bin"
18342(@value{GDBP})
18343@end smallexample
18344
18345
18346@subheading The @code{-environment-pwd} Command
18347@findex -environment-pwd
18348
18349@subsubheading Synopsis
18350
18351@smallexample
18352 -environment-pwd
18353@end smallexample
18354
18355Show the current working directory.
18356
18357@subsubheading @value{GDBN} command
18358
18359The corresponding @value{GDBN} command is @samp{pwd}.
18360
18361@subsubheading Example
18362
18363@smallexample
18364(@value{GDBP})
18365-environment-pwd
18366^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18367(@value{GDBP})
18368@end smallexample
18369
18370@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18371@node GDB/MI Program Control
18372@section @sc{gdb/mi} Program control
18373
18374@subsubheading Program termination
18375
18376As a result of execution, the inferior program can run to completion, if
18377it doesn't encounter any breakpoints. In this case the output will
18378include an exit code, if the program has exited exceptionally.
18379
18380@subsubheading Examples
18381
18382@noindent
18383Program exited normally:
18384
18385@smallexample
18386(@value{GDBP})
18387-exec-run
18388^running
18389(@value{GDBP})
18390x = 55
18391*stopped,reason="exited-normally"
18392(@value{GDBP})
18393@end smallexample
18394
18395@noindent
18396Program exited exceptionally:
18397
18398@smallexample
18399(@value{GDBP})
18400-exec-run
18401^running
18402(@value{GDBP})
18403x = 55
18404*stopped,reason="exited",exit-code="01"
18405(@value{GDBP})
18406@end smallexample
18407
18408Another way the program can terminate is if it receives a signal such as
18409@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18410
18411@smallexample
18412(@value{GDBP})
18413*stopped,reason="exited-signalled",signal-name="SIGINT",
18414signal-meaning="Interrupt"
18415@end smallexample
18416
18417
18418@subheading The @code{-exec-abort} Command
18419@findex -exec-abort
18420
18421@subsubheading Synopsis
18422
18423@smallexample
18424 -exec-abort
18425@end smallexample
18426
18427Kill the inferior running program.
18428
18429@subsubheading @value{GDBN} Command
18430
18431The corresponding @value{GDBN} command is @samp{kill}.
18432
18433@subsubheading Example
18434N.A.
18435
18436
18437@subheading The @code{-exec-arguments} Command
18438@findex -exec-arguments
18439
18440@subsubheading Synopsis
18441
18442@smallexample
18443 -exec-arguments @var{args}
18444@end smallexample
18445
18446Set the inferior program arguments, to be used in the next
18447@samp{-exec-run}.
18448
18449@subsubheading @value{GDBN} Command
18450
18451The corresponding @value{GDBN} command is @samp{set args}.
18452
18453@subsubheading Example
18454
18455@c FIXME!
18456Don't have one around.
18457
18458
18459@subheading The @code{-exec-continue} Command
18460@findex -exec-continue
18461
18462@subsubheading Synopsis
18463
18464@smallexample
18465 -exec-continue
18466@end smallexample
18467
18468Asynchronous command. Resumes the execution of the inferior program
18469until a breakpoint is encountered, or until the inferior exits.
18470
18471@subsubheading @value{GDBN} Command
18472
18473The corresponding @value{GDBN} corresponding is @samp{continue}.
18474
18475@subsubheading Example
18476
18477@smallexample
18478-exec-continue
18479^running
18480(@value{GDBP})
18481@@Hello world
18482*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18483file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18484(@value{GDBP})
18485@end smallexample
18486
18487
18488@subheading The @code{-exec-finish} Command
18489@findex -exec-finish
18490
18491@subsubheading Synopsis
18492
18493@smallexample
18494 -exec-finish
18495@end smallexample
18496
18497Asynchronous command. Resumes the execution of the inferior program
18498until the current function is exited. Displays the results returned by
18499the function.
18500
18501@subsubheading @value{GDBN} Command
18502
18503The corresponding @value{GDBN} command is @samp{finish}.
18504
18505@subsubheading Example
18506
18507Function returning @code{void}.
18508
18509@smallexample
18510-exec-finish
18511^running
18512(@value{GDBP})
18513@@hello from foo
18514*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18515file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18516(@value{GDBP})
18517@end smallexample
18518
18519Function returning other than @code{void}. The name of the internal
18520@value{GDBN} variable storing the result is printed, together with the
18521value itself.
18522
18523@smallexample
18524-exec-finish
18525^running
18526(@value{GDBP})
18527*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18528args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18529file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18530gdb-result-var="$1",return-value="0"
18531(@value{GDBP})
18532@end smallexample
18533
18534
18535@subheading The @code{-exec-interrupt} Command
18536@findex -exec-interrupt
18537
18538@subsubheading Synopsis
18539
18540@smallexample
18541 -exec-interrupt
18542@end smallexample
18543
18544Asynchronous command. Interrupts the background execution of the target.
18545Note how the token associated with the stop message is the one for the
18546execution command that has been interrupted. The token for the interrupt
18547itself only appears in the @samp{^done} output. If the user is trying to
18548interrupt a non-running program, an error message will be printed.
18549
18550@subsubheading @value{GDBN} Command
18551
18552The corresponding @value{GDBN} command is @samp{interrupt}.
18553
18554@subsubheading Example
18555
18556@smallexample
18557(@value{GDBP})
18558111-exec-continue
18559111^running
18560
18561(@value{GDBP})
18562222-exec-interrupt
18563222^done
18564(@value{GDBP})
18565111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18566frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18567fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18568(@value{GDBP})
18569
18570(@value{GDBP})
18571-exec-interrupt
18572^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18573(@value{GDBP})
18574@end smallexample
18575
18576
18577@subheading The @code{-exec-next} Command
18578@findex -exec-next
18579
18580@subsubheading Synopsis
18581
18582@smallexample
18583 -exec-next
18584@end smallexample
18585
18586Asynchronous command. Resumes execution of the inferior program, stopping
18587when the beginning of the next source line is reached.
18588
18589@subsubheading @value{GDBN} Command
18590
18591The corresponding @value{GDBN} command is @samp{next}.
18592
18593@subsubheading Example
18594
18595@smallexample
18596-exec-next
18597^running
18598(@value{GDBP})
18599*stopped,reason="end-stepping-range",line="8",file="hello.c"
18600(@value{GDBP})
18601@end smallexample
18602
18603
18604@subheading The @code{-exec-next-instruction} Command
18605@findex -exec-next-instruction
18606
18607@subsubheading Synopsis
18608
18609@smallexample
18610 -exec-next-instruction
18611@end smallexample
18612
18613Asynchronous command. Executes one machine instruction. If the
18614instruction is a function call continues until the function returns. If
18615the program stops at an instruction in the middle of a source line, the
18616address will be printed as well.
18617
18618@subsubheading @value{GDBN} Command
18619
18620The corresponding @value{GDBN} command is @samp{nexti}.
18621
18622@subsubheading Example
18623
18624@smallexample
18625(@value{GDBP})
18626-exec-next-instruction
18627^running
18628
18629(@value{GDBP})
18630*stopped,reason="end-stepping-range",
18631addr="0x000100d4",line="5",file="hello.c"
18632(@value{GDBP})
18633@end smallexample
18634
18635
18636@subheading The @code{-exec-return} Command
18637@findex -exec-return
18638
18639@subsubheading Synopsis
18640
18641@smallexample
18642 -exec-return
18643@end smallexample
18644
18645Makes current function return immediately. Doesn't execute the inferior.
18646Displays the new current frame.
18647
18648@subsubheading @value{GDBN} Command
18649
18650The corresponding @value{GDBN} command is @samp{return}.
18651
18652@subsubheading Example
18653
18654@smallexample
18655(@value{GDBP})
18656200-break-insert callee4
18657200^done,bkpt=@{number="1",addr="0x00010734",
18658file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18659(@value{GDBP})
18660000-exec-run
18661000^running
18662(@value{GDBP})
18663000*stopped,reason="breakpoint-hit",bkptno="1",
18664frame=@{func="callee4",args=[],
76ff342d
DJ
18665file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18666fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18667(@value{GDBP})
18668205-break-delete
18669205^done
18670(@value{GDBP})
18671111-exec-return
18672111^done,frame=@{level="0",func="callee3",
18673args=[@{name="strarg",
18674value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18675file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18676fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18677(@value{GDBP})
18678@end smallexample
18679
18680
18681@subheading The @code{-exec-run} Command
18682@findex -exec-run
18683
18684@subsubheading Synopsis
18685
18686@smallexample
18687 -exec-run
18688@end smallexample
18689
18690Asynchronous command. Starts execution of the inferior from the
18691beginning. The inferior executes until either a breakpoint is
18692encountered or the program exits.
18693
18694@subsubheading @value{GDBN} Command
18695
18696The corresponding @value{GDBN} command is @samp{run}.
18697
18698@subsubheading Example
18699
18700@smallexample
18701(@value{GDBP})
18702-break-insert main
18703^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18704(@value{GDBP})
18705-exec-run
18706^running
18707(@value{GDBP})
18708*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18709frame=@{func="main",args=[],file="recursive2.c",
18710fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18711(@value{GDBP})
18712@end smallexample
18713
18714
18715@subheading The @code{-exec-show-arguments} Command
18716@findex -exec-show-arguments
18717
18718@subsubheading Synopsis
18719
18720@smallexample
18721 -exec-show-arguments
18722@end smallexample
18723
18724Print the arguments of the program.
18725
18726@subsubheading @value{GDBN} Command
18727
18728The corresponding @value{GDBN} command is @samp{show args}.
18729
18730@subsubheading Example
18731N.A.
18732
18733@c @subheading -exec-signal
18734
18735@subheading The @code{-exec-step} Command
18736@findex -exec-step
18737
18738@subsubheading Synopsis
18739
18740@smallexample
18741 -exec-step
18742@end smallexample
18743
18744Asynchronous command. Resumes execution of the inferior program, stopping
18745when the beginning of the next source line is reached, if the next
18746source line is not a function call. If it is, stop at the first
18747instruction of the called function.
18748
18749@subsubheading @value{GDBN} Command
18750
18751The corresponding @value{GDBN} command is @samp{step}.
18752
18753@subsubheading Example
18754
18755Stepping into a function:
18756
18757@smallexample
18758-exec-step
18759^running
18760(@value{GDBP})
18761*stopped,reason="end-stepping-range",
18762frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18763@{name="b",value="0"@}],file="recursive2.c",
18764fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18765(@value{GDBP})
18766@end smallexample
18767
18768Regular stepping:
18769
18770@smallexample
18771-exec-step
18772^running
18773(@value{GDBP})
18774*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18775(@value{GDBP})
18776@end smallexample
18777
18778
18779@subheading The @code{-exec-step-instruction} Command
18780@findex -exec-step-instruction
18781
18782@subsubheading Synopsis
18783
18784@smallexample
18785 -exec-step-instruction
18786@end smallexample
18787
18788Asynchronous command. Resumes the inferior which executes one machine
18789instruction. The output, once @value{GDBN} has stopped, will vary depending on
18790whether we have stopped in the middle of a source line or not. In the
18791former case, the address at which the program stopped will be printed as
18792well.
18793
18794@subsubheading @value{GDBN} Command
18795
18796The corresponding @value{GDBN} command is @samp{stepi}.
18797
18798@subsubheading Example
18799
18800@smallexample
18801(@value{GDBP})
18802-exec-step-instruction
18803^running
18804
18805(@value{GDBP})
18806*stopped,reason="end-stepping-range",
76ff342d
DJ
18807frame=@{func="foo",args=[],file="try.c",
18808fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18809(@value{GDBP})
18810-exec-step-instruction
18811^running
18812
18813(@value{GDBP})
18814*stopped,reason="end-stepping-range",
76ff342d
DJ
18815frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18816fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18817(@value{GDBP})
18818@end smallexample
18819
18820
18821@subheading The @code{-exec-until} Command
18822@findex -exec-until
18823
18824@subsubheading Synopsis
18825
18826@smallexample
18827 -exec-until [ @var{location} ]
18828@end smallexample
18829
18830Asynchronous command. Executes the inferior until the @var{location}
18831specified in the argument is reached. If there is no argument, the inferior
18832executes until a source line greater than the current one is reached.
18833The reason for stopping in this case will be @samp{location-reached}.
18834
18835@subsubheading @value{GDBN} Command
18836
18837The corresponding @value{GDBN} command is @samp{until}.
18838
18839@subsubheading Example
18840
18841@smallexample
18842(@value{GDBP})
18843-exec-until recursive2.c:6
18844^running
18845(@value{GDBP})
18846x = 55
18847*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18848file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18849(@value{GDBP})
18850@end smallexample
18851
18852@ignore
18853@subheading -file-clear
18854Is this going away????
18855@end ignore
18856
18857
18858@subheading The @code{-file-exec-and-symbols} Command
18859@findex -file-exec-and-symbols
18860
18861@subsubheading Synopsis
18862
18863@smallexample
18864 -file-exec-and-symbols @var{file}
18865@end smallexample
18866
18867Specify the executable file to be debugged. This file is the one from
18868which the symbol table is also read. If no file is specified, the
18869command clears the executable and symbol information. If breakpoints
18870are set when using this command with no arguments, @value{GDBN} will produce
18871error messages. Otherwise, no output is produced, except a completion
18872notification.
18873
18874@subsubheading @value{GDBN} Command
18875
18876The corresponding @value{GDBN} command is @samp{file}.
18877
18878@subsubheading Example
18879
18880@smallexample
18881(@value{GDBP})
18882-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18883^done
18884(@value{GDBP})
18885@end smallexample
18886
18887
18888@subheading The @code{-file-exec-file} Command
18889@findex -file-exec-file
18890
18891@subsubheading Synopsis
18892
18893@smallexample
18894 -file-exec-file @var{file}
18895@end smallexample
18896
18897Specify the executable file to be debugged. Unlike
18898@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18899from this file. If used without argument, @value{GDBN} clears the information
18900about the executable file. No output is produced, except a completion
18901notification.
18902
18903@subsubheading @value{GDBN} Command
18904
18905The corresponding @value{GDBN} command is @samp{exec-file}.
18906
18907@subsubheading Example
18908
18909@smallexample
18910(@value{GDBP})
18911-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18912^done
18913(@value{GDBP})
18914@end smallexample
18915
18916
18917@subheading The @code{-file-list-exec-sections} Command
18918@findex -file-list-exec-sections
18919
18920@subsubheading Synopsis
18921
18922@smallexample
18923 -file-list-exec-sections
18924@end smallexample
18925
18926List the sections of the current executable file.
18927
18928@subsubheading @value{GDBN} Command
18929
18930The @value{GDBN} command @samp{info file} shows, among the rest, the same
18931information as this command. @code{gdbtk} has a corresponding command
18932@samp{gdb_load_info}.
18933
18934@subsubheading Example
18935N.A.
18936
18937
1abaf70c
BR
18938@subheading The @code{-file-list-exec-source-file} Command
18939@findex -file-list-exec-source-file
18940
18941@subsubheading Synopsis
18942
18943@smallexample
18944 -file-list-exec-source-file
18945@end smallexample
18946
b383017d 18947List the line number, the current source file, and the absolute path
1abaf70c
BR
18948to the current source file for the current executable.
18949
18950@subsubheading @value{GDBN} Command
18951
18952There's no @value{GDBN} command which directly corresponds to this one.
18953
18954@subsubheading Example
18955
18956@smallexample
18957(@value{GDBP})
18958123-file-list-exec-source-file
18959123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18960(@value{GDBP})
18961@end smallexample
18962
18963
922fbb7b
AC
18964@subheading The @code{-file-list-exec-source-files} Command
18965@findex -file-list-exec-source-files
18966
18967@subsubheading Synopsis
18968
18969@smallexample
18970 -file-list-exec-source-files
18971@end smallexample
18972
18973List the source files for the current executable.
18974
57c22c6c
BR
18975It will always output the filename, but only when GDB can find the absolute
18976file name of a source file, will it output the fullname.
18977
922fbb7b
AC
18978@subsubheading @value{GDBN} Command
18979
18980There's no @value{GDBN} command which directly corresponds to this one.
18981@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18982
18983@subsubheading Example
57c22c6c
BR
18984@smallexample
18985(@value{GDBP})
18986-file-list-exec-source-files
18987^done,files=[
18988@{file=foo.c,fullname=/home/foo.c@},
18989@{file=/home/bar.c,fullname=/home/bar.c@},
18990@{file=gdb_could_not_find_fullpath.c@}]
18991(@value{GDBP})
18992@end smallexample
922fbb7b
AC
18993
18994@subheading The @code{-file-list-shared-libraries} Command
18995@findex -file-list-shared-libraries
18996
18997@subsubheading Synopsis
18998
18999@smallexample
19000 -file-list-shared-libraries
19001@end smallexample
19002
19003List the shared libraries in the program.
19004
19005@subsubheading @value{GDBN} Command
19006
19007The corresponding @value{GDBN} command is @samp{info shared}.
19008
19009@subsubheading Example
19010N.A.
19011
19012
19013@subheading The @code{-file-list-symbol-files} Command
19014@findex -file-list-symbol-files
19015
19016@subsubheading Synopsis
19017
19018@smallexample
19019 -file-list-symbol-files
19020@end smallexample
19021
19022List symbol files.
19023
19024@subsubheading @value{GDBN} Command
19025
19026The corresponding @value{GDBN} command is @samp{info file} (part of it).
19027
19028@subsubheading Example
19029N.A.
19030
19031
19032@subheading The @code{-file-symbol-file} Command
19033@findex -file-symbol-file
19034
19035@subsubheading Synopsis
19036
19037@smallexample
19038 -file-symbol-file @var{file}
19039@end smallexample
19040
19041Read symbol table info from the specified @var{file} argument. When
19042used without arguments, clears @value{GDBN}'s symbol table info. No output is
19043produced, except for a completion notification.
19044
19045@subsubheading @value{GDBN} Command
19046
19047The corresponding @value{GDBN} command is @samp{symbol-file}.
19048
19049@subsubheading Example
19050
19051@smallexample
19052(@value{GDBP})
19053-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19054^done
19055(@value{GDBP})
19056@end smallexample
19057
19058@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19059@node GDB/MI Miscellaneous Commands
19060@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19061
19062@c @subheading -gdb-complete
19063
19064@subheading The @code{-gdb-exit} Command
19065@findex -gdb-exit
19066
19067@subsubheading Synopsis
19068
19069@smallexample
19070 -gdb-exit
19071@end smallexample
19072
19073Exit @value{GDBN} immediately.
19074
19075@subsubheading @value{GDBN} Command
19076
19077Approximately corresponds to @samp{quit}.
19078
19079@subsubheading Example
19080
19081@smallexample
19082(@value{GDBP})
19083-gdb-exit
19084@end smallexample
19085
19086@subheading The @code{-gdb-set} Command
19087@findex -gdb-set
19088
19089@subsubheading Synopsis
19090
19091@smallexample
19092 -gdb-set
19093@end smallexample
19094
19095Set an internal @value{GDBN} variable.
19096@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19097
19098@subsubheading @value{GDBN} Command
19099
19100The corresponding @value{GDBN} command is @samp{set}.
19101
19102@subsubheading Example
19103
19104@smallexample
19105(@value{GDBP})
19106-gdb-set $foo=3
19107^done
19108(@value{GDBP})
19109@end smallexample
19110
19111
19112@subheading The @code{-gdb-show} Command
19113@findex -gdb-show
19114
19115@subsubheading Synopsis
19116
19117@smallexample
19118 -gdb-show
19119@end smallexample
19120
19121Show the current value of a @value{GDBN} variable.
19122
19123@subsubheading @value{GDBN} command
19124
19125The corresponding @value{GDBN} command is @samp{show}.
19126
19127@subsubheading Example
19128
19129@smallexample
19130(@value{GDBP})
19131-gdb-show annotate
19132^done,value="0"
19133(@value{GDBP})
19134@end smallexample
19135
19136@c @subheading -gdb-source
19137
19138
19139@subheading The @code{-gdb-version} Command
19140@findex -gdb-version
19141
19142@subsubheading Synopsis
19143
19144@smallexample
19145 -gdb-version
19146@end smallexample
19147
19148Show version information for @value{GDBN}. Used mostly in testing.
19149
19150@subsubheading @value{GDBN} Command
19151
19152There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19153information when you start an interactive session.
19154
19155@subsubheading Example
19156
19157@c This example modifies the actual output from GDB to avoid overfull
19158@c box in TeX.
19159@smallexample
19160(@value{GDBP})
19161-gdb-version
19162~GNU gdb 5.2.1
19163~Copyright 2000 Free Software Foundation, Inc.
19164~GDB is free software, covered by the GNU General Public License, and
19165~you are welcome to change it and/or distribute copies of it under
19166~ certain conditions.
19167~Type "show copying" to see the conditions.
19168~There is absolutely no warranty for GDB. Type "show warranty" for
19169~ details.
b383017d 19170~This GDB was configured as
922fbb7b
AC
19171 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19172^done
19173(@value{GDBP})
19174@end smallexample
19175
19176@subheading The @code{-interpreter-exec} Command
19177@findex -interpreter-exec
19178
19179@subheading Synopsis
19180
19181@smallexample
19182-interpreter-exec @var{interpreter} @var{command}
19183@end smallexample
19184
19185Execute the specified @var{command} in the given @var{interpreter}.
19186
19187@subheading @value{GDBN} Command
19188
19189The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19190
19191@subheading Example
19192
19193@smallexample
19194(@value{GDBP})
19195-interpreter-exec console "break main"
19196&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19197&"During symbol reading, bad structure-type format.\n"
19198~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19199^done
19200(@value{GDBP})
19201@end smallexample
19202
3cb3b8df
BR
19203@subheading The @code{-inferior-tty-set} Command
19204@findex -inferior-tty-set
19205
19206@subheading Synopsis
19207
19208@smallexample
19209-inferior-tty-set /dev/pts/1
19210@end smallexample
19211
19212Set terminal for future runs of the program being debugged.
19213
19214@subheading @value{GDBN} Command
19215
19216The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19217
19218@subheading Example
19219
19220@smallexample
19221(@value{GDBP})
19222-inferior-tty-set /dev/pts/1
19223^done
19224(@value{GDBP})
19225@end smallexample
19226
19227@subheading The @code{-inferior-tty-show} Command
19228@findex -inferior-tty-show
19229
19230@subheading Synopsis
19231
19232@smallexample
19233-inferior-tty-show
19234@end smallexample
19235
19236Show terminal for future runs of program being debugged.
19237
19238@subheading @value{GDBN} Command
19239
38f1196a 19240The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19241
19242@subheading Example
19243
19244@smallexample
19245(@value{GDBP})
19246-inferior-tty-set /dev/pts/1
19247^done
19248(@value{GDBP})
19249-inferior-tty-show
19250^done,inferior_tty_terminal="/dev/pts/1"
19251(@value{GDBP})
19252@end smallexample
19253
922fbb7b
AC
19254@ignore
19255@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19256@node GDB/MI Kod Commands
19257@section @sc{gdb/mi} Kod Commands
19258
19259The Kod commands are not implemented.
19260
19261@c @subheading -kod-info
19262
19263@c @subheading -kod-list
19264
19265@c @subheading -kod-list-object-types
19266
19267@c @subheading -kod-show
19268
19269@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19270@node GDB/MI Memory Overlay Commands
19271@section @sc{gdb/mi} Memory Overlay Commands
19272
19273The memory overlay commands are not implemented.
19274
19275@c @subheading -overlay-auto
19276
19277@c @subheading -overlay-list-mapping-state
19278
19279@c @subheading -overlay-list-overlays
19280
19281@c @subheading -overlay-map
19282
19283@c @subheading -overlay-off
19284
19285@c @subheading -overlay-on
19286
19287@c @subheading -overlay-unmap
19288
19289@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19290@node GDB/MI Signal Handling Commands
19291@section @sc{gdb/mi} Signal Handling Commands
19292
19293Signal handling commands are not implemented.
19294
19295@c @subheading -signal-handle
19296
19297@c @subheading -signal-list-handle-actions
19298
19299@c @subheading -signal-list-signal-types
19300@end ignore
19301
19302
19303@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19304@node GDB/MI Stack Manipulation
19305@section @sc{gdb/mi} Stack Manipulation Commands
19306
dcaaae04
NR
19307
19308@subheading The @code{-stack-info-frame} Command
19309@findex -stack-info-frame
19310
19311@subsubheading Synopsis
19312
19313@smallexample
19314 -stack-info-frame
19315@end smallexample
19316
19317Get info on the selected frame.
19318
19319@subsubheading @value{GDBN} Command
19320
19321The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19322(without arguments).
19323
19324@subsubheading Example
19325
19326@smallexample
19327(@value{GDBP})
19328-stack-info-frame
19329^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19330file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19331fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19332(@value{GDBP})
19333@end smallexample
19334
922fbb7b
AC
19335@subheading The @code{-stack-info-depth} Command
19336@findex -stack-info-depth
19337
19338@subsubheading Synopsis
19339
19340@smallexample
19341 -stack-info-depth [ @var{max-depth} ]
19342@end smallexample
19343
19344Return the depth of the stack. If the integer argument @var{max-depth}
19345is specified, do not count beyond @var{max-depth} frames.
19346
19347@subsubheading @value{GDBN} Command
19348
19349There's no equivalent @value{GDBN} command.
19350
19351@subsubheading Example
19352
19353For a stack with frame levels 0 through 11:
19354
19355@smallexample
19356(@value{GDBP})
19357-stack-info-depth
19358^done,depth="12"
19359(@value{GDBP})
19360-stack-info-depth 4
19361^done,depth="4"
19362(@value{GDBP})
19363-stack-info-depth 12
19364^done,depth="12"
19365(@value{GDBP})
19366-stack-info-depth 11
19367^done,depth="11"
19368(@value{GDBP})
19369-stack-info-depth 13
19370^done,depth="12"
19371(@value{GDBP})
19372@end smallexample
19373
19374@subheading The @code{-stack-list-arguments} Command
19375@findex -stack-list-arguments
19376
19377@subsubheading Synopsis
19378
19379@smallexample
19380 -stack-list-arguments @var{show-values}
19381 [ @var{low-frame} @var{high-frame} ]
19382@end smallexample
19383
19384Display a list of the arguments for the frames between @var{low-frame}
19385and @var{high-frame} (inclusive). If @var{low-frame} and
19386@var{high-frame} are not provided, list the arguments for the whole call
19387stack.
19388
19389The @var{show-values} argument must have a value of 0 or 1. A value of
193900 means that only the names of the arguments are listed, a value of 1
19391means that both names and values of the arguments are printed.
19392
19393@subsubheading @value{GDBN} Command
19394
19395@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19396@samp{gdb_get_args} command which partially overlaps with the
19397functionality of @samp{-stack-list-arguments}.
19398
19399@subsubheading Example
19400
19401@smallexample
19402(@value{GDBP})
19403-stack-list-frames
19404^done,
19405stack=[
19406frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19407file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19408fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19409frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19410file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19411fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19412frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19413file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19414fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19415frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19416file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19417fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19418frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19419file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19420fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19421(@value{GDBP})
19422-stack-list-arguments 0
19423^done,
19424stack-args=[
19425frame=@{level="0",args=[]@},
19426frame=@{level="1",args=[name="strarg"]@},
19427frame=@{level="2",args=[name="intarg",name="strarg"]@},
19428frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19429frame=@{level="4",args=[]@}]
19430(@value{GDBP})
19431-stack-list-arguments 1
19432^done,
19433stack-args=[
19434frame=@{level="0",args=[]@},
19435frame=@{level="1",
19436 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19437frame=@{level="2",args=[
19438@{name="intarg",value="2"@},
19439@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19440@{frame=@{level="3",args=[
19441@{name="intarg",value="2"@},
19442@{name="strarg",value="0x11940 \"A string argument.\""@},
19443@{name="fltarg",value="3.5"@}]@},
19444frame=@{level="4",args=[]@}]
19445(@value{GDBP})
19446-stack-list-arguments 0 2 2
19447^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19448(@value{GDBP})
19449-stack-list-arguments 1 2 2
19450^done,stack-args=[frame=@{level="2",
19451args=[@{name="intarg",value="2"@},
19452@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19453(@value{GDBP})
19454@end smallexample
19455
19456@c @subheading -stack-list-exception-handlers
19457
19458
19459@subheading The @code{-stack-list-frames} Command
19460@findex -stack-list-frames
19461
19462@subsubheading Synopsis
19463
19464@smallexample
19465 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19466@end smallexample
19467
19468List the frames currently on the stack. For each frame it displays the
19469following info:
19470
19471@table @samp
19472@item @var{level}
19473The frame number, 0 being the topmost frame, i.e. the innermost function.
19474@item @var{addr}
19475The @code{$pc} value for that frame.
19476@item @var{func}
19477Function name.
19478@item @var{file}
19479File name of the source file where the function lives.
19480@item @var{line}
19481Line number corresponding to the @code{$pc}.
19482@end table
19483
19484If invoked without arguments, this command prints a backtrace for the
19485whole stack. If given two integer arguments, it shows the frames whose
19486levels are between the two arguments (inclusive). If the two arguments
19487are equal, it shows the single frame at the corresponding level.
19488
19489@subsubheading @value{GDBN} Command
19490
19491The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19492
19493@subsubheading Example
19494
19495Full stack backtrace:
19496
19497@smallexample
19498(@value{GDBP})
19499-stack-list-frames
19500^done,stack=
19501[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19502 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19503frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19504 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19505frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19506 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19507frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19508 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19509frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19510 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19511frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19512 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19513frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19514 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19515frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19516 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19517frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19518 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19519frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19520 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19521frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19522 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19523frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19524 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19525(@value{GDBP})
19526@end smallexample
19527
19528Show frames between @var{low_frame} and @var{high_frame}:
19529
19530@smallexample
19531(@value{GDBP})
19532-stack-list-frames 3 5
19533^done,stack=
19534[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19535 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19536frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19537 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19538frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19539 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19540(@value{GDBP})
19541@end smallexample
19542
19543Show a single frame:
19544
19545@smallexample
19546(@value{GDBP})
19547-stack-list-frames 3 3
19548^done,stack=
19549[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19550 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19551(@value{GDBP})
19552@end smallexample
19553
19554
19555@subheading The @code{-stack-list-locals} Command
19556@findex -stack-list-locals
19557
19558@subsubheading Synopsis
19559
19560@smallexample
19561 -stack-list-locals @var{print-values}
19562@end smallexample
19563
265eeb58
NR
19564Display the local variable names for the selected frame. If
19565@var{print-values} is 0 or @code{--no-values}, print only the names of
19566the variables; if it is 1 or @code{--all-values}, print also their
19567values; and if it is 2 or @code{--simple-values}, print the name,
19568type and value for simple data types and the name and type for arrays,
19569structures and unions. In this last case, a frontend can immediately
19570display the value of simple data types and create variable objects for
19571other data types when the the user wishes to explore their values in
bc8ced35 19572more detail.
922fbb7b
AC
19573
19574@subsubheading @value{GDBN} Command
19575
19576@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19577
19578@subsubheading Example
19579
19580@smallexample
19581(@value{GDBP})
19582-stack-list-locals 0
19583^done,locals=[name="A",name="B",name="C"]
19584(@value{GDBP})
bc8ced35 19585-stack-list-locals --all-values
922fbb7b 19586^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19587 @{name="C",value="@{1, 2, 3@}"@}]
19588-stack-list-locals --simple-values
19589^done,locals=[@{name="A",type="int",value="1"@},
19590 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19591(@value{GDBP})
19592@end smallexample
19593
19594
19595@subheading The @code{-stack-select-frame} Command
19596@findex -stack-select-frame
19597
19598@subsubheading Synopsis
19599
19600@smallexample
19601 -stack-select-frame @var{framenum}
19602@end smallexample
19603
265eeb58 19604Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
19605the stack.
19606
19607@subsubheading @value{GDBN} Command
19608
19609The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19610@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19611
19612@subsubheading Example
19613
19614@smallexample
19615(@value{GDBP})
19616-stack-select-frame 2
19617^done
19618(@value{GDBP})
19619@end smallexample
19620
19621@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19622@node GDB/MI Symbol Query
19623@section @sc{gdb/mi} Symbol Query Commands
19624
19625
19626@subheading The @code{-symbol-info-address} Command
19627@findex -symbol-info-address
19628
19629@subsubheading Synopsis
19630
19631@smallexample
19632 -symbol-info-address @var{symbol}
19633@end smallexample
19634
19635Describe where @var{symbol} is stored.
19636
19637@subsubheading @value{GDBN} Command
19638
19639The corresponding @value{GDBN} command is @samp{info address}.
19640
19641@subsubheading Example
19642N.A.
19643
19644
19645@subheading The @code{-symbol-info-file} Command
19646@findex -symbol-info-file
19647
19648@subsubheading Synopsis
19649
19650@smallexample
19651 -symbol-info-file
19652@end smallexample
19653
19654Show the file for the symbol.
19655
19656@subsubheading @value{GDBN} Command
19657
19658There's no equivalent @value{GDBN} command. @code{gdbtk} has
19659@samp{gdb_find_file}.
19660
19661@subsubheading Example
19662N.A.
19663
19664
19665@subheading The @code{-symbol-info-function} Command
19666@findex -symbol-info-function
19667
19668@subsubheading Synopsis
19669
19670@smallexample
19671 -symbol-info-function
19672@end smallexample
19673
19674Show which function the symbol lives in.
19675
19676@subsubheading @value{GDBN} Command
19677
19678@samp{gdb_get_function} in @code{gdbtk}.
19679
19680@subsubheading Example
19681N.A.
19682
19683
19684@subheading The @code{-symbol-info-line} Command
19685@findex -symbol-info-line
19686
19687@subsubheading Synopsis
19688
19689@smallexample
19690 -symbol-info-line
19691@end smallexample
19692
19693Show the core addresses of the code for a source line.
19694
19695@subsubheading @value{GDBN} Command
19696
71952f4c 19697The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19698@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19699
19700@subsubheading Example
19701N.A.
19702
19703
19704@subheading The @code{-symbol-info-symbol} Command
19705@findex -symbol-info-symbol
19706
19707@subsubheading Synopsis
19708
19709@smallexample
19710 -symbol-info-symbol @var{addr}
19711@end smallexample
19712
19713Describe what symbol is at location @var{addr}.
19714
19715@subsubheading @value{GDBN} Command
19716
19717The corresponding @value{GDBN} command is @samp{info symbol}.
19718
19719@subsubheading Example
19720N.A.
19721
19722
19723@subheading The @code{-symbol-list-functions} Command
19724@findex -symbol-list-functions
19725
19726@subsubheading Synopsis
19727
19728@smallexample
19729 -symbol-list-functions
19730@end smallexample
19731
19732List the functions in the executable.
19733
19734@subsubheading @value{GDBN} Command
19735
19736@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19737@samp{gdb_search} in @code{gdbtk}.
19738
19739@subsubheading Example
19740N.A.
19741
19742
32e7087d
JB
19743@subheading The @code{-symbol-list-lines} Command
19744@findex -symbol-list-lines
19745
19746@subsubheading Synopsis
19747
19748@smallexample
19749 -symbol-list-lines @var{filename}
19750@end smallexample
19751
19752Print the list of lines that contain code and their associated program
19753addresses for the given source filename. The entries are sorted in
19754ascending PC order.
19755
19756@subsubheading @value{GDBN} Command
19757
19758There is no corresponding @value{GDBN} command.
19759
19760@subsubheading Example
19761@smallexample
19762(@value{GDBP})
19763-symbol-list-lines basics.c
54ff5908 19764^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19765(@value{GDBP})
19766@end smallexample
19767
19768
922fbb7b
AC
19769@subheading The @code{-symbol-list-types} Command
19770@findex -symbol-list-types
19771
19772@subsubheading Synopsis
19773
19774@smallexample
19775 -symbol-list-types
19776@end smallexample
19777
19778List all the type names.
19779
19780@subsubheading @value{GDBN} Command
19781
19782The corresponding commands are @samp{info types} in @value{GDBN},
19783@samp{gdb_search} in @code{gdbtk}.
19784
19785@subsubheading Example
19786N.A.
19787
19788
19789@subheading The @code{-symbol-list-variables} Command
19790@findex -symbol-list-variables
19791
19792@subsubheading Synopsis
19793
19794@smallexample
19795 -symbol-list-variables
19796@end smallexample
19797
19798List all the global and static variable names.
19799
19800@subsubheading @value{GDBN} Command
19801
19802@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19803
19804@subsubheading Example
19805N.A.
19806
19807
19808@subheading The @code{-symbol-locate} Command
19809@findex -symbol-locate
19810
19811@subsubheading Synopsis
19812
19813@smallexample
19814 -symbol-locate
19815@end smallexample
19816
19817@subsubheading @value{GDBN} Command
19818
19819@samp{gdb_loc} in @code{gdbtk}.
19820
19821@subsubheading Example
19822N.A.
19823
19824
19825@subheading The @code{-symbol-type} Command
19826@findex -symbol-type
19827
19828@subsubheading Synopsis
19829
19830@smallexample
19831 -symbol-type @var{variable}
19832@end smallexample
19833
19834Show type of @var{variable}.
19835
19836@subsubheading @value{GDBN} Command
19837
19838The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19839@samp{gdb_obj_variable}.
19840
19841@subsubheading Example
19842N.A.
19843
19844
19845@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19846@node GDB/MI Target Manipulation
19847@section @sc{gdb/mi} Target Manipulation Commands
19848
19849
19850@subheading The @code{-target-attach} Command
19851@findex -target-attach
19852
19853@subsubheading Synopsis
19854
19855@smallexample
19856 -target-attach @var{pid} | @var{file}
19857@end smallexample
19858
19859Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19860
19861@subsubheading @value{GDBN} command
19862
19863The corresponding @value{GDBN} command is @samp{attach}.
19864
19865@subsubheading Example
19866N.A.
19867
19868
19869@subheading The @code{-target-compare-sections} Command
19870@findex -target-compare-sections
19871
19872@subsubheading Synopsis
19873
19874@smallexample
19875 -target-compare-sections [ @var{section} ]
19876@end smallexample
19877
19878Compare data of section @var{section} on target to the exec file.
19879Without the argument, all sections are compared.
19880
19881@subsubheading @value{GDBN} Command
19882
19883The @value{GDBN} equivalent is @samp{compare-sections}.
19884
19885@subsubheading Example
19886N.A.
19887
19888
19889@subheading The @code{-target-detach} Command
19890@findex -target-detach
19891
19892@subsubheading Synopsis
19893
19894@smallexample
19895 -target-detach
19896@end smallexample
19897
19898Disconnect from the remote target. There's no output.
19899
19900@subsubheading @value{GDBN} command
19901
19902The corresponding @value{GDBN} command is @samp{detach}.
19903
19904@subsubheading Example
19905
19906@smallexample
19907(@value{GDBP})
19908-target-detach
19909^done
19910(@value{GDBP})
19911@end smallexample
19912
19913
07f31aa6
DJ
19914@subheading The @code{-target-disconnect} Command
19915@findex -target-disconnect
19916
19917@subsubheading Synopsis
19918
19919@example
19920 -target-disconnect
19921@end example
19922
19923Disconnect from the remote target. There's no output.
19924
19925@subsubheading @value{GDBN} command
19926
19927The corresponding @value{GDBN} command is @samp{disconnect}.
19928
19929@subsubheading Example
19930
19931@smallexample
19932(@value{GDBP})
19933-target-disconnect
19934^done
19935(@value{GDBP})
19936@end smallexample
19937
19938
922fbb7b
AC
19939@subheading The @code{-target-download} Command
19940@findex -target-download
19941
19942@subsubheading Synopsis
19943
19944@smallexample
19945 -target-download
19946@end smallexample
19947
19948Loads the executable onto the remote target.
19949It prints out an update message every half second, which includes the fields:
19950
19951@table @samp
19952@item section
19953The name of the section.
19954@item section-sent
19955The size of what has been sent so far for that section.
19956@item section-size
19957The size of the section.
19958@item total-sent
19959The total size of what was sent so far (the current and the previous sections).
19960@item total-size
19961The size of the overall executable to download.
19962@end table
19963
19964@noindent
19965Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19966@sc{gdb/mi} Output Syntax}).
19967
19968In addition, it prints the name and size of the sections, as they are
19969downloaded. These messages include the following fields:
19970
19971@table @samp
19972@item section
19973The name of the section.
19974@item section-size
19975The size of the section.
19976@item total-size
19977The size of the overall executable to download.
19978@end table
19979
19980@noindent
19981At the end, a summary is printed.
19982
19983@subsubheading @value{GDBN} Command
19984
19985The corresponding @value{GDBN} command is @samp{load}.
19986
19987@subsubheading Example
19988
19989Note: each status message appears on a single line. Here the messages
19990have been broken down so that they can fit onto a page.
19991
19992@smallexample
19993(@value{GDBP})
19994-target-download
19995+download,@{section=".text",section-size="6668",total-size="9880"@}
19996+download,@{section=".text",section-sent="512",section-size="6668",
19997total-sent="512",total-size="9880"@}
19998+download,@{section=".text",section-sent="1024",section-size="6668",
19999total-sent="1024",total-size="9880"@}
20000+download,@{section=".text",section-sent="1536",section-size="6668",
20001total-sent="1536",total-size="9880"@}
20002+download,@{section=".text",section-sent="2048",section-size="6668",
20003total-sent="2048",total-size="9880"@}
20004+download,@{section=".text",section-sent="2560",section-size="6668",
20005total-sent="2560",total-size="9880"@}
20006+download,@{section=".text",section-sent="3072",section-size="6668",
20007total-sent="3072",total-size="9880"@}
20008+download,@{section=".text",section-sent="3584",section-size="6668",
20009total-sent="3584",total-size="9880"@}
20010+download,@{section=".text",section-sent="4096",section-size="6668",
20011total-sent="4096",total-size="9880"@}
20012+download,@{section=".text",section-sent="4608",section-size="6668",
20013total-sent="4608",total-size="9880"@}
20014+download,@{section=".text",section-sent="5120",section-size="6668",
20015total-sent="5120",total-size="9880"@}
20016+download,@{section=".text",section-sent="5632",section-size="6668",
20017total-sent="5632",total-size="9880"@}
20018+download,@{section=".text",section-sent="6144",section-size="6668",
20019total-sent="6144",total-size="9880"@}
20020+download,@{section=".text",section-sent="6656",section-size="6668",
20021total-sent="6656",total-size="9880"@}
20022+download,@{section=".init",section-size="28",total-size="9880"@}
20023+download,@{section=".fini",section-size="28",total-size="9880"@}
20024+download,@{section=".data",section-size="3156",total-size="9880"@}
20025+download,@{section=".data",section-sent="512",section-size="3156",
20026total-sent="7236",total-size="9880"@}
20027+download,@{section=".data",section-sent="1024",section-size="3156",
20028total-sent="7748",total-size="9880"@}
20029+download,@{section=".data",section-sent="1536",section-size="3156",
20030total-sent="8260",total-size="9880"@}
20031+download,@{section=".data",section-sent="2048",section-size="3156",
20032total-sent="8772",total-size="9880"@}
20033+download,@{section=".data",section-sent="2560",section-size="3156",
20034total-sent="9284",total-size="9880"@}
20035+download,@{section=".data",section-sent="3072",section-size="3156",
20036total-sent="9796",total-size="9880"@}
20037^done,address="0x10004",load-size="9880",transfer-rate="6586",
20038write-rate="429"
20039(@value{GDBP})
20040@end smallexample
20041
20042
20043@subheading The @code{-target-exec-status} Command
20044@findex -target-exec-status
20045
20046@subsubheading Synopsis
20047
20048@smallexample
20049 -target-exec-status
20050@end smallexample
20051
20052Provide information on the state of the target (whether it is running or
20053not, for instance).
20054
20055@subsubheading @value{GDBN} Command
20056
20057There's no equivalent @value{GDBN} command.
20058
20059@subsubheading Example
20060N.A.
20061
20062
20063@subheading The @code{-target-list-available-targets} Command
20064@findex -target-list-available-targets
20065
20066@subsubheading Synopsis
20067
20068@smallexample
20069 -target-list-available-targets
20070@end smallexample
20071
20072List the possible targets to connect to.
20073
20074@subsubheading @value{GDBN} Command
20075
20076The corresponding @value{GDBN} command is @samp{help target}.
20077
20078@subsubheading Example
20079N.A.
20080
20081
20082@subheading The @code{-target-list-current-targets} Command
20083@findex -target-list-current-targets
20084
20085@subsubheading Synopsis
20086
20087@smallexample
20088 -target-list-current-targets
20089@end smallexample
20090
20091Describe the current target.
20092
20093@subsubheading @value{GDBN} Command
20094
20095The corresponding information is printed by @samp{info file} (among
20096other things).
20097
20098@subsubheading Example
20099N.A.
20100
20101
20102@subheading The @code{-target-list-parameters} Command
20103@findex -target-list-parameters
20104
20105@subsubheading Synopsis
20106
20107@smallexample
20108 -target-list-parameters
20109@end smallexample
20110
20111@c ????
20112
20113@subsubheading @value{GDBN} Command
20114
20115No equivalent.
20116
20117@subsubheading Example
20118N.A.
20119
20120
20121@subheading The @code{-target-select} Command
20122@findex -target-select
20123
20124@subsubheading Synopsis
20125
20126@smallexample
20127 -target-select @var{type} @var{parameters @dots{}}
20128@end smallexample
20129
20130Connect @value{GDBN} to the remote target. This command takes two args:
20131
20132@table @samp
20133@item @var{type}
20134The type of target, for instance @samp{async}, @samp{remote}, etc.
20135@item @var{parameters}
20136Device names, host names and the like. @xref{Target Commands, ,
20137Commands for managing targets}, for more details.
20138@end table
20139
20140The output is a connection notification, followed by the address at
20141which the target program is, in the following form:
20142
20143@smallexample
20144^connected,addr="@var{address}",func="@var{function name}",
20145 args=[@var{arg list}]
20146@end smallexample
20147
20148@subsubheading @value{GDBN} Command
20149
20150The corresponding @value{GDBN} command is @samp{target}.
20151
20152@subsubheading Example
20153
20154@smallexample
20155(@value{GDBP})
20156-target-select async /dev/ttya
20157^connected,addr="0xfe00a300",func="??",args=[]
20158(@value{GDBP})
20159@end smallexample
20160
20161@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20162@node GDB/MI Thread Commands
20163@section @sc{gdb/mi} Thread Commands
20164
20165
20166@subheading The @code{-thread-info} Command
20167@findex -thread-info
20168
20169@subsubheading Synopsis
20170
20171@smallexample
20172 -thread-info
20173@end smallexample
20174
20175@subsubheading @value{GDBN} command
20176
20177No equivalent.
20178
20179@subsubheading Example
20180N.A.
20181
20182
20183@subheading The @code{-thread-list-all-threads} Command
20184@findex -thread-list-all-threads
20185
20186@subsubheading Synopsis
20187
20188@smallexample
20189 -thread-list-all-threads
20190@end smallexample
20191
20192@subsubheading @value{GDBN} Command
20193
20194The equivalent @value{GDBN} command is @samp{info threads}.
20195
20196@subsubheading Example
20197N.A.
20198
20199
20200@subheading The @code{-thread-list-ids} Command
20201@findex -thread-list-ids
20202
20203@subsubheading Synopsis
20204
20205@smallexample
20206 -thread-list-ids
20207@end smallexample
20208
20209Produces a list of the currently known @value{GDBN} thread ids. At the
20210end of the list it also prints the total number of such threads.
20211
20212@subsubheading @value{GDBN} Command
20213
20214Part of @samp{info threads} supplies the same information.
20215
20216@subsubheading Example
20217
20218No threads present, besides the main process:
20219
20220@smallexample
20221(@value{GDBP})
20222-thread-list-ids
20223^done,thread-ids=@{@},number-of-threads="0"
20224(@value{GDBP})
20225@end smallexample
20226
20227
20228Several threads:
20229
20230@smallexample
20231(@value{GDBP})
20232-thread-list-ids
20233^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20234number-of-threads="3"
20235(@value{GDBP})
20236@end smallexample
20237
20238
20239@subheading The @code{-thread-select} Command
20240@findex -thread-select
20241
20242@subsubheading Synopsis
20243
20244@smallexample
20245 -thread-select @var{threadnum}
20246@end smallexample
20247
20248Make @var{threadnum} the current thread. It prints the number of the new
20249current thread, and the topmost frame for that thread.
20250
20251@subsubheading @value{GDBN} Command
20252
20253The corresponding @value{GDBN} command is @samp{thread}.
20254
20255@subsubheading Example
20256
20257@smallexample
20258(@value{GDBP})
20259-exec-next
20260^running
20261(@value{GDBP})
20262*stopped,reason="end-stepping-range",thread-id="2",line="187",
20263file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20264(@value{GDBP})
20265-thread-list-ids
20266^done,
20267thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20268number-of-threads="3"
20269(@value{GDBP})
20270-thread-select 3
20271^done,new-thread-id="3",
20272frame=@{level="0",func="vprintf",
20273args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20274@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20275(@value{GDBP})
20276@end smallexample
20277
20278@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20279@node GDB/MI Tracepoint Commands
20280@section @sc{gdb/mi} Tracepoint Commands
20281
20282The tracepoint commands are not yet implemented.
20283
20284@c @subheading -trace-actions
20285
20286@c @subheading -trace-delete
20287
20288@c @subheading -trace-disable
20289
20290@c @subheading -trace-dump
20291
20292@c @subheading -trace-enable
20293
20294@c @subheading -trace-exists
20295
20296@c @subheading -trace-find
20297
20298@c @subheading -trace-frame-number
20299
20300@c @subheading -trace-info
20301
20302@c @subheading -trace-insert
20303
20304@c @subheading -trace-list
20305
20306@c @subheading -trace-pass-count
20307
20308@c @subheading -trace-save
20309
20310@c @subheading -trace-start
20311
20312@c @subheading -trace-stop
20313
20314
20315@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20316@node GDB/MI Variable Objects
20317@section @sc{gdb/mi} Variable Objects
20318
20319
20320@subheading Motivation for Variable Objects in @sc{gdb/mi}
20321
20322For the implementation of a variable debugger window (locals, watched
20323expressions, etc.), we are proposing the adaptation of the existing code
20324used by @code{Insight}.
20325
20326The two main reasons for that are:
20327
20328@enumerate 1
20329@item
20330It has been proven in practice (it is already on its second generation).
20331
20332@item
20333It will shorten development time (needless to say how important it is
20334now).
20335@end enumerate
20336
20337The original interface was designed to be used by Tcl code, so it was
20338slightly changed so it could be used through @sc{gdb/mi}. This section
20339describes the @sc{gdb/mi} operations that will be available and gives some
20340hints about their use.
20341
20342@emph{Note}: In addition to the set of operations described here, we
20343expect the @sc{gui} implementation of a variable window to require, at
20344least, the following operations:
20345
20346@itemize @bullet
20347@item @code{-gdb-show} @code{output-radix}
20348@item @code{-stack-list-arguments}
20349@item @code{-stack-list-locals}
20350@item @code{-stack-select-frame}
20351@end itemize
20352
20353@subheading Introduction to Variable Objects in @sc{gdb/mi}
20354
20355@cindex variable objects in @sc{gdb/mi}
20356The basic idea behind variable objects is the creation of a named object
20357to represent a variable, an expression, a memory location or even a CPU
20358register. For each object created, a set of operations is available for
20359examining or changing its properties.
20360
20361Furthermore, complex data types, such as C structures, are represented
20362in a tree format. For instance, the @code{struct} type variable is the
20363root and the children will represent the struct members. If a child
20364is itself of a complex type, it will also have children of its own.
20365Appropriate language differences are handled for C, C@t{++} and Java.
20366
20367When returning the actual values of the objects, this facility allows
20368for the individual selection of the display format used in the result
20369creation. It can be chosen among: binary, decimal, hexadecimal, octal
20370and natural. Natural refers to a default format automatically
20371chosen based on the variable type (like decimal for an @code{int}, hex
20372for pointers, etc.).
20373
20374The following is the complete set of @sc{gdb/mi} operations defined to
20375access this functionality:
20376
20377@multitable @columnfractions .4 .6
20378@item @strong{Operation}
20379@tab @strong{Description}
20380
20381@item @code{-var-create}
20382@tab create a variable object
20383@item @code{-var-delete}
20384@tab delete the variable object and its children
20385@item @code{-var-set-format}
20386@tab set the display format of this variable
20387@item @code{-var-show-format}
20388@tab show the display format of this variable
20389@item @code{-var-info-num-children}
20390@tab tells how many children this object has
20391@item @code{-var-list-children}
20392@tab return a list of the object's children
20393@item @code{-var-info-type}
20394@tab show the type of this variable object
20395@item @code{-var-info-expression}
20396@tab print what this variable object represents
20397@item @code{-var-show-attributes}
20398@tab is this variable editable? does it exist here?
20399@item @code{-var-evaluate-expression}
20400@tab get the value of this variable
20401@item @code{-var-assign}
20402@tab set the value of this variable
20403@item @code{-var-update}
20404@tab update the variable and its children
20405@end multitable
20406
20407In the next subsection we describe each operation in detail and suggest
20408how it can be used.
20409
20410@subheading Description And Use of Operations on Variable Objects
20411
20412@subheading The @code{-var-create} Command
20413@findex -var-create
20414
20415@subsubheading Synopsis
20416
20417@smallexample
20418 -var-create @{@var{name} | "-"@}
20419 @{@var{frame-addr} | "*"@} @var{expression}
20420@end smallexample
20421
20422This operation creates a variable object, which allows the monitoring of
20423a variable, the result of an expression, a memory cell or a CPU
20424register.
20425
20426The @var{name} parameter is the string by which the object can be
20427referenced. It must be unique. If @samp{-} is specified, the varobj
20428system will generate a string ``varNNNNNN'' automatically. It will be
20429unique provided that one does not specify @var{name} on that format.
20430The command fails if a duplicate name is found.
20431
20432The frame under which the expression should be evaluated can be
20433specified by @var{frame-addr}. A @samp{*} indicates that the current
20434frame should be used.
20435
20436@var{expression} is any expression valid on the current language set (must not
20437begin with a @samp{*}), or one of the following:
20438
20439@itemize @bullet
20440@item
20441@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20442
20443@item
20444@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20445
20446@item
20447@samp{$@var{regname}} --- a CPU register name
20448@end itemize
20449
20450@subsubheading Result
20451
20452This operation returns the name, number of children and the type of the
20453object created. Type is returned as a string as the ones generated by
20454the @value{GDBN} CLI:
20455
20456@smallexample
20457 name="@var{name}",numchild="N",type="@var{type}"
20458@end smallexample
20459
20460
20461@subheading The @code{-var-delete} Command
20462@findex -var-delete
20463
20464@subsubheading Synopsis
20465
20466@smallexample
20467 -var-delete @var{name}
20468@end smallexample
20469
20470Deletes a previously created variable object and all of its children.
20471
20472Returns an error if the object @var{name} is not found.
20473
20474
20475@subheading The @code{-var-set-format} Command
20476@findex -var-set-format
20477
20478@subsubheading Synopsis
20479
20480@smallexample
20481 -var-set-format @var{name} @var{format-spec}
20482@end smallexample
20483
20484Sets the output format for the value of the object @var{name} to be
20485@var{format-spec}.
20486
20487The syntax for the @var{format-spec} is as follows:
20488
20489@smallexample
20490 @var{format-spec} @expansion{}
20491 @{binary | decimal | hexadecimal | octal | natural@}
20492@end smallexample
20493
20494
20495@subheading The @code{-var-show-format} Command
20496@findex -var-show-format
20497
20498@subsubheading Synopsis
20499
20500@smallexample
20501 -var-show-format @var{name}
20502@end smallexample
20503
20504Returns the format used to display the value of the object @var{name}.
20505
20506@smallexample
20507 @var{format} @expansion{}
20508 @var{format-spec}
20509@end smallexample
20510
20511
20512@subheading The @code{-var-info-num-children} Command
20513@findex -var-info-num-children
20514
20515@subsubheading Synopsis
20516
20517@smallexample
20518 -var-info-num-children @var{name}
20519@end smallexample
20520
20521Returns the number of children of a variable object @var{name}:
20522
20523@smallexample
20524 numchild=@var{n}
20525@end smallexample
20526
20527
20528@subheading The @code{-var-list-children} Command
20529@findex -var-list-children
20530
20531@subsubheading Synopsis
20532
20533@smallexample
bc8ced35 20534 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20535@end smallexample
265eeb58 20536@anchor{-var-list-children}
922fbb7b 20537
265eeb58
NR
20538Return a list of the children of the specified variable object and
20539create variable objects for them, if they do not already exist. With
20540a single argument or if @var{print-values} has a value for of 0 or
20541@code{--no-values}, print only the names of the variables; if
20542@var{print-values} is 1 or @code{--all-values}, also print their
20543values; and if it is 2 or @code{--simple-values} print the name and
20544value for simple data types and just the name for arrays, structures
20545and unions.
bc8ced35
NR
20546
20547@subsubheading Example
922fbb7b
AC
20548
20549@smallexample
bc8ced35
NR
20550(@value{GDBP})
20551 -var-list-children n
265eeb58 20552 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20553 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20554(@value{GDBP})
20555 -var-list-children --all-values n
265eeb58 20556 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20557 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20558@end smallexample
20559
20560
20561@subheading The @code{-var-info-type} Command
20562@findex -var-info-type
20563
20564@subsubheading Synopsis
20565
20566@smallexample
20567 -var-info-type @var{name}
20568@end smallexample
20569
20570Returns the type of the specified variable @var{name}. The type is
20571returned as a string in the same format as it is output by the
20572@value{GDBN} CLI:
20573
20574@smallexample
20575 type=@var{typename}
20576@end smallexample
20577
20578
20579@subheading The @code{-var-info-expression} Command
20580@findex -var-info-expression
20581
20582@subsubheading Synopsis
20583
20584@smallexample
20585 -var-info-expression @var{name}
20586@end smallexample
20587
20588Returns what is represented by the variable object @var{name}:
20589
20590@smallexample
20591 lang=@var{lang-spec},exp=@var{expression}
20592@end smallexample
20593
20594@noindent
20595where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20596
20597@subheading The @code{-var-show-attributes} Command
20598@findex -var-show-attributes
20599
20600@subsubheading Synopsis
20601
20602@smallexample
20603 -var-show-attributes @var{name}
20604@end smallexample
20605
20606List attributes of the specified variable object @var{name}:
20607
20608@smallexample
20609 status=@var{attr} [ ( ,@var{attr} )* ]
20610@end smallexample
20611
20612@noindent
20613where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20614
20615@subheading The @code{-var-evaluate-expression} Command
20616@findex -var-evaluate-expression
20617
20618@subsubheading Synopsis
20619
20620@smallexample
20621 -var-evaluate-expression @var{name}
20622@end smallexample
20623
20624Evaluates the expression that is represented by the specified variable
20625object and returns its value as a string in the current format specified
20626for the object:
20627
20628@smallexample
20629 value=@var{value}
20630@end smallexample
20631
20632Note that one must invoke @code{-var-list-children} for a variable
20633before the value of a child variable can be evaluated.
20634
20635@subheading The @code{-var-assign} Command
20636@findex -var-assign
20637
20638@subsubheading Synopsis
20639
20640@smallexample
20641 -var-assign @var{name} @var{expression}
20642@end smallexample
20643
20644Assigns the value of @var{expression} to the variable object specified
20645by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20646value is altered by the assign, the variable will show up in any
922fbb7b
AC
20647subsequent @code{-var-update} list.
20648
20649@subsubheading Example
20650
20651@smallexample
20652(@value{GDBP})
20653-var-assign var1 3
20654^done,value="3"
20655(@value{GDBP})
20656-var-update *
20657^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20658(@value{GDBP})
20659@end smallexample
20660
20661@subheading The @code{-var-update} Command
20662@findex -var-update
20663
20664@subsubheading Synopsis
20665
20666@smallexample
265eeb58 20667 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
20668@end smallexample
20669
20670Update the value of the variable object @var{name} by evaluating its
20671expression after fetching all the new values from memory or registers.
265eeb58 20672A @samp{*} causes all existing variable objects to be updated. The
656d5e12
EZ
20673option @var{print-values} determines whether names both and values, or
20674just names are printed in the manner described for
20675@code{-var-list-children} (@pxref{-var-list-children}).
265eeb58
NR
20676
20677@subsubheading Example
922fbb7b 20678
265eeb58
NR
20679@smallexample
20680(@value{GDBP})
20681-var-assign var1 3
20682^done,value="3"
20683(@value{GDBP})
20684-var-update --all-values var1
20685^done,changelist=[@{name="var1",value="3",in_scope="true",
20686type_changed="false"@}]
20687(@value{GDBP})
20688@end smallexample
922fbb7b
AC
20689
20690@node Annotations
20691@chapter @value{GDBN} Annotations
20692
086432e2
AC
20693This chapter describes annotations in @value{GDBN}. Annotations were
20694designed to interface @value{GDBN} to graphical user interfaces or other
20695similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20696relatively high level.
20697
086432e2
AC
20698The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20699(@pxref{GDB/MI}).
20700
922fbb7b
AC
20701@ignore
20702This is Edition @value{EDITION}, @value{DATE}.
20703@end ignore
20704
20705@menu
20706* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20707* Prompting:: Annotations marking @value{GDBN}'s need for input.
20708* Errors:: Annotations for error messages.
922fbb7b
AC
20709* Invalidation:: Some annotations describe things now invalid.
20710* Annotations for Running::
20711 Whether the program is running, how it stopped, etc.
20712* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20713@end menu
20714
20715@node Annotations Overview
20716@section What is an Annotation?
20717@cindex annotations
20718
922fbb7b
AC
20719Annotations start with a newline character, two @samp{control-z}
20720characters, and the name of the annotation. If there is no additional
20721information associated with this annotation, the name of the annotation
20722is followed immediately by a newline. If there is additional
20723information, the name of the annotation is followed by a space, the
20724additional information, and a newline. The additional information
20725cannot contain newline characters.
20726
20727Any output not beginning with a newline and two @samp{control-z}
20728characters denotes literal output from @value{GDBN}. Currently there is
20729no need for @value{GDBN} to output a newline followed by two
20730@samp{control-z} characters, but if there was such a need, the
20731annotations could be extended with an @samp{escape} annotation which
20732means those three characters as output.
20733
086432e2
AC
20734The annotation @var{level}, which is specified using the
20735@option{--annotate} command line option (@pxref{Mode Options}), controls
20736how much information @value{GDBN} prints together with its prompt,
20737values of expressions, source lines, and other types of output. Level 0
20738is for no anntations, level 1 is for use when @value{GDBN} is run as a
20739subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20740for programs that control @value{GDBN}, and level 2 annotations have
20741been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20742Interface, annotate, GDB's Obsolete Annotations}).
20743
20744@table @code
20745@kindex set annotate
20746@item set annotate @var{level}
e09f16f9 20747The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20748annotations to the specified @var{level}.
9c16f35a
EZ
20749
20750@item show annotate
20751@kindex show annotate
20752Show the current annotation level.
09d4efe1
EZ
20753@end table
20754
20755This chapter describes level 3 annotations.
086432e2 20756
922fbb7b
AC
20757A simple example of starting up @value{GDBN} with annotations is:
20758
20759@smallexample
086432e2
AC
20760$ @kbd{gdb --annotate=3}
20761GNU gdb 6.0
20762Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20763GDB is free software, covered by the GNU General Public License,
20764and you are welcome to change it and/or distribute copies of it
20765under certain conditions.
20766Type "show copying" to see the conditions.
20767There is absolutely no warranty for GDB. Type "show warranty"
20768for details.
086432e2 20769This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20770
20771^Z^Zpre-prompt
f7dc1244 20772(@value{GDBP})
922fbb7b 20773^Z^Zprompt
086432e2 20774@kbd{quit}
922fbb7b
AC
20775
20776^Z^Zpost-prompt
b383017d 20777$
922fbb7b
AC
20778@end smallexample
20779
20780Here @samp{quit} is input to @value{GDBN}; the rest is output from
20781@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20782denotes a @samp{control-z} character) are annotations; the rest is
20783output from @value{GDBN}.
20784
922fbb7b
AC
20785@node Prompting
20786@section Annotation for @value{GDBN} Input
20787
20788@cindex annotations for prompts
20789When @value{GDBN} prompts for input, it annotates this fact so it is possible
20790to know when to send output, when the output from a given command is
20791over, etc.
20792
20793Different kinds of input each have a different @dfn{input type}. Each
20794input type has three annotations: a @code{pre-} annotation, which
20795denotes the beginning of any prompt which is being output, a plain
20796annotation, which denotes the end of the prompt, and then a @code{post-}
20797annotation which denotes the end of any echo which may (or may not) be
20798associated with the input. For example, the @code{prompt} input type
20799features the following annotations:
20800
20801@smallexample
20802^Z^Zpre-prompt
20803^Z^Zprompt
20804^Z^Zpost-prompt
20805@end smallexample
20806
20807The input types are
20808
20809@table @code
20810@findex pre-prompt
20811@findex prompt
20812@findex post-prompt
20813@item prompt
20814When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20815
20816@findex pre-commands
20817@findex commands
20818@findex post-commands
20819@item commands
20820When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20821command. The annotations are repeated for each command which is input.
20822
20823@findex pre-overload-choice
20824@findex overload-choice
20825@findex post-overload-choice
20826@item overload-choice
20827When @value{GDBN} wants the user to select between various overloaded functions.
20828
20829@findex pre-query
20830@findex query
20831@findex post-query
20832@item query
20833When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20834
20835@findex pre-prompt-for-continue
20836@findex prompt-for-continue
20837@findex post-prompt-for-continue
20838@item prompt-for-continue
20839When @value{GDBN} is asking the user to press return to continue. Note: Don't
20840expect this to work well; instead use @code{set height 0} to disable
20841prompting. This is because the counting of lines is buggy in the
20842presence of annotations.
20843@end table
20844
20845@node Errors
20846@section Errors
20847@cindex annotations for errors, warnings and interrupts
20848
20849@findex quit
20850@smallexample
20851^Z^Zquit
20852@end smallexample
20853
20854This annotation occurs right before @value{GDBN} responds to an interrupt.
20855
20856@findex error
20857@smallexample
20858^Z^Zerror
20859@end smallexample
20860
20861This annotation occurs right before @value{GDBN} responds to an error.
20862
20863Quit and error annotations indicate that any annotations which @value{GDBN} was
20864in the middle of may end abruptly. For example, if a
20865@code{value-history-begin} annotation is followed by a @code{error}, one
20866cannot expect to receive the matching @code{value-history-end}. One
20867cannot expect not to receive it either, however; an error annotation
20868does not necessarily mean that @value{GDBN} is immediately returning all the way
20869to the top level.
20870
20871@findex error-begin
20872A quit or error annotation may be preceded by
20873
20874@smallexample
20875^Z^Zerror-begin
20876@end smallexample
20877
20878Any output between that and the quit or error annotation is the error
20879message.
20880
20881Warning messages are not yet annotated.
20882@c If we want to change that, need to fix warning(), type_error(),
20883@c range_error(), and possibly other places.
20884
922fbb7b
AC
20885@node Invalidation
20886@section Invalidation Notices
20887
20888@cindex annotations for invalidation messages
20889The following annotations say that certain pieces of state may have
20890changed.
20891
20892@table @code
20893@findex frames-invalid
20894@item ^Z^Zframes-invalid
20895
20896The frames (for example, output from the @code{backtrace} command) may
20897have changed.
20898
20899@findex breakpoints-invalid
20900@item ^Z^Zbreakpoints-invalid
20901
20902The breakpoints may have changed. For example, the user just added or
20903deleted a breakpoint.
20904@end table
20905
20906@node Annotations for Running
20907@section Running the Program
20908@cindex annotations for running programs
20909
20910@findex starting
20911@findex stopping
20912When the program starts executing due to a @value{GDBN} command such as
b383017d 20913@code{step} or @code{continue},
922fbb7b
AC
20914
20915@smallexample
20916^Z^Zstarting
20917@end smallexample
20918
b383017d 20919is output. When the program stops,
922fbb7b
AC
20920
20921@smallexample
20922^Z^Zstopped
20923@end smallexample
20924
20925is output. Before the @code{stopped} annotation, a variety of
20926annotations describe how the program stopped.
20927
20928@table @code
20929@findex exited
20930@item ^Z^Zexited @var{exit-status}
20931The program exited, and @var{exit-status} is the exit status (zero for
20932successful exit, otherwise nonzero).
20933
20934@findex signalled
20935@findex signal-name
20936@findex signal-name-end
20937@findex signal-string
20938@findex signal-string-end
20939@item ^Z^Zsignalled
20940The program exited with a signal. After the @code{^Z^Zsignalled}, the
20941annotation continues:
20942
20943@smallexample
20944@var{intro-text}
20945^Z^Zsignal-name
20946@var{name}
20947^Z^Zsignal-name-end
20948@var{middle-text}
20949^Z^Zsignal-string
20950@var{string}
20951^Z^Zsignal-string-end
20952@var{end-text}
20953@end smallexample
20954
20955@noindent
20956where @var{name} is the name of the signal, such as @code{SIGILL} or
20957@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20958as @code{Illegal Instruction} or @code{Segmentation fault}.
20959@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20960user's benefit and have no particular format.
20961
20962@findex signal
20963@item ^Z^Zsignal
20964The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20965just saying that the program received the signal, not that it was
20966terminated with it.
20967
20968@findex breakpoint
20969@item ^Z^Zbreakpoint @var{number}
20970The program hit breakpoint number @var{number}.
20971
20972@findex watchpoint
20973@item ^Z^Zwatchpoint @var{number}
20974The program hit watchpoint number @var{number}.
20975@end table
20976
20977@node Source Annotations
20978@section Displaying Source
20979@cindex annotations for source display
20980
20981@findex source
20982The following annotation is used instead of displaying source code:
20983
20984@smallexample
20985^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20986@end smallexample
20987
20988where @var{filename} is an absolute file name indicating which source
20989file, @var{line} is the line number within that file (where 1 is the
20990first line in the file), @var{character} is the character position
20991within the file (where 0 is the first character in the file) (for most
20992debug formats this will necessarily point to the beginning of a line),
20993@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20994line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20995@var{addr} is the address in the target program associated with the
20996source which is being displayed. @var{addr} is in the form @samp{0x}
20997followed by one or more lowercase hex digits (note that this does not
20998depend on the language).
20999
8e04817f
AC
21000@node GDB Bugs
21001@chapter Reporting Bugs in @value{GDBN}
21002@cindex bugs in @value{GDBN}
21003@cindex reporting bugs in @value{GDBN}
c906108c 21004
8e04817f 21005Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 21006
8e04817f
AC
21007Reporting a bug may help you by bringing a solution to your problem, or it
21008may not. But in any case the principal function of a bug report is to help
21009the entire community by making the next version of @value{GDBN} work better. Bug
21010reports are your contribution to the maintenance of @value{GDBN}.
c906108c 21011
8e04817f
AC
21012In order for a bug report to serve its purpose, you must include the
21013information that enables us to fix the bug.
c4555f82
SC
21014
21015@menu
8e04817f
AC
21016* Bug Criteria:: Have you found a bug?
21017* Bug Reporting:: How to report bugs
c4555f82
SC
21018@end menu
21019
8e04817f
AC
21020@node Bug Criteria
21021@section Have you found a bug?
21022@cindex bug criteria
c4555f82 21023
8e04817f 21024If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
21025
21026@itemize @bullet
8e04817f
AC
21027@cindex fatal signal
21028@cindex debugger crash
21029@cindex crash of debugger
c4555f82 21030@item
8e04817f
AC
21031If the debugger gets a fatal signal, for any input whatever, that is a
21032@value{GDBN} bug. Reliable debuggers never crash.
21033
21034@cindex error on valid input
21035@item
21036If @value{GDBN} produces an error message for valid input, that is a
21037bug. (Note that if you're cross debugging, the problem may also be
21038somewhere in the connection to the target.)
c4555f82 21039
8e04817f 21040@cindex invalid input
c4555f82 21041@item
8e04817f
AC
21042If @value{GDBN} does not produce an error message for invalid input,
21043that is a bug. However, you should note that your idea of
21044``invalid input'' might be our idea of ``an extension'' or ``support
21045for traditional practice''.
21046
21047@item
21048If you are an experienced user of debugging tools, your suggestions
21049for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21050@end itemize
21051
8e04817f
AC
21052@node Bug Reporting
21053@section How to report bugs
21054@cindex bug reports
21055@cindex @value{GDBN} bugs, reporting
21056
21057A number of companies and individuals offer support for @sc{gnu} products.
21058If you obtained @value{GDBN} from a support organization, we recommend you
21059contact that organization first.
21060
21061You can find contact information for many support companies and
21062individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21063distribution.
21064@c should add a web page ref...
21065
129188f6
AC
21066In any event, we also recommend that you submit bug reports for
21067@value{GDBN}. The prefered method is to submit them directly using
21068@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21069page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21070be used.
8e04817f
AC
21071
21072@strong{Do not send bug reports to @samp{info-gdb}, or to
21073@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21074not want to receive bug reports. Those that do have arranged to receive
21075@samp{bug-gdb}.
21076
21077The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21078serves as a repeater. The mailing list and the newsgroup carry exactly
21079the same messages. Often people think of posting bug reports to the
21080newsgroup instead of mailing them. This appears to work, but it has one
21081problem which can be crucial: a newsgroup posting often lacks a mail
21082path back to the sender. Thus, if we need to ask for more information,
21083we may be unable to reach you. For this reason, it is better to send
21084bug reports to the mailing list.
c4555f82 21085
8e04817f
AC
21086The fundamental principle of reporting bugs usefully is this:
21087@strong{report all the facts}. If you are not sure whether to state a
21088fact or leave it out, state it!
c4555f82 21089
8e04817f
AC
21090Often people omit facts because they think they know what causes the
21091problem and assume that some details do not matter. Thus, you might
21092assume that the name of the variable you use in an example does not matter.
21093Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21094stray memory reference which happens to fetch from the location where that
21095name is stored in memory; perhaps, if the name were different, the contents
21096of that location would fool the debugger into doing the right thing despite
21097the bug. Play it safe and give a specific, complete example. That is the
21098easiest thing for you to do, and the most helpful.
c4555f82 21099
8e04817f
AC
21100Keep in mind that the purpose of a bug report is to enable us to fix the
21101bug. It may be that the bug has been reported previously, but neither
21102you nor we can know that unless your bug report is complete and
21103self-contained.
c4555f82 21104
8e04817f
AC
21105Sometimes people give a few sketchy facts and ask, ``Does this ring a
21106bell?'' Those bug reports are useless, and we urge everyone to
21107@emph{refuse to respond to them} except to chide the sender to report
21108bugs properly.
21109
21110To enable us to fix the bug, you should include all these things:
c4555f82
SC
21111
21112@itemize @bullet
21113@item
8e04817f
AC
21114The version of @value{GDBN}. @value{GDBN} announces it if you start
21115with no arguments; you can also print it at any time using @code{show
21116version}.
c4555f82 21117
8e04817f
AC
21118Without this, we will not know whether there is any point in looking for
21119the bug in the current version of @value{GDBN}.
c4555f82
SC
21120
21121@item
8e04817f
AC
21122The type of machine you are using, and the operating system name and
21123version number.
c4555f82
SC
21124
21125@item
8e04817f
AC
21126What compiler (and its version) was used to compile @value{GDBN}---e.g.
21127``@value{GCC}--2.8.1''.
c4555f82
SC
21128
21129@item
8e04817f
AC
21130What compiler (and its version) was used to compile the program you are
21131debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21132C Compiler''. For GCC, you can say @code{gcc --version} to get this
21133information; for other compilers, see the documentation for those
21134compilers.
c4555f82 21135
8e04817f
AC
21136@item
21137The command arguments you gave the compiler to compile your example and
21138observe the bug. For example, did you use @samp{-O}? To guarantee
21139you will not omit something important, list them all. A copy of the
21140Makefile (or the output from make) is sufficient.
c4555f82 21141
8e04817f
AC
21142If we were to try to guess the arguments, we would probably guess wrong
21143and then we might not encounter the bug.
c4555f82 21144
8e04817f
AC
21145@item
21146A complete input script, and all necessary source files, that will
21147reproduce the bug.
c4555f82 21148
8e04817f
AC
21149@item
21150A description of what behavior you observe that you believe is
21151incorrect. For example, ``It gets a fatal signal.''
c4555f82 21152
8e04817f
AC
21153Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21154will certainly notice it. But if the bug is incorrect output, we might
21155not notice unless it is glaringly wrong. You might as well not give us
21156a chance to make a mistake.
c4555f82 21157
8e04817f
AC
21158Even if the problem you experience is a fatal signal, you should still
21159say so explicitly. Suppose something strange is going on, such as, your
21160copy of @value{GDBN} is out of synch, or you have encountered a bug in
21161the C library on your system. (This has happened!) Your copy might
21162crash and ours would not. If you told us to expect a crash, then when
21163ours fails to crash, we would know that the bug was not happening for
21164us. If you had not told us to expect a crash, then we would not be able
21165to draw any conclusion from our observations.
c4555f82 21166
e0c07bf0
MC
21167@pindex script
21168@cindex recording a session script
21169To collect all this information, you can use a session recording program
21170such as @command{script}, which is available on many Unix systems.
21171Just run your @value{GDBN} session inside @command{script} and then
21172include the @file{typescript} file with your bug report.
21173
21174Another way to record a @value{GDBN} session is to run @value{GDBN}
21175inside Emacs and then save the entire buffer to a file.
21176
8e04817f
AC
21177@item
21178If you wish to suggest changes to the @value{GDBN} source, send us context
21179diffs. If you even discuss something in the @value{GDBN} source, refer to
21180it by context, not by line number.
c4555f82 21181
8e04817f
AC
21182The line numbers in our development sources will not match those in your
21183sources. Your line numbers would convey no useful information to us.
c4555f82 21184
8e04817f 21185@end itemize
c4555f82 21186
8e04817f 21187Here are some things that are not necessary:
c4555f82 21188
8e04817f
AC
21189@itemize @bullet
21190@item
21191A description of the envelope of the bug.
c4555f82 21192
8e04817f
AC
21193Often people who encounter a bug spend a lot of time investigating
21194which changes to the input file will make the bug go away and which
21195changes will not affect it.
c4555f82 21196
8e04817f
AC
21197This is often time consuming and not very useful, because the way we
21198will find the bug is by running a single example under the debugger
21199with breakpoints, not by pure deduction from a series of examples.
21200We recommend that you save your time for something else.
c4555f82 21201
8e04817f
AC
21202Of course, if you can find a simpler example to report @emph{instead}
21203of the original one, that is a convenience for us. Errors in the
21204output will be easier to spot, running under the debugger will take
21205less time, and so on.
c4555f82 21206
8e04817f
AC
21207However, simplification is not vital; if you do not want to do this,
21208report the bug anyway and send us the entire test case you used.
c4555f82 21209
8e04817f
AC
21210@item
21211A patch for the bug.
c4555f82 21212
8e04817f
AC
21213A patch for the bug does help us if it is a good one. But do not omit
21214the necessary information, such as the test case, on the assumption that
21215a patch is all we need. We might see problems with your patch and decide
21216to fix the problem another way, or we might not understand it at all.
c4555f82 21217
8e04817f
AC
21218Sometimes with a program as complicated as @value{GDBN} it is very hard to
21219construct an example that will make the program follow a certain path
21220through the code. If you do not send us the example, we will not be able
21221to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21222
8e04817f
AC
21223And if we cannot understand what bug you are trying to fix, or why your
21224patch should be an improvement, we will not install it. A test case will
21225help us to understand.
c4555f82 21226
8e04817f
AC
21227@item
21228A guess about what the bug is or what it depends on.
c4555f82 21229
8e04817f
AC
21230Such guesses are usually wrong. Even we cannot guess right about such
21231things without first using the debugger to find the facts.
21232@end itemize
c4555f82 21233
8e04817f
AC
21234@c The readline documentation is distributed with the readline code
21235@c and consists of the two following files:
21236@c rluser.texinfo
21237@c inc-hist.texinfo
21238@c Use -I with makeinfo to point to the appropriate directory,
21239@c environment var TEXINPUTS with TeX.
21240@include rluser.texinfo
21241@include inc-hist.texinfo
c4555f82 21242
c4555f82 21243
8e04817f
AC
21244@node Formatting Documentation
21245@appendix Formatting Documentation
c4555f82 21246
8e04817f
AC
21247@cindex @value{GDBN} reference card
21248@cindex reference card
21249The @value{GDBN} 4 release includes an already-formatted reference card, ready
21250for printing with PostScript or Ghostscript, in the @file{gdb}
21251subdirectory of the main source directory@footnote{In
21252@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21253release.}. If you can use PostScript or Ghostscript with your printer,
21254you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21255
8e04817f
AC
21256The release also includes the source for the reference card. You
21257can format it, using @TeX{}, by typing:
c4555f82 21258
474c8240 21259@smallexample
8e04817f 21260make refcard.dvi
474c8240 21261@end smallexample
c4555f82 21262
8e04817f
AC
21263The @value{GDBN} reference card is designed to print in @dfn{landscape}
21264mode on US ``letter'' size paper;
21265that is, on a sheet 11 inches wide by 8.5 inches
21266high. You will need to specify this form of printing as an option to
21267your @sc{dvi} output program.
c4555f82 21268
8e04817f 21269@cindex documentation
c4555f82 21270
8e04817f
AC
21271All the documentation for @value{GDBN} comes as part of the machine-readable
21272distribution. The documentation is written in Texinfo format, which is
21273a documentation system that uses a single source file to produce both
21274on-line information and a printed manual. You can use one of the Info
21275formatting commands to create the on-line version of the documentation
21276and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21277
8e04817f
AC
21278@value{GDBN} includes an already formatted copy of the on-line Info
21279version of this manual in the @file{gdb} subdirectory. The main Info
21280file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21281subordinate files matching @samp{gdb.info*} in the same directory. If
21282necessary, you can print out these files, or read them with any editor;
21283but they are easier to read using the @code{info} subsystem in @sc{gnu}
21284Emacs or the standalone @code{info} program, available as part of the
21285@sc{gnu} Texinfo distribution.
c4555f82 21286
8e04817f
AC
21287If you want to format these Info files yourself, you need one of the
21288Info formatting programs, such as @code{texinfo-format-buffer} or
21289@code{makeinfo}.
c4555f82 21290
8e04817f
AC
21291If you have @code{makeinfo} installed, and are in the top level
21292@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21293version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21294
474c8240 21295@smallexample
8e04817f
AC
21296cd gdb
21297make gdb.info
474c8240 21298@end smallexample
c4555f82 21299
8e04817f
AC
21300If you want to typeset and print copies of this manual, you need @TeX{},
21301a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21302Texinfo definitions file.
c4555f82 21303
8e04817f
AC
21304@TeX{} is a typesetting program; it does not print files directly, but
21305produces output files called @sc{dvi} files. To print a typeset
21306document, you need a program to print @sc{dvi} files. If your system
21307has @TeX{} installed, chances are it has such a program. The precise
21308command to use depends on your system; @kbd{lpr -d} is common; another
21309(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21310require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21311
8e04817f
AC
21312@TeX{} also requires a macro definitions file called
21313@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21314written in Texinfo format. On its own, @TeX{} cannot either read or
21315typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21316and is located in the @file{gdb-@var{version-number}/texinfo}
21317directory.
c4555f82 21318
8e04817f
AC
21319If you have @TeX{} and a @sc{dvi} printer program installed, you can
21320typeset and print this manual. First switch to the the @file{gdb}
21321subdirectory of the main source directory (for example, to
21322@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21323
474c8240 21324@smallexample
8e04817f 21325make gdb.dvi
474c8240 21326@end smallexample
c4555f82 21327
8e04817f 21328Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21329
8e04817f
AC
21330@node Installing GDB
21331@appendix Installing @value{GDBN}
21332@cindex configuring @value{GDBN}
21333@cindex installation
94e91d6d 21334@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21335
8e04817f
AC
21336@value{GDBN} comes with a @code{configure} script that automates the process
21337of preparing @value{GDBN} for installation; you can then use @code{make} to
21338build the @code{gdb} program.
21339@iftex
21340@c irrelevant in info file; it's as current as the code it lives with.
21341@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21342look at the @file{README} file in the sources; we may have improved the
21343installation procedures since publishing this manual.}
21344@end iftex
c4555f82 21345
8e04817f
AC
21346The @value{GDBN} distribution includes all the source code you need for
21347@value{GDBN} in a single directory, whose name is usually composed by
21348appending the version number to @samp{gdb}.
c4555f82 21349
8e04817f
AC
21350For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21351@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21352
8e04817f
AC
21353@table @code
21354@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21355script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21356
8e04817f
AC
21357@item gdb-@value{GDBVN}/gdb
21358the source specific to @value{GDBN} itself
c4555f82 21359
8e04817f
AC
21360@item gdb-@value{GDBVN}/bfd
21361source for the Binary File Descriptor library
c906108c 21362
8e04817f
AC
21363@item gdb-@value{GDBVN}/include
21364@sc{gnu} include files
c906108c 21365
8e04817f
AC
21366@item gdb-@value{GDBVN}/libiberty
21367source for the @samp{-liberty} free software library
c906108c 21368
8e04817f
AC
21369@item gdb-@value{GDBVN}/opcodes
21370source for the library of opcode tables and disassemblers
c906108c 21371
8e04817f
AC
21372@item gdb-@value{GDBVN}/readline
21373source for the @sc{gnu} command-line interface
c906108c 21374
8e04817f
AC
21375@item gdb-@value{GDBVN}/glob
21376source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21377
8e04817f
AC
21378@item gdb-@value{GDBVN}/mmalloc
21379source for the @sc{gnu} memory-mapped malloc package
21380@end table
c906108c 21381
8e04817f
AC
21382The simplest way to configure and build @value{GDBN} is to run @code{configure}
21383from the @file{gdb-@var{version-number}} source directory, which in
21384this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21385
8e04817f
AC
21386First switch to the @file{gdb-@var{version-number}} source directory
21387if you are not already in it; then run @code{configure}. Pass the
21388identifier for the platform on which @value{GDBN} will run as an
21389argument.
c906108c 21390
8e04817f 21391For example:
c906108c 21392
474c8240 21393@smallexample
8e04817f
AC
21394cd gdb-@value{GDBVN}
21395./configure @var{host}
21396make
474c8240 21397@end smallexample
c906108c 21398
8e04817f
AC
21399@noindent
21400where @var{host} is an identifier such as @samp{sun4} or
21401@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21402(You can often leave off @var{host}; @code{configure} tries to guess the
21403correct value by examining your system.)
c906108c 21404
8e04817f
AC
21405Running @samp{configure @var{host}} and then running @code{make} builds the
21406@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21407libraries, then @code{gdb} itself. The configured source files, and the
21408binaries, are left in the corresponding source directories.
c906108c 21409
8e04817f
AC
21410@need 750
21411@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21412system does not recognize this automatically when you run a different
21413shell, you may need to run @code{sh} on it explicitly:
c906108c 21414
474c8240 21415@smallexample
8e04817f 21416sh configure @var{host}
474c8240 21417@end smallexample
c906108c 21418
8e04817f
AC
21419If you run @code{configure} from a directory that contains source
21420directories for multiple libraries or programs, such as the
21421@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21422creates configuration files for every directory level underneath (unless
21423you tell it not to, with the @samp{--norecursion} option).
21424
94e91d6d
MC
21425You should run the @code{configure} script from the top directory in the
21426source tree, the @file{gdb-@var{version-number}} directory. If you run
21427@code{configure} from one of the subdirectories, you will configure only
21428that subdirectory. That is usually not what you want. In particular,
21429if you run the first @code{configure} from the @file{gdb} subdirectory
21430of the @file{gdb-@var{version-number}} directory, you will omit the
21431configuration of @file{bfd}, @file{readline}, and other sibling
21432directories of the @file{gdb} subdirectory. This leads to build errors
21433about missing include files such as @file{bfd/bfd.h}.
c906108c 21434
8e04817f
AC
21435You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21436However, you should make sure that the shell on your path (named by
21437the @samp{SHELL} environment variable) is publicly readable. Remember
21438that @value{GDBN} uses the shell to start your program---some systems refuse to
21439let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21440
8e04817f
AC
21441@menu
21442* Separate Objdir:: Compiling @value{GDBN} in another directory
21443* Config Names:: Specifying names for hosts and targets
21444* Configure Options:: Summary of options for configure
21445@end menu
c906108c 21446
8e04817f
AC
21447@node Separate Objdir
21448@section Compiling @value{GDBN} in another directory
c906108c 21449
8e04817f
AC
21450If you want to run @value{GDBN} versions for several host or target machines,
21451you need a different @code{gdb} compiled for each combination of
21452host and target. @code{configure} is designed to make this easy by
21453allowing you to generate each configuration in a separate subdirectory,
21454rather than in the source directory. If your @code{make} program
21455handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21456@code{make} in each of these directories builds the @code{gdb}
21457program specified there.
c906108c 21458
8e04817f
AC
21459To build @code{gdb} in a separate directory, run @code{configure}
21460with the @samp{--srcdir} option to specify where to find the source.
21461(You also need to specify a path to find @code{configure}
21462itself from your working directory. If the path to @code{configure}
21463would be the same as the argument to @samp{--srcdir}, you can leave out
21464the @samp{--srcdir} option; it is assumed.)
c906108c 21465
8e04817f
AC
21466For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21467separate directory for a Sun 4 like this:
c906108c 21468
474c8240 21469@smallexample
8e04817f
AC
21470@group
21471cd gdb-@value{GDBVN}
21472mkdir ../gdb-sun4
21473cd ../gdb-sun4
21474../gdb-@value{GDBVN}/configure sun4
21475make
21476@end group
474c8240 21477@end smallexample
c906108c 21478
8e04817f
AC
21479When @code{configure} builds a configuration using a remote source
21480directory, it creates a tree for the binaries with the same structure
21481(and using the same names) as the tree under the source directory. In
21482the example, you'd find the Sun 4 library @file{libiberty.a} in the
21483directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21484@file{gdb-sun4/gdb}.
c906108c 21485
94e91d6d
MC
21486Make sure that your path to the @file{configure} script has just one
21487instance of @file{gdb} in it. If your path to @file{configure} looks
21488like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21489one subdirectory of @value{GDBN}, not the whole package. This leads to
21490build errors about missing include files such as @file{bfd/bfd.h}.
21491
8e04817f
AC
21492One popular reason to build several @value{GDBN} configurations in separate
21493directories is to configure @value{GDBN} for cross-compiling (where
21494@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21495programs that run on another machine---the @dfn{target}).
21496You specify a cross-debugging target by
21497giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21498
8e04817f
AC
21499When you run @code{make} to build a program or library, you must run
21500it in a configured directory---whatever directory you were in when you
21501called @code{configure} (or one of its subdirectories).
c906108c 21502
8e04817f
AC
21503The @code{Makefile} that @code{configure} generates in each source
21504directory also runs recursively. If you type @code{make} in a source
21505directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21506directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21507will build all the required libraries, and then build GDB.
c906108c 21508
8e04817f
AC
21509When you have multiple hosts or targets configured in separate
21510directories, you can run @code{make} on them in parallel (for example,
21511if they are NFS-mounted on each of the hosts); they will not interfere
21512with each other.
c906108c 21513
8e04817f
AC
21514@node Config Names
21515@section Specifying names for hosts and targets
c906108c 21516
8e04817f
AC
21517The specifications used for hosts and targets in the @code{configure}
21518script are based on a three-part naming scheme, but some short predefined
21519aliases are also supported. The full naming scheme encodes three pieces
21520of information in the following pattern:
c906108c 21521
474c8240 21522@smallexample
8e04817f 21523@var{architecture}-@var{vendor}-@var{os}
474c8240 21524@end smallexample
c906108c 21525
8e04817f
AC
21526For example, you can use the alias @code{sun4} as a @var{host} argument,
21527or as the value for @var{target} in a @code{--target=@var{target}}
21528option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21529
8e04817f
AC
21530The @code{configure} script accompanying @value{GDBN} does not provide
21531any query facility to list all supported host and target names or
21532aliases. @code{configure} calls the Bourne shell script
21533@code{config.sub} to map abbreviations to full names; you can read the
21534script, if you wish, or you can use it to test your guesses on
21535abbreviations---for example:
c906108c 21536
8e04817f
AC
21537@smallexample
21538% sh config.sub i386-linux
21539i386-pc-linux-gnu
21540% sh config.sub alpha-linux
21541alpha-unknown-linux-gnu
21542% sh config.sub hp9k700
21543hppa1.1-hp-hpux
21544% sh config.sub sun4
21545sparc-sun-sunos4.1.1
21546% sh config.sub sun3
21547m68k-sun-sunos4.1.1
21548% sh config.sub i986v
21549Invalid configuration `i986v': machine `i986v' not recognized
21550@end smallexample
c906108c 21551
8e04817f
AC
21552@noindent
21553@code{config.sub} is also distributed in the @value{GDBN} source
21554directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21555
8e04817f
AC
21556@node Configure Options
21557@section @code{configure} options
c906108c 21558
8e04817f
AC
21559Here is a summary of the @code{configure} options and arguments that
21560are most often useful for building @value{GDBN}. @code{configure} also has
21561several other options not listed here. @inforef{What Configure
21562Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21563
474c8240 21564@smallexample
8e04817f
AC
21565configure @r{[}--help@r{]}
21566 @r{[}--prefix=@var{dir}@r{]}
21567 @r{[}--exec-prefix=@var{dir}@r{]}
21568 @r{[}--srcdir=@var{dirname}@r{]}
21569 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21570 @r{[}--target=@var{target}@r{]}
21571 @var{host}
474c8240 21572@end smallexample
c906108c 21573
8e04817f
AC
21574@noindent
21575You may introduce options with a single @samp{-} rather than
21576@samp{--} if you prefer; but you may abbreviate option names if you use
21577@samp{--}.
c906108c 21578
8e04817f
AC
21579@table @code
21580@item --help
21581Display a quick summary of how to invoke @code{configure}.
c906108c 21582
8e04817f
AC
21583@item --prefix=@var{dir}
21584Configure the source to install programs and files under directory
21585@file{@var{dir}}.
c906108c 21586
8e04817f
AC
21587@item --exec-prefix=@var{dir}
21588Configure the source to install programs under directory
21589@file{@var{dir}}.
c906108c 21590
8e04817f
AC
21591@c avoid splitting the warning from the explanation:
21592@need 2000
21593@item --srcdir=@var{dirname}
21594@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21595@code{make} that implements the @code{VPATH} feature.}@*
21596Use this option to make configurations in directories separate from the
21597@value{GDBN} source directories. Among other things, you can use this to
21598build (or maintain) several configurations simultaneously, in separate
21599directories. @code{configure} writes configuration specific files in
21600the current directory, but arranges for them to use the source in the
21601directory @var{dirname}. @code{configure} creates directories under
21602the working directory in parallel to the source directories below
21603@var{dirname}.
c906108c 21604
8e04817f
AC
21605@item --norecursion
21606Configure only the directory level where @code{configure} is executed; do not
21607propagate configuration to subdirectories.
c906108c 21608
8e04817f
AC
21609@item --target=@var{target}
21610Configure @value{GDBN} for cross-debugging programs running on the specified
21611@var{target}. Without this option, @value{GDBN} is configured to debug
21612programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21613
8e04817f 21614There is no convenient way to generate a list of all available targets.
c906108c 21615
8e04817f
AC
21616@item @var{host} @dots{}
21617Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21618
8e04817f
AC
21619There is no convenient way to generate a list of all available hosts.
21620@end table
c906108c 21621
8e04817f
AC
21622There are many other options available as well, but they are generally
21623needed for special purposes only.
c906108c 21624
8e04817f
AC
21625@node Maintenance Commands
21626@appendix Maintenance Commands
21627@cindex maintenance commands
21628@cindex internal commands
c906108c 21629
8e04817f 21630In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21631includes a number of commands intended for @value{GDBN} developers,
21632that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21633provided here for reference. (For commands that turn on debugging
21634messages, see @ref{Debugging Output}.)
c906108c 21635
8e04817f 21636@table @code
09d4efe1
EZ
21637@kindex maint agent
21638@item maint agent @var{expression}
21639Translate the given @var{expression} into remote agent bytecodes.
21640This command is useful for debugging the Agent Expression mechanism
21641(@pxref{Agent Expressions}).
21642
8e04817f
AC
21643@kindex maint info breakpoints
21644@item @anchor{maint info breakpoints}maint info breakpoints
21645Using the same format as @samp{info breakpoints}, display both the
21646breakpoints you've set explicitly, and those @value{GDBN} is using for
21647internal purposes. Internal breakpoints are shown with negative
21648breakpoint numbers. The type column identifies what kind of breakpoint
21649is shown:
c906108c 21650
8e04817f
AC
21651@table @code
21652@item breakpoint
21653Normal, explicitly set breakpoint.
c906108c 21654
8e04817f
AC
21655@item watchpoint
21656Normal, explicitly set watchpoint.
c906108c 21657
8e04817f
AC
21658@item longjmp
21659Internal breakpoint, used to handle correctly stepping through
21660@code{longjmp} calls.
c906108c 21661
8e04817f
AC
21662@item longjmp resume
21663Internal breakpoint at the target of a @code{longjmp}.
c906108c 21664
8e04817f
AC
21665@item until
21666Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21667
8e04817f
AC
21668@item finish
21669Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21670
8e04817f
AC
21671@item shlib events
21672Shared library events.
c906108c 21673
8e04817f 21674@end table
c906108c 21675
09d4efe1
EZ
21676@kindex maint check-symtabs
21677@item maint check-symtabs
21678Check the consistency of psymtabs and symtabs.
21679
21680@kindex maint cplus first_component
21681@item maint cplus first_component @var{name}
21682Print the first C@t{++} class/namespace component of @var{name}.
21683
21684@kindex maint cplus namespace
21685@item maint cplus namespace
21686Print the list of possible C@t{++} namespaces.
21687
21688@kindex maint demangle
21689@item maint demangle @var{name}
21690Demangle a C@t{++} or Objective-C manled @var{name}.
21691
21692@kindex maint deprecate
21693@kindex maint undeprecate
21694@cindex deprecated commands
21695@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21696@itemx maint undeprecate @var{command}
21697Deprecate or undeprecate the named @var{command}. Deprecated commands
21698cause @value{GDBN} to issue a warning when you use them. The optional
21699argument @var{replacement} says which newer command should be used in
21700favor of the deprecated one; if it is given, @value{GDBN} will mention
21701the replacement as part of the warning.
21702
21703@kindex maint dump-me
21704@item maint dump-me
721c2651 21705@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21706Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21707This is supported only on systems which support aborting a program
21708with the @code{SIGQUIT} signal.
09d4efe1 21709
8d30a00d
AC
21710@kindex maint internal-error
21711@kindex maint internal-warning
09d4efe1
EZ
21712@item maint internal-error @r{[}@var{message-text}@r{]}
21713@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21714Cause @value{GDBN} to call the internal function @code{internal_error}
21715or @code{internal_warning} and hence behave as though an internal error
21716or internal warning has been detected. In addition to reporting the
21717internal problem, these functions give the user the opportunity to
21718either quit @value{GDBN} or create a core file of the current
21719@value{GDBN} session.
21720
09d4efe1
EZ
21721These commands take an optional parameter @var{message-text} that is
21722used as the text of the error or warning message.
21723
21724Here's an example of using @code{indernal-error}:
21725
8d30a00d 21726@smallexample
f7dc1244 21727(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21728@dots{}/maint.c:121: internal-error: testing, 1, 2
21729A problem internal to GDB has been detected. Further
21730debugging may prove unreliable.
21731Quit this debugging session? (y or n) @kbd{n}
21732Create a core file? (y or n) @kbd{n}
f7dc1244 21733(@value{GDBP})
8d30a00d
AC
21734@end smallexample
21735
09d4efe1
EZ
21736@kindex maint packet
21737@item maint packet @var{text}
21738If @value{GDBN} is talking to an inferior via the serial protocol,
21739then this command sends the string @var{text} to the inferior, and
21740displays the response packet. @value{GDBN} supplies the initial
21741@samp{$} character, the terminating @samp{#} character, and the
21742checksum.
21743
21744@kindex maint print architecture
21745@item maint print architecture @r{[}@var{file}@r{]}
21746Print the entire architecture configuration. The optional argument
21747@var{file} names the file where the output goes.
8d30a00d 21748
00905d52
AC
21749@kindex maint print dummy-frames
21750@item maint print dummy-frames
00905d52
AC
21751Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21752
21753@smallexample
f7dc1244 21754(@value{GDBP}) @kbd{b add}
00905d52 21755@dots{}
f7dc1244 21756(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21757Breakpoint 2, add (a=2, b=3) at @dots{}
2175858 return (a + b);
21759The program being debugged stopped while in a function called from GDB.
21760@dots{}
f7dc1244 21761(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
217620x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21763 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21764 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21765(@value{GDBP})
00905d52
AC
21766@end smallexample
21767
21768Takes an optional file parameter.
21769
0680b120
AC
21770@kindex maint print registers
21771@kindex maint print raw-registers
21772@kindex maint print cooked-registers
617073a9 21773@kindex maint print register-groups
09d4efe1
EZ
21774@item maint print registers @r{[}@var{file}@r{]}
21775@itemx maint print raw-registers @r{[}@var{file}@r{]}
21776@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21777@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21778Print @value{GDBN}'s internal register data structures.
21779
617073a9
AC
21780The command @code{maint print raw-registers} includes the contents of
21781the raw register cache; the command @code{maint print cooked-registers}
21782includes the (cooked) value of all registers; and the command
21783@code{maint print register-groups} includes the groups that each
21784register is a member of. @xref{Registers,, Registers, gdbint,
21785@value{GDBN} Internals}.
0680b120 21786
09d4efe1
EZ
21787These commands take an optional parameter, a file name to which to
21788write the information.
0680b120 21789
617073a9 21790@kindex maint print reggroups
09d4efe1
EZ
21791@item maint print reggroups @r{[}@var{file}@r{]}
21792Print @value{GDBN}'s internal register group data structures. The
21793optional argument @var{file} tells to what file to write the
21794information.
617073a9 21795
09d4efe1 21796The register groups info looks like this:
617073a9
AC
21797
21798@smallexample
f7dc1244 21799(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21800 Group Type
21801 general user
21802 float user
21803 all user
21804 vector user
21805 system user
21806 save internal
21807 restore internal
617073a9
AC
21808@end smallexample
21809
09d4efe1
EZ
21810@kindex flushregs
21811@item flushregs
21812This command forces @value{GDBN} to flush its internal register cache.
21813
21814@kindex maint print objfiles
21815@cindex info for known object files
21816@item maint print objfiles
21817Print a dump of all known object files. For each object file, this
21818command prints its name, address in memory, and all of its psymtabs
21819and symtabs.
21820
21821@kindex maint print statistics
21822@cindex bcache statistics
21823@item maint print statistics
21824This command prints, for each object file in the program, various data
21825about that object file followed by the byte cache (@dfn{bcache})
21826statistics for the object file. The objfile data includes the number
21827of minimal, partical, full, and stabs symbols, the number of types
21828defined by the objfile, the number of as yet unexpanded psym tables,
21829the number of line tables and string tables, and the amount of memory
21830used by the various tables. The bcache statistics include the counts,
21831sizes, and counts of duplicates of all and unique objects, max,
21832average, and median entry size, total memory used and its overhead and
21833savings, and various measures of the hash table size and chain
21834lengths.
21835
21836@kindex maint print type
21837@cindex type chain of a data type
21838@item maint print type @var{expr}
21839Print the type chain for a type specified by @var{expr}. The argument
21840can be either a type name or a symbol. If it is a symbol, the type of
21841that symbol is described. The type chain produced by this command is
21842a recursive definition of the data type as stored in @value{GDBN}'s
21843data structures, including its flags and contained types.
21844
21845@kindex maint set dwarf2 max-cache-age
21846@kindex maint show dwarf2 max-cache-age
21847@item maint set dwarf2 max-cache-age
21848@itemx maint show dwarf2 max-cache-age
21849Control the DWARF 2 compilation unit cache.
21850
21851@cindex DWARF 2 compilation units cache
21852In object files with inter-compilation-unit references, such as those
21853produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21854reader needs to frequently refer to previously read compilation units.
21855This setting controls how long a compilation unit will remain in the
21856cache if it is not referenced. A higher limit means that cached
21857compilation units will be stored in memory longer, and more total
21858memory will be used. Setting it to zero disables caching, which will
21859slow down @value{GDBN} startup, but reduce memory consumption.
21860
e7ba9c65
DJ
21861@kindex maint set profile
21862@kindex maint show profile
21863@cindex profiling GDB
21864@item maint set profile
21865@itemx maint show profile
21866Control profiling of @value{GDBN}.
21867
21868Profiling will be disabled until you use the @samp{maint set profile}
21869command to enable it. When you enable profiling, the system will begin
21870collecting timing and execution count data; when you disable profiling or
21871exit @value{GDBN}, the results will be written to a log file. Remember that
21872if you use profiling, @value{GDBN} will overwrite the profiling log file
21873(often called @file{gmon.out}). If you have a record of important profiling
21874data in a @file{gmon.out} file, be sure to move it to a safe location.
21875
21876Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21877compiled with the @samp{-pg} compiler option.
e7ba9c65 21878
09d4efe1
EZ
21879@kindex maint show-debug-regs
21880@cindex x86 hardware debug registers
21881@item maint show-debug-regs
21882Control whether to show variables that mirror the x86 hardware debug
21883registers. Use @code{ON} to enable, @code{OFF} to disable. If
21884enabled, the debug registers values are shown when GDB inserts or
21885removes a hardware breakpoint or watchpoint, and when the inferior
21886triggers a hardware-assisted breakpoint or watchpoint.
21887
21888@kindex maint space
21889@cindex memory used by commands
21890@item maint space
21891Control whether to display memory usage for each command. If set to a
21892nonzero value, @value{GDBN} will display how much memory each command
21893took, following the command's own output. This can also be requested
21894by invoking @value{GDBN} with the @option{--statistics} command-line
21895switch (@pxref{Mode Options}).
21896
21897@kindex maint time
21898@cindex time of command execution
21899@item maint time
21900Control whether to display the execution time for each command. If
21901set to a nonzero value, @value{GDBN} will display how much time it
21902took to execute each command, following the command's own output.
21903This can also be requested by invoking @value{GDBN} with the
21904@option{--statistics} command-line switch (@pxref{Mode Options}).
21905
21906@kindex maint translate-address
21907@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21908Find the symbol stored at the location specified by the address
21909@var{addr} and an optional section name @var{section}. If found,
21910@value{GDBN} prints the name of the closest symbol and an offset from
21911the symbol's location to the specified address. This is similar to
21912the @code{info address} command (@pxref{Symbols}), except that this
21913command also allows to find symbols in other sections.
ae038cb0 21914
8e04817f 21915@end table
c906108c 21916
9c16f35a
EZ
21917The following command is useful for non-interactive invocations of
21918@value{GDBN}, such as in the test suite.
21919
21920@table @code
21921@item set watchdog @var{nsec}
21922@kindex set watchdog
21923@cindex watchdog timer
21924@cindex timeout for commands
21925Set the maximum number of seconds @value{GDBN} will wait for the
21926target operation to finish. If this time expires, @value{GDBN}
21927reports and error and the command is aborted.
21928
21929@item show watchdog
21930Show the current setting of the target wait timeout.
21931@end table
c906108c 21932
e0ce93ac 21933@node Remote Protocol
8e04817f 21934@appendix @value{GDBN} Remote Serial Protocol
c906108c 21935
ee2d5c50
AC
21936@menu
21937* Overview::
21938* Packets::
21939* Stop Reply Packets::
21940* General Query Packets::
21941* Register Packet Format::
21942* Examples::
0ce1b118 21943* File-I/O remote protocol extension::
ee2d5c50
AC
21944@end menu
21945
21946@node Overview
21947@section Overview
21948
8e04817f
AC
21949There may be occasions when you need to know something about the
21950protocol---for example, if there is only one serial port to your target
21951machine, you might want your program to do something special if it
21952recognizes a packet meant for @value{GDBN}.
c906108c 21953
d2c6833e 21954In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21955transmitted and received data respectfully.
c906108c 21956
8e04817f
AC
21957@cindex protocol, @value{GDBN} remote serial
21958@cindex serial protocol, @value{GDBN} remote
21959@cindex remote serial protocol
21960All @value{GDBN} commands and responses (other than acknowledgments) are
21961sent as a @var{packet}. A @var{packet} is introduced with the character
21962@samp{$}, the actual @var{packet-data}, and the terminating character
21963@samp{#} followed by a two-digit @var{checksum}:
c906108c 21964
474c8240 21965@smallexample
8e04817f 21966@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21967@end smallexample
8e04817f 21968@noindent
c906108c 21969
8e04817f
AC
21970@cindex checksum, for @value{GDBN} remote
21971@noindent
21972The two-digit @var{checksum} is computed as the modulo 256 sum of all
21973characters between the leading @samp{$} and the trailing @samp{#} (an
21974eight bit unsigned checksum).
c906108c 21975
8e04817f
AC
21976Implementors should note that prior to @value{GDBN} 5.0 the protocol
21977specification also included an optional two-digit @var{sequence-id}:
c906108c 21978
474c8240 21979@smallexample
8e04817f 21980@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21981@end smallexample
c906108c 21982
8e04817f
AC
21983@cindex sequence-id, for @value{GDBN} remote
21984@noindent
21985That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21986has never output @var{sequence-id}s. Stubs that handle packets added
21987since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21988
8e04817f
AC
21989@cindex acknowledgment, for @value{GDBN} remote
21990When either the host or the target machine receives a packet, the first
21991response expected is an acknowledgment: either @samp{+} (to indicate
21992the package was received correctly) or @samp{-} (to request
21993retransmission):
c906108c 21994
474c8240 21995@smallexample
d2c6833e
AC
21996-> @code{$}@var{packet-data}@code{#}@var{checksum}
21997<- @code{+}
474c8240 21998@end smallexample
8e04817f 21999@noindent
53a5351d 22000
8e04817f
AC
22001The host (@value{GDBN}) sends @var{command}s, and the target (the
22002debugging stub incorporated in your program) sends a @var{response}. In
22003the case of step and continue @var{command}s, the response is only sent
22004when the operation has completed (the target has again stopped).
c906108c 22005
8e04817f
AC
22006@var{packet-data} consists of a sequence of characters with the
22007exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
22008exceptions).
c906108c 22009
8e04817f 22010Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 22011@cindex remote protocol, field separator
8e04817f 22012@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 22013@sc{hex} with leading zeros suppressed.
c906108c 22014
8e04817f
AC
22015Implementors should note that prior to @value{GDBN} 5.0, the character
22016@samp{:} could not appear as the third character in a packet (as it
22017would potentially conflict with the @var{sequence-id}).
c906108c 22018
8e04817f
AC
22019Response @var{data} can be run-length encoded to save space. A @samp{*}
22020means that the next character is an @sc{ascii} encoding giving a repeat count
22021which stands for that many repetitions of the character preceding the
22022@samp{*}. The encoding is @code{n+29}, yielding a printable character
22023where @code{n >=3} (which is where rle starts to win). The printable
22024characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
22025value greater than 126 should not be used.
c906108c 22026
8e04817f 22027So:
474c8240 22028@smallexample
8e04817f 22029"@code{0* }"
474c8240 22030@end smallexample
8e04817f
AC
22031@noindent
22032means the same as "0000".
c906108c 22033
8e04817f
AC
22034The error response returned for some packets includes a two character
22035error number. That number is not well defined.
c906108c 22036
8e04817f
AC
22037For any @var{command} not supported by the stub, an empty response
22038(@samp{$#00}) should be returned. That way it is possible to extend the
22039protocol. A newer @value{GDBN} can tell if a packet is supported based
22040on that response.
c906108c 22041
b383017d
RM
22042A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22043@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22044optional.
c906108c 22045
ee2d5c50
AC
22046@node Packets
22047@section Packets
22048
22049The following table provides a complete list of all currently defined
22050@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22051@xref{File-I/O remote protocol extension}, for details about the File
22052I/O extension of the remote protocol.
ee2d5c50
AC
22053
22054@table @r
22055
22056@item @code{!} --- extended mode
22057@cindex @code{!} packet
22058
8e04817f
AC
22059Enable extended mode. In extended mode, the remote server is made
22060persistent. The @samp{R} packet is used to restart the program being
22061debugged.
ee2d5c50
AC
22062
22063Reply:
22064@table @samp
22065@item OK
8e04817f 22066The remote target both supports and has enabled extended mode.
ee2d5c50 22067@end table
c906108c 22068
ee2d5c50
AC
22069@item @code{?} --- last signal
22070@cindex @code{?} packet
c906108c 22071
ee2d5c50
AC
22072Indicate the reason the target halted. The reply is the same as for
22073step and continue.
c906108c 22074
ee2d5c50
AC
22075Reply:
22076@xref{Stop Reply Packets}, for the reply specifications.
22077
22078@item @code{a} --- reserved
22079
22080Reserved for future use.
22081
22082@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
22083@cindex @code{A} packet
c906108c 22084
8e04817f
AC
22085Initialized @samp{argv[]} array passed into program. @var{arglen}
22086specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
22087See @code{gdbserver} for more details.
22088
22089Reply:
22090@table @samp
22091@item OK
22092@item E@var{NN}
22093@end table
22094
22095@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22096@cindex @code{b} packet
22097
22098Change the serial line speed to @var{baud}.
22099
22100JTC: @emph{When does the transport layer state change? When it's
22101received, or after the ACK is transmitted. In either case, there are
22102problems if the command or the acknowledgment packet is dropped.}
22103
22104Stan: @emph{If people really wanted to add something like this, and get
22105it working for the first time, they ought to modify ser-unix.c to send
22106some kind of out-of-band message to a specially-setup stub and have the
22107switch happen "in between" packets, so that from remote protocol's point
22108of view, nothing actually happened.}
22109
22110@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22111@cindex @code{B} packet
22112
8e04817f 22113Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22114breakpoint at @var{addr}.
22115
22116This packet has been replaced by the @samp{Z} and @samp{z} packets
22117(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22118
ee2d5c50
AC
22119@item @code{c}@var{addr} --- continue
22120@cindex @code{c} packet
22121
22122@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22123current address.
c906108c 22124
ee2d5c50
AC
22125Reply:
22126@xref{Stop Reply Packets}, for the reply specifications.
22127
22128@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22129@cindex @code{C} packet
22130
8e04817f
AC
22131Continue with signal @var{sig} (hex signal number). If
22132@code{;}@var{addr} is omitted, resume at same address.
c906108c 22133
ee2d5c50
AC
22134Reply:
22135@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22136
ee2d5c50
AC
22137@item @code{d} --- toggle debug @strong{(deprecated)}
22138@cindex @code{d} packet
22139
22140Toggle debug flag.
22141
22142@item @code{D} --- detach
22143@cindex @code{D} packet
22144
22145Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22146before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22147
22148Reply:
22149@table @samp
10fac096
NW
22150@item OK
22151for success
22152@item E@var{NN}
22153for an error
ee2d5c50 22154@end table
c906108c 22155
ee2d5c50 22156@item @code{e} --- reserved
c906108c 22157
ee2d5c50 22158Reserved for future use.
c906108c 22159
ee2d5c50 22160@item @code{E} --- reserved
c906108c 22161
ee2d5c50 22162Reserved for future use.
c906108c 22163
ee2d5c50
AC
22164@item @code{f} --- reserved
22165
22166Reserved for future use.
22167
0ce1b118
CV
22168@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22169@cindex @code{F} packet
ee2d5c50 22170
0ce1b118
CV
22171This packet is send by @value{GDBN} as reply to a @code{F} request packet
22172sent by the target. This is part of the File-I/O protocol extension.
22173@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22174
22175@item @code{g} --- read registers
22176@anchor{read registers packet}
22177@cindex @code{g} packet
22178
22179Read general registers.
22180
22181Reply:
22182@table @samp
22183@item @var{XX@dots{}}
8e04817f
AC
22184Each byte of register data is described by two hex digits. The bytes
22185with the register are transmitted in target byte order. The size of
22186each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22187determined by the @value{GDBN} internal macros
22188@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22189specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22190@item E@var{NN}
22191for an error.
22192@end table
c906108c 22193
ee2d5c50
AC
22194@item @code{G}@var{XX@dots{}} --- write regs
22195@cindex @code{G} packet
c906108c 22196
ee2d5c50
AC
22197@xref{read registers packet}, for a description of the @var{XX@dots{}}
22198data.
22199
22200Reply:
22201@table @samp
22202@item OK
22203for success
22204@item E@var{NN}
22205for an error
22206@end table
22207
22208@item @code{h} --- reserved
22209
22210Reserved for future use.
22211
b383017d 22212@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22213@cindex @code{H} packet
c906108c 22214
8e04817f 22215Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22216@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22217should be @samp{c} for step and continue operations, @samp{g} for other
22218operations. The thread designator @var{t@dots{}} may be -1, meaning all
22219the threads, a thread number, or zero which means pick any thread.
22220
22221Reply:
22222@table @samp
22223@item OK
22224for success
22225@item E@var{NN}
22226for an error
22227@end table
c906108c 22228
8e04817f
AC
22229@c FIXME: JTC:
22230@c 'H': How restrictive (or permissive) is the thread model. If a
22231@c thread is selected and stopped, are other threads allowed
22232@c to continue to execute? As I mentioned above, I think the
22233@c semantics of each command when a thread is selected must be
22234@c described. For example:
22235@c
22236@c 'g': If the stub supports threads and a specific thread is
22237@c selected, returns the register block from that thread;
22238@c otherwise returns current registers.
22239@c
22240@c 'G' If the stub supports threads and a specific thread is
22241@c selected, sets the registers of the register block of
22242@c that thread; otherwise sets current registers.
c906108c 22243
ee2d5c50
AC
22244@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22245@anchor{cycle step packet}
22246@cindex @code{i} packet
22247
8e04817f
AC
22248Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22249present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22250step starting at that address.
c906108c 22251
ee2d5c50
AC
22252@item @code{I} --- signal then cycle step @strong{(reserved)}
22253@cindex @code{I} packet
22254
22255@xref{step with signal packet}. @xref{cycle step packet}.
22256
22257@item @code{j} --- reserved
22258
22259Reserved for future use.
22260
22261@item @code{J} --- reserved
c906108c 22262
ee2d5c50 22263Reserved for future use.
c906108c 22264
ee2d5c50
AC
22265@item @code{k} --- kill request
22266@cindex @code{k} packet
c906108c 22267
ac282366 22268FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22269thread context has been selected (i.e.@: does 'k' kill only that
22270thread?)}.
c906108c 22271
ee2d5c50 22272@item @code{K} --- reserved
c906108c 22273
ee2d5c50
AC
22274Reserved for future use.
22275
22276@item @code{l} --- reserved
22277
22278Reserved for future use.
22279
22280@item @code{L} --- reserved
22281
22282Reserved for future use.
22283
22284@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22285@cindex @code{m} packet
c906108c 22286
8e04817f 22287Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22288Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22289assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22290transfer mechanism is needed.}
c906108c 22291
ee2d5c50
AC
22292Reply:
22293@table @samp
22294@item @var{XX@dots{}}
22295@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22296to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22297that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22298accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22299needed.}
22300@item E@var{NN}
22301@var{NN} is errno
22302@end table
22303
22304@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22305@cindex @code{M} packet
22306
8e04817f 22307Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22308@var{XX@dots{}} is the data.
22309
22310Reply:
22311@table @samp
22312@item OK
22313for success
22314@item E@var{NN}
8e04817f
AC
22315for an error (this includes the case where only part of the data was
22316written).
ee2d5c50 22317@end table
c906108c 22318
ee2d5c50 22319@item @code{n} --- reserved
c906108c 22320
ee2d5c50 22321Reserved for future use.
c906108c 22322
ee2d5c50 22323@item @code{N} --- reserved
c906108c 22324
ee2d5c50 22325Reserved for future use.
c906108c 22326
ee2d5c50
AC
22327@item @code{o} --- reserved
22328
22329Reserved for future use.
22330
22331@item @code{O} --- reserved
22332
2e868123 22333@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22334@cindex @code{p} packet
22335
2e868123
AC
22336@xref{read registers packet}, for a description of how the returned
22337register value is encoded.
ee2d5c50
AC
22338
22339Reply:
22340@table @samp
2e868123
AC
22341@item @var{XX@dots{}}
22342the register's value
22343@item E@var{NN}
22344for an error
22345@item
22346Indicating an unrecognized @var{query}.
ee2d5c50
AC
22347@end table
22348
22349@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22350@anchor{write register packet}
22351@cindex @code{P} packet
22352
22353Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22354digits for each byte in the register (target byte order).
c906108c 22355
ee2d5c50
AC
22356Reply:
22357@table @samp
22358@item OK
22359for success
22360@item E@var{NN}
22361for an error
22362@end table
22363
22364@item @code{q}@var{query} --- general query
22365@anchor{general query packet}
22366@cindex @code{q} packet
22367
22368Request info about @var{query}. In general @value{GDBN} queries have a
22369leading upper case letter. Custom vendor queries should use a company
22370prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22371be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22372that they match the full @var{query} name.
22373
22374Reply:
22375@table @samp
22376@item @var{XX@dots{}}
22377Hex encoded data from query. The reply can not be empty.
22378@item E@var{NN}
22379error reply
8e04817f 22380@item
ee2d5c50
AC
22381Indicating an unrecognized @var{query}.
22382@end table
22383
22384@item @code{Q}@var{var}@code{=}@var{val} --- general set
22385@cindex @code{Q} packet
22386
22387Set value of @var{var} to @var{val}.
22388
22389@xref{general query packet}, for a discussion of naming conventions.
c906108c 22390
ee2d5c50
AC
22391@item @code{r} --- reset @strong{(deprecated)}
22392@cindex @code{r} packet
c906108c 22393
8e04817f 22394Reset the entire system.
c906108c 22395
ee2d5c50
AC
22396@item @code{R}@var{XX} --- remote restart
22397@cindex @code{R} packet
22398
8e04817f
AC
22399Restart the program being debugged. @var{XX}, while needed, is ignored.
22400This packet is only available in extended mode.
ee2d5c50
AC
22401
22402Reply:
22403@table @samp
22404@item @emph{no reply}
8e04817f 22405The @samp{R} packet has no reply.
ee2d5c50
AC
22406@end table
22407
22408@item @code{s}@var{addr} --- step
22409@cindex @code{s} packet
c906108c 22410
8e04817f
AC
22411@var{addr} is address to resume. If @var{addr} is omitted, resume at
22412same address.
c906108c 22413
ee2d5c50
AC
22414Reply:
22415@xref{Stop Reply Packets}, for the reply specifications.
22416
22417@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22418@anchor{step with signal packet}
22419@cindex @code{S} packet
22420
8e04817f 22421Like @samp{C} but step not continue.
c906108c 22422
ee2d5c50
AC
22423Reply:
22424@xref{Stop Reply Packets}, for the reply specifications.
22425
b383017d 22426@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22427@cindex @code{t} packet
22428
8e04817f 22429Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22430@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22431@var{addr} must be at least 3 digits.
c906108c 22432
ee2d5c50
AC
22433@item @code{T}@var{XX} --- thread alive
22434@cindex @code{T} packet
c906108c 22435
ee2d5c50 22436Find out if the thread XX is alive.
c906108c 22437
ee2d5c50
AC
22438Reply:
22439@table @samp
22440@item OK
22441thread is still alive
22442@item E@var{NN}
22443thread is dead
22444@end table
22445
22446@item @code{u} --- reserved
22447
22448Reserved for future use.
22449
22450@item @code{U} --- reserved
22451
22452Reserved for future use.
22453
86d30acc 22454@item @code{v} --- verbose packet prefix
ee2d5c50 22455
86d30acc
DJ
22456Packets starting with @code{v} are identified by a multi-letter name,
22457up to the first @code{;} or @code{?} (or the end of the packet).
22458
22459@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22460@cindex @code{vCont} packet
22461
22462Resume the inferior. Different actions may be specified for each thread.
22463If an action is specified with no @var{tid}, then it is applied to any
22464threads that don't have a specific action specified; if no default action is
22465specified then other threads should remain stopped. Specifying multiple
22466default actions is an error; specifying no actions is also an error.
22467Thread IDs are specified in hexadecimal. Currently supported actions are:
22468
22469@table @code
22470@item c
22471Continue.
22472@item C@var{sig}
22473Continue with signal @var{sig}. @var{sig} should be two hex digits.
22474@item s
22475Step.
22476@item S@var{sig}
22477Step with signal @var{sig}. @var{sig} should be two hex digits.
22478@end table
22479
22480The optional @var{addr} argument normally associated with these packets is
22481not supported in @code{vCont}.
22482
22483Reply:
22484@xref{Stop Reply Packets}, for the reply specifications.
22485
22486@item @code{vCont?} --- extended resume query
22487@cindex @code{vCont?} packet
22488
22489Query support for the @code{vCont} packet.
22490
22491Reply:
22492@table @samp
22493@item @code{vCont}[;@var{action}]...
22494The @code{vCont} packet is supported. Each @var{action} is a supported
22495command in the @code{vCont} packet.
22496@item
22497The @code{vCont} packet is not supported.
22498@end table
ee2d5c50
AC
22499
22500@item @code{V} --- reserved
c906108c 22501
ee2d5c50 22502Reserved for future use.
c906108c 22503
ee2d5c50 22504@item @code{w} --- reserved
c906108c 22505
ee2d5c50 22506Reserved for future use.
c906108c 22507
ee2d5c50 22508@item @code{W} --- reserved
c906108c 22509
ee2d5c50 22510Reserved for future use.
c906108c 22511
ee2d5c50
AC
22512@item @code{x} --- reserved
22513
22514Reserved for future use.
22515
22516@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22517@cindex @code{X} packet
22518
22519@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22520is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22521escaped using @code{0x7d}, and then XORed with @code{0x20}.
22522For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22523
ee2d5c50
AC
22524Reply:
22525@table @samp
22526@item OK
22527for success
22528@item E@var{NN}
22529for an error
22530@end table
22531
22532@item @code{y} --- reserved
c906108c 22533
ee2d5c50 22534Reserved for future use.
c906108c 22535
ee2d5c50
AC
22536@item @code{Y} reserved
22537
22538Reserved for future use.
22539
2f870471
AC
22540@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22541@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22542@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22543@cindex @code{z} packet
2f870471 22544@cindex @code{Z} packets
ee2d5c50 22545
2f870471
AC
22546Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22547watchpoint starting at address @var{address} and covering the next
22548@var{length} bytes.
ee2d5c50 22549
2f870471
AC
22550Each breakpoint and watchpoint packet @var{type} is documented
22551separately.
22552
512217c7
AC
22553@emph{Implementation notes: A remote target shall return an empty string
22554for an unrecognized breakpoint or watchpoint packet @var{type}. A
22555remote target shall support either both or neither of a given
2f870471
AC
22556@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22557avoid potential problems with duplicate packets, the operations should
22558be implemented in an idempotent way.}
22559
22560@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22561@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22562@cindex @code{z0} packet
22563@cindex @code{Z0} packet
22564
22565Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22566@code{addr} of size @code{length}.
22567
22568A memory breakpoint is implemented by replacing the instruction at
22569@var{addr} with a software breakpoint or trap instruction. The
22570@code{length} is used by targets that indicates the size of the
22571breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22572@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22573
2f870471
AC
22574@emph{Implementation note: It is possible for a target to copy or move
22575code that contains memory breakpoints (e.g., when implementing
22576overlays). The behavior of this packet, in the presence of such a
22577target, is not defined.}
c906108c 22578
ee2d5c50
AC
22579Reply:
22580@table @samp
2f870471
AC
22581@item OK
22582success
22583@item
22584not supported
ee2d5c50
AC
22585@item E@var{NN}
22586for an error
2f870471
AC
22587@end table
22588
22589@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22590@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22591@cindex @code{z1} packet
22592@cindex @code{Z1} packet
22593
22594Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22595address @code{addr} of size @code{length}.
22596
22597A hardware breakpoint is implemented using a mechanism that is not
22598dependant on being able to modify the target's memory.
22599
22600@emph{Implementation note: A hardware breakpoint is not affected by code
22601movement.}
22602
22603Reply:
22604@table @samp
ee2d5c50 22605@item OK
2f870471
AC
22606success
22607@item
22608not supported
22609@item E@var{NN}
22610for an error
22611@end table
22612
22613@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22614@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22615@cindex @code{z2} packet
22616@cindex @code{Z2} packet
22617
22618Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22619
22620Reply:
22621@table @samp
22622@item OK
22623success
22624@item
22625not supported
22626@item E@var{NN}
22627for an error
22628@end table
22629
22630@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22631@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22632@cindex @code{z3} packet
22633@cindex @code{Z3} packet
22634
2e834e49 22635Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22636
22637Reply:
22638@table @samp
22639@item OK
22640success
22641@item
22642not supported
22643@item E@var{NN}
22644for an error
22645@end table
22646
2e834e49
HPN
22647@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22648@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22649@cindex @code{z4} packet
22650@cindex @code{Z4} packet
22651
22652Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22653
22654Reply:
22655@table @samp
22656@item OK
22657success
22658@item
22659not supported
22660@item E@var{NN}
22661for an error
ee2d5c50
AC
22662@end table
22663
22664@end table
c906108c 22665
ee2d5c50
AC
22666@node Stop Reply Packets
22667@section Stop Reply Packets
22668@cindex stop reply packets
c906108c 22669
8e04817f
AC
22670The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22671receive any of the below as a reply. In the case of the @samp{C},
22672@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22673when the target halts. In the below the exact meaning of @samp{signal
22674number} is poorly defined. In general one of the UNIX signal numbering
22675conventions is used.
c906108c 22676
ee2d5c50 22677@table @samp
c906108c 22678
ee2d5c50
AC
22679@item S@var{AA}
22680@var{AA} is the signal number
c906108c 22681
8e04817f 22682@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
22683@cindex @code{T} packet reply
22684
8e04817f
AC
22685@var{AA} = two hex digit signal number; @var{n...} = register number
22686(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22687by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22688@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22689(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22690address, this is a hex integer; @var{n...} = other string not starting
22691with valid hex digit. @value{GDBN} should ignore this @var{n...},
22692@var{r...} pair and go on to the next. This way we can extend the
22693protocol.
c906108c 22694
ee2d5c50
AC
22695@item W@var{AA}
22696
8e04817f 22697The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22698applicable to certain targets.
22699
22700@item X@var{AA}
c906108c 22701
8e04817f 22702The process terminated with signal @var{AA}.
c906108c 22703
ee2d5c50 22704@item O@var{XX@dots{}}
c906108c 22705
ee2d5c50
AC
22706@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22707any time while the program is running and the debugger should continue
22708to wait for @samp{W}, @samp{T}, etc.
22709
0ce1b118
CV
22710@item F@var{call-id}@code{,}@var{parameter@dots{}}
22711
22712@var{call-id} is the identifier which says which host system call should
22713be called. This is just the name of the function. Translation into the
22714correct system call is only applicable as it's defined in @value{GDBN}.
22715@xref{File-I/O remote protocol extension}, for a list of implemented
22716system calls.
22717
22718@var{parameter@dots{}} is a list of parameters as defined for this very
22719system call.
22720
22721The target replies with this packet when it expects @value{GDBN} to call
22722a host system call on behalf of the target. @value{GDBN} replies with
22723an appropriate @code{F} packet and keeps up waiting for the next reply
22724packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22725@samp{s} action is expected to be continued.
22726@xref{File-I/O remote protocol extension}, for more details.
22727
ee2d5c50
AC
22728@end table
22729
22730@node General Query Packets
22731@section General Query Packets
9c16f35a 22732@cindex remote query requests
c906108c 22733
8e04817f 22734The following set and query packets have already been defined.
c906108c 22735
ee2d5c50 22736@table @r
c906108c 22737
ee2d5c50 22738@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22739@cindex current thread, remote request
22740@cindex @code{qC} packet
ee2d5c50
AC
22741Return the current thread id.
22742
22743Reply:
22744@table @samp
22745@item @code{QC}@var{pid}
e1aac25b 22746Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22747@item *
22748Any other reply implies the old pid.
22749@end table
22750
22751@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22752@cindex list active threads, remote request
22753@cindex @code{qfThreadInfo} packet
ee2d5c50 22754@code{q}@code{sThreadInfo}
c906108c 22755
8e04817f
AC
22756Obtain a list of active thread ids from the target (OS). Since there
22757may be too many active threads to fit into one reply packet, this query
22758works iteratively: it may require more than one query/reply sequence to
22759obtain the entire list of threads. The first query of the sequence will
22760be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22761sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22762
22763NOTE: replaces the @code{qL} query (see below).
22764
22765Reply:
22766@table @samp
22767@item @code{m}@var{id}
22768A single thread id
22769@item @code{m}@var{id},@var{id}@dots{}
22770a comma-separated list of thread ids
22771@item @code{l}
22772(lower case 'el') denotes end of list.
22773@end table
22774
22775In response to each query, the target will reply with a list of one or
e1aac25b
JB
22776more thread ids, in big-endian unsigned hex, separated by commas.
22777@value{GDBN} will respond to each reply with a request for more thread
22778ids (using the @code{qs} form of the query), until the target responds
22779with @code{l} (lower-case el, for @code{'last'}).
c906108c 22780
ee2d5c50 22781@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22782@cindex thread attributes info, remote request
22783@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22784Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22785string description of a thread's attributes from the target OS. This
22786string may contain anything that the target OS thinks is interesting for
22787@value{GDBN} to tell the user about the thread. The string is displayed
22788in @value{GDBN}'s @samp{info threads} display. Some examples of
22789possible thread extra info strings are ``Runnable'', or ``Blocked on
22790Mutex''.
22791
22792Reply:
22793@table @samp
22794@item @var{XX@dots{}}
22795Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22796the printable string containing the extra information about the thread's
8e04817f 22797attributes.
ee2d5c50
AC
22798@end table
22799
22800@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22801
8e04817f
AC
22802Obtain thread information from RTOS. Where: @var{startflag} (one hex
22803digit) is one to indicate the first query and zero to indicate a
22804subsequent query; @var{threadcount} (two hex digits) is the maximum
22805number of threads the response packet can contain; and @var{nextthread}
22806(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22807returned in the response as @var{argthread}.
ee2d5c50
AC
22808
22809NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22810(see above).
22811
22812Reply:
22813@table @samp
22814@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22815Where: @var{count} (two hex digits) is the number of threads being
22816returned; @var{done} (one hex digit) is zero to indicate more threads
22817and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22818digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22819is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22820digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22821@end table
c906108c 22822
ee2d5c50 22823@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22824@cindex CRC of memory block, remote request
22825@cindex @code{qCRC} packet
ee2d5c50
AC
22826Reply:
22827@table @samp
22828@item @code{E}@var{NN}
22829An error (such as memory fault)
22830@item @code{C}@var{CRC32}
22831A 32 bit cyclic redundancy check of the specified memory region.
22832@end table
22833
22834@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22835@cindex section offsets, remote request
22836@cindex @code{qOffsets} packet
8e04817f
AC
22837Get section offsets that the target used when re-locating the downloaded
22838image. @emph{Note: while a @code{Bss} offset is included in the
22839response, @value{GDBN} ignores this and instead applies the @code{Data}
22840offset to the @code{Bss} section.}
c906108c 22841
ee2d5c50
AC
22842Reply:
22843@table @samp
22844@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22845@end table
22846
22847@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22848@cindex thread information, remote request
22849@cindex @code{qP} packet
8e04817f
AC
22850Returns information on @var{threadid}. Where: @var{mode} is a hex
22851encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22852
22853Reply:
22854@table @samp
22855@item *
22856@end table
22857
8e04817f 22858See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22859
ee2d5c50 22860@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22861@cindex execute remote command, remote request
22862@cindex @code{qRcmd} packet
ee2d5c50 22863@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22864execution. Invalid commands should be reported using the output string.
22865Before the final result packet, the target may also respond with a
ee2d5c50
AC
22866number of intermediate @code{O}@var{output} console output packets.
22867@emph{Implementors should note that providing access to a stubs's
22868interpreter may have security implications}.
22869
22870Reply:
22871@table @samp
22872@item OK
8e04817f 22873A command response with no output.
ee2d5c50 22874@item @var{OUTPUT}
8e04817f 22875A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22876@item @code{E}@var{NN}
8e04817f 22877Indicate a badly formed request.
ee2d5c50 22878@item @samp{}
8e04817f 22879When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22880@end table
9c16f35a 22881z
ee2d5c50 22882@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22883@cindex symbol lookup, remote request
22884@cindex @code{qSymbol} packet
8e04817f
AC
22885Notify the target that @value{GDBN} is prepared to serve symbol lookup
22886requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22887
22888Reply:
22889@table @samp
22890@item @code{OK}
8e04817f 22891The target does not need to look up any (more) symbols.
ee2d5c50
AC
22892@item @code{qSymbol:}@var{sym_name}
22893The target requests the value of symbol @var{sym_name} (hex encoded).
22894@value{GDBN} may provide the value by using the
22895@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22896@end table
22897
22898@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22899
22900Set the value of @var{sym_name} to @var{sym_value}.
22901
22902@var{sym_name} (hex encoded) is the name of a symbol whose value the
22903target has previously requested.
22904
22905@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22906@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22907will be empty.
22908
22909Reply:
22910@table @samp
22911@item @code{OK}
8e04817f 22912The target does not need to look up any (more) symbols.
ee2d5c50
AC
22913@item @code{qSymbol:}@var{sym_name}
22914The target requests the value of a new symbol @var{sym_name} (hex
22915encoded). @value{GDBN} will continue to supply the values of symbols
22916(if available), until the target ceases to request them.
22917@end table
eb12ee30 22918
649e03f6 22919@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22920@cindex read special object, remote request
22921@cindex @code{qPart} packet
649e03f6
RM
22922Read uninterpreted bytes from the target's special data area
22923identified by the keyword @code{object}.
22924Request @var{length} bytes starting at @var{offset} bytes into the data.
22925The content and encoding of @var{annex} is specific to the object;
22926it can supply additional details about what data to access.
22927
22928Here are the specific requests of this form defined so far.
22929All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22930requests use the same reply formats, listed below.
22931
22932@table @asis
22933@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22934Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22935auxiliary vector}, and see @ref{Remote configuration,
22936read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22937@end table
22938
22939Reply:
22940@table @asis
22941@item @code{OK}
22942The @var{offset} in the request is at the end of the data.
22943There is no more data to be read.
22944
22945@item @var{XX@dots{}}
22946Hex encoded data bytes read.
22947This may be fewer bytes than the @var{length} in the request.
22948
22949@item @code{E00}
22950The request was malformed, or @var{annex} was invalid.
22951
22952@item @code{E}@var{nn}
22953The offset was invalid, or there was an error encountered reading the data.
22954@var{nn} is a hex-encoded @code{errno} value.
22955
22956@item @code{""} (empty)
22957An empty reply indicates the @var{object} or @var{annex} string was not
22958recognized by the stub.
22959@end table
22960
22961@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22962@cindex write data into object, remote request
649e03f6
RM
22963Write uninterpreted bytes into the target's special data area
22964identified by the keyword @code{object},
22965starting at @var{offset} bytes into the data.
22966@var{data@dots{}} is the hex-encoded data to be written.
22967The content and encoding of @var{annex} is specific to the object;
22968it can supply additional details about what data to access.
22969
22970No requests of this form are presently in use. This specification
22971serves as a placeholder to document the common format that new
22972specific request specifications ought to use.
22973
22974Reply:
22975@table @asis
22976@item @var{nn}
22977@var{nn} (hex encoded) is the number of bytes written.
22978This may be fewer bytes than supplied in the request.
22979
22980@item @code{E00}
22981The request was malformed, or @var{annex} was invalid.
22982
22983@item @code{E}@var{nn}
22984The offset was invalid, or there was an error encountered writing the data.
22985@var{nn} is a hex-encoded @code{errno} value.
22986
22987@item @code{""} (empty)
22988An empty reply indicates the @var{object} or @var{annex} string was not
22989recognized by the stub, or that the object does not support writing.
22990@end table
22991
22992@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22993Requests of this form may be added in the future. When a stub does
22994not recognize the @var{object} keyword, or its support for
22995@var{object} does not recognize the @var{operation} keyword,
22996the stub must respond with an empty packet.
83761cbd
KB
22997
22998@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22999@cindex get thread-local storage address, remote request
23000@cindex @code{qGetTLSAddr} packet
83761cbd
KB
23001Fetch the address associated with thread local storage specified
23002by @var{thread-id}, @var{offset}, and @var{lm}.
23003
23004@var{thread-id} is the (big endian, hex encoded) thread id associated with the
23005thread for which to fetch the TLS address.
23006
23007@var{offset} is the (big endian, hex encoded) offset associated with the
23008thread local variable. (This offset is obtained from the debug
23009information associated with the variable.)
23010
23011@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
23012the load module associated with the thread local storage. For example,
23013a @sc{gnu}/Linux system will pass the link map address of the shared
23014object associated with the thread local storage under consideration.
23015Other operating environments may choose to represent the load module
23016differently, so the precise meaning of this parameter will vary.
23017
23018Reply:
23019@table @asis
68c71a2e 23020@item @var{XX@dots{}}
83761cbd
KB
23021Hex encoded (big endian) bytes representing the address of the thread
23022local storage requested.
23023
23024@item @code{E}@var{nn} (where @var{nn} are hex digits)
23025An error occurred.
23026
23027@item @code{""} (empty)
23028An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
23029@end table
23030
0abb7bc7
EZ
23031Use of this request packet is controlled by the @code{set remote
23032get-thread-local-storage-address} command (@pxref{Remote
23033configuration, set remote get-thread-local-storage-address}).
23034
ee2d5c50
AC
23035@end table
23036
23037@node Register Packet Format
23038@section Register Packet Format
eb12ee30 23039
8e04817f 23040The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
23041In the below, some thirty-two bit registers are transferred as
23042sixty-four bits. Those registers should be zero/sign extended (which?)
23043to fill the space allocated. Register bytes are transfered in target
23044byte order. The two nibbles within a register byte are transfered
23045most-significant - least-significant.
eb12ee30 23046
ee2d5c50 23047@table @r
eb12ee30 23048
8e04817f 23049@item MIPS32
ee2d5c50 23050
8e04817f
AC
23051All registers are transfered as thirty-two bit quantities in the order:
2305232 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23053registers; fsr; fir; fp.
eb12ee30 23054
8e04817f 23055@item MIPS64
ee2d5c50 23056
8e04817f
AC
23057All registers are transfered as sixty-four bit quantities (including
23058thirty-two bit registers such as @code{sr}). The ordering is the same
23059as @code{MIPS32}.
eb12ee30 23060
ee2d5c50
AC
23061@end table
23062
23063@node Examples
23064@section Examples
eb12ee30 23065
8e04817f
AC
23066Example sequence of a target being re-started. Notice how the restart
23067does not get any direct output:
eb12ee30 23068
474c8240 23069@smallexample
d2c6833e
AC
23070-> @code{R00}
23071<- @code{+}
8e04817f 23072@emph{target restarts}
d2c6833e 23073-> @code{?}
8e04817f 23074<- @code{+}
d2c6833e
AC
23075<- @code{T001:1234123412341234}
23076-> @code{+}
474c8240 23077@end smallexample
eb12ee30 23078
8e04817f 23079Example sequence of a target being stepped by a single instruction:
eb12ee30 23080
474c8240 23081@smallexample
d2c6833e 23082-> @code{G1445@dots{}}
8e04817f 23083<- @code{+}
d2c6833e
AC
23084-> @code{s}
23085<- @code{+}
23086@emph{time passes}
23087<- @code{T001:1234123412341234}
8e04817f 23088-> @code{+}
d2c6833e 23089-> @code{g}
8e04817f 23090<- @code{+}
d2c6833e
AC
23091<- @code{1455@dots{}}
23092-> @code{+}
474c8240 23093@end smallexample
eb12ee30 23094
0ce1b118
CV
23095@node File-I/O remote protocol extension
23096@section File-I/O remote protocol extension
23097@cindex File-I/O remote protocol extension
23098
23099@menu
23100* File-I/O Overview::
23101* Protocol basics::
1d8b2f28
JB
23102* The F request packet::
23103* The F reply packet::
0ce1b118
CV
23104* Memory transfer::
23105* The Ctrl-C message::
23106* Console I/O::
23107* The isatty call::
23108* The system call::
23109* List of supported calls::
23110* Protocol specific representation of datatypes::
23111* Constants::
23112* File-I/O Examples::
23113@end menu
23114
23115@node File-I/O Overview
23116@subsection File-I/O Overview
23117@cindex file-i/o overview
23118
9c16f35a
EZ
23119The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23120target to use the host's file system and console I/O when calling various
0ce1b118
CV
23121system calls. System calls on the target system are translated into a
23122remote protocol packet to the host system which then performs the needed
23123actions and returns with an adequate response packet to the target system.
23124This simulates file system operations even on targets that lack file systems.
23125
23126The protocol is defined host- and target-system independent. It uses
9c16f35a 23127its own independent representation of datatypes and values. Both,
0ce1b118
CV
23128@value{GDBN} and the target's @value{GDBN} stub are responsible for
23129translating the system dependent values into the unified protocol values
23130when data is transmitted.
23131
23132The communication is synchronous. A system call is possible only
23133when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23134packets. While @value{GDBN} handles the request for a system call,
23135the target is stopped to allow deterministic access to the target's
23136memory. Therefore File-I/O is not interuptible by target signals. It
23137is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23138
23139The target's request to perform a host system call does not finish
23140the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23141after finishing the system call, the target returns to continuing the
23142previous activity (continue, step). No additional continue or step
23143request from @value{GDBN} is required.
23144
23145@smallexample
f7dc1244 23146(@value{GDBP}) continue
0ce1b118
CV
23147 <- target requests 'system call X'
23148 target is stopped, @value{GDBN} executes system call
23149 -> GDB returns result
23150 ... target continues, GDB returns to wait for the target
23151 <- target hits breakpoint and sends a Txx packet
23152@end smallexample
23153
23154The protocol is only used for files on the host file system and
23155for I/O on the console. Character or block special devices, pipes,
23156named pipes or sockets or any other communication method on the host
23157system are not supported by this protocol.
23158
23159@node Protocol basics
23160@subsection Protocol basics
23161@cindex protocol basics, file-i/o
23162
23163The File-I/O protocol uses the @code{F} packet, as request as well
23164as as reply packet. Since a File-I/O system call can only occur when
b383017d 23165@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23166File-I/O request is a reply that @value{GDBN} has to expect as a result
23167of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23168This @code{F} packet contains all information needed to allow @value{GDBN}
23169to call the appropriate host system call:
23170
23171@itemize @bullet
b383017d 23172@item
0ce1b118
CV
23173A unique identifier for the requested system call.
23174
23175@item
23176All parameters to the system call. Pointers are given as addresses
23177in the target memory address space. Pointers to strings are given as
b383017d 23178pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23179Numerical control values are given in a protocol specific representation.
23180
23181@end itemize
23182
23183At that point @value{GDBN} has to perform the following actions.
23184
23185@itemize @bullet
b383017d 23186@item
0ce1b118
CV
23187If parameter pointer values are given, which point to data needed as input
23188to a system call, @value{GDBN} requests this data from the target with a
23189standard @code{m} packet request. This additional communication has to be
23190expected by the target implementation and is handled as any other @code{m}
23191packet.
23192
23193@item
23194@value{GDBN} translates all value from protocol representation to host
23195representation as needed. Datatypes are coerced into the host types.
23196
23197@item
23198@value{GDBN} calls the system call
23199
23200@item
23201It then coerces datatypes back to protocol representation.
23202
23203@item
23204If pointer parameters in the request packet point to buffer space in which
23205a system call is expected to copy data to, the data is transmitted to the
23206target using a @code{M} or @code{X} packet. This packet has to be expected
23207by the target implementation and is handled as any other @code{M} or @code{X}
23208packet.
23209
23210@end itemize
23211
23212Eventually @value{GDBN} replies with another @code{F} packet which contains all
23213necessary information for the target to continue. This at least contains
23214
23215@itemize @bullet
23216@item
23217Return value.
23218
23219@item
23220@code{errno}, if has been changed by the system call.
23221
23222@item
23223``Ctrl-C'' flag.
23224
23225@end itemize
23226
23227After having done the needed type and value coercion, the target continues
23228the latest continue or step action.
23229
1d8b2f28 23230@node The F request packet
0ce1b118
CV
23231@subsection The @code{F} request packet
23232@cindex file-i/o request packet
23233@cindex @code{F} request packet
23234
23235The @code{F} request packet has the following format:
23236
23237@table @samp
23238
23239@smallexample
23240@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23241@end smallexample
23242
23243@var{call-id} is the identifier to indicate the host system call to be called.
23244This is just the name of the function.
23245
23246@var{parameter@dots{}} are the parameters to the system call.
23247
b383017d 23248@end table
0ce1b118
CV
23249
23250Parameters are hexadecimal integer values, either the real values in case
23251of scalar datatypes, as pointers to target buffer space in case of compound
23252datatypes and unspecified memory areas or as pointer/length pairs in case
23253of string parameters. These are appended to the call-id, each separated
23254from its predecessor by a comma. All values are transmitted in ASCII
23255string representation, pointer/length pairs separated by a slash.
23256
1d8b2f28 23257@node The F reply packet
0ce1b118
CV
23258@subsection The @code{F} reply packet
23259@cindex file-i/o reply packet
23260@cindex @code{F} reply packet
23261
23262The @code{F} reply packet has the following format:
23263
23264@table @samp
23265
23266@smallexample
23267@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23268@end smallexample
23269
23270@var{retcode} is the return code of the system call as hexadecimal value.
23271
23272@var{errno} is the errno set by the call, in protocol specific representation.
23273This parameter can be omitted if the call was successful.
23274
23275@var{Ctrl-C flag} is only send if the user requested a break. In this
23276case, @var{errno} must be send as well, even if the call was successful.
23277The @var{Ctrl-C flag} itself consists of the character 'C':
23278
23279@smallexample
23280F0,0,C
23281@end smallexample
23282
23283@noindent
23284or, if the call was interupted before the host call has been performed:
23285
23286@smallexample
23287F-1,4,C
23288@end smallexample
23289
23290@noindent
23291assuming 4 is the protocol specific representation of @code{EINTR}.
23292
23293@end table
23294
23295@node Memory transfer
23296@subsection Memory transfer
23297@cindex memory transfer, in file-i/o protocol
23298
23299Structured data which is transferred using a memory read or write as e.g.@:
23300a @code{struct stat} is expected to be in a protocol specific format with
23301all scalar multibyte datatypes being big endian. This should be done by
23302the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23303it transfers memory to the target. Transferred pointers to structured
23304data should point to the already coerced data at any time.
23305
23306@node The Ctrl-C message
23307@subsection The Ctrl-C message
23308@cindex ctrl-c message, in file-i/o protocol
23309
23310A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23311reply packet. In this case the target should behave, as if it had
23312gotten a break message. The meaning for the target is ``system call
23313interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23314(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23315packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23316state the system call was interrupted. Since this action is by design
23317not an atomic operation, we have to differ between two cases:
23318
23319@itemize @bullet
23320@item
23321The system call hasn't been performed on the host yet.
23322
23323@item
23324The system call on the host has been finished.
23325
23326@end itemize
23327
23328These two states can be distinguished by the target by the value of the
23329returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23330call hasn't been performed. This is equivalent to the @code{EINTR} handling
23331on POSIX systems. In any other case, the target may presume that the
23332system call has been finished --- successful or not --- and should behave
23333as if the break message arrived right after the system call.
23334
23335@value{GDBN} must behave reliable. If the system call has not been called
23336yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23337@code{errno} in the packet. If the system call on the host has been finished
23338before the user requests a break, the full action must be finshed by
23339@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23340The @code{F} packet may only be send when either nothing has happened
23341or the full action has been completed.
23342
23343@node Console I/O
23344@subsection Console I/O
23345@cindex console i/o as part of file-i/o
23346
23347By default and if not explicitely closed by the target system, the file
23348descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23349on the @value{GDBN} console is handled as any other file output operation
23350(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23351by @value{GDBN} so that after the target read request from file descriptor
233520 all following typing is buffered until either one of the following
23353conditions is met:
23354
23355@itemize @bullet
23356@item
23357The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23358@code{read}
23359system call is treated as finished.
23360
23361@item
23362The user presses @kbd{Enter}. This is treated as end of input with a trailing
23363line feed.
23364
23365@item
23366The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23367character, especially no Ctrl-D is appended to the input.
23368
23369@end itemize
23370
23371If the user has typed more characters as fit in the buffer given to
23372the read call, the trailing characters are buffered in @value{GDBN} until
23373either another @code{read(0, @dots{})} is requested by the target or debugging
23374is stopped on users request.
23375
23376@node The isatty call
2eecc4ab 23377@subsection The @samp{isatty} function call
0ce1b118
CV
23378@cindex isatty call, file-i/o protocol
23379
23380A special case in this protocol is the library call @code{isatty} which
9c16f35a 23381is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
233821 to the target if the file descriptor given as parameter is attached
23383to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23384would require implementing @code{ioctl} and would be more complex than
23385needed.
23386
23387@node The system call
2eecc4ab 23388@subsection The @samp{system} function call
0ce1b118
CV
23389@cindex system call, file-i/o protocol
23390
23391The other special case in this protocol is the @code{system} call which
9c16f35a 23392is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23393task of calling the necessary host calls to perform the @code{system}
23394call. The return value of @code{system} is simplified before it's returned
23395to the target. Basically, the only signal transmitted back is @code{EINTR}
23396in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23397entirely of the exit status of the called command.
23398
9c16f35a
EZ
23399Due to security concerns, the @code{system} call is by default refused
23400by @value{GDBN}. The user has to allow this call explicitly with the
23401@kbd{set remote system-call-allowed 1} command.
0ce1b118 23402
9c16f35a
EZ
23403@table @code
23404@item set remote system-call-allowed
23405@kindex set remote system-call-allowed
23406Control whether to allow the @code{system} calls in the File I/O
23407protocol for the remote target. The default is zero (disabled).
0ce1b118 23408
9c16f35a 23409@item show remote system-call-allowed
0ce1b118 23410@kindex show remote system-call-allowed
9c16f35a
EZ
23411Show the current setting of system calls for the remote File I/O
23412protocol.
0ce1b118
CV
23413@end table
23414
23415@node List of supported calls
23416@subsection List of supported calls
23417@cindex list of supported file-i/o calls
23418
23419@menu
23420* open::
23421* close::
23422* read::
23423* write::
23424* lseek::
23425* rename::
23426* unlink::
23427* stat/fstat::
23428* gettimeofday::
23429* isatty::
23430* system::
23431@end menu
23432
23433@node open
23434@unnumberedsubsubsec open
23435@cindex open, file-i/o system call
23436
23437@smallexample
23438@exdent Synopsis:
23439int open(const char *pathname, int flags);
23440int open(const char *pathname, int flags, mode_t mode);
23441
b383017d 23442@exdent Request:
0ce1b118
CV
23443Fopen,pathptr/len,flags,mode
23444@end smallexample
23445
23446@noindent
23447@code{flags} is the bitwise or of the following values:
23448
23449@table @code
b383017d 23450@item O_CREAT
0ce1b118
CV
23451If the file does not exist it will be created. The host
23452rules apply as far as file ownership and time stamps
23453are concerned.
23454
b383017d 23455@item O_EXCL
0ce1b118
CV
23456When used with O_CREAT, if the file already exists it is
23457an error and open() fails.
23458
b383017d 23459@item O_TRUNC
0ce1b118
CV
23460If the file already exists and the open mode allows
23461writing (O_RDWR or O_WRONLY is given) it will be
23462truncated to length 0.
23463
b383017d 23464@item O_APPEND
0ce1b118
CV
23465The file is opened in append mode.
23466
b383017d 23467@item O_RDONLY
0ce1b118
CV
23468The file is opened for reading only.
23469
b383017d 23470@item O_WRONLY
0ce1b118
CV
23471The file is opened for writing only.
23472
b383017d 23473@item O_RDWR
0ce1b118
CV
23474The file is opened for reading and writing.
23475
23476@noindent
23477Each other bit is silently ignored.
23478
23479@end table
23480
23481@noindent
23482@code{mode} is the bitwise or of the following values:
23483
23484@table @code
b383017d 23485@item S_IRUSR
0ce1b118
CV
23486User has read permission.
23487
b383017d 23488@item S_IWUSR
0ce1b118
CV
23489User has write permission.
23490
b383017d 23491@item S_IRGRP
0ce1b118
CV
23492Group has read permission.
23493
b383017d 23494@item S_IWGRP
0ce1b118
CV
23495Group has write permission.
23496
b383017d 23497@item S_IROTH
0ce1b118
CV
23498Others have read permission.
23499
b383017d 23500@item S_IWOTH
0ce1b118
CV
23501Others have write permission.
23502
23503@noindent
23504Each other bit is silently ignored.
23505
23506@end table
23507
23508@smallexample
23509@exdent Return value:
23510open returns the new file descriptor or -1 if an error
23511occured.
23512
23513@exdent Errors:
23514@end smallexample
23515
23516@table @code
b383017d 23517@item EEXIST
0ce1b118
CV
23518pathname already exists and O_CREAT and O_EXCL were used.
23519
b383017d 23520@item EISDIR
0ce1b118
CV
23521pathname refers to a directory.
23522
b383017d 23523@item EACCES
0ce1b118
CV
23524The requested access is not allowed.
23525
23526@item ENAMETOOLONG
23527pathname was too long.
23528
b383017d 23529@item ENOENT
0ce1b118
CV
23530A directory component in pathname does not exist.
23531
b383017d 23532@item ENODEV
0ce1b118
CV
23533pathname refers to a device, pipe, named pipe or socket.
23534
b383017d 23535@item EROFS
0ce1b118
CV
23536pathname refers to a file on a read-only filesystem and
23537write access was requested.
23538
b383017d 23539@item EFAULT
0ce1b118
CV
23540pathname is an invalid pointer value.
23541
b383017d 23542@item ENOSPC
0ce1b118
CV
23543No space on device to create the file.
23544
b383017d 23545@item EMFILE
0ce1b118
CV
23546The process already has the maximum number of files open.
23547
b383017d 23548@item ENFILE
0ce1b118
CV
23549The limit on the total number of files open on the system
23550has been reached.
23551
b383017d 23552@item EINTR
0ce1b118
CV
23553The call was interrupted by the user.
23554@end table
23555
23556@node close
23557@unnumberedsubsubsec close
23558@cindex close, file-i/o system call
23559
23560@smallexample
b383017d 23561@exdent Synopsis:
0ce1b118
CV
23562int close(int fd);
23563
b383017d 23564@exdent Request:
0ce1b118
CV
23565Fclose,fd
23566
23567@exdent Return value:
23568close returns zero on success, or -1 if an error occurred.
23569
23570@exdent Errors:
23571@end smallexample
23572
23573@table @code
b383017d 23574@item EBADF
0ce1b118
CV
23575fd isn't a valid open file descriptor.
23576
b383017d 23577@item EINTR
0ce1b118
CV
23578The call was interrupted by the user.
23579@end table
23580
23581@node read
23582@unnumberedsubsubsec read
23583@cindex read, file-i/o system call
23584
23585@smallexample
b383017d 23586@exdent Synopsis:
0ce1b118
CV
23587int read(int fd, void *buf, unsigned int count);
23588
b383017d 23589@exdent Request:
0ce1b118
CV
23590Fread,fd,bufptr,count
23591
23592@exdent Return value:
23593On success, the number of bytes read is returned.
23594Zero indicates end of file. If count is zero, read
b383017d 23595returns zero as well. On error, -1 is returned.
0ce1b118
CV
23596
23597@exdent Errors:
23598@end smallexample
23599
23600@table @code
b383017d 23601@item EBADF
0ce1b118
CV
23602fd is not a valid file descriptor or is not open for
23603reading.
23604
b383017d 23605@item EFAULT
0ce1b118
CV
23606buf is an invalid pointer value.
23607
b383017d 23608@item EINTR
0ce1b118
CV
23609The call was interrupted by the user.
23610@end table
23611
23612@node write
23613@unnumberedsubsubsec write
23614@cindex write, file-i/o system call
23615
23616@smallexample
b383017d 23617@exdent Synopsis:
0ce1b118
CV
23618int write(int fd, const void *buf, unsigned int count);
23619
b383017d 23620@exdent Request:
0ce1b118
CV
23621Fwrite,fd,bufptr,count
23622
23623@exdent Return value:
23624On success, the number of bytes written are returned.
23625Zero indicates nothing was written. On error, -1
23626is returned.
23627
23628@exdent Errors:
23629@end smallexample
23630
23631@table @code
b383017d 23632@item EBADF
0ce1b118
CV
23633fd is not a valid file descriptor or is not open for
23634writing.
23635
b383017d 23636@item EFAULT
0ce1b118
CV
23637buf is an invalid pointer value.
23638
b383017d 23639@item EFBIG
0ce1b118
CV
23640An attempt was made to write a file that exceeds the
23641host specific maximum file size allowed.
23642
b383017d 23643@item ENOSPC
0ce1b118
CV
23644No space on device to write the data.
23645
b383017d 23646@item EINTR
0ce1b118
CV
23647The call was interrupted by the user.
23648@end table
23649
23650@node lseek
23651@unnumberedsubsubsec lseek
23652@cindex lseek, file-i/o system call
23653
23654@smallexample
b383017d 23655@exdent Synopsis:
0ce1b118
CV
23656long lseek (int fd, long offset, int flag);
23657
b383017d 23658@exdent Request:
0ce1b118
CV
23659Flseek,fd,offset,flag
23660@end smallexample
23661
23662@code{flag} is one of:
23663
23664@table @code
b383017d 23665@item SEEK_SET
0ce1b118
CV
23666The offset is set to offset bytes.
23667
b383017d 23668@item SEEK_CUR
0ce1b118
CV
23669The offset is set to its current location plus offset
23670bytes.
23671
b383017d 23672@item SEEK_END
0ce1b118
CV
23673The offset is set to the size of the file plus offset
23674bytes.
23675@end table
23676
23677@smallexample
23678@exdent Return value:
23679On success, the resulting unsigned offset in bytes from
23680the beginning of the file is returned. Otherwise, a
23681value of -1 is returned.
23682
23683@exdent Errors:
23684@end smallexample
23685
23686@table @code
b383017d 23687@item EBADF
0ce1b118
CV
23688fd is not a valid open file descriptor.
23689
b383017d 23690@item ESPIPE
0ce1b118
CV
23691fd is associated with the @value{GDBN} console.
23692
b383017d 23693@item EINVAL
0ce1b118
CV
23694flag is not a proper value.
23695
b383017d 23696@item EINTR
0ce1b118
CV
23697The call was interrupted by the user.
23698@end table
23699
23700@node rename
23701@unnumberedsubsubsec rename
23702@cindex rename, file-i/o system call
23703
23704@smallexample
b383017d 23705@exdent Synopsis:
0ce1b118
CV
23706int rename(const char *oldpath, const char *newpath);
23707
b383017d 23708@exdent Request:
0ce1b118
CV
23709Frename,oldpathptr/len,newpathptr/len
23710
23711@exdent Return value:
23712On success, zero is returned. On error, -1 is returned.
23713
23714@exdent Errors:
23715@end smallexample
23716
23717@table @code
b383017d 23718@item EISDIR
0ce1b118
CV
23719newpath is an existing directory, but oldpath is not a
23720directory.
23721
b383017d 23722@item EEXIST
0ce1b118
CV
23723newpath is a non-empty directory.
23724
b383017d 23725@item EBUSY
0ce1b118
CV
23726oldpath or newpath is a directory that is in use by some
23727process.
23728
b383017d 23729@item EINVAL
0ce1b118
CV
23730An attempt was made to make a directory a subdirectory
23731of itself.
23732
b383017d 23733@item ENOTDIR
0ce1b118
CV
23734A component used as a directory in oldpath or new
23735path is not a directory. Or oldpath is a directory
23736and newpath exists but is not a directory.
23737
b383017d 23738@item EFAULT
0ce1b118
CV
23739oldpathptr or newpathptr are invalid pointer values.
23740
b383017d 23741@item EACCES
0ce1b118
CV
23742No access to the file or the path of the file.
23743
23744@item ENAMETOOLONG
b383017d 23745
0ce1b118
CV
23746oldpath or newpath was too long.
23747
b383017d 23748@item ENOENT
0ce1b118
CV
23749A directory component in oldpath or newpath does not exist.
23750
b383017d 23751@item EROFS
0ce1b118
CV
23752The file is on a read-only filesystem.
23753
b383017d 23754@item ENOSPC
0ce1b118
CV
23755The device containing the file has no room for the new
23756directory entry.
23757
b383017d 23758@item EINTR
0ce1b118
CV
23759The call was interrupted by the user.
23760@end table
23761
23762@node unlink
23763@unnumberedsubsubsec unlink
23764@cindex unlink, file-i/o system call
23765
23766@smallexample
b383017d 23767@exdent Synopsis:
0ce1b118
CV
23768int unlink(const char *pathname);
23769
b383017d 23770@exdent Request:
0ce1b118
CV
23771Funlink,pathnameptr/len
23772
23773@exdent Return value:
23774On success, zero is returned. On error, -1 is returned.
23775
23776@exdent Errors:
23777@end smallexample
23778
23779@table @code
b383017d 23780@item EACCES
0ce1b118
CV
23781No access to the file or the path of the file.
23782
b383017d 23783@item EPERM
0ce1b118
CV
23784The system does not allow unlinking of directories.
23785
b383017d 23786@item EBUSY
0ce1b118
CV
23787The file pathname cannot be unlinked because it's
23788being used by another process.
23789
b383017d 23790@item EFAULT
0ce1b118
CV
23791pathnameptr is an invalid pointer value.
23792
23793@item ENAMETOOLONG
23794pathname was too long.
23795
b383017d 23796@item ENOENT
0ce1b118
CV
23797A directory component in pathname does not exist.
23798
b383017d 23799@item ENOTDIR
0ce1b118
CV
23800A component of the path is not a directory.
23801
b383017d 23802@item EROFS
0ce1b118
CV
23803The file is on a read-only filesystem.
23804
b383017d 23805@item EINTR
0ce1b118
CV
23806The call was interrupted by the user.
23807@end table
23808
23809@node stat/fstat
23810@unnumberedsubsubsec stat/fstat
23811@cindex fstat, file-i/o system call
23812@cindex stat, file-i/o system call
23813
23814@smallexample
b383017d 23815@exdent Synopsis:
0ce1b118
CV
23816int stat(const char *pathname, struct stat *buf);
23817int fstat(int fd, struct stat *buf);
23818
b383017d 23819@exdent Request:
0ce1b118
CV
23820Fstat,pathnameptr/len,bufptr
23821Ffstat,fd,bufptr
23822
23823@exdent Return value:
23824On success, zero is returned. On error, -1 is returned.
23825
23826@exdent Errors:
23827@end smallexample
23828
23829@table @code
b383017d 23830@item EBADF
0ce1b118
CV
23831fd is not a valid open file.
23832
b383017d 23833@item ENOENT
0ce1b118
CV
23834A directory component in pathname does not exist or the
23835path is an empty string.
23836
b383017d 23837@item ENOTDIR
0ce1b118
CV
23838A component of the path is not a directory.
23839
b383017d 23840@item EFAULT
0ce1b118
CV
23841pathnameptr is an invalid pointer value.
23842
b383017d 23843@item EACCES
0ce1b118
CV
23844No access to the file or the path of the file.
23845
23846@item ENAMETOOLONG
23847pathname was too long.
23848
b383017d 23849@item EINTR
0ce1b118
CV
23850The call was interrupted by the user.
23851@end table
23852
23853@node gettimeofday
23854@unnumberedsubsubsec gettimeofday
23855@cindex gettimeofday, file-i/o system call
23856
23857@smallexample
b383017d 23858@exdent Synopsis:
0ce1b118
CV
23859int gettimeofday(struct timeval *tv, void *tz);
23860
b383017d 23861@exdent Request:
0ce1b118
CV
23862Fgettimeofday,tvptr,tzptr
23863
23864@exdent Return value:
23865On success, 0 is returned, -1 otherwise.
23866
23867@exdent Errors:
23868@end smallexample
23869
23870@table @code
b383017d 23871@item EINVAL
0ce1b118
CV
23872tz is a non-NULL pointer.
23873
b383017d 23874@item EFAULT
0ce1b118
CV
23875tvptr and/or tzptr is an invalid pointer value.
23876@end table
23877
23878@node isatty
23879@unnumberedsubsubsec isatty
23880@cindex isatty, file-i/o system call
23881
23882@smallexample
b383017d 23883@exdent Synopsis:
0ce1b118
CV
23884int isatty(int fd);
23885
b383017d 23886@exdent Request:
0ce1b118
CV
23887Fisatty,fd
23888
23889@exdent Return value:
23890Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23891
23892@exdent Errors:
23893@end smallexample
23894
23895@table @code
b383017d 23896@item EINTR
0ce1b118
CV
23897The call was interrupted by the user.
23898@end table
23899
23900@node system
23901@unnumberedsubsubsec system
23902@cindex system, file-i/o system call
23903
23904@smallexample
b383017d 23905@exdent Synopsis:
0ce1b118
CV
23906int system(const char *command);
23907
b383017d 23908@exdent Request:
0ce1b118
CV
23909Fsystem,commandptr/len
23910
23911@exdent Return value:
23912The value returned is -1 on error and the return status
23913of the command otherwise. Only the exit status of the
23914command is returned, which is extracted from the hosts
23915system return value by calling WEXITSTATUS(retval).
23916In case /bin/sh could not be executed, 127 is returned.
23917
23918@exdent Errors:
23919@end smallexample
23920
23921@table @code
b383017d 23922@item EINTR
0ce1b118
CV
23923The call was interrupted by the user.
23924@end table
23925
23926@node Protocol specific representation of datatypes
23927@subsection Protocol specific representation of datatypes
23928@cindex protocol specific representation of datatypes, in file-i/o protocol
23929
23930@menu
23931* Integral datatypes::
23932* Pointer values::
23933* struct stat::
23934* struct timeval::
23935@end menu
23936
23937@node Integral datatypes
23938@unnumberedsubsubsec Integral datatypes
23939@cindex integral datatypes, in file-i/o protocol
23940
23941The integral datatypes used in the system calls are
23942
23943@smallexample
23944int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23945@end smallexample
23946
23947@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23948implemented as 32 bit values in this protocol.
23949
b383017d
RM
23950@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23951
0ce1b118
CV
23952@xref{Limits}, for corresponding MIN and MAX values (similar to those
23953in @file{limits.h}) to allow range checking on host and target.
23954
23955@code{time_t} datatypes are defined as seconds since the Epoch.
23956
23957All integral datatypes transferred as part of a memory read or write of a
23958structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23959byte order.
23960
23961@node Pointer values
23962@unnumberedsubsubsec Pointer values
23963@cindex pointer values, in file-i/o protocol
23964
23965Pointers to target data are transmitted as they are. An exception
23966is made for pointers to buffers for which the length isn't
23967transmitted as part of the function call, namely strings. Strings
23968are transmitted as a pointer/length pair, both as hex values, e.g.@:
23969
23970@smallexample
23971@code{1aaf/12}
23972@end smallexample
23973
23974@noindent
23975which is a pointer to data of length 18 bytes at position 0x1aaf.
23976The length is defined as the full string length in bytes, including
23977the trailing null byte. Example:
23978
23979@smallexample
23980``hello, world'' at address 0x123456
23981@end smallexample
23982
23983@noindent
23984is transmitted as
23985
23986@smallexample
23987@code{123456/d}
23988@end smallexample
23989
23990@node struct stat
23991@unnumberedsubsubsec struct stat
23992@cindex struct stat, in file-i/o protocol
23993
23994The buffer of type struct stat used by the target and @value{GDBN} is defined
23995as follows:
23996
23997@smallexample
23998struct stat @{
23999 unsigned int st_dev; /* device */
24000 unsigned int st_ino; /* inode */
24001 mode_t st_mode; /* protection */
24002 unsigned int st_nlink; /* number of hard links */
24003 unsigned int st_uid; /* user ID of owner */
24004 unsigned int st_gid; /* group ID of owner */
24005 unsigned int st_rdev; /* device type (if inode device) */
24006 unsigned long st_size; /* total size, in bytes */
24007 unsigned long st_blksize; /* blocksize for filesystem I/O */
24008 unsigned long st_blocks; /* number of blocks allocated */
24009 time_t st_atime; /* time of last access */
24010 time_t st_mtime; /* time of last modification */
24011 time_t st_ctime; /* time of last change */
24012@};
24013@end smallexample
24014
24015The integral datatypes are conforming to the definitions given in the
24016approriate section (see @ref{Integral datatypes}, for details) so this
24017structure is of size 64 bytes.
24018
24019The values of several fields have a restricted meaning and/or
24020range of values.
24021
24022@smallexample
24023st_dev: 0 file
24024 1 console
24025
24026st_ino: No valid meaning for the target. Transmitted unchanged.
24027
24028st_mode: Valid mode bits are described in Appendix C. Any other
24029 bits have currently no meaning for the target.
24030
24031st_uid: No valid meaning for the target. Transmitted unchanged.
24032
24033st_gid: No valid meaning for the target. Transmitted unchanged.
24034
24035st_rdev: No valid meaning for the target. Transmitted unchanged.
24036
24037st_atime, st_mtime, st_ctime:
24038 These values have a host and file system dependent
24039 accuracy. Especially on Windows hosts the file systems
24040 don't support exact timing values.
24041@end smallexample
24042
24043The target gets a struct stat of the above representation and is
24044responsible to coerce it to the target representation before
24045continuing.
24046
24047Note that due to size differences between the host and target
24048representation of stat members, these members could eventually
24049get truncated on the target.
24050
24051@node struct timeval
24052@unnumberedsubsubsec struct timeval
24053@cindex struct timeval, in file-i/o protocol
24054
24055The buffer of type struct timeval used by the target and @value{GDBN}
24056is defined as follows:
24057
24058@smallexample
b383017d 24059struct timeval @{
0ce1b118
CV
24060 time_t tv_sec; /* second */
24061 long tv_usec; /* microsecond */
24062@};
24063@end smallexample
24064
24065The integral datatypes are conforming to the definitions given in the
24066approriate section (see @ref{Integral datatypes}, for details) so this
24067structure is of size 8 bytes.
24068
24069@node Constants
24070@subsection Constants
24071@cindex constants, in file-i/o protocol
24072
24073The following values are used for the constants inside of the
24074protocol. @value{GDBN} and target are resposible to translate these
24075values before and after the call as needed.
24076
24077@menu
24078* Open flags::
24079* mode_t values::
24080* Errno values::
24081* Lseek flags::
24082* Limits::
24083@end menu
24084
24085@node Open flags
24086@unnumberedsubsubsec Open flags
24087@cindex open flags, in file-i/o protocol
24088
24089All values are given in hexadecimal representation.
24090
24091@smallexample
24092 O_RDONLY 0x0
24093 O_WRONLY 0x1
24094 O_RDWR 0x2
24095 O_APPEND 0x8
24096 O_CREAT 0x200
24097 O_TRUNC 0x400
24098 O_EXCL 0x800
24099@end smallexample
24100
24101@node mode_t values
24102@unnumberedsubsubsec mode_t values
24103@cindex mode_t values, in file-i/o protocol
24104
24105All values are given in octal representation.
24106
24107@smallexample
24108 S_IFREG 0100000
24109 S_IFDIR 040000
24110 S_IRUSR 0400
24111 S_IWUSR 0200
24112 S_IXUSR 0100
24113 S_IRGRP 040
24114 S_IWGRP 020
24115 S_IXGRP 010
24116 S_IROTH 04
24117 S_IWOTH 02
24118 S_IXOTH 01
24119@end smallexample
24120
24121@node Errno values
24122@unnumberedsubsubsec Errno values
24123@cindex errno values, in file-i/o protocol
24124
24125All values are given in decimal representation.
24126
24127@smallexample
24128 EPERM 1
24129 ENOENT 2
24130 EINTR 4
24131 EBADF 9
24132 EACCES 13
24133 EFAULT 14
24134 EBUSY 16
24135 EEXIST 17
24136 ENODEV 19
24137 ENOTDIR 20
24138 EISDIR 21
24139 EINVAL 22
24140 ENFILE 23
24141 EMFILE 24
24142 EFBIG 27
24143 ENOSPC 28
24144 ESPIPE 29
24145 EROFS 30
24146 ENAMETOOLONG 91
24147 EUNKNOWN 9999
24148@end smallexample
24149
24150 EUNKNOWN is used as a fallback error value if a host system returns
24151 any error value not in the list of supported error numbers.
24152
24153@node Lseek flags
24154@unnumberedsubsubsec Lseek flags
24155@cindex lseek flags, in file-i/o protocol
24156
24157@smallexample
24158 SEEK_SET 0
24159 SEEK_CUR 1
24160 SEEK_END 2
24161@end smallexample
24162
24163@node Limits
24164@unnumberedsubsubsec Limits
24165@cindex limits, in file-i/o protocol
24166
24167All values are given in decimal representation.
24168
24169@smallexample
24170 INT_MIN -2147483648
24171 INT_MAX 2147483647
24172 UINT_MAX 4294967295
24173 LONG_MIN -9223372036854775808
24174 LONG_MAX 9223372036854775807
24175 ULONG_MAX 18446744073709551615
24176@end smallexample
24177
24178@node File-I/O Examples
24179@subsection File-I/O Examples
24180@cindex file-i/o examples
24181
24182Example sequence of a write call, file descriptor 3, buffer is at target
24183address 0x1234, 6 bytes should be written:
24184
24185@smallexample
24186<- @code{Fwrite,3,1234,6}
24187@emph{request memory read from target}
24188-> @code{m1234,6}
24189<- XXXXXX
24190@emph{return "6 bytes written"}
24191-> @code{F6}
24192@end smallexample
24193
24194Example sequence of a read call, file descriptor 3, buffer is at target
24195address 0x1234, 6 bytes should be read:
24196
24197@smallexample
24198<- @code{Fread,3,1234,6}
24199@emph{request memory write to target}
24200-> @code{X1234,6:XXXXXX}
24201@emph{return "6 bytes read"}
24202-> @code{F6}
24203@end smallexample
24204
24205Example sequence of a read call, call fails on the host due to invalid
24206file descriptor (EBADF):
24207
24208@smallexample
24209<- @code{Fread,3,1234,6}
24210-> @code{F-1,9}
24211@end smallexample
24212
24213Example sequence of a read call, user presses Ctrl-C before syscall on
24214host is called:
24215
24216@smallexample
24217<- @code{Fread,3,1234,6}
24218-> @code{F-1,4,C}
24219<- @code{T02}
24220@end smallexample
24221
24222Example sequence of a read call, user presses Ctrl-C after syscall on
24223host is called:
24224
24225@smallexample
24226<- @code{Fread,3,1234,6}
24227-> @code{X1234,6:XXXXXX}
24228<- @code{T02}
24229@end smallexample
24230
f418dd93
DJ
24231@include agentexpr.texi
24232
aab4e0ec 24233@include gpl.texi
eb12ee30 24234
2154891a 24235@raisesections
6826cf00 24236@include fdl.texi
2154891a 24237@lowersections
6826cf00 24238
6d2ebf8b 24239@node Index
c906108c
SS
24240@unnumbered Index
24241
24242@printindex cp
24243
24244@tex
24245% I think something like @colophon should be in texinfo. In the
24246% meantime:
24247\long\def\colophon{\hbox to0pt{}\vfill
24248\centerline{The body of this manual is set in}
24249\centerline{\fontname\tenrm,}
24250\centerline{with headings in {\bf\fontname\tenbf}}
24251\centerline{and examples in {\tt\fontname\tentt}.}
24252\centerline{{\it\fontname\tenit\/},}
24253\centerline{{\bf\fontname\tenbf}, and}
24254\centerline{{\sl\fontname\tensl\/}}
24255\centerline{are used for emphasis.}\vfill}
24256\page\colophon
24257% Blame: doc@cygnus.com, 1991.
24258@end tex
24259
c906108c 24260@bye
This page took 3.07369 seconds and 4 git commands to generate.