PR gas/1299
[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
997@item -nowindows
998@itemx -nw
d700128c
EZ
999@cindex @code{--nowindows}
1000@cindex @code{-nw}
2df3850c 1001``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1002(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1003interface. If no GUI is available, this option has no effect.
1004
1005@item -windows
1006@itemx -w
d700128c
EZ
1007@cindex @code{--windows}
1008@cindex @code{-w}
2df3850c
JM
1009If @value{GDBN} includes a GUI, then this option requires it to be
1010used if possible.
c906108c
SS
1011
1012@item -cd @var{directory}
d700128c 1013@cindex @code{--cd}
c906108c
SS
1014Run @value{GDBN} using @var{directory} as its working directory,
1015instead of the current directory.
1016
c906108c
SS
1017@item -fullname
1018@itemx -f
d700128c
EZ
1019@cindex @code{--fullname}
1020@cindex @code{-f}
7a292a7a
SS
1021@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1022subprocess. It tells @value{GDBN} to output the full file name and line
1023number in a standard, recognizable fashion each time a stack frame is
1024displayed (which includes each time your program stops). This
1025recognizable format looks like two @samp{\032} characters, followed by
1026the file name, line number and character position separated by colons,
1027and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1028@samp{\032} characters as a signal to display the source code for the
1029frame.
c906108c 1030
d700128c
EZ
1031@item -epoch
1032@cindex @code{--epoch}
1033The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1034@value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1035routines so as to allow Epoch to display values of expressions in a
1036separate window.
1037
1038@item -annotate @var{level}
1039@cindex @code{--annotate}
1040This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1041effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1042(@pxref{Annotations}). The annotation @var{level} controls how much
1043information @value{GDBN} prints together with its prompt, values of
1044expressions, source lines, and other types of output. Level 0 is the
1045normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1046@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1047that control @value{GDBN}, and level 2 has been deprecated.
1048
265eeb58 1049The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1050(@pxref{GDB/MI}).
d700128c 1051
aa26fa3a
TT
1052@item --args
1053@cindex @code{--args}
1054Change interpretation of command line so that arguments following the
1055executable file are passed as command line arguments to the inferior.
1056This option stops option processing.
1057
2df3850c
JM
1058@item -baud @var{bps}
1059@itemx -b @var{bps}
d700128c
EZ
1060@cindex @code{--baud}
1061@cindex @code{-b}
c906108c
SS
1062Set the line speed (baud rate or bits per second) of any serial
1063interface used by @value{GDBN} for remote debugging.
c906108c 1064
f47b1503
AS
1065@item -l @var{timeout}
1066@cindex @code{-l}
1067Set the timeout (in seconds) of any communication used by @value{GDBN}
1068for remote debugging.
1069
c906108c 1070@item -tty @var{device}
d700128c
EZ
1071@itemx -t @var{device}
1072@cindex @code{--tty}
1073@cindex @code{-t}
c906108c
SS
1074Run using @var{device} for your program's standard input and output.
1075@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1076
53a5351d 1077@c resolve the situation of these eventually
c4555f82
SC
1078@item -tui
1079@cindex @code{--tui}
d0d5df6f
AC
1080Activate the @dfn{Text User Interface} when starting. The Text User
1081Interface manages several text windows on the terminal, showing
1082source, assembly, registers and @value{GDBN} command outputs
1083(@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1084Text User Interface can be enabled by invoking the program
1085@samp{gdbtui}. Do not use this option if you run @value{GDBN} from
1086Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1087
1088@c @item -xdb
d700128c 1089@c @cindex @code{--xdb}
53a5351d
JM
1090@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1091@c For information, see the file @file{xdb_trans.html}, which is usually
1092@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1093@c systems.
1094
d700128c
EZ
1095@item -interpreter @var{interp}
1096@cindex @code{--interpreter}
1097Use the interpreter @var{interp} for interface with the controlling
1098program or device. This option is meant to be set by programs which
94bbb2c0 1099communicate with @value{GDBN} using it as a back end.
21c294e6 1100@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1101
da0f9dcd 1102@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1103@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1104The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1105previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1106selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1107@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1108
1109@item -write
1110@cindex @code{--write}
1111Open the executable and core files for both reading and writing. This
1112is equivalent to the @samp{set write on} command inside @value{GDBN}
1113(@pxref{Patching}).
1114
1115@item -statistics
1116@cindex @code{--statistics}
1117This option causes @value{GDBN} to print statistics about time and
1118memory usage after it completes each command and returns to the prompt.
1119
1120@item -version
1121@cindex @code{--version}
1122This option causes @value{GDBN} to print its version number and
1123no-warranty blurb, and exit.
1124
c906108c
SS
1125@end table
1126
6fc08d32
EZ
1127@node Startup
1128@subsection What @value{GDBN} does during startup
1129@cindex @value{GDBN} startup
1130
1131Here's the description of what @value{GDBN} does during session startup:
1132
1133@enumerate
1134@item
1135Sets up the command interpreter as specified by the command line
1136(@pxref{Mode Options, interpreter}).
1137
1138@item
1139@cindex init file
1140Reads the @dfn{init file} (if any) in your home directory@footnote{On
1141DOS/Windows systems, the home directory is the one pointed to by the
1142@code{HOME} environment variable.} and executes all the commands in
1143that file.
1144
1145@item
1146Processes command line options and operands.
1147
1148@item
1149Reads and executes the commands from init file (if any) in the current
119b882a
EZ
1150working directory. This is only done if the current directory is
1151different from your home directory. Thus, you can have more than one
1152init file, one generic in your home directory, and another, specific
1153to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1154@value{GDBN}.
1155
1156@item
1157Reads command files specified by the @samp{-x} option. @xref{Command
1158Files}, for more details about @value{GDBN} command files.
1159
1160@item
1161Reads the command history recorded in the @dfn{history file}.
d620b259 1162@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1163files where @value{GDBN} records it.
1164@end enumerate
1165
1166Init files use the same syntax as @dfn{command files} (@pxref{Command
1167Files}) and are processed by @value{GDBN} in the same way. The init
1168file in your home directory can set options (such as @samp{set
1169complaints}) that affect subsequent processing of command line options
1170and operands. Init files are not executed if you use the @samp{-nx}
1171option (@pxref{Mode Options, ,Choosing modes}).
1172
1173@cindex init file name
1174@cindex @file{.gdbinit}
119b882a 1175The @value{GDBN} init files are normally called @file{.gdbinit}.
6fc08d32
EZ
1176On some configurations of @value{GDBN}, the init file is known by a
1177different name (these are typically environments where a specialized
1178form of @value{GDBN} may need to coexist with other forms, hence a
1179different name for the specialized version's init file). These are the
1180environments with special init file names:
1181
6fc08d32 1182@itemize @bullet
119b882a
EZ
1183@cindex @file{gdb.ini}
1184@item
1185The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1186the limitations of file names imposed by DOS filesystems. The Windows
1187ports of @value{GDBN} use the standard name, but if they find a
1188@file{gdb.ini} file, they warn you about that and suggest to rename
1189the file to the standard name.
1190
1191@cindex @file{.vxgdbinit}
6fc08d32
EZ
1192@item
1193VxWorks (Wind River Systems real-time OS): @file{.vxgdbinit}
1194
1195@cindex @file{.os68gdbinit}
1196@item
1197OS68K (Enea Data Systems real-time OS): @file{.os68gdbinit}
1198
1199@cindex @file{.esgdbinit}
1200@item
1201ES-1800 (Ericsson Telecom AB M68000 emulator): @file{.esgdbinit}
1202
1203@item
1204CISCO 68k: @file{.cisco-gdbinit}
1205@end itemize
1206
1207
6d2ebf8b 1208@node Quitting GDB
c906108c
SS
1209@section Quitting @value{GDBN}
1210@cindex exiting @value{GDBN}
1211@cindex leaving @value{GDBN}
1212
1213@table @code
1214@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1215@kindex q @r{(@code{quit})}
96a2c332
SS
1216@item quit @r{[}@var{expression}@r{]}
1217@itemx q
1218To exit @value{GDBN}, use the @code{quit} command (abbreviated
1219@code{q}), or type an end-of-file character (usually @kbd{C-d}). If you
1220do not supply @var{expression}, @value{GDBN} will terminate normally;
1221otherwise it will terminate using the result of @var{expression} as the
1222error code.
c906108c
SS
1223@end table
1224
1225@cindex interrupt
1226An interrupt (often @kbd{C-c}) does not exit from @value{GDBN}, but rather
1227terminates the action of any @value{GDBN} command that is in progress and
1228returns to @value{GDBN} command level. It is safe to type the interrupt
1229character at any time because @value{GDBN} does not allow it to take effect
1230until a time when it is safe.
1231
c906108c
SS
1232If you have been using @value{GDBN} to control an attached process or
1233device, you can release it with the @code{detach} command
1234(@pxref{Attach, ,Debugging an already-running process}).
c906108c 1235
6d2ebf8b 1236@node Shell Commands
c906108c
SS
1237@section Shell commands
1238
1239If you need to execute occasional shell commands during your
1240debugging session, there is no need to leave or suspend @value{GDBN}; you can
1241just use the @code{shell} command.
1242
1243@table @code
1244@kindex shell
1245@cindex shell escape
1246@item shell @var{command string}
1247Invoke a standard shell to execute @var{command string}.
c906108c 1248If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1249shell to run. Otherwise @value{GDBN} uses the default shell
1250(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1251@end table
1252
1253The utility @code{make} is often needed in development environments.
1254You do not have to use the @code{shell} command for this purpose in
1255@value{GDBN}:
1256
1257@table @code
1258@kindex make
1259@cindex calling make
1260@item make @var{make-args}
1261Execute the @code{make} program with the specified
1262arguments. This is equivalent to @samp{shell make @var{make-args}}.
1263@end table
1264
0fac0b41
DJ
1265@node Logging output
1266@section Logging output
1267@cindex logging @value{GDBN} output
9c16f35a 1268@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1269
1270You may want to save the output of @value{GDBN} commands to a file.
1271There are several commands to control @value{GDBN}'s logging.
1272
1273@table @code
1274@kindex set logging
1275@item set logging on
1276Enable logging.
1277@item set logging off
1278Disable logging.
9c16f35a 1279@cindex logging file name
0fac0b41
DJ
1280@item set logging file @var{file}
1281Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1282@item set logging overwrite [on|off]
1283By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1284you want @code{set logging on} to overwrite the logfile instead.
1285@item set logging redirect [on|off]
1286By default, @value{GDBN} output will go to both the terminal and the logfile.
1287Set @code{redirect} if you want output to go only to the log file.
1288@kindex show logging
1289@item show logging
1290Show the current values of the logging settings.
1291@end table
1292
6d2ebf8b 1293@node Commands
c906108c
SS
1294@chapter @value{GDBN} Commands
1295
1296You can abbreviate a @value{GDBN} command to the first few letters of the command
1297name, if that abbreviation is unambiguous; and you can repeat certain
1298@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1299key to get @value{GDBN} to fill out the rest of a word in a command (or to
1300show you the alternatives available, if there is more than one possibility).
1301
1302@menu
1303* Command Syntax:: How to give commands to @value{GDBN}
1304* Completion:: Command completion
1305* Help:: How to ask @value{GDBN} for help
1306@end menu
1307
6d2ebf8b 1308@node Command Syntax
c906108c
SS
1309@section Command syntax
1310
1311A @value{GDBN} command is a single line of input. There is no limit on
1312how long it can be. It starts with a command name, which is followed by
1313arguments whose meaning depends on the command name. For example, the
1314command @code{step} accepts an argument which is the number of times to
1315step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1316with no arguments. Some commands do not allow any arguments.
c906108c
SS
1317
1318@cindex abbreviation
1319@value{GDBN} command names may always be truncated if that abbreviation is
1320unambiguous. Other possible command abbreviations are listed in the
1321documentation for individual commands. In some cases, even ambiguous
1322abbreviations are allowed; for example, @code{s} is specially defined as
1323equivalent to @code{step} even though there are other commands whose
1324names start with @code{s}. You can test abbreviations by using them as
1325arguments to the @code{help} command.
1326
1327@cindex repeating commands
41afff9a 1328@kindex RET @r{(repeat last command)}
c906108c 1329A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1330repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1331will not repeat this way; these are commands whose unintentional
1332repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1333repeat. User-defined commands can disable this feature; see
1334@ref{Define, dont-repeat}.
c906108c
SS
1335
1336The @code{list} and @code{x} commands, when you repeat them with
1337@key{RET}, construct new arguments rather than repeating
1338exactly as typed. This permits easy scanning of source or memory.
1339
1340@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1341output, in a way similar to the common utility @code{more}
1342(@pxref{Screen Size,,Screen size}). Since it is easy to press one
1343@key{RET} too many in this situation, @value{GDBN} disables command
1344repetition after any command that generates this sort of display.
1345
41afff9a 1346@kindex # @r{(a comment)}
c906108c
SS
1347@cindex comment
1348Any text from a @kbd{#} to the end of the line is a comment; it does
1349nothing. This is useful mainly in command files (@pxref{Command
1350Files,,Command files}).
1351
88118b3a
TT
1352@cindex repeating command sequences
1353@kindex C-o @r{(operate-and-get-next)}
1354The @kbd{C-o} binding is useful for repeating a complex sequence of
1355commands. This command accepts the current line, like @kbd{RET}, and
1356then fetches the next line relative to the current line from the history
1357for editing.
1358
6d2ebf8b 1359@node Completion
c906108c
SS
1360@section Command completion
1361
1362@cindex completion
1363@cindex word completion
1364@value{GDBN} can fill in the rest of a word in a command for you, if there is
1365only one possibility; it can also show you what the valid possibilities
1366are for the next word in a command, at any time. This works for @value{GDBN}
1367commands, @value{GDBN} subcommands, and the names of symbols in your program.
1368
1369Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1370of a word. If there is only one possibility, @value{GDBN} fills in the
1371word, and waits for you to finish the command (or press @key{RET} to
1372enter it). For example, if you type
1373
1374@c FIXME "@key" does not distinguish its argument sufficiently to permit
1375@c complete accuracy in these examples; space introduced for clarity.
1376@c If texinfo enhancements make it unnecessary, it would be nice to
1377@c replace " @key" by "@key" in the following...
474c8240 1378@smallexample
c906108c 1379(@value{GDBP}) info bre @key{TAB}
474c8240 1380@end smallexample
c906108c
SS
1381
1382@noindent
1383@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1384the only @code{info} subcommand beginning with @samp{bre}:
1385
474c8240 1386@smallexample
c906108c 1387(@value{GDBP}) info breakpoints
474c8240 1388@end smallexample
c906108c
SS
1389
1390@noindent
1391You can either press @key{RET} at this point, to run the @code{info
1392breakpoints} command, or backspace and enter something else, if
1393@samp{breakpoints} does not look like the command you expected. (If you
1394were sure you wanted @code{info breakpoints} in the first place, you
1395might as well just type @key{RET} immediately after @samp{info bre},
1396to exploit command abbreviations rather than command completion).
1397
1398If there is more than one possibility for the next word when you press
1399@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1400characters and try again, or just press @key{TAB} a second time;
1401@value{GDBN} displays all the possible completions for that word. For
1402example, you might want to set a breakpoint on a subroutine whose name
1403begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1404just sounds the bell. Typing @key{TAB} again displays all the
1405function names in your program that begin with those characters, for
1406example:
1407
474c8240 1408@smallexample
c906108c
SS
1409(@value{GDBP}) b make_ @key{TAB}
1410@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1411make_a_section_from_file make_environ
1412make_abs_section make_function_type
1413make_blockvector make_pointer_type
1414make_cleanup make_reference_type
c906108c
SS
1415make_command make_symbol_completion_list
1416(@value{GDBP}) b make_
474c8240 1417@end smallexample
c906108c
SS
1418
1419@noindent
1420After displaying the available possibilities, @value{GDBN} copies your
1421partial input (@samp{b make_} in the example) so you can finish the
1422command.
1423
1424If you just want to see the list of alternatives in the first place, you
b37052ae 1425can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1426means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1427key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1428one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1429
1430@cindex quotes in commands
1431@cindex completion of quoted strings
1432Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1433parentheses or other characters that @value{GDBN} normally excludes from
1434its notion of a word. To permit word completion to work in this
1435situation, you may enclose words in @code{'} (single quote marks) in
1436@value{GDBN} commands.
c906108c 1437
c906108c 1438The most likely situation where you might need this is in typing the
b37052ae
EZ
1439name of a C@t{++} function. This is because C@t{++} allows function
1440overloading (multiple definitions of the same function, distinguished
1441by argument type). For example, when you want to set a breakpoint you
1442may need to distinguish whether you mean the version of @code{name}
1443that takes an @code{int} parameter, @code{name(int)}, or the version
1444that takes a @code{float} parameter, @code{name(float)}. To use the
1445word-completion facilities in this situation, type a single quote
1446@code{'} at the beginning of the function name. This alerts
1447@value{GDBN} that it may need to consider more information than usual
1448when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1449
474c8240 1450@smallexample
96a2c332 1451(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1452bubble(double,double) bubble(int,int)
1453(@value{GDBP}) b 'bubble(
474c8240 1454@end smallexample
c906108c
SS
1455
1456In some cases, @value{GDBN} can tell that completing a name requires using
1457quotes. When this happens, @value{GDBN} inserts the quote for you (while
1458completing as much as it can) if you do not type the quote in the first
1459place:
1460
474c8240 1461@smallexample
c906108c
SS
1462(@value{GDBP}) b bub @key{TAB}
1463@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1464(@value{GDBP}) b 'bubble(
474c8240 1465@end smallexample
c906108c
SS
1466
1467@noindent
1468In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1469you have not yet started typing the argument list when you ask for
1470completion on an overloaded symbol.
1471
d4f3574e 1472For more information about overloaded functions, see @ref{C plus plus
b37052ae 1473expressions, ,C@t{++} expressions}. You can use the command @code{set
c906108c 1474overload-resolution off} to disable overload resolution;
b37052ae 1475see @ref{Debugging C plus plus, ,@value{GDBN} features for C@t{++}}.
c906108c
SS
1476
1477
6d2ebf8b 1478@node Help
c906108c
SS
1479@section Getting help
1480@cindex online documentation
1481@kindex help
1482
5d161b24 1483You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1484using the command @code{help}.
1485
1486@table @code
41afff9a 1487@kindex h @r{(@code{help})}
c906108c
SS
1488@item help
1489@itemx h
1490You can use @code{help} (abbreviated @code{h}) with no arguments to
1491display a short list of named classes of commands:
1492
1493@smallexample
1494(@value{GDBP}) help
1495List of classes of commands:
1496
2df3850c 1497aliases -- Aliases of other commands
c906108c 1498breakpoints -- Making program stop at certain points
2df3850c 1499data -- Examining data
c906108c 1500files -- Specifying and examining files
2df3850c
JM
1501internals -- Maintenance commands
1502obscure -- Obscure features
1503running -- Running the program
1504stack -- Examining the stack
c906108c
SS
1505status -- Status inquiries
1506support -- Support facilities
96a2c332
SS
1507tracepoints -- Tracing of program execution without@*
1508 stopping the program
c906108c 1509user-defined -- User-defined commands
c906108c 1510
5d161b24 1511Type "help" followed by a class name for a list of
c906108c 1512commands in that class.
5d161b24 1513Type "help" followed by command name for full
c906108c
SS
1514documentation.
1515Command name abbreviations are allowed if unambiguous.
1516(@value{GDBP})
1517@end smallexample
96a2c332 1518@c the above line break eliminates huge line overfull...
c906108c
SS
1519
1520@item help @var{class}
1521Using one of the general help classes as an argument, you can get a
1522list of the individual commands in that class. For example, here is the
1523help display for the class @code{status}:
1524
1525@smallexample
1526(@value{GDBP}) help status
1527Status inquiries.
1528
1529List of commands:
1530
1531@c Line break in "show" line falsifies real output, but needed
1532@c to fit in smallbook page size.
2df3850c
JM
1533info -- Generic command for showing things
1534 about the program being debugged
1535show -- Generic command for showing things
1536 about the debugger
c906108c 1537
5d161b24 1538Type "help" followed by command name for full
c906108c
SS
1539documentation.
1540Command name abbreviations are allowed if unambiguous.
1541(@value{GDBP})
1542@end smallexample
1543
1544@item help @var{command}
1545With a command name as @code{help} argument, @value{GDBN} displays a
1546short paragraph on how to use that command.
1547
6837a0a2
DB
1548@kindex apropos
1549@item apropos @var{args}
09d4efe1 1550The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2
DB
1551commands, and their documentation, for the regular expression specified in
1552@var{args}. It prints out all matches found. For example:
1553
1554@smallexample
1555apropos reload
1556@end smallexample
1557
b37052ae
EZ
1558@noindent
1559results in:
6837a0a2
DB
1560
1561@smallexample
6d2ebf8b
SS
1562@c @group
1563set symbol-reloading -- Set dynamic symbol table reloading
1564 multiple times in one run
1565show symbol-reloading -- Show dynamic symbol table reloading
1566 multiple times in one run
1567@c @end group
6837a0a2
DB
1568@end smallexample
1569
c906108c
SS
1570@kindex complete
1571@item complete @var{args}
1572The @code{complete @var{args}} command lists all the possible completions
1573for the beginning of a command. Use @var{args} to specify the beginning of the
1574command you want completed. For example:
1575
1576@smallexample
1577complete i
1578@end smallexample
1579
1580@noindent results in:
1581
1582@smallexample
1583@group
2df3850c
JM
1584if
1585ignore
c906108c
SS
1586info
1587inspect
c906108c
SS
1588@end group
1589@end smallexample
1590
1591@noindent This is intended for use by @sc{gnu} Emacs.
1592@end table
1593
1594In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1595and @code{show} to inquire about the state of your program, or the state
1596of @value{GDBN} itself. Each command supports many topics of inquiry; this
1597manual introduces each of them in the appropriate context. The listings
1598under @code{info} and under @code{show} in the Index point to
1599all the sub-commands. @xref{Index}.
1600
1601@c @group
1602@table @code
1603@kindex info
41afff9a 1604@kindex i @r{(@code{info})}
c906108c
SS
1605@item info
1606This command (abbreviated @code{i}) is for describing the state of your
1607program. For example, you can list the arguments given to your program
1608with @code{info args}, list the registers currently in use with @code{info
1609registers}, or list the breakpoints you have set with @code{info breakpoints}.
1610You can get a complete list of the @code{info} sub-commands with
1611@w{@code{help info}}.
1612
1613@kindex set
1614@item set
5d161b24 1615You can assign the result of an expression to an environment variable with
c906108c
SS
1616@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1617@code{set prompt $}.
1618
1619@kindex show
1620@item show
5d161b24 1621In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1622@value{GDBN} itself.
1623You can change most of the things you can @code{show}, by using the
1624related command @code{set}; for example, you can control what number
1625system is used for displays with @code{set radix}, or simply inquire
1626which is currently in use with @code{show radix}.
1627
1628@kindex info set
1629To display all the settable parameters and their current
1630values, you can use @code{show} with no arguments; you may also use
1631@code{info set}. Both commands produce the same display.
1632@c FIXME: "info set" violates the rule that "info" is for state of
1633@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1634@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1635@end table
1636@c @end group
1637
1638Here are three miscellaneous @code{show} subcommands, all of which are
1639exceptional in lacking corresponding @code{set} commands:
1640
1641@table @code
1642@kindex show version
9c16f35a 1643@cindex @value{GDBN} version number
c906108c
SS
1644@item show version
1645Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1646information in @value{GDBN} bug-reports. If multiple versions of
1647@value{GDBN} are in use at your site, you may need to determine which
1648version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1649commands are introduced, and old ones may wither away. Also, many
1650system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1651variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1652The version number is the same as the one announced when you start
1653@value{GDBN}.
c906108c
SS
1654
1655@kindex show copying
09d4efe1 1656@kindex info copying
9c16f35a 1657@cindex display @value{GDBN} copyright
c906108c 1658@item show copying
09d4efe1 1659@itemx info copying
c906108c
SS
1660Display information about permission for copying @value{GDBN}.
1661
1662@kindex show warranty
09d4efe1 1663@kindex info warranty
c906108c 1664@item show warranty
09d4efe1 1665@itemx info warranty
2df3850c 1666Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1667if your version of @value{GDBN} comes with one.
2df3850c 1668
c906108c
SS
1669@end table
1670
6d2ebf8b 1671@node Running
c906108c
SS
1672@chapter Running Programs Under @value{GDBN}
1673
1674When you run a program under @value{GDBN}, you must first generate
1675debugging information when you compile it.
7a292a7a
SS
1676
1677You may start @value{GDBN} with its arguments, if any, in an environment
1678of your choice. If you are doing native debugging, you may redirect
1679your program's input and output, debug an already running process, or
1680kill a child process.
c906108c
SS
1681
1682@menu
1683* Compilation:: Compiling for debugging
1684* Starting:: Starting your program
c906108c
SS
1685* Arguments:: Your program's arguments
1686* Environment:: Your program's environment
c906108c
SS
1687
1688* Working Directory:: Your program's working directory
1689* Input/Output:: Your program's input and output
1690* Attach:: Debugging an already-running process
1691* Kill Process:: Killing the child process
c906108c
SS
1692
1693* Threads:: Debugging programs with multiple threads
1694* Processes:: Debugging programs with multiple processes
1695@end menu
1696
6d2ebf8b 1697@node Compilation
c906108c
SS
1698@section Compiling for debugging
1699
1700In order to debug a program effectively, you need to generate
1701debugging information when you compile it. This debugging information
1702is stored in the object file; it describes the data type of each
1703variable or function and the correspondence between source line numbers
1704and addresses in the executable code.
1705
1706To request debugging information, specify the @samp{-g} option when you run
1707the compiler.
1708
514c4d71
EZ
1709Programs that are to be shipped to your customers are compiled with
1710optimizations, using the @samp{-O} compiler option. However, many
1711compilers are unable to handle the @samp{-g} and @samp{-O} options
1712together. Using those compilers, you cannot generate optimized
c906108c
SS
1713executables containing debugging information.
1714
514c4d71 1715@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1716without @samp{-O}, making it possible to debug optimized code. We
1717recommend that you @emph{always} use @samp{-g} whenever you compile a
1718program. You may think your program is correct, but there is no sense
1719in pushing your luck.
c906108c
SS
1720
1721@cindex optimized code, debugging
1722@cindex debugging optimized code
1723When you debug a program compiled with @samp{-g -O}, remember that the
1724optimizer is rearranging your code; the debugger shows you what is
1725really there. Do not be too surprised when the execution path does not
1726exactly match your source file! An extreme example: if you define a
1727variable, but never use it, @value{GDBN} never sees that
1728variable---because the compiler optimizes it out of existence.
1729
1730Some things do not work as well with @samp{-g -O} as with just
1731@samp{-g}, particularly on machines with instruction scheduling. If in
1732doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1733please report it to us as a bug (including a test case!).
15387254 1734@xref{Variables}, for more information about debugging optimized code.
c906108c
SS
1735
1736Older versions of the @sc{gnu} C compiler permitted a variant option
1737@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1738format; if your @sc{gnu} C compiler has this option, do not use it.
1739
514c4d71
EZ
1740@value{GDBN} knows about preprocessor macros and can show you their
1741expansion (@pxref{Macros}). Most compilers do not include information
1742about preprocessor macros in the debugging information if you specify
1743the @option{-g} flag alone, because this information is rather large.
1744Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1745provides macro information if you specify the options
1746@option{-gdwarf-2} and @option{-g3}; the former option requests
1747debugging information in the Dwarf 2 format, and the latter requests
1748``extra information''. In the future, we hope to find more compact
1749ways to represent macro information, so that it can be included with
1750@option{-g} alone.
1751
c906108c 1752@need 2000
6d2ebf8b 1753@node Starting
c906108c
SS
1754@section Starting your program
1755@cindex starting
1756@cindex running
1757
1758@table @code
1759@kindex run
41afff9a 1760@kindex r @r{(@code{run})}
c906108c
SS
1761@item run
1762@itemx r
7a292a7a
SS
1763Use the @code{run} command to start your program under @value{GDBN}.
1764You must first specify the program name (except on VxWorks) with an
1765argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1766@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1767(@pxref{Files, ,Commands to specify files}).
c906108c
SS
1768
1769@end table
1770
c906108c
SS
1771If you are running your program in an execution environment that
1772supports processes, @code{run} creates an inferior process and makes
1773that process run your program. (In environments without processes,
1774@code{run} jumps to the start of your program.)
1775
1776The execution of a program is affected by certain information it
1777receives from its superior. @value{GDBN} provides ways to specify this
1778information, which you must do @emph{before} starting your program. (You
1779can change it after starting your program, but such changes only affect
1780your program the next time you start it.) This information may be
1781divided into four categories:
1782
1783@table @asis
1784@item The @emph{arguments.}
1785Specify the arguments to give your program as the arguments of the
1786@code{run} command. If a shell is available on your target, the shell
1787is used to pass the arguments, so that you may use normal conventions
1788(such as wildcard expansion or variable substitution) in describing
1789the arguments.
1790In Unix systems, you can control which shell is used with the
1791@code{SHELL} environment variable.
1792@xref{Arguments, ,Your program's arguments}.
1793
1794@item The @emph{environment.}
1795Your program normally inherits its environment from @value{GDBN}, but you can
1796use the @value{GDBN} commands @code{set environment} and @code{unset
1797environment} to change parts of the environment that affect
1798your program. @xref{Environment, ,Your program's environment}.
1799
1800@item The @emph{working directory.}
1801Your program inherits its working directory from @value{GDBN}. You can set
1802the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1803@xref{Working Directory, ,Your program's working directory}.
1804
1805@item The @emph{standard input and output.}
1806Your program normally uses the same device for standard input and
1807standard output as @value{GDBN} is using. You can redirect input and output
1808in the @code{run} command line, or you can use the @code{tty} command to
1809set a different device for your program.
1810@xref{Input/Output, ,Your program's input and output}.
1811
1812@cindex pipes
1813@emph{Warning:} While input and output redirection work, you cannot use
1814pipes to pass the output of the program you are debugging to another
1815program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1816wrong program.
1817@end table
c906108c
SS
1818
1819When you issue the @code{run} command, your program begins to execute
1820immediately. @xref{Stopping, ,Stopping and continuing}, for discussion
1821of how to arrange for your program to stop. Once your program has
1822stopped, you may call functions in your program, using the @code{print}
1823or @code{call} commands. @xref{Data, ,Examining Data}.
1824
1825If the modification time of your symbol file has changed since the last
1826time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1827table, and reads it again. When it does this, @value{GDBN} tries to retain
1828your current breakpoints.
1829
4e8b0763
JB
1830@table @code
1831@kindex start
1832@item start
1833@cindex run to main procedure
1834The name of the main procedure can vary from language to language.
1835With C or C@t{++}, the main procedure name is always @code{main}, but
1836other languages such as Ada do not require a specific name for their
1837main procedure. The debugger provides a convenient way to start the
1838execution of the program and to stop at the beginning of the main
1839procedure, depending on the language used.
1840
1841The @samp{start} command does the equivalent of setting a temporary
1842breakpoint at the beginning of the main procedure and then invoking
1843the @samp{run} command.
1844
f018e82f
EZ
1845@cindex elaboration phase
1846Some programs contain an @dfn{elaboration} phase where some startup code is
1847executed before the main procedure is called. This depends on the
1848languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
1849constructors for static and global objects are executed before
1850@code{main} is called. It is therefore possible that the debugger stops
1851before reaching the main procedure. However, the temporary breakpoint
1852will remain to halt execution.
1853
1854Specify the arguments to give to your program as arguments to the
1855@samp{start} command. These arguments will be given verbatim to the
1856underlying @samp{run} command. Note that the same arguments will be
1857reused if no argument is provided during subsequent calls to
1858@samp{start} or @samp{run}.
1859
1860It is sometimes necessary to debug the program during elaboration. In
1861these cases, using the @code{start} command would stop the execution of
1862your program too late, as the program would have already completed the
1863elaboration phase. Under these circumstances, insert breakpoints in your
1864elaboration code before running your program.
1865@end table
1866
6d2ebf8b 1867@node Arguments
c906108c
SS
1868@section Your program's arguments
1869
1870@cindex arguments (to your program)
1871The arguments to your program can be specified by the arguments of the
5d161b24 1872@code{run} command.
c906108c
SS
1873They are passed to a shell, which expands wildcard characters and
1874performs redirection of I/O, and thence to your program. Your
1875@code{SHELL} environment variable (if it exists) specifies what shell
1876@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
1877the default shell (@file{/bin/sh} on Unix).
1878
1879On non-Unix systems, the program is usually invoked directly by
1880@value{GDBN}, which emulates I/O redirection via the appropriate system
1881calls, and the wildcard characters are expanded by the startup code of
1882the program, not by the shell.
c906108c
SS
1883
1884@code{run} with no arguments uses the same arguments used by the previous
1885@code{run}, or those set by the @code{set args} command.
1886
c906108c 1887@table @code
41afff9a 1888@kindex set args
c906108c
SS
1889@item set args
1890Specify the arguments to be used the next time your program is run. If
1891@code{set args} has no arguments, @code{run} executes your program
1892with no arguments. Once you have run your program with arguments,
1893using @code{set args} before the next @code{run} is the only way to run
1894it again without arguments.
1895
1896@kindex show args
1897@item show args
1898Show the arguments to give your program when it is started.
1899@end table
1900
6d2ebf8b 1901@node Environment
c906108c
SS
1902@section Your program's environment
1903
1904@cindex environment (of your program)
1905The @dfn{environment} consists of a set of environment variables and
1906their values. Environment variables conventionally record such things as
1907your user name, your home directory, your terminal type, and your search
1908path for programs to run. Usually you set up environment variables with
1909the shell and they are inherited by all the other programs you run. When
1910debugging, it can be useful to try running your program with a modified
1911environment without having to start @value{GDBN} over again.
1912
1913@table @code
1914@kindex path
1915@item path @var{directory}
1916Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
1917(the search path for executables) that will be passed to your program.
1918The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
1919You may specify several directory names, separated by whitespace or by a
1920system-dependent separator character (@samp{:} on Unix, @samp{;} on
1921MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1922is moved to the front, so it is searched sooner.
c906108c
SS
1923
1924You can use the string @samp{$cwd} to refer to whatever is the current
1925working directory at the time @value{GDBN} searches the path. If you
1926use @samp{.} instead, it refers to the directory where you executed the
1927@code{path} command. @value{GDBN} replaces @samp{.} in the
1928@var{directory} argument (with the current path) before adding
1929@var{directory} to the search path.
1930@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1931@c document that, since repeating it would be a no-op.
1932
1933@kindex show paths
1934@item show paths
1935Display the list of search paths for executables (the @code{PATH}
1936environment variable).
1937
1938@kindex show environment
1939@item show environment @r{[}@var{varname}@r{]}
1940Print the value of environment variable @var{varname} to be given to
1941your program when it starts. If you do not supply @var{varname},
1942print the names and values of all environment variables to be given to
1943your program. You can abbreviate @code{environment} as @code{env}.
1944
1945@kindex set environment
53a5351d 1946@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
1947Set environment variable @var{varname} to @var{value}. The value
1948changes for your program only, not for @value{GDBN} itself. @var{value} may
1949be any string; the values of environment variables are just strings, and
1950any interpretation is supplied by your program itself. The @var{value}
1951parameter is optional; if it is eliminated, the variable is set to a
1952null value.
1953@c "any string" here does not include leading, trailing
1954@c blanks. Gnu asks: does anyone care?
1955
1956For example, this command:
1957
474c8240 1958@smallexample
c906108c 1959set env USER = foo
474c8240 1960@end smallexample
c906108c
SS
1961
1962@noindent
d4f3574e 1963tells the debugged program, when subsequently run, that its user is named
c906108c
SS
1964@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
1965are not actually required.)
1966
1967@kindex unset environment
1968@item unset environment @var{varname}
1969Remove variable @var{varname} from the environment to be passed to your
1970program. This is different from @samp{set env @var{varname} =};
1971@code{unset environment} removes the variable from the environment,
1972rather than assigning it an empty value.
1973@end table
1974
d4f3574e
SS
1975@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
1976the shell indicated
c906108c
SS
1977by your @code{SHELL} environment variable if it exists (or
1978@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
1979that runs an initialization file---such as @file{.cshrc} for C-shell, or
1980@file{.bashrc} for BASH---any variables you set in that file affect
1981your program. You may wish to move setting of environment variables to
1982files that are only run when you sign on, such as @file{.login} or
1983@file{.profile}.
1984
6d2ebf8b 1985@node Working Directory
c906108c
SS
1986@section Your program's working directory
1987
1988@cindex working directory (of your program)
1989Each time you start your program with @code{run}, it inherits its
1990working directory from the current working directory of @value{GDBN}.
1991The @value{GDBN} working directory is initially whatever it inherited
1992from its parent process (typically the shell), but you can specify a new
1993working directory in @value{GDBN} with the @code{cd} command.
1994
1995The @value{GDBN} working directory also serves as a default for the commands
1996that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
1997specify files}.
1998
1999@table @code
2000@kindex cd
721c2651 2001@cindex change working directory
c906108c
SS
2002@item cd @var{directory}
2003Set the @value{GDBN} working directory to @var{directory}.
2004
2005@kindex pwd
2006@item pwd
2007Print the @value{GDBN} working directory.
2008@end table
2009
60bf7e09
EZ
2010It is generally impossible to find the current working directory of
2011the process being debugged (since a program can change its directory
2012during its run). If you work on a system where @value{GDBN} is
2013configured with the @file{/proc} support, you can use the @code{info
2014proc} command (@pxref{SVR4 Process Information}) to find out the
2015current working directory of the debuggee.
2016
6d2ebf8b 2017@node Input/Output
c906108c
SS
2018@section Your program's input and output
2019
2020@cindex redirection
2021@cindex i/o
2022@cindex terminal
2023By default, the program you run under @value{GDBN} does input and output to
5d161b24 2024the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2025to its own terminal modes to interact with you, but it records the terminal
2026modes your program was using and switches back to them when you continue
2027running your program.
2028
2029@table @code
2030@kindex info terminal
2031@item info terminal
2032Displays information recorded by @value{GDBN} about the terminal modes your
2033program is using.
2034@end table
2035
2036You can redirect your program's input and/or output using shell
2037redirection with the @code{run} command. For example,
2038
474c8240 2039@smallexample
c906108c 2040run > outfile
474c8240 2041@end smallexample
c906108c
SS
2042
2043@noindent
2044starts your program, diverting its output to the file @file{outfile}.
2045
2046@kindex tty
2047@cindex controlling terminal
2048Another way to specify where your program should do input and output is
2049with the @code{tty} command. This command accepts a file name as
2050argument, and causes this file to be the default for future @code{run}
2051commands. It also resets the controlling terminal for the child
2052process, for future @code{run} commands. For example,
2053
474c8240 2054@smallexample
c906108c 2055tty /dev/ttyb
474c8240 2056@end smallexample
c906108c
SS
2057
2058@noindent
2059directs that processes started with subsequent @code{run} commands
2060default to do input and output on the terminal @file{/dev/ttyb} and have
2061that as their controlling terminal.
2062
2063An explicit redirection in @code{run} overrides the @code{tty} command's
2064effect on the input/output device, but not its effect on the controlling
2065terminal.
2066
2067When you use the @code{tty} command or redirect input in the @code{run}
2068command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2069for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2070for @code{set inferior-tty}.
2071
2072@cindex inferior tty
2073@cindex set inferior controlling terminal
2074You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2075display the name of the terminal that will be used for future runs of your
2076program.
2077
2078@table @code
2079@item set inferior-tty /dev/ttyb
2080@kindex set inferior-tty
2081Set the tty for the program being debugged to /dev/ttyb.
2082
2083@item show inferior-tty
2084@kindex show inferior-tty
2085Show the current tty for the program being debugged.
2086@end table
c906108c 2087
6d2ebf8b 2088@node Attach
c906108c
SS
2089@section Debugging an already-running process
2090@kindex attach
2091@cindex attach
2092
2093@table @code
2094@item attach @var{process-id}
2095This command attaches to a running process---one that was started
2096outside @value{GDBN}. (@code{info files} shows your active
2097targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2098find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2099or with the @samp{jobs -l} shell command.
2100
2101@code{attach} does not repeat if you press @key{RET} a second time after
2102executing the command.
2103@end table
2104
2105To use @code{attach}, your program must be running in an environment
2106which supports processes; for example, @code{attach} does not work for
2107programs on bare-board targets that lack an operating system. You must
2108also have permission to send the process a signal.
2109
2110When you use @code{attach}, the debugger finds the program running in
2111the process first by looking in the current working directory, then (if
2112the program is not found) by using the source file search path
2113(@pxref{Source Path, ,Specifying source directories}). You can also use
2114the @code{file} command to load the program. @xref{Files, ,Commands to
2115Specify Files}.
2116
2117The first thing @value{GDBN} does after arranging to debug the specified
2118process is to stop it. You can examine and modify an attached process
53a5351d
JM
2119with all the @value{GDBN} commands that are ordinarily available when
2120you start processes with @code{run}. You can insert breakpoints; you
2121can step and continue; you can modify storage. If you would rather the
2122process continue running, you may use the @code{continue} command after
c906108c
SS
2123attaching @value{GDBN} to the process.
2124
2125@table @code
2126@kindex detach
2127@item detach
2128When you have finished debugging the attached process, you can use the
2129@code{detach} command to release it from @value{GDBN} control. Detaching
2130the process continues its execution. After the @code{detach} command,
2131that process and @value{GDBN} become completely independent once more, and you
2132are ready to @code{attach} another process or start one with @code{run}.
2133@code{detach} does not repeat if you press @key{RET} again after
2134executing the command.
2135@end table
2136
2137If you exit @value{GDBN} or use the @code{run} command while you have an
2138attached process, you kill that process. By default, @value{GDBN} asks
2139for confirmation if you try to do either of these things; you can
2140control whether or not you need to confirm by using the @code{set
2141confirm} command (@pxref{Messages/Warnings, ,Optional warnings and
2142messages}).
2143
6d2ebf8b 2144@node Kill Process
c906108c 2145@section Killing the child process
c906108c
SS
2146
2147@table @code
2148@kindex kill
2149@item kill
2150Kill the child process in which your program is running under @value{GDBN}.
2151@end table
2152
2153This command is useful if you wish to debug a core dump instead of a
2154running process. @value{GDBN} ignores any core dump file while your program
2155is running.
2156
2157On some operating systems, a program cannot be executed outside @value{GDBN}
2158while you have breakpoints set on it inside @value{GDBN}. You can use the
2159@code{kill} command in this situation to permit running your program
2160outside the debugger.
2161
2162The @code{kill} command is also useful if you wish to recompile and
2163relink your program, since on many systems it is impossible to modify an
2164executable file while it is running in a process. In this case, when you
2165next type @code{run}, @value{GDBN} notices that the file has changed, and
2166reads the symbol table again (while trying to preserve your current
2167breakpoint settings).
2168
6d2ebf8b 2169@node Threads
c906108c 2170@section Debugging programs with multiple threads
c906108c
SS
2171
2172@cindex threads of execution
2173@cindex multiple threads
2174@cindex switching threads
2175In some operating systems, such as HP-UX and Solaris, a single program
2176may have more than one @dfn{thread} of execution. The precise semantics
2177of threads differ from one operating system to another, but in general
2178the threads of a single program are akin to multiple processes---except
2179that they share one address space (that is, they can all examine and
2180modify the same variables). On the other hand, each thread has its own
2181registers and execution stack, and perhaps private memory.
2182
2183@value{GDBN} provides these facilities for debugging multi-thread
2184programs:
2185
2186@itemize @bullet
2187@item automatic notification of new threads
2188@item @samp{thread @var{threadno}}, a command to switch among threads
2189@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2190@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2191a command to apply a command to a list of threads
2192@item thread-specific breakpoints
2193@end itemize
2194
c906108c
SS
2195@quotation
2196@emph{Warning:} These facilities are not yet available on every
2197@value{GDBN} configuration where the operating system supports threads.
2198If your @value{GDBN} does not support threads, these commands have no
2199effect. For example, a system without thread support shows no output
2200from @samp{info threads}, and always rejects the @code{thread} command,
2201like this:
2202
2203@smallexample
2204(@value{GDBP}) info threads
2205(@value{GDBP}) thread 1
2206Thread ID 1 not known. Use the "info threads" command to
2207see the IDs of currently known threads.
2208@end smallexample
2209@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2210@c doesn't support threads"?
2211@end quotation
c906108c
SS
2212
2213@cindex focus of debugging
2214@cindex current thread
2215The @value{GDBN} thread debugging facility allows you to observe all
2216threads while your program runs---but whenever @value{GDBN} takes
2217control, one thread in particular is always the focus of debugging.
2218This thread is called the @dfn{current thread}. Debugging commands show
2219program information from the perspective of the current thread.
2220
41afff9a 2221@cindex @code{New} @var{systag} message
c906108c
SS
2222@cindex thread identifier (system)
2223@c FIXME-implementors!! It would be more helpful if the [New...] message
2224@c included GDB's numeric thread handle, so you could just go to that
2225@c thread without first checking `info threads'.
2226Whenever @value{GDBN} detects a new thread in your program, it displays
2227the target system's identification for the thread with a message in the
2228form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2229whose form varies depending on the particular system. For example, on
2230LynxOS, you might see
2231
474c8240 2232@smallexample
c906108c 2233[New process 35 thread 27]
474c8240 2234@end smallexample
c906108c
SS
2235
2236@noindent
2237when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2238the @var{systag} is simply something like @samp{process 368}, with no
2239further qualifier.
2240
2241@c FIXME!! (1) Does the [New...] message appear even for the very first
2242@c thread of a program, or does it only appear for the
6ca652b0 2243@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2244@c program?
2245@c (2) *Is* there necessarily a first thread always? Or do some
2246@c multithread systems permit starting a program with multiple
5d161b24 2247@c threads ab initio?
c906108c
SS
2248
2249@cindex thread number
2250@cindex thread identifier (GDB)
2251For debugging purposes, @value{GDBN} associates its own thread
2252number---always a single integer---with each thread in your program.
2253
2254@table @code
2255@kindex info threads
2256@item info threads
2257Display a summary of all threads currently in your
2258program. @value{GDBN} displays for each thread (in this order):
2259
2260@enumerate
09d4efe1
EZ
2261@item
2262the thread number assigned by @value{GDBN}
c906108c 2263
09d4efe1
EZ
2264@item
2265the target system's thread identifier (@var{systag})
c906108c 2266
09d4efe1
EZ
2267@item
2268the current stack frame summary for that thread
c906108c
SS
2269@end enumerate
2270
2271@noindent
2272An asterisk @samp{*} to the left of the @value{GDBN} thread number
2273indicates the current thread.
2274
5d161b24 2275For example,
c906108c
SS
2276@end table
2277@c end table here to get a little more width for example
2278
2279@smallexample
2280(@value{GDBP}) info threads
2281 3 process 35 thread 27 0x34e5 in sigpause ()
2282 2 process 35 thread 23 0x34e5 in sigpause ()
2283* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2284 at threadtest.c:68
2285@end smallexample
53a5351d
JM
2286
2287On HP-UX systems:
c906108c 2288
4644b6e3
EZ
2289@cindex debugging multithreaded programs (on HP-UX)
2290@cindex thread identifier (GDB), on HP-UX
c906108c
SS
2291For debugging purposes, @value{GDBN} associates its own thread
2292number---a small integer assigned in thread-creation order---with each
2293thread in your program.
2294
41afff9a
EZ
2295@cindex @code{New} @var{systag} message, on HP-UX
2296@cindex thread identifier (system), on HP-UX
c906108c
SS
2297@c FIXME-implementors!! It would be more helpful if the [New...] message
2298@c included GDB's numeric thread handle, so you could just go to that
2299@c thread without first checking `info threads'.
2300Whenever @value{GDBN} detects a new thread in your program, it displays
2301both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2302form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2303whose form varies depending on the particular system. For example, on
2304HP-UX, you see
2305
474c8240 2306@smallexample
c906108c 2307[New thread 2 (system thread 26594)]
474c8240 2308@end smallexample
c906108c
SS
2309
2310@noindent
5d161b24 2311when @value{GDBN} notices a new thread.
c906108c
SS
2312
2313@table @code
4644b6e3 2314@kindex info threads (HP-UX)
c906108c
SS
2315@item info threads
2316Display a summary of all threads currently in your
2317program. @value{GDBN} displays for each thread (in this order):
2318
2319@enumerate
2320@item the thread number assigned by @value{GDBN}
2321
2322@item the target system's thread identifier (@var{systag})
2323
2324@item the current stack frame summary for that thread
2325@end enumerate
2326
2327@noindent
2328An asterisk @samp{*} to the left of the @value{GDBN} thread number
2329indicates the current thread.
2330
5d161b24 2331For example,
c906108c
SS
2332@end table
2333@c end table here to get a little more width for example
2334
474c8240 2335@smallexample
c906108c 2336(@value{GDBP}) info threads
6d2ebf8b
SS
2337 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2338 at quicksort.c:137
2339 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2340 from /usr/lib/libc.2
2341 1 system thread 27905 0x7b003498 in _brk () \@*
2342 from /usr/lib/libc.2
474c8240 2343@end smallexample
c906108c 2344
c45da7e6
EZ
2345On Solaris, you can display more information about user threads with a
2346Solaris-specific command:
2347
2348@table @code
2349@item maint info sol-threads
2350@kindex maint info sol-threads
2351@cindex thread info (Solaris)
2352Display info on Solaris user threads.
2353@end table
2354
c906108c
SS
2355@table @code
2356@kindex thread @var{threadno}
2357@item thread @var{threadno}
2358Make thread number @var{threadno} the current thread. The command
2359argument @var{threadno} is the internal @value{GDBN} thread number, as
2360shown in the first field of the @samp{info threads} display.
2361@value{GDBN} responds by displaying the system identifier of the thread
2362you selected, and its current stack frame summary:
2363
2364@smallexample
2365@c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2366(@value{GDBP}) thread 2
c906108c 2367[Switching to process 35 thread 23]
c906108c
SS
23680x34e5 in sigpause ()
2369@end smallexample
2370
2371@noindent
2372As with the @samp{[New @dots{}]} message, the form of the text after
2373@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2374threads.
c906108c 2375
9c16f35a 2376@kindex thread apply
638ac427 2377@cindex apply command to several threads
c906108c
SS
2378@item thread apply [@var{threadno}] [@var{all}] @var{args}
2379The @code{thread apply} command allows you to apply a command to one or
2380more threads. Specify the numbers of the threads that you want affected
2381with the command argument @var{threadno}. @var{threadno} is the internal
2382@value{GDBN} thread number, as shown in the first field of the @samp{info
5d161b24
DB
2383threads} display. To apply a command to all threads, use
2384@code{thread apply all} @var{args}.
c906108c
SS
2385@end table
2386
2387@cindex automatic thread selection
2388@cindex switching threads automatically
2389@cindex threads, automatic switching
2390Whenever @value{GDBN} stops your program, due to a breakpoint or a
2391signal, it automatically selects the thread where that breakpoint or
2392signal happened. @value{GDBN} alerts you to the context switch with a
2393message of the form @samp{[Switching to @var{systag}]} to identify the
2394thread.
2395
2396@xref{Thread Stops,,Stopping and starting multi-thread programs}, for
2397more information about how @value{GDBN} behaves when you stop and start
2398programs with multiple threads.
2399
2400@xref{Set Watchpoints,,Setting watchpoints}, for information about
2401watchpoints in programs with multiple threads.
c906108c 2402
6d2ebf8b 2403@node Processes
c906108c
SS
2404@section Debugging programs with multiple processes
2405
2406@cindex fork, debugging programs which call
2407@cindex multiple processes
2408@cindex processes, multiple
53a5351d
JM
2409On most systems, @value{GDBN} has no special support for debugging
2410programs which create additional processes using the @code{fork}
2411function. When a program forks, @value{GDBN} will continue to debug the
2412parent process and the child process will run unimpeded. If you have
2413set a breakpoint in any code which the child then executes, the child
2414will get a @code{SIGTRAP} signal which (unless it catches the signal)
2415will cause it to terminate.
c906108c
SS
2416
2417However, if you want to debug the child process there is a workaround
2418which isn't too painful. Put a call to @code{sleep} in the code which
2419the child process executes after the fork. It may be useful to sleep
2420only if a certain environment variable is set, or a certain file exists,
2421so that the delay need not occur when you don't want to run @value{GDBN}
2422on the child. While the child is sleeping, use the @code{ps} program to
2423get its process ID. Then tell @value{GDBN} (a new invocation of
2424@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2425the child process (@pxref{Attach}). From that point on you can debug
c906108c 2426the child process just like any other process which you attached to.
c906108c 2427
b51970ac
DJ
2428On some systems, @value{GDBN} provides support for debugging programs that
2429create additional processes using the @code{fork} or @code{vfork} functions.
2430Currently, the only platforms with this feature are HP-UX (11.x and later
2431only?) and GNU/Linux (kernel version 2.5.60 and later).
c906108c
SS
2432
2433By default, when a program forks, @value{GDBN} will continue to debug
2434the parent process and the child process will run unimpeded.
2435
2436If you want to follow the child process instead of the parent process,
2437use the command @w{@code{set follow-fork-mode}}.
2438
2439@table @code
2440@kindex set follow-fork-mode
2441@item set follow-fork-mode @var{mode}
2442Set the debugger response to a program call of @code{fork} or
2443@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 2444process. The @var{mode} argument can be:
c906108c
SS
2445
2446@table @code
2447@item parent
2448The original process is debugged after a fork. The child process runs
2df3850c 2449unimpeded. This is the default.
c906108c
SS
2450
2451@item child
2452The new process is debugged after a fork. The parent process runs
2453unimpeded.
2454
c906108c
SS
2455@end table
2456
9c16f35a 2457@kindex show follow-fork-mode
c906108c 2458@item show follow-fork-mode
2df3850c 2459Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
2460@end table
2461
2462If you ask to debug a child process and a @code{vfork} is followed by an
2463@code{exec}, @value{GDBN} executes the new target up to the first
2464breakpoint in the new target. If you have a breakpoint set on
2465@code{main} in your original program, the breakpoint will also be set on
2466the child process's @code{main}.
2467
2468When a child process is spawned by @code{vfork}, you cannot debug the
2469child or parent until an @code{exec} call completes.
2470
2471If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2472call executes, the new target restarts. To restart the parent process,
2473use the @code{file} command with the parent executable name as its
2474argument.
2475
2476You can use the @code{catch} command to make @value{GDBN} stop whenever
2477a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2478Catchpoints, ,Setting catchpoints}.
c906108c 2479
6d2ebf8b 2480@node Stopping
c906108c
SS
2481@chapter Stopping and Continuing
2482
2483The principal purposes of using a debugger are so that you can stop your
2484program before it terminates; or so that, if your program runs into
2485trouble, you can investigate and find out why.
2486
7a292a7a
SS
2487Inside @value{GDBN}, your program may stop for any of several reasons,
2488such as a signal, a breakpoint, or reaching a new line after a
2489@value{GDBN} command such as @code{step}. You may then examine and
2490change variables, set new breakpoints or remove old ones, and then
2491continue execution. Usually, the messages shown by @value{GDBN} provide
2492ample explanation of the status of your program---but you can also
2493explicitly request this information at any time.
c906108c
SS
2494
2495@table @code
2496@kindex info program
2497@item info program
2498Display information about the status of your program: whether it is
7a292a7a 2499running or not, what process it is, and why it stopped.
c906108c
SS
2500@end table
2501
2502@menu
2503* Breakpoints:: Breakpoints, watchpoints, and catchpoints
2504* Continuing and Stepping:: Resuming execution
c906108c 2505* Signals:: Signals
c906108c 2506* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
2507@end menu
2508
6d2ebf8b 2509@node Breakpoints
c906108c
SS
2510@section Breakpoints, watchpoints, and catchpoints
2511
2512@cindex breakpoints
2513A @dfn{breakpoint} makes your program stop whenever a certain point in
2514the program is reached. For each breakpoint, you can add conditions to
2515control in finer detail whether your program stops. You can set
2516breakpoints with the @code{break} command and its variants (@pxref{Set
2517Breaks, ,Setting breakpoints}), to specify the place where your program
2518should stop by line number, function name or exact address in the
2519program.
2520
09d4efe1
EZ
2521On some systems, you can set breakpoints in shared libraries before
2522the executable is run. There is a minor limitation on HP-UX systems:
2523you must wait until the executable is run in order to set breakpoints
2524in shared library routines that are not called directly by the program
2525(for example, routines that are arguments in a @code{pthread_create}
2526call).
c906108c
SS
2527
2528@cindex watchpoints
2529@cindex memory tracing
2530@cindex breakpoint on memory address
2531@cindex breakpoint on variable modification
2532A @dfn{watchpoint} is a special breakpoint that stops your program
2533when the value of an expression changes. You must use a different
2534command to set watchpoints (@pxref{Set Watchpoints, ,Setting
2535watchpoints}), but aside from that, you can manage a watchpoint like
2536any other breakpoint: you enable, disable, and delete both breakpoints
2537and watchpoints using the same commands.
2538
2539You can arrange to have values from your program displayed automatically
2540whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2541Automatic display}.
2542
2543@cindex catchpoints
2544@cindex breakpoint on events
2545A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 2546when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
2547exception or the loading of a library. As with watchpoints, you use a
2548different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2549catchpoints}), but aside from that, you can manage a catchpoint like any
2550other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 2551@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
2552
2553@cindex breakpoint numbers
2554@cindex numbers for breakpoints
2555@value{GDBN} assigns a number to each breakpoint, watchpoint, or
2556catchpoint when you create it; these numbers are successive integers
2557starting with one. In many of the commands for controlling various
2558features of breakpoints you use the breakpoint number to say which
2559breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2560@dfn{disabled}; if disabled, it has no effect on your program until you
2561enable it again.
2562
c5394b80
JM
2563@cindex breakpoint ranges
2564@cindex ranges of breakpoints
2565Some @value{GDBN} commands accept a range of breakpoints on which to
2566operate. A breakpoint range is either a single breakpoint number, like
2567@samp{5}, or two such numbers, in increasing order, separated by a
2568hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2569all breakpoint in that range are operated on.
2570
c906108c
SS
2571@menu
2572* Set Breaks:: Setting breakpoints
2573* Set Watchpoints:: Setting watchpoints
2574* Set Catchpoints:: Setting catchpoints
2575* Delete Breaks:: Deleting breakpoints
2576* Disabling:: Disabling breakpoints
2577* Conditions:: Break conditions
2578* Break Commands:: Breakpoint command lists
c906108c 2579* Breakpoint Menus:: Breakpoint menus
d4f3574e 2580* Error in Breakpoints:: ``Cannot insert breakpoints''
e4d5f7e1 2581* Breakpoint related warnings:: ``Breakpoint address adjusted...''
c906108c
SS
2582@end menu
2583
6d2ebf8b 2584@node Set Breaks
c906108c
SS
2585@subsection Setting breakpoints
2586
5d161b24 2587@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
2588@c consider in particular declaration with/without initialization.
2589@c
2590@c FIXME 2 is there stuff on this already? break at fun start, already init?
2591
2592@kindex break
41afff9a
EZ
2593@kindex b @r{(@code{break})}
2594@vindex $bpnum@r{, convenience variable}
c906108c
SS
2595@cindex latest breakpoint
2596Breakpoints are set with the @code{break} command (abbreviated
5d161b24 2597@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 2598number of the breakpoint you've set most recently; see @ref{Convenience
c906108c
SS
2599Vars,, Convenience variables}, for a discussion of what you can do with
2600convenience variables.
2601
2602You have several ways to say where the breakpoint should go.
2603
2604@table @code
2605@item break @var{function}
5d161b24 2606Set a breakpoint at entry to function @var{function}.
c906108c 2607When using source languages that permit overloading of symbols, such as
b37052ae 2608C@t{++}, @var{function} may refer to more than one possible place to break.
c906108c 2609@xref{Breakpoint Menus,,Breakpoint menus}, for a discussion of that situation.
c906108c
SS
2610
2611@item break +@var{offset}
2612@itemx break -@var{offset}
2613Set a breakpoint some number of lines forward or back from the position
d4f3574e 2614at which execution stopped in the currently selected @dfn{stack frame}.
2df3850c 2615(@xref{Frames, ,Frames}, for a description of stack frames.)
c906108c
SS
2616
2617@item break @var{linenum}
2618Set a breakpoint at line @var{linenum} in the current source file.
d4f3574e
SS
2619The current source file is the last file whose source text was printed.
2620The breakpoint will stop your program just before it executes any of the
c906108c
SS
2621code on that line.
2622
2623@item break @var{filename}:@var{linenum}
2624Set a breakpoint at line @var{linenum} in source file @var{filename}.
2625
2626@item break @var{filename}:@var{function}
2627Set a breakpoint at entry to function @var{function} found in file
2628@var{filename}. Specifying a file name as well as a function name is
2629superfluous except when multiple files contain similarly named
2630functions.
2631
2632@item break *@var{address}
2633Set a breakpoint at address @var{address}. You can use this to set
2634breakpoints in parts of your program which do not have debugging
2635information or source files.
2636
2637@item break
2638When called without any arguments, @code{break} sets a breakpoint at
2639the next instruction to be executed in the selected stack frame
2640(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2641innermost, this makes your program stop as soon as control
2642returns to that frame. This is similar to the effect of a
2643@code{finish} command in the frame inside the selected frame---except
2644that @code{finish} does not leave an active breakpoint. If you use
2645@code{break} without an argument in the innermost frame, @value{GDBN} stops
2646the next time it reaches the current location; this may be useful
2647inside loops.
2648
2649@value{GDBN} normally ignores breakpoints when it resumes execution, until at
2650least one instruction has been executed. If it did not do this, you
2651would be unable to proceed past a breakpoint without first disabling the
2652breakpoint. This rule applies whether or not the breakpoint already
2653existed when your program stopped.
2654
2655@item break @dots{} if @var{cond}
2656Set a breakpoint with condition @var{cond}; evaluate the expression
2657@var{cond} each time the breakpoint is reached, and stop only if the
2658value is nonzero---that is, if @var{cond} evaluates as true.
2659@samp{@dots{}} stands for one of the possible arguments described
2660above (or no argument) specifying where to break. @xref{Conditions,
2661,Break conditions}, for more information on breakpoint conditions.
2662
2663@kindex tbreak
2664@item tbreak @var{args}
2665Set a breakpoint enabled only for one stop. @var{args} are the
2666same as for the @code{break} command, and the breakpoint is set in the same
2667way, but the breakpoint is automatically deleted after the first time your
2668program stops there. @xref{Disabling, ,Disabling breakpoints}.
2669
c906108c 2670@kindex hbreak
ba04e063 2671@cindex hardware breakpoints
c906108c 2672@item hbreak @var{args}
d4f3574e
SS
2673Set a hardware-assisted breakpoint. @var{args} are the same as for the
2674@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
2675breakpoint requires hardware support and some target hardware may not
2676have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
2677debugging, so you can set a breakpoint at an instruction without
2678changing the instruction. This can be used with the new trap-generation
09d4efe1 2679provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
2680will generate traps when a program accesses some data or instruction
2681address that is assigned to the debug registers. However the hardware
2682breakpoint registers can take a limited number of breakpoints. For
2683example, on the DSU, only two data breakpoints can be set at a time, and
2684@value{GDBN} will reject this command if more than two are used. Delete
2685or disable unused hardware breakpoints before setting new ones
2686(@pxref{Disabling, ,Disabling}). @xref{Conditions, ,Break conditions}.
9c16f35a
EZ
2687For remote targets, you can restrict the number of hardware
2688breakpoints @value{GDBN} will use, see @ref{set remote
2689hardware-breakpoint-limit}.
501eef12 2690
c906108c
SS
2691
2692@kindex thbreak
2693@item thbreak @var{args}
2694Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2695are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 2696the same way. However, like the @code{tbreak} command,
c906108c
SS
2697the breakpoint is automatically deleted after the
2698first time your program stops there. Also, like the @code{hbreak}
5d161b24
DB
2699command, the breakpoint requires hardware support and some target hardware
2700may not have this support. @xref{Disabling, ,Disabling breakpoints}.
d4f3574e 2701See also @ref{Conditions, ,Break conditions}.
c906108c
SS
2702
2703@kindex rbreak
2704@cindex regular expression
c45da7e6
EZ
2705@cindex breakpoints in functions matching a regexp
2706@cindex set breakpoints in many functions
c906108c 2707@item rbreak @var{regex}
c906108c 2708Set breakpoints on all functions matching the regular expression
11cf8741
JM
2709@var{regex}. This command sets an unconditional breakpoint on all
2710matches, printing a list of all breakpoints it set. Once these
2711breakpoints are set, they are treated just like the breakpoints set with
2712the @code{break} command. You can delete them, disable them, or make
2713them conditional the same way as any other breakpoint.
2714
2715The syntax of the regular expression is the standard one used with tools
2716like @file{grep}. Note that this is different from the syntax used by
2717shells, so for instance @code{foo*} matches all functions that include
2718an @code{fo} followed by zero or more @code{o}s. There is an implicit
2719@code{.*} leading and trailing the regular expression you supply, so to
2720match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 2721
f7dc1244 2722@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 2723When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
2724breakpoints on overloaded functions that are not members of any special
2725classes.
c906108c 2726
f7dc1244
EZ
2727@cindex set breakpoints on all functions
2728The @code{rbreak} command can be used to set breakpoints in
2729@strong{all} the functions in a program, like this:
2730
2731@smallexample
2732(@value{GDBP}) rbreak .
2733@end smallexample
2734
c906108c
SS
2735@kindex info breakpoints
2736@cindex @code{$_} and @code{info breakpoints}
2737@item info breakpoints @r{[}@var{n}@r{]}
2738@itemx info break @r{[}@var{n}@r{]}
2739@itemx info watchpoints @r{[}@var{n}@r{]}
2740Print a table of all breakpoints, watchpoints, and catchpoints set and
2741not deleted, with the following columns for each breakpoint:
2742
2743@table @emph
2744@item Breakpoint Numbers
2745@item Type
2746Breakpoint, watchpoint, or catchpoint.
2747@item Disposition
2748Whether the breakpoint is marked to be disabled or deleted when hit.
2749@item Enabled or Disabled
2750Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
2751that are not enabled.
2752@item Address
2650777c
JJ
2753Where the breakpoint is in your program, as a memory address. If the
2754breakpoint is pending (see below for details) on a future load of a shared library, the address
2755will be listed as @samp{<PENDING>}.
c906108c
SS
2756@item What
2757Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
2758line number. For a pending breakpoint, the original string passed to
2759the breakpoint command will be listed as it cannot be resolved until
2760the appropriate shared library is loaded in the future.
c906108c
SS
2761@end table
2762
2763@noindent
2764If a breakpoint is conditional, @code{info break} shows the condition on
2765the line following the affected breakpoint; breakpoint commands, if any,
2650777c
JJ
2766are listed after that. A pending breakpoint is allowed to have a condition
2767specified for it. The condition is not parsed for validity until a shared
2768library is loaded that allows the pending breakpoint to resolve to a
2769valid location.
c906108c
SS
2770
2771@noindent
2772@code{info break} with a breakpoint
2773number @var{n} as argument lists only that breakpoint. The
2774convenience variable @code{$_} and the default examining-address for
2775the @code{x} command are set to the address of the last breakpoint
5d161b24 2776listed (@pxref{Memory, ,Examining memory}).
c906108c
SS
2777
2778@noindent
2779@code{info break} displays a count of the number of times the breakpoint
2780has been hit. This is especially useful in conjunction with the
2781@code{ignore} command. You can ignore a large number of breakpoint
2782hits, look at the breakpoint info to see how many times the breakpoint
2783was hit, and then run again, ignoring one less than that number. This
2784will get you quickly to the last hit of that breakpoint.
2785@end table
2786
2787@value{GDBN} allows you to set any number of breakpoints at the same place in
2788your program. There is nothing silly or meaningless about this. When
2789the breakpoints are conditional, this is even useful
2790(@pxref{Conditions, ,Break conditions}).
2791
2650777c 2792@cindex pending breakpoints
dd79a6cf
JJ
2793If a specified breakpoint location cannot be found, it may be due to the fact
2794that the location is in a shared library that is yet to be loaded. In such
2795a case, you may want @value{GDBN} to create a special breakpoint (known as
2796a @dfn{pending breakpoint}) that
2797attempts to resolve itself in the future when an appropriate shared library
2798gets loaded.
2799
2800Pending breakpoints are useful to set at the start of your
2650777c
JJ
2801@value{GDBN} session for locations that you know will be dynamically loaded
2802later by the program being debugged. When shared libraries are loaded,
dd79a6cf
JJ
2803a check is made to see if the load resolves any pending breakpoint locations.
2804If a pending breakpoint location gets resolved,
2805a regular breakpoint is created and the original pending breakpoint is removed.
2806
2807@value{GDBN} provides some additional commands for controlling pending
2808breakpoint support:
2809
2810@kindex set breakpoint pending
2811@kindex show breakpoint pending
2812@table @code
2813@item set breakpoint pending auto
2814This is the default behavior. When @value{GDBN} cannot find the breakpoint
2815location, it queries you whether a pending breakpoint should be created.
2816
2817@item set breakpoint pending on
2818This indicates that an unrecognized breakpoint location should automatically
2819result in a pending breakpoint being created.
2820
2821@item set breakpoint pending off
2822This indicates that pending breakpoints are not to be created. Any
2823unrecognized breakpoint location results in an error. This setting does
2824not affect any pending breakpoints previously created.
2825
2826@item show breakpoint pending
2827Show the current behavior setting for creating pending breakpoints.
2828@end table
2650777c 2829
649e03f6
RM
2830@cindex operations allowed on pending breakpoints
2831Normal breakpoint operations apply to pending breakpoints as well. You may
2832specify a condition for a pending breakpoint and/or commands to run when the
2650777c
JJ
2833breakpoint is reached. You can also enable or disable
2834the pending breakpoint. When you specify a condition for a pending breakpoint,
2835the parsing of the condition will be deferred until the point where the
2836pending breakpoint location is resolved. Disabling a pending breakpoint
2837tells @value{GDBN} to not attempt to resolve the breakpoint on any subsequent
2838shared library load. When a pending breakpoint is re-enabled,
649e03f6 2839@value{GDBN} checks to see if the location is already resolved.
2650777c
JJ
2840This is done because any number of shared library loads could have
2841occurred since the time the breakpoint was disabled and one or more
2842of these loads could resolve the location.
2843
c906108c
SS
2844@cindex negative breakpoint numbers
2845@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
2846@value{GDBN} itself sometimes sets breakpoints in your program for
2847special purposes, such as proper handling of @code{longjmp} (in C
2848programs). These internal breakpoints are assigned negative numbers,
2849starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 2850You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 2851@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
2852
2853
6d2ebf8b 2854@node Set Watchpoints
c906108c
SS
2855@subsection Setting watchpoints
2856
2857@cindex setting watchpoints
c906108c
SS
2858You can use a watchpoint to stop execution whenever the value of an
2859expression changes, without having to predict a particular place where
2860this may happen.
2861
82f2d802
EZ
2862@cindex software watchpoints
2863@cindex hardware watchpoints
c906108c 2864Depending on your system, watchpoints may be implemented in software or
2df3850c 2865hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
2866program and testing the variable's value each time, which is hundreds of
2867times slower than normal execution. (But this may still be worth it, to
2868catch errors where you have no clue what part of your program is the
2869culprit.)
2870
82f2d802
EZ
2871On some systems, such as HP-UX, @sc{gnu}/Linux and most other
2872x86-based targets, @value{GDBN} includes support for hardware
2873watchpoints, which do not slow down the running of your program.
c906108c
SS
2874
2875@table @code
2876@kindex watch
2877@item watch @var{expr}
2878Set a watchpoint for an expression. @value{GDBN} will break when @var{expr}
2879is written into by the program and its value changes.
2880
2881@kindex rwatch
2882@item rwatch @var{expr}
09d4efe1
EZ
2883Set a watchpoint that will break when the value of @var{expr} is read
2884by the program.
c906108c
SS
2885
2886@kindex awatch
2887@item awatch @var{expr}
09d4efe1
EZ
2888Set a watchpoint that will break when @var{expr} is either read from
2889or written into by the program.
c906108c
SS
2890
2891@kindex info watchpoints
2892@item info watchpoints
2893This command prints a list of watchpoints, breakpoints, and catchpoints;
09d4efe1 2894it is the same as @code{info break} (@pxref{Set Breaks}).
c906108c
SS
2895@end table
2896
2897@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
2898watchpoints execute very quickly, and the debugger reports a change in
2899value at the exact instruction where the change occurs. If @value{GDBN}
2900cannot set a hardware watchpoint, it sets a software watchpoint, which
2901executes more slowly and reports the change in value at the next
82f2d802
EZ
2902@emph{statement}, not the instruction, after the change occurs.
2903
82f2d802
EZ
2904@cindex use only software watchpoints
2905You can force @value{GDBN} to use only software watchpoints with the
2906@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
2907zero, @value{GDBN} will never try to use hardware watchpoints, even if
2908the underlying system supports them. (Note that hardware-assisted
2909watchpoints that were set @emph{before} setting
2910@code{can-use-hw-watchpoints} to zero will still use the hardware
2911mechanism of watching expressiion values.)
c906108c 2912
9c16f35a
EZ
2913@table @code
2914@item set can-use-hw-watchpoints
2915@kindex set can-use-hw-watchpoints
2916Set whether or not to use hardware watchpoints.
2917
2918@item show can-use-hw-watchpoints
2919@kindex show can-use-hw-watchpoints
2920Show the current mode of using hardware watchpoints.
2921@end table
2922
2923For remote targets, you can restrict the number of hardware
2924watchpoints @value{GDBN} will use, see @ref{set remote
2925hardware-breakpoint-limit}.
2926
c906108c
SS
2927When you issue the @code{watch} command, @value{GDBN} reports
2928
474c8240 2929@smallexample
c906108c 2930Hardware watchpoint @var{num}: @var{expr}
474c8240 2931@end smallexample
c906108c
SS
2932
2933@noindent
2934if it was able to set a hardware watchpoint.
2935
7be570e7
JM
2936Currently, the @code{awatch} and @code{rwatch} commands can only set
2937hardware watchpoints, because accesses to data that don't change the
2938value of the watched expression cannot be detected without examining
2939every instruction as it is being executed, and @value{GDBN} does not do
2940that currently. If @value{GDBN} finds that it is unable to set a
2941hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
2942will print a message like this:
2943
2944@smallexample
2945Expression cannot be implemented with read/access watchpoint.
2946@end smallexample
2947
2948Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
2949data type of the watched expression is wider than what a hardware
2950watchpoint on the target machine can handle. For example, some systems
2951can only watch regions that are up to 4 bytes wide; on such systems you
2952cannot set hardware watchpoints for an expression that yields a
2953double-precision floating-point number (which is typically 8 bytes
2954wide). As a work-around, it might be possible to break the large region
2955into a series of smaller ones and watch them with separate watchpoints.
2956
2957If you set too many hardware watchpoints, @value{GDBN} might be unable
2958to insert all of them when you resume the execution of your program.
2959Since the precise number of active watchpoints is unknown until such
2960time as the program is about to be resumed, @value{GDBN} might not be
2961able to warn you about this when you set the watchpoints, and the
2962warning will be printed only when the program is resumed:
2963
2964@smallexample
2965Hardware watchpoint @var{num}: Could not insert watchpoint
2966@end smallexample
2967
2968@noindent
2969If this happens, delete or disable some of the watchpoints.
2970
2971The SPARClite DSU will generate traps when a program accesses some data
2972or instruction address that is assigned to the debug registers. For the
2973data addresses, DSU facilitates the @code{watch} command. However the
2974hardware breakpoint registers can only take two data watchpoints, and
2975both watchpoints must be the same kind. For example, you can set two
2976watchpoints with @code{watch} commands, two with @code{rwatch} commands,
2977@strong{or} two with @code{awatch} commands, but you cannot set one
2978watchpoint with one command and the other with a different command.
c906108c
SS
2979@value{GDBN} will reject the command if you try to mix watchpoints.
2980Delete or disable unused watchpoint commands before setting new ones.
2981
2982If you call a function interactively using @code{print} or @code{call},
2df3850c 2983any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
2984kind of breakpoint or the call completes.
2985
7be570e7
JM
2986@value{GDBN} automatically deletes watchpoints that watch local
2987(automatic) variables, or expressions that involve such variables, when
2988they go out of scope, that is, when the execution leaves the block in
2989which these variables were defined. In particular, when the program
2990being debugged terminates, @emph{all} local variables go out of scope,
2991and so only watchpoints that watch global variables remain set. If you
2992rerun the program, you will need to set all such watchpoints again. One
2993way of doing that would be to set a code breakpoint at the entry to the
2994@code{main} function and when it breaks, set all the watchpoints.
2995
c906108c
SS
2996@quotation
2997@cindex watchpoints and threads
2998@cindex threads and watchpoints
c906108c
SS
2999@emph{Warning:} In multi-thread programs, watchpoints have only limited
3000usefulness. With the current watchpoint implementation, @value{GDBN}
3001can only watch the value of an expression @emph{in a single thread}. If
3002you are confident that the expression can only change due to the current
3003thread's activity (and if you are also confident that no other thread
3004can become current), then you can use watchpoints as usual. However,
3005@value{GDBN} may not notice when a non-current thread's activity changes
3006the expression.
53a5351d 3007
d4f3574e 3008@c FIXME: this is almost identical to the previous paragraph.
53a5351d
JM
3009@emph{HP-UX Warning:} In multi-thread programs, software watchpoints
3010have only limited usefulness. If @value{GDBN} creates a software
3011watchpoint, it can only watch the value of an expression @emph{in a
3012single thread}. If you are confident that the expression can only
3013change due to the current thread's activity (and if you are also
3014confident that no other thread can become current), then you can use
3015software watchpoints as usual. However, @value{GDBN} may not notice
3016when a non-current thread's activity changes the expression. (Hardware
3017watchpoints, in contrast, watch an expression in all threads.)
c906108c 3018@end quotation
c906108c 3019
501eef12
AC
3020@xref{set remote hardware-watchpoint-limit}.
3021
6d2ebf8b 3022@node Set Catchpoints
c906108c 3023@subsection Setting catchpoints
d4f3574e 3024@cindex catchpoints, setting
c906108c
SS
3025@cindex exception handlers
3026@cindex event handling
3027
3028You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 3029kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
3030shared library. Use the @code{catch} command to set a catchpoint.
3031
3032@table @code
3033@kindex catch
3034@item catch @var{event}
3035Stop when @var{event} occurs. @var{event} can be any of the following:
3036@table @code
3037@item throw
4644b6e3 3038@cindex stop on C@t{++} exceptions
b37052ae 3039The throwing of a C@t{++} exception.
c906108c
SS
3040
3041@item catch
b37052ae 3042The catching of a C@t{++} exception.
c906108c
SS
3043
3044@item exec
4644b6e3 3045@cindex break on fork/exec
c906108c
SS
3046A call to @code{exec}. This is currently only available for HP-UX.
3047
3048@item fork
c906108c
SS
3049A call to @code{fork}. This is currently only available for HP-UX.
3050
3051@item vfork
c906108c
SS
3052A call to @code{vfork}. This is currently only available for HP-UX.
3053
3054@item load
3055@itemx load @var{libname}
4644b6e3 3056@cindex break on load/unload of shared library
c906108c
SS
3057The dynamic loading of any shared library, or the loading of the library
3058@var{libname}. This is currently only available for HP-UX.
3059
3060@item unload
3061@itemx unload @var{libname}
c906108c
SS
3062The unloading of any dynamically loaded shared library, or the unloading
3063of the library @var{libname}. This is currently only available for HP-UX.
3064@end table
3065
3066@item tcatch @var{event}
3067Set a catchpoint that is enabled only for one stop. The catchpoint is
3068automatically deleted after the first time the event is caught.
3069
3070@end table
3071
3072Use the @code{info break} command to list the current catchpoints.
3073
b37052ae 3074There are currently some limitations to C@t{++} exception handling
c906108c
SS
3075(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3076
3077@itemize @bullet
3078@item
3079If you call a function interactively, @value{GDBN} normally returns
3080control to you when the function has finished executing. If the call
3081raises an exception, however, the call may bypass the mechanism that
3082returns control to you and cause your program either to abort or to
3083simply continue running until it hits a breakpoint, catches a signal
3084that @value{GDBN} is listening for, or exits. This is the case even if
3085you set a catchpoint for the exception; catchpoints on exceptions are
3086disabled within interactive calls.
3087
3088@item
3089You cannot raise an exception interactively.
3090
3091@item
3092You cannot install an exception handler interactively.
3093@end itemize
3094
3095@cindex raise exceptions
3096Sometimes @code{catch} is not the best way to debug exception handling:
3097if you need to know exactly where an exception is raised, it is better to
3098stop @emph{before} the exception handler is called, since that way you
3099can see the stack before any unwinding takes place. If you set a
3100breakpoint in an exception handler instead, it may not be easy to find
3101out where the exception was raised.
3102
3103To stop just before an exception handler is called, you need some
b37052ae 3104knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
3105raised by calling a library function named @code{__raise_exception}
3106which has the following ANSI C interface:
3107
474c8240 3108@smallexample
c906108c 3109 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
3110 @var{id} is the exception identifier. */
3111 void __raise_exception (void **addr, void *id);
474c8240 3112@end smallexample
c906108c
SS
3113
3114@noindent
3115To make the debugger catch all exceptions before any stack
3116unwinding takes place, set a breakpoint on @code{__raise_exception}
3117(@pxref{Breakpoints, ,Breakpoints; watchpoints; and exceptions}).
3118
3119With a conditional breakpoint (@pxref{Conditions, ,Break conditions})
3120that depends on the value of @var{id}, you can stop your program when
3121a specific exception is raised. You can use multiple conditional
3122breakpoints to stop your program when any of a number of exceptions are
3123raised.
3124
3125
6d2ebf8b 3126@node Delete Breaks
c906108c
SS
3127@subsection Deleting breakpoints
3128
3129@cindex clearing breakpoints, watchpoints, catchpoints
3130@cindex deleting breakpoints, watchpoints, catchpoints
3131It is often necessary to eliminate a breakpoint, watchpoint, or
3132catchpoint once it has done its job and you no longer want your program
3133to stop there. This is called @dfn{deleting} the breakpoint. A
3134breakpoint that has been deleted no longer exists; it is forgotten.
3135
3136With the @code{clear} command you can delete breakpoints according to
3137where they are in your program. With the @code{delete} command you can
3138delete individual breakpoints, watchpoints, or catchpoints by specifying
3139their breakpoint numbers.
3140
3141It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3142automatically ignores breakpoints on the first instruction to be executed
3143when you continue execution without changing the execution address.
3144
3145@table @code
3146@kindex clear
3147@item clear
3148Delete any breakpoints at the next instruction to be executed in the
3149selected stack frame (@pxref{Selection, ,Selecting a frame}). When
3150the innermost frame is selected, this is a good way to delete a
3151breakpoint where your program just stopped.
3152
3153@item clear @var{function}
3154@itemx clear @var{filename}:@var{function}
09d4efe1 3155Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
3156
3157@item clear @var{linenum}
3158@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
3159Delete any breakpoints set at or within the code of the specified
3160@var{linenum} of the specified @var{filename}.
c906108c
SS
3161
3162@cindex delete breakpoints
3163@kindex delete
41afff9a 3164@kindex d @r{(@code{delete})}
c5394b80
JM
3165@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3166Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3167ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
3168breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3169confirm off}). You can abbreviate this command as @code{d}.
3170@end table
3171
6d2ebf8b 3172@node Disabling
c906108c
SS
3173@subsection Disabling breakpoints
3174
4644b6e3 3175@cindex enable/disable a breakpoint
c906108c
SS
3176Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3177prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3178it had been deleted, but remembers the information on the breakpoint so
3179that you can @dfn{enable} it again later.
3180
3181You disable and enable breakpoints, watchpoints, and catchpoints with
3182the @code{enable} and @code{disable} commands, optionally specifying one
3183or more breakpoint numbers as arguments. Use @code{info break} or
3184@code{info watch} to print a list of breakpoints, watchpoints, and
3185catchpoints if you do not know which numbers to use.
3186
3187A breakpoint, watchpoint, or catchpoint can have any of four different
3188states of enablement:
3189
3190@itemize @bullet
3191@item
3192Enabled. The breakpoint stops your program. A breakpoint set
3193with the @code{break} command starts out in this state.
3194@item
3195Disabled. The breakpoint has no effect on your program.
3196@item
3197Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 3198disabled.
c906108c
SS
3199@item
3200Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
3201immediately after it does so it is deleted permanently. A breakpoint
3202set with the @code{tbreak} command starts out in this state.
c906108c
SS
3203@end itemize
3204
3205You can use the following commands to enable or disable breakpoints,
3206watchpoints, and catchpoints:
3207
3208@table @code
c906108c 3209@kindex disable
41afff9a 3210@kindex dis @r{(@code{disable})}
c5394b80 3211@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3212Disable the specified breakpoints---or all breakpoints, if none are
3213listed. A disabled breakpoint has no effect but is not forgotten. All
3214options such as ignore-counts, conditions and commands are remembered in
3215case the breakpoint is enabled again later. You may abbreviate
3216@code{disable} as @code{dis}.
3217
c906108c 3218@kindex enable
c5394b80 3219@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
3220Enable the specified breakpoints (or all defined breakpoints). They
3221become effective once again in stopping your program.
3222
c5394b80 3223@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
3224Enable the specified breakpoints temporarily. @value{GDBN} disables any
3225of these breakpoints immediately after stopping your program.
3226
c5394b80 3227@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
3228Enable the specified breakpoints to work once, then die. @value{GDBN}
3229deletes any of these breakpoints as soon as your program stops there.
09d4efe1 3230Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
3231@end table
3232
d4f3574e
SS
3233@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3234@c confusing: tbreak is also initially enabled.
c906108c
SS
3235Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3236,Setting breakpoints}), breakpoints that you set are initially enabled;
3237subsequently, they become disabled or enabled only when you use one of
3238the commands above. (The command @code{until} can set and delete a
3239breakpoint of its own, but it does not change the state of your other
3240breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3241stepping}.)
3242
6d2ebf8b 3243@node Conditions
c906108c
SS
3244@subsection Break conditions
3245@cindex conditional breakpoints
3246@cindex breakpoint conditions
3247
3248@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 3249@c in particular for a watchpoint?
c906108c
SS
3250The simplest sort of breakpoint breaks every time your program reaches a
3251specified place. You can also specify a @dfn{condition} for a
3252breakpoint. A condition is just a Boolean expression in your
3253programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3254a condition evaluates the expression each time your program reaches it,
3255and your program stops only if the condition is @emph{true}.
3256
3257This is the converse of using assertions for program validation; in that
3258situation, you want to stop when the assertion is violated---that is,
3259when the condition is false. In C, if you want to test an assertion expressed
3260by the condition @var{assert}, you should set the condition
3261@samp{! @var{assert}} on the appropriate breakpoint.
3262
3263Conditions are also accepted for watchpoints; you may not need them,
3264since a watchpoint is inspecting the value of an expression anyhow---but
3265it might be simpler, say, to just set a watchpoint on a variable name,
3266and specify a condition that tests whether the new value is an interesting
3267one.
3268
3269Break conditions can have side effects, and may even call functions in
3270your program. This can be useful, for example, to activate functions
3271that log program progress, or to use your own print functions to
3272format special data structures. The effects are completely predictable
3273unless there is another enabled breakpoint at the same address. (In
3274that case, @value{GDBN} might see the other breakpoint first and stop your
3275program without checking the condition of this one.) Note that
d4f3574e
SS
3276breakpoint commands are usually more convenient and flexible than break
3277conditions for the
c906108c
SS
3278purpose of performing side effects when a breakpoint is reached
3279(@pxref{Break Commands, ,Breakpoint command lists}).
3280
3281Break conditions can be specified when a breakpoint is set, by using
3282@samp{if} in the arguments to the @code{break} command. @xref{Set
3283Breaks, ,Setting breakpoints}. They can also be changed at any time
3284with the @code{condition} command.
53a5351d 3285
c906108c
SS
3286You can also use the @code{if} keyword with the @code{watch} command.
3287The @code{catch} command does not recognize the @code{if} keyword;
3288@code{condition} is the only way to impose a further condition on a
3289catchpoint.
c906108c
SS
3290
3291@table @code
3292@kindex condition
3293@item condition @var{bnum} @var{expression}
3294Specify @var{expression} as the break condition for breakpoint,
3295watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3296breakpoint @var{bnum} stops your program only if the value of
3297@var{expression} is true (nonzero, in C). When you use
3298@code{condition}, @value{GDBN} checks @var{expression} immediately for
3299syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
3300referents in the context of your breakpoint. If @var{expression} uses
3301symbols not referenced in the context of the breakpoint, @value{GDBN}
3302prints an error message:
3303
474c8240 3304@smallexample
d4f3574e 3305No symbol "foo" in current context.
474c8240 3306@end smallexample
d4f3574e
SS
3307
3308@noindent
c906108c
SS
3309@value{GDBN} does
3310not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
3311command (or a command that sets a breakpoint with a condition, like
3312@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
3313
3314@item condition @var{bnum}
3315Remove the condition from breakpoint number @var{bnum}. It becomes
3316an ordinary unconditional breakpoint.
3317@end table
3318
3319@cindex ignore count (of breakpoint)
3320A special case of a breakpoint condition is to stop only when the
3321breakpoint has been reached a certain number of times. This is so
3322useful that there is a special way to do it, using the @dfn{ignore
3323count} of the breakpoint. Every breakpoint has an ignore count, which
3324is an integer. Most of the time, the ignore count is zero, and
3325therefore has no effect. But if your program reaches a breakpoint whose
3326ignore count is positive, then instead of stopping, it just decrements
3327the ignore count by one and continues. As a result, if the ignore count
3328value is @var{n}, the breakpoint does not stop the next @var{n} times
3329your program reaches it.
3330
3331@table @code
3332@kindex ignore
3333@item ignore @var{bnum} @var{count}
3334Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3335The next @var{count} times the breakpoint is reached, your program's
3336execution does not stop; other than to decrement the ignore count, @value{GDBN}
3337takes no action.
3338
3339To make the breakpoint stop the next time it is reached, specify
3340a count of zero.
3341
3342When you use @code{continue} to resume execution of your program from a
3343breakpoint, you can specify an ignore count directly as an argument to
3344@code{continue}, rather than using @code{ignore}. @xref{Continuing and
3345Stepping,,Continuing and stepping}.
3346
3347If a breakpoint has a positive ignore count and a condition, the
3348condition is not checked. Once the ignore count reaches zero,
3349@value{GDBN} resumes checking the condition.
3350
3351You could achieve the effect of the ignore count with a condition such
3352as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3353is decremented each time. @xref{Convenience Vars, ,Convenience
3354variables}.
3355@end table
3356
3357Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3358
3359
6d2ebf8b 3360@node Break Commands
c906108c
SS
3361@subsection Breakpoint command lists
3362
3363@cindex breakpoint commands
3364You can give any breakpoint (or watchpoint or catchpoint) a series of
3365commands to execute when your program stops due to that breakpoint. For
3366example, you might want to print the values of certain expressions, or
3367enable other breakpoints.
3368
3369@table @code
3370@kindex commands
3371@kindex end
3372@item commands @r{[}@var{bnum}@r{]}
3373@itemx @dots{} @var{command-list} @dots{}
3374@itemx end
3375Specify a list of commands for breakpoint number @var{bnum}. The commands
3376themselves appear on the following lines. Type a line containing just
3377@code{end} to terminate the commands.
3378
3379To remove all commands from a breakpoint, type @code{commands} and
3380follow it immediately with @code{end}; that is, give no commands.
3381
3382With no @var{bnum} argument, @code{commands} refers to the last
3383breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3384recently encountered).
3385@end table
3386
3387Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3388disabled within a @var{command-list}.
3389
3390You can use breakpoint commands to start your program up again. Simply
3391use the @code{continue} command, or @code{step}, or any other command
3392that resumes execution.
3393
3394Any other commands in the command list, after a command that resumes
3395execution, are ignored. This is because any time you resume execution
3396(even with a simple @code{next} or @code{step}), you may encounter
3397another breakpoint---which could have its own command list, leading to
3398ambiguities about which list to execute.
3399
3400@kindex silent
3401If the first command you specify in a command list is @code{silent}, the
3402usual message about stopping at a breakpoint is not printed. This may
3403be desirable for breakpoints that are to print a specific message and
3404then continue. If none of the remaining commands print anything, you
3405see no sign that the breakpoint was reached. @code{silent} is
3406meaningful only at the beginning of a breakpoint command list.
3407
3408The commands @code{echo}, @code{output}, and @code{printf} allow you to
3409print precisely controlled output, and are often useful in silent
3410breakpoints. @xref{Output, ,Commands for controlled output}.
3411
3412For example, here is how you could use breakpoint commands to print the
3413value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3414
474c8240 3415@smallexample
c906108c
SS
3416break foo if x>0
3417commands
3418silent
3419printf "x is %d\n",x
3420cont
3421end
474c8240 3422@end smallexample
c906108c
SS
3423
3424One application for breakpoint commands is to compensate for one bug so
3425you can test for another. Put a breakpoint just after the erroneous line
3426of code, give it a condition to detect the case in which something
3427erroneous has been done, and give it commands to assign correct values
3428to any variables that need them. End with the @code{continue} command
3429so that your program does not stop, and start with the @code{silent}
3430command so that no output is produced. Here is an example:
3431
474c8240 3432@smallexample
c906108c
SS
3433break 403
3434commands
3435silent
3436set x = y + 4
3437cont
3438end
474c8240 3439@end smallexample
c906108c 3440
6d2ebf8b 3441@node Breakpoint Menus
c906108c
SS
3442@subsection Breakpoint menus
3443@cindex overloading
3444@cindex symbol overloading
3445
b383017d 3446Some programming languages (notably C@t{++} and Objective-C) permit a
b37303ee 3447single function name
c906108c
SS
3448to be defined several times, for application in different contexts.
3449This is called @dfn{overloading}. When a function name is overloaded,
3450@samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3451a breakpoint. If you realize this is a problem, you can use
3452something like @samp{break @var{function}(@var{types})} to specify which
3453particular version of the function you want. Otherwise, @value{GDBN} offers
3454you a menu of numbered choices for different possible breakpoints, and
3455waits for your selection with the prompt @samp{>}. The first two
3456options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3457sets a breakpoint at each definition of @var{function}, and typing
3458@kbd{0} aborts the @code{break} command without setting any new
3459breakpoints.
3460
3461For example, the following session excerpt shows an attempt to set a
3462breakpoint at the overloaded symbol @code{String::after}.
3463We choose three particular definitions of that function name:
3464
3465@c FIXME! This is likely to change to show arg type lists, at least
3466@smallexample
3467@group
3468(@value{GDBP}) b String::after
3469[0] cancel
3470[1] all
3471[2] file:String.cc; line number:867
3472[3] file:String.cc; line number:860
3473[4] file:String.cc; line number:875
3474[5] file:String.cc; line number:853
3475[6] file:String.cc; line number:846
3476[7] file:String.cc; line number:735
3477> 2 4 6
3478Breakpoint 1 at 0xb26c: file String.cc, line 867.
3479Breakpoint 2 at 0xb344: file String.cc, line 875.
3480Breakpoint 3 at 0xafcc: file String.cc, line 846.
3481Multiple breakpoints were set.
3482Use the "delete" command to delete unwanted
3483 breakpoints.
3484(@value{GDBP})
3485@end group
3486@end smallexample
c906108c
SS
3487
3488@c @ifclear BARETARGET
6d2ebf8b 3489@node Error in Breakpoints
d4f3574e 3490@subsection ``Cannot insert breakpoints''
c906108c
SS
3491@c
3492@c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3493@c
d4f3574e
SS
3494Under some operating systems, breakpoints cannot be used in a program if
3495any other process is running that program. In this situation,
5d161b24 3496attempting to run or continue a program with a breakpoint causes
d4f3574e
SS
3497@value{GDBN} to print an error message:
3498
474c8240 3499@smallexample
d4f3574e
SS
3500Cannot insert breakpoints.
3501The same program may be running in another process.
474c8240 3502@end smallexample
d4f3574e
SS
3503
3504When this happens, you have three ways to proceed:
3505
3506@enumerate
3507@item
3508Remove or disable the breakpoints, then continue.
3509
3510@item
5d161b24 3511Suspend @value{GDBN}, and copy the file containing your program to a new
d4f3574e 3512name. Resume @value{GDBN} and use the @code{exec-file} command to specify
5d161b24 3513that @value{GDBN} should run your program under that name.
d4f3574e
SS
3514Then start your program again.
3515
3516@item
3517Relink your program so that the text segment is nonsharable, using the
3518linker option @samp{-N}. The operating system limitation may not apply
3519to nonsharable executables.
3520@end enumerate
c906108c
SS
3521@c @end ifclear
3522
d4f3574e
SS
3523A similar message can be printed if you request too many active
3524hardware-assisted breakpoints and watchpoints:
3525
3526@c FIXME: the precise wording of this message may change; the relevant
3527@c source change is not committed yet (Sep 3, 1999).
3528@smallexample
3529Stopped; cannot insert breakpoints.
3530You may have requested too many hardware breakpoints and watchpoints.
3531@end smallexample
3532
3533@noindent
3534This message is printed when you attempt to resume the program, since
3535only then @value{GDBN} knows exactly how many hardware breakpoints and
3536watchpoints it needs to insert.
3537
3538When this message is printed, you need to disable or remove some of the
3539hardware-assisted breakpoints and watchpoints, and then continue.
3540
1485d690
KB
3541@node Breakpoint related warnings
3542@subsection ``Breakpoint address adjusted...''
3543@cindex breakpoint address adjusted
3544
3545Some processor architectures place constraints on the addresses at
3546which breakpoints may be placed. For architectures thus constrained,
3547@value{GDBN} will attempt to adjust the breakpoint's address to comply
3548with the constraints dictated by the architecture.
3549
3550One example of such an architecture is the Fujitsu FR-V. The FR-V is
3551a VLIW architecture in which a number of RISC-like instructions may be
3552bundled together for parallel execution. The FR-V architecture
3553constrains the location of a breakpoint instruction within such a
3554bundle to the instruction with the lowest address. @value{GDBN}
3555honors this constraint by adjusting a breakpoint's address to the
3556first in the bundle.
3557
3558It is not uncommon for optimized code to have bundles which contain
3559instructions from different source statements, thus it may happen that
3560a breakpoint's address will be adjusted from one source statement to
3561another. Since this adjustment may significantly alter @value{GDBN}'s
3562breakpoint related behavior from what the user expects, a warning is
3563printed when the breakpoint is first set and also when the breakpoint
3564is hit.
3565
3566A warning like the one below is printed when setting a breakpoint
3567that's been subject to address adjustment:
3568
3569@smallexample
3570warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3571@end smallexample
3572
3573Such warnings are printed both for user settable and @value{GDBN}'s
3574internal breakpoints. If you see one of these warnings, you should
3575verify that a breakpoint set at the adjusted address will have the
3576desired affect. If not, the breakpoint in question may be removed and
b383017d 3577other breakpoints may be set which will have the desired behavior.
1485d690
KB
3578E.g., it may be sufficient to place the breakpoint at a later
3579instruction. A conditional breakpoint may also be useful in some
3580cases to prevent the breakpoint from triggering too often.
3581
3582@value{GDBN} will also issue a warning when stopping at one of these
3583adjusted breakpoints:
3584
3585@smallexample
3586warning: Breakpoint 1 address previously adjusted from 0x00010414
3587to 0x00010410.
3588@end smallexample
3589
3590When this warning is encountered, it may be too late to take remedial
3591action except in cases where the breakpoint is hit earlier or more
3592frequently than expected.
d4f3574e 3593
6d2ebf8b 3594@node Continuing and Stepping
c906108c
SS
3595@section Continuing and stepping
3596
3597@cindex stepping
3598@cindex continuing
3599@cindex resuming execution
3600@dfn{Continuing} means resuming program execution until your program
3601completes normally. In contrast, @dfn{stepping} means executing just
3602one more ``step'' of your program, where ``step'' may mean either one
3603line of source code, or one machine instruction (depending on what
7a292a7a
SS
3604particular command you use). Either when continuing or when stepping,
3605your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
3606it stops due to a signal, you may want to use @code{handle}, or use
3607@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
3608
3609@table @code
3610@kindex continue
41afff9a
EZ
3611@kindex c @r{(@code{continue})}
3612@kindex fg @r{(resume foreground execution)}
c906108c
SS
3613@item continue @r{[}@var{ignore-count}@r{]}
3614@itemx c @r{[}@var{ignore-count}@r{]}
3615@itemx fg @r{[}@var{ignore-count}@r{]}
3616Resume program execution, at the address where your program last stopped;
3617any breakpoints set at that address are bypassed. The optional argument
3618@var{ignore-count} allows you to specify a further number of times to
3619ignore a breakpoint at this location; its effect is like that of
3620@code{ignore} (@pxref{Conditions, ,Break conditions}).
3621
3622The argument @var{ignore-count} is meaningful only when your program
3623stopped due to a breakpoint. At other times, the argument to
3624@code{continue} is ignored.
3625
d4f3574e
SS
3626The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
3627debugged program is deemed to be the foreground program) are provided
3628purely for convenience, and have exactly the same behavior as
3629@code{continue}.
c906108c
SS
3630@end table
3631
3632To resume execution at a different place, you can use @code{return}
3633(@pxref{Returning, ,Returning from a function}) to go back to the
3634calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
3635different address}) to go to an arbitrary location in your program.
3636
3637A typical technique for using stepping is to set a breakpoint
3638(@pxref{Breakpoints, ,Breakpoints; watchpoints; and catchpoints}) at the
3639beginning of the function or the section of your program where a problem
3640is believed to lie, run your program until it stops at that breakpoint,
3641and then step through the suspect area, examining the variables that are
3642interesting, until you see the problem happen.
3643
3644@table @code
3645@kindex step
41afff9a 3646@kindex s @r{(@code{step})}
c906108c
SS
3647@item step
3648Continue running your program until control reaches a different source
3649line, then stop it and return control to @value{GDBN}. This command is
3650abbreviated @code{s}.
3651
3652@quotation
3653@c "without debugging information" is imprecise; actually "without line
3654@c numbers in the debugging information". (gcc -g1 has debugging info but
3655@c not line numbers). But it seems complex to try to make that
3656@c distinction here.
3657@emph{Warning:} If you use the @code{step} command while control is
3658within a function that was compiled without debugging information,
3659execution proceeds until control reaches a function that does have
3660debugging information. Likewise, it will not step into a function which
3661is compiled without debugging information. To step through functions
3662without debugging information, use the @code{stepi} command, described
3663below.
3664@end quotation
3665
4a92d011
EZ
3666The @code{step} command only stops at the first instruction of a source
3667line. This prevents the multiple stops that could otherwise occur in
3668@code{switch} statements, @code{for} loops, etc. @code{step} continues
3669to stop if a function that has debugging information is called within
3670the line. In other words, @code{step} @emph{steps inside} any functions
3671called within the line.
c906108c 3672
d4f3574e
SS
3673Also, the @code{step} command only enters a function if there is line
3674number information for the function. Otherwise it acts like the
5d161b24 3675@code{next} command. This avoids problems when using @code{cc -gl}
c906108c 3676on MIPS machines. Previously, @code{step} entered subroutines if there
5d161b24 3677was any debugging information about the routine.
c906108c
SS
3678
3679@item step @var{count}
3680Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
3681breakpoint is reached, or a signal not related to stepping occurs before
3682@var{count} steps, stepping stops right away.
c906108c
SS
3683
3684@kindex next
41afff9a 3685@kindex n @r{(@code{next})}
c906108c
SS
3686@item next @r{[}@var{count}@r{]}
3687Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
3688This is similar to @code{step}, but function calls that appear within
3689the line of code are executed without stopping. Execution stops when
3690control reaches a different line of code at the original stack level
3691that was executing when you gave the @code{next} command. This command
3692is abbreviated @code{n}.
c906108c
SS
3693
3694An argument @var{count} is a repeat count, as for @code{step}.
3695
3696
3697@c FIX ME!! Do we delete this, or is there a way it fits in with
3698@c the following paragraph? --- Vctoria
3699@c
3700@c @code{next} within a function that lacks debugging information acts like
3701@c @code{step}, but any function calls appearing within the code of the
3702@c function are executed without stopping.
3703
d4f3574e
SS
3704The @code{next} command only stops at the first instruction of a
3705source line. This prevents multiple stops that could otherwise occur in
4a92d011 3706@code{switch} statements, @code{for} loops, etc.
c906108c 3707
b90a5f51
CF
3708@kindex set step-mode
3709@item set step-mode
3710@cindex functions without line info, and stepping
3711@cindex stepping into functions with no line info
3712@itemx set step-mode on
4a92d011 3713The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
3714stop at the first instruction of a function which contains no debug line
3715information rather than stepping over it.
3716
4a92d011
EZ
3717This is useful in cases where you may be interested in inspecting the
3718machine instructions of a function which has no symbolic info and do not
3719want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
3720
3721@item set step-mode off
4a92d011 3722Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
3723debug information. This is the default.
3724
9c16f35a
EZ
3725@item show step-mode
3726Show whether @value{GDBN} will stop in or step over functions without
3727source line debug information.
3728
c906108c
SS
3729@kindex finish
3730@item finish
3731Continue running until just after function in the selected stack frame
3732returns. Print the returned value (if any).
3733
3734Contrast this with the @code{return} command (@pxref{Returning,
3735,Returning from a function}).
3736
3737@kindex until
41afff9a 3738@kindex u @r{(@code{until})}
09d4efe1 3739@cindex run until specified location
c906108c
SS
3740@item until
3741@itemx u
3742Continue running until a source line past the current line, in the
3743current stack frame, is reached. This command is used to avoid single
3744stepping through a loop more than once. It is like the @code{next}
3745command, except that when @code{until} encounters a jump, it
3746automatically continues execution until the program counter is greater
3747than the address of the jump.
3748
3749This means that when you reach the end of a loop after single stepping
3750though it, @code{until} makes your program continue execution until it
3751exits the loop. In contrast, a @code{next} command at the end of a loop
3752simply steps back to the beginning of the loop, which forces you to step
3753through the next iteration.
3754
3755@code{until} always stops your program if it attempts to exit the current
3756stack frame.
3757
3758@code{until} may produce somewhat counterintuitive results if the order
3759of machine code does not match the order of the source lines. For
3760example, in the following excerpt from a debugging session, the @code{f}
3761(@code{frame}) command shows that execution is stopped at line
3762@code{206}; yet when we use @code{until}, we get to line @code{195}:
3763
474c8240 3764@smallexample
c906108c
SS
3765(@value{GDBP}) f
3766#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
3767206 expand_input();
3768(@value{GDBP}) until
3769195 for ( ; argc > 0; NEXTARG) @{
474c8240 3770@end smallexample
c906108c
SS
3771
3772This happened because, for execution efficiency, the compiler had
3773generated code for the loop closure test at the end, rather than the
3774start, of the loop---even though the test in a C @code{for}-loop is
3775written before the body of the loop. The @code{until} command appeared
3776to step back to the beginning of the loop when it advanced to this
3777expression; however, it has not really gone to an earlier
3778statement---not in terms of the actual machine code.
3779
3780@code{until} with no argument works by means of single
3781instruction stepping, and hence is slower than @code{until} with an
3782argument.
3783
3784@item until @var{location}
3785@itemx u @var{location}
3786Continue running your program until either the specified location is
3787reached, or the current stack frame returns. @var{location} is any of
3788the forms of argument acceptable to @code{break} (@pxref{Set Breaks,
c60eb6f1
EZ
3789,Setting breakpoints}). This form of the command uses breakpoints, and
3790hence is quicker than @code{until} without an argument. The specified
3791location is actually reached only if it is in the current frame. This
3792implies that @code{until} can be used to skip over recursive function
3793invocations. For instance in the code below, if the current location is
3794line @code{96}, issuing @code{until 99} will execute the program up to
3795line @code{99} in the same invocation of factorial, i.e. after the inner
3796invocations have returned.
3797
3798@smallexample
379994 int factorial (int value)
380095 @{
380196 if (value > 1) @{
380297 value *= factorial (value - 1);
380398 @}
380499 return (value);
3805100 @}
3806@end smallexample
3807
3808
3809@kindex advance @var{location}
3810@itemx advance @var{location}
09d4efe1
EZ
3811Continue running the program up to the given @var{location}. An argument is
3812required, which should be of the same form as arguments for the @code{break}
c60eb6f1
EZ
3813command. Execution will also stop upon exit from the current stack
3814frame. This command is similar to @code{until}, but @code{advance} will
3815not skip over recursive function calls, and the target location doesn't
3816have to be in the same frame as the current one.
3817
c906108c
SS
3818
3819@kindex stepi
41afff9a 3820@kindex si @r{(@code{stepi})}
c906108c 3821@item stepi
96a2c332 3822@itemx stepi @var{arg}
c906108c
SS
3823@itemx si
3824Execute one machine instruction, then stop and return to the debugger.
3825
3826It is often useful to do @samp{display/i $pc} when stepping by machine
3827instructions. This makes @value{GDBN} automatically display the next
3828instruction to be executed, each time your program stops. @xref{Auto
3829Display,, Automatic display}.
3830
3831An argument is a repeat count, as in @code{step}.
3832
3833@need 750
3834@kindex nexti
41afff9a 3835@kindex ni @r{(@code{nexti})}
c906108c 3836@item nexti
96a2c332 3837@itemx nexti @var{arg}
c906108c
SS
3838@itemx ni
3839Execute one machine instruction, but if it is a function call,
3840proceed until the function returns.
3841
3842An argument is a repeat count, as in @code{next}.
3843@end table
3844
6d2ebf8b 3845@node Signals
c906108c
SS
3846@section Signals
3847@cindex signals
3848
3849A signal is an asynchronous event that can happen in a program. The
3850operating system defines the possible kinds of signals, and gives each
3851kind a name and a number. For example, in Unix @code{SIGINT} is the
d4f3574e 3852signal a program gets when you type an interrupt character (often @kbd{C-c});
c906108c
SS
3853@code{SIGSEGV} is the signal a program gets from referencing a place in
3854memory far away from all the areas in use; @code{SIGALRM} occurs when
3855the alarm clock timer goes off (which happens only if your program has
3856requested an alarm).
3857
3858@cindex fatal signals
3859Some signals, including @code{SIGALRM}, are a normal part of the
3860functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 3861errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
3862program has not specified in advance some other way to handle the signal.
3863@code{SIGINT} does not indicate an error in your program, but it is normally
3864fatal so it can carry out the purpose of the interrupt: to kill the program.
3865
3866@value{GDBN} has the ability to detect any occurrence of a signal in your
3867program. You can tell @value{GDBN} in advance what to do for each kind of
3868signal.
3869
3870@cindex handling signals
24f93129
EZ
3871Normally, @value{GDBN} is set up to let the non-erroneous signals like
3872@code{SIGALRM} be silently passed to your program
3873(so as not to interfere with their role in the program's functioning)
c906108c
SS
3874but to stop your program immediately whenever an error signal happens.
3875You can change these settings with the @code{handle} command.
3876
3877@table @code
3878@kindex info signals
09d4efe1 3879@kindex info handle
c906108c 3880@item info signals
96a2c332 3881@itemx info handle
c906108c
SS
3882Print a table of all the kinds of signals and how @value{GDBN} has been told to
3883handle each one. You can use this to see the signal numbers of all
3884the defined types of signals.
3885
d4f3574e 3886@code{info handle} is an alias for @code{info signals}.
c906108c
SS
3887
3888@kindex handle
3889@item handle @var{signal} @var{keywords}@dots{}
5ece1a18
EZ
3890Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
3891can be the number of a signal or its name (with or without the
24f93129 3892@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18
EZ
3893@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
3894known signals. The @var{keywords} say what change to make.
c906108c
SS
3895@end table
3896
3897@c @group
3898The keywords allowed by the @code{handle} command can be abbreviated.
3899Their full names are:
3900
3901@table @code
3902@item nostop
3903@value{GDBN} should not stop your program when this signal happens. It may
3904still print a message telling you that the signal has come in.
3905
3906@item stop
3907@value{GDBN} should stop your program when this signal happens. This implies
3908the @code{print} keyword as well.
3909
3910@item print
3911@value{GDBN} should print a message when this signal happens.
3912
3913@item noprint
3914@value{GDBN} should not mention the occurrence of the signal at all. This
3915implies the @code{nostop} keyword as well.
3916
3917@item pass
5ece1a18 3918@itemx noignore
c906108c
SS
3919@value{GDBN} should allow your program to see this signal; your program
3920can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 3921and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
3922
3923@item nopass
5ece1a18 3924@itemx ignore
c906108c 3925@value{GDBN} should not allow your program to see this signal.
5ece1a18 3926@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
3927@end table
3928@c @end group
3929
d4f3574e
SS
3930When a signal stops your program, the signal is not visible to the
3931program until you
c906108c
SS
3932continue. Your program sees the signal then, if @code{pass} is in
3933effect for the signal in question @emph{at that time}. In other words,
3934after @value{GDBN} reports a signal, you can use the @code{handle}
3935command with @code{pass} or @code{nopass} to control whether your
3936program sees that signal when you continue.
3937
24f93129
EZ
3938The default is set to @code{nostop}, @code{noprint}, @code{pass} for
3939non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
3940@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
3941erroneous signals.
3942
c906108c
SS
3943You can also use the @code{signal} command to prevent your program from
3944seeing a signal, or cause it to see a signal it normally would not see,
3945or to give it any signal at any time. For example, if your program stopped
3946due to some sort of memory reference error, you might store correct
3947values into the erroneous variables and continue, hoping to see more
3948execution; but your program would probably terminate immediately as
3949a result of the fatal signal once it saw the signal. To prevent this,
3950you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5d161b24 3951program a signal}.
c906108c 3952
6d2ebf8b 3953@node Thread Stops
c906108c
SS
3954@section Stopping and starting multi-thread programs
3955
3956When your program has multiple threads (@pxref{Threads,, Debugging
3957programs with multiple threads}), you can choose whether to set
3958breakpoints on all threads, or on a particular thread.
3959
3960@table @code
3961@cindex breakpoints and threads
3962@cindex thread breakpoints
3963@kindex break @dots{} thread @var{threadno}
3964@item break @var{linespec} thread @var{threadno}
3965@itemx break @var{linespec} thread @var{threadno} if @dots{}
3966@var{linespec} specifies source lines; there are several ways of
3967writing them, but the effect is always to specify some source line.
3968
3969Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
3970to specify that you only want @value{GDBN} to stop the program when a
3971particular thread reaches this breakpoint. @var{threadno} is one of the
3972numeric thread identifiers assigned by @value{GDBN}, shown in the first
3973column of the @samp{info threads} display.
3974
3975If you do not specify @samp{thread @var{threadno}} when you set a
3976breakpoint, the breakpoint applies to @emph{all} threads of your
3977program.
3978
3979You can use the @code{thread} qualifier on conditional breakpoints as
3980well; in this case, place @samp{thread @var{threadno}} before the
3981breakpoint condition, like this:
3982
3983@smallexample
2df3850c 3984(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
3985@end smallexample
3986
3987@end table
3988
3989@cindex stopped threads
3990@cindex threads, stopped
3991Whenever your program stops under @value{GDBN} for any reason,
3992@emph{all} threads of execution stop, not just the current thread. This
3993allows you to examine the overall state of the program, including
3994switching between threads, without worrying that things may change
3995underfoot.
3996
36d86913
MC
3997@cindex thread breakpoints and system calls
3998@cindex system calls and thread breakpoints
3999@cindex premature return from system calls
4000There is an unfortunate side effect. If one thread stops for a
4001breakpoint, or for some other reason, and another thread is blocked in a
4002system call, then the system call may return prematurely. This is a
4003consequence of the interaction between multiple threads and the signals
4004that @value{GDBN} uses to implement breakpoints and other events that
4005stop execution.
4006
4007To handle this problem, your program should check the return value of
4008each system call and react appropriately. This is good programming
4009style anyways.
4010
4011For example, do not write code like this:
4012
4013@smallexample
4014 sleep (10);
4015@end smallexample
4016
4017The call to @code{sleep} will return early if a different thread stops
4018at a breakpoint or for some other reason.
4019
4020Instead, write this:
4021
4022@smallexample
4023 int unslept = 10;
4024 while (unslept > 0)
4025 unslept = sleep (unslept);
4026@end smallexample
4027
4028A system call is allowed to return early, so the system is still
4029conforming to its specification. But @value{GDBN} does cause your
4030multi-threaded program to behave differently than it would without
4031@value{GDBN}.
4032
4033Also, @value{GDBN} uses internal breakpoints in the thread library to
4034monitor certain events such as thread creation and thread destruction.
4035When such an event happens, a system call in another thread may return
4036prematurely, even though your program does not appear to stop.
4037
c906108c
SS
4038@cindex continuing threads
4039@cindex threads, continuing
4040Conversely, whenever you restart the program, @emph{all} threads start
4041executing. @emph{This is true even when single-stepping} with commands
5d161b24 4042like @code{step} or @code{next}.
c906108c
SS
4043
4044In particular, @value{GDBN} cannot single-step all threads in lockstep.
4045Since thread scheduling is up to your debugging target's operating
4046system (not controlled by @value{GDBN}), other threads may
4047execute more than one statement while the current thread completes a
4048single step. Moreover, in general other threads stop in the middle of a
4049statement, rather than at a clean statement boundary, when the program
4050stops.
4051
4052You might even find your program stopped in another thread after
4053continuing or even single-stepping. This happens whenever some other
4054thread runs into a breakpoint, a signal, or an exception before the
4055first thread completes whatever you requested.
4056
4057On some OSes, you can lock the OS scheduler and thus allow only a single
4058thread to run.
4059
4060@table @code
4061@item set scheduler-locking @var{mode}
9c16f35a
EZ
4062@cindex scheduler locking mode
4063@cindex lock scheduler
c906108c
SS
4064Set the scheduler locking mode. If it is @code{off}, then there is no
4065locking and any thread may run at any time. If @code{on}, then only the
4066current thread may run when the inferior is resumed. The @code{step}
4067mode optimizes for single-stepping. It stops other threads from
4068``seizing the prompt'' by preempting the current thread while you are
4069stepping. Other threads will only rarely (or never) get a chance to run
d4f3574e 4070when you step. They are more likely to run when you @samp{next} over a
c906108c 4071function call, and they are completely free to run when you use commands
d4f3574e 4072like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
c906108c 4073thread hits a breakpoint during its timeslice, they will never steal the
2df3850c 4074@value{GDBN} prompt away from the thread that you are debugging.
c906108c
SS
4075
4076@item show scheduler-locking
4077Display the current scheduler locking mode.
4078@end table
4079
c906108c 4080
6d2ebf8b 4081@node Stack
c906108c
SS
4082@chapter Examining the Stack
4083
4084When your program has stopped, the first thing you need to know is where it
4085stopped and how it got there.
4086
4087@cindex call stack
5d161b24
DB
4088Each time your program performs a function call, information about the call
4089is generated.
4090That information includes the location of the call in your program,
4091the arguments of the call,
c906108c 4092and the local variables of the function being called.
5d161b24 4093The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
4094The stack frames are allocated in a region of memory called the @dfn{call
4095stack}.
4096
4097When your program stops, the @value{GDBN} commands for examining the
4098stack allow you to see all of this information.
4099
4100@cindex selected frame
4101One of the stack frames is @dfn{selected} by @value{GDBN} and many
4102@value{GDBN} commands refer implicitly to the selected frame. In
4103particular, whenever you ask @value{GDBN} for the value of a variable in
4104your program, the value is found in the selected frame. There are
4105special @value{GDBN} commands to select whichever frame you are
4106interested in. @xref{Selection, ,Selecting a frame}.
4107
4108When your program stops, @value{GDBN} automatically selects the
5d161b24 4109currently executing frame and describes it briefly, similar to the
c906108c
SS
4110@code{frame} command (@pxref{Frame Info, ,Information about a frame}).
4111
4112@menu
4113* Frames:: Stack frames
4114* Backtrace:: Backtraces
4115* Selection:: Selecting a frame
4116* Frame Info:: Information on a frame
c906108c
SS
4117
4118@end menu
4119
6d2ebf8b 4120@node Frames
c906108c
SS
4121@section Stack frames
4122
d4f3574e 4123@cindex frame, definition
c906108c
SS
4124@cindex stack frame
4125The call stack is divided up into contiguous pieces called @dfn{stack
4126frames}, or @dfn{frames} for short; each frame is the data associated
4127with one call to one function. The frame contains the arguments given
4128to the function, the function's local variables, and the address at
4129which the function is executing.
4130
4131@cindex initial frame
4132@cindex outermost frame
4133@cindex innermost frame
4134When your program is started, the stack has only one frame, that of the
4135function @code{main}. This is called the @dfn{initial} frame or the
4136@dfn{outermost} frame. Each time a function is called, a new frame is
4137made. Each time a function returns, the frame for that function invocation
4138is eliminated. If a function is recursive, there can be many frames for
4139the same function. The frame for the function in which execution is
4140actually occurring is called the @dfn{innermost} frame. This is the most
4141recently created of all the stack frames that still exist.
4142
4143@cindex frame pointer
4144Inside your program, stack frames are identified by their addresses. A
4145stack frame consists of many bytes, each of which has its own address; each
4146kind of computer has a convention for choosing one byte whose
4147address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
4148in a register called the @dfn{frame pointer register}
4149(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
4150
4151@cindex frame number
4152@value{GDBN} assigns numbers to all existing stack frames, starting with
4153zero for the innermost frame, one for the frame that called it,
4154and so on upward. These numbers do not really exist in your program;
4155they are assigned by @value{GDBN} to give you a way of designating stack
4156frames in @value{GDBN} commands.
4157
6d2ebf8b
SS
4158@c The -fomit-frame-pointer below perennially causes hbox overflow
4159@c underflow problems.
c906108c
SS
4160@cindex frameless execution
4161Some compilers provide a way to compile functions so that they operate
6d2ebf8b 4162without stack frames. (For example, the @value{GCC} option
474c8240 4163@smallexample
6d2ebf8b 4164@samp{-fomit-frame-pointer}
474c8240 4165@end smallexample
6d2ebf8b 4166generates functions without a frame.)
c906108c
SS
4167This is occasionally done with heavily used library functions to save
4168the frame setup time. @value{GDBN} has limited facilities for dealing
4169with these function invocations. If the innermost function invocation
4170has no stack frame, @value{GDBN} nevertheless regards it as though
4171it had a separate frame, which is numbered zero as usual, allowing
4172correct tracing of the function call chain. However, @value{GDBN} has
4173no provision for frameless functions elsewhere in the stack.
4174
4175@table @code
d4f3574e 4176@kindex frame@r{, command}
41afff9a 4177@cindex current stack frame
c906108c 4178@item frame @var{args}
5d161b24 4179The @code{frame} command allows you to move from one stack frame to another,
c906108c 4180and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
4181address of the frame or the stack frame number. Without an argument,
4182@code{frame} prints the current stack frame.
c906108c
SS
4183
4184@kindex select-frame
41afff9a 4185@cindex selecting frame silently
c906108c
SS
4186@item select-frame
4187The @code{select-frame} command allows you to move from one stack frame
4188to another without printing the frame. This is the silent version of
4189@code{frame}.
4190@end table
4191
6d2ebf8b 4192@node Backtrace
c906108c
SS
4193@section Backtraces
4194
09d4efe1
EZ
4195@cindex traceback
4196@cindex call stack traces
c906108c
SS
4197A backtrace is a summary of how your program got where it is. It shows one
4198line per frame, for many frames, starting with the currently executing
4199frame (frame zero), followed by its caller (frame one), and on up the
4200stack.
4201
4202@table @code
4203@kindex backtrace
41afff9a 4204@kindex bt @r{(@code{backtrace})}
c906108c
SS
4205@item backtrace
4206@itemx bt
4207Print a backtrace of the entire stack: one line per frame for all
4208frames in the stack.
4209
4210You can stop the backtrace at any time by typing the system interrupt
4211character, normally @kbd{C-c}.
4212
4213@item backtrace @var{n}
4214@itemx bt @var{n}
4215Similar, but print only the innermost @var{n} frames.
4216
4217@item backtrace -@var{n}
4218@itemx bt -@var{n}
4219Similar, but print only the outermost @var{n} frames.
0f061b69
NR
4220
4221@item backtrace full
4222Print the values of the local variables also.
4223@itemx bt full
c906108c
SS
4224@end table
4225
4226@kindex where
4227@kindex info stack
c906108c
SS
4228The names @code{where} and @code{info stack} (abbreviated @code{info s})
4229are additional aliases for @code{backtrace}.
4230
4231Each line in the backtrace shows the frame number and the function name.
4232The program counter value is also shown---unless you use @code{set
4233print address off}. The backtrace also shows the source file name and
4234line number, as well as the arguments to the function. The program
4235counter value is omitted if it is at the beginning of the code for that
4236line number.
4237
4238Here is an example of a backtrace. It was made with the command
4239@samp{bt 3}, so it shows the innermost three frames.
4240
4241@smallexample
4242@group
5d161b24 4243#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c
SS
4244 at builtin.c:993
4245#1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4246#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4247 at macro.c:71
4248(More stack frames follow...)
4249@end group
4250@end smallexample
4251
4252@noindent
4253The display for frame zero does not begin with a program counter
4254value, indicating that your program has stopped at the beginning of the
4255code for line @code{993} of @code{builtin.c}.
4256
18999be5
EZ
4257@cindex value optimized out, in backtrace
4258@cindex function call arguments, optimized out
4259If your program was compiled with optimizations, some compilers will
4260optimize away arguments passed to functions if those arguments are
4261never used after the call. Such optimizations generate code that
4262passes arguments through registers, but doesn't store those arguments
4263in the stack frame. @value{GDBN} has no way of displaying such
4264arguments in stack frames other than the innermost one. Here's what
4265such a backtrace might look like:
4266
4267@smallexample
4268@group
4269#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4270 at builtin.c:993
4271#1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4272#2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4273 at macro.c:71
4274(More stack frames follow...)
4275@end group
4276@end smallexample
4277
4278@noindent
4279The values of arguments that were not saved in their stack frames are
4280shown as @samp{<value optimized out>}.
4281
4282If you need to display the values of such optimized-out arguments,
4283either deduce that from other variables whose values depend on the one
4284you are interested in, or recompile without optimizations.
4285
a8f24a35
EZ
4286@cindex backtrace beyond @code{main} function
4287@cindex program entry point
4288@cindex startup code, and backtrace
25d29d70
AC
4289Most programs have a standard user entry point---a place where system
4290libraries and startup code transition into user code. For C this is
d416eeec
EZ
4291@code{main}@footnote{
4292Note that embedded programs (the so-called ``free-standing''
4293environment) are not required to have a @code{main} function as the
4294entry point. They could even have multiple entry points.}.
4295When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
4296it will terminate the backtrace, to avoid tracing into highly
4297system-specific (and generally uninteresting) code.
4298
4299If you need to examine the startup code, or limit the number of levels
4300in a backtrace, you can change this behavior:
95f90d25
DJ
4301
4302@table @code
25d29d70
AC
4303@item set backtrace past-main
4304@itemx set backtrace past-main on
4644b6e3 4305@kindex set backtrace
25d29d70
AC
4306Backtraces will continue past the user entry point.
4307
4308@item set backtrace past-main off
95f90d25
DJ
4309Backtraces will stop when they encounter the user entry point. This is the
4310default.
4311
25d29d70 4312@item show backtrace past-main
4644b6e3 4313@kindex show backtrace
25d29d70
AC
4314Display the current user entry point backtrace policy.
4315
2315ffec
RC
4316@item set backtrace past-entry
4317@itemx set backtrace past-entry on
a8f24a35 4318Backtraces will continue past the internal entry point of an application.
2315ffec
RC
4319This entry point is encoded by the linker when the application is built,
4320and is likely before the user entry point @code{main} (or equivalent) is called.
4321
4322@item set backtrace past-entry off
4323Backtraces will stop when they encouter the internal entry point of an
4324application. This is the default.
4325
4326@item show backtrace past-entry
4327Display the current internal entry point backtrace policy.
4328
25d29d70
AC
4329@item set backtrace limit @var{n}
4330@itemx set backtrace limit 0
4331@cindex backtrace limit
4332Limit the backtrace to @var{n} levels. A value of zero means
4333unlimited.
95f90d25 4334
25d29d70
AC
4335@item show backtrace limit
4336Display the current limit on backtrace levels.
95f90d25
DJ
4337@end table
4338
6d2ebf8b 4339@node Selection
c906108c
SS
4340@section Selecting a frame
4341
4342Most commands for examining the stack and other data in your program work on
4343whichever stack frame is selected at the moment. Here are the commands for
4344selecting a stack frame; all of them finish by printing a brief description
4345of the stack frame just selected.
4346
4347@table @code
d4f3574e 4348@kindex frame@r{, selecting}
41afff9a 4349@kindex f @r{(@code{frame})}
c906108c
SS
4350@item frame @var{n}
4351@itemx f @var{n}
4352Select frame number @var{n}. Recall that frame zero is the innermost
4353(currently executing) frame, frame one is the frame that called the
4354innermost one, and so on. The highest-numbered frame is the one for
4355@code{main}.
4356
4357@item frame @var{addr}
4358@itemx f @var{addr}
4359Select the frame at address @var{addr}. This is useful mainly if the
4360chaining of stack frames has been damaged by a bug, making it
4361impossible for @value{GDBN} to assign numbers properly to all frames. In
4362addition, this can be useful when your program has multiple stacks and
4363switches between them.
4364
c906108c
SS
4365On the SPARC architecture, @code{frame} needs two addresses to
4366select an arbitrary frame: a frame pointer and a stack pointer.
4367
4368On the MIPS and Alpha architecture, it needs two addresses: a stack
4369pointer and a program counter.
4370
4371On the 29k architecture, it needs three addresses: a register stack
4372pointer, a program counter, and a memory stack pointer.
c906108c
SS
4373
4374@kindex up
4375@item up @var{n}
4376Move @var{n} frames up the stack. For positive numbers @var{n}, this
4377advances toward the outermost frame, to higher frame numbers, to frames
4378that have existed longer. @var{n} defaults to one.
4379
4380@kindex down
41afff9a 4381@kindex do @r{(@code{down})}
c906108c
SS
4382@item down @var{n}
4383Move @var{n} frames down the stack. For positive numbers @var{n}, this
4384advances toward the innermost frame, to lower frame numbers, to frames
4385that were created more recently. @var{n} defaults to one. You may
4386abbreviate @code{down} as @code{do}.
4387@end table
4388
4389All of these commands end by printing two lines of output describing the
4390frame. The first line shows the frame number, the function name, the
4391arguments, and the source file and line number of execution in that
5d161b24 4392frame. The second line shows the text of that source line.
c906108c
SS
4393
4394@need 1000
4395For example:
4396
4397@smallexample
4398@group
4399(@value{GDBP}) up
4400#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4401 at env.c:10
440210 read_input_file (argv[i]);
4403@end group
4404@end smallexample
4405
4406After such a printout, the @code{list} command with no arguments
4407prints ten lines centered on the point of execution in the frame.
87885426
FN
4408You can also edit the program at the point of execution with your favorite
4409editing program by typing @code{edit}.
4410@xref{List, ,Printing source lines},
4411for details.
c906108c
SS
4412
4413@table @code
4414@kindex down-silently
4415@kindex up-silently
4416@item up-silently @var{n}
4417@itemx down-silently @var{n}
4418These two commands are variants of @code{up} and @code{down},
4419respectively; they differ in that they do their work silently, without
4420causing display of the new frame. They are intended primarily for use
4421in @value{GDBN} command scripts, where the output might be unnecessary and
4422distracting.
4423@end table
4424
6d2ebf8b 4425@node Frame Info
c906108c
SS
4426@section Information about a frame
4427
4428There are several other commands to print information about the selected
4429stack frame.
4430
4431@table @code
4432@item frame
4433@itemx f
4434When used without any argument, this command does not change which
4435frame is selected, but prints a brief description of the currently
4436selected stack frame. It can be abbreviated @code{f}. With an
4437argument, this command is used to select a stack frame.
4438@xref{Selection, ,Selecting a frame}.
4439
4440@kindex info frame
41afff9a 4441@kindex info f @r{(@code{info frame})}
c906108c
SS
4442@item info frame
4443@itemx info f
4444This command prints a verbose description of the selected stack frame,
4445including:
4446
4447@itemize @bullet
5d161b24
DB
4448@item
4449the address of the frame
c906108c
SS
4450@item
4451the address of the next frame down (called by this frame)
4452@item
4453the address of the next frame up (caller of this frame)
4454@item
4455the language in which the source code corresponding to this frame is written
4456@item
4457the address of the frame's arguments
4458@item
d4f3574e
SS
4459the address of the frame's local variables
4460@item
c906108c
SS
4461the program counter saved in it (the address of execution in the caller frame)
4462@item
4463which registers were saved in the frame
4464@end itemize
4465
4466@noindent The verbose description is useful when
4467something has gone wrong that has made the stack format fail to fit
4468the usual conventions.
4469
4470@item info frame @var{addr}
4471@itemx info f @var{addr}
4472Print a verbose description of the frame at address @var{addr}, without
4473selecting that frame. The selected frame remains unchanged by this
4474command. This requires the same kind of address (more than one for some
4475architectures) that you specify in the @code{frame} command.
4476@xref{Selection, ,Selecting a frame}.
4477
4478@kindex info args
4479@item info args
4480Print the arguments of the selected frame, each on a separate line.
4481
4482@item info locals
4483@kindex info locals
4484Print the local variables of the selected frame, each on a separate
4485line. These are all variables (declared either static or automatic)
4486accessible at the point of execution of the selected frame.
4487
c906108c 4488@kindex info catch
d4f3574e
SS
4489@cindex catch exceptions, list active handlers
4490@cindex exception handlers, how to list
c906108c
SS
4491@item info catch
4492Print a list of all the exception handlers that are active in the
4493current stack frame at the current point of execution. To see other
4494exception handlers, visit the associated frame (using the @code{up},
4495@code{down}, or @code{frame} commands); then type @code{info catch}.
4496@xref{Set Catchpoints, , Setting catchpoints}.
53a5351d 4497
c906108c
SS
4498@end table
4499
c906108c 4500
6d2ebf8b 4501@node Source
c906108c
SS
4502@chapter Examining Source Files
4503
4504@value{GDBN} can print parts of your program's source, since the debugging
4505information recorded in the program tells @value{GDBN} what source files were
4506used to build it. When your program stops, @value{GDBN} spontaneously prints
4507the line where it stopped. Likewise, when you select a stack frame
4508(@pxref{Selection, ,Selecting a frame}), @value{GDBN} prints the line where
4509execution in that frame has stopped. You can print other portions of
4510source files by explicit command.
4511
7a292a7a 4512If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 4513prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 4514@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
4515
4516@menu
4517* List:: Printing source lines
87885426 4518* Edit:: Editing source files
c906108c 4519* Search:: Searching source files
c906108c
SS
4520* Source Path:: Specifying source directories
4521* Machine Code:: Source and machine code
4522@end menu
4523
6d2ebf8b 4524@node List
c906108c
SS
4525@section Printing source lines
4526
4527@kindex list
41afff9a 4528@kindex l @r{(@code{list})}
c906108c 4529To print lines from a source file, use the @code{list} command
5d161b24 4530(abbreviated @code{l}). By default, ten lines are printed.
c906108c
SS
4531There are several ways to specify what part of the file you want to print.
4532
4533Here are the forms of the @code{list} command most commonly used:
4534
4535@table @code
4536@item list @var{linenum}
4537Print lines centered around line number @var{linenum} in the
4538current source file.
4539
4540@item list @var{function}
4541Print lines centered around the beginning of function
4542@var{function}.
4543
4544@item list
4545Print more lines. If the last lines printed were printed with a
4546@code{list} command, this prints lines following the last lines
4547printed; however, if the last line printed was a solitary line printed
4548as part of displaying a stack frame (@pxref{Stack, ,Examining the
4549Stack}), this prints lines centered around that line.
4550
4551@item list -
4552Print lines just before the lines last printed.
4553@end table
4554
9c16f35a 4555@cindex @code{list}, how many lines to display
c906108c
SS
4556By default, @value{GDBN} prints ten source lines with any of these forms of
4557the @code{list} command. You can change this using @code{set listsize}:
4558
4559@table @code
4560@kindex set listsize
4561@item set listsize @var{count}
4562Make the @code{list} command display @var{count} source lines (unless
4563the @code{list} argument explicitly specifies some other number).
4564
4565@kindex show listsize
4566@item show listsize
4567Display the number of lines that @code{list} prints.
4568@end table
4569
4570Repeating a @code{list} command with @key{RET} discards the argument,
4571so it is equivalent to typing just @code{list}. This is more useful
4572than listing the same lines again. An exception is made for an
4573argument of @samp{-}; that argument is preserved in repetition so that
4574each repetition moves up in the source file.
4575
4576@cindex linespec
4577In general, the @code{list} command expects you to supply zero, one or two
4578@dfn{linespecs}. Linespecs specify source lines; there are several ways
d4f3574e 4579of writing them, but the effect is always to specify some source line.
c906108c
SS
4580Here is a complete description of the possible arguments for @code{list}:
4581
4582@table @code
4583@item list @var{linespec}
4584Print lines centered around the line specified by @var{linespec}.
4585
4586@item list @var{first},@var{last}
4587Print lines from @var{first} to @var{last}. Both arguments are
4588linespecs.
4589
4590@item list ,@var{last}
4591Print lines ending with @var{last}.
4592
4593@item list @var{first},
4594Print lines starting with @var{first}.
4595
4596@item list +
4597Print lines just after the lines last printed.
4598
4599@item list -
4600Print lines just before the lines last printed.
4601
4602@item list
4603As described in the preceding table.
4604@end table
4605
4606Here are the ways of specifying a single source line---all the
4607kinds of linespec.
4608
4609@table @code
4610@item @var{number}
4611Specifies line @var{number} of the current source file.
4612When a @code{list} command has two linespecs, this refers to
4613the same source file as the first linespec.
4614
4615@item +@var{offset}
4616Specifies the line @var{offset} lines after the last line printed.
4617When used as the second linespec in a @code{list} command that has
4618two, this specifies the line @var{offset} lines down from the
4619first linespec.
4620
4621@item -@var{offset}
4622Specifies the line @var{offset} lines before the last line printed.
4623
4624@item @var{filename}:@var{number}
4625Specifies line @var{number} in the source file @var{filename}.
4626
4627@item @var{function}
4628Specifies the line that begins the body of the function @var{function}.
4629For example: in C, this is the line with the open brace.
4630
4631@item @var{filename}:@var{function}
4632Specifies the line of the open-brace that begins the body of the
4633function @var{function} in the file @var{filename}. You only need the
4634file name with a function name to avoid ambiguity when there are
4635identically named functions in different source files.
4636
4637@item *@var{address}
4638Specifies the line containing the program address @var{address}.
4639@var{address} may be any expression.
4640@end table
4641
87885426
FN
4642@node Edit
4643@section Editing source files
4644@cindex editing source files
4645
4646@kindex edit
4647@kindex e @r{(@code{edit})}
4648To edit the lines in a source file, use the @code{edit} command.
4649The editing program of your choice
4650is invoked with the current line set to
4651the active line in the program.
4652Alternatively, there are several ways to specify what part of the file you
4653want to print if you want to see other parts of the program.
4654
4655Here are the forms of the @code{edit} command most commonly used:
4656
4657@table @code
4658@item edit
4659Edit the current source file at the active line number in the program.
4660
4661@item edit @var{number}
4662Edit the current source file with @var{number} as the active line number.
4663
4664@item edit @var{function}
4665Edit the file containing @var{function} at the beginning of its definition.
4666
4667@item edit @var{filename}:@var{number}
4668Specifies line @var{number} in the source file @var{filename}.
4669
4670@item edit @var{filename}:@var{function}
4671Specifies the line that begins the body of the
4672function @var{function} in the file @var{filename}. You only need the
4673file name with a function name to avoid ambiguity when there are
4674identically named functions in different source files.
4675
4676@item edit *@var{address}
4677Specifies the line containing the program address @var{address}.
4678@var{address} may be any expression.
4679@end table
4680
4681@subsection Choosing your editor
4682You can customize @value{GDBN} to use any editor you want
4683@footnote{
4684The only restriction is that your editor (say @code{ex}), recognizes the
4685following command-line syntax:
10998722 4686@smallexample
87885426 4687ex +@var{number} file
10998722 4688@end smallexample
15387254
EZ
4689The optional numeric value +@var{number} specifies the number of the line in
4690the file where to start editing.}.
4691By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
4692by setting the environment variable @code{EDITOR} before using
4693@value{GDBN}. For example, to configure @value{GDBN} to use the
4694@code{vi} editor, you could use these commands with the @code{sh} shell:
4695@smallexample
87885426
FN
4696EDITOR=/usr/bin/vi
4697export EDITOR
15387254 4698gdb @dots{}
10998722 4699@end smallexample
87885426 4700or in the @code{csh} shell,
10998722 4701@smallexample
87885426 4702setenv EDITOR /usr/bin/vi
15387254 4703gdb @dots{}
10998722 4704@end smallexample
87885426 4705
6d2ebf8b 4706@node Search
c906108c 4707@section Searching source files
15387254 4708@cindex searching source files
c906108c
SS
4709
4710There are two commands for searching through the current source file for a
4711regular expression.
4712
4713@table @code
4714@kindex search
4715@kindex forward-search
4716@item forward-search @var{regexp}
4717@itemx search @var{regexp}
4718The command @samp{forward-search @var{regexp}} checks each line,
4719starting with the one following the last line listed, for a match for
5d161b24 4720@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
4721synonym @samp{search @var{regexp}} or abbreviate the command name as
4722@code{fo}.
4723
09d4efe1 4724@kindex reverse-search
c906108c
SS
4725@item reverse-search @var{regexp}
4726The command @samp{reverse-search @var{regexp}} checks each line, starting
4727with the one before the last line listed and going backward, for a match
4728for @var{regexp}. It lists the line that is found. You can abbreviate
4729this command as @code{rev}.
4730@end table
c906108c 4731
6d2ebf8b 4732@node Source Path
c906108c
SS
4733@section Specifying source directories
4734
4735@cindex source path
4736@cindex directories for source files
4737Executable programs sometimes do not record the directories of the source
4738files from which they were compiled, just the names. Even when they do,
4739the directories could be moved between the compilation and your debugging
4740session. @value{GDBN} has a list of directories to search for source files;
4741this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
4742it tries all the directories in the list, in the order they are present
0b66e38c
EZ
4743in the list, until it finds a file with the desired name.
4744
4745For example, suppose an executable references the file
4746@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
4747@file{/mnt/cross}. The file is first looked up literally; if this
4748fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
4749fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
4750message is printed. @value{GDBN} does not look up the parts of the
4751source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
4752Likewise, the subdirectories of the source path are not searched: if
4753the source path is @file{/mnt/cross}, and the binary refers to
4754@file{foo.c}, @value{GDBN} would not find it under
4755@file{/mnt/cross/usr/src/foo-1.0/lib}.
4756
4757Plain file names, relative file names with leading directories, file
4758names containing dots, etc.@: are all treated as described above; for
4759instance, if the source path is @file{/mnt/cross}, and the source file
4760is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
4761@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
4762that---@file{/mnt/cross/foo.c}.
4763
4764Note that the executable search path is @emph{not} used to locate the
4765source files. Neither is the current working directory, unless it
4766happens to be in the source path.
c906108c
SS
4767
4768Whenever you reset or rearrange the source path, @value{GDBN} clears out
4769any information it has cached about where source files are found and where
4770each line is in the file.
4771
4772@kindex directory
4773@kindex dir
d4f3574e
SS
4774When you start @value{GDBN}, its source path includes only @samp{cdir}
4775and @samp{cwd}, in that order.
c906108c
SS
4776To add other directories, use the @code{directory} command.
4777
4778@table @code
4779@item directory @var{dirname} @dots{}
4780@item dir @var{dirname} @dots{}
4781Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
4782directory names may be given to this command, separated by @samp{:}
4783(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
4784part of absolute file names) or
c906108c
SS
4785whitespace. You may specify a directory that is already in the source
4786path; this moves it forward, so @value{GDBN} searches it sooner.
4787
4788@kindex cdir
4789@kindex cwd
41afff9a
EZ
4790@vindex $cdir@r{, convenience variable}
4791@vindex $cwdr@r{, convenience variable}
c906108c
SS
4792@cindex compilation directory
4793@cindex current directory
4794@cindex working directory
4795@cindex directory, current
4796@cindex directory, compilation
4797You can use the string @samp{$cdir} to refer to the compilation
4798directory (if one is recorded), and @samp{$cwd} to refer to the current
4799working directory. @samp{$cwd} is not the same as @samp{.}---the former
4800tracks the current working directory as it changes during your @value{GDBN}
4801session, while the latter is immediately expanded to the current
4802directory at the time you add an entry to the source path.
4803
4804@item directory
4805Reset the source path to empty again. This requires confirmation.
4806
4807@c RET-repeat for @code{directory} is explicitly disabled, but since
4808@c repeating it would be a no-op we do not say that. (thanks to RMS)
4809
4810@item show directories
4811@kindex show directories
4812Print the source path: show which directories it contains.
4813@end table
4814
4815If your source path is cluttered with directories that are no longer of
4816interest, @value{GDBN} may sometimes cause confusion by finding the wrong
4817versions of source. You can correct the situation as follows:
4818
4819@enumerate
4820@item
4821Use @code{directory} with no argument to reset the source path to empty.
4822
4823@item
4824Use @code{directory} with suitable arguments to reinstall the
4825directories you want in the source path. You can add all the
4826directories in one command.
4827@end enumerate
4828
6d2ebf8b 4829@node Machine Code
c906108c 4830@section Source and machine code
15387254 4831@cindex source line and its code address
c906108c
SS
4832
4833You can use the command @code{info line} to map source lines to program
4834addresses (and vice versa), and the command @code{disassemble} to display
4835a range of addresses as machine instructions. When run under @sc{gnu} Emacs
d4f3574e 4836mode, the @code{info line} command causes the arrow to point to the
5d161b24 4837line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
4838well as hex.
4839
4840@table @code
4841@kindex info line
4842@item info line @var{linespec}
4843Print the starting and ending addresses of the compiled code for
4844source line @var{linespec}. You can specify source lines in any of
4845the ways understood by the @code{list} command (@pxref{List, ,Printing
4846source lines}).
4847@end table
4848
4849For example, we can use @code{info line} to discover the location of
4850the object code for the first line of function
4851@code{m4_changequote}:
4852
d4f3574e
SS
4853@c FIXME: I think this example should also show the addresses in
4854@c symbolic form, as they usually would be displayed.
c906108c 4855@smallexample
96a2c332 4856(@value{GDBP}) info line m4_changequote
c906108c
SS
4857Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
4858@end smallexample
4859
4860@noindent
15387254 4861@cindex code address and its source line
c906108c
SS
4862We can also inquire (using @code{*@var{addr}} as the form for
4863@var{linespec}) what source line covers a particular address:
4864@smallexample
4865(@value{GDBP}) info line *0x63ff
4866Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
4867@end smallexample
4868
4869@cindex @code{$_} and @code{info line}
15387254 4870@cindex @code{x} command, default address
41afff9a 4871@kindex x@r{(examine), and} info line
c906108c
SS
4872After @code{info line}, the default address for the @code{x} command
4873is changed to the starting address of the line, so that @samp{x/i} is
4874sufficient to begin examining the machine code (@pxref{Memory,
4875,Examining memory}). Also, this address is saved as the value of the
4876convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
4877variables}).
4878
4879@table @code
4880@kindex disassemble
4881@cindex assembly instructions
4882@cindex instructions, assembly
4883@cindex machine instructions
4884@cindex listing machine instructions
4885@item disassemble
4886This specialized command dumps a range of memory as machine
4887instructions. The default memory range is the function surrounding the
4888program counter of the selected frame. A single argument to this
4889command is a program counter value; @value{GDBN} dumps the function
4890surrounding this value. Two arguments specify a range of addresses
4891(first inclusive, second exclusive) to dump.
4892@end table
4893
c906108c
SS
4894The following example shows the disassembly of a range of addresses of
4895HP PA-RISC 2.0 code:
4896
4897@smallexample
4898(@value{GDBP}) disas 0x32c4 0x32e4
4899Dump of assembler code from 0x32c4 to 0x32e4:
49000x32c4 <main+204>: addil 0,dp
49010x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
49020x32cc <main+212>: ldil 0x3000,r31
49030x32d0 <main+216>: ble 0x3f8(sr4,r31)
49040x32d4 <main+220>: ldo 0(r31),rp
49050x32d8 <main+224>: addil -0x800,dp
49060x32dc <main+228>: ldo 0x588(r1),r26
49070x32e0 <main+232>: ldil 0x3000,r31
4908End of assembler dump.
4909@end smallexample
c906108c
SS
4910
4911Some architectures have more than one commonly-used set of instruction
4912mnemonics or other syntax.
4913
76d17f34
EZ
4914For programs that were dynamically linked and use shared libraries,
4915instructions that call functions or branch to locations in the shared
4916libraries might show a seemingly bogus location---it's actually a
4917location of the relocation table. On some architectures, @value{GDBN}
4918might be able to resolve these to actual function names.
4919
c906108c 4920@table @code
d4f3574e 4921@kindex set disassembly-flavor
d4f3574e
SS
4922@cindex Intel disassembly flavor
4923@cindex AT&T disassembly flavor
4924@item set disassembly-flavor @var{instruction-set}
c906108c
SS
4925Select the instruction set to use when disassembling the
4926program via the @code{disassemble} or @code{x/i} commands.
4927
4928Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
4929can set @var{instruction-set} to either @code{intel} or @code{att}.
4930The default is @code{att}, the AT&T flavor used by default by Unix
4931assemblers for x86-based targets.
9c16f35a
EZ
4932
4933@kindex show disassembly-flavor
4934@item show disassembly-flavor
4935Show the current setting of the disassembly flavor.
c906108c
SS
4936@end table
4937
4938
6d2ebf8b 4939@node Data
c906108c
SS
4940@chapter Examining Data
4941
4942@cindex printing data
4943@cindex examining data
4944@kindex print
4945@kindex inspect
4946@c "inspect" is not quite a synonym if you are using Epoch, which we do not
4947@c document because it is nonstandard... Under Epoch it displays in a
4948@c different window or something like that.
4949The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
4950command (abbreviated @code{p}), or its synonym @code{inspect}. It
4951evaluates and prints the value of an expression of the language your
4952program is written in (@pxref{Languages, ,Using @value{GDBN} with
4953Different Languages}).
c906108c
SS
4954
4955@table @code
d4f3574e
SS
4956@item print @var{expr}
4957@itemx print /@var{f} @var{expr}
4958@var{expr} is an expression (in the source language). By default the
4959value of @var{expr} is printed in a format appropriate to its data type;
c906108c 4960you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 4961@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
c906108c
SS
4962formats}.
4963
4964@item print
4965@itemx print /@var{f}
15387254 4966@cindex reprint the last value
d4f3574e 4967If you omit @var{expr}, @value{GDBN} displays the last value again (from the
c906108c
SS
4968@dfn{value history}; @pxref{Value History, ,Value history}). This allows you to
4969conveniently inspect the same value in an alternative format.
4970@end table
4971
4972A more low-level way of examining data is with the @code{x} command.
4973It examines data in memory at a specified address and prints it in a
4974specified format. @xref{Memory, ,Examining memory}.
4975
7a292a7a 4976If you are interested in information about types, or about how the
d4f3574e
SS
4977fields of a struct or a class are declared, use the @code{ptype @var{exp}}
4978command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 4979Table}.
c906108c
SS
4980
4981@menu
4982* Expressions:: Expressions
4983* Variables:: Program variables
4984* Arrays:: Artificial arrays
4985* Output Formats:: Output formats
4986* Memory:: Examining memory
4987* Auto Display:: Automatic display
4988* Print Settings:: Print settings
4989* Value History:: Value history
4990* Convenience Vars:: Convenience variables
4991* Registers:: Registers
c906108c 4992* Floating Point Hardware:: Floating point hardware
53c69bd7 4993* Vector Unit:: Vector Unit
721c2651 4994* OS Information:: Auxiliary data provided by operating system
29e57380 4995* Memory Region Attributes:: Memory region attributes
16d9dec6 4996* Dump/Restore Files:: Copy between memory and a file
384ee23f 4997* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
4998* Character Sets:: Debugging programs that use a different
4999 character set than GDB does
09d4efe1 5000* Caching Remote Data:: Data caching for remote targets
c906108c
SS
5001@end menu
5002
6d2ebf8b 5003@node Expressions
c906108c
SS
5004@section Expressions
5005
5006@cindex expressions
5007@code{print} and many other @value{GDBN} commands accept an expression and
5008compute its value. Any kind of constant, variable or operator defined
5009by the programming language you are using is valid in an expression in
e2e0bcd1
JB
5010@value{GDBN}. This includes conditional expressions, function calls,
5011casts, and string constants. It also includes preprocessor macros, if
5012you compiled your program to include this information; see
5013@ref{Compilation}.
c906108c 5014
15387254 5015@cindex arrays in expressions
d4f3574e
SS
5016@value{GDBN} supports array constants in expressions input by
5017the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5d161b24 5018you can use the command @code{print @{1, 2, 3@}} to build up an array in
d4f3574e 5019memory that is @code{malloc}ed in the target program.
c906108c 5020
c906108c
SS
5021Because C is so widespread, most of the expressions shown in examples in
5022this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5023Languages}, for information on how to use expressions in other
5024languages.
5025
5026In this section, we discuss operators that you can use in @value{GDBN}
5027expressions regardless of your programming language.
5028
15387254 5029@cindex casts, in expressions
c906108c
SS
5030Casts are supported in all languages, not just in C, because it is so
5031useful to cast a number into a pointer in order to examine a structure
5032at that address in memory.
5033@c FIXME: casts supported---Mod2 true?
c906108c
SS
5034
5035@value{GDBN} supports these operators, in addition to those common
5036to programming languages:
5037
5038@table @code
5039@item @@
5040@samp{@@} is a binary operator for treating parts of memory as arrays.
5041@xref{Arrays, ,Artificial arrays}, for more information.
5042
5043@item ::
5044@samp{::} allows you to specify a variable in terms of the file or
5045function where it is defined. @xref{Variables, ,Program variables}.
5046
5047@cindex @{@var{type}@}
5048@cindex type casting memory
5049@cindex memory, viewing as typed object
5050@cindex casts, to view memory
5051@item @{@var{type}@} @var{addr}
5052Refers to an object of type @var{type} stored at address @var{addr} in
5053memory. @var{addr} may be any expression whose value is an integer or
5054pointer (but parentheses are required around binary operators, just as in
5055a cast). This construct is allowed regardless of what kind of data is
5056normally supposed to reside at @var{addr}.
5057@end table
5058
6d2ebf8b 5059@node Variables
c906108c
SS
5060@section Program variables
5061
5062The most common kind of expression to use is the name of a variable
5063in your program.
5064
5065Variables in expressions are understood in the selected stack frame
5066(@pxref{Selection, ,Selecting a frame}); they must be either:
5067
5068@itemize @bullet
5069@item
5070global (or file-static)
5071@end itemize
5072
5d161b24 5073@noindent or
c906108c
SS
5074
5075@itemize @bullet
5076@item
5077visible according to the scope rules of the
5078programming language from the point of execution in that frame
5d161b24 5079@end itemize
c906108c
SS
5080
5081@noindent This means that in the function
5082
474c8240 5083@smallexample
c906108c
SS
5084foo (a)
5085 int a;
5086@{
5087 bar (a);
5088 @{
5089 int b = test ();
5090 bar (b);
5091 @}
5092@}
474c8240 5093@end smallexample
c906108c
SS
5094
5095@noindent
5096you can examine and use the variable @code{a} whenever your program is
5097executing within the function @code{foo}, but you can only use or
5098examine the variable @code{b} while your program is executing inside
5099the block where @code{b} is declared.
5100
5101@cindex variable name conflict
5102There is an exception: you can refer to a variable or function whose
5103scope is a single source file even if the current execution point is not
5104in this file. But it is possible to have more than one such variable or
5105function with the same name (in different source files). If that
5106happens, referring to that name has unpredictable effects. If you wish,
5107you can specify a static variable in a particular function or file,
15387254 5108using the colon-colon (@code{::}) notation:
c906108c 5109
d4f3574e 5110@cindex colon-colon, context for variables/functions
c906108c
SS
5111@iftex
5112@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 5113@cindex @code{::}, context for variables/functions
c906108c 5114@end iftex
474c8240 5115@smallexample
c906108c
SS
5116@var{file}::@var{variable}
5117@var{function}::@var{variable}
474c8240 5118@end smallexample
c906108c
SS
5119
5120@noindent
5121Here @var{file} or @var{function} is the name of the context for the
5122static @var{variable}. In the case of file names, you can use quotes to
5123make sure @value{GDBN} parses the file name as a single word---for example,
5124to print a global value of @code{x} defined in @file{f2.c}:
5125
474c8240 5126@smallexample
c906108c 5127(@value{GDBP}) p 'f2.c'::x
474c8240 5128@end smallexample
c906108c 5129
b37052ae 5130@cindex C@t{++} scope resolution
c906108c 5131This use of @samp{::} is very rarely in conflict with the very similar
b37052ae 5132use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
5133scope resolution operator in @value{GDBN} expressions.
5134@c FIXME: Um, so what happens in one of those rare cases where it's in
5135@c conflict?? --mew
c906108c
SS
5136
5137@cindex wrong values
5138@cindex variable values, wrong
15387254
EZ
5139@cindex function entry/exit, wrong values of variables
5140@cindex optimized code, wrong values of variables
c906108c
SS
5141@quotation
5142@emph{Warning:} Occasionally, a local variable may appear to have the
5143wrong value at certain points in a function---just after entry to a new
5144scope, and just before exit.
5145@end quotation
5146You may see this problem when you are stepping by machine instructions.
5147This is because, on most machines, it takes more than one instruction to
5148set up a stack frame (including local variable definitions); if you are
5149stepping by machine instructions, variables may appear to have the wrong
5150values until the stack frame is completely built. On exit, it usually
5151also takes more than one machine instruction to destroy a stack frame;
5152after you begin stepping through that group of instructions, local
5153variable definitions may be gone.
5154
5155This may also happen when the compiler does significant optimizations.
5156To be sure of always seeing accurate values, turn off all optimization
5157when compiling.
5158
d4f3574e
SS
5159@cindex ``No symbol "foo" in current context''
5160Another possible effect of compiler optimizations is to optimize
5161unused variables out of existence, or assign variables to registers (as
5162opposed to memory addresses). Depending on the support for such cases
5163offered by the debug info format used by the compiler, @value{GDBN}
5164might not be able to display values for such local variables. If that
5165happens, @value{GDBN} will print a message like this:
5166
474c8240 5167@smallexample
d4f3574e 5168No symbol "foo" in current context.
474c8240 5169@end smallexample
d4f3574e
SS
5170
5171To solve such problems, either recompile without optimizations, or use a
5172different debug info format, if the compiler supports several such
15387254 5173formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
0179ffac
DC
5174usually supports the @option{-gstabs+} option. @option{-gstabs+}
5175produces debug info in a format that is superior to formats such as
5176COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5177an effective form for debug info. @xref{Debugging Options,,Options
5178for Debugging Your Program or @sc{gnu} CC, gcc.info, Using @sc{gnu} CC}.
15387254
EZ
5179@xref{C, , Debugging C++}, for more info about debug info formats
5180that are best suited to C@t{++} programs.
d4f3574e 5181
ab1adacd
EZ
5182If you ask to print an object whose contents are unknown to
5183@value{GDBN}, e.g., because its data type is not completely specified
5184by the debug information, @value{GDBN} will say @samp{<incomplete
5185type>}. @xref{Symbols, incomplete type}, for more about this.
5186
6d2ebf8b 5187@node Arrays
c906108c
SS
5188@section Artificial arrays
5189
5190@cindex artificial array
15387254 5191@cindex arrays
41afff9a 5192@kindex @@@r{, referencing memory as an array}
c906108c
SS
5193It is often useful to print out several successive objects of the
5194same type in memory; a section of an array, or an array of
5195dynamically determined size for which only a pointer exists in the
5196program.
5197
5198You can do this by referring to a contiguous span of memory as an
5199@dfn{artificial array}, using the binary operator @samp{@@}. The left
5200operand of @samp{@@} should be the first element of the desired array
5201and be an individual object. The right operand should be the desired length
5202of the array. The result is an array value whose elements are all of
5203the type of the left argument. The first element is actually the left
5204argument; the second element comes from bytes of memory immediately
5205following those that hold the first element, and so on. Here is an
5206example. If a program says
5207
474c8240 5208@smallexample
c906108c 5209int *array = (int *) malloc (len * sizeof (int));
474c8240 5210@end smallexample
c906108c
SS
5211
5212@noindent
5213you can print the contents of @code{array} with
5214
474c8240 5215@smallexample
c906108c 5216p *array@@len
474c8240 5217@end smallexample
c906108c
SS
5218
5219The left operand of @samp{@@} must reside in memory. Array values made
5220with @samp{@@} in this way behave just like other arrays in terms of
5221subscripting, and are coerced to pointers when used in expressions.
5222Artificial arrays most often appear in expressions via the value history
5223(@pxref{Value History, ,Value history}), after printing one out.
5224
5225Another way to create an artificial array is to use a cast.
5226This re-interprets a value as if it were an array.
5227The value need not be in memory:
474c8240 5228@smallexample
c906108c
SS
5229(@value{GDBP}) p/x (short[2])0x12345678
5230$1 = @{0x1234, 0x5678@}
474c8240 5231@end smallexample
c906108c
SS
5232
5233As a convenience, if you leave the array length out (as in
c3f6f71d 5234@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 5235the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 5236@smallexample
c906108c
SS
5237(@value{GDBP}) p/x (short[])0x12345678
5238$2 = @{0x1234, 0x5678@}
474c8240 5239@end smallexample
c906108c
SS
5240
5241Sometimes the artificial array mechanism is not quite enough; in
5242moderately complex data structures, the elements of interest may not
5243actually be adjacent---for example, if you are interested in the values
5244of pointers in an array. One useful work-around in this situation is
5245to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5246variables}) as a counter in an expression that prints the first
5247interesting value, and then repeat that expression via @key{RET}. For
5248instance, suppose you have an array @code{dtab} of pointers to
5249structures, and you are interested in the values of a field @code{fv}
5250in each structure. Here is an example of what you might type:
5251
474c8240 5252@smallexample
c906108c
SS
5253set $i = 0
5254p dtab[$i++]->fv
5255@key{RET}
5256@key{RET}
5257@dots{}
474c8240 5258@end smallexample
c906108c 5259
6d2ebf8b 5260@node Output Formats
c906108c
SS
5261@section Output formats
5262
5263@cindex formatted output
5264@cindex output formats
5265By default, @value{GDBN} prints a value according to its data type. Sometimes
5266this is not what you want. For example, you might want to print a number
5267in hex, or a pointer in decimal. Or you might want to view data in memory
5268at a certain address as a character string or as an instruction. To do
5269these things, specify an @dfn{output format} when you print a value.
5270
5271The simplest use of output formats is to say how to print a value
5272already computed. This is done by starting the arguments of the
5273@code{print} command with a slash and a format letter. The format
5274letters supported are:
5275
5276@table @code
5277@item x
5278Regard the bits of the value as an integer, and print the integer in
5279hexadecimal.
5280
5281@item d
5282Print as integer in signed decimal.
5283
5284@item u
5285Print as integer in unsigned decimal.
5286
5287@item o
5288Print as integer in octal.
5289
5290@item t
5291Print as integer in binary. The letter @samp{t} stands for ``two''.
5292@footnote{@samp{b} cannot be used because these format letters are also
5293used with the @code{x} command, where @samp{b} stands for ``byte'';
d4f3574e 5294see @ref{Memory,,Examining memory}.}
c906108c
SS
5295
5296@item a
5297@cindex unknown address, locating
3d67e040 5298@cindex locate address
c906108c
SS
5299Print as an address, both absolute in hexadecimal and as an offset from
5300the nearest preceding symbol. You can use this format used to discover
5301where (in what function) an unknown address is located:
5302
474c8240 5303@smallexample
c906108c
SS
5304(@value{GDBP}) p/a 0x54320
5305$3 = 0x54320 <_initialize_vx+396>
474c8240 5306@end smallexample
c906108c 5307
3d67e040
EZ
5308@noindent
5309The command @code{info symbol 0x54320} yields similar results.
5310@xref{Symbols, info symbol}.
5311
c906108c 5312@item c
51274035
EZ
5313Regard as an integer and print it as a character constant. This
5314prints both the numerical value and its character representation. The
5315character representation is replaced with the octal escape @samp{\nnn}
5316for characters outside the 7-bit @sc{ascii} range.
c906108c
SS
5317
5318@item f
5319Regard the bits of the value as a floating point number and print
5320using typical floating point syntax.
5321@end table
5322
5323For example, to print the program counter in hex (@pxref{Registers}), type
5324
474c8240 5325@smallexample
c906108c 5326p/x $pc
474c8240 5327@end smallexample
c906108c
SS
5328
5329@noindent
5330Note that no space is required before the slash; this is because command
5331names in @value{GDBN} cannot contain a slash.
5332
5333To reprint the last value in the value history with a different format,
5334you can use the @code{print} command with just a format and no
5335expression. For example, @samp{p/x} reprints the last value in hex.
5336
6d2ebf8b 5337@node Memory
c906108c
SS
5338@section Examining memory
5339
5340You can use the command @code{x} (for ``examine'') to examine memory in
5341any of several formats, independently of your program's data types.
5342
5343@cindex examining memory
5344@table @code
41afff9a 5345@kindex x @r{(examine memory)}
c906108c
SS
5346@item x/@var{nfu} @var{addr}
5347@itemx x @var{addr}
5348@itemx x
5349Use the @code{x} command to examine memory.
5350@end table
5351
5352@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5353much memory to display and how to format it; @var{addr} is an
5354expression giving the address where you want to start displaying memory.
5355If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5356Several commands set convenient defaults for @var{addr}.
5357
5358@table @r
5359@item @var{n}, the repeat count
5360The repeat count is a decimal integer; the default is 1. It specifies
5361how much memory (counting by units @var{u}) to display.
5362@c This really is **decimal**; unaffected by 'set radix' as of GDB
5363@c 4.1.2.
5364
5365@item @var{f}, the display format
51274035
EZ
5366The display format is one of the formats used by @code{print}
5367(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5368@samp{f}), and in addition @samp{s} (for null-terminated strings) and
5369@samp{i} (for machine instructions). The default is @samp{x}
5370(hexadecimal) initially. The default changes each time you use either
5371@code{x} or @code{print}.
c906108c
SS
5372
5373@item @var{u}, the unit size
5374The unit size is any of
5375
5376@table @code
5377@item b
5378Bytes.
5379@item h
5380Halfwords (two bytes).
5381@item w
5382Words (four bytes). This is the initial default.
5383@item g
5384Giant words (eight bytes).
5385@end table
5386
5387Each time you specify a unit size with @code{x}, that size becomes the
5388default unit the next time you use @code{x}. (For the @samp{s} and
5389@samp{i} formats, the unit size is ignored and is normally not written.)
5390
5391@item @var{addr}, starting display address
5392@var{addr} is the address where you want @value{GDBN} to begin displaying
5393memory. The expression need not have a pointer value (though it may);
5394it is always interpreted as an integer address of a byte of memory.
5395@xref{Expressions, ,Expressions}, for more information on expressions. The default for
5396@var{addr} is usually just after the last address examined---but several
5397other commands also set the default address: @code{info breakpoints} (to
5398the address of the last breakpoint listed), @code{info line} (to the
5399starting address of a line), and @code{print} (if you use it to display
5400a value from memory).
5401@end table
5402
5403For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5404(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5405starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5406words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 5407@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
5408
5409Since the letters indicating unit sizes are all distinct from the
5410letters specifying output formats, you do not have to remember whether
5411unit size or format comes first; either order works. The output
5412specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
5413(However, the count @var{n} must come first; @samp{wx4} does not work.)
5414
5415Even though the unit size @var{u} is ignored for the formats @samp{s}
5416and @samp{i}, you might still want to use a count @var{n}; for example,
5417@samp{3i} specifies that you want to see three machine instructions,
5418including any operands. The command @code{disassemble} gives an
d4f3574e 5419alternative way of inspecting machine instructions; see @ref{Machine
c906108c
SS
5420Code,,Source and machine code}.
5421
5422All the defaults for the arguments to @code{x} are designed to make it
5423easy to continue scanning memory with minimal specifications each time
5424you use @code{x}. For example, after you have inspected three machine
5425instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
5426with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
5427the repeat count @var{n} is used again; the other arguments default as
5428for successive uses of @code{x}.
5429
5430@cindex @code{$_}, @code{$__}, and value history
5431The addresses and contents printed by the @code{x} command are not saved
5432in the value history because there is often too much of them and they
5433would get in the way. Instead, @value{GDBN} makes these values available for
5434subsequent use in expressions as values of the convenience variables
5435@code{$_} and @code{$__}. After an @code{x} command, the last address
5436examined is available for use in expressions in the convenience variable
5437@code{$_}. The contents of that address, as examined, are available in
5438the convenience variable @code{$__}.
5439
5440If the @code{x} command has a repeat count, the address and contents saved
5441are from the last memory unit printed; this is not the same as the last
5442address printed if several units were printed on the last line of output.
5443
09d4efe1
EZ
5444@cindex remote memory comparison
5445@cindex verify remote memory image
5446When you are debugging a program running on a remote target machine
5447(@pxref{Remote}), you may wish to verify the program's image in the
5448remote machine's memory against the executable file you downloaded to
5449the target. The @code{compare-sections} command is provided for such
5450situations.
5451
5452@table @code
5453@kindex compare-sections
5454@item compare-sections @r{[}@var{section-name}@r{]}
5455Compare the data of a loadable section @var{section-name} in the
5456executable file of the program being debugged with the same section in
5457the remote machine's memory, and report any mismatches. With no
5458arguments, compares all loadable sections. This command's
5459availability depends on the target's support for the @code{"qCRC"}
5460remote request.
5461@end table
5462
6d2ebf8b 5463@node Auto Display
c906108c
SS
5464@section Automatic display
5465@cindex automatic display
5466@cindex display of expressions
5467
5468If you find that you want to print the value of an expression frequently
5469(to see how it changes), you might want to add it to the @dfn{automatic
5470display list} so that @value{GDBN} prints its value each time your program stops.
5471Each expression added to the list is given a number to identify it;
5472to remove an expression from the list, you specify that number.
5473The automatic display looks like this:
5474
474c8240 5475@smallexample
c906108c
SS
54762: foo = 38
54773: bar[5] = (struct hack *) 0x3804
474c8240 5478@end smallexample
c906108c
SS
5479
5480@noindent
5481This display shows item numbers, expressions and their current values. As with
5482displays you request manually using @code{x} or @code{print}, you can
5483specify the output format you prefer; in fact, @code{display} decides
5484whether to use @code{print} or @code{x} depending on how elaborate your
5485format specification is---it uses @code{x} if you specify a unit size,
5486or one of the two formats (@samp{i} and @samp{s}) that are only
5487supported by @code{x}; otherwise it uses @code{print}.
5488
5489@table @code
5490@kindex display
d4f3574e
SS
5491@item display @var{expr}
5492Add the expression @var{expr} to the list of expressions to display
c906108c
SS
5493each time your program stops. @xref{Expressions, ,Expressions}.
5494
5495@code{display} does not repeat if you press @key{RET} again after using it.
5496
d4f3574e 5497@item display/@var{fmt} @var{expr}
c906108c 5498For @var{fmt} specifying only a display format and not a size or
d4f3574e 5499count, add the expression @var{expr} to the auto-display list but
c906108c
SS
5500arrange to display it each time in the specified format @var{fmt}.
5501@xref{Output Formats,,Output formats}.
5502
5503@item display/@var{fmt} @var{addr}
5504For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
5505number of units, add the expression @var{addr} as a memory address to
5506be examined each time your program stops. Examining means in effect
5507doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining memory}.
5508@end table
5509
5510For example, @samp{display/i $pc} can be helpful, to see the machine
5511instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 5512is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
5513
5514@table @code
5515@kindex delete display
5516@kindex undisplay
5517@item undisplay @var{dnums}@dots{}
5518@itemx delete display @var{dnums}@dots{}
5519Remove item numbers @var{dnums} from the list of expressions to display.
5520
5521@code{undisplay} does not repeat if you press @key{RET} after using it.
5522(Otherwise you would just get the error @samp{No display number @dots{}}.)
5523
5524@kindex disable display
5525@item disable display @var{dnums}@dots{}
5526Disable the display of item numbers @var{dnums}. A disabled display
5527item is not printed automatically, but is not forgotten. It may be
5528enabled again later.
5529
5530@kindex enable display
5531@item enable display @var{dnums}@dots{}
5532Enable display of item numbers @var{dnums}. It becomes effective once
5533again in auto display of its expression, until you specify otherwise.
5534
5535@item display
5536Display the current values of the expressions on the list, just as is
5537done when your program stops.
5538
5539@kindex info display
5540@item info display
5541Print the list of expressions previously set up to display
5542automatically, each one with its item number, but without showing the
5543values. This includes disabled expressions, which are marked as such.
5544It also includes expressions which would not be displayed right now
5545because they refer to automatic variables not currently available.
5546@end table
5547
15387254 5548@cindex display disabled out of scope
c906108c
SS
5549If a display expression refers to local variables, then it does not make
5550sense outside the lexical context for which it was set up. Such an
5551expression is disabled when execution enters a context where one of its
5552variables is not defined. For example, if you give the command
5553@code{display last_char} while inside a function with an argument
5554@code{last_char}, @value{GDBN} displays this argument while your program
5555continues to stop inside that function. When it stops elsewhere---where
5556there is no variable @code{last_char}---the display is disabled
5557automatically. The next time your program stops where @code{last_char}
5558is meaningful, you can enable the display expression once again.
5559
6d2ebf8b 5560@node Print Settings
c906108c
SS
5561@section Print settings
5562
5563@cindex format options
5564@cindex print settings
5565@value{GDBN} provides the following ways to control how arrays, structures,
5566and symbols are printed.
5567
5568@noindent
5569These settings are useful for debugging programs in any language:
5570
5571@table @code
4644b6e3 5572@kindex set print
c906108c
SS
5573@item set print address
5574@itemx set print address on
4644b6e3 5575@cindex print/don't print memory addresses
c906108c
SS
5576@value{GDBN} prints memory addresses showing the location of stack
5577traces, structure values, pointer values, breakpoints, and so forth,
5578even when it also displays the contents of those addresses. The default
5579is @code{on}. For example, this is what a stack frame display looks like with
5580@code{set print address on}:
5581
5582@smallexample
5583@group
5584(@value{GDBP}) f
5585#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
5586 at input.c:530
5587530 if (lquote != def_lquote)
5588@end group
5589@end smallexample
5590
5591@item set print address off
5592Do not print addresses when displaying their contents. For example,
5593this is the same stack frame displayed with @code{set print address off}:
5594
5595@smallexample
5596@group
5597(@value{GDBP}) set print addr off
5598(@value{GDBP}) f
5599#0 set_quotes (lq="<<", rq=">>") at input.c:530
5600530 if (lquote != def_lquote)
5601@end group
5602@end smallexample
5603
5604You can use @samp{set print address off} to eliminate all machine
5605dependent displays from the @value{GDBN} interface. For example, with
5606@code{print address off}, you should get the same text for backtraces on
5607all machines---whether or not they involve pointer arguments.
5608
4644b6e3 5609@kindex show print
c906108c
SS
5610@item show print address
5611Show whether or not addresses are to be printed.
5612@end table
5613
5614When @value{GDBN} prints a symbolic address, it normally prints the
5615closest earlier symbol plus an offset. If that symbol does not uniquely
5616identify the address (for example, it is a name whose scope is a single
5617source file), you may need to clarify. One way to do this is with
5618@code{info line}, for example @samp{info line *0x4537}. Alternately,
5619you can set @value{GDBN} to print the source file and line number when
5620it prints a symbolic address:
5621
5622@table @code
c906108c 5623@item set print symbol-filename on
9c16f35a
EZ
5624@cindex source file and line of a symbol
5625@cindex symbol, source file and line
c906108c
SS
5626Tell @value{GDBN} to print the source file name and line number of a
5627symbol in the symbolic form of an address.
5628
5629@item set print symbol-filename off
5630Do not print source file name and line number of a symbol. This is the
5631default.
5632
c906108c
SS
5633@item show print symbol-filename
5634Show whether or not @value{GDBN} will print the source file name and
5635line number of a symbol in the symbolic form of an address.
5636@end table
5637
5638Another situation where it is helpful to show symbol filenames and line
5639numbers is when disassembling code; @value{GDBN} shows you the line
5640number and source file that corresponds to each instruction.
5641
5642Also, you may wish to see the symbolic form only if the address being
5643printed is reasonably close to the closest earlier symbol:
5644
5645@table @code
c906108c 5646@item set print max-symbolic-offset @var{max-offset}
4644b6e3 5647@cindex maximum value for offset of closest symbol
c906108c
SS
5648Tell @value{GDBN} to only display the symbolic form of an address if the
5649offset between the closest earlier symbol and the address is less than
5d161b24 5650@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
5651to always print the symbolic form of an address if any symbol precedes it.
5652
c906108c
SS
5653@item show print max-symbolic-offset
5654Ask how large the maximum offset is that @value{GDBN} prints in a
5655symbolic address.
5656@end table
5657
5658@cindex wild pointer, interpreting
5659@cindex pointer, finding referent
5660If you have a pointer and you are not sure where it points, try
5661@samp{set print symbol-filename on}. Then you can determine the name
5662and source file location of the variable where it points, using
5663@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
5664For example, here @value{GDBN} shows that a variable @code{ptt} points
5665at another variable @code{t}, defined in @file{hi2.c}:
5666
474c8240 5667@smallexample
c906108c
SS
5668(@value{GDBP}) set print symbol-filename on
5669(@value{GDBP}) p/a ptt
5670$4 = 0xe008 <t in hi2.c>
474c8240 5671@end smallexample
c906108c
SS
5672
5673@quotation
5674@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
5675does not show the symbol name and filename of the referent, even with
5676the appropriate @code{set print} options turned on.
5677@end quotation
5678
5679Other settings control how different kinds of objects are printed:
5680
5681@table @code
c906108c
SS
5682@item set print array
5683@itemx set print array on
4644b6e3 5684@cindex pretty print arrays
c906108c
SS
5685Pretty print arrays. This format is more convenient to read,
5686but uses more space. The default is off.
5687
5688@item set print array off
5689Return to compressed format for arrays.
5690
c906108c
SS
5691@item show print array
5692Show whether compressed or pretty format is selected for displaying
5693arrays.
5694
3c9c013a
JB
5695@cindex print array indexes
5696@item set print array-indexes
5697@itemx set print array-indexes on
5698Print the index of each element when displaying arrays. May be more
5699convenient to locate a given element in the array or quickly find the
5700index of a given element in that printed array. The default is off.
5701
5702@item set print array-indexes off
5703Stop printing element indexes when displaying arrays.
5704
5705@item show print array-indexes
5706Show whether the index of each element is printed when displaying
5707arrays.
5708
c906108c 5709@item set print elements @var{number-of-elements}
4644b6e3 5710@cindex number of array elements to print
9c16f35a 5711@cindex limit on number of printed array elements
c906108c
SS
5712Set a limit on how many elements of an array @value{GDBN} will print.
5713If @value{GDBN} is printing a large array, it stops printing after it has
5714printed the number of elements set by the @code{set print elements} command.
5715This limit also applies to the display of strings.
d4f3574e 5716When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
5717Setting @var{number-of-elements} to zero means that the printing is unlimited.
5718
c906108c
SS
5719@item show print elements
5720Display the number of elements of a large array that @value{GDBN} will print.
5721If the number is 0, then the printing is unlimited.
5722
9c16f35a
EZ
5723@item set print repeats
5724@cindex repeated array elements
5725Set the threshold for suppressing display of repeated array
5726elelments. When the number of consecutive identical elements of an
5727array exceeds the threshold, @value{GDBN} prints the string
5728@code{"<repeats @var{n} times>"}, where @var{n} is the number of
5729identical repetitions, instead of displaying the identical elements
5730themselves. Setting the threshold to zero will cause all elements to
5731be individually printed. The default threshold is 10.
5732
5733@item show print repeats
5734Display the current threshold for printing repeated identical
5735elements.
5736
c906108c 5737@item set print null-stop
4644b6e3 5738@cindex @sc{null} elements in arrays
c906108c 5739Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 5740@sc{null} is encountered. This is useful when large arrays actually
c906108c 5741contain only short strings.
d4f3574e 5742The default is off.
c906108c 5743
9c16f35a
EZ
5744@item show print null-stop
5745Show whether @value{GDBN} stops printing an array on the first
5746@sc{null} character.
5747
c906108c 5748@item set print pretty on
9c16f35a
EZ
5749@cindex print structures in indented form
5750@cindex indentation in structure display
5d161b24 5751Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
5752per line, like this:
5753
5754@smallexample
5755@group
5756$1 = @{
5757 next = 0x0,
5758 flags = @{
5759 sweet = 1,
5760 sour = 1
5761 @},
5762 meat = 0x54 "Pork"
5763@}
5764@end group
5765@end smallexample
5766
5767@item set print pretty off
5768Cause @value{GDBN} to print structures in a compact format, like this:
5769
5770@smallexample
5771@group
5772$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
5773meat = 0x54 "Pork"@}
5774@end group
5775@end smallexample
5776
5777@noindent
5778This is the default format.
5779
c906108c
SS
5780@item show print pretty
5781Show which format @value{GDBN} is using to print structures.
5782
c906108c 5783@item set print sevenbit-strings on
4644b6e3
EZ
5784@cindex eight-bit characters in strings
5785@cindex octal escapes in strings
c906108c
SS
5786Print using only seven-bit characters; if this option is set,
5787@value{GDBN} displays any eight-bit characters (in strings or
5788character values) using the notation @code{\}@var{nnn}. This setting is
5789best if you are working in English (@sc{ascii}) and you use the
5790high-order bit of characters as a marker or ``meta'' bit.
5791
5792@item set print sevenbit-strings off
5793Print full eight-bit characters. This allows the use of more
5794international character sets, and is the default.
5795
c906108c
SS
5796@item show print sevenbit-strings
5797Show whether or not @value{GDBN} is printing only seven-bit characters.
5798
c906108c 5799@item set print union on
4644b6e3 5800@cindex unions in structures, printing
9c16f35a
EZ
5801Tell @value{GDBN} to print unions which are contained in structures
5802and other unions. This is the default setting.
c906108c
SS
5803
5804@item set print union off
9c16f35a
EZ
5805Tell @value{GDBN} not to print unions which are contained in
5806structures and other unions. @value{GDBN} will print @code{"@{...@}"}
5807instead.
c906108c 5808
c906108c
SS
5809@item show print union
5810Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 5811structures and other unions.
c906108c
SS
5812
5813For example, given the declarations
5814
5815@smallexample
5816typedef enum @{Tree, Bug@} Species;
5817typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 5818typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
5819 Bug_forms;
5820
5821struct thing @{
5822 Species it;
5823 union @{
5824 Tree_forms tree;
5825 Bug_forms bug;
5826 @} form;
5827@};
5828
5829struct thing foo = @{Tree, @{Acorn@}@};
5830@end smallexample
5831
5832@noindent
5833with @code{set print union on} in effect @samp{p foo} would print
5834
5835@smallexample
5836$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
5837@end smallexample
5838
5839@noindent
5840and with @code{set print union off} in effect it would print
5841
5842@smallexample
5843$1 = @{it = Tree, form = @{...@}@}
5844@end smallexample
9c16f35a
EZ
5845
5846@noindent
5847@code{set print union} affects programs written in C-like languages
5848and in Pascal.
c906108c
SS
5849@end table
5850
c906108c
SS
5851@need 1000
5852@noindent
b37052ae 5853These settings are of interest when debugging C@t{++} programs:
c906108c
SS
5854
5855@table @code
4644b6e3 5856@cindex demangling C@t{++} names
c906108c
SS
5857@item set print demangle
5858@itemx set print demangle on
b37052ae 5859Print C@t{++} names in their source form rather than in the encoded
c906108c 5860(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 5861linkage. The default is on.
c906108c 5862
c906108c 5863@item show print demangle
b37052ae 5864Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 5865
c906108c
SS
5866@item set print asm-demangle
5867@itemx set print asm-demangle on
b37052ae 5868Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
5869in assembler code printouts such as instruction disassemblies.
5870The default is off.
5871
c906108c 5872@item show print asm-demangle
b37052ae 5873Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
5874or demangled form.
5875
b37052ae
EZ
5876@cindex C@t{++} symbol decoding style
5877@cindex symbol decoding style, C@t{++}
a8f24a35 5878@kindex set demangle-style
c906108c
SS
5879@item set demangle-style @var{style}
5880Choose among several encoding schemes used by different compilers to
b37052ae 5881represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
5882
5883@table @code
5884@item auto
5885Allow @value{GDBN} to choose a decoding style by inspecting your program.
5886
5887@item gnu
b37052ae 5888Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c 5889This is the default.
c906108c
SS
5890
5891@item hp
b37052ae 5892Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
5893
5894@item lucid
b37052ae 5895Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
5896
5897@item arm
b37052ae 5898Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
5899@strong{Warning:} this setting alone is not sufficient to allow
5900debugging @code{cfront}-generated executables. @value{GDBN} would
5901require further enhancement to permit that.
5902
5903@end table
5904If you omit @var{style}, you will see a list of possible formats.
5905
c906108c 5906@item show demangle-style
b37052ae 5907Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 5908
c906108c
SS
5909@item set print object
5910@itemx set print object on
4644b6e3 5911@cindex derived type of an object, printing
9c16f35a 5912@cindex display derived types
c906108c
SS
5913When displaying a pointer to an object, identify the @emph{actual}
5914(derived) type of the object rather than the @emph{declared} type, using
5915the virtual function table.
5916
5917@item set print object off
5918Display only the declared type of objects, without reference to the
5919virtual function table. This is the default setting.
5920
c906108c
SS
5921@item show print object
5922Show whether actual, or declared, object types are displayed.
5923
c906108c
SS
5924@item set print static-members
5925@itemx set print static-members on
4644b6e3 5926@cindex static members of C@t{++} objects
b37052ae 5927Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
5928
5929@item set print static-members off
b37052ae 5930Do not print static members when displaying a C@t{++} object.
c906108c 5931
c906108c 5932@item show print static-members
9c16f35a
EZ
5933Show whether C@t{++} static members are printed or not.
5934
5935@item set print pascal_static-members
5936@itemx set print pascal_static-members on
5937@cindex static members of Pacal objects
5938@cindex Pacal objects, static members display
5939Print static members when displaying a Pascal object. The default is on.
5940
5941@item set print pascal_static-members off
5942Do not print static members when displaying a Pascal object.
5943
5944@item show print pascal_static-members
5945Show whether Pascal static members are printed or not.
c906108c
SS
5946
5947@c These don't work with HP ANSI C++ yet.
c906108c
SS
5948@item set print vtbl
5949@itemx set print vtbl on
4644b6e3 5950@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
5951@cindex virtual functions (C@t{++}) display
5952@cindex VTBL display
b37052ae 5953Pretty print C@t{++} virtual function tables. The default is off.
c906108c 5954(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 5955ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
5956
5957@item set print vtbl off
b37052ae 5958Do not pretty print C@t{++} virtual function tables.
c906108c 5959
c906108c 5960@item show print vtbl
b37052ae 5961Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 5962@end table
c906108c 5963
6d2ebf8b 5964@node Value History
c906108c
SS
5965@section Value history
5966
5967@cindex value history
9c16f35a 5968@cindex history of values printed by @value{GDBN}
5d161b24
DB
5969Values printed by the @code{print} command are saved in the @value{GDBN}
5970@dfn{value history}. This allows you to refer to them in other expressions.
5971Values are kept until the symbol table is re-read or discarded
5972(for example with the @code{file} or @code{symbol-file} commands).
5973When the symbol table changes, the value history is discarded,
5974since the values may contain pointers back to the types defined in the
c906108c
SS
5975symbol table.
5976
5977@cindex @code{$}
5978@cindex @code{$$}
5979@cindex history number
5980The values printed are given @dfn{history numbers} by which you can
5981refer to them. These are successive integers starting with one.
5982@code{print} shows you the history number assigned to a value by
5983printing @samp{$@var{num} = } before the value; here @var{num} is the
5984history number.
5985
5986To refer to any previous value, use @samp{$} followed by the value's
5987history number. The way @code{print} labels its output is designed to
5988remind you of this. Just @code{$} refers to the most recent value in
5989the history, and @code{$$} refers to the value before that.
5990@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
5991is the value just prior to @code{$$}, @code{$$1} is equivalent to
5992@code{$$}, and @code{$$0} is equivalent to @code{$}.
5993
5994For example, suppose you have just printed a pointer to a structure and
5995want to see the contents of the structure. It suffices to type
5996
474c8240 5997@smallexample
c906108c 5998p *$
474c8240 5999@end smallexample
c906108c
SS
6000
6001If you have a chain of structures where the component @code{next} points
6002to the next one, you can print the contents of the next one with this:
6003
474c8240 6004@smallexample
c906108c 6005p *$.next
474c8240 6006@end smallexample
c906108c
SS
6007
6008@noindent
6009You can print successive links in the chain by repeating this
6010command---which you can do by just typing @key{RET}.
6011
6012Note that the history records values, not expressions. If the value of
6013@code{x} is 4 and you type these commands:
6014
474c8240 6015@smallexample
c906108c
SS
6016print x
6017set x=5
474c8240 6018@end smallexample
c906108c
SS
6019
6020@noindent
6021then the value recorded in the value history by the @code{print} command
6022remains 4 even though the value of @code{x} has changed.
6023
6024@table @code
6025@kindex show values
6026@item show values
6027Print the last ten values in the value history, with their item numbers.
6028This is like @samp{p@ $$9} repeated ten times, except that @code{show
6029values} does not change the history.
6030
6031@item show values @var{n}
6032Print ten history values centered on history item number @var{n}.
6033
6034@item show values +
6035Print ten history values just after the values last printed. If no more
6036values are available, @code{show values +} produces no display.
6037@end table
6038
6039Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6040same effect as @samp{show values +}.
6041
6d2ebf8b 6042@node Convenience Vars
c906108c
SS
6043@section Convenience variables
6044
6045@cindex convenience variables
9c16f35a 6046@cindex user-defined variables
c906108c
SS
6047@value{GDBN} provides @dfn{convenience variables} that you can use within
6048@value{GDBN} to hold on to a value and refer to it later. These variables
6049exist entirely within @value{GDBN}; they are not part of your program, and
6050setting a convenience variable has no direct effect on further execution
6051of your program. That is why you can use them freely.
6052
6053Convenience variables are prefixed with @samp{$}. Any name preceded by
6054@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 6055the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c
SS
6056(Value history references, in contrast, are @emph{numbers} preceded
6057by @samp{$}. @xref{Value History, ,Value history}.)
6058
6059You can save a value in a convenience variable with an assignment
6060expression, just as you would set a variable in your program.
6061For example:
6062
474c8240 6063@smallexample
c906108c 6064set $foo = *object_ptr
474c8240 6065@end smallexample
c906108c
SS
6066
6067@noindent
6068would save in @code{$foo} the value contained in the object pointed to by
6069@code{object_ptr}.
6070
6071Using a convenience variable for the first time creates it, but its
6072value is @code{void} until you assign a new value. You can alter the
6073value with another assignment at any time.
6074
6075Convenience variables have no fixed types. You can assign a convenience
6076variable any type of value, including structures and arrays, even if
6077that variable already has a value of a different type. The convenience
6078variable, when used as an expression, has the type of its current value.
6079
6080@table @code
6081@kindex show convenience
9c16f35a 6082@cindex show all user variables
c906108c
SS
6083@item show convenience
6084Print a list of convenience variables used so far, and their values.
d4f3574e 6085Abbreviated @code{show conv}.
c906108c
SS
6086@end table
6087
6088One of the ways to use a convenience variable is as a counter to be
6089incremented or a pointer to be advanced. For example, to print
6090a field from successive elements of an array of structures:
6091
474c8240 6092@smallexample
c906108c
SS
6093set $i = 0
6094print bar[$i++]->contents
474c8240 6095@end smallexample
c906108c 6096
d4f3574e
SS
6097@noindent
6098Repeat that command by typing @key{RET}.
c906108c
SS
6099
6100Some convenience variables are created automatically by @value{GDBN} and given
6101values likely to be useful.
6102
6103@table @code
41afff9a 6104@vindex $_@r{, convenience variable}
c906108c
SS
6105@item $_
6106The variable @code{$_} is automatically set by the @code{x} command to
6107the last address examined (@pxref{Memory, ,Examining memory}). Other
6108commands which provide a default address for @code{x} to examine also
6109set @code{$_} to that address; these commands include @code{info line}
6110and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6111except when set by the @code{x} command, in which case it is a pointer
6112to the type of @code{$__}.
6113
41afff9a 6114@vindex $__@r{, convenience variable}
c906108c
SS
6115@item $__
6116The variable @code{$__} is automatically set by the @code{x} command
6117to the value found in the last address examined. Its type is chosen
6118to match the format in which the data was printed.
6119
6120@item $_exitcode
41afff9a 6121@vindex $_exitcode@r{, convenience variable}
c906108c
SS
6122The variable @code{$_exitcode} is automatically set to the exit code when
6123the program being debugged terminates.
6124@end table
6125
53a5351d
JM
6126On HP-UX systems, if you refer to a function or variable name that
6127begins with a dollar sign, @value{GDBN} searches for a user or system
6128name first, before it searches for a convenience variable.
c906108c 6129
6d2ebf8b 6130@node Registers
c906108c
SS
6131@section Registers
6132
6133@cindex registers
6134You can refer to machine register contents, in expressions, as variables
6135with names starting with @samp{$}. The names of registers are different
6136for each machine; use @code{info registers} to see the names used on
6137your machine.
6138
6139@table @code
6140@kindex info registers
6141@item info registers
6142Print the names and values of all registers except floating-point
c85508ee 6143and vector registers (in the selected stack frame).
c906108c
SS
6144
6145@kindex info all-registers
6146@cindex floating point registers
6147@item info all-registers
6148Print the names and values of all registers, including floating-point
c85508ee 6149and vector registers (in the selected stack frame).
c906108c
SS
6150
6151@item info registers @var{regname} @dots{}
6152Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
6153As discussed in detail below, register values are normally relative to
6154the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
6155the machine you are using, with or without the initial @samp{$}.
6156@end table
6157
e09f16f9
EZ
6158@cindex stack pointer register
6159@cindex program counter register
6160@cindex process status register
6161@cindex frame pointer register
6162@cindex standard registers
c906108c
SS
6163@value{GDBN} has four ``standard'' register names that are available (in
6164expressions) on most machines---whenever they do not conflict with an
6165architecture's canonical mnemonics for registers. The register names
6166@code{$pc} and @code{$sp} are used for the program counter register and
6167the stack pointer. @code{$fp} is used for a register that contains a
6168pointer to the current stack frame, and @code{$ps} is used for a
6169register that contains the processor status. For example,
6170you could print the program counter in hex with
6171
474c8240 6172@smallexample
c906108c 6173p/x $pc
474c8240 6174@end smallexample
c906108c
SS
6175
6176@noindent
6177or print the instruction to be executed next with
6178
474c8240 6179@smallexample
c906108c 6180x/i $pc
474c8240 6181@end smallexample
c906108c
SS
6182
6183@noindent
6184or add four to the stack pointer@footnote{This is a way of removing
6185one word from the stack, on machines where stacks grow downward in
6186memory (most machines, nowadays). This assumes that the innermost
6187stack frame is selected; setting @code{$sp} is not allowed when other
6188stack frames are selected. To pop entire frames off the stack,
6189regardless of machine architecture, use @code{return};
d4f3574e 6190see @ref{Returning, ,Returning from a function}.} with
c906108c 6191
474c8240 6192@smallexample
c906108c 6193set $sp += 4
474c8240 6194@end smallexample
c906108c
SS
6195
6196Whenever possible, these four standard register names are available on
6197your machine even though the machine has different canonical mnemonics,
6198so long as there is no conflict. The @code{info registers} command
6199shows the canonical names. For example, on the SPARC, @code{info
6200registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
6201can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6202is an alias for the @sc{eflags} register.
c906108c
SS
6203
6204@value{GDBN} always considers the contents of an ordinary register as an
6205integer when the register is examined in this way. Some machines have
6206special registers which can hold nothing but floating point; these
6207registers are considered to have floating point values. There is no way
6208to refer to the contents of an ordinary register as floating point value
6209(although you can @emph{print} it as a floating point value with
6210@samp{print/f $@var{regname}}).
6211
6212Some registers have distinct ``raw'' and ``virtual'' data formats. This
6213means that the data format in which the register contents are saved by
6214the operating system is not the same one that your program normally
6215sees. For example, the registers of the 68881 floating point
6216coprocessor are always saved in ``extended'' (raw) format, but all C
6217programs expect to work with ``double'' (virtual) format. In such
5d161b24 6218cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
6219that makes sense for your program), but the @code{info registers} command
6220prints the data in both formats.
6221
6222Normally, register values are relative to the selected stack frame
6223(@pxref{Selection, ,Selecting a frame}). This means that you get the
6224value that the register would contain if all stack frames farther in
6225were exited and their saved registers restored. In order to see the
6226true contents of hardware registers, you must select the innermost
6227frame (with @samp{frame 0}).
6228
6229However, @value{GDBN} must deduce where registers are saved, from the machine
6230code generated by your compiler. If some registers are not saved, or if
6231@value{GDBN} is unable to locate the saved registers, the selected stack
6232frame makes no difference.
6233
6d2ebf8b 6234@node Floating Point Hardware
c906108c
SS
6235@section Floating point hardware
6236@cindex floating point
6237
6238Depending on the configuration, @value{GDBN} may be able to give
6239you more information about the status of the floating point hardware.
6240
6241@table @code
6242@kindex info float
6243@item info float
6244Display hardware-dependent information about the floating
6245point unit. The exact contents and layout vary depending on the
6246floating point chip. Currently, @samp{info float} is supported on
6247the ARM and x86 machines.
6248@end table
c906108c 6249
e76f1f2e
AC
6250@node Vector Unit
6251@section Vector Unit
6252@cindex vector unit
6253
6254Depending on the configuration, @value{GDBN} may be able to give you
6255more information about the status of the vector unit.
6256
6257@table @code
6258@kindex info vector
6259@item info vector
6260Display information about the vector unit. The exact contents and
6261layout vary depending on the hardware.
6262@end table
6263
721c2651
EZ
6264@node OS Information
6265@section Operating system auxiliary information
6266@cindex OS information
6267
6268@value{GDBN} provides interfaces to useful OS facilities that can help
6269you debug your program.
6270
6271@cindex @code{ptrace} system call
6272@cindex @code{struct user} contents
6273When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6274machines), it interfaces with the inferior via the @code{ptrace}
6275system call. The operating system creates a special sata structure,
6276called @code{struct user}, for this interface. You can use the
6277command @code{info udot} to display the contents of this data
6278structure.
6279
6280@table @code
6281@item info udot
6282@kindex info udot
6283Display the contents of the @code{struct user} maintained by the OS
6284kernel for the program being debugged. @value{GDBN} displays the
6285contents of @code{struct user} as a list of hex numbers, similar to
6286the @code{examine} command.
6287@end table
6288
b383017d
RM
6289@cindex auxiliary vector
6290@cindex vector, auxiliary
b383017d
RM
6291Some operating systems supply an @dfn{auxiliary vector} to programs at
6292startup. This is akin to the arguments and environment that you
6293specify for a program, but contains a system-dependent variety of
6294binary values that tell system libraries important details about the
6295hardware, operating system, and process. Each value's purpose is
6296identified by an integer tag; the meanings are well-known but system-specific.
6297Depending on the configuration and operating system facilities,
9c16f35a
EZ
6298@value{GDBN} may be able to show you this information. For remote
6299targets, this functionality may further depend on the remote stub's
6300support of the @samp{qPart:auxv:read} packet, see @ref{Remote
6301configuration, auxiliary vector}.
b383017d
RM
6302
6303@table @code
6304@kindex info auxv
6305@item info auxv
6306Display the auxiliary vector of the inferior, which can be either a
e4937fc1 6307live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
6308numerically, and also shows names and text descriptions for recognized
6309tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 6310pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
6311most appropriate form for a recognized tag, and in hexadecimal for
6312an unrecognized tag.
6313@end table
6314
721c2651 6315
29e57380 6316@node Memory Region Attributes
b383017d 6317@section Memory region attributes
29e57380
C
6318@cindex memory region attributes
6319
b383017d
RM
6320@dfn{Memory region attributes} allow you to describe special handling
6321required by regions of your target's memory. @value{GDBN} uses attributes
29e57380
C
6322to determine whether to allow certain types of memory accesses; whether to
6323use specific width accesses; and whether to cache target memory.
6324
6325Defined memory regions can be individually enabled and disabled. When a
6326memory region is disabled, @value{GDBN} uses the default attributes when
6327accessing memory in that region. Similarly, if no memory regions have
6328been defined, @value{GDBN} uses the default attributes when accessing
6329all memory.
6330
b383017d 6331When a memory region is defined, it is given a number to identify it;
29e57380
C
6332to enable, disable, or remove a memory region, you specify that number.
6333
6334@table @code
6335@kindex mem
bfac230e 6336@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
6337Define a memory region bounded by @var{lower} and @var{upper} with
6338attributes @var{attributes}@dots{}, and add it to the list of regions
6339monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
6340case: it is treated as the the target's maximum memory address.
bfac230e 6341(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380
C
6342
6343@kindex delete mem
6344@item delete mem @var{nums}@dots{}
09d4efe1
EZ
6345Remove memory regions @var{nums}@dots{} from the list of regions
6346monitored by @value{GDBN}.
29e57380
C
6347
6348@kindex disable mem
6349@item disable mem @var{nums}@dots{}
09d4efe1 6350Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 6351A disabled memory region is not forgotten.
29e57380
C
6352It may be enabled again later.
6353
6354@kindex enable mem
6355@item enable mem @var{nums}@dots{}
09d4efe1 6356Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
6357
6358@kindex info mem
6359@item info mem
6360Print a table of all defined memory regions, with the following columns
09d4efe1 6361for each region:
29e57380
C
6362
6363@table @emph
6364@item Memory Region Number
6365@item Enabled or Disabled.
b383017d 6366Enabled memory regions are marked with @samp{y}.
29e57380
C
6367Disabled memory regions are marked with @samp{n}.
6368
6369@item Lo Address
6370The address defining the inclusive lower bound of the memory region.
6371
6372@item Hi Address
6373The address defining the exclusive upper bound of the memory region.
6374
6375@item Attributes
6376The list of attributes set for this memory region.
6377@end table
6378@end table
6379
6380
6381@subsection Attributes
6382
b383017d 6383@subsubsection Memory Access Mode
29e57380
C
6384The access mode attributes set whether @value{GDBN} may make read or
6385write accesses to a memory region.
6386
6387While these attributes prevent @value{GDBN} from performing invalid
6388memory accesses, they do nothing to prevent the target system, I/O DMA,
6389etc. from accessing memory.
6390
6391@table @code
6392@item ro
6393Memory is read only.
6394@item wo
6395Memory is write only.
6396@item rw
6ca652b0 6397Memory is read/write. This is the default.
29e57380
C
6398@end table
6399
6400@subsubsection Memory Access Size
6401The acccess size attributes tells @value{GDBN} to use specific sized
6402accesses in the memory region. Often memory mapped device registers
6403require specific sized accesses. If no access size attribute is
6404specified, @value{GDBN} may use accesses of any size.
6405
6406@table @code
6407@item 8
6408Use 8 bit memory accesses.
6409@item 16
6410Use 16 bit memory accesses.
6411@item 32
6412Use 32 bit memory accesses.
6413@item 64
6414Use 64 bit memory accesses.
6415@end table
6416
6417@c @subsubsection Hardware/Software Breakpoints
6418@c The hardware/software breakpoint attributes set whether @value{GDBN}
6419@c will use hardware or software breakpoints for the internal breakpoints
6420@c used by the step, next, finish, until, etc. commands.
6421@c
6422@c @table @code
6423@c @item hwbreak
b383017d 6424@c Always use hardware breakpoints
29e57380
C
6425@c @item swbreak (default)
6426@c @end table
6427
6428@subsubsection Data Cache
6429The data cache attributes set whether @value{GDBN} will cache target
6430memory. While this generally improves performance by reducing debug
6431protocol overhead, it can lead to incorrect results because @value{GDBN}
6432does not know about volatile variables or memory mapped device
6433registers.
6434
6435@table @code
6436@item cache
b383017d 6437Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
6438@item nocache
6439Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
6440@end table
6441
6442@c @subsubsection Memory Write Verification
b383017d 6443@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
6444@c will re-reads data after each write to verify the write was successful.
6445@c
6446@c @table @code
6447@c @item verify
6448@c @item noverify (default)
6449@c @end table
6450
16d9dec6
MS
6451@node Dump/Restore Files
6452@section Copy between memory and a file
6453@cindex dump/restore files
6454@cindex append data to a file
6455@cindex dump data to a file
6456@cindex restore data from a file
16d9dec6 6457
df5215a6
JB
6458You can use the commands @code{dump}, @code{append}, and
6459@code{restore} to copy data between target memory and a file. The
6460@code{dump} and @code{append} commands write data to a file, and the
6461@code{restore} command reads data from a file back into the inferior's
6462memory. Files may be in binary, Motorola S-record, Intel hex, or
6463Tektronix Hex format; however, @value{GDBN} can only append to binary
6464files.
6465
6466@table @code
6467
6468@kindex dump
6469@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6470@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
6471Dump the contents of memory from @var{start_addr} to @var{end_addr},
6472or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 6473
df5215a6 6474The @var{format} parameter may be any one of:
16d9dec6 6475@table @code
df5215a6
JB
6476@item binary
6477Raw binary form.
6478@item ihex
6479Intel hex format.
6480@item srec
6481Motorola S-record format.
6482@item tekhex
6483Tektronix Hex format.
6484@end table
6485
6486@value{GDBN} uses the same definitions of these formats as the
6487@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
6488@var{format} is omitted, @value{GDBN} dumps the data in raw binary
6489form.
6490
6491@kindex append
6492@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
6493@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
6494Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 6495or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
6496(@value{GDBN} can only append data to files in raw binary form.)
6497
6498@kindex restore
6499@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
6500Restore the contents of file @var{filename} into memory. The
6501@code{restore} command can automatically recognize any known @sc{bfd}
6502file format, except for raw binary. To restore a raw binary file you
6503must specify the optional keyword @code{binary} after the filename.
16d9dec6 6504
b383017d 6505If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
6506contained in the file. Binary files always start at address zero, so
6507they will be restored at address @var{bias}. Other bfd files have
6508a built-in location; they will be restored at offset @var{bias}
6509from that location.
6510
6511If @var{start} and/or @var{end} are non-zero, then only data between
6512file offset @var{start} and file offset @var{end} will be restored.
b383017d 6513These offsets are relative to the addresses in the file, before
16d9dec6
MS
6514the @var{bias} argument is applied.
6515
6516@end table
6517
384ee23f
EZ
6518@node Core File Generation
6519@section How to Produce a Core File from Your Program
6520@cindex dump core from inferior
6521
6522A @dfn{core file} or @dfn{core dump} is a file that records the memory
6523image of a running process and its process status (register values
6524etc.). Its primary use is post-mortem debugging of a program that
6525crashed while it ran outside a debugger. A program that crashes
6526automatically produces a core file, unless this feature is disabled by
6527the user. @xref{Files}, for information on invoking @value{GDBN} in
6528the post-mortem debugging mode.
6529
6530Occasionally, you may wish to produce a core file of the program you
6531are debugging in order to preserve a snapshot of its state.
6532@value{GDBN} has a special command for that.
6533
6534@table @code
6535@kindex gcore
6536@kindex generate-core-file
6537@item generate-core-file [@var{file}]
6538@itemx gcore [@var{file}]
6539Produce a core dump of the inferior process. The optional argument
6540@var{file} specifies the file name where to put the core dump. If not
6541specified, the file name defaults to @file{core.@var{pid}}, where
6542@var{pid} is the inferior process ID.
6543
6544Note that this command is implemented only for some systems (as of
6545this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
6546@end table
6547
a0eb71c5
KB
6548@node Character Sets
6549@section Character Sets
6550@cindex character sets
6551@cindex charset
6552@cindex translating between character sets
6553@cindex host character set
6554@cindex target character set
6555
6556If the program you are debugging uses a different character set to
6557represent characters and strings than the one @value{GDBN} uses itself,
6558@value{GDBN} can automatically translate between the character sets for
6559you. The character set @value{GDBN} uses we call the @dfn{host
6560character set}; the one the inferior program uses we call the
6561@dfn{target character set}.
6562
6563For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
6564uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
6565remote protocol (@pxref{Remote,Remote Debugging}) to debug a program
6566running on an IBM mainframe, which uses the @sc{ebcdic} character set,
6567then the host character set is Latin-1, and the target character set is
6568@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 6569target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
6570@sc{ebcdic} and Latin 1 as you print character or string values, or use
6571character and string literals in expressions.
6572
6573@value{GDBN} has no way to automatically recognize which character set
6574the inferior program uses; you must tell it, using the @code{set
6575target-charset} command, described below.
6576
6577Here are the commands for controlling @value{GDBN}'s character set
6578support:
6579
6580@table @code
6581@item set target-charset @var{charset}
6582@kindex set target-charset
6583Set the current target character set to @var{charset}. We list the
e33d66ec
EZ
6584character set names @value{GDBN} recognizes below, but if you type
6585@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6586list the target character sets it supports.
a0eb71c5
KB
6587@end table
6588
6589@table @code
6590@item set host-charset @var{charset}
6591@kindex set host-charset
6592Set the current host character set to @var{charset}.
6593
6594By default, @value{GDBN} uses a host character set appropriate to the
6595system it is running on; you can override that default using the
6596@code{set host-charset} command.
6597
6598@value{GDBN} can only use certain character sets as its host character
6599set. We list the character set names @value{GDBN} recognizes below, and
e33d66ec
EZ
6600indicate which can be host character sets, but if you type
6601@code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
6602list the host character sets it supports.
a0eb71c5
KB
6603
6604@item set charset @var{charset}
6605@kindex set charset
e33d66ec
EZ
6606Set the current host and target character sets to @var{charset}. As
6607above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
6608@value{GDBN} will list the name of the character sets that can be used
6609for both host and target.
6610
a0eb71c5
KB
6611
6612@item show charset
a0eb71c5 6613@kindex show charset
b383017d 6614Show the names of the current host and target charsets.
e33d66ec
EZ
6615
6616@itemx show host-charset
a0eb71c5 6617@kindex show host-charset
b383017d 6618Show the name of the current host charset.
e33d66ec
EZ
6619
6620@itemx show target-charset
a0eb71c5 6621@kindex show target-charset
b383017d 6622Show the name of the current target charset.
a0eb71c5
KB
6623
6624@end table
6625
6626@value{GDBN} currently includes support for the following character
6627sets:
6628
6629@table @code
6630
6631@item ASCII
6632@cindex ASCII character set
6633Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
6634character set.
6635
6636@item ISO-8859-1
6637@cindex ISO 8859-1 character set
6638@cindex ISO Latin 1 character set
e33d66ec 6639The ISO Latin 1 character set. This extends @sc{ascii} with accented
a0eb71c5
KB
6640characters needed for French, German, and Spanish. @value{GDBN} can use
6641this as its host character set.
6642
6643@item EBCDIC-US
6644@itemx IBM1047
6645@cindex EBCDIC character set
6646@cindex IBM1047 character set
6647Variants of the @sc{ebcdic} character set, used on some of IBM's
6648mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
6649@value{GDBN} cannot use these as its host character set.
6650
6651@end table
6652
6653Note that these are all single-byte character sets. More work inside
6654GDB is needed to support multi-byte or variable-width character
6655encodings, like the UTF-8 and UCS-2 encodings of Unicode.
6656
6657Here is an example of @value{GDBN}'s character set support in action.
6658Assume that the following source code has been placed in the file
6659@file{charset-test.c}:
6660
6661@smallexample
6662#include <stdio.h>
6663
6664char ascii_hello[]
6665 = @{72, 101, 108, 108, 111, 44, 32, 119,
6666 111, 114, 108, 100, 33, 10, 0@};
6667char ibm1047_hello[]
6668 = @{200, 133, 147, 147, 150, 107, 64, 166,
6669 150, 153, 147, 132, 90, 37, 0@};
6670
6671main ()
6672@{
6673 printf ("Hello, world!\n");
6674@}
10998722 6675@end smallexample
a0eb71c5
KB
6676
6677In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
6678containing the string @samp{Hello, world!} followed by a newline,
6679encoded in the @sc{ascii} and @sc{ibm1047} character sets.
6680
6681We compile the program, and invoke the debugger on it:
6682
6683@smallexample
6684$ gcc -g charset-test.c -o charset-test
6685$ gdb -nw charset-test
6686GNU gdb 2001-12-19-cvs
6687Copyright 2001 Free Software Foundation, Inc.
6688@dots{}
f7dc1244 6689(@value{GDBP})
10998722 6690@end smallexample
a0eb71c5
KB
6691
6692We can use the @code{show charset} command to see what character sets
6693@value{GDBN} is currently using to interpret and display characters and
6694strings:
6695
6696@smallexample
f7dc1244 6697(@value{GDBP}) show charset
e33d66ec 6698The current host and target character set is `ISO-8859-1'.
f7dc1244 6699(@value{GDBP})
10998722 6700@end smallexample
a0eb71c5
KB
6701
6702For the sake of printing this manual, let's use @sc{ascii} as our
6703initial character set:
6704@smallexample
f7dc1244
EZ
6705(@value{GDBP}) set charset ASCII
6706(@value{GDBP}) show charset
e33d66ec 6707The current host and target character set is `ASCII'.
f7dc1244 6708(@value{GDBP})
10998722 6709@end smallexample
a0eb71c5
KB
6710
6711Let's assume that @sc{ascii} is indeed the correct character set for our
6712host system --- in other words, let's assume that if @value{GDBN} prints
6713characters using the @sc{ascii} character set, our terminal will display
6714them properly. Since our current target character set is also
6715@sc{ascii}, the contents of @code{ascii_hello} print legibly:
6716
6717@smallexample
f7dc1244 6718(@value{GDBP}) print ascii_hello
a0eb71c5 6719$1 = 0x401698 "Hello, world!\n"
f7dc1244 6720(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6721$2 = 72 'H'
f7dc1244 6722(@value{GDBP})
10998722 6723@end smallexample
a0eb71c5
KB
6724
6725@value{GDBN} uses the target character set for character and string
6726literals you use in expressions:
6727
6728@smallexample
f7dc1244 6729(@value{GDBP}) print '+'
a0eb71c5 6730$3 = 43 '+'
f7dc1244 6731(@value{GDBP})
10998722 6732@end smallexample
a0eb71c5
KB
6733
6734The @sc{ascii} character set uses the number 43 to encode the @samp{+}
6735character.
6736
6737@value{GDBN} relies on the user to tell it which character set the
6738target program uses. If we print @code{ibm1047_hello} while our target
6739character set is still @sc{ascii}, we get jibberish:
6740
6741@smallexample
f7dc1244 6742(@value{GDBP}) print ibm1047_hello
a0eb71c5 6743$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 6744(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6745$5 = 200 '\310'
f7dc1244 6746(@value{GDBP})
10998722 6747@end smallexample
a0eb71c5 6748
e33d66ec 6749If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
6750@value{GDBN} tells us the character sets it supports:
6751
6752@smallexample
f7dc1244 6753(@value{GDBP}) set target-charset
b383017d 6754ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 6755(@value{GDBP}) set target-charset
10998722 6756@end smallexample
a0eb71c5
KB
6757
6758We can select @sc{ibm1047} as our target character set, and examine the
6759program's strings again. Now the @sc{ascii} string is wrong, but
6760@value{GDBN} translates the contents of @code{ibm1047_hello} from the
6761target character set, @sc{ibm1047}, to the host character set,
6762@sc{ascii}, and they display correctly:
6763
6764@smallexample
f7dc1244
EZ
6765(@value{GDBP}) set target-charset IBM1047
6766(@value{GDBP}) show charset
e33d66ec
EZ
6767The current host character set is `ASCII'.
6768The current target character set is `IBM1047'.
f7dc1244 6769(@value{GDBP}) print ascii_hello
a0eb71c5 6770$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 6771(@value{GDBP}) print ascii_hello[0]
a0eb71c5 6772$7 = 72 '\110'
f7dc1244 6773(@value{GDBP}) print ibm1047_hello
a0eb71c5 6774$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 6775(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 6776$9 = 200 'H'
f7dc1244 6777(@value{GDBP})
10998722 6778@end smallexample
a0eb71c5
KB
6779
6780As above, @value{GDBN} uses the target character set for character and
6781string literals you use in expressions:
6782
6783@smallexample
f7dc1244 6784(@value{GDBP}) print '+'
a0eb71c5 6785$10 = 78 '+'
f7dc1244 6786(@value{GDBP})
10998722 6787@end smallexample
a0eb71c5 6788
e33d66ec 6789The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
6790character.
6791
09d4efe1
EZ
6792@node Caching Remote Data
6793@section Caching Data of Remote Targets
6794@cindex caching data of remote targets
6795
6796@value{GDBN} can cache data exchanged between the debugger and a
6797remote target (@pxref{Remote}). Such caching generally improves
6798performance, because it reduces the overhead of the remote protocol by
6799bundling memory reads and writes into large chunks. Unfortunately,
6800@value{GDBN} does not currently know anything about volatile
6801registers, and thus data caching will produce incorrect results when
6802volatile registers are in use.
6803
6804@table @code
6805@kindex set remotecache
6806@item set remotecache on
6807@itemx set remotecache off
6808Set caching state for remote targets. When @code{ON}, use data
6809caching. By default, this option is @code{OFF}.
6810
6811@kindex show remotecache
6812@item show remotecache
6813Show the current state of data caching for remote targets.
6814
6815@kindex info dcache
6816@item info dcache
6817Print the information about the data cache performance. The
6818information displayed includes: the dcache width and depth; and for
6819each cache line, how many times it was referenced, and its data and
6820state (dirty, bad, ok, etc.). This command is useful for debugging
6821the data cache operation.
6822@end table
6823
a0eb71c5 6824
e2e0bcd1
JB
6825@node Macros
6826@chapter C Preprocessor Macros
6827
49efadf5 6828Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
6829``preprocessor macros'' which expand into strings of tokens.
6830@value{GDBN} can evaluate expressions containing macro invocations, show
6831the result of macro expansion, and show a macro's definition, including
6832where it was defined.
6833
6834You may need to compile your program specially to provide @value{GDBN}
6835with information about preprocessor macros. Most compilers do not
6836include macros in their debugging information, even when you compile
6837with the @option{-g} flag. @xref{Compilation}.
6838
6839A program may define a macro at one point, remove that definition later,
6840and then provide a different definition after that. Thus, at different
6841points in the program, a macro may have different definitions, or have
6842no definition at all. If there is a current stack frame, @value{GDBN}
6843uses the macros in scope at that frame's source code line. Otherwise,
6844@value{GDBN} uses the macros in scope at the current listing location;
6845see @ref{List}.
6846
6847At the moment, @value{GDBN} does not support the @code{##}
6848token-splicing operator, the @code{#} stringification operator, or
6849variable-arity macros.
6850
6851Whenever @value{GDBN} evaluates an expression, it always expands any
6852macro invocations present in the expression. @value{GDBN} also provides
6853the following commands for working with macros explicitly.
6854
6855@table @code
6856
6857@kindex macro expand
6858@cindex macro expansion, showing the results of preprocessor
6859@cindex preprocessor macro expansion, showing the results of
6860@cindex expanding preprocessor macros
6861@item macro expand @var{expression}
6862@itemx macro exp @var{expression}
6863Show the results of expanding all preprocessor macro invocations in
6864@var{expression}. Since @value{GDBN} simply expands macros, but does
6865not parse the result, @var{expression} need not be a valid expression;
6866it can be any string of tokens.
6867
09d4efe1 6868@kindex macro exp1
e2e0bcd1
JB
6869@item macro expand-once @var{expression}
6870@itemx macro exp1 @var{expression}
4644b6e3 6871@cindex expand macro once
e2e0bcd1
JB
6872@i{(This command is not yet implemented.)} Show the results of
6873expanding those preprocessor macro invocations that appear explicitly in
6874@var{expression}. Macro invocations appearing in that expansion are
6875left unchanged. This command allows you to see the effect of a
6876particular macro more clearly, without being confused by further
6877expansions. Since @value{GDBN} simply expands macros, but does not
6878parse the result, @var{expression} need not be a valid expression; it
6879can be any string of tokens.
6880
475b0867 6881@kindex info macro
e2e0bcd1
JB
6882@cindex macro definition, showing
6883@cindex definition, showing a macro's
475b0867 6884@item info macro @var{macro}
e2e0bcd1
JB
6885Show the definition of the macro named @var{macro}, and describe the
6886source location where that definition was established.
6887
6888@kindex macro define
6889@cindex user-defined macros
6890@cindex defining macros interactively
6891@cindex macros, user-defined
6892@item macro define @var{macro} @var{replacement-list}
6893@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
6894@i{(This command is not yet implemented.)} Introduce a definition for a
6895preprocessor macro named @var{macro}, invocations of which are replaced
6896by the tokens given in @var{replacement-list}. The first form of this
6897command defines an ``object-like'' macro, which takes no arguments; the
6898second form defines a ``function-like'' macro, which takes the arguments
6899given in @var{arglist}.
6900
6901A definition introduced by this command is in scope in every expression
6902evaluated in @value{GDBN}, until it is removed with the @command{macro
6903undef} command, described below. The definition overrides all
6904definitions for @var{macro} present in the program being debugged, as
6905well as any previous user-supplied definition.
6906
6907@kindex macro undef
6908@item macro undef @var{macro}
6909@i{(This command is not yet implemented.)} Remove any user-supplied
6910definition for the macro named @var{macro}. This command only affects
6911definitions provided with the @command{macro define} command, described
6912above; it cannot remove definitions present in the program being
6913debugged.
6914
09d4efe1
EZ
6915@kindex macro list
6916@item macro list
6917@i{(This command is not yet implemented.)} List all the macros
6918defined using the @code{macro define} command.
e2e0bcd1
JB
6919@end table
6920
6921@cindex macros, example of debugging with
6922Here is a transcript showing the above commands in action. First, we
6923show our source files:
6924
6925@smallexample
6926$ cat sample.c
6927#include <stdio.h>
6928#include "sample.h"
6929
6930#define M 42
6931#define ADD(x) (M + x)
6932
6933main ()
6934@{
6935#define N 28
6936 printf ("Hello, world!\n");
6937#undef N
6938 printf ("We're so creative.\n");
6939#define N 1729
6940 printf ("Goodbye, world!\n");
6941@}
6942$ cat sample.h
6943#define Q <
6944$
6945@end smallexample
6946
6947Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
6948We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
6949compiler includes information about preprocessor macros in the debugging
6950information.
6951
6952@smallexample
6953$ gcc -gdwarf-2 -g3 sample.c -o sample
6954$
6955@end smallexample
6956
6957Now, we start @value{GDBN} on our sample program:
6958
6959@smallexample
6960$ gdb -nw sample
6961GNU gdb 2002-05-06-cvs
6962Copyright 2002 Free Software Foundation, Inc.
6963GDB is free software, @dots{}
f7dc1244 6964(@value{GDBP})
e2e0bcd1
JB
6965@end smallexample
6966
6967We can expand macros and examine their definitions, even when the
6968program is not running. @value{GDBN} uses the current listing position
6969to decide which macro definitions are in scope:
6970
6971@smallexample
f7dc1244 6972(@value{GDBP}) list main
e2e0bcd1
JB
69733
69744 #define M 42
69755 #define ADD(x) (M + x)
69766
69777 main ()
69788 @{
69799 #define N 28
698010 printf ("Hello, world!\n");
698111 #undef N
698212 printf ("We're so creative.\n");
f7dc1244 6983(@value{GDBP}) info macro ADD
e2e0bcd1
JB
6984Defined at /home/jimb/gdb/macros/play/sample.c:5
6985#define ADD(x) (M + x)
f7dc1244 6986(@value{GDBP}) info macro Q
e2e0bcd1
JB
6987Defined at /home/jimb/gdb/macros/play/sample.h:1
6988 included at /home/jimb/gdb/macros/play/sample.c:2
6989#define Q <
f7dc1244 6990(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 6991expands to: (42 + 1)
f7dc1244 6992(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 6993expands to: once (M + 1)
f7dc1244 6994(@value{GDBP})
e2e0bcd1
JB
6995@end smallexample
6996
6997In the example above, note that @command{macro expand-once} expands only
6998the macro invocation explicit in the original text --- the invocation of
6999@code{ADD} --- but does not expand the invocation of the macro @code{M},
7000which was introduced by @code{ADD}.
7001
7002Once the program is running, GDB uses the macro definitions in force at
7003the source line of the current stack frame:
7004
7005@smallexample
f7dc1244 7006(@value{GDBP}) break main
e2e0bcd1 7007Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 7008(@value{GDBP}) run
b383017d 7009Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
7010
7011Breakpoint 1, main () at sample.c:10
701210 printf ("Hello, world!\n");
f7dc1244 7013(@value{GDBP})
e2e0bcd1
JB
7014@end smallexample
7015
7016At line 10, the definition of the macro @code{N} at line 9 is in force:
7017
7018@smallexample
f7dc1244 7019(@value{GDBP}) info macro N
e2e0bcd1
JB
7020Defined at /home/jimb/gdb/macros/play/sample.c:9
7021#define N 28
f7dc1244 7022(@value{GDBP}) macro expand N Q M
e2e0bcd1 7023expands to: 28 < 42
f7dc1244 7024(@value{GDBP}) print N Q M
e2e0bcd1 7025$1 = 1
f7dc1244 7026(@value{GDBP})
e2e0bcd1
JB
7027@end smallexample
7028
7029As we step over directives that remove @code{N}'s definition, and then
7030give it a new definition, @value{GDBN} finds the definition (or lack
7031thereof) in force at each point:
7032
7033@smallexample
f7dc1244 7034(@value{GDBP}) next
e2e0bcd1
JB
7035Hello, world!
703612 printf ("We're so creative.\n");
f7dc1244 7037(@value{GDBP}) info macro N
e2e0bcd1
JB
7038The symbol `N' has no definition as a C/C++ preprocessor macro
7039at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 7040(@value{GDBP}) next
e2e0bcd1
JB
7041We're so creative.
704214 printf ("Goodbye, world!\n");
f7dc1244 7043(@value{GDBP}) info macro N
e2e0bcd1
JB
7044Defined at /home/jimb/gdb/macros/play/sample.c:13
7045#define N 1729
f7dc1244 7046(@value{GDBP}) macro expand N Q M
e2e0bcd1 7047expands to: 1729 < 42
f7dc1244 7048(@value{GDBP}) print N Q M
e2e0bcd1 7049$2 = 0
f7dc1244 7050(@value{GDBP})
e2e0bcd1
JB
7051@end smallexample
7052
7053
b37052ae
EZ
7054@node Tracepoints
7055@chapter Tracepoints
7056@c This chapter is based on the documentation written by Michael
7057@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7058
7059@cindex tracepoints
7060In some applications, it is not feasible for the debugger to interrupt
7061the program's execution long enough for the developer to learn
7062anything helpful about its behavior. If the program's correctness
7063depends on its real-time behavior, delays introduced by a debugger
7064might cause the program to change its behavior drastically, or perhaps
7065fail, even when the code itself is correct. It is useful to be able
7066to observe the program's behavior without interrupting it.
7067
7068Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7069specify locations in the program, called @dfn{tracepoints}, and
7070arbitrary expressions to evaluate when those tracepoints are reached.
7071Later, using the @code{tfind} command, you can examine the values
7072those expressions had when the program hit the tracepoints. The
7073expressions may also denote objects in memory---structures or arrays,
7074for example---whose values @value{GDBN} should record; while visiting
7075a particular tracepoint, you may inspect those objects as if they were
7076in memory at that moment. However, because @value{GDBN} records these
7077values without interacting with you, it can do so quickly and
7078unobtrusively, hopefully not disturbing the program's behavior.
7079
7080The tracepoint facility is currently available only for remote
2c0069bb
EZ
7081targets. @xref{Targets}. In addition, your remote target must know how
7082to collect trace data. This functionality is implemented in the remote
7083stub; however, none of the stubs distributed with @value{GDBN} support
7084tracepoints as of this writing.
b37052ae
EZ
7085
7086This chapter describes the tracepoint commands and features.
7087
7088@menu
b383017d
RM
7089* Set Tracepoints::
7090* Analyze Collected Data::
7091* Tracepoint Variables::
b37052ae
EZ
7092@end menu
7093
7094@node Set Tracepoints
7095@section Commands to Set Tracepoints
7096
7097Before running such a @dfn{trace experiment}, an arbitrary number of
7098tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7099tracepoint has a number assigned to it by @value{GDBN}. Like with
7100breakpoints, tracepoint numbers are successive integers starting from
7101one. Many of the commands associated with tracepoints take the
7102tracepoint number as their argument, to identify which tracepoint to
7103work on.
7104
7105For each tracepoint, you can specify, in advance, some arbitrary set
7106of data that you want the target to collect in the trace buffer when
7107it hits that tracepoint. The collected data can include registers,
7108local variables, or global data. Later, you can use @value{GDBN}
7109commands to examine the values these data had at the time the
7110tracepoint was hit.
7111
7112This section describes commands to set tracepoints and associated
7113conditions and actions.
7114
7115@menu
b383017d
RM
7116* Create and Delete Tracepoints::
7117* Enable and Disable Tracepoints::
7118* Tracepoint Passcounts::
7119* Tracepoint Actions::
7120* Listing Tracepoints::
7121* Starting and Stopping Trace Experiment::
b37052ae
EZ
7122@end menu
7123
7124@node Create and Delete Tracepoints
7125@subsection Create and Delete Tracepoints
7126
7127@table @code
7128@cindex set tracepoint
7129@kindex trace
7130@item trace
7131The @code{trace} command is very similar to the @code{break} command.
7132Its argument can be a source line, a function name, or an address in
7133the target program. @xref{Set Breaks}. The @code{trace} command
7134defines a tracepoint, which is a point in the target program where the
7135debugger will briefly stop, collect some data, and then allow the
7136program to continue. Setting a tracepoint or changing its commands
7137doesn't take effect until the next @code{tstart} command; thus, you
7138cannot change the tracepoint attributes once a trace experiment is
7139running.
7140
7141Here are some examples of using the @code{trace} command:
7142
7143@smallexample
7144(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7145
7146(@value{GDBP}) @b{trace +2} // 2 lines forward
7147
7148(@value{GDBP}) @b{trace my_function} // first source line of function
7149
7150(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7151
7152(@value{GDBP}) @b{trace *0x2117c4} // an address
7153@end smallexample
7154
7155@noindent
7156You can abbreviate @code{trace} as @code{tr}.
7157
7158@vindex $tpnum
7159@cindex last tracepoint number
7160@cindex recent tracepoint number
7161@cindex tracepoint number
7162The convenience variable @code{$tpnum} records the tracepoint number
7163of the most recently set tracepoint.
7164
7165@kindex delete tracepoint
7166@cindex tracepoint deletion
7167@item delete tracepoint @r{[}@var{num}@r{]}
7168Permanently delete one or more tracepoints. With no argument, the
7169default is to delete all tracepoints.
7170
7171Examples:
7172
7173@smallexample
7174(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7175
7176(@value{GDBP}) @b{delete trace} // remove all tracepoints
7177@end smallexample
7178
7179@noindent
7180You can abbreviate this command as @code{del tr}.
7181@end table
7182
7183@node Enable and Disable Tracepoints
7184@subsection Enable and Disable Tracepoints
7185
7186@table @code
7187@kindex disable tracepoint
7188@item disable tracepoint @r{[}@var{num}@r{]}
7189Disable tracepoint @var{num}, or all tracepoints if no argument
7190@var{num} is given. A disabled tracepoint will have no effect during
7191the next trace experiment, but it is not forgotten. You can re-enable
7192a disabled tracepoint using the @code{enable tracepoint} command.
7193
7194@kindex enable tracepoint
7195@item enable tracepoint @r{[}@var{num}@r{]}
7196Enable tracepoint @var{num}, or all tracepoints. The enabled
7197tracepoints will become effective the next time a trace experiment is
7198run.
7199@end table
7200
7201@node Tracepoint Passcounts
7202@subsection Tracepoint Passcounts
7203
7204@table @code
7205@kindex passcount
7206@cindex tracepoint pass count
7207@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7208Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7209automatically stop a trace experiment. If a tracepoint's passcount is
7210@var{n}, then the trace experiment will be automatically stopped on
7211the @var{n}'th time that tracepoint is hit. If the tracepoint number
7212@var{num} is not specified, the @code{passcount} command sets the
7213passcount of the most recently defined tracepoint. If no passcount is
7214given, the trace experiment will run until stopped explicitly by the
7215user.
7216
7217Examples:
7218
7219@smallexample
b383017d 7220(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 7221@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
7222
7223(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 7224@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
7225(@value{GDBP}) @b{trace foo}
7226(@value{GDBP}) @b{pass 3}
7227(@value{GDBP}) @b{trace bar}
7228(@value{GDBP}) @b{pass 2}
7229(@value{GDBP}) @b{trace baz}
7230(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
7231@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7232@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7233@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
7234@end smallexample
7235@end table
7236
7237@node Tracepoint Actions
7238@subsection Tracepoint Action Lists
7239
7240@table @code
7241@kindex actions
7242@cindex tracepoint actions
7243@item actions @r{[}@var{num}@r{]}
7244This command will prompt for a list of actions to be taken when the
7245tracepoint is hit. If the tracepoint number @var{num} is not
7246specified, this command sets the actions for the one that was most
7247recently defined (so that you can define a tracepoint and then say
7248@code{actions} without bothering about its number). You specify the
7249actions themselves on the following lines, one action at a time, and
7250terminate the actions list with a line containing just @code{end}. So
7251far, the only defined actions are @code{collect} and
7252@code{while-stepping}.
7253
7254@cindex remove actions from a tracepoint
7255To remove all actions from a tracepoint, type @samp{actions @var{num}}
7256and follow it immediately with @samp{end}.
7257
7258@smallexample
7259(@value{GDBP}) @b{collect @var{data}} // collect some data
7260
6826cf00 7261(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 7262
6826cf00 7263(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
7264@end smallexample
7265
7266In the following example, the action list begins with @code{collect}
7267commands indicating the things to be collected when the tracepoint is
7268hit. Then, in order to single-step and collect additional data
7269following the tracepoint, a @code{while-stepping} command is used,
7270followed by the list of things to be collected while stepping. The
7271@code{while-stepping} command is terminated by its own separate
7272@code{end} command. Lastly, the action list is terminated by an
7273@code{end} command.
7274
7275@smallexample
7276(@value{GDBP}) @b{trace foo}
7277(@value{GDBP}) @b{actions}
7278Enter actions for tracepoint 1, one per line:
7279> collect bar,baz
7280> collect $regs
7281> while-stepping 12
7282 > collect $fp, $sp
7283 > end
7284end
7285@end smallexample
7286
7287@kindex collect @r{(tracepoints)}
7288@item collect @var{expr1}, @var{expr2}, @dots{}
7289Collect values of the given expressions when the tracepoint is hit.
7290This command accepts a comma-separated list of any valid expressions.
7291In addition to global, static, or local variables, the following
7292special arguments are supported:
7293
7294@table @code
7295@item $regs
7296collect all registers
7297
7298@item $args
7299collect all function arguments
7300
7301@item $locals
7302collect all local variables.
7303@end table
7304
7305You can give several consecutive @code{collect} commands, each one
7306with a single argument, or one @code{collect} command with several
7307arguments separated by commas: the effect is the same.
7308
f5c37c66
EZ
7309The command @code{info scope} (@pxref{Symbols, info scope}) is
7310particularly useful for figuring out what data to collect.
7311
b37052ae
EZ
7312@kindex while-stepping @r{(tracepoints)}
7313@item while-stepping @var{n}
7314Perform @var{n} single-step traces after the tracepoint, collecting
7315new data at each step. The @code{while-stepping} command is
7316followed by the list of what to collect while stepping (followed by
7317its own @code{end} command):
7318
7319@smallexample
7320> while-stepping 12
7321 > collect $regs, myglobal
7322 > end
7323>
7324@end smallexample
7325
7326@noindent
7327You may abbreviate @code{while-stepping} as @code{ws} or
7328@code{stepping}.
7329@end table
7330
7331@node Listing Tracepoints
7332@subsection Listing Tracepoints
7333
7334@table @code
7335@kindex info tracepoints
09d4efe1 7336@kindex info tp
b37052ae
EZ
7337@cindex information about tracepoints
7338@item info tracepoints @r{[}@var{num}@r{]}
8a037dd7 7339Display information about the tracepoint @var{num}. If you don't specify
798c8bc6 7340a tracepoint number, displays information about all the tracepoints
b37052ae
EZ
7341defined so far. For each tracepoint, the following information is
7342shown:
7343
7344@itemize @bullet
7345@item
7346its number
7347@item
7348whether it is enabled or disabled
7349@item
7350its address
7351@item
7352its passcount as given by the @code{passcount @var{n}} command
7353@item
7354its step count as given by the @code{while-stepping @var{n}} command
7355@item
7356where in the source files is the tracepoint set
7357@item
7358its action list as given by the @code{actions} command
7359@end itemize
7360
7361@smallexample
7362(@value{GDBP}) @b{info trace}
7363Num Enb Address PassC StepC What
73641 y 0x002117c4 0 0 <gdb_asm>
6826cf00
EZ
73652 y 0x0020dc64 0 0 in g_test at g_test.c:1375
73663 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
b37052ae
EZ
7367(@value{GDBP})
7368@end smallexample
7369
7370@noindent
7371This command can be abbreviated @code{info tp}.
7372@end table
7373
7374@node Starting and Stopping Trace Experiment
7375@subsection Starting and Stopping Trace Experiment
7376
7377@table @code
7378@kindex tstart
7379@cindex start a new trace experiment
7380@cindex collected data discarded
7381@item tstart
7382This command takes no arguments. It starts the trace experiment, and
7383begins collecting data. This has the side effect of discarding all
7384the data collected in the trace buffer during the previous trace
7385experiment.
7386
7387@kindex tstop
7388@cindex stop a running trace experiment
7389@item tstop
7390This command takes no arguments. It ends the trace experiment, and
7391stops collecting data.
7392
68c71a2e 7393@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
7394automatically if any tracepoint's passcount is reached
7395(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
7396
7397@kindex tstatus
7398@cindex status of trace data collection
7399@cindex trace experiment, status of
7400@item tstatus
7401This command displays the status of the current trace data
7402collection.
7403@end table
7404
7405Here is an example of the commands we described so far:
7406
7407@smallexample
7408(@value{GDBP}) @b{trace gdb_c_test}
7409(@value{GDBP}) @b{actions}
7410Enter actions for tracepoint #1, one per line.
7411> collect $regs,$locals,$args
7412> while-stepping 11
7413 > collect $regs
7414 > end
7415> end
7416(@value{GDBP}) @b{tstart}
7417 [time passes @dots{}]
7418(@value{GDBP}) @b{tstop}
7419@end smallexample
7420
7421
7422@node Analyze Collected Data
7423@section Using the collected data
7424
7425After the tracepoint experiment ends, you use @value{GDBN} commands
7426for examining the trace data. The basic idea is that each tracepoint
7427collects a trace @dfn{snapshot} every time it is hit and another
7428snapshot every time it single-steps. All these snapshots are
7429consecutively numbered from zero and go into a buffer, and you can
7430examine them later. The way you examine them is to @dfn{focus} on a
7431specific trace snapshot. When the remote stub is focused on a trace
7432snapshot, it will respond to all @value{GDBN} requests for memory and
7433registers by reading from the buffer which belongs to that snapshot,
7434rather than from @emph{real} memory or registers of the program being
7435debugged. This means that @strong{all} @value{GDBN} commands
7436(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
7437behave as if we were currently debugging the program state as it was
7438when the tracepoint occurred. Any requests for data that are not in
7439the buffer will fail.
7440
7441@menu
7442* tfind:: How to select a trace snapshot
7443* tdump:: How to display all data for a snapshot
7444* save-tracepoints:: How to save tracepoints for a future run
7445@end menu
7446
7447@node tfind
7448@subsection @code{tfind @var{n}}
7449
7450@kindex tfind
7451@cindex select trace snapshot
7452@cindex find trace snapshot
7453The basic command for selecting a trace snapshot from the buffer is
7454@code{tfind @var{n}}, which finds trace snapshot number @var{n},
7455counting from zero. If no argument @var{n} is given, the next
7456snapshot is selected.
7457
7458Here are the various forms of using the @code{tfind} command.
7459
7460@table @code
7461@item tfind start
7462Find the first snapshot in the buffer. This is a synonym for
7463@code{tfind 0} (since 0 is the number of the first snapshot).
7464
7465@item tfind none
7466Stop debugging trace snapshots, resume @emph{live} debugging.
7467
7468@item tfind end
7469Same as @samp{tfind none}.
7470
7471@item tfind
7472No argument means find the next trace snapshot.
7473
7474@item tfind -
7475Find the previous trace snapshot before the current one. This permits
7476retracing earlier steps.
7477
7478@item tfind tracepoint @var{num}
7479Find the next snapshot associated with tracepoint @var{num}. Search
7480proceeds forward from the last examined trace snapshot. If no
7481argument @var{num} is given, it means find the next snapshot collected
7482for the same tracepoint as the current snapshot.
7483
7484@item tfind pc @var{addr}
7485Find the next snapshot associated with the value @var{addr} of the
7486program counter. Search proceeds forward from the last examined trace
7487snapshot. If no argument @var{addr} is given, it means find the next
7488snapshot with the same value of PC as the current snapshot.
7489
7490@item tfind outside @var{addr1}, @var{addr2}
7491Find the next snapshot whose PC is outside the given range of
7492addresses.
7493
7494@item tfind range @var{addr1}, @var{addr2}
7495Find the next snapshot whose PC is between @var{addr1} and
7496@var{addr2}. @c FIXME: Is the range inclusive or exclusive?
7497
7498@item tfind line @r{[}@var{file}:@r{]}@var{n}
7499Find the next snapshot associated with the source line @var{n}. If
7500the optional argument @var{file} is given, refer to line @var{n} in
7501that source file. Search proceeds forward from the last examined
7502trace snapshot. If no argument @var{n} is given, it means find the
7503next line other than the one currently being examined; thus saying
7504@code{tfind line} repeatedly can appear to have the same effect as
7505stepping from line to line in a @emph{live} debugging session.
7506@end table
7507
7508The default arguments for the @code{tfind} commands are specifically
7509designed to make it easy to scan through the trace buffer. For
7510instance, @code{tfind} with no argument selects the next trace
7511snapshot, and @code{tfind -} with no argument selects the previous
7512trace snapshot. So, by giving one @code{tfind} command, and then
7513simply hitting @key{RET} repeatedly you can examine all the trace
7514snapshots in order. Or, by saying @code{tfind -} and then hitting
7515@key{RET} repeatedly you can examine the snapshots in reverse order.
7516The @code{tfind line} command with no argument selects the snapshot
7517for the next source line executed. The @code{tfind pc} command with
7518no argument selects the next snapshot with the same program counter
7519(PC) as the current frame. The @code{tfind tracepoint} command with
7520no argument selects the next trace snapshot collected by the same
7521tracepoint as the current one.
7522
7523In addition to letting you scan through the trace buffer manually,
7524these commands make it easy to construct @value{GDBN} scripts that
7525scan through the trace buffer and print out whatever collected data
7526you are interested in. Thus, if we want to examine the PC, FP, and SP
7527registers from each trace frame in the buffer, we can say this:
7528
7529@smallexample
7530(@value{GDBP}) @b{tfind start}
7531(@value{GDBP}) @b{while ($trace_frame != -1)}
7532> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
7533 $trace_frame, $pc, $sp, $fp
7534> tfind
7535> end
7536
7537Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
7538Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
7539Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
7540Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
7541Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
7542Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
7543Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
7544Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
7545Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
7546Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
7547Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
7548@end smallexample
7549
7550Or, if we want to examine the variable @code{X} at each source line in
7551the buffer:
7552
7553@smallexample
7554(@value{GDBP}) @b{tfind start}
7555(@value{GDBP}) @b{while ($trace_frame != -1)}
7556> printf "Frame %d, X == %d\n", $trace_frame, X
7557> tfind line
7558> end
7559
7560Frame 0, X = 1
7561Frame 7, X = 2
7562Frame 13, X = 255
7563@end smallexample
7564
7565@node tdump
7566@subsection @code{tdump}
7567@kindex tdump
7568@cindex dump all data collected at tracepoint
7569@cindex tracepoint data, display
7570
7571This command takes no arguments. It prints all the data collected at
7572the current trace snapshot.
7573
7574@smallexample
7575(@value{GDBP}) @b{trace 444}
7576(@value{GDBP}) @b{actions}
7577Enter actions for tracepoint #2, one per line:
7578> collect $regs, $locals, $args, gdb_long_test
7579> end
7580
7581(@value{GDBP}) @b{tstart}
7582
7583(@value{GDBP}) @b{tfind line 444}
7584#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
7585at gdb_test.c:444
7586444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
7587
7588(@value{GDBP}) @b{tdump}
7589Data collected at tracepoint 2, trace frame 1:
7590d0 0xc4aa0085 -995491707
7591d1 0x18 24
7592d2 0x80 128
7593d3 0x33 51
7594d4 0x71aea3d 119204413
7595d5 0x22 34
7596d6 0xe0 224
7597d7 0x380035 3670069
7598a0 0x19e24a 1696330
7599a1 0x3000668 50333288
7600a2 0x100 256
7601a3 0x322000 3284992
7602a4 0x3000698 50333336
7603a5 0x1ad3cc 1758156
7604fp 0x30bf3c 0x30bf3c
7605sp 0x30bf34 0x30bf34
7606ps 0x0 0
7607pc 0x20b2c8 0x20b2c8
7608fpcontrol 0x0 0
7609fpstatus 0x0 0
7610fpiaddr 0x0 0
7611p = 0x20e5b4 "gdb-test"
7612p1 = (void *) 0x11
7613p2 = (void *) 0x22
7614p3 = (void *) 0x33
7615p4 = (void *) 0x44
7616p5 = (void *) 0x55
7617p6 = (void *) 0x66
7618gdb_long_test = 17 '\021'
7619
7620(@value{GDBP})
7621@end smallexample
7622
7623@node save-tracepoints
7624@subsection @code{save-tracepoints @var{filename}}
7625@kindex save-tracepoints
7626@cindex save tracepoints for future sessions
7627
7628This command saves all current tracepoint definitions together with
7629their actions and passcounts, into a file @file{@var{filename}}
7630suitable for use in a later debugging session. To read the saved
7631tracepoint definitions, use the @code{source} command (@pxref{Command
7632Files}).
7633
7634@node Tracepoint Variables
7635@section Convenience Variables for Tracepoints
7636@cindex tracepoint variables
7637@cindex convenience variables for tracepoints
7638
7639@table @code
7640@vindex $trace_frame
7641@item (int) $trace_frame
7642The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
7643snapshot is selected.
7644
7645@vindex $tracepoint
7646@item (int) $tracepoint
7647The tracepoint for the current trace snapshot.
7648
7649@vindex $trace_line
7650@item (int) $trace_line
7651The line number for the current trace snapshot.
7652
7653@vindex $trace_file
7654@item (char []) $trace_file
7655The source file for the current trace snapshot.
7656
7657@vindex $trace_func
7658@item (char []) $trace_func
7659The name of the function containing @code{$tracepoint}.
7660@end table
7661
7662Note: @code{$trace_file} is not suitable for use in @code{printf},
7663use @code{output} instead.
7664
7665Here's a simple example of using these convenience variables for
7666stepping through all the trace snapshots and printing some of their
7667data.
7668
7669@smallexample
7670(@value{GDBP}) @b{tfind start}
7671
7672(@value{GDBP}) @b{while $trace_frame != -1}
7673> output $trace_file
7674> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
7675> tfind
7676> end
7677@end smallexample
7678
df0cd8c5
JB
7679@node Overlays
7680@chapter Debugging Programs That Use Overlays
7681@cindex overlays
7682
7683If your program is too large to fit completely in your target system's
7684memory, you can sometimes use @dfn{overlays} to work around this
7685problem. @value{GDBN} provides some support for debugging programs that
7686use overlays.
7687
7688@menu
7689* How Overlays Work:: A general explanation of overlays.
7690* Overlay Commands:: Managing overlays in @value{GDBN}.
7691* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
7692 mapped by asking the inferior.
7693* Overlay Sample Program:: A sample program using overlays.
7694@end menu
7695
7696@node How Overlays Work
7697@section How Overlays Work
7698@cindex mapped overlays
7699@cindex unmapped overlays
7700@cindex load address, overlay's
7701@cindex mapped address
7702@cindex overlay area
7703
7704Suppose you have a computer whose instruction address space is only 64
7705kilobytes long, but which has much more memory which can be accessed by
7706other means: special instructions, segment registers, or memory
7707management hardware, for example. Suppose further that you want to
7708adapt a program which is larger than 64 kilobytes to run on this system.
7709
7710One solution is to identify modules of your program which are relatively
7711independent, and need not call each other directly; call these modules
7712@dfn{overlays}. Separate the overlays from the main program, and place
7713their machine code in the larger memory. Place your main program in
7714instruction memory, but leave at least enough space there to hold the
7715largest overlay as well.
7716
7717Now, to call a function located in an overlay, you must first copy that
7718overlay's machine code from the large memory into the space set aside
7719for it in the instruction memory, and then jump to its entry point
7720there.
7721
c928edc0
AC
7722@c NB: In the below the mapped area's size is greater or equal to the
7723@c size of all overlays. This is intentional to remind the developer
7724@c that overlays don't necessarily need to be the same size.
7725
474c8240 7726@smallexample
df0cd8c5 7727@group
c928edc0
AC
7728 Data Instruction Larger
7729Address Space Address Space Address Space
7730+-----------+ +-----------+ +-----------+
7731| | | | | |
7732+-----------+ +-----------+ +-----------+<-- overlay 1
7733| program | | main | .----| overlay 1 | load address
7734| variables | | program | | +-----------+
7735| and heap | | | | | |
7736+-----------+ | | | +-----------+<-- overlay 2
7737| | +-----------+ | | | load address
7738+-----------+ | | | .-| overlay 2 |
7739 | | | | | |
7740 mapped --->+-----------+ | | +-----------+
7741 address | | | | | |
7742 | overlay | <-' | | |
7743 | area | <---' +-----------+<-- overlay 3
7744 | | <---. | | load address
7745 +-----------+ `--| overlay 3 |
7746 | | | |
7747 +-----------+ | |
7748 +-----------+
7749 | |
7750 +-----------+
7751
7752 @anchor{A code overlay}A code overlay
df0cd8c5 7753@end group
474c8240 7754@end smallexample
df0cd8c5 7755
c928edc0
AC
7756The diagram (@pxref{A code overlay}) shows a system with separate data
7757and instruction address spaces. To map an overlay, the program copies
7758its code from the larger address space to the instruction address space.
7759Since the overlays shown here all use the same mapped address, only one
7760may be mapped at a time. For a system with a single address space for
7761data and instructions, the diagram would be similar, except that the
7762program variables and heap would share an address space with the main
7763program and the overlay area.
df0cd8c5
JB
7764
7765An overlay loaded into instruction memory and ready for use is called a
7766@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
7767instruction memory. An overlay not present (or only partially present)
7768in instruction memory is called @dfn{unmapped}; its @dfn{load address}
7769is its address in the larger memory. The mapped address is also called
7770the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
7771called the @dfn{load memory address}, or @dfn{LMA}.
7772
7773Unfortunately, overlays are not a completely transparent way to adapt a
7774program to limited instruction memory. They introduce a new set of
7775global constraints you must keep in mind as you design your program:
7776
7777@itemize @bullet
7778
7779@item
7780Before calling or returning to a function in an overlay, your program
7781must make sure that overlay is actually mapped. Otherwise, the call or
7782return will transfer control to the right address, but in the wrong
7783overlay, and your program will probably crash.
7784
7785@item
7786If the process of mapping an overlay is expensive on your system, you
7787will need to choose your overlays carefully to minimize their effect on
7788your program's performance.
7789
7790@item
7791The executable file you load onto your system must contain each
7792overlay's instructions, appearing at the overlay's load address, not its
7793mapped address. However, each overlay's instructions must be relocated
7794and its symbols defined as if the overlay were at its mapped address.
7795You can use GNU linker scripts to specify different load and relocation
7796addresses for pieces of your program; see @ref{Overlay Description,,,
7797ld.info, Using ld: the GNU linker}.
7798
7799@item
7800The procedure for loading executable files onto your system must be able
7801to load their contents into the larger address space as well as the
7802instruction and data spaces.
7803
7804@end itemize
7805
7806The overlay system described above is rather simple, and could be
7807improved in many ways:
7808
7809@itemize @bullet
7810
7811@item
7812If your system has suitable bank switch registers or memory management
7813hardware, you could use those facilities to make an overlay's load area
7814contents simply appear at their mapped address in instruction space.
7815This would probably be faster than copying the overlay to its mapped
7816area in the usual way.
7817
7818@item
7819If your overlays are small enough, you could set aside more than one
7820overlay area, and have more than one overlay mapped at a time.
7821
7822@item
7823You can use overlays to manage data, as well as instructions. In
7824general, data overlays are even less transparent to your design than
7825code overlays: whereas code overlays only require care when you call or
7826return to functions, data overlays require care every time you access
7827the data. Also, if you change the contents of a data overlay, you
7828must copy its contents back out to its load address before you can copy a
7829different data overlay into the same mapped area.
7830
7831@end itemize
7832
7833
7834@node Overlay Commands
7835@section Overlay Commands
7836
7837To use @value{GDBN}'s overlay support, each overlay in your program must
7838correspond to a separate section of the executable file. The section's
7839virtual memory address and load memory address must be the overlay's
7840mapped and load addresses. Identifying overlays with sections allows
7841@value{GDBN} to determine the appropriate address of a function or
7842variable, depending on whether the overlay is mapped or not.
7843
7844@value{GDBN}'s overlay commands all start with the word @code{overlay};
7845you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
7846
7847@table @code
7848@item overlay off
4644b6e3 7849@kindex overlay
df0cd8c5
JB
7850Disable @value{GDBN}'s overlay support. When overlay support is
7851disabled, @value{GDBN} assumes that all functions and variables are
7852always present at their mapped addresses. By default, @value{GDBN}'s
7853overlay support is disabled.
7854
7855@item overlay manual
df0cd8c5
JB
7856@cindex manual overlay debugging
7857Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
7858relies on you to tell it which overlays are mapped, and which are not,
7859using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
7860commands described below.
7861
7862@item overlay map-overlay @var{overlay}
7863@itemx overlay map @var{overlay}
df0cd8c5
JB
7864@cindex map an overlay
7865Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
7866be the name of the object file section containing the overlay. When an
7867overlay is mapped, @value{GDBN} assumes it can find the overlay's
7868functions and variables at their mapped addresses. @value{GDBN} assumes
7869that any other overlays whose mapped ranges overlap that of
7870@var{overlay} are now unmapped.
7871
7872@item overlay unmap-overlay @var{overlay}
7873@itemx overlay unmap @var{overlay}
df0cd8c5
JB
7874@cindex unmap an overlay
7875Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
7876must be the name of the object file section containing the overlay.
7877When an overlay is unmapped, @value{GDBN} assumes it can find the
7878overlay's functions and variables at their load addresses.
7879
7880@item overlay auto
df0cd8c5
JB
7881Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
7882consults a data structure the overlay manager maintains in the inferior
7883to see which overlays are mapped. For details, see @ref{Automatic
7884Overlay Debugging}.
7885
7886@item overlay load-target
7887@itemx overlay load
df0cd8c5
JB
7888@cindex reloading the overlay table
7889Re-read the overlay table from the inferior. Normally, @value{GDBN}
7890re-reads the table @value{GDBN} automatically each time the inferior
7891stops, so this command should only be necessary if you have changed the
7892overlay mapping yourself using @value{GDBN}. This command is only
7893useful when using automatic overlay debugging.
7894
7895@item overlay list-overlays
7896@itemx overlay list
7897@cindex listing mapped overlays
7898Display a list of the overlays currently mapped, along with their mapped
7899addresses, load addresses, and sizes.
7900
7901@end table
7902
7903Normally, when @value{GDBN} prints a code address, it includes the name
7904of the function the address falls in:
7905
474c8240 7906@smallexample
f7dc1244 7907(@value{GDBP}) print main
df0cd8c5 7908$3 = @{int ()@} 0x11a0 <main>
474c8240 7909@end smallexample
df0cd8c5
JB
7910@noindent
7911When overlay debugging is enabled, @value{GDBN} recognizes code in
7912unmapped overlays, and prints the names of unmapped functions with
7913asterisks around them. For example, if @code{foo} is a function in an
7914unmapped overlay, @value{GDBN} prints it this way:
7915
474c8240 7916@smallexample
f7dc1244 7917(@value{GDBP}) overlay list
df0cd8c5 7918No sections are mapped.
f7dc1244 7919(@value{GDBP}) print foo
df0cd8c5 7920$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 7921@end smallexample
df0cd8c5
JB
7922@noindent
7923When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
7924name normally:
7925
474c8240 7926@smallexample
f7dc1244 7927(@value{GDBP}) overlay list
b383017d 7928Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 7929 mapped at 0x1016 - 0x104a
f7dc1244 7930(@value{GDBP}) print foo
df0cd8c5 7931$6 = @{int (int)@} 0x1016 <foo>
474c8240 7932@end smallexample
df0cd8c5
JB
7933
7934When overlay debugging is enabled, @value{GDBN} can find the correct
7935address for functions and variables in an overlay, whether or not the
7936overlay is mapped. This allows most @value{GDBN} commands, like
7937@code{break} and @code{disassemble}, to work normally, even on unmapped
7938code. However, @value{GDBN}'s breakpoint support has some limitations:
7939
7940@itemize @bullet
7941@item
7942@cindex breakpoints in overlays
7943@cindex overlays, setting breakpoints in
7944You can set breakpoints in functions in unmapped overlays, as long as
7945@value{GDBN} can write to the overlay at its load address.
7946@item
7947@value{GDBN} can not set hardware or simulator-based breakpoints in
7948unmapped overlays. However, if you set a breakpoint at the end of your
7949overlay manager (and tell @value{GDBN} which overlays are now mapped, if
7950you are using manual overlay management), @value{GDBN} will re-set its
7951breakpoints properly.
7952@end itemize
7953
7954
7955@node Automatic Overlay Debugging
7956@section Automatic Overlay Debugging
7957@cindex automatic overlay debugging
7958
7959@value{GDBN} can automatically track which overlays are mapped and which
7960are not, given some simple co-operation from the overlay manager in the
7961inferior. If you enable automatic overlay debugging with the
7962@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
7963looks in the inferior's memory for certain variables describing the
7964current state of the overlays.
7965
7966Here are the variables your overlay manager must define to support
7967@value{GDBN}'s automatic overlay debugging:
7968
7969@table @asis
7970
7971@item @code{_ovly_table}:
7972This variable must be an array of the following structures:
7973
474c8240 7974@smallexample
df0cd8c5
JB
7975struct
7976@{
7977 /* The overlay's mapped address. */
7978 unsigned long vma;
7979
7980 /* The size of the overlay, in bytes. */
7981 unsigned long size;
7982
7983 /* The overlay's load address. */
7984 unsigned long lma;
7985
7986 /* Non-zero if the overlay is currently mapped;
7987 zero otherwise. */
7988 unsigned long mapped;
7989@}
474c8240 7990@end smallexample
df0cd8c5
JB
7991
7992@item @code{_novlys}:
7993This variable must be a four-byte signed integer, holding the total
7994number of elements in @code{_ovly_table}.
7995
7996@end table
7997
7998To decide whether a particular overlay is mapped or not, @value{GDBN}
7999looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8000@code{lma} members equal the VMA and LMA of the overlay's section in the
8001executable file. When @value{GDBN} finds a matching entry, it consults
8002the entry's @code{mapped} member to determine whether the overlay is
8003currently mapped.
8004
81d46470 8005In addition, your overlay manager may define a function called
def71bfa 8006@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
8007will silently set a breakpoint there. If the overlay manager then
8008calls this function whenever it has changed the overlay table, this
8009will enable @value{GDBN} to accurately keep track of which overlays
8010are in program memory, and update any breakpoints that may be set
b383017d 8011in overlays. This will allow breakpoints to work even if the
81d46470
MS
8012overlays are kept in ROM or other non-writable memory while they
8013are not being executed.
df0cd8c5
JB
8014
8015@node Overlay Sample Program
8016@section Overlay Sample Program
8017@cindex overlay example program
8018
8019When linking a program which uses overlays, you must place the overlays
8020at their load addresses, while relocating them to run at their mapped
8021addresses. To do this, you must write a linker script (@pxref{Overlay
8022Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8023since linker scripts are specific to a particular host system, target
8024architecture, and target memory layout, this manual cannot provide
8025portable sample code demonstrating @value{GDBN}'s overlay support.
8026
8027However, the @value{GDBN} source distribution does contain an overlaid
8028program, with linker scripts for a few systems, as part of its test
8029suite. The program consists of the following files from
8030@file{gdb/testsuite/gdb.base}:
8031
8032@table @file
8033@item overlays.c
8034The main program file.
8035@item ovlymgr.c
8036A simple overlay manager, used by @file{overlays.c}.
8037@item foo.c
8038@itemx bar.c
8039@itemx baz.c
8040@itemx grbx.c
8041Overlay modules, loaded and used by @file{overlays.c}.
8042@item d10v.ld
8043@itemx m32r.ld
8044Linker scripts for linking the test program on the @code{d10v-elf}
8045and @code{m32r-elf} targets.
8046@end table
8047
8048You can build the test program using the @code{d10v-elf} GCC
8049cross-compiler like this:
8050
474c8240 8051@smallexample
df0cd8c5
JB
8052$ d10v-elf-gcc -g -c overlays.c
8053$ d10v-elf-gcc -g -c ovlymgr.c
8054$ d10v-elf-gcc -g -c foo.c
8055$ d10v-elf-gcc -g -c bar.c
8056$ d10v-elf-gcc -g -c baz.c
8057$ d10v-elf-gcc -g -c grbx.c
8058$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8059 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 8060@end smallexample
df0cd8c5
JB
8061
8062The build process is identical for any other architecture, except that
8063you must substitute the appropriate compiler and linker script for the
8064target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8065
8066
6d2ebf8b 8067@node Languages
c906108c
SS
8068@chapter Using @value{GDBN} with Different Languages
8069@cindex languages
8070
c906108c
SS
8071Although programming languages generally have common aspects, they are
8072rarely expressed in the same manner. For instance, in ANSI C,
8073dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8074Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 8075represented (and displayed) differently. Hex numbers in C appear as
c906108c 8076@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
8077
8078@cindex working language
8079Language-specific information is built into @value{GDBN} for some languages,
8080allowing you to express operations like the above in your program's
8081native language, and allowing @value{GDBN} to output values in a manner
8082consistent with the syntax of your program's native language. The
8083language you use to build expressions is called the @dfn{working
8084language}.
8085
8086@menu
8087* Setting:: Switching between source languages
8088* Show:: Displaying the language
c906108c 8089* Checks:: Type and range checks
9c16f35a 8090* Supported languages:: Supported languages
4e562065 8091* Unsupported languages:: Unsupported languages
c906108c
SS
8092@end menu
8093
6d2ebf8b 8094@node Setting
c906108c
SS
8095@section Switching between source languages
8096
8097There are two ways to control the working language---either have @value{GDBN}
8098set it automatically, or select it manually yourself. You can use the
8099@code{set language} command for either purpose. On startup, @value{GDBN}
8100defaults to setting the language automatically. The working language is
8101used to determine how expressions you type are interpreted, how values
8102are printed, etc.
8103
8104In addition to the working language, every source file that
8105@value{GDBN} knows about has its own working language. For some object
8106file formats, the compiler might indicate which language a particular
8107source file is in. However, most of the time @value{GDBN} infers the
8108language from the name of the file. The language of a source file
b37052ae 8109controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 8110show each frame appropriately for its own language. There is no way to
d4f3574e
SS
8111set the language of a source file from within @value{GDBN}, but you can
8112set the language associated with a filename extension. @xref{Show, ,
8113Displaying the language}.
c906108c
SS
8114
8115This is most commonly a problem when you use a program, such
5d161b24 8116as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
8117another language. In that case, make the
8118program use @code{#line} directives in its C output; that way
8119@value{GDBN} will know the correct language of the source code of the original
8120program, and will display that source code, not the generated C code.
8121
8122@menu
8123* Filenames:: Filename extensions and languages.
8124* Manually:: Setting the working language manually
8125* Automatically:: Having @value{GDBN} infer the source language
8126@end menu
8127
6d2ebf8b 8128@node Filenames
c906108c
SS
8129@subsection List of filename extensions and languages
8130
8131If a source file name ends in one of the following extensions, then
8132@value{GDBN} infers that its language is the one indicated.
8133
8134@table @file
e07c999f
PH
8135@item .ada
8136@itemx .ads
8137@itemx .adb
8138@itemx .a
8139Ada source file.
c906108c
SS
8140
8141@item .c
8142C source file
8143
8144@item .C
8145@itemx .cc
8146@itemx .cp
8147@itemx .cpp
8148@itemx .cxx
8149@itemx .c++
b37052ae 8150C@t{++} source file
c906108c 8151
b37303ee
AF
8152@item .m
8153Objective-C source file
8154
c906108c
SS
8155@item .f
8156@itemx .F
8157Fortran source file
8158
c906108c
SS
8159@item .mod
8160Modula-2 source file
c906108c
SS
8161
8162@item .s
8163@itemx .S
8164Assembler source file. This actually behaves almost like C, but
8165@value{GDBN} does not skip over function prologues when stepping.
8166@end table
8167
8168In addition, you may set the language associated with a filename
8169extension. @xref{Show, , Displaying the language}.
8170
6d2ebf8b 8171@node Manually
c906108c
SS
8172@subsection Setting the working language
8173
8174If you allow @value{GDBN} to set the language automatically,
8175expressions are interpreted the same way in your debugging session and
8176your program.
8177
8178@kindex set language
8179If you wish, you may set the language manually. To do this, issue the
8180command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 8181a language, such as
c906108c 8182@code{c} or @code{modula-2}.
c906108c
SS
8183For a list of the supported languages, type @samp{set language}.
8184
c906108c
SS
8185Setting the language manually prevents @value{GDBN} from updating the working
8186language automatically. This can lead to confusion if you try
8187to debug a program when the working language is not the same as the
8188source language, when an expression is acceptable to both
8189languages---but means different things. For instance, if the current
8190source file were written in C, and @value{GDBN} was parsing Modula-2, a
8191command such as:
8192
474c8240 8193@smallexample
c906108c 8194print a = b + c
474c8240 8195@end smallexample
c906108c
SS
8196
8197@noindent
8198might not have the effect you intended. In C, this means to add
8199@code{b} and @code{c} and place the result in @code{a}. The result
8200printed would be the value of @code{a}. In Modula-2, this means to compare
8201@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 8202
6d2ebf8b 8203@node Automatically
c906108c
SS
8204@subsection Having @value{GDBN} infer the source language
8205
8206To have @value{GDBN} set the working language automatically, use
8207@samp{set language local} or @samp{set language auto}. @value{GDBN}
8208then infers the working language. That is, when your program stops in a
8209frame (usually by encountering a breakpoint), @value{GDBN} sets the
8210working language to the language recorded for the function in that
8211frame. If the language for a frame is unknown (that is, if the function
8212or block corresponding to the frame was defined in a source file that
8213does not have a recognized extension), the current working language is
8214not changed, and @value{GDBN} issues a warning.
8215
8216This may not seem necessary for most programs, which are written
8217entirely in one source language. However, program modules and libraries
8218written in one source language can be used by a main program written in
8219a different source language. Using @samp{set language auto} in this
8220case frees you from having to set the working language manually.
8221
6d2ebf8b 8222@node Show
c906108c 8223@section Displaying the language
c906108c
SS
8224
8225The following commands help you find out which language is the
8226working language, and also what language source files were written in.
8227
c906108c
SS
8228@table @code
8229@item show language
9c16f35a 8230@kindex show language
c906108c
SS
8231Display the current working language. This is the
8232language you can use with commands such as @code{print} to
8233build and compute expressions that may involve variables in your program.
8234
8235@item info frame
4644b6e3 8236@kindex info frame@r{, show the source language}
5d161b24 8237Display the source language for this frame. This language becomes the
c906108c 8238working language if you use an identifier from this frame.
5d161b24 8239@xref{Frame Info, ,Information about a frame}, to identify the other
c906108c
SS
8240information listed here.
8241
8242@item info source
4644b6e3 8243@kindex info source@r{, show the source language}
c906108c 8244Display the source language of this source file.
5d161b24 8245@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
8246information listed here.
8247@end table
8248
8249In unusual circumstances, you may have source files with extensions
8250not in the standard list. You can then set the extension associated
8251with a language explicitly:
8252
c906108c 8253@table @code
09d4efe1 8254@item set extension-language @var{ext} @var{language}
9c16f35a 8255@kindex set extension-language
09d4efe1
EZ
8256Tell @value{GDBN} that source files with extension @var{ext} are to be
8257assumed as written in the source language @var{language}.
c906108c
SS
8258
8259@item info extensions
9c16f35a 8260@kindex info extensions
c906108c
SS
8261List all the filename extensions and the associated languages.
8262@end table
8263
6d2ebf8b 8264@node Checks
c906108c
SS
8265@section Type and range checking
8266
8267@quotation
8268@emph{Warning:} In this release, the @value{GDBN} commands for type and range
8269checking are included, but they do not yet have any effect. This
8270section documents the intended facilities.
8271@end quotation
8272@c FIXME remove warning when type/range code added
8273
8274Some languages are designed to guard you against making seemingly common
8275errors through a series of compile- and run-time checks. These include
8276checking the type of arguments to functions and operators, and making
8277sure mathematical overflows are caught at run time. Checks such as
8278these help to ensure a program's correctness once it has been compiled
8279by eliminating type mismatches, and providing active checks for range
8280errors when your program is running.
8281
8282@value{GDBN} can check for conditions like the above if you wish.
9c16f35a
EZ
8283Although @value{GDBN} does not check the statements in your program,
8284it can check expressions entered directly into @value{GDBN} for
8285evaluation via the @code{print} command, for example. As with the
8286working language, @value{GDBN} can also decide whether or not to check
8287automatically based on your program's source language.
8288@xref{Supported languages, ,Supported languages}, for the default
8289settings of supported languages.
c906108c
SS
8290
8291@menu
8292* Type Checking:: An overview of type checking
8293* Range Checking:: An overview of range checking
8294@end menu
8295
8296@cindex type checking
8297@cindex checks, type
6d2ebf8b 8298@node Type Checking
c906108c
SS
8299@subsection An overview of type checking
8300
8301Some languages, such as Modula-2, are strongly typed, meaning that the
8302arguments to operators and functions have to be of the correct type,
8303otherwise an error occurs. These checks prevent type mismatch
8304errors from ever causing any run-time problems. For example,
8305
8306@smallexample
83071 + 2 @result{} 3
8308@exdent but
8309@error{} 1 + 2.3
8310@end smallexample
8311
8312The second example fails because the @code{CARDINAL} 1 is not
8313type-compatible with the @code{REAL} 2.3.
8314
5d161b24
DB
8315For the expressions you use in @value{GDBN} commands, you can tell the
8316@value{GDBN} type checker to skip checking;
8317to treat any mismatches as errors and abandon the expression;
8318or to only issue warnings when type mismatches occur,
c906108c
SS
8319but evaluate the expression anyway. When you choose the last of
8320these, @value{GDBN} evaluates expressions like the second example above, but
8321also issues a warning.
8322
5d161b24
DB
8323Even if you turn type checking off, there may be other reasons
8324related to type that prevent @value{GDBN} from evaluating an expression.
8325For instance, @value{GDBN} does not know how to add an @code{int} and
8326a @code{struct foo}. These particular type errors have nothing to do
8327with the language in use, and usually arise from expressions, such as
c906108c
SS
8328the one described above, which make little sense to evaluate anyway.
8329
8330Each language defines to what degree it is strict about type. For
8331instance, both Modula-2 and C require the arguments to arithmetical
8332operators to be numbers. In C, enumerated types and pointers can be
8333represented as numbers, so that they are valid arguments to mathematical
9c16f35a 8334operators. @xref{Supported languages, ,Supported languages}, for further
c906108c
SS
8335details on specific languages.
8336
8337@value{GDBN} provides some additional commands for controlling the type checker:
8338
c906108c
SS
8339@kindex set check type
8340@kindex show check type
8341@table @code
8342@item set check type auto
8343Set type checking on or off based on the current working language.
9c16f35a 8344@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8345each language.
8346
8347@item set check type on
8348@itemx set check type off
8349Set type checking on or off, overriding the default setting for the
8350current working language. Issue a warning if the setting does not
8351match the language default. If any type mismatches occur in
d4f3574e 8352evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
8353message and aborts evaluation of the expression.
8354
8355@item set check type warn
8356Cause the type checker to issue warnings, but to always attempt to
8357evaluate the expression. Evaluating the expression may still
8358be impossible for other reasons. For example, @value{GDBN} cannot add
8359numbers and structures.
8360
8361@item show type
5d161b24 8362Show the current setting of the type checker, and whether or not @value{GDBN}
c906108c
SS
8363is setting it automatically.
8364@end table
8365
8366@cindex range checking
8367@cindex checks, range
6d2ebf8b 8368@node Range Checking
c906108c
SS
8369@subsection An overview of range checking
8370
8371In some languages (such as Modula-2), it is an error to exceed the
8372bounds of a type; this is enforced with run-time checks. Such range
8373checking is meant to ensure program correctness by making sure
8374computations do not overflow, or indices on an array element access do
8375not exceed the bounds of the array.
8376
8377For expressions you use in @value{GDBN} commands, you can tell
8378@value{GDBN} to treat range errors in one of three ways: ignore them,
8379always treat them as errors and abandon the expression, or issue
8380warnings but evaluate the expression anyway.
8381
8382A range error can result from numerical overflow, from exceeding an
8383array index bound, or when you type a constant that is not a member
8384of any type. Some languages, however, do not treat overflows as an
8385error. In many implementations of C, mathematical overflow causes the
8386result to ``wrap around'' to lower values---for example, if @var{m} is
8387the largest integer value, and @var{s} is the smallest, then
8388
474c8240 8389@smallexample
c906108c 8390@var{m} + 1 @result{} @var{s}
474c8240 8391@end smallexample
c906108c
SS
8392
8393This, too, is specific to individual languages, and in some cases
9c16f35a 8394specific to individual compilers or machines. @xref{Supported languages, ,
c906108c
SS
8395Supported languages}, for further details on specific languages.
8396
8397@value{GDBN} provides some additional commands for controlling the range checker:
8398
c906108c
SS
8399@kindex set check range
8400@kindex show check range
8401@table @code
8402@item set check range auto
8403Set range checking on or off based on the current working language.
9c16f35a 8404@xref{Supported languages, ,Supported languages}, for the default settings for
c906108c
SS
8405each language.
8406
8407@item set check range on
8408@itemx set check range off
8409Set range checking on or off, overriding the default setting for the
8410current working language. A warning is issued if the setting does not
c3f6f71d
JM
8411match the language default. If a range error occurs and range checking is on,
8412then a message is printed and evaluation of the expression is aborted.
c906108c
SS
8413
8414@item set check range warn
8415Output messages when the @value{GDBN} range checker detects a range error,
8416but attempt to evaluate the expression anyway. Evaluating the
8417expression may still be impossible for other reasons, such as accessing
8418memory that the process does not own (a typical example from many Unix
8419systems).
8420
8421@item show range
8422Show the current setting of the range checker, and whether or not it is
8423being set automatically by @value{GDBN}.
8424@end table
c906108c 8425
9c16f35a 8426@node Supported languages
c906108c 8427@section Supported languages
c906108c 8428
9c16f35a
EZ
8429@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
8430assembly, Modula-2, and Ada.
cce74817 8431@c This is false ...
c906108c
SS
8432Some @value{GDBN} features may be used in expressions regardless of the
8433language you use: the @value{GDBN} @code{@@} and @code{::} operators,
8434and the @samp{@{type@}addr} construct (@pxref{Expressions,
8435,Expressions}) can be used with the constructs of any supported
8436language.
8437
8438The following sections detail to what degree each source language is
8439supported by @value{GDBN}. These sections are not meant to be language
8440tutorials or references, but serve only as a reference guide to what the
8441@value{GDBN} expression parser accepts, and what input and output
8442formats should look like for different languages. There are many good
8443books written on each of these languages; please look to these for a
8444language reference or tutorial.
8445
c906108c 8446@menu
b37303ee 8447* C:: C and C@t{++}
b383017d 8448* Objective-C:: Objective-C
09d4efe1 8449* Fortran:: Fortran
9c16f35a 8450* Pascal:: Pascal
b37303ee 8451* Modula-2:: Modula-2
e07c999f 8452* Ada:: Ada
c906108c
SS
8453@end menu
8454
6d2ebf8b 8455@node C
b37052ae 8456@subsection C and C@t{++}
7a292a7a 8457
b37052ae
EZ
8458@cindex C and C@t{++}
8459@cindex expressions in C or C@t{++}
c906108c 8460
b37052ae 8461Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
8462to both languages. Whenever this is the case, we discuss those languages
8463together.
8464
41afff9a
EZ
8465@cindex C@t{++}
8466@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
8467@cindex @sc{gnu} C@t{++}
8468The C@t{++} debugging facilities are jointly implemented by the C@t{++}
8469compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
8470effectively, you must compile your C@t{++} programs with a supported
8471C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
8472compiler (@code{aCC}).
8473
0179ffac
DC
8474For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
8475format; if it doesn't work on your system, try the stabs+ debugging
8476format. You can select those formats explicitly with the @code{g++}
8477command-line options @option{-gdwarf-2} and @option{-gstabs+}.
8478@xref{Debugging Options,,Options for Debugging Your Program or @sc{gnu}
8479CC, gcc.info, Using @sc{gnu} CC}.
c906108c 8480
c906108c 8481@menu
b37052ae
EZ
8482* C Operators:: C and C@t{++} operators
8483* C Constants:: C and C@t{++} constants
8484* C plus plus expressions:: C@t{++} expressions
8485* C Defaults:: Default settings for C and C@t{++}
8486* C Checks:: C and C@t{++} type and range checks
c906108c 8487* Debugging C:: @value{GDBN} and C
b37052ae 8488* Debugging C plus plus:: @value{GDBN} features for C@t{++}
c906108c 8489@end menu
c906108c 8490
6d2ebf8b 8491@node C Operators
b37052ae 8492@subsubsection C and C@t{++} operators
7a292a7a 8493
b37052ae 8494@cindex C and C@t{++} operators
c906108c
SS
8495
8496Operators must be defined on values of specific types. For instance,
8497@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 8498often defined on groups of types.
c906108c 8499
b37052ae 8500For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
8501
8502@itemize @bullet
53a5351d 8503
c906108c 8504@item
c906108c 8505@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 8506specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
8507
8508@item
d4f3574e
SS
8509@emph{Floating-point types} include @code{float}, @code{double}, and
8510@code{long double} (if supported by the target platform).
c906108c
SS
8511
8512@item
53a5351d 8513@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
8514
8515@item
8516@emph{Scalar types} include all of the above.
53a5351d 8517
c906108c
SS
8518@end itemize
8519
8520@noindent
8521The following operators are supported. They are listed here
8522in order of increasing precedence:
8523
8524@table @code
8525@item ,
8526The comma or sequencing operator. Expressions in a comma-separated list
8527are evaluated from left to right, with the result of the entire
8528expression being the last expression evaluated.
8529
8530@item =
8531Assignment. The value of an assignment expression is the value
8532assigned. Defined on scalar types.
8533
8534@item @var{op}=
8535Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
8536and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 8537@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
8538@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
8539@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
8540
8541@item ?:
8542The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
8543of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
8544integral type.
8545
8546@item ||
8547Logical @sc{or}. Defined on integral types.
8548
8549@item &&
8550Logical @sc{and}. Defined on integral types.
8551
8552@item |
8553Bitwise @sc{or}. Defined on integral types.
8554
8555@item ^
8556Bitwise exclusive-@sc{or}. Defined on integral types.
8557
8558@item &
8559Bitwise @sc{and}. Defined on integral types.
8560
8561@item ==@r{, }!=
8562Equality and inequality. Defined on scalar types. The value of these
8563expressions is 0 for false and non-zero for true.
8564
8565@item <@r{, }>@r{, }<=@r{, }>=
8566Less than, greater than, less than or equal, greater than or equal.
8567Defined on scalar types. The value of these expressions is 0 for false
8568and non-zero for true.
8569
8570@item <<@r{, }>>
8571left shift, and right shift. Defined on integral types.
8572
8573@item @@
8574The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
8575
8576@item +@r{, }-
8577Addition and subtraction. Defined on integral types, floating-point types and
8578pointer types.
8579
8580@item *@r{, }/@r{, }%
8581Multiplication, division, and modulus. Multiplication and division are
8582defined on integral and floating-point types. Modulus is defined on
8583integral types.
8584
8585@item ++@r{, }--
8586Increment and decrement. When appearing before a variable, the
8587operation is performed before the variable is used in an expression;
8588when appearing after it, the variable's value is used before the
8589operation takes place.
8590
8591@item *
8592Pointer dereferencing. Defined on pointer types. Same precedence as
8593@code{++}.
8594
8595@item &
8596Address operator. Defined on variables. Same precedence as @code{++}.
8597
b37052ae
EZ
8598For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
8599allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
c906108c 8600(or, if you prefer, simply @samp{&&@var{ref}}) to examine the address
b37052ae 8601where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 8602stored.
c906108c
SS
8603
8604@item -
8605Negative. Defined on integral and floating-point types. Same
8606precedence as @code{++}.
8607
8608@item !
8609Logical negation. Defined on integral types. Same precedence as
8610@code{++}.
8611
8612@item ~
8613Bitwise complement operator. Defined on integral types. Same precedence as
8614@code{++}.
8615
8616
8617@item .@r{, }->
8618Structure member, and pointer-to-structure member. For convenience,
8619@value{GDBN} regards the two as equivalent, choosing whether to dereference a
8620pointer based on the stored type information.
8621Defined on @code{struct} and @code{union} data.
8622
c906108c
SS
8623@item .*@r{, }->*
8624Dereferences of pointers to members.
c906108c
SS
8625
8626@item []
8627Array indexing. @code{@var{a}[@var{i}]} is defined as
8628@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
8629
8630@item ()
8631Function parameter list. Same precedence as @code{->}.
8632
c906108c 8633@item ::
b37052ae 8634C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 8635and @code{class} types.
c906108c
SS
8636
8637@item ::
7a292a7a
SS
8638Doubled colons also represent the @value{GDBN} scope operator
8639(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
8640above.
c906108c
SS
8641@end table
8642
c906108c
SS
8643If an operator is redefined in the user code, @value{GDBN} usually
8644attempts to invoke the redefined version instead of using the operator's
8645predefined meaning.
c906108c 8646
c906108c 8647@menu
5d161b24 8648* C Constants::
c906108c
SS
8649@end menu
8650
6d2ebf8b 8651@node C Constants
b37052ae 8652@subsubsection C and C@t{++} constants
c906108c 8653
b37052ae 8654@cindex C and C@t{++} constants
c906108c 8655
b37052ae 8656@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 8657following ways:
c906108c
SS
8658
8659@itemize @bullet
8660@item
8661Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
8662specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
8663by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
8664@samp{l}, specifying that the constant should be treated as a
8665@code{long} value.
8666
8667@item
8668Floating point constants are a sequence of digits, followed by a decimal
8669point, followed by a sequence of digits, and optionally followed by an
8670exponent. An exponent is of the form:
8671@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
8672sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
8673A floating-point constant may also end with a letter @samp{f} or
8674@samp{F}, specifying that the constant should be treated as being of
8675the @code{float} (as opposed to the default @code{double}) type; or with
8676a letter @samp{l} or @samp{L}, which specifies a @code{long double}
8677constant.
c906108c
SS
8678
8679@item
8680Enumerated constants consist of enumerated identifiers, or their
8681integral equivalents.
8682
8683@item
8684Character constants are a single character surrounded by single quotes
8685(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 8686(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
8687be represented by a letter or by @dfn{escape sequences}, which are of
8688the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
8689of the character's ordinal value; or of the form @samp{\@var{x}}, where
8690@samp{@var{x}} is a predefined special character---for example,
8691@samp{\n} for newline.
8692
8693@item
96a2c332
SS
8694String constants are a sequence of character constants surrounded by
8695double quotes (@code{"}). Any valid character constant (as described
8696above) may appear. Double quotes within the string must be preceded by
8697a backslash, so for instance @samp{"a\"b'c"} is a string of five
8698characters.
c906108c
SS
8699
8700@item
8701Pointer constants are an integral value. You can also write pointers
8702to constants using the C operator @samp{&}.
8703
8704@item
8705Array constants are comma-separated lists surrounded by braces @samp{@{}
8706and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
8707integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
8708and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
8709@end itemize
8710
c906108c 8711@menu
5d161b24
DB
8712* C plus plus expressions::
8713* C Defaults::
8714* C Checks::
c906108c 8715
5d161b24 8716* Debugging C::
c906108c
SS
8717@end menu
8718
6d2ebf8b 8719@node C plus plus expressions
b37052ae
EZ
8720@subsubsection C@t{++} expressions
8721
8722@cindex expressions in C@t{++}
8723@value{GDBN} expression handling can interpret most C@t{++} expressions.
8724
0179ffac
DC
8725@cindex debugging C@t{++} programs
8726@cindex C@t{++} compilers
8727@cindex debug formats and C@t{++}
8728@cindex @value{NGCC} and C@t{++}
c906108c 8729@quotation
b37052ae 8730@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
0179ffac
DC
8731proper compiler and the proper debug format. Currently, @value{GDBN}
8732works best when debugging C@t{++} code that is compiled with
8733@value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
8734@option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
8735stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
8736stabs+ as their default debug format, so you usually don't need to
8737specify a debug format explicitly. Other compilers and/or debug formats
8738are likely to work badly or not at all when using @value{GDBN} to debug
8739C@t{++} code.
c906108c 8740@end quotation
c906108c
SS
8741
8742@enumerate
8743
8744@cindex member functions
8745@item
8746Member function calls are allowed; you can use expressions like
8747
474c8240 8748@smallexample
c906108c 8749count = aml->GetOriginal(x, y)
474c8240 8750@end smallexample
c906108c 8751
41afff9a 8752@vindex this@r{, inside C@t{++} member functions}
b37052ae 8753@cindex namespace in C@t{++}
c906108c
SS
8754@item
8755While a member function is active (in the selected stack frame), your
8756expressions have the same namespace available as the member function;
8757that is, @value{GDBN} allows implicit references to the class instance
b37052ae 8758pointer @code{this} following the same rules as C@t{++}.
c906108c 8759
c906108c 8760@cindex call overloaded functions
d4f3574e 8761@cindex overloaded functions, calling
b37052ae 8762@cindex type conversions in C@t{++}
c906108c
SS
8763@item
8764You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 8765call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
8766perform overload resolution involving user-defined type conversions,
8767calls to constructors, or instantiations of templates that do not exist
8768in the program. It also cannot handle ellipsis argument lists or
8769default arguments.
8770
8771It does perform integral conversions and promotions, floating-point
8772promotions, arithmetic conversions, pointer conversions, conversions of
8773class objects to base classes, and standard conversions such as those of
8774functions or arrays to pointers; it requires an exact match on the
8775number of function arguments.
8776
8777Overload resolution is always performed, unless you have specified
8778@code{set overload-resolution off}. @xref{Debugging C plus plus,
b37052ae 8779,@value{GDBN} features for C@t{++}}.
c906108c 8780
d4f3574e 8781You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
8782explicit function signature to call an overloaded function, as in
8783@smallexample
8784p 'foo(char,int)'('x', 13)
8785@end smallexample
d4f3574e 8786
c906108c 8787The @value{GDBN} command-completion facility can simplify this;
d4f3574e 8788see @ref{Completion, ,Command completion}.
c906108c 8789
c906108c
SS
8790@cindex reference declarations
8791@item
b37052ae
EZ
8792@value{GDBN} understands variables declared as C@t{++} references; you can use
8793them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
8794dereferenced.
8795
8796In the parameter list shown when @value{GDBN} displays a frame, the values of
8797reference variables are not displayed (unlike other variables); this
8798avoids clutter, since references are often used for large structures.
8799The @emph{address} of a reference variable is always shown, unless
8800you have specified @samp{set print address off}.
8801
8802@item
b37052ae 8803@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
8804expressions can use it just as expressions in your program do. Since
8805one scope may be defined in another, you can use @code{::} repeatedly if
8806necessary, for example in an expression like
8807@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 8808resolving name scope by reference to source files, in both C and C@t{++}
c906108c
SS
8809debugging (@pxref{Variables, ,Program variables}).
8810@end enumerate
8811
b37052ae 8812In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
53a5351d
JM
8813calling virtual functions correctly, printing out virtual bases of
8814objects, calling functions in a base subobject, casting objects, and
8815invoking user-defined operators.
c906108c 8816
6d2ebf8b 8817@node C Defaults
b37052ae 8818@subsubsection C and C@t{++} defaults
7a292a7a 8819
b37052ae 8820@cindex C and C@t{++} defaults
c906108c 8821
c906108c
SS
8822If you allow @value{GDBN} to set type and range checking automatically, they
8823both default to @code{off} whenever the working language changes to
b37052ae 8824C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 8825selects the working language.
c906108c
SS
8826
8827If you allow @value{GDBN} to set the language automatically, it
8828recognizes source files whose names end with @file{.c}, @file{.C}, or
8829@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 8830these files, it sets the working language to C or C@t{++}.
c906108c
SS
8831@xref{Automatically, ,Having @value{GDBN} infer the source language},
8832for further details.
8833
c906108c
SS
8834@c Type checking is (a) primarily motivated by Modula-2, and (b)
8835@c unimplemented. If (b) changes, it might make sense to let this node
8836@c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
7a292a7a 8837
6d2ebf8b 8838@node C Checks
b37052ae 8839@subsubsection C and C@t{++} type and range checks
7a292a7a 8840
b37052ae 8841@cindex C and C@t{++} checks
c906108c 8842
b37052ae 8843By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
c906108c
SS
8844is not used. However, if you turn type checking on, @value{GDBN}
8845considers two variables type equivalent if:
8846
8847@itemize @bullet
8848@item
8849The two variables are structured and have the same structure, union, or
8850enumerated tag.
8851
8852@item
8853The two variables have the same type name, or types that have been
8854declared equivalent through @code{typedef}.
8855
8856@ignore
8857@c leaving this out because neither J Gilmore nor R Pesch understand it.
8858@c FIXME--beers?
8859@item
8860The two @code{struct}, @code{union}, or @code{enum} variables are
8861declared in the same declaration. (Note: this may not be true for all C
8862compilers.)
8863@end ignore
8864@end itemize
8865
8866Range checking, if turned on, is done on mathematical operations. Array
8867indices are not checked, since they are often used to index a pointer
8868that is not itself an array.
c906108c 8869
6d2ebf8b 8870@node Debugging C
c906108c 8871@subsubsection @value{GDBN} and C
c906108c
SS
8872
8873The @code{set print union} and @code{show print union} commands apply to
8874the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
8875inside a @code{struct} or @code{class} is also printed. Otherwise, it
8876appears as @samp{@{...@}}.
c906108c
SS
8877
8878The @code{@@} operator aids in the debugging of dynamic arrays, formed
8879with pointers and a memory allocation function. @xref{Expressions,
8880,Expressions}.
8881
c906108c 8882@menu
5d161b24 8883* Debugging C plus plus::
c906108c
SS
8884@end menu
8885
6d2ebf8b 8886@node Debugging C plus plus
b37052ae 8887@subsubsection @value{GDBN} features for C@t{++}
c906108c 8888
b37052ae 8889@cindex commands for C@t{++}
7a292a7a 8890
b37052ae
EZ
8891Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
8892designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
8893
8894@table @code
8895@cindex break in overloaded functions
8896@item @r{breakpoint menus}
8897When you want a breakpoint in a function whose name is overloaded,
8898@value{GDBN} breakpoint menus help you specify which function definition
8899you want. @xref{Breakpoint Menus,,Breakpoint menus}.
8900
b37052ae 8901@cindex overloading in C@t{++}
c906108c
SS
8902@item rbreak @var{regex}
8903Setting breakpoints using regular expressions is helpful for setting
8904breakpoints on overloaded functions that are not members of any special
8905classes.
8906@xref{Set Breaks, ,Setting breakpoints}.
8907
b37052ae 8908@cindex C@t{++} exception handling
c906108c
SS
8909@item catch throw
8910@itemx catch catch
b37052ae 8911Debug C@t{++} exception handling using these commands. @xref{Set
c906108c
SS
8912Catchpoints, , Setting catchpoints}.
8913
8914@cindex inheritance
8915@item ptype @var{typename}
8916Print inheritance relationships as well as other information for type
8917@var{typename}.
8918@xref{Symbols, ,Examining the Symbol Table}.
8919
b37052ae 8920@cindex C@t{++} symbol display
c906108c
SS
8921@item set print demangle
8922@itemx show print demangle
8923@itemx set print asm-demangle
8924@itemx show print asm-demangle
b37052ae
EZ
8925Control whether C@t{++} symbols display in their source form, both when
8926displaying code as C@t{++} source and when displaying disassemblies.
c906108c
SS
8927@xref{Print Settings, ,Print settings}.
8928
8929@item set print object
8930@itemx show print object
8931Choose whether to print derived (actual) or declared types of objects.
8932@xref{Print Settings, ,Print settings}.
8933
8934@item set print vtbl
8935@itemx show print vtbl
8936Control the format for printing virtual function tables.
8937@xref{Print Settings, ,Print settings}.
c906108c 8938(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8939ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8940
8941@kindex set overload-resolution
d4f3574e 8942@cindex overloaded functions, overload resolution
c906108c 8943@item set overload-resolution on
b37052ae 8944Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
8945is on. For overloaded functions, @value{GDBN} evaluates the arguments
8946and searches for a function whose signature matches the argument types,
b37052ae 8947using the standard C@t{++} conversion rules (see @ref{C plus plus expressions, ,C@t{++}
d4f3574e 8948expressions}, for details). If it cannot find a match, it emits a
c906108c
SS
8949message.
8950
8951@item set overload-resolution off
b37052ae 8952Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
8953overloaded functions that are not class member functions, @value{GDBN}
8954chooses the first function of the specified name that it finds in the
8955symbol table, whether or not its arguments are of the correct type. For
8956overloaded functions that are class member functions, @value{GDBN}
8957searches for a function whose signature @emph{exactly} matches the
8958argument types.
c906108c 8959
9c16f35a
EZ
8960@kindex show overload-resolution
8961@item show overload-resolution
8962Show the current setting of overload resolution.
8963
c906108c
SS
8964@item @r{Overloaded symbol names}
8965You can specify a particular definition of an overloaded symbol, using
b37052ae 8966the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
8967@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
8968also use the @value{GDBN} command-line word completion facilities to list the
8969available choices, or to finish the type list for you.
8970@xref{Completion,, Command completion}, for details on how to do this.
8971@end table
c906108c 8972
b37303ee
AF
8973@node Objective-C
8974@subsection Objective-C
8975
8976@cindex Objective-C
8977This section provides information about some commands and command
721c2651
EZ
8978options that are useful for debugging Objective-C code. See also
8979@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
8980few more commands specific to Objective-C support.
b37303ee
AF
8981
8982@menu
b383017d
RM
8983* Method Names in Commands::
8984* The Print Command with Objective-C::
b37303ee
AF
8985@end menu
8986
8987@node Method Names in Commands, The Print Command with Objective-C, Objective-C, Objective-C
8988@subsubsection Method Names in Commands
8989
8990The following commands have been extended to accept Objective-C method
8991names as line specifications:
8992
8993@kindex clear@r{, and Objective-C}
8994@kindex break@r{, and Objective-C}
8995@kindex info line@r{, and Objective-C}
8996@kindex jump@r{, and Objective-C}
8997@kindex list@r{, and Objective-C}
8998@itemize
8999@item @code{clear}
9000@item @code{break}
9001@item @code{info line}
9002@item @code{jump}
9003@item @code{list}
9004@end itemize
9005
9006A fully qualified Objective-C method name is specified as
9007
9008@smallexample
9009-[@var{Class} @var{methodName}]
9010@end smallexample
9011
c552b3bb
JM
9012where the minus sign is used to indicate an instance method and a
9013plus sign (not shown) is used to indicate a class method. The class
9014name @var{Class} and method name @var{methodName} are enclosed in
9015brackets, similar to the way messages are specified in Objective-C
9016source code. For example, to set a breakpoint at the @code{create}
9017instance method of class @code{Fruit} in the program currently being
9018debugged, enter:
b37303ee
AF
9019
9020@smallexample
9021break -[Fruit create]
9022@end smallexample
9023
9024To list ten program lines around the @code{initialize} class method,
9025enter:
9026
9027@smallexample
9028list +[NSText initialize]
9029@end smallexample
9030
c552b3bb
JM
9031In the current version of @value{GDBN}, the plus or minus sign is
9032required. In future versions of @value{GDBN}, the plus or minus
9033sign will be optional, but you can use it to narrow the search. It
9034is also possible to specify just a method name:
b37303ee
AF
9035
9036@smallexample
9037break create
9038@end smallexample
9039
9040You must specify the complete method name, including any colons. If
9041your program's source files contain more than one @code{create} method,
9042you'll be presented with a numbered list of classes that implement that
9043method. Indicate your choice by number, or type @samp{0} to exit if
9044none apply.
9045
9046As another example, to clear a breakpoint established at the
9047@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9048
9049@smallexample
9050clear -[NSWindow makeKeyAndOrderFront:]
9051@end smallexample
9052
9053@node The Print Command with Objective-C
9054@subsubsection The Print Command With Objective-C
721c2651 9055@cindex Objective-C, print objects
c552b3bb
JM
9056@kindex print-object
9057@kindex po @r{(@code{print-object})}
b37303ee 9058
c552b3bb 9059The print command has also been extended to accept methods. For example:
b37303ee
AF
9060
9061@smallexample
c552b3bb 9062print -[@var{object} hash]
b37303ee
AF
9063@end smallexample
9064
9065@cindex print an Objective-C object description
c552b3bb
JM
9066@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9067@noindent
9068will tell @value{GDBN} to send the @code{hash} message to @var{object}
9069and print the result. Also, an additional command has been added,
9070@code{print-object} or @code{po} for short, which is meant to print
9071the description of an object. However, this command may only work
9072with certain Objective-C libraries that have a particular hook
9073function, @code{_NSPrintForDebugger}, defined.
b37303ee 9074
09d4efe1
EZ
9075@node Fortran
9076@subsection Fortran
9077@cindex Fortran-specific support in @value{GDBN}
9078
9079@table @code
9080@cindex @code{COMMON} blocks, Fortran
9081@kindex info common
9082@item info common @r{[}@var{common-name}@r{]}
9083This command prints the values contained in the Fortran @code{COMMON}
9084block whose name is @var{common-name}. With no argument, the names of
9085all @code{COMMON} blocks visible at current program location are
9086printed.
9087@end table
9088
a8f24a35
EZ
9089Fortran symbols are usually case-insensitive, so @value{GDBN} by
9090default uses case-insensitive matches for Fortran symbols. You can
9091change that with the @samp{set case-insensitive} command, see
9092@ref{Symbols}, for the details.
9093
9c16f35a
EZ
9094@node Pascal
9095@subsection Pascal
9096
9097@cindex Pascal support in @value{GDBN}, limitations
9098Debugging Pascal programs which use sets, subranges, file variables, or
9099nested functions does not currently work. @value{GDBN} does not support
9100entering expressions, printing values, or similar features using Pascal
9101syntax.
9102
9103The Pascal-specific command @code{set print pascal_static-members}
9104controls whether static members of Pascal objects are displayed.
9105@xref{Print Settings, pascal_static-members}.
9106
09d4efe1 9107@node Modula-2
c906108c 9108@subsection Modula-2
7a292a7a 9109
d4f3574e 9110@cindex Modula-2, @value{GDBN} support
c906108c
SS
9111
9112The extensions made to @value{GDBN} to support Modula-2 only support
9113output from the @sc{gnu} Modula-2 compiler (which is currently being
9114developed). Other Modula-2 compilers are not currently supported, and
9115attempting to debug executables produced by them is most likely
9116to give an error as @value{GDBN} reads in the executable's symbol
9117table.
9118
9119@cindex expressions in Modula-2
9120@menu
9121* M2 Operators:: Built-in operators
9122* Built-In Func/Proc:: Built-in functions and procedures
9123* M2 Constants:: Modula-2 constants
9124* M2 Defaults:: Default settings for Modula-2
9125* Deviations:: Deviations from standard Modula-2
9126* M2 Checks:: Modula-2 type and range checks
9127* M2 Scope:: The scope operators @code{::} and @code{.}
9128* GDB/M2:: @value{GDBN} and Modula-2
9129@end menu
9130
6d2ebf8b 9131@node M2 Operators
c906108c
SS
9132@subsubsection Operators
9133@cindex Modula-2 operators
9134
9135Operators must be defined on values of specific types. For instance,
9136@code{+} is defined on numbers, but not on structures. Operators are
9137often defined on groups of types. For the purposes of Modula-2, the
9138following definitions hold:
9139
9140@itemize @bullet
9141
9142@item
9143@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9144their subranges.
9145
9146@item
9147@emph{Character types} consist of @code{CHAR} and its subranges.
9148
9149@item
9150@emph{Floating-point types} consist of @code{REAL}.
9151
9152@item
9153@emph{Pointer types} consist of anything declared as @code{POINTER TO
9154@var{type}}.
9155
9156@item
9157@emph{Scalar types} consist of all of the above.
9158
9159@item
9160@emph{Set types} consist of @code{SET} and @code{BITSET} types.
9161
9162@item
9163@emph{Boolean types} consist of @code{BOOLEAN}.
9164@end itemize
9165
9166@noindent
9167The following operators are supported, and appear in order of
9168increasing precedence:
9169
9170@table @code
9171@item ,
9172Function argument or array index separator.
9173
9174@item :=
9175Assignment. The value of @var{var} @code{:=} @var{value} is
9176@var{value}.
9177
9178@item <@r{, }>
9179Less than, greater than on integral, floating-point, or enumerated
9180types.
9181
9182@item <=@r{, }>=
96a2c332 9183Less than or equal to, greater than or equal to
c906108c
SS
9184on integral, floating-point and enumerated types, or set inclusion on
9185set types. Same precedence as @code{<}.
9186
9187@item =@r{, }<>@r{, }#
9188Equality and two ways of expressing inequality, valid on scalar types.
9189Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9190available for inequality, since @code{#} conflicts with the script
9191comment character.
9192
9193@item IN
9194Set membership. Defined on set types and the types of their members.
9195Same precedence as @code{<}.
9196
9197@item OR
9198Boolean disjunction. Defined on boolean types.
9199
9200@item AND@r{, }&
d4f3574e 9201Boolean conjunction. Defined on boolean types.
c906108c
SS
9202
9203@item @@
9204The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9205
9206@item +@r{, }-
9207Addition and subtraction on integral and floating-point types, or union
9208and difference on set types.
9209
9210@item *
9211Multiplication on integral and floating-point types, or set intersection
9212on set types.
9213
9214@item /
9215Division on floating-point types, or symmetric set difference on set
9216types. Same precedence as @code{*}.
9217
9218@item DIV@r{, }MOD
9219Integer division and remainder. Defined on integral types. Same
9220precedence as @code{*}.
9221
9222@item -
9223Negative. Defined on @code{INTEGER} and @code{REAL} data.
9224
9225@item ^
9226Pointer dereferencing. Defined on pointer types.
9227
9228@item NOT
9229Boolean negation. Defined on boolean types. Same precedence as
9230@code{^}.
9231
9232@item .
9233@code{RECORD} field selector. Defined on @code{RECORD} data. Same
9234precedence as @code{^}.
9235
9236@item []
9237Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
9238
9239@item ()
9240Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
9241as @code{^}.
9242
9243@item ::@r{, }.
9244@value{GDBN} and Modula-2 scope operators.
9245@end table
9246
9247@quotation
9248@emph{Warning:} Sets and their operations are not yet supported, so @value{GDBN}
9249treats the use of the operator @code{IN}, or the use of operators
9250@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
9251@code{<=}, and @code{>=} on sets as an error.
9252@end quotation
9253
cb51c4e0 9254
6d2ebf8b 9255@node Built-In Func/Proc
c906108c 9256@subsubsection Built-in functions and procedures
cb51c4e0 9257@cindex Modula-2 built-ins
c906108c
SS
9258
9259Modula-2 also makes available several built-in procedures and functions.
9260In describing these, the following metavariables are used:
9261
9262@table @var
9263
9264@item a
9265represents an @code{ARRAY} variable.
9266
9267@item c
9268represents a @code{CHAR} constant or variable.
9269
9270@item i
9271represents a variable or constant of integral type.
9272
9273@item m
9274represents an identifier that belongs to a set. Generally used in the
9275same function with the metavariable @var{s}. The type of @var{s} should
9276be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
9277
9278@item n
9279represents a variable or constant of integral or floating-point type.
9280
9281@item r
9282represents a variable or constant of floating-point type.
9283
9284@item t
9285represents a type.
9286
9287@item v
9288represents a variable.
9289
9290@item x
9291represents a variable or constant of one of many types. See the
9292explanation of the function for details.
9293@end table
9294
9295All Modula-2 built-in procedures also return a result, described below.
9296
9297@table @code
9298@item ABS(@var{n})
9299Returns the absolute value of @var{n}.
9300
9301@item CAP(@var{c})
9302If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 9303equivalent, otherwise it returns its argument.
c906108c
SS
9304
9305@item CHR(@var{i})
9306Returns the character whose ordinal value is @var{i}.
9307
9308@item DEC(@var{v})
c3f6f71d 9309Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9310
9311@item DEC(@var{v},@var{i})
9312Decrements the value in the variable @var{v} by @var{i}. Returns the
9313new value.
9314
9315@item EXCL(@var{m},@var{s})
9316Removes the element @var{m} from the set @var{s}. Returns the new
9317set.
9318
9319@item FLOAT(@var{i})
9320Returns the floating point equivalent of the integer @var{i}.
9321
9322@item HIGH(@var{a})
9323Returns the index of the last member of @var{a}.
9324
9325@item INC(@var{v})
c3f6f71d 9326Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
9327
9328@item INC(@var{v},@var{i})
9329Increments the value in the variable @var{v} by @var{i}. Returns the
9330new value.
9331
9332@item INCL(@var{m},@var{s})
9333Adds the element @var{m} to the set @var{s} if it is not already
9334there. Returns the new set.
9335
9336@item MAX(@var{t})
9337Returns the maximum value of the type @var{t}.
9338
9339@item MIN(@var{t})
9340Returns the minimum value of the type @var{t}.
9341
9342@item ODD(@var{i})
9343Returns boolean TRUE if @var{i} is an odd number.
9344
9345@item ORD(@var{x})
9346Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
9347value of a character is its @sc{ascii} value (on machines supporting the
9348@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
9349integral, character and enumerated types.
9350
9351@item SIZE(@var{x})
9352Returns the size of its argument. @var{x} can be a variable or a type.
9353
9354@item TRUNC(@var{r})
9355Returns the integral part of @var{r}.
9356
9357@item VAL(@var{t},@var{i})
9358Returns the member of the type @var{t} whose ordinal value is @var{i}.
9359@end table
9360
9361@quotation
9362@emph{Warning:} Sets and their operations are not yet supported, so
9363@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
9364an error.
9365@end quotation
9366
9367@cindex Modula-2 constants
6d2ebf8b 9368@node M2 Constants
c906108c
SS
9369@subsubsection Constants
9370
9371@value{GDBN} allows you to express the constants of Modula-2 in the following
9372ways:
9373
9374@itemize @bullet
9375
9376@item
9377Integer constants are simply a sequence of digits. When used in an
9378expression, a constant is interpreted to be type-compatible with the
9379rest of the expression. Hexadecimal integers are specified by a
9380trailing @samp{H}, and octal integers by a trailing @samp{B}.
9381
9382@item
9383Floating point constants appear as a sequence of digits, followed by a
9384decimal point and another sequence of digits. An optional exponent can
9385then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
9386@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
9387digits of the floating point constant must be valid decimal (base 10)
9388digits.
9389
9390@item
9391Character constants consist of a single character enclosed by a pair of
9392like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 9393also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
9394followed by a @samp{C}.
9395
9396@item
9397String constants consist of a sequence of characters enclosed by a
9398pair of like quotes, either single (@code{'}) or double (@code{"}).
9399Escape sequences in the style of C are also allowed. @xref{C
b37052ae 9400Constants, ,C and C@t{++} constants}, for a brief explanation of escape
c906108c
SS
9401sequences.
9402
9403@item
9404Enumerated constants consist of an enumerated identifier.
9405
9406@item
9407Boolean constants consist of the identifiers @code{TRUE} and
9408@code{FALSE}.
9409
9410@item
9411Pointer constants consist of integral values only.
9412
9413@item
9414Set constants are not yet supported.
9415@end itemize
9416
6d2ebf8b 9417@node M2 Defaults
c906108c
SS
9418@subsubsection Modula-2 defaults
9419@cindex Modula-2 defaults
9420
9421If type and range checking are set automatically by @value{GDBN}, they
9422both default to @code{on} whenever the working language changes to
d4f3574e 9423Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
9424selected the working language.
9425
9426If you allow @value{GDBN} to set the language automatically, then entering
9427code compiled from a file whose name ends with @file{.mod} sets the
d4f3574e 9428working language to Modula-2. @xref{Automatically, ,Having @value{GDBN} set
c906108c
SS
9429the language automatically}, for further details.
9430
6d2ebf8b 9431@node Deviations
c906108c
SS
9432@subsubsection Deviations from standard Modula-2
9433@cindex Modula-2, deviations from
9434
9435A few changes have been made to make Modula-2 programs easier to debug.
9436This is done primarily via loosening its type strictness:
9437
9438@itemize @bullet
9439@item
9440Unlike in standard Modula-2, pointer constants can be formed by
9441integers. This allows you to modify pointer variables during
9442debugging. (In standard Modula-2, the actual address contained in a
9443pointer variable is hidden from you; it can only be modified
9444through direct assignment to another pointer variable or expression that
9445returned a pointer.)
9446
9447@item
9448C escape sequences can be used in strings and characters to represent
9449non-printable characters. @value{GDBN} prints out strings with these
9450escape sequences embedded. Single non-printable characters are
9451printed using the @samp{CHR(@var{nnn})} format.
9452
9453@item
9454The assignment operator (@code{:=}) returns the value of its right-hand
9455argument.
9456
9457@item
9458All built-in procedures both modify @emph{and} return their argument.
9459@end itemize
9460
6d2ebf8b 9461@node M2 Checks
c906108c
SS
9462@subsubsection Modula-2 type and range checks
9463@cindex Modula-2 checks
9464
9465@quotation
9466@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
9467range checking.
9468@end quotation
9469@c FIXME remove warning when type/range checks added
9470
9471@value{GDBN} considers two Modula-2 variables type equivalent if:
9472
9473@itemize @bullet
9474@item
9475They are of types that have been declared equivalent via a @code{TYPE
9476@var{t1} = @var{t2}} statement
9477
9478@item
9479They have been declared on the same line. (Note: This is true of the
9480@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
9481@end itemize
9482
9483As long as type checking is enabled, any attempt to combine variables
9484whose types are not equivalent is an error.
9485
9486Range checking is done on all mathematical operations, assignment, array
9487index bounds, and all built-in functions and procedures.
9488
6d2ebf8b 9489@node M2 Scope
c906108c
SS
9490@subsubsection The scope operators @code{::} and @code{.}
9491@cindex scope
41afff9a 9492@cindex @code{.}, Modula-2 scope operator
c906108c
SS
9493@cindex colon, doubled as scope operator
9494@ifinfo
41afff9a 9495@vindex colon-colon@r{, in Modula-2}
c906108c
SS
9496@c Info cannot handle :: but TeX can.
9497@end ifinfo
9498@iftex
41afff9a 9499@vindex ::@r{, in Modula-2}
c906108c
SS
9500@end iftex
9501
9502There are a few subtle differences between the Modula-2 scope operator
9503(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
9504similar syntax:
9505
474c8240 9506@smallexample
c906108c
SS
9507
9508@var{module} . @var{id}
9509@var{scope} :: @var{id}
474c8240 9510@end smallexample
c906108c
SS
9511
9512@noindent
9513where @var{scope} is the name of a module or a procedure,
9514@var{module} the name of a module, and @var{id} is any declared
9515identifier within your program, except another module.
9516
9517Using the @code{::} operator makes @value{GDBN} search the scope
9518specified by @var{scope} for the identifier @var{id}. If it is not
9519found in the specified scope, then @value{GDBN} searches all scopes
9520enclosing the one specified by @var{scope}.
9521
9522Using the @code{.} operator makes @value{GDBN} search the current scope for
9523the identifier specified by @var{id} that was imported from the
9524definition module specified by @var{module}. With this operator, it is
9525an error if the identifier @var{id} was not imported from definition
9526module @var{module}, or if @var{id} is not an identifier in
9527@var{module}.
9528
6d2ebf8b 9529@node GDB/M2
c906108c
SS
9530@subsubsection @value{GDBN} and Modula-2
9531
9532Some @value{GDBN} commands have little use when debugging Modula-2 programs.
9533Five subcommands of @code{set print} and @code{show print} apply
b37052ae 9534specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 9535@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 9536apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
9537analogue in Modula-2.
9538
9539The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 9540with any language, is not useful with Modula-2. Its
c906108c 9541intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 9542created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 9543address can be specified by an integral constant, the construct
d4f3574e 9544@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
9545
9546@cindex @code{#} in Modula-2
9547In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
9548interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 9549
e07c999f
PH
9550@node Ada
9551@subsection Ada
9552@cindex Ada
9553
9554The extensions made to @value{GDBN} for Ada only support
9555output from the @sc{gnu} Ada (GNAT) compiler.
9556Other Ada compilers are not currently supported, and
9557attempting to debug executables produced by them is most likely
9558to be difficult.
9559
9560
9561@cindex expressions in Ada
9562@menu
9563* Ada Mode Intro:: General remarks on the Ada syntax
9564 and semantics supported by Ada mode
9565 in @value{GDBN}.
9566* Omissions from Ada:: Restrictions on the Ada expression syntax.
9567* Additions to Ada:: Extensions of the Ada expression syntax.
9568* Stopping Before Main Program:: Debugging the program during elaboration.
9569* Ada Glitches:: Known peculiarities of Ada mode.
9570@end menu
9571
9572@node Ada Mode Intro
9573@subsubsection Introduction
9574@cindex Ada mode, general
9575
9576The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
9577syntax, with some extensions.
9578The philosophy behind the design of this subset is
9579
9580@itemize @bullet
9581@item
9582That @value{GDBN} should provide basic literals and access to operations for
9583arithmetic, dereferencing, field selection, indexing, and subprogram calls,
9584leaving more sophisticated computations to subprograms written into the
9585program (which therefore may be called from @value{GDBN}).
9586
9587@item
9588That type safety and strict adherence to Ada language restrictions
9589are not particularly important to the @value{GDBN} user.
9590
9591@item
9592That brevity is important to the @value{GDBN} user.
9593@end itemize
9594
9595Thus, for brevity, the debugger acts as if there were
9596implicit @code{with} and @code{use} clauses in effect for all user-written
9597packages, making it unnecessary to fully qualify most names with
9598their packages, regardless of context. Where this causes ambiguity,
9599@value{GDBN} asks the user's intent.
9600
9601The debugger will start in Ada mode if it detects an Ada main program.
9602As for other languages, it will enter Ada mode when stopped in a program that
9603was translated from an Ada source file.
9604
9605While in Ada mode, you may use `@t{--}' for comments. This is useful
9606mostly for documenting command files. The standard @value{GDBN} comment
9607(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
9608middle (to allow based literals).
9609
9610The debugger supports limited overloading. Given a subprogram call in which
9611the function symbol has multiple definitions, it will use the number of
9612actual parameters and some information about their types to attempt to narrow
9613the set of definitions. It also makes very limited use of context, preferring
9614procedures to functions in the context of the @code{call} command, and
9615functions to procedures elsewhere.
9616
9617@node Omissions from Ada
9618@subsubsection Omissions from Ada
9619@cindex Ada, omissions from
9620
9621Here are the notable omissions from the subset:
9622
9623@itemize @bullet
9624@item
9625Only a subset of the attributes are supported:
9626
9627@itemize @minus
9628@item
9629@t{'First}, @t{'Last}, and @t{'Length}
9630 on array objects (not on types and subtypes).
9631
9632@item
9633@t{'Min} and @t{'Max}.
9634
9635@item
9636@t{'Pos} and @t{'Val}.
9637
9638@item
9639@t{'Tag}.
9640
9641@item
9642@t{'Range} on array objects (not subtypes), but only as the right
9643operand of the membership (@code{in}) operator.
9644
9645@item
9646@t{'Access}, @t{'Unchecked_Access}, and
9647@t{'Unrestricted_Access} (a GNAT extension).
9648
9649@item
9650@t{'Address}.
9651@end itemize
9652
9653@item
9654The names in
9655@code{Characters.Latin_1} are not available and
9656concatenation is not implemented. Thus, escape characters in strings are
9657not currently available.
9658
9659@item
9660Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
9661equality of representations. They will generally work correctly
9662for strings and arrays whose elements have integer or enumeration types.
9663They may not work correctly for arrays whose element
9664types have user-defined equality, for arrays of real values
9665(in particular, IEEE-conformant floating point, because of negative
9666zeroes and NaNs), and for arrays whose elements contain unused bits with
9667indeterminate values.
9668
9669@item
9670The other component-by-component array operations (@code{and}, @code{or},
9671@code{xor}, @code{not}, and relational tests other than equality)
9672are not implemented.
9673
9674@item
9675There are no record or array aggregates.
9676
9677@item
9678Calls to dispatching subprograms are not implemented.
9679
9680@item
9681The overloading algorithm is much more limited (i.e., less selective)
9682than that of real Ada. It makes only limited use of the context in which a subexpression
9683appears to resolve its meaning, and it is much looser in its rules for allowing
9684type matches. As a result, some function calls will be ambiguous, and the user
9685will be asked to choose the proper resolution.
9686
9687@item
9688The @code{new} operator is not implemented.
9689
9690@item
9691Entry calls are not implemented.
9692
9693@item
9694Aside from printing, arithmetic operations on the native VAX floating-point
9695formats are not supported.
9696
9697@item
9698It is not possible to slice a packed array.
9699@end itemize
9700
9701@node Additions to Ada
9702@subsubsection Additions to Ada
9703@cindex Ada, deviations from
9704
9705As it does for other languages, @value{GDBN} makes certain generic
9706extensions to Ada (@pxref{Expressions}):
9707
9708@itemize @bullet
9709@item
9710If the expression @var{E} is a variable residing in memory
9711(typically a local variable or array element) and @var{N} is
9712a positive integer, then @code{@var{E}@@@var{N}} displays the values of
9713@var{E} and the @var{N}-1 adjacent variables following it in memory as an array.
9714In Ada, this operator is generally not necessary, since its prime use
9715is in displaying parts of an array, and slicing will usually do this in Ada.
9716However, there are occasional uses when debugging programs
9717in which certain debugging information has been optimized away.
9718
9719@item
9720@code{@var{B}::@var{var}} means ``the variable named @var{var} that appears
9721in function or file @var{B}.'' When @var{B} is a file name, you must typically
9722surround it in single quotes.
9723
9724@item
9725The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
9726@var{type} that appears at address @var{addr}.''
9727
9728@item
9729A name starting with @samp{$} is a convenience variable
9730(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
9731@end itemize
9732
9733In addition, @value{GDBN} provides a few other shortcuts and outright additions specific
9734to Ada:
9735
9736@itemize @bullet
9737@item
9738The assignment statement is allowed as an expression, returning
9739its right-hand operand as its value. Thus, you may enter
9740
9741@smallexample
9742set x := y + 3
9743print A(tmp := y + 1)
9744@end smallexample
9745
9746@item
9747The semicolon is allowed as an ``operator,'' returning as its value
9748the value of its right-hand operand.
9749This allows, for example,
9750complex conditional breaks:
9751
9752@smallexample
9753break f
9754condition 1 (report(i); k += 1; A(k) > 100)
9755@end smallexample
9756
9757@item
9758Rather than use catenation and symbolic character names to introduce special
9759characters into strings, one may instead use a special bracket notation,
9760which is also used to print strings. A sequence of characters of the form
9761@samp{["@var{XX}"]} within a string or character literal denotes the
9762(single) character whose numeric encoding is @var{XX} in hexadecimal. The
9763sequence of characters @samp{["""]} also denotes a single quotation mark
9764in strings. For example,
9765@smallexample
9766 "One line.["0a"]Next line.["0a"]"
9767@end smallexample
9768@noindent
9769contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF}) after each
9770period.
9771
9772@item
9773The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
9774@t{'Max} is optional (and is ignored in any case). For example, it is valid
9775to write
9776
9777@smallexample
9778print 'max(x, y)
9779@end smallexample
9780
9781@item
9782When printing arrays, @value{GDBN} uses positional notation when the
9783array has a lower bound of 1, and uses a modified named notation otherwise.
9784For example, a one-dimensional array of three integers with a lower bound of 3 might print as
9785
9786@smallexample
9787(3 => 10, 17, 1)
9788@end smallexample
9789
9790@noindent
9791That is, in contrast to valid Ada, only the first component has a @code{=>}
9792clause.
9793
9794@item
9795You may abbreviate attributes in expressions with any unique,
9796multi-character subsequence of
9797their names (an exact match gets preference).
9798For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
9799in place of @t{a'length}.
9800
9801@item
9802@cindex quoting Ada internal identifiers
9803Since Ada is case-insensitive, the debugger normally maps identifiers you type
9804to lower case. The GNAT compiler uses upper-case characters for
9805some of its internal identifiers, which are normally of no interest to users.
9806For the rare occasions when you actually have to look at them,
9807enclose them in angle brackets to avoid the lower-case mapping.
9808For example,
9809@smallexample
9810@value{GDBP} print <JMPBUF_SAVE>[0]
9811@end smallexample
9812
9813@item
9814Printing an object of class-wide type or dereferencing an
9815access-to-class-wide value will display all the components of the object's
9816specific type (as indicated by its run-time tag). Likewise, component
9817selection on such a value will operate on the specific type of the
9818object.
9819
9820@end itemize
9821
9822@node Stopping Before Main Program
9823@subsubsection Stopping at the Very Beginning
9824
9825@cindex breakpointing Ada elaboration code
9826It is sometimes necessary to debug the program during elaboration, and
9827before reaching the main procedure.
9828As defined in the Ada Reference
9829Manual, the elaboration code is invoked from a procedure called
9830@code{adainit}. To run your program up to the beginning of
9831elaboration, simply use the following two commands:
9832@code{tbreak adainit} and @code{run}.
9833
9834@node Ada Glitches
9835@subsubsection Known Peculiarities of Ada Mode
9836@cindex Ada, problems
9837
9838Besides the omissions listed previously (@pxref{Omissions from Ada}),
9839we know of several problems with and limitations of Ada mode in
9840@value{GDBN},
9841some of which will be fixed with planned future releases of the debugger
9842and the GNU Ada compiler.
9843
9844@itemize @bullet
9845@item
9846Currently, the debugger
9847has insufficient information to determine whether certain pointers represent
9848pointers to objects or the objects themselves.
9849Thus, the user may have to tack an extra @code{.all} after an expression
9850to get it printed properly.
9851
9852@item
9853Static constants that the compiler chooses not to materialize as objects in
9854storage are invisible to the debugger.
9855
9856@item
9857Named parameter associations in function argument lists are ignored (the
9858argument lists are treated as positional).
9859
9860@item
9861Many useful library packages are currently invisible to the debugger.
9862
9863@item
9864Fixed-point arithmetic, conversions, input, and output is carried out using
9865floating-point arithmetic, and may give results that only approximate those on
9866the host machine.
9867
9868@item
9869The type of the @t{'Address} attribute may not be @code{System.Address}.
9870
9871@item
9872The GNAT compiler never generates the prefix @code{Standard} for any of
9873the standard symbols defined by the Ada language. @value{GDBN} knows about
9874this: it will strip the prefix from names when you use it, and will never
9875look for a name you have so qualified among local symbols, nor match against
9876symbols in other packages or subprograms. If you have
9877defined entities anywhere in your program other than parameters and
9878local variables whose simple names match names in @code{Standard},
9879GNAT's lack of qualification here can cause confusion. When this happens,
9880you can usually resolve the confusion
9881by qualifying the problematic names with package
9882@code{Standard} explicitly.
9883@end itemize
9884
4e562065
JB
9885@node Unsupported languages
9886@section Unsupported languages
9887
9888@cindex unsupported languages
9889@cindex minimal language
9890In addition to the other fully-supported programming languages,
9891@value{GDBN} also provides a pseudo-language, called @code{minimal}.
9892It does not represent a real programming language, but provides a set
9893of capabilities close to what the C or assembly languages provide.
9894This should allow most simple operations to be performed while debugging
9895an application that uses a language currently not supported by @value{GDBN}.
9896
9897If the language is set to @code{auto}, @value{GDBN} will automatically
9898select this language if the current frame corresponds to an unsupported
9899language.
9900
6d2ebf8b 9901@node Symbols
c906108c
SS
9902@chapter Examining the Symbol Table
9903
d4f3574e 9904The commands described in this chapter allow you to inquire about the
c906108c
SS
9905symbols (names of variables, functions and types) defined in your
9906program. This information is inherent in the text of your program and
9907does not change as your program executes. @value{GDBN} finds it in your
9908program's symbol table, in the file indicated when you started @value{GDBN}
9909(@pxref{File Options, ,Choosing files}), or by one of the
9910file-management commands (@pxref{Files, ,Commands to specify files}).
9911
9912@cindex symbol names
9913@cindex names of symbols
9914@cindex quoting names
9915Occasionally, you may need to refer to symbols that contain unusual
9916characters, which @value{GDBN} ordinarily treats as word delimiters. The
9917most frequent case is in referring to static variables in other
9918source files (@pxref{Variables,,Program variables}). File names
9919are recorded in object files as debugging symbols, but @value{GDBN} would
9920ordinarily parse a typical file name, like @file{foo.c}, as the three words
9921@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
9922@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
9923
474c8240 9924@smallexample
c906108c 9925p 'foo.c'::x
474c8240 9926@end smallexample
c906108c
SS
9927
9928@noindent
9929looks up the value of @code{x} in the scope of the file @file{foo.c}.
9930
9931@table @code
a8f24a35
EZ
9932@cindex case-insensitive symbol names
9933@cindex case sensitivity in symbol names
9934@kindex set case-sensitive
9935@item set case-sensitive on
9936@itemx set case-sensitive off
9937@itemx set case-sensitive auto
9938Normally, when @value{GDBN} looks up symbols, it matches their names
9939with case sensitivity determined by the current source language.
9940Occasionally, you may wish to control that. The command @code{set
9941case-sensitive} lets you do that by specifying @code{on} for
9942case-sensitive matches or @code{off} for case-insensitive ones. If
9943you specify @code{auto}, case sensitivity is reset to the default
9944suitable for the source language. The default is case-sensitive
9945matches for all languages except for Fortran, for which the default is
9946case-insensitive matches.
9947
9c16f35a
EZ
9948@kindex show case-sensitive
9949@item show case-sensitive
a8f24a35
EZ
9950This command shows the current setting of case sensitivity for symbols
9951lookups.
9952
c906108c 9953@kindex info address
b37052ae 9954@cindex address of a symbol
c906108c
SS
9955@item info address @var{symbol}
9956Describe where the data for @var{symbol} is stored. For a register
9957variable, this says which register it is kept in. For a non-register
9958local variable, this prints the stack-frame offset at which the variable
9959is always stored.
9960
9961Note the contrast with @samp{print &@var{symbol}}, which does not work
9962at all for a register variable, and for a stack local variable prints
9963the exact address of the current instantiation of the variable.
9964
3d67e040 9965@kindex info symbol
b37052ae 9966@cindex symbol from address
9c16f35a 9967@cindex closest symbol and offset for an address
3d67e040
EZ
9968@item info symbol @var{addr}
9969Print the name of a symbol which is stored at the address @var{addr}.
9970If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
9971nearest symbol and an offset from it:
9972
474c8240 9973@smallexample
3d67e040
EZ
9974(@value{GDBP}) info symbol 0x54320
9975_initialize_vx + 396 in section .text
474c8240 9976@end smallexample
3d67e040
EZ
9977
9978@noindent
9979This is the opposite of the @code{info address} command. You can use
9980it to find out the name of a variable or a function given its address.
9981
c906108c 9982@kindex whatis
d4f3574e
SS
9983@item whatis @var{expr}
9984Print the data type of expression @var{expr}. @var{expr} is not
c906108c
SS
9985actually evaluated, and any side-effecting operations (such as
9986assignments or function calls) inside it do not take place.
9987@xref{Expressions, ,Expressions}.
9988
9989@item whatis
9990Print the data type of @code{$}, the last value in the value history.
9991
9992@kindex ptype
9993@item ptype @var{typename}
9994Print a description of data type @var{typename}. @var{typename} may be
7a292a7a
SS
9995the name of a type, or for C code it may have the form @samp{class
9996@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
9997@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 9998
d4f3574e 9999@item ptype @var{expr}
c906108c 10000@itemx ptype
d4f3574e 10001Print a description of the type of expression @var{expr}. @code{ptype}
c906108c
SS
10002differs from @code{whatis} by printing a detailed description, instead
10003of just the name of the type.
10004
10005For example, for this variable declaration:
10006
474c8240 10007@smallexample
c906108c 10008struct complex @{double real; double imag;@} v;
474c8240 10009@end smallexample
c906108c
SS
10010
10011@noindent
10012the two commands give this output:
10013
474c8240 10014@smallexample
c906108c
SS
10015@group
10016(@value{GDBP}) whatis v
10017type = struct complex
10018(@value{GDBP}) ptype v
10019type = struct complex @{
10020 double real;
10021 double imag;
10022@}
10023@end group
474c8240 10024@end smallexample
c906108c
SS
10025
10026@noindent
10027As with @code{whatis}, using @code{ptype} without an argument refers to
10028the type of @code{$}, the last value in the value history.
10029
ab1adacd
EZ
10030@cindex incomplete type
10031Sometimes, programs use opaque data types or incomplete specifications
10032of complex data structure. If the debug information included in the
10033program does not allow @value{GDBN} to display a full declaration of
10034the data type, it will say @samp{<incomplete type>}. For example,
10035given these declarations:
10036
10037@smallexample
10038 struct foo;
10039 struct foo *fooptr;
10040@end smallexample
10041
10042@noindent
10043but no definition for @code{struct foo} itself, @value{GDBN} will say:
10044
10045@smallexample
10046 (gdb) ptype foo
10047 $1 = <incomplete type>
10048@end smallexample
10049
10050@noindent
10051``Incomplete type'' is C terminology for data types that are not
10052completely specified.
10053
c906108c
SS
10054@kindex info types
10055@item info types @var{regexp}
10056@itemx info types
09d4efe1
EZ
10057Print a brief description of all types whose names match the regular
10058expression @var{regexp} (or all types in your program, if you supply
10059no argument). Each complete typename is matched as though it were a
10060complete line; thus, @samp{i type value} gives information on all
10061types in your program whose names include the string @code{value}, but
10062@samp{i type ^value$} gives information only on types whose complete
10063name is @code{value}.
c906108c
SS
10064
10065This command differs from @code{ptype} in two ways: first, like
10066@code{whatis}, it does not print a detailed description; second, it
10067lists all source files where a type is defined.
10068
b37052ae
EZ
10069@kindex info scope
10070@cindex local variables
09d4efe1 10071@item info scope @var{location}
b37052ae 10072List all the variables local to a particular scope. This command
09d4efe1
EZ
10073accepts a @var{location} argument---a function name, a source line, or
10074an address preceded by a @samp{*}, and prints all the variables local
10075to the scope defined by that location. For example:
b37052ae
EZ
10076
10077@smallexample
10078(@value{GDBP}) @b{info scope command_line_handler}
10079Scope for command_line_handler:
10080Symbol rl is an argument at stack/frame offset 8, length 4.
10081Symbol linebuffer is in static storage at address 0x150a18, length 4.
10082Symbol linelength is in static storage at address 0x150a1c, length 4.
10083Symbol p is a local variable in register $esi, length 4.
10084Symbol p1 is a local variable in register $ebx, length 4.
10085Symbol nline is a local variable in register $edx, length 4.
10086Symbol repeat is a local variable at frame offset -8, length 4.
10087@end smallexample
10088
f5c37c66
EZ
10089@noindent
10090This command is especially useful for determining what data to collect
10091during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
10092collect}.
10093
c906108c
SS
10094@kindex info source
10095@item info source
919d772c
JB
10096Show information about the current source file---that is, the source file for
10097the function containing the current point of execution:
10098@itemize @bullet
10099@item
10100the name of the source file, and the directory containing it,
10101@item
10102the directory it was compiled in,
10103@item
10104its length, in lines,
10105@item
10106which programming language it is written in,
10107@item
10108whether the executable includes debugging information for that file, and
10109if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
10110@item
10111whether the debugging information includes information about
10112preprocessor macros.
10113@end itemize
10114
c906108c
SS
10115
10116@kindex info sources
10117@item info sources
10118Print the names of all source files in your program for which there is
10119debugging information, organized into two lists: files whose symbols
10120have already been read, and files whose symbols will be read when needed.
10121
10122@kindex info functions
10123@item info functions
10124Print the names and data types of all defined functions.
10125
10126@item info functions @var{regexp}
10127Print the names and data types of all defined functions
10128whose names contain a match for regular expression @var{regexp}.
10129Thus, @samp{info fun step} finds all functions whose names
10130include @code{step}; @samp{info fun ^step} finds those whose names
b383017d
RM
10131start with @code{step}. If a function name contains characters
10132that conflict with the regular expression language (eg.
1c5dfdad 10133@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
10134
10135@kindex info variables
10136@item info variables
10137Print the names and data types of all variables that are declared
6ca652b0 10138outside of functions (i.e.@: excluding local variables).
c906108c
SS
10139
10140@item info variables @var{regexp}
10141Print the names and data types of all variables (except for local
10142variables) whose names contain a match for regular expression
10143@var{regexp}.
10144
b37303ee 10145@kindex info classes
721c2651 10146@cindex Objective-C, classes and selectors
b37303ee
AF
10147@item info classes
10148@itemx info classes @var{regexp}
10149Display all Objective-C classes in your program, or
10150(with the @var{regexp} argument) all those matching a particular regular
10151expression.
10152
10153@kindex info selectors
10154@item info selectors
10155@itemx info selectors @var{regexp}
10156Display all Objective-C selectors in your program, or
10157(with the @var{regexp} argument) all those matching a particular regular
10158expression.
10159
c906108c
SS
10160@ignore
10161This was never implemented.
10162@kindex info methods
10163@item info methods
10164@itemx info methods @var{regexp}
10165The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
10166methods within C@t{++} program, or (with the @var{regexp} argument) a
10167specific set of methods found in the various C@t{++} classes. Many
10168C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
10169from the @code{ptype} command can be overwhelming and hard to use. The
10170@code{info-methods} command filters the methods, printing only those
10171which match the regular-expression @var{regexp}.
10172@end ignore
10173
c906108c
SS
10174@cindex reloading symbols
10175Some systems allow individual object files that make up your program to
7a292a7a
SS
10176be replaced without stopping and restarting your program. For example,
10177in VxWorks you can simply recompile a defective object file and keep on
10178running. If you are running on one of these systems, you can allow
10179@value{GDBN} to reload the symbols for automatically relinked modules:
c906108c
SS
10180
10181@table @code
10182@kindex set symbol-reloading
10183@item set symbol-reloading on
10184Replace symbol definitions for the corresponding source file when an
10185object file with a particular name is seen again.
10186
10187@item set symbol-reloading off
6d2ebf8b
SS
10188Do not replace symbol definitions when encountering object files of the
10189same name more than once. This is the default state; if you are not
10190running on a system that permits automatic relinking of modules, you
10191should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
10192may discard symbols when linking large programs, that may contain
10193several modules (from different directories or libraries) with the same
10194name.
c906108c
SS
10195
10196@kindex show symbol-reloading
10197@item show symbol-reloading
10198Show the current @code{on} or @code{off} setting.
10199@end table
c906108c 10200
9c16f35a 10201@cindex opaque data types
c906108c
SS
10202@kindex set opaque-type-resolution
10203@item set opaque-type-resolution on
10204Tell @value{GDBN} to resolve opaque types. An opaque type is a type
10205declared as a pointer to a @code{struct}, @code{class}, or
10206@code{union}---for example, @code{struct MyType *}---that is used in one
10207source file although the full declaration of @code{struct MyType} is in
10208another source file. The default is on.
10209
10210A change in the setting of this subcommand will not take effect until
10211the next time symbols for a file are loaded.
10212
10213@item set opaque-type-resolution off
10214Tell @value{GDBN} not to resolve opaque types. In this case, the type
10215is printed as follows:
10216@smallexample
10217@{<no data fields>@}
10218@end smallexample
10219
10220@kindex show opaque-type-resolution
10221@item show opaque-type-resolution
10222Show whether opaque types are resolved or not.
c906108c
SS
10223
10224@kindex maint print symbols
10225@cindex symbol dump
10226@kindex maint print psymbols
10227@cindex partial symbol dump
10228@item maint print symbols @var{filename}
10229@itemx maint print psymbols @var{filename}
10230@itemx maint print msymbols @var{filename}
10231Write a dump of debugging symbol data into the file @var{filename}.
10232These commands are used to debug the @value{GDBN} symbol-reading code. Only
10233symbols with debugging data are included. If you use @samp{maint print
10234symbols}, @value{GDBN} includes all the symbols for which it has already
10235collected full details: that is, @var{filename} reflects symbols for
10236only those files whose symbols @value{GDBN} has read. You can use the
10237command @code{info sources} to find out which files these are. If you
10238use @samp{maint print psymbols} instead, the dump shows information about
10239symbols that @value{GDBN} only knows partially---that is, symbols defined in
10240files that @value{GDBN} has skimmed, but not yet read completely. Finally,
10241@samp{maint print msymbols} dumps just the minimal symbol information
10242required for each object file from which @value{GDBN} has read some symbols.
10243@xref{Files, ,Commands to specify files}, for a discussion of how
10244@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 10245
5e7b2f39
JB
10246@kindex maint info symtabs
10247@kindex maint info psymtabs
44ea7b70
JB
10248@cindex listing @value{GDBN}'s internal symbol tables
10249@cindex symbol tables, listing @value{GDBN}'s internal
10250@cindex full symbol tables, listing @value{GDBN}'s internal
10251@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
10252@item maint info symtabs @r{[} @var{regexp} @r{]}
10253@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
10254
10255List the @code{struct symtab} or @code{struct partial_symtab}
10256structures whose names match @var{regexp}. If @var{regexp} is not
10257given, list them all. The output includes expressions which you can
10258copy into a @value{GDBN} debugging this one to examine a particular
10259structure in more detail. For example:
10260
10261@smallexample
5e7b2f39 10262(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
10263@{ objfile /home/gnu/build/gdb/gdb
10264 ((struct objfile *) 0x82e69d0)
b383017d 10265 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10266 ((struct partial_symtab *) 0x8474b10)
10267 readin no
10268 fullname (null)
10269 text addresses 0x814d3c8 -- 0x8158074
10270 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
10271 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
10272 dependencies (none)
10273 @}
10274@}
5e7b2f39 10275(@value{GDBP}) maint info symtabs
44ea7b70
JB
10276(@value{GDBP})
10277@end smallexample
10278@noindent
10279We see that there is one partial symbol table whose filename contains
10280the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
10281and we see that @value{GDBN} has not read in any symtabs yet at all.
10282If we set a breakpoint on a function, that will cause @value{GDBN} to
10283read the symtab for the compilation unit containing that function:
10284
10285@smallexample
10286(@value{GDBP}) break dwarf2_psymtab_to_symtab
10287Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
10288line 1574.
5e7b2f39 10289(@value{GDBP}) maint info symtabs
b383017d 10290@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 10291 ((struct objfile *) 0x82e69d0)
b383017d 10292 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
10293 ((struct symtab *) 0x86c1f38)
10294 dirname (null)
10295 fullname (null)
10296 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
10297 debugformat DWARF 2
10298 @}
10299@}
b383017d 10300(@value{GDBP})
44ea7b70 10301@end smallexample
c906108c
SS
10302@end table
10303
44ea7b70 10304
6d2ebf8b 10305@node Altering
c906108c
SS
10306@chapter Altering Execution
10307
10308Once you think you have found an error in your program, you might want to
10309find out for certain whether correcting the apparent error would lead to
10310correct results in the rest of the run. You can find the answer by
10311experiment, using the @value{GDBN} features for altering execution of the
10312program.
10313
10314For example, you can store new values into variables or memory
7a292a7a
SS
10315locations, give your program a signal, restart it at a different
10316address, or even return prematurely from a function.
c906108c
SS
10317
10318@menu
10319* Assignment:: Assignment to variables
10320* Jumping:: Continuing at a different address
c906108c 10321* Signaling:: Giving your program a signal
c906108c
SS
10322* Returning:: Returning from a function
10323* Calling:: Calling your program's functions
10324* Patching:: Patching your program
10325@end menu
10326
6d2ebf8b 10327@node Assignment
c906108c
SS
10328@section Assignment to variables
10329
10330@cindex assignment
10331@cindex setting variables
10332To alter the value of a variable, evaluate an assignment expression.
10333@xref{Expressions, ,Expressions}. For example,
10334
474c8240 10335@smallexample
c906108c 10336print x=4
474c8240 10337@end smallexample
c906108c
SS
10338
10339@noindent
10340stores the value 4 into the variable @code{x}, and then prints the
5d161b24 10341value of the assignment expression (which is 4).
c906108c
SS
10342@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
10343information on operators in supported languages.
c906108c
SS
10344
10345@kindex set variable
10346@cindex variables, setting
10347If you are not interested in seeing the value of the assignment, use the
10348@code{set} command instead of the @code{print} command. @code{set} is
10349really the same as @code{print} except that the expression's value is
10350not printed and is not put in the value history (@pxref{Value History,
10351,Value history}). The expression is evaluated only for its effects.
10352
c906108c
SS
10353If the beginning of the argument string of the @code{set} command
10354appears identical to a @code{set} subcommand, use the @code{set
10355variable} command instead of just @code{set}. This command is identical
10356to @code{set} except for its lack of subcommands. For example, if your
10357program has a variable @code{width}, you get an error if you try to set
10358a new value with just @samp{set width=13}, because @value{GDBN} has the
10359command @code{set width}:
10360
474c8240 10361@smallexample
c906108c
SS
10362(@value{GDBP}) whatis width
10363type = double
10364(@value{GDBP}) p width
10365$4 = 13
10366(@value{GDBP}) set width=47
10367Invalid syntax in expression.
474c8240 10368@end smallexample
c906108c
SS
10369
10370@noindent
10371The invalid expression, of course, is @samp{=47}. In
10372order to actually set the program's variable @code{width}, use
10373
474c8240 10374@smallexample
c906108c 10375(@value{GDBP}) set var width=47
474c8240 10376@end smallexample
53a5351d 10377
c906108c
SS
10378Because the @code{set} command has many subcommands that can conflict
10379with the names of program variables, it is a good idea to use the
10380@code{set variable} command instead of just @code{set}. For example, if
10381your program has a variable @code{g}, you run into problems if you try
10382to set a new value with just @samp{set g=4}, because @value{GDBN} has
10383the command @code{set gnutarget}, abbreviated @code{set g}:
10384
474c8240 10385@smallexample
c906108c
SS
10386@group
10387(@value{GDBP}) whatis g
10388type = double
10389(@value{GDBP}) p g
10390$1 = 1
10391(@value{GDBP}) set g=4
2df3850c 10392(@value{GDBP}) p g
c906108c
SS
10393$2 = 1
10394(@value{GDBP}) r
10395The program being debugged has been started already.
10396Start it from the beginning? (y or n) y
10397Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
10398"/home/smith/cc_progs/a.out": can't open to read symbols:
10399 Invalid bfd target.
c906108c
SS
10400(@value{GDBP}) show g
10401The current BFD target is "=4".
10402@end group
474c8240 10403@end smallexample
c906108c
SS
10404
10405@noindent
10406The program variable @code{g} did not change, and you silently set the
10407@code{gnutarget} to an invalid value. In order to set the variable
10408@code{g}, use
10409
474c8240 10410@smallexample
c906108c 10411(@value{GDBP}) set var g=4
474c8240 10412@end smallexample
c906108c
SS
10413
10414@value{GDBN} allows more implicit conversions in assignments than C; you can
10415freely store an integer value into a pointer variable or vice versa,
10416and you can convert any structure to any other structure that is the
10417same length or shorter.
10418@comment FIXME: how do structs align/pad in these conversions?
10419@comment /doc@cygnus.com 18dec1990
10420
10421To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
10422construct to generate a value of specified type at a specified address
10423(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
10424to memory location @code{0x83040} as an integer (which implies a certain size
10425and representation in memory), and
10426
474c8240 10427@smallexample
c906108c 10428set @{int@}0x83040 = 4
474c8240 10429@end smallexample
c906108c
SS
10430
10431@noindent
10432stores the value 4 into that memory location.
10433
6d2ebf8b 10434@node Jumping
c906108c
SS
10435@section Continuing at a different address
10436
10437Ordinarily, when you continue your program, you do so at the place where
10438it stopped, with the @code{continue} command. You can instead continue at
10439an address of your own choosing, with the following commands:
10440
10441@table @code
10442@kindex jump
10443@item jump @var{linespec}
10444Resume execution at line @var{linespec}. Execution stops again
10445immediately if there is a breakpoint there. @xref{List, ,Printing
10446source lines}, for a description of the different forms of
10447@var{linespec}. It is common practice to use the @code{tbreak} command
10448in conjunction with @code{jump}. @xref{Set Breaks, ,Setting
10449breakpoints}.
10450
10451The @code{jump} command does not change the current stack frame, or
10452the stack pointer, or the contents of any memory location or any
10453register other than the program counter. If line @var{linespec} is in
10454a different function from the one currently executing, the results may
10455be bizarre if the two functions expect different patterns of arguments or
10456of local variables. For this reason, the @code{jump} command requests
10457confirmation if the specified line is not in the function currently
10458executing. However, even bizarre results are predictable if you are
10459well acquainted with the machine-language code of your program.
10460
10461@item jump *@var{address}
10462Resume execution at the instruction at address @var{address}.
10463@end table
10464
c906108c 10465@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
10466On many systems, you can get much the same effect as the @code{jump}
10467command by storing a new value into the register @code{$pc}. The
10468difference is that this does not start your program running; it only
10469changes the address of where it @emph{will} run when you continue. For
10470example,
c906108c 10471
474c8240 10472@smallexample
c906108c 10473set $pc = 0x485
474c8240 10474@end smallexample
c906108c
SS
10475
10476@noindent
10477makes the next @code{continue} command or stepping command execute at
10478address @code{0x485}, rather than at the address where your program stopped.
10479@xref{Continuing and Stepping, ,Continuing and stepping}.
c906108c
SS
10480
10481The most common occasion to use the @code{jump} command is to back
10482up---perhaps with more breakpoints set---over a portion of a program
10483that has already executed, in order to examine its execution in more
10484detail.
10485
c906108c 10486@c @group
6d2ebf8b 10487@node Signaling
c906108c 10488@section Giving your program a signal
9c16f35a 10489@cindex deliver a signal to a program
c906108c
SS
10490
10491@table @code
10492@kindex signal
10493@item signal @var{signal}
10494Resume execution where your program stopped, but immediately give it the
10495signal @var{signal}. @var{signal} can be the name or the number of a
10496signal. For example, on many systems @code{signal 2} and @code{signal
10497SIGINT} are both ways of sending an interrupt signal.
10498
10499Alternatively, if @var{signal} is zero, continue execution without
10500giving a signal. This is useful when your program stopped on account of
10501a signal and would ordinary see the signal when resumed with the
10502@code{continue} command; @samp{signal 0} causes it to resume without a
10503signal.
10504
10505@code{signal} does not repeat when you press @key{RET} a second time
10506after executing the command.
10507@end table
10508@c @end group
10509
10510Invoking the @code{signal} command is not the same as invoking the
10511@code{kill} utility from the shell. Sending a signal with @code{kill}
10512causes @value{GDBN} to decide what to do with the signal depending on
10513the signal handling tables (@pxref{Signals}). The @code{signal} command
10514passes the signal directly to your program.
10515
c906108c 10516
6d2ebf8b 10517@node Returning
c906108c
SS
10518@section Returning from a function
10519
10520@table @code
10521@cindex returning from a function
10522@kindex return
10523@item return
10524@itemx return @var{expression}
10525You can cancel execution of a function call with the @code{return}
10526command. If you give an
10527@var{expression} argument, its value is used as the function's return
10528value.
10529@end table
10530
10531When you use @code{return}, @value{GDBN} discards the selected stack frame
10532(and all frames within it). You can think of this as making the
10533discarded frame return prematurely. If you wish to specify a value to
10534be returned, give that value as the argument to @code{return}.
10535
10536This pops the selected stack frame (@pxref{Selection, ,Selecting a
10537frame}), and any other frames inside of it, leaving its caller as the
10538innermost remaining frame. That frame becomes selected. The
10539specified value is stored in the registers used for returning values
10540of functions.
10541
10542The @code{return} command does not resume execution; it leaves the
10543program stopped in the state that would exist if the function had just
10544returned. In contrast, the @code{finish} command (@pxref{Continuing
10545and Stepping, ,Continuing and stepping}) resumes execution until the
10546selected stack frame returns naturally.
10547
6d2ebf8b 10548@node Calling
c906108c
SS
10549@section Calling program functions
10550
f8568604 10551@table @code
c906108c 10552@cindex calling functions
f8568604
EZ
10553@cindex inferior functions, calling
10554@item print @var{expr}
9c16f35a 10555Evaluate the expression @var{expr} and display the resuling value.
f8568604
EZ
10556@var{expr} may include calls to functions in the program being
10557debugged.
10558
c906108c 10559@kindex call
c906108c
SS
10560@item call @var{expr}
10561Evaluate the expression @var{expr} without displaying @code{void}
10562returned values.
c906108c
SS
10563
10564You can use this variant of the @code{print} command if you want to
f8568604
EZ
10565execute a function from your program that does not return anything
10566(a.k.a.@: @dfn{a void function}), but without cluttering the output
10567with @code{void} returned values that @value{GDBN} will otherwise
10568print. If the result is not void, it is printed and saved in the
10569value history.
10570@end table
10571
9c16f35a
EZ
10572It is possible for the function you call via the @code{print} or
10573@code{call} command to generate a signal (e.g., if there's a bug in
10574the function, or if you passed it incorrect arguments). What happens
10575in that case is controlled by the @code{set unwindonsignal} command.
10576
10577@table @code
10578@item set unwindonsignal
10579@kindex set unwindonsignal
10580@cindex unwind stack in called functions
10581@cindex call dummy stack unwinding
10582Set unwinding of the stack if a signal is received while in a function
10583that @value{GDBN} called in the program being debugged. If set to on,
10584@value{GDBN} unwinds the stack it created for the call and restores
10585the context to what it was before the call. If set to off (the
10586default), @value{GDBN} stops in the frame where the signal was
10587received.
10588
10589@item show unwindonsignal
10590@kindex show unwindonsignal
10591Show the current setting of stack unwinding in the functions called by
10592@value{GDBN}.
10593@end table
10594
f8568604
EZ
10595@cindex weak alias functions
10596Sometimes, a function you wish to call is actually a @dfn{weak alias}
10597for another function. In such case, @value{GDBN} might not pick up
10598the type information, including the types of the function arguments,
10599which causes @value{GDBN} to call the inferior function incorrectly.
10600As a result, the called function will function erroneously and may
10601even crash. A solution to that is to use the name of the aliased
10602function instead.
c906108c 10603
6d2ebf8b 10604@node Patching
c906108c 10605@section Patching programs
7a292a7a 10606
c906108c
SS
10607@cindex patching binaries
10608@cindex writing into executables
c906108c 10609@cindex writing into corefiles
c906108c 10610
7a292a7a
SS
10611By default, @value{GDBN} opens the file containing your program's
10612executable code (or the corefile) read-only. This prevents accidental
10613alterations to machine code; but it also prevents you from intentionally
10614patching your program's binary.
c906108c
SS
10615
10616If you'd like to be able to patch the binary, you can specify that
10617explicitly with the @code{set write} command. For example, you might
10618want to turn on internal debugging flags, or even to make emergency
10619repairs.
10620
10621@table @code
10622@kindex set write
10623@item set write on
10624@itemx set write off
7a292a7a
SS
10625If you specify @samp{set write on}, @value{GDBN} opens executable and
10626core files for both reading and writing; if you specify @samp{set write
c906108c
SS
10627off} (the default), @value{GDBN} opens them read-only.
10628
10629If you have already loaded a file, you must load it again (using the
7a292a7a
SS
10630@code{exec-file} or @code{core-file} command) after changing @code{set
10631write}, for your new setting to take effect.
c906108c
SS
10632
10633@item show write
10634@kindex show write
7a292a7a
SS
10635Display whether executable files and core files are opened for writing
10636as well as reading.
c906108c
SS
10637@end table
10638
6d2ebf8b 10639@node GDB Files
c906108c
SS
10640@chapter @value{GDBN} Files
10641
7a292a7a
SS
10642@value{GDBN} needs to know the file name of the program to be debugged,
10643both in order to read its symbol table and in order to start your
10644program. To debug a core dump of a previous run, you must also tell
10645@value{GDBN} the name of the core dump file.
c906108c
SS
10646
10647@menu
10648* Files:: Commands to specify files
5b5d99cf 10649* Separate Debug Files:: Debugging information in separate files
c906108c
SS
10650* Symbol Errors:: Errors reading symbol files
10651@end menu
10652
6d2ebf8b 10653@node Files
c906108c 10654@section Commands to specify files
c906108c 10655
7a292a7a 10656@cindex symbol table
c906108c 10657@cindex core dump file
7a292a7a
SS
10658
10659You may want to specify executable and core dump file names. The usual
10660way to do this is at start-up time, using the arguments to
10661@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
10662Out of @value{GDBN}}).
c906108c
SS
10663
10664Occasionally it is necessary to change to a different file during a
397ca115
EZ
10665@value{GDBN} session. Or you may run @value{GDBN} and forget to
10666specify a file you want to use. Or you are debugging a remote target
10667via @code{gdbserver} (@pxref{Server, file}). In these situations the
10668@value{GDBN} commands to specify new files are useful.
c906108c
SS
10669
10670@table @code
10671@cindex executable file
10672@kindex file
10673@item file @var{filename}
10674Use @var{filename} as the program to be debugged. It is read for its
10675symbols and for the contents of pure memory. It is also the program
10676executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
10677directory and the file is not found in the @value{GDBN} working directory,
10678@value{GDBN} uses the environment variable @code{PATH} as a list of
10679directories to search, just as the shell does when looking for a program
10680to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
10681and your program, using the @code{path} command.
10682
fc8be69e
EZ
10683@cindex unlinked object files
10684@cindex patching object files
10685You can load unlinked object @file{.o} files into @value{GDBN} using
10686the @code{file} command. You will not be able to ``run'' an object
10687file, but you can disassemble functions and inspect variables. Also,
10688if the underlying BFD functionality supports it, you could use
10689@kbd{gdb -write} to patch object files using this technique. Note
10690that @value{GDBN} can neither interpret nor modify relocations in this
10691case, so branches and some initialized variables will appear to go to
10692the wrong place. But this feature is still handy from time to time.
10693
c906108c
SS
10694@item file
10695@code{file} with no argument makes @value{GDBN} discard any information it
10696has on both executable file and the symbol table.
10697
10698@kindex exec-file
10699@item exec-file @r{[} @var{filename} @r{]}
10700Specify that the program to be run (but not the symbol table) is found
10701in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
10702if necessary to locate your program. Omitting @var{filename} means to
10703discard information on the executable file.
10704
10705@kindex symbol-file
10706@item symbol-file @r{[} @var{filename} @r{]}
10707Read symbol table information from file @var{filename}. @code{PATH} is
10708searched when necessary. Use the @code{file} command to get both symbol
10709table and program to run from the same file.
10710
10711@code{symbol-file} with no argument clears out @value{GDBN} information on your
10712program's symbol table.
10713
5d161b24 10714The @code{symbol-file} command causes @value{GDBN} to forget the contents
c906108c
SS
10715of its convenience variables, the value history, and all breakpoints and
10716auto-display expressions. This is because they may contain pointers to
10717the internal data recording symbols and data types, which are part of
10718the old symbol table data being discarded inside @value{GDBN}.
10719
10720@code{symbol-file} does not repeat if you press @key{RET} again after
10721executing it once.
10722
10723When @value{GDBN} is configured for a particular environment, it
10724understands debugging information in whatever format is the standard
10725generated for that environment; you may use either a @sc{gnu} compiler, or
10726other compilers that adhere to the local conventions.
c906108c
SS
10727Best results are usually obtained from @sc{gnu} compilers; for example,
10728using @code{@value{GCC}} you can generate debugging information for
10729optimized code.
c906108c
SS
10730
10731For most kinds of object files, with the exception of old SVR3 systems
10732using COFF, the @code{symbol-file} command does not normally read the
10733symbol table in full right away. Instead, it scans the symbol table
10734quickly to find which source files and which symbols are present. The
10735details are read later, one source file at a time, as they are needed.
10736
10737The purpose of this two-stage reading strategy is to make @value{GDBN}
10738start up faster. For the most part, it is invisible except for
10739occasional pauses while the symbol table details for a particular source
10740file are being read. (The @code{set verbose} command can turn these
10741pauses into messages if desired. @xref{Messages/Warnings, ,Optional
10742warnings and messages}.)
10743
c906108c
SS
10744We have not implemented the two-stage strategy for COFF yet. When the
10745symbol table is stored in COFF format, @code{symbol-file} reads the
10746symbol table data in full right away. Note that ``stabs-in-COFF''
10747still does the two-stage strategy, since the debug info is actually
10748in stabs format.
10749
10750@kindex readnow
10751@cindex reading symbols immediately
10752@cindex symbols, reading immediately
a94ab193
EZ
10753@item symbol-file @var{filename} @r{[} -readnow @r{]}
10754@itemx file @var{filename} @r{[} -readnow @r{]}
c906108c
SS
10755You can override the @value{GDBN} two-stage strategy for reading symbol
10756tables by using the @samp{-readnow} option with any of the commands that
10757load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 10758entire symbol table available.
c906108c 10759
c906108c
SS
10760@c FIXME: for now no mention of directories, since this seems to be in
10761@c flux. 13mar1992 status is that in theory GDB would look either in
10762@c current dir or in same dir as myprog; but issues like competing
10763@c GDB's, or clutter in system dirs, mean that in practice right now
10764@c only current dir is used. FFish says maybe a special GDB hierarchy
10765@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
10766@c files.
10767
c906108c 10768@kindex core-file
09d4efe1 10769@item core-file @r{[}@var{filename}@r{]}
4644b6e3 10770@itemx core
c906108c
SS
10771Specify the whereabouts of a core dump file to be used as the ``contents
10772of memory''. Traditionally, core files contain only some parts of the
10773address space of the process that generated them; @value{GDBN} can access the
10774executable file itself for other parts.
10775
10776@code{core-file} with no argument specifies that no core file is
10777to be used.
10778
10779Note that the core file is ignored when your program is actually running
7a292a7a
SS
10780under @value{GDBN}. So, if you have been running your program and you
10781wish to debug a core file instead, you must kill the subprocess in which
10782the program is running. To do this, use the @code{kill} command
c906108c 10783(@pxref{Kill Process, ,Killing the child process}).
c906108c 10784
c906108c
SS
10785@kindex add-symbol-file
10786@cindex dynamic linking
10787@item add-symbol-file @var{filename} @var{address}
a94ab193 10788@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
17d9d558 10789@itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
96a2c332
SS
10790The @code{add-symbol-file} command reads additional symbol table
10791information from the file @var{filename}. You would use this command
10792when @var{filename} has been dynamically loaded (by some other means)
10793into the program that is running. @var{address} should be the memory
10794address at which the file has been loaded; @value{GDBN} cannot figure
d167840f
EZ
10795this out for itself. You can additionally specify an arbitrary number
10796of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
10797section name and base address for that section. You can specify any
10798@var{address} as an expression.
c906108c
SS
10799
10800The symbol table of the file @var{filename} is added to the symbol table
10801originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
10802@code{add-symbol-file} command any number of times; the new symbol data
10803thus read keeps adding to the old. To discard all old symbol data
10804instead, use the @code{symbol-file} command without any arguments.
c906108c 10805
17d9d558
JB
10806@cindex relocatable object files, reading symbols from
10807@cindex object files, relocatable, reading symbols from
10808@cindex reading symbols from relocatable object files
10809@cindex symbols, reading from relocatable object files
10810@cindex @file{.o} files, reading symbols from
10811Although @var{filename} is typically a shared library file, an
10812executable file, or some other object file which has been fully
10813relocated for loading into a process, you can also load symbolic
10814information from relocatable @file{.o} files, as long as:
10815
10816@itemize @bullet
10817@item
10818the file's symbolic information refers only to linker symbols defined in
10819that file, not to symbols defined by other object files,
10820@item
10821every section the file's symbolic information refers to has actually
10822been loaded into the inferior, as it appears in the file, and
10823@item
10824you can determine the address at which every section was loaded, and
10825provide these to the @code{add-symbol-file} command.
10826@end itemize
10827
10828@noindent
10829Some embedded operating systems, like Sun Chorus and VxWorks, can load
10830relocatable files into an already running program; such systems
10831typically make the requirements above easy to meet. However, it's
10832important to recognize that many native systems use complex link
49efadf5 10833procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
10834assembly, for example) that make the requirements difficult to meet. In
10835general, one cannot assume that using @code{add-symbol-file} to read a
10836relocatable object file's symbolic information will have the same effect
10837as linking the relocatable object file into the program in the normal
10838way.
10839
c906108c
SS
10840@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
10841
c45da7e6
EZ
10842@kindex add-symbol-file-from-memory
10843@cindex @code{syscall DSO}
10844@cindex load symbols from memory
10845@item add-symbol-file-from-memory @var{address}
10846Load symbols from the given @var{address} in a dynamically loaded
10847object file whose image is mapped directly into the inferior's memory.
10848For example, the Linux kernel maps a @code{syscall DSO} into each
10849process's address space; this DSO provides kernel-specific code for
10850some system calls. The argument can be any expression whose
10851evaluation yields the address of the file's shared object file header.
10852For this command to work, you must have used @code{symbol-file} or
10853@code{exec-file} commands in advance.
10854
09d4efe1
EZ
10855@kindex add-shared-symbol-files
10856@kindex assf
10857@item add-shared-symbol-files @var{library-file}
10858@itemx assf @var{library-file}
10859The @code{add-shared-symbol-files} command can currently be used only
10860in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
10861alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
10862@value{GDBN} automatically looks for shared libraries, however if
10863@value{GDBN} does not find yours, you can invoke
10864@code{add-shared-symbol-files}. It takes one argument: the shared
10865library's file name. @code{assf} is a shorthand alias for
10866@code{add-shared-symbol-files}.
c906108c 10867
c906108c 10868@kindex section
09d4efe1
EZ
10869@item section @var{section} @var{addr}
10870The @code{section} command changes the base address of the named
10871@var{section} of the exec file to @var{addr}. This can be used if the
10872exec file does not contain section addresses, (such as in the
10873@code{a.out} format), or when the addresses specified in the file
10874itself are wrong. Each section must be changed separately. The
10875@code{info files} command, described below, lists all the sections and
10876their addresses.
c906108c
SS
10877
10878@kindex info files
10879@kindex info target
10880@item info files
10881@itemx info target
7a292a7a
SS
10882@code{info files} and @code{info target} are synonymous; both print the
10883current target (@pxref{Targets, ,Specifying a Debugging Target}),
10884including the names of the executable and core dump files currently in
10885use by @value{GDBN}, and the files from which symbols were loaded. The
10886command @code{help target} lists all possible targets rather than
10887current ones.
10888
fe95c787
MS
10889@kindex maint info sections
10890@item maint info sections
10891Another command that can give you extra information about program sections
10892is @code{maint info sections}. In addition to the section information
10893displayed by @code{info files}, this command displays the flags and file
10894offset of each section in the executable and core dump files. In addition,
10895@code{maint info sections} provides the following command options (which
10896may be arbitrarily combined):
10897
10898@table @code
10899@item ALLOBJ
10900Display sections for all loaded object files, including shared libraries.
10901@item @var{sections}
6600abed 10902Display info only for named @var{sections}.
fe95c787
MS
10903@item @var{section-flags}
10904Display info only for sections for which @var{section-flags} are true.
10905The section flags that @value{GDBN} currently knows about are:
10906@table @code
10907@item ALLOC
10908Section will have space allocated in the process when loaded.
10909Set for all sections except those containing debug information.
10910@item LOAD
10911Section will be loaded from the file into the child process memory.
10912Set for pre-initialized code and data, clear for @code{.bss} sections.
10913@item RELOC
10914Section needs to be relocated before loading.
10915@item READONLY
10916Section cannot be modified by the child process.
10917@item CODE
10918Section contains executable code only.
6600abed 10919@item DATA
fe95c787
MS
10920Section contains data only (no executable code).
10921@item ROM
10922Section will reside in ROM.
10923@item CONSTRUCTOR
10924Section contains data for constructor/destructor lists.
10925@item HAS_CONTENTS
10926Section is not empty.
10927@item NEVER_LOAD
10928An instruction to the linker to not output the section.
10929@item COFF_SHARED_LIBRARY
10930A notification to the linker that the section contains
10931COFF shared library information.
10932@item IS_COMMON
10933Section contains common symbols.
10934@end table
10935@end table
6763aef9 10936@kindex set trust-readonly-sections
9c16f35a 10937@cindex read-only sections
6763aef9
MS
10938@item set trust-readonly-sections on
10939Tell @value{GDBN} that readonly sections in your object file
6ca652b0 10940really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
10941In that case, @value{GDBN} can fetch values from these sections
10942out of the object file, rather than from the target program.
10943For some targets (notably embedded ones), this can be a significant
10944enhancement to debugging performance.
10945
10946The default is off.
10947
10948@item set trust-readonly-sections off
15110bc3 10949Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
10950the contents of the section might change while the program is running,
10951and must therefore be fetched from the target when needed.
9c16f35a
EZ
10952
10953@item show trust-readonly-sections
10954Show the current setting of trusting readonly sections.
c906108c
SS
10955@end table
10956
10957All file-specifying commands allow both absolute and relative file names
10958as arguments. @value{GDBN} always converts the file name to an absolute file
10959name and remembers it that way.
10960
c906108c 10961@cindex shared libraries
9c16f35a
EZ
10962@value{GDBN} supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
10963and IBM RS/6000 AIX shared libraries.
53a5351d 10964
c906108c
SS
10965@value{GDBN} automatically loads symbol definitions from shared libraries
10966when you use the @code{run} command, or when you examine a core file.
10967(Before you issue the @code{run} command, @value{GDBN} does not understand
10968references to a function in a shared library, however---unless you are
10969debugging a core file).
53a5351d
JM
10970
10971On HP-UX, if the program loads a library explicitly, @value{GDBN}
10972automatically loads the symbols at the time of the @code{shl_load} call.
10973
c906108c
SS
10974@c FIXME: some @value{GDBN} release may permit some refs to undef
10975@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
10976@c FIXME...lib; check this from time to time when updating manual
10977
b7209cb4
FF
10978There are times, however, when you may wish to not automatically load
10979symbol definitions from shared libraries, such as when they are
10980particularly large or there are many of them.
10981
10982To control the automatic loading of shared library symbols, use the
10983commands:
10984
10985@table @code
10986@kindex set auto-solib-add
10987@item set auto-solib-add @var{mode}
10988If @var{mode} is @code{on}, symbols from all shared object libraries
10989will be loaded automatically when the inferior begins execution, you
10990attach to an independently started inferior, or when the dynamic linker
10991informs @value{GDBN} that a new library has been loaded. If @var{mode}
10992is @code{off}, symbols must be loaded manually, using the
10993@code{sharedlibrary} command. The default value is @code{on}.
10994
dcaf7c2c
EZ
10995@cindex memory used for symbol tables
10996If your program uses lots of shared libraries with debug info that
10997takes large amounts of memory, you can decrease the @value{GDBN}
10998memory footprint by preventing it from automatically loading the
10999symbols from shared libraries. To that end, type @kbd{set
11000auto-solib-add off} before running the inferior, then load each
11001library whose debug symbols you do need with @kbd{sharedlibrary
11002@var{regexp}}, where @var{regexp} is a regular expresion that matches
11003the libraries whose symbols you want to be loaded.
11004
b7209cb4
FF
11005@kindex show auto-solib-add
11006@item show auto-solib-add
11007Display the current autoloading mode.
11008@end table
11009
c45da7e6 11010@cindex load shared library
b7209cb4
FF
11011To explicitly load shared library symbols, use the @code{sharedlibrary}
11012command:
11013
c906108c
SS
11014@table @code
11015@kindex info sharedlibrary
11016@kindex info share
11017@item info share
11018@itemx info sharedlibrary
11019Print the names of the shared libraries which are currently loaded.
11020
11021@kindex sharedlibrary
11022@kindex share
11023@item sharedlibrary @var{regex}
11024@itemx share @var{regex}
c906108c
SS
11025Load shared object library symbols for files matching a
11026Unix regular expression.
11027As with files loaded automatically, it only loads shared libraries
11028required by your program for a core file or after typing @code{run}. If
11029@var{regex} is omitted all shared libraries required by your program are
11030loaded.
c45da7e6
EZ
11031
11032@item nosharedlibrary
11033@kindex nosharedlibrary
11034@cindex unload symbols from shared libraries
11035Unload all shared object library symbols. This discards all symbols
11036that have been loaded from all shared libraries. Symbols from shared
11037libraries that were loaded by explicit user requests are not
11038discarded.
c906108c
SS
11039@end table
11040
721c2651
EZ
11041Sometimes you may wish that @value{GDBN} stops and gives you control
11042when any of shared library events happen. Use the @code{set
11043stop-on-solib-events} command for this:
11044
11045@table @code
11046@item set stop-on-solib-events
11047@kindex set stop-on-solib-events
11048This command controls whether @value{GDBN} should give you control
11049when the dynamic linker notifies it about some shared library event.
11050The most common event of interest is loading or unloading of a new
11051shared library.
11052
11053@item show stop-on-solib-events
11054@kindex show stop-on-solib-events
11055Show whether @value{GDBN} stops and gives you control when shared
11056library events happen.
11057@end table
11058
f5ebfba0
DJ
11059Shared libraries are also supported in many cross or remote debugging
11060configurations. A copy of the target's libraries need to be present on the
11061host system; they need to be the same as the target libraries, although the
11062copies on the target can be stripped as long as the copies on the host are
11063not.
11064
59b7b46f
EZ
11065@cindex where to look for shared libraries
11066For remote debugging, you need to tell @value{GDBN} where the target
11067libraries are, so that it can load the correct copies---otherwise, it
11068may try to load the host's libraries. @value{GDBN} has two variables
11069to specify the search directories for target libraries.
f5ebfba0
DJ
11070
11071@table @code
59b7b46f 11072@cindex prefix for shared library file names
f5ebfba0
DJ
11073@kindex set solib-absolute-prefix
11074@item set solib-absolute-prefix @var{path}
11075If this variable is set, @var{path} will be used as a prefix for any
11076absolute shared library paths; many runtime loaders store the absolute
11077paths to the shared library in the target program's memory. If you use
11078@samp{solib-absolute-prefix} to find shared libraries, they need to be laid
11079out in the same way that they are on the target, with e.g.@: a
11080@file{/usr/lib} hierarchy under @var{path}.
11081
59b7b46f
EZ
11082@cindex default value of @samp{solib-absolute-prefix}
11083@cindex @samp{--with-sysroot}
f5ebfba0
DJ
11084You can set the default value of @samp{solib-absolute-prefix} by using the
11085configure-time @samp{--with-sysroot} option.
11086
11087@kindex show solib-absolute-prefix
11088@item show solib-absolute-prefix
11089Display the current shared library prefix.
11090
11091@kindex set solib-search-path
11092@item set solib-search-path @var{path}
11093If this variable is set, @var{path} is a colon-separated list of directories
11094to search for shared libraries. @samp{solib-search-path} is used after
11095@samp{solib-absolute-prefix} fails to locate the library, or if the path to
11096the library is relative instead of absolute. If you want to use
11097@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to
11098set @samp{solib-absolute-prefix} to a nonexistant directory to prevent
11099@value{GDBN} from finding your host's libraries.
11100
11101@kindex show solib-search-path
11102@item show solib-search-path
11103Display the current shared library search path.
11104@end table
11105
5b5d99cf
JB
11106
11107@node Separate Debug Files
11108@section Debugging Information in Separate Files
11109@cindex separate debugging information files
11110@cindex debugging information in separate files
11111@cindex @file{.debug} subdirectories
11112@cindex debugging information directory, global
11113@cindex global debugging information directory
11114
11115@value{GDBN} allows you to put a program's debugging information in a
11116file separate from the executable itself, in a way that allows
11117@value{GDBN} to find and load the debugging information automatically.
11118Since debugging information can be very large --- sometimes larger
11119than the executable code itself --- some systems distribute debugging
11120information for their executables in separate files, which users can
11121install only when they need to debug a problem.
11122
11123If an executable's debugging information has been extracted to a
11124separate file, the executable should contain a @dfn{debug link} giving
11125the name of the debugging information file (with no directory
11126components), and a checksum of its contents. (The exact form of a
11127debug link is described below.) If the full name of the directory
11128containing the executable is @var{execdir}, and the executable has a
11129debug link that specifies the name @var{debugfile}, then @value{GDBN}
11130will automatically search for the debugging information file in three
11131places:
11132
11133@itemize @bullet
11134@item
11135the directory containing the executable file (that is, it will look
11136for a file named @file{@var{execdir}/@var{debugfile}},
11137@item
11138a subdirectory of that directory named @file{.debug} (that is, the
11139file @file{@var{execdir}/.debug/@var{debugfile}}, and
11140@item
11141a subdirectory of the global debug file directory that includes the
11142executable's full path, and the name from the link (that is, the file
11143@file{@var{globaldebugdir}/@var{execdir}/@var{debugfile}}, where
11144@var{globaldebugdir} is the global debug file directory, and
11145@var{execdir} has been turned into a relative path).
11146@end itemize
11147@noindent
11148@value{GDBN} checks under each of these names for a debugging
11149information file whose checksum matches that given in the link, and
11150reads the debugging information from the first one it finds.
11151
11152So, for example, if you ask @value{GDBN} to debug @file{/usr/bin/ls},
11153which has a link containing the name @file{ls.debug}, and the global
11154debug directory is @file{/usr/lib/debug}, then @value{GDBN} will look
11155for debug information in @file{/usr/bin/ls.debug},
11156@file{/usr/bin/.debug/ls.debug}, and
11157@file{/usr/lib/debug/usr/bin/ls.debug}.
11158
11159You can set the global debugging info directory's name, and view the
11160name @value{GDBN} is currently using.
11161
11162@table @code
11163
11164@kindex set debug-file-directory
11165@item set debug-file-directory @var{directory}
11166Set the directory which @value{GDBN} searches for separate debugging
11167information files to @var{directory}.
11168
11169@kindex show debug-file-directory
11170@item show debug-file-directory
11171Show the directory @value{GDBN} searches for separate debugging
11172information files.
11173
11174@end table
11175
11176@cindex @code{.gnu_debuglink} sections
11177@cindex debug links
11178A debug link is a special section of the executable file named
11179@code{.gnu_debuglink}. The section must contain:
11180
11181@itemize
11182@item
11183A filename, with any leading directory components removed, followed by
11184a zero byte,
11185@item
11186zero to three bytes of padding, as needed to reach the next four-byte
11187boundary within the section, and
11188@item
11189a four-byte CRC checksum, stored in the same endianness used for the
11190executable file itself. The checksum is computed on the debugging
11191information file's full contents by the function given below, passing
11192zero as the @var{crc} argument.
11193@end itemize
11194
11195Any executable file format can carry a debug link, as long as it can
11196contain a section named @code{.gnu_debuglink} with the contents
11197described above.
11198
11199The debugging information file itself should be an ordinary
11200executable, containing a full set of linker symbols, sections, and
11201debugging information. The sections of the debugging information file
11202should have the same names, addresses and sizes as the original file,
11203but they need not contain any data --- much like a @code{.bss} section
11204in an ordinary executable.
11205
11206As of December 2002, there is no standard GNU utility to produce
11207separated executable / debugging information file pairs. Ulrich
11208Drepper's @file{elfutils} package, starting with version 0.53,
11209contains a version of the @code{strip} command such that the command
11210@kbd{strip foo -f foo.debug} removes the debugging information from
11211the executable file @file{foo}, places it in the file
11212@file{foo.debug}, and leaves behind a debug link in @file{foo}.
11213
11214Since there are many different ways to compute CRC's (different
11215polynomials, reversals, byte ordering, etc.), the simplest way to
11216describe the CRC used in @code{.gnu_debuglink} sections is to give the
11217complete code for a function that computes it:
11218
4644b6e3 11219@kindex gnu_debuglink_crc32
5b5d99cf
JB
11220@smallexample
11221unsigned long
11222gnu_debuglink_crc32 (unsigned long crc,
11223 unsigned char *buf, size_t len)
11224@{
11225 static const unsigned long crc32_table[256] =
11226 @{
11227 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11228 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11229 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11230 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11231 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11232 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11233 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11234 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11235 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11236 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11237 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11238 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11239 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11240 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11241 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11242 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11243 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11244 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11245 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11246 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11247 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11248 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11249 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11250 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11251 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11252 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11253 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11254 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11255 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11256 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11257 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11258 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11259 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11260 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11261 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11262 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11263 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11264 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11265 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11266 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11267 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11268 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11269 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11270 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11271 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11272 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11273 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11274 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11275 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11276 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11277 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11278 0x2d02ef8d
11279 @};
11280 unsigned char *end;
11281
11282 crc = ~crc & 0xffffffff;
11283 for (end = buf + len; buf < end; ++buf)
11284 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 11285 return ~crc & 0xffffffff;
5b5d99cf
JB
11286@}
11287@end smallexample
11288
11289
6d2ebf8b 11290@node Symbol Errors
c906108c
SS
11291@section Errors reading symbol files
11292
11293While reading a symbol file, @value{GDBN} occasionally encounters problems,
11294such as symbol types it does not recognize, or known bugs in compiler
11295output. By default, @value{GDBN} does not notify you of such problems, since
11296they are relatively common and primarily of interest to people
11297debugging compilers. If you are interested in seeing information
11298about ill-constructed symbol tables, you can either ask @value{GDBN} to print
11299only one message about each such type of problem, no matter how many
11300times the problem occurs; or you can ask @value{GDBN} to print more messages,
11301to see how many times the problems occur, with the @code{set
11302complaints} command (@pxref{Messages/Warnings, ,Optional warnings and
11303messages}).
11304
11305The messages currently printed, and their meanings, include:
11306
11307@table @code
11308@item inner block not inside outer block in @var{symbol}
11309
11310The symbol information shows where symbol scopes begin and end
11311(such as at the start of a function or a block of statements). This
11312error indicates that an inner scope block is not fully contained
11313in its outer scope blocks.
11314
11315@value{GDBN} circumvents the problem by treating the inner block as if it had
11316the same scope as the outer block. In the error message, @var{symbol}
11317may be shown as ``@code{(don't know)}'' if the outer block is not a
11318function.
11319
11320@item block at @var{address} out of order
11321
11322The symbol information for symbol scope blocks should occur in
11323order of increasing addresses. This error indicates that it does not
11324do so.
11325
11326@value{GDBN} does not circumvent this problem, and has trouble
11327locating symbols in the source file whose symbols it is reading. (You
11328can often determine what source file is affected by specifying
11329@code{set verbose on}. @xref{Messages/Warnings, ,Optional warnings and
11330messages}.)
11331
11332@item bad block start address patched
11333
11334The symbol information for a symbol scope block has a start address
11335smaller than the address of the preceding source line. This is known
11336to occur in the SunOS 4.1.1 (and earlier) C compiler.
11337
11338@value{GDBN} circumvents the problem by treating the symbol scope block as
11339starting on the previous source line.
11340
11341@item bad string table offset in symbol @var{n}
11342
11343@cindex foo
11344Symbol number @var{n} contains a pointer into the string table which is
11345larger than the size of the string table.
11346
11347@value{GDBN} circumvents the problem by considering the symbol to have the
11348name @code{foo}, which may cause other problems if many symbols end up
11349with this name.
11350
11351@item unknown symbol type @code{0x@var{nn}}
11352
7a292a7a
SS
11353The symbol information contains new data types that @value{GDBN} does
11354not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 11355uncomprehended information, in hexadecimal.
c906108c 11356
7a292a7a
SS
11357@value{GDBN} circumvents the error by ignoring this symbol information.
11358This usually allows you to debug your program, though certain symbols
c906108c 11359are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
11360debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
11361on @code{complain}, then go up to the function @code{read_dbx_symtab}
11362and examine @code{*bufp} to see the symbol.
c906108c
SS
11363
11364@item stub type has NULL name
c906108c 11365
7a292a7a 11366@value{GDBN} could not find the full definition for a struct or class.
c906108c 11367
7a292a7a 11368@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 11369The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
11370information that recent versions of the compiler should have output for
11371it.
c906108c
SS
11372
11373@item info mismatch between compiler and debugger
11374
11375@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 11376
c906108c
SS
11377@end table
11378
6d2ebf8b 11379@node Targets
c906108c 11380@chapter Specifying a Debugging Target
7a292a7a 11381
c906108c 11382@cindex debugging target
c906108c 11383A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
11384
11385Often, @value{GDBN} runs in the same host environment as your program;
11386in that case, the debugging target is specified as a side effect when
11387you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
11388flexibility---for example, running @value{GDBN} on a physically separate
11389host, or controlling a standalone system over a serial port or a
53a5351d
JM
11390realtime system over a TCP/IP connection---you can use the @code{target}
11391command to specify one of the target types configured for @value{GDBN}
11392(@pxref{Target Commands, ,Commands for managing targets}).
c906108c 11393
a8f24a35
EZ
11394@cindex target architecture
11395It is possible to build @value{GDBN} for several different @dfn{target
11396architectures}. When @value{GDBN} is built like that, you can choose
11397one of the available architectures with the @kbd{set architecture}
11398command.
11399
11400@table @code
11401@kindex set architecture
11402@kindex show architecture
11403@item set architecture @var{arch}
11404This command sets the current target architecture to @var{arch}. The
11405value of @var{arch} can be @code{"auto"}, in addition to one of the
11406supported architectures.
11407
11408@item show architecture
11409Show the current target architecture.
9c16f35a
EZ
11410
11411@item set processor
11412@itemx processor
11413@kindex set processor
11414@kindex show processor
11415These are alias commands for, respectively, @code{set architecture}
11416and @code{show architecture}.
a8f24a35
EZ
11417@end table
11418
c906108c
SS
11419@menu
11420* Active Targets:: Active targets
11421* Target Commands:: Commands for managing targets
c906108c
SS
11422* Byte Order:: Choosing target byte order
11423* Remote:: Remote debugging
96baa820 11424* KOD:: Kernel Object Display
c906108c
SS
11425
11426@end menu
11427
6d2ebf8b 11428@node Active Targets
c906108c 11429@section Active targets
7a292a7a 11430
c906108c
SS
11431@cindex stacking targets
11432@cindex active targets
11433@cindex multiple targets
11434
c906108c 11435There are three classes of targets: processes, core files, and
7a292a7a
SS
11436executable files. @value{GDBN} can work concurrently on up to three
11437active targets, one in each class. This allows you to (for example)
11438start a process and inspect its activity without abandoning your work on
11439a core file.
c906108c
SS
11440
11441For example, if you execute @samp{gdb a.out}, then the executable file
11442@code{a.out} is the only active target. If you designate a core file as
11443well---presumably from a prior run that crashed and coredumped---then
11444@value{GDBN} has two active targets and uses them in tandem, looking
11445first in the corefile target, then in the executable file, to satisfy
11446requests for memory addresses. (Typically, these two classes of target
11447are complementary, since core files contain only a program's
11448read-write memory---variables and so on---plus machine status, while
11449executable files contain only the program text and initialized data.)
c906108c
SS
11450
11451When you type @code{run}, your executable file becomes an active process
7a292a7a
SS
11452target as well. When a process target is active, all @value{GDBN}
11453commands requesting memory addresses refer to that target; addresses in
11454an active core file or executable file target are obscured while the
11455process target is active.
c906108c 11456
7a292a7a
SS
11457Use the @code{core-file} and @code{exec-file} commands to select a new
11458core file or executable target (@pxref{Files, ,Commands to specify
c906108c 11459files}). To specify as a target a process that is already running, use
7a292a7a
SS
11460the @code{attach} command (@pxref{Attach, ,Debugging an already-running
11461process}).
c906108c 11462
6d2ebf8b 11463@node Target Commands
c906108c
SS
11464@section Commands for managing targets
11465
11466@table @code
11467@item target @var{type} @var{parameters}
7a292a7a
SS
11468Connects the @value{GDBN} host environment to a target machine or
11469process. A target is typically a protocol for talking to debugging
11470facilities. You use the argument @var{type} to specify the type or
11471protocol of the target machine.
c906108c
SS
11472
11473Further @var{parameters} are interpreted by the target protocol, but
11474typically include things like device names or host names to connect
11475with, process numbers, and baud rates.
c906108c
SS
11476
11477The @code{target} command does not repeat if you press @key{RET} again
11478after executing the command.
11479
11480@kindex help target
11481@item help target
11482Displays the names of all targets available. To display targets
11483currently selected, use either @code{info target} or @code{info files}
11484(@pxref{Files, ,Commands to specify files}).
11485
11486@item help target @var{name}
11487Describe a particular target, including any parameters necessary to
11488select it.
11489
11490@kindex set gnutarget
11491@item set gnutarget @var{args}
5d161b24 11492@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 11493knows whether it is reading an @dfn{executable},
5d161b24
DB
11494a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
11495with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
11496with @code{gnutarget} the @code{target} refers to a program, not a machine.
11497
d4f3574e 11498@quotation
c906108c
SS
11499@emph{Warning:} To specify a file format with @code{set gnutarget},
11500you must know the actual BFD name.
d4f3574e 11501@end quotation
c906108c 11502
d4f3574e
SS
11503@noindent
11504@xref{Files, , Commands to specify files}.
c906108c 11505
5d161b24 11506@kindex show gnutarget
c906108c
SS
11507@item show gnutarget
11508Use the @code{show gnutarget} command to display what file format
11509@code{gnutarget} is set to read. If you have not set @code{gnutarget},
11510@value{GDBN} will determine the file format for each file automatically,
11511and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
11512@end table
11513
4644b6e3 11514@cindex common targets
c906108c
SS
11515Here are some common targets (available, or not, depending on the GDB
11516configuration):
c906108c
SS
11517
11518@table @code
4644b6e3 11519@kindex target
c906108c 11520@item target exec @var{program}
4644b6e3 11521@cindex executable file target
c906108c
SS
11522An executable file. @samp{target exec @var{program}} is the same as
11523@samp{exec-file @var{program}}.
11524
c906108c 11525@item target core @var{filename}
4644b6e3 11526@cindex core dump file target
c906108c
SS
11527A core dump file. @samp{target core @var{filename}} is the same as
11528@samp{core-file @var{filename}}.
c906108c 11529
c906108c 11530@item target remote @var{dev}
4644b6e3 11531@cindex remote target
c906108c
SS
11532Remote serial target in GDB-specific protocol. The argument @var{dev}
11533specifies what serial device to use for the connection (e.g.
11534@file{/dev/ttya}). @xref{Remote, ,Remote debugging}. @code{target remote}
d4f3574e 11535supports the @code{load} command. This is only useful if you have
c906108c
SS
11536some other way of getting the stub to the target system, and you can put
11537it somewhere in memory where it won't get clobbered by the download.
11538
c906108c 11539@item target sim
4644b6e3 11540@cindex built-in simulator target
2df3850c 11541Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 11542In general,
474c8240 11543@smallexample
104c1213
JM
11544 target sim
11545 load
11546 run
474c8240 11547@end smallexample
d4f3574e 11548@noindent
104c1213 11549works; however, you cannot assume that a specific memory map, device
d4f3574e 11550drivers, or even basic I/O is available, although some simulators do
104c1213
JM
11551provide these. For info about any processor-specific simulator details,
11552see the appropriate section in @ref{Embedded Processors, ,Embedded
11553Processors}.
11554
c906108c
SS
11555@end table
11556
104c1213 11557Some configurations may include these targets as well:
c906108c
SS
11558
11559@table @code
11560
c906108c 11561@item target nrom @var{dev}
4644b6e3 11562@cindex NetROM ROM emulator target
c906108c
SS
11563NetROM ROM emulator. This target only supports downloading.
11564
c906108c
SS
11565@end table
11566
5d161b24 11567Different targets are available on different configurations of @value{GDBN};
c906108c 11568your configuration may have more or fewer targets.
c906108c 11569
721c2651
EZ
11570Many remote targets require you to download the executable's code once
11571you've successfully established a connection. You may wish to control
11572various aspects of this process, such as the size of the data chunks
11573used by @value{GDBN} to download program parts to the remote target.
a8f24a35
EZ
11574
11575@table @code
11576@kindex set download-write-size
11577@item set download-write-size @var{size}
11578Set the write size used when downloading a program. Only used when
11579downloading a program onto a remote target. Specify zero or a
11580negative value to disable blocked writes. The actual size of each
11581transfer is also limited by the size of the target packet and the
11582memory cache.
11583
11584@kindex show download-write-size
11585@item show download-write-size
721c2651 11586@kindex show download-write-size
a8f24a35 11587Show the current value of the write size.
721c2651
EZ
11588
11589@item set hash
11590@kindex set hash@r{, for remote monitors}
11591@cindex hash mark while downloading
11592This command controls whether a hash mark @samp{#} is displayed while
11593downloading a file to the remote monitor. If on, a hash mark is
11594displayed after each S-record is successfully downloaded to the
11595monitor.
11596
11597@item show hash
11598@kindex show hash@r{, for remote monitors}
11599Show the current status of displaying the hash mark.
11600
11601@item set debug monitor
11602@kindex set debug monitor
11603@cindex display remote monitor communications
11604Enable or disable display of communications messages between
11605@value{GDBN} and the remote monitor.
11606
11607@item show debug monitor
11608@kindex show debug monitor
11609Show the current status of displaying communications between
11610@value{GDBN} and the remote monitor.
a8f24a35 11611@end table
c906108c
SS
11612
11613@table @code
11614
11615@kindex load @var{filename}
11616@item load @var{filename}
c906108c
SS
11617Depending on what remote debugging facilities are configured into
11618@value{GDBN}, the @code{load} command may be available. Where it exists, it
11619is meant to make @var{filename} (an executable) available for debugging
11620on the remote system---by downloading, or dynamic linking, for example.
11621@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
11622the @code{add-symbol-file} command.
11623
11624If your @value{GDBN} does not have a @code{load} command, attempting to
11625execute it gets the error message ``@code{You can't do that when your
11626target is @dots{}}''
c906108c
SS
11627
11628The file is loaded at whatever address is specified in the executable.
11629For some object file formats, you can specify the load address when you
11630link the program; for other formats, like a.out, the object file format
11631specifies a fixed address.
11632@c FIXME! This would be a good place for an xref to the GNU linker doc.
11633
c906108c
SS
11634@code{load} does not repeat if you press @key{RET} again after using it.
11635@end table
11636
6d2ebf8b 11637@node Byte Order
c906108c 11638@section Choosing target byte order
7a292a7a 11639
c906108c
SS
11640@cindex choosing target byte order
11641@cindex target byte order
c906108c 11642
172c2a43 11643Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
c906108c
SS
11644offer the ability to run either big-endian or little-endian byte
11645orders. Usually the executable or symbol will include a bit to
11646designate the endian-ness, and you will not need to worry about
11647which to use. However, you may still find it useful to adjust
d4f3574e 11648@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
11649
11650@table @code
4644b6e3 11651@kindex set endian
c906108c
SS
11652@item set endian big
11653Instruct @value{GDBN} to assume the target is big-endian.
11654
c906108c
SS
11655@item set endian little
11656Instruct @value{GDBN} to assume the target is little-endian.
11657
c906108c
SS
11658@item set endian auto
11659Instruct @value{GDBN} to use the byte order associated with the
11660executable.
11661
11662@item show endian
11663Display @value{GDBN}'s current idea of the target byte order.
11664
11665@end table
11666
11667Note that these commands merely adjust interpretation of symbolic
11668data on the host, and that they have absolutely no effect on the
11669target system.
11670
6d2ebf8b 11671@node Remote
c906108c
SS
11672@section Remote debugging
11673@cindex remote debugging
11674
11675If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
11676@value{GDBN} in the usual way, it is often useful to use remote debugging.
11677For example, you might use remote debugging on an operating system kernel,
c906108c
SS
11678or on a small system which does not have a general purpose operating system
11679powerful enough to run a full-featured debugger.
11680
11681Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
11682to make this work with particular debugging targets. In addition,
5d161b24 11683@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
11684but not specific to any particular target system) which you can use if you
11685write the remote stubs---the code that runs on the remote system to
11686communicate with @value{GDBN}.
11687
11688Other remote targets may be available in your
11689configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 11690
c45da7e6
EZ
11691Once you've connected to the remote target, @value{GDBN} allows you to
11692send arbitrary commands to the remote monitor:
11693
11694@table @code
11695@item remote @var{command}
11696@kindex remote@r{, a command}
11697@cindex send command to remote monitor
11698Send an arbitrary @var{command} string to the remote monitor.
11699@end table
11700
11701
6f05cf9f
AC
11702@node KOD
11703@section Kernel Object Display
6f05cf9f 11704@cindex kernel object display
6f05cf9f
AC
11705@cindex KOD
11706
11707Some targets support kernel object display. Using this facility,
11708@value{GDBN} communicates specially with the underlying operating system
11709and can display information about operating system-level objects such as
11710mutexes and other synchronization objects. Exactly which objects can be
11711displayed is determined on a per-OS basis.
11712
3bbe9696 11713@kindex set os
6f05cf9f
AC
11714Use the @code{set os} command to set the operating system. This tells
11715@value{GDBN} which kernel object display module to initialize:
11716
474c8240 11717@smallexample
6f05cf9f 11718(@value{GDBP}) set os cisco
474c8240 11719@end smallexample
6f05cf9f 11720
3bbe9696
EZ
11721@kindex show os
11722The associated command @code{show os} displays the operating system
11723set with the @code{set os} command; if no operating system has been
11724set, @code{show os} will display an empty string @samp{""}.
11725
6f05cf9f
AC
11726If @code{set os} succeeds, @value{GDBN} will display some information
11727about the operating system, and will create a new @code{info} command
11728which can be used to query the target. The @code{info} command is named
11729after the operating system:
c906108c 11730
3bbe9696 11731@kindex info cisco
474c8240 11732@smallexample
6f05cf9f
AC
11733(@value{GDBP}) info cisco
11734List of Cisco Kernel Objects
11735Object Description
11736any Any and all objects
474c8240 11737@end smallexample
6f05cf9f
AC
11738
11739Further subcommands can be used to query about particular objects known
11740by the kernel.
11741
3bbe9696
EZ
11742There is currently no way to determine whether a given operating
11743system is supported other than to try setting it with @kbd{set os
11744@var{name}}, where @var{name} is the name of the operating system you
11745want to try.
6f05cf9f
AC
11746
11747
11748@node Remote Debugging
11749@chapter Debugging remote programs
11750
6b2f586d 11751@menu
07f31aa6 11752* Connecting:: Connecting to a remote target
6b2f586d
AC
11753* Server:: Using the gdbserver program
11754* NetWare:: Using the gdbserve.nlm program
501eef12 11755* Remote configuration:: Remote configuration
6b2f586d 11756* remote stub:: Implementing a remote stub
6b2f586d
AC
11757@end menu
11758
07f31aa6
DJ
11759@node Connecting
11760@section Connecting to a remote target
11761
11762On the @value{GDBN} host machine, you will need an unstripped copy of
11763your program, since @value{GDBN} needs symobl and debugging information.
11764Start up @value{GDBN} as usual, using the name of the local copy of your
11765program as the first argument.
11766
11767@cindex serial line, @code{target remote}
11768If you're using a serial line, you may want to give @value{GDBN} the
11769@w{@samp{--baud}} option, or use the @code{set remotebaud} command
9c16f35a
EZ
11770(@pxref{Remote configuration, set remotebaud}) before the
11771@code{target} command.
07f31aa6
DJ
11772
11773After that, use @code{target remote} to establish communications with
11774the target machine. Its argument specifies how to communicate---either
11775via a devicename attached to a direct serial line, or a TCP or UDP port
11776(possibly to a terminal server which in turn has a serial line to the
11777target). For example, to use a serial line connected to the device
11778named @file{/dev/ttyb}:
11779
11780@smallexample
11781target remote /dev/ttyb
11782@end smallexample
11783
11784@cindex TCP port, @code{target remote}
11785To use a TCP connection, use an argument of the form
11786@code{@var{host}:@var{port}} or @code{tcp:@var{host}:@var{port}}.
11787For example, to connect to port 2828 on a
11788terminal server named @code{manyfarms}:
11789
11790@smallexample
11791target remote manyfarms:2828
11792@end smallexample
11793
11794If your remote target is actually running on the same machine as
11795your debugger session (e.g.@: a simulator of your target running on
11796the same host), you can omit the hostname. For example, to connect
11797to port 1234 on your local machine:
11798
11799@smallexample
11800target remote :1234
11801@end smallexample
11802@noindent
11803
11804Note that the colon is still required here.
11805
11806@cindex UDP port, @code{target remote}
11807To use a UDP connection, use an argument of the form
11808@code{udp:@var{host}:@var{port}}. For example, to connect to UDP port 2828
11809on a terminal server named @code{manyfarms}:
11810
11811@smallexample
11812target remote udp:manyfarms:2828
11813@end smallexample
11814
11815When using a UDP connection for remote debugging, you should keep in mind
11816that the `U' stands for ``Unreliable''. UDP can silently drop packets on
11817busy or unreliable networks, which will cause havoc with your debugging
11818session.
11819
11820Now you can use all the usual commands to examine and change data and to
11821step and continue the remote program.
11822
11823@cindex interrupting remote programs
11824@cindex remote programs, interrupting
11825Whenever @value{GDBN} is waiting for the remote program, if you type the
11826interrupt character (often @key{C-C}), @value{GDBN} attempts to stop the
11827program. This may or may not succeed, depending in part on the hardware
11828and the serial drivers the remote system uses. If you type the
11829interrupt character once again, @value{GDBN} displays this prompt:
11830
11831@smallexample
11832Interrupted while waiting for the program.
11833Give up (and stop debugging it)? (y or n)
11834@end smallexample
11835
11836If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
11837(If you decide you want to try again later, you can use @samp{target
11838remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
11839goes back to waiting.
11840
11841@table @code
11842@kindex detach (remote)
11843@item detach
11844When you have finished debugging the remote program, you can use the
11845@code{detach} command to release it from @value{GDBN} control.
11846Detaching from the target normally resumes its execution, but the results
11847will depend on your particular remote stub. After the @code{detach}
11848command, @value{GDBN} is free to connect to another target.
11849
11850@kindex disconnect
11851@item disconnect
11852The @code{disconnect} command behaves like @code{detach}, except that
11853the target is generally not resumed. It will wait for @value{GDBN}
11854(this instance or another one) to connect and continue debugging. After
11855the @code{disconnect} command, @value{GDBN} is again free to connect to
11856another target.
09d4efe1
EZ
11857
11858@cindex send command to remote monitor
11859@kindex monitor
11860@item monitor @var{cmd}
11861This command allows you to send commands directly to the remote
11862monitor.
07f31aa6
DJ
11863@end table
11864
6f05cf9f
AC
11865@node Server
11866@section Using the @code{gdbserver} program
11867
11868@kindex gdbserver
11869@cindex remote connection without stubs
11870@code{gdbserver} is a control program for Unix-like systems, which
11871allows you to connect your program with a remote @value{GDBN} via
11872@code{target remote}---but without linking in the usual debugging stub.
11873
11874@code{gdbserver} is not a complete replacement for the debugging stubs,
11875because it requires essentially the same operating-system facilities
11876that @value{GDBN} itself does. In fact, a system that can run
11877@code{gdbserver} to connect to a remote @value{GDBN} could also run
11878@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
11879because it is a much smaller program than @value{GDBN} itself. It is
11880also easier to port than all of @value{GDBN}, so you may be able to get
11881started more quickly on a new system by using @code{gdbserver}.
11882Finally, if you develop code for real-time systems, you may find that
11883the tradeoffs involved in real-time operation make it more convenient to
11884do as much development work as possible on another system, for example
11885by cross-compiling. You can use @code{gdbserver} to make a similar
11886choice for debugging.
11887
11888@value{GDBN} and @code{gdbserver} communicate via either a serial line
11889or a TCP connection, using the standard @value{GDBN} remote serial
11890protocol.
11891
11892@table @emph
11893@item On the target machine,
11894you need to have a copy of the program you want to debug.
11895@code{gdbserver} does not need your program's symbol table, so you can
11896strip the program if necessary to save space. @value{GDBN} on the host
11897system does all the symbol handling.
11898
11899To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 11900the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
11901syntax is:
11902
11903@smallexample
11904target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
11905@end smallexample
11906
11907@var{comm} is either a device name (to use a serial line) or a TCP
11908hostname and portnumber. For example, to debug Emacs with the argument
11909@samp{foo.txt} and communicate with @value{GDBN} over the serial port
11910@file{/dev/com1}:
11911
11912@smallexample
11913target> gdbserver /dev/com1 emacs foo.txt
11914@end smallexample
11915
11916@code{gdbserver} waits passively for the host @value{GDBN} to communicate
11917with it.
11918
11919To use a TCP connection instead of a serial line:
11920
11921@smallexample
11922target> gdbserver host:2345 emacs foo.txt
11923@end smallexample
11924
11925The only difference from the previous example is the first argument,
11926specifying that you are communicating with the host @value{GDBN} via
11927TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
11928expect a TCP connection from machine @samp{host} to local TCP port 2345.
11929(Currently, the @samp{host} part is ignored.) You can choose any number
11930you want for the port number as long as it does not conflict with any
11931TCP ports already in use on the target system (for example, @code{23} is
11932reserved for @code{telnet}).@footnote{If you choose a port number that
11933conflicts with another service, @code{gdbserver} prints an error message
11934and exits.} You must use the same port number with the host @value{GDBN}
11935@code{target remote} command.
11936
56460a61
DJ
11937On some targets, @code{gdbserver} can also attach to running programs.
11938This is accomplished via the @code{--attach} argument. The syntax is:
11939
11940@smallexample
11941target> gdbserver @var{comm} --attach @var{pid}
11942@end smallexample
11943
11944@var{pid} is the process ID of a currently running process. It isn't necessary
11945to point @code{gdbserver} at a binary for the running process.
11946
b1fe9455
DJ
11947@pindex pidof
11948@cindex attach to a program by name
11949You can debug processes by name instead of process ID if your target has the
11950@code{pidof} utility:
11951
11952@smallexample
11953target> gdbserver @var{comm} --attach `pidof @var{PROGRAM}`
11954@end smallexample
11955
11956In case more than one copy of @var{PROGRAM} is running, or @var{PROGRAM}
11957has multiple threads, most versions of @code{pidof} support the
11958@code{-s} option to only return the first process ID.
11959
07f31aa6
DJ
11960@item On the host machine,
11961connect to your target (@pxref{Connecting,,Connecting to a remote target}).
6f05cf9f
AC
11962For TCP connections, you must start up @code{gdbserver} prior to using
11963the @code{target remote} command. Otherwise you may get an error whose
11964text depends on the host system, but which usually looks something like
07f31aa6 11965@samp{Connection refused}. You don't need to use the @code{load}
397ca115
EZ
11966command in @value{GDBN} when using @code{gdbserver}, since the program is
11967already on the target. However, if you want to load the symbols (as
11968you normally would), do that with the @code{file} command, and issue
11969it @emph{before} connecting to the server; otherwise, you will get an
11970error message saying @code{"Program is already running"}, since the
11971program is considered running after the connection.
07f31aa6 11972
6f05cf9f
AC
11973@end table
11974
11975@node NetWare
11976@section Using the @code{gdbserve.nlm} program
11977
11978@kindex gdbserve.nlm
11979@code{gdbserve.nlm} is a control program for NetWare systems, which
11980allows you to connect your program with a remote @value{GDBN} via
11981@code{target remote}.
11982
11983@value{GDBN} and @code{gdbserve.nlm} communicate via a serial line,
11984using the standard @value{GDBN} remote serial protocol.
11985
11986@table @emph
11987@item On the target machine,
11988you need to have a copy of the program you want to debug.
11989@code{gdbserve.nlm} does not need your program's symbol table, so you
11990can strip the program if necessary to save space. @value{GDBN} on the
11991host system does all the symbol handling.
11992
11993To use the server, you must tell it how to communicate with
11994@value{GDBN}; the name of your program; and the arguments for your
11995program. The syntax is:
11996
11997@smallexample
11998load gdbserve [ BOARD=@var{board} ] [ PORT=@var{port} ]
11999 [ BAUD=@var{baud} ] @var{program} [ @var{args} @dots{} ]
12000@end smallexample
12001
12002@var{board} and @var{port} specify the serial line; @var{baud} specifies
12003the baud rate used by the connection. @var{port} and @var{node} default
12004to 0, @var{baud} defaults to 9600@dmn{bps}.
12005
12006For example, to debug Emacs with the argument @samp{foo.txt}and
12007communicate with @value{GDBN} over serial port number 2 or board 1
12008using a 19200@dmn{bps} connection:
12009
12010@smallexample
12011load gdbserve BOARD=1 PORT=2 BAUD=19200 emacs foo.txt
12012@end smallexample
12013
07f31aa6
DJ
12014@item
12015On the @value{GDBN} host machine, connect to your target (@pxref{Connecting,,
12016Connecting to a remote target}).
6f05cf9f 12017
6f05cf9f
AC
12018@end table
12019
501eef12
AC
12020@node Remote configuration
12021@section Remote configuration
12022
9c16f35a
EZ
12023@kindex set remote
12024@kindex show remote
12025This section documents the configuration options available when
12026debugging remote programs. For the options related to the File I/O
12027extensions of the remote protocol, see @ref{The system call,
12028system-call-allowed}.
501eef12
AC
12029
12030@table @code
9c16f35a
EZ
12031@item set remoteaddresssize @var{bits}
12032@cindex adress size for remote targets
12033@cindex bits in remote address
12034Set the maximum size of address in a memory packet to the specified
12035number of bits. @value{GDBN} will mask off the address bits above
12036that number, when it passes addresses to the remote target. The
12037default value is the number of bits in the target's address.
12038
12039@item show remoteaddresssize
12040Show the current value of remote address size in bits.
12041
12042@item set remotebaud @var{n}
12043@cindex baud rate for remote targets
12044Set the baud rate for the remote serial I/O to @var{n} baud. The
12045value is used to set the speed of the serial port used for debugging
12046remote targets.
12047
12048@item show remotebaud
12049Show the current speed of the remote connection.
12050
12051@item set remotebreak
12052@cindex interrupt remote programs
12053@cindex BREAK signal instead of Ctrl-C
12054If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
12055when you press the @key{Ctrl-C} key to interrupt the program running
12056on the remote. If set to off, @value{GDBN} sends the @samp{Strl-C}
12057character instead. The default is off, since most remote systems
12058expect to see @samp{Ctrl-C} as the interrupt signal.
12059
12060@item show remotebreak
12061Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
12062interrupt the remote program.
12063
12064@item set remotedebug
12065@cindex debug remote protocol
12066@cindex remote protocol debugging
12067@cindex display remote packets
12068Control the debugging of the remote protocol. When enabled, each
12069packet sent to or received from the remote target is displayed. The
12070defaults is off.
12071
12072@item show remotedebug
12073Show the current setting of the remote protocol debugging.
12074
12075@item set remotedevice @var{device}
12076@cindex serial port name
12077Set the name of the serial port through which to communicate to the
12078remote target to @var{device}. This is the device used by
12079@value{GDBN} to open the serial communications line to the remote
12080target. There's no default, so you must set a valid port name for the
12081remote serial communications to work. (Some varieties of the
12082@code{target} command accept the port name as part of their
12083arguments.)
12084
12085@item show remotedevice
12086Show the current name of the serial port.
12087
12088@item set remotelogbase @var{base}
12089Set the base (a.k.a.@: radix) of logging serial protocol
12090communications to @var{base}. Supported values of @var{base} are:
12091@code{ascii}, @code{octal}, and @code{hex}. The default is
12092@code{ascii}.
12093
12094@item show remotelogbase
12095Show the current setting of the radix for logging remote serial
12096protocol.
12097
12098@item set remotelogfile @var{file}
12099@cindex record serial communications on file
12100Record remote serial communications on the named @var{file}. The
12101default is not to record at all.
12102
12103@item show remotelogfile.
12104Show the current setting of the file name on which to record the
12105serial communications.
12106
12107@item set remotetimeout @var{num}
12108@cindex timeout for serial communications
12109@cindex remote timeout
12110Set the timeout limit to wait for the remote target to respond to
12111@var{num} seconds. The default is 2 seconds.
12112
12113@item show remotetimeout
12114Show the current number of seconds to wait for the remote target
12115responses.
12116
12117@cindex limit hardware breakpoints and watchpoints
12118@cindex remote target, limit break- and watchpoints
501eef12
AC
12119@anchor{set remote hardware-watchpoint-limit}
12120@anchor{set remote hardware-breakpoint-limit}
12121@item set remote hardware-watchpoint-limit @var{limit}
12122@itemx set remote hardware-breakpoint-limit @var{limit}
12123Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
12124watchpoints. A limit of -1, the default, is treated as unlimited.
9c16f35a
EZ
12125
12126@item set remote fetch-register-packet
12127@itemx set remote set-register-packet
12128@itemx set remote P-packet
12129@itemx set remote p-packet
12130@cindex P-packet
12131@cindex fetch registers from remote targets
12132@cindex set registers in remote targets
12133Determine whether @value{GDBN} can set and fetch registers from the
12134remote target using the @samp{P} packets. The default depends on the
12135remote stub's support of the @samp{P} packets (@value{GDBN} queries
12136the stub when this packet is first required).
12137
12138@item show remote fetch-register-packet
12139@itemx show remote set-register-packet
12140@itemx show remote P-packet
12141@itemx show remote p-packet
12142Show the current setting of using the @samp{P} packets for setting and
12143fetching registers from the remote target.
12144
12145@cindex binary downloads
12146@cindex X-packet
12147@item set remote binary-download-packet
12148@itemx set remote X-packet
12149Determine whether @value{GDBN} sends downloads in binary mode using
12150the @samp{X} packets. The default is on.
12151
12152@item show remote binary-download-packet
12153@itemx show remote X-packet
12154Show the current setting of using the @samp{X} packets for binary
12155downloads.
12156
12157@item set remote read-aux-vector-packet
12158@cindex auxiliary vector of remote target
12159@cindex @code{auxv}, and remote targets
12160Set the use of the remote protocol's @samp{qPart:auxv:read} (target
12161auxiliary vector read) request. This request is used to fetch the
721c2651
EZ
12162remote target's @dfn{auxiliary vector}, see @ref{OS Information,
12163Auxiliary Vector}. The default setting depends on the remote stub's
12164support of this request (@value{GDBN} queries the stub when this
12165request is first required). @xref{General Query Packets, qPart}, for
12166more information about this request.
9c16f35a
EZ
12167
12168@item show remote read-aux-vector-packet
12169Show the current setting of use of the @samp{qPart:auxv:read} request.
12170
12171@item set remote symbol-lookup-packet
12172@cindex remote symbol lookup request
12173Set the use of the remote protocol's @samp{qSymbol} (target symbol
12174lookup) request. This request is used to communicate symbol
12175information to the remote target, e.g., whenever a new shared library
12176is loaded by the remote (@pxref{Files, shared libraries}). The
12177default setting depends on the remote stub's support of this request
12178(@value{GDBN} queries the stub when this request is first required).
12179@xref{General Query Packets, qSymbol}, for more information about this
12180request.
12181
12182@item show remote symbol-lookup-packet
12183Show the current setting of use of the @samp{qSymbol} request.
12184
12185@item set remote verbose-resume-packet
12186@cindex resume remote target
12187@cindex signal thread, and remote targets
12188@cindex single-step thread, and remote targets
12189@cindex thread-specific operations on remote targets
12190Set the use of the remote protocol's @samp{vCont} (descriptive resume)
12191request. This request is used to resume specific threads in the
12192remote target, and to single-step or signal them. The default setting
12193depends on the remote stub's support of this request (@value{GDBN}
12194queries the stub when this request is first required). This setting
12195affects debugging of multithreaded programs: if @samp{vCont} cannot be
12196used, @value{GDBN} might be unable to single-step a specific thread,
12197especially under @code{set scheduler-locking off}; it is also
12198impossible to pause a specific thread. @xref{Packets, vCont}, for
12199more details.
12200
12201@item show remote verbose-resume-packet
12202Show the current setting of use of the @samp{vCont} request
12203
12204@item set remote software-breakpoint-packet
12205@itemx set remote hardware-breakpoint-packet
12206@itemx set remote write-watchpoint-packet
12207@itemx set remote read-watchpoint-packet
12208@itemx set remote access-watchpoint-packet
12209@itemx set remote Z-packet
12210@cindex Z-packet
12211@cindex remote hardware breakpoints and watchpoints
12212These commands enable or disable the use of @samp{Z} packets for
12213setting breakpoints and watchpoints in the remote target. The default
12214depends on the remote stub's support of the @samp{Z} packets
12215(@value{GDBN} queries the stub when each packet is first required).
12216The command @code{set remote Z-packet}, kept for back-compatibility,
12217turns on or off all the features that require the use of @samp{Z}
12218packets.
12219
12220@item show remote software-breakpoint-packet
12221@itemx show remote hardware-breakpoint-packet
12222@itemx show remote write-watchpoint-packet
12223@itemx show remote read-watchpoint-packet
12224@itemx show remote access-watchpoint-packet
12225@itemx show remote Z-packet
12226Show the current setting of @samp{Z} packets usage.
0abb7bc7
EZ
12227
12228@item set remote get-thread-local-storage-address
12229@kindex set remote get-thread-local-storage-address
12230@cindex thread local storage of remote targets
12231This command enables or disables the use of the @samp{qGetTLSAddr}
12232(Get Thread Local Storage Address) request packet. The default
12233depends on whether the remote stub supports this request.
12234@xref{General Query Packets, qGetTLSAddr}, for more details about this
12235packet.
12236
12237@item show remote get-thread-local-storage-address
12238@kindex show remote get-thread-local-storage-address
12239Show the current setting of @samp{qGetTLSAddr} packet usage.
501eef12
AC
12240@end table
12241
6f05cf9f
AC
12242@node remote stub
12243@section Implementing a remote stub
7a292a7a 12244
8e04817f
AC
12245@cindex debugging stub, example
12246@cindex remote stub, example
12247@cindex stub example, remote debugging
12248The stub files provided with @value{GDBN} implement the target side of the
12249communication protocol, and the @value{GDBN} side is implemented in the
12250@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
12251these subroutines to communicate, and ignore the details. (If you're
12252implementing your own stub file, you can still ignore the details: start
12253with one of the existing stub files. @file{sparc-stub.c} is the best
12254organized, and therefore the easiest to read.)
12255
104c1213
JM
12256@cindex remote serial debugging, overview
12257To debug a program running on another machine (the debugging
12258@dfn{target} machine), you must first arrange for all the usual
12259prerequisites for the program to run by itself. For example, for a C
12260program, you need:
c906108c 12261
104c1213
JM
12262@enumerate
12263@item
12264A startup routine to set up the C runtime environment; these usually
12265have a name like @file{crt0}. The startup routine may be supplied by
12266your hardware supplier, or you may have to write your own.
96baa820 12267
5d161b24 12268@item
d4f3574e 12269A C subroutine library to support your program's
104c1213 12270subroutine calls, notably managing input and output.
96baa820 12271
104c1213
JM
12272@item
12273A way of getting your program to the other machine---for example, a
12274download program. These are often supplied by the hardware
12275manufacturer, but you may have to write your own from hardware
12276documentation.
12277@end enumerate
96baa820 12278
104c1213
JM
12279The next step is to arrange for your program to use a serial port to
12280communicate with the machine where @value{GDBN} is running (the @dfn{host}
12281machine). In general terms, the scheme looks like this:
96baa820 12282
104c1213
JM
12283@table @emph
12284@item On the host,
12285@value{GDBN} already understands how to use this protocol; when everything
12286else is set up, you can simply use the @samp{target remote} command
12287(@pxref{Targets,,Specifying a Debugging Target}).
12288
12289@item On the target,
12290you must link with your program a few special-purpose subroutines that
12291implement the @value{GDBN} remote serial protocol. The file containing these
12292subroutines is called a @dfn{debugging stub}.
12293
12294On certain remote targets, you can use an auxiliary program
12295@code{gdbserver} instead of linking a stub into your program.
12296@xref{Server,,Using the @code{gdbserver} program}, for details.
12297@end table
96baa820 12298
104c1213
JM
12299The debugging stub is specific to the architecture of the remote
12300machine; for example, use @file{sparc-stub.c} to debug programs on
12301@sc{sparc} boards.
96baa820 12302
104c1213
JM
12303@cindex remote serial stub list
12304These working remote stubs are distributed with @value{GDBN}:
96baa820 12305
104c1213
JM
12306@table @code
12307
12308@item i386-stub.c
41afff9a 12309@cindex @file{i386-stub.c}
104c1213
JM
12310@cindex Intel
12311@cindex i386
12312For Intel 386 and compatible architectures.
12313
12314@item m68k-stub.c
41afff9a 12315@cindex @file{m68k-stub.c}
104c1213
JM
12316@cindex Motorola 680x0
12317@cindex m680x0
12318For Motorola 680x0 architectures.
12319
12320@item sh-stub.c
41afff9a 12321@cindex @file{sh-stub.c}
172c2a43 12322@cindex Renesas
104c1213 12323@cindex SH
172c2a43 12324For Renesas SH architectures.
104c1213
JM
12325
12326@item sparc-stub.c
41afff9a 12327@cindex @file{sparc-stub.c}
104c1213
JM
12328@cindex Sparc
12329For @sc{sparc} architectures.
12330
12331@item sparcl-stub.c
41afff9a 12332@cindex @file{sparcl-stub.c}
104c1213
JM
12333@cindex Fujitsu
12334@cindex SparcLite
12335For Fujitsu @sc{sparclite} architectures.
12336
12337@end table
12338
12339The @file{README} file in the @value{GDBN} distribution may list other
12340recently added stubs.
12341
12342@menu
12343* Stub Contents:: What the stub can do for you
12344* Bootstrapping:: What you must do for the stub
12345* Debug Session:: Putting it all together
104c1213
JM
12346@end menu
12347
6d2ebf8b 12348@node Stub Contents
6f05cf9f 12349@subsection What the stub can do for you
104c1213
JM
12350
12351@cindex remote serial stub
12352The debugging stub for your architecture supplies these three
12353subroutines:
12354
12355@table @code
12356@item set_debug_traps
4644b6e3 12357@findex set_debug_traps
104c1213
JM
12358@cindex remote serial stub, initialization
12359This routine arranges for @code{handle_exception} to run when your
12360program stops. You must call this subroutine explicitly near the
12361beginning of your program.
12362
12363@item handle_exception
4644b6e3 12364@findex handle_exception
104c1213
JM
12365@cindex remote serial stub, main routine
12366This is the central workhorse, but your program never calls it
12367explicitly---the setup code arranges for @code{handle_exception} to
12368run when a trap is triggered.
12369
12370@code{handle_exception} takes control when your program stops during
12371execution (for example, on a breakpoint), and mediates communications
12372with @value{GDBN} on the host machine. This is where the communications
12373protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 12374representative on the target machine. It begins by sending summary
104c1213
JM
12375information on the state of your program, then continues to execute,
12376retrieving and transmitting any information @value{GDBN} needs, until you
12377execute a @value{GDBN} command that makes your program resume; at that point,
12378@code{handle_exception} returns control to your own code on the target
5d161b24 12379machine.
104c1213
JM
12380
12381@item breakpoint
12382@cindex @code{breakpoint} subroutine, remote
12383Use this auxiliary subroutine to make your program contain a
12384breakpoint. Depending on the particular situation, this may be the only
12385way for @value{GDBN} to get control. For instance, if your target
12386machine has some sort of interrupt button, you won't need to call this;
12387pressing the interrupt button transfers control to
12388@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
12389simply receiving characters on the serial port may also trigger a trap;
12390again, in that situation, you don't need to call @code{breakpoint} from
12391your own program---simply running @samp{target remote} from the host
5d161b24 12392@value{GDBN} session gets control.
104c1213
JM
12393
12394Call @code{breakpoint} if none of these is true, or if you simply want
12395to make certain your program stops at a predetermined point for the
12396start of your debugging session.
12397@end table
12398
6d2ebf8b 12399@node Bootstrapping
6f05cf9f 12400@subsection What you must do for the stub
104c1213
JM
12401
12402@cindex remote stub, support routines
12403The debugging stubs that come with @value{GDBN} are set up for a particular
12404chip architecture, but they have no information about the rest of your
12405debugging target machine.
12406
12407First of all you need to tell the stub how to communicate with the
12408serial port.
12409
12410@table @code
12411@item int getDebugChar()
4644b6e3 12412@findex getDebugChar
104c1213
JM
12413Write this subroutine to read a single character from the serial port.
12414It may be identical to @code{getchar} for your target system; a
12415different name is used to allow you to distinguish the two if you wish.
12416
12417@item void putDebugChar(int)
4644b6e3 12418@findex putDebugChar
104c1213 12419Write this subroutine to write a single character to the serial port.
5d161b24 12420It may be identical to @code{putchar} for your target system; a
104c1213
JM
12421different name is used to allow you to distinguish the two if you wish.
12422@end table
12423
12424@cindex control C, and remote debugging
12425@cindex interrupting remote targets
12426If you want @value{GDBN} to be able to stop your program while it is
12427running, you need to use an interrupt-driven serial driver, and arrange
12428for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
12429character). That is the character which @value{GDBN} uses to tell the
12430remote system to stop.
12431
12432Getting the debugging target to return the proper status to @value{GDBN}
12433probably requires changes to the standard stub; one quick and dirty way
12434is to just execute a breakpoint instruction (the ``dirty'' part is that
12435@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
12436
12437Other routines you need to supply are:
12438
12439@table @code
12440@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 12441@findex exceptionHandler
104c1213
JM
12442Write this function to install @var{exception_address} in the exception
12443handling tables. You need to do this because the stub does not have any
12444way of knowing what the exception handling tables on your target system
12445are like (for example, the processor's table might be in @sc{rom},
12446containing entries which point to a table in @sc{ram}).
12447@var{exception_number} is the exception number which should be changed;
12448its meaning is architecture-dependent (for example, different numbers
12449might represent divide by zero, misaligned access, etc). When this
12450exception occurs, control should be transferred directly to
12451@var{exception_address}, and the processor state (stack, registers,
12452and so on) should be just as it is when a processor exception occurs. So if
12453you want to use a jump instruction to reach @var{exception_address}, it
12454should be a simple jump, not a jump to subroutine.
12455
12456For the 386, @var{exception_address} should be installed as an interrupt
12457gate so that interrupts are masked while the handler runs. The gate
12458should be at privilege level 0 (the most privileged level). The
12459@sc{sparc} and 68k stubs are able to mask interrupts themselves without
12460help from @code{exceptionHandler}.
12461
12462@item void flush_i_cache()
4644b6e3 12463@findex flush_i_cache
d4f3574e 12464On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
12465instruction cache, if any, on your target machine. If there is no
12466instruction cache, this subroutine may be a no-op.
12467
12468On target machines that have instruction caches, @value{GDBN} requires this
12469function to make certain that the state of your program is stable.
12470@end table
12471
12472@noindent
12473You must also make sure this library routine is available:
12474
12475@table @code
12476@item void *memset(void *, int, int)
4644b6e3 12477@findex memset
104c1213
JM
12478This is the standard library function @code{memset} that sets an area of
12479memory to a known value. If you have one of the free versions of
12480@code{libc.a}, @code{memset} can be found there; otherwise, you must
12481either obtain it from your hardware manufacturer, or write your own.
12482@end table
12483
12484If you do not use the GNU C compiler, you may need other standard
12485library subroutines as well; this varies from one stub to another,
12486but in general the stubs are likely to use any of the common library
d4f3574e 12487subroutines which @code{@value{GCC}} generates as inline code.
104c1213
JM
12488
12489
6d2ebf8b 12490@node Debug Session
6f05cf9f 12491@subsection Putting it all together
104c1213
JM
12492
12493@cindex remote serial debugging summary
12494In summary, when your program is ready to debug, you must follow these
12495steps.
12496
12497@enumerate
12498@item
6d2ebf8b 12499Make sure you have defined the supporting low-level routines
104c1213
JM
12500(@pxref{Bootstrapping,,What you must do for the stub}):
12501@display
12502@code{getDebugChar}, @code{putDebugChar},
12503@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
12504@end display
12505
12506@item
12507Insert these lines near the top of your program:
12508
474c8240 12509@smallexample
104c1213
JM
12510set_debug_traps();
12511breakpoint();
474c8240 12512@end smallexample
104c1213
JM
12513
12514@item
12515For the 680x0 stub only, you need to provide a variable called
12516@code{exceptionHook}. Normally you just use:
12517
474c8240 12518@smallexample
104c1213 12519void (*exceptionHook)() = 0;
474c8240 12520@end smallexample
104c1213 12521
d4f3574e 12522@noindent
104c1213 12523but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 12524function in your program, that function is called when
104c1213
JM
12525@code{@value{GDBN}} continues after stopping on a trap (for example, bus
12526error). The function indicated by @code{exceptionHook} is called with
12527one parameter: an @code{int} which is the exception number.
12528
12529@item
12530Compile and link together: your program, the @value{GDBN} debugging stub for
12531your target architecture, and the supporting subroutines.
12532
12533@item
12534Make sure you have a serial connection between your target machine and
12535the @value{GDBN} host, and identify the serial port on the host.
12536
12537@item
12538@c The "remote" target now provides a `load' command, so we should
12539@c document that. FIXME.
12540Download your program to your target machine (or get it there by
12541whatever means the manufacturer provides), and start it.
12542
12543@item
07f31aa6
DJ
12544Start @value{GDBN} on the host, and connect to the target
12545(@pxref{Connecting,,Connecting to a remote target}).
9db8d71f 12546
104c1213
JM
12547@end enumerate
12548
8e04817f
AC
12549@node Configurations
12550@chapter Configuration-Specific Information
104c1213 12551
8e04817f
AC
12552While nearly all @value{GDBN} commands are available for all native and
12553cross versions of the debugger, there are some exceptions. This chapter
12554describes things that are only available in certain configurations.
104c1213 12555
8e04817f
AC
12556There are three major categories of configurations: native
12557configurations, where the host and target are the same, embedded
12558operating system configurations, which are usually the same for several
12559different processor architectures, and bare embedded processors, which
12560are quite different from each other.
104c1213 12561
8e04817f
AC
12562@menu
12563* Native::
12564* Embedded OS::
12565* Embedded Processors::
12566* Architectures::
12567@end menu
104c1213 12568
8e04817f
AC
12569@node Native
12570@section Native
104c1213 12571
8e04817f
AC
12572This section describes details specific to particular native
12573configurations.
6cf7e474 12574
8e04817f
AC
12575@menu
12576* HP-UX:: HP-UX
7561d450 12577* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
12578* SVR4 Process Information:: SVR4 process information
12579* DJGPP Native:: Features specific to the DJGPP port
78c47bea 12580* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 12581* Hurd Native:: Features specific to @sc{gnu} Hurd
a64548ea 12582* Neutrino:: Features specific to QNX Neutrino
8e04817f 12583@end menu
6cf7e474 12584
8e04817f
AC
12585@node HP-UX
12586@subsection HP-UX
104c1213 12587
8e04817f
AC
12588On HP-UX systems, if you refer to a function or variable name that
12589begins with a dollar sign, @value{GDBN} searches for a user or system
12590name first, before it searches for a convenience variable.
104c1213 12591
9c16f35a 12592
7561d450
MK
12593@node BSD libkvm Interface
12594@subsection BSD libkvm Interface
12595
12596@cindex libkvm
12597@cindex kernel memory image
12598@cindex kernel crash dump
12599
12600BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
12601interface that provides a uniform interface for accessing kernel virtual
12602memory images, including live systems and crash dumps. @value{GDBN}
12603uses this interface to allow you to debug live kernels and kernel crash
12604dumps on many native BSD configurations. This is implemented as a
12605special @code{kvm} debugging target. For debugging a live system, load
12606the currently running kernel into @value{GDBN} and connect to the
12607@code{kvm} target:
12608
12609@smallexample
12610(@value{GDBP}) @b{target kvm}
12611@end smallexample
12612
12613For debugging crash dumps, provide the file name of the crash dump as an
12614argument:
12615
12616@smallexample
12617(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
12618@end smallexample
12619
12620Once connected to the @code{kvm} target, the following commands are
12621available:
12622
12623@table @code
12624@kindex kvm
12625@item kvm pcb
721c2651 12626Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
12627
12628@item kvm proc
12629Set current context from proc address. This command isn't available on
12630modern FreeBSD systems.
12631@end table
12632
8e04817f
AC
12633@node SVR4 Process Information
12634@subsection SVR4 process information
60bf7e09
EZ
12635@cindex /proc
12636@cindex examine process image
12637@cindex process info via @file{/proc}
104c1213 12638
60bf7e09
EZ
12639Many versions of SVR4 and compatible systems provide a facility called
12640@samp{/proc} that can be used to examine the image of a running
12641process using file-system subroutines. If @value{GDBN} is configured
12642for an operating system with this facility, the command @code{info
12643proc} is available to report information about the process running
12644your program, or about any process running on your system. @code{info
12645proc} works only on SVR4 systems that include the @code{procfs} code.
12646This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
12647Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
104c1213 12648
8e04817f
AC
12649@table @code
12650@kindex info proc
60bf7e09 12651@cindex process ID
8e04817f 12652@item info proc
60bf7e09
EZ
12653@itemx info proc @var{process-id}
12654Summarize available information about any running process. If a
12655process ID is specified by @var{process-id}, display information about
12656that process; otherwise display information about the program being
12657debugged. The summary includes the debugged process ID, the command
12658line used to invoke it, its current working directory, and its
12659executable file's absolute file name.
12660
12661On some systems, @var{process-id} can be of the form
12662@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
12663within a process. If the optional @var{pid} part is missing, it means
12664a thread from the process being debugged (the leading @samp{/} still
12665needs to be present, or else @value{GDBN} will interpret the number as
12666a process ID rather than a thread ID).
6cf7e474 12667
8e04817f 12668@item info proc mappings
60bf7e09
EZ
12669@cindex memory address space mappings
12670Report the memory address space ranges accessible in the program, with
12671information on whether the process has read, write, or execute access
12672rights to each range. On @sc{gnu}/Linux systems, each memory range
12673includes the object file which is mapped to that range, instead of the
12674memory access rights to that range.
12675
12676@item info proc stat
12677@itemx info proc status
12678@cindex process detailed status information
12679These subcommands are specific to @sc{gnu}/Linux systems. They show
12680the process-related information, including the user ID and group ID;
12681how many threads are there in the process; its virtual memory usage;
12682the signals that are pending, blocked, and ignored; its TTY; its
12683consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 12684value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
12685(type @kbd{man 5 proc} from your shell prompt).
12686
12687@item info proc all
12688Show all the information about the process described under all of the
12689above @code{info proc} subcommands.
12690
8e04817f
AC
12691@ignore
12692@comment These sub-options of 'info proc' were not included when
12693@comment procfs.c was re-written. Keep their descriptions around
12694@comment against the day when someone finds the time to put them back in.
12695@kindex info proc times
12696@item info proc times
12697Starting time, user CPU time, and system CPU time for your program and
12698its children.
6cf7e474 12699
8e04817f
AC
12700@kindex info proc id
12701@item info proc id
12702Report on the process IDs related to your program: its own process ID,
12703the ID of its parent, the process group ID, and the session ID.
8e04817f 12704@end ignore
721c2651
EZ
12705
12706@item set procfs-trace
12707@kindex set procfs-trace
12708@cindex @code{procfs} API calls
12709This command enables and disables tracing of @code{procfs} API calls.
12710
12711@item show procfs-trace
12712@kindex show procfs-trace
12713Show the current state of @code{procfs} API call tracing.
12714
12715@item set procfs-file @var{file}
12716@kindex set procfs-file
12717Tell @value{GDBN} to write @code{procfs} API trace to the named
12718@var{file}. @value{GDBN} appends the trace info to the previous
12719contents of the file. The default is to display the trace on the
12720standard output.
12721
12722@item show procfs-file
12723@kindex show procfs-file
12724Show the file to which @code{procfs} API trace is written.
12725
12726@item proc-trace-entry
12727@itemx proc-trace-exit
12728@itemx proc-untrace-entry
12729@itemx proc-untrace-exit
12730@kindex proc-trace-entry
12731@kindex proc-trace-exit
12732@kindex proc-untrace-entry
12733@kindex proc-untrace-exit
12734These commands enable and disable tracing of entries into and exits
12735from the @code{syscall} interface.
12736
12737@item info pidlist
12738@kindex info pidlist
12739@cindex process list, QNX Neutrino
12740For QNX Neutrino only, this command displays the list of all the
12741processes and all the threads within each process.
12742
12743@item info meminfo
12744@kindex info meminfo
12745@cindex mapinfo list, QNX Neutrino
12746For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 12747@end table
104c1213 12748
8e04817f
AC
12749@node DJGPP Native
12750@subsection Features for Debugging @sc{djgpp} Programs
12751@cindex @sc{djgpp} debugging
12752@cindex native @sc{djgpp} debugging
12753@cindex MS-DOS-specific commands
104c1213 12754
514c4d71
EZ
12755@cindex DPMI
12756@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
12757MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
12758that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
12759top of real-mode DOS systems and their emulations.
104c1213 12760
8e04817f
AC
12761@value{GDBN} supports native debugging of @sc{djgpp} programs, and
12762defines a few commands specific to the @sc{djgpp} port. This
12763subsection describes those commands.
104c1213 12764
8e04817f
AC
12765@table @code
12766@kindex info dos
12767@item info dos
12768This is a prefix of @sc{djgpp}-specific commands which print
12769information about the target system and important OS structures.
f1251bdd 12770
8e04817f
AC
12771@kindex sysinfo
12772@cindex MS-DOS system info
12773@cindex free memory information (MS-DOS)
12774@item info dos sysinfo
12775This command displays assorted information about the underlying
12776platform: the CPU type and features, the OS version and flavor, the
12777DPMI version, and the available conventional and DPMI memory.
104c1213 12778
8e04817f
AC
12779@cindex GDT
12780@cindex LDT
12781@cindex IDT
12782@cindex segment descriptor tables
12783@cindex descriptor tables display
12784@item info dos gdt
12785@itemx info dos ldt
12786@itemx info dos idt
12787These 3 commands display entries from, respectively, Global, Local,
12788and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
12789tables are data structures which store a descriptor for each segment
12790that is currently in use. The segment's selector is an index into a
12791descriptor table; the table entry for that index holds the
12792descriptor's base address and limit, and its attributes and access
12793rights.
104c1213 12794
8e04817f
AC
12795A typical @sc{djgpp} program uses 3 segments: a code segment, a data
12796segment (used for both data and the stack), and a DOS segment (which
12797allows access to DOS/BIOS data structures and absolute addresses in
12798conventional memory). However, the DPMI host will usually define
12799additional segments in order to support the DPMI environment.
d4f3574e 12800
8e04817f
AC
12801@cindex garbled pointers
12802These commands allow to display entries from the descriptor tables.
12803Without an argument, all entries from the specified table are
12804displayed. An argument, which should be an integer expression, means
12805display a single entry whose index is given by the argument. For
12806example, here's a convenient way to display information about the
12807debugged program's data segment:
104c1213 12808
8e04817f
AC
12809@smallexample
12810@exdent @code{(@value{GDBP}) info dos ldt $ds}
12811@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
12812@end smallexample
104c1213 12813
8e04817f
AC
12814@noindent
12815This comes in handy when you want to see whether a pointer is outside
12816the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 12817
8e04817f
AC
12818@cindex page tables display (MS-DOS)
12819@item info dos pde
12820@itemx info dos pte
12821These two commands display entries from, respectively, the Page
12822Directory and the Page Tables. Page Directories and Page Tables are
12823data structures which control how virtual memory addresses are mapped
12824into physical addresses. A Page Table includes an entry for every
12825page of memory that is mapped into the program's address space; there
12826may be several Page Tables, each one holding up to 4096 entries. A
12827Page Directory has up to 4096 entries, one each for every Page Table
12828that is currently in use.
104c1213 12829
8e04817f
AC
12830Without an argument, @kbd{info dos pde} displays the entire Page
12831Directory, and @kbd{info dos pte} displays all the entries in all of
12832the Page Tables. An argument, an integer expression, given to the
12833@kbd{info dos pde} command means display only that entry from the Page
12834Directory table. An argument given to the @kbd{info dos pte} command
12835means display entries from a single Page Table, the one pointed to by
12836the specified entry in the Page Directory.
104c1213 12837
8e04817f
AC
12838@cindex direct memory access (DMA) on MS-DOS
12839These commands are useful when your program uses @dfn{DMA} (Direct
12840Memory Access), which needs physical addresses to program the DMA
12841controller.
104c1213 12842
8e04817f 12843These commands are supported only with some DPMI servers.
104c1213 12844
8e04817f
AC
12845@cindex physical address from linear address
12846@item info dos address-pte @var{addr}
12847This command displays the Page Table entry for a specified linear
514c4d71
EZ
12848address. The argument @var{addr} is a linear address which should
12849already have the appropriate segment's base address added to it,
12850because this command accepts addresses which may belong to @emph{any}
12851segment. For example, here's how to display the Page Table entry for
12852the page where a variable @code{i} is stored:
104c1213 12853
b383017d 12854@smallexample
8e04817f
AC
12855@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
12856@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 12857@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 12858@end smallexample
104c1213 12859
8e04817f
AC
12860@noindent
12861This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 12862whose physical base address is @code{0x02698000}, and shows all the
8e04817f 12863attributes of that page.
104c1213 12864
8e04817f
AC
12865Note that you must cast the addresses of variables to a @code{char *},
12866since otherwise the value of @code{__djgpp_base_address}, the base
12867address of all variables and functions in a @sc{djgpp} program, will
12868be added using the rules of C pointer arithmetics: if @code{i} is
12869declared an @code{int}, @value{GDBN} will add 4 times the value of
12870@code{__djgpp_base_address} to the address of @code{i}.
104c1213 12871
8e04817f
AC
12872Here's another example, it displays the Page Table entry for the
12873transfer buffer:
104c1213 12874
8e04817f
AC
12875@smallexample
12876@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
12877@exdent @code{Page Table entry for address 0x29110:}
12878@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
12879@end smallexample
104c1213 12880
8e04817f
AC
12881@noindent
12882(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
128833rd member of the @code{_go32_info_block} structure.) The output
12884clearly shows that this DPMI server maps the addresses in conventional
12885memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
12886linear (@code{0x29110}) addresses are identical.
104c1213 12887
8e04817f
AC
12888This command is supported only with some DPMI servers.
12889@end table
104c1213 12890
c45da7e6 12891@cindex DOS serial data link, remote debugging
a8f24a35
EZ
12892In addition to native debugging, the DJGPP port supports remote
12893debugging via a serial data link. The following commands are specific
12894to remote serial debugging in the DJGPP port of @value{GDBN}.
12895
12896@table @code
12897@kindex set com1base
12898@kindex set com1irq
12899@kindex set com2base
12900@kindex set com2irq
12901@kindex set com3base
12902@kindex set com3irq
12903@kindex set com4base
12904@kindex set com4irq
12905@item set com1base @var{addr}
12906This command sets the base I/O port address of the @file{COM1} serial
12907port.
12908
12909@item set com1irq @var{irq}
12910This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
12911for the @file{COM1} serial port.
12912
12913There are similar commands @samp{set com2base}, @samp{set com3irq},
12914etc.@: for setting the port address and the @code{IRQ} lines for the
12915other 3 COM ports.
12916
12917@kindex show com1base
12918@kindex show com1irq
12919@kindex show com2base
12920@kindex show com2irq
12921@kindex show com3base
12922@kindex show com3irq
12923@kindex show com4base
12924@kindex show com4irq
12925The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
12926display the current settings of the base address and the @code{IRQ}
12927lines used by the COM ports.
c45da7e6
EZ
12928
12929@item info serial
12930@kindex info serial
12931@cindex DOS serial port status
12932This command prints the status of the 4 DOS serial ports. For each
12933port, it prints whether it's active or not, its I/O base address and
12934IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
12935counts of various errors encountered so far.
a8f24a35
EZ
12936@end table
12937
12938
78c47bea
PM
12939@node Cygwin Native
12940@subsection Features for Debugging MS Windows PE executables
12941@cindex MS Windows debugging
12942@cindex native Cygwin debugging
12943@cindex Cygwin-specific commands
12944
be448670
CF
12945@value{GDBN} supports native debugging of MS Windows programs, including
12946DLLs with and without symbolic debugging information. There are various
12947additional Cygwin-specific commands, described in this subsection. The
12948subsubsection @pxref{Non-debug DLL symbols} describes working with DLLs
12949that have no debugging symbols.
12950
78c47bea
PM
12951
12952@table @code
12953@kindex info w32
12954@item info w32
12955This is a prefix of MS Windows specific commands which print
12956information about the target system and important OS structures.
12957
12958@item info w32 selector
12959This command displays information returned by
12960the Win32 API @code{GetThreadSelectorEntry} function.
12961It takes an optional argument that is evaluated to
12962a long value to give the information about this given selector.
12963Without argument, this command displays information
12964about the the six segment registers.
12965
12966@kindex info dll
12967@item info dll
12968This is a Cygwin specific alias of info shared.
12969
12970@kindex dll-symbols
12971@item dll-symbols
12972This command loads symbols from a dll similarly to
12973add-sym command but without the need to specify a base address.
12974
b383017d 12975@kindex set new-console
78c47bea 12976@item set new-console @var{mode}
b383017d 12977If @var{mode} is @code{on} the debuggee will
78c47bea
PM
12978be started in a new console on next start.
12979If @var{mode} is @code{off}i, the debuggee will
12980be started in the same console as the debugger.
12981
12982@kindex show new-console
12983@item show new-console
12984Displays whether a new console is used
12985when the debuggee is started.
12986
12987@kindex set new-group
12988@item set new-group @var{mode}
12989This boolean value controls whether the debuggee should
12990start a new group or stay in the same group as the debugger.
12991This affects the way the Windows OS handles
12992Ctrl-C.
12993
12994@kindex show new-group
12995@item show new-group
12996Displays current value of new-group boolean.
12997
12998@kindex set debugevents
12999@item set debugevents
13000This boolean value adds debug output concerning events seen by the debugger.
13001
13002@kindex set debugexec
13003@item set debugexec
b383017d 13004This boolean value adds debug output concerning execute events
78c47bea
PM
13005seen by the debugger.
13006
13007@kindex set debugexceptions
13008@item set debugexceptions
b383017d 13009This boolean value adds debug ouptut concerning exception events
78c47bea
PM
13010seen by the debugger.
13011
13012@kindex set debugmemory
13013@item set debugmemory
b383017d 13014This boolean value adds debug ouptut concerning memory events
78c47bea
PM
13015seen by the debugger.
13016
13017@kindex set shell
13018@item set shell
13019This boolean values specifies whether the debuggee is called
13020via a shell or directly (default value is on).
13021
13022@kindex show shell
13023@item show shell
13024Displays if the debuggee will be started with a shell.
13025
13026@end table
13027
be448670
CF
13028@menu
13029* Non-debug DLL symbols:: Support for DLLs without debugging symbols
13030@end menu
13031
13032@node Non-debug DLL symbols
13033@subsubsection Support for DLLs without debugging symbols
13034@cindex DLLs with no debugging symbols
13035@cindex Minimal symbols and DLLs
13036
13037Very often on windows, some of the DLLs that your program relies on do
13038not include symbolic debugging information (for example,
13039@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
13040symbols in a DLL, it relies on the minimal amount of symbolic
13041information contained in the DLL's export table. This subsubsection
13042describes working with such symbols, known internally to @value{GDBN} as
13043``minimal symbols''.
13044
13045Note that before the debugged program has started execution, no DLLs
13046will have been loaded. The easiest way around this problem is simply to
13047start the program --- either by setting a breakpoint or letting the
13048program run once to completion. It is also possible to force
13049@value{GDBN} to load a particular DLL before starting the executable ---
13050see the shared library information in @pxref{Files} or the
13051@code{dll-symbols} command in @pxref{Cygwin Native}. Currently,
13052explicitly loading symbols from a DLL with no debugging information will
13053cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
13054which may adversely affect symbol lookup performance.
13055
13056@subsubsection DLL name prefixes
13057
13058In keeping with the naming conventions used by the Microsoft debugging
13059tools, DLL export symbols are made available with a prefix based on the
13060DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
13061also entered into the symbol table, so @code{CreateFileA} is often
13062sufficient. In some cases there will be name clashes within a program
13063(particularly if the executable itself includes full debugging symbols)
13064necessitating the use of the fully qualified name when referring to the
13065contents of the DLL. Use single-quotes around the name to avoid the
13066exclamation mark (``!'') being interpreted as a language operator.
13067
13068Note that the internal name of the DLL may be all upper-case, even
13069though the file name of the DLL is lower-case, or vice-versa. Since
13070symbols within @value{GDBN} are @emph{case-sensitive} this may cause
13071some confusion. If in doubt, try the @code{info functions} and
13072@code{info variables} commands or even @code{maint print msymbols} (see
13073@pxref{Symbols}). Here's an example:
13074
13075@smallexample
f7dc1244 13076(@value{GDBP}) info function CreateFileA
be448670
CF
13077All functions matching regular expression "CreateFileA":
13078
13079Non-debugging symbols:
130800x77e885f4 CreateFileA
130810x77e885f4 KERNEL32!CreateFileA
13082@end smallexample
13083
13084@smallexample
f7dc1244 13085(@value{GDBP}) info function !
be448670
CF
13086All functions matching regular expression "!":
13087
13088Non-debugging symbols:
130890x6100114c cygwin1!__assert
130900x61004034 cygwin1!_dll_crt0@@0
130910x61004240 cygwin1!dll_crt0(per_process *)
13092[etc...]
13093@end smallexample
13094
13095@subsubsection Working with minimal symbols
13096
13097Symbols extracted from a DLL's export table do not contain very much
13098type information. All that @value{GDBN} can do is guess whether a symbol
13099refers to a function or variable depending on the linker section that
13100contains the symbol. Also note that the actual contents of the memory
13101contained in a DLL are not available unless the program is running. This
13102means that you cannot examine the contents of a variable or disassemble
13103a function within a DLL without a running program.
13104
13105Variables are generally treated as pointers and dereferenced
13106automatically. For this reason, it is often necessary to prefix a
13107variable name with the address-of operator (``&'') and provide explicit
13108type information in the command. Here's an example of the type of
13109problem:
13110
13111@smallexample
f7dc1244 13112(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
13113$1 = 268572168
13114@end smallexample
13115
13116@smallexample
f7dc1244 13117(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
131180x10021610: "\230y\""
13119@end smallexample
13120
13121And two possible solutions:
13122
13123@smallexample
f7dc1244 13124(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
13125$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
13126@end smallexample
13127
13128@smallexample
f7dc1244 13129(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 131300x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 13131(@value{GDBP}) x/x 0x10021608
be448670 131320x10021608: 0x0022fd98
f7dc1244 13133(@value{GDBP}) x/s 0x0022fd98
be448670
CF
131340x22fd98: "/cygdrive/c/mydirectory/myprogram"
13135@end smallexample
13136
13137Setting a break point within a DLL is possible even before the program
13138starts execution. However, under these circumstances, @value{GDBN} can't
13139examine the initial instructions of the function in order to skip the
13140function's frame set-up code. You can work around this by using ``*&''
13141to set the breakpoint at a raw memory address:
13142
13143@smallexample
f7dc1244 13144(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
13145Breakpoint 1 at 0x1e04eff0
13146@end smallexample
13147
13148The author of these extensions is not entirely convinced that setting a
13149break point within a shared DLL like @file{kernel32.dll} is completely
13150safe.
13151
14d6dd68
EZ
13152@node Hurd Native
13153@subsection Commands specific to @sc{gnu} Hurd systems
13154@cindex @sc{gnu} Hurd debugging
13155
13156This subsection describes @value{GDBN} commands specific to the
13157@sc{gnu} Hurd native debugging.
13158
13159@table @code
13160@item set signals
13161@itemx set sigs
13162@kindex set signals@r{, Hurd command}
13163@kindex set sigs@r{, Hurd command}
13164This command toggles the state of inferior signal interception by
13165@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
13166affected by this command. @code{sigs} is a shorthand alias for
13167@code{signals}.
13168
13169@item show signals
13170@itemx show sigs
13171@kindex show signals@r{, Hurd command}
13172@kindex show sigs@r{, Hurd command}
13173Show the current state of intercepting inferior's signals.
13174
13175@item set signal-thread
13176@itemx set sigthread
13177@kindex set signal-thread
13178@kindex set sigthread
13179This command tells @value{GDBN} which thread is the @code{libc} signal
13180thread. That thread is run when a signal is delivered to a running
13181process. @code{set sigthread} is the shorthand alias of @code{set
13182signal-thread}.
13183
13184@item show signal-thread
13185@itemx show sigthread
13186@kindex show signal-thread
13187@kindex show sigthread
13188These two commands show which thread will run when the inferior is
13189delivered a signal.
13190
13191@item set stopped
13192@kindex set stopped@r{, Hurd command}
13193This commands tells @value{GDBN} that the inferior process is stopped,
13194as with the @code{SIGSTOP} signal. The stopped process can be
13195continued by delivering a signal to it.
13196
13197@item show stopped
13198@kindex show stopped@r{, Hurd command}
13199This command shows whether @value{GDBN} thinks the debuggee is
13200stopped.
13201
13202@item set exceptions
13203@kindex set exceptions@r{, Hurd command}
13204Use this command to turn off trapping of exceptions in the inferior.
13205When exception trapping is off, neither breakpoints nor
13206single-stepping will work. To restore the default, set exception
13207trapping on.
13208
13209@item show exceptions
13210@kindex show exceptions@r{, Hurd command}
13211Show the current state of trapping exceptions in the inferior.
13212
13213@item set task pause
13214@kindex set task@r{, Hurd commands}
13215@cindex task attributes (@sc{gnu} Hurd)
13216@cindex pause current task (@sc{gnu} Hurd)
13217This command toggles task suspension when @value{GDBN} has control.
13218Setting it to on takes effect immediately, and the task is suspended
13219whenever @value{GDBN} gets control. Setting it to off will take
13220effect the next time the inferior is continued. If this option is set
13221to off, you can use @code{set thread default pause on} or @code{set
13222thread pause on} (see below) to pause individual threads.
13223
13224@item show task pause
13225@kindex show task@r{, Hurd commands}
13226Show the current state of task suspension.
13227
13228@item set task detach-suspend-count
13229@cindex task suspend count
13230@cindex detach from task, @sc{gnu} Hurd
13231This command sets the suspend count the task will be left with when
13232@value{GDBN} detaches from it.
13233
13234@item show task detach-suspend-count
13235Show the suspend count the task will be left with when detaching.
13236
13237@item set task exception-port
13238@itemx set task excp
13239@cindex task exception port, @sc{gnu} Hurd
13240This command sets the task exception port to which @value{GDBN} will
13241forward exceptions. The argument should be the value of the @dfn{send
13242rights} of the task. @code{set task excp} is a shorthand alias.
13243
13244@item set noninvasive
13245@cindex noninvasive task options
13246This command switches @value{GDBN} to a mode that is the least
13247invasive as far as interfering with the inferior is concerned. This
13248is the same as using @code{set task pause}, @code{set exceptions}, and
13249@code{set signals} to values opposite to the defaults.
13250
13251@item info send-rights
13252@itemx info receive-rights
13253@itemx info port-rights
13254@itemx info port-sets
13255@itemx info dead-names
13256@itemx info ports
13257@itemx info psets
13258@cindex send rights, @sc{gnu} Hurd
13259@cindex receive rights, @sc{gnu} Hurd
13260@cindex port rights, @sc{gnu} Hurd
13261@cindex port sets, @sc{gnu} Hurd
13262@cindex dead names, @sc{gnu} Hurd
13263These commands display information about, respectively, send rights,
13264receive rights, port rights, port sets, and dead names of a task.
13265There are also shorthand aliases: @code{info ports} for @code{info
13266port-rights} and @code{info psets} for @code{info port-sets}.
13267
13268@item set thread pause
13269@kindex set thread@r{, Hurd command}
13270@cindex thread properties, @sc{gnu} Hurd
13271@cindex pause current thread (@sc{gnu} Hurd)
13272This command toggles current thread suspension when @value{GDBN} has
13273control. Setting it to on takes effect immediately, and the current
13274thread is suspended whenever @value{GDBN} gets control. Setting it to
13275off will take effect the next time the inferior is continued.
13276Normally, this command has no effect, since when @value{GDBN} has
13277control, the whole task is suspended. However, if you used @code{set
13278task pause off} (see above), this command comes in handy to suspend
13279only the current thread.
13280
13281@item show thread pause
13282@kindex show thread@r{, Hurd command}
13283This command shows the state of current thread suspension.
13284
13285@item set thread run
13286This comamnd sets whether the current thread is allowed to run.
13287
13288@item show thread run
13289Show whether the current thread is allowed to run.
13290
13291@item set thread detach-suspend-count
13292@cindex thread suspend count, @sc{gnu} Hurd
13293@cindex detach from thread, @sc{gnu} Hurd
13294This command sets the suspend count @value{GDBN} will leave on a
13295thread when detaching. This number is relative to the suspend count
13296found by @value{GDBN} when it notices the thread; use @code{set thread
13297takeover-suspend-count} to force it to an absolute value.
13298
13299@item show thread detach-suspend-count
13300Show the suspend count @value{GDBN} will leave on the thread when
13301detaching.
13302
13303@item set thread exception-port
13304@itemx set thread excp
13305Set the thread exception port to which to forward exceptions. This
13306overrides the port set by @code{set task exception-port} (see above).
13307@code{set thread excp} is the shorthand alias.
13308
13309@item set thread takeover-suspend-count
13310Normally, @value{GDBN}'s thread suspend counts are relative to the
13311value @value{GDBN} finds when it notices each thread. This command
13312changes the suspend counts to be absolute instead.
13313
13314@item set thread default
13315@itemx show thread default
13316@cindex thread default settings, @sc{gnu} Hurd
13317Each of the above @code{set thread} commands has a @code{set thread
13318default} counterpart (e.g., @code{set thread default pause}, @code{set
13319thread default exception-port}, etc.). The @code{thread default}
13320variety of commands sets the default thread properties for all
13321threads; you can then change the properties of individual threads with
13322the non-default commands.
13323@end table
13324
13325
a64548ea
EZ
13326@node Neutrino
13327@subsection QNX Neutrino
13328@cindex QNX Neutrino
13329
13330@value{GDBN} provides the following commands specific to the QNX
13331Neutrino target:
13332
13333@table @code
13334@item set debug nto-debug
13335@kindex set debug nto-debug
13336When set to on, enables debugging messages specific to the QNX
13337Neutrino support.
13338
13339@item show debug nto-debug
13340@kindex show debug nto-debug
13341Show the current state of QNX Neutrino messages.
13342@end table
13343
13344
8e04817f
AC
13345@node Embedded OS
13346@section Embedded Operating Systems
104c1213 13347
8e04817f
AC
13348This section describes configurations involving the debugging of
13349embedded operating systems that are available for several different
13350architectures.
d4f3574e 13351
8e04817f
AC
13352@menu
13353* VxWorks:: Using @value{GDBN} with VxWorks
13354@end menu
104c1213 13355
8e04817f
AC
13356@value{GDBN} includes the ability to debug programs running on
13357various real-time operating systems.
104c1213 13358
8e04817f
AC
13359@node VxWorks
13360@subsection Using @value{GDBN} with VxWorks
104c1213 13361
8e04817f 13362@cindex VxWorks
104c1213 13363
8e04817f 13364@table @code
104c1213 13365
8e04817f
AC
13366@kindex target vxworks
13367@item target vxworks @var{machinename}
13368A VxWorks system, attached via TCP/IP. The argument @var{machinename}
13369is the target system's machine name or IP address.
104c1213 13370
8e04817f 13371@end table
104c1213 13372
8e04817f
AC
13373On VxWorks, @code{load} links @var{filename} dynamically on the
13374current target system as well as adding its symbols in @value{GDBN}.
104c1213 13375
8e04817f
AC
13376@value{GDBN} enables developers to spawn and debug tasks running on networked
13377VxWorks targets from a Unix host. Already-running tasks spawned from
13378the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
13379both the Unix host and on the VxWorks target. The program
13380@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
13381installed with the name @code{vxgdb}, to distinguish it from a
13382@value{GDBN} for debugging programs on the host itself.)
104c1213 13383
8e04817f
AC
13384@table @code
13385@item VxWorks-timeout @var{args}
13386@kindex vxworks-timeout
13387All VxWorks-based targets now support the option @code{vxworks-timeout}.
13388This option is set by the user, and @var{args} represents the number of
13389seconds @value{GDBN} waits for responses to rpc's. You might use this if
13390your VxWorks target is a slow software simulator or is on the far side
13391of a thin network line.
13392@end table
104c1213 13393
8e04817f
AC
13394The following information on connecting to VxWorks was current when
13395this manual was produced; newer releases of VxWorks may use revised
13396procedures.
104c1213 13397
4644b6e3 13398@findex INCLUDE_RDB
8e04817f
AC
13399To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
13400to include the remote debugging interface routines in the VxWorks
13401library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
13402VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
13403kernel. The resulting kernel contains @file{rdb.a}, and spawns the
13404source debugging task @code{tRdbTask} when VxWorks is booted. For more
13405information on configuring and remaking VxWorks, see the manufacturer's
13406manual.
13407@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 13408
8e04817f
AC
13409Once you have included @file{rdb.a} in your VxWorks system image and set
13410your Unix execution search path to find @value{GDBN}, you are ready to
13411run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
13412@code{vxgdb}, depending on your installation).
104c1213 13413
8e04817f 13414@value{GDBN} comes up showing the prompt:
104c1213 13415
474c8240 13416@smallexample
8e04817f 13417(vxgdb)
474c8240 13418@end smallexample
104c1213 13419
8e04817f
AC
13420@menu
13421* VxWorks Connection:: Connecting to VxWorks
13422* VxWorks Download:: VxWorks download
13423* VxWorks Attach:: Running tasks
13424@end menu
104c1213 13425
8e04817f
AC
13426@node VxWorks Connection
13427@subsubsection Connecting to VxWorks
104c1213 13428
8e04817f
AC
13429The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
13430network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 13431
474c8240 13432@smallexample
8e04817f 13433(vxgdb) target vxworks tt
474c8240 13434@end smallexample
104c1213 13435
8e04817f
AC
13436@need 750
13437@value{GDBN} displays messages like these:
104c1213 13438
8e04817f
AC
13439@smallexample
13440Attaching remote machine across net...
13441Connected to tt.
13442@end smallexample
104c1213 13443
8e04817f
AC
13444@need 1000
13445@value{GDBN} then attempts to read the symbol tables of any object modules
13446loaded into the VxWorks target since it was last booted. @value{GDBN} locates
13447these files by searching the directories listed in the command search
13448path (@pxref{Environment, ,Your program's environment}); if it fails
13449to find an object file, it displays a message such as:
5d161b24 13450
474c8240 13451@smallexample
8e04817f 13452prog.o: No such file or directory.
474c8240 13453@end smallexample
104c1213 13454
8e04817f
AC
13455When this happens, add the appropriate directory to the search path with
13456the @value{GDBN} command @code{path}, and execute the @code{target}
13457command again.
104c1213 13458
8e04817f
AC
13459@node VxWorks Download
13460@subsubsection VxWorks download
104c1213 13461
8e04817f
AC
13462@cindex download to VxWorks
13463If you have connected to the VxWorks target and you want to debug an
13464object that has not yet been loaded, you can use the @value{GDBN}
13465@code{load} command to download a file from Unix to VxWorks
13466incrementally. The object file given as an argument to the @code{load}
13467command is actually opened twice: first by the VxWorks target in order
13468to download the code, then by @value{GDBN} in order to read the symbol
13469table. This can lead to problems if the current working directories on
13470the two systems differ. If both systems have NFS mounted the same
13471filesystems, you can avoid these problems by using absolute paths.
13472Otherwise, it is simplest to set the working directory on both systems
13473to the directory in which the object file resides, and then to reference
13474the file by its name, without any path. For instance, a program
13475@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
13476and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
13477program, type this on VxWorks:
104c1213 13478
474c8240 13479@smallexample
8e04817f 13480-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 13481@end smallexample
104c1213 13482
8e04817f
AC
13483@noindent
13484Then, in @value{GDBN}, type:
104c1213 13485
474c8240 13486@smallexample
8e04817f
AC
13487(vxgdb) cd @var{hostpath}/vw/demo/rdb
13488(vxgdb) load prog.o
474c8240 13489@end smallexample
104c1213 13490
8e04817f 13491@value{GDBN} displays a response similar to this:
104c1213 13492
8e04817f
AC
13493@smallexample
13494Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
13495@end smallexample
104c1213 13496
8e04817f
AC
13497You can also use the @code{load} command to reload an object module
13498after editing and recompiling the corresponding source file. Note that
13499this makes @value{GDBN} delete all currently-defined breakpoints,
13500auto-displays, and convenience variables, and to clear the value
13501history. (This is necessary in order to preserve the integrity of
13502debugger's data structures that reference the target system's symbol
13503table.)
104c1213 13504
8e04817f
AC
13505@node VxWorks Attach
13506@subsubsection Running tasks
104c1213
JM
13507
13508@cindex running VxWorks tasks
13509You can also attach to an existing task using the @code{attach} command as
13510follows:
13511
474c8240 13512@smallexample
104c1213 13513(vxgdb) attach @var{task}
474c8240 13514@end smallexample
104c1213
JM
13515
13516@noindent
13517where @var{task} is the VxWorks hexadecimal task ID. The task can be running
13518or suspended when you attach to it. Running tasks are suspended at
13519the time of attachment.
13520
6d2ebf8b 13521@node Embedded Processors
104c1213
JM
13522@section Embedded Processors
13523
13524This section goes into details specific to particular embedded
13525configurations.
13526
c45da7e6
EZ
13527@cindex send command to simulator
13528Whenever a specific embedded processor has a simulator, @value{GDBN}
13529allows to send an arbitrary command to the simulator.
13530
13531@table @code
13532@item sim @var{command}
13533@kindex sim@r{, a command}
13534Send an arbitrary @var{command} string to the simulator. Consult the
13535documentation for the specific simulator in use for information about
13536acceptable commands.
13537@end table
13538
7d86b5d5 13539
104c1213 13540@menu
c45da7e6 13541* ARM:: ARM RDI
172c2a43
KI
13542* H8/300:: Renesas H8/300
13543* H8/500:: Renesas H8/500
13544* M32R/D:: Renesas M32R/D
104c1213 13545* M68K:: Motorola M68K
104c1213 13546* MIPS Embedded:: MIPS Embedded
a37295f9 13547* OpenRISC 1000:: OpenRisc 1000
104c1213
JM
13548* PA:: HP PA Embedded
13549* PowerPC: PowerPC
172c2a43 13550* SH:: Renesas SH
104c1213
JM
13551* Sparclet:: Tsqware Sparclet
13552* Sparclite:: Fujitsu Sparclite
13553* ST2000:: Tandem ST2000
13554* Z8000:: Zilog Z8000
a64548ea
EZ
13555* AVR:: Atmel AVR
13556* CRIS:: CRIS
13557* Super-H:: Renesas Super-H
c45da7e6 13558* WinCE:: Windows CE child processes
104c1213
JM
13559@end menu
13560
6d2ebf8b 13561@node ARM
104c1213 13562@subsection ARM
c45da7e6 13563@cindex ARM RDI
104c1213
JM
13564
13565@table @code
8e04817f
AC
13566@kindex target rdi
13567@item target rdi @var{dev}
13568ARM Angel monitor, via RDI library interface to ADP protocol. You may
13569use this target to communicate with both boards running the Angel
13570monitor, or with the EmbeddedICE JTAG debug device.
13571
13572@kindex target rdp
13573@item target rdp @var{dev}
13574ARM Demon monitor.
13575
13576@end table
13577
e2f4edfd
EZ
13578@value{GDBN} provides the following ARM-specific commands:
13579
13580@table @code
13581@item set arm disassembler
13582@kindex set arm
13583This commands selects from a list of disassembly styles. The
13584@code{"std"} style is the standard style.
13585
13586@item show arm disassembler
13587@kindex show arm
13588Show the current disassembly style.
13589
13590@item set arm apcs32
13591@cindex ARM 32-bit mode
13592This command toggles ARM operation mode between 32-bit and 26-bit.
13593
13594@item show arm apcs32
13595Display the current usage of the ARM 32-bit mode.
13596
13597@item set arm fpu @var{fputype}
13598This command sets the ARM floating-point unit (FPU) type. The
13599argument @var{fputype} can be one of these:
13600
13601@table @code
13602@item auto
13603Determine the FPU type by querying the OS ABI.
13604@item softfpa
13605Software FPU, with mixed-endian doubles on little-endian ARM
13606processors.
13607@item fpa
13608GCC-compiled FPA co-processor.
13609@item softvfp
13610Software FPU with pure-endian doubles.
13611@item vfp
13612VFP co-processor.
13613@end table
13614
13615@item show arm fpu
13616Show the current type of the FPU.
13617
13618@item set arm abi
13619This command forces @value{GDBN} to use the specified ABI.
13620
13621@item show arm abi
13622Show the currently used ABI.
13623
13624@item set debug arm
13625Toggle whether to display ARM-specific debugging messages from the ARM
13626target support subsystem.
13627
13628@item show debug arm
13629Show whether ARM-specific debugging messages are enabled.
13630@end table
13631
c45da7e6
EZ
13632The following commands are available when an ARM target is debugged
13633using the RDI interface:
13634
13635@table @code
13636@item rdilogfile @r{[}@var{file}@r{]}
13637@kindex rdilogfile
13638@cindex ADP (Angel Debugger Protocol) logging
13639Set the filename for the ADP (Angel Debugger Protocol) packet log.
13640With an argument, sets the log file to the specified @var{file}. With
13641no argument, show the current log file name. The default log file is
13642@file{rdi.log}.
13643
13644@item rdilogenable @r{[}@var{arg}@r{]}
13645@kindex rdilogenable
13646Control logging of ADP packets. With an argument of 1 or @code{"yes"}
13647enables logging, with an argument 0 or @code{"no"} disables it. With
13648no arguments displays the current setting. When logging is enabled,
13649ADP packets exchanged between @value{GDBN} and the RDI target device
13650are logged to a file.
13651
13652@item set rdiromatzero
13653@kindex set rdiromatzero
13654@cindex ROM at zero address, RDI
13655Tell @value{GDBN} whether the target has ROM at address 0. If on,
13656vector catching is disabled, so that zero address can be used. If off
13657(the default), vector catching is enabled. For this command to take
13658effect, it needs to be invoked prior to the @code{target rdi} command.
13659
13660@item show rdiromatzero
13661@kindex show rdiromatzero
13662Show the current setting of ROM at zero address.
13663
13664@item set rdiheartbeat
13665@kindex set rdiheartbeat
13666@cindex RDI heartbeat
13667Enable or disable RDI heartbeat packets. It is not recommended to
13668turn on this option, since it confuses ARM and EPI JTAG interface, as
13669well as the Angel monitor.
13670
13671@item show rdiheartbeat
13672@kindex show rdiheartbeat
13673Show the setting of RDI heartbeat packets.
13674@end table
13675
e2f4edfd 13676
8e04817f 13677@node H8/300
172c2a43 13678@subsection Renesas H8/300
8e04817f
AC
13679
13680@table @code
13681
13682@kindex target hms@r{, with H8/300}
13683@item target hms @var{dev}
172c2a43 13684A Renesas SH, H8/300, or H8/500 board, attached via serial line to your host.
8e04817f
AC
13685Use special commands @code{device} and @code{speed} to control the serial
13686line and the communications speed used.
13687
13688@kindex target e7000@r{, with H8/300}
13689@item target e7000 @var{dev}
172c2a43 13690E7000 emulator for Renesas H8 and SH.
8e04817f
AC
13691
13692@kindex target sh3@r{, with H8/300}
13693@kindex target sh3e@r{, with H8/300}
13694@item target sh3 @var{dev}
13695@itemx target sh3e @var{dev}
172c2a43 13696Renesas SH-3 and SH-3E target systems.
8e04817f
AC
13697
13698@end table
13699
13700@cindex download to H8/300 or H8/500
13701@cindex H8/300 or H8/500 download
172c2a43
KI
13702@cindex download to Renesas SH
13703@cindex Renesas SH download
13704When you select remote debugging to a Renesas SH, H8/300, or H8/500
13705board, the @code{load} command downloads your program to the Renesas
8e04817f
AC
13706board and also opens it as the current executable target for
13707@value{GDBN} on your host (like the @code{file} command).
13708
13709@value{GDBN} needs to know these things to talk to your
172c2a43 13710Renesas SH, H8/300, or H8/500:
8e04817f
AC
13711
13712@enumerate
13713@item
13714that you want to use @samp{target hms}, the remote debugging interface
172c2a43
KI
13715for Renesas microprocessors, or @samp{target e7000}, the in-circuit
13716emulator for the Renesas SH and the Renesas 300H. (@samp{target hms} is
13717the default when @value{GDBN} is configured specifically for the Renesas SH,
8e04817f
AC
13718H8/300, or H8/500.)
13719
13720@item
172c2a43 13721what serial device connects your host to your Renesas board (the first
8e04817f
AC
13722serial device available on your host is the default).
13723
13724@item
13725what speed to use over the serial device.
13726@end enumerate
13727
13728@menu
172c2a43
KI
13729* Renesas Boards:: Connecting to Renesas boards.
13730* Renesas ICE:: Using the E7000 In-Circuit Emulator.
13731* Renesas Special:: Special @value{GDBN} commands for Renesas micros.
8e04817f
AC
13732@end menu
13733
172c2a43
KI
13734@node Renesas Boards
13735@subsubsection Connecting to Renesas boards
8e04817f
AC
13736
13737@c only for Unix hosts
13738@kindex device
172c2a43 13739@cindex serial device, Renesas micros
8e04817f
AC
13740Use the special @code{@value{GDBN}} command @samp{device @var{port}} if you
13741need to explicitly set the serial device. The default @var{port} is the
13742first available port on your host. This is only necessary on Unix
13743hosts, where it is typically something like @file{/dev/ttya}.
13744
13745@kindex speed
172c2a43 13746@cindex serial line speed, Renesas micros
8e04817f
AC
13747@code{@value{GDBN}} has another special command to set the communications
13748speed: @samp{speed @var{bps}}. This command also is only used from Unix
13749hosts; on DOS hosts, set the line speed as usual from outside @value{GDBN} with
13750the DOS @code{mode} command (for instance,
13751@w{@kbd{mode com2:9600,n,8,1,p}} for a 9600@dmn{bps} connection).
13752
13753The @samp{device} and @samp{speed} commands are available only when you
172c2a43 13754use a Unix host to debug your Renesas microprocessor programs. If you
8e04817f
AC
13755use a DOS host,
13756@value{GDBN} depends on an auxiliary terminate-and-stay-resident program
13757called @code{asynctsr} to communicate with the development board
13758through a PC serial port. You must also use the DOS @code{mode} command
13759to set up the serial port on the DOS side.
13760
13761The following sample session illustrates the steps needed to start a
13762program under @value{GDBN} control on an H8/300. The example uses a
13763sample H8/300 program called @file{t.x}. The procedure is the same for
172c2a43 13764the Renesas SH and the H8/500.
8e04817f
AC
13765
13766First hook up your development board. In this example, we use a
13767board attached to serial port @code{COM2}; if you use a different serial
13768port, substitute its name in the argument of the @code{mode} command.
13769When you call @code{asynctsr}, the auxiliary comms program used by the
13770debugger, you give it just the numeric part of the serial port's name;
13771for example, @samp{asyncstr 2} below runs @code{asyncstr} on
13772@code{COM2}.
13773
474c8240 13774@smallexample
8e04817f
AC
13775C:\H8300\TEST> asynctsr 2
13776C:\H8300\TEST> mode com2:9600,n,8,1,p
13777
13778Resident portion of MODE loaded
13779
13780COM2: 9600, n, 8, 1, p
13781
474c8240 13782@end smallexample
8e04817f
AC
13783
13784@quotation
13785@emph{Warning:} We have noticed a bug in PC-NFS that conflicts with
13786@code{asynctsr}. If you also run PC-NFS on your DOS host, you may need to
13787disable it, or even boot without it, to use @code{asynctsr} to control
13788your development board.
13789@end quotation
13790
13791@kindex target hms@r{, and serial protocol}
13792Now that serial communications are set up, and the development board is
9c16f35a 13793connected, you can start up @value{GDBN}. Call @code{@value{GDBN}} with
8e04817f
AC
13794the name of your program as the argument. @code{@value{GDBN}} prompts
13795you, as usual, with the prompt @samp{(@value{GDBP})}. Use two special
13796commands to begin your debugging session: @samp{target hms} to specify
172c2a43 13797cross-debugging to the Renesas board, and the @code{load} command to
8e04817f
AC
13798download your program to the board. @code{load} displays the names of
13799the program's sections, and a @samp{*} for each 2K of data downloaded.
13800(If you want to refresh @value{GDBN} data on symbols or on the
13801executable file without downloading, use the @value{GDBN} commands
13802@code{file} or @code{symbol-file}. These commands, and @code{load}
13803itself, are described in @ref{Files,,Commands to specify files}.)
13804
13805@smallexample
13806(eg-C:\H8300\TEST) @value{GDBP} t.x
13807@value{GDBN} is free software and you are welcome to distribute copies
13808 of it under certain conditions; type "show copying" to see
13809 the conditions.
13810There is absolutely no warranty for @value{GDBN}; type "show warranty"
13811for details.
13812@value{GDBN} @value{GDBVN}, Copyright 1992 Free Software Foundation, Inc...
13813(@value{GDBP}) target hms
13814Connected to remote H8/300 HMS system.
13815(@value{GDBP}) load t.x
13816.text : 0x8000 .. 0xabde ***********
13817.data : 0xabde .. 0xad30 *
13818.stack : 0xf000 .. 0xf014 *
13819@end smallexample
13820
13821At this point, you're ready to run or debug your program. From here on,
13822you can use all the usual @value{GDBN} commands. The @code{break} command
13823sets breakpoints; the @code{run} command starts your program;
13824@code{print} or @code{x} display data; the @code{continue} command
13825resumes execution after stopping at a breakpoint. You can use the
13826@code{help} command at any time to find out more about @value{GDBN} commands.
13827
13828Remember, however, that @emph{operating system} facilities aren't
13829available on your development board; for example, if your program hangs,
13830you can't send an interrupt---but you can press the @sc{reset} switch!
13831
13832Use the @sc{reset} button on the development board
13833@itemize @bullet
13834@item
13835to interrupt your program (don't use @kbd{ctl-C} on the DOS host---it has
13836no way to pass an interrupt signal to the development board); and
13837
13838@item
13839to return to the @value{GDBN} command prompt after your program finishes
13840normally. The communications protocol provides no other way for @value{GDBN}
13841to detect program completion.
13842@end itemize
13843
13844In either case, @value{GDBN} sees the effect of a @sc{reset} on the
13845development board as a ``normal exit'' of your program.
13846
172c2a43 13847@node Renesas ICE
8e04817f
AC
13848@subsubsection Using the E7000 in-circuit emulator
13849
172c2a43 13850@kindex target e7000@r{, with Renesas ICE}
8e04817f 13851You can use the E7000 in-circuit emulator to develop code for either the
172c2a43 13852Renesas SH or the H8/300H. Use one of these forms of the @samp{target
8e04817f
AC
13853e7000} command to connect @value{GDBN} to your E7000:
13854
13855@table @code
13856@item target e7000 @var{port} @var{speed}
13857Use this form if your E7000 is connected to a serial port. The
13858@var{port} argument identifies what serial port to use (for example,
13859@samp{com2}). The third argument is the line speed in bits per second
13860(for example, @samp{9600}).
13861
13862@item target e7000 @var{hostname}
13863If your E7000 is installed as a host on a TCP/IP network, you can just
13864specify its hostname; @value{GDBN} uses @code{telnet} to connect.
13865@end table
13866
ba04e063
EZ
13867The following special commands are available when debugging with the
13868Renesas E7000 ICE:
13869
13870@table @code
13871@item e7000 @var{command}
13872@kindex e7000
13873@cindex send command to E7000 monitor
13874This sends the specified @var{command} to the E7000 monitor.
13875
13876@item ftplogin @var{machine} @var{username} @var{password} @var{dir}
13877@kindex ftplogin@r{, E7000}
13878This command records information for subsequent interface with the
13879E7000 monitor via the FTP protocol: @value{GDBN} will log into the
13880named @var{machine} using specified @var{username} and @var{password},
13881and then chdir to the named directory @var{dir}.
13882
13883@item ftpload @var{file}
13884@kindex ftpload@r{, E7000}
13885This command uses credentials recorded by @code{ftplogin} to fetch and
13886load the named @var{file} from the E7000 monitor.
13887
13888@item drain
13889@kindex drain@r{, E7000}
13890This command drains any pending text buffers stored on the E7000.
13891
13892@item set usehardbreakpoints
13893@itemx show usehardbreakpoints
13894@kindex set usehardbreakpoints@r{, E7000}
13895@kindex show usehardbreakpoints@r{, E7000}
13896@cindex hardware breakpoints, and E7000
13897These commands set and show the use of hardware breakpoints for all
13898breakpoints. @xref{Set Breaks, hardware-assisted breakpoint}, for
13899more information about using hardware breakpoints selectively.
13900@end table
13901
172c2a43
KI
13902@node Renesas Special
13903@subsubsection Special @value{GDBN} commands for Renesas micros
8e04817f
AC
13904
13905Some @value{GDBN} commands are available only for the H8/300:
13906
13907@table @code
13908
13909@kindex set machine
13910@kindex show machine
13911@item set machine h8300
13912@itemx set machine h8300h
13913Condition @value{GDBN} for one of the two variants of the H8/300
13914architecture with @samp{set machine}. You can use @samp{show machine}
13915to check which variant is currently in effect.
104c1213
JM
13916
13917@end table
13918
8e04817f
AC
13919@node H8/500
13920@subsection H8/500
104c1213
JM
13921
13922@table @code
13923
8e04817f
AC
13924@kindex set memory @var{mod}
13925@cindex memory models, H8/500
13926@item set memory @var{mod}
13927@itemx show memory
13928Specify which H8/500 memory model (@var{mod}) you are using with
13929@samp{set memory}; check which memory model is in effect with @samp{show
13930memory}. The accepted values for @var{mod} are @code{small},
13931@code{big}, @code{medium}, and @code{compact}.
104c1213 13932
8e04817f 13933@end table
104c1213 13934
8e04817f 13935@node M32R/D
ba04e063 13936@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
13937
13938@table @code
8e04817f
AC
13939@kindex target m32r
13940@item target m32r @var{dev}
172c2a43 13941Renesas M32R/D ROM monitor.
8e04817f 13942
fb3e19c0
KI
13943@kindex target m32rsdi
13944@item target m32rsdi @var{dev}
13945Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
13946@end table
13947
13948The following @value{GDBN} commands are specific to the M32R monitor:
13949
13950@table @code
13951@item set download-path @var{path}
13952@kindex set download-path
13953@cindex find downloadable @sc{srec} files (M32R)
13954Set the default path for finding donwloadable @sc{srec} files.
13955
13956@item show download-path
13957@kindex show download-path
13958Show the default path for downloadable @sc{srec} files.
fb3e19c0 13959
721c2651
EZ
13960@item set board-address @var{addr}
13961@kindex set board-address
13962@cindex M32-EVA target board address
13963Set the IP address for the M32R-EVA target board.
13964
13965@item show board-address
13966@kindex show board-address
13967Show the current IP address of the target board.
13968
13969@item set server-address @var{addr}
13970@kindex set server-address
13971@cindex download server address (M32R)
13972Set the IP address for the download server, which is the @value{GDBN}'s
13973host machine.
13974
13975@item show server-address
13976@kindex show server-address
13977Display the IP address of the download server.
13978
13979@item upload @r{[}@var{file}@r{]}
13980@kindex upload@r{, M32R}
13981Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
13982upload capability. If no @var{file} argument is given, the current
13983executable file is uploaded.
13984
13985@item tload @r{[}@var{file}@r{]}
13986@kindex tload@r{, M32R}
13987Test the @code{upload} command.
8e04817f
AC
13988@end table
13989
ba04e063
EZ
13990The following commands are available for M32R/SDI:
13991
13992@table @code
13993@item sdireset
13994@kindex sdireset
13995@cindex reset SDI connection, M32R
13996This command resets the SDI connection.
13997
13998@item sdistatus
13999@kindex sdistatus
14000This command shows the SDI connection status.
14001
14002@item debug_chaos
14003@kindex debug_chaos
14004@cindex M32R/Chaos debugging
14005Instructs the remote that M32R/Chaos debugging is to be used.
14006
14007@item use_debug_dma
14008@kindex use_debug_dma
14009Instructs the remote to use the DEBUG_DMA method of accessing memory.
14010
14011@item use_mon_code
14012@kindex use_mon_code
14013Instructs the remote to use the MON_CODE method of accessing memory.
14014
14015@item use_ib_break
14016@kindex use_ib_break
14017Instructs the remote to set breakpoints by IB break.
14018
14019@item use_dbt_break
14020@kindex use_dbt_break
14021Instructs the remote to set breakpoints by DBT.
14022@end table
14023
8e04817f
AC
14024@node M68K
14025@subsection M68k
14026
14027The Motorola m68k configuration includes ColdFire support, and
14028target command for the following ROM monitors.
14029
14030@table @code
14031
14032@kindex target abug
14033@item target abug @var{dev}
14034ABug ROM monitor for M68K.
14035
14036@kindex target cpu32bug
14037@item target cpu32bug @var{dev}
14038CPU32BUG monitor, running on a CPU32 (M68K) board.
14039
14040@kindex target dbug
14041@item target dbug @var{dev}
14042dBUG ROM monitor for Motorola ColdFire.
14043
14044@kindex target est
14045@item target est @var{dev}
14046EST-300 ICE monitor, running on a CPU32 (M68K) board.
14047
14048@kindex target rom68k
14049@item target rom68k @var{dev}
14050ROM 68K monitor, running on an M68K IDP board.
14051
14052@end table
14053
8e04817f
AC
14054@table @code
14055
14056@kindex target rombug
14057@item target rombug @var{dev}
14058ROMBUG ROM monitor for OS/9000.
14059
14060@end table
14061
8e04817f
AC
14062@node MIPS Embedded
14063@subsection MIPS Embedded
14064
14065@cindex MIPS boards
14066@value{GDBN} can use the MIPS remote debugging protocol to talk to a
14067MIPS board attached to a serial line. This is available when
14068you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
104c1213 14069
8e04817f
AC
14070@need 1000
14071Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 14072
8e04817f
AC
14073@table @code
14074@item target mips @var{port}
14075@kindex target mips @var{port}
14076To run a program on the board, start up @code{@value{GDBP}} with the
14077name of your program as the argument. To connect to the board, use the
14078command @samp{target mips @var{port}}, where @var{port} is the name of
14079the serial port connected to the board. If the program has not already
14080been downloaded to the board, you may use the @code{load} command to
14081download it. You can then use all the usual @value{GDBN} commands.
104c1213 14082
8e04817f
AC
14083For example, this sequence connects to the target board through a serial
14084port, and loads and runs a program called @var{prog} through the
14085debugger:
104c1213 14086
474c8240 14087@smallexample
8e04817f
AC
14088host$ @value{GDBP} @var{prog}
14089@value{GDBN} is free software and @dots{}
14090(@value{GDBP}) target mips /dev/ttyb
14091(@value{GDBP}) load @var{prog}
14092(@value{GDBP}) run
474c8240 14093@end smallexample
104c1213 14094
8e04817f
AC
14095@item target mips @var{hostname}:@var{portnumber}
14096On some @value{GDBN} host configurations, you can specify a TCP
14097connection (for instance, to a serial line managed by a terminal
14098concentrator) instead of a serial port, using the syntax
14099@samp{@var{hostname}:@var{portnumber}}.
104c1213 14100
8e04817f
AC
14101@item target pmon @var{port}
14102@kindex target pmon @var{port}
14103PMON ROM monitor.
104c1213 14104
8e04817f
AC
14105@item target ddb @var{port}
14106@kindex target ddb @var{port}
14107NEC's DDB variant of PMON for Vr4300.
104c1213 14108
8e04817f
AC
14109@item target lsi @var{port}
14110@kindex target lsi @var{port}
14111LSI variant of PMON.
104c1213 14112
8e04817f
AC
14113@kindex target r3900
14114@item target r3900 @var{dev}
14115Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 14116
8e04817f
AC
14117@kindex target array
14118@item target array @var{dev}
14119Array Tech LSI33K RAID controller board.
104c1213 14120
8e04817f 14121@end table
104c1213 14122
104c1213 14123
8e04817f
AC
14124@noindent
14125@value{GDBN} also supports these special commands for MIPS targets:
104c1213 14126
8e04817f 14127@table @code
8e04817f
AC
14128@item set mipsfpu double
14129@itemx set mipsfpu single
14130@itemx set mipsfpu none
a64548ea 14131@itemx set mipsfpu auto
8e04817f
AC
14132@itemx show mipsfpu
14133@kindex set mipsfpu
14134@kindex show mipsfpu
14135@cindex MIPS remote floating point
14136@cindex floating point, MIPS remote
14137If your target board does not support the MIPS floating point
14138coprocessor, you should use the command @samp{set mipsfpu none} (if you
14139need this, you may wish to put the command in your @value{GDBN} init
14140file). This tells @value{GDBN} how to find the return value of
14141functions which return floating point values. It also allows
14142@value{GDBN} to avoid saving the floating point registers when calling
14143functions on the board. If you are using a floating point coprocessor
14144with only single precision floating point support, as on the @sc{r4650}
14145processor, use the command @samp{set mipsfpu single}. The default
14146double precision floating point coprocessor may be selected using
14147@samp{set mipsfpu double}.
104c1213 14148
8e04817f
AC
14149In previous versions the only choices were double precision or no
14150floating point, so @samp{set mipsfpu on} will select double precision
14151and @samp{set mipsfpu off} will select no floating point.
104c1213 14152
8e04817f
AC
14153As usual, you can inquire about the @code{mipsfpu} variable with
14154@samp{show mipsfpu}.
104c1213 14155
8e04817f
AC
14156@item set timeout @var{seconds}
14157@itemx set retransmit-timeout @var{seconds}
14158@itemx show timeout
14159@itemx show retransmit-timeout
14160@cindex @code{timeout}, MIPS protocol
14161@cindex @code{retransmit-timeout}, MIPS protocol
14162@kindex set timeout
14163@kindex show timeout
14164@kindex set retransmit-timeout
14165@kindex show retransmit-timeout
14166You can control the timeout used while waiting for a packet, in the MIPS
14167remote protocol, with the @code{set timeout @var{seconds}} command. The
14168default is 5 seconds. Similarly, you can control the timeout used while
14169waiting for an acknowledgement of a packet with the @code{set
14170retransmit-timeout @var{seconds}} command. The default is 3 seconds.
14171You can inspect both values with @code{show timeout} and @code{show
14172retransmit-timeout}. (These commands are @emph{only} available when
14173@value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
104c1213 14174
8e04817f
AC
14175The timeout set by @code{set timeout} does not apply when @value{GDBN}
14176is waiting for your program to stop. In that case, @value{GDBN} waits
14177forever because it has no way of knowing how long the program is going
14178to run before stopping.
ba04e063
EZ
14179
14180@item set syn-garbage-limit @var{num}
14181@kindex set syn-garbage-limit@r{, MIPS remote}
14182@cindex synchronize with remote MIPS target
14183Limit the maximum number of characters @value{GDBN} should ignore when
14184it tries to synchronize with the remote target. The default is 10
14185characters. Setting the limit to -1 means there's no limit.
14186
14187@item show syn-garbage-limit
14188@kindex show syn-garbage-limit@r{, MIPS remote}
14189Show the current limit on the number of characters to ignore when
14190trying to synchronize with the remote system.
14191
14192@item set monitor-prompt @var{prompt}
14193@kindex set monitor-prompt@r{, MIPS remote}
14194@cindex remote monitor prompt
14195Tell @value{GDBN} to expect the specified @var{prompt} string from the
14196remote monitor. The default depends on the target:
14197@table @asis
14198@item pmon target
14199@samp{PMON}
14200@item ddb target
14201@samp{NEC010}
14202@item lsi target
14203@samp{PMON>}
14204@end table
14205
14206@item show monitor-prompt
14207@kindex show monitor-prompt@r{, MIPS remote}
14208Show the current strings @value{GDBN} expects as the prompt from the
14209remote monitor.
14210
14211@item set monitor-warnings
14212@kindex set monitor-warnings@r{, MIPS remote}
14213Enable or disable monitor warnings about hardware breakpoints. This
14214has effect only for the @code{lsi} target. When on, @value{GDBN} will
14215display warning messages whose codes are returned by the @code{lsi}
14216PMON monitor for breakpoint commands.
14217
14218@item show monitor-warnings
14219@kindex show monitor-warnings@r{, MIPS remote}
14220Show the current setting of printing monitor warnings.
14221
14222@item pmon @var{command}
14223@kindex pmon@r{, MIPS remote}
14224@cindex send PMON command
14225This command allows sending an arbitrary @var{command} string to the
14226monitor. The monitor must be in debug mode for this to work.
8e04817f 14227@end table
104c1213 14228
a37295f9
MM
14229@node OpenRISC 1000
14230@subsection OpenRISC 1000
14231@cindex OpenRISC 1000
14232
14233@cindex or1k boards
14234See OR1k Architecture document (@uref{www.opencores.org}) for more information
14235about platform and commands.
14236
14237@table @code
14238
14239@kindex target jtag
14240@item target jtag jtag://@var{host}:@var{port}
14241
14242Connects to remote JTAG server.
14243JTAG remote server can be either an or1ksim or JTAG server,
14244connected via parallel port to the board.
14245
14246Example: @code{target jtag jtag://localhost:9999}
14247
14248@kindex or1ksim
14249@item or1ksim @var{command}
14250If connected to @code{or1ksim} OpenRISC 1000 Architectural
14251Simulator, proprietary commands can be executed.
14252
14253@kindex info or1k spr
14254@item info or1k spr
14255Displays spr groups.
14256
14257@item info or1k spr @var{group}
14258@itemx info or1k spr @var{groupno}
14259Displays register names in selected group.
14260
14261@item info or1k spr @var{group} @var{register}
14262@itemx info or1k spr @var{register}
14263@itemx info or1k spr @var{groupno} @var{registerno}
14264@itemx info or1k spr @var{registerno}
14265Shows information about specified spr register.
14266
14267@kindex spr
14268@item spr @var{group} @var{register} @var{value}
14269@itemx spr @var{register @var{value}}
14270@itemx spr @var{groupno} @var{registerno @var{value}}
14271@itemx spr @var{registerno @var{value}}
14272Writes @var{value} to specified spr register.
14273@end table
14274
14275Some implementations of OpenRISC 1000 Architecture also have hardware trace.
14276It is very similar to @value{GDBN} trace, except it does not interfere with normal
14277program execution and is thus much faster. Hardware breakpoints/watchpoint
14278triggers can be set using:
14279@table @code
14280@item $LEA/$LDATA
14281Load effective address/data
14282@item $SEA/$SDATA
14283Store effective address/data
14284@item $AEA/$ADATA
14285Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
14286@item $FETCH
14287Fetch data
14288@end table
14289
14290When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
14291@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
14292
14293@code{htrace} commands:
14294@cindex OpenRISC 1000 htrace
14295@table @code
14296@kindex hwatch
14297@item hwatch @var{conditional}
14298Set hardware watchpoint on combination of Load/Store Effecive Address(es)
14299or Data. For example:
14300
14301@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14302
14303@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
14304
4644b6e3 14305@kindex htrace
a37295f9
MM
14306@item htrace info
14307Display information about current HW trace configuration.
14308
a37295f9
MM
14309@item htrace trigger @var{conditional}
14310Set starting criteria for HW trace.
14311
a37295f9
MM
14312@item htrace qualifier @var{conditional}
14313Set acquisition qualifier for HW trace.
14314
a37295f9
MM
14315@item htrace stop @var{conditional}
14316Set HW trace stopping criteria.
14317
f153cc92 14318@item htrace record [@var{data}]*
a37295f9
MM
14319Selects the data to be recorded, when qualifier is met and HW trace was
14320triggered.
14321
a37295f9 14322@item htrace enable
a37295f9
MM
14323@itemx htrace disable
14324Enables/disables the HW trace.
14325
f153cc92 14326@item htrace rewind [@var{filename}]
a37295f9
MM
14327Clears currently recorded trace data.
14328
14329If filename is specified, new trace file is made and any newly collected data
14330will be written there.
14331
f153cc92 14332@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
14333Prints trace buffer, using current record configuration.
14334
a37295f9
MM
14335@item htrace mode continuous
14336Set continuous trace mode.
14337
a37295f9
MM
14338@item htrace mode suspend
14339Set suspend trace mode.
14340
14341@end table
14342
8e04817f
AC
14343@node PowerPC
14344@subsection PowerPC
104c1213
JM
14345
14346@table @code
8e04817f
AC
14347@kindex target dink32
14348@item target dink32 @var{dev}
14349DINK32 ROM monitor.
104c1213 14350
8e04817f
AC
14351@kindex target ppcbug
14352@item target ppcbug @var{dev}
14353@kindex target ppcbug1
14354@item target ppcbug1 @var{dev}
14355PPCBUG ROM monitor for PowerPC.
104c1213 14356
8e04817f
AC
14357@kindex target sds
14358@item target sds @var{dev}
14359SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 14360@end table
8e04817f 14361
c45da7e6
EZ
14362@cindex SDS protocol
14363The following commands specifi to the SDS protocol are supported
14364by@value{GDBN}:
14365
14366@table @code
14367@item set sdstimeout @var{nsec}
14368@kindex set sdstimeout
14369Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
14370default is 2 seconds.
14371
14372@item show sdstimeout
14373@kindex show sdstimeout
14374Show the current value of the SDS timeout.
14375
14376@item sds @var{command}
14377@kindex sds@r{, a command}
14378Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
14379@end table
14380
c45da7e6 14381
8e04817f
AC
14382@node PA
14383@subsection HP PA Embedded
104c1213
JM
14384
14385@table @code
14386
8e04817f
AC
14387@kindex target op50n
14388@item target op50n @var{dev}
14389OP50N monitor, running on an OKI HPPA board.
14390
14391@kindex target w89k
14392@item target w89k @var{dev}
14393W89K monitor, running on a Winbond HPPA board.
104c1213
JM
14394
14395@end table
14396
8e04817f 14397@node SH
172c2a43 14398@subsection Renesas SH
104c1213
JM
14399
14400@table @code
14401
172c2a43 14402@kindex target hms@r{, with Renesas SH}
8e04817f 14403@item target hms @var{dev}
172c2a43 14404A Renesas SH board attached via serial line to your host. Use special
8e04817f
AC
14405commands @code{device} and @code{speed} to control the serial line and
14406the communications speed used.
104c1213 14407
172c2a43 14408@kindex target e7000@r{, with Renesas SH}
8e04817f 14409@item target e7000 @var{dev}
172c2a43 14410E7000 emulator for Renesas SH.
104c1213 14411
8e04817f
AC
14412@kindex target sh3@r{, with SH}
14413@kindex target sh3e@r{, with SH}
14414@item target sh3 @var{dev}
14415@item target sh3e @var{dev}
172c2a43 14416Renesas SH-3 and SH-3E target systems.
104c1213 14417
8e04817f 14418@end table
104c1213 14419
8e04817f
AC
14420@node Sparclet
14421@subsection Tsqware Sparclet
104c1213 14422
8e04817f
AC
14423@cindex Sparclet
14424
14425@value{GDBN} enables developers to debug tasks running on
14426Sparclet targets from a Unix host.
14427@value{GDBN} uses code that runs on
14428both the Unix host and on the Sparclet target. The program
14429@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 14430
8e04817f
AC
14431@table @code
14432@item remotetimeout @var{args}
14433@kindex remotetimeout
14434@value{GDBN} supports the option @code{remotetimeout}.
14435This option is set by the user, and @var{args} represents the number of
14436seconds @value{GDBN} waits for responses.
104c1213
JM
14437@end table
14438
8e04817f
AC
14439@cindex compiling, on Sparclet
14440When compiling for debugging, include the options @samp{-g} to get debug
14441information and @samp{-Ttext} to relocate the program to where you wish to
14442load it on the target. You may also want to add the options @samp{-n} or
14443@samp{-N} in order to reduce the size of the sections. Example:
104c1213 14444
474c8240 14445@smallexample
8e04817f 14446sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 14447@end smallexample
104c1213 14448
8e04817f 14449You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 14450
474c8240 14451@smallexample
8e04817f 14452sparclet-aout-objdump --headers --syms prog
474c8240 14453@end smallexample
104c1213 14454
8e04817f
AC
14455@cindex running, on Sparclet
14456Once you have set
14457your Unix execution search path to find @value{GDBN}, you are ready to
14458run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
14459(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 14460
8e04817f
AC
14461@value{GDBN} comes up showing the prompt:
14462
474c8240 14463@smallexample
8e04817f 14464(gdbslet)
474c8240 14465@end smallexample
104c1213
JM
14466
14467@menu
8e04817f
AC
14468* Sparclet File:: Setting the file to debug
14469* Sparclet Connection:: Connecting to Sparclet
14470* Sparclet Download:: Sparclet download
14471* Sparclet Execution:: Running and debugging
104c1213
JM
14472@end menu
14473
8e04817f
AC
14474@node Sparclet File
14475@subsubsection Setting file to debug
104c1213 14476
8e04817f 14477The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 14478
474c8240 14479@smallexample
8e04817f 14480(gdbslet) file prog
474c8240 14481@end smallexample
104c1213 14482
8e04817f
AC
14483@need 1000
14484@value{GDBN} then attempts to read the symbol table of @file{prog}.
14485@value{GDBN} locates
14486the file by searching the directories listed in the command search
14487path.
14488If the file was compiled with debug information (option "-g"), source
14489files will be searched as well.
14490@value{GDBN} locates
14491the source files by searching the directories listed in the directory search
14492path (@pxref{Environment, ,Your program's environment}).
14493If it fails
14494to find a file, it displays a message such as:
104c1213 14495
474c8240 14496@smallexample
8e04817f 14497prog: No such file or directory.
474c8240 14498@end smallexample
104c1213 14499
8e04817f
AC
14500When this happens, add the appropriate directories to the search paths with
14501the @value{GDBN} commands @code{path} and @code{dir}, and execute the
14502@code{target} command again.
104c1213 14503
8e04817f
AC
14504@node Sparclet Connection
14505@subsubsection Connecting to Sparclet
104c1213 14506
8e04817f
AC
14507The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
14508To connect to a target on serial port ``@code{ttya}'', type:
104c1213 14509
474c8240 14510@smallexample
8e04817f
AC
14511(gdbslet) target sparclet /dev/ttya
14512Remote target sparclet connected to /dev/ttya
14513main () at ../prog.c:3
474c8240 14514@end smallexample
104c1213 14515
8e04817f
AC
14516@need 750
14517@value{GDBN} displays messages like these:
104c1213 14518
474c8240 14519@smallexample
8e04817f 14520Connected to ttya.
474c8240 14521@end smallexample
104c1213 14522
8e04817f
AC
14523@node Sparclet Download
14524@subsubsection Sparclet download
104c1213 14525
8e04817f
AC
14526@cindex download to Sparclet
14527Once connected to the Sparclet target,
14528you can use the @value{GDBN}
14529@code{load} command to download the file from the host to the target.
14530The file name and load offset should be given as arguments to the @code{load}
14531command.
14532Since the file format is aout, the program must be loaded to the starting
14533address. You can use @code{objdump} to find out what this value is. The load
14534offset is an offset which is added to the VMA (virtual memory address)
14535of each of the file's sections.
14536For instance, if the program
14537@file{prog} was linked to text address 0x1201000, with data at 0x12010160
14538and bss at 0x12010170, in @value{GDBN}, type:
104c1213 14539
474c8240 14540@smallexample
8e04817f
AC
14541(gdbslet) load prog 0x12010000
14542Loading section .text, size 0xdb0 vma 0x12010000
474c8240 14543@end smallexample
104c1213 14544
8e04817f
AC
14545If the code is loaded at a different address then what the program was linked
14546to, you may need to use the @code{section} and @code{add-symbol-file} commands
14547to tell @value{GDBN} where to map the symbol table.
14548
14549@node Sparclet Execution
14550@subsubsection Running and debugging
14551
14552@cindex running and debugging Sparclet programs
14553You can now begin debugging the task using @value{GDBN}'s execution control
14554commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
14555manual for the list of commands.
14556
474c8240 14557@smallexample
8e04817f
AC
14558(gdbslet) b main
14559Breakpoint 1 at 0x12010000: file prog.c, line 3.
14560(gdbslet) run
14561Starting program: prog
14562Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
145633 char *symarg = 0;
14564(gdbslet) step
145654 char *execarg = "hello!";
14566(gdbslet)
474c8240 14567@end smallexample
8e04817f
AC
14568
14569@node Sparclite
14570@subsection Fujitsu Sparclite
104c1213
JM
14571
14572@table @code
14573
8e04817f
AC
14574@kindex target sparclite
14575@item target sparclite @var{dev}
14576Fujitsu sparclite boards, used only for the purpose of loading.
14577You must use an additional command to debug the program.
14578For example: target remote @var{dev} using @value{GDBN} standard
14579remote protocol.
104c1213
JM
14580
14581@end table
14582
8e04817f
AC
14583@node ST2000
14584@subsection Tandem ST2000
104c1213 14585
8e04817f
AC
14586@value{GDBN} may be used with a Tandem ST2000 phone switch, running Tandem's
14587STDBUG protocol.
104c1213 14588
8e04817f
AC
14589To connect your ST2000 to the host system, see the manufacturer's
14590manual. Once the ST2000 is physically attached, you can run:
104c1213 14591
474c8240 14592@smallexample
8e04817f 14593target st2000 @var{dev} @var{speed}
474c8240 14594@end smallexample
104c1213 14595
8e04817f
AC
14596@noindent
14597to establish it as your debugging environment. @var{dev} is normally
14598the name of a serial device, such as @file{/dev/ttya}, connected to the
14599ST2000 via a serial line. You can instead specify @var{dev} as a TCP
14600connection (for example, to a serial line attached via a terminal
14601concentrator) using the syntax @code{@var{hostname}:@var{portnumber}}.
104c1213 14602
8e04817f
AC
14603The @code{load} and @code{attach} commands are @emph{not} defined for
14604this target; you must load your program into the ST2000 as you normally
14605would for standalone operation. @value{GDBN} reads debugging information
14606(such as symbols) from a separate, debugging version of the program
14607available on your host computer.
14608@c FIXME!! This is terribly vague; what little content is here is
14609@c basically hearsay.
104c1213 14610
8e04817f
AC
14611@cindex ST2000 auxiliary commands
14612These auxiliary @value{GDBN} commands are available to help you with the ST2000
14613environment:
104c1213 14614
8e04817f
AC
14615@table @code
14616@item st2000 @var{command}
14617@kindex st2000 @var{cmd}
14618@cindex STDBUG commands (ST2000)
14619@cindex commands to STDBUG (ST2000)
14620Send a @var{command} to the STDBUG monitor. See the manufacturer's
14621manual for available commands.
104c1213 14622
8e04817f
AC
14623@item connect
14624@cindex connect (to STDBUG)
14625Connect the controlling terminal to the STDBUG command monitor. When
14626you are done interacting with STDBUG, typing either of two character
14627sequences gets you back to the @value{GDBN} command prompt:
14628@kbd{@key{RET}~.} (Return, followed by tilde and period) or
14629@kbd{@key{RET}~@key{C-d}} (Return, followed by tilde and control-D).
104c1213
JM
14630@end table
14631
8e04817f
AC
14632@node Z8000
14633@subsection Zilog Z8000
104c1213 14634
8e04817f
AC
14635@cindex Z8000
14636@cindex simulator, Z8000
14637@cindex Zilog Z8000 simulator
104c1213 14638
8e04817f
AC
14639When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
14640a Z8000 simulator.
14641
14642For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
14643unsegmented variant of the Z8000 architecture) or the Z8001 (the
14644segmented variant). The simulator recognizes which architecture is
14645appropriate by inspecting the object code.
104c1213 14646
8e04817f
AC
14647@table @code
14648@item target sim @var{args}
14649@kindex sim
14650@kindex target sim@r{, with Z8000}
14651Debug programs on a simulated CPU. If the simulator supports setup
14652options, specify them via @var{args}.
104c1213
JM
14653@end table
14654
8e04817f
AC
14655@noindent
14656After specifying this target, you can debug programs for the simulated
14657CPU in the same style as programs for your host computer; use the
14658@code{file} command to load a new program image, the @code{run} command
14659to run your program, and so on.
14660
14661As well as making available all the usual machine registers
14662(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
14663additional items of information as specially named registers:
104c1213
JM
14664
14665@table @code
14666
8e04817f
AC
14667@item cycles
14668Counts clock-ticks in the simulator.
104c1213 14669
8e04817f
AC
14670@item insts
14671Counts instructions run in the simulator.
104c1213 14672
8e04817f
AC
14673@item time
14674Execution time in 60ths of a second.
104c1213 14675
8e04817f 14676@end table
104c1213 14677
8e04817f
AC
14678You can refer to these values in @value{GDBN} expressions with the usual
14679conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
14680conditional breakpoint that suspends only after at least 5000
14681simulated clock ticks.
104c1213 14682
a64548ea
EZ
14683@node AVR
14684@subsection Atmel AVR
14685@cindex AVR
14686
14687When configured for debugging the Atmel AVR, @value{GDBN} supports the
14688following AVR-specific commands:
14689
14690@table @code
14691@item info io_registers
14692@kindex info io_registers@r{, AVR}
14693@cindex I/O registers (Atmel AVR)
14694This command displays information about the AVR I/O registers. For
14695each register, @value{GDBN} prints its number and value.
14696@end table
14697
14698@node CRIS
14699@subsection CRIS
14700@cindex CRIS
14701
14702When configured for debugging CRIS, @value{GDBN} provides the
14703following CRIS-specific commands:
14704
14705@table @code
14706@item set cris-version @var{ver}
14707@cindex CRIS version
e22e55c9
OF
14708Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
14709The CRIS version affects register names and sizes. This command is useful in
14710case autodetection of the CRIS version fails.
a64548ea
EZ
14711
14712@item show cris-version
14713Show the current CRIS version.
14714
14715@item set cris-dwarf2-cfi
14716@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
14717Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
14718Change to @samp{off} when using @code{gcc-cris} whose version is below
14719@code{R59}.
a64548ea
EZ
14720
14721@item show cris-dwarf2-cfi
14722Show the current state of using DWARF-2 CFI.
e22e55c9
OF
14723
14724@item set cris-mode @var{mode}
14725@cindex CRIS mode
14726Set the current CRIS mode to @var{mode}. It should only be changed when
14727debugging in guru mode, in which case it should be set to
14728@samp{guru} (the default is @samp{normal}).
14729
14730@item show cris-mode
14731Show the current CRIS mode.
a64548ea
EZ
14732@end table
14733
14734@node Super-H
14735@subsection Renesas Super-H
14736@cindex Super-H
14737
14738For the Renesas Super-H processor, @value{GDBN} provides these
14739commands:
14740
14741@table @code
14742@item regs
14743@kindex regs@r{, Super-H}
14744Show the values of all Super-H registers.
14745@end table
14746
c45da7e6
EZ
14747@node WinCE
14748@subsection Windows CE
14749@cindex Windows CE
14750
14751The following commands are available for Windows CE:
14752
14753@table @code
14754@item set remotedirectory @var{dir}
14755@kindex set remotedirectory
14756Tell @value{GDBN} to upload files from the named directory @var{dir}.
14757The default is @file{/gdb}, i.e.@: the root directory on the current
14758drive.
14759
14760@item show remotedirectory
14761@kindex show remotedirectory
14762Show the current value of the upload directory.
14763
14764@item set remoteupload @var{method}
14765@kindex set remoteupload
14766Set the method used to upload files to remote device. Valid values
14767for @var{method} are @samp{always}, @samp{newer}, and @samp{never}.
14768The default is @samp{newer}.
14769
14770@item show remoteupload
14771@kindex show remoteupload
14772Show the current setting of the upload method.
14773
14774@item set remoteaddhost
14775@kindex set remoteaddhost
14776Tell @value{GDBN} whether to add this host to the remote stub's
14777arguments when you debug over a network.
14778
14779@item show remoteaddhost
14780@kindex show remoteaddhost
14781Show whether to add this host to remote stub's arguments when
14782debugging over a network.
14783@end table
14784
a64548ea 14785
8e04817f
AC
14786@node Architectures
14787@section Architectures
104c1213 14788
8e04817f
AC
14789This section describes characteristics of architectures that affect
14790all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 14791
8e04817f 14792@menu
9c16f35a 14793* i386::
8e04817f
AC
14794* A29K::
14795* Alpha::
14796* MIPS::
a64548ea 14797* HPPA:: HP PA architecture
8e04817f 14798@end menu
104c1213 14799
9c16f35a
EZ
14800@node i386
14801@subsection x86 Architecture-specific issues.
14802
14803@table @code
14804@item set struct-convention @var{mode}
14805@kindex set struct-convention
14806@cindex struct return convention
14807@cindex struct/union returned in registers
14808Set the convention used by the inferior to return @code{struct}s and
14809@code{union}s from functions to @var{mode}. Possible values of
14810@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
14811default). @code{"default"} or @code{"pcc"} means that @code{struct}s
14812are returned on the stack, while @code{"reg"} means that a
14813@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
14814be returned in a register.
14815
14816@item show struct-convention
14817@kindex show struct-convention
14818Show the current setting of the convention to return @code{struct}s
14819from functions.
14820@end table
14821
8e04817f
AC
14822@node A29K
14823@subsection A29K
104c1213
JM
14824
14825@table @code
104c1213 14826
8e04817f
AC
14827@kindex set rstack_high_address
14828@cindex AMD 29K register stack
14829@cindex register stack, AMD29K
14830@item set rstack_high_address @var{address}
14831On AMD 29000 family processors, registers are saved in a separate
14832@dfn{register stack}. There is no way for @value{GDBN} to determine the
14833extent of this stack. Normally, @value{GDBN} just assumes that the
14834stack is ``large enough''. This may result in @value{GDBN} referencing
14835memory locations that do not exist. If necessary, you can get around
14836this problem by specifying the ending address of the register stack with
14837the @code{set rstack_high_address} command. The argument should be an
14838address, which you probably want to precede with @samp{0x} to specify in
14839hexadecimal.
104c1213 14840
8e04817f
AC
14841@kindex show rstack_high_address
14842@item show rstack_high_address
14843Display the current limit of the register stack, on AMD 29000 family
14844processors.
104c1213 14845
8e04817f 14846@end table
104c1213 14847
8e04817f
AC
14848@node Alpha
14849@subsection Alpha
104c1213 14850
8e04817f 14851See the following section.
104c1213 14852
8e04817f
AC
14853@node MIPS
14854@subsection MIPS
104c1213 14855
8e04817f
AC
14856@cindex stack on Alpha
14857@cindex stack on MIPS
14858@cindex Alpha stack
14859@cindex MIPS stack
14860Alpha- and MIPS-based computers use an unusual stack frame, which
14861sometimes requires @value{GDBN} to search backward in the object code to
14862find the beginning of a function.
104c1213 14863
8e04817f
AC
14864@cindex response time, MIPS debugging
14865To improve response time (especially for embedded applications, where
14866@value{GDBN} may be restricted to a slow serial line for this search)
14867you may want to limit the size of this search, using one of these
14868commands:
104c1213 14869
8e04817f
AC
14870@table @code
14871@cindex @code{heuristic-fence-post} (Alpha, MIPS)
14872@item set heuristic-fence-post @var{limit}
14873Restrict @value{GDBN} to examining at most @var{limit} bytes in its
14874search for the beginning of a function. A value of @var{0} (the
14875default) means there is no limit. However, except for @var{0}, the
14876larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
14877and therefore the longer it takes to run. You should only need to use
14878this command when debugging a stripped executable.
104c1213 14879
8e04817f
AC
14880@item show heuristic-fence-post
14881Display the current limit.
14882@end table
104c1213
JM
14883
14884@noindent
8e04817f
AC
14885These commands are available @emph{only} when @value{GDBN} is configured
14886for debugging programs on Alpha or MIPS processors.
104c1213 14887
a64548ea
EZ
14888Several MIPS-specific commands are available when debugging MIPS
14889programs:
14890
14891@table @code
14892@item set mips saved-gpreg-size @var{size}
14893@kindex set mips saved-gpreg-size
14894@cindex MIPS GP register size on stack
14895Set the size of MIPS general-purpose registers saved on the stack.
14896The argument @var{size} can be one of the following:
14897
14898@table @samp
14899@item 32
1490032-bit GP registers
14901@item 64
1490264-bit GP registers
14903@item auto
14904Use the target's default setting or autodetect the saved size from the
14905information contained in the executable. This is the default
14906@end table
14907
14908@item show mips saved-gpreg-size
14909@kindex show mips saved-gpreg-size
14910Show the current size of MIPS GP registers on the stack.
14911
14912@item set mips stack-arg-size @var{size}
14913@kindex set mips stack-arg-size
14914@cindex MIPS stack space for arguments
14915Set the amount of stack space reserved for arguments to functions.
14916The argument can be one of @code{"32"}, @code{"64"} or @code{"auto"}
14917(the default).
14918
14919@item set mips abi @var{arg}
14920@kindex set mips abi
14921@cindex set ABI for MIPS
14922Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
14923values of @var{arg} are:
14924
14925@table @samp
14926@item auto
14927The default ABI associated with the current binary (this is the
14928default).
14929@item o32
14930@item o64
14931@item n32
14932@item n64
14933@item eabi32
14934@item eabi64
14935@item auto
14936@end table
14937
14938@item show mips abi
14939@kindex show mips abi
14940Show the MIPS ABI used by @value{GDBN} to debug the inferior.
14941
14942@item set mipsfpu
14943@itemx show mipsfpu
14944@xref{MIPS Embedded, set mipsfpu}.
14945
14946@item set mips mask-address @var{arg}
14947@kindex set mips mask-address
14948@cindex MIPS addresses, masking
14949This command determines whether the most-significant 32 bits of 64-bit
14950MIPS addresses are masked off. The argument @var{arg} can be
14951@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
14952setting, which lets @value{GDBN} determine the correct value.
14953
14954@item show mips mask-address
14955@kindex show mips mask-address
14956Show whether the upper 32 bits of MIPS addresses are masked off or
14957not.
14958
14959@item set remote-mips64-transfers-32bit-regs
14960@kindex set remote-mips64-transfers-32bit-regs
14961This command controls compatibility with 64-bit MIPS targets that
14962transfer data in 32-bit quantities. If you have an old MIPS 64 target
14963that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
14964and 64 bits for other registers, set this option to @samp{on}.
14965
14966@item show remote-mips64-transfers-32bit-regs
14967@kindex show remote-mips64-transfers-32bit-regs
14968Show the current setting of compatibility with older MIPS 64 targets.
14969
14970@item set debug mips
14971@kindex set debug mips
14972This command turns on and off debugging messages for the MIPS-specific
14973target code in @value{GDBN}.
14974
14975@item show debug mips
14976@kindex show debug mips
14977Show the current setting of MIPS debugging messages.
14978@end table
14979
14980
14981@node HPPA
14982@subsection HPPA
14983@cindex HPPA support
14984
14985When @value{GDBN} is debugging te HP PA architecture, it provides the
14986following special commands:
14987
14988@table @code
14989@item set debug hppa
14990@kindex set debug hppa
14991THis command determines whether HPPA architecture specific debugging
14992messages are to be displayed.
14993
14994@item show debug hppa
14995Show whether HPPA debugging messages are displayed.
14996
14997@item maint print unwind @var{address}
14998@kindex maint print unwind@r{, HPPA}
14999This command displays the contents of the unwind table entry at the
15000given @var{address}.
15001
15002@end table
15003
104c1213 15004
8e04817f
AC
15005@node Controlling GDB
15006@chapter Controlling @value{GDBN}
15007
15008You can alter the way @value{GDBN} interacts with you by using the
15009@code{set} command. For commands controlling how @value{GDBN} displays
15010data, see @ref{Print Settings, ,Print settings}. Other settings are
15011described here.
15012
15013@menu
15014* Prompt:: Prompt
15015* Editing:: Command editing
d620b259 15016* Command History:: Command history
8e04817f
AC
15017* Screen Size:: Screen size
15018* Numbers:: Numbers
1e698235 15019* ABI:: Configuring the current ABI
8e04817f
AC
15020* Messages/Warnings:: Optional warnings and messages
15021* Debugging Output:: Optional messages about internal happenings
15022@end menu
15023
15024@node Prompt
15025@section Prompt
104c1213 15026
8e04817f 15027@cindex prompt
104c1213 15028
8e04817f
AC
15029@value{GDBN} indicates its readiness to read a command by printing a string
15030called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15031can change the prompt string with the @code{set prompt} command. For
15032instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15033the prompt in one of the @value{GDBN} sessions so that you can always tell
15034which one you are talking to.
104c1213 15035
8e04817f
AC
15036@emph{Note:} @code{set prompt} does not add a space for you after the
15037prompt you set. This allows you to set a prompt which ends in a space
15038or a prompt that does not.
104c1213 15039
8e04817f
AC
15040@table @code
15041@kindex set prompt
15042@item set prompt @var{newprompt}
15043Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 15044
8e04817f
AC
15045@kindex show prompt
15046@item show prompt
15047Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
15048@end table
15049
8e04817f
AC
15050@node Editing
15051@section Command editing
15052@cindex readline
15053@cindex command line editing
104c1213 15054
703663ab 15055@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
15056@sc{gnu} library provides consistent behavior for programs which provide a
15057command line interface to the user. Advantages are @sc{gnu} Emacs-style
15058or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15059substitution, and a storage and recall of command history across
15060debugging sessions.
104c1213 15061
8e04817f
AC
15062You may control the behavior of command line editing in @value{GDBN} with the
15063command @code{set}.
104c1213 15064
8e04817f
AC
15065@table @code
15066@kindex set editing
15067@cindex editing
15068@item set editing
15069@itemx set editing on
15070Enable command line editing (enabled by default).
104c1213 15071
8e04817f
AC
15072@item set editing off
15073Disable command line editing.
104c1213 15074
8e04817f
AC
15075@kindex show editing
15076@item show editing
15077Show whether command line editing is enabled.
104c1213
JM
15078@end table
15079
703663ab
EZ
15080@xref{Command Line Editing}, for more details about the Readline
15081interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15082encouraged to read that chapter.
15083
d620b259 15084@node Command History
8e04817f 15085@section Command history
703663ab 15086@cindex command history
8e04817f
AC
15087
15088@value{GDBN} can keep track of the commands you type during your
15089debugging sessions, so that you can be certain of precisely what
15090happened. Use these commands to manage the @value{GDBN} command
15091history facility.
104c1213 15092
703663ab
EZ
15093@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15094package, to provide the history facility. @xref{Using History
15095Interactively}, for the detailed description of the History library.
15096
d620b259
NR
15097To issue a command to @value{GDBN} without affecting certain aspects of
15098the state which is seen by users, prefix it with @samp{server }. This
15099means that this command will not affect the command history, nor will it
15100affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15101pressed on a line by itself.
15102
15103@cindex @code{server}, command prefix
15104The server prefix does not affect the recording of values into the value
15105history; to print a value without recording it into the value history,
15106use the @code{output} command instead of the @code{print} command.
15107
703663ab
EZ
15108Here is the description of @value{GDBN} commands related to command
15109history.
15110
104c1213 15111@table @code
8e04817f
AC
15112@cindex history substitution
15113@cindex history file
15114@kindex set history filename
4644b6e3 15115@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
15116@item set history filename @var{fname}
15117Set the name of the @value{GDBN} command history file to @var{fname}.
15118This is the file where @value{GDBN} reads an initial command history
15119list, and where it writes the command history from this session when it
15120exits. You can access this list through history expansion or through
15121the history command editing characters listed below. This file defaults
15122to the value of the environment variable @code{GDBHISTFILE}, or to
15123@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15124is not set.
104c1213 15125
9c16f35a
EZ
15126@cindex save command history
15127@kindex set history save
8e04817f
AC
15128@item set history save
15129@itemx set history save on
15130Record command history in a file, whose name may be specified with the
15131@code{set history filename} command. By default, this option is disabled.
104c1213 15132
8e04817f
AC
15133@item set history save off
15134Stop recording command history in a file.
104c1213 15135
8e04817f 15136@cindex history size
9c16f35a 15137@kindex set history size
6fc08d32 15138@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
15139@item set history size @var{size}
15140Set the number of commands which @value{GDBN} keeps in its history list.
15141This defaults to the value of the environment variable
15142@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
15143@end table
15144
8e04817f 15145History expansion assigns special meaning to the character @kbd{!}.
703663ab 15146@xref{Event Designators}, for more details.
8e04817f 15147
703663ab 15148@cindex history expansion, turn on/off
8e04817f
AC
15149Since @kbd{!} is also the logical not operator in C, history expansion
15150is off by default. If you decide to enable history expansion with the
15151@code{set history expansion on} command, you may sometimes need to
15152follow @kbd{!} (when it is used as logical not, in an expression) with
15153a space or a tab to prevent it from being expanded. The readline
15154history facilities do not attempt substitution on the strings
15155@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15156
15157The commands to control history expansion are:
104c1213
JM
15158
15159@table @code
8e04817f
AC
15160@item set history expansion on
15161@itemx set history expansion
703663ab 15162@kindex set history expansion
8e04817f 15163Enable history expansion. History expansion is off by default.
104c1213 15164
8e04817f
AC
15165@item set history expansion off
15166Disable history expansion.
104c1213 15167
8e04817f
AC
15168@c @group
15169@kindex show history
15170@item show history
15171@itemx show history filename
15172@itemx show history save
15173@itemx show history size
15174@itemx show history expansion
15175These commands display the state of the @value{GDBN} history parameters.
15176@code{show history} by itself displays all four states.
15177@c @end group
15178@end table
15179
15180@table @code
9c16f35a
EZ
15181@kindex show commands
15182@cindex show last commands
15183@cindex display command history
8e04817f
AC
15184@item show commands
15185Display the last ten commands in the command history.
104c1213 15186
8e04817f
AC
15187@item show commands @var{n}
15188Print ten commands centered on command number @var{n}.
15189
15190@item show commands +
15191Print ten commands just after the commands last printed.
104c1213
JM
15192@end table
15193
8e04817f
AC
15194@node Screen Size
15195@section Screen size
15196@cindex size of screen
15197@cindex pauses in output
104c1213 15198
8e04817f
AC
15199Certain commands to @value{GDBN} may produce large amounts of
15200information output to the screen. To help you read all of it,
15201@value{GDBN} pauses and asks you for input at the end of each page of
15202output. Type @key{RET} when you want to continue the output, or @kbd{q}
15203to discard the remaining output. Also, the screen width setting
15204determines when to wrap lines of output. Depending on what is being
15205printed, @value{GDBN} tries to break the line at a readable place,
15206rather than simply letting it overflow onto the following line.
15207
15208Normally @value{GDBN} knows the size of the screen from the terminal
15209driver software. For example, on Unix @value{GDBN} uses the termcap data base
15210together with the value of the @code{TERM} environment variable and the
15211@code{stty rows} and @code{stty cols} settings. If this is not correct,
15212you can override it with the @code{set height} and @code{set
15213width} commands:
15214
15215@table @code
15216@kindex set height
15217@kindex set width
15218@kindex show width
15219@kindex show height
15220@item set height @var{lpp}
15221@itemx show height
15222@itemx set width @var{cpl}
15223@itemx show width
15224These @code{set} commands specify a screen height of @var{lpp} lines and
15225a screen width of @var{cpl} characters. The associated @code{show}
15226commands display the current settings.
104c1213 15227
8e04817f
AC
15228If you specify a height of zero lines, @value{GDBN} does not pause during
15229output no matter how long the output is. This is useful if output is to a
15230file or to an editor buffer.
104c1213 15231
8e04817f
AC
15232Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
15233from wrapping its output.
9c16f35a
EZ
15234
15235@item set pagination on
15236@itemx set pagination off
15237@kindex set pagination
15238Turn the output pagination on or off; the default is on. Turning
15239pagination off is the alternative to @code{set height 0}.
15240
15241@item show pagination
15242@kindex show pagination
15243Show the current pagination mode.
104c1213
JM
15244@end table
15245
8e04817f
AC
15246@node Numbers
15247@section Numbers
15248@cindex number representation
15249@cindex entering numbers
104c1213 15250
8e04817f
AC
15251You can always enter numbers in octal, decimal, or hexadecimal in
15252@value{GDBN} by the usual conventions: octal numbers begin with
15253@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
15254begin with @samp{0x}. Numbers that neither begin with @samp{0} or
15255@samp{0x}, nor end with a @samp{.} are, by default, entered in base
1525610; likewise, the default display for numbers---when no particular
15257format is specified---is base 10. You can change the default base for
15258both input and output with the commands described below.
104c1213 15259
8e04817f
AC
15260@table @code
15261@kindex set input-radix
15262@item set input-radix @var{base}
15263Set the default base for numeric input. Supported choices
15264for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15265specified either unambiguously or using the current input radix; for
8e04817f 15266example, any of
104c1213 15267
8e04817f 15268@smallexample
9c16f35a
EZ
15269set input-radix 012
15270set input-radix 10.
15271set input-radix 0xa
8e04817f 15272@end smallexample
104c1213 15273
8e04817f 15274@noindent
9c16f35a 15275sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
15276leaves the input radix unchanged, no matter what it was, since
15277@samp{10}, being without any leading or trailing signs of its base, is
15278interpreted in the current radix. Thus, if the current radix is 16,
15279@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
15280change the radix.
104c1213 15281
8e04817f
AC
15282@kindex set output-radix
15283@item set output-radix @var{base}
15284Set the default base for numeric display. Supported choices
15285for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 15286specified either unambiguously or using the current input radix.
104c1213 15287
8e04817f
AC
15288@kindex show input-radix
15289@item show input-radix
15290Display the current default base for numeric input.
104c1213 15291
8e04817f
AC
15292@kindex show output-radix
15293@item show output-radix
15294Display the current default base for numeric display.
9c16f35a
EZ
15295
15296@item set radix @r{[}@var{base}@r{]}
15297@itemx show radix
15298@kindex set radix
15299@kindex show radix
15300These commands set and show the default base for both input and output
15301of numbers. @code{set radix} sets the radix of input and output to
15302the same base; without an argument, it resets the radix back to its
15303default value of 10.
15304
8e04817f 15305@end table
104c1213 15306
1e698235
DJ
15307@node ABI
15308@section Configuring the current ABI
15309
15310@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
15311application automatically. However, sometimes you need to override its
15312conclusions. Use these commands to manage @value{GDBN}'s view of the
15313current ABI.
15314
98b45e30
DJ
15315@cindex OS ABI
15316@kindex set osabi
b4e9345d 15317@kindex show osabi
98b45e30
DJ
15318
15319One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 15320system targets, either via remote debugging or native emulation.
98b45e30
DJ
15321@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
15322but you can override its conclusion using the @code{set osabi} command.
15323One example where this is useful is in debugging of binaries which use
15324an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
15325not have the same identifying marks that the standard C library for your
15326platform provides.
15327
15328@table @code
15329@item show osabi
15330Show the OS ABI currently in use.
15331
15332@item set osabi
15333With no argument, show the list of registered available OS ABI's.
15334
15335@item set osabi @var{abi}
15336Set the current OS ABI to @var{abi}.
15337@end table
15338
1e698235 15339@cindex float promotion
1e698235
DJ
15340
15341Generally, the way that an argument of type @code{float} is passed to a
15342function depends on whether the function is prototyped. For a prototyped
15343(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
15344according to the architecture's convention for @code{float}. For unprototyped
15345(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
15346@code{double} and then passed.
15347
15348Unfortunately, some forms of debug information do not reliably indicate whether
15349a function is prototyped. If @value{GDBN} calls a function that is not marked
15350as prototyped, it consults @kbd{set coerce-float-to-double}.
15351
15352@table @code
a8f24a35 15353@kindex set coerce-float-to-double
1e698235
DJ
15354@item set coerce-float-to-double
15355@itemx set coerce-float-to-double on
15356Arguments of type @code{float} will be promoted to @code{double} when passed
15357to an unprototyped function. This is the default setting.
15358
15359@item set coerce-float-to-double off
15360Arguments of type @code{float} will be passed directly to unprototyped
15361functions.
9c16f35a
EZ
15362
15363@kindex show coerce-float-to-double
15364@item show coerce-float-to-double
15365Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
15366@end table
15367
f1212245
DJ
15368@kindex set cp-abi
15369@kindex show cp-abi
15370@value{GDBN} needs to know the ABI used for your program's C@t{++}
15371objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
15372used to build your application. @value{GDBN} only fully supports
15373programs with a single C@t{++} ABI; if your program contains code using
15374multiple C@t{++} ABI's or if @value{GDBN} can not identify your
15375program's ABI correctly, you can tell @value{GDBN} which ABI to use.
15376Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
15377before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
15378``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
15379use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
15380``auto''.
15381
15382@table @code
15383@item show cp-abi
15384Show the C@t{++} ABI currently in use.
15385
15386@item set cp-abi
15387With no argument, show the list of supported C@t{++} ABI's.
15388
15389@item set cp-abi @var{abi}
15390@itemx set cp-abi auto
15391Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
15392@end table
15393
8e04817f
AC
15394@node Messages/Warnings
15395@section Optional warnings and messages
104c1213 15396
9c16f35a
EZ
15397@cindex verbose operation
15398@cindex optional warnings
8e04817f
AC
15399By default, @value{GDBN} is silent about its inner workings. If you are
15400running on a slow machine, you may want to use the @code{set verbose}
15401command. This makes @value{GDBN} tell you when it does a lengthy
15402internal operation, so you will not think it has crashed.
104c1213 15403
8e04817f
AC
15404Currently, the messages controlled by @code{set verbose} are those
15405which announce that the symbol table for a source file is being read;
15406see @code{symbol-file} in @ref{Files, ,Commands to specify files}.
104c1213 15407
8e04817f
AC
15408@table @code
15409@kindex set verbose
15410@item set verbose on
15411Enables @value{GDBN} output of certain informational messages.
104c1213 15412
8e04817f
AC
15413@item set verbose off
15414Disables @value{GDBN} output of certain informational messages.
104c1213 15415
8e04817f
AC
15416@kindex show verbose
15417@item show verbose
15418Displays whether @code{set verbose} is on or off.
15419@end table
104c1213 15420
8e04817f
AC
15421By default, if @value{GDBN} encounters bugs in the symbol table of an
15422object file, it is silent; but if you are debugging a compiler, you may
15423find this information useful (@pxref{Symbol Errors, ,Errors reading
15424symbol files}).
104c1213 15425
8e04817f 15426@table @code
104c1213 15427
8e04817f
AC
15428@kindex set complaints
15429@item set complaints @var{limit}
15430Permits @value{GDBN} to output @var{limit} complaints about each type of
15431unusual symbols before becoming silent about the problem. Set
15432@var{limit} to zero to suppress all complaints; set it to a large number
15433to prevent complaints from being suppressed.
104c1213 15434
8e04817f
AC
15435@kindex show complaints
15436@item show complaints
15437Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 15438
8e04817f 15439@end table
104c1213 15440
8e04817f
AC
15441By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
15442lot of stupid questions to confirm certain commands. For example, if
15443you try to run a program which is already running:
104c1213 15444
474c8240 15445@smallexample
8e04817f
AC
15446(@value{GDBP}) run
15447The program being debugged has been started already.
15448Start it from the beginning? (y or n)
474c8240 15449@end smallexample
104c1213 15450
8e04817f
AC
15451If you are willing to unflinchingly face the consequences of your own
15452commands, you can disable this ``feature'':
104c1213 15453
8e04817f 15454@table @code
104c1213 15455
8e04817f
AC
15456@kindex set confirm
15457@cindex flinching
15458@cindex confirmation
15459@cindex stupid questions
15460@item set confirm off
15461Disables confirmation requests.
104c1213 15462
8e04817f
AC
15463@item set confirm on
15464Enables confirmation requests (the default).
104c1213 15465
8e04817f
AC
15466@kindex show confirm
15467@item show confirm
15468Displays state of confirmation requests.
15469
15470@end table
104c1213 15471
8e04817f
AC
15472@node Debugging Output
15473@section Optional messages about internal happenings
4644b6e3
EZ
15474@cindex optional debugging messages
15475
da316a69
EZ
15476@value{GDBN} has commands that enable optional debugging messages from
15477various @value{GDBN} subsystems; normally these commands are of
15478interest to @value{GDBN} maintainers, or when reporting a bug. This
15479section documents those commands.
15480
104c1213 15481@table @code
a8f24a35
EZ
15482@kindex set exec-done-display
15483@item set exec-done-display
15484Turns on or off the notification of asynchronous commands'
15485completion. When on, @value{GDBN} will print a message when an
15486asynchronous command finishes its execution. The default is off.
15487@kindex show exec-done-display
15488@item show exec-done-display
15489Displays the current setting of asynchronous command completion
15490notification.
4644b6e3
EZ
15491@kindex set debug
15492@cindex gdbarch debugging info
a8f24a35 15493@cindex architecture debugging info
8e04817f 15494@item set debug arch
a8f24a35 15495Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 15496@kindex show debug
8e04817f
AC
15497@item show debug arch
15498Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
15499@item set debug aix-thread
15500@cindex AIX threads
15501Display debugging messages about inner workings of the AIX thread
15502module.
15503@item show debug aix-thread
15504Show the current state of AIX thread debugging info display.
8e04817f 15505@item set debug event
4644b6e3 15506@cindex event debugging info
a8f24a35 15507Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 15508default is off.
8e04817f
AC
15509@item show debug event
15510Displays the current state of displaying @value{GDBN} event debugging
15511info.
8e04817f 15512@item set debug expression
4644b6e3 15513@cindex expression debugging info
721c2651
EZ
15514Turns on or off display of debugging info about @value{GDBN}
15515expression parsing. The default is off.
8e04817f 15516@item show debug expression
721c2651
EZ
15517Displays the current state of displaying debugging info about
15518@value{GDBN} expression parsing.
7453dc06 15519@item set debug frame
4644b6e3 15520@cindex frame debugging info
7453dc06
AC
15521Turns on or off display of @value{GDBN} frame debugging info. The
15522default is off.
7453dc06
AC
15523@item show debug frame
15524Displays the current state of displaying @value{GDBN} frame debugging
15525info.
30e91e0b
RC
15526@item set debug infrun
15527@cindex inferior debugging info
15528Turns on or off display of @value{GDBN} debugging info for running the inferior.
15529The default is off. @file{infrun.c} contains GDB's runtime state machine used
15530for implementing operations such as single-stepping the inferior.
15531@item show debug infrun
15532Displays the current state of @value{GDBN} inferior debugging.
da316a69
EZ
15533@item set debug lin-lwp
15534@cindex @sc{gnu}/Linux LWP debug messages
15535@cindex Linux lightweight processes
721c2651 15536Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
15537@item show debug lin-lwp
15538Show the current state of Linux LWP debugging messages.
2b4855ab 15539@item set debug observer
4644b6e3 15540@cindex observer debugging info
2b4855ab
AC
15541Turns on or off display of @value{GDBN} observer debugging. This
15542includes info such as the notification of observable events.
2b4855ab
AC
15543@item show debug observer
15544Displays the current state of observer debugging.
8e04817f 15545@item set debug overload
4644b6e3 15546@cindex C@t{++} overload debugging info
8e04817f
AC
15547Turns on or off display of @value{GDBN} C@t{++} overload debugging
15548info. This includes info such as ranking of functions, etc. The default
15549is off.
8e04817f
AC
15550@item show debug overload
15551Displays the current state of displaying @value{GDBN} C@t{++} overload
15552debugging info.
8e04817f
AC
15553@cindex packets, reporting on stdout
15554@cindex serial connections, debugging
15555@item set debug remote
15556Turns on or off display of reports on all packets sent back and forth across
15557the serial line to the remote machine. The info is printed on the
15558@value{GDBN} standard output stream. The default is off.
8e04817f
AC
15559@item show debug remote
15560Displays the state of display of remote packets.
8e04817f
AC
15561@item set debug serial
15562Turns on or off display of @value{GDBN} serial debugging info. The
15563default is off.
8e04817f
AC
15564@item show debug serial
15565Displays the current state of displaying @value{GDBN} serial debugging
15566info.
c45da7e6
EZ
15567@item set debug solib-frv
15568@cindex FR-V shared-library debugging
15569Turns on or off debugging messages for FR-V shared-library code.
15570@item show debug solib-frv
15571Display the current state of FR-V shared-library code debugging
15572messages.
8e04817f 15573@item set debug target
4644b6e3 15574@cindex target debugging info
8e04817f
AC
15575Turns on or off display of @value{GDBN} target debugging info. This info
15576includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
15577default is 0. Set it to 1 to track events, and to 2 to also track the
15578value of large memory transfers. Changes to this flag do not take effect
15579until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
15580@item show debug target
15581Displays the current state of displaying @value{GDBN} target debugging
15582info.
c45da7e6 15583@item set debugvarobj
4644b6e3 15584@cindex variable object debugging info
8e04817f
AC
15585Turns on or off display of @value{GDBN} variable object debugging
15586info. The default is off.
c45da7e6 15587@item show debugvarobj
8e04817f
AC
15588Displays the current state of displaying @value{GDBN} variable object
15589debugging info.
15590@end table
104c1213 15591
8e04817f
AC
15592@node Sequences
15593@chapter Canned Sequences of Commands
104c1213 15594
8e04817f
AC
15595Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
15596command lists}), @value{GDBN} provides two ways to store sequences of
15597commands for execution as a unit: user-defined commands and command
15598files.
104c1213 15599
8e04817f
AC
15600@menu
15601* Define:: User-defined commands
15602* Hooks:: User-defined command hooks
15603* Command Files:: Command files
15604* Output:: Commands for controlled output
15605@end menu
104c1213 15606
8e04817f
AC
15607@node Define
15608@section User-defined commands
104c1213 15609
8e04817f
AC
15610@cindex user-defined command
15611A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
15612which you assign a new name as a command. This is done with the
15613@code{define} command. User commands may accept up to 10 arguments
15614separated by whitespace. Arguments are accessed within the user command
15615via @var{$arg0@dots{}$arg9}. A trivial example:
104c1213 15616
8e04817f
AC
15617@smallexample
15618define adder
15619 print $arg0 + $arg1 + $arg2
15620@end smallexample
104c1213
JM
15621
15622@noindent
8e04817f 15623To execute the command use:
104c1213 15624
8e04817f
AC
15625@smallexample
15626adder 1 2 3
15627@end smallexample
104c1213 15628
8e04817f
AC
15629@noindent
15630This defines the command @code{adder}, which prints the sum of
15631its three arguments. Note the arguments are text substitutions, so they may
15632reference variables, use complex expressions, or even perform inferior
15633functions calls.
104c1213
JM
15634
15635@table @code
104c1213 15636
8e04817f
AC
15637@kindex define
15638@item define @var{commandname}
15639Define a command named @var{commandname}. If there is already a command
15640by that name, you are asked to confirm that you want to redefine it.
104c1213 15641
8e04817f
AC
15642The definition of the command is made up of other @value{GDBN} command lines,
15643which are given following the @code{define} command. The end of these
15644commands is marked by a line containing @code{end}.
104c1213 15645
8e04817f
AC
15646@kindex if
15647@kindex else
15648@item if
09d4efe1 15649@itemx else
8e04817f
AC
15650Takes a single argument, which is an expression to evaluate.
15651It is followed by a series of commands that are executed
15652only if the expression is true (nonzero).
15653There can then optionally be a line @code{else}, followed
15654by a series of commands that are only executed if the expression
15655was false. The end of the list is marked by a line containing @code{end}.
104c1213 15656
8e04817f
AC
15657@kindex while
15658@item while
15659The syntax is similar to @code{if}: the command takes a single argument,
15660which is an expression to evaluate, and must be followed by the commands to
15661execute, one per line, terminated by an @code{end}.
15662The commands are executed repeatedly as long as the expression
15663evaluates to true.
104c1213 15664
8e04817f
AC
15665@kindex document
15666@item document @var{commandname}
15667Document the user-defined command @var{commandname}, so that it can be
15668accessed by @code{help}. The command @var{commandname} must already be
15669defined. This command reads lines of documentation just as @code{define}
15670reads the lines of the command definition, ending with @code{end}.
15671After the @code{document} command is finished, @code{help} on command
15672@var{commandname} displays the documentation you have written.
104c1213 15673
8e04817f
AC
15674You may use the @code{document} command again to change the
15675documentation of a command. Redefining the command with @code{define}
15676does not change the documentation.
104c1213 15677
c45da7e6
EZ
15678@kindex dont-repeat
15679@cindex don't repeat command
15680@item dont-repeat
15681Used inside a user-defined command, this tells @value{GDBN} that this
15682command should not be repeated when the user hits @key{RET}
15683(@pxref{Command Syntax, repeat last command}).
15684
8e04817f
AC
15685@kindex help user-defined
15686@item help user-defined
15687List all user-defined commands, with the first line of the documentation
15688(if any) for each.
104c1213 15689
8e04817f
AC
15690@kindex show user
15691@item show user
15692@itemx show user @var{commandname}
15693Display the @value{GDBN} commands used to define @var{commandname} (but
15694not its documentation). If no @var{commandname} is given, display the
15695definitions for all user-defined commands.
104c1213 15696
9c16f35a 15697@cindex infinite recusrion in user-defined commands
20f01a46
DH
15698@kindex show max-user-call-depth
15699@kindex set max-user-call-depth
15700@item show max-user-call-depth
5ca0cb28
DH
15701@itemx set max-user-call-depth
15702The value of @code{max-user-call-depth} controls how many recursion
15703levels are allowed in user-defined commands before GDB suspects an
15704infinite recursion and aborts the command.
20f01a46 15705
104c1213
JM
15706@end table
15707
8e04817f
AC
15708When user-defined commands are executed, the
15709commands of the definition are not printed. An error in any command
15710stops execution of the user-defined command.
104c1213 15711
8e04817f
AC
15712If used interactively, commands that would ask for confirmation proceed
15713without asking when used inside a user-defined command. Many @value{GDBN}
15714commands that normally print messages to say what they are doing omit the
15715messages when used in a user-defined command.
104c1213 15716
8e04817f
AC
15717@node Hooks
15718@section User-defined command hooks
15719@cindex command hooks
15720@cindex hooks, for commands
15721@cindex hooks, pre-command
104c1213 15722
8e04817f 15723@kindex hook
8e04817f
AC
15724You may define @dfn{hooks}, which are a special kind of user-defined
15725command. Whenever you run the command @samp{foo}, if the user-defined
15726command @samp{hook-foo} exists, it is executed (with no arguments)
15727before that command.
104c1213 15728
8e04817f
AC
15729@cindex hooks, post-command
15730@kindex hookpost
8e04817f
AC
15731A hook may also be defined which is run after the command you executed.
15732Whenever you run the command @samp{foo}, if the user-defined command
15733@samp{hookpost-foo} exists, it is executed (with no arguments) after
15734that command. Post-execution hooks may exist simultaneously with
15735pre-execution hooks, for the same command.
104c1213 15736
8e04817f 15737It is valid for a hook to call the command which it hooks. If this
9f1c6395 15738occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 15739
8e04817f
AC
15740@c It would be nice if hookpost could be passed a parameter indicating
15741@c if the command it hooks executed properly or not. FIXME!
104c1213 15742
8e04817f
AC
15743@kindex stop@r{, a pseudo-command}
15744In addition, a pseudo-command, @samp{stop} exists. Defining
15745(@samp{hook-stop}) makes the associated commands execute every time
15746execution stops in your program: before breakpoint commands are run,
15747displays are printed, or the stack frame is printed.
104c1213 15748
8e04817f
AC
15749For example, to ignore @code{SIGALRM} signals while
15750single-stepping, but treat them normally during normal execution,
15751you could define:
104c1213 15752
474c8240 15753@smallexample
8e04817f
AC
15754define hook-stop
15755handle SIGALRM nopass
15756end
104c1213 15757
8e04817f
AC
15758define hook-run
15759handle SIGALRM pass
15760end
104c1213 15761
8e04817f
AC
15762define hook-continue
15763handle SIGLARM pass
15764end
474c8240 15765@end smallexample
104c1213 15766
8e04817f 15767As a further example, to hook at the begining and end of the @code{echo}
b383017d 15768command, and to add extra text to the beginning and end of the message,
8e04817f 15769you could define:
104c1213 15770
474c8240 15771@smallexample
8e04817f
AC
15772define hook-echo
15773echo <<<---
15774end
104c1213 15775
8e04817f
AC
15776define hookpost-echo
15777echo --->>>\n
15778end
104c1213 15779
8e04817f
AC
15780(@value{GDBP}) echo Hello World
15781<<<---Hello World--->>>
15782(@value{GDBP})
104c1213 15783
474c8240 15784@end smallexample
104c1213 15785
8e04817f
AC
15786You can define a hook for any single-word command in @value{GDBN}, but
15787not for command aliases; you should define a hook for the basic command
15788name, e.g. @code{backtrace} rather than @code{bt}.
15789@c FIXME! So how does Joe User discover whether a command is an alias
15790@c or not?
15791If an error occurs during the execution of your hook, execution of
15792@value{GDBN} commands stops and @value{GDBN} issues a prompt
15793(before the command that you actually typed had a chance to run).
104c1213 15794
8e04817f
AC
15795If you try to define a hook which does not match any known command, you
15796get a warning from the @code{define} command.
c906108c 15797
8e04817f
AC
15798@node Command Files
15799@section Command files
c906108c 15800
8e04817f 15801@cindex command files
6fc08d32
EZ
15802A command file for @value{GDBN} is a text file made of lines that are
15803@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
15804also be included. An empty line in a command file does nothing; it
15805does not mean to repeat the last command, as it would from the
15806terminal.
c906108c 15807
6fc08d32
EZ
15808You can request the execution of a command file with the @code{source}
15809command:
c906108c 15810
8e04817f
AC
15811@table @code
15812@kindex source
15813@item source @var{filename}
15814Execute the command file @var{filename}.
c906108c
SS
15815@end table
15816
8e04817f 15817The lines in a command file are executed sequentially. They are not
a71ec265
DH
15818printed as they are executed. An error in any command terminates
15819execution of the command file and control is returned to the console.
c906108c 15820
8e04817f
AC
15821Commands that would ask for confirmation if used interactively proceed
15822without asking when used in a command file. Many @value{GDBN} commands that
15823normally print messages to say what they are doing omit the messages
15824when called from command files.
c906108c 15825
8e04817f
AC
15826@value{GDBN} also accepts command input from standard input. In this
15827mode, normal output goes to standard output and error output goes to
15828standard error. Errors in a command file supplied on standard input do
6fc08d32 15829not terminate execution of the command file---execution continues with
8e04817f 15830the next command.
c906108c 15831
474c8240 15832@smallexample
8e04817f 15833gdb < cmds > log 2>&1
474c8240 15834@end smallexample
c906108c 15835
8e04817f
AC
15836(The syntax above will vary depending on the shell used.) This example
15837will execute commands from the file @file{cmds}. All output and errors
15838would be directed to @file{log}.
c906108c 15839
8e04817f
AC
15840@node Output
15841@section Commands for controlled output
c906108c 15842
8e04817f
AC
15843During the execution of a command file or a user-defined command, normal
15844@value{GDBN} output is suppressed; the only output that appears is what is
15845explicitly printed by the commands in the definition. This section
15846describes three commands useful for generating exactly the output you
15847want.
c906108c
SS
15848
15849@table @code
8e04817f
AC
15850@kindex echo
15851@item echo @var{text}
15852@c I do not consider backslash-space a standard C escape sequence
15853@c because it is not in ANSI.
15854Print @var{text}. Nonprinting characters can be included in
15855@var{text} using C escape sequences, such as @samp{\n} to print a
15856newline. @strong{No newline is printed unless you specify one.}
15857In addition to the standard C escape sequences, a backslash followed
15858by a space stands for a space. This is useful for displaying a
15859string with spaces at the beginning or the end, since leading and
15860trailing spaces are otherwise trimmed from all arguments.
15861To print @samp{@w{ }and foo =@w{ }}, use the command
15862@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 15863
8e04817f
AC
15864A backslash at the end of @var{text} can be used, as in C, to continue
15865the command onto subsequent lines. For example,
c906108c 15866
474c8240 15867@smallexample
8e04817f
AC
15868echo This is some text\n\
15869which is continued\n\
15870onto several lines.\n
474c8240 15871@end smallexample
c906108c 15872
8e04817f 15873produces the same output as
c906108c 15874
474c8240 15875@smallexample
8e04817f
AC
15876echo This is some text\n
15877echo which is continued\n
15878echo onto several lines.\n
474c8240 15879@end smallexample
c906108c 15880
8e04817f
AC
15881@kindex output
15882@item output @var{expression}
15883Print the value of @var{expression} and nothing but that value: no
15884newlines, no @samp{$@var{nn} = }. The value is not entered in the
15885value history either. @xref{Expressions, ,Expressions}, for more information
15886on expressions.
c906108c 15887
8e04817f
AC
15888@item output/@var{fmt} @var{expression}
15889Print the value of @var{expression} in format @var{fmt}. You can use
15890the same formats as for @code{print}. @xref{Output Formats,,Output
15891formats}, for more information.
c906108c 15892
8e04817f
AC
15893@kindex printf
15894@item printf @var{string}, @var{expressions}@dots{}
15895Print the values of the @var{expressions} under the control of
15896@var{string}. The @var{expressions} are separated by commas and may be
15897either numbers or pointers. Their values are printed as specified by
15898@var{string}, exactly as if your program were to execute the C
15899subroutine
15900@c FIXME: the above implies that at least all ANSI C formats are
15901@c supported, but it isn't true: %E and %G don't work (or so it seems).
15902@c Either this is a bug, or the manual should document what formats are
15903@c supported.
c906108c 15904
474c8240 15905@smallexample
8e04817f 15906printf (@var{string}, @var{expressions}@dots{});
474c8240 15907@end smallexample
c906108c 15908
8e04817f 15909For example, you can print two values in hex like this:
c906108c 15910
8e04817f
AC
15911@smallexample
15912printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
15913@end smallexample
c906108c 15914
8e04817f
AC
15915The only backslash-escape sequences that you can use in the format
15916string are the simple ones that consist of backslash followed by a
15917letter.
c906108c
SS
15918@end table
15919
21c294e6
AC
15920@node Interpreters
15921@chapter Command Interpreters
15922@cindex command interpreters
15923
15924@value{GDBN} supports multiple command interpreters, and some command
15925infrastructure to allow users or user interface writers to switch
15926between interpreters or run commands in other interpreters.
15927
15928@value{GDBN} currently supports two command interpreters, the console
15929interpreter (sometimes called the command-line interpreter or @sc{cli})
15930and the machine interface interpreter (or @sc{gdb/mi}). This manual
15931describes both of these interfaces in great detail.
15932
15933By default, @value{GDBN} will start with the console interpreter.
15934However, the user may choose to start @value{GDBN} with another
15935interpreter by specifying the @option{-i} or @option{--interpreter}
15936startup options. Defined interpreters include:
15937
15938@table @code
15939@item console
15940@cindex console interpreter
15941The traditional console or command-line interpreter. This is the most often
15942used interpreter with @value{GDBN}. With no interpreter specified at runtime,
15943@value{GDBN} will use this interpreter.
15944
15945@item mi
15946@cindex mi interpreter
15947The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
15948by programs wishing to use @value{GDBN} as a backend for a debugger GUI
15949or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
15950Interface}.
15951
15952@item mi2
15953@cindex mi2 interpreter
15954The current @sc{gdb/mi} interface.
15955
15956@item mi1
15957@cindex mi1 interpreter
15958The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
15959
15960@end table
15961
15962@cindex invoke another interpreter
15963The interpreter being used by @value{GDBN} may not be dynamically
15964switched at runtime. Although possible, this could lead to a very
15965precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
15966enters the command "interpreter-set console" in a console view,
15967@value{GDBN} would switch to using the console interpreter, rendering
15968the IDE inoperable!
15969
15970@kindex interpreter-exec
15971Although you may only choose a single interpreter at startup, you may execute
15972commands in any interpreter from the current interpreter using the appropriate
15973command. If you are running the console interpreter, simply use the
15974@code{interpreter-exec} command:
15975
15976@smallexample
15977interpreter-exec mi "-data-list-register-names"
15978@end smallexample
15979
15980@sc{gdb/mi} has a similar command, although it is only available in versions of
15981@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
15982
8e04817f
AC
15983@node TUI
15984@chapter @value{GDBN} Text User Interface
15985@cindex TUI
d0d5df6f 15986@cindex Text User Interface
c906108c 15987
8e04817f
AC
15988@menu
15989* TUI Overview:: TUI overview
15990* TUI Keys:: TUI key bindings
7cf36c78 15991* TUI Single Key Mode:: TUI single key mode
8e04817f
AC
15992* TUI Commands:: TUI specific commands
15993* TUI Configuration:: TUI configuration variables
15994@end menu
c906108c 15995
d0d5df6f
AC
15996The @value{GDBN} Text User Interface, TUI in short, is a terminal
15997interface which uses the @code{curses} library to show the source
15998file, the assembly output, the program registers and @value{GDBN}
15999commands in separate text windows.
16000
16001The TUI is enabled by invoking @value{GDBN} using either
16002@pindex gdbtui
16003@samp{gdbtui} or @samp{gdb -tui}.
c906108c 16004
8e04817f
AC
16005@node TUI Overview
16006@section TUI overview
c906108c 16007
8e04817f
AC
16008The TUI has two display modes that can be switched while
16009@value{GDBN} runs:
c906108c 16010
8e04817f
AC
16011@itemize @bullet
16012@item
16013A curses (or TUI) mode in which it displays several text
16014windows on the terminal.
c906108c 16015
8e04817f
AC
16016@item
16017A standard mode which corresponds to the @value{GDBN} configured without
16018the TUI.
16019@end itemize
c906108c 16020
8e04817f
AC
16021In the TUI mode, @value{GDBN} can display several text window
16022on the terminal:
c906108c 16023
8e04817f
AC
16024@table @emph
16025@item command
16026This window is the @value{GDBN} command window with the @value{GDBN}
16027prompt and the @value{GDBN} outputs. The @value{GDBN} input is still
16028managed using readline but through the TUI. The @emph{command}
16029window is always visible.
c906108c 16030
8e04817f
AC
16031@item source
16032The source window shows the source file of the program. The current
16033line as well as active breakpoints are displayed in this window.
c906108c 16034
8e04817f
AC
16035@item assembly
16036The assembly window shows the disassembly output of the program.
c906108c 16037
8e04817f
AC
16038@item register
16039This window shows the processor registers. It detects when
16040a register is changed and when this is the case, registers that have
6a1b180d 16041changed are highlighted.
c906108c 16042
c906108c
SS
16043@end table
16044
269c21fe
SC
16045The source and assembly windows show the current program position
16046by highlighting the current line and marking them with the @samp{>} marker.
16047Breakpoints are also indicated with two markers. A first one
16048indicates the breakpoint type:
16049
16050@table @code
16051@item B
16052Breakpoint which was hit at least once.
16053
16054@item b
16055Breakpoint which was never hit.
16056
16057@item H
16058Hardware breakpoint which was hit at least once.
16059
16060@item h
16061Hardware breakpoint which was never hit.
16062
16063@end table
16064
16065The second marker indicates whether the breakpoint is enabled or not:
16066
16067@table @code
16068@item +
16069Breakpoint is enabled.
16070
16071@item -
16072Breakpoint is disabled.
16073
16074@end table
16075
8e04817f
AC
16076The source, assembly and register windows are attached to the thread
16077and the frame position. They are updated when the current thread
16078changes, when the frame changes or when the program counter changes.
16079These three windows are arranged by the TUI according to several
16080layouts. The layout defines which of these three windows are visible.
16081The following layouts are available:
c906108c 16082
8e04817f
AC
16083@itemize @bullet
16084@item
16085source
2df3850c 16086
8e04817f
AC
16087@item
16088assembly
16089
16090@item
16091source and assembly
16092
16093@item
16094source and registers
c906108c 16095
8e04817f
AC
16096@item
16097assembly and registers
2df3850c 16098
8e04817f 16099@end itemize
c906108c 16100
b7bb15bc
SC
16101On top of the command window a status line gives various information
16102concerning the current process begin debugged. The status line is
16103updated when the information it shows changes. The following fields
16104are displayed:
16105
16106@table @emph
16107@item target
16108Indicates the current gdb target
16109(@pxref{Targets, ,Specifying a Debugging Target}).
16110
16111@item process
16112Gives information about the current process or thread number.
16113When no process is being debugged, this field is set to @code{No process}.
16114
16115@item function
16116Gives the current function name for the selected frame.
16117The name is demangled if demangling is turned on (@pxref{Print Settings}).
16118When there is no symbol corresponding to the current program counter
16119the string @code{??} is displayed.
16120
16121@item line
16122Indicates the current line number for the selected frame.
16123When the current line number is not known the string @code{??} is displayed.
16124
16125@item pc
16126Indicates the current program counter address.
16127
16128@end table
16129
8e04817f
AC
16130@node TUI Keys
16131@section TUI Key Bindings
16132@cindex TUI key bindings
c906108c 16133
8e04817f
AC
16134The TUI installs several key bindings in the readline keymaps
16135(@pxref{Command Line Editing}).
16136They allow to leave or enter in the TUI mode or they operate
7cf36c78
SC
16137directly on the TUI layout and windows. The TUI also provides
16138a @emph{SingleKey} keymap which binds several keys directly to
16139@value{GDBN} commands. The following key bindings
8e04817f 16140are installed for both TUI mode and the @value{GDBN} standard mode.
c906108c 16141
8e04817f
AC
16142@table @kbd
16143@kindex C-x C-a
16144@item C-x C-a
16145@kindex C-x a
16146@itemx C-x a
16147@kindex C-x A
16148@itemx C-x A
16149Enter or leave the TUI mode. When the TUI mode is left,
16150the curses window management is left and @value{GDBN} operates using
16151its standard mode writing on the terminal directly. When the TUI
16152mode is entered, the control is given back to the curses windows.
16153The screen is then refreshed.
c906108c 16154
8e04817f
AC
16155@kindex C-x 1
16156@item C-x 1
16157Use a TUI layout with only one window. The layout will
16158either be @samp{source} or @samp{assembly}. When the TUI mode
16159is not active, it will switch to the TUI mode.
2df3850c 16160
8e04817f 16161Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 16162
8e04817f
AC
16163@kindex C-x 2
16164@item C-x 2
16165Use a TUI layout with at least two windows. When the current
16166layout shows already two windows, a next layout with two windows is used.
16167When a new layout is chosen, one window will always be common to the
16168previous layout and the new one.
c906108c 16169
8e04817f 16170Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 16171
72ffddc9
SC
16172@kindex C-x o
16173@item C-x o
16174Change the active window. The TUI associates several key bindings
16175(like scrolling and arrow keys) to the active window. This command
16176gives the focus to the next TUI window.
16177
16178Think of it as the Emacs @kbd{C-x o} binding.
16179
7cf36c78
SC
16180@kindex C-x s
16181@item C-x s
16182Use the TUI @emph{SingleKey} keymap that binds single key to gdb commands
16183(@pxref{TUI Single Key Mode}).
16184
c906108c
SS
16185@end table
16186
8e04817f 16187The following key bindings are handled only by the TUI mode:
5d161b24 16188
8e04817f
AC
16189@table @key
16190@kindex PgUp
16191@item PgUp
16192Scroll the active window one page up.
c906108c 16193
8e04817f
AC
16194@kindex PgDn
16195@item PgDn
16196Scroll the active window one page down.
c906108c 16197
8e04817f
AC
16198@kindex Up
16199@item Up
16200Scroll the active window one line up.
c906108c 16201
8e04817f
AC
16202@kindex Down
16203@item Down
16204Scroll the active window one line down.
c906108c 16205
8e04817f
AC
16206@kindex Left
16207@item Left
16208Scroll the active window one column left.
c906108c 16209
8e04817f
AC
16210@kindex Right
16211@item Right
16212Scroll the active window one column right.
c906108c 16213
8e04817f
AC
16214@kindex C-L
16215@item C-L
16216Refresh the screen.
c906108c 16217
8e04817f 16218@end table
c906108c 16219
8e04817f 16220In the TUI mode, the arrow keys are used by the active window
72ffddc9
SC
16221for scrolling. This means they are available for readline when the
16222active window is the command window. When the command window
16223does not have the focus, it is necessary to use other readline
16224key bindings such as @key{C-p}, @key{C-n}, @key{C-b} and @key{C-f}.
8e04817f 16225
7cf36c78
SC
16226@node TUI Single Key Mode
16227@section TUI Single Key Mode
16228@cindex TUI single key mode
16229
16230The TUI provides a @emph{SingleKey} mode in which it installs a particular
16231key binding in the readline keymaps to connect single keys to
b383017d 16232some gdb commands.
7cf36c78
SC
16233
16234@table @kbd
16235@kindex c @r{(SingleKey TUI key)}
16236@item c
16237continue
16238
16239@kindex d @r{(SingleKey TUI key)}
16240@item d
16241down
16242
16243@kindex f @r{(SingleKey TUI key)}
16244@item f
16245finish
16246
16247@kindex n @r{(SingleKey TUI key)}
16248@item n
16249next
16250
16251@kindex q @r{(SingleKey TUI key)}
16252@item q
16253exit the @emph{SingleKey} mode.
16254
16255@kindex r @r{(SingleKey TUI key)}
16256@item r
16257run
16258
16259@kindex s @r{(SingleKey TUI key)}
16260@item s
16261step
16262
16263@kindex u @r{(SingleKey TUI key)}
16264@item u
16265up
16266
16267@kindex v @r{(SingleKey TUI key)}
16268@item v
16269info locals
16270
16271@kindex w @r{(SingleKey TUI key)}
16272@item w
16273where
16274
16275@end table
16276
16277Other keys temporarily switch to the @value{GDBN} command prompt.
16278The key that was pressed is inserted in the editing buffer so that
16279it is possible to type most @value{GDBN} commands without interaction
16280with the TUI @emph{SingleKey} mode. Once the command is entered the TUI
16281@emph{SingleKey} mode is restored. The only way to permanently leave
16282this mode is by hitting @key{q} or @samp{@key{C-x} @key{s}}.
16283
16284
8e04817f
AC
16285@node TUI Commands
16286@section TUI specific commands
16287@cindex TUI commands
16288
16289The TUI has specific commands to control the text windows.
16290These commands are always available, that is they do not depend on
16291the current terminal mode in which @value{GDBN} runs. When @value{GDBN}
16292is in the standard mode, using these commands will automatically switch
16293in the TUI mode.
c906108c
SS
16294
16295@table @code
3d757584
SC
16296@item info win
16297@kindex info win
16298List and give the size of all displayed windows.
16299
8e04817f 16300@item layout next
4644b6e3 16301@kindex layout
8e04817f 16302Display the next layout.
2df3850c 16303
8e04817f 16304@item layout prev
8e04817f 16305Display the previous layout.
c906108c 16306
8e04817f 16307@item layout src
8e04817f 16308Display the source window only.
c906108c 16309
8e04817f 16310@item layout asm
8e04817f 16311Display the assembly window only.
c906108c 16312
8e04817f 16313@item layout split
8e04817f 16314Display the source and assembly window.
c906108c 16315
8e04817f 16316@item layout regs
8e04817f
AC
16317Display the register window together with the source or assembly window.
16318
16319@item focus next | prev | src | asm | regs | split
16320@kindex focus
16321Set the focus to the named window.
16322This command allows to change the active window so that scrolling keys
16323can be affected to another window.
c906108c 16324
8e04817f
AC
16325@item refresh
16326@kindex refresh
16327Refresh the screen. This is similar to using @key{C-L} key.
c906108c 16328
6a1b180d
SC
16329@item tui reg float
16330@kindex tui reg
16331Show the floating point registers in the register window.
16332
16333@item tui reg general
16334Show the general registers in the register window.
16335
16336@item tui reg next
16337Show the next register group. The list of register groups as well as
16338their order is target specific. The predefined register groups are the
16339following: @code{general}, @code{float}, @code{system}, @code{vector},
16340@code{all}, @code{save}, @code{restore}.
16341
16342@item tui reg system
16343Show the system registers in the register window.
16344
8e04817f
AC
16345@item update
16346@kindex update
16347Update the source window and the current execution point.
c906108c 16348
8e04817f
AC
16349@item winheight @var{name} +@var{count}
16350@itemx winheight @var{name} -@var{count}
16351@kindex winheight
16352Change the height of the window @var{name} by @var{count}
16353lines. Positive counts increase the height, while negative counts
16354decrease it.
2df3850c 16355
c45da7e6
EZ
16356@item tabset
16357@kindex tabset @var{nchars}
16358Set the width of tab stops to be @var{nchars} characters.
16359
c906108c
SS
16360@end table
16361
8e04817f
AC
16362@node TUI Configuration
16363@section TUI configuration variables
16364@cindex TUI configuration variables
c906108c 16365
8e04817f
AC
16366The TUI has several configuration variables that control the
16367appearance of windows on the terminal.
c906108c 16368
8e04817f
AC
16369@table @code
16370@item set tui border-kind @var{kind}
16371@kindex set tui border-kind
16372Select the border appearance for the source, assembly and register windows.
16373The possible values are the following:
16374@table @code
16375@item space
16376Use a space character to draw the border.
c906108c 16377
8e04817f
AC
16378@item ascii
16379Use ascii characters + - and | to draw the border.
c906108c 16380
8e04817f
AC
16381@item acs
16382Use the Alternate Character Set to draw the border. The border is
16383drawn using character line graphics if the terminal supports them.
c78b4128 16384
8e04817f 16385@end table
c78b4128 16386
8e04817f
AC
16387@item set tui active-border-mode @var{mode}
16388@kindex set tui active-border-mode
16389Select the attributes to display the border of the active window.
16390The possible values are @code{normal}, @code{standout}, @code{reverse},
16391@code{half}, @code{half-standout}, @code{bold} and @code{bold-standout}.
c78b4128 16392
8e04817f
AC
16393@item set tui border-mode @var{mode}
16394@kindex set tui border-mode
16395Select the attributes to display the border of other windows.
16396The @var{mode} can be one of the following:
16397@table @code
16398@item normal
16399Use normal attributes to display the border.
c906108c 16400
8e04817f
AC
16401@item standout
16402Use standout mode.
c906108c 16403
8e04817f
AC
16404@item reverse
16405Use reverse video mode.
c906108c 16406
8e04817f
AC
16407@item half
16408Use half bright mode.
c906108c 16409
8e04817f
AC
16410@item half-standout
16411Use half bright and standout mode.
c906108c 16412
8e04817f
AC
16413@item bold
16414Use extra bright or bold mode.
c78b4128 16415
8e04817f
AC
16416@item bold-standout
16417Use extra bright or bold and standout mode.
c78b4128 16418
8e04817f 16419@end table
c78b4128 16420
8e04817f 16421@end table
c78b4128 16422
8e04817f
AC
16423@node Emacs
16424@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 16425
8e04817f
AC
16426@cindex Emacs
16427@cindex @sc{gnu} Emacs
16428A special interface allows you to use @sc{gnu} Emacs to view (and
16429edit) the source files for the program you are debugging with
16430@value{GDBN}.
c906108c 16431
8e04817f
AC
16432To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
16433executable file you want to debug as an argument. This command starts
16434@value{GDBN} as a subprocess of Emacs, with input and output through a newly
16435created Emacs buffer.
16436@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 16437
8e04817f
AC
16438Using @value{GDBN} under Emacs is just like using @value{GDBN} normally except for two
16439things:
c906108c 16440
8e04817f
AC
16441@itemize @bullet
16442@item
16443All ``terminal'' input and output goes through the Emacs buffer.
16444@end itemize
c906108c 16445
8e04817f
AC
16446This applies both to @value{GDBN} commands and their output, and to the input
16447and output done by the program you are debugging.
bf0184be 16448
8e04817f
AC
16449This is useful because it means that you can copy the text of previous
16450commands and input them again; you can even use parts of the output
16451in this way.
bf0184be 16452
8e04817f
AC
16453All the facilities of Emacs' Shell mode are available for interacting
16454with your program. In particular, you can send signals the usual
16455way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
16456stop.
bf0184be 16457
8e04817f 16458@itemize @bullet
bf0184be 16459@item
8e04817f
AC
16460@value{GDBN} displays source code through Emacs.
16461@end itemize
bf0184be 16462
8e04817f
AC
16463Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
16464source file for that frame and puts an arrow (@samp{=>}) at the
16465left margin of the current line. Emacs uses a separate buffer for
16466source display, and splits the screen to show both your @value{GDBN} session
16467and the source.
bf0184be 16468
8e04817f
AC
16469Explicit @value{GDBN} @code{list} or search commands still produce output as
16470usual, but you probably have no reason to use them from Emacs.
c906108c 16471
64fabec2
AC
16472If you specify an absolute file name when prompted for the @kbd{M-x
16473gdb} argument, then Emacs sets your current working directory to where
16474your program resides. If you only specify the file name, then Emacs
16475sets your current working directory to to the directory associated
16476with the previous buffer. In this case, @value{GDBN} may find your
16477program by searching your environment's @code{PATH} variable, but on
16478some operating systems it might not find the source. So, although the
16479@value{GDBN} input and output session proceeds normally, the auxiliary
16480buffer does not display the current source and line of execution.
16481
16482The initial working directory of @value{GDBN} is printed on the top
16483line of the @value{GDBN} I/O buffer and this serves as a default for
16484the commands that specify files for @value{GDBN} to operate
16485on. @xref{Files, ,Commands to specify files}.
16486
16487By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
16488need to call @value{GDBN} by a different name (for example, if you
16489keep several configurations around, with different names) you can
16490customize the Emacs variable @code{gud-gdb-command-name} to run the
16491one you want.
8e04817f
AC
16492
16493In the @value{GDBN} I/O buffer, you can use these special Emacs commands in
16494addition to the standard Shell mode commands:
c906108c 16495
8e04817f
AC
16496@table @kbd
16497@item C-h m
16498Describe the features of Emacs' @value{GDBN} Mode.
c906108c 16499
64fabec2 16500@item C-c C-s
8e04817f
AC
16501Execute to another source line, like the @value{GDBN} @code{step} command; also
16502update the display window to show the current file and location.
c906108c 16503
64fabec2 16504@item C-c C-n
8e04817f
AC
16505Execute to next source line in this function, skipping all function
16506calls, like the @value{GDBN} @code{next} command. Then update the display window
16507to show the current file and location.
c906108c 16508
64fabec2 16509@item C-c C-i
8e04817f
AC
16510Execute one instruction, like the @value{GDBN} @code{stepi} command; update
16511display window accordingly.
c906108c 16512
8e04817f
AC
16513@item C-c C-f
16514Execute until exit from the selected stack frame, like the @value{GDBN}
16515@code{finish} command.
c906108c 16516
64fabec2 16517@item C-c C-r
8e04817f
AC
16518Continue execution of your program, like the @value{GDBN} @code{continue}
16519command.
b433d00b 16520
64fabec2 16521@item C-c <
8e04817f
AC
16522Go up the number of frames indicated by the numeric argument
16523(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
16524like the @value{GDBN} @code{up} command.
b433d00b 16525
64fabec2 16526@item C-c >
8e04817f
AC
16527Go down the number of frames indicated by the numeric argument, like the
16528@value{GDBN} @code{down} command.
8e04817f 16529@end table
c906108c 16530
64fabec2 16531In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break})
8e04817f 16532tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 16533
64fabec2
AC
16534If you type @kbd{M-x speedbar}, then Emacs displays a separate frame which
16535shows a backtrace when the @value{GDBN} I/O buffer is current. Move
16536point to any frame in the stack and type @key{RET} to make it become the
16537current frame and display the associated source in the source buffer.
16538Alternatively, click @kbd{Mouse-2} to make the selected frame become the
16539current one.
16540
8e04817f
AC
16541If you accidentally delete the source-display buffer, an easy way to get
16542it back is to type the command @code{f} in the @value{GDBN} buffer, to
16543request a frame display; when you run under Emacs, this recreates
16544the source buffer if necessary to show you the context of the current
16545frame.
c906108c 16546
8e04817f
AC
16547The source files displayed in Emacs are in ordinary Emacs buffers
16548which are visiting the source files in the usual way. You can edit
16549the files with these buffers if you wish; but keep in mind that @value{GDBN}
16550communicates with Emacs in terms of line numbers. If you add or
16551delete lines from the text, the line numbers that @value{GDBN} knows cease
16552to correspond properly with the code.
b383017d 16553
64fabec2
AC
16554The description given here is for GNU Emacs version 21.3 and a more
16555detailed description of its interaction with @value{GDBN} is given in
16556the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu} Emacs Manual}).
c906108c 16557
8e04817f
AC
16558@c The following dropped because Epoch is nonstandard. Reactivate
16559@c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
16560@ignore
16561@kindex Emacs Epoch environment
16562@kindex Epoch
16563@kindex inspect
c906108c 16564
8e04817f
AC
16565Version 18 of @sc{gnu} Emacs has a built-in window system
16566called the @code{epoch}
16567environment. Users of this environment can use a new command,
16568@code{inspect} which performs identically to @code{print} except that
16569each value is printed in its own window.
16570@end ignore
c906108c 16571
922fbb7b
AC
16572
16573@node GDB/MI
16574@chapter The @sc{gdb/mi} Interface
16575
16576@unnumberedsec Function and Purpose
16577
16578@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
16579@sc{gdb/mi} is a line based machine oriented text interface to
16580@value{GDBN} and is activated by specifying using the
16581@option{--interpreter} command line option (@pxref{Mode Options}). It
16582is specifically intended to support the development of systems which
16583use the debugger as just one small component of a larger system.
922fbb7b
AC
16584
16585This chapter is a specification of the @sc{gdb/mi} interface. It is written
16586in the form of a reference manual.
16587
16588Note that @sc{gdb/mi} is still under construction, so some of the
16589features described below are incomplete and subject to change.
16590
16591@unnumberedsec Notation and Terminology
16592
16593@cindex notational conventions, for @sc{gdb/mi}
16594This chapter uses the following notation:
16595
16596@itemize @bullet
16597@item
16598@code{|} separates two alternatives.
16599
16600@item
16601@code{[ @var{something} ]} indicates that @var{something} is optional:
16602it may or may not be given.
16603
16604@item
16605@code{( @var{group} )*} means that @var{group} inside the parentheses
16606may repeat zero or more times.
16607
16608@item
16609@code{( @var{group} )+} means that @var{group} inside the parentheses
16610may repeat one or more times.
16611
16612@item
16613@code{"@var{string}"} means a literal @var{string}.
16614@end itemize
16615
16616@ignore
16617@heading Dependencies
16618@end ignore
16619
16620@heading Acknowledgments
16621
16622In alphabetic order: Andrew Cagney, Fernando Nasser, Stan Shebs and
16623Elena Zannoni.
16624
16625@menu
16626* GDB/MI Command Syntax::
16627* GDB/MI Compatibility with CLI::
16628* GDB/MI Output Records::
16629* GDB/MI Command Description Format::
16630* GDB/MI Breakpoint Table Commands::
16631* GDB/MI Data Manipulation::
16632* GDB/MI Program Control::
16633* GDB/MI Miscellaneous Commands::
16634@ignore
16635* GDB/MI Kod Commands::
16636* GDB/MI Memory Overlay Commands::
16637* GDB/MI Signal Handling Commands::
16638@end ignore
16639* GDB/MI Stack Manipulation::
16640* GDB/MI Symbol Query::
16641* GDB/MI Target Manipulation::
16642* GDB/MI Thread Commands::
16643* GDB/MI Tracepoint Commands::
16644* GDB/MI Variable Objects::
16645@end menu
16646
16647@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16648@node GDB/MI Command Syntax
16649@section @sc{gdb/mi} Command Syntax
16650
16651@menu
16652* GDB/MI Input Syntax::
16653* GDB/MI Output Syntax::
16654* GDB/MI Simple Examples::
16655@end menu
16656
16657@node GDB/MI Input Syntax
16658@subsection @sc{gdb/mi} Input Syntax
16659
16660@cindex input syntax for @sc{gdb/mi}
16661@cindex @sc{gdb/mi}, input syntax
16662@table @code
16663@item @var{command} @expansion{}
16664@code{@var{cli-command} | @var{mi-command}}
16665
16666@item @var{cli-command} @expansion{}
16667@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
16668@var{cli-command} is any existing @value{GDBN} CLI command.
16669
16670@item @var{mi-command} @expansion{}
16671@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
16672@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
16673
16674@item @var{token} @expansion{}
16675"any sequence of digits"
16676
16677@item @var{option} @expansion{}
16678@code{"-" @var{parameter} [ " " @var{parameter} ]}
16679
16680@item @var{parameter} @expansion{}
16681@code{@var{non-blank-sequence} | @var{c-string}}
16682
16683@item @var{operation} @expansion{}
16684@emph{any of the operations described in this chapter}
16685
16686@item @var{non-blank-sequence} @expansion{}
16687@emph{anything, provided it doesn't contain special characters such as
16688"-", @var{nl}, """ and of course " "}
16689
16690@item @var{c-string} @expansion{}
16691@code{""" @var{seven-bit-iso-c-string-content} """}
16692
16693@item @var{nl} @expansion{}
16694@code{CR | CR-LF}
16695@end table
16696
16697@noindent
16698Notes:
16699
16700@itemize @bullet
16701@item
16702The CLI commands are still handled by the @sc{mi} interpreter; their
16703output is described below.
16704
16705@item
16706The @code{@var{token}}, when present, is passed back when the command
16707finishes.
16708
16709@item
16710Some @sc{mi} commands accept optional arguments as part of the parameter
16711list. Each option is identified by a leading @samp{-} (dash) and may be
16712followed by an optional argument parameter. Options occur first in the
16713parameter list and can be delimited from normal parameters using
16714@samp{--} (this is useful when some parameters begin with a dash).
16715@end itemize
16716
16717Pragmatics:
16718
16719@itemize @bullet
16720@item
16721We want easy access to the existing CLI syntax (for debugging).
16722
16723@item
16724We want it to be easy to spot a @sc{mi} operation.
16725@end itemize
16726
16727@node GDB/MI Output Syntax
16728@subsection @sc{gdb/mi} Output Syntax
16729
16730@cindex output syntax of @sc{gdb/mi}
16731@cindex @sc{gdb/mi}, output syntax
16732The output from @sc{gdb/mi} consists of zero or more out-of-band records
16733followed, optionally, by a single result record. This result record
16734is for the most recent command. The sequence of output records is
16735terminated by @samp{(@value{GDBP})}.
16736
16737If an input command was prefixed with a @code{@var{token}} then the
16738corresponding output for that command will also be prefixed by that same
16739@var{token}.
16740
16741@table @code
16742@item @var{output} @expansion{}
f7dc1244 16743@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(@value{GDBP})" @var{nl}}
922fbb7b
AC
16744
16745@item @var{result-record} @expansion{}
16746@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
16747
16748@item @var{out-of-band-record} @expansion{}
16749@code{@var{async-record} | @var{stream-record}}
16750
16751@item @var{async-record} @expansion{}
16752@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
16753
16754@item @var{exec-async-output} @expansion{}
16755@code{[ @var{token} ] "*" @var{async-output}}
16756
16757@item @var{status-async-output} @expansion{}
16758@code{[ @var{token} ] "+" @var{async-output}}
16759
16760@item @var{notify-async-output} @expansion{}
16761@code{[ @var{token} ] "=" @var{async-output}}
16762
16763@item @var{async-output} @expansion{}
16764@code{@var{async-class} ( "," @var{result} )* @var{nl}}
16765
16766@item @var{result-class} @expansion{}
16767@code{"done" | "running" | "connected" | "error" | "exit"}
16768
16769@item @var{async-class} @expansion{}
16770@code{"stopped" | @var{others}} (where @var{others} will be added
16771depending on the needs---this is still in development).
16772
16773@item @var{result} @expansion{}
16774@code{ @var{variable} "=" @var{value}}
16775
16776@item @var{variable} @expansion{}
16777@code{ @var{string} }
16778
16779@item @var{value} @expansion{}
16780@code{ @var{const} | @var{tuple} | @var{list} }
16781
16782@item @var{const} @expansion{}
16783@code{@var{c-string}}
16784
16785@item @var{tuple} @expansion{}
16786@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
16787
16788@item @var{list} @expansion{}
16789@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
16790@var{result} ( "," @var{result} )* "]" }
16791
16792@item @var{stream-record} @expansion{}
16793@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
16794
16795@item @var{console-stream-output} @expansion{}
16796@code{"~" @var{c-string}}
16797
16798@item @var{target-stream-output} @expansion{}
16799@code{"@@" @var{c-string}}
16800
16801@item @var{log-stream-output} @expansion{}
16802@code{"&" @var{c-string}}
16803
16804@item @var{nl} @expansion{}
16805@code{CR | CR-LF}
16806
16807@item @var{token} @expansion{}
16808@emph{any sequence of digits}.
16809@end table
16810
16811@noindent
16812Notes:
16813
16814@itemize @bullet
16815@item
16816All output sequences end in a single line containing a period.
16817
16818@item
16819The @code{@var{token}} is from the corresponding request. If an execution
16820command is interrupted by the @samp{-exec-interrupt} command, the
16821@var{token} associated with the @samp{*stopped} message is the one of the
16822original execution command, not the one of the interrupt command.
16823
16824@item
16825@cindex status output in @sc{gdb/mi}
16826@var{status-async-output} contains on-going status information about the
16827progress of a slow operation. It can be discarded. All status output is
16828prefixed by @samp{+}.
16829
16830@item
16831@cindex async output in @sc{gdb/mi}
16832@var{exec-async-output} contains asynchronous state change on the target
16833(stopped, started, disappeared). All async output is prefixed by
16834@samp{*}.
16835
16836@item
16837@cindex notify output in @sc{gdb/mi}
16838@var{notify-async-output} contains supplementary information that the
16839client should handle (e.g., a new breakpoint information). All notify
16840output is prefixed by @samp{=}.
16841
16842@item
16843@cindex console output in @sc{gdb/mi}
16844@var{console-stream-output} is output that should be displayed as is in the
16845console. It is the textual response to a CLI command. All the console
16846output is prefixed by @samp{~}.
16847
16848@item
16849@cindex target output in @sc{gdb/mi}
16850@var{target-stream-output} is the output produced by the target program.
16851All the target output is prefixed by @samp{@@}.
16852
16853@item
16854@cindex log output in @sc{gdb/mi}
16855@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
16856instance messages that should be displayed as part of an error log. All
16857the log output is prefixed by @samp{&}.
16858
16859@item
16860@cindex list output in @sc{gdb/mi}
16861New @sc{gdb/mi} commands should only output @var{lists} containing
16862@var{values}.
16863
16864
16865@end itemize
16866
16867@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
16868details about the various output records.
16869
16870@node GDB/MI Simple Examples
16871@subsection Simple Examples of @sc{gdb/mi} Interaction
16872@cindex @sc{gdb/mi}, simple examples
16873
16874This subsection presents several simple examples of interaction using
16875the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
16876following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
16877the output received from @sc{gdb/mi}.
16878
16879@subsubheading Target Stop
16880@c Ummm... There is no "-stop" command. This assumes async, no?
16881Here's an example of stopping the inferior process:
16882
16883@smallexample
16884-> -stop
16885<- (@value{GDBP})
16886@end smallexample
16887
16888@noindent
16889and later:
16890
16891@smallexample
16892<- *stop,reason="stop",address="0x123",source="a.c:123"
16893<- (@value{GDBP})
16894@end smallexample
16895
16896@subsubheading Simple CLI Command
16897
16898Here's an example of a simple CLI command being passed through
16899@sc{gdb/mi} and on to the CLI.
16900
16901@smallexample
16902-> print 1+2
16903<- &"print 1+2\n"
16904<- ~"$1 = 3\n"
16905<- ^done
16906<- (@value{GDBP})
16907@end smallexample
16908
16909@subsubheading Command With Side Effects
16910
16911@smallexample
16912-> -symbol-file xyz.exe
16913<- *breakpoint,nr="3",address="0x123",source="a.c:123"
16914<- (@value{GDBP})
16915@end smallexample
16916
16917@subsubheading A Bad Command
16918
16919Here's what happens if you pass a non-existent command:
16920
16921@smallexample
16922-> -rubbish
16923<- ^error,msg="Undefined MI command: rubbish"
16924<- (@value{GDBP})
16925@end smallexample
16926
16927@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16928@node GDB/MI Compatibility with CLI
16929@section @sc{gdb/mi} Compatibility with CLI
16930
16931@cindex compatibility, @sc{gdb/mi} and CLI
16932@cindex @sc{gdb/mi}, compatibility with CLI
16933To help users familiar with @value{GDBN}'s existing CLI interface, @sc{gdb/mi}
16934accepts existing CLI commands. As specified by the syntax, such
16935commands can be directly entered into the @sc{gdb/mi} interface and @value{GDBN} will
16936respond.
16937
16938This mechanism is provided as an aid to developers of @sc{gdb/mi}
16939clients and not as a reliable interface into the CLI. Since the command
16940is being interpreteted in an environment that assumes @sc{gdb/mi}
16941behaviour, the exact output of such commands is likely to end up being
16942an un-supported hybrid of @sc{gdb/mi} and CLI output.
16943
16944@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16945@node GDB/MI Output Records
16946@section @sc{gdb/mi} Output Records
16947
16948@menu
16949* GDB/MI Result Records::
16950* GDB/MI Stream Records::
16951* GDB/MI Out-of-band Records::
16952@end menu
16953
16954@node GDB/MI Result Records
16955@subsection @sc{gdb/mi} Result Records
16956
16957@cindex result records in @sc{gdb/mi}
16958@cindex @sc{gdb/mi}, result records
16959In addition to a number of out-of-band notifications, the response to a
16960@sc{gdb/mi} command includes one of the following result indications:
16961
16962@table @code
16963@findex ^done
16964@item "^done" [ "," @var{results} ]
16965The synchronous operation was successful, @code{@var{results}} are the return
16966values.
16967
16968@item "^running"
16969@findex ^running
16970@c Is this one correct? Should it be an out-of-band notification?
16971The asynchronous operation was successfully started. The target is
16972running.
16973
16974@item "^error" "," @var{c-string}
16975@findex ^error
16976The operation failed. The @code{@var{c-string}} contains the corresponding
16977error message.
16978@end table
16979
16980@node GDB/MI Stream Records
16981@subsection @sc{gdb/mi} Stream Records
16982
16983@cindex @sc{gdb/mi}, stream records
16984@cindex stream records in @sc{gdb/mi}
16985@value{GDBN} internally maintains a number of output streams: the console, the
16986target, and the log. The output intended for each of these streams is
16987funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
16988
16989Each stream record begins with a unique @dfn{prefix character} which
16990identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
16991Syntax}). In addition to the prefix, each stream record contains a
16992@code{@var{string-output}}. This is either raw text (with an implicit new
16993line) or a quoted C string (which does not contain an implicit newline).
16994
16995@table @code
16996@item "~" @var{string-output}
16997The console output stream contains text that should be displayed in the
16998CLI console window. It contains the textual responses to CLI commands.
16999
17000@item "@@" @var{string-output}
17001The target output stream contains any textual output from the running
17002target.
17003
17004@item "&" @var{string-output}
17005The log stream contains debugging messages being produced by @value{GDBN}'s
17006internals.
17007@end table
17008
17009@node GDB/MI Out-of-band Records
17010@subsection @sc{gdb/mi} Out-of-band Records
17011
17012@cindex out-of-band records in @sc{gdb/mi}
17013@cindex @sc{gdb/mi}, out-of-band records
17014@dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17015additional changes that have occurred. Those changes can either be a
17016consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17017target activity (e.g., target stopped).
17018
17019The following is a preliminary list of possible out-of-band records.
034dad6f 17020In particular, the @var{exec-async-output} records.
922fbb7b
AC
17021
17022@table @code
034dad6f
BR
17023@item *stopped,reason="@var{reason}"
17024@end table
17025
17026@var{reason} can be one of the following:
17027
17028@table @code
17029@item breakpoint-hit
17030A breakpoint was reached.
17031@item watchpoint-trigger
17032A watchpoint was triggered.
17033@item read-watchpoint-trigger
17034A read watchpoint was triggered.
17035@item access-watchpoint-trigger
17036An access watchpoint was triggered.
17037@item function-finished
17038An -exec-finish or similar CLI command was accomplished.
17039@item location-reached
17040An -exec-until or similar CLI command was accomplished.
17041@item watchpoint-scope
17042A watchpoint has gone out of scope.
17043@item end-stepping-range
17044An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
17045similar CLI command was accomplished.
17046@item exited-signalled
17047The inferior exited because of a signal.
17048@item exited
17049The inferior exited.
17050@item exited-normally
17051The inferior exited normally.
17052@item signal-received
17053A signal was received by the inferior.
922fbb7b
AC
17054@end table
17055
17056
17057@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17058@node GDB/MI Command Description Format
17059@section @sc{gdb/mi} Command Description Format
17060
17061The remaining sections describe blocks of commands. Each block of
17062commands is laid out in a fashion similar to this section.
17063
17064Note the the line breaks shown in the examples are here only for
17065readability. They don't appear in the real output.
17066Also note that the commands with a non-available example (N.A.@:) are
17067not yet implemented.
17068
17069@subheading Motivation
17070
17071The motivation for this collection of commands.
17072
17073@subheading Introduction
17074
17075A brief introduction to this collection of commands as a whole.
17076
17077@subheading Commands
17078
17079For each command in the block, the following is described:
17080
17081@subsubheading Synopsis
17082
17083@smallexample
17084 -command @var{args}@dots{}
17085@end smallexample
17086
922fbb7b
AC
17087@subsubheading Result
17088
265eeb58 17089@subsubheading @value{GDBN} Command
922fbb7b 17090
265eeb58 17091The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
17092
17093@subsubheading Example
17094
922fbb7b
AC
17095@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17096@node GDB/MI Breakpoint Table Commands
17097@section @sc{gdb/mi} Breakpoint table commands
17098
17099@cindex breakpoint commands for @sc{gdb/mi}
17100@cindex @sc{gdb/mi}, breakpoint commands
17101This section documents @sc{gdb/mi} commands for manipulating
17102breakpoints.
17103
17104@subheading The @code{-break-after} Command
17105@findex -break-after
17106
17107@subsubheading Synopsis
17108
17109@smallexample
17110 -break-after @var{number} @var{count}
17111@end smallexample
17112
17113The breakpoint number @var{number} is not in effect until it has been
17114hit @var{count} times. To see how this is reflected in the output of
17115the @samp{-break-list} command, see the description of the
17116@samp{-break-list} command below.
17117
17118@subsubheading @value{GDBN} Command
17119
17120The corresponding @value{GDBN} command is @samp{ignore}.
17121
17122@subsubheading Example
17123
17124@smallexample
17125(@value{GDBP})
17126-break-insert main
17127^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",line="5"@}
17128(@value{GDBP})
17129-break-after 1 3
17130~
17131^done
17132(@value{GDBP})
17133-break-list
17134^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17135hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17136@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17137@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17138@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17139@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17140@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17141body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17142addr="0x000100d0",func="main",file="hello.c",line="5",times="0",
17143ignore="3"@}]@}
17144(@value{GDBP})
17145@end smallexample
17146
17147@ignore
17148@subheading The @code{-break-catch} Command
17149@findex -break-catch
17150
17151@subheading The @code{-break-commands} Command
17152@findex -break-commands
17153@end ignore
17154
17155
17156@subheading The @code{-break-condition} Command
17157@findex -break-condition
17158
17159@subsubheading Synopsis
17160
17161@smallexample
17162 -break-condition @var{number} @var{expr}
17163@end smallexample
17164
17165Breakpoint @var{number} will stop the program only if the condition in
17166@var{expr} is true. The condition becomes part of the
17167@samp{-break-list} output (see the description of the @samp{-break-list}
17168command below).
17169
17170@subsubheading @value{GDBN} Command
17171
17172The corresponding @value{GDBN} command is @samp{condition}.
17173
17174@subsubheading Example
17175
17176@smallexample
17177(@value{GDBP})
17178-break-condition 1 1
17179^done
17180(@value{GDBP})
17181-break-list
17182^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17183hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17184@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17185@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17186@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17187@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17188@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17189body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17190addr="0x000100d0",func="main",file="hello.c",line="5",cond="1",
17191times="0",ignore="3"@}]@}
17192(@value{GDBP})
17193@end smallexample
17194
17195@subheading The @code{-break-delete} Command
17196@findex -break-delete
17197
17198@subsubheading Synopsis
17199
17200@smallexample
17201 -break-delete ( @var{breakpoint} )+
17202@end smallexample
17203
17204Delete the breakpoint(s) whose number(s) are specified in the argument
17205list. This is obviously reflected in the breakpoint list.
17206
17207@subsubheading @value{GDBN} command
17208
17209The corresponding @value{GDBN} command is @samp{delete}.
17210
17211@subsubheading Example
17212
17213@smallexample
17214(@value{GDBP})
17215-break-delete 1
17216^done
17217(@value{GDBP})
17218-break-list
17219^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17220hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17221@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17222@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17223@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17224@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17225@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17226body=[]@}
17227(@value{GDBP})
17228@end smallexample
17229
17230@subheading The @code{-break-disable} Command
17231@findex -break-disable
17232
17233@subsubheading Synopsis
17234
17235@smallexample
17236 -break-disable ( @var{breakpoint} )+
17237@end smallexample
17238
17239Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
17240break list is now set to @samp{n} for the named @var{breakpoint}(s).
17241
17242@subsubheading @value{GDBN} Command
17243
17244The corresponding @value{GDBN} command is @samp{disable}.
17245
17246@subsubheading Example
17247
17248@smallexample
17249(@value{GDBP})
17250-break-disable 2
17251^done
17252(@value{GDBP})
17253-break-list
17254^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17255hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17256@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17257@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17258@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17259@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17260@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17261body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
17262addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17263(@value{GDBP})
17264@end smallexample
17265
17266@subheading The @code{-break-enable} Command
17267@findex -break-enable
17268
17269@subsubheading Synopsis
17270
17271@smallexample
17272 -break-enable ( @var{breakpoint} )+
17273@end smallexample
17274
17275Enable (previously disabled) @var{breakpoint}(s).
17276
17277@subsubheading @value{GDBN} Command
17278
17279The corresponding @value{GDBN} command is @samp{enable}.
17280
17281@subsubheading Example
17282
17283@smallexample
17284(@value{GDBP})
17285-break-enable 2
17286^done
17287(@value{GDBP})
17288-break-list
17289^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17290hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17291@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17292@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17293@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17294@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17295@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17296body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17297addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@}]@}
17298(@value{GDBP})
17299@end smallexample
17300
17301@subheading The @code{-break-info} Command
17302@findex -break-info
17303
17304@subsubheading Synopsis
17305
17306@smallexample
17307 -break-info @var{breakpoint}
17308@end smallexample
17309
17310@c REDUNDANT???
17311Get information about a single breakpoint.
17312
17313@subsubheading @value{GDBN} command
17314
17315The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
17316
17317@subsubheading Example
17318N.A.
17319
17320@subheading The @code{-break-insert} Command
17321@findex -break-insert
17322
17323@subsubheading Synopsis
17324
17325@smallexample
17326 -break-insert [ -t ] [ -h ] [ -r ]
17327 [ -c @var{condition} ] [ -i @var{ignore-count} ]
17328 [ -p @var{thread} ] [ @var{line} | @var{addr} ]
17329@end smallexample
17330
17331@noindent
17332If specified, @var{line}, can be one of:
17333
17334@itemize @bullet
17335@item function
17336@c @item +offset
17337@c @item -offset
17338@c @item linenum
17339@item filename:linenum
17340@item filename:function
17341@item *address
17342@end itemize
17343
17344The possible optional parameters of this command are:
17345
17346@table @samp
17347@item -t
17348Insert a tempoary breakpoint.
17349@item -h
17350Insert a hardware breakpoint.
17351@item -c @var{condition}
17352Make the breakpoint conditional on @var{condition}.
17353@item -i @var{ignore-count}
17354Initialize the @var{ignore-count}.
17355@item -r
17356Insert a regular breakpoint in all the functions whose names match the
17357given regular expression. Other flags are not applicable to regular
17358expresson.
17359@end table
17360
17361@subsubheading Result
17362
17363The result is in the form:
17364
17365@smallexample
17366 ^done,bkptno="@var{number}",func="@var{funcname}",
17367 file="@var{filename}",line="@var{lineno}"
17368@end smallexample
17369
17370@noindent
17371where @var{number} is the @value{GDBN} number for this breakpoint, @var{funcname}
17372is the name of the function where the breakpoint was inserted,
17373@var{filename} is the name of the source file which contains this
17374function, and @var{lineno} is the source line number within that file.
17375
17376Note: this format is open to change.
17377@c An out-of-band breakpoint instead of part of the result?
17378
17379@subsubheading @value{GDBN} Command
17380
17381The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
17382@samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
17383
17384@subsubheading Example
17385
17386@smallexample
17387(@value{GDBP})
17388-break-insert main
17389^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
17390(@value{GDBP})
17391-break-insert -t foo
17392^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",line="11"@}
17393(@value{GDBP})
17394-break-list
17395^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17396hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17397@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17398@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17399@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17400@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17401@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17402body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17403addr="0x0001072c", func="main",file="recursive2.c",line="4",times="0"@},
17404bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
17405addr="0x00010774",func="foo",file="recursive2.c",line="11",times="0"@}]@}
17406(@value{GDBP})
17407-break-insert -r foo.*
17408~int foo(int, int);
17409^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c",line="11"@}
17410(@value{GDBP})
17411@end smallexample
17412
17413@subheading The @code{-break-list} Command
17414@findex -break-list
17415
17416@subsubheading Synopsis
17417
17418@smallexample
17419 -break-list
17420@end smallexample
17421
17422Displays the list of inserted breakpoints, showing the following fields:
17423
17424@table @samp
17425@item Number
17426number of the breakpoint
17427@item Type
17428type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
17429@item Disposition
17430should the breakpoint be deleted or disabled when it is hit: @samp{keep}
17431or @samp{nokeep}
17432@item Enabled
17433is the breakpoint enabled or no: @samp{y} or @samp{n}
17434@item Address
17435memory location at which the breakpoint is set
17436@item What
17437logical location of the breakpoint, expressed by function name, file
17438name, line number
17439@item Times
17440number of times the breakpoint has been hit
17441@end table
17442
17443If there are no breakpoints or watchpoints, the @code{BreakpointTable}
17444@code{body} field is an empty list.
17445
17446@subsubheading @value{GDBN} Command
17447
17448The corresponding @value{GDBN} command is @samp{info break}.
17449
17450@subsubheading Example
17451
17452@smallexample
17453(@value{GDBP})
17454-break-list
17455^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17456hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17457@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17458@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17459@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17460@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17461@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17462body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17463addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
17464bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
17465addr="0x00010114",func="foo",file="hello.c",line="13",times="0"@}]@}
17466(@value{GDBP})
17467@end smallexample
17468
17469Here's an example of the result when there are no breakpoints:
17470
17471@smallexample
17472(@value{GDBP})
17473-break-list
17474^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
17475hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17476@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17477@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17478@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17479@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17480@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17481body=[]@}
17482(@value{GDBP})
17483@end smallexample
17484
17485@subheading The @code{-break-watch} Command
17486@findex -break-watch
17487
17488@subsubheading Synopsis
17489
17490@smallexample
17491 -break-watch [ -a | -r ]
17492@end smallexample
17493
17494Create a watchpoint. With the @samp{-a} option it will create an
17495@dfn{access} watchpoint, i.e. a watchpoint that triggers either on a
17496read from or on a write to the memory location. With the @samp{-r}
17497option, the watchpoint created is a @dfn{read} watchpoint, i.e. it will
17498trigger only when the memory location is accessed for reading. Without
17499either of the options, the watchpoint created is a regular watchpoint,
17500i.e. it will trigger when the memory location is accessed for writing.
17501@xref{Set Watchpoints, , Setting watchpoints}.
17502
17503Note that @samp{-break-list} will report a single list of watchpoints and
17504breakpoints inserted.
17505
17506@subsubheading @value{GDBN} Command
17507
17508The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
17509@samp{rwatch}.
17510
17511@subsubheading Example
17512
17513Setting a watchpoint on a variable in the @code{main} function:
17514
17515@smallexample
17516(@value{GDBP})
17517-break-watch x
17518^done,wpt=@{number="2",exp="x"@}
17519(@value{GDBP})
17520-exec-continue
17521^running
17522^done,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
17523value=@{old="-268439212",new="55"@},
76ff342d
DJ
17524frame=@{func="main",args=[],file="recursive2.c",
17525fullname="/home/foo/bar/devo/myproject/recursive2.c",line="5"@}
922fbb7b
AC
17526(@value{GDBP})
17527@end smallexample
17528
17529Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
17530the program execution twice: first for the variable changing value, then
17531for the watchpoint going out of scope.
17532
17533@smallexample
17534(@value{GDBP})
17535-break-watch C
17536^done,wpt=@{number="5",exp="C"@}
17537(@value{GDBP})
17538-exec-continue
17539^running
17540^done,reason="watchpoint-trigger",
17541wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
17542frame=@{func="callee4",args=[],
76ff342d
DJ
17543file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17544fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17545(@value{GDBP})
17546-exec-continue
17547^running
17548^done,reason="watchpoint-scope",wpnum="5",
17549frame=@{func="callee3",args=[@{name="strarg",
17550value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17551file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17552fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17553(@value{GDBP})
17554@end smallexample
17555
17556Listing breakpoints and watchpoints, at different points in the program
17557execution. Note that once the watchpoint goes out of scope, it is
17558deleted.
17559
17560@smallexample
17561(@value{GDBP})
17562-break-watch C
17563^done,wpt=@{number="2",exp="C"@}
17564(@value{GDBP})
17565-break-list
17566^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17567hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17568@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17569@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17570@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17571@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17572@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17573body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17574addr="0x00010734",func="callee4",
17575file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17576bkpt=@{number="2",type="watchpoint",disp="keep",
17577enabled="y",addr="",what="C",times="0"@}]@}
17578(@value{GDBP})
17579-exec-continue
17580^running
17581^done,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
17582value=@{old="-276895068",new="3"@},
17583frame=@{func="callee4",args=[],
76ff342d
DJ
17584file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17585fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
922fbb7b
AC
17586(@value{GDBP})
17587-break-list
17588^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
17589hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17590@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17591@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17592@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17593@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17594@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17595body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17596addr="0x00010734",func="callee4",
17597file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
17598bkpt=@{number="2",type="watchpoint",disp="keep",
17599enabled="y",addr="",what="C",times="-5"@}]@}
17600(@value{GDBP})
17601-exec-continue
17602^running
17603^done,reason="watchpoint-scope",wpnum="2",
17604frame=@{func="callee3",args=[@{name="strarg",
17605value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
17606file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
17607fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
17608(@value{GDBP})
17609-break-list
17610^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
17611hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
17612@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
17613@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
17614@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
17615@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
17616@{width="40",alignment="2",col_name="what",colhdr="What"@}],
17617body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
17618addr="0x00010734",func="callee4",
17619file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@}]@}
17620(@value{GDBP})
17621@end smallexample
17622
17623@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17624@node GDB/MI Data Manipulation
17625@section @sc{gdb/mi} Data Manipulation
17626
17627@cindex data manipulation, in @sc{gdb/mi}
17628@cindex @sc{gdb/mi}, data manipulation
17629This section describes the @sc{gdb/mi} commands that manipulate data:
17630examine memory and registers, evaluate expressions, etc.
17631
17632@c REMOVED FROM THE INTERFACE.
17633@c @subheading -data-assign
17634@c Change the value of a program variable. Plenty of side effects.
17635@c @subsubheading GDB command
17636@c set variable
17637@c @subsubheading Example
17638@c N.A.
17639
17640@subheading The @code{-data-disassemble} Command
17641@findex -data-disassemble
17642
17643@subsubheading Synopsis
17644
17645@smallexample
17646 -data-disassemble
17647 [ -s @var{start-addr} -e @var{end-addr} ]
17648 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
17649 -- @var{mode}
17650@end smallexample
17651
17652@noindent
17653Where:
17654
17655@table @samp
17656@item @var{start-addr}
17657is the beginning address (or @code{$pc})
17658@item @var{end-addr}
17659is the end address
17660@item @var{filename}
17661is the name of the file to disassemble
17662@item @var{linenum}
17663is the line number to disassemble around
17664@item @var{lines}
17665is the the number of disassembly lines to be produced. If it is -1,
17666the whole function will be disassembled, in case no @var{end-addr} is
17667specified. If @var{end-addr} is specified as a non-zero value, and
17668@var{lines} is lower than the number of disassembly lines between
17669@var{start-addr} and @var{end-addr}, only @var{lines} lines are
17670displayed; if @var{lines} is higher than the number of lines between
17671@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
17672are displayed.
17673@item @var{mode}
17674is either 0 (meaning only disassembly) or 1 (meaning mixed source and
17675disassembly).
17676@end table
17677
17678@subsubheading Result
17679
17680The output for each instruction is composed of four fields:
17681
17682@itemize @bullet
17683@item Address
17684@item Func-name
17685@item Offset
17686@item Instruction
17687@end itemize
17688
17689Note that whatever included in the instruction field, is not manipulated
17690directely by @sc{gdb/mi}, i.e. it is not possible to adjust its format.
17691
17692@subsubheading @value{GDBN} Command
17693
17694There's no direct mapping from this command to the CLI.
17695
17696@subsubheading Example
17697
17698Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
17699
17700@smallexample
17701(@value{GDBP})
17702-data-disassemble -s $pc -e "$pc + 20" -- 0
17703^done,
17704asm_insns=[
17705@{address="0x000107c0",func-name="main",offset="4",
17706inst="mov 2, %o0"@},
17707@{address="0x000107c4",func-name="main",offset="8",
17708inst="sethi %hi(0x11800), %o2"@},
17709@{address="0x000107c8",func-name="main",offset="12",
17710inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
17711@{address="0x000107cc",func-name="main",offset="16",
17712inst="sethi %hi(0x11800), %o2"@},
17713@{address="0x000107d0",func-name="main",offset="20",
17714inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
17715(@value{GDBP})
17716@end smallexample
17717
17718Disassemble the whole @code{main} function. Line 32 is part of
17719@code{main}.
17720
17721@smallexample
17722-data-disassemble -f basics.c -l 32 -- 0
17723^done,asm_insns=[
17724@{address="0x000107bc",func-name="main",offset="0",
17725inst="save %sp, -112, %sp"@},
17726@{address="0x000107c0",func-name="main",offset="4",
17727inst="mov 2, %o0"@},
17728@{address="0x000107c4",func-name="main",offset="8",
17729inst="sethi %hi(0x11800), %o2"@},
17730[@dots{}]
17731@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
17732@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
17733(@value{GDBP})
17734@end smallexample
17735
17736Disassemble 3 instructions from the start of @code{main}:
17737
17738@smallexample
17739(@value{GDBP})
17740-data-disassemble -f basics.c -l 32 -n 3 -- 0
17741^done,asm_insns=[
17742@{address="0x000107bc",func-name="main",offset="0",
17743inst="save %sp, -112, %sp"@},
17744@{address="0x000107c0",func-name="main",offset="4",
17745inst="mov 2, %o0"@},
17746@{address="0x000107c4",func-name="main",offset="8",
17747inst="sethi %hi(0x11800), %o2"@}]
17748(@value{GDBP})
17749@end smallexample
17750
17751Disassemble 3 instructions from the start of @code{main} in mixed mode:
17752
17753@smallexample
17754(@value{GDBP})
17755-data-disassemble -f basics.c -l 32 -n 3 -- 1
17756^done,asm_insns=[
17757src_and_asm_line=@{line="31",
17758file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17759 testsuite/gdb.mi/basics.c",line_asm_insn=[
17760@{address="0x000107bc",func-name="main",offset="0",
17761inst="save %sp, -112, %sp"@}]@},
17762src_and_asm_line=@{line="32",
17763file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
17764 testsuite/gdb.mi/basics.c",line_asm_insn=[
17765@{address="0x000107c0",func-name="main",offset="4",
17766inst="mov 2, %o0"@},
17767@{address="0x000107c4",func-name="main",offset="8",
17768inst="sethi %hi(0x11800), %o2"@}]@}]
17769(@value{GDBP})
17770@end smallexample
17771
17772
17773@subheading The @code{-data-evaluate-expression} Command
17774@findex -data-evaluate-expression
17775
17776@subsubheading Synopsis
17777
17778@smallexample
17779 -data-evaluate-expression @var{expr}
17780@end smallexample
17781
17782Evaluate @var{expr} as an expression. The expression could contain an
17783inferior function call. The function call will execute synchronously.
17784If the expression contains spaces, it must be enclosed in double quotes.
17785
17786@subsubheading @value{GDBN} Command
17787
17788The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
17789@samp{call}. In @code{gdbtk} only, there's a corresponding
17790@samp{gdb_eval} command.
17791
17792@subsubheading Example
17793
17794In the following example, the numbers that precede the commands are the
17795@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
17796Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
17797output.
17798
17799@smallexample
17800211-data-evaluate-expression A
17801211^done,value="1"
17802(@value{GDBP})
17803311-data-evaluate-expression &A
17804311^done,value="0xefffeb7c"
17805(@value{GDBP})
17806411-data-evaluate-expression A+3
17807411^done,value="4"
17808(@value{GDBP})
17809511-data-evaluate-expression "A + 3"
17810511^done,value="4"
17811(@value{GDBP})
17812@end smallexample
17813
17814
17815@subheading The @code{-data-list-changed-registers} Command
17816@findex -data-list-changed-registers
17817
17818@subsubheading Synopsis
17819
17820@smallexample
17821 -data-list-changed-registers
17822@end smallexample
17823
17824Display a list of the registers that have changed.
17825
17826@subsubheading @value{GDBN} Command
17827
17828@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
17829has the corresponding command @samp{gdb_changed_register_list}.
17830
17831@subsubheading Example
17832
17833On a PPC MBX board:
17834
17835@smallexample
17836(@value{GDBP})
17837-exec-continue
17838^running
17839
17840(@value{GDBP})
17841*stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
76ff342d 17842args=[],file="try.c",fullname="/home/foo/bar/devo/myproject/try.c",line="5"@}
922fbb7b
AC
17843(@value{GDBP})
17844-data-list-changed-registers
17845^done,changed-registers=["0","1","2","4","5","6","7","8","9",
17846"10","11","13","14","15","16","17","18","19","20","21","22","23",
17847"24","25","26","27","28","30","31","64","65","66","67","69"]
17848(@value{GDBP})
17849@end smallexample
17850
17851
17852@subheading The @code{-data-list-register-names} Command
17853@findex -data-list-register-names
17854
17855@subsubheading Synopsis
17856
17857@smallexample
17858 -data-list-register-names [ ( @var{regno} )+ ]
17859@end smallexample
17860
17861Show a list of register names for the current target. If no arguments
17862are given, it shows a list of the names of all the registers. If
17863integer numbers are given as arguments, it will print a list of the
17864names of the registers corresponding to the arguments. To ensure
17865consistency between a register name and its number, the output list may
17866include empty register names.
17867
17868@subsubheading @value{GDBN} Command
17869
17870@value{GDBN} does not have a command which corresponds to
17871@samp{-data-list-register-names}. In @code{gdbtk} there is a
17872corresponding command @samp{gdb_regnames}.
17873
17874@subsubheading Example
17875
17876For the PPC MBX board:
17877@smallexample
17878(@value{GDBP})
17879-data-list-register-names
17880^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
17881"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
17882"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
17883"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
17884"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
17885"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
17886"", "pc","ps","cr","lr","ctr","xer"]
17887(@value{GDBP})
17888-data-list-register-names 1 2 3
17889^done,register-names=["r1","r2","r3"]
17890(@value{GDBP})
17891@end smallexample
17892
17893@subheading The @code{-data-list-register-values} Command
17894@findex -data-list-register-values
17895
17896@subsubheading Synopsis
17897
17898@smallexample
17899 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
17900@end smallexample
17901
17902Display the registers' contents. @var{fmt} is the format according to
17903which the registers' contents are to be returned, followed by an optional
17904list of numbers specifying the registers to display. A missing list of
17905numbers indicates that the contents of all the registers must be returned.
17906
17907Allowed formats for @var{fmt} are:
17908
17909@table @code
17910@item x
17911Hexadecimal
17912@item o
17913Octal
17914@item t
17915Binary
17916@item d
17917Decimal
17918@item r
17919Raw
17920@item N
17921Natural
17922@end table
17923
17924@subsubheading @value{GDBN} Command
17925
17926The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
17927all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
17928
17929@subsubheading Example
17930
17931For a PPC MBX board (note: line breaks are for readability only, they
17932don't appear in the actual output):
17933
17934@smallexample
17935(@value{GDBP})
17936-data-list-register-values r 64 65
17937^done,register-values=[@{number="64",value="0xfe00a300"@},
17938@{number="65",value="0x00029002"@}]
17939(@value{GDBP})
17940-data-list-register-values x
17941^done,register-values=[@{number="0",value="0xfe0043c8"@},
17942@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
17943@{number="3",value="0x0"@},@{number="4",value="0xa"@},
17944@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
17945@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
17946@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
17947@{number="11",value="0x1"@},@{number="12",value="0x0"@},
17948@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
17949@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
17950@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
17951@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
17952@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
17953@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
17954@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
17955@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
17956@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
17957@{number="31",value="0x0"@},@{number="32",value="0x0"@},
17958@{number="33",value="0x0"@},@{number="34",value="0x0"@},
17959@{number="35",value="0x0"@},@{number="36",value="0x0"@},
17960@{number="37",value="0x0"@},@{number="38",value="0x0"@},
17961@{number="39",value="0x0"@},@{number="40",value="0x0"@},
17962@{number="41",value="0x0"@},@{number="42",value="0x0"@},
17963@{number="43",value="0x0"@},@{number="44",value="0x0"@},
17964@{number="45",value="0x0"@},@{number="46",value="0x0"@},
17965@{number="47",value="0x0"@},@{number="48",value="0x0"@},
17966@{number="49",value="0x0"@},@{number="50",value="0x0"@},
17967@{number="51",value="0x0"@},@{number="52",value="0x0"@},
17968@{number="53",value="0x0"@},@{number="54",value="0x0"@},
17969@{number="55",value="0x0"@},@{number="56",value="0x0"@},
17970@{number="57",value="0x0"@},@{number="58",value="0x0"@},
17971@{number="59",value="0x0"@},@{number="60",value="0x0"@},
17972@{number="61",value="0x0"@},@{number="62",value="0x0"@},
17973@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
17974@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
17975@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
17976@{number="69",value="0x20002b03"@}]
17977(@value{GDBP})
17978@end smallexample
17979
17980
17981@subheading The @code{-data-read-memory} Command
17982@findex -data-read-memory
17983
17984@subsubheading Synopsis
17985
17986@smallexample
17987 -data-read-memory [ -o @var{byte-offset} ]
17988 @var{address} @var{word-format} @var{word-size}
17989 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
17990@end smallexample
17991
17992@noindent
17993where:
17994
17995@table @samp
17996@item @var{address}
17997An expression specifying the address of the first memory word to be
17998read. Complex expressions containing embedded white space should be
17999quoted using the C convention.
18000
18001@item @var{word-format}
18002The format to be used to print the memory words. The notation is the
18003same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
18004,Output formats}).
18005
18006@item @var{word-size}
18007The size of each memory word in bytes.
18008
18009@item @var{nr-rows}
18010The number of rows in the output table.
18011
18012@item @var{nr-cols}
18013The number of columns in the output table.
18014
18015@item @var{aschar}
18016If present, indicates that each row should include an @sc{ascii} dump. The
18017value of @var{aschar} is used as a padding character when a byte is not a
18018member of the printable @sc{ascii} character set (printable @sc{ascii}
18019characters are those whose code is between 32 and 126, inclusively).
18020
18021@item @var{byte-offset}
18022An offset to add to the @var{address} before fetching memory.
18023@end table
18024
18025This command displays memory contents as a table of @var{nr-rows} by
18026@var{nr-cols} words, each word being @var{word-size} bytes. In total,
18027@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
18028(returned as @samp{total-bytes}). Should less than the requested number
18029of bytes be returned by the target, the missing words are identified
18030using @samp{N/A}. The number of bytes read from the target is returned
18031in @samp{nr-bytes} and the starting address used to read memory in
18032@samp{addr}.
18033
18034The address of the next/previous row or page is available in
18035@samp{next-row} and @samp{prev-row}, @samp{next-page} and
18036@samp{prev-page}.
18037
18038@subsubheading @value{GDBN} Command
18039
18040The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
18041@samp{gdb_get_mem} memory read command.
18042
18043@subsubheading Example
18044
18045Read six bytes of memory starting at @code{bytes+6} but then offset by
18046@code{-6} bytes. Format as three rows of two columns. One byte per
18047word. Display each word in hex.
18048
18049@smallexample
18050(@value{GDBP})
180519-data-read-memory -o -6 -- bytes+6 x 1 3 2
180529^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
18053next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
18054prev-page="0x0000138a",memory=[
18055@{addr="0x00001390",data=["0x00","0x01"]@},
18056@{addr="0x00001392",data=["0x02","0x03"]@},
18057@{addr="0x00001394",data=["0x04","0x05"]@}]
18058(@value{GDBP})
18059@end smallexample
18060
18061Read two bytes of memory starting at address @code{shorts + 64} and
18062display as a single word formatted in decimal.
18063
18064@smallexample
18065(@value{GDBP})
180665-data-read-memory shorts+64 d 2 1 1
180675^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
18068next-row="0x00001512",prev-row="0x0000150e",
18069next-page="0x00001512",prev-page="0x0000150e",memory=[
18070@{addr="0x00001510",data=["128"]@}]
18071(@value{GDBP})
18072@end smallexample
18073
18074Read thirty two bytes of memory starting at @code{bytes+16} and format
18075as eight rows of four columns. Include a string encoding with @samp{x}
18076used as the non-printable character.
18077
18078@smallexample
18079(@value{GDBP})
180804-data-read-memory bytes+16 x 1 8 4 x
180814^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
18082next-row="0x000013c0",prev-row="0x0000139c",
18083next-page="0x000013c0",prev-page="0x00001380",memory=[
18084@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
18085@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
18086@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
18087@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
18088@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
18089@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
18090@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
18091@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
18092(@value{GDBP})
18093@end smallexample
18094
18095@subheading The @code{-display-delete} Command
18096@findex -display-delete
18097
18098@subsubheading Synopsis
18099
18100@smallexample
18101 -display-delete @var{number}
18102@end smallexample
18103
18104Delete the display @var{number}.
18105
18106@subsubheading @value{GDBN} Command
18107
18108The corresponding @value{GDBN} command is @samp{delete display}.
18109
18110@subsubheading Example
18111N.A.
18112
18113
18114@subheading The @code{-display-disable} Command
18115@findex -display-disable
18116
18117@subsubheading Synopsis
18118
18119@smallexample
18120 -display-disable @var{number}
18121@end smallexample
18122
18123Disable display @var{number}.
18124
18125@subsubheading @value{GDBN} Command
18126
18127The corresponding @value{GDBN} command is @samp{disable display}.
18128
18129@subsubheading Example
18130N.A.
18131
18132
18133@subheading The @code{-display-enable} Command
18134@findex -display-enable
18135
18136@subsubheading Synopsis
18137
18138@smallexample
18139 -display-enable @var{number}
18140@end smallexample
18141
18142Enable display @var{number}.
18143
18144@subsubheading @value{GDBN} Command
18145
18146The corresponding @value{GDBN} command is @samp{enable display}.
18147
18148@subsubheading Example
18149N.A.
18150
18151
18152@subheading The @code{-display-insert} Command
18153@findex -display-insert
18154
18155@subsubheading Synopsis
18156
18157@smallexample
18158 -display-insert @var{expression}
18159@end smallexample
18160
18161Display @var{expression} every time the program stops.
18162
18163@subsubheading @value{GDBN} Command
18164
18165The corresponding @value{GDBN} command is @samp{display}.
18166
18167@subsubheading Example
18168N.A.
18169
18170
18171@subheading The @code{-display-list} Command
18172@findex -display-list
18173
18174@subsubheading Synopsis
18175
18176@smallexample
18177 -display-list
18178@end smallexample
18179
18180List the displays. Do not show the current values.
18181
18182@subsubheading @value{GDBN} Command
18183
18184The corresponding @value{GDBN} command is @samp{info display}.
18185
18186@subsubheading Example
18187N.A.
18188
18189
18190@subheading The @code{-environment-cd} Command
18191@findex -environment-cd
18192
18193@subsubheading Synopsis
18194
18195@smallexample
18196 -environment-cd @var{pathdir}
18197@end smallexample
18198
18199Set @value{GDBN}'s working directory.
18200
18201@subsubheading @value{GDBN} Command
18202
18203The corresponding @value{GDBN} command is @samp{cd}.
18204
18205@subsubheading Example
18206
18207@smallexample
18208(@value{GDBP})
18209-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18210^done
18211(@value{GDBP})
18212@end smallexample
18213
18214
18215@subheading The @code{-environment-directory} Command
18216@findex -environment-directory
18217
18218@subsubheading Synopsis
18219
18220@smallexample
18221 -environment-directory [ -r ] [ @var{pathdir} ]+
18222@end smallexample
18223
18224Add directories @var{pathdir} to beginning of search path for source files.
18225If the @samp{-r} option is used, the search path is reset to the default
b383017d 18226search path. If directories @var{pathdir} are supplied in addition to the
922fbb7b
AC
18227@samp{-r} option, the search path is first reset and then addition
18228occurs as normal.
b383017d 18229Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18230multiple directories in a single command
18231results in the directories added to the beginning of the
18232search path in the same order they were presented in the command.
18233If blanks are needed as
18234part of a directory name, double-quotes should be used around
18235the name. In the command output, the path will show up separated
b383017d 18236by the system directory-separator character. The directory-seperator
922fbb7b
AC
18237character must not be used
18238in any directory name.
18239If no directories are specified, the current search path is displayed.
18240
18241@subsubheading @value{GDBN} Command
18242
18243The corresponding @value{GDBN} command is @samp{dir}.
18244
18245@subsubheading Example
18246
18247@smallexample
18248(@value{GDBP})
18249-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18250^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18251(@value{GDBP})
18252-environment-directory ""
18253^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18254(@value{GDBP})
18255-environment-directory -r /home/jjohnstn/src/gdb /usr/src
18256^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18257(@value{GDBP})
18258-environment-directory -r
18259^done,source-path="$cdir:$cwd"
18260(@value{GDBP})
18261@end smallexample
18262
18263
18264@subheading The @code{-environment-path} Command
18265@findex -environment-path
18266
18267@subsubheading Synopsis
18268
18269@smallexample
18270 -environment-path [ -r ] [ @var{pathdir} ]+
18271@end smallexample
18272
18273Add directories @var{pathdir} to beginning of search path for object files.
18274If the @samp{-r} option is used, the search path is reset to the original
b383017d
RM
18275search path that existed at gdb start-up. If directories @var{pathdir} are
18276supplied in addition to the
922fbb7b
AC
18277@samp{-r} option, the search path is first reset and then addition
18278occurs as normal.
b383017d 18279Multiple directories may be specified, separated by blanks. Specifying
922fbb7b
AC
18280multiple directories in a single command
18281results in the directories added to the beginning of the
18282search path in the same order they were presented in the command.
18283If blanks are needed as
18284part of a directory name, double-quotes should be used around
18285the name. In the command output, the path will show up separated
b383017d 18286by the system directory-separator character. The directory-seperator
922fbb7b
AC
18287character must not be used
18288in any directory name.
18289If no directories are specified, the current path is displayed.
18290
18291
18292@subsubheading @value{GDBN} Command
18293
18294The corresponding @value{GDBN} command is @samp{path}.
18295
18296@subsubheading Example
18297
18298@smallexample
18299(@value{GDBP})
b383017d 18300-environment-path
922fbb7b
AC
18301^done,path="/usr/bin"
18302(@value{GDBP})
18303-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18304^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18305(@value{GDBP})
18306-environment-path -r /usr/local/bin
18307^done,path="/usr/local/bin:/usr/bin"
18308(@value{GDBP})
18309@end smallexample
18310
18311
18312@subheading The @code{-environment-pwd} Command
18313@findex -environment-pwd
18314
18315@subsubheading Synopsis
18316
18317@smallexample
18318 -environment-pwd
18319@end smallexample
18320
18321Show the current working directory.
18322
18323@subsubheading @value{GDBN} command
18324
18325The corresponding @value{GDBN} command is @samp{pwd}.
18326
18327@subsubheading Example
18328
18329@smallexample
18330(@value{GDBP})
18331-environment-pwd
18332^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18333(@value{GDBP})
18334@end smallexample
18335
18336@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18337@node GDB/MI Program Control
18338@section @sc{gdb/mi} Program control
18339
18340@subsubheading Program termination
18341
18342As a result of execution, the inferior program can run to completion, if
18343it doesn't encounter any breakpoints. In this case the output will
18344include an exit code, if the program has exited exceptionally.
18345
18346@subsubheading Examples
18347
18348@noindent
18349Program exited normally:
18350
18351@smallexample
18352(@value{GDBP})
18353-exec-run
18354^running
18355(@value{GDBP})
18356x = 55
18357*stopped,reason="exited-normally"
18358(@value{GDBP})
18359@end smallexample
18360
18361@noindent
18362Program exited exceptionally:
18363
18364@smallexample
18365(@value{GDBP})
18366-exec-run
18367^running
18368(@value{GDBP})
18369x = 55
18370*stopped,reason="exited",exit-code="01"
18371(@value{GDBP})
18372@end smallexample
18373
18374Another way the program can terminate is if it receives a signal such as
18375@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
18376
18377@smallexample
18378(@value{GDBP})
18379*stopped,reason="exited-signalled",signal-name="SIGINT",
18380signal-meaning="Interrupt"
18381@end smallexample
18382
18383
18384@subheading The @code{-exec-abort} Command
18385@findex -exec-abort
18386
18387@subsubheading Synopsis
18388
18389@smallexample
18390 -exec-abort
18391@end smallexample
18392
18393Kill the inferior running program.
18394
18395@subsubheading @value{GDBN} Command
18396
18397The corresponding @value{GDBN} command is @samp{kill}.
18398
18399@subsubheading Example
18400N.A.
18401
18402
18403@subheading The @code{-exec-arguments} Command
18404@findex -exec-arguments
18405
18406@subsubheading Synopsis
18407
18408@smallexample
18409 -exec-arguments @var{args}
18410@end smallexample
18411
18412Set the inferior program arguments, to be used in the next
18413@samp{-exec-run}.
18414
18415@subsubheading @value{GDBN} Command
18416
18417The corresponding @value{GDBN} command is @samp{set args}.
18418
18419@subsubheading Example
18420
18421@c FIXME!
18422Don't have one around.
18423
18424
18425@subheading The @code{-exec-continue} Command
18426@findex -exec-continue
18427
18428@subsubheading Synopsis
18429
18430@smallexample
18431 -exec-continue
18432@end smallexample
18433
18434Asynchronous command. Resumes the execution of the inferior program
18435until a breakpoint is encountered, or until the inferior exits.
18436
18437@subsubheading @value{GDBN} Command
18438
18439The corresponding @value{GDBN} corresponding is @samp{continue}.
18440
18441@subsubheading Example
18442
18443@smallexample
18444-exec-continue
18445^running
18446(@value{GDBP})
18447@@Hello world
18448*stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
76ff342d 18449file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="13"@}
922fbb7b
AC
18450(@value{GDBP})
18451@end smallexample
18452
18453
18454@subheading The @code{-exec-finish} Command
18455@findex -exec-finish
18456
18457@subsubheading Synopsis
18458
18459@smallexample
18460 -exec-finish
18461@end smallexample
18462
18463Asynchronous command. Resumes the execution of the inferior program
18464until the current function is exited. Displays the results returned by
18465the function.
18466
18467@subsubheading @value{GDBN} Command
18468
18469The corresponding @value{GDBN} command is @samp{finish}.
18470
18471@subsubheading Example
18472
18473Function returning @code{void}.
18474
18475@smallexample
18476-exec-finish
18477^running
18478(@value{GDBP})
18479@@hello from foo
18480*stopped,reason="function-finished",frame=@{func="main",args=[],
76ff342d 18481file="hello.c",fullname="/home/foo/bar/devo/myproject/hello.c",line="7"@}
922fbb7b
AC
18482(@value{GDBP})
18483@end smallexample
18484
18485Function returning other than @code{void}. The name of the internal
18486@value{GDBN} variable storing the result is printed, together with the
18487value itself.
18488
18489@smallexample
18490-exec-finish
18491^running
18492(@value{GDBP})
18493*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
18494args=[@{name="a",value="1"],@{name="b",value="9"@}@},
76ff342d 18495file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b
AC
18496gdb-result-var="$1",return-value="0"
18497(@value{GDBP})
18498@end smallexample
18499
18500
18501@subheading The @code{-exec-interrupt} Command
18502@findex -exec-interrupt
18503
18504@subsubheading Synopsis
18505
18506@smallexample
18507 -exec-interrupt
18508@end smallexample
18509
18510Asynchronous command. Interrupts the background execution of the target.
18511Note how the token associated with the stop message is the one for the
18512execution command that has been interrupted. The token for the interrupt
18513itself only appears in the @samp{^done} output. If the user is trying to
18514interrupt a non-running program, an error message will be printed.
18515
18516@subsubheading @value{GDBN} Command
18517
18518The corresponding @value{GDBN} command is @samp{interrupt}.
18519
18520@subsubheading Example
18521
18522@smallexample
18523(@value{GDBP})
18524111-exec-continue
18525111^running
18526
18527(@value{GDBP})
18528222-exec-interrupt
18529222^done
18530(@value{GDBP})
18531111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d
DJ
18532frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
18533fullname="/home/foo/bar/devo/myproject/try.c",line="13"@}
922fbb7b
AC
18534(@value{GDBP})
18535
18536(@value{GDBP})
18537-exec-interrupt
18538^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
18539(@value{GDBP})
18540@end smallexample
18541
18542
18543@subheading The @code{-exec-next} Command
18544@findex -exec-next
18545
18546@subsubheading Synopsis
18547
18548@smallexample
18549 -exec-next
18550@end smallexample
18551
18552Asynchronous command. Resumes execution of the inferior program, stopping
18553when the beginning of the next source line is reached.
18554
18555@subsubheading @value{GDBN} Command
18556
18557The corresponding @value{GDBN} command is @samp{next}.
18558
18559@subsubheading Example
18560
18561@smallexample
18562-exec-next
18563^running
18564(@value{GDBP})
18565*stopped,reason="end-stepping-range",line="8",file="hello.c"
18566(@value{GDBP})
18567@end smallexample
18568
18569
18570@subheading The @code{-exec-next-instruction} Command
18571@findex -exec-next-instruction
18572
18573@subsubheading Synopsis
18574
18575@smallexample
18576 -exec-next-instruction
18577@end smallexample
18578
18579Asynchronous command. Executes one machine instruction. If the
18580instruction is a function call continues until the function returns. If
18581the program stops at an instruction in the middle of a source line, the
18582address will be printed as well.
18583
18584@subsubheading @value{GDBN} Command
18585
18586The corresponding @value{GDBN} command is @samp{nexti}.
18587
18588@subsubheading Example
18589
18590@smallexample
18591(@value{GDBP})
18592-exec-next-instruction
18593^running
18594
18595(@value{GDBP})
18596*stopped,reason="end-stepping-range",
18597addr="0x000100d4",line="5",file="hello.c"
18598(@value{GDBP})
18599@end smallexample
18600
18601
18602@subheading The @code{-exec-return} Command
18603@findex -exec-return
18604
18605@subsubheading Synopsis
18606
18607@smallexample
18608 -exec-return
18609@end smallexample
18610
18611Makes current function return immediately. Doesn't execute the inferior.
18612Displays the new current frame.
18613
18614@subsubheading @value{GDBN} Command
18615
18616The corresponding @value{GDBN} command is @samp{return}.
18617
18618@subsubheading Example
18619
18620@smallexample
18621(@value{GDBP})
18622200-break-insert callee4
18623200^done,bkpt=@{number="1",addr="0x00010734",
18624file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
18625(@value{GDBP})
18626000-exec-run
18627000^running
18628(@value{GDBP})
18629000*stopped,reason="breakpoint-hit",bkptno="1",
18630frame=@{func="callee4",args=[],
76ff342d
DJ
18631file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18632fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
922fbb7b
AC
18633(@value{GDBP})
18634205-break-delete
18635205^done
18636(@value{GDBP})
18637111-exec-return
18638111^done,frame=@{level="0",func="callee3",
18639args=[@{name="strarg",
18640value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
18641file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18642fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
922fbb7b
AC
18643(@value{GDBP})
18644@end smallexample
18645
18646
18647@subheading The @code{-exec-run} Command
18648@findex -exec-run
18649
18650@subsubheading Synopsis
18651
18652@smallexample
18653 -exec-run
18654@end smallexample
18655
18656Asynchronous command. Starts execution of the inferior from the
18657beginning. The inferior executes until either a breakpoint is
18658encountered or the program exits.
18659
18660@subsubheading @value{GDBN} Command
18661
18662The corresponding @value{GDBN} command is @samp{run}.
18663
18664@subsubheading Example
18665
18666@smallexample
18667(@value{GDBP})
18668-break-insert main
18669^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
18670(@value{GDBP})
18671-exec-run
18672^running
18673(@value{GDBP})
18674*stopped,reason="breakpoint-hit",bkptno="1",
76ff342d
DJ
18675frame=@{func="main",args=[],file="recursive2.c",
18676fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}
922fbb7b
AC
18677(@value{GDBP})
18678@end smallexample
18679
18680
18681@subheading The @code{-exec-show-arguments} Command
18682@findex -exec-show-arguments
18683
18684@subsubheading Synopsis
18685
18686@smallexample
18687 -exec-show-arguments
18688@end smallexample
18689
18690Print the arguments of the program.
18691
18692@subsubheading @value{GDBN} Command
18693
18694The corresponding @value{GDBN} command is @samp{show args}.
18695
18696@subsubheading Example
18697N.A.
18698
18699@c @subheading -exec-signal
18700
18701@subheading The @code{-exec-step} Command
18702@findex -exec-step
18703
18704@subsubheading Synopsis
18705
18706@smallexample
18707 -exec-step
18708@end smallexample
18709
18710Asynchronous command. Resumes execution of the inferior program, stopping
18711when the beginning of the next source line is reached, if the next
18712source line is not a function call. If it is, stop at the first
18713instruction of the called function.
18714
18715@subsubheading @value{GDBN} Command
18716
18717The corresponding @value{GDBN} command is @samp{step}.
18718
18719@subsubheading Example
18720
18721Stepping into a function:
18722
18723@smallexample
18724-exec-step
18725^running
18726(@value{GDBP})
18727*stopped,reason="end-stepping-range",
18728frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d
DJ
18729@{name="b",value="0"@}],file="recursive2.c",
18730fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@}
922fbb7b
AC
18731(@value{GDBP})
18732@end smallexample
18733
18734Regular stepping:
18735
18736@smallexample
18737-exec-step
18738^running
18739(@value{GDBP})
18740*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
18741(@value{GDBP})
18742@end smallexample
18743
18744
18745@subheading The @code{-exec-step-instruction} Command
18746@findex -exec-step-instruction
18747
18748@subsubheading Synopsis
18749
18750@smallexample
18751 -exec-step-instruction
18752@end smallexample
18753
18754Asynchronous command. Resumes the inferior which executes one machine
18755instruction. The output, once @value{GDBN} has stopped, will vary depending on
18756whether we have stopped in the middle of a source line or not. In the
18757former case, the address at which the program stopped will be printed as
18758well.
18759
18760@subsubheading @value{GDBN} Command
18761
18762The corresponding @value{GDBN} command is @samp{stepi}.
18763
18764@subsubheading Example
18765
18766@smallexample
18767(@value{GDBP})
18768-exec-step-instruction
18769^running
18770
18771(@value{GDBP})
18772*stopped,reason="end-stepping-range",
76ff342d
DJ
18773frame=@{func="foo",args=[],file="try.c",
18774fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18775(@value{GDBP})
18776-exec-step-instruction
18777^running
18778
18779(@value{GDBP})
18780*stopped,reason="end-stepping-range",
76ff342d
DJ
18781frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
18782fullname="/home/foo/bar/devo/myproject/try.c",line="10"@}
922fbb7b
AC
18783(@value{GDBP})
18784@end smallexample
18785
18786
18787@subheading The @code{-exec-until} Command
18788@findex -exec-until
18789
18790@subsubheading Synopsis
18791
18792@smallexample
18793 -exec-until [ @var{location} ]
18794@end smallexample
18795
18796Asynchronous command. Executes the inferior until the @var{location}
18797specified in the argument is reached. If there is no argument, the inferior
18798executes until a source line greater than the current one is reached.
18799The reason for stopping in this case will be @samp{location-reached}.
18800
18801@subsubheading @value{GDBN} Command
18802
18803The corresponding @value{GDBN} command is @samp{until}.
18804
18805@subsubheading Example
18806
18807@smallexample
18808(@value{GDBP})
18809-exec-until recursive2.c:6
18810^running
18811(@value{GDBP})
18812x = 55
18813*stopped,reason="location-reached",frame=@{func="main",args=[],
76ff342d 18814file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="6"@}
922fbb7b
AC
18815(@value{GDBP})
18816@end smallexample
18817
18818@ignore
18819@subheading -file-clear
18820Is this going away????
18821@end ignore
18822
18823
18824@subheading The @code{-file-exec-and-symbols} Command
18825@findex -file-exec-and-symbols
18826
18827@subsubheading Synopsis
18828
18829@smallexample
18830 -file-exec-and-symbols @var{file}
18831@end smallexample
18832
18833Specify the executable file to be debugged. This file is the one from
18834which the symbol table is also read. If no file is specified, the
18835command clears the executable and symbol information. If breakpoints
18836are set when using this command with no arguments, @value{GDBN} will produce
18837error messages. Otherwise, no output is produced, except a completion
18838notification.
18839
18840@subsubheading @value{GDBN} Command
18841
18842The corresponding @value{GDBN} command is @samp{file}.
18843
18844@subsubheading Example
18845
18846@smallexample
18847(@value{GDBP})
18848-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18849^done
18850(@value{GDBP})
18851@end smallexample
18852
18853
18854@subheading The @code{-file-exec-file} Command
18855@findex -file-exec-file
18856
18857@subsubheading Synopsis
18858
18859@smallexample
18860 -file-exec-file @var{file}
18861@end smallexample
18862
18863Specify the executable file to be debugged. Unlike
18864@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
18865from this file. If used without argument, @value{GDBN} clears the information
18866about the executable file. No output is produced, except a completion
18867notification.
18868
18869@subsubheading @value{GDBN} Command
18870
18871The corresponding @value{GDBN} command is @samp{exec-file}.
18872
18873@subsubheading Example
18874
18875@smallexample
18876(@value{GDBP})
18877-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
18878^done
18879(@value{GDBP})
18880@end smallexample
18881
18882
18883@subheading The @code{-file-list-exec-sections} Command
18884@findex -file-list-exec-sections
18885
18886@subsubheading Synopsis
18887
18888@smallexample
18889 -file-list-exec-sections
18890@end smallexample
18891
18892List the sections of the current executable file.
18893
18894@subsubheading @value{GDBN} Command
18895
18896The @value{GDBN} command @samp{info file} shows, among the rest, the same
18897information as this command. @code{gdbtk} has a corresponding command
18898@samp{gdb_load_info}.
18899
18900@subsubheading Example
18901N.A.
18902
18903
1abaf70c
BR
18904@subheading The @code{-file-list-exec-source-file} Command
18905@findex -file-list-exec-source-file
18906
18907@subsubheading Synopsis
18908
18909@smallexample
18910 -file-list-exec-source-file
18911@end smallexample
18912
b383017d 18913List the line number, the current source file, and the absolute path
1abaf70c
BR
18914to the current source file for the current executable.
18915
18916@subsubheading @value{GDBN} Command
18917
18918There's no @value{GDBN} command which directly corresponds to this one.
18919
18920@subsubheading Example
18921
18922@smallexample
18923(@value{GDBP})
18924123-file-list-exec-source-file
18925123^done,line="1",file="foo.c",fullname="/home/bar/foo.c"
18926(@value{GDBP})
18927@end smallexample
18928
18929
922fbb7b
AC
18930@subheading The @code{-file-list-exec-source-files} Command
18931@findex -file-list-exec-source-files
18932
18933@subsubheading Synopsis
18934
18935@smallexample
18936 -file-list-exec-source-files
18937@end smallexample
18938
18939List the source files for the current executable.
18940
57c22c6c
BR
18941It will always output the filename, but only when GDB can find the absolute
18942file name of a source file, will it output the fullname.
18943
922fbb7b
AC
18944@subsubheading @value{GDBN} Command
18945
18946There's no @value{GDBN} command which directly corresponds to this one.
18947@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
18948
18949@subsubheading Example
57c22c6c
BR
18950@smallexample
18951(@value{GDBP})
18952-file-list-exec-source-files
18953^done,files=[
18954@{file=foo.c,fullname=/home/foo.c@},
18955@{file=/home/bar.c,fullname=/home/bar.c@},
18956@{file=gdb_could_not_find_fullpath.c@}]
18957(@value{GDBP})
18958@end smallexample
922fbb7b
AC
18959
18960@subheading The @code{-file-list-shared-libraries} Command
18961@findex -file-list-shared-libraries
18962
18963@subsubheading Synopsis
18964
18965@smallexample
18966 -file-list-shared-libraries
18967@end smallexample
18968
18969List the shared libraries in the program.
18970
18971@subsubheading @value{GDBN} Command
18972
18973The corresponding @value{GDBN} command is @samp{info shared}.
18974
18975@subsubheading Example
18976N.A.
18977
18978
18979@subheading The @code{-file-list-symbol-files} Command
18980@findex -file-list-symbol-files
18981
18982@subsubheading Synopsis
18983
18984@smallexample
18985 -file-list-symbol-files
18986@end smallexample
18987
18988List symbol files.
18989
18990@subsubheading @value{GDBN} Command
18991
18992The corresponding @value{GDBN} command is @samp{info file} (part of it).
18993
18994@subsubheading Example
18995N.A.
18996
18997
18998@subheading The @code{-file-symbol-file} Command
18999@findex -file-symbol-file
19000
19001@subsubheading Synopsis
19002
19003@smallexample
19004 -file-symbol-file @var{file}
19005@end smallexample
19006
19007Read symbol table info from the specified @var{file} argument. When
19008used without arguments, clears @value{GDBN}'s symbol table info. No output is
19009produced, except for a completion notification.
19010
19011@subsubheading @value{GDBN} Command
19012
19013The corresponding @value{GDBN} command is @samp{symbol-file}.
19014
19015@subsubheading Example
19016
19017@smallexample
19018(@value{GDBP})
19019-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
19020^done
19021(@value{GDBP})
19022@end smallexample
19023
19024@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19025@node GDB/MI Miscellaneous Commands
19026@section Miscellaneous @value{GDBN} commands in @sc{gdb/mi}
19027
19028@c @subheading -gdb-complete
19029
19030@subheading The @code{-gdb-exit} Command
19031@findex -gdb-exit
19032
19033@subsubheading Synopsis
19034
19035@smallexample
19036 -gdb-exit
19037@end smallexample
19038
19039Exit @value{GDBN} immediately.
19040
19041@subsubheading @value{GDBN} Command
19042
19043Approximately corresponds to @samp{quit}.
19044
19045@subsubheading Example
19046
19047@smallexample
19048(@value{GDBP})
19049-gdb-exit
19050@end smallexample
19051
19052@subheading The @code{-gdb-set} Command
19053@findex -gdb-set
19054
19055@subsubheading Synopsis
19056
19057@smallexample
19058 -gdb-set
19059@end smallexample
19060
19061Set an internal @value{GDBN} variable.
19062@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
19063
19064@subsubheading @value{GDBN} Command
19065
19066The corresponding @value{GDBN} command is @samp{set}.
19067
19068@subsubheading Example
19069
19070@smallexample
19071(@value{GDBP})
19072-gdb-set $foo=3
19073^done
19074(@value{GDBP})
19075@end smallexample
19076
19077
19078@subheading The @code{-gdb-show} Command
19079@findex -gdb-show
19080
19081@subsubheading Synopsis
19082
19083@smallexample
19084 -gdb-show
19085@end smallexample
19086
19087Show the current value of a @value{GDBN} variable.
19088
19089@subsubheading @value{GDBN} command
19090
19091The corresponding @value{GDBN} command is @samp{show}.
19092
19093@subsubheading Example
19094
19095@smallexample
19096(@value{GDBP})
19097-gdb-show annotate
19098^done,value="0"
19099(@value{GDBP})
19100@end smallexample
19101
19102@c @subheading -gdb-source
19103
19104
19105@subheading The @code{-gdb-version} Command
19106@findex -gdb-version
19107
19108@subsubheading Synopsis
19109
19110@smallexample
19111 -gdb-version
19112@end smallexample
19113
19114Show version information for @value{GDBN}. Used mostly in testing.
19115
19116@subsubheading @value{GDBN} Command
19117
19118There's no equivalent @value{GDBN} command. @value{GDBN} by default shows this
19119information when you start an interactive session.
19120
19121@subsubheading Example
19122
19123@c This example modifies the actual output from GDB to avoid overfull
19124@c box in TeX.
19125@smallexample
19126(@value{GDBP})
19127-gdb-version
19128~GNU gdb 5.2.1
19129~Copyright 2000 Free Software Foundation, Inc.
19130~GDB is free software, covered by the GNU General Public License, and
19131~you are welcome to change it and/or distribute copies of it under
19132~ certain conditions.
19133~Type "show copying" to see the conditions.
19134~There is absolutely no warranty for GDB. Type "show warranty" for
19135~ details.
b383017d 19136~This GDB was configured as
922fbb7b
AC
19137 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
19138^done
19139(@value{GDBP})
19140@end smallexample
19141
19142@subheading The @code{-interpreter-exec} Command
19143@findex -interpreter-exec
19144
19145@subheading Synopsis
19146
19147@smallexample
19148-interpreter-exec @var{interpreter} @var{command}
19149@end smallexample
19150
19151Execute the specified @var{command} in the given @var{interpreter}.
19152
19153@subheading @value{GDBN} Command
19154
19155The corresponding @value{GDBN} command is @samp{interpreter-exec}.
19156
19157@subheading Example
19158
19159@smallexample
19160(@value{GDBP})
19161-interpreter-exec console "break main"
19162&"During symbol reading, couldn't parse type; debugger out of date?.\n"
19163&"During symbol reading, bad structure-type format.\n"
19164~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
19165^done
19166(@value{GDBP})
19167@end smallexample
19168
3cb3b8df
BR
19169@subheading The @code{-inferior-tty-set} Command
19170@findex -inferior-tty-set
19171
19172@subheading Synopsis
19173
19174@smallexample
19175-inferior-tty-set /dev/pts/1
19176@end smallexample
19177
19178Set terminal for future runs of the program being debugged.
19179
19180@subheading @value{GDBN} Command
19181
19182The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
19183
19184@subheading Example
19185
19186@smallexample
19187(@value{GDBP})
19188-inferior-tty-set /dev/pts/1
19189^done
19190(@value{GDBP})
19191@end smallexample
19192
19193@subheading The @code{-inferior-tty-show} Command
19194@findex -inferior-tty-show
19195
19196@subheading Synopsis
19197
19198@smallexample
19199-inferior-tty-show
19200@end smallexample
19201
19202Show terminal for future runs of program being debugged.
19203
19204@subheading @value{GDBN} Command
19205
38f1196a 19206The corresponding @value{GDBN} command is @samp{show inferior-tty}.
3cb3b8df
BR
19207
19208@subheading Example
19209
19210@smallexample
19211(@value{GDBP})
19212-inferior-tty-set /dev/pts/1
19213^done
19214(@value{GDBP})
19215-inferior-tty-show
19216^done,inferior_tty_terminal="/dev/pts/1"
19217(@value{GDBP})
19218@end smallexample
19219
922fbb7b
AC
19220@ignore
19221@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19222@node GDB/MI Kod Commands
19223@section @sc{gdb/mi} Kod Commands
19224
19225The Kod commands are not implemented.
19226
19227@c @subheading -kod-info
19228
19229@c @subheading -kod-list
19230
19231@c @subheading -kod-list-object-types
19232
19233@c @subheading -kod-show
19234
19235@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19236@node GDB/MI Memory Overlay Commands
19237@section @sc{gdb/mi} Memory Overlay Commands
19238
19239The memory overlay commands are not implemented.
19240
19241@c @subheading -overlay-auto
19242
19243@c @subheading -overlay-list-mapping-state
19244
19245@c @subheading -overlay-list-overlays
19246
19247@c @subheading -overlay-map
19248
19249@c @subheading -overlay-off
19250
19251@c @subheading -overlay-on
19252
19253@c @subheading -overlay-unmap
19254
19255@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19256@node GDB/MI Signal Handling Commands
19257@section @sc{gdb/mi} Signal Handling Commands
19258
19259Signal handling commands are not implemented.
19260
19261@c @subheading -signal-handle
19262
19263@c @subheading -signal-list-handle-actions
19264
19265@c @subheading -signal-list-signal-types
19266@end ignore
19267
19268
19269@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19270@node GDB/MI Stack Manipulation
19271@section @sc{gdb/mi} Stack Manipulation Commands
19272
dcaaae04
NR
19273
19274@subheading The @code{-stack-info-frame} Command
19275@findex -stack-info-frame
19276
19277@subsubheading Synopsis
19278
19279@smallexample
19280 -stack-info-frame
19281@end smallexample
19282
19283Get info on the selected frame.
19284
19285@subsubheading @value{GDBN} Command
19286
19287The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19288(without arguments).
19289
19290@subsubheading Example
19291
19292@smallexample
19293(@value{GDBP})
19294-stack-info-frame
19295^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19296file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19297fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19298(@value{GDBP})
19299@end smallexample
19300
922fbb7b
AC
19301@subheading The @code{-stack-info-depth} Command
19302@findex -stack-info-depth
19303
19304@subsubheading Synopsis
19305
19306@smallexample
19307 -stack-info-depth [ @var{max-depth} ]
19308@end smallexample
19309
19310Return the depth of the stack. If the integer argument @var{max-depth}
19311is specified, do not count beyond @var{max-depth} frames.
19312
19313@subsubheading @value{GDBN} Command
19314
19315There's no equivalent @value{GDBN} command.
19316
19317@subsubheading Example
19318
19319For a stack with frame levels 0 through 11:
19320
19321@smallexample
19322(@value{GDBP})
19323-stack-info-depth
19324^done,depth="12"
19325(@value{GDBP})
19326-stack-info-depth 4
19327^done,depth="4"
19328(@value{GDBP})
19329-stack-info-depth 12
19330^done,depth="12"
19331(@value{GDBP})
19332-stack-info-depth 11
19333^done,depth="11"
19334(@value{GDBP})
19335-stack-info-depth 13
19336^done,depth="12"
19337(@value{GDBP})
19338@end smallexample
19339
19340@subheading The @code{-stack-list-arguments} Command
19341@findex -stack-list-arguments
19342
19343@subsubheading Synopsis
19344
19345@smallexample
19346 -stack-list-arguments @var{show-values}
19347 [ @var{low-frame} @var{high-frame} ]
19348@end smallexample
19349
19350Display a list of the arguments for the frames between @var{low-frame}
19351and @var{high-frame} (inclusive). If @var{low-frame} and
19352@var{high-frame} are not provided, list the arguments for the whole call
19353stack.
19354
19355The @var{show-values} argument must have a value of 0 or 1. A value of
193560 means that only the names of the arguments are listed, a value of 1
19357means that both names and values of the arguments are printed.
19358
19359@subsubheading @value{GDBN} Command
19360
19361@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19362@samp{gdb_get_args} command which partially overlaps with the
19363functionality of @samp{-stack-list-arguments}.
19364
19365@subsubheading Example
19366
19367@smallexample
19368(@value{GDBP})
19369-stack-list-frames
19370^done,
19371stack=[
19372frame=@{level="0",addr="0x00010734",func="callee4",
76ff342d
DJ
19373file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19374fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
922fbb7b 19375frame=@{level="1",addr="0x0001076c",func="callee3",
76ff342d
DJ
19376file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19377fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
922fbb7b 19378frame=@{level="2",addr="0x0001078c",func="callee2",
76ff342d
DJ
19379file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19380fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
922fbb7b 19381frame=@{level="3",addr="0x000107b4",func="callee1",
76ff342d
DJ
19382file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19383fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
922fbb7b 19384frame=@{level="4",addr="0x000107e0",func="main",
76ff342d
DJ
19385file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19386fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
922fbb7b
AC
19387(@value{GDBP})
19388-stack-list-arguments 0
19389^done,
19390stack-args=[
19391frame=@{level="0",args=[]@},
19392frame=@{level="1",args=[name="strarg"]@},
19393frame=@{level="2",args=[name="intarg",name="strarg"]@},
19394frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19395frame=@{level="4",args=[]@}]
19396(@value{GDBP})
19397-stack-list-arguments 1
19398^done,
19399stack-args=[
19400frame=@{level="0",args=[]@},
19401frame=@{level="1",
19402 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19403frame=@{level="2",args=[
19404@{name="intarg",value="2"@},
19405@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19406@{frame=@{level="3",args=[
19407@{name="intarg",value="2"@},
19408@{name="strarg",value="0x11940 \"A string argument.\""@},
19409@{name="fltarg",value="3.5"@}]@},
19410frame=@{level="4",args=[]@}]
19411(@value{GDBP})
19412-stack-list-arguments 0 2 2
19413^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19414(@value{GDBP})
19415-stack-list-arguments 1 2 2
19416^done,stack-args=[frame=@{level="2",
19417args=[@{name="intarg",value="2"@},
19418@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19419(@value{GDBP})
19420@end smallexample
19421
19422@c @subheading -stack-list-exception-handlers
19423
19424
19425@subheading The @code{-stack-list-frames} Command
19426@findex -stack-list-frames
19427
19428@subsubheading Synopsis
19429
19430@smallexample
19431 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19432@end smallexample
19433
19434List the frames currently on the stack. For each frame it displays the
19435following info:
19436
19437@table @samp
19438@item @var{level}
19439The frame number, 0 being the topmost frame, i.e. the innermost function.
19440@item @var{addr}
19441The @code{$pc} value for that frame.
19442@item @var{func}
19443Function name.
19444@item @var{file}
19445File name of the source file where the function lives.
19446@item @var{line}
19447Line number corresponding to the @code{$pc}.
19448@end table
19449
19450If invoked without arguments, this command prints a backtrace for the
19451whole stack. If given two integer arguments, it shows the frames whose
19452levels are between the two arguments (inclusive). If the two arguments
19453are equal, it shows the single frame at the corresponding level.
19454
19455@subsubheading @value{GDBN} Command
19456
19457The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19458
19459@subsubheading Example
19460
19461Full stack backtrace:
19462
19463@smallexample
19464(@value{GDBP})
19465-stack-list-frames
19466^done,stack=
19467[frame=@{level="0",addr="0x0001076c",func="foo",
76ff342d 19468 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="11"@},
922fbb7b 19469frame=@{level="1",addr="0x000107a4",func="foo",
76ff342d 19470 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19471frame=@{level="2",addr="0x000107a4",func="foo",
76ff342d 19472 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19473frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19474 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19475frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19476 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19477frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19478 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19479frame=@{level="6",addr="0x000107a4",func="foo",
76ff342d 19480 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19481frame=@{level="7",addr="0x000107a4",func="foo",
76ff342d 19482 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19483frame=@{level="8",addr="0x000107a4",func="foo",
76ff342d 19484 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19485frame=@{level="9",addr="0x000107a4",func="foo",
76ff342d 19486 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19487frame=@{level="10",addr="0x000107a4",func="foo",
76ff342d 19488 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19489frame=@{level="11",addr="0x00010738",func="main",
76ff342d 19490 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="4"@}]
922fbb7b
AC
19491(@value{GDBP})
19492@end smallexample
19493
19494Show frames between @var{low_frame} and @var{high_frame}:
19495
19496@smallexample
19497(@value{GDBP})
19498-stack-list-frames 3 5
19499^done,stack=
19500[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19501 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19502frame=@{level="4",addr="0x000107a4",func="foo",
76ff342d 19503 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@},
922fbb7b 19504frame=@{level="5",addr="0x000107a4",func="foo",
76ff342d 19505 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19506(@value{GDBP})
19507@end smallexample
19508
19509Show a single frame:
19510
19511@smallexample
19512(@value{GDBP})
19513-stack-list-frames 3 3
19514^done,stack=
19515[frame=@{level="3",addr="0x000107a4",func="foo",
76ff342d 19516 file="recursive2.c",fullname="/home/foo/bar/devo/myproject/recursive2.c",line="14"@}]
922fbb7b
AC
19517(@value{GDBP})
19518@end smallexample
19519
19520
19521@subheading The @code{-stack-list-locals} Command
19522@findex -stack-list-locals
19523
19524@subsubheading Synopsis
19525
19526@smallexample
19527 -stack-list-locals @var{print-values}
19528@end smallexample
19529
265eeb58
NR
19530Display the local variable names for the selected frame. If
19531@var{print-values} is 0 or @code{--no-values}, print only the names of
19532the variables; if it is 1 or @code{--all-values}, print also their
19533values; and if it is 2 or @code{--simple-values}, print the name,
19534type and value for simple data types and the name and type for arrays,
19535structures and unions. In this last case, a frontend can immediately
19536display the value of simple data types and create variable objects for
19537other data types when the the user wishes to explore their values in
bc8ced35 19538more detail.
922fbb7b
AC
19539
19540@subsubheading @value{GDBN} Command
19541
19542@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19543
19544@subsubheading Example
19545
19546@smallexample
19547(@value{GDBP})
19548-stack-list-locals 0
19549^done,locals=[name="A",name="B",name="C"]
19550(@value{GDBP})
bc8ced35 19551-stack-list-locals --all-values
922fbb7b 19552^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
bc8ced35
NR
19553 @{name="C",value="@{1, 2, 3@}"@}]
19554-stack-list-locals --simple-values
19555^done,locals=[@{name="A",type="int",value="1"@},
19556 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
922fbb7b
AC
19557(@value{GDBP})
19558@end smallexample
19559
19560
19561@subheading The @code{-stack-select-frame} Command
19562@findex -stack-select-frame
19563
19564@subsubheading Synopsis
19565
19566@smallexample
19567 -stack-select-frame @var{framenum}
19568@end smallexample
19569
265eeb58 19570Change the selected frame. Select a different frame @var{framenum} on
922fbb7b
AC
19571the stack.
19572
19573@subsubheading @value{GDBN} Command
19574
19575The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19576@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19577
19578@subsubheading Example
19579
19580@smallexample
19581(@value{GDBP})
19582-stack-select-frame 2
19583^done
19584(@value{GDBP})
19585@end smallexample
19586
19587@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19588@node GDB/MI Symbol Query
19589@section @sc{gdb/mi} Symbol Query Commands
19590
19591
19592@subheading The @code{-symbol-info-address} Command
19593@findex -symbol-info-address
19594
19595@subsubheading Synopsis
19596
19597@smallexample
19598 -symbol-info-address @var{symbol}
19599@end smallexample
19600
19601Describe where @var{symbol} is stored.
19602
19603@subsubheading @value{GDBN} Command
19604
19605The corresponding @value{GDBN} command is @samp{info address}.
19606
19607@subsubheading Example
19608N.A.
19609
19610
19611@subheading The @code{-symbol-info-file} Command
19612@findex -symbol-info-file
19613
19614@subsubheading Synopsis
19615
19616@smallexample
19617 -symbol-info-file
19618@end smallexample
19619
19620Show the file for the symbol.
19621
19622@subsubheading @value{GDBN} Command
19623
19624There's no equivalent @value{GDBN} command. @code{gdbtk} has
19625@samp{gdb_find_file}.
19626
19627@subsubheading Example
19628N.A.
19629
19630
19631@subheading The @code{-symbol-info-function} Command
19632@findex -symbol-info-function
19633
19634@subsubheading Synopsis
19635
19636@smallexample
19637 -symbol-info-function
19638@end smallexample
19639
19640Show which function the symbol lives in.
19641
19642@subsubheading @value{GDBN} Command
19643
19644@samp{gdb_get_function} in @code{gdbtk}.
19645
19646@subsubheading Example
19647N.A.
19648
19649
19650@subheading The @code{-symbol-info-line} Command
19651@findex -symbol-info-line
19652
19653@subsubheading Synopsis
19654
19655@smallexample
19656 -symbol-info-line
19657@end smallexample
19658
19659Show the core addresses of the code for a source line.
19660
19661@subsubheading @value{GDBN} Command
19662
71952f4c 19663The corresponding @value{GDBN} command is @samp{info line}.
922fbb7b
AC
19664@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
19665
19666@subsubheading Example
19667N.A.
19668
19669
19670@subheading The @code{-symbol-info-symbol} Command
19671@findex -symbol-info-symbol
19672
19673@subsubheading Synopsis
19674
19675@smallexample
19676 -symbol-info-symbol @var{addr}
19677@end smallexample
19678
19679Describe what symbol is at location @var{addr}.
19680
19681@subsubheading @value{GDBN} Command
19682
19683The corresponding @value{GDBN} command is @samp{info symbol}.
19684
19685@subsubheading Example
19686N.A.
19687
19688
19689@subheading The @code{-symbol-list-functions} Command
19690@findex -symbol-list-functions
19691
19692@subsubheading Synopsis
19693
19694@smallexample
19695 -symbol-list-functions
19696@end smallexample
19697
19698List the functions in the executable.
19699
19700@subsubheading @value{GDBN} Command
19701
19702@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
19703@samp{gdb_search} in @code{gdbtk}.
19704
19705@subsubheading Example
19706N.A.
19707
19708
32e7087d
JB
19709@subheading The @code{-symbol-list-lines} Command
19710@findex -symbol-list-lines
19711
19712@subsubheading Synopsis
19713
19714@smallexample
19715 -symbol-list-lines @var{filename}
19716@end smallexample
19717
19718Print the list of lines that contain code and their associated program
19719addresses for the given source filename. The entries are sorted in
19720ascending PC order.
19721
19722@subsubheading @value{GDBN} Command
19723
19724There is no corresponding @value{GDBN} command.
19725
19726@subsubheading Example
19727@smallexample
19728(@value{GDBP})
19729-symbol-list-lines basics.c
54ff5908 19730^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32e7087d
JB
19731(@value{GDBP})
19732@end smallexample
19733
19734
922fbb7b
AC
19735@subheading The @code{-symbol-list-types} Command
19736@findex -symbol-list-types
19737
19738@subsubheading Synopsis
19739
19740@smallexample
19741 -symbol-list-types
19742@end smallexample
19743
19744List all the type names.
19745
19746@subsubheading @value{GDBN} Command
19747
19748The corresponding commands are @samp{info types} in @value{GDBN},
19749@samp{gdb_search} in @code{gdbtk}.
19750
19751@subsubheading Example
19752N.A.
19753
19754
19755@subheading The @code{-symbol-list-variables} Command
19756@findex -symbol-list-variables
19757
19758@subsubheading Synopsis
19759
19760@smallexample
19761 -symbol-list-variables
19762@end smallexample
19763
19764List all the global and static variable names.
19765
19766@subsubheading @value{GDBN} Command
19767
19768@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
19769
19770@subsubheading Example
19771N.A.
19772
19773
19774@subheading The @code{-symbol-locate} Command
19775@findex -symbol-locate
19776
19777@subsubheading Synopsis
19778
19779@smallexample
19780 -symbol-locate
19781@end smallexample
19782
19783@subsubheading @value{GDBN} Command
19784
19785@samp{gdb_loc} in @code{gdbtk}.
19786
19787@subsubheading Example
19788N.A.
19789
19790
19791@subheading The @code{-symbol-type} Command
19792@findex -symbol-type
19793
19794@subsubheading Synopsis
19795
19796@smallexample
19797 -symbol-type @var{variable}
19798@end smallexample
19799
19800Show type of @var{variable}.
19801
19802@subsubheading @value{GDBN} Command
19803
19804The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
19805@samp{gdb_obj_variable}.
19806
19807@subsubheading Example
19808N.A.
19809
19810
19811@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19812@node GDB/MI Target Manipulation
19813@section @sc{gdb/mi} Target Manipulation Commands
19814
19815
19816@subheading The @code{-target-attach} Command
19817@findex -target-attach
19818
19819@subsubheading Synopsis
19820
19821@smallexample
19822 -target-attach @var{pid} | @var{file}
19823@end smallexample
19824
19825Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
19826
19827@subsubheading @value{GDBN} command
19828
19829The corresponding @value{GDBN} command is @samp{attach}.
19830
19831@subsubheading Example
19832N.A.
19833
19834
19835@subheading The @code{-target-compare-sections} Command
19836@findex -target-compare-sections
19837
19838@subsubheading Synopsis
19839
19840@smallexample
19841 -target-compare-sections [ @var{section} ]
19842@end smallexample
19843
19844Compare data of section @var{section} on target to the exec file.
19845Without the argument, all sections are compared.
19846
19847@subsubheading @value{GDBN} Command
19848
19849The @value{GDBN} equivalent is @samp{compare-sections}.
19850
19851@subsubheading Example
19852N.A.
19853
19854
19855@subheading The @code{-target-detach} Command
19856@findex -target-detach
19857
19858@subsubheading Synopsis
19859
19860@smallexample
19861 -target-detach
19862@end smallexample
19863
19864Disconnect from the remote target. There's no output.
19865
19866@subsubheading @value{GDBN} command
19867
19868The corresponding @value{GDBN} command is @samp{detach}.
19869
19870@subsubheading Example
19871
19872@smallexample
19873(@value{GDBP})
19874-target-detach
19875^done
19876(@value{GDBP})
19877@end smallexample
19878
19879
07f31aa6
DJ
19880@subheading The @code{-target-disconnect} Command
19881@findex -target-disconnect
19882
19883@subsubheading Synopsis
19884
19885@example
19886 -target-disconnect
19887@end example
19888
19889Disconnect from the remote target. There's no output.
19890
19891@subsubheading @value{GDBN} command
19892
19893The corresponding @value{GDBN} command is @samp{disconnect}.
19894
19895@subsubheading Example
19896
19897@smallexample
19898(@value{GDBP})
19899-target-disconnect
19900^done
19901(@value{GDBP})
19902@end smallexample
19903
19904
922fbb7b
AC
19905@subheading The @code{-target-download} Command
19906@findex -target-download
19907
19908@subsubheading Synopsis
19909
19910@smallexample
19911 -target-download
19912@end smallexample
19913
19914Loads the executable onto the remote target.
19915It prints out an update message every half second, which includes the fields:
19916
19917@table @samp
19918@item section
19919The name of the section.
19920@item section-sent
19921The size of what has been sent so far for that section.
19922@item section-size
19923The size of the section.
19924@item total-sent
19925The total size of what was sent so far (the current and the previous sections).
19926@item total-size
19927The size of the overall executable to download.
19928@end table
19929
19930@noindent
19931Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
19932@sc{gdb/mi} Output Syntax}).
19933
19934In addition, it prints the name and size of the sections, as they are
19935downloaded. These messages include the following fields:
19936
19937@table @samp
19938@item section
19939The name of the section.
19940@item section-size
19941The size of the section.
19942@item total-size
19943The size of the overall executable to download.
19944@end table
19945
19946@noindent
19947At the end, a summary is printed.
19948
19949@subsubheading @value{GDBN} Command
19950
19951The corresponding @value{GDBN} command is @samp{load}.
19952
19953@subsubheading Example
19954
19955Note: each status message appears on a single line. Here the messages
19956have been broken down so that they can fit onto a page.
19957
19958@smallexample
19959(@value{GDBP})
19960-target-download
19961+download,@{section=".text",section-size="6668",total-size="9880"@}
19962+download,@{section=".text",section-sent="512",section-size="6668",
19963total-sent="512",total-size="9880"@}
19964+download,@{section=".text",section-sent="1024",section-size="6668",
19965total-sent="1024",total-size="9880"@}
19966+download,@{section=".text",section-sent="1536",section-size="6668",
19967total-sent="1536",total-size="9880"@}
19968+download,@{section=".text",section-sent="2048",section-size="6668",
19969total-sent="2048",total-size="9880"@}
19970+download,@{section=".text",section-sent="2560",section-size="6668",
19971total-sent="2560",total-size="9880"@}
19972+download,@{section=".text",section-sent="3072",section-size="6668",
19973total-sent="3072",total-size="9880"@}
19974+download,@{section=".text",section-sent="3584",section-size="6668",
19975total-sent="3584",total-size="9880"@}
19976+download,@{section=".text",section-sent="4096",section-size="6668",
19977total-sent="4096",total-size="9880"@}
19978+download,@{section=".text",section-sent="4608",section-size="6668",
19979total-sent="4608",total-size="9880"@}
19980+download,@{section=".text",section-sent="5120",section-size="6668",
19981total-sent="5120",total-size="9880"@}
19982+download,@{section=".text",section-sent="5632",section-size="6668",
19983total-sent="5632",total-size="9880"@}
19984+download,@{section=".text",section-sent="6144",section-size="6668",
19985total-sent="6144",total-size="9880"@}
19986+download,@{section=".text",section-sent="6656",section-size="6668",
19987total-sent="6656",total-size="9880"@}
19988+download,@{section=".init",section-size="28",total-size="9880"@}
19989+download,@{section=".fini",section-size="28",total-size="9880"@}
19990+download,@{section=".data",section-size="3156",total-size="9880"@}
19991+download,@{section=".data",section-sent="512",section-size="3156",
19992total-sent="7236",total-size="9880"@}
19993+download,@{section=".data",section-sent="1024",section-size="3156",
19994total-sent="7748",total-size="9880"@}
19995+download,@{section=".data",section-sent="1536",section-size="3156",
19996total-sent="8260",total-size="9880"@}
19997+download,@{section=".data",section-sent="2048",section-size="3156",
19998total-sent="8772",total-size="9880"@}
19999+download,@{section=".data",section-sent="2560",section-size="3156",
20000total-sent="9284",total-size="9880"@}
20001+download,@{section=".data",section-sent="3072",section-size="3156",
20002total-sent="9796",total-size="9880"@}
20003^done,address="0x10004",load-size="9880",transfer-rate="6586",
20004write-rate="429"
20005(@value{GDBP})
20006@end smallexample
20007
20008
20009@subheading The @code{-target-exec-status} Command
20010@findex -target-exec-status
20011
20012@subsubheading Synopsis
20013
20014@smallexample
20015 -target-exec-status
20016@end smallexample
20017
20018Provide information on the state of the target (whether it is running or
20019not, for instance).
20020
20021@subsubheading @value{GDBN} Command
20022
20023There's no equivalent @value{GDBN} command.
20024
20025@subsubheading Example
20026N.A.
20027
20028
20029@subheading The @code{-target-list-available-targets} Command
20030@findex -target-list-available-targets
20031
20032@subsubheading Synopsis
20033
20034@smallexample
20035 -target-list-available-targets
20036@end smallexample
20037
20038List the possible targets to connect to.
20039
20040@subsubheading @value{GDBN} Command
20041
20042The corresponding @value{GDBN} command is @samp{help target}.
20043
20044@subsubheading Example
20045N.A.
20046
20047
20048@subheading The @code{-target-list-current-targets} Command
20049@findex -target-list-current-targets
20050
20051@subsubheading Synopsis
20052
20053@smallexample
20054 -target-list-current-targets
20055@end smallexample
20056
20057Describe the current target.
20058
20059@subsubheading @value{GDBN} Command
20060
20061The corresponding information is printed by @samp{info file} (among
20062other things).
20063
20064@subsubheading Example
20065N.A.
20066
20067
20068@subheading The @code{-target-list-parameters} Command
20069@findex -target-list-parameters
20070
20071@subsubheading Synopsis
20072
20073@smallexample
20074 -target-list-parameters
20075@end smallexample
20076
20077@c ????
20078
20079@subsubheading @value{GDBN} Command
20080
20081No equivalent.
20082
20083@subsubheading Example
20084N.A.
20085
20086
20087@subheading The @code{-target-select} Command
20088@findex -target-select
20089
20090@subsubheading Synopsis
20091
20092@smallexample
20093 -target-select @var{type} @var{parameters @dots{}}
20094@end smallexample
20095
20096Connect @value{GDBN} to the remote target. This command takes two args:
20097
20098@table @samp
20099@item @var{type}
20100The type of target, for instance @samp{async}, @samp{remote}, etc.
20101@item @var{parameters}
20102Device names, host names and the like. @xref{Target Commands, ,
20103Commands for managing targets}, for more details.
20104@end table
20105
20106The output is a connection notification, followed by the address at
20107which the target program is, in the following form:
20108
20109@smallexample
20110^connected,addr="@var{address}",func="@var{function name}",
20111 args=[@var{arg list}]
20112@end smallexample
20113
20114@subsubheading @value{GDBN} Command
20115
20116The corresponding @value{GDBN} command is @samp{target}.
20117
20118@subsubheading Example
20119
20120@smallexample
20121(@value{GDBP})
20122-target-select async /dev/ttya
20123^connected,addr="0xfe00a300",func="??",args=[]
20124(@value{GDBP})
20125@end smallexample
20126
20127@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20128@node GDB/MI Thread Commands
20129@section @sc{gdb/mi} Thread Commands
20130
20131
20132@subheading The @code{-thread-info} Command
20133@findex -thread-info
20134
20135@subsubheading Synopsis
20136
20137@smallexample
20138 -thread-info
20139@end smallexample
20140
20141@subsubheading @value{GDBN} command
20142
20143No equivalent.
20144
20145@subsubheading Example
20146N.A.
20147
20148
20149@subheading The @code{-thread-list-all-threads} Command
20150@findex -thread-list-all-threads
20151
20152@subsubheading Synopsis
20153
20154@smallexample
20155 -thread-list-all-threads
20156@end smallexample
20157
20158@subsubheading @value{GDBN} Command
20159
20160The equivalent @value{GDBN} command is @samp{info threads}.
20161
20162@subsubheading Example
20163N.A.
20164
20165
20166@subheading The @code{-thread-list-ids} Command
20167@findex -thread-list-ids
20168
20169@subsubheading Synopsis
20170
20171@smallexample
20172 -thread-list-ids
20173@end smallexample
20174
20175Produces a list of the currently known @value{GDBN} thread ids. At the
20176end of the list it also prints the total number of such threads.
20177
20178@subsubheading @value{GDBN} Command
20179
20180Part of @samp{info threads} supplies the same information.
20181
20182@subsubheading Example
20183
20184No threads present, besides the main process:
20185
20186@smallexample
20187(@value{GDBP})
20188-thread-list-ids
20189^done,thread-ids=@{@},number-of-threads="0"
20190(@value{GDBP})
20191@end smallexample
20192
20193
20194Several threads:
20195
20196@smallexample
20197(@value{GDBP})
20198-thread-list-ids
20199^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20200number-of-threads="3"
20201(@value{GDBP})
20202@end smallexample
20203
20204
20205@subheading The @code{-thread-select} Command
20206@findex -thread-select
20207
20208@subsubheading Synopsis
20209
20210@smallexample
20211 -thread-select @var{threadnum}
20212@end smallexample
20213
20214Make @var{threadnum} the current thread. It prints the number of the new
20215current thread, and the topmost frame for that thread.
20216
20217@subsubheading @value{GDBN} Command
20218
20219The corresponding @value{GDBN} command is @samp{thread}.
20220
20221@subsubheading Example
20222
20223@smallexample
20224(@value{GDBP})
20225-exec-next
20226^running
20227(@value{GDBP})
20228*stopped,reason="end-stepping-range",thread-id="2",line="187",
20229file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
20230(@value{GDBP})
20231-thread-list-ids
20232^done,
20233thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
20234number-of-threads="3"
20235(@value{GDBP})
20236-thread-select 3
20237^done,new-thread-id="3",
20238frame=@{level="0",func="vprintf",
20239args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
20240@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
20241(@value{GDBP})
20242@end smallexample
20243
20244@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20245@node GDB/MI Tracepoint Commands
20246@section @sc{gdb/mi} Tracepoint Commands
20247
20248The tracepoint commands are not yet implemented.
20249
20250@c @subheading -trace-actions
20251
20252@c @subheading -trace-delete
20253
20254@c @subheading -trace-disable
20255
20256@c @subheading -trace-dump
20257
20258@c @subheading -trace-enable
20259
20260@c @subheading -trace-exists
20261
20262@c @subheading -trace-find
20263
20264@c @subheading -trace-frame-number
20265
20266@c @subheading -trace-info
20267
20268@c @subheading -trace-insert
20269
20270@c @subheading -trace-list
20271
20272@c @subheading -trace-pass-count
20273
20274@c @subheading -trace-save
20275
20276@c @subheading -trace-start
20277
20278@c @subheading -trace-stop
20279
20280
20281@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20282@node GDB/MI Variable Objects
20283@section @sc{gdb/mi} Variable Objects
20284
20285
20286@subheading Motivation for Variable Objects in @sc{gdb/mi}
20287
20288For the implementation of a variable debugger window (locals, watched
20289expressions, etc.), we are proposing the adaptation of the existing code
20290used by @code{Insight}.
20291
20292The two main reasons for that are:
20293
20294@enumerate 1
20295@item
20296It has been proven in practice (it is already on its second generation).
20297
20298@item
20299It will shorten development time (needless to say how important it is
20300now).
20301@end enumerate
20302
20303The original interface was designed to be used by Tcl code, so it was
20304slightly changed so it could be used through @sc{gdb/mi}. This section
20305describes the @sc{gdb/mi} operations that will be available and gives some
20306hints about their use.
20307
20308@emph{Note}: In addition to the set of operations described here, we
20309expect the @sc{gui} implementation of a variable window to require, at
20310least, the following operations:
20311
20312@itemize @bullet
20313@item @code{-gdb-show} @code{output-radix}
20314@item @code{-stack-list-arguments}
20315@item @code{-stack-list-locals}
20316@item @code{-stack-select-frame}
20317@end itemize
20318
20319@subheading Introduction to Variable Objects in @sc{gdb/mi}
20320
20321@cindex variable objects in @sc{gdb/mi}
20322The basic idea behind variable objects is the creation of a named object
20323to represent a variable, an expression, a memory location or even a CPU
20324register. For each object created, a set of operations is available for
20325examining or changing its properties.
20326
20327Furthermore, complex data types, such as C structures, are represented
20328in a tree format. For instance, the @code{struct} type variable is the
20329root and the children will represent the struct members. If a child
20330is itself of a complex type, it will also have children of its own.
20331Appropriate language differences are handled for C, C@t{++} and Java.
20332
20333When returning the actual values of the objects, this facility allows
20334for the individual selection of the display format used in the result
20335creation. It can be chosen among: binary, decimal, hexadecimal, octal
20336and natural. Natural refers to a default format automatically
20337chosen based on the variable type (like decimal for an @code{int}, hex
20338for pointers, etc.).
20339
20340The following is the complete set of @sc{gdb/mi} operations defined to
20341access this functionality:
20342
20343@multitable @columnfractions .4 .6
20344@item @strong{Operation}
20345@tab @strong{Description}
20346
20347@item @code{-var-create}
20348@tab create a variable object
20349@item @code{-var-delete}
20350@tab delete the variable object and its children
20351@item @code{-var-set-format}
20352@tab set the display format of this variable
20353@item @code{-var-show-format}
20354@tab show the display format of this variable
20355@item @code{-var-info-num-children}
20356@tab tells how many children this object has
20357@item @code{-var-list-children}
20358@tab return a list of the object's children
20359@item @code{-var-info-type}
20360@tab show the type of this variable object
20361@item @code{-var-info-expression}
20362@tab print what this variable object represents
20363@item @code{-var-show-attributes}
20364@tab is this variable editable? does it exist here?
20365@item @code{-var-evaluate-expression}
20366@tab get the value of this variable
20367@item @code{-var-assign}
20368@tab set the value of this variable
20369@item @code{-var-update}
20370@tab update the variable and its children
20371@end multitable
20372
20373In the next subsection we describe each operation in detail and suggest
20374how it can be used.
20375
20376@subheading Description And Use of Operations on Variable Objects
20377
20378@subheading The @code{-var-create} Command
20379@findex -var-create
20380
20381@subsubheading Synopsis
20382
20383@smallexample
20384 -var-create @{@var{name} | "-"@}
20385 @{@var{frame-addr} | "*"@} @var{expression}
20386@end smallexample
20387
20388This operation creates a variable object, which allows the monitoring of
20389a variable, the result of an expression, a memory cell or a CPU
20390register.
20391
20392The @var{name} parameter is the string by which the object can be
20393referenced. It must be unique. If @samp{-} is specified, the varobj
20394system will generate a string ``varNNNNNN'' automatically. It will be
20395unique provided that one does not specify @var{name} on that format.
20396The command fails if a duplicate name is found.
20397
20398The frame under which the expression should be evaluated can be
20399specified by @var{frame-addr}. A @samp{*} indicates that the current
20400frame should be used.
20401
20402@var{expression} is any expression valid on the current language set (must not
20403begin with a @samp{*}), or one of the following:
20404
20405@itemize @bullet
20406@item
20407@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
20408
20409@item
20410@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
20411
20412@item
20413@samp{$@var{regname}} --- a CPU register name
20414@end itemize
20415
20416@subsubheading Result
20417
20418This operation returns the name, number of children and the type of the
20419object created. Type is returned as a string as the ones generated by
20420the @value{GDBN} CLI:
20421
20422@smallexample
20423 name="@var{name}",numchild="N",type="@var{type}"
20424@end smallexample
20425
20426
20427@subheading The @code{-var-delete} Command
20428@findex -var-delete
20429
20430@subsubheading Synopsis
20431
20432@smallexample
20433 -var-delete @var{name}
20434@end smallexample
20435
20436Deletes a previously created variable object and all of its children.
20437
20438Returns an error if the object @var{name} is not found.
20439
20440
20441@subheading The @code{-var-set-format} Command
20442@findex -var-set-format
20443
20444@subsubheading Synopsis
20445
20446@smallexample
20447 -var-set-format @var{name} @var{format-spec}
20448@end smallexample
20449
20450Sets the output format for the value of the object @var{name} to be
20451@var{format-spec}.
20452
20453The syntax for the @var{format-spec} is as follows:
20454
20455@smallexample
20456 @var{format-spec} @expansion{}
20457 @{binary | decimal | hexadecimal | octal | natural@}
20458@end smallexample
20459
20460
20461@subheading The @code{-var-show-format} Command
20462@findex -var-show-format
20463
20464@subsubheading Synopsis
20465
20466@smallexample
20467 -var-show-format @var{name}
20468@end smallexample
20469
20470Returns the format used to display the value of the object @var{name}.
20471
20472@smallexample
20473 @var{format} @expansion{}
20474 @var{format-spec}
20475@end smallexample
20476
20477
20478@subheading The @code{-var-info-num-children} Command
20479@findex -var-info-num-children
20480
20481@subsubheading Synopsis
20482
20483@smallexample
20484 -var-info-num-children @var{name}
20485@end smallexample
20486
20487Returns the number of children of a variable object @var{name}:
20488
20489@smallexample
20490 numchild=@var{n}
20491@end smallexample
20492
20493
20494@subheading The @code{-var-list-children} Command
20495@findex -var-list-children
20496
20497@subsubheading Synopsis
20498
20499@smallexample
bc8ced35 20500 -var-list-children [@var{print-values}] @var{name}
922fbb7b 20501@end smallexample
265eeb58 20502@anchor{-var-list-children}
922fbb7b 20503
265eeb58
NR
20504Return a list of the children of the specified variable object and
20505create variable objects for them, if they do not already exist. With
20506a single argument or if @var{print-values} has a value for of 0 or
20507@code{--no-values}, print only the names of the variables; if
20508@var{print-values} is 1 or @code{--all-values}, also print their
20509values; and if it is 2 or @code{--simple-values} print the name and
20510value for simple data types and just the name for arrays, structures
20511and unions.
bc8ced35
NR
20512
20513@subsubheading Example
922fbb7b
AC
20514
20515@smallexample
bc8ced35
NR
20516(@value{GDBP})
20517 -var-list-children n
265eeb58 20518 ^done,numchild=@var{n},children=[@{name=@var{name},
922fbb7b 20519 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
bc8ced35
NR
20520(@value{GDBP})
20521 -var-list-children --all-values n
265eeb58 20522 ^done,numchild=@var{n},children=[@{name=@var{name},
bc8ced35 20523 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
20524@end smallexample
20525
20526
20527@subheading The @code{-var-info-type} Command
20528@findex -var-info-type
20529
20530@subsubheading Synopsis
20531
20532@smallexample
20533 -var-info-type @var{name}
20534@end smallexample
20535
20536Returns the type of the specified variable @var{name}. The type is
20537returned as a string in the same format as it is output by the
20538@value{GDBN} CLI:
20539
20540@smallexample
20541 type=@var{typename}
20542@end smallexample
20543
20544
20545@subheading The @code{-var-info-expression} Command
20546@findex -var-info-expression
20547
20548@subsubheading Synopsis
20549
20550@smallexample
20551 -var-info-expression @var{name}
20552@end smallexample
20553
20554Returns what is represented by the variable object @var{name}:
20555
20556@smallexample
20557 lang=@var{lang-spec},exp=@var{expression}
20558@end smallexample
20559
20560@noindent
20561where @var{lang-spec} is @code{@{"C" | "C++" | "Java"@}}.
20562
20563@subheading The @code{-var-show-attributes} Command
20564@findex -var-show-attributes
20565
20566@subsubheading Synopsis
20567
20568@smallexample
20569 -var-show-attributes @var{name}
20570@end smallexample
20571
20572List attributes of the specified variable object @var{name}:
20573
20574@smallexample
20575 status=@var{attr} [ ( ,@var{attr} )* ]
20576@end smallexample
20577
20578@noindent
20579where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20580
20581@subheading The @code{-var-evaluate-expression} Command
20582@findex -var-evaluate-expression
20583
20584@subsubheading Synopsis
20585
20586@smallexample
20587 -var-evaluate-expression @var{name}
20588@end smallexample
20589
20590Evaluates the expression that is represented by the specified variable
20591object and returns its value as a string in the current format specified
20592for the object:
20593
20594@smallexample
20595 value=@var{value}
20596@end smallexample
20597
20598Note that one must invoke @code{-var-list-children} for a variable
20599before the value of a child variable can be evaluated.
20600
20601@subheading The @code{-var-assign} Command
20602@findex -var-assign
20603
20604@subsubheading Synopsis
20605
20606@smallexample
20607 -var-assign @var{name} @var{expression}
20608@end smallexample
20609
20610Assigns the value of @var{expression} to the variable object specified
20611by @var{name}. The object must be @samp{editable}. If the variable's
b383017d 20612value is altered by the assign, the variable will show up in any
922fbb7b
AC
20613subsequent @code{-var-update} list.
20614
20615@subsubheading Example
20616
20617@smallexample
20618(@value{GDBP})
20619-var-assign var1 3
20620^done,value="3"
20621(@value{GDBP})
20622-var-update *
20623^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20624(@value{GDBP})
20625@end smallexample
20626
20627@subheading The @code{-var-update} Command
20628@findex -var-update
20629
20630@subsubheading Synopsis
20631
20632@smallexample
265eeb58 20633 -var-update [@var{print-values}] @{@var{name} | "*"@}
922fbb7b
AC
20634@end smallexample
20635
20636Update the value of the variable object @var{name} by evaluating its
20637expression after fetching all the new values from memory or registers.
265eeb58 20638A @samp{*} causes all existing variable objects to be updated. The
656d5e12
EZ
20639option @var{print-values} determines whether names both and values, or
20640just names are printed in the manner described for
20641@code{-var-list-children} (@pxref{-var-list-children}).
265eeb58
NR
20642
20643@subsubheading Example
922fbb7b 20644
265eeb58
NR
20645@smallexample
20646(@value{GDBP})
20647-var-assign var1 3
20648^done,value="3"
20649(@value{GDBP})
20650-var-update --all-values var1
20651^done,changelist=[@{name="var1",value="3",in_scope="true",
20652type_changed="false"@}]
20653(@value{GDBP})
20654@end smallexample
922fbb7b
AC
20655
20656@node Annotations
20657@chapter @value{GDBN} Annotations
20658
086432e2
AC
20659This chapter describes annotations in @value{GDBN}. Annotations were
20660designed to interface @value{GDBN} to graphical user interfaces or other
20661similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
20662relatively high level.
20663
086432e2
AC
20664The annotation mechanism has largely been superseeded by @sc{gdb/mi}
20665(@pxref{GDB/MI}).
20666
922fbb7b
AC
20667@ignore
20668This is Edition @value{EDITION}, @value{DATE}.
20669@end ignore
20670
20671@menu
20672* Annotations Overview:: What annotations are; the general syntax.
922fbb7b
AC
20673* Prompting:: Annotations marking @value{GDBN}'s need for input.
20674* Errors:: Annotations for error messages.
922fbb7b
AC
20675* Invalidation:: Some annotations describe things now invalid.
20676* Annotations for Running::
20677 Whether the program is running, how it stopped, etc.
20678* Source Annotations:: Annotations describing source code.
922fbb7b
AC
20679@end menu
20680
20681@node Annotations Overview
20682@section What is an Annotation?
20683@cindex annotations
20684
922fbb7b
AC
20685Annotations start with a newline character, two @samp{control-z}
20686characters, and the name of the annotation. If there is no additional
20687information associated with this annotation, the name of the annotation
20688is followed immediately by a newline. If there is additional
20689information, the name of the annotation is followed by a space, the
20690additional information, and a newline. The additional information
20691cannot contain newline characters.
20692
20693Any output not beginning with a newline and two @samp{control-z}
20694characters denotes literal output from @value{GDBN}. Currently there is
20695no need for @value{GDBN} to output a newline followed by two
20696@samp{control-z} characters, but if there was such a need, the
20697annotations could be extended with an @samp{escape} annotation which
20698means those three characters as output.
20699
086432e2
AC
20700The annotation @var{level}, which is specified using the
20701@option{--annotate} command line option (@pxref{Mode Options}), controls
20702how much information @value{GDBN} prints together with its prompt,
20703values of expressions, source lines, and other types of output. Level 0
20704is for no anntations, level 1 is for use when @value{GDBN} is run as a
20705subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
20706for programs that control @value{GDBN}, and level 2 annotations have
20707been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
20708Interface, annotate, GDB's Obsolete Annotations}).
20709
20710@table @code
20711@kindex set annotate
20712@item set annotate @var{level}
e09f16f9 20713The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 20714annotations to the specified @var{level}.
9c16f35a
EZ
20715
20716@item show annotate
20717@kindex show annotate
20718Show the current annotation level.
09d4efe1
EZ
20719@end table
20720
20721This chapter describes level 3 annotations.
086432e2 20722
922fbb7b
AC
20723A simple example of starting up @value{GDBN} with annotations is:
20724
20725@smallexample
086432e2
AC
20726$ @kbd{gdb --annotate=3}
20727GNU gdb 6.0
20728Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
20729GDB is free software, covered by the GNU General Public License,
20730and you are welcome to change it and/or distribute copies of it
20731under certain conditions.
20732Type "show copying" to see the conditions.
20733There is absolutely no warranty for GDB. Type "show warranty"
20734for details.
086432e2 20735This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
20736
20737^Z^Zpre-prompt
f7dc1244 20738(@value{GDBP})
922fbb7b 20739^Z^Zprompt
086432e2 20740@kbd{quit}
922fbb7b
AC
20741
20742^Z^Zpost-prompt
b383017d 20743$
922fbb7b
AC
20744@end smallexample
20745
20746Here @samp{quit} is input to @value{GDBN}; the rest is output from
20747@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
20748denotes a @samp{control-z} character) are annotations; the rest is
20749output from @value{GDBN}.
20750
922fbb7b
AC
20751@node Prompting
20752@section Annotation for @value{GDBN} Input
20753
20754@cindex annotations for prompts
20755When @value{GDBN} prompts for input, it annotates this fact so it is possible
20756to know when to send output, when the output from a given command is
20757over, etc.
20758
20759Different kinds of input each have a different @dfn{input type}. Each
20760input type has three annotations: a @code{pre-} annotation, which
20761denotes the beginning of any prompt which is being output, a plain
20762annotation, which denotes the end of the prompt, and then a @code{post-}
20763annotation which denotes the end of any echo which may (or may not) be
20764associated with the input. For example, the @code{prompt} input type
20765features the following annotations:
20766
20767@smallexample
20768^Z^Zpre-prompt
20769^Z^Zprompt
20770^Z^Zpost-prompt
20771@end smallexample
20772
20773The input types are
20774
20775@table @code
20776@findex pre-prompt
20777@findex prompt
20778@findex post-prompt
20779@item prompt
20780When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
20781
20782@findex pre-commands
20783@findex commands
20784@findex post-commands
20785@item commands
20786When @value{GDBN} prompts for a set of commands, like in the @code{commands}
20787command. The annotations are repeated for each command which is input.
20788
20789@findex pre-overload-choice
20790@findex overload-choice
20791@findex post-overload-choice
20792@item overload-choice
20793When @value{GDBN} wants the user to select between various overloaded functions.
20794
20795@findex pre-query
20796@findex query
20797@findex post-query
20798@item query
20799When @value{GDBN} wants the user to confirm a potentially dangerous operation.
20800
20801@findex pre-prompt-for-continue
20802@findex prompt-for-continue
20803@findex post-prompt-for-continue
20804@item prompt-for-continue
20805When @value{GDBN} is asking the user to press return to continue. Note: Don't
20806expect this to work well; instead use @code{set height 0} to disable
20807prompting. This is because the counting of lines is buggy in the
20808presence of annotations.
20809@end table
20810
20811@node Errors
20812@section Errors
20813@cindex annotations for errors, warnings and interrupts
20814
20815@findex quit
20816@smallexample
20817^Z^Zquit
20818@end smallexample
20819
20820This annotation occurs right before @value{GDBN} responds to an interrupt.
20821
20822@findex error
20823@smallexample
20824^Z^Zerror
20825@end smallexample
20826
20827This annotation occurs right before @value{GDBN} responds to an error.
20828
20829Quit and error annotations indicate that any annotations which @value{GDBN} was
20830in the middle of may end abruptly. For example, if a
20831@code{value-history-begin} annotation is followed by a @code{error}, one
20832cannot expect to receive the matching @code{value-history-end}. One
20833cannot expect not to receive it either, however; an error annotation
20834does not necessarily mean that @value{GDBN} is immediately returning all the way
20835to the top level.
20836
20837@findex error-begin
20838A quit or error annotation may be preceded by
20839
20840@smallexample
20841^Z^Zerror-begin
20842@end smallexample
20843
20844Any output between that and the quit or error annotation is the error
20845message.
20846
20847Warning messages are not yet annotated.
20848@c If we want to change that, need to fix warning(), type_error(),
20849@c range_error(), and possibly other places.
20850
922fbb7b
AC
20851@node Invalidation
20852@section Invalidation Notices
20853
20854@cindex annotations for invalidation messages
20855The following annotations say that certain pieces of state may have
20856changed.
20857
20858@table @code
20859@findex frames-invalid
20860@item ^Z^Zframes-invalid
20861
20862The frames (for example, output from the @code{backtrace} command) may
20863have changed.
20864
20865@findex breakpoints-invalid
20866@item ^Z^Zbreakpoints-invalid
20867
20868The breakpoints may have changed. For example, the user just added or
20869deleted a breakpoint.
20870@end table
20871
20872@node Annotations for Running
20873@section Running the Program
20874@cindex annotations for running programs
20875
20876@findex starting
20877@findex stopping
20878When the program starts executing due to a @value{GDBN} command such as
b383017d 20879@code{step} or @code{continue},
922fbb7b
AC
20880
20881@smallexample
20882^Z^Zstarting
20883@end smallexample
20884
b383017d 20885is output. When the program stops,
922fbb7b
AC
20886
20887@smallexample
20888^Z^Zstopped
20889@end smallexample
20890
20891is output. Before the @code{stopped} annotation, a variety of
20892annotations describe how the program stopped.
20893
20894@table @code
20895@findex exited
20896@item ^Z^Zexited @var{exit-status}
20897The program exited, and @var{exit-status} is the exit status (zero for
20898successful exit, otherwise nonzero).
20899
20900@findex signalled
20901@findex signal-name
20902@findex signal-name-end
20903@findex signal-string
20904@findex signal-string-end
20905@item ^Z^Zsignalled
20906The program exited with a signal. After the @code{^Z^Zsignalled}, the
20907annotation continues:
20908
20909@smallexample
20910@var{intro-text}
20911^Z^Zsignal-name
20912@var{name}
20913^Z^Zsignal-name-end
20914@var{middle-text}
20915^Z^Zsignal-string
20916@var{string}
20917^Z^Zsignal-string-end
20918@var{end-text}
20919@end smallexample
20920
20921@noindent
20922where @var{name} is the name of the signal, such as @code{SIGILL} or
20923@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
20924as @code{Illegal Instruction} or @code{Segmentation fault}.
20925@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
20926user's benefit and have no particular format.
20927
20928@findex signal
20929@item ^Z^Zsignal
20930The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
20931just saying that the program received the signal, not that it was
20932terminated with it.
20933
20934@findex breakpoint
20935@item ^Z^Zbreakpoint @var{number}
20936The program hit breakpoint number @var{number}.
20937
20938@findex watchpoint
20939@item ^Z^Zwatchpoint @var{number}
20940The program hit watchpoint number @var{number}.
20941@end table
20942
20943@node Source Annotations
20944@section Displaying Source
20945@cindex annotations for source display
20946
20947@findex source
20948The following annotation is used instead of displaying source code:
20949
20950@smallexample
20951^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
20952@end smallexample
20953
20954where @var{filename} is an absolute file name indicating which source
20955file, @var{line} is the line number within that file (where 1 is the
20956first line in the file), @var{character} is the character position
20957within the file (where 0 is the first character in the file) (for most
20958debug formats this will necessarily point to the beginning of a line),
20959@var{middle} is @samp{middle} if @var{addr} is in the middle of the
20960line, or @samp{beg} if @var{addr} is at the beginning of the line, and
20961@var{addr} is the address in the target program associated with the
20962source which is being displayed. @var{addr} is in the form @samp{0x}
20963followed by one or more lowercase hex digits (note that this does not
20964depend on the language).
20965
8e04817f
AC
20966@node GDB Bugs
20967@chapter Reporting Bugs in @value{GDBN}
20968@cindex bugs in @value{GDBN}
20969@cindex reporting bugs in @value{GDBN}
c906108c 20970
8e04817f 20971Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 20972
8e04817f
AC
20973Reporting a bug may help you by bringing a solution to your problem, or it
20974may not. But in any case the principal function of a bug report is to help
20975the entire community by making the next version of @value{GDBN} work better. Bug
20976reports are your contribution to the maintenance of @value{GDBN}.
c906108c 20977
8e04817f
AC
20978In order for a bug report to serve its purpose, you must include the
20979information that enables us to fix the bug.
c4555f82
SC
20980
20981@menu
8e04817f
AC
20982* Bug Criteria:: Have you found a bug?
20983* Bug Reporting:: How to report bugs
c4555f82
SC
20984@end menu
20985
8e04817f
AC
20986@node Bug Criteria
20987@section Have you found a bug?
20988@cindex bug criteria
c4555f82 20989
8e04817f 20990If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
20991
20992@itemize @bullet
8e04817f
AC
20993@cindex fatal signal
20994@cindex debugger crash
20995@cindex crash of debugger
c4555f82 20996@item
8e04817f
AC
20997If the debugger gets a fatal signal, for any input whatever, that is a
20998@value{GDBN} bug. Reliable debuggers never crash.
20999
21000@cindex error on valid input
21001@item
21002If @value{GDBN} produces an error message for valid input, that is a
21003bug. (Note that if you're cross debugging, the problem may also be
21004somewhere in the connection to the target.)
c4555f82 21005
8e04817f 21006@cindex invalid input
c4555f82 21007@item
8e04817f
AC
21008If @value{GDBN} does not produce an error message for invalid input,
21009that is a bug. However, you should note that your idea of
21010``invalid input'' might be our idea of ``an extension'' or ``support
21011for traditional practice''.
21012
21013@item
21014If you are an experienced user of debugging tools, your suggestions
21015for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
21016@end itemize
21017
8e04817f
AC
21018@node Bug Reporting
21019@section How to report bugs
21020@cindex bug reports
21021@cindex @value{GDBN} bugs, reporting
21022
21023A number of companies and individuals offer support for @sc{gnu} products.
21024If you obtained @value{GDBN} from a support organization, we recommend you
21025contact that organization first.
21026
21027You can find contact information for many support companies and
21028individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
21029distribution.
21030@c should add a web page ref...
21031
129188f6
AC
21032In any event, we also recommend that you submit bug reports for
21033@value{GDBN}. The prefered method is to submit them directly using
21034@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
21035page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
21036be used.
8e04817f
AC
21037
21038@strong{Do not send bug reports to @samp{info-gdb}, or to
21039@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
21040not want to receive bug reports. Those that do have arranged to receive
21041@samp{bug-gdb}.
21042
21043The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
21044serves as a repeater. The mailing list and the newsgroup carry exactly
21045the same messages. Often people think of posting bug reports to the
21046newsgroup instead of mailing them. This appears to work, but it has one
21047problem which can be crucial: a newsgroup posting often lacks a mail
21048path back to the sender. Thus, if we need to ask for more information,
21049we may be unable to reach you. For this reason, it is better to send
21050bug reports to the mailing list.
c4555f82 21051
8e04817f
AC
21052The fundamental principle of reporting bugs usefully is this:
21053@strong{report all the facts}. If you are not sure whether to state a
21054fact or leave it out, state it!
c4555f82 21055
8e04817f
AC
21056Often people omit facts because they think they know what causes the
21057problem and assume that some details do not matter. Thus, you might
21058assume that the name of the variable you use in an example does not matter.
21059Well, probably it does not, but one cannot be sure. Perhaps the bug is a
21060stray memory reference which happens to fetch from the location where that
21061name is stored in memory; perhaps, if the name were different, the contents
21062of that location would fool the debugger into doing the right thing despite
21063the bug. Play it safe and give a specific, complete example. That is the
21064easiest thing for you to do, and the most helpful.
c4555f82 21065
8e04817f
AC
21066Keep in mind that the purpose of a bug report is to enable us to fix the
21067bug. It may be that the bug has been reported previously, but neither
21068you nor we can know that unless your bug report is complete and
21069self-contained.
c4555f82 21070
8e04817f
AC
21071Sometimes people give a few sketchy facts and ask, ``Does this ring a
21072bell?'' Those bug reports are useless, and we urge everyone to
21073@emph{refuse to respond to them} except to chide the sender to report
21074bugs properly.
21075
21076To enable us to fix the bug, you should include all these things:
c4555f82
SC
21077
21078@itemize @bullet
21079@item
8e04817f
AC
21080The version of @value{GDBN}. @value{GDBN} announces it if you start
21081with no arguments; you can also print it at any time using @code{show
21082version}.
c4555f82 21083
8e04817f
AC
21084Without this, we will not know whether there is any point in looking for
21085the bug in the current version of @value{GDBN}.
c4555f82
SC
21086
21087@item
8e04817f
AC
21088The type of machine you are using, and the operating system name and
21089version number.
c4555f82
SC
21090
21091@item
8e04817f
AC
21092What compiler (and its version) was used to compile @value{GDBN}---e.g.
21093``@value{GCC}--2.8.1''.
c4555f82
SC
21094
21095@item
8e04817f
AC
21096What compiler (and its version) was used to compile the program you are
21097debugging---e.g. ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
21098C Compiler''. For GCC, you can say @code{gcc --version} to get this
21099information; for other compilers, see the documentation for those
21100compilers.
c4555f82 21101
8e04817f
AC
21102@item
21103The command arguments you gave the compiler to compile your example and
21104observe the bug. For example, did you use @samp{-O}? To guarantee
21105you will not omit something important, list them all. A copy of the
21106Makefile (or the output from make) is sufficient.
c4555f82 21107
8e04817f
AC
21108If we were to try to guess the arguments, we would probably guess wrong
21109and then we might not encounter the bug.
c4555f82 21110
8e04817f
AC
21111@item
21112A complete input script, and all necessary source files, that will
21113reproduce the bug.
c4555f82 21114
8e04817f
AC
21115@item
21116A description of what behavior you observe that you believe is
21117incorrect. For example, ``It gets a fatal signal.''
c4555f82 21118
8e04817f
AC
21119Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
21120will certainly notice it. But if the bug is incorrect output, we might
21121not notice unless it is glaringly wrong. You might as well not give us
21122a chance to make a mistake.
c4555f82 21123
8e04817f
AC
21124Even if the problem you experience is a fatal signal, you should still
21125say so explicitly. Suppose something strange is going on, such as, your
21126copy of @value{GDBN} is out of synch, or you have encountered a bug in
21127the C library on your system. (This has happened!) Your copy might
21128crash and ours would not. If you told us to expect a crash, then when
21129ours fails to crash, we would know that the bug was not happening for
21130us. If you had not told us to expect a crash, then we would not be able
21131to draw any conclusion from our observations.
c4555f82 21132
e0c07bf0
MC
21133@pindex script
21134@cindex recording a session script
21135To collect all this information, you can use a session recording program
21136such as @command{script}, which is available on many Unix systems.
21137Just run your @value{GDBN} session inside @command{script} and then
21138include the @file{typescript} file with your bug report.
21139
21140Another way to record a @value{GDBN} session is to run @value{GDBN}
21141inside Emacs and then save the entire buffer to a file.
21142
8e04817f
AC
21143@item
21144If you wish to suggest changes to the @value{GDBN} source, send us context
21145diffs. If you even discuss something in the @value{GDBN} source, refer to
21146it by context, not by line number.
c4555f82 21147
8e04817f
AC
21148The line numbers in our development sources will not match those in your
21149sources. Your line numbers would convey no useful information to us.
c4555f82 21150
8e04817f 21151@end itemize
c4555f82 21152
8e04817f 21153Here are some things that are not necessary:
c4555f82 21154
8e04817f
AC
21155@itemize @bullet
21156@item
21157A description of the envelope of the bug.
c4555f82 21158
8e04817f
AC
21159Often people who encounter a bug spend a lot of time investigating
21160which changes to the input file will make the bug go away and which
21161changes will not affect it.
c4555f82 21162
8e04817f
AC
21163This is often time consuming and not very useful, because the way we
21164will find the bug is by running a single example under the debugger
21165with breakpoints, not by pure deduction from a series of examples.
21166We recommend that you save your time for something else.
c4555f82 21167
8e04817f
AC
21168Of course, if you can find a simpler example to report @emph{instead}
21169of the original one, that is a convenience for us. Errors in the
21170output will be easier to spot, running under the debugger will take
21171less time, and so on.
c4555f82 21172
8e04817f
AC
21173However, simplification is not vital; if you do not want to do this,
21174report the bug anyway and send us the entire test case you used.
c4555f82 21175
8e04817f
AC
21176@item
21177A patch for the bug.
c4555f82 21178
8e04817f
AC
21179A patch for the bug does help us if it is a good one. But do not omit
21180the necessary information, such as the test case, on the assumption that
21181a patch is all we need. We might see problems with your patch and decide
21182to fix the problem another way, or we might not understand it at all.
c4555f82 21183
8e04817f
AC
21184Sometimes with a program as complicated as @value{GDBN} it is very hard to
21185construct an example that will make the program follow a certain path
21186through the code. If you do not send us the example, we will not be able
21187to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 21188
8e04817f
AC
21189And if we cannot understand what bug you are trying to fix, or why your
21190patch should be an improvement, we will not install it. A test case will
21191help us to understand.
c4555f82 21192
8e04817f
AC
21193@item
21194A guess about what the bug is or what it depends on.
c4555f82 21195
8e04817f
AC
21196Such guesses are usually wrong. Even we cannot guess right about such
21197things without first using the debugger to find the facts.
21198@end itemize
c4555f82 21199
8e04817f
AC
21200@c The readline documentation is distributed with the readline code
21201@c and consists of the two following files:
21202@c rluser.texinfo
21203@c inc-hist.texinfo
21204@c Use -I with makeinfo to point to the appropriate directory,
21205@c environment var TEXINPUTS with TeX.
21206@include rluser.texinfo
21207@include inc-hist.texinfo
c4555f82 21208
c4555f82 21209
8e04817f
AC
21210@node Formatting Documentation
21211@appendix Formatting Documentation
c4555f82 21212
8e04817f
AC
21213@cindex @value{GDBN} reference card
21214@cindex reference card
21215The @value{GDBN} 4 release includes an already-formatted reference card, ready
21216for printing with PostScript or Ghostscript, in the @file{gdb}
21217subdirectory of the main source directory@footnote{In
21218@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
21219release.}. If you can use PostScript or Ghostscript with your printer,
21220you can print the reference card immediately with @file{refcard.ps}.
c4555f82 21221
8e04817f
AC
21222The release also includes the source for the reference card. You
21223can format it, using @TeX{}, by typing:
c4555f82 21224
474c8240 21225@smallexample
8e04817f 21226make refcard.dvi
474c8240 21227@end smallexample
c4555f82 21228
8e04817f
AC
21229The @value{GDBN} reference card is designed to print in @dfn{landscape}
21230mode on US ``letter'' size paper;
21231that is, on a sheet 11 inches wide by 8.5 inches
21232high. You will need to specify this form of printing as an option to
21233your @sc{dvi} output program.
c4555f82 21234
8e04817f 21235@cindex documentation
c4555f82 21236
8e04817f
AC
21237All the documentation for @value{GDBN} comes as part of the machine-readable
21238distribution. The documentation is written in Texinfo format, which is
21239a documentation system that uses a single source file to produce both
21240on-line information and a printed manual. You can use one of the Info
21241formatting commands to create the on-line version of the documentation
21242and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 21243
8e04817f
AC
21244@value{GDBN} includes an already formatted copy of the on-line Info
21245version of this manual in the @file{gdb} subdirectory. The main Info
21246file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
21247subordinate files matching @samp{gdb.info*} in the same directory. If
21248necessary, you can print out these files, or read them with any editor;
21249but they are easier to read using the @code{info} subsystem in @sc{gnu}
21250Emacs or the standalone @code{info} program, available as part of the
21251@sc{gnu} Texinfo distribution.
c4555f82 21252
8e04817f
AC
21253If you want to format these Info files yourself, you need one of the
21254Info formatting programs, such as @code{texinfo-format-buffer} or
21255@code{makeinfo}.
c4555f82 21256
8e04817f
AC
21257If you have @code{makeinfo} installed, and are in the top level
21258@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
21259version @value{GDBVN}), you can make the Info file by typing:
c4555f82 21260
474c8240 21261@smallexample
8e04817f
AC
21262cd gdb
21263make gdb.info
474c8240 21264@end smallexample
c4555f82 21265
8e04817f
AC
21266If you want to typeset and print copies of this manual, you need @TeX{},
21267a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
21268Texinfo definitions file.
c4555f82 21269
8e04817f
AC
21270@TeX{} is a typesetting program; it does not print files directly, but
21271produces output files called @sc{dvi} files. To print a typeset
21272document, you need a program to print @sc{dvi} files. If your system
21273has @TeX{} installed, chances are it has such a program. The precise
21274command to use depends on your system; @kbd{lpr -d} is common; another
21275(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
21276require a file name without any extension or a @samp{.dvi} extension.
c4555f82 21277
8e04817f
AC
21278@TeX{} also requires a macro definitions file called
21279@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
21280written in Texinfo format. On its own, @TeX{} cannot either read or
21281typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
21282and is located in the @file{gdb-@var{version-number}/texinfo}
21283directory.
c4555f82 21284
8e04817f
AC
21285If you have @TeX{} and a @sc{dvi} printer program installed, you can
21286typeset and print this manual. First switch to the the @file{gdb}
21287subdirectory of the main source directory (for example, to
21288@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 21289
474c8240 21290@smallexample
8e04817f 21291make gdb.dvi
474c8240 21292@end smallexample
c4555f82 21293
8e04817f 21294Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 21295
8e04817f
AC
21296@node Installing GDB
21297@appendix Installing @value{GDBN}
21298@cindex configuring @value{GDBN}
21299@cindex installation
94e91d6d 21300@cindex configuring @value{GDBN}, and source tree subdirectories
c4555f82 21301
8e04817f
AC
21302@value{GDBN} comes with a @code{configure} script that automates the process
21303of preparing @value{GDBN} for installation; you can then use @code{make} to
21304build the @code{gdb} program.
21305@iftex
21306@c irrelevant in info file; it's as current as the code it lives with.
21307@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
21308look at the @file{README} file in the sources; we may have improved the
21309installation procedures since publishing this manual.}
21310@end iftex
c4555f82 21311
8e04817f
AC
21312The @value{GDBN} distribution includes all the source code you need for
21313@value{GDBN} in a single directory, whose name is usually composed by
21314appending the version number to @samp{gdb}.
c4555f82 21315
8e04817f
AC
21316For example, the @value{GDBN} version @value{GDBVN} distribution is in the
21317@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 21318
8e04817f
AC
21319@table @code
21320@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
21321script for configuring @value{GDBN} and all its supporting libraries
c4555f82 21322
8e04817f
AC
21323@item gdb-@value{GDBVN}/gdb
21324the source specific to @value{GDBN} itself
c4555f82 21325
8e04817f
AC
21326@item gdb-@value{GDBVN}/bfd
21327source for the Binary File Descriptor library
c906108c 21328
8e04817f
AC
21329@item gdb-@value{GDBVN}/include
21330@sc{gnu} include files
c906108c 21331
8e04817f
AC
21332@item gdb-@value{GDBVN}/libiberty
21333source for the @samp{-liberty} free software library
c906108c 21334
8e04817f
AC
21335@item gdb-@value{GDBVN}/opcodes
21336source for the library of opcode tables and disassemblers
c906108c 21337
8e04817f
AC
21338@item gdb-@value{GDBVN}/readline
21339source for the @sc{gnu} command-line interface
c906108c 21340
8e04817f
AC
21341@item gdb-@value{GDBVN}/glob
21342source for the @sc{gnu} filename pattern-matching subroutine
c906108c 21343
8e04817f
AC
21344@item gdb-@value{GDBVN}/mmalloc
21345source for the @sc{gnu} memory-mapped malloc package
21346@end table
c906108c 21347
8e04817f
AC
21348The simplest way to configure and build @value{GDBN} is to run @code{configure}
21349from the @file{gdb-@var{version-number}} source directory, which in
21350this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 21351
8e04817f
AC
21352First switch to the @file{gdb-@var{version-number}} source directory
21353if you are not already in it; then run @code{configure}. Pass the
21354identifier for the platform on which @value{GDBN} will run as an
21355argument.
c906108c 21356
8e04817f 21357For example:
c906108c 21358
474c8240 21359@smallexample
8e04817f
AC
21360cd gdb-@value{GDBVN}
21361./configure @var{host}
21362make
474c8240 21363@end smallexample
c906108c 21364
8e04817f
AC
21365@noindent
21366where @var{host} is an identifier such as @samp{sun4} or
21367@samp{decstation}, that identifies the platform where @value{GDBN} will run.
21368(You can often leave off @var{host}; @code{configure} tries to guess the
21369correct value by examining your system.)
c906108c 21370
8e04817f
AC
21371Running @samp{configure @var{host}} and then running @code{make} builds the
21372@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
21373libraries, then @code{gdb} itself. The configured source files, and the
21374binaries, are left in the corresponding source directories.
c906108c 21375
8e04817f
AC
21376@need 750
21377@code{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
21378system does not recognize this automatically when you run a different
21379shell, you may need to run @code{sh} on it explicitly:
c906108c 21380
474c8240 21381@smallexample
8e04817f 21382sh configure @var{host}
474c8240 21383@end smallexample
c906108c 21384
8e04817f
AC
21385If you run @code{configure} from a directory that contains source
21386directories for multiple libraries or programs, such as the
21387@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN}, @code{configure}
21388creates configuration files for every directory level underneath (unless
21389you tell it not to, with the @samp{--norecursion} option).
21390
94e91d6d
MC
21391You should run the @code{configure} script from the top directory in the
21392source tree, the @file{gdb-@var{version-number}} directory. If you run
21393@code{configure} from one of the subdirectories, you will configure only
21394that subdirectory. That is usually not what you want. In particular,
21395if you run the first @code{configure} from the @file{gdb} subdirectory
21396of the @file{gdb-@var{version-number}} directory, you will omit the
21397configuration of @file{bfd}, @file{readline}, and other sibling
21398directories of the @file{gdb} subdirectory. This leads to build errors
21399about missing include files such as @file{bfd/bfd.h}.
c906108c 21400
8e04817f
AC
21401You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
21402However, you should make sure that the shell on your path (named by
21403the @samp{SHELL} environment variable) is publicly readable. Remember
21404that @value{GDBN} uses the shell to start your program---some systems refuse to
21405let @value{GDBN} debug child processes whose programs are not readable.
c906108c 21406
8e04817f
AC
21407@menu
21408* Separate Objdir:: Compiling @value{GDBN} in another directory
21409* Config Names:: Specifying names for hosts and targets
21410* Configure Options:: Summary of options for configure
21411@end menu
c906108c 21412
8e04817f
AC
21413@node Separate Objdir
21414@section Compiling @value{GDBN} in another directory
c906108c 21415
8e04817f
AC
21416If you want to run @value{GDBN} versions for several host or target machines,
21417you need a different @code{gdb} compiled for each combination of
21418host and target. @code{configure} is designed to make this easy by
21419allowing you to generate each configuration in a separate subdirectory,
21420rather than in the source directory. If your @code{make} program
21421handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
21422@code{make} in each of these directories builds the @code{gdb}
21423program specified there.
c906108c 21424
8e04817f
AC
21425To build @code{gdb} in a separate directory, run @code{configure}
21426with the @samp{--srcdir} option to specify where to find the source.
21427(You also need to specify a path to find @code{configure}
21428itself from your working directory. If the path to @code{configure}
21429would be the same as the argument to @samp{--srcdir}, you can leave out
21430the @samp{--srcdir} option; it is assumed.)
c906108c 21431
8e04817f
AC
21432For example, with version @value{GDBVN}, you can build @value{GDBN} in a
21433separate directory for a Sun 4 like this:
c906108c 21434
474c8240 21435@smallexample
8e04817f
AC
21436@group
21437cd gdb-@value{GDBVN}
21438mkdir ../gdb-sun4
21439cd ../gdb-sun4
21440../gdb-@value{GDBVN}/configure sun4
21441make
21442@end group
474c8240 21443@end smallexample
c906108c 21444
8e04817f
AC
21445When @code{configure} builds a configuration using a remote source
21446directory, it creates a tree for the binaries with the same structure
21447(and using the same names) as the tree under the source directory. In
21448the example, you'd find the Sun 4 library @file{libiberty.a} in the
21449directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
21450@file{gdb-sun4/gdb}.
c906108c 21451
94e91d6d
MC
21452Make sure that your path to the @file{configure} script has just one
21453instance of @file{gdb} in it. If your path to @file{configure} looks
21454like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
21455one subdirectory of @value{GDBN}, not the whole package. This leads to
21456build errors about missing include files such as @file{bfd/bfd.h}.
21457
8e04817f
AC
21458One popular reason to build several @value{GDBN} configurations in separate
21459directories is to configure @value{GDBN} for cross-compiling (where
21460@value{GDBN} runs on one machine---the @dfn{host}---while debugging
21461programs that run on another machine---the @dfn{target}).
21462You specify a cross-debugging target by
21463giving the @samp{--target=@var{target}} option to @code{configure}.
c906108c 21464
8e04817f
AC
21465When you run @code{make} to build a program or library, you must run
21466it in a configured directory---whatever directory you were in when you
21467called @code{configure} (or one of its subdirectories).
c906108c 21468
8e04817f
AC
21469The @code{Makefile} that @code{configure} generates in each source
21470directory also runs recursively. If you type @code{make} in a source
21471directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
21472directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
21473will build all the required libraries, and then build GDB.
c906108c 21474
8e04817f
AC
21475When you have multiple hosts or targets configured in separate
21476directories, you can run @code{make} on them in parallel (for example,
21477if they are NFS-mounted on each of the hosts); they will not interfere
21478with each other.
c906108c 21479
8e04817f
AC
21480@node Config Names
21481@section Specifying names for hosts and targets
c906108c 21482
8e04817f
AC
21483The specifications used for hosts and targets in the @code{configure}
21484script are based on a three-part naming scheme, but some short predefined
21485aliases are also supported. The full naming scheme encodes three pieces
21486of information in the following pattern:
c906108c 21487
474c8240 21488@smallexample
8e04817f 21489@var{architecture}-@var{vendor}-@var{os}
474c8240 21490@end smallexample
c906108c 21491
8e04817f
AC
21492For example, you can use the alias @code{sun4} as a @var{host} argument,
21493or as the value for @var{target} in a @code{--target=@var{target}}
21494option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 21495
8e04817f
AC
21496The @code{configure} script accompanying @value{GDBN} does not provide
21497any query facility to list all supported host and target names or
21498aliases. @code{configure} calls the Bourne shell script
21499@code{config.sub} to map abbreviations to full names; you can read the
21500script, if you wish, or you can use it to test your guesses on
21501abbreviations---for example:
c906108c 21502
8e04817f
AC
21503@smallexample
21504% sh config.sub i386-linux
21505i386-pc-linux-gnu
21506% sh config.sub alpha-linux
21507alpha-unknown-linux-gnu
21508% sh config.sub hp9k700
21509hppa1.1-hp-hpux
21510% sh config.sub sun4
21511sparc-sun-sunos4.1.1
21512% sh config.sub sun3
21513m68k-sun-sunos4.1.1
21514% sh config.sub i986v
21515Invalid configuration `i986v': machine `i986v' not recognized
21516@end smallexample
c906108c 21517
8e04817f
AC
21518@noindent
21519@code{config.sub} is also distributed in the @value{GDBN} source
21520directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 21521
8e04817f
AC
21522@node Configure Options
21523@section @code{configure} options
c906108c 21524
8e04817f
AC
21525Here is a summary of the @code{configure} options and arguments that
21526are most often useful for building @value{GDBN}. @code{configure} also has
21527several other options not listed here. @inforef{What Configure
21528Does,,configure.info}, for a full explanation of @code{configure}.
c906108c 21529
474c8240 21530@smallexample
8e04817f
AC
21531configure @r{[}--help@r{]}
21532 @r{[}--prefix=@var{dir}@r{]}
21533 @r{[}--exec-prefix=@var{dir}@r{]}
21534 @r{[}--srcdir=@var{dirname}@r{]}
21535 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
21536 @r{[}--target=@var{target}@r{]}
21537 @var{host}
474c8240 21538@end smallexample
c906108c 21539
8e04817f
AC
21540@noindent
21541You may introduce options with a single @samp{-} rather than
21542@samp{--} if you prefer; but you may abbreviate option names if you use
21543@samp{--}.
c906108c 21544
8e04817f
AC
21545@table @code
21546@item --help
21547Display a quick summary of how to invoke @code{configure}.
c906108c 21548
8e04817f
AC
21549@item --prefix=@var{dir}
21550Configure the source to install programs and files under directory
21551@file{@var{dir}}.
c906108c 21552
8e04817f
AC
21553@item --exec-prefix=@var{dir}
21554Configure the source to install programs under directory
21555@file{@var{dir}}.
c906108c 21556
8e04817f
AC
21557@c avoid splitting the warning from the explanation:
21558@need 2000
21559@item --srcdir=@var{dirname}
21560@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
21561@code{make} that implements the @code{VPATH} feature.}@*
21562Use this option to make configurations in directories separate from the
21563@value{GDBN} source directories. Among other things, you can use this to
21564build (or maintain) several configurations simultaneously, in separate
21565directories. @code{configure} writes configuration specific files in
21566the current directory, but arranges for them to use the source in the
21567directory @var{dirname}. @code{configure} creates directories under
21568the working directory in parallel to the source directories below
21569@var{dirname}.
c906108c 21570
8e04817f
AC
21571@item --norecursion
21572Configure only the directory level where @code{configure} is executed; do not
21573propagate configuration to subdirectories.
c906108c 21574
8e04817f
AC
21575@item --target=@var{target}
21576Configure @value{GDBN} for cross-debugging programs running on the specified
21577@var{target}. Without this option, @value{GDBN} is configured to debug
21578programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 21579
8e04817f 21580There is no convenient way to generate a list of all available targets.
c906108c 21581
8e04817f
AC
21582@item @var{host} @dots{}
21583Configure @value{GDBN} to run on the specified @var{host}.
c906108c 21584
8e04817f
AC
21585There is no convenient way to generate a list of all available hosts.
21586@end table
c906108c 21587
8e04817f
AC
21588There are many other options available as well, but they are generally
21589needed for special purposes only.
c906108c 21590
8e04817f
AC
21591@node Maintenance Commands
21592@appendix Maintenance Commands
21593@cindex maintenance commands
21594@cindex internal commands
c906108c 21595
8e04817f 21596In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
21597includes a number of commands intended for @value{GDBN} developers,
21598that are not documented elsewhere in this manual. These commands are
da316a69
EZ
21599provided here for reference. (For commands that turn on debugging
21600messages, see @ref{Debugging Output}.)
c906108c 21601
8e04817f 21602@table @code
09d4efe1
EZ
21603@kindex maint agent
21604@item maint agent @var{expression}
21605Translate the given @var{expression} into remote agent bytecodes.
21606This command is useful for debugging the Agent Expression mechanism
21607(@pxref{Agent Expressions}).
21608
8e04817f
AC
21609@kindex maint info breakpoints
21610@item @anchor{maint info breakpoints}maint info breakpoints
21611Using the same format as @samp{info breakpoints}, display both the
21612breakpoints you've set explicitly, and those @value{GDBN} is using for
21613internal purposes. Internal breakpoints are shown with negative
21614breakpoint numbers. The type column identifies what kind of breakpoint
21615is shown:
c906108c 21616
8e04817f
AC
21617@table @code
21618@item breakpoint
21619Normal, explicitly set breakpoint.
c906108c 21620
8e04817f
AC
21621@item watchpoint
21622Normal, explicitly set watchpoint.
c906108c 21623
8e04817f
AC
21624@item longjmp
21625Internal breakpoint, used to handle correctly stepping through
21626@code{longjmp} calls.
c906108c 21627
8e04817f
AC
21628@item longjmp resume
21629Internal breakpoint at the target of a @code{longjmp}.
c906108c 21630
8e04817f
AC
21631@item until
21632Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 21633
8e04817f
AC
21634@item finish
21635Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 21636
8e04817f
AC
21637@item shlib events
21638Shared library events.
c906108c 21639
8e04817f 21640@end table
c906108c 21641
09d4efe1
EZ
21642@kindex maint check-symtabs
21643@item maint check-symtabs
21644Check the consistency of psymtabs and symtabs.
21645
21646@kindex maint cplus first_component
21647@item maint cplus first_component @var{name}
21648Print the first C@t{++} class/namespace component of @var{name}.
21649
21650@kindex maint cplus namespace
21651@item maint cplus namespace
21652Print the list of possible C@t{++} namespaces.
21653
21654@kindex maint demangle
21655@item maint demangle @var{name}
21656Demangle a C@t{++} or Objective-C manled @var{name}.
21657
21658@kindex maint deprecate
21659@kindex maint undeprecate
21660@cindex deprecated commands
21661@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
21662@itemx maint undeprecate @var{command}
21663Deprecate or undeprecate the named @var{command}. Deprecated commands
21664cause @value{GDBN} to issue a warning when you use them. The optional
21665argument @var{replacement} says which newer command should be used in
21666favor of the deprecated one; if it is given, @value{GDBN} will mention
21667the replacement as part of the warning.
21668
21669@kindex maint dump-me
21670@item maint dump-me
721c2651 21671@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 21672Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
21673This is supported only on systems which support aborting a program
21674with the @code{SIGQUIT} signal.
09d4efe1 21675
8d30a00d
AC
21676@kindex maint internal-error
21677@kindex maint internal-warning
09d4efe1
EZ
21678@item maint internal-error @r{[}@var{message-text}@r{]}
21679@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
21680Cause @value{GDBN} to call the internal function @code{internal_error}
21681or @code{internal_warning} and hence behave as though an internal error
21682or internal warning has been detected. In addition to reporting the
21683internal problem, these functions give the user the opportunity to
21684either quit @value{GDBN} or create a core file of the current
21685@value{GDBN} session.
21686
09d4efe1
EZ
21687These commands take an optional parameter @var{message-text} that is
21688used as the text of the error or warning message.
21689
21690Here's an example of using @code{indernal-error}:
21691
8d30a00d 21692@smallexample
f7dc1244 21693(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
21694@dots{}/maint.c:121: internal-error: testing, 1, 2
21695A problem internal to GDB has been detected. Further
21696debugging may prove unreliable.
21697Quit this debugging session? (y or n) @kbd{n}
21698Create a core file? (y or n) @kbd{n}
f7dc1244 21699(@value{GDBP})
8d30a00d
AC
21700@end smallexample
21701
09d4efe1
EZ
21702@kindex maint packet
21703@item maint packet @var{text}
21704If @value{GDBN} is talking to an inferior via the serial protocol,
21705then this command sends the string @var{text} to the inferior, and
21706displays the response packet. @value{GDBN} supplies the initial
21707@samp{$} character, the terminating @samp{#} character, and the
21708checksum.
21709
21710@kindex maint print architecture
21711@item maint print architecture @r{[}@var{file}@r{]}
21712Print the entire architecture configuration. The optional argument
21713@var{file} names the file where the output goes.
8d30a00d 21714
00905d52
AC
21715@kindex maint print dummy-frames
21716@item maint print dummy-frames
00905d52
AC
21717Prints the contents of @value{GDBN}'s internal dummy-frame stack.
21718
21719@smallexample
f7dc1244 21720(@value{GDBP}) @kbd{b add}
00905d52 21721@dots{}
f7dc1244 21722(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
21723Breakpoint 2, add (a=2, b=3) at @dots{}
2172458 return (a + b);
21725The program being debugged stopped while in a function called from GDB.
21726@dots{}
f7dc1244 21727(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
217280x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
21729 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
21730 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 21731(@value{GDBP})
00905d52
AC
21732@end smallexample
21733
21734Takes an optional file parameter.
21735
0680b120
AC
21736@kindex maint print registers
21737@kindex maint print raw-registers
21738@kindex maint print cooked-registers
617073a9 21739@kindex maint print register-groups
09d4efe1
EZ
21740@item maint print registers @r{[}@var{file}@r{]}
21741@itemx maint print raw-registers @r{[}@var{file}@r{]}
21742@itemx maint print cooked-registers @r{[}@var{file}@r{]}
21743@itemx maint print register-groups @r{[}@var{file}@r{]}
0680b120
AC
21744Print @value{GDBN}'s internal register data structures.
21745
617073a9
AC
21746The command @code{maint print raw-registers} includes the contents of
21747the raw register cache; the command @code{maint print cooked-registers}
21748includes the (cooked) value of all registers; and the command
21749@code{maint print register-groups} includes the groups that each
21750register is a member of. @xref{Registers,, Registers, gdbint,
21751@value{GDBN} Internals}.
0680b120 21752
09d4efe1
EZ
21753These commands take an optional parameter, a file name to which to
21754write the information.
0680b120 21755
617073a9 21756@kindex maint print reggroups
09d4efe1
EZ
21757@item maint print reggroups @r{[}@var{file}@r{]}
21758Print @value{GDBN}'s internal register group data structures. The
21759optional argument @var{file} tells to what file to write the
21760information.
617073a9 21761
09d4efe1 21762The register groups info looks like this:
617073a9
AC
21763
21764@smallexample
f7dc1244 21765(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
21766 Group Type
21767 general user
21768 float user
21769 all user
21770 vector user
21771 system user
21772 save internal
21773 restore internal
617073a9
AC
21774@end smallexample
21775
09d4efe1
EZ
21776@kindex flushregs
21777@item flushregs
21778This command forces @value{GDBN} to flush its internal register cache.
21779
21780@kindex maint print objfiles
21781@cindex info for known object files
21782@item maint print objfiles
21783Print a dump of all known object files. For each object file, this
21784command prints its name, address in memory, and all of its psymtabs
21785and symtabs.
21786
21787@kindex maint print statistics
21788@cindex bcache statistics
21789@item maint print statistics
21790This command prints, for each object file in the program, various data
21791about that object file followed by the byte cache (@dfn{bcache})
21792statistics for the object file. The objfile data includes the number
21793of minimal, partical, full, and stabs symbols, the number of types
21794defined by the objfile, the number of as yet unexpanded psym tables,
21795the number of line tables and string tables, and the amount of memory
21796used by the various tables. The bcache statistics include the counts,
21797sizes, and counts of duplicates of all and unique objects, max,
21798average, and median entry size, total memory used and its overhead and
21799savings, and various measures of the hash table size and chain
21800lengths.
21801
21802@kindex maint print type
21803@cindex type chain of a data type
21804@item maint print type @var{expr}
21805Print the type chain for a type specified by @var{expr}. The argument
21806can be either a type name or a symbol. If it is a symbol, the type of
21807that symbol is described. The type chain produced by this command is
21808a recursive definition of the data type as stored in @value{GDBN}'s
21809data structures, including its flags and contained types.
21810
21811@kindex maint set dwarf2 max-cache-age
21812@kindex maint show dwarf2 max-cache-age
21813@item maint set dwarf2 max-cache-age
21814@itemx maint show dwarf2 max-cache-age
21815Control the DWARF 2 compilation unit cache.
21816
21817@cindex DWARF 2 compilation units cache
21818In object files with inter-compilation-unit references, such as those
21819produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
21820reader needs to frequently refer to previously read compilation units.
21821This setting controls how long a compilation unit will remain in the
21822cache if it is not referenced. A higher limit means that cached
21823compilation units will be stored in memory longer, and more total
21824memory will be used. Setting it to zero disables caching, which will
21825slow down @value{GDBN} startup, but reduce memory consumption.
21826
e7ba9c65
DJ
21827@kindex maint set profile
21828@kindex maint show profile
21829@cindex profiling GDB
21830@item maint set profile
21831@itemx maint show profile
21832Control profiling of @value{GDBN}.
21833
21834Profiling will be disabled until you use the @samp{maint set profile}
21835command to enable it. When you enable profiling, the system will begin
21836collecting timing and execution count data; when you disable profiling or
21837exit @value{GDBN}, the results will be written to a log file. Remember that
21838if you use profiling, @value{GDBN} will overwrite the profiling log file
21839(often called @file{gmon.out}). If you have a record of important profiling
21840data in a @file{gmon.out} file, be sure to move it to a safe location.
21841
21842Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 21843compiled with the @samp{-pg} compiler option.
e7ba9c65 21844
09d4efe1
EZ
21845@kindex maint show-debug-regs
21846@cindex x86 hardware debug registers
21847@item maint show-debug-regs
21848Control whether to show variables that mirror the x86 hardware debug
21849registers. Use @code{ON} to enable, @code{OFF} to disable. If
21850enabled, the debug registers values are shown when GDB inserts or
21851removes a hardware breakpoint or watchpoint, and when the inferior
21852triggers a hardware-assisted breakpoint or watchpoint.
21853
21854@kindex maint space
21855@cindex memory used by commands
21856@item maint space
21857Control whether to display memory usage for each command. If set to a
21858nonzero value, @value{GDBN} will display how much memory each command
21859took, following the command's own output. This can also be requested
21860by invoking @value{GDBN} with the @option{--statistics} command-line
21861switch (@pxref{Mode Options}).
21862
21863@kindex maint time
21864@cindex time of command execution
21865@item maint time
21866Control whether to display the execution time for each command. If
21867set to a nonzero value, @value{GDBN} will display how much time it
21868took to execute each command, following the command's own output.
21869This can also be requested by invoking @value{GDBN} with the
21870@option{--statistics} command-line switch (@pxref{Mode Options}).
21871
21872@kindex maint translate-address
21873@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
21874Find the symbol stored at the location specified by the address
21875@var{addr} and an optional section name @var{section}. If found,
21876@value{GDBN} prints the name of the closest symbol and an offset from
21877the symbol's location to the specified address. This is similar to
21878the @code{info address} command (@pxref{Symbols}), except that this
21879command also allows to find symbols in other sections.
ae038cb0 21880
8e04817f 21881@end table
c906108c 21882
9c16f35a
EZ
21883The following command is useful for non-interactive invocations of
21884@value{GDBN}, such as in the test suite.
21885
21886@table @code
21887@item set watchdog @var{nsec}
21888@kindex set watchdog
21889@cindex watchdog timer
21890@cindex timeout for commands
21891Set the maximum number of seconds @value{GDBN} will wait for the
21892target operation to finish. If this time expires, @value{GDBN}
21893reports and error and the command is aborted.
21894
21895@item show watchdog
21896Show the current setting of the target wait timeout.
21897@end table
c906108c 21898
e0ce93ac 21899@node Remote Protocol
8e04817f 21900@appendix @value{GDBN} Remote Serial Protocol
c906108c 21901
ee2d5c50
AC
21902@menu
21903* Overview::
21904* Packets::
21905* Stop Reply Packets::
21906* General Query Packets::
21907* Register Packet Format::
21908* Examples::
0ce1b118 21909* File-I/O remote protocol extension::
ee2d5c50
AC
21910@end menu
21911
21912@node Overview
21913@section Overview
21914
8e04817f
AC
21915There may be occasions when you need to know something about the
21916protocol---for example, if there is only one serial port to your target
21917machine, you might want your program to do something special if it
21918recognizes a packet meant for @value{GDBN}.
c906108c 21919
d2c6833e 21920In the examples below, @samp{->} and @samp{<-} are used to indicate
8e04817f 21921transmitted and received data respectfully.
c906108c 21922
8e04817f
AC
21923@cindex protocol, @value{GDBN} remote serial
21924@cindex serial protocol, @value{GDBN} remote
21925@cindex remote serial protocol
21926All @value{GDBN} commands and responses (other than acknowledgments) are
21927sent as a @var{packet}. A @var{packet} is introduced with the character
21928@samp{$}, the actual @var{packet-data}, and the terminating character
21929@samp{#} followed by a two-digit @var{checksum}:
c906108c 21930
474c8240 21931@smallexample
8e04817f 21932@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 21933@end smallexample
8e04817f 21934@noindent
c906108c 21935
8e04817f
AC
21936@cindex checksum, for @value{GDBN} remote
21937@noindent
21938The two-digit @var{checksum} is computed as the modulo 256 sum of all
21939characters between the leading @samp{$} and the trailing @samp{#} (an
21940eight bit unsigned checksum).
c906108c 21941
8e04817f
AC
21942Implementors should note that prior to @value{GDBN} 5.0 the protocol
21943specification also included an optional two-digit @var{sequence-id}:
c906108c 21944
474c8240 21945@smallexample
8e04817f 21946@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 21947@end smallexample
c906108c 21948
8e04817f
AC
21949@cindex sequence-id, for @value{GDBN} remote
21950@noindent
21951That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
21952has never output @var{sequence-id}s. Stubs that handle packets added
21953since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 21954
8e04817f
AC
21955@cindex acknowledgment, for @value{GDBN} remote
21956When either the host or the target machine receives a packet, the first
21957response expected is an acknowledgment: either @samp{+} (to indicate
21958the package was received correctly) or @samp{-} (to request
21959retransmission):
c906108c 21960
474c8240 21961@smallexample
d2c6833e
AC
21962-> @code{$}@var{packet-data}@code{#}@var{checksum}
21963<- @code{+}
474c8240 21964@end smallexample
8e04817f 21965@noindent
53a5351d 21966
8e04817f
AC
21967The host (@value{GDBN}) sends @var{command}s, and the target (the
21968debugging stub incorporated in your program) sends a @var{response}. In
21969the case of step and continue @var{command}s, the response is only sent
21970when the operation has completed (the target has again stopped).
c906108c 21971
8e04817f
AC
21972@var{packet-data} consists of a sequence of characters with the
21973exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
21974exceptions).
c906108c 21975
8e04817f 21976Fields within the packet should be separated using @samp{,} @samp{;} or
ee2d5c50 21977@cindex remote protocol, field separator
8e04817f 21978@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 21979@sc{hex} with leading zeros suppressed.
c906108c 21980
8e04817f
AC
21981Implementors should note that prior to @value{GDBN} 5.0, the character
21982@samp{:} could not appear as the third character in a packet (as it
21983would potentially conflict with the @var{sequence-id}).
c906108c 21984
8e04817f
AC
21985Response @var{data} can be run-length encoded to save space. A @samp{*}
21986means that the next character is an @sc{ascii} encoding giving a repeat count
21987which stands for that many repetitions of the character preceding the
21988@samp{*}. The encoding is @code{n+29}, yielding a printable character
21989where @code{n >=3} (which is where rle starts to win). The printable
21990characters @samp{$}, @samp{#}, @samp{+} and @samp{-} or with a numeric
21991value greater than 126 should not be used.
c906108c 21992
8e04817f 21993So:
474c8240 21994@smallexample
8e04817f 21995"@code{0* }"
474c8240 21996@end smallexample
8e04817f
AC
21997@noindent
21998means the same as "0000".
c906108c 21999
8e04817f
AC
22000The error response returned for some packets includes a two character
22001error number. That number is not well defined.
c906108c 22002
8e04817f
AC
22003For any @var{command} not supported by the stub, an empty response
22004(@samp{$#00}) should be returned. That way it is possible to extend the
22005protocol. A newer @value{GDBN} can tell if a packet is supported based
22006on that response.
c906108c 22007
b383017d
RM
22008A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
22009@samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
8e04817f 22010optional.
c906108c 22011
ee2d5c50
AC
22012@node Packets
22013@section Packets
22014
22015The following table provides a complete list of all currently defined
22016@var{command}s and their corresponding response @var{data}.
9c16f35a
EZ
22017@xref{File-I/O remote protocol extension}, for details about the File
22018I/O extension of the remote protocol.
ee2d5c50
AC
22019
22020@table @r
22021
22022@item @code{!} --- extended mode
22023@cindex @code{!} packet
22024
8e04817f
AC
22025Enable extended mode. In extended mode, the remote server is made
22026persistent. The @samp{R} packet is used to restart the program being
22027debugged.
ee2d5c50
AC
22028
22029Reply:
22030@table @samp
22031@item OK
8e04817f 22032The remote target both supports and has enabled extended mode.
ee2d5c50 22033@end table
c906108c 22034
ee2d5c50
AC
22035@item @code{?} --- last signal
22036@cindex @code{?} packet
c906108c 22037
ee2d5c50
AC
22038Indicate the reason the target halted. The reply is the same as for
22039step and continue.
c906108c 22040
ee2d5c50
AC
22041Reply:
22042@xref{Stop Reply Packets}, for the reply specifications.
22043
22044@item @code{a} --- reserved
22045
22046Reserved for future use.
22047
22048@item @code{A}@var{arglen}@code{,}@var{argnum}@code{,}@var{arg}@code{,@dots{}} --- set program arguments @strong{(reserved)}
22049@cindex @code{A} packet
c906108c 22050
8e04817f
AC
22051Initialized @samp{argv[]} array passed into program. @var{arglen}
22052specifies the number of bytes in the hex encoded byte stream @var{arg}.
ee2d5c50
AC
22053See @code{gdbserver} for more details.
22054
22055Reply:
22056@table @samp
22057@item OK
22058@item E@var{NN}
22059@end table
22060
22061@item @code{b}@var{baud} --- set baud @strong{(deprecated)}
22062@cindex @code{b} packet
22063
22064Change the serial line speed to @var{baud}.
22065
22066JTC: @emph{When does the transport layer state change? When it's
22067received, or after the ACK is transmitted. In either case, there are
22068problems if the command or the acknowledgment packet is dropped.}
22069
22070Stan: @emph{If people really wanted to add something like this, and get
22071it working for the first time, they ought to modify ser-unix.c to send
22072some kind of out-of-band message to a specially-setup stub and have the
22073switch happen "in between" packets, so that from remote protocol's point
22074of view, nothing actually happened.}
22075
22076@item @code{B}@var{addr},@var{mode} --- set breakpoint @strong{(deprecated)}
22077@cindex @code{B} packet
22078
8e04817f 22079Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
22080breakpoint at @var{addr}.
22081
22082This packet has been replaced by the @samp{Z} and @samp{z} packets
22083(@pxref{insert breakpoint or watchpoint packet}).
c906108c 22084
ee2d5c50
AC
22085@item @code{c}@var{addr} --- continue
22086@cindex @code{c} packet
22087
22088@var{addr} is address to resume. If @var{addr} is omitted, resume at
8e04817f 22089current address.
c906108c 22090
ee2d5c50
AC
22091Reply:
22092@xref{Stop Reply Packets}, for the reply specifications.
22093
22094@item @code{C}@var{sig}@code{;}@var{addr} --- continue with signal
22095@cindex @code{C} packet
22096
8e04817f
AC
22097Continue with signal @var{sig} (hex signal number). If
22098@code{;}@var{addr} is omitted, resume at same address.
c906108c 22099
ee2d5c50
AC
22100Reply:
22101@xref{Stop Reply Packets}, for the reply specifications.
c906108c 22102
ee2d5c50
AC
22103@item @code{d} --- toggle debug @strong{(deprecated)}
22104@cindex @code{d} packet
22105
22106Toggle debug flag.
22107
22108@item @code{D} --- detach
22109@cindex @code{D} packet
22110
22111Detach @value{GDBN} from the remote system. Sent to the remote target
07f31aa6 22112before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50
AC
22113
22114Reply:
22115@table @samp
10fac096
NW
22116@item OK
22117for success
22118@item E@var{NN}
22119for an error
ee2d5c50 22120@end table
c906108c 22121
ee2d5c50 22122@item @code{e} --- reserved
c906108c 22123
ee2d5c50 22124Reserved for future use.
c906108c 22125
ee2d5c50 22126@item @code{E} --- reserved
c906108c 22127
ee2d5c50 22128Reserved for future use.
c906108c 22129
ee2d5c50
AC
22130@item @code{f} --- reserved
22131
22132Reserved for future use.
22133
0ce1b118
CV
22134@item @code{F}@var{RC}@code{,}@var{EE}@code{,}@var{CF}@code{;}@var{XX} --- Reply to target's F packet.
22135@cindex @code{F} packet
ee2d5c50 22136
0ce1b118
CV
22137This packet is send by @value{GDBN} as reply to a @code{F} request packet
22138sent by the target. This is part of the File-I/O protocol extension.
22139@xref{File-I/O remote protocol extension}, for the specification.
ee2d5c50
AC
22140
22141@item @code{g} --- read registers
22142@anchor{read registers packet}
22143@cindex @code{g} packet
22144
22145Read general registers.
22146
22147Reply:
22148@table @samp
22149@item @var{XX@dots{}}
8e04817f
AC
22150Each byte of register data is described by two hex digits. The bytes
22151with the register are transmitted in target byte order. The size of
22152each register and their position within the @samp{g} @var{packet} are
12c266ea
AC
22153determined by the @value{GDBN} internal macros
22154@var{DEPRECATED_REGISTER_RAW_SIZE} and @var{REGISTER_NAME} macros. The
22155specification of several standard @code{g} packets is specified below.
ee2d5c50
AC
22156@item E@var{NN}
22157for an error.
22158@end table
c906108c 22159
ee2d5c50
AC
22160@item @code{G}@var{XX@dots{}} --- write regs
22161@cindex @code{G} packet
c906108c 22162
ee2d5c50
AC
22163@xref{read registers packet}, for a description of the @var{XX@dots{}}
22164data.
22165
22166Reply:
22167@table @samp
22168@item OK
22169for success
22170@item E@var{NN}
22171for an error
22172@end table
22173
22174@item @code{h} --- reserved
22175
22176Reserved for future use.
22177
b383017d 22178@item @code{H}@var{c}@var{t@dots{}} --- set thread
ee2d5c50 22179@cindex @code{H} packet
c906108c 22180
8e04817f 22181Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
ee2d5c50
AC
22182@samp{G}, et.al.). @var{c} depends on the operation to be performed: it
22183should be @samp{c} for step and continue operations, @samp{g} for other
22184operations. The thread designator @var{t@dots{}} may be -1, meaning all
22185the threads, a thread number, or zero which means pick any thread.
22186
22187Reply:
22188@table @samp
22189@item OK
22190for success
22191@item E@var{NN}
22192for an error
22193@end table
c906108c 22194
8e04817f
AC
22195@c FIXME: JTC:
22196@c 'H': How restrictive (or permissive) is the thread model. If a
22197@c thread is selected and stopped, are other threads allowed
22198@c to continue to execute? As I mentioned above, I think the
22199@c semantics of each command when a thread is selected must be
22200@c described. For example:
22201@c
22202@c 'g': If the stub supports threads and a specific thread is
22203@c selected, returns the register block from that thread;
22204@c otherwise returns current registers.
22205@c
22206@c 'G' If the stub supports threads and a specific thread is
22207@c selected, sets the registers of the register block of
22208@c that thread; otherwise sets current registers.
c906108c 22209
ee2d5c50
AC
22210@item @code{i}@var{addr}@code{,}@var{nnn} --- cycle step @strong{(draft)}
22211@anchor{cycle step packet}
22212@cindex @code{i} packet
22213
8e04817f
AC
22214Step the remote target by a single clock cycle. If @code{,}@var{nnn} is
22215present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
22216step starting at that address.
c906108c 22217
ee2d5c50
AC
22218@item @code{I} --- signal then cycle step @strong{(reserved)}
22219@cindex @code{I} packet
22220
22221@xref{step with signal packet}. @xref{cycle step packet}.
22222
22223@item @code{j} --- reserved
22224
22225Reserved for future use.
22226
22227@item @code{J} --- reserved
c906108c 22228
ee2d5c50 22229Reserved for future use.
c906108c 22230
ee2d5c50
AC
22231@item @code{k} --- kill request
22232@cindex @code{k} packet
c906108c 22233
ac282366 22234FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
22235thread context has been selected (i.e.@: does 'k' kill only that
22236thread?)}.
c906108c 22237
ee2d5c50 22238@item @code{K} --- reserved
c906108c 22239
ee2d5c50
AC
22240Reserved for future use.
22241
22242@item @code{l} --- reserved
22243
22244Reserved for future use.
22245
22246@item @code{L} --- reserved
22247
22248Reserved for future use.
22249
22250@item @code{m}@var{addr}@code{,}@var{length} --- read memory
22251@cindex @code{m} packet
c906108c 22252
8e04817f 22253Read @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50 22254Neither @value{GDBN} nor the stub assume that sized memory transfers are
2e834e49 22255assumed using word aligned accesses. FIXME: @emph{A word aligned memory
8e04817f 22256transfer mechanism is needed.}
c906108c 22257
ee2d5c50
AC
22258Reply:
22259@table @samp
22260@item @var{XX@dots{}}
22261@var{XX@dots{}} is mem contents. Can be fewer bytes than requested if able
22262to read only part of the data. Neither @value{GDBN} nor the stub assume
2e834e49 22263that sized memory transfers are assumed using word aligned
ee2d5c50
AC
22264accesses. FIXME: @emph{A word aligned memory transfer mechanism is
22265needed.}
22266@item E@var{NN}
22267@var{NN} is errno
22268@end table
22269
22270@item @code{M}@var{addr},@var{length}@code{:}@var{XX@dots{}} --- write mem
22271@cindex @code{M} packet
22272
8e04817f 22273Write @var{length} bytes of memory starting at address @var{addr}.
ee2d5c50
AC
22274@var{XX@dots{}} is the data.
22275
22276Reply:
22277@table @samp
22278@item OK
22279for success
22280@item E@var{NN}
8e04817f
AC
22281for an error (this includes the case where only part of the data was
22282written).
ee2d5c50 22283@end table
c906108c 22284
ee2d5c50 22285@item @code{n} --- reserved
c906108c 22286
ee2d5c50 22287Reserved for future use.
c906108c 22288
ee2d5c50 22289@item @code{N} --- reserved
c906108c 22290
ee2d5c50 22291Reserved for future use.
c906108c 22292
ee2d5c50
AC
22293@item @code{o} --- reserved
22294
22295Reserved for future use.
22296
22297@item @code{O} --- reserved
22298
2e868123 22299@item @code{p}@var{hex number of register} --- read register packet
ee2d5c50
AC
22300@cindex @code{p} packet
22301
2e868123
AC
22302@xref{read registers packet}, for a description of how the returned
22303register value is encoded.
ee2d5c50
AC
22304
22305Reply:
22306@table @samp
2e868123
AC
22307@item @var{XX@dots{}}
22308the register's value
22309@item E@var{NN}
22310for an error
22311@item
22312Indicating an unrecognized @var{query}.
ee2d5c50
AC
22313@end table
22314
22315@item @code{P}@var{n@dots{}}@code{=}@var{r@dots{}} --- write register
22316@anchor{write register packet}
22317@cindex @code{P} packet
22318
22319Write register @var{n@dots{}} with value @var{r@dots{}}, which contains two hex
8e04817f 22320digits for each byte in the register (target byte order).
c906108c 22321
ee2d5c50
AC
22322Reply:
22323@table @samp
22324@item OK
22325for success
22326@item E@var{NN}
22327for an error
22328@end table
22329
22330@item @code{q}@var{query} --- general query
22331@anchor{general query packet}
22332@cindex @code{q} packet
22333
22334Request info about @var{query}. In general @value{GDBN} queries have a
22335leading upper case letter. Custom vendor queries should use a company
22336prefix (in lower case) ex: @samp{qfsf.var}. @var{query} may optionally
22337be followed by a @samp{,} or @samp{;} separated list. Stubs must ensure
22338that they match the full @var{query} name.
22339
22340Reply:
22341@table @samp
22342@item @var{XX@dots{}}
22343Hex encoded data from query. The reply can not be empty.
22344@item E@var{NN}
22345error reply
8e04817f 22346@item
ee2d5c50
AC
22347Indicating an unrecognized @var{query}.
22348@end table
22349
22350@item @code{Q}@var{var}@code{=}@var{val} --- general set
22351@cindex @code{Q} packet
22352
22353Set value of @var{var} to @var{val}.
22354
22355@xref{general query packet}, for a discussion of naming conventions.
c906108c 22356
ee2d5c50
AC
22357@item @code{r} --- reset @strong{(deprecated)}
22358@cindex @code{r} packet
c906108c 22359
8e04817f 22360Reset the entire system.
c906108c 22361
ee2d5c50
AC
22362@item @code{R}@var{XX} --- remote restart
22363@cindex @code{R} packet
22364
8e04817f
AC
22365Restart the program being debugged. @var{XX}, while needed, is ignored.
22366This packet is only available in extended mode.
ee2d5c50
AC
22367
22368Reply:
22369@table @samp
22370@item @emph{no reply}
8e04817f 22371The @samp{R} packet has no reply.
ee2d5c50
AC
22372@end table
22373
22374@item @code{s}@var{addr} --- step
22375@cindex @code{s} packet
c906108c 22376
8e04817f
AC
22377@var{addr} is address to resume. If @var{addr} is omitted, resume at
22378same address.
c906108c 22379
ee2d5c50
AC
22380Reply:
22381@xref{Stop Reply Packets}, for the reply specifications.
22382
22383@item @code{S}@var{sig}@code{;}@var{addr} --- step with signal
22384@anchor{step with signal packet}
22385@cindex @code{S} packet
22386
8e04817f 22387Like @samp{C} but step not continue.
c906108c 22388
ee2d5c50
AC
22389Reply:
22390@xref{Stop Reply Packets}, for the reply specifications.
22391
b383017d 22392@item @code{t}@var{addr}@code{:}@var{PP}@code{,}@var{MM} --- search
ee2d5c50
AC
22393@cindex @code{t} packet
22394
8e04817f 22395Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
22396@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
22397@var{addr} must be at least 3 digits.
c906108c 22398
ee2d5c50
AC
22399@item @code{T}@var{XX} --- thread alive
22400@cindex @code{T} packet
c906108c 22401
ee2d5c50 22402Find out if the thread XX is alive.
c906108c 22403
ee2d5c50
AC
22404Reply:
22405@table @samp
22406@item OK
22407thread is still alive
22408@item E@var{NN}
22409thread is dead
22410@end table
22411
22412@item @code{u} --- reserved
22413
22414Reserved for future use.
22415
22416@item @code{U} --- reserved
22417
22418Reserved for future use.
22419
86d30acc 22420@item @code{v} --- verbose packet prefix
ee2d5c50 22421
86d30acc
DJ
22422Packets starting with @code{v} are identified by a multi-letter name,
22423up to the first @code{;} or @code{?} (or the end of the packet).
22424
22425@item @code{vCont}[;@var{action}[@code{:}@var{tid}]]... --- extended resume
22426@cindex @code{vCont} packet
22427
22428Resume the inferior. Different actions may be specified for each thread.
22429If an action is specified with no @var{tid}, then it is applied to any
22430threads that don't have a specific action specified; if no default action is
22431specified then other threads should remain stopped. Specifying multiple
22432default actions is an error; specifying no actions is also an error.
22433Thread IDs are specified in hexadecimal. Currently supported actions are:
22434
22435@table @code
22436@item c
22437Continue.
22438@item C@var{sig}
22439Continue with signal @var{sig}. @var{sig} should be two hex digits.
22440@item s
22441Step.
22442@item S@var{sig}
22443Step with signal @var{sig}. @var{sig} should be two hex digits.
22444@end table
22445
22446The optional @var{addr} argument normally associated with these packets is
22447not supported in @code{vCont}.
22448
22449Reply:
22450@xref{Stop Reply Packets}, for the reply specifications.
22451
22452@item @code{vCont?} --- extended resume query
22453@cindex @code{vCont?} packet
22454
22455Query support for the @code{vCont} packet.
22456
22457Reply:
22458@table @samp
22459@item @code{vCont}[;@var{action}]...
22460The @code{vCont} packet is supported. Each @var{action} is a supported
22461command in the @code{vCont} packet.
22462@item
22463The @code{vCont} packet is not supported.
22464@end table
ee2d5c50
AC
22465
22466@item @code{V} --- reserved
c906108c 22467
ee2d5c50 22468Reserved for future use.
c906108c 22469
ee2d5c50 22470@item @code{w} --- reserved
c906108c 22471
ee2d5c50 22472Reserved for future use.
c906108c 22473
ee2d5c50 22474@item @code{W} --- reserved
c906108c 22475
ee2d5c50 22476Reserved for future use.
c906108c 22477
ee2d5c50
AC
22478@item @code{x} --- reserved
22479
22480Reserved for future use.
22481
22482@item @code{X}@var{addr}@code{,}@var{length}@var{:}@var{XX@dots{}} --- write mem (binary)
22483@cindex @code{X} packet
22484
22485@var{addr} is address, @var{length} is number of bytes, @var{XX@dots{}}
22486is binary data. The characters @code{$}, @code{#}, and @code{0x7d} are
69065f5d
AC
22487escaped using @code{0x7d}, and then XORed with @code{0x20}.
22488For example, @code{0x7d} would be transmitted as @code{0x7d 0x5d}.
c906108c 22489
ee2d5c50
AC
22490Reply:
22491@table @samp
22492@item OK
22493for success
22494@item E@var{NN}
22495for an error
22496@end table
22497
22498@item @code{y} --- reserved
c906108c 22499
ee2d5c50 22500Reserved for future use.
c906108c 22501
ee2d5c50
AC
22502@item @code{Y} reserved
22503
22504Reserved for future use.
22505
2f870471
AC
22506@item @code{z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- remove breakpoint or watchpoint @strong{(draft)}
22507@itemx @code{Z}@var{type}@code{,}@var{addr}@code{,}@var{length} --- insert breakpoint or watchpoint @strong{(draft)}
22508@anchor{insert breakpoint or watchpoint packet}
ee2d5c50 22509@cindex @code{z} packet
2f870471 22510@cindex @code{Z} packets
ee2d5c50 22511
2f870471
AC
22512Insert (@code{Z}) or remove (@code{z}) a @var{type} breakpoint or
22513watchpoint starting at address @var{address} and covering the next
22514@var{length} bytes.
ee2d5c50 22515
2f870471
AC
22516Each breakpoint and watchpoint packet @var{type} is documented
22517separately.
22518
512217c7
AC
22519@emph{Implementation notes: A remote target shall return an empty string
22520for an unrecognized breakpoint or watchpoint packet @var{type}. A
22521remote target shall support either both or neither of a given
2f870471
AC
22522@code{Z}@var{type}@dots{} and @code{z}@var{type}@dots{} packet pair. To
22523avoid potential problems with duplicate packets, the operations should
22524be implemented in an idempotent way.}
22525
22526@item @code{z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- remove memory breakpoint @strong{(draft)}
22527@item @code{Z}@code{0}@code{,}@var{addr}@code{,}@var{length} --- insert memory breakpoint @strong{(draft)}
22528@cindex @code{z0} packet
22529@cindex @code{Z0} packet
22530
22531Insert (@code{Z0}) or remove (@code{z0}) a memory breakpoint at address
22532@code{addr} of size @code{length}.
22533
22534A memory breakpoint is implemented by replacing the instruction at
22535@var{addr} with a software breakpoint or trap instruction. The
22536@code{length} is used by targets that indicates the size of the
22537breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
22538@sc{mips} can insert either a 2 or 4 byte breakpoint).
c906108c 22539
2f870471
AC
22540@emph{Implementation note: It is possible for a target to copy or move
22541code that contains memory breakpoints (e.g., when implementing
22542overlays). The behavior of this packet, in the presence of such a
22543target, is not defined.}
c906108c 22544
ee2d5c50
AC
22545Reply:
22546@table @samp
2f870471
AC
22547@item OK
22548success
22549@item
22550not supported
ee2d5c50
AC
22551@item E@var{NN}
22552for an error
2f870471
AC
22553@end table
22554
22555@item @code{z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- remove hardware breakpoint @strong{(draft)}
22556@item @code{Z}@code{1}@code{,}@var{addr}@code{,}@var{length} --- insert hardware breakpoint @strong{(draft)}
22557@cindex @code{z1} packet
22558@cindex @code{Z1} packet
22559
22560Insert (@code{Z1}) or remove (@code{z1}) a hardware breakpoint at
22561address @code{addr} of size @code{length}.
22562
22563A hardware breakpoint is implemented using a mechanism that is not
22564dependant on being able to modify the target's memory.
22565
22566@emph{Implementation note: A hardware breakpoint is not affected by code
22567movement.}
22568
22569Reply:
22570@table @samp
ee2d5c50 22571@item OK
2f870471
AC
22572success
22573@item
22574not supported
22575@item E@var{NN}
22576for an error
22577@end table
22578
22579@item @code{z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- remove write watchpoint @strong{(draft)}
22580@item @code{Z}@code{2}@code{,}@var{addr}@code{,}@var{length} --- insert write watchpoint @strong{(draft)}
22581@cindex @code{z2} packet
22582@cindex @code{Z2} packet
22583
22584Insert (@code{Z2}) or remove (@code{z2}) a write watchpoint.
22585
22586Reply:
22587@table @samp
22588@item OK
22589success
22590@item
22591not supported
22592@item E@var{NN}
22593for an error
22594@end table
22595
22596@item @code{z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- remove read watchpoint @strong{(draft)}
22597@item @code{Z}@code{3}@code{,}@var{addr}@code{,}@var{length} --- insert read watchpoint @strong{(draft)}
22598@cindex @code{z3} packet
22599@cindex @code{Z3} packet
22600
2e834e49 22601Insert (@code{Z3}) or remove (@code{z3}) a read watchpoint.
2f870471
AC
22602
22603Reply:
22604@table @samp
22605@item OK
22606success
22607@item
22608not supported
22609@item E@var{NN}
22610for an error
22611@end table
22612
2e834e49
HPN
22613@item @code{z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- remove access watchpoint @strong{(draft)}
22614@item @code{Z}@code{4}@code{,}@var{addr}@code{,}@var{length} --- insert access watchpoint @strong{(draft)}
2f870471
AC
22615@cindex @code{z4} packet
22616@cindex @code{Z4} packet
22617
22618Insert (@code{Z4}) or remove (@code{z4}) an access watchpoint.
22619
22620Reply:
22621@table @samp
22622@item OK
22623success
22624@item
22625not supported
22626@item E@var{NN}
22627for an error
ee2d5c50
AC
22628@end table
22629
22630@end table
c906108c 22631
ee2d5c50
AC
22632@node Stop Reply Packets
22633@section Stop Reply Packets
22634@cindex stop reply packets
c906108c 22635
8e04817f
AC
22636The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
22637receive any of the below as a reply. In the case of the @samp{C},
22638@samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
22639when the target halts. In the below the exact meaning of @samp{signal
22640number} is poorly defined. In general one of the UNIX signal numbering
22641conventions is used.
c906108c 22642
ee2d5c50 22643@table @samp
c906108c 22644
ee2d5c50
AC
22645@item S@var{AA}
22646@var{AA} is the signal number
c906108c 22647
8e04817f 22648@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
22649@cindex @code{T} packet reply
22650
8e04817f
AC
22651@var{AA} = two hex digit signal number; @var{n...} = register number
22652(hex), @var{r...} = target byte ordered register contents, size defined
12c266ea
AC
22653by @code{DEPRECATED_REGISTER_RAW_SIZE}; @var{n...} = @samp{thread},
22654@var{r...} = thread process ID, this is a hex integer; @var{n...} =
22655(@samp{watch} | @samp{rwatch} | @samp{awatch}, @var{r...} = data
22656address, this is a hex integer; @var{n...} = other string not starting
22657with valid hex digit. @value{GDBN} should ignore this @var{n...},
22658@var{r...} pair and go on to the next. This way we can extend the
22659protocol.
c906108c 22660
ee2d5c50
AC
22661@item W@var{AA}
22662
8e04817f 22663The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
22664applicable to certain targets.
22665
22666@item X@var{AA}
c906108c 22667
8e04817f 22668The process terminated with signal @var{AA}.
c906108c 22669
ee2d5c50 22670@item O@var{XX@dots{}}
c906108c 22671
ee2d5c50
AC
22672@var{XX@dots{}} is hex encoding of @sc{ascii} data. This can happen at
22673any time while the program is running and the debugger should continue
22674to wait for @samp{W}, @samp{T}, etc.
22675
0ce1b118
CV
22676@item F@var{call-id}@code{,}@var{parameter@dots{}}
22677
22678@var{call-id} is the identifier which says which host system call should
22679be called. This is just the name of the function. Translation into the
22680correct system call is only applicable as it's defined in @value{GDBN}.
22681@xref{File-I/O remote protocol extension}, for a list of implemented
22682system calls.
22683
22684@var{parameter@dots{}} is a list of parameters as defined for this very
22685system call.
22686
22687The target replies with this packet when it expects @value{GDBN} to call
22688a host system call on behalf of the target. @value{GDBN} replies with
22689an appropriate @code{F} packet and keeps up waiting for the next reply
22690packet from the target. The latest @samp{C}, @samp{c}, @samp{S} or
22691@samp{s} action is expected to be continued.
22692@xref{File-I/O remote protocol extension}, for more details.
22693
ee2d5c50
AC
22694@end table
22695
22696@node General Query Packets
22697@section General Query Packets
9c16f35a 22698@cindex remote query requests
c906108c 22699
8e04817f 22700The following set and query packets have already been defined.
c906108c 22701
ee2d5c50 22702@table @r
c906108c 22703
ee2d5c50 22704@item @code{q}@code{C} --- current thread
9c16f35a
EZ
22705@cindex current thread, remote request
22706@cindex @code{qC} packet
ee2d5c50
AC
22707Return the current thread id.
22708
22709Reply:
22710@table @samp
22711@item @code{QC}@var{pid}
e1aac25b 22712Where @var{pid} is an unsigned hexidecimal process id.
ee2d5c50
AC
22713@item *
22714Any other reply implies the old pid.
22715@end table
22716
22717@item @code{q}@code{fThreadInfo} -- all thread ids
9c16f35a
EZ
22718@cindex list active threads, remote request
22719@cindex @code{qfThreadInfo} packet
ee2d5c50 22720@code{q}@code{sThreadInfo}
c906108c 22721
8e04817f
AC
22722Obtain a list of active thread ids from the target (OS). Since there
22723may be too many active threads to fit into one reply packet, this query
22724works iteratively: it may require more than one query/reply sequence to
22725obtain the entire list of threads. The first query of the sequence will
22726be the @code{qf}@code{ThreadInfo} query; subsequent queries in the
22727sequence will be the @code{qs}@code{ThreadInfo} query.
ee2d5c50
AC
22728
22729NOTE: replaces the @code{qL} query (see below).
22730
22731Reply:
22732@table @samp
22733@item @code{m}@var{id}
22734A single thread id
22735@item @code{m}@var{id},@var{id}@dots{}
22736a comma-separated list of thread ids
22737@item @code{l}
22738(lower case 'el') denotes end of list.
22739@end table
22740
22741In response to each query, the target will reply with a list of one or
e1aac25b
JB
22742more thread ids, in big-endian unsigned hex, separated by commas.
22743@value{GDBN} will respond to each reply with a request for more thread
22744ids (using the @code{qs} form of the query), until the target responds
22745with @code{l} (lower-case el, for @code{'last'}).
c906108c 22746
ee2d5c50 22747@item @code{q}@code{ThreadExtraInfo}@code{,}@var{id} --- extra thread info
9c16f35a
EZ
22748@cindex thread attributes info, remote request
22749@cindex @code{qThreadExtraInfo} packet
ee2d5c50
AC
22750Where @var{id} is a thread-id in big-endian hex. Obtain a printable
22751string description of a thread's attributes from the target OS. This
22752string may contain anything that the target OS thinks is interesting for
22753@value{GDBN} to tell the user about the thread. The string is displayed
22754in @value{GDBN}'s @samp{info threads} display. Some examples of
22755possible thread extra info strings are ``Runnable'', or ``Blocked on
22756Mutex''.
22757
22758Reply:
22759@table @samp
22760@item @var{XX@dots{}}
22761Where @var{XX@dots{}} is a hex encoding of @sc{ascii} data, comprising
22762the printable string containing the extra information about the thread's
8e04817f 22763attributes.
ee2d5c50
AC
22764@end table
22765
22766@item @code{q}@code{L}@var{startflag}@var{threadcount}@var{nextthread} --- query @var{LIST} or @var{threadLIST} @strong{(deprecated)}
c906108c 22767
8e04817f
AC
22768Obtain thread information from RTOS. Where: @var{startflag} (one hex
22769digit) is one to indicate the first query and zero to indicate a
22770subsequent query; @var{threadcount} (two hex digits) is the maximum
22771number of threads the response packet can contain; and @var{nextthread}
22772(eight hex digits), for subsequent queries (@var{startflag} is zero), is
22773returned in the response as @var{argthread}.
ee2d5c50
AC
22774
22775NOTE: this query is replaced by the @code{q}@code{fThreadInfo} query
22776(see above).
22777
22778Reply:
22779@table @samp
22780@item @code{q}@code{M}@var{count}@var{done}@var{argthread}@var{thread@dots{}}
8e04817f
AC
22781Where: @var{count} (two hex digits) is the number of threads being
22782returned; @var{done} (one hex digit) is zero to indicate more threads
22783and one indicates no further threads; @var{argthreadid} (eight hex
ee2d5c50
AC
22784digits) is @var{nextthread} from the request packet; @var{thread@dots{}}
22785is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 22786digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 22787@end table
c906108c 22788
ee2d5c50 22789@item @code{q}@code{CRC:}@var{addr}@code{,}@var{length} --- compute CRC of memory block
9c16f35a
EZ
22790@cindex CRC of memory block, remote request
22791@cindex @code{qCRC} packet
ee2d5c50
AC
22792Reply:
22793@table @samp
22794@item @code{E}@var{NN}
22795An error (such as memory fault)
22796@item @code{C}@var{CRC32}
22797A 32 bit cyclic redundancy check of the specified memory region.
22798@end table
22799
22800@item @code{q}@code{Offsets} --- query sect offs
9c16f35a
EZ
22801@cindex section offsets, remote request
22802@cindex @code{qOffsets} packet
8e04817f
AC
22803Get section offsets that the target used when re-locating the downloaded
22804image. @emph{Note: while a @code{Bss} offset is included in the
22805response, @value{GDBN} ignores this and instead applies the @code{Data}
22806offset to the @code{Bss} section.}
c906108c 22807
ee2d5c50
AC
22808Reply:
22809@table @samp
22810@item @code{Text=}@var{xxx}@code{;Data=}@var{yyy}@code{;Bss=}@var{zzz}
22811@end table
22812
22813@item @code{q}@code{P}@var{mode}@var{threadid} --- thread info request
9c16f35a
EZ
22814@cindex thread information, remote request
22815@cindex @code{qP} packet
8e04817f
AC
22816Returns information on @var{threadid}. Where: @var{mode} is a hex
22817encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
ee2d5c50
AC
22818
22819Reply:
22820@table @samp
22821@item *
22822@end table
22823
8e04817f 22824See @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 22825
ee2d5c50 22826@item @code{q}@code{Rcmd,}@var{command} --- remote command
9c16f35a
EZ
22827@cindex execute remote command, remote request
22828@cindex @code{qRcmd} packet
ee2d5c50 22829@var{command} (hex encoded) is passed to the local interpreter for
8e04817f
AC
22830execution. Invalid commands should be reported using the output string.
22831Before the final result packet, the target may also respond with a
ee2d5c50
AC
22832number of intermediate @code{O}@var{output} console output packets.
22833@emph{Implementors should note that providing access to a stubs's
22834interpreter may have security implications}.
22835
22836Reply:
22837@table @samp
22838@item OK
8e04817f 22839A command response with no output.
ee2d5c50 22840@item @var{OUTPUT}
8e04817f 22841A command response with the hex encoded output string @var{OUTPUT}.
ee2d5c50 22842@item @code{E}@var{NN}
8e04817f 22843Indicate a badly formed request.
ee2d5c50 22844@item @samp{}
8e04817f 22845When @samp{q}@samp{Rcmd} is not recognized.
ee2d5c50 22846@end table
9c16f35a 22847z
ee2d5c50 22848@item @code{qSymbol::} --- symbol lookup
9c16f35a
EZ
22849@cindex symbol lookup, remote request
22850@cindex @code{qSymbol} packet
8e04817f
AC
22851Notify the target that @value{GDBN} is prepared to serve symbol lookup
22852requests. Accept requests from the target for the values of symbols.
ee2d5c50
AC
22853
22854Reply:
22855@table @samp
22856@item @code{OK}
8e04817f 22857The target does not need to look up any (more) symbols.
ee2d5c50
AC
22858@item @code{qSymbol:}@var{sym_name}
22859The target requests the value of symbol @var{sym_name} (hex encoded).
22860@value{GDBN} may provide the value by using the
22861@code{qSymbol:}@var{sym_value}:@var{sym_name} message, described below.
22862@end table
22863
22864@item @code{qSymbol:}@var{sym_value}:@var{sym_name} --- symbol value
22865
22866Set the value of @var{sym_name} to @var{sym_value}.
22867
22868@var{sym_name} (hex encoded) is the name of a symbol whose value the
22869target has previously requested.
22870
22871@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
22872@value{GDBN} cannot supply a value for @var{sym_name}, then this field
22873will be empty.
22874
22875Reply:
22876@table @samp
22877@item @code{OK}
8e04817f 22878The target does not need to look up any (more) symbols.
ee2d5c50
AC
22879@item @code{qSymbol:}@var{sym_name}
22880The target requests the value of a new symbol @var{sym_name} (hex
22881encoded). @value{GDBN} will continue to supply the values of symbols
22882(if available), until the target ceases to request them.
22883@end table
eb12ee30 22884
649e03f6 22885@item @code{qPart}:@var{object}:@code{read}:@var{annex}:@var{offset},@var{length} --- read special data
9c16f35a
EZ
22886@cindex read special object, remote request
22887@cindex @code{qPart} packet
649e03f6
RM
22888Read uninterpreted bytes from the target's special data area
22889identified by the keyword @code{object}.
22890Request @var{length} bytes starting at @var{offset} bytes into the data.
22891The content and encoding of @var{annex} is specific to the object;
22892it can supply additional details about what data to access.
22893
22894Here are the specific requests of this form defined so far.
22895All @samp{@code{qPart}:@var{object}:@code{read}:@dots{}}
22896requests use the same reply formats, listed below.
22897
22898@table @asis
22899@item @code{qPart}:@code{auxv}:@code{read}::@var{offset},@var{length}
721c2651
EZ
22900Access the target's @dfn{auxiliary vector}. @xref{OS Information,
22901auxiliary vector}, and see @ref{Remote configuration,
22902read-aux-vector-packet}. Note @var{annex} must be empty.
649e03f6
RM
22903@end table
22904
22905Reply:
22906@table @asis
22907@item @code{OK}
22908The @var{offset} in the request is at the end of the data.
22909There is no more data to be read.
22910
22911@item @var{XX@dots{}}
22912Hex encoded data bytes read.
22913This may be fewer bytes than the @var{length} in the request.
22914
22915@item @code{E00}
22916The request was malformed, or @var{annex} was invalid.
22917
22918@item @code{E}@var{nn}
22919The offset was invalid, or there was an error encountered reading the data.
22920@var{nn} is a hex-encoded @code{errno} value.
22921
22922@item @code{""} (empty)
22923An empty reply indicates the @var{object} or @var{annex} string was not
22924recognized by the stub.
22925@end table
22926
22927@item @code{qPart}:@var{object}:@code{write}:@var{annex}:@var{offset}:@var{data@dots{}}
9c16f35a 22928@cindex write data into object, remote request
649e03f6
RM
22929Write uninterpreted bytes into the target's special data area
22930identified by the keyword @code{object},
22931starting at @var{offset} bytes into the data.
22932@var{data@dots{}} is the hex-encoded data to be written.
22933The content and encoding of @var{annex} is specific to the object;
22934it can supply additional details about what data to access.
22935
22936No requests of this form are presently in use. This specification
22937serves as a placeholder to document the common format that new
22938specific request specifications ought to use.
22939
22940Reply:
22941@table @asis
22942@item @var{nn}
22943@var{nn} (hex encoded) is the number of bytes written.
22944This may be fewer bytes than supplied in the request.
22945
22946@item @code{E00}
22947The request was malformed, or @var{annex} was invalid.
22948
22949@item @code{E}@var{nn}
22950The offset was invalid, or there was an error encountered writing the data.
22951@var{nn} is a hex-encoded @code{errno} value.
22952
22953@item @code{""} (empty)
22954An empty reply indicates the @var{object} or @var{annex} string was not
22955recognized by the stub, or that the object does not support writing.
22956@end table
22957
22958@item @code{qPart}:@var{object}:@var{operation}:@dots{}
22959Requests of this form may be added in the future. When a stub does
22960not recognize the @var{object} keyword, or its support for
22961@var{object} does not recognize the @var{operation} keyword,
22962the stub must respond with an empty packet.
83761cbd
KB
22963
22964@item @code{qGetTLSAddr}:@var{thread-id},@var{offset},@var{lm} --- get thread local storage address
9c16f35a
EZ
22965@cindex get thread-local storage address, remote request
22966@cindex @code{qGetTLSAddr} packet
83761cbd
KB
22967Fetch the address associated with thread local storage specified
22968by @var{thread-id}, @var{offset}, and @var{lm}.
22969
22970@var{thread-id} is the (big endian, hex encoded) thread id associated with the
22971thread for which to fetch the TLS address.
22972
22973@var{offset} is the (big endian, hex encoded) offset associated with the
22974thread local variable. (This offset is obtained from the debug
22975information associated with the variable.)
22976
22977@var{lm} is the (big endian, hex encoded) OS/ABI specific encoding of the
22978the load module associated with the thread local storage. For example,
22979a @sc{gnu}/Linux system will pass the link map address of the shared
22980object associated with the thread local storage under consideration.
22981Other operating environments may choose to represent the load module
22982differently, so the precise meaning of this parameter will vary.
22983
22984Reply:
22985@table @asis
68c71a2e 22986@item @var{XX@dots{}}
83761cbd
KB
22987Hex encoded (big endian) bytes representing the address of the thread
22988local storage requested.
22989
22990@item @code{E}@var{nn} (where @var{nn} are hex digits)
22991An error occurred.
22992
22993@item @code{""} (empty)
22994An empty reply indicates that @code{qGetTLSAddr} is not supported by the stub.
22995@end table
22996
0abb7bc7
EZ
22997Use of this request packet is controlled by the @code{set remote
22998get-thread-local-storage-address} command (@pxref{Remote
22999configuration, set remote get-thread-local-storage-address}).
23000
ee2d5c50
AC
23001@end table
23002
23003@node Register Packet Format
23004@section Register Packet Format
eb12ee30 23005
8e04817f 23006The following @samp{g}/@samp{G} packets have previously been defined.
ee2d5c50
AC
23007In the below, some thirty-two bit registers are transferred as
23008sixty-four bits. Those registers should be zero/sign extended (which?)
23009to fill the space allocated. Register bytes are transfered in target
23010byte order. The two nibbles within a register byte are transfered
23011most-significant - least-significant.
eb12ee30 23012
ee2d5c50 23013@table @r
eb12ee30 23014
8e04817f 23015@item MIPS32
ee2d5c50 23016
8e04817f
AC
23017All registers are transfered as thirty-two bit quantities in the order:
2301832 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
23019registers; fsr; fir; fp.
eb12ee30 23020
8e04817f 23021@item MIPS64
ee2d5c50 23022
8e04817f
AC
23023All registers are transfered as sixty-four bit quantities (including
23024thirty-two bit registers such as @code{sr}). The ordering is the same
23025as @code{MIPS32}.
eb12ee30 23026
ee2d5c50
AC
23027@end table
23028
23029@node Examples
23030@section Examples
eb12ee30 23031
8e04817f
AC
23032Example sequence of a target being re-started. Notice how the restart
23033does not get any direct output:
eb12ee30 23034
474c8240 23035@smallexample
d2c6833e
AC
23036-> @code{R00}
23037<- @code{+}
8e04817f 23038@emph{target restarts}
d2c6833e 23039-> @code{?}
8e04817f 23040<- @code{+}
d2c6833e
AC
23041<- @code{T001:1234123412341234}
23042-> @code{+}
474c8240 23043@end smallexample
eb12ee30 23044
8e04817f 23045Example sequence of a target being stepped by a single instruction:
eb12ee30 23046
474c8240 23047@smallexample
d2c6833e 23048-> @code{G1445@dots{}}
8e04817f 23049<- @code{+}
d2c6833e
AC
23050-> @code{s}
23051<- @code{+}
23052@emph{time passes}
23053<- @code{T001:1234123412341234}
8e04817f 23054-> @code{+}
d2c6833e 23055-> @code{g}
8e04817f 23056<- @code{+}
d2c6833e
AC
23057<- @code{1455@dots{}}
23058-> @code{+}
474c8240 23059@end smallexample
eb12ee30 23060
0ce1b118
CV
23061@node File-I/O remote protocol extension
23062@section File-I/O remote protocol extension
23063@cindex File-I/O remote protocol extension
23064
23065@menu
23066* File-I/O Overview::
23067* Protocol basics::
1d8b2f28
JB
23068* The F request packet::
23069* The F reply packet::
0ce1b118
CV
23070* Memory transfer::
23071* The Ctrl-C message::
23072* Console I/O::
23073* The isatty call::
23074* The system call::
23075* List of supported calls::
23076* Protocol specific representation of datatypes::
23077* Constants::
23078* File-I/O Examples::
23079@end menu
23080
23081@node File-I/O Overview
23082@subsection File-I/O Overview
23083@cindex file-i/o overview
23084
9c16f35a
EZ
23085The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
23086target to use the host's file system and console I/O when calling various
0ce1b118
CV
23087system calls. System calls on the target system are translated into a
23088remote protocol packet to the host system which then performs the needed
23089actions and returns with an adequate response packet to the target system.
23090This simulates file system operations even on targets that lack file systems.
23091
23092The protocol is defined host- and target-system independent. It uses
9c16f35a 23093its own independent representation of datatypes and values. Both,
0ce1b118
CV
23094@value{GDBN} and the target's @value{GDBN} stub are responsible for
23095translating the system dependent values into the unified protocol values
23096when data is transmitted.
23097
23098The communication is synchronous. A system call is possible only
23099when GDB is waiting for the @samp{C}, @samp{c}, @samp{S} or @samp{s}
23100packets. While @value{GDBN} handles the request for a system call,
23101the target is stopped to allow deterministic access to the target's
23102memory. Therefore File-I/O is not interuptible by target signals. It
23103is possible to interrupt File-I/O by a user interrupt (Ctrl-C), though.
23104
23105The target's request to perform a host system call does not finish
23106the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
23107after finishing the system call, the target returns to continuing the
23108previous activity (continue, step). No additional continue or step
23109request from @value{GDBN} is required.
23110
23111@smallexample
f7dc1244 23112(@value{GDBP}) continue
0ce1b118
CV
23113 <- target requests 'system call X'
23114 target is stopped, @value{GDBN} executes system call
23115 -> GDB returns result
23116 ... target continues, GDB returns to wait for the target
23117 <- target hits breakpoint and sends a Txx packet
23118@end smallexample
23119
23120The protocol is only used for files on the host file system and
23121for I/O on the console. Character or block special devices, pipes,
23122named pipes or sockets or any other communication method on the host
23123system are not supported by this protocol.
23124
23125@node Protocol basics
23126@subsection Protocol basics
23127@cindex protocol basics, file-i/o
23128
23129The File-I/O protocol uses the @code{F} packet, as request as well
23130as as reply packet. Since a File-I/O system call can only occur when
b383017d 23131@value{GDBN} is waiting for the continuing or stepping target, the
0ce1b118
CV
23132File-I/O request is a reply that @value{GDBN} has to expect as a result
23133of a former @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
23134This @code{F} packet contains all information needed to allow @value{GDBN}
23135to call the appropriate host system call:
23136
23137@itemize @bullet
b383017d 23138@item
0ce1b118
CV
23139A unique identifier for the requested system call.
23140
23141@item
23142All parameters to the system call. Pointers are given as addresses
23143in the target memory address space. Pointers to strings are given as
b383017d 23144pointer/length pair. Numerical values are given as they are.
0ce1b118
CV
23145Numerical control values are given in a protocol specific representation.
23146
23147@end itemize
23148
23149At that point @value{GDBN} has to perform the following actions.
23150
23151@itemize @bullet
b383017d 23152@item
0ce1b118
CV
23153If parameter pointer values are given, which point to data needed as input
23154to a system call, @value{GDBN} requests this data from the target with a
23155standard @code{m} packet request. This additional communication has to be
23156expected by the target implementation and is handled as any other @code{m}
23157packet.
23158
23159@item
23160@value{GDBN} translates all value from protocol representation to host
23161representation as needed. Datatypes are coerced into the host types.
23162
23163@item
23164@value{GDBN} calls the system call
23165
23166@item
23167It then coerces datatypes back to protocol representation.
23168
23169@item
23170If pointer parameters in the request packet point to buffer space in which
23171a system call is expected to copy data to, the data is transmitted to the
23172target using a @code{M} or @code{X} packet. This packet has to be expected
23173by the target implementation and is handled as any other @code{M} or @code{X}
23174packet.
23175
23176@end itemize
23177
23178Eventually @value{GDBN} replies with another @code{F} packet which contains all
23179necessary information for the target to continue. This at least contains
23180
23181@itemize @bullet
23182@item
23183Return value.
23184
23185@item
23186@code{errno}, if has been changed by the system call.
23187
23188@item
23189``Ctrl-C'' flag.
23190
23191@end itemize
23192
23193After having done the needed type and value coercion, the target continues
23194the latest continue or step action.
23195
1d8b2f28 23196@node The F request packet
0ce1b118
CV
23197@subsection The @code{F} request packet
23198@cindex file-i/o request packet
23199@cindex @code{F} request packet
23200
23201The @code{F} request packet has the following format:
23202
23203@table @samp
23204
23205@smallexample
23206@code{F}@var{call-id}@code{,}@var{parameter@dots{}}
23207@end smallexample
23208
23209@var{call-id} is the identifier to indicate the host system call to be called.
23210This is just the name of the function.
23211
23212@var{parameter@dots{}} are the parameters to the system call.
23213
b383017d 23214@end table
0ce1b118
CV
23215
23216Parameters are hexadecimal integer values, either the real values in case
23217of scalar datatypes, as pointers to target buffer space in case of compound
23218datatypes and unspecified memory areas or as pointer/length pairs in case
23219of string parameters. These are appended to the call-id, each separated
23220from its predecessor by a comma. All values are transmitted in ASCII
23221string representation, pointer/length pairs separated by a slash.
23222
1d8b2f28 23223@node The F reply packet
0ce1b118
CV
23224@subsection The @code{F} reply packet
23225@cindex file-i/o reply packet
23226@cindex @code{F} reply packet
23227
23228The @code{F} reply packet has the following format:
23229
23230@table @samp
23231
23232@smallexample
23233@code{F}@var{retcode}@code{,}@var{errno}@code{,}@var{Ctrl-C flag}@code{;}@var{call specific attachment}
23234@end smallexample
23235
23236@var{retcode} is the return code of the system call as hexadecimal value.
23237
23238@var{errno} is the errno set by the call, in protocol specific representation.
23239This parameter can be omitted if the call was successful.
23240
23241@var{Ctrl-C flag} is only send if the user requested a break. In this
23242case, @var{errno} must be send as well, even if the call was successful.
23243The @var{Ctrl-C flag} itself consists of the character 'C':
23244
23245@smallexample
23246F0,0,C
23247@end smallexample
23248
23249@noindent
23250or, if the call was interupted before the host call has been performed:
23251
23252@smallexample
23253F-1,4,C
23254@end smallexample
23255
23256@noindent
23257assuming 4 is the protocol specific representation of @code{EINTR}.
23258
23259@end table
23260
23261@node Memory transfer
23262@subsection Memory transfer
23263@cindex memory transfer, in file-i/o protocol
23264
23265Structured data which is transferred using a memory read or write as e.g.@:
23266a @code{struct stat} is expected to be in a protocol specific format with
23267all scalar multibyte datatypes being big endian. This should be done by
23268the target before the @code{F} packet is sent resp.@: by @value{GDBN} before
23269it transfers memory to the target. Transferred pointers to structured
23270data should point to the already coerced data at any time.
23271
23272@node The Ctrl-C message
23273@subsection The Ctrl-C message
23274@cindex ctrl-c message, in file-i/o protocol
23275
23276A special case is, if the @var{Ctrl-C flag} is set in the @value{GDBN}
23277reply packet. In this case the target should behave, as if it had
23278gotten a break message. The meaning for the target is ``system call
23279interupted by @code{SIGINT}''. Consequentially, the target should actually stop
23280(as with a break message) and return to @value{GDBN} with a @code{T02}
b383017d 23281packet. In this case, it's important for the target to know, in which
0ce1b118
CV
23282state the system call was interrupted. Since this action is by design
23283not an atomic operation, we have to differ between two cases:
23284
23285@itemize @bullet
23286@item
23287The system call hasn't been performed on the host yet.
23288
23289@item
23290The system call on the host has been finished.
23291
23292@end itemize
23293
23294These two states can be distinguished by the target by the value of the
23295returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
23296call hasn't been performed. This is equivalent to the @code{EINTR} handling
23297on POSIX systems. In any other case, the target may presume that the
23298system call has been finished --- successful or not --- and should behave
23299as if the break message arrived right after the system call.
23300
23301@value{GDBN} must behave reliable. If the system call has not been called
23302yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
23303@code{errno} in the packet. If the system call on the host has been finished
23304before the user requests a break, the full action must be finshed by
23305@value{GDBN}. This requires sending @code{M} or @code{X} packets as they fit.
23306The @code{F} packet may only be send when either nothing has happened
23307or the full action has been completed.
23308
23309@node Console I/O
23310@subsection Console I/O
23311@cindex console i/o as part of file-i/o
23312
23313By default and if not explicitely closed by the target system, the file
23314descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
23315on the @value{GDBN} console is handled as any other file output operation
23316(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
23317by @value{GDBN} so that after the target read request from file descriptor
233180 all following typing is buffered until either one of the following
23319conditions is met:
23320
23321@itemize @bullet
23322@item
23323The user presses @kbd{Ctrl-C}. The behaviour is as explained above, the
23324@code{read}
23325system call is treated as finished.
23326
23327@item
23328The user presses @kbd{Enter}. This is treated as end of input with a trailing
23329line feed.
23330
23331@item
23332The user presses @kbd{Ctrl-D}. This is treated as end of input. No trailing
23333character, especially no Ctrl-D is appended to the input.
23334
23335@end itemize
23336
23337If the user has typed more characters as fit in the buffer given to
23338the read call, the trailing characters are buffered in @value{GDBN} until
23339either another @code{read(0, @dots{})} is requested by the target or debugging
23340is stopped on users request.
23341
23342@node The isatty call
2eecc4ab 23343@subsection The @samp{isatty} function call
0ce1b118
CV
23344@cindex isatty call, file-i/o protocol
23345
23346A special case in this protocol is the library call @code{isatty} which
9c16f35a 23347is implemented as its own call inside of this protocol. It returns
0ce1b118
CV
233481 to the target if the file descriptor given as parameter is attached
23349to the @value{GDBN} console, 0 otherwise. Implementing through system calls
23350would require implementing @code{ioctl} and would be more complex than
23351needed.
23352
23353@node The system call
2eecc4ab 23354@subsection The @samp{system} function call
0ce1b118
CV
23355@cindex system call, file-i/o protocol
23356
23357The other special case in this protocol is the @code{system} call which
9c16f35a 23358is implemented as its own call, too. @value{GDBN} is taking over the full
0ce1b118
CV
23359task of calling the necessary host calls to perform the @code{system}
23360call. The return value of @code{system} is simplified before it's returned
23361to the target. Basically, the only signal transmitted back is @code{EINTR}
23362in case the user pressed @kbd{Ctrl-C}. Otherwise the return value consists
23363entirely of the exit status of the called command.
23364
9c16f35a
EZ
23365Due to security concerns, the @code{system} call is by default refused
23366by @value{GDBN}. The user has to allow this call explicitly with the
23367@kbd{set remote system-call-allowed 1} command.
0ce1b118 23368
9c16f35a
EZ
23369@table @code
23370@item set remote system-call-allowed
23371@kindex set remote system-call-allowed
23372Control whether to allow the @code{system} calls in the File I/O
23373protocol for the remote target. The default is zero (disabled).
0ce1b118 23374
9c16f35a 23375@item show remote system-call-allowed
0ce1b118 23376@kindex show remote system-call-allowed
9c16f35a
EZ
23377Show the current setting of system calls for the remote File I/O
23378protocol.
0ce1b118
CV
23379@end table
23380
23381@node List of supported calls
23382@subsection List of supported calls
23383@cindex list of supported file-i/o calls
23384
23385@menu
23386* open::
23387* close::
23388* read::
23389* write::
23390* lseek::
23391* rename::
23392* unlink::
23393* stat/fstat::
23394* gettimeofday::
23395* isatty::
23396* system::
23397@end menu
23398
23399@node open
23400@unnumberedsubsubsec open
23401@cindex open, file-i/o system call
23402
23403@smallexample
23404@exdent Synopsis:
23405int open(const char *pathname, int flags);
23406int open(const char *pathname, int flags, mode_t mode);
23407
b383017d 23408@exdent Request:
0ce1b118
CV
23409Fopen,pathptr/len,flags,mode
23410@end smallexample
23411
23412@noindent
23413@code{flags} is the bitwise or of the following values:
23414
23415@table @code
b383017d 23416@item O_CREAT
0ce1b118
CV
23417If the file does not exist it will be created. The host
23418rules apply as far as file ownership and time stamps
23419are concerned.
23420
b383017d 23421@item O_EXCL
0ce1b118
CV
23422When used with O_CREAT, if the file already exists it is
23423an error and open() fails.
23424
b383017d 23425@item O_TRUNC
0ce1b118
CV
23426If the file already exists and the open mode allows
23427writing (O_RDWR or O_WRONLY is given) it will be
23428truncated to length 0.
23429
b383017d 23430@item O_APPEND
0ce1b118
CV
23431The file is opened in append mode.
23432
b383017d 23433@item O_RDONLY
0ce1b118
CV
23434The file is opened for reading only.
23435
b383017d 23436@item O_WRONLY
0ce1b118
CV
23437The file is opened for writing only.
23438
b383017d 23439@item O_RDWR
0ce1b118
CV
23440The file is opened for reading and writing.
23441
23442@noindent
23443Each other bit is silently ignored.
23444
23445@end table
23446
23447@noindent
23448@code{mode} is the bitwise or of the following values:
23449
23450@table @code
b383017d 23451@item S_IRUSR
0ce1b118
CV
23452User has read permission.
23453
b383017d 23454@item S_IWUSR
0ce1b118
CV
23455User has write permission.
23456
b383017d 23457@item S_IRGRP
0ce1b118
CV
23458Group has read permission.
23459
b383017d 23460@item S_IWGRP
0ce1b118
CV
23461Group has write permission.
23462
b383017d 23463@item S_IROTH
0ce1b118
CV
23464Others have read permission.
23465
b383017d 23466@item S_IWOTH
0ce1b118
CV
23467Others have write permission.
23468
23469@noindent
23470Each other bit is silently ignored.
23471
23472@end table
23473
23474@smallexample
23475@exdent Return value:
23476open returns the new file descriptor or -1 if an error
23477occured.
23478
23479@exdent Errors:
23480@end smallexample
23481
23482@table @code
b383017d 23483@item EEXIST
0ce1b118
CV
23484pathname already exists and O_CREAT and O_EXCL were used.
23485
b383017d 23486@item EISDIR
0ce1b118
CV
23487pathname refers to a directory.
23488
b383017d 23489@item EACCES
0ce1b118
CV
23490The requested access is not allowed.
23491
23492@item ENAMETOOLONG
23493pathname was too long.
23494
b383017d 23495@item ENOENT
0ce1b118
CV
23496A directory component in pathname does not exist.
23497
b383017d 23498@item ENODEV
0ce1b118
CV
23499pathname refers to a device, pipe, named pipe or socket.
23500
b383017d 23501@item EROFS
0ce1b118
CV
23502pathname refers to a file on a read-only filesystem and
23503write access was requested.
23504
b383017d 23505@item EFAULT
0ce1b118
CV
23506pathname is an invalid pointer value.
23507
b383017d 23508@item ENOSPC
0ce1b118
CV
23509No space on device to create the file.
23510
b383017d 23511@item EMFILE
0ce1b118
CV
23512The process already has the maximum number of files open.
23513
b383017d 23514@item ENFILE
0ce1b118
CV
23515The limit on the total number of files open on the system
23516has been reached.
23517
b383017d 23518@item EINTR
0ce1b118
CV
23519The call was interrupted by the user.
23520@end table
23521
23522@node close
23523@unnumberedsubsubsec close
23524@cindex close, file-i/o system call
23525
23526@smallexample
b383017d 23527@exdent Synopsis:
0ce1b118
CV
23528int close(int fd);
23529
b383017d 23530@exdent Request:
0ce1b118
CV
23531Fclose,fd
23532
23533@exdent Return value:
23534close returns zero on success, or -1 if an error occurred.
23535
23536@exdent Errors:
23537@end smallexample
23538
23539@table @code
b383017d 23540@item EBADF
0ce1b118
CV
23541fd isn't a valid open file descriptor.
23542
b383017d 23543@item EINTR
0ce1b118
CV
23544The call was interrupted by the user.
23545@end table
23546
23547@node read
23548@unnumberedsubsubsec read
23549@cindex read, file-i/o system call
23550
23551@smallexample
b383017d 23552@exdent Synopsis:
0ce1b118
CV
23553int read(int fd, void *buf, unsigned int count);
23554
b383017d 23555@exdent Request:
0ce1b118
CV
23556Fread,fd,bufptr,count
23557
23558@exdent Return value:
23559On success, the number of bytes read is returned.
23560Zero indicates end of file. If count is zero, read
b383017d 23561returns zero as well. On error, -1 is returned.
0ce1b118
CV
23562
23563@exdent Errors:
23564@end smallexample
23565
23566@table @code
b383017d 23567@item EBADF
0ce1b118
CV
23568fd is not a valid file descriptor or is not open for
23569reading.
23570
b383017d 23571@item EFAULT
0ce1b118
CV
23572buf is an invalid pointer value.
23573
b383017d 23574@item EINTR
0ce1b118
CV
23575The call was interrupted by the user.
23576@end table
23577
23578@node write
23579@unnumberedsubsubsec write
23580@cindex write, file-i/o system call
23581
23582@smallexample
b383017d 23583@exdent Synopsis:
0ce1b118
CV
23584int write(int fd, const void *buf, unsigned int count);
23585
b383017d 23586@exdent Request:
0ce1b118
CV
23587Fwrite,fd,bufptr,count
23588
23589@exdent Return value:
23590On success, the number of bytes written are returned.
23591Zero indicates nothing was written. On error, -1
23592is returned.
23593
23594@exdent Errors:
23595@end smallexample
23596
23597@table @code
b383017d 23598@item EBADF
0ce1b118
CV
23599fd is not a valid file descriptor or is not open for
23600writing.
23601
b383017d 23602@item EFAULT
0ce1b118
CV
23603buf is an invalid pointer value.
23604
b383017d 23605@item EFBIG
0ce1b118
CV
23606An attempt was made to write a file that exceeds the
23607host specific maximum file size allowed.
23608
b383017d 23609@item ENOSPC
0ce1b118
CV
23610No space on device to write the data.
23611
b383017d 23612@item EINTR
0ce1b118
CV
23613The call was interrupted by the user.
23614@end table
23615
23616@node lseek
23617@unnumberedsubsubsec lseek
23618@cindex lseek, file-i/o system call
23619
23620@smallexample
b383017d 23621@exdent Synopsis:
0ce1b118
CV
23622long lseek (int fd, long offset, int flag);
23623
b383017d 23624@exdent Request:
0ce1b118
CV
23625Flseek,fd,offset,flag
23626@end smallexample
23627
23628@code{flag} is one of:
23629
23630@table @code
b383017d 23631@item SEEK_SET
0ce1b118
CV
23632The offset is set to offset bytes.
23633
b383017d 23634@item SEEK_CUR
0ce1b118
CV
23635The offset is set to its current location plus offset
23636bytes.
23637
b383017d 23638@item SEEK_END
0ce1b118
CV
23639The offset is set to the size of the file plus offset
23640bytes.
23641@end table
23642
23643@smallexample
23644@exdent Return value:
23645On success, the resulting unsigned offset in bytes from
23646the beginning of the file is returned. Otherwise, a
23647value of -1 is returned.
23648
23649@exdent Errors:
23650@end smallexample
23651
23652@table @code
b383017d 23653@item EBADF
0ce1b118
CV
23654fd is not a valid open file descriptor.
23655
b383017d 23656@item ESPIPE
0ce1b118
CV
23657fd is associated with the @value{GDBN} console.
23658
b383017d 23659@item EINVAL
0ce1b118
CV
23660flag is not a proper value.
23661
b383017d 23662@item EINTR
0ce1b118
CV
23663The call was interrupted by the user.
23664@end table
23665
23666@node rename
23667@unnumberedsubsubsec rename
23668@cindex rename, file-i/o system call
23669
23670@smallexample
b383017d 23671@exdent Synopsis:
0ce1b118
CV
23672int rename(const char *oldpath, const char *newpath);
23673
b383017d 23674@exdent Request:
0ce1b118
CV
23675Frename,oldpathptr/len,newpathptr/len
23676
23677@exdent Return value:
23678On success, zero is returned. On error, -1 is returned.
23679
23680@exdent Errors:
23681@end smallexample
23682
23683@table @code
b383017d 23684@item EISDIR
0ce1b118
CV
23685newpath is an existing directory, but oldpath is not a
23686directory.
23687
b383017d 23688@item EEXIST
0ce1b118
CV
23689newpath is a non-empty directory.
23690
b383017d 23691@item EBUSY
0ce1b118
CV
23692oldpath or newpath is a directory that is in use by some
23693process.
23694
b383017d 23695@item EINVAL
0ce1b118
CV
23696An attempt was made to make a directory a subdirectory
23697of itself.
23698
b383017d 23699@item ENOTDIR
0ce1b118
CV
23700A component used as a directory in oldpath or new
23701path is not a directory. Or oldpath is a directory
23702and newpath exists but is not a directory.
23703
b383017d 23704@item EFAULT
0ce1b118
CV
23705oldpathptr or newpathptr are invalid pointer values.
23706
b383017d 23707@item EACCES
0ce1b118
CV
23708No access to the file or the path of the file.
23709
23710@item ENAMETOOLONG
b383017d 23711
0ce1b118
CV
23712oldpath or newpath was too long.
23713
b383017d 23714@item ENOENT
0ce1b118
CV
23715A directory component in oldpath or newpath does not exist.
23716
b383017d 23717@item EROFS
0ce1b118
CV
23718The file is on a read-only filesystem.
23719
b383017d 23720@item ENOSPC
0ce1b118
CV
23721The device containing the file has no room for the new
23722directory entry.
23723
b383017d 23724@item EINTR
0ce1b118
CV
23725The call was interrupted by the user.
23726@end table
23727
23728@node unlink
23729@unnumberedsubsubsec unlink
23730@cindex unlink, file-i/o system call
23731
23732@smallexample
b383017d 23733@exdent Synopsis:
0ce1b118
CV
23734int unlink(const char *pathname);
23735
b383017d 23736@exdent Request:
0ce1b118
CV
23737Funlink,pathnameptr/len
23738
23739@exdent Return value:
23740On success, zero is returned. On error, -1 is returned.
23741
23742@exdent Errors:
23743@end smallexample
23744
23745@table @code
b383017d 23746@item EACCES
0ce1b118
CV
23747No access to the file or the path of the file.
23748
b383017d 23749@item EPERM
0ce1b118
CV
23750The system does not allow unlinking of directories.
23751
b383017d 23752@item EBUSY
0ce1b118
CV
23753The file pathname cannot be unlinked because it's
23754being used by another process.
23755
b383017d 23756@item EFAULT
0ce1b118
CV
23757pathnameptr is an invalid pointer value.
23758
23759@item ENAMETOOLONG
23760pathname was too long.
23761
b383017d 23762@item ENOENT
0ce1b118
CV
23763A directory component in pathname does not exist.
23764
b383017d 23765@item ENOTDIR
0ce1b118
CV
23766A component of the path is not a directory.
23767
b383017d 23768@item EROFS
0ce1b118
CV
23769The file is on a read-only filesystem.
23770
b383017d 23771@item EINTR
0ce1b118
CV
23772The call was interrupted by the user.
23773@end table
23774
23775@node stat/fstat
23776@unnumberedsubsubsec stat/fstat
23777@cindex fstat, file-i/o system call
23778@cindex stat, file-i/o system call
23779
23780@smallexample
b383017d 23781@exdent Synopsis:
0ce1b118
CV
23782int stat(const char *pathname, struct stat *buf);
23783int fstat(int fd, struct stat *buf);
23784
b383017d 23785@exdent Request:
0ce1b118
CV
23786Fstat,pathnameptr/len,bufptr
23787Ffstat,fd,bufptr
23788
23789@exdent Return value:
23790On success, zero is returned. On error, -1 is returned.
23791
23792@exdent Errors:
23793@end smallexample
23794
23795@table @code
b383017d 23796@item EBADF
0ce1b118
CV
23797fd is not a valid open file.
23798
b383017d 23799@item ENOENT
0ce1b118
CV
23800A directory component in pathname does not exist or the
23801path is an empty string.
23802
b383017d 23803@item ENOTDIR
0ce1b118
CV
23804A component of the path is not a directory.
23805
b383017d 23806@item EFAULT
0ce1b118
CV
23807pathnameptr is an invalid pointer value.
23808
b383017d 23809@item EACCES
0ce1b118
CV
23810No access to the file or the path of the file.
23811
23812@item ENAMETOOLONG
23813pathname was too long.
23814
b383017d 23815@item EINTR
0ce1b118
CV
23816The call was interrupted by the user.
23817@end table
23818
23819@node gettimeofday
23820@unnumberedsubsubsec gettimeofday
23821@cindex gettimeofday, file-i/o system call
23822
23823@smallexample
b383017d 23824@exdent Synopsis:
0ce1b118
CV
23825int gettimeofday(struct timeval *tv, void *tz);
23826
b383017d 23827@exdent Request:
0ce1b118
CV
23828Fgettimeofday,tvptr,tzptr
23829
23830@exdent Return value:
23831On success, 0 is returned, -1 otherwise.
23832
23833@exdent Errors:
23834@end smallexample
23835
23836@table @code
b383017d 23837@item EINVAL
0ce1b118
CV
23838tz is a non-NULL pointer.
23839
b383017d 23840@item EFAULT
0ce1b118
CV
23841tvptr and/or tzptr is an invalid pointer value.
23842@end table
23843
23844@node isatty
23845@unnumberedsubsubsec isatty
23846@cindex isatty, file-i/o system call
23847
23848@smallexample
b383017d 23849@exdent Synopsis:
0ce1b118
CV
23850int isatty(int fd);
23851
b383017d 23852@exdent Request:
0ce1b118
CV
23853Fisatty,fd
23854
23855@exdent Return value:
23856Returns 1 if fd refers to the @value{GDBN} console, 0 otherwise.
23857
23858@exdent Errors:
23859@end smallexample
23860
23861@table @code
b383017d 23862@item EINTR
0ce1b118
CV
23863The call was interrupted by the user.
23864@end table
23865
23866@node system
23867@unnumberedsubsubsec system
23868@cindex system, file-i/o system call
23869
23870@smallexample
b383017d 23871@exdent Synopsis:
0ce1b118
CV
23872int system(const char *command);
23873
b383017d 23874@exdent Request:
0ce1b118
CV
23875Fsystem,commandptr/len
23876
23877@exdent Return value:
23878The value returned is -1 on error and the return status
23879of the command otherwise. Only the exit status of the
23880command is returned, which is extracted from the hosts
23881system return value by calling WEXITSTATUS(retval).
23882In case /bin/sh could not be executed, 127 is returned.
23883
23884@exdent Errors:
23885@end smallexample
23886
23887@table @code
b383017d 23888@item EINTR
0ce1b118
CV
23889The call was interrupted by the user.
23890@end table
23891
23892@node Protocol specific representation of datatypes
23893@subsection Protocol specific representation of datatypes
23894@cindex protocol specific representation of datatypes, in file-i/o protocol
23895
23896@menu
23897* Integral datatypes::
23898* Pointer values::
23899* struct stat::
23900* struct timeval::
23901@end menu
23902
23903@node Integral datatypes
23904@unnumberedsubsubsec Integral datatypes
23905@cindex integral datatypes, in file-i/o protocol
23906
23907The integral datatypes used in the system calls are
23908
23909@smallexample
23910int@r{,} unsigned int@r{,} long@r{,} unsigned long@r{,} mode_t @r{and} time_t
23911@end smallexample
23912
23913@code{Int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
23914implemented as 32 bit values in this protocol.
23915
b383017d
RM
23916@code{Long} and @code{unsigned long} are implemented as 64 bit types.
23917
0ce1b118
CV
23918@xref{Limits}, for corresponding MIN and MAX values (similar to those
23919in @file{limits.h}) to allow range checking on host and target.
23920
23921@code{time_t} datatypes are defined as seconds since the Epoch.
23922
23923All integral datatypes transferred as part of a memory read or write of a
23924structured datatype e.g.@: a @code{struct stat} have to be given in big endian
23925byte order.
23926
23927@node Pointer values
23928@unnumberedsubsubsec Pointer values
23929@cindex pointer values, in file-i/o protocol
23930
23931Pointers to target data are transmitted as they are. An exception
23932is made for pointers to buffers for which the length isn't
23933transmitted as part of the function call, namely strings. Strings
23934are transmitted as a pointer/length pair, both as hex values, e.g.@:
23935
23936@smallexample
23937@code{1aaf/12}
23938@end smallexample
23939
23940@noindent
23941which is a pointer to data of length 18 bytes at position 0x1aaf.
23942The length is defined as the full string length in bytes, including
23943the trailing null byte. Example:
23944
23945@smallexample
23946``hello, world'' at address 0x123456
23947@end smallexample
23948
23949@noindent
23950is transmitted as
23951
23952@smallexample
23953@code{123456/d}
23954@end smallexample
23955
23956@node struct stat
23957@unnumberedsubsubsec struct stat
23958@cindex struct stat, in file-i/o protocol
23959
23960The buffer of type struct stat used by the target and @value{GDBN} is defined
23961as follows:
23962
23963@smallexample
23964struct stat @{
23965 unsigned int st_dev; /* device */
23966 unsigned int st_ino; /* inode */
23967 mode_t st_mode; /* protection */
23968 unsigned int st_nlink; /* number of hard links */
23969 unsigned int st_uid; /* user ID of owner */
23970 unsigned int st_gid; /* group ID of owner */
23971 unsigned int st_rdev; /* device type (if inode device) */
23972 unsigned long st_size; /* total size, in bytes */
23973 unsigned long st_blksize; /* blocksize for filesystem I/O */
23974 unsigned long st_blocks; /* number of blocks allocated */
23975 time_t st_atime; /* time of last access */
23976 time_t st_mtime; /* time of last modification */
23977 time_t st_ctime; /* time of last change */
23978@};
23979@end smallexample
23980
23981The integral datatypes are conforming to the definitions given in the
23982approriate section (see @ref{Integral datatypes}, for details) so this
23983structure is of size 64 bytes.
23984
23985The values of several fields have a restricted meaning and/or
23986range of values.
23987
23988@smallexample
23989st_dev: 0 file
23990 1 console
23991
23992st_ino: No valid meaning for the target. Transmitted unchanged.
23993
23994st_mode: Valid mode bits are described in Appendix C. Any other
23995 bits have currently no meaning for the target.
23996
23997st_uid: No valid meaning for the target. Transmitted unchanged.
23998
23999st_gid: No valid meaning for the target. Transmitted unchanged.
24000
24001st_rdev: No valid meaning for the target. Transmitted unchanged.
24002
24003st_atime, st_mtime, st_ctime:
24004 These values have a host and file system dependent
24005 accuracy. Especially on Windows hosts the file systems
24006 don't support exact timing values.
24007@end smallexample
24008
24009The target gets a struct stat of the above representation and is
24010responsible to coerce it to the target representation before
24011continuing.
24012
24013Note that due to size differences between the host and target
24014representation of stat members, these members could eventually
24015get truncated on the target.
24016
24017@node struct timeval
24018@unnumberedsubsubsec struct timeval
24019@cindex struct timeval, in file-i/o protocol
24020
24021The buffer of type struct timeval used by the target and @value{GDBN}
24022is defined as follows:
24023
24024@smallexample
b383017d 24025struct timeval @{
0ce1b118
CV
24026 time_t tv_sec; /* second */
24027 long tv_usec; /* microsecond */
24028@};
24029@end smallexample
24030
24031The integral datatypes are conforming to the definitions given in the
24032approriate section (see @ref{Integral datatypes}, for details) so this
24033structure is of size 8 bytes.
24034
24035@node Constants
24036@subsection Constants
24037@cindex constants, in file-i/o protocol
24038
24039The following values are used for the constants inside of the
24040protocol. @value{GDBN} and target are resposible to translate these
24041values before and after the call as needed.
24042
24043@menu
24044* Open flags::
24045* mode_t values::
24046* Errno values::
24047* Lseek flags::
24048* Limits::
24049@end menu
24050
24051@node Open flags
24052@unnumberedsubsubsec Open flags
24053@cindex open flags, in file-i/o protocol
24054
24055All values are given in hexadecimal representation.
24056
24057@smallexample
24058 O_RDONLY 0x0
24059 O_WRONLY 0x1
24060 O_RDWR 0x2
24061 O_APPEND 0x8
24062 O_CREAT 0x200
24063 O_TRUNC 0x400
24064 O_EXCL 0x800
24065@end smallexample
24066
24067@node mode_t values
24068@unnumberedsubsubsec mode_t values
24069@cindex mode_t values, in file-i/o protocol
24070
24071All values are given in octal representation.
24072
24073@smallexample
24074 S_IFREG 0100000
24075 S_IFDIR 040000
24076 S_IRUSR 0400
24077 S_IWUSR 0200
24078 S_IXUSR 0100
24079 S_IRGRP 040
24080 S_IWGRP 020
24081 S_IXGRP 010
24082 S_IROTH 04
24083 S_IWOTH 02
24084 S_IXOTH 01
24085@end smallexample
24086
24087@node Errno values
24088@unnumberedsubsubsec Errno values
24089@cindex errno values, in file-i/o protocol
24090
24091All values are given in decimal representation.
24092
24093@smallexample
24094 EPERM 1
24095 ENOENT 2
24096 EINTR 4
24097 EBADF 9
24098 EACCES 13
24099 EFAULT 14
24100 EBUSY 16
24101 EEXIST 17
24102 ENODEV 19
24103 ENOTDIR 20
24104 EISDIR 21
24105 EINVAL 22
24106 ENFILE 23
24107 EMFILE 24
24108 EFBIG 27
24109 ENOSPC 28
24110 ESPIPE 29
24111 EROFS 30
24112 ENAMETOOLONG 91
24113 EUNKNOWN 9999
24114@end smallexample
24115
24116 EUNKNOWN is used as a fallback error value if a host system returns
24117 any error value not in the list of supported error numbers.
24118
24119@node Lseek flags
24120@unnumberedsubsubsec Lseek flags
24121@cindex lseek flags, in file-i/o protocol
24122
24123@smallexample
24124 SEEK_SET 0
24125 SEEK_CUR 1
24126 SEEK_END 2
24127@end smallexample
24128
24129@node Limits
24130@unnumberedsubsubsec Limits
24131@cindex limits, in file-i/o protocol
24132
24133All values are given in decimal representation.
24134
24135@smallexample
24136 INT_MIN -2147483648
24137 INT_MAX 2147483647
24138 UINT_MAX 4294967295
24139 LONG_MIN -9223372036854775808
24140 LONG_MAX 9223372036854775807
24141 ULONG_MAX 18446744073709551615
24142@end smallexample
24143
24144@node File-I/O Examples
24145@subsection File-I/O Examples
24146@cindex file-i/o examples
24147
24148Example sequence of a write call, file descriptor 3, buffer is at target
24149address 0x1234, 6 bytes should be written:
24150
24151@smallexample
24152<- @code{Fwrite,3,1234,6}
24153@emph{request memory read from target}
24154-> @code{m1234,6}
24155<- XXXXXX
24156@emph{return "6 bytes written"}
24157-> @code{F6}
24158@end smallexample
24159
24160Example sequence of a read call, file descriptor 3, buffer is at target
24161address 0x1234, 6 bytes should be read:
24162
24163@smallexample
24164<- @code{Fread,3,1234,6}
24165@emph{request memory write to target}
24166-> @code{X1234,6:XXXXXX}
24167@emph{return "6 bytes read"}
24168-> @code{F6}
24169@end smallexample
24170
24171Example sequence of a read call, call fails on the host due to invalid
24172file descriptor (EBADF):
24173
24174@smallexample
24175<- @code{Fread,3,1234,6}
24176-> @code{F-1,9}
24177@end smallexample
24178
24179Example sequence of a read call, user presses Ctrl-C before syscall on
24180host is called:
24181
24182@smallexample
24183<- @code{Fread,3,1234,6}
24184-> @code{F-1,4,C}
24185<- @code{T02}
24186@end smallexample
24187
24188Example sequence of a read call, user presses Ctrl-C after syscall on
24189host is called:
24190
24191@smallexample
24192<- @code{Fread,3,1234,6}
24193-> @code{X1234,6:XXXXXX}
24194<- @code{T02}
24195@end smallexample
24196
f418dd93
DJ
24197@include agentexpr.texi
24198
aab4e0ec 24199@include gpl.texi
eb12ee30 24200
2154891a 24201@raisesections
6826cf00 24202@include fdl.texi
2154891a 24203@lowersections
6826cf00 24204
6d2ebf8b 24205@node Index
c906108c
SS
24206@unnumbered Index
24207
24208@printindex cp
24209
24210@tex
24211% I think something like @colophon should be in texinfo. In the
24212% meantime:
24213\long\def\colophon{\hbox to0pt{}\vfill
24214\centerline{The body of this manual is set in}
24215\centerline{\fontname\tenrm,}
24216\centerline{with headings in {\bf\fontname\tenbf}}
24217\centerline{and examples in {\tt\fontname\tentt}.}
24218\centerline{{\it\fontname\tenit\/},}
24219\centerline{{\bf\fontname\tenbf}, and}
24220\centerline{{\sl\fontname\tensl\/}}
24221\centerline{are used for emphasis.}\vfill}
24222\page\colophon
24223% Blame: doc@cygnus.com, 1991.
24224@end tex
24225
c906108c 24226@bye
This page took 2.670084 seconds and 4 git commands to generate.